Hi, I am trying to get a list off all children from my model like in the picture
Here is my JS fileapp.js (2.8 KB) .
Thanks for helping out.
Hi, I am trying to get a list off all children from my model like in the picture
When adding the loaded model to the scene, you can use the following code in order to traverse through the object hierarchy and push all descendants into an array:
const objects = [];
// in your onLoad() callback
model.traverse( ( child ) => {
if ( child.isMesh ) objects.push( child );
} );
Change the if
condition if you also want to add lines or point clouds.
Hi When i add your code i get an error like this
Uncaught SyntaxError: missing ) after argument list
Ups, I had a typo in the arrow function. I’ve updated my post.
Is there a way to get only the 3D elements and toggle them on and off like a layer. Thanks for helping out. I’m a student so I new to this kind off stuff
What do you mean with lines or point clouds. Could you explain this to me.
You could have line or point cloud objects in your scene graph. If you want to collect all those objects, the code would look like so:
model.traverse( ( child ) {
if ( child.isMesh || child.isPoints || child.isLine ) objects.push( child );
} );
ah oke thanks!.
Is there a way to dispays this array (children) in a dat.gui that can be toggled on and off.
Yes, but I don’t have to code for this ready. I guess you have to figure this out by yourself^^.
I always had difficulty finding all the childs meshes… I think this link made me happy.