Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add static glTF support #14557

Merged
merged 37 commits into from
Sep 2, 2024
Merged

Conversation

JosiahWI
Copy link
Contributor

@JosiahWI JosiahWI commented Apr 18, 2024

This adds code for loading static glTF meshes to get a scaffold in place to keep the rest of the glTF feature PRs small and focused. But every time I have to rebase this it takes up hours of my time, so I would like to land this very soon so it can be over with. This has been reviewed by me and @appgurueu.

To do

Ready for Review

How to test

The code is covered pretty thoroughly by Catch2 tests, which can be run with ./minetest --run-unittests --test-module "gltf".

Additionally the gltf devtest mod features some static glTF models that can be viewed in-game as nodes, entities, or in a formspec.

@JosiahWI JosiahWI force-pushed the feat/gltf-loader branch 6 times, most recently from 32c0180 to 9ad41e4 Compare April 18, 2024 18:56
irr/include/IMesh.h Outdated Show resolved Hide resolved
@appgurueu appgurueu mentioned this pull request May 14, 2024
8 tasks
@appgurueu
Copy link
Contributor

I have a branch based on this that also adds animation support now. You can just compile that branch to enjoy an animated gltf spider in Minetest.

The only major thing left to be done is to actually run the tests there via catch2, which depends on #14565.

@Wuzzy2
Copy link
Contributor

Wuzzy2 commented May 17, 2024

I've tested @appgurueu's branch and it works fine! I think it deserves a proper PR, assuming this PR is stale.

@appgurueu
Copy link
Contributor

I've tested @appgurueu's branch and it works fine! I think it deserves a proper PR, assuming this PR is stale.

This PR is (like my branch, which is based on this) waiting on the Catch2 PR, so that we can get the unit tests to work.

However, we don't know yet whether the other devs would like to review this as one big PR which adds supported for animated gltf, or first a slightly smaller PR to add support for static gltf, then a follow-up PR to add animation support.

I personally would prefer one big PR because this lets me avoid rebase hell, but ultimately it's up to the reviewer to decide.

@JosiahWI
Copy link
Contributor Author

This could already be reviewed in its current state. The work to get the unit tests to work with the build should not block any review efforts except that reviewers may have more trouble verifying that the tests work. We could also push a temporary patch so that the tests can be run separately from --run-unittests for review purposes. If a core dev is ready to review this, please go ahead.

@appgurueu appgurueu added Roadmap The change matches an item on the current roadmap Feature ✨ PRs that add or enhance a feature @ Client rendering labels May 21, 2024
Copy link
Contributor

@appgurueu appgurueu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As said, this has my approval as a co-author. There are still a few details in tiniergltf for me to sort out - nothing that negatively impacts loading of correct models, however - and the aforementioned To-Do of fixing the build to include unit tests. Still, this PR is ready to be reviewed.

@appgurueu appgurueu added One approval ✅ ◻️ Waiting (on dependency) Waiting on another PR or external circumstances (not for rebases/changes requested) labels May 21, 2024
@appgurueu appgurueu marked this pull request as ready for review May 21, 2024 16:07
irr/include/IMesh.h Outdated Show resolved Hide resolved
irr/include/SSkinMeshBuffer.h Outdated Show resolved Hide resolved
irr/src/CGLTFMeshFileLoader.cpp Show resolved Hide resolved
irr/src/CGLTFMeshFileLoader.cpp Show resolved Hide resolved
irr/include/SSkinMeshBuffer.h Outdated Show resolved Hide resolved
irr/src/CGLTFMeshFileLoader.cpp Outdated Show resolved Hide resolved
irr/src/CGLTFMeshFileLoader.cpp Outdated Show resolved Hide resolved
irr/src/CMakeLists.txt Outdated Show resolved Hide resolved
irr/src/CMakeLists.txt Show resolved Hide resolved
irr/src/tests/CMakeLists.txt Outdated Show resolved Hide resolved
@sfan5
Copy link
Collaborator

sfan5 commented May 21, 2024

One more question: since GLB avoids the need to handle base64 decoding and is more efficient, has supporting it been considered?

@JosiahWI
Copy link
Contributor Author

JosiahWI commented May 21, 2024

Yes, it has been considered, and it should be quite an easy change (relative to animation for example), but I did not prioritize it for this PR because it works well as its own chunk of functionality that could be PRd separately. However, we could reconsider whether we want to initially support glTF or glb.

