Jump to content

trouble looping through arrays in VEX


jkunz07

Recommended Posts

Hey, I'm probably doing something terribly wrong here - but I'm not sure why this code acts as if it's only operating over a single primitive instead of all of them.

 

I have a attribwrangle set to 'primitives' mode with the following code:

float target_upos = chf('point_uu');

int spline_pt_list[] = primpoints(0, @primnum);

int closest_ptnum = -1;
float dist = 1;
vector found_uv = set(0,0,0);

foreach(int i; spline_pt_list)  {
    found_uv = point(0, "uv", spline_pt_list[i]);
    if( abs(target_upos - found_uv.x) < dist )  {
        dist = target_upos - found_uv.x;
        closest_ptnum = i;
    }
}

vector new_pt_pos = point(0, "P", closest_ptnum);
int new_pt = addpoint(geoself(), new_pt_pos);

addattrib(geoself(), "point", "pt_list", primpoints(0, @primnum) );
setattrib(geoself(), "point", "pt_list", new_pt, 0, spline_pt_list, "set");

removeprim(geoself(), @primnum, 1);
int new_prim = addprim(geoself(), "polyline");


However when the 'point_uu' slider is adjusted, only one point changes position?

 

My file is attached:primpoints_test.hip

 

Thanks!

Link to comment
Share on other sites

sorry, I've found the error in my code:

foreach(int i; spline_pt_list)  {
    found_uv = point(0, "uv", spline_pt_list[i]);
    if( abs(target_upos - found_uv.x) < dist )  {
        dist = target_upos - found_uv.x;
        closest_ptnum = i;
    }
}

becomes:

foreach(int i; spline_pt_list)  {
    found_uv = point(0, "uv", i);
    if( abs(target_upos - found_uv.x) < dist )  {
        dist = target_upos - found_uv.x;
        closest_ptnum = i;
    }
}

and it works as expected for me now.

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...