-
Notifications
You must be signed in to change notification settings - Fork 1
/
Util.py
119 lines (77 loc) · 2.8 KB
/
Util.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
import bpy
from mathutils import *
def GetSelectedCurves():
rvList = []
for obj in bpy.context.selected_objects:
if obj.type == "CURVE": rvList.append(obj)
return rvList
def Selected1Curve():
if len(GetSelectedCurves()) == 1:
return (bpy.context.active_object.type == "CURVE")
return False
def Selected1SingleSplineCurve():
if Selected1Curve():
return (len(bpy.context.active_object.data.splines) == 1)
return False
def Selected2Curves():
if len(GetSelectedCurves()) == 2:
return (bpy.context.active_object.type == "CURVE")
return False
def Selected3Curves():
if len(GetSelectedCurves()) == 3:
return (bpy.context.active_object.type == "CURVE")
return False
def Selected1OrMoreCurves():
if len(GetSelectedCurves()) > 0:
return (bpy.context.active_object.type == "CURVE")
return False
def GetToolsRegion():
for area in bpy.context.screen.areas:
if area.type == 'VIEW_3D':
for region in area.regions:
if region.type == 'TOOLS': return region
return None
def GetFirstRegionView3D():
for area in bpy.context.screen.areas:
if area.type == 'VIEW_3D':
return area.spaces[0].region_3d
return None
def LogFirstRegionView3D():
print("LogFirstRegionView3D()")
regionView3D = GetFirstRegionView3D()
if regionView3D is None:
print("--", "ERROR:", "regionView3D is None")
return
print("--", "view_matrix:")
print("--", "--", regionView3D.view_matrix)
print("--", "view_location:")
print("--", "--", regionView3D.view_location)
class Intersection:
# listIP: list of BezierSplineIntersectionPoint
# return: list of splines
@staticmethod
def GetBezierSplines(listIP):
rvList = []
for ip in listIP:
if not (ip.spline in rvList): rvList.append(ip.spline)
return rvList
# listIP: list of BezierSplineIntersectionPoint
# return: list of segments
@staticmethod
def GetBezierSegments(listIP, spline):
rvList = []
for ip in listIP:
if not ip.spline is spline: continue
segIP = ip.bezierSegmentIntersectionPoint
if not (segIP.segment in rvList): rvList.append(segIP.segment)
return rvList
# listIP: list of BezierSplineIntersectionPoint
# return: list of floats (not necessarily ordered)
@staticmethod
def GetBezierSegmentParameters(listIP, segment):
rvList = []
for ip in listIP:
segIP = ip.bezierSegmentIntersectionPoint
if not segIP.segment is segment: continue
rvList.append(segIP.parameter)
return rvList