Skip to content

API Class MeshRenderer

github-actions[bot] edited this page Nov 25, 2026 · 7 revisions

Class: MeshRenderer

Defined in: src/engine/render/components.ts:373

Draws a mesh with a material (ADR 0043, 0044). mesh is a model asset (asset:models/robot.fbx draws all its meshes, asset:models/robot.fbx#Body one of them) or a built-in mesh (builtin:cube, sphere, capsule, cylinder, plane, quad). Meshes are lit by the World's Lights; a World with no Light gets a default sun and ambient light.

Extends

Constructors

Constructor

new MeshRenderer(): MeshRenderer;

Returns

MeshRenderer

Inherited from

Component.constructor

Properties

castShadows

castShadows: boolean = true;

Defined in: src/engine/render/components.ts:388

Cast shadows from Lights with castShadows on.


material

material: string = "";

Defined in: src/engine/render/components.ts:379

A material asset (asset:materials/wood.material.json). Empty: the model's own materials, or the default material (white, lit) for meshes without one.


materials

materials: string[] = [];

Defined in: src/engine/render/components.ts:386

A material asset per material slot (ADR 0089), drawn in place of material for that slot. The slots are the model's own materials, in the order its meshes first use them (a built-in mesh has one); an empty entry, or none, leaves the slot to material, then to the model's import settings, then to the model's own material.


mesh

mesh: string = "builtin:cube";

Defined in: src/engine/render/components.ts:374


receiveShadows

receiveShadows: boolean = true;

Defined in: src/engine/render/components.ts:390

Show shadows cast onto it.


variant

variant: string = "";

Defined in: src/engine/render/components.ts:396

The model's material variant to draw (glTF KHR_materials_variants, ADR 0118), by name; empty draws the file's default materials. It changes only slots drawing the model's own material: a slot with a material asset keeps it. The choices are variants.

Accessors

enabled

Get Signature

get enabled(): boolean;

Defined in: src/engine/core/Component.ts:57

Returns

boolean

Set Signature

set enabled(value): void;

Defined in: src/engine/core/Component.ts:61

Parameters
value

boolean

Returns

void

Inherited from

Component.enabled


gameObject

Get Signature

get gameObject(): GameObject;

Defined in: src/engine/core/Component.ts:37

Unity-style alias for node.

Returns

GameObject

Inherited from

Component.gameObject


isActiveAndEnabled

Get Signature

get isActiveAndEnabled(): boolean;

Defined in: src/engine/core/Component.ts:68

True when enabled, the node is active in the hierarchy, and the node is in a loaded world.

Returns

boolean

Inherited from

Component.isActiveAndEnabled


materialInstance

Get Signature

get materialInstance(): Material;

Defined in: src/engine/render/components.ts:472

Slot 0's own Material (Unity's renderer.material; getMaterialInstance(0)).

Returns

Material


node

Get Signature

get node(): GameObject;

Defined in: src/engine/core/Component.ts:32

The node this component is on.

Returns

GameObject

Inherited from

Component.node


owner

Get Signature

get owner(): GameObject;

Defined in: src/engine/core/Component.ts:45

The node this component acts for: the node itself when attached directly, or the parent node when this component lives on a component node (ADR 0009).

Returns

GameObject

Inherited from

Component.owner


sharedMaterial

Get Signature

get sharedMaterial(): Material | null;

Defined in: src/engine/render/components.ts:463

The Material slot 0 draws (getSharedMaterial(0)); assigning sets slot 0 (setSharedMaterial(0, m)). A renderer without material slots has only slot 0, drawn by every mesh.

Returns

Material | null

Set Signature

set sharedMaterial(m): void;

Defined in: src/engine/render/components.ts:467

Parameters
m

Material | null

Returns

void


sharedMaterials

Get Signature

get sharedMaterials(): (Material | null)[];

Defined in: src/engine/render/components.ts:481

Every slot's Material (Unity's sharedMaterials): slot 0, then the slots materials lists or Materials were assigned to. The model decides how many slots it has (ADR 0089); a slot past the list draws material.

Returns

(Material | null)[]

Set Signature

set sharedMaterials(ms): void;

Defined in: src/engine/render/components.ts:486

Parameters
ms

readonly (Material | null)[]

Returns

void


time

Get Signature

get time(): Readonly<TimeState>;

