parallel_pocket almost done

pull/273/head
abosafia 2024-09-28 00:18:43 +03:00
rodzic 7570035ea4
commit 9e39b0e806
4 zmienionych plików z 34 dodań i 21 usunięć

Wyświetl plik

@ -311,7 +311,7 @@ class camOperation(PropertyGroup):
parallelPocketAngle: FloatProperty(
name="Parallel Pocket Angle",
description="Angle for parallel pocket",
min=0.0,
min=-180,
max=180.0,
default=45.0,
precision=constants.PRECISION,

Wyświetl plik

@ -33,7 +33,7 @@ from . import (
utils,
)
def generate_crosshatch(context, angle, distance, offset, pocket_shape):
def generate_crosshatch(context, angle, distance, offset, pocket_shape, ob = None):
"""Execute the crosshatch generation process based on the provided context.
Args:
@ -45,10 +45,12 @@ def generate_crosshatch(context, angle, distance, offset, pocket_shape):
Returns:
shapely.geometry.MultiLineString: The resulting intersection geometry of the crosshatch.
"""
ob = context.active_object
"""
if ob is None :
ob = context.active_object
else:
bpy.context.view_layer.objects.active = ob
ob.select_set(True)
if ob.data.splines and ob.data.splines[0].type == 'BEZIER':
bpy.ops.object.curve_remove_doubles(merg_distance=0.0001, keep_bezier=True)
else:
@ -57,7 +59,7 @@ def generate_crosshatch(context, angle, distance, offset, pocket_shape):
bpy.ops.object.origin_set(type='ORIGIN_GEOMETRY', center='MEDIAN')
depth = ob.location[2]
shapes = utils.curveToShapely(bpy.context.active_object)
shapes = utils.curveToShapely(ob)
if pocket_shape == 'HULL':
shapes = shapes.convex_hull
@ -144,10 +146,11 @@ class CamCurveHatch(Operator):
layout.prop(self, 'distance')
layout.prop(self, 'offset')
layout.prop(self, 'pocket_shape')
layout.prop(self, 'contour')
layout.prop(self, 'xhatch')
if self.contour:
layout.prop(self, 'contour_separate')
if self.pocket_shape=='POCKET':
layout.prop(self, 'contour')
if self.contour:
layout.prop(self, 'contour_separate')
def execute(self, context):
ob = context.active_object
@ -172,7 +175,7 @@ class CamCurveHatch(Operator):
simple.make_active(obname)
xingra = generate_crosshatch(
context,
self.angle + 1.570796327,
self.angle + pi/2,
self.distance,
xingOffset,
self.pocket_shape,

Wyświetl plik

@ -438,6 +438,8 @@ async def pocket(o):
c_offset += o.skin # add skin
print("Cutter Offset", c_offset)
obname = o.object_name
c_ob =bpy.data.objects[obname]
for ob in o.objects:
if ob.type == 'CURVE':
if ob.data.splines and ob.data.splines[0].type == 'BEZIER':
@ -446,19 +448,26 @@ async def pocket(o):
else:
bpy.ops.object.curve_remove_doubles()
chunksFromCurve = []
# Parallel lines is disabled until finish
use_parallel =False
if use_parallel:
angle = 45
distance = o.dist_between_paths
offset = -c_offset
pocket_shape = ""
# Call the crosshatch generation function
crosshatch_result = generate_crosshatch(bpy.context, angle, distance, offset, pocket_shape)
# Convert crosshatch result into chunks
angle = radians(o.parallelPocketAngle)
distance = o.dist_between_paths
p_l_offset= -c_offset*1.2
pocket_shape = ""
n_angle= angle-pi/2
if o.pocketType == 'PARALLEL':
crosshatch_result = generate_crosshatch(bpy.context, angle, distance, p_l_offset, pocket_shape, c_ob)
nchunks = shapelyToChunks(crosshatch_result, o.min.z)
chunksFromCurve.extend(nchunks)
if o.parallelPocketCrosshatch:
crosshatch_result = generate_crosshatch(bpy.context, n_angle, distance, p_l_offset, pocket_shape, c_ob)
nchunks = shapelyToChunks(crosshatch_result, o.min.z)
chunksFromCurve.extend(nchunks)
if o.parallelPocketContour:
p = getObjectOutline(c_offset, o, False)
nchunks = shapelyToChunks(p, o.min.z)
chunksFromCurve.extend(nchunks)
else:
p = getObjectOutline(c_offset, o, False)
approxn = (min(o.max.x - o.min.x, o.max.y - o.min.y) / o.dist_between_paths) / 2

Wyświetl plik

@ -183,6 +183,7 @@ class CAM_OPERATION_PROPERTIES_Panel(CAMButtonsPanel, Panel):
self.layout.prop(self.op, 'pocket_option')
self.layout.prop(self.op, 'pocketType')
if self.op.pocketType == 'PARALLEL':
self.layout.label(text="Warning: Experimental", icon='ERROR')
self.layout.prop(self.op, 'parallelPocketAngle')
self.layout.prop(self.op, 'parallelPocketCrosshatch')
self.layout.prop(self.op, 'parallelPocketContour')