public static bool ExportItemHasClosedContainers(IINode itemRootNode) { if (itemRootNode == null) { itemRootNode = Loader.Core.RootNode; } List <IINode> nodesList = new List <IINode>(); nodesList.Add(itemRootNode); nodesList.AddRange(itemRootNode.NodeTree().ToList()); foreach (var node in nodesList) { IIContainerObject containerNode = Loader.Global.ContainerManagerInterface.IsContainerNode(node); if (containerNode != null && !containerNode.IsOpen) { MessageBox.Show("You are tring to export a CLOSED Container\nUse the Container Manager"); return(true); } } return(false); }
public static IINode BabylonContainerHelper(this IIContainerObject containerObject) { IINode babylonHelper = null; foreach (IINode directChild in containerObject.ContainerNode.DirectChildren()) { if (directChild.IsBabylonContainerHelper()) { babylonHelper = directChild; } } if (babylonHelper == null) { IDummyObject dummy = Loader.Global.DummyObject.Create(); babylonHelper = Loader.Core.CreateObjectNode(dummy, $"BabylonContainerHelper_{Random.Next(0, 99999)}"); babylonHelper.SetUserPropBool("babylonjs_ContainerHelper", true); Loader.Core.SetQuietMode(true); containerObject.ContainerNode.AttachChild(babylonHelper, false); Loader.Core.SetQuietMode(false); containerObject.AddNodeToContent(babylonHelper); } return(babylonHelper); }
private void OnNodeAdded(IntPtr param0, IntPtr param1) { try { INotifyInfo obj = Loader.Global.NotifyInfo.Marshal(param1); IINode n = (IINode)obj.CallParam; //todo replace this with something like isXREFNODE //to have a distinction between added xref node and max node string guid = n.GetStringProperty("babylonjs_GUID", string.Empty); if (string.IsNullOrEmpty(guid)) { n.GetGuid(); // force to assigne a new guid if not exist yet for this node } IIContainerObject contaner = Loader.Global.ContainerManagerInterface.IsContainerNode(n); if (contaner != null) { // a generic operation on a container is done (open/inherit) contaner.ResolveContainer(); } } catch { // Fails silently } }
public static List <IIContainerObject> GetContainerInSelection() { #if MAX2020 || MAX2021 || MAX2022 IINodeTab selection = Loader.Global.INodeTab.Create(); #else IINodeTab selection = Loader.Global.INodeTabNS.Create(); #endif Loader.Core.GetSelNodeTab(selection); List <IIContainerObject> selectedContainers = new List <IIContainerObject>(); for (int i = 0; i < selection.Count; i++) { #if MAX2015 || MAX2016 var selectedNode = selection[(IntPtr)i]; #else var selectedNode = selection[i]; #endif IIContainerObject containerObject = Loader.Global.ContainerManagerInterface.IsContainerNode(selectedNode); if (containerObject != null) { selectedContainers.Add(containerObject); } } return(selectedContainers); }
public static void SaveDataToContainerHelper(IIContainerObject iContainerObject) { if (!iContainerObject.IsOpen) { MessageBox.Show("Animations of " + iContainerObject.ContainerNode.Name + " cannot be saved because Container is closed"); return; } AnimationGroupList animationGroupList = new AnimationGroupList(); animationGroupList.LoadFromData(Loader.Core.RootNode); RemoveDataOnContainer(iContainerObject); //cleanup for a new serialization List <string> animationPropertyNameList = new List <string>(); foreach (AnimationGroup animationGroup in animationGroupList) { IIContainerObject containerObject = animationGroup.NodeGuids.InSameContainer(); if (containerObject != null && containerObject.ContainerNode.Handle == iContainerObject.ContainerNode.Handle) { string prop = Loader.Core.RootNode.GetStringProperty(animationGroup.GetPropertyName(), ""); containerObject.BabylonContainerHelper().SetStringProperty(animationGroup.GetPropertyName(), prop); animationPropertyNameList.Add(animationGroup.GetPropertyName()); } } if (animationPropertyNameList.Count > 0) { iContainerObject.BabylonContainerHelper().SetStringArrayProperty(s_AnimationListPropertyName, animationPropertyNameList); } }
public static void LoadDataFromContainerHelper(IIContainerObject iContainerObject) { if (!iContainerObject.IsOpen) { MessageBox.Show("Animations of " + iContainerObject.ContainerNode.Name + " cannot be loaded because Container is closed"); return; } ResolveMultipleInheritedContainer(iContainerObject); //on container added in scene try retrieve info from containers string[] sceneAnimationPropertyNames = Loader.Core.RootNode.GetStringArrayProperty(s_AnimationListPropertyName); string[] containerAnimationPropertyNames = iContainerObject.BabylonContainerHelper().GetStringArrayProperty(s_AnimationListPropertyName); string[] mergedAnimationPropertyNames = sceneAnimationPropertyNames.Concat(containerAnimationPropertyNames).Distinct().ToArray(); Loader.Core.RootNode.SetStringArrayProperty(s_AnimationListPropertyName, mergedAnimationPropertyNames); foreach (string propertyNameStr in containerAnimationPropertyNames) { //copy string prop = iContainerObject.BabylonContainerHelper().GetStringProperty(propertyNameStr, ""); Loader.Core.RootNode.SetStringProperty(propertyNameStr, prop); } }
public static void ResolveContainer(this IIContainerObject container) { guids = new Dictionary <Guid, IAnimatable>(); int id = container.GetNextAvailableContainerID(); container.ContainerNode.SetUserPropInt("babylonjs_ContainerID", id); }
public static void RemoveDataOnContainer(IIContainerObject containerObject) { //remove all property related to animation group string[] animationPropertyNames = containerObject.BabylonContainerHelper().GetStringArrayProperty(s_AnimationListPropertyName); foreach (string propertyNameStr in animationPropertyNames) { containerObject.BabylonContainerHelper().DeleteProperty(propertyNameStr); } containerObject.BabylonContainerHelper().DeleteProperty(s_AnimationListPropertyName); }
public static IIContainerObject GetContainer(this IList <uint> handles) { foreach (uint handle in handles) { IINode node = Loader.Core.GetINodeByHandle(handle); IIContainerObject containerObject = Loader.Global.ContainerManagerInterface.IsInContainer(node); if (containerObject != null) { return(containerObject); } } return(null); }
public static IIContainerObject GetContainer(this IList <Guid> guids) { foreach (Guid guid in guids) { IINode node = GetINodeByGuid(guid); IIContainerObject containerObject = Loader.Global.ContainerManagerInterface.IsInContainer(node); if (containerObject != null) { return(containerObject); } } return(null); }
public static List <IIContainerObject> GetAllContainers() { List <IIContainerObject> containersList = new List <IIContainerObject>(); foreach (IINode node in Loader.Core.RootNode.NodeTree()) { IIContainerObject containerObject = Loader.Global.ContainerManagerInterface.IsContainerNode(node); if (containerObject != null) { containersList.Add(containerObject); } } return(containersList); }
public static List <IILayer> GetContainerLayers(this IIContainerObject container) { List <IILayer> result = new List <IILayer>(); List <IINode> containerNodes = container.ContainerNode.ContainerNodeTree(true); foreach (IINode node in containerNodes) { IILayer nodeLayer = node.GetNodeLayer(); if (nodeLayer != null) { result.Add(node.GetNodeLayer()); } } return(result); }
public static IINode BabylonContainerHelper(this IIContainerObject containerObject) { IINode babylonHelper = containerObject.ContainerNode.FindChildNode("BabylonAnimationHelper"); if (babylonHelper == null) { IDummyObject dummy = Loader.Global.DummyObject.Create(); babylonHelper = Loader.Core.CreateObjectNode(dummy, "BabylonAnimationHelper"); Loader.Core.SetQuietMode(true); containerObject.ContainerNode.AttachChild(babylonHelper, false); Loader.Core.SetQuietMode(false); containerObject.AddNodeToContent(babylonHelper); } return(babylonHelper); }
public override bool ExecuteAction() { if (Loader.Core.SelNodeCount == 0) { MessageBox.Show("No Container selected"); return(false); } #if MAX2020 IINodeTab selection = Loader.Global.INodeTab.Create(); #else IINodeTab selection = Loader.Global.INodeTabNS.Create(); #endif Loader.Core.GetSelNodeTab(selection); List <IIContainerObject> selectedContainers = new List <IIContainerObject>(); for (int i = 0; i < selection.Count; i++) { #if MAX2015 var selectedNode = selection[(IntPtr)i]; #else var selectedNode = selection[i]; #endif IIContainerObject containerObject = Loader.Global.ContainerManagerInterface.IsContainerNode(selectedNode); if (containerObject != null) { selectedContainers.Add(containerObject); } } if (selectedContainers.Count <= 0) { MessageBox.Show("No Container selected"); return(false); } foreach (IIContainerObject containerObject in selectedContainers) { AnimationGroupList.SaveDataToContainer(containerObject); } return(true); }
public static IINode BabylonContainerHelper(this IIContainerObject containerObject) { IINode babylonHelper = containerObject.ContainerNode.FindChildNode("BabylonAnimationHelper"); if (babylonHelper == null) { MessageBox.Show($"Container {containerObject.ContainerNode.Name} has no Babylon Animation Helper, " + $"a default one has been created, this process should be done on the container source"); IDummyObject dummy = Loader.Global.DummyObject.Create(); babylonHelper = Loader.Core.CreateObjectNode(dummy, "BabylonAnimationHelper"); Loader.Core.SetQuietMode(true); containerObject.ContainerNode.AttachChild(babylonHelper, false); Loader.Core.SetQuietMode(false); containerObject.AddNodeToContent(babylonHelper); } return(babylonHelper); }
public static void SaveDataToContainers() { //on scene close automatically move serialization to affected containers // look on each animation group if all node are in same container // copy property to container List <IIContainerObject> containers = Tools.GetAllContainers(); if (containers.Count <= 0) { return; } AnimationGroupList animationGroupList = new AnimationGroupList(); animationGroupList.LoadFromData(); foreach (IIContainerObject iContainerObject in containers) { if (!iContainerObject.IsOpen) { MessageBox.Show("Animations of " + iContainerObject.ContainerNode.Name + " cannot be saved because Container is closed"); continue; } RemoveDataOnContainer(iContainerObject); //cleanup for a new serialization List <string> animationPropertyNameList = new List <string>(); foreach (AnimationGroup animationGroup in animationGroupList) { IIContainerObject containerObject = animationGroup.NodeGuids.InSameContainer(); if (containerObject != null && containerObject.ContainerNode.Handle == iContainerObject.ContainerNode.Handle) { string prop = Loader.Core.RootNode.GetStringProperty(animationGroup.GetPropertyName(), ""); containerObject.BabylonContainerHelper().SetStringProperty(animationGroup.GetPropertyName(), prop); animationPropertyNameList.Add(animationGroup.GetPropertyName()); } } if (animationPropertyNameList.Count > 0) { iContainerObject.BabylonContainerHelper().SetStringArrayProperty(s_AnimationListPropertyName, animationPropertyNameList); } } }
private static IIContainerObject GetConflictingContainer(this IIContainerObject container) { string guidStr = container.ContainerNode.GetStringProperty("babylonjs_GUID", Guid.NewGuid().ToString()); List <IIContainerObject> containers = GetAllContainers(); foreach (IIContainerObject iContainerObject in containers) { if (container.ContainerNode.Handle == iContainerObject.ContainerNode.Handle) { continue; } string compareGuid = iContainerObject.ContainerNode.GetStringProperty("babylonjs_GUID", Guid.NewGuid().ToString()); if (compareGuid == guidStr && iContainerObject.ContainerNode.Name == container.ContainerNode.Name) { return(iContainerObject); } } return(null); }
private void OnNodeAdded(IntPtr objPtr, INotifyInfo infoPtr) { try { IINode n = (IINode)infoPtr.CallParam; n.GetGuid(); // force to assigne a new guid if not exist yet for this node IIContainerObject contaner = Loader.Global.ContainerManagerInterface.IsContainerNode(n); if (contaner != null) { // a generic operation on a container is done (open/inherit) contaner.ResolveContainer(); } } catch { // Fails silently } }
private void OnNodeAdded(IntPtr param0, IntPtr param1) { try { INotifyInfo obj = Loader.Global.NotifyInfo.Marshal(param1); IINode n = (IINode)obj.CallParam; n.GetGuid(); // force to assigne a new guid if not exist yet for this node IIContainerObject contaner = Loader.Global.ContainerManagerInterface.IsContainerNode(n); if (contaner != null) { // a generic operation on a container is done (open/inherit) Tools.guids = new Dictionary <Guid, IAnimatable>(); } } catch { // Fails silently } }
public static void ResolveContainer(this IIContainerObject container) { int id = 2; while (container.GetConflictingContainer() != null) //container with same guid && same name exist) { bool hasID = Regex.IsMatch(container.ContainerNode.Name, @"_ID_\d+"); if (hasID) { int index = container.ContainerNode.Name.LastIndexOf("_"); string containerName = container.ContainerNode.Name.Remove(index + 1); containerName = containerName + id; container.ContainerNode.Name = containerName; } else { container.ContainerNode.Name = container.ContainerNode.Name + "_ID_" + id; } container.ContainerNode.SetUserPropInt("babylonjs_ContainerID", id); id++; } }
public static IIContainerObject InSameContainer(this IList <Guid> guids) { List <IIContainerObject> containers = new List <IIContainerObject>(); foreach (Guid guid in guids) { IINode node = GetINodeByGuid(guid); IIContainerObject containerObject = Loader.Global.ContainerManagerInterface.IsInContainer(node); if (containerObject != null) { if (!containers.Contains(containerObject)) { containers.Add(containerObject); } } } if (containers.Count == 1) { return(containers[0]); } return(null); }
public static List <IINode> ContainerNodeTree(this IINode containerNode, bool includeSubContainer) { List <IINode> containersChildren = new List <IINode>(); foreach (IINode x in containerNode.Nodes()) { IIContainerObject nestedContainerObject = Loader.Global.ContainerManagerInterface.IsContainerNode(x); if (nestedContainerObject != null) { if (includeSubContainer) { containersChildren.AddRange(ContainerNodeTree(nestedContainerObject.ContainerNode, includeSubContainer)); } } else { containersChildren.Add(x); containersChildren.AddRange(ContainerNodeTree(x, includeSubContainer)); } } return(containersChildren); }
private static int GetNextAvailableContainerID(this IIContainerObject container) { int id = 1; string guidStr = container.ContainerNode.GetStringProperty("babylonjs_GUID", Guid.NewGuid().ToString()); List <IIContainerObject> containers = GetAllContainers(); foreach (IIContainerObject othersContainer in containers) { if (container.ContainerNode.Handle == othersContainer.ContainerNode.Handle) { continue; } //string compareGuid = iContainerObject.ContainerNode.GetStringProperty("babylonjs_GUID",Guid.NewGuid().ToString()); string otherName = Regex.Replace(othersContainer.ContainerNode.Name, @"_\d+", ""); string originalName = Regex.Replace(container.ContainerNode.Name, @"_\d+", ""); if (otherName == originalName) { int containerID = 1; othersContainer.ContainerNode.GetUserPropInt("babylonjs_ContainerID", ref containerID); id = Math.Max(id, containerID + 1); } } return(id); }
private static void ResolveMultipleInheritedContainer(IIContainerObject container) { string helperPropBuffer = string.Empty; container.BabylonContainerHelper().GetUserPropBuffer(ref helperPropBuffer); List <IINode> containerHierarchy = new List <IINode>() { container.ContainerNode }; containerHierarchy.AddRange(container.ContainerNode.ContainerNodeTree(false)); int containerID = 1; container.ContainerNode.GetUserPropInt("babylonjs_ContainerID", ref containerID); //the first istance of the multiples containers, the one without _ID_* //mContainer ->referenceBrotherContainer //mContainer_ID_2 int idIndex = container.ContainerNode.Name.IndexOf("_ID_"); if (idIndex < 0) { return; } string refBrotherName = container.ContainerNode.Name.Substring(0, idIndex); IINode refBrotherContainerObject = Loader.Core.GetINodeByName(refBrotherName); //if there is no brother, there is nothing to resolve if (refBrotherContainerObject == null) { 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()); if (containerID > 1 && !n.Name.EndsWith("_ID_" + containerID)) { string originalName = n.Name; n.Name = $"{n.Name}_ID_{containerID}"; IINode source = refBrotherContainerObject.FindChildNode(originalName); IMtl mat = source.Mtl; if (mat != null) { n.Mtl = mat; } } } //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); if (containerID > 1) { 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) && !name.EndsWith("_ID_" + containerID)) { propertiesString = propertiesString.Replace(name, name + "_ID_" + containerID); container.BabylonContainerHelper().SetUserPropString(guidStr, propertiesString); } } } } }
private static void ResolveMultipleInheritedContainer(IIContainerObject container) { string helperPropBuffer = string.Empty; container.BabylonContainerHelper().GetUserPropBuffer(ref helperPropBuffer); List <IINode> containerHierarchy = new List <IINode>() { container.ContainerNode }; containerHierarchy.AddRange(container.ContainerNode.ContainerNodeTree(false)); int containerID = 1; container.ContainerNode.GetUserPropInt("babylonjs_ContainerID", ref containerID); //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()); if (containerID > 1 && !n.Name.EndsWith("_ID_" + containerID)) { n.Name = $"{n.Name}_ID_{containerID}"; } } //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); if (containerID > 1) { 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) && !name.EndsWith("_ID_" + containerID)) { propertiesString = propertiesString.Replace(name, name + "_ID_" + containerID); container.BabylonContainerHelper().SetUserPropString(guidStr, propertiesString); } } } } }
private static void ResolveMultipleInheritedContainer(IIContainerObject container) { //resolve container name int b = 0; if (container.ContainerNode.GetUserPropBool("flightsim_resolved", ref b) && b != 0) { return; } List <IINode> containerHierarchy = new List <IINode>() { }; containerHierarchy.AddRange(container.ContainerNode.ContainerNodeTree(false)); string helperPropBuffer = string.Empty; container.BabylonContainerHelper().GetUserPropBuffer(ref helperPropBuffer); int containerID = 1; container.ContainerNode.GetUserPropInt("babylonjs_ContainerID", ref containerID); container.ContainerNode.Name = containerID == -1 ? $"{container.ContainerNode.Name}" : $"{container.ContainerNode.Name}_{containerID}"; // resolve nodes , adding an id at the end { //manage multiple containers inherited 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 = containerID == -1 ? $"{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"; ScriptsUtilities.ExecuteMaxScriptCommand(cmd); } } } } //replace animationList guid to have distinct list of AnimationGroup for each container string animationListStr = string.Empty; IINode containerHelper = container.BabylonContainerHelper(); containerHelper.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()); } containerHelper.SetUserPropBuffer(helperPropBuffer); //add ID of container to animationGroup name to identify animation in viewer containerHelper.GetUserPropString(s_AnimationListPropertyName, ref animationListStr); string[] newAnimationGroupGuid = animationListStr.Split(AnimationGroup.s_PropertySeparator); foreach (string guidStr in newAnimationGroupGuid) { string propertiesString = string.Empty; if (!containerHelper.GetUserPropString(guidStr, ref propertiesString)) { return; } try // new serialization method { SerializableAnimationGroup serialAnimGroup = new SerializableAnimationGroup(propertiesString); serialAnimGroup.name = containerID == -1 ? serialAnimGroup.name : serialAnimGroup.name + $"_{containerID}"; string serializedInfo = JsonConvert.SerializeObject(serialAnimGroup); container.BabylonContainerHelper().SetUserPropString(guidStr, serializedInfo); } catch (Exception) { string[] properties = propertiesString.Split(AnimationGroup.s_PropertySeparator); if (properties.Length < 4) { throw new Exception($"Invalid number of properties, can't de-serialize property of {containerHelper.Name} of {container.ContainerNode.Name}."); } 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); }
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); }