FBXLoader: Loading FBX files with out-of-bounds material assignments lead to incorrect geometry groups and subsequent errors #30581
+30
−0
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.
Description
The previous behaviour was a visual hole (invalid material) and hard-to-catch errors e.g. when using
Mesh._computeIntersections
orSkinnedMesh._computeIntersections
.In line with other FBX loaders (tested in Unity/Blender/F3D), a default material is now created. Note that "default material" is to be taken literal; the material looks different in all implementations I tested because their defaults differ, so I decided that's the most reasonable approach here as well.
Reproduction file:
response.fbx.zip
Screenshots
The hot pink parts have an invalid materialIndex already in the underlying FBX data (there's 6 materials in the file, the index here is "8"):

Unity just uses an existing default material for that problematic slot:

Blender just kicks out the wrong group and thus uses whatever the "last valid" material was, which is super confusing (e.g. if the last valid material was textured, that texture is now on random geometry).
This contribution is funded by Needle