How to spawn only 1 particle, apply a popkill, and on deletion spawn a new, single particle?

   4166   5   1
User Avatar
Member
81 posts
Joined: Feb. 2014
Offline
Hi All

In my attached file I spawn particles from a point and use a popkill with a bounding-sop setting to delete them, once outside the bounding object. Please press play to see the result.

What I am looking for is the following situation: That there exists only one particle. It is born, rests on the ground, once outside the bounding object it dies and a new one gets immediately respawned at the emitter point. And then repeat.

Again in steps.
- birth a particle
- kill it once outside bounding region
- spawn a new one

Is this possible to achieve?


Thanks

Michiel

Attachments:
stretchParticle03.hiplc (266.9 KB)

User Avatar
Member
7754 posts
Joined: Sept. 2011
Offline
If you don't mind controlling sourcing yourself, it's quite simple. I have done so using a geometry wrangle to create a single point with random position and velocity under the condition that no points exist. The popkill is done using a popkill sop in ‘bounds’ mode with ‘invert’ checked on.

source code for source:
if (npoints(0)==0) {
    vector2 h = set(@Time,chf('seed'));
    int hash0 = random_fhash(h);
    int hash1 = random_fhash(set(hash0/65536,hash0%65536));
    int hash2 = random_fhash(set(hash1/65536,hash1%65536,hash0/65536,hash0%65536));
    vector uv = set(float(random(hash0)),float(random(hash1)),float(random(hash2)));
    vector p = sample_sphere_uniform(uv)*chf('radius')+chv('location');
    hash0 = random_fhash(uv);
    hash1 = random_fhash(set(hash0/65536,hash0%65536));
    hash2 = random_fhash(set(hash1/65536,hash1%65536,hash0/65536,hash0%65536));
    uv = set(float(random(hash0)),float(random(hash1)),float(random(hash2)));
    vector v = sample_sphere_uniform(uv)*chf('energy');
    int pt = addpoint(0,p);
    setattrib(0,"point","v",pt,-1,v);
}
I got fancy with random number and spherical sample generation. Feel free to throw a simple ‘rand()’ in there if you feel more comfortable with that.

Edit: A slight change, hash velocity off of uv instead of p, as p could be 0,0,0 if radius is 0. On popsolver, changed ‘reap at end’ to off to prevent ‘dead’ frames with no particles existing.
Edited by jsmack - Dec. 16, 2017 17:00:57

Attachments:
birth_one_and_kill.zip (31.6 KB)

User Avatar
Member
81 posts
Joined: Feb. 2014
Offline
Hi Jsmack

At first and second glance this seems elegant, robust and indeed what I am looking for.
I have to alter it a bit to match more my own scenario but that is a good exercise to understand better what is happening where and why.
I will dive into it further and gladly give a follow up later on..

Thanks a lot!

Michiel
User Avatar
Member
1737 posts
Joined: May 2006
Offline
If I understand your question, all you should need to do is check if a particle's @ptnum is greater than 0, if so, remove it.

In a new pop wrangle:

if (@ptnum>0) {
  removepoint(0,@ptnum);
}

Attachments:
pop_single.gif (52.7 KB)

http://www.tokeru.com/cgwiki [www.tokeru.com]
https://www.patreon.com/mattestela [www.patreon.com]
User Avatar
Member
81 posts
Joined: Feb. 2014
Offline
Hi Matt. That is awesome and directly applicable to the current set-up.
I think you know what I am aiming for and now I can take that extra step, yay..

There is one small glitch though: One frame between death and reincarnation where there is no particle present. The object which tries to follow this point zero jumps back to the origin and a frame later falls in line again.
For the moment I can roughly ignore it by stating:
if (@ptnum>1) {
  removepoint(0,@ptnum);
}
Now there are two particles most of the time and one before rebirth.
This causes some micro skitting which is actually, for the moment, not that bad at all. But for all round smoothness, curiosity and world domination it would be neat if it also worked with a single particle.

Thanks for the help. Hopefully I can post something soon about the usefulness of this.
User Avatar
Member
81 posts
Joined: Feb. 2014
Offline
Hi Matt

I should rinse myself in battery acid until the shame comes off.
Your setup is valid.
Jsmack's method did not have the mentioned ‘glitch’ and when comparing the two methods the solution lied in the popsolver settings. Unchecking ‘Reap at frame end’ did yield smooth results.
Both approaches are equally possible, yours is handy because I can directly pipe in the transforming spawn object (bugfoot!). With Jsmacks method I would use a pointexpression for this. I don't know how that would scale in performance when used extensively.
  • Quick Links