Jump to content

Accessing $YSIZE in attribwrangle


TomRaynor

Recommended Posts

Hi,

 

What I am trying to do is use an attribwrangle set to loop over primitives to work out the y-size of each primitive on my geometry and store that as a primitive attribute.

 

I am trying to do it using an attribwrangle rather than using a foreach node looping over primitives and using the bbox() expression for speed purposes.

 

Where I am stuck is working out the what to use instead of bbox in my attribwrangle that will give me the y-size of each primitive...

Can anyone ofer up any suggestions? (with a snippet of example code preferably)

 

Thanks very much

Link to comment
Share on other sites

Here are 2 solutions but I can't really say they are efficient. It might still be useful for you before anybody gives a better input.

 

First one is the easy trick to edit the parameter interface of your attribWrangle and add a float parameter.

You can now type hscript in this and access the value via ch("parmname") in your VEX.

Quick, efficient but I've no idea of the actual cost of calling an hscript function before using VEX.

 

Second is probably not a good idea as it loops through all the points and annihilate any multi threading or clever computer things I'm not able to explain but here it is :

float posx[] = array(); // array that will store positions

for(int i=0; i<@numpt; i++) {
    // fill the array with X coords
    vector _tmp = point(0, "P", i);
    push(posx, _tmp[0]);
}

posx = sort(posx);  // sort the array
int msize = len(posx);  // get size of array


// addition of first and last elements of the array
// --> min and max values on X axis
@xsize = abs(posx[0]) + abs(posx[msize-1]);

Edit : completely misread your question sorry...

This will give the XSIZE of the whole object. But same code can probably be adapted to loop through all points from a giver primitive.

Edited by iamyog
  • Like 1
Link to comment
Share on other sites

Well thought was to do something like use the attribwrangle to run over each primitive, and for each of the points in each primitive, find the minimum and maximum P.y values (and hence the range). I guess I would have to store these point positions in an array for each primitive...

 

Stil, I'm hoping that someone is going to pipe up and tell me that I can run a nice vex function to access the bbox information PER PRIMITIVE.

 

What about primitive intrinsic attributes? Do they help me and if so how can I access them?

Link to comment
Share on other sites

...

 

What about primitive intrinsic attributes? Do they help me and if so how can I access them?

you are on the right path

here is the code (PrimitiveWrangle):

float bbox[] = primintrinsic(0, "bounds", @primnum);
f@ysize = bbox[3]-bbox[2];

you can as well use getbbox() to get bbox of a group, so even per prim (though much slower than the former)

vector bbmin, bbmax;
getbbox(0, itoa(@primnum), bbmin, bbmax);
f@ysize = bbmax.y-bbmin.y;
Edited by anim
  • Like 2
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...