
Mirror Engine API / MeshInstance
Class: MeshInstance
An instance of a Mesh. A single mesh can be referenced by many mesh instances that can have different transforms and materials.
Constructors
new MeshInstance()
new MeshInstance(
mesh: Mesh,
material: Material,
node?: GraphNode): MeshInstance
Create a new MeshInstance instance.
Parameters
mesh
The graphics mesh to instance.
material
The material to use for this mesh instance.
node?
GraphNode
= null
The graph node defining the transform for this instance. This parameter is optional when used with RenderComponent and will use the node the component is attached to.
Returns
Example
// Create a mesh instance pointing to a 1x1x1 'cube' mesh
const mesh = Mesh.fromGeometry(app.graphicsDevice, new BoxGeometry())
const material = new StandardMaterial()
const meshInstance = new MeshInstance(mesh, material)
const entity = new Entity()
entity.addComponent('render', {
meshInstances: [
meshInstance
]
})
// Add the entity to the scene hierarchy
this.app.scene.root.addChild(entity)
Properties
castShadow
castShadow: boolean = false
Enable shadow casting for this mesh instance. Use this property to enable/disable shadow casting without overhead of removing from scene. Note that this property does not add the mesh instance to appropriate list of shadow casters on a Layer, but allows mesh to be skipped from shadow casting while it is in the list already. Defaults to false.
cull
cull: boolean = true
Controls whether the mesh instance can be culled by frustum culling (see CameraComponent#frustumCulling). Defaults to true.
drawOrder
drawOrder: number = 0
Determines the rendering order of mesh instances. Only used when mesh instances are added to a Layer with Layer#opaqueSortMode or Layer#transparentSortMode (depending on the material) set to SORTMODE_MANUAL.
node
node: GraphNode
The graph node defining the transform for this instance.
visible
visible: boolean = true
Enable rendering for this mesh instance. Use visible property to enable/disable rendering without overhead of removing from scene. But note that the mesh instance is still in the hierarchy and still in the draw call list.
visibleThisFrame
visibleThisFrame: boolean = false
Read this value in Scene#EVENT_POSTCULL event to determine if the object is actually going to be rendered.
aabb
Get Signature
get aabb(): BoundingBox
Gets the world space axis-aligned bounding box for this mesh instance.
Returns
Set Signature
set aabb(aabb: BoundingBox): void
Sets the world space axis-aligned bounding box for this mesh instance.
Parameters
aabb
Returns
void
calculateSortDistance
Get Signature
get calculateSortDistance(): null | CalculateSortDistanceCallback
Gets the callback to calculate sort distance.
Returns
null
| CalculateSortDistanceCallback
Set Signature
set calculateSortDistance(calculateSortDistance: null | CalculateSortDistanceCallback): void
Sets the callback to calculate sort distance. In some circumstances mesh instances are sorted by a distance calculation to determine their rendering order. Set this callback to override the default distance calculation, which gives the dot product of the camera forward vector and the vector between the camera position and the center of the mesh instance's axis-aligned bounding box. This option can be particularly useful for rendering transparent meshes in a better order than the default.
Parameters
calculateSortDistance
null
| CalculateSortDistanceCallback
Returns
void
drawBucket
Get Signature
get drawBucket(): number
Gets the draw bucket for mesh instance.
Returns
number
Set Signature
set drawBucket(bucket: number): void
Sets the draw bucket for mesh instances. The draw bucket, an integer from 0 to 255 (default 127), serves as the primary sort key for mesh rendering. Meshes are sorted by draw bucket, then by sort mode. This setting is only effective when mesh instances are added to a Layer with its Layer#opaqueSortMode or Layer#transparentSortMode (depending on the material) set to SORTMODE_BACK2FRONT, SORTMODE_FRONT2BACK, or SORTMODE_MATERIALMESH.
Note: When SORTMODE_BACK2FRONT is used, a descending sort order is used; otherwise, an ascending sort order is used.
Parameters
bucket
number
Returns
void
instancingCount
Get Signature
get instancingCount(): number
Gets the number of instances when using hardware instancing to render the mesh.
Returns
number
Set Signature
set instancingCount(value: number): void
Sets the number of instances when using hardware instancing to render the mesh.
Parameters
value
number
Returns
void
mask
Get Signature
get mask(): number
Gets the mask controlling which LightComponents light this mesh instance, which CameraComponent sees it and in which Layer it is rendered.
Returns
number
Set Signature
set mask(val: number): void
Sets the mask controlling which LightComponents light this mesh instance, which CameraComponent sees it and in which Layer it is rendered. Defaults to 1.
Parameters
val
number
Returns
void
material
Get Signature
get material(): Material
Gets the material used by this mesh instance.
Returns
Set Signature
set material(material: Material): void
Sets the material used by this mesh instance.
Parameters
material
Returns
void
mesh
Get Signature
get mesh(): Mesh
Gets the graphics mesh being instanced.
Returns
Set Signature
set mesh(mesh: Mesh): void
Sets the graphics mesh being instanced.
Parameters
mesh
Returns
void
morphInstance
Get Signature
get morphInstance(): null | MorphInstance
Gets the morph instance managing morphing of this mesh instance.
Returns
null
| MorphInstance
Set Signature
set morphInstance(val: null | MorphInstance): void
Sets the morph instance managing morphing of this mesh instance. Set to null if morphing is not used.
Parameters
val
null
| MorphInstance
Returns
void
renderStyle
Get Signature
get renderStyle(): number
Gets the render style of the mesh instance.
Returns
number
Set Signature
set renderStyle(renderStyle: number): void
Sets the render style of the mesh instance. Can be:
Defaults to RENDERSTYLE_SOLID.
Parameters
renderStyle
number
Returns
void
skinInstance
Get Signature
get skinInstance(): null | SkinInstance
Gets the skin instance managing skinning of this mesh instance.
Returns
null
| SkinInstance
Set Signature
set skinInstance(val: null | SkinInstance): void
Sets the skin instance managing skinning of this mesh instance. Set to null if skinning is not used.
Parameters
val
null
| SkinInstance
Returns
void
Methods
deleteParameter()
deleteParameter(name: string): void
Deletes a shader parameter on a mesh instance.
Parameters
name
string
The name of the parameter to delete.
Returns
void
getParameter()
getParameter(name: string): any
Retrieves the specified shader parameter from a mesh instance.
Parameters
name
string
The name of the parameter to query.
Returns
any
The named parameter.
setInstancing()
setInstancing(vertexBuffer: null | VertexBuffer, cull: boolean): void
Sets up MeshInstance to be rendered using Hardware Instancing.
Parameters
vertexBuffer
Vertex buffer to hold per-instance vertex data (usually world matrices). Pass null to turn off hardware instancing.
null
| VertexBuffer
cull
boolean
= false
Whether to perform frustum culling on this instance. If true, the whole instance will be culled by the camera frustum. This often involves setting RenderComponent#customAabb containing all instances. Defaults to false, which means the whole instance is always rendered.
Returns
void
setParameter()
setParameter(
name: string,
data:
| number
| number[]
| Float32Array<ArrayBufferLike>
| Texture,
passFlags?: number): void
Sets a shader parameter on a mesh instance. Note that this parameter will take precedence over parameter of the same name if set on Material this mesh instance uses for rendering.
Parameters
name
string
The name of the parameter to set.
data
The value for the specified parameter.
number
| number
[] | Float32Array
<ArrayBufferLike
> | Texture
passFlags?
number
= 0xFFFFFFFF
Mask describing which passes the material should be included in. Defaults to 0xFFFFFFFF (all passes).
Returns
void