Jump to content

Infect code confusion


bonassus

Recommended Posts

I just followed a video tutorial found on the sideFX website titled  :Houdini Quicktip#03 - Infecting points using VEX & the solver SOP.

I I'm embarrassed to say i'm confused by the code snippet provided. The set up starts with scattered points and an attribute @infect = 1 added to one point. which by default gives all other points @infect = 0; Then an wrangle with this snippet is put in to a solver. 

 if(@infect == 0){
    int spnts[] = nearpoints(0,@P,1,5);
    foreach(int pt;spnts){
        if(point(0,"infect",pt) == 1){
          @infect = 1;
          @Cd = {1,0,0};
        }
    }
}

this code works. But i'm confused why it does. Allow me to walk through the code as i understand it. 

if the points @infect value is 0 which on frame one is all points except one. 

gather the 5 nearest points and append them to the array spnts[]

foreach of these 5 points with a @infect value of 0 check if its @infect attribute is equal to 1 and then set it to 1;

What confuses me, first is this code is only operating on points with @infect == 0 because of the first conditional check.

then the last conditional checks if @infect == 1 and if true sets it to 1. is't it already 1?

sorry for the confused and confusing question. obviously I am on the rails somewhere. It would be super helpful is someone wants to enlighten me as to where my mistake is. 

 

thanks.

B

 

 

 

 

Link to comment
Share on other sites

you are opening your point cloud around points that are infect=0. when you set @infect = 1 you are setting the attribute on the current wrangle point, not the foreach point.

you are looking around the current wrangle point for infected points so that you can become infected also

  • Like 1
Link to comment
Share on other sites

Oh. now it makes more sense. thank you. The first if statement through me off. I just tested the code with out it and is apears to work just as well. I don't know why it was included in the first place.

//if(@infect == 0){
    int spnts[] = nearpoints(0,@P,1,5);
    foreach(int pt;spnts){
        if(point(0,"infect",pt) == 1){
          @infect = 1;
          @Cd = {1,0,0};
        }
    }
//}

thank you! 

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