I need to get an array or object with all 3D models that have been added to the Mapbox map, as it is on the screenshot below. How can I get these objects?
I was trying to do something like this code but it didn't work.
const buildings3DModels = map.tb.world.children;
console.log("buildings3DModels: ", buildings3DModels);
buildings3DModels.forEach(element => console.log(element));
I can see log an array with object with:
console.log(map.tb.world.children);
But for some reason I cant loop through the array with for example forEach or any other loops, it's just don't return anything.
So, my question is: How can I get these 3D objects from the map after they were added to the map? and how can I loop through each object?
I'm maintaining the latest threebox repo.
tb.world.children
is a simple array so iftb.world.children.forEach((o) => { console.log(o) });
is not logging anything is because is empty at the runtime is being executed. Could you post your full code?If your 3D objects are being loaded through
tb.loadObj
which is a full async method, it's very probable you are trying to access totb.world.children
array before the objects are fully loaded. If so, then you should manage thePromise
instances returned by this method and control when all of them are resolved.Here you have a method that loads 100 models and logs the objects inside threebox.