示例#1
0
	public void OnInitializeAgent()
    {
		Time.fixedDeltaTime = FixedDeltaTime;
		_waitingForAnimation = true;
		_decisionRequester = GetComponent<DecisionRequester>();

		BodyParts = new List<BodyPart002> ();
		BodyPart002 root = null;
		foreach (var t in GetComponentsInChildren<Transform>())
		{
			if (BodyConfig.GetBodyPartGroup(t.name) == BodyHelper002.BodyPartGroup.None)
				continue;
			
			var bodyPart = new BodyPart002{
				Rigidbody = t.GetComponent<Rigidbody>(),
				Transform = t,
				Name = t.name,
				Group = BodyConfig.GetBodyPartGroup(t.name), 
			};
			if (bodyPart.Group == BodyConfig.GetRootBodyPart())
				root = bodyPart;
			bodyPart.Root = root;
			bodyPart.Init();
			BodyParts.Add(bodyPart);
		}
		var partCount = BodyParts.Count;

		Muscles = new List<Muscle002> ();
		var muscles = GetComponentsInChildren<ConfigurableJoint>();
		ConfigurableJoint rootConfigurableJoint = null;
		var ragDoll = GetComponent<RagDoll002>();
		foreach (var m in muscles)
		{
			var maximumForce = ragDoll.MusclePowers.First(x=>x.Muscle == m.name).PowerVector;
			// maximumForce *= 2f;
			var muscle = new Muscle002{
				Rigidbody = m.GetComponent<Rigidbody>(),
				Transform = m.GetComponent<Transform>(),
				ConfigurableJoint = m,
				Name = m.name,
				Group = BodyConfig.GetMuscleGroup(m.name),
				MaximumForce = maximumForce
			};
			if (muscle.Group == BodyConfig.GetRootMuscle())
				rootConfigurableJoint = muscle.ConfigurableJoint;
			muscle.RootConfigurableJoint = rootConfigurableJoint;
			muscle.Init();

			Muscles.Add(muscle);			
		}
		var spawnableEnv = GetComponentInParent<SpawnableEnv>();
		_localStyleAnimator = spawnableEnv.gameObject.GetComponentInChildren<StyleTransfer002Animator>();
		_styleAnimator = _localStyleAnimator.GetFirstOfThisAnim();
		// _styleAnimator = _localStyleAnimator;
		_muscleAnimator = _styleAnimator;
		_agent = GetComponent<StyleTransfer002Agent>();
		// _trainerAgent = GetComponent<StyleTransfer002TrainerAgent>();
		// _brain = FindObjectsOfType<Brain>().First(x=>x.name=="LearnFromMocapBrain");
		IsInferenceMode = !Academy.Instance.IsCommunicatorOn;
	}
