ShapeScript

Primitives

ShapeScript has a number of built-in shapes that you can use to quickly construct a scene. These are known as primitives, to distinguish them from more complex custom shapes that you can define using builders or CSG operations.

Cube

The cube primitive creates a box. You can create a cube just by using the cube command, which defines a cube with the default size of one unit:

cube

To alter the size of the cube, you can pass a block containing a size option followed by up to 3 values specifying the individual dimensions of the cube, or a single value to create a cube with equal sides.

cube { size 1 2 }

Box

You can also rotate and position the cube using the orientation and position options, as follows:

cube {
    size 1 1 2
    position 1 0 0
    orientation 0.25
}

The size, position and orientation options are common to all shapes. For more information about these (and other) options, see the options section.

Sphere

The sphere primitive creates a spherical ball. Again, size can be used to control the diameter. The following creates a sphere with a diameter of 1 unit (which is the default).

sphere { size 1 }

Sphere

You may notice that the sphere doesn’t look very smooth. As mentioned in the getting started section, 3D shapes in ShapeScript are made up of polygons, so curves cannot be represented exactly, only approximated.

You can improve the quality of the sphere by using the detail option:

sphere {
    detail 32
    size 1
}

Smoother sphere

You can also pass multiple parameters to size to create a spheroid:

sphere {
    detail 32
    size 1 2 3
}

Spheroid

Cylinder

The cylinder primitive creates a flat-ended cylinder.

cylinder { size 1 }

Cylinder

Like the sphere primitive, cylinder uses the detail command to control its smoothness. If you require a cylinder that is longer or shorter, you can pass a second parameter to the size to control the diameter and length independently:

cylinder {
    detail 64
    size 1 2
}

Cone

The cone primitive creates a conical shape:

cone { size 1 }

Cone

Like sphere and cylinder, its smoothness is controlled by the detail command, and the diameter and length can be controlled independently by passing additional parameters to size:

cone {
    detail 48
    size 1 2
}

Index | Next: Options