public MyAnimationPlayerBlendPair(MySkinnedEntity skinnedEntity, string[] bones, Dictionary<float, string[]> boneLODs, string name)
 {
     m_bones = bones;
     m_skinnedEntity = skinnedEntity;
     m_boneLODs = boneLODs;
     m_name = name;
 }
 public MyAnimationPlayerBlendPair(MySkinnedEntity skinnedEntity, string[] bones, Dictionary <float, string[]> boneLODs, string name)
 {
     m_bones         = bones;
     m_skinnedEntity = skinnedEntity;
     m_boneLODs      = boneLODs;
     m_name          = name;
 }
            /// <summary>
            /// Assign this bone to the correct bone in the model
            /// </summary>
            /// <param name="model"></param>
            public void SetModel(MySkinnedEntity skinnedEntity)
            {
                if (ClipBone == null)
                {
                    return;
                }

                // Find this bone
                int index;

                m_assignedBone = skinnedEntity.AnimationController.FindBone(ClipBone.Name, out index);
            }
Beispiel #4
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;
        }
Beispiel #5
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;
        }
        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;
        }
        public void Initialize(MyModel animationModel, string playerName, int clipIndex, MySkinnedEntity skinnedEntity, float weight, float timeScale, MyFrameOption frameOption, string[] explicitBones = null, Dictionary<float, string[]> boneLODs = null)
        {
            if (m_hash != 0)
            {
                CachedAnimationPlayers.Remove(m_hash);
                m_hash = 0;
            }

            var clip = animationModel.Animations.Clips[clipIndex];
            Name = MyStringId.GetOrCompute(animationModel.AssetName + " : " + playerName);
            m_duration = (float)clip.Duration;
            m_skinnedEntity = skinnedEntity;
            m_weight = weight;
            m_timeScale = timeScale;
            m_frameOption = frameOption;

            foreach (var list in m_boneLODs.Values)
                list.Clear();
            //m_boneLODs.Clear();

            List<BoneInfo> lod0;
            if (!m_boneLODs.TryGetValue(0, out lod0))
            {
                lod0 = new List<BoneInfo>();
                m_boneLODs.Add(0, lod0);
            }

            // 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
                BoneInfo boneInfo = m_boneInfos[neededBonesCount];
                if(m_boneInfos[neededBonesCount] == null)
                    boneInfo = new BoneInfo(bone, this);
                else
                {
                    boneInfo.Clear();
                    boneInfo.Init(bone, this);
                }

                m_boneInfos[neededBonesCount] = boneInfo;

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

                if (boneInfo.ModelBone != null)
                {
                    lod0.Add(boneInfo);

                    if (boneLODs != null)
                    {
                        foreach (var boneLOD in boneLODs)
                        {
                            List<BoneInfo> lodBones;
                            if (!m_boneLODs.TryGetValue(boneLOD.Key, out lodBones))
                            {
                                lodBones = new List<BoneInfo>();
                                m_boneLODs.Add(boneLOD.Key, lodBones);
                            }

                            foreach (var boneName in boneLOD.Value)
                            {
                                if (boneInfo.ModelBone.Name == boneName)
                                {
                                    lodBones.Add(boneInfo);
                                    break;
                                }
                            }
                        }
                    }
                }

                neededBonesCount++;
            }

            m_boneCount = neededBonesCount;

            Position = 0;

            m_initialized = true;
        }
        public void Initialize(AnimationPlayer player)
        {
            if (m_hash != 0)
            {
                CachedAnimationPlayers.Remove(m_hash);
                m_hash = 0;
            }

            Name = player.Name;
            m_duration = player.m_duration;
            m_skinnedEntity = player.m_skinnedEntity;
            m_weight = player.Weight;
            m_timeScale = player.m_timeScale;
            m_frameOption = player.m_frameOption;

            foreach(var list in m_boneLODs.Values)
                list.Clear();
            //m_boneLODs.Clear();

            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++)
            {
                var boneInfo = m_boneInfos[b];
                if (boneInfo == null)
                {
                    boneInfo = new BoneInfo();
                    m_boneInfos[b] = boneInfo;
                }

                // Create it
                boneInfo.ClipBone = player.m_boneInfos[b].ClipBone;
                boneInfo.Player = this;
                    
                // Assign it to a model bone
                boneInfo.SetModel(m_skinnedEntity);
                boneInfo.CurrentKeyframe = player.m_boneInfos[b].CurrentKeyframe;
                boneInfo.SetPosition(Position);


                if (player.m_boneLODs != null && boneInfo.ModelBone != null && ENABLE_ANIMATION_LODS)
                {
                    foreach (var boneLOD in player.m_boneLODs)
                    {
                        List<BoneInfo> lodBones;
                        if (!m_boneLODs.TryGetValue(boneLOD.Key, out lodBones))
                        {
                            lodBones = new List<BoneInfo>();
                            m_boneLODs.Add(boneLOD.Key, lodBones);
                        }

                        foreach (var boneName in boneLOD.Value)
                        {
                            if (boneName.ModelBone == null)
                                continue;

                            if (boneInfo.ModelBone.Name == boneName.ModelBone.Name)
                            {
                                lodBones.Add(boneInfo);
                                break;
                            }
                        }
                    }
                }

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


            m_initialized = true;
        }
        public void Initialize(AnimationPlayer player)
        {
            if (m_hash != 0)
            {
                CachedAnimationPlayers.Remove(m_hash);
                m_hash = 0;
            }

            Name            = player.Name;
            m_duration      = player.m_duration;
            m_skinnedEntity = player.m_skinnedEntity;
            m_weight        = player.Weight;
            m_timeScale     = player.m_timeScale;
            m_frameOption   = player.m_frameOption;

            foreach (var list in m_boneLODs.Values)
            {
                list.Clear();
            }
            //m_boneLODs.Clear();

            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++)
            {
                var boneInfo = m_boneInfos[b];
                if (boneInfo == null)
                {
                    boneInfo       = new BoneInfo();
                    m_boneInfos[b] = boneInfo;
                }

                // Create it
                boneInfo.ClipBone = player.m_boneInfos[b].ClipBone;
                boneInfo.Player   = this;

                // Assign it to a model bone
                boneInfo.SetModel(m_skinnedEntity);
                boneInfo.CurrentKeyframe = player.m_boneInfos[b].CurrentKeyframe;
                boneInfo.SetPosition(Position);


                if (player.m_boneLODs != null && boneInfo.ModelBone != null && ENABLE_ANIMATION_LODS)
                {
                    foreach (var boneLOD in player.m_boneLODs)
                    {
                        List <BoneInfo> lodBones;
                        if (!m_boneLODs.TryGetValue(boneLOD.Key, out lodBones))
                        {
                            lodBones = new List <BoneInfo>();
                            m_boneLODs.Add(boneLOD.Key, lodBones);
                        }

                        foreach (var boneName in boneLOD.Value)
                        {
                            if (boneName.ModelBone == null)
                            {
                                continue;
                            }

                            if (boneInfo.ModelBone.Name == boneName.ModelBone.Name)
                            {
                                lodBones.Add(boneInfo);
                                break;
                            }
                        }
                    }
                }

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


            m_initialized = true;
        }
        void SpawnSimpleSkinnedObject()
        {

            var skin = new MySkinnedEntity();

            MyObjectBuilder_Character ob = new MyObjectBuilder_Character();
            ob.EntityDefinitionId = new SerializableDefinitionId(typeof(MyObjectBuilder_Character), "Medieval_barbarian");
            ob.PositionAndOrientation = new VRage.MyPositionAndOrientation(MySector.MainCamera.Position + 2 * MySector.MainCamera.ForwardVector, MySector.MainCamera.ForwardVector, MySector.MainCamera.UpVector);
            skin.Init(null, @"Models\Characters\Basic\ME_barbar.mwm", null, null);
            skin.Init(ob);

            MyEntities.Add(skin);

            var command = new MyAnimationCommand()
            {
                AnimationSubtypeName = "IdleBarbar",
                FrameOption = MyFrameOption.Loop,
                TimeScale = 1
            };
            skin.AddCommand(command);

            m_skins.Add(skin);
        }
