jupyter-widgets / pythreejs

A Jupyter - Three.js bridge
https://pythreejs.readthedocs.io
Other
951 stars 188 forks source link

generate image files from canvas #106

Closed cekees closed 5 years ago

cekees commented 7 years ago

Our team is looking for a way to generate image frames (for animations) based on our pythreejs canvas. Would this be a worthwhile thing for us to try adding to pythreejs?

https://stackoverflow.com/questions/15558418/how-do-you-save-an-image-from-a-three-js-canvas

abelnation commented 7 years ago

We actually already generate images from the canvas for the purposes of "freezing" the canvas when it's not in use. So yes, it's possible, and probably not that hard to add.

On Tue, Jun 20, 2017 at 8:24 AM, Chris Kees notifications@github.com wrote:

Our team is looking for a way to generate image frames (for animations) based on our pythreejs canvas. Would this be a worthwhile thing for us to try adding to pythreejs?

https://stackoverflow.com/questions/15558418/how-do-you- save-an-image-from-a-three-js-canvas

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/jovyan/pythreejs/issues/106, or mute the thread https://github.com/notifications/unsubscribe-auth/AAMNduZ4UqsKhk72izyB94LcHL1TxMAoks5sF-QSgaJpZM4N_wDc .

-- Abel Allison abel.allison@gmail.com

elPistolero commented 6 years ago

I'm trying to implement this. From what I understand I need to register a callback in Renderer.py:

self.on_msg(self._screenshot_ret_val)

And in Renderable.js I have a screenshot function that sends data back to the python side:

this.send({
    type: '...',
    method_name: 'screenshot',
    ret_val: ...,}, this.callbacks(), null);

However, I'm unclear on how ret_val needs to be packaged. I tried to set ret_val: this.renderer.domElement.toDataURL(), but then session.py complained that it could not handle a string and was expecting a byte object. Are there some js functions I can call with exec_three_obj_method that actually return something so that I can gain a better understanding on how the communication from javascript to python is supposed to work? I tried calling localToWorld from Object3D.js but that method could not be found.

maartenbreddels commented 6 years ago

see also my comment here