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

Example: After using noise functions on hair, some of the points might end up inside the geometry. This script will move the points that are inside a geometry to the surface.

Logic around the script:

  • Check if the point is inside a geometry

    • find the nearest point on the skin geometry with xyzdist() vex function

    • store the nearest primitive number and barycentric UV coordinate to variables

    • find the nearest point position on the skin geo with primuv() vex function

    • calculate the direction vector to the surface

    • calculate the closest primitives normal at the nearest point position

    • if the direction vector and evaluated surface normal vectors dot product is greater than zero the vectors are pointing away from each other, therefore the point is inside the geometry

  • for the points inside geometry, move along the surface direction vector multiplied by the distance to the surface.

  • To add padding create a slider.

float dist; int near_prim; vector near_primuv; vector near_pos; vector dir_surface; vector primN; float padding = chf("padding"); dist = xyzdist(1,@P,near_prim,near_primuv); near_pos = primuv(1, "P", near_prim, near_primuv); dir_surface = normalize(near_pos - @P); primN = prim_normal(1, near_prim, near_primuv); float dot = dot(dir_surface, primN); if ( dot > 0){ @P += (dist + padding) * dir_surface; }
Previous
Previous

Get animation cache frame range to a variable in Houdini (Python)

Next
Next

Snap curve roots to a geometry surface (VEX)