Jump to content
Sign in to follow this  
konstantin magnus

Fitting a mesh between curves / Bilinear interpolation?

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.


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?


Share this post

Link to post
Share on other sites


here is an approach using linear blend for profile curves and transforming them onto the rail curves.




Edited by Aizatulin

Share this post

Link to post
Share on other sites

Thank you @petz! I can see myself creating procedural cars with this!

* once I have found an elegant way to shape the guide curves and solved a bunch of other problems ; )

Edited by konstantin magnus

Share this post

Link to post
Share on other sites

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

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this