Help to attach a particleSystem to a submesh by clone/instanced mesh

i have error when i tried use submesh by cloned mesh as emiter for particleSystem.

other view

code to create particleSystem (yellow particleSystem)

setTurbines(){

    // console.log( this.mesh._children );

    // return;

    // //obtener las turbinas de mi mesh...

   

    if( utils.ships[this.ship].mode_turbine == "single" ){

      //a single turbine

      this.turbine_center ={};

    }else{

      for(let _k =0; _k < 3; _k+=1){

       

        for(let _u=0; _u < scene.meshes.length;_u+=1){

          // console.log( scene.meshes[_u].name+", mi ship "+this.ship );

          if( scene.meshes[_u].name.includes(this.nombre+"_sh."+this.ship+"_turbina")  & (this.turbines[_k] == null | this.turbines[_k] == undefined) ){

            //navee  

            console.log( "AAAA" );

            if( !this.ids.includes( scene.meshes[_u].name) ){

              this.ids.push( scene.meshes[_u].name);

              this.turbines_index.push(scene.meshes[_u].name);

              console.log( this.ids );

              this.turbines[_k] = new BABYLON.ParticleSystem("particle_"+this.nombre+"-"+scene.meshes[_u].name, 500, scene);

              console.log( _k+"up turbinaa "+ scene.meshes[_u].name);

              //

              //Texture of each particle

              this.turbines[_k].particleTexture = new BABYLON.Texture("/textures/flare.png", scene);

              this.turbines[_k].emitter =  scene.meshes[_u];

              // console.log( this.turbines[_k].emitter );

              // this.turbines[_k].worldOffset = new BABYLON.Vector3(-2, 0, 0);

              this.turbines[_k].minEmitBox = new BABYLON.Vector3(-0.1, 0, 0); // Starting all from

              this.turbines[_k].maxEmitBox = new BABYLON.Vector3(0.1, 0, 0); // To...

              // Colors of all particles

              this.turbines[_k].color1 = new BABYLON.Color4(0.7, 0.0, 0.0, 1.0);

              this.turbines[_k].color2 = new BABYLON.Color4(0.2, 0.0, 0.0, 1.0);

              this.turbines[_k].colorDead = new BABYLON.Color4(0.2, 0.2, 0.2, 0.0);

              // Size of each particle (random between...

              this.turbines[_k].minSize = 0.3;

              this.turbines[_k].maxSize = 0.8;

              // Life time of each particle (random between...

              this.turbines[_k].minLifeTime = 0.2;

              this.turbines[_k].maxLifeTime = 0.4;

              // Emission rate

              this.turbines[_k].emitRate = 50;

              // Blend mode : BLENDMODE_ONEONE, or BLENDMODE_STANDARD

              this.turbines[_k].blendMode = BABYLON.ParticleSystem.BLENDMODE_ONEONE;

              // Set the gravity of all particles

              this.turbines[_k].gravity = new BABYLON.Vector3(0, -10, 0);

              // Direction of each particle after it has been emitted

              this.turbines[_k].direction1 = new BABYLON.Vector3(0, 5, 0);

              this.turbines[_k].direction2 = new BABYLON.Vector3(0, 5, 0);

              // Angular speed, in radians

              this.turbines[_k].minAngularSpeed = 0;

              this.turbines[_k].maxAngularSpeed = Math.PI;

              // Speed

              this.turbines[_k].minEmitPower = 1;

              this.turbines[_k].maxEmitPower = 3;

              this.turbines[_k].updateSpeed = 0.01;

              this.turbines[_k].isLocal = true;

              this.turbines[_k].isVisible=true;

              // Start the particle system            

              this.turbines[_k].start();

             

            }    

          }

        }

               

      }

     

    }

  }

above: iterate over all meshes by scene, qhen i find appropiatte mesh, u tried to use as emitter.

when i see thap position is bad, in update i tried this (blue particleSystem) :

