This package contains the Shape class that underlies everything else, and its composite, MultiShape, along with several factory functions to instantiate these classes, such as Cube. It also contains some algorithms for modifying existing shape instances.
Factory functions that return a single Shape instance in shapes similar to or derived from a cube
Return a new Shape, shaped like a cube. One of the platonic solids. Vertices are positioned at radius from the center, meaning the cube edges are sqrt(3*radius^2).
colors may be either an instance of Color, or a sequence of colors, one for each face.
Return a new Shape, cuboid of dimensions x, y, z, centered on the origin.
colors may be either an instance of Color, or a sequence of colors, one for each face.
Return a new Shape, an space-station from the vintage computer game Elite, a truncated cube with an extra black face for the entrance.
Return a new Shape, a cube with the corners cut off.
truncation varies from 0.0 (a regular cube) to 1.0 (cut off corners start to meet each other at the midpoint of each edge.)
color1’ is for the cube faces. `color2 is for the exposed corners.
Factory functions that return a single MultiShape instance formed by composing several cubes
Return a new Shape, consisting of a single, large cube, and eight smaller ones at each of its corners.
Return a new Shape, consisting of a single large cube, and six smaller ones sticking out of each of its faces.
Return a new Shape consisting of a random glob of cubes arranged in a spherical shell.
Return a new Shape consisting of a random array of cubes arranged within a large cube-shaped volume. The small cubes are colored by their position in RGB space.
edge: the edge of a small cube
cluster_edge: the edge of the large volume
cube_count: the number of cubes to generate within the volume
Modify the given shape in-place, by extruding the specified faces by offset.
faces is an iterable of integer face indices upon which to operate. If omitted, it defaults to all faces.
Doesn’t work on Multishapes. This should get fixed in a future release.
Bases: object
A composite of multiple Shapes. This allows many shapes to be stuck together and converted into a single Glyph, which means they are rendered as a single call to glDrawElements.
This Multishape provides attributes that make it accessible like a normal shape:
vertices: a sequence of all the vertices in all the child shapes, each one offset and oriented by that child shape’s position and orientation.
faces: a collection of all the Face instances of all the child shapes.
Modifies the given shape in-place, by normalizing the position of every vertex to lie at length distance from the center. This squishes the shape to make it roughly spherical.
If the shape contains edges which have one face on one side, but more than one face on the other side, then normalizing will result in ugly split seams, through which the interior of the object will be visible.
Doesn’t work on Multishapes. This should get fixed in a future release.
Bases: object
A single flat face that forms part of a Shape. Attributes are the params to the constructor below, plus:
normal: A Vector, perpendicular to the face
indices: a list of int indices into the parent shape’s vertex list
color: an instance of Color
shape: a reference to the parent Shape
Bases: object
Defines a polyhedron, a 3D shape with flat faces and straight edges.
vertices: a list of Vector points in 3D space, relative to the shape’s center point.
faces: a list of faces, where each face is a list of integer indices into the vertices list. The referenced vertices of a single face must form a coplanar ring defining the face’s edges. Duplicate indices do not have to be given at the start and end of each face, the closed loop is implied.
colors: a single Color which is applied to every face, or a sequence of colors, one for each face.
name: the ‘source’ attribute to be applied to each face.
See the source for factory functions like Cube() for examples of constructing Shapes.
Modifies vertices in-place by appending the given new_vert. Returns the index number of the new vertex.
Loads of Shape-modifying algorithms seem to need this function. Can’t make it a method because they often haven’t constructed the shape instance yet.
Modify the given shape in-place. By ‘stellate’ I mean add a new vertex in the middle of the face, raised by ‘height’ out of the plane of the face, and replace the original face by an n-sided pyramid connecting this new vertex to each edge of the original face’s edges.
This isn’t strictly ‘stellation’ as it is technically defined, but is instead a more flexible superset of operations that includes stellation.
By default, all faces are opertated on, but this can be overidden by specifying ‘faces’ as an iterable of integer face indices.
Modify the given shape in-place. Subdivides each of its faces into new, smaller faces, by cutting off the corners:
v0
/\
/ \
mid[0]/----\mid[2]
/ \ / \
/___\/___\
v1 mid[1] v2
By default, all faces are operated on, but this can be overidden by specifying ‘faces’ as an iterable of integer face indices.
Modify the given shape in-place. Subdivides the single face at position face_index.
edges should be a dictionary, which starts empty, but is filled by subdivide face for it’s own internal bookkeeping. Pass in the same dict object for every call to subdivide_face on the same shape. See subdivide for an example of this.