What's in a Shape.

Sub-parts

Every shape in this library is made up of 1 or more sub-parts. For instance the Box has six sides each one is a sub-part, a tube has three, the main body and two end-caps. Each sub-part has its own visual attributes which are used when rendering, it is also possible to control the visibility of each sub-part.

Each sub-part has two values to identify it

  • part no - part numbers start at zero and increment by 1 for each part, so the box has six parts numbered 0-5 inclusive. This identifier is rarely used except when shape picking.
  • bit-flag - each part has a named bit flag (i.e. an integer with just one bit set) which allows us to combine sub-parts when modifying the appearance of the shapes.
Shape Sub-part
Description Number Named bit-flag
Box Bottom face
Top face
Front face
Back face
Left face
Right face
0
1
2
3
4
5
S3D.BOTTOM
S3D.TOP
S3D.FRONT
S3D.BACK
S3D.LEFT
S3D.RIGHT
DoubleCone Top
Bottom
0
1
S3D.BOTTOM
S3D.TOP
Ellipsoid Curved surface 0 S3D.BODY
Extrusion Surface along length
Cap at start
Cap at other end
0
1
2
S3D.BODY
S3D.END0
S3D.END1
Tube Surface along length
Cap at start
Cap at other end
0
1
2
S3D.BODY
S3D.END0
S3D.END1
LatheStock Lathed (rotated) surface
Cap at start
Cap at other end
0
1
2
S3D.BODY
S3D.END0
S3D.END1

Using bit flags is really useful when applying attributes to our shape for instance the code

tube.fill(color(255,255,0), S3D.END0 | S3D.END1);

sets the fill colour for both end-caps in one statement.

There is one more constant you should be aware of, S3D.ALL which matches all sub-parts, so the statement

shape.fill(color(255,0,255), S3D.ALL);

sets the fill colour for the entire shape in one statement.

More on drawing attributes in the next guide but one last example for those familiar with bit operations. The following 2 statements

box.fill(color(200), S3D.BOTTOM | S3D.TOP | S3D.LEFT | S3D.RIGHT | S3D.BACK);
// and
box.fill(color(200), S3D.ALL ^ S3D.FRONT); 

both set the fill colour for all faces except the front face.