Snap curve roots to a geometry surface (VEX)

Example: Run this script in a primitive wrangle to make sure the hair curves roots sit on the skin surface. Good for handling small model updates as well, since this doesn’t care about UV -coordinates or topology.

Logic around the script:

  • Run over primitives

  • Get the first point (root) of the primitive to a variable

  • Store root point position to a variable

  • Use xyzdist() and primuv() functions to find the closest position on a surface measured from the root position of the iterated primitive

  • Set the found position as the P attribute of the root point

// run in a primitive wrangle
// hair curves to the first input
// skin geometry to snap to to the second input

int pnt = primpoint(0,@primnum,0);

vector rootP = point(0,"P",pnt);

int prim;
vector uv;

xyzdist(1,rootP,prim,uv);

vector pos = primuv(1,"P",prim,uv);

setpointattrib(0,"P",pnt,pos);
Previous
Previous

Move hairs that are inside the geometry back to the surface (VEX)

Next
Next

Move animation cache to origin (VEX)