Beispiel #1
0
        public override void ApplyAgentState()
        {
            /*
             * for (int b = 0; b < agentState.boneValues.Length; b++) {
             *  //bones[b].localPosition = agentState.positions[b];
             *  //bones[b].localRotation = agentState.rotations[b];
             *
             *  Vector3 newPosition = Vector3.zero;
             *  if (b < 2) {
             *      newPosition = new Vector3(
             *          -agentState.boneTranslations[b].t[0], // Minus x value b/c of different COS in ASAP
             *           agentState.boneTranslations[b].t[1],
             *           agentState.boneTranslations[b].t[2]);
             *  }
             *  Quaternion newRotation = new Quaternion(
             *      -agentState.boneValues[b].r[0], // Same with order and sign of quat values
             *       agentState.boneValues[b].r[1],
             *       agentState.boneValues[b].r[2],
             *      -agentState.boneValues[b].r[3]);
             *  if (b == 0) {
             *      // Humanoid Root
             *      bones[b].localPosition = newPosition;
             *      bones[b].localRotation = qInit[b] * RGi[b] * newRotation * RG[b];
             *      //positionBone.position = new Vector3(bones[b].position.x, 0.0f, bones[b].position.z);
             *      // The above caused double x/y translation as position is also added to hip bone...
             *      // TODO: orientation facing HumanoidRoot direction
             *      positionBone.localPosition = new Vector3(0.0f, 0.0f, 0.0f);
             *  } else if (b == 1) {
             *      // Hip Bone
             *      //bones[b].localPosition = humanoidRoot.TransformPoint(newPosition);
             *      bones[b].localRotation = qInit[b] * RGi[b] * newRotation * RG[b];
             *  } else {
             *      bones[b].localRotation = qInit[b] * RGi[b] * newRotation * RG[b];
             *  }
             *  //bones[b].localRotation = agentState.rotations[b];
             * }
             */


            AgentState _agentState;

            if (manualAnimation && manualAgentState != null)
            {
                _agentState = manualAgentState;
            }
            else
            {
                _agentState = agentState;
            }

            for (int b = 0; b < _agentState.boneValues.Length; b++)
            {
                //bones[b].localPosition = agentState.positions[b];
                //bones[b].localRotation = agentState.rotations[b];
                Vector3 newPosition = Vector3.zero;
                if (b < 2)
                {
                    newPosition = new Vector3(
                        -_agentState.boneTranslations[b].t[0], // Minus x value b/c of different COS in ASAP
                        _agentState.boneTranslations[b].t[1],
                        _agentState.boneTranslations[b].t[2]);
                }
                Quaternion newRotation = new Quaternion(
                    -_agentState.boneValues[b].r[0], // Same with order and sign of quat values
                    _agentState.boneValues[b].r[1],
                    _agentState.boneValues[b].r[2],
                    -_agentState.boneValues[b].r[3]);


                if (b == 0)
                {
                    Quaternion newRot = qInit[b] * RGi[b] * newRotation * RG[b];
                    positionBone.position      = new Vector3(newPosition.x, 0.0f, newPosition.z) * (positionBone.localScale.x);
                    bones[b].localPosition     = new Vector3(-newPosition.y, 0.0f, 0.0f);//* (1/positionBone.localScale.x);
                    positionBone.localRotation = Quaternion.Euler(newRot.eulerAngles.x, 0.0f, 0.0f);
                    bones[b].localRotation     = Quaternion.Inverse(positionBone.localRotation) * newRot;
                }
                else if (b == 1)
                {
                    //hipShouldBeHere.parent = bones[b];
                    //hipShouldBeHere.localPosition = newPosition;
                    // Hip Bone

                    bones[b].position = bones[b - 1].TransformPoint(Quaternion.Euler(0.0f, 0.0f, 90.0f) * rootToHipsOffset); // humanoid root is a fake parent
                    Quaternion hipRotation = qInit[b] * RGi[b] * newRotation * RG[b];
                    bones[b].rotation = bones[b - 1].rotation * hipRotation;                                                 // humanoid root is a fake parent
                }
                else
                {
                    bones[b].localRotation = qInit[b] * RGi[b] * newRotation * RG[b];
                }
                //bones[b].localRotation = agentState.rotations[b];
            }

            if (retarget != null)
            {
                retarget.StorePose();
                HumanPose pose = retarget.GetPose();
                poseHandler.SetHumanPose(ref pose);
            }

            float[] zeroes = new float[ExpressionPlayer.PoseCount];
            expressionControlValues = zeroes;

            for (int f = 0; f < agentState.faceTargetValues.Length; f++)
            {
                if (Mathf.Approximately(agentState.faceTargetValues[f], 0.0f))
                {
                    continue;
                }

                if (typeof(ExpressionPlayerFaceTarget) == agentSpec.faceTargetsControls[f].GetType())
                {
                    ExpressionPlayerFaceTarget epft = ((ExpressionPlayerFaceTarget)agentSpec.faceTargetsControls[f]);
                    for (int c = 0; c < epft.expressionControlMapping.indexes.Length; c++)
                    {
                        int idx = epft.expressionControlMapping.indexes[c];
                        expressionControlValues[idx] = epft.expressionControlMapping.values[c] * agentState.faceTargetValues[f];
                    }
                }
            }

            ep.Values = expressionControlValues;
            ep.SetValues();
        }
        public override void ApplyAgentState()
        {
            //Debug.Log("Would Set AGent Sate...");

            AgentState _agentState;

            if (manualAnimation && manualAgentState != null)
            {
                _agentState = manualAgentState;
            }
            else
            {
                _agentState = agentState;
            }

            for (int b = 0; b < _agentState.boneValues.Length; b++)
            {
                //bones[b].localPosition = agentState.positions[b];
                //bones[b].localRotation = agentState.rotations[b];
                Vector3 newPosition = Vector3.zero;
                if (b < 2)
                {
                    newPosition = new Vector3(
                        -_agentState.boneTranslations[b].t[0], // Minus x value b/c of different COS in ASAP
                        _agentState.boneTranslations[b].t[1],
                        _agentState.boneTranslations[b].t[2]);
                }
                Quaternion newRotation = new Quaternion(
                    -_agentState.boneValues[b].r[0], // Same with order and sign of quat values
                    _agentState.boneValues[b].r[1],
                    _agentState.boneValues[b].r[2],
                    -_agentState.boneValues[b].r[3]);
                if (b == 0)
                {
                    Quaternion newRot = qInit[b] * RGi[b] * newRotation * RG[b];
                    positionBone.position      = new Vector3(newPosition.x, 0.0f, newPosition.z);// * (1/positionBone.localScale.x);
                    bones[b].localPosition     = new Vector3(-newPosition.y, 0.0f, 0.0f) * (1 / positionBone.localScale.x);
                    positionBone.localRotation = Quaternion.Euler(newRot.eulerAngles.x, 0.0f, 0.0f);
                    bones[b].localRotation     = Quaternion.Inverse(positionBone.localRotation) * newRot;
                }
                else if (b == 1)
                {
                    //hipShouldBeHere.parent = bones[b];
                    //hipShouldBeHere.localPosition = newPosition;
                    // Hip Bone

                    bones[b].position = bones[b - 1].TransformPoint(Quaternion.Euler(0.0f, 0.0f, 90.0f) * rootToHipsOffset); // humanoid root is a fake parent
                    Quaternion hipRotation = qInit[b] * RGi[b] * newRotation * RG[b];
                    bones[b].rotation = bones[b - 1].rotation * hipRotation;                                                 // humanoid root is a fake parent
                }
                else
                {
                    bones[b].localRotation = qInit[b] * RGi[b] * newRotation * RG[b];
                }
                //bones[b].localRotation = agentState.rotations[b];
            }

            if (retarget != null)
            {
                retarget.StorePose();
                HumanPose pose = retarget.GetPose();
                poseHandler.SetHumanPose(ref pose);
            }

            float[] zeroes = new float[ExpressionPlayer.PoseCount];
            expressionControlValues = zeroes;

            for (int f = 0; f < agentState.faceTargetValues.Length; f++)
            {
                if (Mathf.Approximately(agentState.faceTargetValues[f], 0.0f))
                {
                    continue;
                }

                if (typeof(ExpressionPlayerFaceTarget) == agentSpec.faceTargetsControls[f].GetType())
                {
                    ExpressionPlayerFaceTarget epft = ((ExpressionPlayerFaceTarget)agentSpec.faceTargetsControls[f]);
                    for (int c = 0; c < epft.expressionControlMapping.indexes.Length; c++)
                    {
                        int idx = epft.expressionControlMapping.indexes[c];
                        expressionControlValues[idx] += epft.expressionControlMapping.values[c] * agentState.faceTargetValues[f];
                        // TODO: Average/dampen/....
                    }
                }
            }
            ep.Values = expressionControlValues;

            if (twistBones != null)
            {
                // Don't want to change the default UMA script to have
                // a Twist() function that is called when we want it...
                // Better to make a clone instead.
                //twistBones.Twist ();
            }
        }