Ensure a GLTF Default material is loaded #1016
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
GLTF does not require that mesh primitives provide a material. In that case, a default material is supposed to be used.
In the bevy gltf loader, we iterate over all materials (gltf.materials()) but this iterates over all the materials defined in the gltf, not including the default material. This means we never create a StandardMaterial asset for the default gltf material. This causes a panic later on since we do create a PbrBundle referencing the handle for the default material.
Panic:
thread 'Compute Task Pool (3)' panicked at 'called
Option::unwrap()on a
Nonevalue', C:\github\bevy\crates\bevy_render\src\shader\shader_defs.rs:101:52
This changes makes it so that when iterating over all mesh primitives, if we run into a primitive which has a material which isn't yet in the 'load_context', then we at that time create the standard material and add it to the load_context. The default material will be captured here since primitive.material() will return it. Unfortunately, the gltf library can not provide a default implementation function, otherwise we could just append this onto our gltf.materials() iterator.
Here is a glb file which reproducing the issue (provided by Sheepyhead on discord). I have another glb that repros this as well from my own project, but that one is not postable.
man_with_melting_head.zip
Tested loading this glb and also tested FlightHelmet.