/// <summary>Initializes a new instance of the 
        /// <see cref="T:XNAnimation.Controllers.AnimationController" />
        /// class.
        /// </summary>
        /// <param name="skeleton">The skeleton of the model to be animated</param>
        public AnimationController(SkinnedModelBoneCollection skeleton)
        {
            this.skeleton = skeleton;
            localBonePoses = new Pose[skeleton.Count];
            skinnedBoneTransforms = new Matrix[skeleton.Count];
            skeleton[0].CopyBindPoseTo(localBonePoses);

            time = TimeSpan.Zero;
            speed = 1.0f;
            loopEnabled = true;
            playbackMode = PlaybackMode.Forward;

            blendWeight = 1.0f;

            translationInterpolation = InterpolationMode.None;
            orientationInterpolation = InterpolationMode.None;
            scaleInterpolation = InterpolationMode.None;

            crossFadeEnabled = false;
            crossFadeInterpolationAmount = 0.0f;
            crossFadeTime = TimeSpan.Zero;
            crossFadeElapsedTime = TimeSpan.Zero;

            hasFinished = false;
            isPlaying = false;
        }
Exemplo n.º 2
0
        /// <summary>Initializes a new instance of the
        /// <see cref="T:XNAnimation.Controllers.AnimationController" />
        /// class.
        /// </summary>
        /// <param name="skeleton">The skeleton of the model to be animated</param>
        public AnimationController(SkinnedModelBoneCollection skeleton)
        {
            this.skeleton         = skeleton;
            localBonePoses        = new Pose[skeleton.Count];
            skinnedBoneTransforms = new Matrix[skeleton.Count];
            skeleton[0].CopyBindPoseTo(localBonePoses);

            time         = TimeSpan.Zero;
            speed        = 1.0f;
            loopEnabled  = true;
            playbackMode = PlaybackMode.Forward;

            blendWeight = 1.0f;

            translationInterpolation = InterpolationMode.None;
            orientationInterpolation = InterpolationMode.None;
            scaleInterpolation       = InterpolationMode.None;

            crossFadeEnabled             = false;
            crossFadeInterpolationAmount = 0.0f;
            crossFadeTime        = TimeSpan.Zero;
            crossFadeElapsedTime = TimeSpan.Zero;

            hasFinished = false;
            isPlaying   = false;
        }
        private void ReadBones(ContentReader input)
        {
            int numSkeletonBones = input.ReadInt32();
            List<SkinnedModelBone> skinnedModelBoneList = new List<SkinnedModelBone>(numSkeletonBones);

            // Read all bones
            for (int i = 0; i < numSkeletonBones; i++)
            {
                input.ReadSharedResource<SkinnedModelBone>(
                    delegate(SkinnedModelBone skinnedBone) { skinnedModelBoneList.Add(skinnedBone); });
            }

            // Create the skeleton
            skeleton = new SkinnedModelBoneCollection(skinnedModelBoneList);

            //foreach (SkinnedModelBoneContent bone in skeleton)
            //output.WriteSharedResource(bone);

            /*
            ///
            /// TODO I can optimize this using write shared resource for the skeleton
            /// 
            string rootBoneName = input.ReadString();
            int numBones = input.ReadInt32();

            SkinnedModelBone[] tempBonesArray = new SkinnedModelBone[numBones];
            Dictionary<string, SkinnedModelBone> boneDictionary =
                new Dictionary<string, SkinnedModelBone>();

            // Read all boneDictionary
            for (int i = 0; i < numBones; i++)
            {
                string boneName = input.ReadString();
                Matrix boneTransform = input.ReadMatrix();
                Matrix boneAbsoluteTransform = input.ReadMatrix();
                Matrix boneBindPoseTransform = input.ReadMatrix();

                SkinnedModelBone bone =
                    new SkinnedModelBone(boneName, boneTransform, boneAbsoluteTransform,
                        boneBindPoseTransform);

                tempBonesArray[i] = bone;
                boneDictionary.Add(boneName, bone);
            }

            // Read the boneDictionary parent and children
            for (int i = 0; i < numBones; i++)
            {
                // Find parent bone
                SkinnedModelBone parentBone = null;
                string parentBoneName = input.ReadObject<string>();
                if (parentBoneName != null)
                    parentBone = boneDictionary[parentBoneName];

                tempBonesArray[i].Parent = parentBone;

                // Find children
                int numChildren = input.ReadInt32();
                List<SkinnedModelBone> childrenList = new List<SkinnedModelBone>(numChildren);
                for (int j = 0; j < numChildren; j++)
                {
                    string childName = input.ReadString();
                    childrenList.Add(boneDictionary[childName]);
                }

                tempBonesArray[i].Children = new SkinnedModelBoneCollection(childrenList);
            }

            // Store everything
            tempBonesArray = null;

            rootBone = boneDictionary[rootBoneName];
            this.boneDictionary = new SkinnedModelBoneDictionary(boneDictionary);
            skinnedBones = new Matrix[numBones];

            inverseBindPose = new Matrix[numBones];
            rootBone.GetHierarchyInverseBindPoseTransfom(ref inverseBindPose);
             */
        }
Exemplo n.º 4
0
        private void ReadBones(ContentReader input)
        {
            int numSkeletonBones = input.ReadInt32();
            List<SkinnedModelBone> skinnedModelBoneList = new List<SkinnedModelBone>(numSkeletonBones);

            // Read all bones
            for (int i = 0; i < numSkeletonBones; i++)
            {
                input.ReadSharedResource<SkinnedModelBone>(
                    delegate(SkinnedModelBone skinnedBone) { skinnedModelBoneList.Add(skinnedBone); });
            }

            // Create the skeleton
            skeleton = new SkinnedModelBoneCollection(skinnedModelBoneList);
        }