MeshRenderer
class for the mesh renderer
| Type | Name | Interface Description |
|---|---|---|
| Variables | mainMaterial: Material | null | • Function: Get the first shared material used by the MeshRenderer. Returns The first shared material used by the MeshRenderer, or null if none is assigned. |
| Variables | mainPass: Pass | null | • Function: Retrieves the main pass from the object's shared material. Returns The first pass of the shared material, or null if no passes are available. |
| Variables | mesh: Mesh | • Function: Retrieves the mesh associated with the MeshRenderer. Returns The mesh object. |
| Functions | constructor() | |
| Functions | getBoundingBox(): AABB | • Function: Retrieves the axis-aligned bounding box (AABB) for this mesh renderer. Returns The axis-aligned bounding box representing the bounds of the mesh. |
Examples
constructor()
let obj = new APJS.MeshRenderer();
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 {}
}