Jump to content

Point Wrangle inside foreach loop


spectronaut

Recommended Posts

I'll get right to it. I am running a foreach loop on a bunch of prims. 
For each prim I scatter a number of points. Still within the foreach loop, I run a point wrangle on those points. In the wrangle I run intersect on each of the points and if one hits I want to set an attribute on the prim (foreach loop peice) that the points were scattered on. In the end I don't need the scattered points, I just need the prims output with the attribute @keepage.
What I cant figure out is how to set up the forloop so that this works. 
 

Link to comment
Share on other sites

Obviously this loop will output points. The VEX for the wrangle "secondaryIntersect" seems valid, but I have no way of applying the attribute to the iteration pieces (primitives).

loopage.PNG

VEX for "secondaryIntersect" running over primitives.

vector p;
vector hitprimuvw;
vector srcpt;


i@ptrefprim = prim(2, "refprim", 0);
srcpt = v@P + (normalize(v@rdir)*2);
i@hitprim  = intersect(1, srcpt, v@rdir, p, hitprimuvw);

if(@hitprim<5){
setprimattrib(2, "keepage", 0, 1, "set");      
}

Link to comment
Share on other sites

Given what you currently have, you could make secondaryIntersect set a detail attribute on itself that marks whether or not an intersection happened. Then, disconnect the output of secondaryIntersect from the foreach_end. Drop an attribute create, linking foreach_begin -> secondaryIntersect -> foreach_end, and set the attribute create to look at the detail attribute that secondaryIntersect set, thus marking the current prim with whether or not the intersection happened.

Might not necessarily be the most computationally efficient way, but maybe the easiest thing to do given the current setup.

 

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...