Create a new ModelComponent instance.
The ComponentSystem that created this Component.
The Entity that this Component is attached to.
Private
_assetPrivate
_batchPrivate
_castPrivate
_castPrivate
_clonedPrivate
_customPrivate
_layersPrivate
_lightmapPrivate
_lightmappedPrivate
_mappingPrivate
_materialPrivate
_materialPrivate
_modelPrivate
_receivePrivate
_typeThe Entity that this Component is attached to.
Mark meshes as non-movable (optimization).
The ComponentSystem used to create this Component.
Assign model to a specific batch group (see BatchGroup). Default is -1 (no group).
If true, this model will cast shadows for lights that have shadow casting enabled.
If true, this model will cast shadows when rendering lightmaps.
If set, the object space bounding box is used as a bounding box for visibility culling of attached mesh instances. This is an optimization, allowing oversized bounding box to be specified for skinned characters in order to avoid per frame bounding box computations based on bone positions.
Enables or disables the component.
An array of layer IDs (Layer#id) to which this model should belong. Don't push, pop, splice or modify this array, if you want to change it - set a new one instead.
Lightmap resolution multiplier.
If true, this model will be lightmapped after using lightmapper.bake().
A dictionary that holds material overrides for each mesh instance. Only applies to model components of type 'asset'. The mapping contains pairs of mesh instance index - material asset id.
An array of meshInstances contained in the component's model. If model is not set or loaded for component it will return null.
If true, shadows will be cast on this model.
The type of the model. Can be:
Private
_bindPrivate
The material asset to bind events to.
Private
_bindPrivate
The model asset to bind events to.
Private
_getPrivate
_getPrivate
_loadPrivate
The material asset to load.
The mesh instance to assign the material to.
The index of the mesh instance.
Private
_onPrivate
The material asset on which an asset add event has been fired.
Private
_onPrivate
The material asset on which an asset change event has been fired.
Private
_onPrivate
The material asset on which an asset load event has been fired.
Private
_onPrivate
The material asset on which an asset remove event has been fired.
Private
_onPrivate
The material asset on which an asset unload event has been fired.
Private
_onPrivate
The model asset on which an asset add event has been fired.
Private
_onPrivate
The model asset on which an asset change event has been fired.
The attribute that was changed.
The new value of the attribute.
The old value of the attribute.
Private
_onPrivate
The model asset on which an asset load event has been fired.
Private
_onPrivate
The model asset on which an asset remove event has been fired.
Private
_onPrivate
The model asset on which an asset unload event has been fired.
Private
_setPrivate
The material to be set.
Private
_setPrivate
_unbindPrivate
The material asset to unbind events from.
Private
_unbindPrivate
The model asset to unbind events from.
Private
_unsetFire an event, all additional arguments are passed on to the event listener.
Name of event to fire.
Optional
arg1: anyFirst argument that is passed to the event handler.
Optional
arg2: anySecond argument that is passed to the event handler.
Optional
arg3: anyThird argument that is passed to the event handler.
Optional
arg4: anyFourth argument that is passed to the event handler.
Optional
arg5: anyFifth argument that is passed to the event handler.
Optional
arg6: anySixth argument that is passed to the event handler.
Optional
arg7: anySeventh argument that is passed to the event handler.
Optional
arg8: anyEighth argument that is passed to the event handler.
Self for chaining.
obj.fire('test', 'This is the message');
Test if there are any handlers bound to an event name.
The name of the event to test.
True if the object has handlers bound to the specified event name.
obj.on('test', function () { }); // bind an event to 'test'
obj.hasEvent('test'); // returns true
obj.hasEvent('hello'); // returns false
Stop rendering model without removing it from the scene hierarchy. This method sets the MeshInstance#visible property of every MeshInstance in the model to false Note, this does not remove the model or mesh instances from the scene hierarchy or draw call list. So the model component still incurs some CPU overhead.
this.timer = 0;
this.visible = true;
// ...
// blink model every 0.1 seconds
this.timer += dt;
if (this.timer > 0.1) {
if (!this.visible) {
this.entity.model.show();
this.visible = true;
} else {
this.entity.model.hide();
this.visible = false;
}
this.timer = 0;
}
Detach an event handler from an event. If callback is not provided then all callbacks are unbound from the event, if scope is not provided then all events with the callback will be unbound.
Optional
name: stringName of the event to unbind.
Optional
callback: HandleEventCallbackFunction to be unbound.
Optional
scope: objectScope that was used as the this when the event is fired.
Self for chaining.
const handler = function () {
};
obj.on('test', handler);
obj.off(); // Removes all events
obj.off('test'); // Removes all events called 'test'
obj.off('test', handler); // Removes all handler functions, called 'test'
obj.off('test', handler, this); // Removes all handler functions, called 'test' with scope this
Attach an event handler to an event.
Name of the event to bind the callback to.
Function that is called when event is fired. Note the callback is limited to 8 arguments.
Optional
scope: object = ...Object to use as 'this' when the event is fired, defaults to current this.
Can be used for removing event in the future.
obj.on('test', function (a, b) {
console.log(a + b);
});
obj.fire('test', 1, 2); // prints 3 to the console
const evt = obj.on('test', function (a, b) {
console.log(a + b);
});
// some time later
evt.off();
Private
onPrivate
The layer that was added.
Private
onPrivate
The layer that was removed.
Private
onPrivate
The old layer composition.
The new layer composition.
Attach an event handler to an event. This handler will be removed after being fired once.
Name of the event to bind the callback to.
Function that is called when event is fired. Note the callback is limited to 8 arguments.
Optional
scope: object = ...Object to use as 'this' when the event is fired, defaults to current this.
obj.once('test', function (a, b) {
console.log(a + b);
});
obj.fire('test', 1, 2); // prints 3 to the console
obj.fire('test', 1, 2); // not going to get handled
Enable rendering of the model if hidden using ModelComponent#hide. This method sets all the MeshInstance#visible property on all mesh instances to true.
Enables an Entity to render a model or a primitive shape. This Component attaches additional model geometry in to the scene graph below the Entity.