Example #1
0
    private void UpdateJoints(GPUSkinningFrame frame)
    {
        if (joints == null)
        {
            return;
        }

        Matrix4x4[]       matrices = frame.matrices;
        GPUSkinningBone[] bones    = res.anim.bones;
        int numJoints = joints.Count;

        for (int i = 0; i < numJoints; ++i)
        {
            GPUSkinningPlayerJoint joint = joints[i];
            Transform jointTransform     = Application.isPlaying ? joint.Transform : joint.transform;
            if (jointTransform != null)
            {
                jointTransform.localPosition = (frame.matrices[joint.BoneIndex] * bones[joint.BoneIndex].BindposeInv).MultiplyPoint(Vector3.zero);
            }
            else
            {
                joints.RemoveAt(i);
                --i;
                --numJoints;
            }
        }
    }
Example #2
0
    private void UpdateJoints(GPUSkinningFrame frame)
    {
        if (joints == null)
        {
            return;
        }

        //fzy delete:never used
        //Matrix4x4[] matrices = frame.matrices;
        GPUSkinningBone[] bones = res.anim.bones;
        int numJoints           = joints.Count;

        for (int i = 0; i < numJoints; ++i)
        {
            GPUSkinningPlayerJoint joint = joints[i];
            Transform jointTransform     = Application.isPlaying ? joint.Transform : joint.transform;
            if (jointTransform != null)
            {
                // TODO: Update Joint when Animation Blend

                Matrix4x4 jointMatrix = frame.matrices[joint.BoneIndex] * bones[joint.BoneIndex].BindposeInv;
                if (playingClip.rootMotionEnabled && rootMotionEnabled)
                {
                    jointMatrix = frame.RootMotionInv(res.anim.rootBoneIndex) * jointMatrix;
                }

                jointTransform.localPosition = jointMatrix.MultiplyPoint(Vector3.zero);

                Vector3    jointDir      = jointMatrix.MultiplyVector(Vector3.right);
                Quaternion jointRotation = Quaternion.FromToRotation(Vector3.right, jointDir);
                jointTransform.localRotation = jointRotation;
            }
            else
            {
                joints.RemoveAt(i);
                --i;
                --numJoints;
            }
        }
    }
Example #3
0
    private void ConstructJoints()
    {
        if (joints == null)
        {
            GPUSkinningPlayerJoint[] existingJoints = go.GetComponentsInChildren <GPUSkinningPlayerJoint>();

            GPUSkinningBone[] bones = res.anim.bones;
            int numBones            = bones == null ? 0 : bones.Length;
            for (int i = 0; i < numBones; ++i)
            {
                GPUSkinningBone bone = bones[i];
                if (bone.isExposed)
                {
                    if (joints == null)
                    {
                        joints = new List <GPUSkinningPlayerJoint>();
                    }

                    bool inTheExistingJoints = false;
                    if (existingJoints != null)
                    {
                        for (int j = 0; j < existingJoints.Length; ++j)
                        {
                            if (existingJoints[j] != null && existingJoints[j].BoneGUID == bone.guid)
                            {
                                if (existingJoints[j].BoneIndex != i)
                                {
                                    existingJoints[j].Init(i, bone.guid);
                                    GPUSkinningUtil.MarkAllScenesDirty();
                                }
                                joints.Add(existingJoints[j]);
                                existingJoints[j]   = null;
                                inTheExistingJoints = true;
                                break;
                            }
                        }
                    }

                    if (!inTheExistingJoints)
                    {
                        GameObject jointGo = new GameObject(bone.name);
                        jointGo.transform.parent        = go.transform;
                        jointGo.transform.localPosition = Vector3.zero;
                        jointGo.transform.localScale    = Vector3.one;

                        GPUSkinningPlayerJoint joint = jointGo.AddComponent <GPUSkinningPlayerJoint>();
                        joints.Add(joint);
                        joint.Init(i, bone.guid);
                        GPUSkinningUtil.MarkAllScenesDirty();
                    }
                }
            }

            if (!Application.isPlaying)
            {
#if UNITY_EDITOR
                UnityEditor.EditorApplication.CallbackFunction DelayCall = null;
                DelayCall = () =>
                {
                    UnityEditor.EditorApplication.delayCall -= DelayCall;
                    DeleteInvalidJoints(existingJoints);
                };
                UnityEditor.EditorApplication.delayCall += DelayCall;
#endif
            }
            else
            {
                DeleteInvalidJoints(existingJoints);
            }
        }
    }