Jump to content

Fitting a mesh between curves / Bilinear interpolation?


konstantin magnus

Recommended Posts

I am trying to fit a 2d mesh between 4 curves. Pretty much what the skin SOP does but potentially with a custom mesh.

skin.png.be8552d6d40a428d7fcf958d18e78485.png

vector bbox = relbbox(0, v@P);

function vector blerp(vector a, b, c, d; float x, y){
    vector lr = a * (1.0 - x) + b * (x);
    vector tb = c * (1.0 - y) + d * (y);
    return 0.5 * (lr + tb);
}

vector p0 = primuv(1, 'P', 0, bbox.z);
vector p1 = primuv(1, 'P', 1, bbox.x);
vector p2 = primuv(1, 'P', 2, bbox.z);
vector p3 = primuv(1, 'P', 3, bbox.x);

v@P = blerp(p0, p2, p1, p3, bbox.x, bbox.z);

How can I smoothly interpolate the point positions so the borders actually touch the curves?

blerp.hiplc

Link to comment
Share on other sites

  • 5 months later...

Broken down into more comprehensible steps:

vector uv = relbbox(0, v@P);

vector crv_0 = primuv(1, 'P', 0, uv.z);
vector crv_1 = primuv(1, 'P', 1, uv.x);
vector crv_2 = primuv(1, 'P', 2, uv.z);
vector crv_3 = primuv(1, 'P', 3, uv.x);

vector start_0 = primuv(1, 'P', 0, 0);
vector start_2 = primuv(1, 'P', 2, 0);
vector end_0   = primuv(1, 'P', 0, 1);
vector end_2   = primuv(1, 'P', 2, 1);

vector ipol = lerp(crv_0, crv_2, uv.x);
ipol       += lerp(crv_1, crv_3, uv.z);

vector fit_0 = lerp(start_0, end_0, uv.z);
vector fit_2 = lerp(start_2, end_2, uv.z);

v@P = ipol - lerp(fit_0, fit_2, uv.x);

 

  • Like 2
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...