Пример #1
0
 public static void Execute(string mxs)
 {
     try
     {
         MaxscriptSDK.ExecuteMaxscriptCommand(mxs);
     }
     catch
     {
         OnError("Couldn't Execute: " + mxs);
     }
 }
Пример #2
0
        public static string Command(string command, params object[] args)
        {
            string formatCommand = MaxscriptSDK.AssembleScript(command, args);

            if (Execute)
            {
                MaxscriptSDK.ExecuteMaxscriptCommand(formatCommand);
            }
            if (OutputCommands)
            {
                output.Add(formatCommand);
            }
            return(formatCommand);
        }
Пример #3
0
        private static void ResolveMultipleInheritedContainer(IIContainerObject container)
        {
            int b = 0;

            if (container.ContainerNode.GetUserPropBool("flightsim_resolved", ref b))
            {
                return;
            }

            string helperPropBuffer = string.Empty;

            container.BabylonContainerHelper().GetUserPropBuffer(ref helperPropBuffer);

            List <IINode> containerHierarchy = new List <IINode>()
            {
            };

            containerHierarchy.AddRange(container.ContainerNode.ContainerNodeTree(false));

            int containerID = 1;

            container.ContainerNode.GetUserPropInt("babylonjs_ContainerID", ref containerID);

            int    idIndex              = container.ContainerNode.Name.LastIndexOf("_");
            string firstContainer       = container.ContainerNode.Name.Substring(0, idIndex);
            IINode firstContainerObject = Loader.Core.GetINodeByName(firstContainer + "_1");

            if (firstContainerObject == null)
            {
                MessageBox.Show("ERROR resolve ID with FlightSim/BabylonUtilities/UpdateContainerID");
                return;
            }


            //manage multiple containers inherithed from the same source
            foreach (IINode n in containerHierarchy)
            {
                if (n.IsBabylonContainerHelper())
                {
                    continue;
                }
                //change the guid of the node
                //replace the guid in the babylon helper
                string oldGuid = n.GetStringProperty("babylonjs_GUID", Guid.NewGuid().ToString());
                n.DeleteProperty("babylonjs_GUID");
                Guid newGuid = n.GetGuid();
                helperPropBuffer = helperPropBuffer.Replace(oldGuid, newGuid.ToString());

                n.Name = $"{n.Name}_{containerID}";
                if (n.Mtl != null && FlightSimMaterialUtilities.HasFlightSimMaterials(n.Mtl) && FlightSimMaterialUtilities.HasRuntimeAccess(n.Mtl))
                {
                    if (n.Mtl.IsMultiMtl)
                    {
                        throw new Exception($@"Material {n.Mtl.Name} has a property ""Unique In Container"" enabled, cannot be child of a multi material");
                    }
                    else
                    {
                        string cmd = $"mNode = maxOps.getNodeByHandle {n.Handle} \r\n" +
                                     $"newMat = copy mNode.material \r\n" +
                                     $"newMat.name = \"{n.Mtl.Name}_{containerID}\" \r\n" +
                                     $"mNode.material = newMat";

                        MaxscriptSDK.ExecuteMaxscriptCommand(cmd);
                    }
                }
            }

            //replace animationList guid to have distinct list of AnimationGroup for each container
            string animationListStr = string.Empty;

            container.BabylonContainerHelper().GetUserPropString(s_AnimationListPropertyName, ref animationListStr);
            if (!string.IsNullOrEmpty(animationListStr))
            {
                string[] animationGroupGuid = animationListStr.Split(AnimationGroup.s_PropertySeparator);
                foreach (string guidStr in animationGroupGuid)
                {
                    Guid newAnimGroupGuid = Guid.NewGuid();
                    helperPropBuffer = helperPropBuffer.Replace(guidStr, newAnimGroupGuid.ToString());
                }

                container.BabylonContainerHelper().SetUserPropBuffer(helperPropBuffer);

                //add ID of container to animationGroup name to identify animation in viewer
                container.BabylonContainerHelper().GetUserPropString(s_AnimationListPropertyName, ref animationListStr);
                string[] newAnimationGroupGuid = animationListStr.Split(AnimationGroup.s_PropertySeparator);

                foreach (string guidStr in newAnimationGroupGuid)
                {
                    string propertiesString = string.Empty;
                    if (!container.BabylonContainerHelper().GetUserPropString(guidStr, ref propertiesString))
                    {
                        return;
                    }

                    string[] properties = propertiesString.Split(AnimationGroup.s_PropertySeparator);
                    if (properties.Length < 4)
                    {
                        throw new Exception("Invalid number of properties, can't deserialize.");
                    }

                    string name = properties[0];
                    if (!string.IsNullOrEmpty(name))
                    {
                        propertiesString = propertiesString.Replace(name, name + "_" + containerID);
                        container.BabylonContainerHelper().SetUserPropString(guidStr, propertiesString);
                    }
                }
            }
            container.ContainerNode.SetUserPropBool("flightsim_resolved", true);
        }
Пример #4
0
        public override void RunPythonCommand(string command)
        {
            var pythonCommand = $"python.Execute \"{command}\"";

            MaxscriptSDK.ExecuteMaxscriptCommand(pythonCommand);
        }