-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Add :meth:~.Scene.interactive_embed
for OpenGL rendering
#1285
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add :meth:~.Scene.interactive_embed
for OpenGL rendering
#1285
Conversation
Maybe a better name for this could be thought of? Such as |
I used |
The interactive part is working as it should, but the embed part does not function properly. Neither |
What OS are you using? |
Also what command are you using to test with? |
Ubuntu 20.04
Code:
|
Turns out that making it possible to prepend |
|
That doesn't happen for me. It'd help if you could find out which line is hanging (adding in print statements should be enough to figure it out). The |
I don't know why but I solved the problem by only adding a print statement on line 983 as follows, does this make any sense?
|
uh, not really :/ |
Prints fixing things is typically a sign of a race condition somewhere in my experience |
Mine too, but the multithreading here doesn't have anything to block on. It'd probably be easiest for me to debug this over a discord call, but in the meantime there are a few questions that might be helpful:
|
That's expected, though it may be worth adding some sort of guard against prepending |
So can this be approved now? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I approve but with a cautionary note that I've mainly just verified it functions on my machine and skimmed over scene.py's implementation. The other files seem fine.
I do find it odd that ipython_magic.py can make use of self.play
, self.wait
, self.add
and self.remove
but interactive_embed
cannot. I've requested @behackl read over this due to writing ipython_magic.py and having an understanding of the package.
~.Scene.interactive_embed
for OpenGL rendering
It's probably because when manim is used in ipython the interpreter doesn't need to continually rerender the screen and listen for user input simultaneously. |
I think that's essentially true. The Interactivity certainly makes things more complicated; this was also something we observed in the livestreaming approach over at #778 -- there it was also easier to make special |
Changelog / Overview
:meth:
~.Scene.interactive_embed
allows interaction with Scene via mouse and keyboard as well as dynamic commands via an iPython terminal.Motivation
Scene.interactive_embed()
allows screen interaction and dynamic commands simultaneously as opposed toScene.embed()
, which only allows dynamic commands andScene.interact()
, which only allows screen interaction.Explanation for Changes
Scene.interactive_embed()
runs an IPython terminal in a separate thread which communicates with the main thread via a shared queue. This allows screen interaction and dynamic control via the terminal simultaneously.Testing Status
I tested with the following Scene:
on the last line a live terminal will spawn and the screen will still be interactive.
Further Comments
Attempting to render from the terminal thread will result in a segfault. This is because OpenGL contexts are bound to a single thread. The add, remove, play, and wait methods are communicated to the renderer thread via a shared queue (so the action is performed on the renderer thread). This means that running
self.play(...)
(as opposed toplay(...)
) will crash.Things like updating mobject attributes works as expected (even though data is updated on the terminal thread and read on the renderer thread) but I'm not sure whether this is actually safe or just luck.
Checklist
Reviewer Checklist