Page 1 of 3

Ring particle emitter?

PostPosted: Sunday, 08.June 2014, 12:13
by Skinnytorus
Hi there.
1) I've been playing with particle code. In fxparticle.cpp at line 223 there is this code:
Code: Select all
sFORALL(Particles,p)
  {
    switch(Para.CreateFlags & 3)
    {
    case 0:
      r.InitRandom(rnd);
      break;
    case 1:
      r.x = rnd.Float(2)-1;
      r.y = rnd.Float(2)-1;
      r.z = rnd.Float(2)-1;
      break;
    case 2:
      r.InitRandom(rnd);
      r.Unit();
      break;
    }
    p->Pos = (sVector31)r;
    r.InitRandom(rnd);
    p->Speed = r;
    p->Time = rnd.Float(1);
  }

It initializes particle positions for Ballistic. I wonder is there is a simple way to create a ring emitter with particles oriented outwards?

2) I've also noticed that if we rem out string 241 (i.e. r.InitRandom(rnd); which randomizes particle speed vectors) we can orient particles outwards (in Forward and Fly mode in Chunks)! Thus, by making a switch that excludes this string we can orient particles correctly. I coded the switch, but just can't make it work (no difference if it's on or off). Maybe The Great Master Code Guru could do that properly? Thanks anyway ;)

Re: Ring particle emitter?

PostPosted: Monday, 09.June 2014, 06:02
by ikam
1/ best way to create a ring (or other shape) emiter outward is maybe to use mesh and a normal emiter.

2/ You cannot simply add a new case in this switch, because it is relative to balistic shapes (0= sphere, 1 = square , 2 = bouble), if you add a case 4: (is that you did ?) there is nothing in the operator parameter that drive this new value, why it doesn't work...

first (in switch code part), r variable is used to compute the particle position according shape flag and set pos here : p->Pos = (sVector31)r;

in a second time, r variable is reused to compute speed particle :

r.InitRandom(rnd);
p->Speed = r;

In all cases (all shapes) speed will be a random value.

So yes this random could be run or not. if yes it works as usual, if not speed init value will be the same as pos, why not...
But best way is to create another parameter in the operator, because it is not really relative to shape and It will keep the backward behavior.

my test file :

Re: Ring particle emitter?

PostPosted: Monday, 09.June 2014, 07:52
by Skinnytorus
1/ best way to create a ring (or other shape) emiter outward is maybe to use mesh and a normal emiter.

I agree with that, but how to orient the particles outwards without using workarounds (Explosion etc.)? Imho this should be a quick and easy operation.

if you add a case 4: (is that you did ?) there is nothing in the operator parameter that drive this new value, why it doesn't work...

Not really... I created a SameSpeed integer var, then a switch in the .ops file (like yours AnimateSource), then made a condition:
if(Para.SameSpeed&0) r.InitRandom(rnd);
Imho, it should be checked each cycle. Something is wrong here...
And thanks for the file. :) I will have a look at it this evening.

Re: Ring particle emitter?

PostPosted: Monday, 09.June 2014, 10:54
by ikam
what is the SameSpeed variable, a param speed value instead of a random ?

it should work if you something like that :
in .ops => flags RandomSpeedFlag ("-|on") = 1; // 1 as default value ensure backward compatibility in balictic behavior
in .cpp => if(Para.RandomSpeedFlag ) r.InitRandom(rnd);

ps : don't forget to add new ops parameter at end of existing parameters, else it break operator backward compatibility and you need to to reorder parameters with a special syntax.

if it doesn't work show me your code.
I'm thinking on how to use fromvertex in combination with balisctic to emit from normals.

Re: Ring particle emitter?

PostPosted: Monday, 09.June 2014, 11:20
by Skinnytorus
Edit:
what is the SameSpeed variable, a param speed value instead of a random ?

No. It's basically the name of the switch that turns random speed off and makes it equal to converted particle positions.

Many thanks for the code. I will check that and get back to you.
Combination with balisctic to emit from normals:
It would be great if FromVertex could initially align particles along normals (as an option) and then pass vertex normal vectors as initial speed direction to Ballistic.

Re: Ring particle emitter?

PostPosted: Monday, 09.June 2014, 17:32
by Skinnytorus
It works! Many thanks! I called the switch RandomSpeed. Here are my test files. If you are fine with how it works, could you please commit that?

Re: Ring particle emitter?

PostPosted: Monday, 09.June 2014, 18:55
by CybeREX
Work! Great job man!

Re: Ring particle emitter?

PostPosted: Monday, 09.June 2014, 18:58
by ikam
great, ok i'll commit it.

Re: Ring particle emitter?

PostPosted: Monday, 09.June 2014, 19:11
by Skinnytorus
Cool. Thanks. Any progress with FromVertex+Ballistic normal alignment? Vertex struct seems to have point normal member. I'm not the king of c++ but it should be quite easy to get normals from mesh... I wonder which function works best for particle alignment? Quaternions?

Re: Ring particle emitter?

PostPosted: Tuesday, 10.June 2014, 06:51
by ikam
I added the direction information in the particle struct, particles operators can now use this info.
I also modified fromvertex to fill this info and balistic to add a mode that use it.
You can now combine them to emit from vertex normals of a mesh.

Re: Ring particle emitter?

PostPosted: Tuesday, 10.June 2014, 08:07
by Skinnytorus
Yo! Great many thanks, Master Code Guru! :-({|=
I will check this one this evening. Did you decide to omit implementing RandomSpeed on/off switch because it seems useless now?
I suggest you implement it just for the hell of it. Someday it might still prove useful. No need for a mesh in simple cases will simplify the stack.

Re: Ring particle emitter?

PostPosted: Tuesday, 10.June 2014, 08:22
by ikam
I added it, maybe It should be usefull in some case...
here some little examples.
Image

Re: Ring particle emitter?

PostPosted: Tuesday, 10.June 2014, 08:25
by ikam
It should be possible now to modify chuncks to oriente meshes from particles directions.

Re: Ring particle emitter?

PostPosted: Tuesday, 10.June 2014, 09:58
by Skinnytorus
Very nice. Huge thanks as always. =D>
I will comment on how it works this evening.

Re: Ring particle emitter?

PostPosted: Tuesday, 10.June 2014, 11:12
by Skinnytorus
By the way... What do you think about adding normal alignment to the mesh FromVertex operator? That would be so cool for modeling!