1 # SPDX-License-Identifier: GPL-2.0-or-later
7 from bpy
.props
import *
12 from gpu_extras
.batch
import batch_for_shader
16 from mathutils
import Vector
17 from mathutils
.geometry
import interpolate_bezier
20 def get_points(spline
, matrix_world
):
22 bezier_points
= spline
.bezier_points
24 if len(bezier_points
) < 2:
27 r
= spline
.resolution_u
+ 1
30 segments
= len(bezier_points
)
32 if not spline
.use_cyclic_u
:
36 for i
in range(segments
):
37 inext
= (i
+ 1) % len(bezier_points
)
39 bezier_points1
= matrix_world
@ bezier_points
[i
].co
40 handle1
= matrix_world
@ bezier_points
[i
].handle_right
41 handle2
= matrix_world
@ bezier_points
[inext
].handle_left
42 bezier_points2
= matrix_world
@ bezier_points
[inext
].co
44 bezier
= bezier_points1
, handle1
, handle2
, bezier_points2
, r
45 points
= interpolate_bezier(*bezier
)
46 point_list
.extend(points
)
50 def draw(self
, context
, splines
, curve_vertcolor
, matrix_world
):
52 for spline
in splines
:
53 points
= get_points(spline
, matrix_world
)
55 shader
= gpu
.shader
.from_builtin('3D_UNIFORM_COLOR')
57 batch
= batch_for_shader(shader
, 'POINTS', {"pos": points
})
60 shader
.uniform_float("color", curve_vertcolor
)
64 class ShowCurveResolution(bpy
.types
.Operator
):
65 bl_idname
= "curvetools.show_resolution"
66 bl_label
= "Show Curve Resolution"
67 bl_description
= "Show curve Resolution / [ESC] - remove"
71 def modal(self
, context
, event
):
72 context
.area
.tag_redraw()
74 if event
.type in {'ESC'}:
75 for handler
in self
.handlers
:
77 bpy
.types
.SpaceView3D
.draw_handler_remove(handler
, 'WINDOW')
80 for handler
in self
.handlers
:
81 self
.handlers
.remove(handler
)
84 return {'PASS_THROUGH'}
87 def invoke(self
, context
, event
):
89 if context
.area
.type == 'VIEW_3D':
91 # color change in the panel
92 curve_vertcolor
= bpy
.context
.scene
.curvetools
.curve_vertcolor
94 splines
= context
.active_object
.data
.splines
95 matrix_world
= context
.active_object
.matrix_world
97 # the arguments we pass the the callback
98 args
= (self
, context
, splines
, curve_vertcolor
, matrix_world
)
100 # Add the region OpenGL drawing callback
101 # draw in view space with 'POST_VIEW' and 'PRE_VIEW'
102 self
.handlers
.append(bpy
.types
.SpaceView3D
.draw_handler_add(draw
, args
, 'WINDOW', 'POST_VIEW'))
104 context
.window_manager
.modal_handler_add(self
)
105 return {'RUNNING_MODAL'}
107 self
.report({'WARNING'},
108 "View3D not found, cannot run operator")
112 def poll(cls
, context
):
113 return (context
.object is not None and
114 context
.object.type == 'CURVE')
118 bpy
.utils
.register_class(operators
)
122 bpy
.utils
.unregister_class(operators
)
124 if __name__
== "__main__":