1 # ##### BEGIN GPL LICENSE BLOCK #####
3 # This program is free software; you can redistribute it and / or
4 # modify it under the terms of the GNU General Public License
5 # as published by the Free Software Foundation; either version 2
6 # of the License, or (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software Foundation,
15 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 - 1301, USA.
17 # ##### END GPL LICENSE BLOCK #####
24 from bpy
.props
import *
29 from gpu_extras
.batch
import batch_for_shader
33 from mathutils
import Vector
34 from mathutils
.geometry
import interpolate_bezier
37 def get_points(spline
, matrix_world
):
39 bezier_points
= spline
.bezier_points
41 if len(bezier_points
) < 2:
44 r
= spline
.resolution_u
+ 1
47 segments
= len(bezier_points
)
49 if not spline
.use_cyclic_u
:
53 for i
in range(segments
):
54 inext
= (i
+ 1) % len(bezier_points
)
56 bezier_points1
= matrix_world
@ bezier_points
[i
].co
57 handle1
= matrix_world
@ bezier_points
[i
].handle_right
58 handle2
= matrix_world
@ bezier_points
[inext
].handle_left
59 bezier_points2
= matrix_world
@ bezier_points
[inext
].co
61 bezier
= bezier_points1
, handle1
, handle2
, bezier_points2
, r
62 points
= interpolate_bezier(*bezier
)
63 point_list
.extend(points
)
67 def draw(self
, context
, splines
, curve_vertcolor
, matrix_world
):
69 for spline
in splines
:
70 points
= get_points(spline
, matrix_world
)
72 shader
= gpu
.shader
.from_builtin('3D_UNIFORM_COLOR')
74 batch
= batch_for_shader(shader
, 'POINTS', {"pos": points
})
77 shader
.uniform_float("color", curve_vertcolor
)
81 class ShowCurveResolution(bpy
.types
.Operator
):
82 bl_idname
= "curvetools.show_resolution"
83 bl_label
= "Show Curve Resolution"
84 bl_description
= "Show curve Resolution / [ESC] - remove"
88 def modal(self
, context
, event
):
89 context
.area
.tag_redraw()
91 if event
.type in {'ESC'}:
92 for handler
in self
.handlers
:
94 bpy
.types
.SpaceView3D
.draw_handler_remove(handler
, 'WINDOW')
97 for handler
in self
.handlers
:
98 self
.handlers
.remove(handler
)
101 return {'PASS_THROUGH'}
104 def invoke(self
, context
, event
):
106 if context
.area
.type == 'VIEW_3D':
108 # color change in the panel
109 curve_vertcolor
= bpy
.context
.scene
.curvetools
.curve_vertcolor
111 splines
= context
.active_object
.data
.splines
112 matrix_world
= context
.active_object
.matrix_world
114 # the arguments we pass the the callback
115 args
= (self
, context
, splines
, curve_vertcolor
, matrix_world
)
117 # Add the region OpenGL drawing callback
118 # draw in view space with 'POST_VIEW' and 'PRE_VIEW'
119 self
.handlers
.append(bpy
.types
.SpaceView3D
.draw_handler_add(draw
, args
, 'WINDOW', 'POST_VIEW'))
121 context
.window_manager
.modal_handler_add(self
)
122 return {'RUNNING_MODAL'}
124 self
.report({'WARNING'},
125 "View3D not found, cannot run operator")
129 def poll(cls
, context
):
130 return (context
.object is not None and
131 context
.object.type == 'CURVE')
135 bpy
.utils
.register_class(operators
)
139 bpy
.utils
.unregister_class(operators
)
141 if __name__
== "__main__":