Import_3ds: Improved distance cue node setup
[blender-addons.git] / curve_tools / auto_loft.py
blobe0e7c9280ba4c11fd898ac08936ca033d0bab5d1
1 # SPDX-FileCopyrightText: 2019-2022 Blender Foundation
3 # SPDX-License-Identifier: GPL-2.0-or-later
5 import bpy
6 from bpy.props import BoolProperty
7 from bpy.types import Operator, Panel
8 from . import surfaces
9 from . import curves
10 from . import util
13 class OperatorAutoLoftCurves(Operator):
14 bl_idname = "curvetools.create_auto_loft"
15 bl_label = "Loft"
16 bl_description = "Lofts selected curves"
17 bl_options = {'UNDO'}
19 @classmethod
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
43 return {'FINISHED'}
45 class AutoLoftModalOperator(Operator):
46 """Auto Loft"""
47 bl_idname = "curvetools.update_auto_loft_curves"
48 bl_label = "Update Auto Loft"
49 bl_description = "Update Lofts selected curves"
51 _timer = None
52 @classmethod
53 def poll(cls, context):
54 # two curves selected.
55 return True
57 def execute(self, context):
58 scene = context.scene
59 lofters = [o for o in scene.objects if "autoloft" in o.keys()]
60 # quick hack
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'])
66 if curve0 and curve1:
67 ls = surfaces.LoftedSurface(curves.Curve(curve0), curves.Curve(curve1), loftmesh.name)
68 ls.bMesh.to_mesh(loftmesh.data)
69 return {'FINISHED'}
71 def register():
72 bpy.utils.register_class(AutoLoftModalOperator)
73 bpy.utils.register_class(OperatorAutoLoftCurves)
74 bpy.types.WindowManager.auto_loft = BoolProperty(default=False,
75 name="Auto Loft")
76 bpy.context.window_manager.auto_loft = False
78 def unregister():
79 bpy.utils.unregister_class(AutoLoftModalOperator)
80 bpy.utils.unregister_class(OperatorAutoLoftCurves)
82 if __name__ == "__main__":
83 register()