Jump to content
localstarlight

Getting centre of primitive in Foreach?

Recommended Posts

I'm feeding a grid of primitives into a Foreach subnetwork, and I want to be able to place something (in this case move the centre of a bounding sphere for group definition) at the centre of each primitive. I feel like this should be simple, but I cannot figure out how to do it.

Straight after the 'each1' node, I added an attribute wrangle which adds the centroid of the primitive as a detail attribute like this:

v@centroid = prim(geoself(),"P",0);

But then in the group node further down, I am trying to access this attribute for each of the X,Y and Z values of the Bounding -> Center channels, but cannot figure out how to access each of the X,Y and Z values of the attribute separately. I am trying to use this expression:

detail("../attribwrangle3/","centroid",0)

But it obviously only gives me the X value from the vector. I have tried:

detail("../attribwrangle3/","centroid.x",0)
detail("../attribwrangle3/","centroid[0]",0)
detail("../attribwrangle3/","centroid",0).x

...and various other ways to access the different parts of the vector, but nothing seems to work and I can't find anything in the docs (or on the forums) about how this should be done.

Or maybe I am going about this totally the wrong way in the first place?!

Share this post


Link to post
Share on other sites

At first, try just @-syntax, it might work in your case. If not, fallback to the expression function, but call it properly. The last number in detail expression function used to get the component of vector.

# From first input, using @-syntax.
@centroid.x
@centroid.y
@centroid.z

# From any node, using index numbers.
detail("../attribwrangle3/", "centroid", 0)
detail("../attribwrangle3/", "centroid", 1)
detail("../attribwrangle3/", "centroid", 2)

# From any node, using enum-style constants.
detail("../attribwrangle3/", "centroid", D_X)
detail("../attribwrangle3/", "centroid", D_Y)
detail("../attribwrangle3/", "centroid", D_Z)

 

  • Like 1

Share this post


Link to post
Share on other sites
vector v = detail("../attribwrangle3/","centroid",0)

Gives me exact the vector which was added to the detail.

 

Sorry, didn't read the question correctly, you are talking about expressions not vex.

 

 

Edited by haggi
error

Share this post


Link to post
Share on other sites

detail("../attribwrangle3", "centroid", 0) for x component

detail("../attribwrangle3", "centroid", 1) for y component

detail("../attribwrangle3", "centroid", 2) for z component

  • Like 1

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

×