I want to visit all element in a scene. These elements are object of type: THREE.Object3D, THREE.Mesh, and so on. Some elements have a field called children, and this is an array of other elements. So we can conclude that the scene ( also it has the children field ) is a tree.
With this knowledge, I want to perform a depth first search visit, to set some attribute on, for each element present in the scene object. This is my code:
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++ );
}
Now, this code lead to an infinite computation, it never ends. How is this possible?