I have a desire to explore each element within a particular scene. These elements come in various forms such as THREE.Object3D, THREE.Mesh, and more. Some of these elements contain a property called children, which is essentially an array of other elements. Therefore, it can be inferred that the scene (which also possesses the children property) can be viewed as a tree structure.
Armed with this understanding, I aim to conduct a depth-first search visit to assign a specific attribute to every element housed within the scene object. Below is the code snippet:
function setShadowRenderer( element ) {
element.receiveShadow = true;
element.castShadow = true;
if (element.children !== undefined || element.children !== []) {
for (i = 0; i < element.children.length; i++) {
setShadowRenderer(element.children[i]);
}
}
console.log("C++");
}
However, running this code results in an infinite loop; the computation never reaches its end. But why is this happening?