Renderer
APJS Script API reference for the Renderer class.
| Type | Name | Interface Description |
|---|---|---|
| Variables | autoSortingOrder: boolean | • Function: Indicates whether the sorting order is automatically managed. |
| Variables | materials: Material[] | • Function: Retrieves the shared materials used by the Renderer. |
| Variables | shadowMode: ShadowMode | • Function: Gets the shadow mode of the renderer. |
| Variables | sortingOrder: number | • Function: Gets the sorting order of the Renderer. Returns The current sorting order. |
| Functions | constructor() |
Examples
constructor()
let obj = new APJS.Renderer();
Use Case
Change a 3D object's material color at runtime via MeshRenderer.mainMaterial
@component()
export class MaterialColorChange extends APJS.BasicScriptComponent {
@serializeProperty
private targetColor: APJS.Color = new APJS.Color(1, 0, 0, 1);
onStart(): void {
this.applyColor(this.targetColor);
}
private applyColor(color: APJS.Color): void {
const renderer = this.getSceneObject().getComponent("MeshRenderer") as APJS.MeshRenderer;
// Use mainMaterial for single material access
// Use setVector (NOT setVector4 — it doesn't exist)
if (renderer && renderer.mainMaterial) {
renderer.mainMaterial.setVector("_AlbedoColor", new APJS.Vector4f(color.r, color.g, color.b, color.a));
}
}
onDestroy(): void {}
}