Suggestions / feedback on the extensions for the gpu module

Hi All, I have been experimenting with the python gpu module, and going through the examples here. I can draw the lines and wireframes as in the examples, but I can’t make a solid triangle that is properly shaded; it is just a solid color with no lighting dependence.

When I send a list of normals using batch = batch_for_shader(shader, ‘TRIS’, {“pos”: coords, “normal”: normals}), it gives me a ValueError: Unknown attribute name. I asked this in chat and one reply was that ‘normal’ is not a valid attribute, but from the vbo example here, it seems that ‘normal’ should be valid. My code is below

import bpy
import gpu
from gpu_extras.batch import batch_for_shader

coords = [(0,0,0), (0,1,0), (0,0,1)]
normals = [(1,0,0), (1,0,0), (1,0,0)]
colors = [(0.5,0.5,0.5, 1), (0.5, 0.5, 0.5, 1), (1.0, 1.0, 0.5, 1)]

shader = gpu.shader.from_builtin('3D_FLAT_COLOR')
batch = batch_for_shader(shader, 'TRIS', {"pos": coords, "color": colors, "normal": normals})

def draw():
    shader.bind()
    batch.draw(shader)

bpy.types.SpaceView3D.draw_handler_add(draw, (), 'WINDOW', 'POST_VIEW')

If anyone has an idea what I am doing wrong, I would appreciate any help. Thanks very much, and thanks for making this awesome software.

1 Like