jupyter-widgets / pythreejs

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

Widget controls for time #269

Closed jhmitchel closed 5 years ago

jhmitchel commented 5 years ago

Relatively new to pythreejs. I created an animation that has gotten quite long. The only time controls for the widget are play, pause, stop, and reset. I can't seem to find any support or guidance on how to add time controls where one could select a time (either via a scrubber or directly entering a value) in the animation to jump to.

Is this supported (either directly or indirectly)? If so, what is the best method or tool for this.

jasongrout commented 5 years ago

Are you using the play widget? Can you just create an int slider and link that also to your time variable?

jhmitchel commented 5 years ago

I tried using jslink to link an int slider to the time numpy array I pass into NumberKeyframeTrack. But jslink requires linking between Widget objects. Is there a way to represent time in a Widget object (as opposed to a numpy array)? Or am I misunderstanding another opportunity?

vidartf commented 5 years ago

I haven't had time to play around with this myself, but from looking at the code, here are some observations:

jhmitchel commented 5 years ago

I tried setting the animation time input to the slider value (animation = AnimationAction(..., timeScale=playback_speed, time=slider.value)) but then the slider had no effect on on the time of the animation. Is that what you were suggesting or am I misunderstanding?

jhmitchel commented 5 years ago

This example actually shows very clearly what I want: https://ipywidgets.readthedocs.io/en/stable/examples/Widget%20List.html#Play-(Animation)-widget

The problem is I don't know how to access the Play Widget of the animation (which is the mechanism used there that I would like to replicate). Any thoughts there?

vidartf commented 5 years ago

You would have to link the time values using jslink, as you see in your linked example:

animation = AnimationAction(...)
ipywidgets.jslink((animation, 'time'), (slider, 'value'))
vidartf commented 5 years ago

One improvement on the pythreejs side would be to have AnimationAction sync its time back to the kernel in a conflatable way.

jhmitchel commented 5 years ago

Agreed a two way link would be an improvement. But what you suggested worked one way. Thank you!

vidartf commented 5 years ago

Nice, thanks for reporting back :)

vidartf commented 5 years ago

Closing as answered then, but let me know if there is anything outstanding here, and I'll reopen.