Pop Birth Attribute
Here’s its existing code:
#include <voptype.h>
#include <voplib.h>
int npts = ch("npts");
int seed = ch("seed");
float frame = ch("frame");
int firstpointcount = ch("firstpointcount");
int firstprimcount = ch("firstprimcount");
for(int i = 0; i < npts; ++i)
{
float r = rand(vop_floattovec((float)i, frame, (float)seed));
int sourcept = (int)(r * firstpointcount);
sourcept = clamp(sourcept, 0, firstpointcount-1);
int newpt = addpoint(geoself(), sourcept);
setpointattrib(geoself(), "sourceptnum", newpt, sourcept);
}
for(int i = 0; i < firstprimcount; ++i)
removeprim(geoself(), i, 0);
for(int i = 0; i < firstpointcount; ++i)
removepoint(geoself(), i);
It works by taking the total number of points that are supposed to be birthed this frame and spreading it randomly across the source points. But we want to go through all the source points, read the @birth attrib, and birth that many particles on the point. So replace the bold bit with this new code:
for(int sourcept = 0; sourcept < firstpointcount; ++sourcept)
{
for (int j = 0; j < point(geoself(), "birth", sourcept); j++) {
int newpt = addpoint(geoself(), sourcept);
setpointattrib(geoself(), "sourceptnum", newpt, sourcept);
}
}
No Comments