pcopen to add points based on distance

   2545   3   1
User Avatar
Member
336 posts
Joined: Dec. 2014
Offline
So, finding the distance between current points and adding new ones at their midpoint based on a threshold value. I've seen this done with VOPS but it's very messy, I'd like to get this going in VEX but I could use some help I'm pretty new to pcopen()
User Avatar
Staff
6196 posts
Joined: July 2005
Offline
I strongly recommend using pcfind() instead. The pciterate loop is a bit odd, and pcimport doesn't help you with general attribute import problems, while the point() works everywhere.

// If closest point to us is farther than threshold,
// add point at midpoint

float threshold = 1;
int nearpts[] = pcfind(0, 'P', @P, /*maxdist*/1e20, /*numpt*/ 2);

// Nearest point is ourself, so we are interested in second
if (len(nearpts) > 1)
{
int pt = nearpts[1];
vector npos = point(0, 'P', pt);
if (length(@P - npos) > threshold)
{
// Too far, add a point.
vector midpoint = (npos + @P) / 2;
addpoint(geoself(), midpoint);
}
}

Note the difference between len() and length().
User Avatar
Member
4512 posts
Joined: Feb. 2012
Offline
One thing to note with pcopen though, there is a free pcfilter function which you will have to implement yourself for pcfind. SESI should provide one that works with arrays so pcfind can be used more often.
Senior FX TD @ Industrial Light & Magic
Get to the NEXT level in Houdini & VEX with Pragmatic VEX! [www.pragmatic-vfx.com]

youtube.com/@pragmaticvfx | patreon.com/animatrix | animatrix2k7.gumroad.com
User Avatar
Member
336 posts
Joined: Dec. 2014
Offline
Super helpful guys, thanks tons
  • Quick Links