-
Notifications
You must be signed in to change notification settings - Fork 233
ShaderLib2D
Dealga McArdle edited this page May 20, 2021
·
9 revisions
implementing the current prototype/version of the node timer / time graph has introduced a new drawing library, which will let the user compile shader geometry into a canvas
. It takes care of some of the tedious stuff behind the scene. Essentially it has a a few shapes that can be drawn at given coordinates with given colours.
from sverchok.utils.modules.shader_utils import ShaderLib2D
canvas = ShaderLib2D()
# add a rectangle of W * H at X, Y, with a solid rgb (3-tuple) of
canvas.add_rect(x, y, w, h, rgb_color)
# for more specialized drawing requirements you can generate your own verts, colors and face indices
# and add them to the total geom this way
canvas.add_data(verts, colors, indices)
geom = canvas.compile()
# then you can pass all shapes in one go to the batch draw.
# -- importing the appropriate `batch_from_shader` and `gpu` too. (not shown here)
shader = gpu.shader.from_builtin('2D_SMOOTH_COLOR')
batch = batch_for_shader(shader, 'TRIS', {"pos": geom.vectors, "color": geom.vertex_colors}, indices=geom.indices)
batch.draw(shader)
the following shapes are not yet implemented
def add_rect_rounded(self, x, y, w, h, color, radius=0, precision=5):
...
def add_line(self, x1, y1, x2, y2, width, color):
...
def add_polyline(self, path, width, color):
...
def add_bezier(self, controls, width, color, samples=20, resampled=False):
...
def add_circle(self, x, y, radius, color, precision=32):
...
def add_arc(self, x, y, start_angle, end_angle, radius, width, color, precision=32):
...