Problems at clone second time mesh, it have visibility problems :

code creation each tank :

class Tanker {
contructor(){}

//...

setMesh(){
    console.log( "en set mesh de ",this.name );
    this.mesh = scenes[this.parent_scene].getMeshByName("tanker_base").clone(this.name+"_mesh");
    this.mesh_collider = scenes[this.parent_scene].getMeshByName(this.name+"_mesh.tanker_base_collider");
    // this.mesh_collider.computeWorldMatrix(true);
    this.mesh_coll_pos = scenes[this.parent_scene].getMeshByName(this.name+"_mesh.tanker_base_collider_pos");    
    this.mesh_coll_pos.setEnabled(true);

    // scenes[this.parent_scene].meshes.forEach(_mesh => {
    //   if( _mesh.name.includes(this.name) ){
    //     console.log( _mesh.name );
    //   }
    // });

    this.taller = ceil.mid-0.6;
    this.mesh.position = new BABYLON.Vector3(0,this.taller,FuelDepot.POS_Z);
    this.mesh.setEnabled(true);
    // return;
    this.agr = new BABYLON.PhysicsAggregate(this.mesh_collider, BABYLON.PhysicsShapeType.MESH, {mass: 0});
    this.agr.shape.filterMembershipMask = 2;
    
    this.esfera = BABYLON.MeshBuilder.CreateSphere("sphere", { segments:5, diameter:2.5 }, scenes[this.parent_scene]);
    this.esfera.material = test_mat_green.clone("mat_fuel_dpot_au");
    this.esfera.material.wireframe = true;//
    this.esfera.enableEdgesRendering();
    this.esfera.edgesWidth = 0.5;
    this.esfera.position = this.mesh.position;   
    this.esfera.isPickable = false;
    this.esfera.isVisible = false;
    
    this.real_center = this.mesh.getBoundingInfo().boundingBox.centerWorld;
    
    this.id_radar_screen = gb_radar_screen.register(this.alias);
    // console.log( this.name,", mi radar id es ",this.id_radar_screen );
    gb_radar_screen.show(this.id_radar_screen);
    
    for (let _ca = 1; _ca < 9; _ca++) {
      this.tanks[_ca-1].mesh = scenes[this.parent_scene].getMeshByName(this.name+"_mesh.tank_"+_ca);
      this.tanks[_ca-1].mesh_collider = scenes[this.parent_scene].getMeshByName(this.name+"_mesh.tank_"+_ca+"_collider");
      this.tanks[_ca-1].mesh_collider.isPickable = false;
      this.tanks[_ca-1].mesh.setEnabled(true);
      this.tanks[_ca-1].mesh.isVisible=true;
      // this.tanks[_ca-1].mesh.material = test_mat_black.clone(utils.generateId(16));
      if( _ca == 1 ){
        console.log( "mesh tank 1" );
        console.log( this.tanks[_ca-1].mesh.material );
      }
      this.tanks[_ca-1].life_tag = new BABYLON.GUI.Slider(this.name+"_tank_"+_ca+"_tag");
      this.tanks[_ca-1].life_tag.minimum = 0;
      this.tanks[_ca-1].life_tag.maximum = this.tanks[_ca-1].life_shield;
      this.tanks[_ca-1].life_tag.value = this.tanks[_ca-1].life_shield;
      this.tanks[_ca-1].life_tag.isThumbClamped = false;
      this.tanks[_ca-1].life_tag.isVertical = false;
      this.tanks[_ca-1].life_tag.displayThumb = false;    
      this.tanks[_ca-1].life_tag.height = "6px";
      this.tanks[_ca-1].life_tag.width = "60px";
      this.tanks[_ca-1].life_tag.verticalAlignment = BABYLON.GUI.Control.VERTICAL_ALIGNMENT_TOP;
      this.tanks[_ca-1].life_tag.horizontalAlignment = BABYLON.GUI.Control.HORIZONTAL_ALIGNMENT_CENTER;
      this.tanks[_ca-1].life_tag.top = "4px";
      this.tanks[_ca-1].life_tag.isThumbCircle = false;
      this.tanks[_ca-1].life_tag.color = "#ff0000";
      this.tanks[_ca-1].life_tag.background = "#000";
      this.tanks[_ca-1].life_tag.thickness = 1;
      this.tanks[_ca-1].life_tag.borderColor = "#ffffff";
      
      gameplay_ui.addControl(this.tanks[_ca-1].life_tag);
      this.tanks[_ca-1].life_tag.linkWithMesh(big_enemy.tanks[_ca-1].mesh);   
      this.tanks[_ca-1].life_tag.linkOffsetY = -35;

      //tank shield... 
      this.tanks[_ca-1].shield_mesh = scenes[this.parent_scene].getMeshByName(this.name+"_mesh.tank_"+_ca+"_shield");
      this.tanks[_ca-1].shield_mesh.material = enemy_shield_material;
      this.tanks[_ca-1].shield_mesh.isPickable = false;
      this.tanks[_ca-1].shield_mesh.setEnabled(false);

      let _cx = utils.rand(1,3)-1;
      //mes destroyed 
      this.tanks[_ca-1].mesh_destroyed = tanks_damaged_base[_cx].clone(utils.generateId(16));      
      this.tanks[_ca-1].mesh_destroyed.material = tanks_damaged_mat;
      this.tanks[_ca-1].mesh.computeWorldMatrix(true);
      this.tanks[_ca-1].mesh_destroyed.position = this.tanks[_ca-1].mesh.getBoundingInfo().boundingBox.centerWorld.clone();
      this.tanks[_ca-1].mesh_destroyed.setEnabled(false);
    }

}//end set mesh
}

