I'm trying to randomly place many dense objects onto a plane centered at the origin (0,0,0) without overlap. I figured out a way to do this using 3D mesh intersection but the time it takes to conduct placement with lots of object instances is undesirable. I have a camera that points directly downward at the plane (0,0,Z) on which the objects will be placed. Since the camera resolution is known, I had an idea to create a 2D list of pixels in the rendered camera image and use 2D collision algorithms with the bounds of my objects as seen from the camera to place my objects instead. I could effectively calculate object positions in 2D and then use the list of center points and rotations to place the objects in Blender using bpy. For my purposes I am fine with all of the objects resting flat on the plane.
The problem is I'm not sure how to go about translating my object bounds from 3D to 2D, and then translating my calculated origin points from 2D back to 3D. I know what the exact dimensions of my objects are in Blender units but I don't know how to translate that to measurements in rendered image pixels. I also don't know how to effectively map my 2D points onto the plane in Blender from the camera's perspective. I'm fairly new to Blender and don't know too much about matrix math, but I imagine there must be a way to do this using view3d_utils.region_3d_to_location_2d
and view3d_utils.region_2d_to_location_3d
. Any assistance in how to get something like this set up would be greatly appreciated.