Select Point A, select another point, PontB above Point A. If no point found, select another PointA and repeat

   2041   2   0
User Avatar
Member
4 posts
Joined: April 2015
Offline
Hi there, what i´m trying to accomplish is to generate random pattern of different sizes for a corridor.

Let´s say, i have a grid.
I generate a point in the center of every primitive.

After that, i want to select a random PointA and imidiatly select another PointB wich is above PointA.
If there is no PointB above PointA then search for another random PointA and try again.

What i tried:

int pts[];
float seed;
@rand;

/////////////////////

pts = expandpointgroup(0, "*");
pos = point(0, "P", @ptnum);
seed = ch("seed");
@rand = floor(rand(seed)*@numpt);

//////////////////////

//s@pointName = "pointA";
@p0 = @ptnum;
@p1 = @ptnum+1;
@selected = 0;

////////////////////////
// for loop

for(int i=0; i <= len(pts); i++) {
    if(@p0 == @rand) {
        //setpointattrib(0, "selected", @rand, 1);
        i@selected = 1;  
        s@pointName = "pointA";
    } 
    else if(@p1 == @rand) {
        i@selected = 1;
        s@pointName = "pointB";
    } else {
        i@selected = 0;
        s@pointName = "none";
    }
}


//////////////
// foreach


// foreach(int pt; pts) {
//     if(@p0 == rand) {
//         @selected = 1;  
//         s@pointName = "pointA";
//     } else if(@p1 == rand) {
//         @selected = 1;
//         s@pointName = "pointB";
//     }
// }


///////////////////
// if (first approach

// if(@p0 == rand) {
//     @selected = 1;
// }else {
//     @selected = 0;
// }

@pts = len(pts);

//////////////////////
//  out messages

// printf("Length %d", len(pts));
// printf("Rand %d", rand);
// printf("CurrentP %d", @p0);
// printf("Test %d", rand); 

All the things that are commented out where my first approaches, nothing of them worked.
My Wrangle Node runs over points, but letting it run over Detail didn´t work either.

I also tried to pts instead of @p0 into the foreach loopm but this does set teh @selected attribute to 1 on every point and not just in a single point.

I am very new to coding at all and i´m a bit stuck on this.

It seems that i misunderstand loops in Houdini in general.

If possible, please send me the longer way and easier to understand first so i can figure out what is happening, again, i am very new to coding and maybe i don´t understand everything at first, but i´ll try

Thanks a lot for every answer from you guys!!!
User Avatar
Member
4 posts
Joined: April 2015
Offline
I´ve talked to a programmer who´s not familiar with houdini but with C. He gave me a possible solution.

My question here is, is it nessecary that i have to create a random algorythm for this particluar thing or is there an even better / easier approach?

Here´s what he made for me:

int pts[];
vector posi[];
int takenPositions[];
int height;
vector pos;
float seed;
int findTopPoint;

@rand;

/////////////////////

pts = expandpointgroup(0, "*");
pos = point(0, "P", @ptnum);
height = chi("height")-1;
findTopPoint = 0;


// random algorythm
seed = ch("seed");
@rand = floor(rand(seed)*@numpt);
if(@ptnum > 10){
    while(@rand < @ptnum && find(takenPositions, @rand)<0){
     
         push(takenPositions, @rand);
         seed +=1;
         @rand = floor(rand(seed)*@numpt);
    }
}
if(@ptnum == @rand){
    findTopPoint = 1;
}


// select point > y
float range = 0.001;
if(findTopPoint == 1){
    foreach(int pt; pts) {
        vector currentPos = point(0,"P", pt);
        if(
        currentPos.x <= @P.x + range && 
        currentPos.x >= @P.x - range &&
        currentPos.z <= @P.z + range &&
        currentPos.z >= @P.z - range &&
        currentPos.y > @P.y &&
        point(0,"selected", @ptnum) != 1
        ) {
            setpointattrib(0, "selected", pt, 1, "set");
            @selected = 1;
            height--;
            if(height<=0){
            break;
            }
        }
    }
}

I know this is not the best solution but it works and i have to figure out whatßs going on here and honestly, i also have to figure out how i can approach this, cause, like i said, i´m very new to coding, but i´m happy that i have something to work with
Still wondering if it´s the correct way doing it, thought there would be a nicer / easier solution
User Avatar
Member
4 posts
Joined: April 2015
Offline
no one can help me out with this?
  • Quick Links