コード例 #1
0
        public RigidModel CreateRigidModel(bool drawable)
        {
            var model = new RigidModel();
            var part  = new RigidModelPart();
            var dcs   = new List <MeshDrawcall>();
            var scale = Matrix4x4.CreateScale(Radius);

            if (drawable && SideMaterials.Length >= 6)
            {
                for (int i = 0; i < 6; i++)
                {
                    int     start, count;
                    Vector3 pos;
                    sphere.GetDrawParameters(faces[i], out start, out count, out pos);
                    var dc = new MeshDrawcall();
                    dc.Buffer         = sphere.VertexBuffer;
                    dc.MaterialCrc    = CrcTool.FLModelCrc(sideMaterialNames[i]);
                    dc.BaseVertex     = 0;
                    dc.StartIndex     = start;
                    dc.PrimitiveCount = count;
                    dc.HasScale       = true;
                    dc.Scale          = scale;
                    dcs.Add(dc);
                }

                if (SideMaterials.Length > 6)
                {
                    var crc = CrcTool.FLModelCrc(sideMaterialNames[6]);
                    for (int i = 0; i < 6; i++)
                    {
                        int     start, count;
                        Vector3 pos;
                        sphere.GetDrawParameters(faces[i], out start, out count, out pos);
                        var dc = new MeshDrawcall();
                        dc.Buffer         = sphere.VertexBuffer;
                        dc.MaterialCrc    = crc;
                        dc.BaseVertex     = 0;
                        dc.StartIndex     = start;
                        dc.PrimitiveCount = count;
                        dc.HasScale       = true;
                        dc.Scale          = scale;
                        dcs.Add(dc);
                    }
                }
            }
            var vmesh = new VisualMesh();

            vmesh.Radius      = Radius;
            vmesh.BoundingBox = BoundingBox.CreateFromSphere(new BoundingSphere(Vector3.Zero, Radius));
            vmesh.Levels      = new[] { dcs.ToArray() };
            part.Hardpoints   = new List <Hardpoint>();
            part.Mesh         = vmesh;
            model.Root        = part;
            model.AllParts    = new[] { part };
            return(model);
        }
コード例 #2
0
        public RigidModelPart CreatePart(bool drawable)
        {
            var p = new RigidModelPart  {
                Path = Path
            };

            if (Levels.Length > 0 && Levels[0] != null)
            {
                p.Mesh = new VisualMesh();
                if (drawable)
                {
                    p.Mesh.Levels = new MeshDrawcall[Levels.Length][];
                    for (int i = 0; i < Levels.Length; i++)
                    {
                        if (Levels[i] != null && Levels[i].MeshCrc != 0)
                        {
                            p.Mesh.Levels[i] = Levels[i].GetDrawcalls();
                        }
                    }
                }
                else
                {
                    p.Mesh.Levels = new MeshDrawcall[0][];
                }
                p.Mesh.Radius      = Levels[0].Radius;
                p.Mesh.Center      = Levels[0].Center;
                p.Mesh.BoundingBox = Levels[0].BoundingBox;
                p.Mesh.Switch2     = Switch2;
            }
            p.Hardpoints = new List <Hardpoint>(Hardpoints.Count);
            for (int i = 0; i < Hardpoints.Count; i++)
            {
                p.Hardpoints.Add(new Hardpoint(Hardpoints[i], p));
            }
            p.Wireframe = VMeshWire;
            return(p);
        }
