Jump to content
TomRaynor

Accessing $YSIZE in attribwrangle

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

Share this post


Link to post
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

Share this post


Link to post
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?

Share this post


Link to post
Share on other sites

You can loop through the points of each primitive and calculate it manually. Check out geometry traversing functions.

  • Like 1

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

That is right on the money! Exactly what I needed, cheers Tomas.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×