Hello everyone, I want to upgrade my addon from 2.7 to 2.8. I need to draw some faces from bmesh over mesh in viewport. Previously it was done using bgl.glBegin(bgl.GL_POLYGONS). After many tries in 2.8 I generate vertices list and indices list for batch_for_shader, but this methon doesn’t work with n-gons, just with triangles. So, how can I draw bm.faces[0:9] for example, if some of them are tris, some quads and n-gons?
or, maybe, how to convert this script from api for using with bmesh module:
import bpy
import gpu
import numpy as np
from random import random
from gpu_extras.batch import batch_for_shader
mesh = bpy.context.active_object.data
mesh.calc_loop_triangles()
vertices = np.empty((len(mesh.vertices), 3), 'f')
indices = np.empty((len(mesh.loop_triangles), 3), 'i')
mesh.vertices.foreach_get(
"co", np.reshape(vertices, len(mesh.vertices) * 3))
mesh.loop_triangles.foreach_get(
"vertices", np.reshape(indices, len(mesh.loop_triangles) * 3))
vertex_colors = [(random(), random(), random(), 1) for _ in range(len(mesh.vertices))]
shader = gpu.shader.from_builtin('3D_SMOOTH_COLOR')
batch = batch_for_shader(
shader, 'TRIS',
{"pos": vertices, "color": vertex_colors},
indices=indices,
)
def draw():
batch.draw(shader)
bpy.types.SpaceView3D.draw_handler_add(draw, (), 'WINDOW', 'POST_VIEW')