Hey everyone, I'm currently facing a bit of a hurdle.
The issue I'm encountering is that I find myself back at the starting point before all my objects have finished loading.
Once I create my shelf, I calculate a bounding box that's crucial for determining the position and translation of my object. However, because I'm reverting back too early, I can't calculate the bounding box, resulting in everything showing up as 0 or infinity. So, I need a way to wait until everything is fully loaded. I initially thought the onload part on the loader would handle this, but it doesn't seem to be effective.
Below are key excerpts from my code:
In my init function, I call:
let shelf = this.creators.createShelf(parts);
Within my Creator Class, I construct an object:
createShelf(parts) {
let shelf= new THREE.Mesh();
let mesh: THREE.Mesh;
let props;
for (let part of parts) {
if (part.model == true) {
let loadObject = this.helpers.loadObject(part);
shelf.add(loadObject);
// perform actions
return shelf;
Next, I load a 3D object using the ObjectLoader in ThreeJS:
loadObject(props: Object3D) {
let object = new THREE.Mesh();
let modelLoader = new THREE.ObjectLoader();
modelLoader.load(part.modelObjPath,
// onload
function (obj) {
// manipulate the object
object.add(obj);
},
function (xhr) {
console.log( (xhr.loaded / xhr.total * 100) + '% ' + part.name + ' loaded' );
},
function (xhr) {
console.error( 'An error happened' );
}
);
return object;
}
When I create my bounding box using Box3 or a BoxHelper, it returns the following output:
let box = new THREE.Box3().setFromObject(shelf);
bb object
Ta {min: p, max: p}
max:
p {x: -Infinity, y: -Infinity, z: -Infinity}
min:
p {x: Infinity, y: -Infinity, z: -Infinity}
I hope I've been able to clarify where I'm encountering the problem.
Thank you for taking a look at it.