spnda / fastgltf

A modern C++17 glTF 2.0 library focused on speed, correctness, and usability
https://fastgltf.readthedocs.io/v0.8.x/
MIT License
272 stars 42 forks source link

lack of extensions or so... #34

Closed tigrazone closed 10 months ago

tigrazone commented 10 months ago

Hello! Thank you for fastgltf. It's impressive but not open all files from https://github.com/gkjohnson/3d-demo-data.git which use and can open https://github.com/gkjohnson/three-gpu-pathtracer.git For example, I try to open https://raw.githubusercontent.com/gkjohnson/3d-demo-data/main/models/pathtracing-bathroom/modernbathroom.glb and fastgltf_gl_viewer fails with error

Loading c:\msys64\home\user\from-git\3d-demo-data\models\pathtracing-bathroom\modernbathroom.glb
Failed to load glTF: One or more extensions are required by the glTF but not enabled in the Parser.
Failed to parse glTF.

I find here is extension list and extend it to all possible https://github.com/spnda/fastgltf/blob/d2e8a52bcf8b844570f9aee9a83c5341d1f476e4/examples/gl_viewer/gl_viewer.cpp#L289 with change to fastgltf::Parser parser((fastgltf::Extensions)~0);

After change fastgltf_gl_viewer fails with error

Loading c:\msys64\home\user\from-git\3d-demo-data\models\pathtracing-bathroom\modernbathroom.glb
Failed to load glTF: The glTF is either missing something or has invalid data.
Failed to parse glTF

Can you fix this error?

spnda commented 10 months ago

Hi, thanks for the report. First of all, the gl_viewer example simply does not support the EXT_meshopt_compression. I want to keep the example at a bare minimum and only support the core glTF specification. While some extensions are widely used, I will not add code to support them to the example. KHR_mesh_quantization was the only one I added because it required no additional code.

As for the parsing error you experienced after enabling the extensions in the parser, it turns out there was a part of the spec for EXT_meshopt_compression that I seem to have missed. It adds the concept of so-called fallback buffers which are buffers with a byteLength property but they contain no data. The code currently throws an error in this case because it expects to either have a uri property or use the GLB buffer, which is why you're getting that error.

I've now changed the code in an upcoming commit that adds a new (empty) data source called ´Fallback` that is used whenever the library detects the extension is enabled (and required by the asset) and a buffer has no data. It is then the users responsibility to always use the compressed buffer version.