Exemple #1
0
        public void AddMaterial(IMtl material)
        {
            if (material == null)
            {
                return;
            }
            if (!FlightSimMaterialUtilities.IsFlightSimMaterial(material))
            {
                return;
            }
            Guid         matGuid = material.GetGuid();
            ListViewItem item    = FillMaterialItem(material, matGuid);

            if (item != null)
            {
                previousMaterialMap.Add(matGuid, item);
            }
        }
Exemple #2
0
        public void RemoveMaterialFromSelection(IMtl material)
        {
            if (material == null)
            {
                return;
            }
            if (!FlightSimMaterialUtilities.IsFlightSimMaterial(material))
            {
                return;
            }
            Guid         matGuid = material.GetGuid();
            ListViewItem itemToRemove;

            if (previousMaterialMap.TryGetValue(matGuid, out itemToRemove))
            {
                itemToRemove.BackColor = Color.Red;
                currentMaterialMap.Remove(matGuid);
            }
        }
Exemple #3
0
        public static IMtl GetAnimatableMaterial(this IINode node)
        {
            IMtl material = node.Mtl;

            if (material == null)
            {
                MessageBox.Show("No Material found for the selected node");
                return(null);
            }
            if (material.IsMultiMtl)
            {
                MessageBox.Show("MultiMaterial animation is not supported, use a non-MultiMaterial material");
                return(null);
            }
            if (!FlightSimMaterialUtilities.IsFlightSimMaterial(material))
            {
                MessageBox.Show("Material animation is supported only for FlightSimMaterial");
                return(null);
            }
            return(material);
        }
Exemple #4
0
        public void AddMaterialFromSelection(IMtl material)
        {
            if (material == null)
            {
                return;
            }
            if (!MaterialUtilities.IsMaterialAssignedInScene(material))
            {
                return;
            }
            if (!FlightSimMaterialUtilities.IsFlightSimMaterial(material))
            {
                return;
            }
            Guid         matGuid = material.GetGuid();
            ListViewItem item    = FillMaterialItem(material, matGuid);

            if (item != null)
            {
                currentMaterialMap.Add(matGuid, item);
                item.BackColor = Color.Green;
            }
        }
Exemple #5
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);
        }
Exemple #6
0
        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);
        }