3

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:

  1. 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)
  2. calling bpy.ops.render.render() - even slower
  3. 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.

EMon
  • 131
  • 4
  • Have a look to: https://wiki.blender.org/wiki/Building_Blender/Other/BlenderAsPyModule – lemon Mar 21 '20 at 07:49
  • Very cool! will definitely try that out, although I suspect/fear that the render time will be the same as when running python from blender. Worth a shot though. – EMon Mar 22 '20 at 17:33
  • @lemon Do you have any results to share? – Dustin Oprea Jun 09 '20 at 16:27
  • Just discovered this question. I am currently also dealing with this problem and I got at least something working. However, it's not satisfying though. Did you make any progress since you posted here, @EMon? https://blender.stackexchange.com/questions/190140/copy-framebuffer-of-3d-view-into-custom-frame-buffer – reg.cs Aug 07 '20 at 23:01

0 Answers0