-
Notifications
You must be signed in to change notification settings - Fork 194
bitmap output #22
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
Comments
Yep, there are ways to do it, but we are not set up to do it yet. We'll keep this issue open as a todo item. |
Thanks.. |
from this post |
no, not hard at all. Or we can do it with the webgl renderer, as in the first answer. |
This also looks interesting: http://stackoverflow.com/a/22579139 |
I was also wondering if it is possible to use ipython it self maybe trough some trickery with display() ? |
Has there been any updates on this issue (e.g., concrete |
Bumping this issue |
In ipyvolume I do screenshots by indeed saving the canvas to a png, and sending that over the wire. I think a good way so solve this issue (and #167) is to make the renderer an (ipywebrtc) MediaStream, and put this feature in ipywebrtc. The video part is already working, I think it's not so difficult to add what is done on the backend and frontend to ipywebrtc (frontend and backend) Pythreejs's renderer needs to inherit from from MediaStream (backend) and deliver a mediastream (for the first view) on the frontend. |
There is a gory way of doing that, if you start diving into this part which ends up doing a busy loop |
I saw the busy loop, but I was wondering whether it would be possible for the def screenshot(self):
self.screenshot_ready = False
content = {
"type": "screenshot"
}
self.send(content)
busy_loop()
return self.screenshot_data However, when I tried this the returned data seems to be gobbled up. Is moving this into ipywebrtc/jupyter-webrtc and introducing a new dependency for pythreejs something the maintainers of this project want? |
I haven't seen gobbled up data, but I have seen the output coming after that being all over the place. That's why I use |
I'm a lot more concerned about the PIL dependency than about the ipywebrtc one, but hopefully using ipywebrtc can solve that. I'm all for having a way to render to a ipywebrtc.MediaStream. Whether that should be the default for all I'm also concerned about the |
As a workaround, I copied ipyvolume's JavaScript code for saving screenshots in the browser and added a Python method to trigger this (based on @elPistolero's code). The modified code is here. I use the code like this: for i in range(k):
# prepare and display scene i
time.sleep(0.5)
renderer.download_screenshot('screenshot-{}.png'.format(i))
clear_output() Results are super flimsy: It seems to only work with the delay between display and the call to |
In the "(really) hacky workarounds" category, a method I use that doesn't require modification of pythreejs is to grab the canvas from the jupyter notebook DOM with javascript injection, and pass the output to python with That is, assuming you only have one pythreejs canvas, use var canvas = $('canvas')[0];
var data = canvas.toDataURL();
Jupyter.notebook.kernel.execute("canvas_data = '" + data + "'"); Then after a few milliseconds, png_data = base64.decodestring(canvas_data[21:])
pil_img = Image.open(StringIO(png_data)) This is slightly more convenient, I think, than the above method, but still a big hack, of course. |
The current long term plan here is to try to integrate ipywebrtc into pythreejs. I think I will try to bug @maartenbreddels a bit to help me get started though ;) |
https://ipywebrtc.readthedocs.io/en/latest/WidgetStream.html + https://ipywebrtc.readthedocs.io/en/latest/ImageRecorder.html should allow you to capture images, the first demos capturing a movie, but if you stick the WidgetStream into the ImageRecorder, you should be set. |
Sure, I was just thinking there would be some possible optimizations by integrating it fully instead of relying on |
ThreeJS has the method SVGRenderer that does exactly this. Pythreejs should have a wrapper for this. |
Is there a way for producing a bitmap image of the rendnering ? Looking at some threejs examples I found that from threejs it is in principle possible to produce a png output, but if I am not mistaken pythreejs is not yet setup to do so.
The text was updated successfully, but these errors were encountered: