Hello… I have several gltf meshes that I load from blob urls and then store in a variable and use later to create several instances of each asset in an absolute position at a defined scale. But for one particular asset it seems sometimes when I load even after loading it in the assets does not appear on the scene. This is not consistent as it re-appears on reloading the browser… Please help…
const plugin = BABYLON.SceneLoader.ImportMesh(
'',
url,
'',
_scene,
null,
null,
(reason) => {
console.log(reason)
// TODO sceneError({ name: fileName }, null, reason.message || reason);
},
'.gltf'
)
const self = this
plugin.onMeshLoaded = function (mesh) {
if (mesh.name !== '__root__') {
console.log(`loaded model: ${mesh.name}`)
// remove it from scene
mesh.setEnabled(false)
self._sceneMeshes.set(key, mesh)
self.progress += 1
if (self.progress === self.totalModels) {
console.log('Loading successful')
self.createInstances()
self.loadAsset()
}
}
}
Here is how am creating the instances
const { instanceID, origin, size } = instance
const { _sceneMeshes } = this
const mesh = _sceneMeshes.get(modelType)
if (mesh) {
const asset = mesh.createInstance(instanceID)
asset.setEnabled(true)
asset.checkCollisions = true
const modelSize = asset
.getBoundingInfo()
.boundingBox.extendSize.scale(2)
const position = new BABYLON.Vector3(
-origin.x - size.width,
origin.y,
origin.z
)
const scale = new BABYLON.Vector3(
size.width / modelSize.x,
size.height / modelSize.y,
size.depth / modelSize.z
)
asset.setAbsolutePosition(position)
asset.scaling = scale
} else {
console.error(`could not find: ${modelType}`)
}
I have no errors in the console…