Jump to content

Make Curve In VEX


Igor

Recommended Posts

Put all point positions into an array and make parameter "t" slide e.g. from 0 to 1 inside a for loop.

int steps = chi('steps');
vector all_points[];
resize(all_points, npoints(0));

for (int i = 0; i < npoints(0); i++){
    all_points[i] = point(0, "P", i);
}

int prim = addprim(0, "polyline");

for(int i = 0; i < steps; i++){
    float slide = i / float(steps - 1);
    vector pos = spline("catrom", slide, all_points);
    int inter_pt = addpoint(0, pos);
    addvertex(0, prim, inter_pt);   
}

Also a simple function for interpolating 4 points to a curve by yourself would be:

int steps = chi('steps');

vector pt0 = point(0, "P", 0);
vector pt1 = point(0, "P", 1);
vector pt2 = point(0, "P", 2);
vector pt3 = point(0, "P", 3);

int prim = addprim(0, "polyline");

for(int i = 0; i < steps; i++) {

    float slide = i / float(steps - 1);
    vector pos0 = lerp(pt0, pt1, slide);
    vector pos1 = lerp(pt2, pt3, slide);
    vector ipol = lerp(pos0, pos1, slide);

    int inter_pt = addpoint(0, ipol);
    addvertex(0, prim, inter_pt);
}

 

VEX_spline.hipnc

Edited by konstantin magnus
  • Like 7
Link to comment
Share on other sites

  • 1 year later...
2 hours ago, patremblay said:

include the first and last points as well and also smoothly close the curve?

I dont think the spline()-function does this for cubic splines. You can read about it here: http://www.sidefx.com/docs/houdini/vex/functions/spline.html

But you could connect points to a curve and close it with an add-node and resample this to an 'interpolating curve' or a 'subdivision curve'.

spline.hipnc

Edited by konstantin magnus
Link to comment
Share on other sites

  • 1 year later...

Hi, I have an additional question, related to this thread. 

There are random existing curves, for instance. When applying a resample node, it adds points evenly. However, I am looking for a way to add points exponentially then add points with even distance. 

Is that possible to do it procedurally?  

splineCurve.png

Link to comment
Share on other sites

Hi @tagosaku,

you can shift points by sampling positions from their respective curves with a channel ramp:

float u = vertexprimindex(0, i@vtxnum) / float(primvertexcount(0, i@primnum) - 1);
v@P = primuv(0, 'P', i@primnum, chramp('shift', u));

 

curve_density.hipnc

Edited by konstantin magnus
  • Like 3
  • Thanks 3
Link to comment
Share on other sites

On 4/3/2020 at 6:29 AM, konstantin magnus said:

Hi @tagosaku,

you can shift points by sampling positions from their respective curves with a channel ramp:


float u = vertexprimindex(0, i@vtxnum) / float(primvertexcount(0, i@primnum));
v@P = primuv(0, 'P', i@primnum, chramp('shift', u));

curve_density.hipnc

well this trumps my curveu bias HDA royally !!!

  • Haha 1
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...