Some cleanup

This commit is contained in:
KillzXGaming 2019-11-23 16:06:33 -05:00
parent 211b530c45
commit 940994604a
9 changed files with 95 additions and 148 deletions

View file

@ -87,7 +87,6 @@ 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(); ShaderLoader.CafeShader.Disable();

View file

@ -94,6 +94,9 @@ namespace LayoutBXLYT
shader.SetInt("textures1", 0); shader.SetInt("textures1", 0);
shader.SetInt("textures2", 0); shader.SetInt("textures2", 0);
if (Runtime.DEVELOPER_DEBUG_MODE)
return;
BindTextureUniforms(shader, material); BindTextureUniforms(shader, material);
if (material.TextureMaps.Length > 0 || Runtime.LayoutEditor.Shading == Runtime.LayoutEditor.DebugShading.UVTestPattern) if (material.TextureMaps.Length > 0 || Runtime.LayoutEditor.Shading == Runtime.LayoutEditor.DebugShading.UVTestPattern)

View file

@ -259,7 +259,7 @@ namespace FirstPlugin
GL.Enable(EnableCap.Texture2D); GL.Enable(EnableCap.Texture2D);
} }
public void CenterCamera(GL_ControlModern control) public void CenterCamera(GL_ControlBase control)
{ {
if (!Runtime.FrameCamera) if (!Runtime.FrameCamera)
return; return;

View file

@ -141,9 +141,9 @@ namespace FirstPlugin.Forms
if (!Runtime.UseOpenGL || !DisplayViewport) if (!Runtime.UseOpenGL || !DisplayViewport)
return; return;
if (viewport.GL_ControlModern != null) if (viewport.GL_Control != null)
{ {
Renderer.CenterCamera(viewport.GL_ControlModern); Renderer.CenterCamera(viewport.GL_Control);
viewport.UpdateViewport(); viewport.UpdateViewport();
} }
} }

View file

@ -464,10 +464,10 @@ namespace FirstPlugin.Forms
for (int frame = 0; frame < PathTime; frame++) 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.CameraEye = pathLookAtPoint.Translate;
viewport.GL_ControlModern.CameraTarget = pathMovePoint.Translate; viewport.GL_Control.CameraTarget = pathMovePoint.Translate;
viewport.UpdateViewport(); viewport.UpdateViewport();
} }

View file

@ -277,37 +277,19 @@ namespace Toolbox.Library
if (viewport == null) if (viewport == null)
return; return;
if (viewport.GL_ControlLegacy != null && if (viewport.GL_Control == null || viewport.GL_Control.IsDisposed || viewport.GL_Control.Disposing)
!viewport.GL_ControlLegacy.IsDisposed)
{
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();
}
}
else
{
if (viewport.GL_ControlModern == null || viewport.GL_ControlModern.IsDisposed || viewport.GL_ControlModern.Disposing)
return; return;
if (viewport.GL_ControlModern.InvokeRequired) if (viewport.GL_Control.InvokeRequired)
{ {
viewport.GL_ControlModern.Invoke((MethodInvoker)delegate { viewport.GL_Control.Invoke((MethodInvoker)delegate {
// Running on the UI thread // Running on the UI thread
viewport.GL_ControlModern.Invalidate(); viewport.GL_Control.Invalidate();
}); });
} }
else else
{ {
viewport.GL_ControlModern.Invalidate(); viewport.GL_Control.Invalidate();
}
} }
} }
@ -343,7 +325,7 @@ namespace Toolbox.Library
private void SetAnimationsToFrame(float frameNum) private void SetAnimationsToFrame(float frameNum)
{ {
if (currentAnimation == null) if (currentAnimation == null && stCurrentAnimation == null)
return; return;
var viewport = LibraryGUI.GetActiveViewport(); var viewport = LibraryGUI.GetActiveViewport();
@ -352,6 +334,8 @@ namespace Toolbox.Library
if (stCurrentAnimation != null) if (stCurrentAnimation != null)
{ {
Console.WriteLine("SetAnimationsToFrame");
if (frameNum > stCurrentAnimation.FrameCount) if (frameNum > stCurrentAnimation.FrameCount)
return; return;
@ -449,10 +433,8 @@ namespace Toolbox.Library
Viewport viewport = LibraryGUI.GetActiveViewport(); Viewport viewport = LibraryGUI.GetActiveViewport();
if (viewport != null) if (viewport != null)
{ {
if (viewport.GL_ControlLegacy != null) if (viewport.GL_Control != null)
viewport.GL_ControlLegacy.VSync = Runtime.enableVSync; viewport.GL_Control.VSync = Runtime.enableVSync;
else
viewport.GL_ControlModern.VSync = Runtime.enableVSync;
} }
renderThread = new Thread(new ThreadStart(RenderAndAnimationLoop)); renderThread = new Thread(new ThreadStart(RenderAndAnimationLoop));
@ -524,6 +506,8 @@ namespace Toolbox.Library
isOpen = false; isOpen = false;
Dispose(); Dispose();
Console.WriteLine("Disposeing ANIM PANEL!!");
} }
private void panel1_Paint(object sender, PaintEventArgs e) private void panel1_Paint(object sender, PaintEventArgs e)

View file

@ -52,10 +52,7 @@ namespace Toolbox.Library
if (viewport == null) if (viewport == null)
return null; return null;
if (viewport.GL_ControlModern != null) return viewport.GL_Control;
return viewport.GL_ControlModern;
else
return viewport.GL_ControlLegacy;
} }
public void SetViewport(OpenTK.GLControl control) public void SetViewport(OpenTK.GLControl control)

