WL

.Alignment: enum

Alignment type enum for TextComponent.

Values

NameValueDescription
Center1Text center is at object origin
Left0Text start is at object origin
Right2Text end is at object origin

.AnimationState: enum

Animation state of AnimationComponent.

Values

NameValueDescription
Paused1Animation is paused and will continue at current playback time on play
Playing0Animation is currently playing
Stopped2Animation is stopped

.CBORType: enum

Values

NameValueDescription
Array0
Constant2
Native3
Record1

.Collider: enum

Collider type enum for CollisionComponent.

Values

NameValueDescription
AxisAlignedBox1Axis Aligned Bounding Box Collider: Box that is always aligned to XYZ axis. It cannot be rotated but is more efficient than Box.
Box2Aligned Bounding Box Collider: Box that matches the object’s rotation and translation correctly. This is the least efficient collider and should only be chosen over Sphere and AxisAlignedBox if really necessary.
Sphere0Sphere Collider: Simplest and most performant collision shape. If this type is set on a CollisionComponent, only the first component of extents will be used to determine the radius.

.CollisionEventType: enum

Collision callback event type.

Values

NameValueDescription
Touch0Touch/contact detected, collision
TouchLost1Touch/contact lost, uncollide
TriggerTouch2Touch/contact with trigger detected
TriggerTouchLost3Touch/contact with trigger lost

.ForceMode: enum

Rigid body force mode for addForce and addTorque.

PhysX API Reference

Values

NameValueDescription
Acceleration3Apply as mass dependent force
Force0Apply as force
Impulse1Apply as impulse
VelocityChange2Apply as velocity change, mass dependent

.GraphicsApi: enum

1.5.0+

Graphics API enum.

Values

NameValueDescription
WebGL20WebGL 2.0
WebGPU1WebGPU

.InputType: enum

Input type enum for InputComponent.

Values

NameValueDescription
ControllerLeft3Left controller input
ControllerRight4Right controller input
EyeLeft1Left eye input
EyeRight2Right eye input
Head0Head input
RayLeft5Left ray input
RayRight6Right ray input

.LightType: enum

Light type enum for LightComponent.

Values

NameValueDescription
Point0Point light
Spot1Spot light
Sun2Sun light / Directional light

.LockAxis: enum

Enum for Physics axes locking

See angularLockAxis and linearLockAxis.

Values

NameValueDescription
None0No axis selected.
X1X axis:
Y2Y axis:
Z4Z axis:

.LogLevel: enum

Logging levels supported by Logger.

Values

NameValueDescription
Error2
Info0
Warn1

.LogTag: enum

Default set of logging tags used by the API.

Values

NameValueDescription
Component2Component init, update, etc…
Engine0Initialization, component registration, etc…
Scene1Scene loading

.MaterialParamType: enum

Material parameter type.

Values

NameValueDescription
Float3Float parameter type.
Font5Font resource parameter type. Note: Changing font isn’t exposed yet and will raise an error.
HalfFloat216-bit float parameter type.
Int1Integer parameter type.
Sampler4Sampler resource parameter type, i.e., a Texture.
UnsignedInt0Unsigned integer parameter type.

.MeshAttribute: enum

0.9.0+

Mesh attribute enum.

Values

NameValueDescription
Color4Color attribute, 4 floats, RGBA, range 0 to 1
JointId5Joint id attribute, 8 unsigned ints
JointWeight6Joint weights attribute, 8 floats
Normal2Normal attribute, 3 floats
Position0Position attribute, 3 floats
SecondaryTextureCoordinate7Secondary texture coordinate attribute, 2 floats
Tangent1Tangent attribute, 4 floats
TextureCoordinate3Texture coordinate attribute, 2 floats

.MeshIndexType: enum

Mesh index type.

Values

NameValueDescription
UnsignedByte1Single byte mesh index, range 0-255
UnsignedInt4Four byte mesh index, range 0-4294967295
UnsignedShort2Two byte mesh index, range 0-65535

.MeshSkinningType: enum

Mesh skinning type.

Values

NameValueDescription
EightJoints2Skinned, 8 joints/weight per vertex
FourJoints1Skinned, 4 joints/weight per vertex
None0Not skinned

