Constructor
new ModelComponent(system, entity)
Create a new ModelComponent
Parameters:
Name | Type | Description |
---|---|---|
system |
pc.ModelComponentSystem | The ComponentSystem that created this Component |
entity |
pc.Entity | The Entity that this Component is attached to. |
Properties:
Name | Type | Description |
---|---|---|
type |
String | The type of the model, which can be one of the following values:
|
asset |
pc.Asset | The asset for the model (only applies to models of type 'asset') - can also be an asset id. |
castShadows |
Boolean | If true, this model will cast shadows for lights that have shadow casting enabled. |
receiveShadows |
Boolean | If true, shadows will be cast on this model |
materialAsset |
Number | The material pc.Asset that will be used to render the model (not used on models of type 'asset') |
model |
pc.Model | The model that is added to the scene graph. It can be not set or loaded, so will return null. |
mapping |
Object | 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. |
castShadowsLightmap |
Boolean | If true, this model will cast shadows when rendering lightmaps |
lightmapped |
Boolean | If true, this model will be lightmapped after using lightmapper.bake() |
lightmapSizeMultiplier |
Number | Lightmap resolution multiplier |
isStatic |
Boolean | Mark model as non-movable (optimization) |
meshInstances |
Array.<pc.MeshInstance> | An array of meshInstances contained in the component's model. If model is not set or loaded for component it will return null. |
batchGroupId |
Number | Assign model to a specific batch group (see pc.BatchGroup). Default value is -1 (no group). |
layers |
Array | An array of layer IDs (pc.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. |
Extends
Methods
hide()
Stop rendering model without removing it from the scene hierarchy.
This method sets the pc.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.
Example
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;
}
show()
Enable rendering of the model if hidden using pc.ModelComponent#hide.
This method sets all the pc.MeshInstance#visible property on all mesh instances to true.