-
Notifications
You must be signed in to change notification settings - Fork 1
/
auto_loft.py
120 lines (90 loc) · 3.68 KB
/
auto_loft.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
120
import bpy
from bpy.props import BoolProperty
from bpy.types import Operator, Panel
from curve_tools.Surfaces import LoftedSurface
from curve_tools.Curves import Curve
from curve_tools import Util
class OperatorAutoLoftCurves(Operator):
bl_idname = "curvetools2.create_auto_loft"
bl_label = "Loft"
bl_description = "Lofts selected curves"
@classmethod
def poll(cls, context):
return Util.Selected2Curves()
def execute(self, context):
#print("### TODO: OperatorLoftCurves.execute()")
mesh = bpy.data.meshes.new("LoftMesh")
curve0 = context.selected_objects[0]
curve1 = context.selected_objects[1]
ls = LoftedSurface(Curve(curve0), Curve(curve1), "AutoLoft")
ls.bMesh.to_mesh(mesh)
loftobj = bpy.data.objects.new(self.name, mesh)
context.collection.objects.link(loftobj)
loftobj["autoloft"] = True
if loftobj.get('_RNA_UI') is None:
loftobj['_RNA_UI'] = {}
loftobj['_RNA_UI']["autoloft"] = {
"name": "Auto Loft",
"description": "Auto loft from %s to %s" % (curve0.name, curve1.name),
"curve0": curve0.name,
"curve1": curve1.name}
print(loftobj['_RNA_UI'].to_dict())
self.report({'INFO'}, "OperatorAutoLoftCurves.execute()")
return {'FINISHED'}
class AutoLoftModalOperator(Operator):
"""Auto Loft"""
bl_idname = "wm.auto_loft_curve"
bl_label = "Auto Loft"
bl_description = "Lofts selected curves"
_timer = None
@classmethod
def poll(cls, context):
# two curves selected.
return True
def modal(self, context, event):
scene = context.scene
wm = context.window_manager
if event.type in {'ESC'}:
wm.auto_loft = False
if not wm.auto_loft:
self.cancel(context)
return {'CANCELLED'}
if event.type == 'TIMER':
lofters = [o for o in scene.objects if "autoloft" in o.keys()]
# quick hack
#print("TIMER", lofters)
for loftmesh in lofters:
loftmesh.hide_select = True
rna = loftmesh['_RNA_UI']["autoloft"].to_dict()
curve0 = scene.objects.get(rna["curve0"])
curve1 = scene.objects.get(rna["curve1"])
if curve0 and curve1:
ls = LoftedSurface(Curve(curve0), Curve(curve1), loftmesh.name)
ls.bMesh.to_mesh(loftmesh.data)
return {'PASS_THROUGH'}
def execute(self, context):
wm = context.window_manager
self._timer = wm.event_timer_add(0.1, context.window)
wm.modal_handler_add(self)
return {'RUNNING_MODAL'}
def cancel(self, context):
wm = context.window_manager
wm.event_timer_remove(self._timer)
def run_auto_loft(self, context):
if self.auto_loft:
bpy.ops.wm.auto_loft_curve()
return None
def register():
bpy.utils.register_class(AutoLoftModalOperator)
bpy.utils.register_class(OperatorAutoLoftCurves)
bpy.types.WindowManager.auto_loft = BoolProperty(default=False,
name="Auto Loft",
update=run_auto_loft)
bpy.context.window_manager.auto_loft = False
def unregister():
bpy.utils.unregister_class(AutoLoftModalOperator)
bpy.utils.unregister_class(OperatorAutoLoftCurves)
if __name__ == "__main__":
register()
# test call
#bpy.ops.wm.modal_timer_operator()