[Bf-extensions-cvs] [b1a63218] master: Curve Tools 2: added PathFinder
Spivak Vladimir cwolf3d
noreply at git.blender.org
Sun Sep 8 19:13:00 CEST 2019
Commit: b1a63218106824cba3c2b39d42cdf74e0eef0436
Author: Spivak Vladimir (cwolf3d)
Date: Sun Sep 8 20:11:26 2019 +0300
Branches: master
https://developer.blender.org/rBACb1a63218106824cba3c2b39d42cdf74e0eef0436
Curve Tools 2: added PathFinder
===================================================================
M curve_tools/Operators.py
M curve_tools/Util.py
M curve_tools/__init__.py
===================================================================
diff --git a/curve_tools/Operators.py b/curve_tools/Operators.py
index 7779304d..5c10a999 100644
--- a/curve_tools/Operators.py
+++ b/curve_tools/Operators.py
@@ -3,7 +3,7 @@ import threading
import bpy
from bpy.props import *
-from bpy_extras import object_utils
+from bpy_extras import object_utils, view3d_utils
from . import Properties
from . import Curves
@@ -175,7 +175,7 @@ class OperatorIntersectCurves(bpy.types.Operator):
@classmethod
def poll(cls, context):
- return Util.Selected2Curves()
+ return Util.Selected2OrMoreCurves()
def execute(self, context):
@@ -194,16 +194,28 @@ class OperatorIntersectCurves(bpy.types.Operator):
affect = context.scene.curvetools.IntersectCurvesAffect
print("-- affect:", affect)
+ selected_objects = context.selected_objects
+ lenodjs = len(selected_objects)
+ print('lenodjs:', lenodjs)
+ for i in range(0, lenodjs):
+ for j in range(0, lenodjs):
+ if j != i:
+ bpy.ops.object.select_all(action='DESELECT')
+ selected_objects[i].select_set(True)
+ selected_objects[j].select_set(True)
+
+ if selected_objects[i].type == 'CURVE' and selected_objects[j].type == 'CURVE':
+ curveIntersector = CurveIntersections.CurvesIntersector.FromSelection()
+ rvIntersectionNrs = curveIntersector.CalcAndApplyIntersections()
- curveIntersector = CurveIntersections.CurvesIntersector.FromSelection()
- rvIntersectionNrs = curveIntersector.CalcAndApplyIntersections()
-
- self.report({'INFO'}, "Active curve points: %d; other curve points: %d" % (rvIntersectionNrs[0], rvIntersectionNrs[1]))
-
+ self.report({'INFO'}, "Active curve points: %d; other curve points: %d" % (rvIntersectionNrs[0], rvIntersectionNrs[1]))
+
+ for obj in selected_objects:
+ obj.select_set(True)
+
return {'FINISHED'}
-
class OperatorLoftCurves(bpy.types.Operator):
bl_idname = "curvetools2.operatorloftcurves"
bl_label = "Loft"
@@ -625,3 +637,123 @@ class ConvertBezierToSurface(bpy.types.Operator):
surfacedata.resolution_v = self.Resolution_V
return {'FINISHED'}
+
+def click(self, context, event, select):
+ bpy.ops.object.mode_set(mode = 'EDIT')
+ for object in context.selected_objects:
+ matrix_world = object.matrix_world
+ if object.type == 'CURVE':
+ curvedata = object.data
+
+ radius = bpy.context.scene.curvetools.PathFinderRadius
+
+ for spline in curvedata.splines:
+ for bezier_point in spline.bezier_points:
+ factor = 0
+ co = matrix_world @ bezier_point.co
+ if co.x > (self.location3D.x - radius):
+ factor += 1
+ if co.x < (self.location3D.x + radius):
+ factor += 1
+ if co.y > (self.location3D.y - radius):
+ factor += 1
+ if co.y < (self.location3D.y + radius):
+ factor += 1
+ if co.z > (self.location3D.z - radius):
+ factor += 1
+ if co.z < (self.location3D.z + radius):
+ factor += 1
+ if factor == 6:
+ for bezier_point in spline.bezier_points:
+ bezier_point.select_control_point = select
+ bezier_point.select_left_handle = select
+ bezier_point.select_right_handle = select
+
+ for spline in curvedata.splines:
+ for point in spline.points:
+ factor = 0
+ co = matrix_world @ point.co
+ if co.x > (self.location3D.x - radius):
+ factor += 1
+ if co.x < (self.location3D.x + radius):
+ factor += 1
+ if co.y > (self.location3D.y - radius):
+ factor += 1
+ if co.y < (self.location3D.y + radius):
+ factor += 1
+ if co.z > (self.location3D.z - radius):
+ factor += 1
+ if co.z < (self.location3D.z + radius):
+ factor += 1
+ if factor == 6:
+ for point in spline.points:
+ point = select
+
+class PathFinder(bpy.types.Operator):
+ bl_idname = "curvetools2.pathfinder"
+ bl_label = "Path Finder"
+ bl_description = "Path Finder"
+ bl_options = {'REGISTER', 'UNDO'}
+
+ x: IntProperty(name="x", description="x")
+ y: IntProperty(name="y", description="y")
+ location3D: FloatVectorProperty(name = "",
+ description = "Start location",
+ default = (0.0, 0.0, 0.0),
+ subtype = 'XYZ')
+
+ def __init__(self):
+ bpy.context.space_data.overlay.show_curve_handles = False
+ self.report({'INFO'}, "ESC or TAB - cancel")
+ print("Start PathFinder")
+
+ def __del__(self):
+ bpy.context.space_data.overlay.show_curve_handles = True
+ self.report({'INFO'}, "PathFinder deactivated")
+ print("End PathFinder")
+
+ def modal(self, context, event):
+ if event.type in {'DEL', 'X'}:
+ bpy.ops.curve.delete(type='VERT')
+
+ #if event.ctrl and event.type == 'Z':
+ # bpy.ops.ed.undo()
+
+ #if event.shift and event.type == 'Z':
+ # bpy.ops.ed.redo()
+
+ elif event.type == 'LEFTMOUSE':
+ click(self, context, event, True)
+
+ elif event.type == 'RIGHTMOUSE':
+ click(self, context, event, False)
+
+ elif event.type == 'A':
+ bpy.ops.curve.select_all(action='DESELECT')
+
+ elif event.type == 'MOUSEMOVE': #
+ self.x = event.mouse_x
+ self.y = event.mouse_y
+ region = bpy.context.region
+ rv3d = bpy.context.space_data.region_3d
+ self.location3D = view3d_utils.region_2d_to_location_3d(
+ region,
+ rv3d,
+ (event.mouse_region_x, event.mouse_region_y),
+ (0.0, 0.0, 0.0)
+ )
+
+ elif event.type == 'WHEELUPMOUSE': #
+ bpy.ops.curve.select_more()
+
+ elif event.type == 'WHEELDOWNMOUSE': #
+ bpy.ops.curve.select_less()
+
+ elif event.type in {'ESC', 'TAB'}: # Cancel
+ return {'CANCELLED'}
+
+ return {'RUNNING_MODAL'}
+
+ def invoke(self, context, event):
+ context.window_manager.modal_handler_add(self)
+ return {'RUNNING_MODAL'}
diff --git a/curve_tools/Util.py b/curve_tools/Util.py
index 56fc0d20..30596697 100644
--- a/curve_tools/Util.py
+++ b/curve_tools/Util.py
@@ -84,6 +84,15 @@ def Selected1OrMoreCurves():
pass
return False
+
+def Selected2OrMoreCurves():
+ try:
+ if len(GetSelectedCurves()) > 1:
+ return (bpy.context.active_object.type == "CURVE")
+ except:
+ pass
+
+ return False
def Selected1OrMoreMesh():
diff --git a/curve_tools/__init__.py b/curve_tools/__init__.py
index 0623b241..86c8b557 100644
--- a/curve_tools/__init__.py
+++ b/curve_tools/__init__.py
@@ -20,7 +20,7 @@ bl_info = {
"name": "Curve Tools 2",
"description": "Adds some functionality for bezier/nurbs curve/surface modeling",
"author": "Mackraken, guy lateur, Spivak Vladimir (cwolf3d)",
- "version": (0, 3, 1),
+ "version": (0, 3, 2),
"blender": (2, 80, 0),
"location": "View3D > Tool Shelf > Addons Tab",
"warning": "WIP",
@@ -59,7 +59,7 @@ from bpy.types import (
def UpdateDummy(object, context):
scene = context.scene
SINGLEDROP = scene.UTSingleDrop
- DOUBLEDROP = scene.UTDoubleDrop
+ MOREDROP = scene.UTMOREDROP
LOFTDROP = scene.UTLoftDrop
TRIPLEDROP = scene.UTTripleDrop
UTILSDROP = scene.UTUtilsDrop
@@ -177,6 +177,12 @@ class CurveTools2Settings(PropertyGroup):
description="Determines which of the selected curves will be affected by the operation",
default='Both'
)
+ PathFinderRadius: FloatProperty(
+ name="PathFinder detection radius",
+ default=0.2,
+ precision=6,
+ description="PathFinder detection radius"
+ )
class VIEW3D_PT_CurvePanel(Panel):
@@ -193,7 +199,7 @@ class VIEW3D_PT_CurvePanel(Panel):
def draw(self, context):
scene = context.scene
SINGLEDROP = scene.UTSingleDrop
- DOUBLEDROP = scene.UTDoubleDrop
+ MOREDROP = scene.UTMOREDROP
LOFTDROP = scene.UTLoftDrop
TRIPLEDROP = scene.UTTripleDrop
UTILSDROP = scene.UTUtilsDrop
@@ -207,8 +213,6 @@ class VIEW3D_PT_CurvePanel(Panel):
if SINGLEDROP:
# A. 1 curve
row = col.row(align=True)
- row.label(text="Single Curve:")
- row = col.row(align=True)
# A.1 curve info/length
row.operator("curvetools2.operatorcurveinfo", text="Curve info")
@@ -232,12 +236,11 @@ class VIEW3D_PT_CurvePanel(Panel):
box2 = self.layout.box()
col = box2.column(align=True)
row = col.row(align=True)
- row.prop(scene, "UTDoubleDrop", icon="TRIA_DOWN")
+ row.prop(scene, "UTMOREDROP", icon="TRIA_DOWN")
- if DOUBLEDROP:
+ if MOREDROP:
# B. 2 curves
row = col.row(align=True)
- row.label(text="2 curves:")
# B.1 curve intersections
row = col.row(align=True)
@@ -332,6 +335,26 @@ class VIEW3D_PT_CurvePanel(Panel):
row = col.row(align=True)
row.prop(context.scene.curvetools, "SplineJoinMode", text="Join
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-extensions-cvs
mailing list