Inheritance: AnimationTrack
Esempio n. 1
0
        /// <summary>
        ///		Creates a new NodeAnimationTrack automatically associated with a Node.
        /// </summary>
        /// <param name="index">Handle to give the track, used for accessing the track later.</param>
        /// <param name="targetNode">Node object which will be affected by this track.</param>
        /// <returns></returns>
        public NodeAnimationTrack CreateNodeTrack(ushort handle, Node targetNode)
        {
            // create a new track and set it's target
            NodeAnimationTrack track = CreateNodeTrack(handle);

            track.TargetNode = targetNode;

            return(track);
        }
Esempio n. 2
0
        /// <summary>
        ///		Creates an NodeAnimationTrack.
        /// </summary>
        /// <param name="handle">Handle to give the track, used for accessing the track later.</param>
        /// <returns></returns>
        public NodeAnimationTrack CreateNodeTrack(ushort handle)
        {
            NodeAnimationTrack track = new NodeAnimationTrack(this, handle);

            // add the track to the list
            nodeTrackList[handle] = track;

            return(track);
        }
Esempio n. 3
0
 public void Apply(Skeleton skeleton, float time, float weight, bool accumulate, float scale)
 {
     // loop through tracks and update them all with current time
     foreach (KeyValuePair <ushort, NodeAnimationTrack> pair in nodeTrackList)
     {
         NodeAnimationTrack track = pair.Value;
         Bone bone = skeleton.GetBone(pair.Key);
         track.ApplyToNode(bone, time, weight, accumulate, scale);
     }
 }
 protected XmlElement WriteTrack(NodeAnimationTrack track)
 {
     XmlElement node = document.CreateElement("track");
     XmlAttribute attr;
     attr = document.CreateAttribute("bone");
     attr.Value = track.TargetNode.Name;
     node.Attributes.Append(attr);
     XmlElement keyFramesNode = document.CreateElement("keyframes");
     foreach (KeyFrame baseKeyFrame in track.KeyFrames) {
         TransformKeyFrame keyFrame = (TransformKeyFrame)baseKeyFrame;
         //if (track.TargetNode.Parent != null)
         //    Debug.Assert(keyFrame.Translate.LengthSquared < .01);
         XmlElement keyFrameNode = WriteKeyFrame(keyFrame);
         keyFramesNode.AppendChild(keyFrameNode);
     }
     node.AppendChild(keyFramesNode);
     return node;
 }
        protected void TransformTrack(Matrix4 exportTransform,
									  NodeAnimationTrack newTrack, 
									  NodeAnimationTrack track,
									  Bone bone)
        {
            Matrix4 invExportTransform = exportTransform.Inverse();
            Bone oldNode = (Bone)track.TargetNode;
            Bone newNode = (Bone)newTrack.TargetNode;
            for (int i = 0; i < track.KeyFrames.Count; ++i) {
                TransformKeyFrame keyFrame = track.GetTransformKeyFrame(i);
                TransformKeyFrame newKeyFrame = newTrack.CreateNodeKeyFrame(keyFrame.Time);
                Quaternion oldOrientation = oldNode.Orientation * keyFrame.Rotation;
                Vector3 oldTranslation = oldNode.Position + keyFrame.Translate;
                Matrix4 oldTransform = Multiverse.MathLib.MathUtil.GetTransform(oldOrientation, oldTranslation);
                Matrix4 newTransform = exportTransform * oldTransform * invExportTransform;
                Quaternion newOrientation = GetRotation(newTransform);
                Vector3 newTranslation = newTransform.Translation;
                newKeyFrame.Rotation = newNode.Orientation.Inverse() * newOrientation;
                newKeyFrame.Translate = newTranslation - newNode.Position;
                //if (oldNode.Name == "Lower_Torso_BIND_jjj") {
                //    log.DebugFormat("New translation: {0}; New Position: {1}", newTranslation, newNode.Position);
                //}
            }
        }
Esempio n. 6
0
		protected void WriteAnimationTrack( BinaryWriter writer, NodeAnimationTrack track )
		{
			long start_offset = writer.Seek( 0, SeekOrigin.Current );
			WriteChunk( writer, SkeletonChunkID.AnimationTrack, 0 );

			WriteUShort( writer, (ushort)track.Handle );
			for ( ushort i = 0; i < track.KeyFrames.Count; i++ )
			{
				TransformKeyFrame keyFrame = track.GetNodeKeyFrame( i );
				WriteKeyFrame( writer, keyFrame );
			}
			long end_offset = writer.Seek( 0, SeekOrigin.Current );
			writer.Seek( (int)start_offset, SeekOrigin.Begin );
			WriteChunk( writer, SkeletonChunkID.AnimationTrack, (int)( end_offset - start_offset ) );
			writer.Seek( (int)end_offset, SeekOrigin.Begin );
		}
Esempio n. 7
0
	    /// <summary>
	    ///    Reads an animation track section.
	    /// </summary>
	    protected void ReadKeyFrame( BinaryReader reader, NodeAnimationTrack track )
		{
			float time = ReadFloat( reader );

			// create a new keyframe with the specified length
			TransformKeyFrame keyFrame = track.CreateNodeKeyFrame( time );

			// read orientation
			Quaternion rotate = ReadQuat( reader );
			keyFrame.Rotation = rotate;

			// read translation
			Vector3 translate = ReadVector3( reader );
			keyFrame.Translate = translate;

			// read scale if it is in there
			if ( currentChunkLength >= 50 )
			{
				Vector3 scale = ReadVector3( reader );
				keyFrame.Scale = scale;
			}
			else
			{
				keyFrame.Scale = Vector3.UnitScale;
			}
		}
Esempio n. 8
0
		/// <summary>
		///		Creates an NodeAnimationTrack. 
		/// </summary>
		/// <param name="handle">Handle to give the track, used for accessing the track later.</param>
		/// <returns></returns>
		public NodeAnimationTrack CreateNodeTrack( ushort handle )
		{
			NodeAnimationTrack track = new NodeAnimationTrack( this, handle );

			// add the track to the list
			nodeTrackList[ handle ] = track;

			return track;
		}
 public static void DuplicateKeyFrame(NodeAnimationTrack track, TransformKeyFrame orig)
 {
     TransformKeyFrame newKeyFrame = (TransformKeyFrame)track.CreateKeyFrame(orig.Time);
     newKeyFrame.Scale = orig.Scale;
     newKeyFrame.Rotation = orig.Rotation;
     newKeyFrame.Translate = orig.Translate;
 }