Fix io_anim_camera error exporting cameras with quotes in their name
[blender-addons.git] / curve_tools / auto_loft.py
blob3092e6b856c13f2ea24fbee8bdd3c2cd01b506cf
1 # SPDX-License-Identifier: GPL-2.0-or-later
3 import bpy
4 from bpy.props import BoolProperty
5 from bpy.types import Operator, Panel
6 from . import surfaces
7 from . import curves
8 from . import util
11 class OperatorAutoLoftCurves(Operator):
12 bl_idname = "curvetools.create_auto_loft"
13 bl_label = "Loft"
14 bl_description = "Lofts selected curves"
16 @classmethod
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
40 return {'FINISHED'}
42 class AutoLoftModalOperator(Operator):
43 """Auto Loft"""
44 bl_idname = "curvetools.update_auto_loft_curves"
45 bl_label = "Update Auto Loft"
46 bl_description = "Update Lofts selected curves"
48 _timer = None
49 @classmethod
50 def poll(cls, context):
51 # two curves selected.
52 return True
54 def execute(self, context):
55 scene = context.scene
56 lofters = [o for o in scene.objects if "autoloft" in o.keys()]
57 # quick hack
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'])
63 if curve0 and curve1:
64 ls = surfaces.LoftedSurface(curves.Curve(curve0), curves.Curve(curve1), loftmesh.name)
65 ls.bMesh.to_mesh(loftmesh.data)
66 return {'FINISHED'}
68 def register():
69 bpy.utils.register_class(AutoLoftModalOperator)
70 bpy.utils.register_class(OperatorAutoLoftCurves)
71 bpy.types.WindowManager.auto_loft = BoolProperty(default=False,
72 name="Auto Loft")
73 bpy.context.window_manager.auto_loft = False
75 def unregister():
76 bpy.utils.unregister_class(AutoLoftModalOperator)
77 bpy.utils.unregister_class(OperatorAutoLoftCurves)
79 if __name__ == "__main__":
80 register()