3
$\begingroup$

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.

$\endgroup$
4
  • $\begingroup$ Have a look to: wiki.blender.org/wiki/Building_Blender/Other/BlenderAsPyModule $\endgroup$
    – lemon
    Commented Mar 21, 2020 at 7:49
  • $\begingroup$ 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. $\endgroup$
    – EMon
    Commented Mar 22, 2020 at 17:33
  • $\begingroup$ @lemon Do you have any results to share? $\endgroup$ Commented Jun 9, 2020 at 16:27
  • $\begingroup$ 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? blender.stackexchange.com/questions/190140/… $\endgroup$
    – reg.cs
    Commented Aug 7, 2020 at 23:01

0

You must log in to answer this question.

Browse other questions tagged .