Jump to content
amin.khormaei

iterate over certain points

Recommended Posts

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.

Share this post


Link to post
Share on other sites

Hi,

You can do it using a detail wrangle:

int pts [ ] = array ( 1, 3, 4 );
foreach ( int pt; pts )
    setpointattrib ( 0, "P", pt, 1 );

 

Share this post


Link to post
Share on other sites
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

Share this post


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

Share this post


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

Share this post


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

Share this post


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

Share this post


Link to post
Share on other sites
14 minutes ago, animatrix said:

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

It's not correct. See attached file.

Screenshot_2020-09-15_18-53-53.png

vector(1) give a vector of (1,1,1)

Edited by fsimerey
  • Like 1

Share this post


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

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

×