Hi,
I’ve got certain items in a GLB file that I need to animate their opacity in sections, so my thinking was to traverse each item in the loaded asset, check if the name matches certain keywords I’ve put into an array, and then if it finds each one of those, pull them out of the main object and put it into it’s own group, so that I can then target each group as I want to change opacity
loader.load("path/to/my/environment_model.glb", function(gltf) {
const environment = gltf.scene;
scene.add(environment);
environment.traverse(child => {
if (uniqueObjects.indexOf(child.name) > -1) {
let group = new THREE.Group();
group.name = child.name;
console.log(group.name);
// Up to here seems to work as I'd expect
group.add(child);
scene.add(group);
environment.remove(child);
// This is what I'd presume the code would be
}
});
}
If I run the code above, I get this error
Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'traverse')
If I had to guess it looks like the last few lines of code are adding another item within the environment
object for it to traverse though, but it doesn’t know what they are. It also then seems to be skipping every other item in my array as well, so I’m just really a bit confused