Sun position: remove unused prop in HDRI mode
[blender-addons.git] / curve_tools / show_resolution.py
blobfc8fdad22d846742931cf48feeb85bf1747f3bec
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 #####
21 # LOAD MODUL #
22 import bpy
23 from bpy import *
24 from bpy.props import *
26 import bgl
27 import blf
28 import gpu
29 from gpu_extras.batch import batch_for_shader
31 import math
32 import mathutils
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:
42 return []
44 r = spline.resolution_u + 1
45 if r < 2:
46 return []
47 segments = len(bezier_points)
49 if not spline.use_cyclic_u:
50 segments -= 1
52 point_list = []
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)
65 return point_list
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})
76 shader.bind()
77 shader.uniform_float("color", curve_vertcolor)
78 batch.draw(shader)
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"
86 handlers = []
88 def modal(self, context, event):
89 context.area.tag_redraw()
91 if event.type in {'ESC'}:
92 for handler in self.handlers:
93 try:
94 bpy.types.SpaceView3D.draw_handler_remove(handler, 'WINDOW')
95 except:
96 pass
97 for handler in self.handlers:
98 self.handlers.remove(handler)
99 return {'CANCELLED'}
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'}
123 else:
124 self.report({'WARNING'},
125 "View3D not found, cannot run operator")
126 return {'CANCELLED'}
128 @classmethod
129 def poll(cls, context):
130 return (context.object is not None and
131 context.object.type == 'CURVE')
133 def register():
134 for cls in classes:
135 bpy.utils.register_class(operators)
137 def unregister():
138 for cls in classes:
139 bpy.utils.unregister_class(operators)
141 if __name__ == "__main__":
142 register()
144 operators = [
145 ShowCurveResolution,