Merge pull request #3112 from jlewin/design_tools

Add AggVisualizers project
This commit is contained in:
johnlewin 2018-03-23 16:58:24 -07:00 committed by GitHub
commit 1bed1df282
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 12 additions and 140 deletions

View file

@ -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);

View file

@ -191,7 +191,6 @@
<Compile Include="PartPreviewWindow\View3D\Actions\IntersectionEditor.cs" />
<Compile Include="PartPreviewWindow\View3D\Actions\MeshWrapper.cs" />
<Compile Include="PartPreviewWindow\View3D\Actions\SubtractEditor.cs" />
<Compile Include="PartPreviewWindow\View3D\LightingData.cs" />
<Compile Include="PartPreviewWindow\View3D\PrinterBar\CancelButton.cs" />
<Compile Include="PartPreviewWindow\View3D\PrinterBar\PauseResumeButton.cs" />
<Compile Include="Library\ReadOnlyStreamItem.cs" />

View file

@ -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();
}
}
}

View file

@ -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 };
}
}

View file

@ -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);

@ -1 +1 @@
Subproject commit d831c5bd787e0913d0dc25b1c6b28a162bf73207
Subproject commit 8ccc44c3fe0c884e87665f00762be66952772650