ThreeInstances

An InstancedMesh's instances as a Batch's members: wardic.batch(instanced) animates each instance's transforms and colour by its index, as one run, where three would update an Object3D and call setMatrixAt for each. The writer composes each moving instance's matrix in place, uploads only the span of instances it wrote, and keeps the mesh's bounding sphere around them while they move, so culling and the raycast stay right.

  • Its members are every instance the mesh holds, its capacity. Its count, how many are drawn, stays the app's.
  • Each starts where its matrix puts it, read once when the Batch is made: its position, its rotation in degrees (Euler XYZ, three's default order) and its scale. A key the Batch doesn't take keeps that value.
  • The matrices are the Batch's from then on: a setMatrixAt of the app's is drawn over at that instance's next write.
  • color is an instance's colour, which three multiplies into the material's: in linear light, as ThreeColours splits it, colorR, colorG and colorB. The instances start white.
  • One Batch a mesh in a runtime: a second wardic.batch of it is an error.
import * as WardicThree from "@wardic/three/WardicThree"

const wardic = WardicThree.make()
const swarm = wardic.batch(instanced)
wardic.animate(swarm, { y: (i) => rowY(i), rotateY: 90 }, { type: "spring", delay: stagger(0.002) })
wardic.animate(swarm.at(42), { scale: 1.4, color: "#ff8800" })

Its exports also name types the module doesn't export: its internal types.

Interfaces

Instance

One instance of an InstancedMesh M, as its Batch's member: the mesh, and the instance's index.

Type Parameters

M

M extends object = object

Properties

index
readonly index: number;
mesh
readonly mesh: M;

Type Aliases

InstanceKey

type InstanceKey = 
  | "x"
  | "y"
  | "z"
  | "rotateX"
  | "rotateY"
  | "rotateZ"
  | "scale"
  | "scaleX"
  | "scaleY"
  | "scaleZ"
  | "colorR"
  | "colorG"
  | "colorB";

An instance's keys in a Batch: its transforms, and its colour's channels in linear light.

Functions

batchSource()

function batchSource(): (given) => any;

A runtime's Batches of instances, its Environment's batchSource: an InstancedMesh's instances as a Batch's members, a handle each, { mesh, index }, drawn by a writer of its own; undefined for anything else. A mesh is one Batch's in the runtime.

Returns

(given) => any


boundsOf()

function boundsOf(
   te, 
   count, 
   geometry, 
   reach, 
   sphere
): void;

The sphere around the first count instances of te, into sphere: each instance's geometry sphere (geometry) through its matrix, kept in reach, an AABB of them, then the farthest reach from its middle. Every instance is inside it.

Parameters

te

Float32Array

count

number

geometry

SphereLike

reach

Float64Array

sphere

SphereLike

Returns

void


compose()

function compose(
   te, 
   o, 
   x, 
   y, 
   z, 
   a, 
   b, 
   c, 
   d, 
   e, 
   f, 
   sx, 
   sy, 
   sz
): void;

The matrix of a position, a rotation by its axes' cos and sin (a, b for x; c, d for y; e, f for z; Euler XYZ) and a scale, written at o in te: three's makeRotationFromEuler, scaled.

Parameters

te

Float32Array

o

number

x

number

y

number

z

number

a

number

b

number

c

number

d

number

e

number

f

number

sx

number

sy

number

sz

number

Returns

void


decompose()

function decompose(
   te, 
   o, 
   out, 
   at
): void;

The matrix at o in te read into out at at: its position, its rotation in degrees (Euler XYZ), its scale, and each axis's cos and sin. three's decompose and Euler.setFromRotationMatrix, with a mirrored matrix's sign on its x scale.

Parameters

te

ArrayLike<number>

o

number

out

Float64Array

at

number

Returns

void


isInstance()

function isInstance(given): given is Instance<object>;

Whether given is an instance a Batch's member handle names: one of a mesh that has a Batch.

Parameters

given

unknown

Returns

given is Instance<object>


isInstancedMesh()

function isInstancedMesh(given): boolean;

Whether given is a three InstancedMesh, by its flag.

Parameters

given

unknown

Returns

boolean