Jump to content

Simple problem with vex, attribute array?


Recommended Posts

I'm stumped here.  Searched many threads with no joy.

Why can i create newpoints, created with addpoint and correctly place these new points in space, but not be able to store these points as an attribute array on their respective prims?


Create newpoints with addpoint() at positions a given mid distance along the half edges of all primitives .  This works fine.

I want to store the point numbers of these newpoints in an array and store that array as an attribute of the each prim.  ..This doesn't work.

Sounds simple enough but the code only repeats storing the newly created midpoints of the first prim only on all prims no matter what @primnum the wrangle is processing.


in code below, The other polycnrs array and hedgeloop array store the correct, unique point numbers, that belong to each unique prim.     

I am guessing I must be making some extremely basic error.  Really hope someone can set me straight.  Thanks in advance vex masters.


PS:    Hip file

Code snippet below :   works with input 1 or more prims.  example uses 2 (1 triangle, 1 pent). 


// test slightly more complicated example using half edges. 
// parameters ------------------
float ratio = chf("ratio");
int midpts[];
int polycnrs[];
// ------------------------------------------
//  get the first hedge of the primitive
int hedge = primhedge(0, @primnum);
// store initial value for loop below.
int start = hedge;
// TESTING -----  
i@hedgestart = start;
int hedgeloop[];

while(hedge != -1){
    int src = hedge_srcpoint(0, hedge);   // get sorce point number 
    int dst = hedge_dstpoint(0, hedge);  // get destination point number
    vector srcpos = point(0, "P", src);  //  get the src point postion
    vector dstpos = point(0, "P", dst);  // get dest postion

    vector diredge1 = dstpos - srcpos;  // dir vector from source to dest
    vector pos1 = srcpos + (diredge1 * ratio);  // point from 1 end
    vector pos2 = dstpos - (diredge1 * ratio); //  point from other end
    int pt1 = addpoint(0, pos1);
    int pt2 = addpoint(0, pos2);

    push(midpts, pt1);
    push(midpts, pt2);
    push(polycnrs, src);
    push(polycnrs, dst);
    // store the current hedge (just a data check)
    push(hedgeloop, hedge);  
    //------  update to the next hedge before looping again. 
    hedge = hedge_next(0, hedge);  

    if(hedge == start){   // break when get full circle. 

// write to attributes
i[]@hedgeloop = hedgeloop;   // WORKS
i[]@midpts = midpts;         // DOESNT WORK
i[]@polycnrs = polycnrs;     // WORKS



Edited by Benra
Link to comment
Share on other sites

Hi Ben,

Your code is fine. It's just that the point numbers returned by addpoint are not guaranteed to be the final point numbers:



A point number for the created point, or -1 if the point could not be created.

You can use the return value with setpointattrib to set attributes on the new point, however it may not be the final number of the point.

Link to comment
Share on other sites

Perfect ! 

Thanks so much Yunus.   ... (and mods, my apologies for posting in wrong area. )

Overnight i came to the same conclusion after much further head scratching.  After remembering that Houdini effectively multithreads the calculation of the wrangle across all prims simultaneously and given that it was ending up writing the same pt numbers to the array starting at the same next available number each time it ran.  I figured that in each one of those threads Houdini was performing the process independent of the others... effectively it then would write those very same pt numbers to those arrays. giving me endless copies starting from the same pt nums.

I guess the wrangle must work like this and then after all is said and done it must then reorder all new points giving them their final point numbers.    

I'm needing to keep track of what primid these newpoints originated from for another wrangle downstream ...

i solved the issue by creating an attribute on the points as they are made then using that attribute post wrangle to refer back to the pt nums they finally get assigned.


Side note.. I'm wondering if the wrangle node could use a tab which could allow for attribute assignment  post processing of any newly created  pt nums .  before final exit. 

Not sure how that would work but something like a tab similar to attribute create.  Maybe thats an over complication to an otherwise clean node for a case that might not occur often. 

anyway thanks again!.


for the 2c it might be worth for anyone , updated hip with my solve.   Wish there was a more elegant solution. 





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.

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