Skip to content

Instantly share code, notes, and snippets.

@zeffii
Created April 19, 2017 10:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zeffii/06bd602aacf8f050966b1b4696ffc085 to your computer and use it in GitHub Desktop.
Save zeffii/06bd602aacf8f050966b1b4696ffc085 to your computer and use it in GitHub Desktop.
2d grid drawing GL_QUADS
"""
in in_colors v d=[[]] n=0
out dummy_out s
"""
import math
import bgl
import bpy
from sverchok.data_structure import node_id
from sverchok.ui import nodeview_bgl_viewer_draw_mk2 as nvBGL2
def get_location(i):
items_wide = 40
offset_x = 5
offset_y = 5
x = offset_x * (i % items_wide)
y = offset_y * math.floor(i / items_wide)
return [x, y]
self.n_id = node_id(self)
nvBGL2.callback_disable(self.n_id)
def simple_color_viewer_nvBGL(x, y, args):
colors = args[0]
size = 10.0
bgl.glEnable(bgl.GL_POINT_SMOOTH)
bgl.glPointSize(size)
bgl.glBlendFunc(bgl.GL_SRC_ALPHA, bgl.GL_ONE_MINUS_SRC_ALPHA)
for color_list in colors:
bgl.glBegin(bgl.GL_QUADS)
for idx, color in enumerate(color_list):
bgl.glColor4f(*color)
coord = get_location(idx)
tx = coord[0] + x
ty = coord[1] + y
w = size//2
h = size//2
coords = [(tx, ty), (tx+w, ty), (w+tx, ty-h), (tx, ty-h)]
for coord in coords:
bgl.glVertex2f(*coord)
bgl.glEnd()
bgl.glDisable(bgl.GL_POINT_SMOOTH)
bgl.glDisable(bgl.GL_POINTS)
socket = self.inputs['in_colors']
if socket.links:
draw_data = {
'tree_name': self.id_data.name[:],
'mode': 'custom_function',
'custom_function': simple_color_viewer_nvBGL,
'loc': (self.location[:]),
'args': (socket.sv_get(),)
}
nvBGL2.callback_enable(self.n_id, draw_data)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment