jupyter-widgets / pythreejs

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

How to hold / pause / batch visible updates? Animation related #290

Closed hagrid67 closed 1 year ago

hagrid67 commented 4 years ago

Hi, may I ask if it's possible to stop the visible canvas updating, until a batch of updates has been made to object locations?

I'm implementing some simple animation from python, moving some objects around and moving the camera. I need to keep the logic of the updates in the python side (ie I don't think I can set up a deterministic animation sequence in three / pythreejs, I need each step to come from python). Moving several objects around and moving the camera results in quite a jumpy animation: it seems to update the canvas after each individual object move.

Is there a way of pausing the visible updates until I've moved everything, then telling it to update?

I've tried setting scene.autoUpdate=False, and setting matrixAutoUpdate to False on the object meshes, but it doesn't seem to make any difference.

(I haven't yet tried doing a similar thing in pure JS / threejs so I don't know if this would work there. it tends to run faster there anyway.)

Many thanks!

vidartf commented 4 years ago

ipywidgets has a context manager for this exact purpose:

with my_widget.hold_sync():
    my_widget.a = 5
    my_widget.b = 'foo'

Let me know if this works for you!

hagrid67 commented 4 years ago

Hey thanks Vidar - I've tried but I'm not sure it is. I'll try to make an obvious example I can share.

vidartf commented 4 years ago

Please also check if #292 / #293 addresses your concerns. On the other hand, if you want to control every draw (without user camera control), you might want to consider using the WebGLRenderer (there should be an example in the examples folder).

vidartf commented 1 year ago

Closing as answered.