View file

@ -35,8 +35,7 @@ namespace Toolbox.Library
public List<DrawableContainer> DrawableContainers; public List<DrawableContainer> DrawableContainers;
public EditorScene scene = new EditorScene(); public EditorScene scene = new EditorScene();
public GL_ControlLegacy GL_ControlLegacy; public GL_ControlBase GL_Control;
public GL_ControlModern GL_ControlModern;
Runtime.ViewportEditor editor; Runtime.ViewportEditor editor;
@ -173,12 +172,6 @@ namespace Toolbox.Library
public Bitmap CaptureScreenshot(int width, int height, bool enableAlpha) 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); Bitmap bitmap = new Bitmap(width, height);
return bitmap; return bitmap;
} }
@ -196,20 +189,14 @@ namespace Toolbox.Library
private void LoadViewport() private void LoadViewport()
{ {
if (Runtime.UseLegacyGL) if (Runtime.UseLegacyGL)
{ GL_Control = new GL_ControlLegacy();
GL_ControlLegacy = new GL_ControlLegacy();
GL_ControlLegacy.Dock = DockStyle.Fill;
panelViewport.Controls.Add(GL_ControlLegacy);
}
else else
{ GL_Control = new GL_ControlModern();
GL_ControlModern = new GL_ControlModern();
GL_ControlModern.Dock = DockStyle.Fill;
GL_ControlModern.VSync = true;
panelViewport.Controls.Add(GL_ControlModern);
} GL_Control.Dock = DockStyle.Fill;
GL_Control.VSync = true;
panelViewport.Controls.Add(GL_Control);
} }
public void UpdateGrid() public void UpdateGrid()
@ -277,26 +264,21 @@ namespace Toolbox.Library
UpdateScene(); UpdateScene();
} }
private void UpdateScene() private void UpdateScene() {
{ if (GL_Control != null)
if (GL_ControlModern != null) GL_Control.MainDrawable = scene;
GL_ControlModern.MainDrawable = scene;
if (GL_ControlLegacy != null)
GL_ControlLegacy.MainDrawable = scene;
} }
public void UpdateViewport() public void UpdateViewport()
{ {
if (SuppressUpdating) return; if (SuppressUpdating) return;
if (GL_ControlModern != null) if (GL_Control != null)
GL_ControlModern.Refresh(); GL_Control.Refresh();
if (GL_ControlLegacy != null)
GL_ControlLegacy.Refresh();
} }
public void RenderToTexture() public void RenderToTexture()
{ {
if (GL_ControlModern == null) if (GL_Control == null)
return; return;
int Framebuffer = 0; int Framebuffer = 0;
@ -325,55 +307,31 @@ namespace Toolbox.Library
} }
public void LoadViewportRuntimeValues() public void LoadViewportRuntimeValues()
{ {
if (GL_ControlLegacy != null) if (GL_Control != null)
{ {
switch (Runtime.cameraMovement) switch (Runtime.cameraMovement)
{ {
case Runtime.CameraMovement.Inspect: case Runtime.CameraMovement.Inspect:
GL_ControlLegacy.ActiveCamera = new InspectCamera(Runtime.MaxCameraSpeed); GL_Control.ActiveCamera = new InspectCamera(Runtime.MaxCameraSpeed);
break; break;
case Runtime.CameraMovement.Walk: case Runtime.CameraMovement.Walk:
GL_ControlLegacy.ActiveCamera = new WalkaroundCamera(Runtime.MaxCameraSpeed); GL_Control.ActiveCamera = new WalkaroundCamera(Runtime.MaxCameraSpeed);
break; break;
} }
GL_ControlLegacy.Stereoscopy = Runtime.stereoscopy; GL_Control.Stereoscopy = Runtime.stereoscopy;
GL_ControlLegacy.ZNear = Runtime.CameraNear; GL_Control.ZNear = Runtime.CameraNear;
GL_ControlLegacy.ZFar = Runtime.CameraFar; GL_Control.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;
} }
} }
public void SetupViewportRuntimeValues() 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; Runtime.cameraMovement = Runtime.CameraMovement.Inspect;
if (GL_ControlLegacy.ActiveCamera is WalkaroundCamera) if (GL_Control.ActiveCamera is WalkaroundCamera)
Runtime.cameraMovement = Runtime.CameraMovement.Walk; Runtime.cameraMovement = Runtime.CameraMovement.Walk;
Runtime.stereoscopy = GL_ControlLegacy.Stereoscopy; Runtime.stereoscopy = GL_Control.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;
} }
} }
@ -397,8 +355,8 @@ namespace Toolbox.Library
private void reloadShadersToolStripMenuItem_Click(object sender, EventArgs e) private void reloadShadersToolStripMenuItem_Click(object sender, EventArgs e)
{ {
if (GL_ControlModern != null) if (GL_Control != null && GL_Control is GL_ControlModern)
GL_ControlModern.ReloadShaders(); ((GL_ControlModern)GL_Control).ReloadShaders();
} }
private void resetPoseToolStripMenuItem_Click(object sender, EventArgs e) private void resetPoseToolStripMenuItem_Click(object sender, EventArgs e)
@ -407,7 +365,8 @@ namespace Toolbox.Library
if (animationPanel1 != null) if (animationPanel1 != null)
{ {
if (animationPanel1.CurrentAnimation != null) if (animationPanel1.CurrentAnimation != null ||
animationPanel1.CurrentSTAnimation != null)
animationPanel1.ResetModels(); animationPanel1.ResetModels();
UpdateViewport(); UpdateViewport();
@ -498,39 +457,25 @@ namespace Toolbox.Library
{ {
int pickingBuffer = (int)CameraPick; int pickingBuffer = (int)CameraPick;
if (GL_ControlModern != null) if (GL_Control != null)
GL_ControlModern.ApplyCameraOrientation(pickingBuffer); GL_Control.ApplyCameraOrientation(pickingBuffer);
else
GL_ControlModern.ApplyCameraOrientation(pickingBuffer);
UpdateViewport(); UpdateViewport();
} }
private void toOriginToolStripMenuItem_Click(object sender, EventArgs e) private void toOriginToolStripMenuItem_Click(object sender, EventArgs e)
{ {
if (GL_ControlLegacy != null) if (GL_Control != null) {
{ GL_Control.ResetCamera(false);
GL_ControlLegacy.ResetCamera(false); GL_Control.Refresh();
GL_ControlLegacy.Refresh();
}
else
{
GL_ControlModern.ResetCamera(false);
GL_ControlModern.Refresh();
} }
} }
private void toActiveModelToolStripMenuItem_Click(object sender, EventArgs e) private void toActiveModelToolStripMenuItem_Click(object sender, EventArgs e)
{ {
if (GL_ControlLegacy != null) if (GL_Control != null) {
{ GL_Control.ResetCamera(true);
GL_ControlLegacy.ResetCamera(true); GL_Control.Refresh();
GL_ControlLegacy.Refresh();
}
else
{
GL_ControlModern.ResetCamera(true);
GL_ControlModern.Refresh();
} }
} }
@ -550,6 +495,9 @@ namespace Toolbox.Library
for (int i = 0; i < DrawableContainers.Count; i++) for (int i = 0; i < DrawableContainers.Count; i++)
{ {
if (i == index)
CenterCamera(GL_Control, new List<DrawableContainer>() { DrawableContainers[i] });
for (int a = 0; a < DrawableContainers[i].Drawables.Count; a++) for (int a = 0; a < DrawableContainers[i].Drawables.Count; a++)
{ {
if (i == index) if (i == index)
@ -596,6 +544,32 @@ namespace Toolbox.Library
} }
} }
public void CenterCamera(GL_ControlBase control, List<DrawableContainer> Drawables)
{
if (!Runtime.FrameCamera)
return;
var spheres = new List<Vector4>();
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) private void uVViewerToolStripMenuItem_Click(object sender, EventArgs e)
{ {
if (!Runtime.UseOpenGL) if (!Runtime.UseOpenGL)
@ -609,23 +583,15 @@ namespace Toolbox.Library
uvEditor1.Show(this); uvEditor1.Show(this);
} }
public GLControl GetActiveControl()
{
if (GL_ControlModern != null)
return GL_ControlModern;
else
return GL_ControlLegacy;
}
public void SaveScreenshot() public void SaveScreenshot()
{ {
var control = GetActiveControl(); if (GL_Control == null) return;
SaveFileDialog sfd = new SaveFileDialog(); SaveFileDialog sfd = new SaveFileDialog();
sfd.Filter = BitmapExtension.FileFilter; sfd.Filter = BitmapExtension.FileFilter;
if (sfd.ShowDialog() == DialogResult.OK) 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; Runtime.cameraMovement = Runtime.CameraMovement.Inspect;
} }
if (GL_ControlModern != null) if (GL_Control != null)
GL_ControlModern.ResetCamera(Runtime.FrameCamera); GL_Control.ResetCamera(Runtime.FrameCamera);
else
GL_ControlModern.ResetCamera(Runtime.FrameCamera);
LoadViewportRuntimeValues(); LoadViewportRuntimeValues();
UpdateViewport(); UpdateViewport();