Пример #1
0
 protected internal override Quaternion Read(
     ContentReader input,
     Quaternion existingInstance
     )
 {
     return(input.ReadQuaternion());
 }
        internal static AnimationClip Read(ContentReader input)
        {
            string animationName = input.ReadString();
            TimeSpan animationDuration = input.ReadObject<TimeSpan>();

            // Read animation clip channels
            Dictionary<string, AnimationChannel> animationChannelDictionary =
                new Dictionary<string, AnimationChannel>();

            int numAnimationChannels = input.ReadInt32();
            for (int i = 0; i < numAnimationChannels; i++)
            {
                string channelName = input.ReadString();

                // Read animation channel keyframes
                int numChannelKeyframes = input.ReadInt32();
                List<AnimationChannelKeyframe> keyframeList =
                    new List<AnimationChannelKeyframe>(numChannelKeyframes);

                for (int j = 0; j < numChannelKeyframes; j++)
                {
                    TimeSpan keyframeTime = input.ReadObject<TimeSpan>();

                    // Read keyframe pose
                    Pose keyframePose;
                    keyframePose.Translation = input.ReadVector3();
                    keyframePose.Orientation = input.ReadQuaternion();
                    keyframePose.Scale = input.ReadVector3();

                    keyframeList.Add(new AnimationChannelKeyframe(keyframeTime, keyframePose));
                }

                AnimationChannel animationChannel = new AnimationChannel(keyframeList);

                // Add the animation channel to the dictionary
                animationChannelDictionary.Add(channelName, animationChannel);
            }

            return
                new AnimationClip(animationName, animationDuration,
                    new AnimationChannelDictionary(animationChannelDictionary));
        }
        internal static SkinnedModelBone Read(ContentReader input)
        {
            // Read bone data
            ushort index = input.ReadUInt16();
            string name = input.ReadString();

            // Read bind pose
            Pose bindPose;
            bindPose.Translation = input.ReadVector3();
            bindPose.Orientation = input.ReadQuaternion();
            bindPose.Scale = input.ReadVector3();

            Matrix inverseBindPoseTransform = input.ReadMatrix();
            SkinnedModelBone skinnedBone =
                new SkinnedModelBone(index, name, bindPose, inverseBindPoseTransform);

            // Read bone parent
            input.ReadSharedResource<SkinnedModelBone>(
                delegate(SkinnedModelBone parentBone) { skinnedBone.parent = parentBone; });

            // Read bone children
            int numChildren = input.ReadInt32();
            List<SkinnedModelBone> childrenList = new List<SkinnedModelBone>(numChildren);
            for (int i = 0; i < numChildren; i++)
            {
                input.ReadSharedResource<SkinnedModelBone>(
                    delegate(SkinnedModelBone childBone) { childrenList.Add(childBone); });
            }
            skinnedBone.children = new SkinnedModelBoneCollection(childrenList);

            return skinnedBone;
        }