Cubes and cylinders

■ The Cube command

The Cube command in B3D and CSV objects is equivalent to a series of Vertex/AddVertex and Face/AddFace commands.

Given the following code (B3D style):

Cube x, y, z

The Cube command corresponds to these instructions (B3D style):

Vertex x, y, -z
Vertex x, -y, -z
Vertex -x, -y, -z
Vertex -x, y, -z
Vertex x, y, z
Vertex x, -y, z
Vertex -x, -y, z
Vertex -x, y, z
Face v+0, v+1, v+2, v+3
Face v+0, v+4, v+5, v+1
Face v+0, v+3, v+7, v+4
Face v+6, v+5, v+4, v+7
Face v+6, v+7, v+3, v+2
Face v+6, v+2, v+1, v+5

where v is the number of vertices that have already been created before the Cube command was used.

If you want to texture the cube, you need to add appropriate Coordinate/SetTextureCoordinate commands manually.

■ The Cylinder command

The Cylinder command in B3D and CSV objects is equivalent to a series of Vertex/AddVertex and Face/AddFace commands.

Given the following code (B3D style):

Cylinder n, r1, r2, h

The Cylinder command first corresponds to n pairs of two vertex instructions (B3D style):

Vertex cos[2*pi*0/n]*r1, h/2, sin[2*pi*0/n]*r1
Vertex cos[2*pi*0/n]*r2, -h/2, sin[2*pi*0/n]*r2
Vertex cos[2*pi*1/n]*r1, h/2, sin[2*pi*1/n]*r1
Vertex cos[2*pi*1/n]*r2, -h/2, sin[2*pi*1/n]*r2
Vertex cos[2*pi*2/n]*r1, h/2, sin[2*pi*2/n]*r1
Vertex cos[2*pi*2/n]*r2, -h/2, sin[2*pi*2/n]*r2

Vertex cos[2*pi*(n-1)/n]*r1, h/2, sin[2*pi*(n-1)/n]*r1
Vertex cos[2*pi*(n-1)/n]*r2, -h/2, sin[2*pi*(n-1)/n]*r2

Then, n faces are added to form the side walls (B3D style):

Face 2, 3, 1, 0
Face 4, 5, 3, 2
Face 6, 7, 5, 4
Face 8, 9, 7, 6

Face 2*n-6, 2*n-5, 2*n-7, 2*n-8
Face 2*n-4, 2*n-3, 2*n-5, 2*n-6
Face 2*n-2, 2*n-1, 2*n-3, 2*n-4
Face 0,     1,      2*n-1, 2*n-2

If r2>0, a lower cap is then added (B3D style):

Face 2*n-2, 2*n-4, 2*n-6, …, 4, 2, 0

If r1>0, an upper cap is then added (B3D style):

Face 1, 3, 5, …, 2*n-5, 2*n-3, 2*n-1

If you want to texture the cylinder, you need to add appropriate Coordinate/SetTextureCoordinate commands manually.