Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Three.js: for loop for every mesh in scene?

So what I want is to do something like

scene.forEachMeshInScene(function(mesh){
      //And here I can do stuff
});

But sadly, that doesn't exist. How can I do something like this?

like image 444
ByteDuck Avatar asked Dec 04 '14 01:12

ByteDuck


1 Answers

You can use the following pattern to iterate over the Mesh objects in the scene graph:

scene.traverse( function( node ) {

    if ( node instanceof THREE.Mesh ) {

        // insert your code here, for example:
        node.material = new THREE.MeshNormalMaterial()

    }

} );

three.js r.69

like image 103
WestLangley Avatar answered Oct 03 '22 10:10

WestLangley