diff --git a/.vs/Switch_Toolbox/v15/.suo b/.vs/Switch_Toolbox/v15/.suo index 9f428b7e..c4091b92 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 cc457026..9f1c3f37 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-wal b/.vs/Switch_Toolbox/v15/Server/sqlite3/storage.ide-wal index c878e24d..f35b4627 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/GL/BCRES_Render.cs b/Switch_FileFormatsMain/GL/BCRES_Render.cs index 13def4e0..d5795767 100644 --- a/Switch_FileFormatsMain/GL/BCRES_Render.cs +++ b/Switch_FileFormatsMain/GL/BCRES_Render.cs @@ -194,7 +194,7 @@ namespace FirstPlugin SetDefaultTextureAttributes(mat, shader); GL.ActiveTexture(TextureUnit.Texture0 + 1); - GL.BindTexture(TextureTarget.Texture2D, RenderTools.defaultTex.Id); + GL.BindTexture(TextureTarget.Texture2D, RenderTools.defaultTex.RenderableTex.TexID); GL.Uniform1(shader["debugOption"], 2); @@ -209,7 +209,7 @@ namespace FirstPlugin GL.ActiveTexture(TextureUnit.Texture10); GL.Uniform1(shader["UVTestPattern"], 10); - GL.BindTexture(TextureTarget.Texture2D, RenderTools.uvTestPattern.Id); + GL.BindTexture(TextureTarget.Texture2D, RenderTools.uvTestPattern.RenderableTex.TexID); foreach (STGenericMatTexture matex in mat.TextureMaps) { @@ -233,13 +233,12 @@ namespace FirstPlugin public static int BindTexture(STGenericMatTexture tex) { GL.ActiveTexture(TextureUnit.Texture0 + tex.textureUnit + 1); - GL.BindTexture(TextureTarget.Texture2D, RenderTools.defaultTex.Id); + GL.BindTexture(TextureTarget.Texture2D, RenderTools.defaultTex.RenderableTex.TexID); string activeTex = tex.Name; foreach (var bcresTexContainer in PluginRuntime.bcresTexContainers) { - if (bcresTexContainer.ResourceNodes.ContainsKey(activeTex)) { TXOBWrapper txob = (TXOBWrapper)bcresTexContainer.ResourceNodes[activeTex]; @@ -248,6 +247,7 @@ namespace FirstPlugin txob.LoadOpenGLTexture(); BindGLTexture(tex, txob.RenderableTex.TexID); + break; } } return tex.textureUnit + 1; diff --git a/Switch_FileFormatsMain/GL/BFRES_Render.cs b/Switch_FileFormatsMain/GL/BFRES_Render.cs index 41da493a..3744fbad 100644 --- a/Switch_FileFormatsMain/GL/BFRES_Render.cs +++ b/Switch_FileFormatsMain/GL/BFRES_Render.cs @@ -238,6 +238,33 @@ namespace FirstPlugin public void CenterCamera(GL_ControlModern control) { + Vector3 minVector = new Vector3(0); + Vector3 maxVector = new Vector3(0); + if (models.Count != 0) + { + minVector = models[0].MinPosition; + maxVector = models[0].MaxPosition; + } + + Vector3 translation = control.CameraPosition; + + float minSize = Math.Min(Math.Min(minVector.X, minVector.Y), minVector.Z); + float maxSize = Math.Max(Math.Max(maxVector.X, maxVector.Y), maxVector.Z); + float scale = (10f / (maxSize - minSize)); //Try to adjust to screen + if (maxSize - minSize == 0) scale = 1; + + Matrix4 centerMatrix = Matrix4.CreateTranslation( + -(minVector.X + maxVector.X) / 2, + -(minVector.Y + maxVector.Y) / 2, + -(minVector.Z + maxVector.Z) / 2); + Matrix4 translationMatrix = Matrix4.CreateTranslation( + (-translation.X / 50) / scale, + (translation.Y / 50) / scale, + control.CameraDistance / scale); + + + + control.CameraPosition = centerMatrix.ExtractTranslation(); } public static Vector4 GenerateBoundingSphere(IEnumerable boundingSpheres) @@ -463,7 +490,7 @@ namespace FirstPlugin SetDefaultTextureAttributes(mat, shader); GL.ActiveTexture(TextureUnit.Texture0 + 1); - GL.BindTexture(TextureTarget.Texture2D, RenderTools.defaultTex.Id); + GL.BindTexture(TextureTarget.Texture2D, RenderTools.defaultTex.RenderableTex.TexID); GL.ActiveTexture(TextureUnit.Texture11); GL.Uniform1(shader["weightRamp1"], 11); @@ -478,7 +505,7 @@ namespace FirstPlugin GL.ActiveTexture(TextureUnit.Texture10); GL.Uniform1(shader["UVTestPattern"], 10); - GL.BindTexture(TextureTarget.Texture2D, RenderTools.uvTestPattern.Id); + GL.BindTexture(TextureTarget.Texture2D, RenderTools.uvTestPattern.RenderableTex.TexID); GL.Uniform1(shader["normalMap"], 0); GL.Uniform1(shader["BakeShadowMap"], 0); @@ -550,7 +577,7 @@ namespace FirstPlugin public static int BindTexture(MatTexture tex, bool IsWiiU) { GL.ActiveTexture(TextureUnit.Texture0 + tex.textureUnit + 1); - GL.BindTexture(TextureTarget.Texture2D, RenderTools.defaultTex.Id); + GL.BindTexture(TextureTarget.Texture2D, RenderTools.defaultTex.RenderableTex.TexID); string activeTex = tex.Name; if (tex.animatedTexName != "") diff --git a/Switch_FileFormatsMain/obj/Release/Switch_FileFormatsMain.csprojAssemblyReference.cache b/Switch_FileFormatsMain/obj/Release/Switch_FileFormatsMain.csprojAssemblyReference.cache index b73ab551..f5118441 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/Forms/Editors/UV/UVEditor.cs b/Switch_Toolbox_Library/Forms/Editors/UV/UVEditor.cs index 51ae2bf9..5caa146c 100644 --- a/Switch_Toolbox_Library/Forms/Editors/UV/UVEditor.cs +++ b/Switch_Toolbox_Library/Forms/Editors/UV/UVEditor.cs @@ -67,7 +67,7 @@ namespace Switch_Toolbox.Library.Forms comboBox2.Items.Clear(); if (RenderTools.defaultTex != null) - texid = RenderTools.defaultTex.Id; + texid = RenderTools.defaultTex.RenderableTex.TexID; foreach (var item in Textures) comboBox2.Items.Add(item.texture.Text); diff --git a/Switch_Toolbox_Library/Forms/Editors/UV/UVEditor2.cs b/Switch_Toolbox_Library/Forms/Editors/UV/UVEditor2.cs index f7695b47..46c6221b 100644 --- a/Switch_Toolbox_Library/Forms/Editors/UV/UVEditor2.cs +++ b/Switch_Toolbox_Library/Forms/Editors/UV/UVEditor2.cs @@ -67,7 +67,7 @@ namespace Switch_Toolbox.Library.Forms.test comboBox2.Items.Clear(); if (RenderTools.defaultTex != null) - texid = RenderTools.defaultTex.Id; + texid = RenderTools.defaultTex.RenderableTex.TexID; foreach (var item in Textures) comboBox2.Items.Add(item.texture.Text); diff --git a/Switch_Toolbox_Library/Generics/RenderableTex.cs b/Switch_Toolbox_Library/Generics/RenderableTex.cs index 44612578..42ac716e 100644 --- a/Switch_Toolbox_Library/Generics/RenderableTex.cs +++ b/Switch_Toolbox_Library/Generics/RenderableTex.cs @@ -124,6 +124,7 @@ namespace Switch_Toolbox.Library.Rendering TexID = loadImage(this); } + public static int loadImage(RenderableTex t) { if (!t.GLInitialized) @@ -149,6 +150,12 @@ namespace Switch_Toolbox.Library.Rendering return texID; } + + public void Bind() + { + GL.BindTexture(TextureTarget.Texture2D, TexID); + } + private static int getImageSize(RenderableTex t) { switch (t.pixelInternalFormat) diff --git a/Switch_Toolbox_Library/Rendering/RenderTools.cs b/Switch_Toolbox_Library/Rendering/RenderTools.cs index 92cd4394..08cb757f 100644 --- a/Switch_Toolbox_Library/Rendering/RenderTools.cs +++ b/Switch_Toolbox_Library/Rendering/RenderTools.cs @@ -23,18 +23,18 @@ namespace Switch_Toolbox.Library brdfpbr != null); } } - - private static Texture2D defaulttex; - public static Texture2D defaultTex + + public static STGenericTexture defaulttex; + public static STGenericTexture defaultTex { get { if (defaulttex == null) { - defaulttex = new Texture2D(); - defaultTex.LoadImageData(Properties.Resources.DefaultTexture); + defaulttex = new GenericBitmapTexture(Properties.Resources.DefaultTexture); + defaulttex.LoadOpenGLTexture(); + defaulttex.RenderableTex.Bind(); } - return defaulttex; } set @@ -77,18 +77,16 @@ namespace Switch_Toolbox.Library specularpbr = value; } } - public static Texture2D uvtestPattern; - public static Texture2D uvTestPattern + public static STGenericTexture uvtestPattern; + public static STGenericTexture uvTestPattern { get { if (uvtestPattern == null) { - uvtestPattern = new Texture2D(); - uvtestPattern.LoadImageData(Properties.Resources.UVPattern); - uvtestPattern.TextureWrapR = TextureWrapMode.Repeat; - uvtestPattern.TextureWrapS = TextureWrapMode.Repeat; - uvtestPattern.TextureWrapT = TextureWrapMode.Repeat; + uvTestPattern = new GenericBitmapTexture(Properties.Resources.UVPattern); + uvTestPattern.LoadOpenGLTexture(); + uvTestPattern.RenderableTex.Bind(); } return uvtestPattern; } diff --git a/Toolbox/Gl_EditorFramework.dll b/Toolbox/Gl_EditorFramework.dll index 4fa37cda..e1611522 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 a49e998f..7f065937 100644 Binary files a/Toolbox/Gl_EditorFramework.pdb and b/Toolbox/Gl_EditorFramework.pdb differ