gltfjsx icon indicating copy to clipboard operation
gltfjsx copied to clipboard

Error when using typescript flag on object with animation

Open jerricko opened this issue 1 year ago • 3 comments

I get the following error when running gltjsx -t ./{model}.gltf on any model that has an animation:

TypeError: Cannot read properties of undefined (reading 'name') at file:///**/.npm/_npx/16b3f312213fced0/node_modules/gltfjsx/src/utils/parser.js:103:60 at Array.map (<anonymous>) at printTypes (file:///**/.npm/_npx/16b3f312213fced0/node_modules/gltfjsx/src/utils/parser.js:103:34) at parse (file:///**/.npm/_npx/16b3f312213fced0/node_modules/gltfjsx/src/utils/parser.js:436:27) at file:///**/.npm/_npx/16b3f312213fced0/node_modules/gltfjsx/src/gltfjsx.js:52:26 at file:///**/.npm/_npx/16b3f312213fced0/node_modules/gltfjsx/src/bin/GLTFLoader.js:1215:7 at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

I tried to do some debugging and it seems the animations array comes in as [ undefined ]. It works fine without the types flag. Attached is a cube with a small rotate animation for reproducibility. cube.gltf.zip

jerricko avatar Jul 11 '23 14:07 jerricko

I believe this was introduced in https://github.com/pmndrs/gltfjsx/commit/e71898376e666677bb9cd54b160bcc64a2316afe. Animations are being overridden when we wrap the reassign the gltf parameter at the top of parser/parse

willkrakow avatar Jul 20 '23 00:07 willkrakow

I had debugged that initially and it wasn't hitting that if statement. Instead of an empty array, it'll actually fill the array with a matching number of undefineds as animations in the gltf (ex [undefined, undefined] for 2 animations.

After more diving, I think it is caused by 7b3377a9. Seems the loadAnimation method was completely gutted for some reason.

jerricko avatar Jul 20 '23 05:07 jerricko

Hi - whats up with the gutted load animation?

LukeWood avatar Oct 13 '23 00:10 LukeWood