Dispose all on restart event

static disposeAll(){
    //las torretas... 
    gb_radar_screen.remove(big_enemy.id_radar_screen);
    big_enemy.front_turret.mesh_damaged.dispose();
    big_enemy.front_turret.mesh_collider.dispose();
    big_enemy.front_turret.init_bullets.dispose();
    big_enemy.front_turret.mesh.dispose();
    big_enemy.front_turret.rayHelper.dispose();
    big_enemy.front_turret.ray=null;
    if( big_enemy.front_turret.life_tag != null ){
      big_enemy.front_turret.life_tag.dispose();
      big_enemy.front_turret.life_tag=null;
    }    
    big_enemy.front_turret=null;
    
    big_enemy.back_turret.mesh_damaged.dispose();
    big_enemy.back_turret.mesh_collider.dispose();
    big_enemy.back_turret.init_bullets.dispose();
    big_enemy.back_turret.mesh.dispose();
    big_enemy.back_turret.rayHelper.dispose();
    big_enemy.back_turret.ray=null;
    if( big_enemy.back_turret.life_tag != null ){
      big_enemy.back_turret.life_tag.dispose();
      big_enemy.back_turret.life_tag=null;
    }    
    big_enemy.front_turret=null;

    //los 8 depositos de combustible    
    for (let _ca = 1; _ca < 9; _ca++) {
      
      if( big_enemy.tanks[_ca-1].life_tag != null ){
        big_enemy.tanks[_ca-1].life_tag.dispose();
        big_enemy.tanks[_ca-1].life_tag=null;      
      }

      //tank shield... 
      big_enemy.tanks[_ca-1].shield_mesh.dispose();
      big_enemy.tanks[_ca-1].mesh_destroyed.dispose();
      
      big_enemy.tanks[_ca-1].mesh_collider.dispose();
      big_enemy.tanks[_ca-1].mesh.dispose();
      big_enemy.tanks[_ca-1]=null;
    }
    big_enemy.tanks=null;

    //fires 
    for (let _fi = 0; _fi < big_enemy.maxFires; _fi++) {
      
      big_enemy.fires[_fi].flow.stop();
      big_enemy.fires[_fi].flow.dispose();
      big_enemy.fires[_fi].emitter.dispose();
    }

    //morteros
    for (let _mk = 0; _mk < FuelDepot.MAX_MORTARS; _mk++) {
      
      for (let _mu = 1; _mu < 4; _mu++){
        big_enemy.mortars[_mk].muzzles[_mu -1].dispose();      
        big_enemy.mortars[_mk].muzzles_end[_mu -1].dispose();      
      }

      big_enemy.mortars[_mk].rayHelper.dispose();
      big_enemy.mortars[_mk].ray=null;
      
      if( big_enemy.mortars[_mk].life_tag != null ){
        big_enemy.mortars[_mk].life_tag.dispose();
        big_enemy.mortars[_mk].life_tag=null;
      }

      big_enemy.mortars[_mk].mesh_damaged.dispose();
      big_enemy.mortars[_mk].mesh_collider.dispose();
      big_enemy.mortars[_mk].mesh.dispose();
      big_enemy.mortars[_mk]=null;
    }

    big_enemy.mortars=[];

    //meshes
    big_enemy.agr.dispose();
    big_enemy.agr=null;
    big_enemy.esfera.dispose();
    big_enemy.mesh_collider.dispose();
    big_enemy.mesh_coll_pos.dispose();
    big_enemy.mesh.dispose();

  }//fin de dispose all de tanquero

