WardicThree
Wardic for three.js: Motion's animate on a scene's meshes, materials, cameras, lights and uniforms,
on frames the Host loop pumps. One runtime per Host loop: make builds it, the loop calls
frame(time) once a frame before it renders, and dispose ends it.
- Transform keys are Motion's names:
x,yandzmoveposition;rotateX,rotateYandrotateZturnrotation, in degrees;scalesets all three scales, andscaleX,scaleYandscaleZone each. - Any other key is the object's own number (a camera's
fov, a light'sintensity), else its material's (opacity,roughness: on every mesh that shares the material), a uniform's, or a vector's axis (emissiveIntensity,uProgress,positionX). The types are three's own:animate(mesh, { rotatY: 90 })is an error. - Colours (
color,emissive, a uniform'sColor) take a CSS colour, a hex number or aColor, and blend in linear light, three's: red to blue passes#bc00bc. A spring keeps a colour's speed through a change of target, as it keeps a position's. - A Batch (
batch) moves many objects as one run, or anInstancedMesh's instances: each by its transforms and its instance colour, its matrix written in place. - Units:
x,yandzare metres, so springs rest within millimetres (unitScale). - three's rules after a write: a camera's projection keys update its projection matrix, and an
opacitybelow 1 draws its material transparent. - Hover and press (
hover,press), givenmake'scanvas,cameraandscene: a pointer hits the nearest drawn object under it, cast once a frame (ThreeInput).
import * as WardicThree from "@wardic/three/WardicThree"
const wardic = WardicThree.make()
renderer.setAnimationLoop((time) => {
wardic.frame(time)
renderer.render(scene, camera)
})
wardic.animate(cube, { y: 2, rotateY: 180 }, { type: "spring", bounce: 0.3 })
await wardic.animate(cube, { opacity: 0 }, { duration: 0.4 })Its exports also name types the module doesn't export: its internal types.
Interfaces
Options
A runtime's options: @wardic/object's, the scene's unit scale, and its input.
Extends
createBatch
Properties
camera?
readonly camera?: Camera | (() => Camera);The camera the scene is drawn with, or a function giving the one active now: a pointer's ray is cast from it.
canvas?
readonly canvas?: CanvasLike;The canvas the scene is drawn on, whose pointer events hover and press hear: with camera and scene.
hitTest?
readonly hitTest?: HitTest;What a pointer hits, in the raycast's place: a BVH's, or a GPU pick's.
scene?
readonly scene?: Object3D<Object3DEventMap>;The scene a pointer hits.
unitScale?
readonly unitScale?: number;How many of Motion's units a metre is, for x, y and z's springs' rest: 100 (a scene in
metres), so a 10 m move rests within 5 mm. Give 1 for a scene in pixels.
window?
readonly window?: EventTarget;Where a held pointer's events are heard once it leaves the canvas: the canvas's window when left out.
ThreeAnimate()
animate(subject, target, options?) animates a scene's Subject, or each of a list of them, to
target; animate(sequence, options?) plays a sequence. Either returns its Playback controls. Motion's.
The options' transition takes an entry under any of the Subject's keys: a Batch's, its keys.
A Subject whose keys are any name (a ShaderMaterial, a mesh drawn with one) has its target checked
key by key as given, though a misspelt key, even a mesh's own (rotatY), isn't caught, any name being
one of its keys; naming its type, animate<T>(…), checks its keys as values only.
Call Signature
ThreeAnimate<T>(
batch,
target,
options?
): WardicPlaybackControls;animate(subject, target, options?) animates a scene's Subject, or each of a list of them, to
target; animate(sequence, options?) plays a sequence. Either returns its Playback controls. Motion's.
The options' transition takes an entry under any of the Subject's keys: a Batch's, its keys.
A Subject whose keys are any name (a ShaderMaterial, a mesh drawn with one) has its target checked
key by key as given, though a misspelt key, even a mesh's own (rotatY), isn't caught, any name being
one of its keys; naming its type, animate<T>(…), checks its keys as values only.
Type Parameters
T
T extends object
Parameters
batch
any
target
options?
any
Returns
WardicPlaybackControls
Call Signature
ThreeAnimate<T, G>(
subject,
target,
options?
): WardicPlaybackControls;animate(subject, target, options?) animates a scene's Subject, or each of a list of them, to
target; animate(sequence, options?) plays a sequence. Either returns its Playback controls. Motion's.
The options' transition takes an entry under any of the Subject's keys: a Batch's, its keys.
A Subject whose keys are any name (a ShaderMaterial, a mesh drawn with one) has its target checked
key by key as given, though a misspelt key, even a mesh's own (rotatY), isn't caught, any name being
one of its keys; naming its type, animate<T>(…), checks its keys as values only.
Type Parameters
T
T extends Readonly<Record<string, unknown>>
G
G extends Readonly<Record<string, unknown>> = Readonly<Record<string, unknown>>
Parameters
subject
T
target
| ThreeTarget<T>
| AnyKeyTargetFor<T, G>
options?
any
Returns
WardicPlaybackControls
Call Signature
ThreeAnimate(sequence, options?): WardicPlaybackControls;animate(subject, target, options?) animates a scene's Subject, or each of a list of them, to
target; animate(sequence, options?) plays a sequence. Either returns its Playback controls. Motion's.
The options' transition takes an entry under any of the Subject's keys: a Batch's, its keys.
A Subject whose keys are any name (a ShaderMaterial, a mesh drawn with one) has its target checked
key by key as given, though a misspelt key, even a mesh's own (rotatY), isn't caught, any name being
one of its keys; naming its type, animate<T>(…), checks its keys as values only.
Parameters
sequence
options?
any
Returns
WardicPlaybackControls
Call Signature
ThreeAnimate<T, G>(
subject,
target,
options?
): WardicPlaybackControls;animate(subject, target, options?) animates a scene's Subject, or each of a list of them, to
target; animate(sequence, options?) plays a sequence. Either returns its Playback controls. Motion's.
The options' transition takes an entry under any of the Subject's keys: a Batch's, its keys.
A Subject whose keys are any name (a ShaderMaterial, a mesh drawn with one) has its target checked
key by key as given, though a misspelt key, even a mesh's own (rotatY), isn't caught, any name being
one of its keys; naming its type, animate<T>(…), checks its keys as values only.
Type Parameters
T
T extends object
G
G extends Readonly<Record<string, unknown>> = Readonly<Record<string, unknown>>
Parameters
subject
T | readonly T[]
target
| ThreeTarget<T>
| AnyKeyTargetFor<T, G>
options?
any
Returns
WardicPlaybackControls
ThreeBatchOf()
batch(objects, options?) makes a Batch of a list of objects; batch(instanced, options?) one of an
InstancedMesh's instances, a member each. Either runs on the keys of its first animate (or keys).
Call Signature
ThreeBatchOf<M>(instanced, options?): ObjectBatch<T>;batch(objects, options?) makes a Batch of a list of objects; batch(instanced, options?) one of an
InstancedMesh's instances, a member each. Either runs on the keys of its first animate (or keys).
Type Parameters
M
M extends IsInstancedMesh
Parameters
instanced
M
options?
any
Returns
ObjectBatch<T>
Call Signature
ThreeBatchOf<T>(objects, options?): ObjectBatch<T>;batch(objects, options?) makes a Batch of a list of objects; batch(instanced, options?) one of an
InstancedMesh's instances, a member each. Either runs on the keys of its first animate (or keys).
Type Parameters
T
T extends object
Parameters
objects
readonly T[]
options?
any
Returns
ObjectBatch<T>
WardicThree
A runtime: what animates a scene on one Host loop.
Extends
Omit<WardicObject.WardicObject,"animate"|"batch">
Indexable
[key: string]: WardicObject[key: number]: WardicObject[key: symbol]: WardicObjectProperties
animate
readonly animate: ThreeAnimate;batch
readonly batch: ThreeBatchOf;A Batch of objects, or of an InstancedMesh's instances: one run for all of them, on the keys of
its first animate (or keys). animate(batch, target) moves every member; animate(batch.at(i), target) member i. An instance takes its transforms and its colour.
hover
readonly hover: (subject, onStart) => () => void;hover(subject, onStart): onStart runs as a pointer comes over subject (a scene object, a Batch's
member, or each member of a Batch), and what it returns, as the pointer goes off. Returns its cancel.
Needs make's canvas, camera and scene.
Parameters
subject
object
onStart
Returns
() => void
input
readonly input: any;The scene's pointer input, as core's InputSource, for a binding's gestures: undefined with no
canvas. Unstable: what @wardic/three/solid's Stage hands its hooks.
press
readonly press: (subject, onStart) => () => void;press(subject, onStart): onStart runs as a press starts on subject, and what it returns, as it
ends, told whether it ended on it. Returns its cancel. Needs make's canvas, camera and scene.
Parameters
subject
object
onStart
Returns
() => void
Type Aliases
BatchColourKey
type BatchColourKey<T> = T extends Instance<IsInstancedMesh> ? "color" : T extends object ? ColourKey<T> : never;The colour keys a Batch of T takes: an instance's color, a scene object's colours.
Type Parameters
T
T
BatchKey
type BatchKey<T> = T extends Instance<IsInstancedMesh> ? InstanceKey : [SceneKey<T>] extends [never] ? ObjectBatch.NumberKey<T> : SceneKey<T>;The keys a Batch of T takes: an InstancedMesh's instance's, a scene object's scene keys, any other object's numbers.
Type Parameters
T
T
ColourKey
type ColourKey<T> = T extends object ?
| ColourKeyOf<T>
| MaterialColourKey<MaterialOf<T>> : T extends object ? MaterialColourKey<T> : UniformColourKey<T>;The colour keys of a three Subject T: its material's Colors for a scene object, a material's own, a uniforms object's.
Type Parameters
T
T
SceneKey
type SceneKey<T> = T extends object ?
| TransformKey
| SceneNumberKey<T>
| VectorKey<T>
| MaterialKey<MaterialOf<T>> : T extends object ? MaterialKey<T> : never;The number keys of a three Subject T: a scene object's transforms, numbers and vectors' axes, and its material's; a material's own. Not their id, which three makes read-only.
Type Parameters
T
T
ThreeBatch
type ThreeBatch<T> = ObjectBatch.ObjectBatch<T, BatchKey<T>>;A Batch of a scene's objects, or of an InstancedMesh's instances: one run for all of them. @wardic/object's, on scene keys.
Type Parameters
T
T extends object
ThreeBatchSegment
type ThreeBatchSegment =
| readonly [batch:
| ObjectBatch.ObjectBatch<any, any>
| ObjectBatch.Member<any, any>, target: Readonly<Record<string,
| ObjectBatch.SegmentValue
| ColourSegmentValue>>]
| readonly [batch:
| ObjectBatch.ObjectBatch<any, any>
| ObjectBatch.Member<any, any>, target: Readonly<Record<string,
| ObjectBatch.SegmentValue
| ColourSegmentValue>>, options: Imperative.WardicSegmentOptions];A Segment of a Batch, [batch, target, options?], its colour keys taking colours: every member, or a member's handle, batch.at(i).
ThreeBatchTarget
type ThreeBatchTarget<T> = { readonly [Key in BatchKey<T> | BatchColourKey<T>]?: ValueOf<Key, BatchKey<T>, BatchColourKey<T>, BatchNumberValue, BatchColourValue> };A Batch of T's targets for an animate call: each number key and colour key a stop, two, or a function of a member's index giving them.
Type Parameters
T
T
ThreeSequence
type ThreeSequence = ReadonlyArray<
| WardicObject.ObjectSequence[number]
| ThreeBatchSegment>;A sequence of a scene: @wardic/object's Segments, its Segments of Batches taking colours. Motion's AnimationSequence.
ThreeTarget
type ThreeTarget<T> = [T] extends [ReadonlyArray<unknown>] ? WardicObject.ObjectTarget<T> : [SceneKey<T>] extends [never] ? Omit<WardicObject.ObjectTarget<T>, "transition"> & SceneTarget<UniformKey<T>, UniformColourKey<T>, TransitionKey<T>> : SceneTarget<SceneKey<T>, ColourKey<T>, TransitionKey<T>>;A target for T: a scene object's or a material's by its scene keys and colours; a uniforms object's
by its uniforms' names; any other object's (a Vector3, a plain { x }) by its own keys, as @wardic/object's.
Its transition takes an entry under any of them, a colour's or a channel's. An array has none that
fits: animate reads one as a list of Subjects, or a sequence, never as one Subject.
Type Parameters
T
T
TransformKey
type TransformKey =
| "x"
| "y"
| "z"
| "rotateX"
| "rotateY"
| "rotateZ"
| "scale"
| "scaleX"
| "scaleY"
| "scaleZ";A scene object's transform keys: its position, its rotation in degrees, and its scales.
Variables
UNIT_SCALE
const UNIT_SCALE: 100 = 100;A scene's unit scale when the app gives none: a metre counts as 100 of Motion's units.
Functions
environment()
function environment(unitScale?): Environment;three's Environment for @wardic/object's runtime, at unitScale.
Parameters
unitScale?
number = UNIT_SCALE
Returns
Environment
make()
function make(options?): WardicThree;A runtime on frames the Host loop pumps: frame(time) once a frame, before it renders.
Parameters
options?
Options = {}