improving path drawing

This commit is contained in:
LarsBrubaker 2020-10-11 19:29:42 -07:00
parent 574eed06cd
commit 823b664127
8 changed files with 93 additions and 68 deletions

View file

@ -42,8 +42,8 @@ using MatterHackers.Agg.VertexSource;
using MatterHackers.DataConverters3D;
using MatterHackers.Localizations;
using MatterHackers.MarchingSquares;
using MatterHackers.MatterControl.DesignTools.Operations;
using MatterHackers.MatterControl.PartPreviewWindow;
using MatterHackers.RenderOpenGl.OpenGl;
using MatterHackers.VectorMath;
using Newtonsoft.Json;
using Polygon = System.Collections.Generic.List<ClipperLib.IntPoint>;
@ -199,68 +199,9 @@ namespace MatterHackers.MatterControl.DesignTools
object3DControlsLayer.AddControls(ControlTypes.Standard2D);
}
public static void DrawPath(IObject3D item)
{
if (item is IPathObject pathObject)
{
if (pathObject.VertexSource == null)
{
return;
}
bool first = true;
var lastPosition = Vector2.Zero;
var aabb = item.VisibleMeshes().FirstOrDefault().GetAxisAlignedBoundingBox();
var firstMove = Vector2.Zero;
foreach (var vertex in pathObject.VertexSource.Vertices())
{
var position = vertex.position;
if (first)
{
GL.PushMatrix();
GL.PushAttrib(AttribMask.EnableBit);
GL.MultMatrix(item.WorldMatrix().GetAsFloatArray());
GL.Disable(EnableCap.Texture2D);
GL.Disable(EnableCap.Blend);
GL.Begin(BeginMode.Lines);
GL.Color4(255, 0, 0, 255);
}
if (vertex.IsMoveTo)
{
firstMove = position;
}
else if (vertex.IsLineTo)
{
GL.Vertex3(lastPosition.X, lastPosition.Y, aabb.MaxXYZ.Z + 0.002);
GL.Vertex3(position.X, position.Y, aabb.MaxXYZ.Z + 0.002);
}
else if (vertex.IsClose)
{
GL.Vertex3(firstMove.X, firstMove.Y, aabb.MaxXYZ.Z + 0.002);
GL.Vertex3(lastPosition.X, lastPosition.Y, aabb.MaxXYZ.Z + 0.002);
}
lastPosition = position;
first = false;
}
// if we drew anything
if (!first)
{
GL.End();
GL.PopAttrib();
GL.PopMatrix();
}
}
}
public void DrawEditor(Object3DControlsLayer layer, List<Object3DView> transparentMeshes, DrawEventArgs e)
{
ImageToPathObject3D.DrawPath(this);
this.DrawPath();
}
public void GenerateMarchingSquaresAndLines(Action<double, string> progressReporter, ImageBuffer image, IThresholdFunction thresholdFunction)

View file

