Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@zeffii
Forked from anonymous/donkle.py
Last active August 29, 2015 13:56
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/8792546 to your computer and use it in GitHub Desktop.
Save zeffii/8792546 to your computer and use it in GitHub Desktop.
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 and style of gl_points
bgl.glEnable(bgl.GL_POINT_SMOOTH) # for round vertex
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