Hi,
i’m trying to create instances of an object.
I want to do this things in a class : if the object doesn’t exist then import him and create an instances, else (if the object doesn’t exist) create an instances.
I have the following code :
index
const scene = createScene();
let obj = new ObjetSupp("test", "./Objets de decoration/", "Tree.obj");
obj.Charge();
obj.Charge();
console.log(obj);
ObjetSupp
isCreated() {
console.log(scene.meshes);
if(scene.meshes.find(meshe => meshe.name == this.nom) != undefined){
console.log(true);
return true;
}
else{
console.log(false);
return false;
}
}
async Charge() {
if (!this.isCreated()) {
console.log("not created");
BABYLON.SceneLoader.ShowLoadingScreen = false;
var newMeshes = await BABYLON.SceneLoader.ImportMeshAsync(null, this.path, this.file, scene);
console.log("end await")
for (var i = 0; i < newMeshes.meshes.length; i++) {
if (newMeshes.meshes[i].material != null) {
if (newMeshes.meshes[i].material.diffuseTexture != null) {
newMeshes.meshes[i].material.diffuseTexture.hasAlpha = true;
newMeshes.meshes[i].material.useAlphaFromDiffuseTexture = true;
}
}
}
console.log("start merge")
this.mesh = BABYLON.Mesh.MergeMeshes(newMeshes.meshes, true, true, null, false, false);
this.mesh.name = this.nom;
this.mesh.normalizeToUnitCube();
// this.mesh.isVisible = false;
}
console.log("create instance");
this.mesh.createInstance(this.nom + "-" + this.mesh.instances.length+1);
}
But it doesn’t work beacause the 2nd “obj.Charge()” start before the end of the 1st one.
Here all my console log to illustre what i say :
Can i get some help ?
thanks by advance