Exemplo n.º 1
0
        public void Initialize(AnimationClip clip, MySkinnedEntity skinnedEntity, float weight, float timeScale, MyFrameOption frameOption, string[] explicitBones = null)
        {
            m_clip = clip;
            m_skinnedEntity = skinnedEntity;
            m_weight = weight;
            m_timeScale = timeScale;
            m_frameOption = frameOption;
            
            // Create the bone information classes
            var maxBoneCount = explicitBones == null ? clip.Bones.Count : explicitBones.Length;
            if (m_boneInfos == null || m_boneInfos.Length < maxBoneCount)
                m_boneInfos = new BoneInfo[maxBoneCount];

            int neededBonesCount = 0;

            for (int b = 0; b < maxBoneCount; b++)
            {
                var bone = explicitBones == null ? clip.Bones[b] : FindBone(clip.Bones, explicitBones[b]);
                if (bone == null)
                    continue;

                if (bone.Keyframes.Count == 0) 
                    continue;

                // Create it
                m_boneInfos[neededBonesCount] = new BoneInfo(bone, this);

                // Assign it to a model bone
                m_boneInfos[neededBonesCount].SetModel(skinnedEntity);

                neededBonesCount++;
            }

            m_boneCount = neededBonesCount;

            Position = 0;

            m_initialized = true;
        }
Exemplo n.º 2
0
            public BoneInfo(AnimationClip.Bone bone, AnimationPlayer player)
            {
                this.ClipBone = bone;
                Player = player;

                SetKeyframes();
                SetPosition(0);

                m_isConst = bone.Keyframes.Count == 1;
            }
Exemplo n.º 3
0
        public void Initialize(AnimationPlayer player)
        {
            m_clip = player.Clip;
            m_skinnedEntity = player.m_skinnedEntity;
            m_weight = player.Weight;
            m_timeScale = player.m_timeScale;
            m_frameOption = player.m_frameOption;

            m_boneCount = player.m_boneCount;
            if (m_boneInfos == null || m_boneInfos.Length < m_boneCount)
                m_boneInfos = new BoneInfo[m_boneCount];


            Position = player.Position;

            for (int b = 0; b < m_boneCount; b++)
            {
                if (m_boneInfos[b] == null)
                    m_boneInfos[b] = new BoneInfo();
                // Create it
                m_boneInfos[b].ClipBone = player.m_boneInfos[b].ClipBone;
                m_boneInfos[b].Player = this;
                    
                // Assign it to a model bone
                m_boneInfos[b].SetModel(m_skinnedEntity);
                m_boneInfos[b].CurrentKeyframe = player.m_boneInfos[b].CurrentKeyframe;
                m_boneInfos[b].SetPosition(Position);

                if (MyFakes.ENABLE_BONES_AND_ANIMATIONS_DEBUG)
                {
                    int index;
                    System.Diagnostics.Debug.Assert(m_skinnedEntity.FindBone(m_boneInfos[b].ClipBone.Name, out index) != null, "Can not find clip bone with name: " + m_boneInfos[b].ClipBone.Name + " in model: " + m_skinnedEntity.Name);
                }
            }


            m_initialized = true;
        }
Exemplo n.º 4
0
 protected void Write(AnimationClip clip)
 {
     m_writer.Write(clip.Name);
     m_writer.Write(clip.Duration);
     m_writer.Write(clip.Bones.Count);
     foreach (AnimationClip.Bone bone in clip.Bones)
     {
         m_writer.Write(bone.Name);
         m_writer.Write(bone.Keyframes.Count);
         foreach (AnimationClip.Keyframe keyframe in bone.Keyframes)
         {
             m_writer.Write(keyframe.Time);
             WriteQuaternion(keyframe.Rotation);
             WriteVector(keyframe.Translation);
         }
     }
 }
Exemplo n.º 5
0
        private static ModelAnimations ReadModelAnimations(BinaryReader reader)
        {
            var modelAnimations = new ModelAnimations { Clips = new List<AnimationClip>() };
            var animationCount = reader.ReadInt32();

            for (var i = 0; i < animationCount; i++)
            {
                var clipName = reader.ReadString();
                var duration = reader.ReadDouble();
                var animationClip = new AnimationClip() { Name = clipName, Duration = duration };

                var boneCount = reader.ReadInt32();
                for (var j = 0; j < boneCount; j++)
                {
                    var boneName = reader.ReadString();
                    var bone = new AnimationClip.Bone() { Name = boneName };
                    var keyFrameCount = reader.ReadInt32();

                    for (var k = 0; k < keyFrameCount; k++)
                    {
                        var time = reader.ReadDouble();
                        var vector = ReadVector4(reader);
                        var rotation = new Quaternion(vector.X, vector.Y, vector.Z, vector.W);
                        var translation = ReadVector3(reader);
                        bone.Keyframes.Add(new AnimationClip.Keyframe() { Time = time, Rotation = rotation, Translation = translation });
                    }

                    animationClip.Bones.Add(bone);
                }

                modelAnimations.Clips.Add(animationClip);
            }

            modelAnimations.Skeleton = ReadArrayOfInt(reader).ToList();
            return modelAnimations;
        }
            public BoneInfo(AnimationClip.Bone bone, AnimationPlayer player)
            {
                this.ClipBone = bone;
                Player = player;

                SetKeyframes();
                SetPosition(0);
            }
        public void Initialize(AnimationClip clip, MyCharacter model, float weight, float timeScale, bool justFirstFrame, string[] explicitBones = null)
        {
            m_clip = clip;
            m_model = model;
            m_weight = weight;
            m_timeScale = timeScale;
            m_justFirstFrame = justFirstFrame;
            
            // Create the bone information classes
            m_boneCount = explicitBones == null ? clip.Bones.Count : explicitBones.Length;
            if (m_boneInfos == null || m_boneInfos.Length < m_boneCount)
                m_boneInfos = new BoneInfo[m_boneCount];

            for (int b = 0; b < m_boneCount; b++)
            {
                // Create it
                m_boneInfos[b] = new BoneInfo(explicitBones == null ? clip.Bones[b] : FindBone(clip.Bones, explicitBones[b]), this);

                // Assign it to a model bone
                m_boneInfos[b].SetModel(model);
            }

            Position = 0;

            m_initialized = true;
        }