Skip to content

Find

Nearest point from ancillary

Let Input 0 be a regular points Input 1, a smaller set of points Find the closest point index Run over: points

vex
int near = nearpoint(1, v@P, chf("maxdist"));
i@near = near;

Find the value of a variable in other table

Table 0:

PownerId
xyzsomeString

Many positions with a name

Table 1:

ownerIdCd
idA1,1,1
idB0,0,0

Few colors, with a name associated this is like a dictionary, it will only work if the keys are unique

vex
string id = s@ownerId;
//int colorIndex = nametopoint(1, id);
int colorIndex = findattribval(1, "point", "ownerId", id);
vector color;
if (colorIndex == -1)
{
color = {0,0,0};
}
else
{
color = point(1, "Cd", colorIndex);
}
//printf("Color is: %f \n" , color);
v@Cd = color;

Now every point is colored by the colors table.

Find unique attrib and group

vex
// In detail mode
// searching for the endpoint attrib of a path, if is found more than once, reject
int unique[];
for (int i=0; i< i@numprim ; i++)
{
int ending = prim(0, "endpt", i);
int found = find(unique, ending);
printf("found %d \n", found);
if (found < 0){ // if value is negative, then it was found
push(unique, ending);
setprimgroup(0, "unique_path", i, 1);
printf("Ending %d, at primnum %d \n", ending, i);
}
}

Find if a primitive has an incorrect winding order

vex
// run over primitives
// ancillary value 1, is the reference point/prim normal
vector prim_normal = prim_normal(0, i@primnum, vector(0.0));
vector centroid_normal = point(1, "N", 0);
float normals_dot = dot(prim_normal, centroid_normal);
f@ndot = normals_dot;
if (normals_dot < 0)
{
setprimgroup(0, "reversed" , @primnum, 1, "set");
}

After use a reverse sop node to only reverse the prims in the ‘reversed’ group Adjust Winding Order procedurally Reversing and Correcting normals