1 # SPDX-FileCopyrightText: 2019-2023 Blender Foundation
3 # SPDX-License-Identifier: GPL-2.0-or-later
9 from bpy
.props
import *
13 from gpu_extras
.batch
import batch_for_shader
17 from mathutils
import Vector
18 from mathutils
.geometry
import interpolate_bezier
21 def get_points(spline
, matrix_world
):
23 bezier_points
= spline
.bezier_points
25 if len(bezier_points
) < 2:
28 r
= spline
.resolution_u
+ 1
31 segments
= len(bezier_points
)
33 if not spline
.use_cyclic_u
:
37 for i
in range(segments
):
38 inext
= (i
+ 1) % len(bezier_points
)
40 bezier_points1
= matrix_world
@ bezier_points
[i
].co
41 handle1
= matrix_world
@ bezier_points
[i
].handle_right
42 handle2
= matrix_world
@ bezier_points
[inext
].handle_left
43 bezier_points2
= matrix_world
@ bezier_points
[inext
].co
45 bezier
= bezier_points1
, handle1
, handle2
, bezier_points2
, r
46 points
= interpolate_bezier(*bezier
)
47 point_list
.extend(points
)
51 def draw(self
, context
, splines
, curve_vertcolor
, matrix_world
):
53 for spline
in splines
:
54 points
= get_points(spline
, matrix_world
)
56 shader
= gpu
.shader
.from_builtin('UNIFORM_COLOR')
58 batch
= batch_for_shader(shader
, 'POINTS', {"pos": points
})
61 shader
.uniform_float("color", curve_vertcolor
)
65 class ShowCurveResolution(bpy
.types
.Operator
):
66 bl_idname
= "curvetools.show_resolution"
67 bl_label
= "Show Curve Resolution"
68 bl_description
= "Show curve Resolution / [ESC] - remove"
72 def modal(self
, context
, event
):
73 context
.area
.tag_redraw()
75 if event
.type in {'ESC'}:
76 for handler
in self
.handlers
:
78 bpy
.types
.SpaceView3D
.draw_handler_remove(handler
, 'WINDOW')
81 for handler
in self
.handlers
:
82 self
.handlers
.remove(handler
)
85 return {'PASS_THROUGH'}
88 def invoke(self
, context
, event
):
90 if context
.area
.type == 'VIEW_3D':
92 # color change in the panel
93 curve_vertcolor
= bpy
.context
.scene
.curvetools
.curve_vertcolor
95 splines
= context
.active_object
.data
.splines
96 matrix_world
= context
.active_object
.matrix_world
98 # the arguments we pass the the callback
99 args
= (self
, context
, splines
, curve_vertcolor
, matrix_world
)
101 # Add the region OpenGL drawing callback
102 # draw in view space with 'POST_VIEW' and 'PRE_VIEW'
103 self
.handlers
.append(bpy
.types
.SpaceView3D
.draw_handler_add(draw
, args
, 'WINDOW', 'POST_VIEW'))
105 context
.window_manager
.modal_handler_add(self
)
106 return {'RUNNING_MODAL'}
108 self
.report({'WARNING'},
109 "View3D not found, cannot run operator")
113 def poll(cls
, context
):
114 return (context
.object is not None and
115 context
.object.type == 'CURVE')
119 bpy
.utils
.register_class(operators
)
123 bpy
.utils
.unregister_class(operators
)
125 if __name__
== "__main__":