With this page, I found 3 id´s and respective names.
id 3 … name scene_name
id 8 … name cubeA
id 9 … name cubeB
Please, help me to find what are the 1,2,5,6,7 others id´s.
PS: console.logs errors in Firefox were detected and corrected:
a) the way id s were written … changed to id’s,
b) if(scene.getObjectById(w)){…} is now included in the search for id’s,
c) the original url of the page is mantained on the site (id_name.html).
Hello Chris,
scene.name=“scene_name”;
cubeA.name=“cubeA”;
cubeB.name=“cubeB”;
then 3 scene.getObjectById().id appeared.
but as id=3, id=8 and id=9,
Please, help me to find what are the 1,2,5,6,7 ids.
Thank You for the interest.
I think that objects in a scene have incrementing IDs. They appear to start at 10, though this could vary between scenes, or maybe even versions of three.
Here is an example fiddle with 10 cubes and a camera. I log each ID, they increment starting from 10.
With Copyright 2010-2022 Three.js Authors const REVISION = ‘137’, happened:
id= 4 … name is: scene_name
id= 10 … name is: cubeA, and
id= 11 … name is: cubeB.
OK… different for different versions… but still not justified for me.
First of all, not just your cubes, but also, for example, your camera (or lights, if you had any) have their id. Secondly, those ids are not necessarily consecutive, so there can be “gaps” between ids. You can find which are the objects corresponding to the other ids you mentioned in at least 2 ways:
use a console.log(scene); somewhere outside any loop in your code, and manually examine the scene’s children, grandchildren, etc. and notice their ids
do the above automatically, by using something like for (var i = 0; i < 10; i++) {try {console.log(scene.getObjectById(i));} catch {};};, or, if you want a more compact form, log the scene.getObjectById(i).type instead in the loop; obviously, the 10 value in the for can be adjusted based on what you estimate that your maximum id will be
As already pointed out by @notchris, your code yields some errors and, well, it’s not that friendly on resources, so I’ll leave adding one of the above to it in your hands, so to speak.
P.S. Getting your objects by name, assuming that you set them to unique values, is a more reliable way to get your objects, a way that you have full control over.
Hello Chris and Yin,
I made some changes in the original (QUESTION) post.
Now id_name_r1.html.
Searching…
console.log(scene); and
for (var i = 0; i < 10; i++) {try {console.log(scene.getObjectById(i));} catch {};};
and
var objects = [ ];
scene.traverse( ( child ) => { if ( child.isMesh || child.isPoints || child.isLine ) objects.push( child );console.log(child);} ); … (from [ Mugen87 Michael Herzog in Get list of all children - #2 by Mugen87 )
I could not find news… only two childs cubeA and cubeB.
I will continue to try discovering why “those ids are not necessarily consecutive, so there can be “gaps” between ids”.
Thank You for the interest with this post.
Well, good luck with that, and if you find why, let me know. I actually discovered this while exploring my own project object ids, which also had gaps between them. To be honest, I anticipated that and it doesn’t seem strange to me, but obviously I don’t know the internal reason for it, I just shared what I found out in a similar examination process.