Class BasicXMLUIRootComponent

The base component for a lazy-widgets UI.

Hierarchy

Constructors

Properties

_engine: WonderlandEngine

Wonderland Engine instance.

Hidden

_id: number

Instance index.

Hidden

_manager: number

Manager index.

Hidden

_object: null | Object3D

Object containing this object.

Note: This is cached for faster retrieval.

Hidden

allowScripts: boolean

Should scripts in XML files be executed?

cloneMaterial: boolean

Should the material used for the Root be cloned? If false, then the actual material will be used, which will lead to issues if the material is also used elsewhere.

collisionGroupsMask: number

The collision groups that this root's collider will belong to. If 0, collider and cursor-target will not be added.

collisionOverextensionPixels: number

How many pixels to over-extend the collision by. For example, if 2, and the units-per-pixel is 0.01, then the collision extents will be expanded by 0.02 game units on all sides.

cursorStyleManagerName: string

Component name for cursor style manager

cursorStyleManagerObject: null | Object3D

Object with cursor style manager

destroyTextureWhenDisabled: boolean

When true, the UI texture will be destroyed to clear up space in the texture atlas whenever the UI root is disabled. Note that this will cause additional texture updates when re-enabling the UI root.

material: Material

Material to apply the canvas texture to

maxCanvasHeight: number

Maximum canvas (texture) height. If the height is exceeded, then the contents will be squeezed automatically to fit the texture.

maxCanvasWidth: number

Maximum canvas (texture) width. If the width is exceeded, then the contents will be squeezed automatically to fit the texture.

maxHeight: number

Maximum layout height. Must be a number greater than 0, or 0 if there is no maximum height.

maxWidth: number

Maximum layout width. Must be a number greater than 0, or 0 if there is no maximum width.

minHeight: number

Minimum layout height. Must be a number greater or equal to 0.

minWidth: number

Minimum layout width. Must be a number greater or equal to 0.

overextendCollisionOnCursorCapture: boolean

Should the collision extents only be expanded when the cursor is being captured?

preventAtlasBleeding: boolean

Should texture bleeding introduced from the texture atlas be prevented by adding a transparent black 1 pixel border to the canvas?

preventBleeding: boolean

Should texture bleeding introduced from old content be prevented by clearing areas with old content?

registerKeyboardDriver: boolean

Register the default keyboard driver to this root? true by default.

registerPointerDriver: boolean

Register the default pointer driver to this root? If collisionGroupsMask is zero, this is forced to false. true by default.

resolution: number

The resolution of the canvas. For example, if 2, then the resolution of the canvas will be doubled. If 0.5, then the resolution of the canvas will be halved.

The lazy-widgets UI root.

If initialization failed, this will be undefined. Make sure to guard references to this in case initialization fails, so that the console isn't spammed with errors unrelated to the failed initialization.

rootDestroyed: boolean = false

Was the root destroyed? Used to prevent data races in the loading logic.

textureUniformName: string

Which uniform name should be used for setting the material's texture? If not passed, then the uniform name will be guessed from the pipeline name, which will result in an error when an unknown pipeline is used.

uiTreeName: string

UI tree name in XML file. Defaults to 'default'

unitsPerPixel: number

The amount of world units per canvas pixel. Determines the pixel density of the mesh.

wantEnabled: boolean = false

Do we want the root to be enabled when it's created? Used to handle root toggling when the root isn't loaded yet

xmlUrl: string

URL to XML with UI

InheritProperties?: boolean

When set to true, the child class inherits from the parent properties, as shown in the following example:

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

class Parent extends Component {
static TypeName = 'parent';
static Properties = {parentName: Property.string('parent')}
}

class Child extends Parent {
static TypeName = 'child';
static Properties = {name: Property.string('child')}
static InheritProperties = true;

start() {
// Works because `InheritProperties` is `true`.
console.log(`${this.name} inherits from ${this.parentName}`);
}
}

Note

Properties defined in descendant classes will override properties with the same name defined in ancestor classes.

Defaults to true.

Properties: {
    allowScripts: ComponentProperty;
    registerKeyboardDriver: ComponentProperty;
    registerPointerDriver: ComponentProperty;
    uiTreeName: ComponentProperty;
    xmlUrl: ComponentProperty;
} = ...

Properties of this component class.

Properties are public attributes that can be configured via the Wonderland Editor.

Example:

import { Component, Type } from '@wonderlandengine/api';
class MyComponent extends Component {
static TypeName = 'my-component';
static Properties = {
myBoolean: { type: Type.Boolean, default: false },
myFloat: { type: Type.Float, default: false },
myTexture: { type: Type.Texture, default: null },
};
}

