Module: primitives

primitives

Various functions to make simple primitives

Methods

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:

The
created plane vertices.

Type
Object.<string, TypedArray>

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:

The
created plane vertices.

Type
Object.<string, TypedArray>

createPlaneVertices(width, depth, subdivisionsWidth, subdivisionsDepth, matrix) → {Object.<string, TypedArray>}

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

Parameters:
Name Type Argument 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:

The
created plane vertices.

Type
Object.<string, TypedArray>

createSphereVertices(radius, subdivisionsAxis, subdivisionsHeight, opt_startLatitudeInRadians, opt_endLatitudeInRadians, opt_startLongitudeInRadians, opt_endLongitudeInRadians) → {Object.<string, TypedArray>}

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

Parameters:
Name Type Argument 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:

The
created plane vertices.

Type
Object.<string, TypedArray>

createTruncatedConeVertices(bottomRadius, topRadius, height, radialSubdivisions, verticalSubdivisions, opt_topCap, opt_bottomCap) → {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 Argument 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:

The
created plane vertices.

Type
Object.<string, TypedArray>

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:

The deindexed vertices

Type
Object.<string, TypedArray>

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:

The flattened vertices (same as was passed in)

Type
Object.<string, TypedArray>

makeRandomVertexColors(vertices, options) → {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 Argument Description
vertices Object.<string, augmentedTypedArray>

Vertices as returned from one of the createXXXVertices functions.

options RandomVerticesOptions <optional>

options.

Returns:

same vertices as passed in with color added.

Type
Object.<string, augmentedTypedArray>

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:

the same array that was passed in

Type
Array.<number>| TypedArray

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:

the same array that was passed in

Type
Array.<number>| TypedArray

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:

the same array that was passed in

Type
Array.<number>| TypedArray

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:

same arrays that were passed in.

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

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:

a number from 0 to 255

Type
number

RandomVerticesOptions

Type:
  • Object
Properties:
Name Type Argument Description
vertsPerColor number <optional>

Defaults to 3 for non-indexed vertices

rand RandomColorFunc <optional>

A function to generate random numbers

copyright Gregg Tavares