Iteratively approximating a subdivision model to match a target surface after subdivision.
Calculating the subdivision limit surface.
int prim_hit;
vector uvw;
xyzdist(0, v@P, prim_hit, uvw);
int patch;
float patch_u;
float patch_v;
osd_lookuppatch(0, prim_hit, uvw[0], uvw[1], patch, patch_u, patch_v);
vector pos;
osd_limitsurface(0, 'P', patch, patch_u, patch_v, pos);
v@pos = pos;
Displacing the surface along the normals by the signed distance between the limit surface and the target surface.
int pr;
vector uvw;
float d = xyzdist(1, v@pos, pr, uvw);
vector pos = primuv(1, 'P', pr, uvw);
vector dir = normalize(v@pos - pos);
vector nml = primuv(1, 'N', pr, uvw);
float s = sign(dot(dir, nml) + 0.01);
v@P -= v@N * s * d;