コード例 #3
0
        void DoModel(RigidModelPart part)
        {
            //Hardpoints
            bool open = ImGui.TreeNode(ImGuiExt.Pad("Hardpoints"));
            var  act  = NewHpMenu(part.Path);

            switch (act)
            {
            case ContextActions.NewFixed:
            case ContextActions.NewRevolute:
                newIsFixed = act == ContextActions.NewFixed;
                addTo      = part;
                newHpBuffer.Clear();
                popups.OpenPopup("New Hardpoint");
                break;
            }
            Theme.RenderTreeIcon("Hardpoints", "hardpoint", Color4.CornflowerBlue);
            if (open)
            {
                List <Action> addActions = new List <Action>();
                foreach (var hp in part.Hardpoints)
                {
                    if (doFilter)
                    {
                        if (hp.Name.IndexOf(currentFilter, StringComparison.OrdinalIgnoreCase) == -1)
                        {
                            continue;
                        }
                    }
                    HardpointGizmo gz = null;
                    foreach (var gizmo in gizmos)
                    {
                        if (gizmo.Hardpoint == hp)
                        {
                            gz = gizmo;
                            break;
                        }
                    }
                    if (hp.Definition is RevoluteHardpointDefinition)
                    {
                        Theme.Icon("rev", Color4.LightSeaGreen);
                    }
                    else
                    {
                        Theme.Icon("fix", Color4.Purple);
                    }
                    ImGui.SameLine();
                    if (Theme.IconButton("visible$" + hp.Name, "eye", gz.Enabled ? Color4.White : Color4.Gray))
                    {
                        gz.Enabled = !gz.Enabled;
                    }
                    ImGui.SameLine();
                    ImGui.Selectable(ImGuiExt.IDSafe(hp.Name));
                    var action = EditDeleteHpMenu(part.Path + hp.Name);
                    if (action == ContextActions.Delete)
                    {
                        hpDelete     = hp;
                        hpDeleteFrom = part.Hardpoints;
                        popups.OpenPopup("Confirm Delete");
                    }
                    if (action == ContextActions.Edit)
                    {
                        hpEditing = hp;
                    }
                    if (action == ContextActions.MirrorX)
                    {
                        var newHp = MakeDuplicate(GetDupName(hp.Name), hp);
                        //do mirroring
                        newHp.Definition.Position.X   = -newHp.Definition.Position.X;
                        newHp.Definition.Orientation *= new Matrix4x4(
                            -1, 0, 0, 0,
                            0, 1, 0, 0,
                            0, 0, 1, 0,
                            0, 0, 0, 1
                            );
                        //add
                        addActions.Add(() =>
                        {
                            part.Hardpoints.Add(newHp);
                            gizmos.Add(new HardpointGizmo(newHp, gz.Parent));
                            OnDirtyHp();
                        });
                    }
                    if (action == ContextActions.MirrorY)
                    {
                        var newHp = MakeDuplicate(GetDupName(hp.Name), hp);
                        //do mirroring
                        newHp.Definition.Position.Y   = -newHp.Definition.Position.Y;
                        newHp.Definition.Orientation *= new Matrix4x4(
                            1, 0, 0, 0,
                            0, -1, 0, 0,
                            0, 0, 1, 0,
                            0, 0, 0, 1
                            );
                        //add
                        addActions.Add(() =>
                        {
                            part.Hardpoints.Add(newHp);
                            gizmos.Add(new HardpointGizmo(newHp, gz.Parent));
                            OnDirtyHp();
                        });
                    }
                    if (action == ContextActions.MirrorZ)
                    {
                        var newHp = MakeDuplicate(GetDupName(hp.Name), hp);
                        //do mirroring
                        newHp.Definition.Position.Z   = -newHp.Definition.Position.Z;
                        newHp.Definition.Orientation *= new Matrix4x4(
                            1, 0, 0, 0,
                            0, 1, 0, 0,
                            0, 0, -1, 0,
                            0, 0, 0, 1
                            );
                        //add
                        addActions.Add(() =>
                        {
                            part.Hardpoints.Add(newHp);
                            gizmos.Add(new HardpointGizmo(newHp, gz.Parent));
                            OnDirtyHp();
                        });
                    }
                }
                foreach (var action in addActions)
                {
                    action();
                }
                ImGui.TreePop();
            }
        }
コード例 #4
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();
     }
 }
コード例 #5
0
        void DoConstructNode(RigidModelPart cn)
        {
            var n      = ImGuiExt.IDSafe(string.Format("{0} ({1})", cn.Construct.ChildName, ConType(cn.Construct)));
            var tflags = ImGuiTreeNodeFlags.OpenOnArrow | ImGuiTreeNodeFlags.OpenOnDoubleClick;

            if (selectedNode == cn)
            {
                tflags |= ImGuiTreeNodeFlags.Selected;
            }
            var icon  = "fix";
            var color = Color4.LightYellow;

            if (cn.Construct is PrisConstruct)
            {
                icon  = "pris";
                color = Color4.LightPink;
            }
            if (cn.Construct is SphereConstruct)
            {
                icon  = "sphere";
                color = Color4.LightGreen;
            }
            if (cn.Construct is RevConstruct)
            {
                icon  = "rev";
                color = Color4.LightCoral;
            }
            bool mdlVisible = cn.Active;

            if (!mdlVisible)
            {
                var disabledColor = ImGui.GetStyle().Colors[(int)ImGuiCol.TextDisabled];
                ImGui.PushStyleColor(ImGuiCol.Text, disabledColor);
            }
            if (ImGui.TreeNodeEx(ImGuiExt.Pad(n), tflags))
            {
                if (!mdlVisible)
                {
                    ImGui.PopStyleColor();
                }
                if (ImGui.IsItemClicked(0))
                {
                    selectedNode = cn;
                }
                ConstructContext(cn, mdlVisible);
                Theme.RenderTreeIcon(n, icon, color);
                if (cn.Children != null)
                {
                    foreach (var child in cn.Children)
                    {
                        DoConstructNode(child);
                    }
                }

                DoModel(cn);
                ImGui.TreePop();
            }
            else
            {
                if (!mdlVisible)
                {
                    ImGui.PopStyleColor();
                }
                if (ImGui.IsItemClicked(0))
                {
                    selectedNode = cn;
                }
                ConstructContext(cn, mdlVisible);
                Theme.RenderTreeIcon(n, icon, color);
            }
        }
