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); }
public override void Draw() { //Child Window var size = ImGui.GetWindowSize(); ImGui.BeginChild("##utfchild", new Vector2(size.X - 15, size.Y - 50), false, 0); //Layout if (selectedNode != null) { ImGui.Columns(2, "NodeColumns", true); } //Headers ImGui.Separator(); ImGui.Text("Nodes"); if (selectedNode != null) { ImGui.NextColumn(); ImGui.Text("Node Information"); ImGui.NextColumn(); } ImGui.Separator(); //Tree ImGui.BeginChild("##scroll"); var flags = selectedNode == Utf.Root ? ImGuiTreeNodeFlags.Selected | tflags : tflags; var isOpen = ImGui.TreeNodeEx("/", flags); if (ImGui.IsItemClicked(0)) { selectedNode = Utf.Root; } ImGui.PushID("/##ROOT"); DoNodeMenu("/##ROOT", Utf.Root, null); ImGui.PopID(); if (isOpen) { for (int i = 0; i < Utf.Root.Children.Count; i++) { DoNode(Utf.Root.Children[i], Utf.Root, i); } ImGui.TreePop(); } ImGui.EndChild(); //End Tree if (selectedNode != null) { //Node preview ImGui.NextColumn(); NodeInformation(); } //Action Bar ImGui.EndChild(); ImGui.Separator(); if (ImGui.Button("Actions")) { ImGui.OpenPopup("actions"); } if (ImGui.BeginPopup("actions")) { if (ImGui.MenuItem("View Model")) { IDrawable drawable = null; ModelNodes hpn = new ModelNodes(); try { drawable = LibreLancer.Utf.UtfLoader.GetDrawable(Utf.Export(), main.Resources); drawable.Initialize(main.Resources); if (Utf.Root.Children.Any((x) => x.Name.Equals("cmpnd", StringComparison.OrdinalIgnoreCase))) { foreach (var child in Utf.Root.Children.Where((x) => x.Name.EndsWith(".3db", StringComparison.OrdinalIgnoreCase))) { var n = new ModelHpNode(); n.Name = child.Name; n.Node = child; n.HardpointsNode = child.Children.FirstOrDefault((x) => x.Name.Equals("hardpoints", StringComparison.OrdinalIgnoreCase)); hpn.Nodes.Add(n); } var cmpnd = Utf.Root.Children.First((x) => x.Name.Equals("cmpnd", StringComparison.OrdinalIgnoreCase)); hpn.Cons = cmpnd.Children.FirstOrDefault((x) => x.Name.Equals("cons", StringComparison.OrdinalIgnoreCase)); } else { var n = new ModelHpNode(); n.Name = "ROOT"; n.Node = Utf.Root; n.HardpointsNode = Utf.Root.Children.FirstOrDefault((x) => x.Name.Equals("hardpoints", StringComparison.OrdinalIgnoreCase)); hpn.Nodes.Add(n); } } catch (Exception ex) { ErrorPopup("Could not open as model\n" + ex.Message + "\n" + ex.StackTrace); drawable = null; } if (drawable != null) { main.AddTab(new ModelViewer(DocumentName, drawable, main, this, hpn)); } } if (ImGui.MenuItem("Export Collada")) { LibreLancer.Utf.Cmp.ModelFile model = null; LibreLancer.Utf.Cmp.CmpFile cmp = null; try { var drawable = LibreLancer.Utf.UtfLoader.GetDrawable(Utf.Export(), main.Resources); model = (drawable as LibreLancer.Utf.Cmp.ModelFile); cmp = (drawable as LibreLancer.Utf.Cmp.CmpFile); } catch (Exception) { ErrorPopup("Could not open as model"); model = null; } if (model != null) { var output = FileDialog.Save(); if (output != null) { model.Path = DocumentName; try { ColladaExport.ExportCollada(model, main.Resources, output); } catch (Exception ex) { ErrorPopup("Error\n" + ex.Message + "\n" + ex.StackTrace); } } } if (cmp != null) { var output = FileDialog.Save(); if (output != null) { cmp.Path = DocumentName; try { ColladaExport.ExportCollada(cmp, main.Resources, output); } catch (Exception ex) { ErrorPopup("Error\n" + ex.Message + "\n" + ex.StackTrace); } } } } if (ImGui.MenuItem("View Ale")) { AleFile ale = null; try { ale = new AleFile(Utf.Export()); } catch (Exception) { ErrorPopup("Could not open as ale"); ale = null; } if (ale != null) { main.AddTab(new AleViewer(Title, ale, main)); } } if (ImGui.MenuItem("Resolve Audio Hashes")) { var folder = FileDialog.ChooseFolder(); if (folder != null) { var idtable = new IDTable(folder); foreach (var n in Utf.Root.IterateAll()) { if (n.Name.StartsWith("0x")) { uint v; if (uint.TryParse(n.Name.Substring(2), NumberStyles.HexNumber, CultureInfo.InvariantCulture, out v)) { idtable.UtfNicknameTable.TryGetValue(v, out n.ResolvedName); } } else { n.ResolvedName = null; } } } } ImGui.EndPopup(); } ImGui.SameLine(); if (ImGui.Button("Reload Resources")) { main.Resources.RemoveResourcesForId(Unique.ToString()); main.Resources.AddResources(Utf.Export(), Unique.ToString()); } Popups(); }
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); }