diff --git a/ApplicationView/LogoSpinner.cs b/ApplicationView/LogoSpinner.cs index 311a9fa85..7eac99346 100644 --- a/ApplicationView/LogoSpinner.cs +++ b/ApplicationView/LogoSpinner.cs @@ -82,9 +82,9 @@ namespace MatterHackers.MatterControl world.Translate(new Vector3(0, yOffset, 0)); world.Rotate(Quaternion.FromEulerAngles(new Vector3(rotateX, 0, 0))); - InteractionLayer.SetGlContext(world, screenSpaceBounds, lighting, this.AmbientColor); + GLHelper.SetGlContext(world, screenSpaceBounds, lighting); GLHelper.Render(logoMesh, this.MeshColor, Matrix4X4.CreateRotationY(angle), RenderTypes.Shaded); - InteractionLayer.UnsetGlContext(); + GLHelper.UnsetGlContext(); }; UiThread.SetInterval(widget.Invalidate, .05, () => !widget.HasBeenClosed); diff --git a/MatterControl.csproj b/MatterControl.csproj index 5197b4f5d..37529c87b 100644 --- a/MatterControl.csproj +++ b/MatterControl.csproj @@ -191,7 +191,6 @@ - diff --git a/PartPreviewWindow/View3D/InteractionLayer.cs b/PartPreviewWindow/View3D/InteractionLayer.cs index 9103aa760..50dc07ac3 100644 --- a/PartPreviewWindow/View3D/InteractionLayer.cs +++ b/PartPreviewWindow/View3D/InteractionLayer.cs @@ -36,6 +36,7 @@ using MatterHackers.DataConverters3D; using MatterHackers.MeshVisualizer; using MatterHackers.RayTracer; using MatterHackers.RayTracer.Traceable; +using MatterHackers.RenderOpenGl; using MatterHackers.RenderOpenGl.OpenGl; using MatterHackers.VectorMath; using static MatterHackers.MeshVisualizer.MeshViewerWidget; @@ -82,9 +83,9 @@ namespace MatterHackers.MatterControl.PartPreviewWindow { if (DoOpenGlDrawing) { - SetGlContext(this.World, renderSource.TransformToScreenSpace(renderSource.LocalBounds), lighting); + GLHelper.SetGlContext(this.World, renderSource.TransformToScreenSpace(renderSource.LocalBounds), lighting); OnDrawGlContent(e); - UnsetGlContext(); + GLHelper.UnsetGlContext(); } } @@ -184,7 +185,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow { base.OnMouseMove(mouseEvent); - if (SuppressUiVolumes + if (SuppressUiVolumes || !this.PositionWithinLocalBounds(mouseEvent.X, mouseEvent.Y)) { return; @@ -327,88 +328,5 @@ namespace MatterHackers.MatterControl.PartPreviewWindow DrawGlOpaqueContent?.Invoke(this, e); DrawGlTransparentContent?.Invoke(this, e); } - - private static float[] ambientColor = new float[] { 0, 0, 0, 0 }; - - public static void SetGlContext(WorldView worldView, RectangleDouble screenRect, LightingData lighting) - { - SetGlContext(worldView, screenRect, lighting, ambientColor); - } - - public static void SetGlContext(WorldView worldView, RectangleDouble screenRect, LightingData lighting, float[] ambientColor) - { - GL.ClearDepth(1.0); - GL.Clear(ClearBufferMask.DepthBufferBit); // Clear the Depth Buffer - - GL.PushAttrib(AttribMask.ViewportBit); - GL.Viewport((int)screenRect.Left, (int)screenRect.Bottom, (int)screenRect.Width, (int)screenRect.Height); - - GL.ShadeModel(ShadingModel.Smooth); - - GL.FrontFace(FrontFaceDirection.Ccw); - GL.CullFace(CullFaceMode.Back); - - GL.DepthFunc(DepthFunction.Lequal); - - GL.Disable(EnableCap.DepthTest); - //ClearToGradient(); - - GL.Light(LightName.Light0, LightParameter.Ambient, lighting.ambientLight); - - GL.Light(LightName.Light0, LightParameter.Diffuse, lighting.diffuseLight0); - GL.Light(LightName.Light0, LightParameter.Specular, lighting.specularLight0); - - GL.Light(LightName.Light0, LightParameter.Ambient, ambientColor); - GL.Light(LightName.Light1, LightParameter.Diffuse, lighting.diffuseLight1); - GL.Light(LightName.Light1, LightParameter.Specular, lighting.specularLight1); - - GL.ColorMaterial(MaterialFace.FrontAndBack, ColorMaterialParameter.AmbientAndDiffuse); - - GL.Enable(EnableCap.Light0); - GL.Enable(EnableCap.Light1); - GL.Enable(EnableCap.DepthTest); - GL.Enable(EnableCap.Blend); - GL.Enable(EnableCap.Normalize); - GL.Enable(EnableCap.Lighting); - GL.Enable(EnableCap.ColorMaterial); - - Vector3 lightDirectionVector = new Vector3(lighting.lightDirection0[0], lighting.lightDirection0[1], lighting.lightDirection0[2]); - lightDirectionVector.Normalize(); - lighting.lightDirection0[0] = (float)lightDirectionVector.X; - lighting.lightDirection0[1] = (float)lightDirectionVector.Y; - lighting.lightDirection0[2] = (float)lightDirectionVector.Z; - GL.Light(LightName.Light0, LightParameter.Position, lighting.lightDirection0); - GL.Light(LightName.Light1, LightParameter.Position, lighting.lightDirection1); - - // set the projection matrix - GL.MatrixMode(MatrixMode.Projection); - GL.PushMatrix(); - GL.LoadMatrix(worldView.ProjectionMatrix.GetAsDoubleArray()); - - // set the modelview matrix - GL.MatrixMode(MatrixMode.Modelview); - GL.PushMatrix(); - GL.LoadMatrix(worldView.ModelviewMatrix.GetAsDoubleArray()); - } - - public static void UnsetGlContext() - { - GL.MatrixMode(MatrixMode.Projection); - GL.PopMatrix(); - - GL.MatrixMode(MatrixMode.Modelview); - GL.PopMatrix(); - - GL.Disable(EnableCap.ColorMaterial); - GL.Disable(EnableCap.Lighting); - GL.Disable(EnableCap.Light0); - GL.Disable(EnableCap.Light1); - - GL.Disable(EnableCap.Normalize); - GL.Disable(EnableCap.Blend); - GL.Disable(EnableCap.DepthTest); - - GL.PopAttrib(); - } } } \ No newline at end of file diff --git a/PartPreviewWindow/View3D/LightingData.cs b/PartPreviewWindow/View3D/LightingData.cs deleted file mode 100644 index 514a02df6..000000000 --- a/PartPreviewWindow/View3D/LightingData.cs +++ /dev/null @@ -1,45 +0,0 @@ -/* -Copyright (c) 2017, Lars Brubaker, John Lewin -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - -1. Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. -2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR -ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND -ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -The views and conclusions contained in the software and documentation are those -of the authors and should not be interpreted as representing official policies, -either expressed or implied, of the FreeBSD Project. -*/ - - -namespace MatterHackers.MatterControl.PartPreviewWindow -{ - public class LightingData - { - internal float[] ambientLight = { 0.2f, 0.2f, 0.2f, 1.0f }; - - internal float[] diffuseLight0 = { 0.7f, 0.7f, 0.7f, 1.0f }; - internal float[] specularLight0 = { 0.5f, 0.5f, 0.5f, 1.0f }; - internal float[] lightDirection0 = { -1, -1, 1, 0.0f }; - - internal float[] diffuseLight1 = { 0.5f, 0.5f, 0.5f, 1.0f }; - internal float[] specularLight1 = { 0.3f, 0.3f, 0.3f, 1.0f }; - internal float[] lightDirection1 = { 1, 1, 1, 0.0f }; - } -} \ No newline at end of file diff --git a/PartPreviewWindow/View3D/TumbleCubeControl.cs b/PartPreviewWindow/View3D/TumbleCubeControl.cs index b28a32e13..b025f033c 100644 --- a/PartPreviewWindow/View3D/TumbleCubeControl.cs +++ b/PartPreviewWindow/View3D/TumbleCubeControl.cs @@ -76,8 +76,8 @@ namespace MatterHackers.MatterControl.PartPreviewWindow public override void OnDraw(Graphics2D graphics2D) { - var screenSpcaeBounds = this.TransformToScreenSpace(LocalBounds); - world = new WorldView(screenSpcaeBounds.Width, screenSpcaeBounds.Height); + var screenSpaceBounds = this.TransformToScreenSpace(LocalBounds); + world = new WorldView(screenSpaceBounds.Width, screenSpaceBounds.Height); var forward = -Vector3.UnitZ; var directionForward = Vector3.TransformNormal(forward, interactionLayer.World.InverseModelviewMatrix); @@ -86,9 +86,9 @@ namespace MatterHackers.MatterControl.PartPreviewWindow var directionUp = Vector3.TransformNormal(up, interactionLayer.World.InverseModelviewMatrix); world.RotationMatrix = Matrix4X4.LookAt(Vector3.Zero, directionForward, directionUp); - InteractionLayer.SetGlContext(world, screenSpcaeBounds, lighting); + GLHelper.SetGlContext(world, screenSpaceBounds, lighting); GLHelper.Render(cube, Color.White, Matrix4X4.Identity, RenderTypes.Shaded); - InteractionLayer.UnsetGlContext(); + GLHelper.UnsetGlContext(); base.OnDraw(graphics2D); } @@ -121,7 +121,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow interactionLayer.Invalidate(); } } - else if(world != null + else if(world != null && cubeTraceData != null) // Make sure we don't use the trace data before it is ready { Ray ray = world.GetRayForLocalBounds(mouseEvent.Position); diff --git a/Submodules/agg-sharp b/Submodules/agg-sharp index d831c5bd7..8ccc44c3f 160000 --- a/Submodules/agg-sharp +++ b/Submodules/agg-sharp @@ -1 +1 @@ -Subproject commit d831c5bd787e0913d0dc25b1c6b28a162bf73207 +Subproject commit 8ccc44c3fe0c884e87665f00762be66952772650