To get array of all meshes

“scene.children” only return array which is directly added into scene.
if I add cubeB in cubeA,
“scene.children” gave only cubeA.
and there cubeA.children gave cubeB.

is there any way to get all 3d meshes of scene?

You could do something recursive if the child has children of its own:

function listChildren(children) {
    let child;
    for (let i = 0; i < children.length; i++) {
        child = children[i];

        // Calls this function again if the child has children
        if (child.children) {
        // Logs if this child last in recursion
        else {
            console.log('Reached bottom with: ', child);


You can also use Object3D.traverse() which executes the given callback on the object and all descendants. In this way, you can identify all meshes in your scene like so:

scene.traverse( function( object ) {

    if ( object.isMesh ) console.log( object );

} );

This gives an error. Has the API changed or is it typed incorrectly?


Maybe you can try this instead:

if(object instanceof THREE.Mesh){
1 Like

Bit of a hack but that’s what I wound up doing, thanks!

1 Like