.ParticleReplacementPolicy: enum

Replacement policies for spawning particles.

Values

NameValueDescription
DontReplace0Don’t replace existing particles.
ReplaceOldest1Replace oldest particles first.

.ProjectionType: enum

Projection type enum for ViewComponent.

Values

NameValueDescription
Orthographic1Orthographic projection
Perspective0Perspective projection

.RootMotionMode: enum

Root motion mode of AnimationComponent.

Values

NameValueDescription
ApplyToOwner1Move and rotate root with the delta of its motion
None0Do nothing
Script2Store the motion to be retrieved by a JS script

.Shape: enum

Rigid body shape.

PhysX SDK Guide.

Values

NameValueDescription
Box3Box shape.
Capsule2Capsule shape.
ConvexMesh5Convex mesh shape.
None0No shape.
Plane4Plane shape.
Sphere1Sphere shape.
TriangleMesh6Triangle mesh shape.

.TextEffect: enum

Effect type enum for TextComponent.

Values

NameValueDescription
None0Text is rendered normally
Outline1Text is rendered with an outline
Shadow2Text is rendered with a drop shadow

.TextWrapMode: enum

1.2.1+

Wrap mode enum for TextComponent.

Values

NameValueDescription
Clip3Text is cut off
Hard2Text wraps anywhere
None0Text doesn’t wrap automatically, only with explicit newline
Soft1Text wraps at word boundaries

.Type: enum

Component property type.

Values

NameValueDescription
Animation10Animation reference: Appears in the editor as an animation resource selection dropdown. Initial value is null.
Array16Array of property: Appears in the editor as a list of N elements. Initial value is [], unless overridden by the default property.
AudioClip19AudioClip reference: Appears in the editor as an audio resource selection dropdown. Initial value is null.
Bool1Bool: Appears in the editor as a checkbox. Initial value is false, unless overridden by the default property.
Color12Color: Appears in the editor as a color widget. Initial value is [0.0, 0.0, 0.0, 1.0], unless overridden by the default property.
Enum5Enumeration: Appears in the editor as a dropdown with given values. The additional values parameter with selection options is mandatory. The property value is resolved to an index into the values array. Initial value is the first element in values, unless overridden by the default property. The default value can be a string or an index into values. Example: js camera: {type: Type.Enum, values: ['auto', 'back', 'front'], default: 'auto'},
Float3Float: Appears in the editor as a floating point input field. Initial value is 0.0, unless overridden by the default property.
Int2Int: Appears in the editor as an integer input field. Initial value is 0, unless overridden by the default property.
Material9Material reference: Appears in the editor as a material resource selection dropdown. Initial value is null.
Mesh7Mesh reference: Appears in the editor as a mesh resource selection dropdown. Initial value is null.
Object6Object reference: Appears in the editor as an object resource selection dropdown with object picker. Initial value is null.
ParticleEffect18Particle effect reference: Appears in the editor as a particle effect resource selection dropdown. Initial value is null.
Record17Class with sub-properties: Appears in the editor as a nested properties structure. Initial value is {}, unless overridden by the default property.
Skin11Skin reference: Appears in the editor as a skin resource selection dropdown. Initial value is null.
String4String / Text: Appears in the editor as a single-line text input field. Initial value is an empty string, unless overridden by the default property.
Texture8Texture reference: Appears in the editor as a texture resource selection dropdown. Initial value is null.
Vector213Vector of two floats: Appears in the editor as a two-element floating point input field. Initial value is [0.0, 0.0], unless overridden by the default property.
Vector314Vector of three floats: Appears in the editor as a three-element floating point input field. Initial value is [0.0, 0.0, 0.0], unless overridden by the default property.
Vector415Vector of four floats: Appears in the editor as a four-element floating point input field. Initial value is [0.0, 0.0, 0.0, 0.0], unless overridden by the default property.

.VerticalAlignment: enum

Vertical alignment type enum for TextComponent.

Values

NameValueDescription
Bottom3Text bottom is at object origin
Line0Text line is at object origin
Middle1Text middle is at object origin
Top2Text top is at object origin

.APIVersion: Version

Version of this API.

.Justification: typeof VerticalAlignment

Justification type enum for TextComponent.

