Reference transform3D()

transform3D()

This API is experimental

Its behavior may change in a future version of p5.js.

Creates a 3D transform inside a p5.strands shader callback.

A transform is a 4x4 matrix that stores a combination of moves, turns, and scales in three dimensions. Calling transform3D() without arguments returns the identity transform, which leaves points exactly where they are.

A transform is built up by passing it to translate(), rotate(), rotateX(), rotateY(), rotateZ(), rotateAxisAngle(), and scale(). Each of those returns a new transform instead of changing the one passed in, so the result has to be assigned back, as in t = translate(t, 20, 0, 0).

The finished transform is applied to a position with transformPoint(), and to a surface direction with transformNormal(). This is the usual way to place each copy of a shape when drawing many instances at once with instances() or model().

transform3D() is the same function as mat4(). Use transform3D() when describing a transformation, and mat4() when thinking of the value as a plain 4x4 matrix.

It can also be called with a single number, which fills the diagonal of the matrix; a single matrix, which is resized (a 3x3 is extended with the identity matrix); 4 column vectors; or 16 values in column-major order.

Note: transform3D() can only be used inside a p5.strands shader callback.

Examples

Syntax

transform3D(values1, values2, ..., valuesn)

Parameters

values1, ..., valuesn
Number: nothing for the identity transform, one number, one matrix, 4 column vectors, or 16 values in column-major order.

Returns

a 4x4 transform.

Related References