示例#2
0
    void SetupBody()
    {
        _agent              = GetComponent <Agent>();
        _decisionRequester  = GetComponent <DecisionRequester>();
        Time.fixedDeltaTime = FixedDeltaTime;

        BodyParts = new List <BodyPart002> ();
        BodyPart002 root = null;

        foreach (var t in GetComponentsInChildren <Transform>())
        {
            if (BodyConfig.GetBodyPartGroup(t.name) == BodyHelper002.BodyPartGroup.None)
            {
                continue;
            }

            var bodyPart = new BodyPart002 {
                Rigidbody = t.GetComponent <Rigidbody>(),
                Transform = t,
                Name      = t.name,
                Group     = BodyConfig.GetBodyPartGroup(t.name),
            };
            if (bodyPart.Group == BodyConfig.GetRootBodyPart())
            {
                root = bodyPart;
            }
            bodyPart.Root = root;
            bodyPart.Init();
            BodyParts.Add(bodyPart);
        }
        var partCount = BodyParts.Count;

        Muscles = new List <Muscle002> ();
        var muscles = GetComponentsInChildren <ConfigurableJoint>();
        ConfigurableJoint rootConfigurableJoint = null;
        var ragDoll = GetComponent <RagDoll002>();

        foreach (var m in muscles)
        {
            var maximumForce = ragDoll.MusclePowers.First(x => x.Muscle == m.name).PowerVector;
            maximumForce *= ragDoll.MotorScale;
            var muscle = new Muscle002 {
                Rigidbody         = m.GetComponent <Rigidbody>(),
                Transform         = m.GetComponent <Transform>(),
                ConfigurableJoint = m,
                Name         = m.name,
                Group        = BodyConfig.GetMuscleGroup(m.name),
                MaximumForce = maximumForce
            };
            if (muscle.Group == BodyConfig.GetRootMuscle())
            {
                rootConfigurableJoint = muscle.ConfigurableJoint;
            }
            muscle.RootConfigurableJoint = rootConfigurableJoint;
            muscle.Init();

            Muscles.Add(muscle);
        }
        _startCount++;
    }
    // Reset the animator.
    void Reset()
    {
        BodyParts = new List <BodyPart002> ();
        BodyPart002 root = null;

        if (_rigidbodies == null || _transforms == null)
        {
            _rigidbodies = GetComponentsInChildren <Rigidbody>().ToList();
            _transforms  = GetComponentsInChildren <Transform>().ToList();
        }

        foreach (var t in _transforms)
        {
            if (BodyConfig.GetBodyPartGroup(t.name) == BodyHelper002.BodyPartGroup.None)
            {
                continue;
            }

            var bodyPart = new BodyPart002 {
                Rigidbody = t.GetComponent <Rigidbody>(),
                Transform = t,
                Name      = t.name,
                Group     = BodyConfig.GetBodyPartGroup(t.name),
            };
            if (bodyPart.Group == BodyConfig.GetRootBodyPart())
            {
                root = bodyPart;
            }
            bodyPart.Root = root;
            bodyPart.Init();
            BodyParts.Add(bodyPart);
        }
        var partCount = BodyParts.Count;

        SetupSensors();

        _lastPosition      = Enumerable.Repeat(Vector3.zero, partCount).ToList();
        _lastRotation      = Enumerable.Repeat(Quaternion.identity, partCount).ToList();
        _lastPositionLocal = Enumerable.Repeat(Vector3.zero, partCount).ToList();
        _lastRotationLocal = Enumerable.Repeat(Quaternion.identity, partCount).ToList();
        _lastCenterOfMass  = transform.position;
        _initialRotations  = BodyParts
                             .Select(x => x.Transform.rotation)
                             .ToList();
        BecomeAnimated();
    }
    void Reset()
    {
        BodyParts = new List <BodyPart002> ();
        BodyPart002 root = null;

        foreach (var t in GetComponentsInChildren <Transform>())
        {
            if (BodyHelper002.GetBodyPartGroup(t.name) == BodyHelper002.BodyPartGroup.None)
            {
                continue;
            }

            var bodyPart = new BodyPart002 {
                Rigidbody = t.GetComponent <Rigidbody>(),
                Transform = t,
                Name      = t.name,
                Group     = BodyHelper002.GetBodyPartGroup(t.name),
            };
            if (bodyPart.Group == BodyHelper002.BodyPartGroup.Hips)
            {
                root = bodyPart;
            }
            bodyPart.Root = root;
            bodyPart.Init();
            BodyParts.Add(bodyPart);
        }
        var partCount = BodyParts.Count;

        SetupSensors();

        _lastPosition         = Enumerable.Repeat(Vector3.zero, partCount).ToList();
        _lastRotation         = Enumerable.Repeat(Quaternion.identity, partCount).ToList();
        _lastVelocityPosition = transform.position;
        var anims = GetComponentsInChildren <Transform>();

        //_bodyParts = _master.Muscles.Select(x=> anims.First(y=>y.name == x.Name).transform).ToList();
        _initialRotations = BodyParts
                            .Select(x => x.Transform.rotation)
                            .ToList();
        BecomeAnimated();
    }
    void Start()
    {
        Time.fixedDeltaTime  = FixedDeltaTime;
        _waitingForAnimation = true;

        BodyParts = new List <BodyPart002> ();
        BodyPart002 root = null;

        foreach (var t in GetComponentsInChildren <Transform>())
        {
            if (BodyHelper002.GetBodyPartGroup(t.name) == BodyHelper002.BodyPartGroup.None)
            {
                continue;
            }

            var bodyPart = new BodyPart002 {
                Rigidbody = t.GetComponent <Rigidbody>(),
                Transform = t,
                Name      = t.name,
                Group     = BodyHelper002.GetBodyPartGroup(t.name),
            };
            if (bodyPart.Group == BodyHelper002.BodyPartGroup.Hips)
            {
                root = bodyPart;
            }
            bodyPart.Root = root;
            bodyPart.Init();
            BodyParts.Add(bodyPart);
        }
        var partCount = BodyParts.Count;

        Muscles = new List <Muscle002> ();
        var muscles = GetComponentsInChildren <ConfigurableJoint>();
        ConfigurableJoint rootConfigurableJoint = null;
        var ragDoll = GetComponent <RagDoll002>();

        foreach (var m in muscles)
        {
            var maximumForce = ragDoll.MusclePowers.First(x => x.Muscle == m.name).PowerVector;
            // maximumForce *= 2f;
            var muscle = new Muscle002 {
                Rigidbody         = m.GetComponent <Rigidbody>(),
                Transform         = m.GetComponent <Transform>(),
                ConfigurableJoint = m,
                Name         = m.name,
                Group        = BodyHelper002.GetMuscleGroup(m.name),
                MaximumForce = maximumForce
            };
            if (muscle.Group == BodyHelper002.MuscleGroup.Hips)
            {
                rootConfigurableJoint = muscle.ConfigurableJoint;
            }
            muscle.RootConfigurableJoint = rootConfigurableJoint;
            muscle.Init();

            Muscles.Add(muscle);
        }
        _muscleAnimator = FindObjectOfType <StyleTransfer002Animator>();
        _agent          = GetComponent <StyleTransfer002Agent>();
        // _trainerAgent = GetComponent<StyleTransfer002TrainerAgent>();
        _brain         = FindObjectsOfType <Brain>().First(x => x.name == "LearnFromMocapBrain");
        _academy       = FindObjectOfType <Academy>();
        _styleAnimator = FindObjectOfType <StyleTransfer002Animator>();
        switch (_brain.brainType)
        {
        case BrainType.External:
            IsInferenceMode = false;
            break;

        case BrainType.Player:
        case BrainType.Internal:
        case BrainType.Heuristic:
            IsInferenceMode = true;
            break;

        default:
            throw new System.NotImplementedException();
        }
    }