Discussion:
[Bf-python] Non-blocking OpenGL animation rendering.
Adhi Hargo
2013-05-27 09:32:06 UTC
Permalink
Hi, everyone.

I'm currently writing a custom preview render operator, internally
calling bpy.ops.render.opengl(). The problem is, opengl() runs
blocking (made the UI unresponsive) if called from another operator,
though it isn't if called directly from GUI. I see that executing it
runs the underlying C function, screen_render_exec, which is blocking.

Is there any way to get non-blocking OpenGL render from Python code? I
haven't found any addon/sample that does this. Tried using
context.window_manager.invoke* functions, or running it in a separate
thread, but they crash Blender. If all else fails, I may have to spawn
new Blender process to do the job.

Thank you in advance.

--
- Adhi Hargo
Campbell Barton
2013-05-27 09:48:11 UTC
Permalink
No, there is no way to do this currently.

And running operators from a thread isnt supported (as you already found)

The reason is cycles and blender-internal make a copy of the data and
operate on it, where as opengl render is just rendering the viewport
to an offscreen buffer which makes it more tricky to do at the same
time as the user interacting with the same view -without getting into
problematic conflicts.
Post by Adhi Hargo
Hi, everyone.
I'm currently writing a custom preview render operator, internally
calling bpy.ops.render.opengl(). The problem is, opengl() runs
blocking (made the UI unresponsive) if called from another operator,
though it isn't if called directly from GUI. I see that executing it
runs the underlying C function, screen_render_exec, which is blocking.
Is there any way to get non-blocking OpenGL render from Python code? I
haven't found any addon/sample that does this. Tried using
context.window_manager.invoke* functions, or running it in a separate
thread, but they crash Blender. If all else fails, I may have to spawn
new Blender process to do the job.
Thank you in advance.
--
- Adhi Hargo
_______________________________________________
Bf-python mailing list
Bf-python at blender.org
http://lists.blender.org/mailman/listinfo/bf-python
--
- Campbell
Mohamed Sakr
2013-05-27 10:36:14 UTC
Permalink
Hey Canpbell,

I know this is off topic And kinda jumping over the topic so I'm sorry
but I NEED your help to integrate my addon into the trunk

http://blenderartists.org/forum/showthread.php?284678-MSMesher
Post by Campbell Barton
No, there is no way to do this currently.
And running operators from a thread isnt supported (as you already found)
The reason is cycles and blender-internal make a copy of the data and
operate on it, where as opengl render is just rendering the viewport
to an offscreen buffer which makes it more tricky to do at the same
time as the user interacting with the same view -without getting into
problematic conflicts.
Post by Adhi Hargo
Hi, everyone.
I'm currently writing a custom preview render operator, internally
calling bpy.ops.render.opengl(). The problem is, opengl() runs
blocking (made the UI unresponsive) if called from another operator,
though it isn't if called directly from GUI. I see that executing it
runs the underlying C function, screen_render_exec, which is blocking.
Is there any way to get non-blocking OpenGL render from Python code? I
haven't found any addon/sample that does this. Tried using
context.window_manager.invoke* functions, or running it in a separate
thread, but they crash Blender. If all else fails, I may have to spawn
new Blender process to do the job.
Thank you in advance.
--
- Adhi Hargo
_______________________________________________
Bf-python mailing list
Bf-python at blender.org
http://lists.blender.org/mailman/listinfo/bf-python
--
- Campbell
_______________________________________________
Bf-python mailing list
Bf-python at blender.org
http://lists.blender.org/mailman/listinfo/bf-python
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.blender.org/pipermail/bf-python/attachments/20130527/ce5a170d/attachment.htm
Adhi Hargo
2013-05-29 01:25:36 UTC
Permalink
Thanks, Campbell. Stopped mucking with threads, timers and whatnot
when I read that. I have two issues that led to a further question:

1. I just realized that passing "INVOKE_DEFAULT" runs the render job
on a separate thread, what I want in the first place. But I
temporarily change some render settings, and it's restored way too
early, even before the render job began. Delaying with time.sleep
doesn't work. I need some way to poll the render.opengl() operator,
anything to delay execution of post-render code.

2. My current solution to get non-blocking render + temporary render
setting is creating a Blender subprocess (using subprocess.Popen) to
render the file. Ugly, but it works. The problem is, user still can't
cancel the render, because though the subprocess itself can be
terminated, its render thread just gets severed from the process and
won't die before render finishes.

Basically I just need to know, is there's some way to communicate with
a running render thread or operator, from Python code?

Thank you in advance for any help. The code I'm working on is here:
http://git.io/O3JqoQ
Post by Campbell Barton
No, there is no way to do this currently.
And running operators from a thread isnt supported (as you already found)
The reason is cycles and blender-internal make a copy of the data and
operate on it, where as opengl render is just rendering the viewport
to an offscreen buffer which makes it more tricky to do at the same
time as the user interacting with the same view -without getting into
problematic conflicts.
--
- Adhi Hargo
Loading...