Jump to content

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?!

Link to comment
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
Link to comment
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
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...