예제 #1
0
        public ModelViewer(string name, IDrawable drawable, MainWindow win, UtfTab parent, ModelNodes hprefs)
        {
            Title         = string.Format("Model Viewer ({0})", name);
            Name          = name;
            this.drawable = drawable;
            this.parent   = parent;
            this.hprefs   = hprefs;
            rstate        = win.RenderState;
            vps           = win.Viewport;
            res           = win.Resources;
            buffer        = win.Commands;
            _window       = win;
            if (drawable is CmpFile)
            {
                //Setup Editor UI for constructs + hardpoints
                vmsModel = (drawable as CmpFile).CreateRigidModel(true);
                animator = new AnimationComponent(vmsModel, (drawable as CmpFile).Animation);
                int maxLevels = 0;
                foreach (var p in vmsModel.AllParts)
                {
                    if (p.Mesh != null && p.Mesh.Levels != null)
                    {
                        maxLevels = Math.Max(maxLevels, p.Mesh.Levels.Length);
                        if (p.Mesh.Switch2 != null)
                        {
                            foreach (var d in p.Mesh.Switch2)
                            {
                                maxDistance = Math.Max(d, maxDistance);
                            }
                        }
                    }
                }
                foreach (var cmpPart in (drawable as CmpFile).Parts)
                {
                    if (cmpPart.Camera != null)
                    {
                        cameraPart = cmpPart;
                        break;
                    }
                }
                levels = new string[maxLevels];
                for (int i = 0; i < maxLevels; i++)
                {
                    levels[i] = i.ToString();
                }
            }
            else if (drawable is ModelFile)
            {
                vmsModel = (drawable as ModelFile).CreateRigidModel(true);
                levels   = new string[vmsModel.AllParts[0].Mesh.Levels.Length];
                for (int i = 0; i < levels.Length; i++)
                {
                    levels[i] = i.ToString();
                }
                if (vmsModel.Root.Mesh.Switch2 != null)
                {
                    foreach (var d in vmsModel.Root.Mesh.Switch2)
                    {
                        maxDistance = Math.Max(d, maxDistance);
                    }
                }
            }
            else if (drawable is SphFile)
            {
                levels   = new string[] { "0" };
                vmsModel = (drawable as SphFile).CreateRigidModel(true);
            }
            if (vmsModel != null)
            {
                foreach (var p in vmsModel.AllParts)
                {
                    foreach (var hp in p.Hardpoints)
                    {
                        gizmos.Add(new HardpointGizmo(hp, p));
                    }
                    if (p.Wireframe != null)
                    {
                        hasVWire = true;
                    }
                }
            }
            SetupViewport();
            maxDistance += 50;

            popups = new PopupManager();
            popups.AddPopup("Confirm Delete", ConfirmDelete, ImGuiWindowFlags.AlwaysAutoResize);
            popups.AddPopup("Warning", MinMaxWarning, ImGuiWindowFlags.AlwaysAutoResize);
            popups.AddPopup("Apply Complete", (x) =>
            {
                ImGui.Text("Hardpoints successfully written");
                if (ImGui.Button("Ok"))
                {
                    ImGui.CloseCurrentPopup();
                }
            }, ImGuiWindowFlags.AlwaysAutoResize);
            popups.AddPopup("Apply Complete##Parts", (x) =>
            {
                ImGui.Text("Parts successfully written");
                if (ImGui.Button("Ok"))
                {
                    ImGui.CloseCurrentPopup();
                }
            }, ImGuiWindowFlags.AlwaysAutoResize);
            popups.AddPopup("New Hardpoint", NewHardpoint, ImGuiWindowFlags.AlwaysAutoResize);
        }
