1 # SPDX-FileCopyrightText: 2019-2022 Blender Foundation
3 # SPDX-License-Identifier: GPL-2.0-or-later
6 from bpy
.props
import BoolProperty
7 from bpy
.types
import Operator
, Panel
13 class OperatorAutoLoftCurves(Operator
):
14 bl_idname
= "curvetools.create_auto_loft"
16 bl_description
= "Lofts selected curves"
20 def poll(cls
, context
):
21 return util
.Selected2Curves()
23 def execute(self
, context
):
24 #print("### TODO: OperatorLoftcurves.execute()")
25 mesh
= bpy
.data
.meshes
.new("LoftMesh")
27 curve0
= context
.selected_objects
[0]
28 curve1
= context
.selected_objects
[1]
30 ls
= surfaces
.LoftedSurface(curves
.Curve(curve0
), curves
.Curve(curve1
), "AutoLoft")
32 ls
.bMesh
.to_mesh(mesh
)
34 loftobj
= bpy
.data
.objects
.new(self
.name
, mesh
)
36 context
.collection
.objects
.link(loftobj
)
37 loftobj
["autoloft"] = True
38 ui_data
= loftobj
.id_properties_ui("autoloft")
39 ui_data
.update(description
="Auto loft from %s to %s" % (curve0
.name
, curve1
.name
))
40 loftobj
["autoloft_curve0"] = curve0
.name
41 loftobj
["autoloft_curve1"] = curve1
.name
45 class AutoLoftModalOperator(Operator
):
47 bl_idname
= "curvetools.update_auto_loft_curves"
48 bl_label
= "Update Auto Loft"
49 bl_description
= "Update Lofts selected curves"
53 def poll(cls
, context
):
54 # two curves selected.
57 def execute(self
, context
):
59 lofters
= [o
for o
in scene
.objects
if "autoloft" in o
.keys()]
61 #print("TIMER", lofters)
63 for loftmesh
in lofters
:
64 curve0
= scene
.objects
.get(loftmesh
['autoloft_curve0'])
65 curve1
= scene
.objects
.get(loftmesh
['autoloft_curve1'])
67 ls
= surfaces
.LoftedSurface(curves
.Curve(curve0
), curves
.Curve(curve1
), loftmesh
.name
)
68 ls
.bMesh
.to_mesh(loftmesh
.data
)
72 bpy
.utils
.register_class(AutoLoftModalOperator
)
73 bpy
.utils
.register_class(OperatorAutoLoftCurves
)
74 bpy
.types
.WindowManager
.auto_loft
= BoolProperty(default
=False,
76 bpy
.context
.window_manager
.auto_loft
= False
79 bpy
.utils
.unregister_class(AutoLoftModalOperator
)
80 bpy
.utils
.unregister_class(OperatorAutoLoftCurves
)
82 if __name__
== "__main__":