コード例 #6
0
 public HardpointGizmo(Hardpoint hp, RigidModelPart parent)
 {
     Hardpoint = hp;
     Parent    = parent;
     Enabled   = false;
 }
コード例 #7
0
        void DoModel(RigidModelPart part)
        {
            //Hardpoints
            bool open = Theme.IconTreeNode(Icons.Hardpoints, "Hardpoints");
            var  act  = NewHpMenu(part.Path);

            switch (act)
            {
            case ContextActions.NewFixed:
            case ContextActions.NewRevolute:
                newIsFixed = act == ContextActions.NewFixed;
                addTo      = part;
                newHpBuffer.Clear();
                popups.OpenPopup("New Hardpoint");
                break;
            }
            if (open)
            {
                List <Action> addActions = new List <Action>();
                foreach (var hp in part.Hardpoints)
                {
                    if (doFilter)
                    {
                        if (hp.Name.IndexOf(currentFilter, StringComparison.OrdinalIgnoreCase) == -1)
                        {
                            continue;
                        }
                    }
                    HardpointGizmo gz = null;
                    foreach (var gizmo in gizmos)
                    {
                        if (gizmo.Hardpoint == hp)
                        {
                            gz = gizmo;
                            break;
                        }
                    }

                    if (gz == null)
                    {
                        throw new Exception("gizmo for hp not exist");
                    }
                    if (hp.Definition is RevoluteHardpointDefinition)
                    {
                        ImGui.Text(Icons.Rev_LightSeaGreen.ToString());
                    }
                    else
                    {
                        ImGui.Text(Icons.Cube_Purple.ToString());
                    }
                    ImGui.SameLine();
                    ImGui.PushStyleVar(ImGuiStyleVar.FramePadding, new Vector2(0));
                    ImGui.PushID("visible$" + hp.Name);
                    var push = !gz.Enabled;
                    if (push)
                    {
                        ImGui.PushStyleColor(ImGuiCol.Text, (uint)Color4.Gray.ToAbgr());
                    }
                    if (ImGui.Button(Icons.Eye.ToString()))
                    {
                        gz.Enabled = !gz.Enabled;
                    }
                    if (push)
                    {
                        ImGui.PopStyleColor();
                    }
                    ImGui.PopID();
                    ImGui.PopStyleVar(1);
                    ImGui.SameLine();
                    ImGui.Selectable(ImGuiExt.IDSafe(hp.Name));
                    var action = EditDeleteHpMenu(part.Path + hp.Name);
                    if (action == ContextActions.Delete)
                    {
                        hpDelete     = hp;
                        hpDeleteFrom = part.Hardpoints;
                        popups.OpenPopup("Confirm Delete");
                    }
                    if (action == ContextActions.Edit)
                    {
                        hpEditing = hp;
                    }
                    if (action == ContextActions.MirrorX)
                    {
                        var newHp = MakeDuplicate(GetDupName(hp.Name), hp);
                        //do mirroring
                        newHp.Definition.Position.X   = -newHp.Definition.Position.X;
                        newHp.Definition.Orientation *= new Matrix4x4(
                            -1, 0, 0, 0,
                            0, 1, 0, 0,
                            0, 0, 1, 0,
                            0, 0, 0, 1
                            );
                        //add
                        addActions.Add(() =>
                        {
                            part.Hardpoints.Add(newHp);
                            gizmos.Add(new HardpointGizmo(newHp, gz.Parent));
                            OnDirtyHp();
                        });
                    }
                    if (action == ContextActions.MirrorY)
                    {
                        var newHp = MakeDuplicate(GetDupName(hp.Name), hp);
                        //do mirroring
                        newHp.Definition.Position.Y   = -newHp.Definition.Position.Y;
                        newHp.Definition.Orientation *= new Matrix4x4(
                            1, 0, 0, 0,
                            0, -1, 0, 0,
                            0, 0, 1, 0,
                            0, 0, 0, 1
                            );
                        //add
                        addActions.Add(() =>
                        {
                            part.Hardpoints.Add(newHp);
                            gizmos.Add(new HardpointGizmo(newHp, gz.Parent));
                            OnDirtyHp();
                        });
                    }
                    if (action == ContextActions.MirrorZ)
                    {
                        var newHp = MakeDuplicate(GetDupName(hp.Name), hp);
                        //do mirroring
                        newHp.Definition.Position.Z   = -newHp.Definition.Position.Z;
                        newHp.Definition.Orientation *= new Matrix4x4(
                            1, 0, 0, 0,
                            0, 1, 0, 0,
                            0, 0, -1, 0,
                            0, 0, 0, 1
                            );
                        //add
                        addActions.Add(() =>
                        {
                            part.Hardpoints.Add(newHp);
                            gizmos.Add(new HardpointGizmo(newHp, gz.Parent));
                            OnDirtyHp();
                        });
                    }
                }
                foreach (var action in addActions)
                {
                    action();
                }
                ImGui.TreePop();
            }
        }
コード例 #8
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();
     }
 }