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"
17 def poll(cls
, context
):
18 return util
.Selected2Curves()
20 def execute(self
, context
):
21 #print("### TODO: OperatorLoftcurves.execute()")
22 mesh
= bpy
.data
.meshes
.new("LoftMesh")
24 curve0
= context
.selected_objects
[0]
25 curve1
= context
.selected_objects
[1]
27 ls
= surfaces
.LoftedSurface(curves
.Curve(curve0
), curves
.Curve(curve1
), "AutoLoft")
29 ls
.bMesh
.to_mesh(mesh
)
31 loftobj
= bpy
.data
.objects
.new(self
.name
, mesh
)
33 context
.collection
.objects
.link(loftobj
)
34 loftobj
["autoloft"] = True
35 ui_data
= loftobj
.id_properties_ui("autoloft")
36 ui_data
.update(description
="Auto loft from %s to %s" % (curve0
.name
, curve1
.name
))
37 loftobj
["autoloft_curve0"] = curve0
.name
38 loftobj
["autoloft_curve1"] = curve1
.name
42 class AutoLoftModalOperator(Operator
):
44 bl_idname
= "curvetools.update_auto_loft_curves"
45 bl_label
= "Update Auto Loft"
46 bl_description
= "Update Lofts selected curves"
50 def poll(cls
, context
):
51 # two curves selected.
54 def execute(self
, context
):
56 lofters
= [o
for o
in scene
.objects
if "autoloft" in o
.keys()]
58 #print("TIMER", lofters)
60 for loftmesh
in lofters
:
61 curve0
= scene
.objects
.get(loftmesh
['autoloft_curve0'])
62 curve1
= scene
.objects
.get(loftmesh
['autoloft_curve1'])
64 ls
= surfaces
.LoftedSurface(curves
.Curve(curve0
), curves
.Curve(curve1
), loftmesh
.name
)
65 ls
.bMesh
.to_mesh(loftmesh
.data
)
69 bpy
.utils
.register_class(AutoLoftModalOperator
)
70 bpy
.utils
.register_class(OperatorAutoLoftCurves
)
71 bpy
.types
.WindowManager
.auto_loft
= BoolProperty(default
=False,
73 bpy
.context
.window_manager
.auto_loft
= False
76 bpy
.utils
.unregister_class(AutoLoftModalOperator
)
77 bpy
.utils
.unregister_class(OperatorAutoLoftCurves
)
79 if __name__
== "__main__":