Fix empty name problem in GLTFLoader #18585
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.
References:
#18530 (comment)
https://spectrum.chat/react-three-fiber/general/help-required-unable-to-load-a-gltf-model~d77788d6-35ff-4e5d-b3e9-23682c661699
GLTF's can be exported with empty names, or missing names. GLTFLoader seems to have problems with the former. For instance, this is the nodes array of the following model: https://sketchfab.com/3d-models/red-city-356c773c4b9a45d8b9d4aa04c60ecb27
GLTFLoader will auto generate names, like mesh_0, mesh_1 and so on, this happens in loadMesh:
Notice how it checks the string itself. So, by now the mesh has an actual name, but a small bug wipes it out again afterwards in the LoadNode function:
Here it checks against undefined, so despite the def name being empty and the auto-generated name being present, it goes in there and overwrites the name with an empty string.
I have fixed all the other places that had this problem.