-
-
Save zeffii/8792546 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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