An instance of a Mesh. A single mesh can be referenced by many mesh instances that can have different transforms and materials.
new MeshInstance(
mesh: Mesh,
material: Material,
node?: GraphNode): MeshInstance
Create a new MeshInstance instance.
The graphics mesh to instance.
The material to use for this mesh instance.
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.
// 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)
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: boolean = true
Controls whether the mesh instance can be culled by frustum culling (see CameraComponent#frustumCulling). Defaults to true.
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: GraphNode
The graph node defining the transform for this instance.
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: boolean = false
Read this value in Scene#EVENT_POSTCULL event to determine if the object is actually going to be rendered.
get aabb(): BoundingBox
Gets the world space axis-aligned bounding box for this mesh instance.
set aabb(aabb: BoundingBox): void
Sets the world space axis-aligned bounding box for this mesh instance.
void
get calculateSortDistance(): null | CalculateSortDistanceCallback
Gets the callback to calculate sort distance.
null | CalculateSortDistanceCallback
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.
null | CalculateSortDistanceCallback
void
get drawBucket(): number
Gets the draw bucket for mesh instance.
number
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.
number
void
get instancingCount(): number
Gets the number of instances when using hardware instancing to render the mesh.
number
set instancingCount(value: number): void
Sets the number of instances when using hardware instancing to render the mesh.
number
void
get mask(): number
Gets the mask controlling which LightComponents light this mesh instance, which CameraComponent sees it and in which Layer it is rendered.
number
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.
number
void
get material(): Material
Gets the material used by this mesh instance.
set material(material: Material): void
Sets the material used by this mesh instance.
void
get mesh(): Mesh
Gets the graphics mesh being instanced.
set mesh(mesh: Mesh): void
Sets the graphics mesh being instanced.
void
get morphInstance(): null | MorphInstance
Gets the morph instance managing morphing of this mesh instance.
null | MorphInstance
set morphInstance(val: null | MorphInstance): void
Sets the morph instance managing morphing of this mesh instance. Set to null if morphing is not used.
null | MorphInstance
void
get renderStyle(): number
Gets the render style of the mesh instance.
number
set renderStyle(renderStyle: number): void
Sets the render style of the mesh instance. Can be:
Defaults to RENDERSTYLE_SOLID.
number
void
get skinInstance(): null | SkinInstance
Gets the skin instance managing skinning of this mesh instance.
null | SkinInstance
set skinInstance(val: null | SkinInstance): void
Sets the skin instance managing skinning of this mesh instance. Set to null if skinning is not used.
null | SkinInstance
void
deleteParameter(name: string): void
Deletes a shader parameter on a mesh instance.
string
The name of the parameter to delete.
void
getParameter(name: string): any
Retrieves the specified shader parameter from a mesh instance.
string
The name of the parameter to query.
any
The named parameter.
setInstancing(vertexBuffer: null | VertexBuffer, cull: boolean): void
Sets up MeshInstance to be rendered using Hardware Instancing.
Vertex buffer to hold per-instance vertex data (usually world matrices). Pass null to turn off hardware instancing.
null | VertexBuffer
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.
void
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.
string
The name of the parameter to set.
The value for the specified parameter.
number | number | Float32Array<ArrayBufferLike> | Texture
number = 0xFFFFFFFF
Mask describing which passes the material should be included in. Defaults to 0xFFFFFFFF (all passes).
void