Create a new instance
The engine instance.
Optional
manager: numberIndex of the manager.
Optional
id: numberWASM component instance index.
Protected
Readonly
_engineWonderland Engine instance.
Readonly
_idInstance index.
Readonly
_managerManager index.
Object containing this object.
Note: This is cached for faster retrieval.
Should scripts in XML files be executed?
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.
The collision groups that this root's collider will belong to. If 0, collider and cursor-target will not be added.
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.
Component name for cursor style manager
Object with cursor style manager
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 to apply the canvas texture to
Maximum canvas (texture) height. If the height is exceeded, then the contents will be squeezed automatically to fit the texture.
Maximum canvas (texture) width. If the width is exceeded, then the contents will be squeezed automatically to fit the texture.
Maximum layout height. Must be a number greater than 0, or 0 if there is no maximum height.
Maximum layout width. Must be a number greater than 0, or 0 if there is no maximum width.
Minimum layout height. Must be a number greater or equal to 0.
Minimum layout width. Must be a number greater or equal to 0.
Should the collision extents only be expanded when the cursor is being captured?
Should texture bleeding introduced from the texture atlas be prevented by adding a transparent black 1 pixel border to the canvas?
Should texture bleeding introduced from old content be prevented by clearing areas with old content?
Register the default keyboard driver to this root? true by default.
Register the default pointer driver to this root? If collisionGroupsMask is zero, this is forced to false. true by default.
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.
Protected
Optional
rootThe 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.
Protected
rootWas the root destroyed? Used to prevent data races in the loading logic.
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.
UI tree name in XML file. Defaults to 'default'
The amount of world units per canvas pixel. Determines the pixel density of the mesh.
Protected
wantDo we want the root to be enabled when it's created? Used to handle root toggling when the root isn't loaded yet
URL to XML with UI
Static
Optional
InheritWhen 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}`);
}
}
Properties defined in descendant classes will override properties with the same name defined in ancestor classes.
Defaults to true
.
Static
PropertiesProperties 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;
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.
Static
TypeUnique identifier for this component class.
This is used to register, add, and retrieve components of a given type.
Static
Readonly
_istrue
for every class inheriting from this class.
This is a workaround for instanceof
to prevent issues
that could arise when an application ends up using multiple API versions.
Whether this component is active
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.
New active state.
Hosting engine instance.
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
1.1.1
The object this component is attached to.
The name of this component's type
Trigger the component Component.init method.
Use this method instead of directly calling Component.init, because this method creates an handler for the Component.start.
This api is meant to be used internally.
Trigger the component Component.onActivate method.
This api is meant to be used internally.
Trigger the component Component.onDestroy method.
This api is meant to be used internally.
Protected
afterCalled after a lazy-widgets update is done on this UI root. Can optionally be implemented by child class.
Protected
beforeCalled before a lazy-widgets update is done on this UI root. Can optionally be implemented by child class. If any falsy value other than undefined is returned, then the update is skipped.
Copy all the properties from src
into this instance.
The source component to copy from.
Reference to self (for method chaining).
Only properties are copied. If a component needs to copy extra data, it needs to override this method.
class MyComponent extends Component {
nonPropertyData = 'Hello World';
copy(src) {
super.copy(src);
this.nonPropertyData = src.nonPropertyData;
return this;
}
}
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.
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.
Protected
createWLRootCreate the WLRoot to use for this UI. Can optionally be overridden by child class, but creates a WLRoot by default. If overriding and the WLRoot needs a widget created by the user, then call createWidgetGuarded to get a widget.
Protected
createCreate the child widget to use for the WLRoot of this UI. Must be implemented by child class. Note that if createWLRoot doesn't need a widget, then this won't be called and the method doesn't have to be implemented.
Optional
_properties: WLVirtualKeyboardRootPropertiesProtected
createSimilar to createWidget, except this method should be called instead of createWidget. If you are looking for a method to override and create a new widget, then override createWidget instead of this method.
Optional
properties: WLVirtualKeyboardRootPropertiesProtected
createXMLParserCreate an XML parser. Can be overridden, but creates a new XMLUIParser with the default widgets already registered by default.
Protected
getGet the properties to use for the WLRoot of this UI. Can optionally be implemented by child class. If not implemented, then the default options are used for the WLRoot, as well as some properties from the component specific to the Wonderland Engine integration.
Protected
getXMLParserGet the properties to use for the XML parser. Can optionally be implemented by child class. If not implemented, then the default options are used.
Protected
onCalled after the UI root of this component is ready. Can optionally be implemented by child class.
Protected
onUITreeCalled after the wanted UI tree is loaded. Can optionally be implemented by child class.
Protected
onXMLLoadedCalled after the XML is loaded. Can optionally be implemented by child class.
Protected
parseXMLParse the UI trees of an XML. Must be overridden.
Use Component.resetProperties instead.
Reset the component properties to default.
Reference to self (for method chaining).
This is automatically called during the component instantiation.
Optional
startStatic
_inheritStatic
onGenerated using TypeDoc
The base component for a lazy-widgets UI.