pythreejs icon indicating copy to clipboard operation
pythreejs copied to clipboard

BufferGeometry/Attribute Lifecycle - Strange Behavior

Open jjennings955 opened this issue 6 years ago • 4 comments

The attributes dictionary of a BufferGeometry seems to be populated in a strange/unintuitive way.

It appears that it isn't available (in some cases) until you run a new cell in jupyter (and "run all" doesn't count).

I attached a gist with a minimal-ish example.

Example

jjennings955 avatar Apr 10 '19 03:04 jjennings955

This issue is inherent to the way that pythreejs works: It is only a remote wrapper around three.js. This means that three.js has the code responsible for filling out the buffer attributes, and pythreejs knows nothing about it until three.js tells it the results. As such, trying to use the buffer attributes of a geometry created with from_geometry is not a recommended pattern. Instead, you can create the buffer geometries directly (e.g. copy pasting what you get with from_geometry into your code). If you only want a buffer geometry without access to the attributes, you can use IcosahedronBufferGeometry etc.

vidartf avatar Apr 10 '19 12:04 vidartf

It seems like if certain attributes are going to be undefined until some action is taken on the threejs side, some asynchronous pattern (like Futures/Promises) should be used.

jjennings955 avatar Apr 12 '19 22:04 jjennings955

@jjennings955 There is a guide for asynchronous widgets here: https://ipywidgets.readthedocs.io/en/stable/examples/Widget%20Asynchronous.html

Any suggestions for how to help integrate pythreejs with such a setup are very welcome 😃

vidartf avatar Apr 13 '19 00:04 vidartf

The code is a bit too complex for me to make sense of. There are a lot of callbacks internally in ipywidgets, so it should be possible to hook into one of those and recognize when the attributes have been created.

Something like buffer_geometry.observe(some_callback, 'attributes') would be great if it worked (but it doesn't seem to).

Unfortunately right now, there's really no way to know when these attributes have actually been created.

jjennings955 avatar Apr 13 '19 01:04 jjennings955