示例#1
0
        public JointPose jointAt(float time)
        {
            //check for single pose
            if (poses.Count == 1)
            {
                return(poses[0]);
            }

            int idx = 0;

            while (idx < poses.Count - 1 && time > poses[idx].time)
            {
                idx++;
            }

            //check for time past the last pose
            if (time > poses[idx].time || idx == 0)
            {
                return(poses[idx]);
            }

            float interpolation = (time - poses[idx - 1].time) / (poses[idx].time - poses[idx - 1].time);

            JointPose ret = new JointPose();

            ret.position = Vector3.Lerp(poses[idx - 1].position, poses[idx].position, interpolation);
            ret.rotation = Quaternion.Slerp(poses[idx - 1].rotation, poses[idx].rotation, interpolation);

            return(ret);
        }
示例#2
0
        public List <Matrix4> buildAnimationFrame(float time)
        {
            List <Matrix4> frame = new List <Matrix4>(skeleton.boneCount);

            for (int i = 0; i < skeleton.boneCount; i++)
            {
                JointPose jp = channels[i].jointAt(time);

                Matrix4 rel   = Matrix4.CreateFromQuaternion(jp.rotation) * Matrix4.CreateTranslation(jp.position);
                Matrix4 final = Matrix4.Identity;
                Bone    b     = skeleton.myBones[i];
                if (b.myParent == -1)
                {
                    final = rel;
                }
                else
                {
                    final = rel * frame[b.myParent];
                }

                frame.Add(final);
            }

            for (int i = 0; i < skeleton.boneCount; i++)
            {
                frame[i] = skeleton.myBones[i].myInvWorldBindMatrix * frame[i];
            }

            return(frame);
        }
示例#3
0
        public void createNullAnimation()
        {
            //insert the null animation
            Animation nullAni = new Animation();

            nullAni.name     = "null";
            nullAni.fps      = 0;
            nullAni.loop     = false;
            nullAni.skeleton = skeleton;

            for (int i = 0; i < skeleton.boneCount; i++)
            {
                AnimationChannel boneChannel = new AnimationChannel();
                JointPose        jp          = new JointPose();
                jp.position = Vector3.Zero;
                jp.rotation = Quaternion.Identity;
                boneChannel.poses.Add(jp);
                nullAni.channels.Add(boneChannel);
            }

            animations["null"] = nullAni;
        }