Navigation


 Tutorials and Articles


 Go back to the forum

Computer Games Modelling and Animation   

Creating a Pyramid Function with Vex

Admin | Published on the mon 1 Jul 2019 - 13:21 | 1664 Views

Go to Object and press tab >geo and use the Geometry node - double click it and go inside.

Press tab and type att and find the AttribWrangle node. Click it and set it to detail.

Vector placePyramid (vector start)//function to place the pyramid at start vector
{
    vector pos1 = start + {0,0,0}; //create vectors in relation to start vector to position points
    vector pos2 = start +{-2,0,-2};
    vector pos3 = start + {-2,0,0};
    vector pos4 = start + {0,0,-2};
    
    int p1 = addpoint(0, pos1);//add points at the named pos vectors
    int p2 = addpoint(0, pos2);
    int p3 = addpoint(0, pos3);
    int p4 = addpoint(0, pos4);
    
    int prim1 = addprim(0, "poly"); //then add a primative
    
    addvertex(0, prim1, p4);// to add a primative (prim1) we need vertexes at the points
    addvertex(0, prim1, p2);
    addvertex(0, prim1, p3);
    addvertex(0, prim1, p1);// do this in a clockwise or anticw order to get the normal to face the right way
    
    vector pos = start + {-1,2,-1};
    int p = addpoint(0, pos);//point 4 (p) is the top of the pyramid
    
    int prim2 = addprim(0,"poly"); //add primatives for the sides of the pyramid
    addvertex(0,prim2,p);
    addvertex(0,prim2,p1);
    addvertex(0,prim2,p3);
    
    int prim3 = addprim(0,"poly");//another side
    addvertex(0,prim3,p);
    addvertex(0,prim3,p3);
    addvertex(0,prim3,p2);
    
    int prim4 = addprim(0,"poly");
    addvertex(0,prim4,p);
    addvertex(0,prim4,p2);
    addvertex(0,prim4,p4);
    
    int prim5 = addprim(0,"poly");
    addvertex(0,prim5,p);
    addvertex(0,prim5,p4);
    addvertex(0,prim5,p1);
    
    return pos; //return the value of the top
}
vector placePyramidToTheRight (vector start)// this is for moving the pyramid to the right and is 
\\another function just the same as the one above
{ vector pos1 = start + {0,0,0};//position in realtion to start vector vector pos2 = start +{-2,0,-2};//point1 vector pos3 = start + {-2,0,0};//point2 vector pos4 = start + {0,0,-2};//point3 int p1 = addpoint(0, pos1); int p2 = addpoint(0, pos2); int p3 = addpoint(0, pos3); int p4 = addpoint(0, pos4); int prim1 = addprim(0, "poly"); addvertex(0, prim1, p4); addvertex(0, prim1, p2); addvertex(0, prim1, p3); addvertex(0, prim1, p1); vector pos= start+ {-1,2,-1};//point 4 int p = addpoint(0, pos); int prim2 = addprim(0,"poly"); addvertex(0,prim2,p); addvertex(0,prim2,p1); addvertex(0,prim2,p3); int prim3 = addprim(0,"poly"); addvertex(0,prim3,p); addvertex(0,prim3,p3); addvertex(0,prim3,p2); int prim4 = addprim(0,"poly"); addvertex(0,prim4,p); addvertex(0,prim4,p2); addvertex(0,prim4,p4); int prim5 = addprim(0,"poly"); addvertex(0,prim5,p); addvertex(0,prim5,p4); addvertex(0,prim5,p1); return pos4; //this time return the value of the origin } /////////////Belwo we can run a few iterations over a loop of both funtions vector newPos = {0,0,0}; vector newPosRight = {0,0,0}; for (int i=0; i<5; i++) //for next loop called i to create an array of pyramids { newPosRight = placePyramidToTheRight(newPosRight);//replace the position with the new one newPos= newPosRight; for (int y=0; y<5; y++) // a loop within a loop called y { newPos = placePyramid(newPos);//replace position with the new one } }
void placePyramid (vector myArray[]; vector start)// slider array press button on side to generate sliders 
{
    vector pos1 = start + {0,0,0};
    vector pos2 = start +{-2,0,-2};
    vector pos3 = start + {-2,0,0};
    vector pos4 = start + {0,0,-2};
    
    int p1 = addpoint(0, pos1);
    int p2 = addpoint(0, pos2);
    int p3 = addpoint(0, pos3);
    int p4 = addpoint(0, pos4);
    
    int prim1 = addprim(0, "poly");
    
    addvertex(0, prim1, p4);
    addvertex(0, prim1, p2);
    addvertex(0, prim1, p3);
    addvertex(0, prim1, p1);
    
    vector pos= start+ {-1,2,-1};//point 4
    int p = addpoint(0, pos);
    
    int prim2 = addprim(0,"poly");
    addvertex(0,prim2,p);
    addvertex(0,prim2,p1);
    addvertex(0,prim2,p3);
    
    int prim3 = addprim(0,"poly");
    addvertex(0,prim3,p);
    addvertex(0,prim3,p3);
    addvertex(0,prim3,p2);
    
    int prim4 = addprim(0,"poly");
    addvertex(0,prim4,p);
    addvertex(0,prim4,p2);
    addvertex(0,prim4,p4);
    
    int prim5 = addprim(0,"poly");
    addvertex(0,prim5,p);
    addvertex(0,prim5,p4);
    addvertex(0,prim5,p1);
    myArray[0]=pos;
    myArray[1]=pos4;
   
}
vector placePyramidToTheRight (vector start)
{
    vector pos1 = start + {0,0,0};//position in realtion to start vector
    vector pos2 = start +{-2,0,-2};//point1
    vector pos3 = start + {-2,0,0};//point2
    vector pos4 = start + {0,0,-2};//point3
    
    int p1 = addpoint(0, pos1);
    int p2 = addpoint(0, pos2);
    int p3 = addpoint(0, pos3);
    int p4 = addpoint(0, pos4);
    
    int prim1 = addprim(0, "poly");
    
    addvertex(0, prim1, p4);
    addvertex(0, prim1, p2);
    addvertex(0, prim1, p3);
    addvertex(0, prim1, p1);
    
    vector pos= start+ {-1,2,-1};//point 4
    int p = addpoint(0, pos);
    
    int prim2 = addprim(0,"poly");
    addvertex(0,prim2,p);
    addvertex(0,prim2,p1);
    addvertex(0,prim2,p3);
    
    int prim3 = addprim(0,"poly");
    addvertex(0,prim3,p);
    addvertex(0,prim3,p3);
    addvertex(0,prim3,p2);
    
    int prim4 = addprim(0,"poly");
    addvertex(0,prim4,p);
    addvertex(0,prim4,p2);
    addvertex(0,prim4,p4);
    
    int prim5 = addprim(0,"poly");
    addvertex(0,prim5,p);
    addvertex(0,prim5,p4);
    addvertex(0,prim5,p1);
    
  
}
////////////

int loop1 = chi("loop1");
int loop2 = chi("loop2");//set sliders

vector myPositions[];

vector newPos = {0,0,0};
vector newPosRight = {0,0,0};

for (int i=0; i<loop1; i++)
{
    placePyramid(myPositions, newPosRight);
    
    newPos =myPositions[0];
    newPosRight =myPositions[1];
    
    for (int y=0; y<loop2; y++)
    {
       placePyramid(myPositions, newPos);
       newPos = myPositions[0];
    }
}

The above script adds more funtionality with the use of funtion arrays copied by reference and the use of sliders using chi command and then generated through thebutton at the sideof the vex box.

Use a fuse node to join the points that share the same space.

Next add a scatter >set the number of points to about 80

int closePTS[] = nearpoints(0, @P, 20);//create and integer named closePTS  and look at the points
//through channel 0, use the @p attribute to store their vector and look 20 units always //round
foreach (int pt; closePTS) // for each closePTS (each searched for point) set it in pt
{
    int connect = addprim(0, "polyline"); //create a polyline prim and store it in connect 

    addvertex(0, connect, @ptnum); //add a vertex for that point number looked at add the primative edges 
    addvertex(0, connect, pt); //add vertex at the search for points 
}


About the author