How to Stick or Snap Points to Deforming Geometry in Houdini
02 Apr 26 (1mo ago)
In VFX and CFX, one of the most common tasks is sticking/snapping points to a geometry. In C4D, you have to battle with priorities. In Maya, much better but you have to manage several rivets yourself.
Good thing, Houdini is much capable than that, and its procedural nature makes it fun to work with.
The Core Logic: xyzdist and primuv
To snap a point to any surface, you need to find its unique "address." This address consists of a Primitive ID and Parametric UVs. You use a Point Wrangle with your points in Input 0 and the target mesh in Input 1.
Scenario A: Snapping to Static Geometry
If you are snapping points to a non-deforming target—like conforming a prop to terrain or a one-time "shrink-wrap"—the logic is simple and can be handled in a single node:
int target_prim;
vector uvw;
// 1. Find the "address" on the target mesh in Input 1
float dist = xyzdist(1, @P, target_prim, uvw);
// 2. Snap @P to that exact surface position
@P = primuv(1, "P", target_prim, uvw);
Scenario B: Sticking to Deforming (Animated) Geometry
When the target is moving (like our leech-covered character), the code above fails because it recalculates the "closest point" every frame. To make points stick, you must split the process into two steps.
Step 1: The Capture (Done once on a Rest Frame) On Frame 1 (or your rest pose), store the address as permanent attributes so the points "remember" where they live:
// Store the address attributes for later use
xyzdist(1, @P, i@target_prim, v@target_uvw);
Step 2: The Deform (Applied to the Animated Timeline) Downstream, use a second Wrangle to "pluck" the new position from the moving mesh (connected to Input 1) using those stored addresses:
// Update @P based on the stored home address
@P = primuv(1, "P", i@target_prim, v@target_uvw);
Versatile Use Cases
The beauty of this VEX snippet is its versatility; it works whether you are sticking points to their own mesh or a completely different object (Cross-Geometry Snapping):
- Conforming to Terrain: Snapping a character's feet or a prop's base to a ground plane deformed by a Mountain SOP.
- Shrink-wrap Effects: Taking a loose cloud of points and "vacuum sealing" them onto a specific collision mesh.
- Constraint Setup: Pinning FX elements like sparks, debris, or buttons to a moving "driver" mesh that isn't part of the original simulation.