### VEX: How to use their spline functions to draw a spline

2856   3   0
Member
1787 posts
Joined: Sept. 2015
Offline
Hello,

I was hoping someone could point me in the right direction in getting a spline drawn using VEX.

In the code below I have no problem making a zigzag line from within a point wrangler, but I cannot get the spline function to draw a spline.

In the docs it says the second argument of the spline function is a float and is the position along the spline.

http://www.sidefx.com/docs/houdini15.5/vex/functions/spline [sidefx.com]

Now what I don't understand is what is that float position? I mean it can't be a vector position of x,y,z because it's only a float.

Am I to understand that it's like an equadistant position along that spline defined by the number of vectors arguments given?

eg. say I give the function 4 vectors and define the second float argument as 3.5. Does this mean I am going to get the returned value ( height according to docs ) of that second argument that lies mid-point between the 3rd and 4th vectors given on the calculated spline?

Then if this is so…what it seems to me what I have to do is use the addprim and addvertex functions to actually draw the line? Getting better resolution with more values with the second argument of the spline function?

eg create a function that runs through many values to smooth out the curve. ( Use each returned value of the spline function as a vertex point in the function addvertex. )

I could probably have tested this idea by working at it, but if I am off track I was hoping someone could help by providing a comment and possibly save me some time researching this.

Thank you.

`// Vex code in point wrangler set to 'Detail'vector vpt0, vpt1, vpt2, vpt3;int    ipt0, ipt1, ipt2, ipt3;vpt0 = {0,0,0};vpt1 = {2,3,0};vpt2 = {4,-1,0};vpt3 = {8,2,0};ipt0 = addpoint(0, vpt0);ipt1 = addpoint(0, vpt1);ipt2 = addpoint(0, vpt2);ipt3 = addpoint(0, vpt3);int Tprim = addprim(0, "polyline" );addvertex( 0, Tprim, ipt0 );addvertex( 0, Tprim, ipt1 );addvertex( 0, Tprim, ipt2 );addvertex( 0, Tprim, ipt3 );// The above code works, giving a zig zag line but the code below doesn't give anythingfloat T_pos = 2;vector T_height;T_height = spline("catrom", T_pos, vpt0, vpt1, vpt2, vpt3);`
Edited by BabaJ - Aug. 20, 2016 15:19:18
Member
881 posts
Joined: May 2006
Offline
I may be wrong, but I don't think the vex spline functions are meant for drawing curves. My understanding is they're for creating and interpreting a mathematical model of a spline, say for doing an interpolation between values.

If you want to draw a spline curve, create a polyline as you're doing now, and append a convert sop in bezier curve/nurbs curve mode.

Edited by mestela - Aug. 21, 2016 09:05:09
Member
1787 posts
Joined: Sept. 2015
Offline
Hi mestela,

Yeah, by reading the doc's what you say seems to be the case.

Unfortunately using a convert sop won't work for me as it takes a prim.

In my case the number of individual prims is, changes frame by frame which results in two situations.

One is that the prim number of the “polyboxes” will change and not knowing beforehand how many too I cannot put down a corresponding number of covnert sops.

There will be a high number of individual “polyboxes” that change in number and uniquely each in size/color/position/other attribues.

This is the reason I went with vex and point wrangler so that I could use functions to control the individual boxes and number of them.

I appreciate the suggestion though; Yet maybe I don't understand fully how I could apply your suggestion.

I will have to look at it again, but for now some matters have come up and I will have to leave this topic for a number of days.

Perhaps when I return I will post an example of what I am doing. And maybe write those functions that take the information from the spline function and see if I could create a spline from that as mentioned.

Thanks again.
Member
1787 posts
Joined: Sept. 2015
Offline
So I played around with this function and it works as I originally suspected.

I'm including the hip file here for anyone interested.

The code is in the point wrangler along with the spare paramters I created.

The docs seems to indicate that it's possible to use any number of vectors as the input for the function.

Here in this file I am only using four user defined vectors.

In this case the first and last vectors become the “control” handle that affects the shape of the curve;

While the second and third vector reflects the x,y coordinates of the the respective start and endpoints of the curve.

Also, the second argument of the function does act like an ‘equadistant’ position along the curve between the second and third vectors.

The range of this argument is as if it has been ‘normalized’ meaning its range is always between 0 and 1.0

But you can define the increments to ever smaller values like 0.1, 0.001, 0.0001 etc.

It acts like what a resample node might do.

I created a short function that works with a spare paramter that can increase or decrease the number of points along the curve.

The other spare paramters control the x,y positions of the vectors that go towards creating the final spline curve.

These spare paramters are located just below the vex code window of the point wrangler.

Also, as a side note…in the vex code my integer variable ‘Range’ is linked to the spare paramter ‘range_resolution’ and its Type was made to be integer.

But I think there is a bug because the vex code is generating a warning of implicit cast from float to int.

I've noticed this happening with any spare paramter created as an integer type. But the code works regardless.
Edited by BabaJ - Aug. 27, 2016 10:44:26

Attachments:
test vex spline functions.hiplc (676.2 KB)