I would like to export the verts of a 3D object as 2D coordinates relative to the camera region (in pixels or floats from 0,1 so it’s resolution independent) - to use in 2D compositing.
Did some searching and, found the utility function location_3d_to_region_2d that almost does this, but returns pixels relative to the whole viewport region not to the camera “letterbox”. Is there a way to compute the 2D coordinates relative to the camera/resolution? Maybe by substracting the Passepartout region? I am not sure where to get that from. Also it seems that the sensor/gate mode (vertical,horizontal) influences the behavior of the Camera viewport.
from bpy_extras.view3d_utils import location_3d_to_region_2d my_region = C.screen.areas.spaces.region_3d #hardcoded region/pane of my screen location_3d_to_region_2d(bpy.context.region, my_region ,bpy.data.objects["Cube"].data.vertices.co)