// --------------- methods (public) --------------------------------------------------

        // Pass clip that should be bound to this track. Returns false on failure.
        // Note: Passing null makes this node invalid and may result in invalid animation system result.
        public bool SetClip(MyAnimationClip animationClip)
        {
            m_animationClip = animationClip;
            m_currentKeyframes = animationClip != null ? new int[animationClip.Bones.Count] : null;
            m_boneIndicesMapping = null; // will be initialized later, we do not have sufficient data here
            return true;
        }
        // --------------- methods (public) --------------------------------------------------

        // Pass clip that should be bound to this track. Returns false on failure.
        // Note: Passing null makes this node invalid and may result in invalid animation system result.
        public bool SetClip(MyAnimationClip animationClip)
        {
            m_animationClip      = animationClip;
            m_currentKeyframes   = animationClip != null ? new int[animationClip.Bones.Count] : null;
            m_boneIndicesMapping = null; // will be initialized later, we do not have sufficient data here
            return(true);
        }
 // Constructor of node having single animation.
 // Parameter animationClip must not be null.
 public MyAnimationStateMachineNode(string name, MyAnimationClip animationClip)
     : base(name)
 {
     if (animationClip != null)
     {
         var nodeTrack = new MyAnimationTreeNodeTrack();
         nodeTrack.SetClip(animationClip);
         m_rootAnimationNode = nodeTrack;
     }
     else
     {
         Debug.Fail("Creating single animation node in machine " + this.Name + ", node name "
         + name + ": Animation clip must not be null!");            
     }
 }
 // Constructor of node having single animation.
 // Parameter animationClip must not be null.
 public MyAnimationStateMachineNode(string name, MyAnimationClip animationClip)
     : base(name)
 {
     if (animationClip != null)
     {
         var nodeTrack = new MyAnimationTreeNodeTrack();
         nodeTrack.SetClip(animationClip);
         m_rootAnimationNode = nodeTrack;
     }
     else
     {
         Debug.Fail("Creating single animation node in machine " + this.Name + ", node name "
                    + name + ": Animation clip must not be null!");
     }
 }
            public void Init(MyAnimationClip.Bone bone, AnimationPlayer player)
            {
                this.ClipBone = bone;
                Player = player;

                SetKeyframes();
                SetPosition(0);

                m_isConst = ClipBone.Keyframes.Count == 1;
            }
 public BoneInfo(MyAnimationClip.Bone bone, AnimationPlayer player)
 {
     Init(bone, player);
 }
Example #7
0
 protected void Write(MyAnimationClip clip)
 {
     m_writer.Write(clip.Name);
     m_writer.Write(clip.Duration);
     m_writer.Write(clip.Bones.Count);
     foreach (MyAnimationClip.Bone bone in clip.Bones)
     {
         m_writer.Write(bone.Name);
         m_writer.Write(bone.Keyframes.Count);
         foreach (MyAnimationClip.Keyframe keyframe in bone.Keyframes)
         {
             m_writer.Write(keyframe.Time);
             WriteQuaternion(keyframe.Rotation);
             WriteVector(keyframe.Translation);
         }
     }
 }
