Fix path subtract

This commit is contained in:
LarsBrubaker 2022-08-14 21:30:40 -07:00
parent 33cb9dafd2
commit 844b3fdb14
4 changed files with 25 additions and 16 deletions

View file

@ -120,16 +120,16 @@ namespace MatterHackers.MatterControl.DesignTools.Operations
VertexStorage = path.Offset(Inflate.Value(this), GetJoinType(Style));
}
internal static JoinType GetJoinType(ExpandStyles style)
public static JoinType GetJoinType(ExpandStyles style)
{
ClipperLib.JoinType joinType = ClipperLib.JoinType.jtMiter;
ClipperLib.JoinType joinType = JoinType.jtMiter;
switch (style)
{
case ExpandStyles.Flat:
joinType = ClipperLib.JoinType.jtSquare;
joinType = JoinType.jtSquare;
break;
case ExpandStyles.Round:
joinType = ClipperLib.JoinType.jtRound;
joinType = JoinType.jtRound;
break;
}

View file

@ -39,6 +39,7 @@ using MatterHackers.Agg.VertexSource;
using MatterHackers.DataConverters2D;
using MatterHackers.DataConverters3D;
using MatterHackers.Localizations;
using MatterHackers.MatterControl.DesignTools.Operations;
using MatterHackers.MatterControl.PartPreviewWindow;
using MatterHackers.PolygonMesh.Csg;
using MatterHackers.PolygonMesh.Processors;
@ -90,6 +91,9 @@ namespace MatterHackers.MatterControl.DesignTools
[Slider(0, 10, Easing.EaseType.Quadratic, snapDistance: .1)]
public DoubleOrExpression InfillAmount { get; set; } = 3;
[EnumDisplay(Mode = EnumDisplayAttribute.PresentationMode.Buttons)]
public ExpandStyles Style { get; set; } = ExpandStyles.Round;
[DisplayName("Height")]
[Slider(1, 50, Easing.EaseType.Quadratic, useSnappingGrid: true)]
public DoubleOrExpression ExtrusionHeight { get; set; } = 5;
@ -368,18 +372,19 @@ namespace MatterHackers.MatterControl.DesignTools
var infillAmount = InfillAmount.Value(this);
var baseSize = BaseSize.Value(this);
var extrusionHeight = ExtrusionHeight.Value(this);
var joinType = InflatePathObject3D.GetJoinType(Style);
if (BaseType == BaseTypes.Outline
&& infillAmount > 0)
{
basePolygons = polysToOffset.Offset((baseSize + infillAmount) * scalingForClipper);
basePolygons = basePolygons.Offset(-infillAmount * scalingForClipper);
basePolygons = polysToOffset.Offset((baseSize + infillAmount) * scalingForClipper, joinType);
basePolygons = basePolygons.Offset(-infillAmount * scalingForClipper, joinType);
}
else
{
basePolygons = polysToOffset.Offset(baseSize * scalingForClipper);
basePolygons = polysToOffset.Offset(baseSize * scalingForClipper, joinType);
}
basePolygons = ClipperLib.Clipper.CleanPolygons(basePolygons, 10);
basePolygons = Clipper.CleanPolygons(basePolygons, 10);
VertexStorage rawVectorShape = basePolygons.PolygonToPathStorage();
var vectorShape = new VertexSourceApplyTransform(rawVectorShape, Affine.NewScaling(1.0 / scalingForClipper));
@ -414,6 +419,7 @@ namespace MatterHackers.MatterControl.DesignTools
changeSet.Add(nameof(InfillAmount), BaseType == BaseTypes.Outline);
changeSet.Add(nameof(Centering), BaseType == BaseTypes.Circle);
changeSet.Add(nameof(ExtrusionHeight), BaseType != BaseTypes.None);
changeSet.Add(nameof(Style), BaseType != BaseTypes.Circle);
var vertexSource = GetVertexSource();
var meshSource = this.Descendants<IObject3D>().Where((i) => i.Mesh != null);

View file

@ -123,14 +123,17 @@ namespace MatterHackers.MatterControl.PartPreviewWindow.View3D
}
// set the mesh to show the path
var extrudeMesh = this.GetVertexSource().Extrude(Constants.PathPolygonsHeight);
if(extrudeMesh.Vertices.Count() > 5)
if (this.GetVertexSource() != null)
{
this.Mesh = extrudeMesh;
}
else
{
this.Mesh = null;
var extrudeMesh = this.GetVertexSource().Extrude(Constants.PathPolygonsHeight);
if (extrudeMesh.Vertices.Count() > 5)
{
this.Mesh = extrudeMesh;
}
else
{
this.Mesh = null;
}
}
UiThread.RunOnIdle(() =>

@ -1 +1 @@
Subproject commit 0fee6ab0d2d61107717114258b06182815bc11d7
Subproject commit c2b8646bf496a0ecf99338e513cf96cb6fdeed17