Пример #1
0
 public void Add(SphereConstruct con)
 {
     StartAdd(con.ParentName, con.ChildName, con.Origin);
     writer.Write(con.Offset.X);
     writer.Write(con.Offset.Y);
     writer.Write(con.Offset.Z);
     WriteMatrix3x3(con.Rotation);
     writer.Write(con.Min1);
     writer.Write(con.Max1);
     writer.Write(con.Min2);
     writer.Write(con.Max2);
     writer.Write(con.Min3);
     writer.Write(con.Max3);
 }
Пример #2
0
 void ConstructContext(RigidModelPart con, bool mdlVisible)
 {
     if (ImGui.IsItemClicked(1))
     {
         ImGui.OpenPopup(con.Construct.ChildName + "_context");
     }
     if (ImGui.BeginPopupContextItem(con.Construct.ChildName + "_context"))
     {
         if (con.Mesh != null)
         {
             //Visibility of model (this is bad)
             bool visibleVar = mdlVisible;
             Theme.IconMenuToggle("Visible", "eye", Color4.White, ref visibleVar, true);
             if (visibleVar != mdlVisible)
             {
                 con.Active = visibleVar;
             }
         }
         if (Theme.BeginIconMenu("Change To", "change", Color4.White))
         {
             var cmp = (CmpFile)drawable;
             if (!(con.Construct is FixConstruct) && Theme.IconMenuItem("Fix", "fix", Color4.LightYellow, true))
             {
                 var fix = new FixConstruct(cmp.Constructs)
                 {
                     ParentName = con.Construct.ParentName,
                     ChildName  = con.Construct.ChildName,
                     Origin     = con.Construct.Origin,
                     Rotation   = con.Construct.Rotation
                 };
                 fix.Reset();
                 con.Construct = fix;
                 OnDirtyPart();
             }
             if (!(con.Construct is RevConstruct) && Theme.IconMenuItem("Rev", "rev", Color4.LightCoral, true))
             {
                 var rev = new RevConstruct()
                 {
                     ParentName = con.Construct.ParentName,
                     ChildName  = con.Construct.ChildName,
                     Origin     = con.Construct.Origin,
                     Rotation   = con.Construct.Rotation
                 };
                 con.Construct = rev;
                 OnDirtyPart();
             }
             if (!(con.Construct is PrisConstruct) && Theme.IconMenuItem("Pris", "pris", Color4.LightPink, true))
             {
                 var pris = new PrisConstruct()
                 {
                     ParentName = con.Construct.ParentName,
                     ChildName  = con.Construct.ChildName,
                     Origin     = con.Construct.Origin,
                     Rotation   = con.Construct.Rotation
                 };
                 con.Construct = pris;
                 OnDirtyPart();
             }
             if (!(con.Construct is SphereConstruct) && Theme.IconMenuItem("Sphere", "sphere", Color4.LightGreen, true))
             {
                 var sphere = new SphereConstruct()
                 {
                     ParentName = con.Construct.ParentName,
                     ChildName  = con.Construct.ChildName,
                     Origin     = con.Construct.Origin,
                     Rotation   = con.Construct.Rotation
                 };
                 con.Construct = sphere;
                 OnDirtyPart();
             }
             ImGui.EndMenu();
         }
         if (Theme.IconMenuItem("Edit", "edit", Color4.White, true))
         {
             AddPartEditor(con.Construct);
         }
         ImGui.EndPopup();
     }
 }
Пример #3
0
        void ConstructContext(ConstructNode con, bool mdlVisible)
        {
            if (ImGui.IsItemClicked(1))
            {
                ImGui.OpenPopup(con.Con.ChildName + "_context");
            }
            if (ImGui.BeginPopupContextItem(con.Con.ChildName + "_context"))
            {
                if (con.Model != null)
                {
                    //Visibility of model (this is bad)
                    bool visibleVar = mdlVisible;
                    Theme.IconMenuToggle("Visible", "eye", Color4.White, ref visibleVar, true);
                    if (visibleVar != mdlVisible)
                    {
                        if (visibleVar)
                        {
                            hiddenModels.Remove(con.Model);
                        }
                        else
                        {
                            hiddenModels.Add(con.Model);
                        }
                    }
                }

                if (Theme.BeginIconMenu("Change To", "change", Color4.White))
                {
                    var cmp = (CmpFile)drawable;
                    if (!(con.Con is FixConstruct) && Theme.IconMenuItem("Fix", "fix", Color4.LightYellow, true))
                    {
                        var fix = new FixConstruct(cmp.Constructs)
                        {
                            ParentName = con.Con.ParentName,
                            ChildName  = con.Con.ChildName,
                            Origin     = con.Con.Origin,
                            Rotation   = con.Con.Rotation
                        };
                        fix.Reset();
                        ReplaceConstruct(con, fix);
                        OnDirtyPart();
                    }
                    if (!(con.Con is RevConstruct) && Theme.IconMenuItem("Rev", "rev", Color4.LightCoral, true))
                    {
                        var rev = new RevConstruct(cmp.Constructs)
                        {
                            ParentName = con.Con.ParentName,
                            ChildName  = con.Con.ChildName,
                            Origin     = con.Con.Origin,
                            Rotation   = con.Con.Rotation
                        };
                        ReplaceConstruct(con, rev);
                        OnDirtyPart();
                    }
                    if (!(con.Con is PrisConstruct) && Theme.IconMenuItem("Pris", "pris", Color4.LightPink, true))
                    {
                        var pris = new PrisConstruct(cmp.Constructs)
                        {
                            ParentName = con.Con.ParentName,
                            ChildName  = con.Con.ChildName,
                            Origin     = con.Con.Origin,
                            Rotation   = con.Con.Rotation
                        };
                        ReplaceConstruct(con, pris);
                        OnDirtyPart();
                    }
                    if (!(con.Con is SphereConstruct) && Theme.IconMenuItem("Sphere", "sphere", Color4.LightGreen, true))
                    {
                        var sphere = new SphereConstruct(cmp.Constructs)
                        {
                            ParentName = con.Con.ParentName,
                            ChildName  = con.Con.ChildName,
                            Origin     = con.Con.Origin,
                            Rotation   = con.Con.Rotation
                        };
                        ReplaceConstruct(con, sphere);
                        OnDirtyPart();
                    }
                    ImGui.EndMenu();
                }
                if (Theme.IconMenuItem("Edit", "edit", Color4.White, true))
                {
                    AddPartEditor(con.Con);
                }
                ImGui.EndPopup();
            }
        }