Properties are automatically added to each component instance, and are accessible like any JS attribute:

// Creates a new component and set each properties value:
const myComponent = object.addComponent(MyComponent, {
myBoolean: true,
myFloat: 42.0,
myTexture: null
});

// You can also override the properties on the instance:
myComponent.myBoolean = false;
myComponent.myFloat = -42.0;

References

Reference types (i.e., mesh, object, etc...) can also be listed as required:

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

class MyComponent extends Component {
static Properties = {
myObject: Property.object({required: true}),
myAnimation: Property.animation({required: true}),
myTexture: Property.texture({required: true}),
myMesh: Property.mesh({required: true}),
}
}

Please note that references are validated once before the call to Component.start only, via the Component.validateProperties method.

Type declaration

  • allowScripts: ComponentProperty
  • registerKeyboardDriver: ComponentProperty
  • registerPointerDriver: ComponentProperty
  • uiTreeName: ComponentProperty
  • xmlUrl: ComponentProperty
TypeName: string = 'basic-xml-ui-root'

Unique identifier for this component class.

This is used to register, add, and retrieve components of a given type.

_isBaseComponent: true = true

true for every class inheriting from this class.

Note

This is a workaround for instanceof to prevent issues that could arise when an application ends up using multiple API versions.

Hidden

Accessors

  • get active(): boolean
  • Whether this component is active

    Returns boolean

  • set active(active): void
  • Set whether this component is active.

    Activating/deactivating a component comes at a small cost of reordering components in the respective component manager. This function therefore is not a trivial assignment.

    Does nothing if the component is already activated/deactivated.

    Parameters

    • active: boolean

      New active state.

    Returns void

  • get engine(): WonderlandEngine
  • Hosting engine instance.

    Returns WonderlandEngine

  • get isDestroyed(): boolean
  • true if the component is destroyed, false otherwise.

    If WonderlandEngine.erasePrototypeOnDestroy is true, reading a custom property will not work:

    engine.erasePrototypeOnDestroy = true;

    const comp = obj.addComponent('mesh');
    comp.customParam = 'Hello World!';

    console.log(comp.isDestroyed); // Prints `false`
    comp.destroy();
    console.log(comp.isDestroyed); // Prints `true`
    console.log(comp.customParam); // Throws an error

    Returns boolean

    Since

    1.1.1

  • get object(): Object3D
  • The object this component is attached to.

    Returns Object3D

  • get type(): string
  • The name of this component's type

    Returns string

Methods

  • Trigger the component Component.init method.

    Returns void

    Note

    Use this method instead of directly calling Component.init, because this method creates an handler for the Component.start.

    Note

    This api is meant to be used internally.

    Hidden

  • Trigger the component Component.onDeactivate method.

    Returns void

    Note

    This api is meant to be used internally.

    Hidden

  • Trigger the component Component.update method.

    Parameters

    • dt: number

    Returns void

    Note

    This api is meant to be used internally.

    Hidden

  • Copy all the properties from src into this instance.

    Parameters

    • src: Record<string, any>

      The source component to copy from.

    Returns BasicXMLUIRootComponent

    Reference to self (for method chaining).

    Note

    Only properties are copied. If a component needs to copy extra data, it needs to override this method.

    Example

    class MyComponent extends Component {
    nonPropertyData = 'Hello World';

    copy(src) {
    super.copy(src);
    this.nonPropertyData = src.nonPropertyData;
    return this;
    }
    }

    Note

    This method is called by Object3D.clone. Do not attempt to: - Create new component - Read references to other objects

    When cloning via Object3D.clone, this method will be called before Component.start.

    Note

    JavaScript component properties aren't retargeted. Thus, references inside the source object will not be retargeted to the destination object, at the exception of the skin data on MeshComponent and AnimationComponent.

  • Remove this component from its objects and destroy it.

    It is best practice to set the component to null after, to ensure it does not get used later.

       c.destroy();
    c = null;

    Returns void

    Since

    0.9.0

  • Checks equality by comparing whether the wrapped native component ids and component manager types are equal.

    Parameters

    • otherComponent: undefined | null | Component

      Component to check equality with.

    Returns boolean

    Whether this component equals the given component.

  • Triggered when the component is started by the runtime, or activated.

    You can use that to re-initialize the state of the component.

    Returns void

  • Validate the properties on this instance.

    Returns void

    Throws

    If any of the required properties isn't initialized on this instance.

  • Allows to inherit properties directly inside the editor.

    Returns void

    Note

    Do not use directly, prefer using inheritProperties.

    Hidden

Generated using TypeDoc