Deprecated: Please use VerticalAlignment instead.

.Property: { (opts: PropertyReferenceOptions) ⇒ ComponentProperty; (element: ComponentProperty) ⇒ ComponentProperty; (opts: PropertyReferenceOptions) ⇒ ComponentProperty; (defaultValue: boolean) ⇒ ComponentProperty; (r: number, g: number, b: number, a: number) ⇒ ComponentProperty; (values: string[], defaultValue: string | number) ⇒ ComponentProperty; (defaultValue: number) ⇒ ComponentProperty; (defaultValue: number) ⇒ ComponentProperty; (opts: PropertyReferenceOptions) ⇒ ComponentProperty; (opts: PropertyReferenceOptions) ⇒ ComponentProperty; (opts: PropertyReferenceOptions) ⇒ ComponentProperty; (opts: PropertyReferenceOptions) ⇒ ComponentProperty; (definition: PropertyRecord) ⇒ ComponentProperty; (opts: PropertyReferenceOptions) ⇒ ComponentProperty; (defaultValue: string) ⇒ ComponentProperty; (opts: PropertyReferenceOptions) ⇒ ComponentProperty; (x: number, y: number) ⇒ ComponentProperty; (x: number, y: number, z: number) ⇒ ComponentProperty; (x: number, y: number, z: number, w: number) ⇒ ComponentProperty; }

Component property namespace.

Usage:

import {Component, Property} from '@wonderlandengine/api';

class MyComponent extends Component {
    static Properties = {
        myBool: Property.bool(true),
        myInt: Property.int(42),
        myString: Property.string('Hello World!'),
        myMesh: Property.mesh()
    }
}

It’s possible to nest properties using record, and array:

import {Component, Property} from '@wonderlandengine/api';

class Weapon {
    static Properties = {
        damage: Property.float(100.0),
        fireRate: Property.int(10)
    }
}
class Zombie {
    static Properties = {
        names: Property.string('Mad Zombie'),
        animation: Property.animation()
    }
}

class Player extends Component {
    static Properties = {
        weapon: Property.record(Weapon),
        zombieTargets: Property.array(Zombie),
    }
}

For TypeScript users, you can use the decorators instead.

.defaultPropertyCloner: DefaultPropertyCloner

Default cloner for property values.

.capitalizeFirstUTF8(str: string) ⇒ string

Capitalize the first letter in a string.

Note: The string must be UTF-8.

Returns: The string with the first letter capitalized.

ParamTypeDescription
strstringThe string to format.

.checkRuntimeCompatibility(version: Version) ⇒ void

Ensures that this API is compatible with the given runtime version.

We only enforce compatibility for major and minor components, i.e., the runtime and the API must both be of the form x.y.*.

Throws: If the major or the minor components are different.

ParamTypeDescription
versionVersionThe target version

.clamp(val: number, min: number, max: number) ⇒ number

Clamp the value in the range [min; max].

Returns: The clamped value.

ParamTypeDescription
valnumberThe value to clamp.
minnumberThe minimum value (inclusive).
maxnumberThe maximum value (inclusive).

.decode<T>(data: Uint8Array, tagger: Tagger, options: Options) ⇒ T

Converts a Concise Binary Object Representation (CBOR) buffer into an object.

const buffer = new Uint8Array([0xa2, 0x01, 0x02, 0x03, 0x04]).buffer;
const decoded = decode(buffer);
console.log(decoded); // { "1": 2, "3": 4 }

CBOR values can be wrapped in a numeric tag. To handle and possibly transform tagged values, pass a tagger function:

const buffer = new Uint8Array([
  0xa1, 0x63, 0x75, 0x72, 0x6c, 0xd8, 0x20, 0x70,
  0x68, 0x74, 0x74, 0x70, 0x3a, 0x2f, 0x2f, 0x73,
  0x69, 0x74, 0x65, 0x2e, 0x63, 0x6f, 0x6d, 0x2f
]);
const decoded = decode(buffer, (tag, value) => {
    if (tag === 32) return new URL(value);
    return value;
});
console.log(decoded); // { url: URL { href: "http://site.com/" } }

Decoded basic types generally match the equivalent JavaScript types. Byte strings are decoded to Uint8Array.

