improving path drawing
This commit is contained in:
parent
574eed06cd
commit
823b664127
8 changed files with 93 additions and 68 deletions
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue