I added some objects to ThreeJS scene (using scene.add(object)
). I know the name of object and just want to fetch index of it from scene.children.
I tried to use scene.children.indexOf("objectName")
but it returns -1 index. Can anybody suggest what can I do?
Thanks
var object = scene.getObjectByName( "objectName" );
or to recursively search the scene graph
var object = scene.getObjectByName( "objectName", true );
Alternatively, you can search by ID.
var id = scene.getObjectById( 4, true );
three.js r.60
I believe that something that can actually can answer your question is the following code that I use to clean the scene:
while (scene.children.length > 0) {
scene.remove(scene.children[scene.children.length - 1]);
}
this way I don't need to access an element by its name or id. The object are simply fetched from the array with an index, so it's like scene.children[i]
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With