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 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 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 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 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) { 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) { 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); }
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); }