I started an add-on by copying operators and ended up using numpy. I have some raw 3D-vertex-coords and need there 2D-viewport-coords. I'd like to do the following, but with numpy:
for area in bpy.context.screen.areas:
if area.type == 'VIEW_3D':
viewport = area.regions[4]
selvrts = [v for v in bpy.context.active_object.data.vertices if v.select]
for v in selvrts:
#coo in 3d space Blender 2.8
co_3d = oa.matrix_world @ v.co
#coo in the 3d view area (2d)
co_2d = view3d_utils.location_3d_to_region_2d(viewport, area.spaces[0].region_3d, co_3d)
Looping over the coords is somehow an interruption, since I'm continuing with numpy calculations afterwards. I need to know, which connected vertex the user sees left or right from the selected vertex.
At the moment I went thus far but couldn't find the code to get the 2D-coords.
for area in bpy.context.screen.areas:
if area.type == 'VIEW_3D':
viewport = area.regions[4]
# Add an extra 1.0s column (for matrix dot product)
coB = np.c_[cB, np.ones(cB.shape[0])]
# Then:
# Dot product matrix with the coords transpose
# Keep the first 3 rows (x,y,z)
# Transpose result to Nx3
# Flatten
coB = np.dot(oa.matrix_world, coB.T)[0:3].T.reshape((-1))
coB = coB.reshape(cB.shape)
How can I get 2D-viewport-coords with numpy?
scripts/modules/bpy_extras/view3d_utils.py
$\endgroup$