protected void TransformTrack(Matrix4 unscaledTransform, float scale,
                                      Animation newAnim, Animation anim, Bone bone)
        {
            AnimationTrack track             = GetBoneTrack(anim, bone.Handle);
            AnimationTrack newTrack          = GetBoneTrack(newAnim, bone.Handle);
            Bone           oldNode           = (Bone)track.TargetNode;
            Bone           newNode           = (Bone)newTrack.TargetNode;
            Quaternion     exportRotation    = GetRotation(unscaledTransform);
            Vector3        exportTranslation = unscaledTransform.Translation;

            for (int i = 0; i < track.KeyFrames.Count; ++i)
            {
                KeyFrame   keyFrame       = track.KeyFrames[i];
                Quaternion oldOrientation = Quaternion.Identity;
                Vector3    oldTranslation = Vector3.Zero;
                // Now build the composite transform for the old node
                GetCompositeTransform(ref oldOrientation, ref oldTranslation, oldNode, anim, i);
                Quaternion targetOrientation = exportRotation * oldOrientation;
                Vector3    targetTranslation = exportTranslation + scale * (exportRotation * oldTranslation);
                KeyFrame   newKeyFrame       = newTrack.CreateKeyFrame(keyFrame.Time);
                // we have a parent - where is it?
                Quaternion parentOrientation = Quaternion.Identity;
                Vector3    parentTranslation = Vector3.Zero;
                GetCompositeTransform(ref parentOrientation, ref parentTranslation, (Bone)newNode.Parent, newAnim, i);
                newKeyFrame.Rotation  = newNode.Orientation.Inverse() * parentOrientation.Inverse() * targetOrientation;
                newKeyFrame.Translate = (-1 * newNode.Position) + (-1 * parentTranslation) + targetTranslation;
            }
        }
        protected void ReadKeyFrame(XmlNode node, AnimationTrack track)
        {
            float time = float.Parse(node.Attributes["time"].Value);
            // create a new keyframe with the specified length
            TransformKeyFrame keyFrame = (TransformKeyFrame)track.CreateKeyFrame(time);

            foreach (XmlNode childNode in node.ChildNodes)
            {
                switch (childNode.Name)
                {
                case "translate":
                    keyFrame.Translate = ReadVector3(childNode);
                    break;

                case "rotate":
                    ReadRotate(childNode, keyFrame);
                    break;

                default:
                    DebugMessage(childNode);
                    break;
                }
            }
        }
Esempio n. 3
0
        protected void AddKey(AnimationTrack track, float time, Vector3 translate)
        {
            TransformKeyFrame key = (TransformKeyFrame)track.CreateKeyFrame(time);

            key.Translate = translate;
        }