gpu.4.py 712 B

12345678910111213141516171819202122232425262728293031
  1. """
  2. Wireframe Cube using Index Buffer
  3. ---------------------------------
  4. """
  5. import bpy
  6. import gpu
  7. from gpu_extras.batch import batch_for_shader
  8. coords = (
  9. (-1, -1, -1), (+1, -1, -1),
  10. (-1, +1, -1), (+1, +1, -1),
  11. (-1, -1, +1), (+1, -1, +1),
  12. (-1, +1, +1), (+1, +1, +1))
  13. indices = (
  14. (0, 1), (0, 2), (1, 3), (2, 3),
  15. (4, 5), (4, 6), (5, 7), (6, 7),
  16. (0, 4), (1, 5), (2, 6), (3, 7))
  17. shader = gpu.shader.from_builtin('3D_UNIFORM_COLOR')
  18. batch = batch_for_shader(shader, 'LINES', {"pos": coords}, indices=indices)
  19. def draw():
  20. shader.bind()
  21. shader.uniform_float("color", (1, 0, 0, 1))
  22. batch.draw(shader)
  23. bpy.types.SpaceView3D.draw_handler_add(draw, (), 'WINDOW', 'POST_VIEW')