Beispiel #11
0
 public void Initialize(AnimationPlayer player)
 {
     if (this.m_hash != 0)
     {
         CachedAnimationPlayers.Remove(this.m_hash);
         this.m_hash = 0;
     }
     this.Name            = player.Name;
     this.m_duration      = player.m_duration;
     this.m_skinnedEntity = player.m_skinnedEntity;
     this.m_weight        = player.Weight;
     this.m_timeScale     = player.m_timeScale;
     this.m_frameOption   = player.m_frameOption;
     using (Dictionary <float, List <BoneInfo> > .ValueCollection.Enumerator enumerator = this.m_boneLODs.Values.GetEnumerator())
     {
         while (enumerator.MoveNext())
         {
             enumerator.Current.Clear();
         }
     }
     this.m_boneCount = player.m_boneCount;
     if ((this.m_boneInfos == null) || (this.m_boneInfos.Length < this.m_boneCount))
     {
         this.m_boneInfos = new BoneInfo[this.m_boneCount];
     }
     this.Position = player.Position;
     for (int i = 0; i < this.m_boneCount; i++)
     {
         BoneInfo item = this.m_boneInfos[i];
         if (item == null)
         {
             item = new BoneInfo();
             this.m_boneInfos[i] = item;
         }
         item.ClipBone = player.m_boneInfos[i].ClipBone;
         item.Player   = this;
         item.SetModel(this.m_skinnedEntity);
         item.CurrentKeyframe = player.m_boneInfos[i].CurrentKeyframe;
         item.SetPosition(this.Position);
         if (((player.m_boneLODs != null) && (item.ModelBone != null)) && ENABLE_ANIMATION_LODS)
         {
             foreach (KeyValuePair <float, List <BoneInfo> > pair in player.m_boneLODs)
             {
                 List <BoneInfo> list;
                 if (!this.m_boneLODs.TryGetValue(pair.Key, out list))
                 {
                     list = new List <BoneInfo>();
                     this.m_boneLODs.Add(pair.Key, list);
                 }
                 foreach (BoneInfo info2 in pair.Value)
                 {
                     if ((info2.ModelBone != null) && (item.ModelBone.Name == info2.ModelBone.Name))
                     {
                         list.Add(item);
                         break;
                     }
                 }
             }
         }
         bool flag1 = MyFakes.ENABLE_BONES_AND_ANIMATIONS_DEBUG;
     }
     this.m_initialized = true;
 }