irr/src/CGLTFMeshFileLoader.h Outdated Show resolved Hide resolved
irr/src/tests/CMakeLists.txt Outdated Show resolved Hide resolved
JosiahWI and others added 17 commits August 26, 2024 16:20
This also corrects the function name to be snake_case because it is
not a method.
- Alignment issues
- Use os::Byteswap::byteswap
- Directly write into matrices
Fix -Wsign-compare warning

Fix snow man test texture coordinates

The current texture coordinates specified in the test did not use sufficient precision.
It is unfortunately common for software to round away the last bit when displaying floats.
This issue was previously masked by Irrlicht using a float comparison with tolerance for vectors,
which was changed in 3452857 to an exact float comparison for unrelated reasons.
Manual inspection of the buffer reveals that the values produced by the reader are correct.

Clean up unit tests

Move everything to sections of one big "gltf" test case

Fix triangle with vertex stride test case

Improve docs

Add copy & move constructor from STL string to Irrlicht string

Move test assets to devtest, add corresponding entities

Test fixes (get rid of device creation, fix error case tests)

Address minor TODOs in tiniergltf

Add spider model

Work around lack of SKIP

Implement clang-tidy suggestions in tiniergltf

Update devtest mod count, add mod.conf

Use SKIP now that we can

Add applicable tests from animated branch

Fix sparse accessor handling in tiniergltf

Fix invalid bufferview bounds test

Rename (& minify) files to follow naming conventions

Improve logging

Add frog gltf test model

rebased

minuscule refactor

trailing whitespace

let primitives share textures

🐸

fix gltf nodes

fix model[] element

add model[] test

more trailing whitespace

Update doc/lua_api.md

Co-authored-by: SmallJoker <SmallJoker@users.noreply.github.com>

{

remove obsolete file

explain use of terms in enums

don't unnecessarily zero-initialize

begone, base64!

Improve documentation
Copy link
Member

@Desour Desour left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just took a small look, no full review.

A bit sad that glb is not yet supported.

Why was it again necessary and/or useful to create a new gltf lib? (Haven't found an answer in the discussions.)

irr/include/irrArray.h Outdated Show resolved Hide resolved
irr/include/SSkinMeshBuffer.h Outdated Show resolved Hide resolved
irr/include/irrString.h Outdated Show resolved Hide resolved
src/unittest/test_irr_gltf_mesh_loader.cpp Outdated Show resolved Hide resolved
doc/lua_api.md Outdated Show resolved Hide resolved
@appgurueu
Copy link
Contributor

appgurueu commented Aug 29, 2024

A bit sad that glb is not yet supported.

I plan to add glb support in a subsequent PR. It is relatively easy to do. It doesn't have to be in this PR.

Why was it again necessary and/or useful to create a new gltf lib? (Haven't found an answer in the discussions.)

Because tinygltf was awful, especially for our purposes. The main reasons are:

  • tinygltf wasn't written with security in mind; it is not fit for reading untrusted media files. You can easily verify this by supplying some out of bounds indices for example (we have a unit test for this). There were some half-hearted attempts to add checks later but it's still an unsafe mess. Initially I tried to audit / patch tinygltf, but ultimately I found that writing a better alternative for just what we need to be much more feasible.
  • tinygltf introduces plenty of bloat - a gltf writer, support for two JSON libraries (none of which we use), support for embedded image loading (via another image library, though that can be turned off), etc. tinygltf.hpp alone has around 9kloc; the JSON library it uses by default (json.hpp) has 26kloc. In contrast, tiniergltf.hpp only adds 1.5kloc.
  • tinygltf code quality is, in my opinion, bad. I don't want to depend on this code.

@appgurueu appgurueu merged commit ac11a14 into luanti-org:master Sep 2, 2024
17 checks passed
Mahoyomu pushed a commit to Mahoyomu/minetest that referenced this pull request Oct 7, 2024
Co-authored-by: Lars Mueller <appgurulars@gmx.de>
Co-authored-by: jordan4ibanez <jordan4ibanez@users.noreply.github.com>
Co-authored-by: sfan5 <sfan5@live.de>
Co-authored-by: SmallJoker <SmallJoker@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@ Client rendering Feature ✨ PRs that add or enhance a feature One approval ✅ ◻️ Roadmap The change matches an item on the current roadmap
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants