1 # SPDX-License-Identifier: GPL-2.0-or-later
4 from bpy
.props
import BoolProperty
5 from bpy
.types
import Operator
, Panel
11 class OperatorAutoLoftCurves(Operator
):
12 bl_idname
= "curvetools.create_auto_loft"
14 bl_description
= "Lofts selected curves"
18 def poll(cls
, context
):
19 return util
.Selected2Curves()
21 def execute(self
, context
):
22 #print("### TODO: OperatorLoftcurves.execute()")
23 mesh
= bpy
.data
.meshes
.new("LoftMesh")
25 curve0
= context
.selected_objects
[0]
26 curve1
= context
.selected_objects
[1]
28 ls
= surfaces
.LoftedSurface(curves
.Curve(curve0
), curves
.Curve(curve1
), "AutoLoft")
30 ls
.bMesh
.to_mesh(mesh
)
32 loftobj
= bpy
.data
.objects
.new(self
.name
, mesh
)
34 context
.collection
.objects
.link(loftobj
)
35 loftobj
["autoloft"] = True
36 ui_data
= loftobj
.id_properties_ui("autoloft")
37 ui_data
.update(description
="Auto loft from %s to %s" % (curve0
.name
, curve1
.name
))
38 loftobj
["autoloft_curve0"] = curve0
.name
39 loftobj
["autoloft_curve1"] = curve1
.name
43 class AutoLoftModalOperator(Operator
):
45 bl_idname
= "curvetools.update_auto_loft_curves"
46 bl_label
= "Update Auto Loft"
47 bl_description
= "Update Lofts selected curves"
51 def poll(cls
, context
):
52 # two curves selected.
55 def execute(self
, context
):
57 lofters
= [o
for o
in scene
.objects
if "autoloft" in o
.keys()]
59 #print("TIMER", lofters)
61 for loftmesh
in lofters
:
62 curve0
= scene
.objects
.get(loftmesh
['autoloft_curve0'])
63 curve1
= scene
.objects
.get(loftmesh
['autoloft_curve1'])
65 ls
= surfaces
.LoftedSurface(curves
.Curve(curve0
), curves
.Curve(curve1
), loftmesh
.name
)
66 ls
.bMesh
.to_mesh(loftmesh
.data
)
70 bpy
.utils
.register_class(AutoLoftModalOperator
)
71 bpy
.utils
.register_class(OperatorAutoLoftCurves
)
72 bpy
.types
.WindowManager
.auto_loft
= BoolProperty(default
=False,
74 bpy
.context
.window_manager
.auto_loft
= False
77 bpy
.utils
.unregister_class(AutoLoftModalOperator
)
78 bpy
.utils
.unregister_class(OperatorAutoLoftCurves
)
80 if __name__
== "__main__":