Defined in: src/engine/core/Component.ts:93

This component's World's clock (ADR 0032): the same values as Time, but safe to read outside the World's frame too (after an await, say).

Returns

Readonly<TimeState>

Inherited from

Component.time


transform

Get Signature

get transform(): Transform;

Defined in: src/engine/core/Component.ts:51

The Transform of the node this component is on, if it has one.

Returns

Transform

Inherited from

Component.transform


variants

Get Signature

get variants(): readonly string[];

Defined in: src/engine/render/components.ts:399

The names of the material variants the model offers (ADR 0118): empty until it has loaded, or for a model without variants.

Returns

readonly string[]


world

Get Signature

get world(): WorldHandle;

Defined in: src/engine/core/Component.ts:82

A handle on this component's World (ADR 0132): the same one Engine.findWorld returns. Load a scene into it, pause, connect or destroy it: this.world.loadScene("scenes/level2.scene.json"). Throws for a World no Engine owns.

Returns

WorldHandle

Inherited from

Component.world

Methods

clearMaterialProperties()

clearMaterialProperties(slot?): void;

Defined in: src/engine/render/components.ts:552

Go back to the material's own values for every property (of the slot slot, or, without it, the whole renderer's).

Parameters

slot?

number

Returns

void


clearMaterialProperty()

clearMaterialProperty(name, slot?): void;

Defined in: src/engine/render/components.ts:540

Go back to the material's own value for one property.

Parameters

name

string

slot?

number

Returns

void


getMaterialInstance()

getMaterialInstance(slot?): Material;

Defined in: src/engine/render/components.ts:453

Slot slot's own Material (Unity's renderer.materials[i], ADR 0107): made on first access as a copy of the slot's shared Material (its values at that moment), then kept. It draws apart from the instanced batch of its mesh. A slot without a material asset gets an instance of the default lit material.

Parameters

slot?

number = 0

Returns

Material


getMaterialProperty()

getMaterialProperty(name, slot?): 
  | MaterialPropertyValue
  | undefined;

Defined in: src/engine/render/components.ts:535

The value set with setMaterialProperty, or undefined when the material's own value is used.

Parameters

name

string

slot?

number

Returns

| MaterialPropertyValue | undefined


getSharedMaterial()

getSharedMaterial(slot?): Material | null;

Defined in: src/engine/render/components.ts:434

The Material slot slot draws (ADR 0107): its material asset's shared Material (changing it changes every renderer drawing that asset), or a Material assigned to the slot. Null when the slot has no material asset (the model's own material).

Parameters

slot?

number = 0

Returns

Material | null


instantiate()

instantiate(prefabPath, options?): GameObject;

Defined in: src/engine/core/Component.ts:103

Instantiate a prefab in this component's World (ADR 0034), like GameObject.instantiate. Use it in code that may run after an await: by then the frame is over and the current World is the Engine's default one, which may not be this component's. A parent from another World throws.

Parameters

prefabPath

string

options?

InstantiateOptions = {}

Returns

GameObject

Inherited from

Component.instantiate


setMaterialProperty()

setMaterialProperty(
   name, 
   value, 
   slot?
): void;

Defined in: src/engine/render/components.ts:521

Override one of the material's properties for this renderer only (ADR 0049), like Unity's MaterialPropertyBlock: the material asset and other renderers are unchanged. Names are a shader graph's property names, or color, emission, metalness, roughness and texture for the built-in lit and unlit materials. A texture is an asset path.

With slot (ADR 0371: an animation's materials[slot].<name> track), the override is for that material slot only, whatever draws it (the model's own material included), and the built-in names also take the glTF ones: alphaCutoff, normalScale, occlusionStrength, clearcoatNormalScale, dispersion, attenuationColor, attenuationDistance, iridescenceThicknessMinimum, iridescenceThicknessMaximum and textureTransform.offset, .scale and .rotation. A slot's colours are linear (as a model surface holds them), not sRGB.

Parameters

name

string

value

MaterialPropertyValue

slot?

number

Returns

void


setSharedMaterial()

setSharedMaterial(slot, m): void;

Defined in: src/engine/render/components.ts:442

Draw m in slot slot: a shared Material sets the slot's asset path; an instance is drawn as it is (renderers may share one). Null clears the slot.

Parameters

slot

number

m

Material | null

Returns

void

Clone this wiki locally