Question : for each primitive in vex

   341   4   0
User Avatar
Member
7 posts
Joined: May 2018
Offline
Hi, I'm currently learning houdini vex, but I can't understand how to write ForeachLoop in vex. i simply want to run " i@get = @ptnum" in each primitive but don't want to use foreach node just for the simple line. Would be nice if some one tell me how to do this in ves. thanks!

Attachments:
Capture.JPG (175.8 KB)

User Avatar
Member
7814 posts
Joined: Sept. 2011
Offline
I'm not sure what you're after, but you don't need a for each loop block in sops just to enumerate primitives in VEX. On the wrangle, change the run over to primitive, and @primnum will be the number of the current primitive. The for each loop block is only needed for isolating parts of the geometry and running a set of nodes over each isolated part.
User Avatar
Member
7 posts
Joined: May 2018
Offline
Hi I simply want to have the same pointNumber between distant primitives. so I used foreach node to run the wrangle to get the same numver between them but I feel this is not smart way so would like to do the same thing just in vex.
User Avatar
Member
8599 posts
Joined: July 2007
Offline
if your primitives are all separate you can do this in Point Wrangle
i@get = vertexprimindex(0, @vtxnum);

if any of the points is shared among multiple primitives it will get the vertex index value from first connected primitive
Edited by tamte - May 5, 2024 20:21:26
Tomas Slancik
FX Supervisor
Method Studios, NY
User Avatar
Member
4531 posts
Joined: Feb. 2012
Offline
A-kun
Hi I simply want to have the same pointNumber between distant primitives. so I used foreach node to run the wrangle to get the same numver between them but I feel this is not smart way so would like to do the same thing just in vex.

If you mean to get the same point indices between different prims, you can just create a new points array for each prim like so:

int indices [ ] = array ( );
int pts [ ] = primpoints ( 0, @primnum );

foreach ( int index; int pt; pts )
    append ( indices, index );
    
i[]@indices = indices;

Senior FX TD @ Industrial Light & Magic
Get to the NEXT level in Houdini & VEX with Pragmatic VEX! [www.pragmatic-vfx.com]

youtube.com/@pragmaticvfx | patreon.com/animatrix | pragmaticvfx.gumroad.com
  • Quick Links