I've encountered a perplexing issue when switching from OBJLoader to OBJMTLLoader in my code. The OBJ file I'm working with contains groups that are loaded by both loaders into different child meshes.
In both cases, the scene has a THREE.Object3D as a child with 1837 children. However, upon inspecting the object in the console:
- When using OBJLoader, the first child starts at id 12 and increases sequentially up to 1848. This progression makes sense.
- On the other hand, when loading with OBJMTLLoader, some ids are missing - starting at 13 and ending at 5521. For example, the first five children have ids: 13, 16, 19, 22, 25.
While this discrepancy may not be an issue, here's where it gets tricky. In my project, I utilize raycasting to change the color of selected meshes (by clicking on them) and display their names:
- With OBJLoader, the color changes and mesh names are displayed correctly.
- But with OBJMTLLoader, while color changes work fine, the mesh names are empty.
Interestingly, every mesh does have a name in both scenarios.
The odd part is when checking the selected mesh's id via the console. With OBJLoader, the id matches the mesh in the Object3D. But with OBJMTLLoader, the id seems to be missing from the Object3D...
Any ideas on where the problem might lie?
Thank you!
UPDATE :
I've made some progress in solving the issue but something still seems off. Here's an example of the structure of my 3D model imported with THREE.OBJMTLLoader:
THREE.Group
[...]
children : Array[1837]
0 : THREE.Object3D
[...]
name : "the name of the part"
children : Array[2]
0: THREE.Mesh
name : ""
children : Array[0]
[...]
1: THREE.Mesh
[...]
[...]
1 : THREE.Object3D
[...]
It turns out the raycaster intersects with THREE.Mesh and stores the name one level above. Hence, the absence of names when trying to display them. But why doesn't this extra level exist when using OBJLoader for the same 3D model? With OBJLoader, the structure looks like this:
THREE.Group
[...]
children : Array[1837]
0 : THREE.Mesh
[...]
name : "the name of the part"
children : Array[0]
[...]
1 : THREE.Mesh
[...]