예제 #2
0
        public ModelViewer(string name, IDrawable drawable, MainWindow win, UtfTab parent, ModelNodes hprefs)
        {
            Title         = string.Format("Model Viewer ({0})", name);
            Name          = name;
            this.drawable = drawable;
            this.parent   = parent;
            this.hprefs   = hprefs;
            rstate        = win.RenderState;
            vps           = win.Viewport;
            res           = win.Resources;
            buffer        = win.Commands;
            _window       = win;
            SetupViewport();

            if (drawable is CmpFile)
            {
                //Setup Editor UI for constructs + hardpoints
                var cmp = (CmpFile)drawable;
                foreach (var p in cmp.Parts)
                {
                    if (p.Camera != null)
                    {
                        continue;
                    }
                    if (p.Model.VMeshWire != null)
                    {
                        hasVWire = true;
                    }
                    foreach (var hp in p.Model.Hardpoints)
                    {
                        gizmos.Add(new HardpointGizmo(hp, p.Construct));
                    }
                }
                if (cmp.Animation != null)
                {
                    animator = new AnimationComponent(cmp.Constructs, cmp.Animation);
                }
                foreach (var p in cmp.Parts)
                {
                    if (p.Construct == null)
                    {
                        rootModel = p.Model;
                    }
                }
                var q = new Queue <AbstractConstruct>();
                foreach (var c in cmp.Constructs)
                {
                    if (c.ParentName == "Root" || string.IsNullOrEmpty(c.ParentName))
                    {
                        cons.Add(GetNodeCmp(cmp, c));
                    }
                    else
                    {
                        if (cmp.Constructs.Find(c.ParentName) != null)
                        {
                            q.Enqueue(c);
                        }
                        else
                        {
                            conOrphan.Add(c);
                        }
                    }
                }
                while (q.Count > 0)
                {
                    var c = q.Dequeue();
                    if (!PlaceNode(cons, c))
                    {
                        q.Enqueue(c);
                    }
                }
                int maxLevels = 0;
                foreach (var p in cmp.Parts)
                {
                    if (p.Camera != null)
                    {
                        continue;
                    }
                    maxLevels = Math.Max(maxLevels, p.Model.Levels.Length - 1);
                    if (p.Model.Switch2 != null)
                    {
                        for (int i = 0; i < p.Model.Switch2.Length - 1; i++)
                        {
                            maxDistance = Math.Max(maxDistance, p.Model.Switch2[i]);
                        }
                    }
                }
                levels = new string[maxLevels + 1];
                for (int i = 0; i <= maxLevels; i++)
                {
                    levels[i] = i.ToString();
                }
            }
            else if (drawable is ModelFile)
            {
                var mdl = (ModelFile)drawable;
                if (mdl.VMeshWire != null)
                {
                    hasVWire = true;
                }
                rootModel = mdl;
                foreach (var hp in mdl.Hardpoints)
                {
                    gizmos.Add(new HardpointGizmo(hp, null));
                }

                levels = new string[mdl.Levels.Length];
                for (int i = 0; i < mdl.Levels.Length; i++)
                {
                    levels[i] = i.ToString();
                }
                if (mdl.Switch2 != null)
                {
                    for (int i = 0; i < mdl.Switch2.Length - 1; i++)
                    {
                        maxDistance = Math.Max(maxDistance, mdl.Switch2[i]);
                    }
                }
            }
            maxDistance += 50;

            popups = new PopupManager();
            popups.AddPopup("Confirm Delete", ConfirmDelete, ImGuiWindowFlags.AlwaysAutoResize);
            popups.AddPopup("Warning", MinMaxWarning, ImGuiWindowFlags.AlwaysAutoResize);
            popups.AddPopup("Apply Complete", (x) =>
            {
                ImGui.Text("Hardpoints successfully written");
                if (ImGui.Button("Ok"))
                {
                    ImGui.CloseCurrentPopup();
                }
            }, ImGuiWindowFlags.AlwaysAutoResize);
            popups.AddPopup("Apply Complete##Parts", (x) =>
            {
                ImGui.Text("Parts successfully written");
                if (ImGui.Button("Ok"))
                {
                    ImGui.CloseCurrentPopup();
                }
            }, ImGuiWindowFlags.AlwaysAutoResize);
            popups.AddPopup("New Hardpoint", NewHardpoint, ImGuiWindowFlags.AlwaysAutoResize);
        }