I have a python script that receives data over a socket and uses that data to update a scene. The resulting render of that scene then needs to be sent to an output socket. This needs to occur in real-time (50-60fps) The viewport render is very fast, and has a high enough quality to work for my needs. How can I trigger a viewport render from a python script and then access those pixels?
Some things I've tried:
- calling bpy.ops.render.opengl() from the script. This is a lot slower than the live viewport render (which surprised me because I thought this was what the viewport was doing)
- calling bpy.ops.render.render() - even slower
- calling bpy.types.SpaceView3D.draw_handler_add() and from within the handler, calling offscreen.draw_view3d(). Same problem. -- For this one, I would "think" that in the draw handler, the pixels already exist somewhere in the system (and there would be no need to call draw_view3d()). But, glReadPixels() does not work.
Any other ideas?
I've looked at: How to access Render Result pixels from python script? (the solution for which is not fast enough)
and
Accessing Viewport Render Result pixels from script (doesn't have a solution, but what it does have doesn't solve my issue)
and https://docs.blender.org/api/current/gpu.html
and reviewed the docs here: https://docs.blender.org/api/current/gpu.html
In none of these cases have I been able to both (a) render fast enough, and (b) retrieve the pixels
I am open to hacking the blender source code as well, but could use some guidance determining where to begin.