private void ResolveMwmPaths(MyModContext modContext, MyObjectBuilder_AnimationTreeNode objBuilderNode)
 {
     // ------- tree node track -------
     var objBuilderNodeTrack = objBuilderNode as VRage.Game.ObjectBuilders.MyObjectBuilder_AnimationTreeNodeTrack;
     if (objBuilderNodeTrack != null)
     {
         string testMwmPath = Path.Combine(modContext.ModPath, objBuilderNodeTrack.PathToModel);
         if (MyFileSystem.FileExists(testMwmPath))
         {
             objBuilderNodeTrack.PathToModel = testMwmPath;
         }
     }
     // ------ tree node mix -----------------------
     var objBuilderNodeMix1D = objBuilderNode as MyObjectBuilder_AnimationTreeNodeMix1D;
     if (objBuilderNodeMix1D != null)
     {
         if (objBuilderNodeMix1D.Children != null)
         {
             foreach (var mappingObjBuilder in objBuilderNodeMix1D.Children)
                 if (mappingObjBuilder.Node != null)
                     ResolveMwmPaths(modContext, mappingObjBuilder.Node);
         }
     }
     // ------ tree node add -----------------------
     var objBuilderNodeAdd = objBuilderNode as MyObjectBuilder_AnimationTreeNodeAdd;
     if (objBuilderNodeAdd != null)
     {
         if (objBuilderNodeAdd.BaseNode.Node != null)
             ResolveMwmPaths(modContext, objBuilderNodeAdd.BaseNode.Node);
         if (objBuilderNodeAdd.AddNode.Node != null)
             ResolveMwmPaths(modContext, objBuilderNodeAdd.AddNode.Node);
     }
 }
Ejemplo n.º 2
0
        // Initialize animation tree of the state machine node.
        private static VRage.Animations.MyAnimationTreeNode InitNodeAnimationTree(VRage.Game.ObjectBuilders.MyObjectBuilder_AnimationTreeNode objBuilderNode)
        {
            // ------- tree node track -------
            var objBuilderNodeTrack = objBuilderNode as VRage.Game.ObjectBuilders.MyObjectBuilder_AnimationTreeNodeTrack;

            if (objBuilderNodeTrack != null)
            {
                var     nodeTrack      = new VRage.Animations.AnimationNodes.MyAnimationTreeNodeTrack();
                MyModel modelAnimation = MyModels.GetModelOnlyAnimationData(objBuilderNodeTrack.PathToModel);
                if (modelAnimation != null)
                {
                    VRage.Animations.MyAnimationClip selectedClip = modelAnimation.Animations.Clips.FirstOrDefault(clipItem => clipItem.Name == objBuilderNodeTrack.AnimationName);
                    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;
                }
                return(nodeTrack);
            }
            // ------ tree node mix -----------------------
            var objBuilderNodeMix1D = objBuilderNode as MyObjectBuilder_AnimationTreeNodeMix1D;

            if (objBuilderNodeMix1D != null)
            {
                var nodeMix1D = new VRage.Animations.AnimationNodes.MyAnimationTreeNodeMix1D();
                if (objBuilderNodeMix1D.Children != null)
                {
                    foreach (var mappingObjBuilder in objBuilderNodeMix1D.Children)
                    {
                        MyAnimationTreeNodeMix1D.MyParameterNodeMapping mapping = new MyAnimationTreeNodeMix1D.MyParameterNodeMapping()
                        {
                            ParamValueBinding = mappingObjBuilder.Param,
                            Child             = InitNodeAnimationTree(mappingObjBuilder.Node)
                        };
                        nodeMix1D.ChildMappings.Add(mapping);
                    }
                    nodeMix1D.ChildMappings.Sort((x, y) => x.ParamValueBinding.CompareTo(y.ParamValueBinding));
                }
                nodeMix1D.ParameterName = MyStringId.GetOrCompute(objBuilderNodeMix1D.ParameterName);
                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);
        }
Ejemplo n.º 3
0
        // Initialize animation tree of the state machine node.
        private static MyAnimationTreeNode InitNodeAnimationTree(VRage.Game.ObjectBuilders.MyObjectBuilder_AnimationTreeNode objBuilderNode)
        {
            // ------- 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) : null;

                if (modelAnimation != null && modelAnimation.Animations != null && modelAnimation.Animations.Clips != null && modelAnimation.Animations.Clips.Count > 0)
                {
                    VRage.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;
                }
                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)
                        };
                        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);
        }