Пример #4
0
        public static Model3D LoadModel(string file)
        {
            UtfManager utfManager = new UtfManager(file);
            UtfNode    root       = utfManager.Read();

            if (root == null || root.Nodes.Count == 0)
            {
                return(null);
            }

            // select root (\) node
            root = root.Nodes[0];

            Dictionary <uint, VMeshData> meshes             = null;
            List <MeshReferenceMatch>    meshReferenceNodes = new List <MeshReferenceMatch>();
            List <CmpPart> constructs = new List <CmpPart>();
            Dictionary <string, string> mapFileToObj = new Dictionary <string, string>
            {
                { "\\", "Model" }
            };

            foreach (UtfNode node in root.Nodes)
            {
                switch (node.Name.ToLowerInvariant())
                {
                case "vmeshlibrary":
                    meshes = new Dictionary <uint, VMeshData>(node.Nodes.Count);
                    foreach (UtfNode vmsNode in node.Nodes)
                    {
                        if (vmsNode.Nodes.Count > 0)
                        {
                            meshes.Add(CrcTool.FlModelCrc(vmsNode.Name), new VMeshData(vmsNode.Nodes[0].Data));
                        }
                    }

                    break;

                case "cmpnd":
                    foreach (UtfNode cmpndNode in node.Nodes)
                    {
                        if (cmpndNode.Name.Equals("cons", StringComparison.OrdinalIgnoreCase))
                        {
                            foreach (UtfNode constructNode in cmpndNode.Nodes)
                            {
                                switch (constructNode.Name.ToLowerInvariant())
                                {
                                case "fix":
                                    FixConstruct.Parse(constructs, constructNode.Data);
                                    break;

                                case "rev":
                                    RevConstruct.Parse(constructs, constructNode.Data);
                                    break;

                                case "pris":
                                    PrisConstruct.Parse(constructs, constructNode.Data);
                                    break;

                                case "sphere":
                                    SphereConstruct.Parse(constructs, constructNode.Data);
                                    break;
                                }
                            }
                        }
                        else if (cmpndNode.Name.StartsWith("part_", StringComparison.OrdinalIgnoreCase) ||
                                 cmpndNode.Name.Equals("root", StringComparison.OrdinalIgnoreCase))
                        {
                            string objectName = null;
                            string fileName   = null;

                            // int index = -1;
                            foreach (UtfNode partNode in cmpndNode.Nodes)
                            {
                                switch (partNode.Name.ToLowerInvariant())
                                {
                                case "object name":
                                    objectName = Encoding.ASCII.GetString(partNode.Data).TrimEnd('\0');
                                    break;

                                case "file name":
                                    fileName = Encoding.ASCII.GetString(partNode.Data).TrimEnd('\0');
                                    break;

                                    // case "index":
                                    // index = BitConverter.ToInt32(partNode.Data, 0);
                                    // break;
                                }
                            }

                            if (objectName != null && fileName != null)
                            {
                                mapFileToObj[fileName] = objectName;
                            }
                        }
                    }

                    break;

                case "multilevel":
                    // multi LoD 3db model (\MultiLevel\Level0\VMeshPart\VMeshRef => \)
                    VMeshRef meshReference2 = ParseMultiLevelNode(node);
                    if (meshReference2 != null)
                    {
                        meshReferenceNodes.Add(new MeshReferenceMatch {
                            FileName = "\\", MeshReference = meshReference2
                        });
                    }

                    break;

                case "vmeshpart":
                    // single LoD 3db model (\VMeshPart\VMeshRef => \)
                    VMeshRef meshReference3 = ParseMeshPartNode(node);
                    if (meshReference3 != null)
                    {
                        meshReferenceNodes.Add(new MeshReferenceMatch {
                            FileName = "\\", MeshReference = meshReference3
                        });
                    }

                    break;

                default:
                    if (node.Name.EndsWith(".3db", StringComparison.OrdinalIgnoreCase))
                    {
                        foreach (UtfNode subNode in node.Nodes)
                        {
                            if (subNode.Name.Equals("multilevel", StringComparison.OrdinalIgnoreCase))
                            {
                                // multi LoD cmp model (\PARTNAME.3db\MultiLevel\Level0\VMeshPart\VMeshRef => PARTNAME.3db)
                                VMeshRef meshReference = ParseMultiLevelNode(subNode);
                                if (meshReference != null)
                                {
                                    meshReferenceNodes.Add(new MeshReferenceMatch {
                                        FileName = node.Name, MeshReference = meshReference
                                    });
                                }

                                break;
                            }

                            if (subNode.Name.Equals("vmeshpart", StringComparison.OrdinalIgnoreCase))
                            {
                                // single LoD cmp model (\PARTNAME.3db\VMeshPart\VMeshRef => PARTNAME.3db)
                                VMeshRef meshReference = ParseMeshPartNode(subNode);
                                if (meshReference != null)
                                {
                                    meshReferenceNodes.Add(new MeshReferenceMatch {
                                        FileName = node.Name, MeshReference = meshReference
                                    });
                                }

                                break;
                            }
                        }
                    }

                    break;
                }
            }

            if (meshes == null || meshReferenceNodes.Count == 0)
            {
                return(null);
            }

            List <MeshGroup> meshGroups = new List <MeshGroup>();

            foreach (MeshReferenceMatch meshReferenceNode in meshReferenceNodes)
            {
                string meshGroupName;
                if (mapFileToObj.TryGetValue(meshReferenceNode.FileName, out meshGroupName))
                {
                    VMeshData mesh;
                    if (meshes.TryGetValue(meshReferenceNode.MeshReference.VMeshLibId, out mesh))
                    {
                        meshGroups.Add(new MeshGroup
                        {
                            MeshReference = meshReferenceNode.MeshReference,
                            Mesh          = mesh,
                            Transform     = GetTransform(constructs, meshGroupName)
                        });
                    }
                }
            }

            return(GetCmpModelGroup(meshGroups));
        }
