Skip to content

Instantly share code, notes, and snippets.

Created February 3, 2014 13:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/8784212 to your computer and use it in GitHub Desktop.
Save anonymous/8784212 to your computer and use it in GitHub Desktop.
test
import bpy
import bgl
from bpy_extras.view3d_utils import location_3d_to_region_2d as loc3d2d
# (...)
def draw_points(context, points, size, gl_col):
"""
input
- context: bpy.context ( a 3d view )
- points: a list/iterable of proper vectors
- size: dot/vertex size, pixels
- gl_col: rgba as tuple (0.2, 0.9, 0.2, .2)
outpt
- draws points to screen.
loc3d2d is renamed during import purely
because it's a big whopping function name
"""
region = context.region
rv3d = context.space_data.region_3d
this_object = context.active_object
matrix_world = this_object.matrix_world
# needed for adjusting the size of gl_points
bgl.glEnable(bgl.GL_POINT_SMOOTH)
bgl.glPointSize(size)
bgl.glBlendFunc(bgl.GL_SRC_ALPHA, bgl.GL_ONE_MINUS_SRC_ALPHA)
bgl.glBegin(bgl.GL_POINTS)
bgl.glColor4f(*gl_col)
# for each vector in points, call bgl.glVertex2f
for coord in points:
vector3d = matrix_world * coord
vector2d = loc3d2d(region, rv3d, vector3d) # returns a 2-tuple
bgl.glVertex2f(*vector2d) # needs a 2d vector to draw to 2d screen
bgl.glEnd()
bgl.glDisable(bgl.GL_POINT_SMOOTH)
bgl.glDisable(bgl.GL_POINTS)
return
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment