Jump to content

iterate over certain points


amin.khormaei

Recommended Posts

int pts [ ] = array ( 1, 3, 4 );
foreach ( int pt; pts ) {
      vector _P = {0,1,0}; // Create a vector
      setpointattrib ( 0, "P", pt, _P ); // Here all points would get the same position : _P -> (0,1,0)
    }

{} are missing, and attrib P is a vector, so you must put a vector and not a single integer.

In your case, if you want only change P.y on those points:

int pts [ ] = array ( 1, 3, 4 );
foreach ( int pt; pts ) {
      vector _P = point(0, "P", pt); // Get P attribute of point pt
      _P.y = 1.0;
      setpointattrib ( 0, "P", pt, _P );
    }

 

Edited by fsimerey
  • Like 1
Link to comment
Share on other sites

3 hours ago, amin.khormaei said:

I have this code below:


i[]@TP = neighbours(0,0);
foreach(int i ; @TP)
{
    @P.y = 1;
}

how can I tell Houdini to just move the points insideTP array?

foreach move all the points.

Try this:

i[]@TP = neighbours(0,0);
foreach(int i ; @TP)
{
    if(i == @ptnum) @P.y = 1;
}

 

  • Like 1
Link to comment
Share on other sites

3 hours ago, amin.khormaei said:

your code doesn't work

I tried it before posting, it works fine. Can you post what error are you seeing?

3 hours ago, fsimerey said:

int pts [ ] = array ( 1, 3, 4 );
foreach ( int pt; pts ) {
      vector _P = {0,1,0}; // Create a vector
      setpointattrib ( 0, "P", pt, _P ); // Here all points would get the same position : _P -> (0,1,0)
    }

{} are missing, and attrib P is a vector, so you must put a vector and not a single integer.

In your case, if you want only change P.y on those points:


int pts [ ] = array ( 1, 3, 4 );
foreach ( int pt; pts ) {
      vector _P = point(0, "P", pt); // Get P attribute of point pt
      _P.y = 1.0;
      setpointattrib ( 0, "P", pt, _P );
    }

 

1. {} is not needed in my code. Look here for similar C style syntax rules: http://www.cplusplus.com/forum/beginner/180452

2. You don't need to provide a vector type. VEX will automatically cast 0 into a vector.

Link to comment
Share on other sites

4 hours ago, amin.khormaei said:

I have this code below:


i[]@TP = neighbours(0,0);
foreach(int i ; @TP)
{
    @P.y = 1;
}

how can I tell Houdini to just move the points insideTP array?

foreach move all the points.

 

10 minutes ago, animatrix said:

2. You don't need to provide a vector type. VEX will automatically cast 0 into a vector.

In the case of Amin, he seems want to move in Y axis. In your example the 1 give a vector (1,0,0), so moving along X axis AND ALL points are at the same position (1,0,0)...

Good to know for C style syntax ;)

Edited by fsimerey
  • Like 1
Link to comment
Share on other sites

13 minutes ago, fsimerey said:

 

In the case of Amin, he seems want to move in Y axis. In your example the 1 give a vector (1,0,0), so moving along X axis AND ALL points are at the same position (1,0,0)...

Good to know for C style syntax ;)

No, 1 will become (1,1,1).

I just posted an example. He should be able to adapt it to his needs.

  • Like 1
Link to comment
Share on other sites

3 hours ago, amin.khormaei said:

thank you for all answers. the simplest way was:


i[]@pts = neighbours(0,0);
foreach(int i ; @pts)
{
    if(i == @ptnum)
    {
        @P.y = 1;
    }
}

 

if your array is not varying per point (at least from your example) and you still want to use Point wrangle instead of detail you can simplify your code further to 

int pts[] = neighbours(0,0);
if(find(pts, @ptnum) >= 0) {
        @P.y = 1;
}

or @P.y += 1; if you want to offset them instead of hardcode to 1

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