Projecting parts of a mesh onto a plane using the planepointdistance-function combined with a dot product to determine sides.
The planepointdistance function returns the closest position p
on the plane for the mesh to press against. The signed dot
product compares the direction towards the plane dir
versus the planes normal nml
to later only deform the part of the mesh that lies behind the plane. in
and out
parameters inside a smooth
function make the pressing fade out over distance, stored in bias
. Similarly, a mask is defined to later drive a blur node which smoothes out the deformation area.
// PARAMETERS
float in = chf('in');
float out = chf('out');
float off = chf('offset');
float soft = chf('soften');
// PLANE
vector p;
vector pos_pt = point(1, 'P', 0);
vector nml = prim_normal(1, 0, vector(0.0));
float d = planepointdistance(pos_pt, nml, v@P, p);
vector plane = p + normalize(nml) * off;
// MASK
vector dir = normalize(pos_pt - v@P);
float angle = dot(dir, nml);
float sdist = sign(angle) * d;
float bias = smooth(-out, in, sdist);
float mask = smooth(-soft, soft, sdist);
vector pos = lerp(v@P, plane, bias);
// OUTPUT
f@mask = mask;
v@P = pos;