primitives

Various functions to make simple primitives

Methods

(static) create3DFVertices() → {Object.<string, TypedArray>}

Creates 3D 'F' vertices.
An 'F' is useful because you can easily tell which way it is oriented.
The created 'F' has position, normal and uv streams.

Returns:
Type:
Object.<string, TypedArray>

The
created plane vertices.

(static) createCubeVertices(size) → {Object.<string, TypedArray>}

Creates the vertices and indices for a cube. The
cube will be created around the origin. (-size / 2, size / 2)

Parameters:
Name Type Description
size number

Width, height and depth of the cube.

Returns:
Type:
Object.<string, TypedArray>

The
created plane vertices.

(static) createPlaneVertices(widthopt, depthopt, subdivisionsWidthopt, subdivisionsDepthopt, matrixopt) → {Object.<string, TypedArray>}

Creates XZ plane vertices.
The created plane has position, normal and uv streams.

Parameters:
Name Type Attributes Description
width number <optional>

Width of the plane. Default = 1

depth number <optional>

Depth of the plane. Default = 1

subdivisionsWidth number <optional>

Number of steps across the plane. Default = 1

subdivisionsDepth number <optional>

Number of steps down the plane. Default = 1

matrix Matrix4 <optional>

A matrix by which to multiply all the vertices.

Returns:
Type:
Object.<string, TypedArray>

The
created plane vertices.

(static) createSphereVertices(radius, subdivisionsAxis, subdivisionsHeight, opt_startLatitudeInRadiansopt, opt_endLatitudeInRadiansopt, opt_startLongitudeInRadiansopt, opt_endLongitudeInRadiansopt) → {Object.<string, TypedArray>}

Creates sphere vertices.
The created sphere has position, normal and uv streams.

Parameters:
Name Type Attributes Description
radius number

radius of the sphere.

subdivisionsAxis number

number of steps around the sphere.

subdivisionsHeight number

number of vertically on the sphere.

opt_startLatitudeInRadians number <optional>

where to start the
top of the sphere. Default = 0.

opt_endLatitudeInRadians number <optional>

Where to end the
bottom of the sphere. Default = Math.PI.

opt_startLongitudeInRadians number <optional>

where to start
wrapping the sphere. Default = 0.

opt_endLongitudeInRadians number <optional>

where to end
wrapping the sphere. Default = 2 * Math.PI.

Returns:
Type:
Object.<string, TypedArray>

The
created plane vertices.

(static) createTruncatedConeVertices(bottomRadius, topRadius, height, radialSubdivisions, verticalSubdivisions, opt_topCapopt, opt_bottomCapopt) → {Object.<string, TypedArray>}

Creates vertices for a truncated cone, which is like a cylinder
except that it has different top and bottom radii. A truncated cone
can also be used to create cylinders and regular cones. The
truncated cone will be created centered about the origin, with the
y axis as its vertical axis. The created cone has position, normal
and uv streams.

Parameters:
Name Type Attributes Description
bottomRadius number

Bottom radius of truncated cone.

topRadius number

Top radius of truncated cone.

height number

Height of truncated cone.

radialSubdivisions number

The number of subdivisions around the
truncated cone.

verticalSubdivisions number

The number of subdivisions down the
truncated cone.

opt_topCap boolean <optional>

Create top cap. Default = true.

opt_bottomCap boolean <optional>

Create bottom cap. Default =
true.

Returns:
Type:
Object.<string, TypedArray>

The
created plane vertices.

(static) deindexVertices(vertices) → {Object.<string, TypedArray>}

Given indexed vertices creates a new set of vertices unindexed by expanding the indexed vertices.

Parameters:
Name Type Description
vertices Object.<string, TypedArray>

The indexed vertices to deindex

Returns:
Type:
Object.<string, TypedArray>

The deindexed vertices

(static) flattenNormals(vertices) → {Object.<string, TypedArray>}

flattens the normals of deindexed vertices in place.

Parameters:
Name Type Description
vertices Object.<string, TypedArray>

The deindexed vertices who's normals to flatten

Returns:
Type:
Object.<string, TypedArray>

The flattened vertices (same as was passed in)

(static) makeRandomVertexColors(vertices, optionsopt) → {Object.<string, augmentedTypedArray>}

Creates an augmentedTypedArray of random vertex colors.
If the vertices are indexed (have an indices array) then will
just make random colors. Otherwise assumes they are triangless
and makes one random color for every 3 vertices.

Parameters:
Name Type Attributes Description
vertices Object.<string, augmentedTypedArray>

Vertices as returned from one of the createXXXVertices functions.

options module:primitives.RandomVerticesOptions <optional>

options.

Returns:
Type:
Object.<string, augmentedTypedArray>

same vertices as passed in with color added.

(static) reorientDirections(array, matrix) → {Array.<number>|TypedArray}

Reorients directions by the given matrix..

Parameters:
Name Type Description
array Array.<number> | TypedArray

The array. Assumes value floats per element.

matrix Matrix

A matrix to multiply by.

Returns:
Type:
Array.<number> | TypedArray

the same array that was passed in

(static) reorientNormals(array, matrix) → {Array.<number>|TypedArray}

Reorients normals by the inverse-transpose of the given
matrix..

Parameters:
Name Type Description
array Array.<number> | TypedArray

The array. Assumes value floats per element.

matrix Matrix

A matrix to multiply by.

Returns:
Type:
Array.<number> | TypedArray

the same array that was passed in

(static) reorientPositions(array, matrix) → {Array.<number>|TypedArray}

Reorients positions by the given matrix. In other words, it
multiplies each vertex by the given matrix.

Parameters:
Name Type Description
array Array.<number> | TypedArray

The array. Assumes value floats per element.

matrix Matrix

A matrix to multiply by.

Returns:
Type:
Array.<number> | TypedArray

the same array that was passed in

(static) reorientVertices(arrays, matrix) → {Object.<string, (Array.<number>|TypedArray)>}

Reorients arrays by the given matrix. Assumes arrays have
names that contains 'pos' could be reoriented as positions,
'binorm' or 'tan' as directions, and 'norm' as normals.

Parameters:
Name Type Description
arrays Object.<string, (Array.<number>|TypedArray)>

The vertices to reorient

matrix Matrix

matrix to reorient by.

Returns:
Type:
Object.<string, (Array.<number>|TypedArray)>

same arrays that were passed in.

Type Definitions

RandomColorFunc(ndx, channel) → {number}

Used to supply random colors

Parameters:
Name Type Description
ndx number

index of triangle/quad if unindexed or index of vertex if indexed

channel number

0 = red, 1 = green, 2 = blue, 3 = alpha

Returns:
Type:
number

a number from 0 to 255

RandomVerticesOptions

Properties:
Name Type Attributes Description
vertsPerColor number <optional>

Defaults to 3 for non-indexed vertices

rand module:primitives.RandomColorFunc <optional>

A function to generate random numbers

Type:
  • Object