import gpu from gpu_extras.batch import batch_for_shader import bpy from bpy.types import Gizmo, GizmoGroup class MyCustomShapeWidget(Gizmo): bl_idname = "VIEW3D_GT_custom_shape_widget" bl_target_properties = () def draw(self, context): skew = 100.0 x0 = 100.0 y0 = 100.0 x1 = 500.0 y1 = 500.0 z = 0.0 color = (0.0, 0.0, 0.0, 0.9) verts = [(x0, y0, z), (x0+skew, y1, z), (x1, y1, z), (x1-skew, y0, z)] colors = [color, color, color, color] indices = [(0, 1, 2), (0, 2, 3)] content = {"pos":verts, "color":colors} gpu.state.blend_set('ALPHA') shader = gpu.shader.from_builtin('SMOOTH_COLOR') batch = batch_for_shader(shader, 'TRIS', content, indices=indices) batch.draw(shader) gpu.state.blend_set('NONE') class MyCustomShapeWidgetGroup(GizmoGroup): bl_idname = "OBJECT_GGT_light_test" bl_label = "Test Light Widget" bl_space_type = 'VIEW_3D' bl_region_type = 'WINDOW' # If bl_options has '3D' (like in the "Gizmo Custom Geometry" template), # there seem to be no gaps between triangles, even though they are # antialiased. If it's absent, there are gaps. #bl_options = {'3D', 'PERSISTENT'} bl_options = {'PERSISTENT'} def setup(self, context): gizmo = self.gizmos.new(MyCustomShapeWidget.bl_idname) gizmo.use_draw_modal = True bpy.utils.register_class(MyCustomShapeWidget) bpy.utils.register_class(MyCustomShapeWidgetGroup)