Help with python to vex

   3457   2   1
User Avatar
Member
93 posts
Joined: March 2014
Offline
Hi.

I did a simple asset which can calculate curve length for every point. I did the last node with python as i know only python. Could you help me to transfer it to vex/vop, please?

Thank you a lot. I attached my hip file with unlocked otl.

Attachments:
temp.hiplc (79.6 KB)

User Avatar
Member
8555 posts
Joined: July 2007
Offline
well if you just have such simple case with one input curve with ordered points, then you can use code like this to replace both your VOP and Python nodes:
// Detail Wrangle
// works only when the input geometry is one curve with sorted points
// so pretty much limited use
addpointattrib(0, “cur_length”, 0.0);
vector P=0;
vector prevP=0;
float length=0;
for (int pt=0;pt<@numpt;pt++)
{
P = point(0, “P”, pt);
if (pt!=0)
{
length += distance(prevP, P);
setpointattrib(0, “cur_length”, pt, length );
}
prevP = P;
}

However if you want to have something robust, you better count with possibility of multiple input curves with random point order, with possibly shared points and in that case you can do this and store your attrib as vertex attrib:
// Primitive Wrangle
// works on geometry with multiple curves and unordered point numbers
// storesresult as vertexattrib so curves can share points
int vtxs = primvertices(0, @primnum);
addvertexattrib(0, “cur_length”, 0.0);
vector P=0;
vector prevP=0;
float length = 0;
foreach(int idx;int vtx;vtxs)
{
int pt = vertexpoint(0, vtx);
P = point(0, “P”, pt);
if (idx!=0)
{
length += distance(prevP, P);
setvertexattrib(0, “cur_length”, -1, vtx, length );
}
prevP = P;
}
then if you need point attrib you can promote it, however shared points will have incorrect value

if you however know you don't have any shared points and want to have point attrib then you can do it directly as well:
// Primitive Wrangle
// works on geometry with multiple curves and unordered point numbers
// they can't share points though
int vtxs = primvertices(0, @primnum);
addpointattrib(0, “cur_length”, 0.0);
vector P=0;
vector prevP=0;
float length = 0;
foreach(int idx;int vtx;vtxs)
{
int pt = vertexpoint(0, vtx);
P = point(0, “P”, pt);
if (idx!=0)
{
length += distance(prevP, P);
setpointattrib(0, “cur_length”, pt, length );
}
prevP = P;
}
Tomas Slancik
FX Supervisor
Method Studios, NY
User Avatar
Member
93 posts
Joined: March 2014
Offline
Thank you a lot!
You are my hero!
I used first your code!!

Thanks you!!!!!!!!!!!!!!!!!!!!
  • Quick Links