Beispiel #12
0
        public void Initialize(MyModel animationModel, string playerName, int clipIndex, MySkinnedEntity skinnedEntity, float weight, float timeScale, MyFrameOption frameOption, string[] explicitBones = null, Dictionary <float, string[]> boneLODs = null)
        {
            List <BoneInfo> list;

            if (this.m_hash != 0)
            {
                CachedAnimationPlayers.Remove(this.m_hash);
                this.m_hash = 0;
            }
            MyAnimationClip clip = animationModel.Animations.Clips[clipIndex];

            this.Name            = MyStringId.GetOrCompute(animationModel.AssetName + " : " + playerName);
            this.m_duration      = (float)clip.Duration;
            this.m_skinnedEntity = skinnedEntity;
            this.m_weight        = weight;
            this.m_timeScale     = timeScale;
            this.m_frameOption   = frameOption;
            using (Dictionary <float, List <BoneInfo> > .ValueCollection.Enumerator enumerator = this.m_boneLODs.Values.GetEnumerator())
            {
                while (enumerator.MoveNext())
                {
                    enumerator.Current.Clear();
                }
            }
            if (!this.m_boneLODs.TryGetValue(0f, out list))
            {
                list = new List <BoneInfo>();
                this.m_boneLODs.Add(0f, list);
            }
            int num = (explicitBones == null) ? clip.Bones.Count : explicitBones.Length;

            if ((this.m_boneInfos == null) || (this.m_boneInfos.Length < num))
            {
                this.m_boneInfos = new BoneInfo[num];
            }
            int index = 0;

            for (int i = 0; i < num; i++)
            {
                MyAnimationClip.Bone bone = (explicitBones == null) ? clip.Bones[i] : this.FindBone(clip.Bones, explicitBones[i]);
                if ((bone != null) && (bone.Keyframes.Count != 0))
                {
                    BoneInfo item = this.m_boneInfos[index];
                    if (this.m_boneInfos[index] == null)
                    {
                        item = new BoneInfo(bone, this);
                    }
                    else
                    {
                        item.Clear();
                        item.Init(bone, this);
                    }
                    this.m_boneInfos[index] = item;
                    this.m_boneInfos[index].SetModel(skinnedEntity);
                    if (item.ModelBone != null)
                    {
                        list.Add(item);
                        if (boneLODs != null)
                        {
                            foreach (KeyValuePair <float, string[]> pair in boneLODs)
                            {
                                List <BoneInfo> list2;
                                if (!this.m_boneLODs.TryGetValue(pair.Key, out list2))
                                {
                                    list2 = new List <BoneInfo>();
                                    this.m_boneLODs.Add(pair.Key, list2);
                                }
                                foreach (string str in pair.Value)
                                {
                                    if (item.ModelBone.Name == str)
                                    {
                                        list2.Add(item);
                                        break;
                                    }
                                }
                            }
                        }
                    }
                    index++;
                }
            }
            this.m_boneCount   = index;
            this.Position      = 0f;
            this.m_initialized = true;
        }
 public MyAnimationPlayerBlendPair(MySkinnedEntity skinnedEntity, string[] bones, string name)
 {
     m_bones = bones;
     m_skinnedEntity = skinnedEntity;
     m_name = name;
 }
 public override void OnAddedToContainer()
 {
     base.OnAddedToContainer();
     m_skinnedEntity = Container.Entity as MySkinnedEntity;
 }