Example #8
0
        // Initialize animation tree of the state machine node.
        private static MyAnimationTreeNode InitNodeAnimationTree(VRage.Game.ObjectBuilders.MyObjectBuilder_AnimationTreeNode objBuilderNode, bool forceReloadMwm)
        {
            // ------- tree node track -------
            var objBuilderNodeTrack = objBuilderNode as VRage.Game.ObjectBuilders.MyObjectBuilder_AnimationTreeNodeTrack;

            if (objBuilderNodeTrack != null)
            {
                var     nodeTrack      = new MyAnimationTreeNodeTrack();
                MyModel modelAnimation = objBuilderNodeTrack.PathToModel != null?MyModels.GetModelOnlyAnimationData(objBuilderNodeTrack.PathToModel, forceReloadMwm) : null;

                if (modelAnimation != null && modelAnimation.Animations != null && modelAnimation.Animations.Clips != null && modelAnimation.Animations.Clips.Count > 0)
                {
                    VRageRender.Animations.MyAnimationClip selectedClip = modelAnimation.Animations.Clips.FirstOrDefault(clipItem => clipItem.Name == objBuilderNodeTrack.AnimationName);
                    selectedClip = selectedClip ?? modelAnimation.Animations.Clips[0]; // fallback
                    if (selectedClip == null)
                    {
                        Debug.Fail("File '" + objBuilderNodeTrack.PathToModel + "' does not contain animation clip '"
                                   + objBuilderNodeTrack.AnimationName + "'.");
                    }
                    nodeTrack.SetClip(selectedClip);
                    nodeTrack.Loop                 = objBuilderNodeTrack.Loop;
                    nodeTrack.Speed                = objBuilderNodeTrack.Speed;
                    nodeTrack.Interpolate          = objBuilderNodeTrack.Interpolate;
                    nodeTrack.SynchronizeWithLayer = objBuilderNodeTrack.SynchronizeWithLayer;
                }
                else if (objBuilderNodeTrack.PathToModel != null)
                {
                    MyLog.Default.Log(MyLogSeverity.Error, "Cannot load MWM track {0}.", objBuilderNodeTrack.PathToModel);
                    Debug.Fail("Cannot load MWM track " + objBuilderNodeTrack.PathToModel);
                }
                return(nodeTrack);
            }
            // ------ tree node mix -----------------------
            var objBuilderNodeMix1D = objBuilderNode as MyObjectBuilder_AnimationTreeNodeMix1D;

            if (objBuilderNodeMix1D != null)
            {
                var nodeMix1D = new MyAnimationTreeNodeMix1D();
                if (objBuilderNodeMix1D.Children != null)
                {
                    foreach (var mappingObjBuilder in objBuilderNodeMix1D.Children)
                    {
                        MyAnimationTreeNodeMix1D.MyParameterNodeMapping mapping = new MyAnimationTreeNodeMix1D.MyParameterNodeMapping()
                        {
                            ParamValueBinding = mappingObjBuilder.Param,
                            Child             = InitNodeAnimationTree(mappingObjBuilder.Node, forceReloadMwm)
                        };
                        nodeMix1D.ChildMappings.Add(mapping);
                    }
                    nodeMix1D.ChildMappings.Sort((x, y) => x.ParamValueBinding.CompareTo(y.ParamValueBinding));
                }
                nodeMix1D.ParameterName = MyStringId.GetOrCompute(objBuilderNodeMix1D.ParameterName);
                nodeMix1D.Circular      = objBuilderNodeMix1D.Circular;
                nodeMix1D.Sensitivity   = objBuilderNodeMix1D.Sensitivity;
                nodeMix1D.MaxChange     = objBuilderNodeMix1D.MaxChange ?? float.PositiveInfinity;
                if (nodeMix1D.MaxChange <= 0.0f)
                {
                    nodeMix1D.MaxChange = float.PositiveInfinity;
                }
                return(nodeMix1D);
            }
            // ------ tree node add -----------------------
            var objBuilderNodeAdd = objBuilderNode as MyObjectBuilder_AnimationTreeNodeAdd;

            if (objBuilderNodeAdd != null)
            {
                Debug.Fail("Addition node: currently unsupported type of animation tree node.");
            }
            return(null);
        }
Example #9
0
        private static ModelAnimations ReadModelAnimations(BinaryReader reader)
        {
            var modelAnimations = new ModelAnimations { Clips = new List<MyAnimationClip>() };
            var animationCount = reader.ReadInt32();

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

                var boneCount = reader.ReadInt32();
                for (var j = 0; j < boneCount; j++)
                {
                    var boneName = reader.ReadString();
                    var bone = new MyAnimationClip.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 MyAnimationClip.Keyframe() { Time = time, Rotation = rotation, Translation = translation });
                    }

                    animationClip.Bones.Add(bone);
                }

                modelAnimations.Clips.Add(animationClip);
            }

            modelAnimations.Skeleton = ReadArrayOfInt(reader).ToList();
            return modelAnimations;
        }