Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender-addons.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSpivak Vladimir (cwolf3d) <cwolf3d@gmail.com>2019-10-30 12:18:10 +0300
committerSpivak Vladimir (cwolf3d) <cwolf3d@gmail.com>2019-10-30 12:18:10 +0300
commitb6751d4d0390257a4352d449991407065cc29124 (patch)
tree6ea1e12cdc1734c99830b2155b374496758ce27d /curve_tools/operators.py
parentacfe2a22e07046564cc5788388c2404486c76fe9 (diff)
Addon: Curve Tools: Add 2D Curve Boolean. Fixed some errors.
Diffstat (limited to 'curve_tools/operators.py')
-rw-r--r--curve_tools/operators.py96
1 files changed, 96 insertions, 0 deletions
diff --git a/curve_tools/operators.py b/curve_tools/operators.py
index e4fe24dd..099b57bb 100644
--- a/curve_tools/operators.py
+++ b/curve_tools/operators.py
@@ -13,6 +13,7 @@ from . import intersections
from . import util
from . import surfaces
from . import mathematics
+from . import internal
# 1 CURVE SELECTED
# ################
@@ -1020,6 +1021,100 @@ class SeparateOutline(bpy.types.Operator):
bpy.ops.curve.separate()
return {'FINISHED'}
+
+class CurveBoolean(bpy.types.Operator):
+ bl_idname = "curvetools.bezier_curve_boolean"
+ bl_description = "Curve Boolean"
+ bl_label = "Curve Boolean"
+ bl_options = {'REGISTER', 'UNDO'}
+
+ operation: bpy.props.EnumProperty(name='Type', items=[
+ ('UNION', 'Union', 'Boolean OR', 0),
+ ('INTERSECTION', 'Intersection', 'Boolean AND', 1),
+ ('DIFFERENCE AB', 'Difference AB', 'Active minus Selected', 2),
+ ('DIFFERENCE BA', 'Difference BA', 'Selected minus Active', 3),
+ ])
+
+ @classmethod
+ def poll(cls, context):
+ return util.Selected1OrMoreCurves()
+
+ def execute(self, context):
+ current_mode = bpy.context.object.mode
+
+ if bpy.ops.object.mode_set.poll():
+ bpy.ops.object.mode_set(mode = 'OBJECT')
+
+ selected_Curves = util.GetSelectedCurves()
+ len_selected_curves = len(selected_Curves)
+
+ bpy.ops.object.select_all(action='DESELECT')
+
+ if len_selected_curves < 2:
+ return {'FINISHED'}
+
+ spline1 = selected_Curves[0].data.splines[0]
+ matrix_world1 = selected_Curves[0].matrix_world
+
+ len_spline1 = len(spline1.bezier_points)
+
+ dataCurve = bpy.data.curves.new(self.operation, type='CURVE')
+ dataCurve.dimensions = '2D'
+ newSpline1 = dataCurve.splines.new(type='BEZIER')
+ newSpline1.use_cyclic_u = True
+ newSpline1.bezier_points.add(len_spline1 - 1)
+ for n in range(0, len_spline1):
+ newSpline1.bezier_points[n].co = matrix_world1 @ spline1.bezier_points[n].co
+ newSpline1.bezier_points[n].handle_left_type = spline1.bezier_points[n].handle_left_type
+ newSpline1.bezier_points[n].handle_left = matrix_world1 @ spline1.bezier_points[n].handle_left
+ newSpline1.bezier_points[n].handle_right_type = spline1.bezier_points[n].handle_right_type
+ newSpline1.bezier_points[n].handle_right = matrix_world1 @ spline1.bezier_points[n].handle_right
+
+ Curve = object_utils.object_data_add(context, dataCurve)
+ bpy.context.view_layer.objects.active = Curve
+ Curve.select_set(True)
+
+ for iCurve in range(0, len_selected_curves):
+ matrix_world = selected_Curves[iCurve].matrix_world
+ len_splines = len(selected_Curves[iCurve].data.splines)
+ first = 0
+ if iCurve == 0:
+ first = 1
+ for ispline in range(first, len_splines):
+ spline = selected_Curves[iCurve].data.splines[ispline]
+ len_spline = len(spline.bezier_points)
+ newSpline = dataCurve.splines.new(type='BEZIER')
+ newSpline.use_cyclic_u = True
+ newSpline.bezier_points.add(len_spline - 1)
+ for n in range(0, len_spline):
+ newSpline.bezier_points[n].co = matrix_world @ spline.bezier_points[n].co
+ newSpline.bezier_points[n].handle_left_type = spline.bezier_points[n].handle_left_type
+ newSpline.bezier_points[n].handle_left = matrix_world @ spline.bezier_points[n].handle_left
+ newSpline.bezier_points[n].handle_right_type = spline.bezier_points[n].handle_right_type
+ newSpline.bezier_points[n].handle_right = matrix_world @ spline.bezier_points[n].handle_right
+
+ bpy.ops.object.mode_set(mode = 'EDIT')
+ bpy.ops.curve.select_all(action='SELECT')
+ splines = internal.getSelectedSplines(True, True)
+ splineA = splines[0]
+ splineB = splines[1]
+ operation = self.operation
+ dataCurve.splines.active = newSpline1
+ if self.operation == 'DIFFERENCE AB':
+ operation = 'DIFFERENCE'
+ if self.operation == 'DIFFERENCE BA':
+ dataCurve.splines.active = newSpline
+ operation = 'DIFFERENCE'
+ splineA = splines[1]
+ splineB = splines[0]
+
+ if not internal.bezierBooleanGeometry(splineA, splineB, operation):
+ self.report({'WARNING'}, 'Invalid selection.')
+ return {'CANCELLED'}
+
+ bpy.ops.object.mode_set (mode = current_mode)
+
+ return {'FINISHED'}
def register():
for cls in classes:
@@ -1053,4 +1148,5 @@ operators = [
CurveScaleReset,
Split,
SeparateOutline,
+ CurveBoolean,
]