@ -27,6 +27,7 @@ of the authors and should not be interpreted as representing official policies,
either expressed or implied, of the FreeBSD Project.
*/
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
@ -36,15 +37,17 @@ using MatterHackers.Agg.VertexSource;
using MatterHackers.DataConverters3D;
using MatterHackers.DataConverters3D.UndoCommands;
using MatterHackers.Localizations;
using MatterHackers.MatterControl.DesignTools.Operations;
using MatterHackers.MatterControl.PartPreviewWindow;
using MatterHackers.PolygonMesh;
using MatterHackers.RenderOpenGl;
using MatterHackers.VectorMath;
using Newtonsoft.Json;
namespace MatterHackers.MatterControl.DesignTools
{
public class RevolveObject3D : Object3D
public class RevolveObject3D : Object3D, IEditorDraw
{
public double AxisPosition { get; set; } = 0;
@ -124,6 +127,28 @@ namespace MatterHackers.MatterControl.DesignTools
}
}
public void DrawEditor(Object3DControlsLayer layer, List<Object3DView> transparentMeshes, DrawEventArgs e)
{
var child = this.Children.FirstOrDefault();
if (child is IPathObject pathObject)
{
// draw the path
child.DrawPath();
// draw the line that is the rotation point
var aabb = this.GetAxisAlignedBoundingBox();
var vertexSource = this.VertexSource.Transform(Matrix);
var bounds = vertexSource.GetBounds();
var lineX = bounds.Left + AxisPosition;
var start = new Vector3(lineX, aabb.MinXYZ.Y, aabb.MinXYZ.Z);
var end = new Vector3(lineX, aabb.MaxXYZ.Y, aabb.MinXYZ.Z);
layer.World.Render3DLine(start, end, Color.Red, true);
layer.World.Render3DLine(start, end, Color.Red.WithAlpha(20), false);
}
}
public override Task Rebuild()
{
this.DebugDepth("Rebuild");
@ -153,7 +178,7 @@ namespace MatterHackers.MatterControl.DesignTools
null,
(reporter, cancellationToken) =>
{
var vertexSource = this.VertexSource;
var vertexSource = this.VertexSource.Transform(Matrix);
var bounds = vertexSource.GetBounds();
vertexSource = vertexSource.Translate(-bounds.Left - AxisPosition, 0);
Mesh mesh = null;

View file

@ -40,6 +40,7 @@ using MatterHackers.DataConverters2D;
using MatterHackers.DataConverters3D;
using MatterHackers.DataConverters3D.UndoCommands;
using MatterHackers.MatterControl.PartPreviewWindow.View3D;
using MatterHackers.RenderOpenGl.OpenGl;
using MatterHackers.VectorMath;
namespace MatterHackers.MatterControl.DesignTools.Operations
@ -89,6 +90,64 @@ namespace MatterHackers.MatterControl.DesignTools.Operations
return 0;
}
public static void DrawPath(this IObject3D item)
{
if (item is IPathObject pathObject)
{
if (pathObject.VertexSource == null)
{
return;
}
bool first = true;
var lastPosition = Vector2.Zero;
var aabb = item.VisibleMeshes().FirstOrDefault().GetAxisAlignedBoundingBox();
var firstMove = Vector2.Zero;
foreach (var vertex in pathObject.VertexSource.Vertices())
{
var position = vertex.position;
if (first)
{
GL.PushMatrix();
GL.PushAttrib(AttribMask.EnableBit);
GL.MultMatrix(item.WorldMatrix().GetAsFloatArray());
GL.Disable(EnableCap.Texture2D);
GL.Disable(EnableCap.Blend);
GL.Begin(BeginMode.Lines);
GL.Color4(255, 0, 0, 255);
}
if (vertex.IsMoveTo)
{
firstMove = position;
}
else if (vertex.IsLineTo)
{
GL.Vertex3(lastPosition.X, lastPosition.Y, aabb.MaxXYZ.Z + 0.002);
GL.Vertex3(position.X, position.Y, aabb.MaxXYZ.Z + 0.002);
}
else if (vertex.IsClose)
{
GL.Vertex3(firstMove.X, firstMove.Y, aabb.MaxXYZ.Z + 0.002);
GL.Vertex3(lastPosition.X, lastPosition.Y, aabb.MaxXYZ.Z + 0.002);
}
lastPosition = position;
first = false;
}
// if we drew anything
if (!first)
{
GL.End();
GL.PopAttrib();
GL.PopMatrix();
}
}
}
public static bool IsRoot(this IObject3D object3D)
{
return object3D.Parent == null;

View file

@ -132,7 +132,7 @@ namespace MatterHackers.MatterControl.DesignTools.Operations
public void DrawEditor(Object3DControlsLayer layer, List<Object3DView> transparentMeshes, DrawEventArgs e)
{
ImageToPathObject3D.DrawPath(this);
this.DrawPath();
}
}
}

View file

@ -149,7 +149,7 @@ namespace MatterHackers.MatterControl.DesignTools.Operations
public void DrawEditor(Object3DControlsLayer layer, List<Object3DView> transparentMeshes, DrawEventArgs e)
{
ImageToPathObject3D.DrawPath(this);
this.DrawPath();
}
}
}

View file

@ -167,7 +167,7 @@ namespace MatterHackers.MatterControl.DesignTools.Operations
public void DrawEditor(Object3DControlsLayer layer, List<Object3DView> transparentMeshes, DrawEventArgs e)
{
ImageToPathObject3D.DrawPath(this);
this.DrawPath();
}
}
}

View file

@ -182,7 +182,7 @@ namespace MatterHackers.MatterControl.DesignTools
public void DrawEditor(Object3DControlsLayer layer, List<Object3DView> transparentMeshes, DrawEventArgs e)
{
ImageToPathObject3D.DrawPath(this);
this.DrawPath();
}
}
}

@ -1 +1 @@
Subproject commit 49170baf0c5621c7b41099337c7c3328c94d2b62
Subproject commit bc8e5e108256998b3d2c5381c2fa09435dec8889