GLTFLoader: Objects not found under original name, regression from r119 -> r123
See original GitHub issueDescribe the bug After upgrading three to r123 on a working project, that was before using r119, three cannot find some Camera’s anymore. Strangely enough it can find some cameras, but not others. It doesn’t seem to be related to ortographic vs perspective. It looks like the problem arrises only with nested camera’s, so cameras within other 3D objects. But I’m not completely sure yet.
I’ve read all migration guides from r119 -> r120 up to the last one, but cannot find anything in there that should cause this IMO.
I’m still debuging, but so far this seems to be the issue: getObjectByName()
can find some camera’s, but others return undefined
so cannot be found in the scene loaded by gltf. Before this was working fine, the only thing I needed to do before was traverse this object, because for some reason camera’s are wrapped inside some object in gltf. But now even the wrapper object cannot be found. It is still in the gltf or glb though, nothing changed to the data.
const cameraWrap = scene.getObjectByName(camName);
I keep you informed if I know more when exactly this happens. But for now please let me know if something has changed that could cause this that I should be aware of! Thanks
To Reproduce
Steps to reproduce the behavior:
- Create a scene with objects and camera’s in blender (probably the problem occurs when cameras are nested (and nested) within 3D objects, but not sure yet)
- Use the blender gltf or glb export to export to gltf or glb
- Import the gltf or glb in three to get the scene
- Try to get the cameras by using
scene.getObjectByName(camName)
Code
scene.getObjectByName(camName)
Expected behavior
Nothing changed in three version according to the migration guide around cameras or objects AFAIK, so I would expect this to still work in r123.
Platform:
- Device: Desktop/Mobile
- OS: Windows
- Browser: Edge Chromium
- Three.js version: r123
Issue Analytics
- State:
- Created 3 years ago
- Comments:16 (2 by maintainers)
Top GitHub Comments
An opt-out method is proposed in https://github.com/mrdoob/three.js/pull/16639#issuecomment-797653487, if someone would like to open a PR and confirm it fixes this issue.
I’m afraid even experienced developers will disagree on whether duplicate names are “errors.” The glTF specification does not require unique names, so the file is 100% valid and will play animation in other glTF viewers. three.js does require unique names for animation to work, and so GLTFLoader has the responsibility of turning a valid glTF file into valid three.js objects. No single perfect solution here, so I think the opt-out method is a reasonable choice.
We’re still open to accepting a PR for an opt-out method, to prevent GLTFLoader from de-duplicating names. But I think someone who has a use case for the feature will need to implement and test it, this is not otherwise on the roadmap.