K3D-tools / K3D-jupyter

K3D lets you create 3D plots backed by WebGL with high-level API (surfaces, isosurfaces, voxels, mesh, cloud points, vtk objects, volume renderer, colormaps, etc). The primary aim of K3D-jupyter is to be easy for use as stand alone package like matplotlib, but also to allow interoperation with existing libraries as VTK.
MIT License
953 stars 121 forks source link

model_matrix not updated when using manipulators #426

Open wmalara opened 1 year ago

wmalara commented 1 year ago

Description

When manipulating an object in plot "manipulate" mode the object's model matrix doesn't get updated and also "observe" callback is not fired. I found that it's probably because of this commented out code: https://github.com/K3D-tools/K3D-jupyter/blob/main/js/src/providers/threejs/initializers/Manipulate.js#L18 and could probably simply create a PR reversing this, but I guess there is some broader context of this change I don't know :) (https://github.com/K3D-tools/K3D-jupyter/commit/46d508b39255fc16e2ed7704fcadb5dae6d61952#diff-6863658dc28ee81ff40444d18191cad7547592119a5f4a302ecee062b6bb428f).

Simple example

import k3d
import k3d.platonic

plot = k3d.plot()
cube = k3d.platonic.Cube().mesh
plot += cube
plot
plot.mode = "manipulate"
plot.manipulate_mode = "rotate"
cube.observe(print)

When manipulating the object the callback is not fired and when checking the model_matrix directly:

cube.model_matrix

it's still an identity matrix:

array([[1., 0., 0., 0.],
       [0., 1., 0., 0.],
       [0., 0., 1., 0.],
       [0., 0., 0., 1.]], dtype=float32)