From 940994604a10257834793b9c45539c832285a03e Mon Sep 17 00:00:00 2001 From: KillzXGaming Date: Sat, 23 Nov 2019 16:06:33 -0500 Subject: [PATCH] Some cleanup --- .../FileFormats/Layout/BxlytToGL.cs | 3 +- .../FileFormats/Layout/CAFE/BflytShader.cs | 3 + File_Format_Library/GL/BFRES_Render.cs | 2 +- File_Format_Library/GUI/BFRES/BfresEditor.cs | 4 +- .../Byaml/TurboCourseMuunt/Matrix2DHelper.cs | 2 +- .../TurboCourseMuunt/TurboMunntEditor.cs | 4 +- .../Forms/Animation/AnimationPanel.cs | 48 ++--- .../Forms/Animation/Rewrite/AnimationPanel.cs | 5 +- Switch_Toolbox_Library/Forms/Viewport.cs | 172 +++++++----------- 9 files changed, 95 insertions(+), 148 deletions(-) diff --git a/File_Format_Library/FileFormats/Layout/BxlytToGL.cs b/File_Format_Library/FileFormats/Layout/BxlytToGL.cs index 9f083597..fd07363b 100644 --- a/File_Format_Library/FileFormats/Layout/BxlytToGL.cs +++ b/File_Format_Library/FileFormats/Layout/BxlytToGL.cs @@ -87,8 +87,7 @@ namespace LayoutBXLYT }; } - if (!Runtime.DEVELOPER_DEBUG_MODE) - DrawRectangle(pane, gameWindow, pane.Rectangle, TexCoords, Colors, false, effectiveAlpha, isSelected); + DrawRectangle(pane, gameWindow, pane.Rectangle, TexCoords, Colors, false, effectiveAlpha, isSelected); ShaderLoader.CafeShader.Disable(); } diff --git a/File_Format_Library/FileFormats/Layout/CAFE/BflytShader.cs b/File_Format_Library/FileFormats/Layout/CAFE/BflytShader.cs index 172e9255..d17baf0d 100644 --- a/File_Format_Library/FileFormats/Layout/CAFE/BflytShader.cs +++ b/File_Format_Library/FileFormats/Layout/CAFE/BflytShader.cs @@ -94,6 +94,9 @@ namespace LayoutBXLYT shader.SetInt("textures1", 0); shader.SetInt("textures2", 0); + if (Runtime.DEVELOPER_DEBUG_MODE) + return; + BindTextureUniforms(shader, material); if (material.TextureMaps.Length > 0 || Runtime.LayoutEditor.Shading == Runtime.LayoutEditor.DebugShading.UVTestPattern) diff --git a/File_Format_Library/GL/BFRES_Render.cs b/File_Format_Library/GL/BFRES_Render.cs index 5cd810da..f2034f61 100644 --- a/File_Format_Library/GL/BFRES_Render.cs +++ b/File_Format_Library/GL/BFRES_Render.cs @@ -259,7 +259,7 @@ namespace FirstPlugin GL.Enable(EnableCap.Texture2D); } - public void CenterCamera(GL_ControlModern control) + public void CenterCamera(GL_ControlBase control) { if (!Runtime.FrameCamera) return; diff --git a/File_Format_Library/GUI/BFRES/BfresEditor.cs b/File_Format_Library/GUI/BFRES/BfresEditor.cs index d35c9d3e..5609a586 100644 --- a/File_Format_Library/GUI/BFRES/BfresEditor.cs +++ b/File_Format_Library/GUI/BFRES/BfresEditor.cs @@ -141,9 +141,9 @@ namespace FirstPlugin.Forms if (!Runtime.UseOpenGL || !DisplayViewport) return; - if (viewport.GL_ControlModern != null) + if (viewport.GL_Control != null) { - Renderer.CenterCamera(viewport.GL_ControlModern); + Renderer.CenterCamera(viewport.GL_Control); viewport.UpdateViewport(); } } diff --git a/File_Format_Library/GUI/Byaml/TurboCourseMuunt/Matrix2DHelper.cs b/File_Format_Library/GUI/Byaml/TurboCourseMuunt/Matrix2DHelper.cs index 77015a64..923bf526 100644 --- a/File_Format_Library/GUI/Byaml/TurboCourseMuunt/Matrix2DHelper.cs +++ b/File_Format_Library/GUI/Byaml/TurboCourseMuunt/Matrix2DHelper.cs @@ -8,7 +8,7 @@ using OpenTK; namespace FirstPlugin.Turbo.CourseMuuntStructs { public class Matrix2DHelper - { + { public static Vector3 RotatePoint(Vector3 translate, float X, float Y, float Z, Vector3 rotate) { Matrix4 rotationX = Matrix4.CreateRotationX(rotate.X); diff --git a/File_Format_Library/GUI/Byaml/TurboCourseMuunt/TurboMunntEditor.cs b/File_Format_Library/GUI/Byaml/TurboCourseMuunt/TurboMunntEditor.cs index 1f1f1b68..10142875 100644 --- a/File_Format_Library/GUI/Byaml/TurboCourseMuunt/TurboMunntEditor.cs +++ b/File_Format_Library/GUI/Byaml/TurboCourseMuunt/TurboMunntEditor.cs @@ -464,10 +464,10 @@ namespace FirstPlugin.Forms for (int frame = 0; frame < PathTime; frame++) { - if (viewport.GL_ControlModern != null) + if (viewport.GL_Control != null) { // viewport.GL_ControlModern.CameraEye = pathLookAtPoint.Translate; - viewport.GL_ControlModern.CameraTarget = pathMovePoint.Translate; + viewport.GL_Control.CameraTarget = pathMovePoint.Translate; viewport.UpdateViewport(); } diff --git a/Switch_Toolbox_Library/Forms/Animation/AnimationPanel.cs b/Switch_Toolbox_Library/Forms/Animation/AnimationPanel.cs index 34e6511d..e4fd2561 100644 --- a/Switch_Toolbox_Library/Forms/Animation/AnimationPanel.cs +++ b/Switch_Toolbox_Library/Forms/Animation/AnimationPanel.cs @@ -277,37 +277,19 @@ namespace Toolbox.Library if (viewport == null) return; - if (viewport.GL_ControlLegacy != null && - !viewport.GL_ControlLegacy.IsDisposed) + if (viewport.GL_Control == null || viewport.GL_Control.IsDisposed || viewport.GL_Control.Disposing) + return; + + if (viewport.GL_Control.InvokeRequired) { - if (viewport.GL_ControlLegacy.InvokeRequired) - { - viewport.GL_ControlLegacy.Invoke((MethodInvoker)delegate { - // Running on the UI thread - viewport.GL_ControlLegacy.Invalidate(); - }); - } - else - { - viewport.GL_ControlLegacy.Invalidate(); - } + viewport.GL_Control.Invoke((MethodInvoker)delegate { + // Running on the UI thread + viewport.GL_Control.Invalidate(); + }); } else { - if (viewport.GL_ControlModern == null || viewport.GL_ControlModern.IsDisposed || viewport.GL_ControlModern.Disposing) - return; - - if (viewport.GL_ControlModern.InvokeRequired) - { - viewport.GL_ControlModern.Invoke((MethodInvoker)delegate { - // Running on the UI thread - viewport.GL_ControlModern.Invalidate(); - }); - } - else - { - viewport.GL_ControlModern.Invalidate(); - } + viewport.GL_Control.Invalidate(); } } @@ -343,7 +325,7 @@ namespace Toolbox.Library private void SetAnimationsToFrame(float frameNum) { - if (currentAnimation == null) + if (currentAnimation == null && stCurrentAnimation == null) return; var viewport = LibraryGUI.GetActiveViewport(); @@ -352,6 +334,8 @@ namespace Toolbox.Library if (stCurrentAnimation != null) { + Console.WriteLine("SetAnimationsToFrame"); + if (frameNum > stCurrentAnimation.FrameCount) return; @@ -449,10 +433,8 @@ namespace Toolbox.Library Viewport viewport = LibraryGUI.GetActiveViewport(); if (viewport != null) { - if (viewport.GL_ControlLegacy != null) - viewport.GL_ControlLegacy.VSync = Runtime.enableVSync; - else - viewport.GL_ControlModern.VSync = Runtime.enableVSync; + if (viewport.GL_Control != null) + viewport.GL_Control.VSync = Runtime.enableVSync; } renderThread = new Thread(new ThreadStart(RenderAndAnimationLoop)); @@ -524,6 +506,8 @@ namespace Toolbox.Library isOpen = false; Dispose(); + Console.WriteLine("Disposeing ANIM PANEL!!"); + } private void panel1_Paint(object sender, PaintEventArgs e) diff --git a/Switch_Toolbox_Library/Forms/Animation/Rewrite/AnimationPanel.cs b/Switch_Toolbox_Library/Forms/Animation/Rewrite/AnimationPanel.cs index d32331b9..f3d3f946 100644 --- a/Switch_Toolbox_Library/Forms/Animation/Rewrite/AnimationPanel.cs +++ b/Switch_Toolbox_Library/Forms/Animation/Rewrite/AnimationPanel.cs @@ -52,10 +52,7 @@ namespace Toolbox.Library if (viewport == null) return null; - if (viewport.GL_ControlModern != null) - return viewport.GL_ControlModern; - else - return viewport.GL_ControlLegacy; + return viewport.GL_Control; } public void SetViewport(OpenTK.GLControl control) diff --git a/Switch_Toolbox_Library/Forms/Viewport.cs b/Switch_Toolbox_Library/Forms/Viewport.cs index cb2507e6..61e99ae0 100644 --- a/Switch_Toolbox_Library/Forms/Viewport.cs +++ b/Switch_Toolbox_Library/Forms/Viewport.cs @@ -35,8 +35,7 @@ namespace Toolbox.Library public List DrawableContainers; public EditorScene scene = new EditorScene(); - public GL_ControlLegacy GL_ControlLegacy; - public GL_ControlModern GL_ControlModern; + public GL_ControlBase GL_Control; Runtime.ViewportEditor editor; @@ -173,12 +172,6 @@ namespace Toolbox.Library public Bitmap CaptureScreenshot(int width, int height, bool enableAlpha) { - GLControl control = null; - if (GL_ControlModern != null) - control = GL_ControlModern; - else - control = GL_ControlLegacy; - Bitmap bitmap = new Bitmap(width, height); return bitmap; } @@ -196,20 +189,14 @@ namespace Toolbox.Library private void LoadViewport() { if (Runtime.UseLegacyGL) - { - GL_ControlLegacy = new GL_ControlLegacy(); - GL_ControlLegacy.Dock = DockStyle.Fill; - - panelViewport.Controls.Add(GL_ControlLegacy); - } + GL_Control = new GL_ControlLegacy(); else - { - GL_ControlModern = new GL_ControlModern(); - GL_ControlModern.Dock = DockStyle.Fill; - GL_ControlModern.VSync = true; + GL_Control = new GL_ControlModern(); - panelViewport.Controls.Add(GL_ControlModern); - } + + GL_Control.Dock = DockStyle.Fill; + GL_Control.VSync = true; + panelViewport.Controls.Add(GL_Control); } public void UpdateGrid() @@ -277,26 +264,21 @@ namespace Toolbox.Library UpdateScene(); } - private void UpdateScene() - { - if (GL_ControlModern != null) - GL_ControlModern.MainDrawable = scene; - if (GL_ControlLegacy != null) - GL_ControlLegacy.MainDrawable = scene; + private void UpdateScene() { + if (GL_Control != null) + GL_Control.MainDrawable = scene; } public void UpdateViewport() { if (SuppressUpdating) return; - if (GL_ControlModern != null) - GL_ControlModern.Refresh(); - if (GL_ControlLegacy != null) - GL_ControlLegacy.Refresh(); + if (GL_Control != null) + GL_Control.Refresh(); } public void RenderToTexture() { - if (GL_ControlModern == null) + if (GL_Control == null) return; int Framebuffer = 0; @@ -325,55 +307,31 @@ namespace Toolbox.Library } public void LoadViewportRuntimeValues() { - if (GL_ControlLegacy != null) + if (GL_Control != null) { switch (Runtime.cameraMovement) { case Runtime.CameraMovement.Inspect: - GL_ControlLegacy.ActiveCamera = new InspectCamera(Runtime.MaxCameraSpeed); + GL_Control.ActiveCamera = new InspectCamera(Runtime.MaxCameraSpeed); break; case Runtime.CameraMovement.Walk: - GL_ControlLegacy.ActiveCamera = new WalkaroundCamera(Runtime.MaxCameraSpeed); + GL_Control.ActiveCamera = new WalkaroundCamera(Runtime.MaxCameraSpeed); break; } - GL_ControlLegacy.Stereoscopy = Runtime.stereoscopy; - GL_ControlLegacy.ZNear = Runtime.CameraNear; - GL_ControlLegacy.ZFar = Runtime.CameraFar; - } - else - { - switch (Runtime.cameraMovement) - { - case Runtime.CameraMovement.Inspect: - GL_ControlModern.ActiveCamera = new InspectCamera(Runtime.MaxCameraSpeed); - break; - case Runtime.CameraMovement.Walk: - GL_ControlModern.ActiveCamera = new WalkaroundCamera(Runtime.MaxCameraSpeed); - break; - } - GL_ControlModern.Stereoscopy = Runtime.stereoscopy; - GL_ControlModern.ZNear = Runtime.CameraNear; - GL_ControlModern.ZFar = Runtime.CameraFar; - + GL_Control.Stereoscopy = Runtime.stereoscopy; + GL_Control.ZNear = Runtime.CameraNear; + GL_Control.ZFar = Runtime.CameraFar; } } public void SetupViewportRuntimeValues() { - if (GL_ControlLegacy != null) + if (GL_Control != null) { - if (GL_ControlLegacy.ActiveCamera is InspectCamera) + if (GL_Control.ActiveCamera is InspectCamera) Runtime.cameraMovement = Runtime.CameraMovement.Inspect; - if (GL_ControlLegacy.ActiveCamera is WalkaroundCamera) + if (GL_Control.ActiveCamera is WalkaroundCamera) Runtime.cameraMovement = Runtime.CameraMovement.Walk; - Runtime.stereoscopy = GL_ControlLegacy.Stereoscopy; - } - else - { - if (GL_ControlModern.ActiveCamera is InspectCamera) - Runtime.cameraMovement = Runtime.CameraMovement.Inspect; - if (GL_ControlModern.ActiveCamera is WalkaroundCamera) - Runtime.cameraMovement = Runtime.CameraMovement.Walk; - Runtime.stereoscopy = GL_ControlModern.Stereoscopy; + Runtime.stereoscopy = GL_Control.Stereoscopy; } } @@ -397,8 +355,8 @@ namespace Toolbox.Library private void reloadShadersToolStripMenuItem_Click(object sender, EventArgs e) { - if (GL_ControlModern != null) - GL_ControlModern.ReloadShaders(); + if (GL_Control != null && GL_Control is GL_ControlModern) + ((GL_ControlModern)GL_Control).ReloadShaders(); } private void resetPoseToolStripMenuItem_Click(object sender, EventArgs e) @@ -407,7 +365,8 @@ namespace Toolbox.Library if (animationPanel1 != null) { - if (animationPanel1.CurrentAnimation != null) + if (animationPanel1.CurrentAnimation != null || + animationPanel1.CurrentSTAnimation != null) animationPanel1.ResetModels(); UpdateViewport(); @@ -498,39 +457,25 @@ namespace Toolbox.Library { int pickingBuffer = (int)CameraPick; - if (GL_ControlModern != null) - GL_ControlModern.ApplyCameraOrientation(pickingBuffer); - else - GL_ControlModern.ApplyCameraOrientation(pickingBuffer); + if (GL_Control != null) + GL_Control.ApplyCameraOrientation(pickingBuffer); UpdateViewport(); } private void toOriginToolStripMenuItem_Click(object sender, EventArgs e) { - if (GL_ControlLegacy != null) - { - GL_ControlLegacy.ResetCamera(false); - GL_ControlLegacy.Refresh(); - } - else - { - GL_ControlModern.ResetCamera(false); - GL_ControlModern.Refresh(); + if (GL_Control != null) { + GL_Control.ResetCamera(false); + GL_Control.Refresh(); } } private void toActiveModelToolStripMenuItem_Click(object sender, EventArgs e) { - if (GL_ControlLegacy != null) - { - GL_ControlLegacy.ResetCamera(true); - GL_ControlLegacy.Refresh(); - } - else - { - GL_ControlModern.ResetCamera(true); - GL_ControlModern.Refresh(); + if (GL_Control != null) { + GL_Control.ResetCamera(true); + GL_Control.Refresh(); } } @@ -550,6 +495,9 @@ namespace Toolbox.Library for (int i = 0; i < DrawableContainers.Count; i++) { + if (i == index) + CenterCamera(GL_Control, new List() { DrawableContainers[i] }); + for (int a = 0; a < DrawableContainers[i].Drawables.Count; a++) { if (i == index) @@ -596,6 +544,32 @@ namespace Toolbox.Library } } + public void CenterCamera(GL_ControlBase control, List Drawables) + { + if (!Runtime.FrameCamera) + return; + + var spheres = new List(); + for (int i = 0; i < Drawables.Count; i++) + { + foreach (var drawable in Drawables[i].Drawables) + { + if (drawable is IMeshContainer) + { + for (int m = 0; m < ((IMeshContainer)drawable).Meshes.Count; m++) + { + var mesh = ((IMeshContainer)drawable).Meshes[m]; + var vertexPositions = mesh.vertices.Select(x => x.pos).Distinct(); + spheres.Add(control.GenerateBoundingSphere(vertexPositions)); + } + } + } + } + + if (spheres.Count > 0) + control.FrameSelect(spheres); + } + private void uVViewerToolStripMenuItem_Click(object sender, EventArgs e) { if (!Runtime.UseOpenGL) @@ -609,23 +583,15 @@ namespace Toolbox.Library uvEditor1.Show(this); } - public GLControl GetActiveControl() - { - if (GL_ControlModern != null) - return GL_ControlModern; - else - return GL_ControlLegacy; - } - public void SaveScreenshot() { - var control = GetActiveControl(); + if (GL_Control == null) return; SaveFileDialog sfd = new SaveFileDialog(); sfd.Filter = BitmapExtension.FileFilter; if (sfd.ShowDialog() == DialogResult.OK) { - CreateScreenshot(control.Width, control.Height, false).Save(sfd.FileName); + CreateScreenshot(GL_Control.Width, GL_Control.Height, false).Save(sfd.FileName); } } @@ -659,10 +625,8 @@ namespace Toolbox.Library Runtime.cameraMovement = Runtime.CameraMovement.Inspect; } - if (GL_ControlModern != null) - GL_ControlModern.ResetCamera(Runtime.FrameCamera); - else - GL_ControlModern.ResetCamera(Runtime.FrameCamera); + if (GL_Control != null) + GL_Control.ResetCamera(Runtime.FrameCamera); LoadViewportRuntimeValues(); UpdateViewport();