*click event over mesh after the second clone not fired

As you can imagine it is tough to compile in your mind :wink:

Please share a repro in the PG

1 Like

Hi, i found the problem, unfortunately i don´t have time to make an elegant solution :

class FuelTanker {
//....

  makeHurtInTank(_tank_index,_damage){
    // return;
    // console.log( "llego a dañar tanke ", _tank_index ); 
   
    if( this.tanks[_tank_index].life_shield > 0  ){
      //trabajar sobre el escudo.... 
      if( this.tanks[_tank_index].shieldOn ){ _damage = ~~(_damage / 2);}
            
      this.tanks[_tank_index].life_shield -= _damage;
      this.tanks[_tank_index].life_tag.value = this.tanks[_tank_index].life_shield;
      this.tanks[_tank_index].shield_counter = this.tanks[_tank_index].shield_counter_max;

      if( !this.tanks[_tank_index].shieldOn ){
        this.tanks[_tank_index].shieldOn=true;
        this.tanks[_tank_index].shield_mesh.setEnabled(true);
      }

    }else{
      //trabajar sobre la vida del tanke....
      this.tanks[_tank_index].life_shield=0;
      
      if( this.tanks[_tank_index].useShield ){
        //cambiar el slider a blanco... 
        // console.log( this.name,"debio poner blanco", this.tanks[_tank_index].life);
        this.tanks[_tank_index].useShield=false;
        this.tanks[_tank_index].life_tag.color=COLORES_HEXA.TagLifeColor;
        this.tanks[_tank_index].life_tag.value = this.tanks[_tank_index].life;
        this.tanks[_tank_index].life_tag.maximum = this.tanks[_tank_index].life;
      }

      this.tanks[_tank_index].life -= _damage;
      this.tanks[_tank_index].life_tag.value = this.tanks[_tank_index].life;

      if( this.tanks[_tank_index].life < 1 ){
        //TODO: destruir el tanke
        this.tanks[_tank_index].life=0;
        // console.log( this.tanks[_tank_index].name, "destruir", );
        this.tanks[_tank_index].life_tag.dispose();
        this.tanks[_tank_index].life_tag=null;
        this.vertices_tank=[];
        let _texplodes = utils.rand(2,4);
        // let _vertices = this.tanks[_tank_index].mesh.getVerticesData(BABYLON.VertexBuffer.PositionKind);
        // this.tanks[_tank_index].mesh.computeWorldMatrix(true);
        this.vertices_tank = utils.getPositionVerticesFromMesh(this.tanks[_tank_index].mesh);
        // let _center_tank = this.tanks[_tank_index].mesh.getBoundingInfo().boundingBox.centerWorld.clone();
        if( GPU_PROFILE.level == 1 ){
          SparkFire.shoot_next(this.tanks[_tank_index].mesh_destroyed.position);
        }
        // 
        for (let _expl = 0; _expl < _texplodes; _expl++) {
          // let _pos_explo = utils.posInCircleWithOrigin(utils.rand(0,359),utils.rand(1,5)/10,_center_tank);
          let _v = utils.rand(0,this.vertices_tank.length-1);
          let _pos_explo = this.vertices_tank[_v];

          if( GPU_PROFILE.level > 2 ){
            SparkFire.shoot_next(_pos_explo);
          }
          
          Explosion.explodeNext(_pos_explo.x,_pos_explo.y,_pos_explo.z,500,Game.ELEMENT_EXPLOSION,null);          
        }

        let _mesh_d = utils.rand(1,3)-1;

        this.tanks[_tank_index].mesh.setEnabled(false);
        // console.log( "tank ", _tank_index, "uso mesh destruida",_mesh_d);
       
        this.tanks[_tank_index].mesh_destroyed.setEnabled(true);
        
        _texplodes = utils.rand(1,2);//total fires... 
        
        for (let _expl = 0; _expl < _texplodes; _expl++) {
          // let _pos_explo = utils.posInCircleWithOrigin(utils.rand(0,359),utils.rand(1,5)/10,_center_tank);
          let _v = utils.rand(0,this.vertices_tank.length-1);          
          let _delay = utils.rand(300,900);
          setTimeout(() => {
            this.startFire(this.vertices_tank[_v],_tank_index); 
          }, _delay);

        }

      }
      
    }//fin de afectar vida propia
    
  }//fin de hurt tank

}

i used the vertexs of each tank to select randomly 3 or 4 to use as center of explosion (and fire after explosion, position) when tank is destroyed. I change to make a rantom position from tank center and the new instances appear good in camera

Now working, the change is position of explosions and fires after explosions, all is close to center of mesh: