jupyter-widgets / pythreejs

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

Saved widget state not producing same output than live notebook. #201

Closed KelSolaar closed 5 years ago

KelSolaar commented 6 years ago

Hi,

It seems like the widget state might not be fully saved. Taking the following notebook which requires latest Colour develop branch: https://nbviewer.jupyter.org/github/colour-science/colour-ramblings/blob/master/pythreejs_ramblings.ipynb

This is how it looks in the live notebook: image

And this is once the state is saved and viewed with NBViewer: image

It seems like some of the vertex colours or a related attribute is not saved and the rotations are not preserved.

Cheers,

Thomas

vidartf commented 6 years ago

For the rotation, I would recommend you rotate the objects, not the geometries. I.e. rotate the Mesh and Line and LineSegments. That only changes the transform matrix of the objects, not the underlying vertices, and should therefore be simpler.

It's harder to determine why the vertex colors are not retained properly. I'll run some smaller tests here.

There does also seem to be an issue with pythreejs where it doesn't recognize the need to sync back the updated vertices array of the geometry. I'll look further into that.

maartenbreddels commented 6 years ago

There does also seem to be an issue with pythreejs where it doesn't recognize the need to sync back the updated vertices array of the geometry. I'll look further into that.

wouldn't be surprised if that is an underscore issue (_.eq) with typed arrays, it doesn't detect changes (or was is that it always thinks it is different

Niolon commented 5 years ago

I do have a similar problem. When I do rotate the objects not the meshes, this rotation is not embedded in the widget state. I attached a minimal (non-)working notebook with two ellipsis and one tube connecting the two positions. Everything looks fine in the live notebook, but not when opening it up again or exporting the notebook state. It would be really awesome to have this for rotatable 3d (molecular) models in a reveal.js exported presentation.

illustrate.zip

vidartf commented 5 years ago

Sorry for this taking a while, but I have now submitted a fix in #226. The different orientation properties (rotation, quaternion and matrix) were interfering with each other.

The vertex color issue is also solved in the same PR: it was an issue with how the faces of Geometry was serialized. In general though, I would recommend to switch to use BufferGeometry over Geometry though. It should be more performant in almost all aspects.