bwasty / gltf-loader-ts

Engine-agnostic glTF 2.0 Loader in TypeScript
https://bwasty.github.io/gltf-loader-ts/
MIT License
53 stars 8 forks source link

Incorrect indices values #37

Closed Owlzy closed 6 years ago

Owlzy commented 6 years ago

Hi There,

Please accept my apologies if this is not a bug with the loader, but having spent the last few days exploring various options I'm coming to the conclusion that its either the blender-gltf exporter that's at issue, or the loader. Seeing as this lib is pretty new I'm guessing the issue lies here (although it may be the case that its on my end).

I've build a 3d plugin for a 2d renderer, and this loader is my method of loading models. Any models produced by our 3d artist in maya display just fine. However if I attempt a simple texture mapped cube in blender and export I get out of range webgl errors on the position buffer. (note that models made in maya I have been importing into blender as obj and exporting as gltf, hence my reasoning the export gltf isn't the issue).

When I check the indices buffer on this simple cube, I have some really huge numbers that are way out of range.

Int16Array(18) [256, 770, 1, 1284, 1030, 1287, 2312, 2058, 2315, 3340, 3086, 3343, 4368, 4114, 4371, 5396, 5142, 5399]

Yet my position buffer has a length of 72, so these numbers are crazy high. I know blender can sometimes behave a little differently to other 3d modelling programs, I've had weird side effects importing into other engines before such as Unity. But I assume this loader is intended to work with data exported from Blender, seeing as its such a popular tool?

It should be easily reproducible by creating a simple texture mapped plane or cube in blender, exporting to gltf, and then run the loader and log the values for the Uint16 array produced.

Thanks in advance for any assistance if you are able to provide it.

bwasty commented 6 years ago

Can you try loading it here: https://gltf-viewer.donmccurdy.com/? This is kind of the canonical loader/viewer and also includes the official validator (there's a widget for validation issues at the bottom). If everything is fine there, it would be great if you could provide a gltf file to test - I haven't touched Blender in many years...

Owlzy commented 6 years ago

Thanks for the reply. I actually noticed I was on an old version so I have updated to 3.0.0 and now the issue seems to of gone, but I am having some difficulty with the API at the moment so can't confirm. Will confirm when I resolve these issues.

Owlzy commented 6 years ago

Sorry forgot to add I have already validated the gltf file in the official validator as well as trying it on the viewer you linked and it worked fine.

It seems 3.0.0 has broken the plugin due to only returning Uint8Arrays, whereas for everything except indices I was previously using float32 array. I will have a look for a way to convert between them.

Owlzy commented 6 years ago

Going to close this as I have got a temp solution by avoiding the blender gltf export, which seems to be the issue as I tested another loader and found it gave the same output as this one. Although it does seem that some loaders or renders managed to get around the issue somehow, I'm not sure how.

I also had to roll back to a previous version to solve the issue I had with all arrays now being Uint8's.