Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

Forked from anonymous/
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):
- 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)
- 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.glBlendFunc(bgl.GL_SRC_ALPHA, bgl.GL_ONE_MINUS_SRC_ALPHA)
# 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment