Hey guys!
I got a weird error since I updated from r137 to r156 (Tried r158 too).
Im loading multiple objects with the GLTFLoader and position them in the scene.
Sometimes when refreshing and reentering the page, all models arent visible anymore. I checked transformation and visibility etc of all objects, it is in the scene, its position is 0,0,0 and it should be visible.
The only thing I could find out is, when outputting the freshly calculated boundingbox of all objects, on a mouse click event, the bounding boxes would be { x: NaN, y: NaN, z: NaN }
(same with center), but when checking the Geometry’s, the vertices seemed to be fine!
I then calculated the boundingbox at various situations. For example right after the GLTF is loaded and cloned. At that point everything seems fine, the size is correct.
In the same onLoad callback from the GLTFLoader, the model clone is added to a object3D, which is used as container. After adding it to the container, all boundingboxes are NaN!
At this point, im kinda confused.
This is a simplified version of my function
public create2(parts: TransferObject[]) : THREE.Object3D {
let container: THREE.Object3D = new THREE.Object3D()
let obj: THREE.Object3D
parts.forEach((part, index)=> {
// if model to load
if (part.model == true) {
if (part.modelObjPath != null) {
// Load model
LoadingManager.loadGLTF(Globals.path(part.modelObjPath), (gltf: GLTF)=> {
console.log('LOAD glft', part.modelObjPath)
obj = gltf.scene.clone(true)
this.setModel(obj, part)
obj.name = part.name
// Calculating boundingbox first time
let box = new THREE.Box3().setFromObject(obj, true)
let v = new THREE.Vector3()
let c = new THREE.Vector3()
box.getSize(v)
box.getCenter(c)
console.log('bbox create',v, c)
// After adding it, the boundingbox is NaN
container.add(obj)
// Calculating boundingbox second time
box = new THREE.Box3().setFromObject(obj, true)
v = new THREE.Vector3()
c = new THREE.Vector3()
box.getSize(v)
box.getCenter(c)
console.log('bbox create2',v, c)
})
}
}
}) // For loop - parts ende
container.matrixAutoUpdate = false
container.updateMatrix()
return container
}
The LoadingManager class takes care of loading gltf models and storing them in a map, The original gltf is stored and returned, then cloned when used.
Any help is appreciated!