update(){

    //actualizacion de posicion de turbina emiter
    if( game.key != "" ){
      // let matrix = this.mesh.computeWorldMatrix(true);  // force calculation of world matrix
      // let local_pos = new BABYLON.Vector3(0,0,-3); //top middle of box relative to box
      // let global_pos = BABYLON.Vector3.TransformCoordinates(local_pos, matrix); //calculate world position
      // console.log( global_pos );
      // this.turbines[0].emitter = global_pos;

      scene.meshes.forEach(_mesh => {      
        // console.log( m.name );
        this.turbines_index.forEach(_name =>{
          if( _mesh.name == _name ){
            //
            
            switch(this.ship){
              case "raptor":
                let matrix = _mesh.computeWorldMatrix(true);  // force calculation of world matrix
                let local_pos = new BABYLON.Vector3(0.46,1.2,0.1); 
                let global_pos = BABYLON.Vector3.TransformCoordinates(local_pos, matrix);
                // console.log( global_pos );
                this.turbines[0].emitter = global_pos;
                this.turbines[0].isLocal = true;
                this.turbines[0].gravity = new BABYLON.Vector3(0, 0, -0);
                this.turbines[0].direction1 = new BABYLON.Vector3(0, 0, 5);
                this.turbines[0].direction2 = new BABYLON.Vector3(0, 0, 5);

                this.turbines[0].minAngularSpeed = 0;
                this.turbines[0].maxAngularSpeed = Math.PI;

                // Speed
                this.turbines[0].minEmitPower = 10;
                this.turbines[0].maxEmitPower = 30;
                // local_pos = new BABYLON.Vector3(-0.46,1.2,0); 
                // global_pos = BABYLON.Vector3.TransformCoordinates(local_pos, matrix);
                // this.turbines[1].emitter = global_pos;
                // this.turbines[1].gravity = new BABYLON.Vector3(0, -10, 0);
                // this.turbines[1].direction1 = new BABYLON.Vector3(0, 0, 0);
                // this.turbines[1].direction2 = new BABYLON.Vector3(0, 0, 0);
                
              break;
            }
            // let local_pos = _mesh.position; //top middle of box relative to box
            
          }
        });

      });


    }
    
}//end of method

NOTE: previously I have achieved it but with a mesh, NOT with an instance or clone of a mesh

NOTE 2 : this

this.turbines[0].isLocal = true;

and

this.turbines[0].isLocal = false;

tested in update method

Would be great if you could repro in the playground ??? it is hard to troubleshoot without a repro

hi, game is deployed here :

http://142.93.26.151/

This won t really help as it takes a lot of time to troubleshoot on a deployed app like this. Could you create a small repro (no need to have all the app) in the playground ?

I could not make it rotate or move, I made sure to use the same version 4.2, but it was not possible, there the error is described in any case, regarding the positioning of the jets

https://playground.babylonjs.com/#ASEH6Y#61

I am not sure to understand the issue. If I attached the particle system to the turbines and rotate it looks like it is working ?

I need it on a cloned object (it is a multiplayer game and therefore a ship can be instantiated at any time)

For some reason that I do not know in PG when instantiating a mesh, this DOES NOT INSTANCE its children, for this reason is that the turbines (cones) are not seen in the duplicate

Thanks for sharing this! Would mind simplifying it a bit so it’s just the part that isn’t working? There is a lot of code here which makes it a bit tricky to figure out what is going wrong

I would work on a clone the exact same way but I am not sure it can be attached to an instance.

with both not works

It is very simple, I need to put a particlesystem to a submesh of a mesh that was cloned, the clone is NOT created in the definition of the scene, it is create afterwards, because being a multiplayer game at any time a new player joins the game.

Something like this maybe for positioning the emitters? I used a child TransformNode for each of the 3 emitters and set their positions to move 1 of them to the middle of each wing. Not sure if this is exactly what you’re going for but hopefully it gets it closer. :slightly_smiling_face: :beers:
https://playground.babylonjs.com/#ASEH6Y#68

Edit: an issue I think was that all 3 particle systems used this.mesh as their emitter, that’s why I made 3 children of this.mesh (transform nodes) for the emitters, to give each a different position relative to this.mesh. Also I moved the code to add a player out of the setTimeout callback and into an addPlayer function and added 2 players right way after the model loads to save time. :slightly_smiling_face:

1 Like

hi, thanks, y will try it, :+1:

1 Like

hi, result here, many thanks

2 Likes