Closed ghost closed 2 years ago
hi @MironLeon
K3D is build over ipywidgets. Ipywidgets are build over traitlets :) - so...
import k3d
import ipywidgets
out = ipywidgets.Output()
plot = k3d.plot()
plot.display()
def on_camera_change(c):
with out:
print(c)
plot.observe(on_camera_change, 'camera')
out
Please look at line:
plot.observe(on_camera_change, 'camera')
btw you can obvserve any attribute of plot and any of objects iny K3D! :)
Thanks! Didn't think it would be that easy
From the docs:
Is there any way to execute your own python code on camera changed events? I have been searching through the code a bit:
https://github.com/K3D-tools/K3D-jupyter/blob/dab98020eef3a7c92e04d462342810d2d324ab77/js/src/providers/threejs/initializers/Canvas.js#L21
https://github.com/K3D-tools/K3D-jupyter/blob/539c53cab580d55b8841bb87589ab3d4cf95bdb0/js/src/k3d.js#L355
and it seems to revolve around this
K3D.events.CAMERA_CHANGE
event, but I can not find wherek3d.plot.camera
is updated on the python side