Пример #5
0
 void ConstructContext(RigidModelPart con, bool mdlVisible)
 {
     if (ImGui.IsItemClicked(ImGuiMouseButton.Right))
     {
         ImGui.OpenPopup(con.Construct.ChildName + "_context");
     }
     if (ImGui.BeginPopupContextItem(con.Construct.ChildName + "_context"))
     {
         if (con.Mesh != null)
         {
             //Visibility of model (this is bad)
             bool visibleVar = mdlVisible;
             Theme.IconMenuToggle(Icons.Eye, "Visible", ref visibleVar, true);
             if (visibleVar != mdlVisible)
             {
                 con.Active = visibleVar;
             }
         }
         if (Theme.BeginIconMenu(Icons.Exchange, "Change To"))
         {
             var cmp = (CmpFile)drawable;
             if (!(con.Construct is FixConstruct) && Theme.IconMenuItem(Icons.Cube_LightYellow, "Fix", true))
             {
                 var fix = new FixConstruct(cmp.Constructs)
                 {
                     ParentName = con.Construct.ParentName,
                     ChildName  = con.Construct.ChildName,
                     Origin     = con.Construct.Origin,
                     Rotation   = con.Construct.Rotation
                 };
                 fix.Reset();
                 con.Construct = fix;
                 OnDirtyPart();
             }
             if (!(con.Construct is RevConstruct) && Theme.IconMenuItem(Icons.Rev_LightCoral, "Rev", true))
             {
                 var rev = new RevConstruct()
                 {
                     ParentName = con.Construct.ParentName,
                     ChildName  = con.Construct.ChildName,
                     Origin     = con.Construct.Origin,
                     Rotation   = con.Construct.Rotation
                 };
                 con.Construct = rev;
                 OnDirtyPart();
             }
             if (!(con.Construct is PrisConstruct) && Theme.IconMenuItem(Icons.Con_Pris, "Pris", true))
             {
                 var pris = new PrisConstruct()
                 {
                     ParentName = con.Construct.ParentName,
                     ChildName  = con.Construct.ChildName,
                     Origin     = con.Construct.Origin,
                     Rotation   = con.Construct.Rotation
                 };
                 con.Construct = pris;
                 OnDirtyPart();
             }
             if (!(con.Construct is SphereConstruct) && Theme.IconMenuItem(Icons.Con_Sph, "Sphere", true))
             {
                 var sphere = new SphereConstruct()
                 {
                     ParentName = con.Construct.ParentName,
                     ChildName  = con.Construct.ChildName,
                     Origin     = con.Construct.Origin,
                     Rotation   = con.Construct.Rotation
                 };
                 con.Construct = sphere;
                 OnDirtyPart();
             }
             ImGui.EndMenu();
         }
         if (Theme.IconMenuItem(Icons.Edit, "Edit", true))
         {
             AddPartEditor(con.Construct);
         }
         ImGui.EndPopup();
     }
 }
Пример #6
0
 void ConstructContext(ConstructNode con)
 {
     if (ImGui.IsItemClicked(1))
     {
         ImGui.OpenPopup(con.Con.ChildName + "_context");
     }
     if (ImGui.BeginPopupContextItem(con.Con.ChildName + "_context"))
     {
         if (Theme.BeginIconMenu("Change To", "change", Color4.White))
         {
             var cmp = (CmpFile)drawable;
             if (!(con.Con is FixConstruct) && Theme.IconMenuItem("Fix", "fix", Color4.LightYellow, true))
             {
                 var fix = new FixConstruct(cmp.Constructs)
                 {
                     ParentName = con.Con.ParentName,
                     ChildName  = con.Con.ChildName,
                     Origin     = con.Con.Origin,
                     Rotation   = con.Con.Rotation
                 };
                 fix.Reset();
                 ReplaceConstruct(con, fix);
             }
             if (!(con.Con is RevConstruct) && Theme.IconMenuItem("Rev", "rev", Color4.LightCoral, true))
             {
                 var rev = new RevConstruct(cmp.Constructs)
                 {
                     ParentName = con.Con.ParentName,
                     ChildName  = con.Con.ChildName,
                     Origin     = con.Con.Origin,
                     Rotation   = con.Con.Rotation
                 };
                 ReplaceConstruct(con, rev);
             }
             if (!(con.Con is PrisConstruct) && Theme.IconMenuItem("Pris", "pris", Color4.LightPink, true))
             {
                 var pris = new PrisConstruct(cmp.Constructs)
                 {
                     ParentName = con.Con.ParentName,
                     ChildName  = con.Con.ChildName,
                     Origin     = con.Con.Origin,
                     Rotation   = con.Con.Rotation
                 };
                 ReplaceConstruct(con, pris);
             }
             if (!(con.Con is SphereConstruct) && Theme.IconMenuItem("Sphere", "sphere", Color4.LightGreen, true))
             {
                 var sphere = new SphereConstruct(cmp.Constructs)
                 {
                     ParentName = con.Con.ParentName,
                     ChildName  = con.Con.ChildName,
                     Origin     = con.Con.Origin,
                     Rotation   = con.Con.Rotation
                 };
                 ReplaceConstruct(con, sphere);
             }
             ImGui.EndMenu();
         }
         if (Theme.IconMenuItem("Edit", "edit", Color4.White, true))
         {
             AddPartEditor(con.Con);
         }
         ImGui.EndPopup();
     }
 }