Beispiel #15
0
 public MyAnimationPlayerBlendPair(MySkinnedEntity skinnedEntity, string[] bones, string name)
 {
     m_bones         = bones;
     m_skinnedEntity = skinnedEntity;
     m_name          = name;
 }
        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;
        }
            /// <summary>
            /// Assign this bone to the correct bone in the model
            /// </summary>
            /// <param name="model"></param>
            public void SetModel(MySkinnedEntity skinnedEntity)
            {
                if (ClipBone == null)
                    return;

                // Find this bone
                int index;
                m_assignedBone = skinnedEntity.FindBone(ClipBone.Name, out index);
            }
        public void Initialize(MyModel animationModel, string playerName, int clipIndex, MySkinnedEntity skinnedEntity, float weight, float timeScale, MyFrameOption frameOption, string[] explicitBones = null, Dictionary <float, string[]> boneLODs = null)
        {
            if (m_hash != 0)
            {
                CachedAnimationPlayers.Remove(m_hash);
                m_hash = 0;
            }

            var clip = animationModel.Animations.Clips[clipIndex];

            Name            = MyStringId.GetOrCompute(animationModel.AssetName + " : " + playerName);
            m_duration      = (float)clip.Duration;
            m_skinnedEntity = skinnedEntity;
            m_weight        = weight;
            m_timeScale     = timeScale;
            m_frameOption   = frameOption;

            foreach (var list in m_boneLODs.Values)
            {
                list.Clear();
            }
            //m_boneLODs.Clear();

            List <BoneInfo> lod0;

            if (!m_boneLODs.TryGetValue(0, out lod0))
            {
                lod0 = new List <BoneInfo>();
                m_boneLODs.Add(0, lod0);
            }

            // 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
                BoneInfo boneInfo = m_boneInfos[neededBonesCount];
                if (m_boneInfos[neededBonesCount] == null)
                {
                    boneInfo = new BoneInfo(bone, this);
                }
                else
                {
                    boneInfo.Clear();
                    boneInfo.Init(bone, this);
                }

                m_boneInfos[neededBonesCount] = boneInfo;

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

                if (boneInfo.ModelBone != null)
                {
                    lod0.Add(boneInfo);

                    if (boneLODs != null)
                    {
                        foreach (var boneLOD in boneLODs)
                        {
                            List <BoneInfo> lodBones;
                            if (!m_boneLODs.TryGetValue(boneLOD.Key, out lodBones))
                            {
                                lodBones = new List <BoneInfo>();
                                m_boneLODs.Add(boneLOD.Key, lodBones);
                            }

                            foreach (var boneName in boneLOD.Value)
                            {
                                if (boneInfo.ModelBone.Name == boneName)
                                {
                                    lodBones.Add(boneInfo);
                                    break;
                                }
                            }
                        }
                    }
                }

                neededBonesCount++;
            }

            m_boneCount = neededBonesCount;

            Position = 0;

            m_initialized = true;
        }