Jump to content
Sign in to follow this  
spectronaut

Point Wrangle inside foreach loop

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. 
 

Share this post


Link to post
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");      
}

Share this post


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

 

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
Sign in to follow this  

×