Vertices

Custom 3D shapes are drawn using the beginShape() and endShape() functions. Within those two functions are several calls to vertex(), which in 3D space, takes 3 arguments: an x, y, and z. The code below will draw a four-sided pyramid made up of four triangles, all connected to one point (the apex) and a flat plane (the base).
void setup() {
  size(100, 100, P3D);
}

void draw() {
  background(100);
  lights();
  stroke(0);
  fill(255);
  translate(width/2, height/2, 0);
  rotateX(map(mouseY, 0, height, 0, PI/2));
  scale(map(mouseX, 0, width, 10, 40));
  beginShape();
  //bottom triangle
  vertex(-1, -1, -1);
  vertex( 1, -1, -1);
  //apex
  vertex( 0, 0, 1);
  
  //right triangle
  vertex( 1, -1, -1);
  vertex( 1, 1, -1);
  //apex
  vertex( 0, 0, 1);
  
  //top triangle
  vertex( 1, 1, -1);
  vertex(-1, 1, -1);
  //apex
  vertex( 0, 0, 1);

  //left triangle
  vertex(-1, 1, -1);
  vertex(-1, -1, -1);
  //apex
  vertex( 0, 0, 1);
  endShape();
}
applet

The beginShape() function begins recording vertices for a shape and endShape() stops recording them.

beginShape() has a few modes: To understand how the modes work:


Dan Wilcox 2007