Tagged values are left as-is, with the following exceptions:

  • Bignum values (byte strings with tag 2 or 3) are decoded to BigInt
  • Little-endian versions of typed arrays as defined in RFC 8746 are decoded to JavaScript typed arrays

Returns: The CBOR buffer converted to a JavaScript value.

ParamTypeDescription
dataUint8ArrayA valid CBOR buffer.
taggerTaggerOptional callback for transformation of tagged values.
optionsOptionsOptions for decoding behavior.
Template ParamType Definition
T

.fetchStreamWithProgress(path: string, onProgress: ProgressCallback, signal: AbortSignal) ⇒ Promise<ReadableStream<Uint8Array>>

Fetch a file as a ReadableStream, with fetch progress passed to a callback.

Returns: Promise that resolves when the fetch successfully completes.

ParamTypeDescription
pathstringPath of the file to fetch.
onProgressProgressCallbackCallback receiving the current fetch progress and total size, in bytes. Also called a final time on completion.
signalAbortSignalAbort signal passed to fetch().

.fetchWithProgress(path: string, onProgress: ProgressCallback, signal: AbortSignal) ⇒ Promise<ArrayBuffer>

Fetch a file as an ArrayBuffer, with fetch progress passed to a callback.

Returns: Promise that resolves when the fetch successfully completes.

ParamTypeDescription
pathstringPath of the file to fetch.
onProgressProgressCallbackCallback receiving the current fetch progress and total size, in bytes. Also called a final time on completion.
signalAbortSignalAbort signal passed to fetch().

.getBaseUrl(url: string) ⇒ string

Get parent path from a URL.

Returns: Parent URL without trailing slash.

ParamTypeDescription
urlstringURL to get the parent from.

.getFilename(url: string) ⇒ string

Get the filename of a url.

Returns: A string containing the filename. If no filename is found, returns the input string.

ParamTypeDescription
urlstringThe url to extract the name from.

.getType(typeInfo: number) ⇒ CBORType

Check whether the type is an array, a record, or a native type (decodable without recursion).

Returns: The type category.

ParamTypeDescription
typeInfonumberType information obtained using readTypeInfo.

.isImageLike(value: any) ⇒ value is ImageLike

Check whether a given value is a visual media.

Returns: true if the value is an image, video, or canvas.

ParamTypeDescription
valueanyThe value to check

.isNumber(value: any) ⇒ value is number

Check if a given value is a native number or a Number instance.

Returns: true if the value has type number literal or Number, false otherwise.

ParamTypeDescription
valueanyThe value to check.

.isString(value: any) ⇒ value is string

Check if a given value is a native string or a String instance.

Returns: true if the value has type string literal or String, false otherwise.

ParamTypeDescription
valueanyThe value to check.

.isUndefined(type: CBORType, length: number) ⇒ boolean

ParamTypeDescription
typeCBORType
lengthnumber

.isWebGPUSupported() ⇒ Promise<boolean>

1.5.0+

Whether Wonderland can use the WebGPU API in this browser

Returns: true if the browser supports WebGPU and exposes an adapter that implements all required features.

.loadRuntime(runtime: string, options: Partial<LoadRuntimeOptions>) ⇒ Promise<WonderlandEngine>

Load the runtime using the WASM and JS files.

Returns: A promise that resolves when the engine is ready to be used.

ParamTypeDescription
runtimestringThe runtime base string, e.g,: WonderlandRuntime-loader-physx.
optionsPartial<LoadRuntimeOptions>Options to modify the loading behaviour.

.needsFlipY(image: ImageLike) ⇒ 0 | 1

ParamTypeDescription
imageImageLike

.onImageReady<T>(image: T) ⇒ Promise<T>

Promise resolved once the image is ready to be used

Returns: A promise with the image, once it’s ready to be used.

ParamTypeDescription
imageTThe image, video, or canvas to wait for.
Template ParamType Definition
Textends ImageLike

.timeout(time: number) ⇒ Promise<void>

Schedule a timeout, resolving in time milliseconds.

Note: setTimeout being a macro-task, this method can be use as a debounce call.

Returns: A promise resolving in time ms.

ParamTypeDescription
timenumberThe time until it resolves, in milliseconds.