Jump to content

A VEX helix?


Atom

Recommended Posts

Hi All,

 

I am trying to port an hScript expression in a point node to a point wrangle but the wrangle is not performing as expected.

 

In the Point node I am modifying the position with an expression to create a helix.

$TX+sin($TY*ch("../line1/freq")) * ch("../line1/amp")
$TZ+cos($TY*ch("../line1/freq")) * ch("../line1/amp")

This works and you can see the helix on the left.

 

Then I merge in a Point Wrange and put the following code in place.

float x, z, freq, amp;

freq = ch("../line1/freq");
amp = ch("../line1/amp");
x = sin(freq)*amp;
z = cos(freq)*amp;
vector result = set(x,0,z);
@P += result;

This produces a straight line, however?

 

I guess I need a way to gain access to the $TY component of @P inside of VEX?

 

I tried this but get an error.

float x, z, freq, amp;

freq = ch("../line1/freq");
amp = ch("../line1/amp");
x = sin(@P.y*freq)*amp;
z = cos(@P.y*freq)*amp;
vector result = set(x,0,z);
@P += result;

How do I access other elements of a vector in VEX?

 

Hmm...I guess a pythonic attempt seems to work when reading from an attribute.

float x, z, freq, amp;

freq = ch("../line1/freq");
amp = ch("../line1/amp");
x = @P[0] + sin(radians(@P[1]*freq))*amp;
z = @P[2] + cos(radians(@P[1]*freq))*amp;
vector result = set(x,@P[1],z);
@P = result;

post-12295-0-52555500-1438458021_thumb.j

ap_VEX_based_helix.hipnc

Edited by Atom
Link to comment
Share on other sites

Now that I have the VEX code version working, it matches the Point node exactly.

When I middle click on the Point node I see that it takes 0.16ms to cook. The Wrangle takes 0.13ms to cook.

 

I was under the impression that VEX as much faster? These kinds of small gains seem marginal.

.

.

.

Ok, I upped the point count from 36 to 10,000 and the speed gains are more apparent.

With 10,000 points in my helix the Point node takes 30.22ms to calculate and the Wrangle node reports 0.12ms.

When I increase the point count to 60,000 the Point node reports 187.22ms and the Wrangle node reports 0.16ms.

 

That is a more significant speed gain. :)

Edited by Atom
Link to comment
Share on other sites

There's currently a largish overhead in VEX nodes to do the initial setup. Plus, they currently multi-thread on blocks of 1024 elements. So it's hard to see an improvement under 1024 items. Say you have 8 cores, then to really see the improvements, you need at least 8*1024=8192 items.

  • Like 1
Link to comment
Share on other sites

don't use MMB to measure speed, use Performance Monitor

 

MMB on wrangle will just show you time spent on Wrangle container itself, which is a subnet, if you dive inside you will see AttribVOP there, that's  the node that does the work, MMB on that and you should see bigger number

 

if you measure with Performance Monitor, you will get time as a sum of all the nested nodes, therefore you would see the real value that it took to execute

Link to comment
Share on other sites

Hey Atom,

 

Another way you could write it in vex which is similar to what you had is the point sop is:

float freq, amp;
vector pos = @P;

freq = chf("freq");
amp = chf("amp");

pos.x += sin(pos.y * freq) * amp;
pos.z += cos(pos.y * freq) * amp;

@P = pos;
  • Like 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...