diff --git a/.vs/Switch_Toolbox/v15/.suo b/.vs/Switch_Toolbox/v15/.suo index 7ccf6636..1bed43bb 100644 Binary files a/.vs/Switch_Toolbox/v15/.suo and b/.vs/Switch_Toolbox/v15/.suo differ diff --git a/.vs/Switch_Toolbox/v15/Server/sqlite3/storage.ide b/.vs/Switch_Toolbox/v15/Server/sqlite3/storage.ide index 7119b295..13fe4fc6 100644 Binary files a/.vs/Switch_Toolbox/v15/Server/sqlite3/storage.ide and b/.vs/Switch_Toolbox/v15/Server/sqlite3/storage.ide differ diff --git a/.vs/Switch_Toolbox/v15/Server/sqlite3/storage.ide-shm b/.vs/Switch_Toolbox/v15/Server/sqlite3/storage.ide-shm index 13d48246..60a0dca5 100644 Binary files a/.vs/Switch_Toolbox/v15/Server/sqlite3/storage.ide-shm and b/.vs/Switch_Toolbox/v15/Server/sqlite3/storage.ide-shm differ diff --git a/.vs/Switch_Toolbox/v15/Server/sqlite3/storage.ide-wal b/.vs/Switch_Toolbox/v15/Server/sqlite3/storage.ide-wal index 1bf16d62..a364c149 100644 Binary files a/.vs/Switch_Toolbox/v15/Server/sqlite3/storage.ide-wal and b/.vs/Switch_Toolbox/v15/Server/sqlite3/storage.ide-wal differ diff --git a/Switch_FileFormatsMain/FileFormats/BCRES/BCRES.cs b/Switch_FileFormatsMain/FileFormats/BCRES/BCRES.cs index 466b12f3..52484c3f 100644 --- a/Switch_FileFormatsMain/FileFormats/BCRES/BCRES.cs +++ b/Switch_FileFormatsMain/FileFormats/BCRES/BCRES.cs @@ -43,6 +43,7 @@ namespace FirstPlugin public BcresFile BcresFile; public BCRES_Render RenderedBcres; + public DrawableContainer DrawableContainer = new DrawableContainer(); public void Load(System.IO.Stream stream) { @@ -50,6 +51,9 @@ namespace FirstPlugin BcresFile = new BcresFile(stream); RenderedBcres = new BCRES_Render(); + DrawableContainer.Name = FileName; + DrawableContainer.Drawables.Add(RenderedBcres); + AddNodeGroup(BcresFile.Data.Models, new BCRESGroupNode(BCRESGroupType.Models)); AddNodeGroup(BcresFile.Data.Textures, new BCRESGroupNode(BCRESGroupType.Textures)); AddNodeGroup(BcresFile.Data.Lookups, new BCRESGroupNode(BCRESGroupType.Lookups)); @@ -96,8 +100,7 @@ namespace FirstPlugin } } - List drawables = new List(); - + private bool DrawablesLoaded; public void LoadEditors(TreeNode Wrapper, Action OnPropertyChanged) { BcresEditor bcresEditor = (BcresEditor)LibraryGUI.Instance.GetActiveContent(typeof(BcresEditor)); @@ -109,20 +112,21 @@ namespace FirstPlugin LibraryGUI.Instance.LoadEditor(bcresEditor); } - if (drawables.Count <= 0) + if (!DrawablesLoaded) { - //Add drawables - drawables.Add(RenderedBcres); + ObjectEditor.AddContainer(DrawableContainer); for (int m = 0; m < RenderedBcres.Models.Count; m++) { if (RenderedBcres.Models[m].Skeleton.Renderable != null) - drawables.Add(RenderedBcres.Models[m].Skeleton.Renderable); + DrawableContainer.Drawables.Add(RenderedBcres.Models[m].Skeleton.Renderable); } + + DrawablesLoaded = true; } if (Runtime.UseOpenGL) - bcresEditor.LoadViewport(drawables); + bcresEditor.LoadViewport(this, DrawableContainer); if (Wrapper is BcresTextureMapWrapper) { @@ -166,7 +170,7 @@ namespace FirstPlugin public void Unload() { - + ObjectEditor.RemoveContainer(DrawableContainer); } public byte[] Save() { diff --git a/Switch_FileFormatsMain/FileFormats/BCRES/Wrappers/CMDL/CRESSkeletonWrapper.cs b/Switch_FileFormatsMain/FileFormats/BCRES/Wrappers/CMDL/CRESSkeletonWrapper.cs index 3eea3395..fc291350 100644 --- a/Switch_FileFormatsMain/FileFormats/BCRES/Wrappers/CMDL/CRESSkeletonWrapper.cs +++ b/Switch_FileFormatsMain/FileFormats/BCRES/Wrappers/CMDL/CRESSkeletonWrapper.cs @@ -10,7 +10,7 @@ using BcresLibrary; namespace FirstPlugin { - public class CRESSkeletonWrapper : STBone + public class CRESSkeletonWrapper : TreeNodeCustom { internal BCRES BcresParent; internal Skeleton Skeleton; diff --git a/Switch_FileFormatsMain/FileFormats/BFRES/BFRES.cs b/Switch_FileFormatsMain/FileFormats/BFRES/BFRES.cs index e63de0d7..f5bfff4e 100644 --- a/Switch_FileFormatsMain/FileFormats/BFRES/BFRES.cs +++ b/Switch_FileFormatsMain/FileFormats/BFRES/BFRES.cs @@ -49,10 +49,11 @@ namespace FirstPlugin } } - private Thread Thread; - public override string ExportFilter => Utils.GetAllFilters(new BFRES()); + //Stores the skeleton and models in this + public DrawableContainer DrawableContainer = new DrawableContainer(); + class MenuExt : IFileMenuExtension { public STToolStripItem[] NewFileMenuExtensions => newFileExt; @@ -176,29 +177,6 @@ namespace FirstPlugin editor.Refresh(); } - //Used for adding new skeleton drawables - public void AddSkeletonDrawable(STSkeleton skeleton) - { - BfresEditor bfresEditor = (BfresEditor)LibraryGUI.Instance.GetActiveContent(typeof(BfresEditor)); - if (bfresEditor != null) - { - bfresEditor.AddDrawable(skeleton); - } - - drawables.Add(skeleton); - } - - public void RemoveSkeletonDrawable(STSkeleton skeleton) - { - BfresEditor bfresEditor = (BfresEditor)LibraryGUI.Instance.GetActiveContent(typeof(BfresEditor)); - if (bfresEditor != null) - { - bfresEditor.RemoveDrawable(skeleton); - } - - drawables.Remove(skeleton); - } - public void LoadAdvancedMode() { foreach (var model in BFRESRender.models) @@ -300,7 +278,7 @@ namespace FirstPlugin return ""; } - List drawables = new List(); + private bool DrawablesLoaded = false; public void LoadEditors(object SelectedSection) { BfresEditor bfresEditor = (BfresEditor)LibraryGUI.Instance.GetActiveContent(typeof(BfresEditor)); @@ -405,18 +383,14 @@ namespace FirstPlugin return; } - if (drawables.Count <= 0) + if (!DrawablesLoaded) { - //Add drawables - drawables.Add(BFRESRender); - - for (int m = 0; m < BFRESRender.models.Count; m++) - drawables.Add(BFRESRender.models[m].Skeleton); + ObjectEditor.AddContainer(DrawableContainer); + DrawablesLoaded = true; } if (Runtime.UseOpenGL) - bfresEditor.LoadViewport(drawables, new List()); - + bfresEditor.LoadViewport(this, DrawableContainer); bool IsSimpleEditor = PluginRuntime.UseSimpleBfresEditor; @@ -707,10 +681,14 @@ namespace FirstPlugin reader.Position = 0; } + LoadMenus(IsWiiU); BFRESRender = new BFRESRender(); + DrawableContainer.Drawables.Add(BFRESRender); + DrawableContainer.Name = FileName; + BFRESRender.ModelTransform = MarioCostumeEditor.SetTransform(FileName); BFRESRender.ResFileNode = this; @@ -723,11 +701,20 @@ namespace FirstPlugin { LoadFile(new Syroot.NintenTools.NSW.Bfres.ResFile(stream)); } + + var Models = GetModels(); + if (Models != null) + { + foreach (FMDL mdl in Models) + DrawableContainer.Drawables.Add(mdl.Skeleton); + } } public void Unload() { BFRESRender.Destroy(); + ObjectEditor.RemoveContainer(DrawableContainer); + foreach (var node in TreeViewExtensions.Collect(BFRESRender.ResFileNode.Nodes)) { if (node is BFRESGroupNode) diff --git a/Switch_FileFormatsMain/FileFormats/BFRES/BFRESGroupNode.cs b/Switch_FileFormatsMain/FileFormats/BFRES/BFRESGroupNode.cs index f7f5c50d..b07c2814 100644 --- a/Switch_FileFormatsMain/FileFormats/BFRES/BFRESGroupNode.cs +++ b/Switch_FileFormatsMain/FileFormats/BFRES/BFRESGroupNode.cs @@ -192,7 +192,7 @@ namespace Bfres.Structs fmdl.ModelU.Materials.Add("NewMaterial", new ResU.Material() { Name = "NewMaterial", RenderState = new ResU.RenderState(), }); BfresWiiU.ReadModel(fmdl, fmdl.ModelU); - ((BFRES)Parent).AddSkeletonDrawable(fmdl.Skeleton); + ((BFRES)Parent).DrawableContainer.Drawables.Add(fmdl.Skeleton); } else { @@ -218,7 +218,7 @@ namespace Bfres.Structs fmdl.Model.VertexBuffers.Add(VertexBuffer); BfresSwitch.ReadModel(fmdl, fmdl.Model); - ((BFRES)Parent).AddSkeletonDrawable(fmdl.Skeleton); + ((BFRES)Parent).DrawableContainer.Drawables.Add(fmdl.Skeleton); } if (AddTreeNode) diff --git a/Switch_FileFormatsMain/FileFormats/BFRES/Bfres Structs/SubFiles/FMDL.cs b/Switch_FileFormatsMain/FileFormats/BFRES/Bfres Structs/SubFiles/FMDL.cs index ebcad199..5d3befb0 100644 --- a/Switch_FileFormatsMain/FileFormats/BFRES/Bfres Structs/SubFiles/FMDL.cs +++ b/Switch_FileFormatsMain/FileFormats/BFRES/Bfres Structs/SubFiles/FMDL.cs @@ -108,7 +108,7 @@ namespace Bfres.Structs if (dialogResult == DialogResult.Yes) { - ((BFRES)Parent.Parent).RemoveSkeletonDrawable(Skeleton); + ((BFRES)Parent.Parent).DrawableContainer.Drawables.Remove(Skeleton); shapes.Clear(); materials.Clear(); @@ -469,7 +469,7 @@ namespace Bfres.Structs public override void Unload() { if (Parent != null) - ((BFRES)Parent.Parent).RemoveSkeletonDrawable(Skeleton); + ((BFRES)Parent.Parent).DrawableContainer.Drawables.Remove(Skeleton); shapes.Clear(); materials.Clear(); diff --git a/Switch_FileFormatsMain/FileFormats/Collision/KCL.cs b/Switch_FileFormatsMain/FileFormats/Collision/KCL.cs index 0049df27..4b87886b 100644 --- a/Switch_FileFormatsMain/FileFormats/Collision/KCL.cs +++ b/Switch_FileFormatsMain/FileFormats/Collision/KCL.cs @@ -75,11 +75,19 @@ namespace FirstPlugin } } + public DrawableContainer DrawableContainer = new DrawableContainer(); + public void Load(System.IO.Stream stream) { Text = FileName; Renderer = new KCLRendering(); + DrawableContainer = new DrawableContainer() + { + Name = FileName, + Drawables = new List() { Renderer }, + }; + stream.Position = 0; data = stream.ToArray(); Read(data); @@ -123,6 +131,13 @@ namespace FirstPlugin kcl.IFileInfo = new IFileInfo(); kcl.FileName = name; kcl.Renderer = new KCLRendering(); + + kcl.DrawableContainer = new DrawableContainer() + { + Name = kcl.FileName, + Drawables = new List() { kcl.Renderer }, + }; + kcl.Read(f.Write(ByteOrder)); ObjectEditor editor = new ObjectEditor(kcl); @@ -133,7 +148,7 @@ namespace FirstPlugin public void Unload() { - + ObjectEditor.RemoveContainer(DrawableContainer); } public byte[] Save() { @@ -294,27 +309,27 @@ namespace FirstPlugin } public KCLRendering Renderer; - bool IsLoaded = false; + bool DrawablesLoaded = false; public override void OnClick(TreeView treeView) { if (Runtime.UseOpenGL) { if (viewport == null) { - viewport = new Viewport(); + viewport = new Viewport(ObjectEditor.GetDrawableContainers()); viewport.Dock = DockStyle.Fill; } + + if (!DrawablesLoaded) + { + ObjectEditor.AddContainer(DrawableContainer); + DrawablesLoaded = true; + } + + viewport.ReloadDrawables(DrawableContainer); LibraryGUI.Instance.LoadEditor(viewport); viewport.Text = Text; - - if (!IsLoaded) - { - viewport.AddDrawable(Renderer); - viewport.LoadObjects(); - } - - IsLoaded = true; } } diff --git a/Switch_FileFormatsMain/GUI/BCRES/BfresEditor.Designer.cs b/Switch_FileFormatsMain/GUI/BCRES/BcresEditor.Designer.cs similarity index 100% rename from Switch_FileFormatsMain/GUI/BCRES/BfresEditor.Designer.cs rename to Switch_FileFormatsMain/GUI/BCRES/BcresEditor.Designer.cs diff --git a/Switch_FileFormatsMain/GUI/BCRES/BfresEditor.cs b/Switch_FileFormatsMain/GUI/BCRES/BcresEditor.cs similarity index 73% rename from Switch_FileFormatsMain/GUI/BCRES/BfresEditor.cs rename to Switch_FileFormatsMain/GUI/BCRES/BcresEditor.cs index 78c7ce0e..b72dede7 100644 --- a/Switch_FileFormatsMain/GUI/BCRES/BfresEditor.cs +++ b/Switch_FileFormatsMain/GUI/BCRES/BcresEditor.cs @@ -43,7 +43,7 @@ namespace FirstPlugin.Forms OnLoadedTab(); else { - viewport = new Viewport(); + viewport = new Viewport(ObjectEditor.GetDrawableContainers()); viewport.Dock = DockStyle.Fill; OnLoadedTab(); } @@ -80,7 +80,7 @@ namespace FirstPlugin.Forms //Always create an instance of the viewport unless opengl is disabled if (viewport == null && Runtime.UseOpenGL) { - viewport = new Viewport(); + viewport = new Viewport(ObjectEditor.GetDrawableContainers()); viewport.Dock = DockStyle.Fill; } @@ -134,16 +134,11 @@ namespace FirstPlugin.Forms public bool IsLoaded = false; + private BCRES ActiveBcres; - //All drawables for this particular editor - List Drawables; - - //Drawables removed but the viewport is toggled off to update - List RemovedDrawables = new List(); - - public void LoadViewport(List drawables, List customContextMenus = null) + public void LoadViewport(BCRES bcres, DrawableContainer ActiveDrawable, List customContextMenus = null) { - Drawables = drawables; + ActiveBcres = bcres; if (!Runtime.UseOpenGL || !DisplayViewport) return; @@ -154,40 +149,11 @@ namespace FirstPlugin.Forms viewport.LoadCustomMenuItem(menu); } + viewport.ReloadDrawables(ActiveDrawable); + OnLoadedTab(); } - public void AddDrawable(AbstractGlDrawable draw) - { - Drawables.Add(draw); - - if (!Runtime.UseOpenGL || !Runtime.DisplayViewport || viewport == null) - { - IsLoaded = false; - return; - } - - if (!viewport.scene.staticObjects.Contains(draw) && - !viewport.scene.objects.Contains(draw)) - { - viewport.AddDrawable(draw); - } - } - - public void RemoveDrawable(AbstractGlDrawable draw) - { - Drawables.Remove(draw); - - if (!Runtime.UseOpenGL || !Runtime.DisplayViewport || viewport == null) - { - IsLoaded = false; - RemovedDrawables.Add(draw); - return; - } - - viewport.RemoveDrawable(draw); - } - public override void OnControlClosing() { } @@ -195,23 +161,9 @@ namespace FirstPlugin.Forms private void OnLoadedTab() { //If a model was loaded we don't need to load the drawables again - if (IsLoaded || Drawables == null || !Runtime.UseOpenGL || !Runtime.DisplayViewport) + if (IsLoaded ||!Runtime.UseOpenGL || !Runtime.DisplayViewport) return; - Console.WriteLine("drawables count " + Drawables.Count); - - foreach (var draw in Drawables) - { - if (!viewport.scene.staticObjects.Contains(draw) && - !viewport.scene.objects.Contains(draw)) - { - viewport.AddDrawable(draw); - } - } - - foreach (var draw in RemovedDrawables) - viewport.RemoveDrawable(draw); - viewport.LoadObjects(); IsLoaded = true; diff --git a/Switch_FileFormatsMain/GUI/BCRES/BfresEditor.resx b/Switch_FileFormatsMain/GUI/BCRES/BcresEditor.resx similarity index 100% rename from Switch_FileFormatsMain/GUI/BCRES/BfresEditor.resx rename to Switch_FileFormatsMain/GUI/BCRES/BcresEditor.resx diff --git a/Switch_FileFormatsMain/GUI/BFRES/BfresEditor.Designer.cs b/Switch_FileFormatsMain/GUI/BFRES/BfresEditor.Designer.cs index 7ac81af4..22756819 100644 --- a/Switch_FileFormatsMain/GUI/BFRES/BfresEditor.Designer.cs +++ b/Switch_FileFormatsMain/GUI/BFRES/BfresEditor.Designer.cs @@ -182,6 +182,7 @@ this.Controls.Add(this.stPanel2); this.Name = "BfresEditor"; this.Size = new System.Drawing.Size(712, 543); + this.Enter += new System.EventHandler(this.BfresEditor_Enter); this.stPanel2.ResumeLayout(false); this.stPanel2.PerformLayout(); this.stToolStrip1.ResumeLayout(false); diff --git a/Switch_FileFormatsMain/GUI/BFRES/BfresEditor.cs b/Switch_FileFormatsMain/GUI/BFRES/BfresEditor.cs index 68dcf304..c6295f21 100644 --- a/Switch_FileFormatsMain/GUI/BFRES/BfresEditor.cs +++ b/Switch_FileFormatsMain/GUI/BFRES/BfresEditor.cs @@ -43,7 +43,7 @@ namespace FirstPlugin.Forms OnLoadedTab(); else { - viewport = new Viewport(); + viewport = new Viewport(ObjectEditor.GetDrawableContainers()); viewport.Dock = DockStyle.Fill; OnLoadedTab(); } @@ -89,7 +89,7 @@ namespace FirstPlugin.Forms //Always create an instance of the viewport unless opengl is disabled if (viewport == null && Runtime.UseOpenGL) { - viewport = new Viewport(); + viewport = new Viewport(ObjectEditor.GetDrawableContainers()); viewport.Dock = DockStyle.Fill; } @@ -156,15 +156,10 @@ namespace FirstPlugin.Forms public bool IsLoaded = false; - //All drawables for this particular editor - List Drawables; - - //Drawables removed but the viewport is toggled off to update - List RemovedDrawables = new List(); - - public void LoadViewport(List drawables, List customContextMenus = null) + private BFRES ActiveBfres; + public void LoadViewport(BFRES bfres, DrawableContainer ActiveDrawable, List customContextMenus = null) { - Drawables = drawables; + ActiveBfres = bfres; if (!Runtime.UseOpenGL || !DisplayViewport) return; @@ -175,40 +170,11 @@ namespace FirstPlugin.Forms viewport.LoadCustomMenuItem(menu); } + viewport.ReloadDrawables(ActiveDrawable); + OnLoadedTab(); } - public void AddDrawable(AbstractGlDrawable draw) - { - Drawables.Add(draw); - - if (!Runtime.UseOpenGL || !Runtime.DisplayViewport || viewport == null) - { - IsLoaded = false; - return; - } - - if (!viewport.scene.staticObjects.Contains(draw) && - !viewport.scene.objects.Contains(draw)) - { - viewport.AddDrawable(draw); - } - } - - public void RemoveDrawable(AbstractGlDrawable draw) - { - Drawables.Remove(draw); - - if (!Runtime.UseOpenGL || !Runtime.DisplayViewport || viewport == null) - { - IsLoaded = false; - RemovedDrawables.Add(draw); - return; - } - - viewport.RemoveDrawable(draw); - } - public override void OnControlClosing() { animationPanel.ClosePanel(); @@ -217,23 +183,9 @@ namespace FirstPlugin.Forms private void OnLoadedTab() { //If a model was loaded we don't need to load the drawables again - if (IsLoaded || Drawables == null || !Runtime.UseOpenGL || !Runtime.DisplayViewport) + if (IsLoaded ||!Runtime.UseOpenGL || !Runtime.DisplayViewport) return; - Console.WriteLine("drawables count " + Drawables.Count); - - foreach (var draw in Drawables) - { - if (!viewport.scene.staticObjects.Contains(draw) && - !viewport.scene.objects.Contains(draw)) - { - viewport.AddDrawable(draw); - } - } - - foreach (var draw in RemovedDrawables) - viewport.RemoveDrawable(draw); - viewport.LoadObjects(); IsLoaded = true; @@ -280,5 +232,10 @@ namespace FirstPlugin.Forms DisplayViewport = Runtime.DisplayViewport; Config.Save(); } + + private void BfresEditor_Enter(object sender, EventArgs e) + { + + } } } diff --git a/Switch_FileFormatsMain/GUI/Byaml/CourseMuunt/TurboMunntEditor.cs b/Switch_FileFormatsMain/GUI/Byaml/CourseMuunt/TurboMunntEditor.cs index a20b48b5..996fd321 100644 --- a/Switch_FileFormatsMain/GUI/Byaml/CourseMuunt/TurboMunntEditor.cs +++ b/Switch_FileFormatsMain/GUI/Byaml/CourseMuunt/TurboMunntEditor.cs @@ -34,7 +34,7 @@ namespace FirstPlugin.Forms treeView1.BackColor = FormThemes.BaseTheme.FormBackColor; treeView1.ForeColor = FormThemes.BaseTheme.FormForeColor; - viewport = new Viewport(); + viewport = new Viewport(ObjectEditor.GetDrawableContainers()); viewport.Dock = DockStyle.Fill; viewport.scene.SelectionChanged += Scene_SelectionChanged; stPanel4.Controls.Add(viewport); diff --git a/Switch_FileFormatsMain/Switch_FileFormatsMain.csproj b/Switch_FileFormatsMain/Switch_FileFormatsMain.csproj index ac67fd19..214988af 100644 --- a/Switch_FileFormatsMain/Switch_FileFormatsMain.csproj +++ b/Switch_FileFormatsMain/Switch_FileFormatsMain.csproj @@ -286,11 +286,11 @@ SmoothNormalsMultiMeshForm.cs - + UserControl - - BfresEditor.cs + + BcresEditor.cs UserControl @@ -928,8 +928,8 @@ AttributeEditor.cs - - BfresEditor.cs + + BcresEditor.cs SamplerEditorSimple.cs diff --git a/Switch_FileFormatsMain/obj/Release/AxInterop.WMPLib.dll b/Switch_FileFormatsMain/obj/Release/AxInterop.WMPLib.dll index 41d41411..3ad1996a 100644 Binary files a/Switch_FileFormatsMain/obj/Release/AxInterop.WMPLib.dll and b/Switch_FileFormatsMain/obj/Release/AxInterop.WMPLib.dll differ diff --git a/Switch_FileFormatsMain/obj/Release/DesignTimeResolveAssemblyReferences.cache b/Switch_FileFormatsMain/obj/Release/DesignTimeResolveAssemblyReferences.cache index 4e755739..3592dfa1 100644 Binary files a/Switch_FileFormatsMain/obj/Release/DesignTimeResolveAssemblyReferences.cache and b/Switch_FileFormatsMain/obj/Release/DesignTimeResolveAssemblyReferences.cache differ diff --git a/Switch_FileFormatsMain/obj/Release/Interop.WMPLib.dll b/Switch_FileFormatsMain/obj/Release/Interop.WMPLib.dll index 5daab68e..48250b88 100644 Binary files a/Switch_FileFormatsMain/obj/Release/Interop.WMPLib.dll and b/Switch_FileFormatsMain/obj/Release/Interop.WMPLib.dll differ diff --git a/Switch_FileFormatsMain/obj/Release/Switch_FileFormatsMain.csproj.CoreCompileInputs.cache b/Switch_FileFormatsMain/obj/Release/Switch_FileFormatsMain.csproj.CoreCompileInputs.cache index d17fc5c1..c78e851d 100644 --- a/Switch_FileFormatsMain/obj/Release/Switch_FileFormatsMain.csproj.CoreCompileInputs.cache +++ b/Switch_FileFormatsMain/obj/Release/Switch_FileFormatsMain.csproj.CoreCompileInputs.cache @@ -1 +1 @@ -3779dc3a197c1f391b60c356a4d2114a1d71e61a +5e2bb78fbebca632406427d80546922252d8f7ff diff --git a/Switch_FileFormatsMain/obj/Release/Switch_FileFormatsMain.csproj.GenerateResource.cache b/Switch_FileFormatsMain/obj/Release/Switch_FileFormatsMain.csproj.GenerateResource.cache index a8662755..11f207e5 100644 Binary files a/Switch_FileFormatsMain/obj/Release/Switch_FileFormatsMain.csproj.GenerateResource.cache and b/Switch_FileFormatsMain/obj/Release/Switch_FileFormatsMain.csproj.GenerateResource.cache differ diff --git a/Switch_FileFormatsMain/obj/Release/Switch_FileFormatsMain.csprojAssemblyReference.cache b/Switch_FileFormatsMain/obj/Release/Switch_FileFormatsMain.csprojAssemblyReference.cache index 83f9a029..42bfbe3d 100644 Binary files a/Switch_FileFormatsMain/obj/Release/Switch_FileFormatsMain.csprojAssemblyReference.cache and b/Switch_FileFormatsMain/obj/Release/Switch_FileFormatsMain.csprojAssemblyReference.cache differ diff --git a/Switch_Toolbox_Library/DrawableContainer.cs b/Switch_Toolbox_Library/DrawableContainer.cs new file mode 100644 index 00000000..7b0ef62b --- /dev/null +++ b/Switch_Toolbox_Library/DrawableContainer.cs @@ -0,0 +1,42 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using GL_EditorFramework.Interfaces; +using Switch_Toolbox.Library.Forms; + +namespace Switch_Toolbox.Library +{ + //Represents a container that stores multiple drawables + //These can be switched between the viewport + public class DrawableContainer + { + private string _name; + public string Name + { + set + { + List Names = ObjectEditor.GetDrawableContainers().Select(o => o.Name).ToList(); + foreach (string str in Names) + Console.WriteLine("STR NAME " + str); + _name = Utils.RenameDuplicateString(Names, value); + } + get + { + return _name; + } + } + + public ContainerState ContainerState { get; set; } + + public List Drawables = new List(); + } + + public enum ContainerState + { + Active, + Inactive, + Disposed, + } +} diff --git a/Switch_Toolbox_Library/FileFormats/Assimp/AssimpSaver.cs b/Switch_Toolbox_Library/FileFormats/Assimp/AssimpSaver.cs index 9d0643fc..52151777 100644 --- a/Switch_Toolbox_Library/FileFormats/Assimp/AssimpSaver.cs +++ b/Switch_Toolbox_Library/FileFormats/Assimp/AssimpSaver.cs @@ -6,6 +6,7 @@ using Switch_Toolbox.Library; using Switch_Toolbox.Library.Animations; using Switch_Toolbox.Library.Rendering; using System.Windows.Forms; +using System.Linq; namespace Switch_Toolbox.Library { @@ -42,14 +43,14 @@ namespace Switch_Toolbox.Library progressBar.Task = "Saving File..."; progressBar.Value = 80; - SaveScene(FileName, scene); + SaveScene(FileName, scene, model); progressBar.Value = 100; progressBar.Close(); progressBar.Dispose(); } - private void SaveScene(string FileName, Scene scene) + private void SaveScene(string FileName, Scene scene, STGenericModel model) { using (var v = new AssimpContext()) { @@ -65,11 +66,16 @@ namespace Switch_Toolbox.Library if (ext == ".ply") formatID = "ply"; - if (v.ExportFile(scene, FileName, formatID, PostProcessSteps.FlipUVs)) + bool ExportSuccessScene = v.ExportFile(scene, FileName, formatID, PostProcessSteps.FlipUVs); + if (ExportSuccessScene) + { + // WriteExtraSkinningInfo(FileName, scene, model); MessageBox.Show($"Exported {FileName} Successfuly!"); + } else MessageBox.Show($"Failed to export {FileName}!"); } + } private void SaveMeshes(Scene scene, STGenericModel model, STSkeleton skeleton, string FileName, List NodeArray) @@ -171,6 +177,295 @@ namespace Switch_Toolbox.Library return mesh; } + //Extra skin data based on https://github.com/Sage-of-Mirrors/SuperBMD/blob/ce1061e9b5f57de112f1d12f6459b938594664a0/SuperBMDLib/source/Model.cs#L193 + //Todo this doesn't quite work yet + //Need to adjust all mesh name IDs so they are correct + private void WriteExtraSkinningInfo(string FileName, Scene outScene, STGenericModel Model) + { + StreamWriter test = new StreamWriter(FileName + ".tmp"); + StreamReader dae = File.OpenText(FileName); + + while (!dae.EndOfStream) + { + string line = dae.ReadLine(); + + if (line == " ") + { + AddControllerLibrary(outScene, test); + test.WriteLine(line); + test.Flush(); + } + else if (line.Contains("", $" sid=\"{ name }\" type=\"JOINT\">"); + test.WriteLine(jointLine); + test.Flush(); + } + if (line.Contains("")) + { + int index = 0; + foreach (Mesh mesh in outScene.Meshes) + { + test.WriteLine($" "); + + test.WriteLine($" "); + test.WriteLine(" #skeleton_root"); + test.WriteLine(" "); + test.WriteLine(" "); + test.WriteLine($" "); + test.WriteLine(" "); + test.WriteLine(" "); + test.WriteLine(" "); + + test.WriteLine(" "); + test.Flush(); + + index++; + } + + test.WriteLine(line); + test.Flush(); + } + else if (line.Contains("", ""); + test.WriteLine(matLine); + test.Flush(); + } + else + { + test.WriteLine(line); + test.Flush(); + } + } + + test.Close(); + dae.Close(); + + File.Copy(FileName + ".tmp", FileName, true); + File.Delete(FileName + ".tmp"); + } + + private void AddControllerLibrary(Scene scene, StreamWriter writer) + { + writer.WriteLine(" "); + + for (int i = 0; i < scene.MeshCount; i++) + { + Mesh curMesh = scene.Meshes[i]; + curMesh.Name = curMesh.Name.Replace('_', '-'); + + writer.WriteLine($" "); + + writer.WriteLine($" "); + + WriteBindShapeMatrixToStream(writer); + WriteJointNameArrayToStream(curMesh, writer); + WriteInverseBindMatricesToStream(curMesh, writer); + WriteSkinWeightsToStream(curMesh, writer); + + writer.WriteLine(" "); + + writer.WriteLine($" "); + writer.WriteLine($" "); + + writer.WriteLine(" "); + writer.Flush(); + + WriteVertexWeightsToStream(curMesh, writer); + + writer.WriteLine(" "); + + writer.WriteLine(" "); + writer.Flush(); + } + + writer.WriteLine(" "); + writer.Flush(); + } + + private void WriteJointNameArrayToStream(Mesh mesh, StreamWriter writer) + { + writer.WriteLine($" "); + writer.WriteLine($" "); + + writer.Write(" "); + foreach (Bone bone in mesh.Bones) + { + writer.Write($"{ bone.Name }"); + if (bone != mesh.Bones.Last()) + writer.Write(' '); + else + writer.Write('\n'); + + writer.Flush(); + } + + writer.WriteLine(" "); + writer.Flush(); + + writer.WriteLine(" "); + writer.WriteLine($" "); + writer.WriteLine(" "); + writer.WriteLine(" "); + writer.WriteLine(" "); + writer.WriteLine(" "); + writer.Flush(); + } + + private void WriteInverseBindMatricesToStream(Mesh mesh, StreamWriter writer) + { + writer.WriteLine($" "); + writer.WriteLine($" "); + + foreach (Bone bone in mesh.Bones) + { + Matrix4x4 ibm = bone.OffsetMatrix; + ibm.Transpose(); + + writer.WriteLine($" {ibm.A1.ToString("F")} {ibm.A2.ToString("F")} {ibm.A3.ToString("F")} {ibm.A4.ToString("F")}"); + writer.WriteLine($" {ibm.B1.ToString("F")} {ibm.B2.ToString("F")} {ibm.B3.ToString("F")} {ibm.B4.ToString("F")}"); + writer.WriteLine($" {ibm.C1.ToString("F")} {ibm.C2.ToString("F")} {ibm.C3.ToString("F")} {ibm.C4.ToString("F")}"); + writer.WriteLine($" {ibm.D1.ToString("F")} {ibm.D2.ToString("F")} {ibm.D3.ToString("F")} {ibm.D4.ToString("F")}"); + + if (bone != mesh.Bones.Last()) + writer.WriteLine(""); + } + + writer.WriteLine(" "); + writer.Flush(); + + writer.WriteLine(" "); + writer.WriteLine($" "); + writer.WriteLine(" "); + writer.WriteLine(" "); + writer.WriteLine(" "); + writer.WriteLine(" "); + writer.Flush(); + } + + private void WriteSkinWeightsToStream(Mesh mesh, StreamWriter writer) + { + int totalWeightCount = 0; + + foreach (Bone bone in mesh.Bones) + { + totalWeightCount += bone.VertexWeightCount; + } + + writer.WriteLine($" "); + writer.WriteLine($" "); + writer.Write(" "); + + foreach (Bone bone in mesh.Bones) + { + foreach (VertexWeight weight in bone.VertexWeights) + { + writer.Write($"{ weight.Weight } "); + } + + if (bone == mesh.Bones.Last()) + writer.WriteLine(); + } + + writer.WriteLine(" "); + writer.Flush(); + + writer.WriteLine(" "); + writer.WriteLine($" "); + writer.WriteLine(" "); + writer.WriteLine(" "); + writer.WriteLine(" "); + writer.WriteLine(" "); + writer.Flush(); + } + + private class RiggedWeight + { + public List Weights { get; private set; } + public List BoneIndices { get; private set; } + + public int WeightCount { get; private set; } + + public RiggedWeight() + { + Weights = new List(); + BoneIndices = new List(); + } + + public void AddWeight(float weight, int boneIndex) + { + Weights.Add(weight); + BoneIndices.Add(boneIndex); + WeightCount++; + } + } + + private void WriteVertexWeightsToStream(Mesh mesh, StreamWriter writer) + { + List weights = new List(); + Dictionary vertIDWeights = new Dictionary(); + + foreach (Bone bone in mesh.Bones) + { + foreach (VertexWeight weight in bone.VertexWeights) + { + weights.Add(weight.Weight); + + if (!vertIDWeights.ContainsKey(weight.VertexID)) + vertIDWeights.Add(weight.VertexID, new RiggedWeight()); + + vertIDWeights[weight.VertexID].AddWeight(weight.Weight, mesh.Bones.IndexOf(bone)); + } + } + + writer.WriteLine($" "); + + writer.WriteLine($" "); + writer.WriteLine($" "); + + writer.WriteLine(" "); + + writer.Write(" "); + for (int i = 0; i < vertIDWeights.Count; i++) + writer.Write($"{ vertIDWeights[i].WeightCount } "); + + writer.WriteLine("\n "); + + writer.WriteLine(" "); + writer.Write(" "); + + for (int i = 0; i < vertIDWeights.Count; i++) + { + RiggedWeight curWeight = vertIDWeights[i]; + + for (int j = 0; j < curWeight.WeightCount; j++) + { + writer.Write($"{ curWeight.BoneIndices[j] } { weights.IndexOf(curWeight.Weights[j]) } "); + } + } + + writer.WriteLine("\n "); + + writer.WriteLine($" "); + } + + private void WriteBindShapeMatrixToStream(StreamWriter writer) + { + writer.WriteLine(" "); + + writer.WriteLine(" 1 0 0 0"); + writer.WriteLine(" 0 1 0 0"); + writer.WriteLine(" 0 0 1 0"); + writer.WriteLine(" 0 0 0 1"); + + writer.WriteLine(" "); + writer.Flush(); + } + private void SaveMaterials(Scene scene, STGenericModel model, string FileName, List Textures) { string TextureExtension = ".png"; @@ -280,7 +575,7 @@ namespace Switch_Toolbox.Library material.Name = "NewMaterial"; scene.Materials.Add(material); - SaveScene(FileName, scene); + SaveScene(FileName, scene, new STGenericModel()); } private void SaveSkeleton(STSkeleton skeleton, Node parentNode) diff --git a/Switch_Toolbox_Library/Forms/Custom/STComboBox.cs b/Switch_Toolbox_Library/Forms/Custom/STComboBox.cs index 158b67e1..979bcbfa 100644 --- a/Switch_Toolbox_Library/Forms/Custom/STComboBox.cs +++ b/Switch_Toolbox_Library/Forms/Custom/STComboBox.cs @@ -76,6 +76,11 @@ namespace Switch_Toolbox.Library.Forms return GetItemText(SelectedItem); } + public void SelectItemByText(string text) + { + SelectedIndex = FindStringExact(text); + } + public void Bind(Type EnumType, object Object, string PropertyName, bool IsReset = true) { if (IsReset) diff --git a/Switch_Toolbox_Library/Forms/Editors/Object Editor/ObjectEditor.cs b/Switch_Toolbox_Library/Forms/Editors/Object Editor/ObjectEditor.cs index 9a5e4012..416f644f 100644 --- a/Switch_Toolbox_Library/Forms/Editors/Object Editor/ObjectEditor.cs +++ b/Switch_Toolbox_Library/Forms/Editors/Object Editor/ObjectEditor.cs @@ -175,16 +175,33 @@ namespace Switch_Toolbox.Library.Forms IsLoaded = true; } - public List editableGlDrawables = new List(); - public List staticGlDrawables = new List(); + public List DrawableContainers = new List(); - public static void AddObject(EditableObject drawable) + public static List GetDrawableContainers() + { + var editor = LibraryGUI.Instance.GetObjectEditor(); + if (editor == null) + return new List(); + + return editor.DrawableContainers; + } + + public static void AddContainer(DrawableContainer drawable) { var editor = LibraryGUI.Instance.GetObjectEditor(); if (editor == null) return; - editor.editableGlDrawables.Add(drawable); + editor.DrawableContainers.Add(drawable); + } + + public static void RemoveContainer(DrawableContainer drawable) + { + var editor = LibraryGUI.Instance.GetObjectEditor(); + if (editor == null) + return; + + editor.DrawableContainers.Remove(drawable); } public List GetEditors() diff --git a/Switch_Toolbox_Library/Forms/Editors/Object Editor/ObjectEditorList.cs b/Switch_Toolbox_Library/Forms/Editors/Object Editor/ObjectEditorList.cs index 85ff21f9..89eb2af7 100644 --- a/Switch_Toolbox_Library/Forms/Editors/Object Editor/ObjectEditorList.cs +++ b/Switch_Toolbox_Library/Forms/Editors/Object Editor/ObjectEditorList.cs @@ -107,18 +107,6 @@ namespace Switch_Toolbox.Library.Forms IsLoaded = true; } - public List editableGlDrawables = new List(); - public List staticGlDrawables = new List(); - - public static void AddObject(EditableObject drawable) - { - var editor = LibraryGUI.Instance.GetObjectEditor(); - if (editor == null) - return; - - editor.editableGlDrawables.Add(drawable); - } - public IFileFormat GetActiveFile() { if (treeViewCustom1.Nodes.Count == 0) diff --git a/Switch_Toolbox_Library/Forms/Editors/Object Editor/ObjectEditorTree.Designer.cs b/Switch_Toolbox_Library/Forms/Editors/Object Editor/ObjectEditorTree.Designer.cs index c51ddc92..90480460 100644 --- a/Switch_Toolbox_Library/Forms/Editors/Object Editor/ObjectEditorTree.Designer.cs +++ b/Switch_Toolbox_Library/Forms/Editors/Object Editor/ObjectEditorTree.Designer.cs @@ -92,7 +92,6 @@ // // treeViewCustom1 // - this.treeViewCustom1.AllowDrop = true; this.treeViewCustom1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); diff --git a/Switch_Toolbox_Library/Forms/Editors/Object Editor/ObjectEditorTree.cs b/Switch_Toolbox_Library/Forms/Editors/Object Editor/ObjectEditorTree.cs index c85d3f4d..a009223a 100644 --- a/Switch_Toolbox_Library/Forms/Editors/Object Editor/ObjectEditorTree.cs +++ b/Switch_Toolbox_Library/Forms/Editors/Object Editor/ObjectEditorTree.cs @@ -120,18 +120,6 @@ namespace Switch_Toolbox.Library.Forms IsLoaded = true; } - public List editableGlDrawables = new List(); - public List staticGlDrawables = new List(); - - public static void AddObject(EditableObject drawable) - { - var editor = LibraryGUI.Instance.GetObjectEditor(); - if (editor == null) - return; - - editor.editableGlDrawables.Add(drawable); - } - public IFileFormat GetActiveFile() { if (treeViewCustom1.Nodes.Count == 0) @@ -523,8 +511,8 @@ namespace Switch_Toolbox.Library.Forms if (IsFolder || IsRoot || IsFile) e.Effect = DragDropEffects.Link; - else - e.Effect = DragDropEffects.None; + // else + // e.Effect = DragDropEffects.None; } private IArchiveFile GetActiveArchive() diff --git a/Switch_Toolbox_Library/Forms/Editors/Object Editor/ObjectEditorTree.resx b/Switch_Toolbox_Library/Forms/Editors/Object Editor/ObjectEditorTree.resx index a3264e1d..197ca22e 100644 --- a/Switch_Toolbox_Library/Forms/Editors/Object Editor/ObjectEditorTree.resx +++ b/Switch_Toolbox_Library/Forms/Editors/Object Editor/ObjectEditorTree.resx @@ -120,7 +120,4 @@ 17, 17 - - 17, 17 - \ No newline at end of file diff --git a/Switch_Toolbox_Library/Forms/Viewport.Designer.cs b/Switch_Toolbox_Library/Forms/Viewport.Designer.cs index ffe1d3ab..6f3c063e 100644 --- a/Switch_Toolbox_Library/Forms/Viewport.Designer.cs +++ b/Switch_Toolbox_Library/Forms/Viewport.Designer.cs @@ -29,6 +29,7 @@ private void InitializeComponent() { this.normalsShadingToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.drawContainersCB = new Switch_Toolbox.Library.Forms.STComboBox(); this.panelViewport = new Switch_Toolbox.Library.Forms.STPanel(); this.stContextMenuStrip1 = new Switch_Toolbox.Library.Forms.STMenuStrip(); this.viewToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); @@ -45,12 +46,15 @@ this.leftToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.shadingToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.resetCameraToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.toOriginToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.toActiveModelToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.resetPoseToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.optionsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.reloadShadersToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.toOriginToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.toActiveModelToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.stPanel1 = new Switch_Toolbox.Library.Forms.STPanel(); + this.stLabel1 = new Switch_Toolbox.Library.Forms.STLabel(); this.stContextMenuStrip1.SuspendLayout(); + this.stPanel1.SuspendLayout(); this.SuspendLayout(); // // normalsShadingToolStripMenuItem @@ -63,12 +67,28 @@ this.normalsShadingToolStripMenuItem.Text = "Normals Shading"; this.normalsShadingToolStripMenuItem.TextImageRelation = System.Windows.Forms.TextImageRelation.ImageAboveText; // + // drawContainersCB + // + this.drawContainersCB.BorderColor = System.Drawing.Color.Empty; + this.drawContainersCB.BorderStyle = System.Windows.Forms.ButtonBorderStyle.Solid; + this.drawContainersCB.ButtonColor = System.Drawing.Color.Empty; + this.drawContainersCB.FormattingEnabled = true; + this.drawContainersCB.Location = new System.Drawing.Point(93, 0); + this.drawContainersCB.Name = "drawContainersCB"; + this.drawContainersCB.ReadOnly = true; + this.drawContainersCB.Size = new System.Drawing.Size(183, 21); + this.drawContainersCB.TabIndex = 0; + this.drawContainersCB.SelectedIndexChanged += new System.EventHandler(this.drawContainersCB_SelectedIndexChanged); + this.drawContainersCB.MouseDown += new System.Windows.Forms.MouseEventHandler(this.drawContainersCB_MouseDown); + // // panelViewport // - this.panelViewport.Dock = System.Windows.Forms.DockStyle.Fill; - this.panelViewport.Location = new System.Drawing.Point(0, 24); + this.panelViewport.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.panelViewport.Location = new System.Drawing.Point(0, 48); this.panelViewport.Name = "panelViewport"; - this.panelViewport.Size = new System.Drawing.Size(781, 498); + this.panelViewport.Size = new System.Drawing.Size(781, 474); this.panelViewport.TabIndex = 3; // // stContextMenuStrip1 @@ -196,6 +216,20 @@ this.resetCameraToolStripMenuItem.Size = new System.Drawing.Size(91, 20); this.resetCameraToolStripMenuItem.Text = "Reset Camera"; // + // toOriginToolStripMenuItem + // + this.toOriginToolStripMenuItem.Name = "toOriginToolStripMenuItem"; + this.toOriginToolStripMenuItem.Size = new System.Drawing.Size(160, 22); + this.toOriginToolStripMenuItem.Text = "To Origin"; + this.toOriginToolStripMenuItem.Click += new System.EventHandler(this.toOriginToolStripMenuItem_Click); + // + // toActiveModelToolStripMenuItem + // + this.toActiveModelToolStripMenuItem.Name = "toActiveModelToolStripMenuItem"; + this.toActiveModelToolStripMenuItem.Size = new System.Drawing.Size(160, 22); + this.toActiveModelToolStripMenuItem.Text = "To Active Model"; + this.toActiveModelToolStripMenuItem.Click += new System.EventHandler(this.toActiveModelToolStripMenuItem_Click); + // // resetPoseToolStripMenuItem // this.resetPoseToolStripMenuItem.Name = "resetPoseToolStripMenuItem"; @@ -218,31 +252,40 @@ this.reloadShadersToolStripMenuItem.Text = "Reload Shaders"; this.reloadShadersToolStripMenuItem.Click += new System.EventHandler(this.reloadShadersToolStripMenuItem_Click); // - // toOriginToolStripMenuItem + // stPanel1 // - this.toOriginToolStripMenuItem.Name = "toOriginToolStripMenuItem"; - this.toOriginToolStripMenuItem.Size = new System.Drawing.Size(180, 22); - this.toOriginToolStripMenuItem.Text = "To Origin"; - this.toOriginToolStripMenuItem.Click += new System.EventHandler(this.toOriginToolStripMenuItem_Click); + this.stPanel1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.stPanel1.Controls.Add(this.stLabel1); + this.stPanel1.Controls.Add(this.drawContainersCB); + this.stPanel1.Location = new System.Drawing.Point(0, 26); + this.stPanel1.Name = "stPanel1"; + this.stPanel1.Size = new System.Drawing.Size(778, 24); + this.stPanel1.TabIndex = 5; // - // toActiveModelToolStripMenuItem + // stLabel1 // - this.toActiveModelToolStripMenuItem.Name = "toActiveModelToolStripMenuItem"; - this.toActiveModelToolStripMenuItem.Size = new System.Drawing.Size(180, 22); - this.toActiveModelToolStripMenuItem.Text = "To Active Model"; - this.toActiveModelToolStripMenuItem.Click += new System.EventHandler(this.toActiveModelToolStripMenuItem_Click); + this.stLabel1.AutoSize = true; + this.stLabel1.Location = new System.Drawing.Point(3, 3); + this.stLabel1.Name = "stLabel1"; + this.stLabel1.Size = new System.Drawing.Size(83, 13); + this.stLabel1.TabIndex = 1; + this.stLabel1.Text = "Active Model(s):"; // // Viewport // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64))))); + this.Controls.Add(this.stPanel1); this.Controls.Add(this.panelViewport); this.Controls.Add(this.stContextMenuStrip1); this.Name = "Viewport"; this.Size = new System.Drawing.Size(781, 522); this.stContextMenuStrip1.ResumeLayout(false); this.stContextMenuStrip1.PerformLayout(); + this.stPanel1.ResumeLayout(false); + this.stPanel1.PerformLayout(); this.ResumeLayout(false); this.PerformLayout(); @@ -271,5 +314,8 @@ private System.Windows.Forms.ToolStripMenuItem leftToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem toOriginToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem toActiveModelToolStripMenuItem; + private Forms.STComboBox drawContainersCB; + private Forms.STPanel stPanel1; + private Forms.STLabel stLabel1; } } \ No newline at end of file diff --git a/Switch_Toolbox_Library/Forms/Viewport.cs b/Switch_Toolbox_Library/Forms/Viewport.cs index c60d850f..ebf765af 100644 --- a/Switch_Toolbox_Library/Forms/Viewport.cs +++ b/Switch_Toolbox_Library/Forms/Viewport.cs @@ -18,14 +18,20 @@ namespace Switch_Toolbox.Library { public partial class Viewport : UserControl { + public List DrawableContainers; + public EditorScene scene = new EditorScene(); public GL_ControlLegacy GL_ControlLegacy; public GL_ControlModern GL_ControlModern; Runtime.ViewportEditor editor; - public Viewport(bool LoadDrawables = true) + public Viewport(List container, bool LoadDrawables = true) { + DrawableContainers = container; + if (DrawableContainers == null) + DrawableContainers = new List(); + this.DoubleBuffered = true; InitializeComponent(); @@ -47,10 +53,59 @@ namespace Switch_Toolbox.Library shadingToolStripMenuItem.Text = $"Shading: [{Runtime.viewportShading.ToString()}]"; + if (LoadDrawables) LoadBaseDrawables(); } + //Reloads drawable containers without an active object being selected + public void ReloadDrawables() + { + drawContainersCB.Items.Clear(); + drawContainersCB.Items.Add("All Active Drawables"); + + for (int i = 0; i < DrawableContainers.Count; i++) + { + drawContainersCB.Items.Add(DrawableContainers[i].Name); + + for (int a = 0; a < DrawableContainers[i].Drawables.Count; a++) + { + if (!ContainsDrawable(DrawableContainers[i].Drawables[a])) + AddDrawable((DrawableContainers[i].Drawables[a])); + } + } + } + + //Reloads drawable containers with the active container selected + public void ReloadDrawables(DrawableContainer ActiveContainer) + { + drawContainersCB.Items.Clear(); + drawContainersCB.Items.Add("All Active Drawables"); + + for (int i = 0; i < DrawableContainers.Count;i++) + { + drawContainersCB.Items.Add(DrawableContainers[i].Name); + + for (int a = 0; a < DrawableContainers[i].Drawables.Count; a++) + { + if (DrawableContainers[i] != ActiveContainer) + DrawableContainers[i].Drawables[a].Visible = false; + else + DrawableContainers[i].Drawables[a].Visible = true; + + if (!ContainsDrawable(DrawableContainers[i].Drawables[a])) + AddDrawable((DrawableContainers[i].Drawables[a])); + } + } + + drawContainersCB.SelectItemByText(ActiveContainer.Name); + } + + public bool ContainsDrawable(AbstractGlDrawable Drawable) + { + return scene.staticObjects.Contains(Drawable) || scene.objects.Contains(Drawable); + } + private void shadingToolStripMenuItem_DropDownItemClicked(object sender, ToolStripItemClickedEventArgs e) { int i = 0; @@ -422,5 +477,44 @@ namespace Switch_Toolbox.Library GL_ControlModern.Refresh(); } } + + private void drawContainersCB_SelectedIndexChanged(object sender, EventArgs e) + { + if (drawContainersCB.SelectedIndex == 0) + DrawAllActive(); + else if (drawContainersCB.SelectedIndex > 0) + { + int index = drawContainersCB.SelectedIndex - 1; + + for (int i = 0; i < DrawableContainers.Count; i++) + { + for (int a = 0; a < DrawableContainers[i].Drawables.Count; a++) + { + if (i == index) + DrawableContainers[i].Drawables[a].Visible = true; + else + DrawableContainers[i].Drawables[a].Visible = false; + } + } + } + + UpdateViewport(); + } + + private void DrawAllActive() + { + for (int i = 0; i < DrawableContainers.Count; i++) + { + for (int a = 0; a < DrawableContainers[i].Drawables.Count; a++) + { + DrawableContainers[i].Drawables[a].Visible = true; + } + } + } + + private void drawContainersCB_MouseDown(object sender, MouseEventArgs e) + { + ReloadDrawables(); + } } } diff --git a/Switch_Toolbox_Library/Switch_Toolbox_Library.csproj b/Switch_Toolbox_Library/Switch_Toolbox_Library.csproj index e24f9e4e..cbb9d138 100644 --- a/Switch_Toolbox_Library/Switch_Toolbox_Library.csproj +++ b/Switch_Toolbox_Library/Switch_Toolbox_Library.csproj @@ -203,6 +203,7 @@ + diff --git a/Toolbox/Gl_EditorFramework.dll b/Toolbox/Gl_EditorFramework.dll index f0e70d5e..6e916b0d 100644 Binary files a/Toolbox/Gl_EditorFramework.dll and b/Toolbox/Gl_EditorFramework.dll differ diff --git a/Toolbox/Gl_EditorFramework.pdb b/Toolbox/Gl_EditorFramework.pdb index 51f569d8..0e396a89 100644 Binary files a/Toolbox/Gl_EditorFramework.pdb and b/Toolbox/Gl_EditorFramework.pdb differ diff --git a/Toolbox/MainForm.cs b/Toolbox/MainForm.cs index cd3a7d54..a4e2e17d 100644 --- a/Toolbox/MainForm.cs +++ b/Toolbox/MainForm.cs @@ -98,7 +98,7 @@ namespace Toolbox if (Runtime.UseOpenGL) { //Create an instance of this to help load open gl data easier and quicker after boot - var viewport = new Viewport(false); + var viewport = new Viewport(ObjectEditor.GetDrawableContainers(), false); ShaderTools.executableDir = Runtime.ExecutableDir; if (OpenTK.Graphics.GraphicsContext.CurrentContext != null)