Renderer

Mesh Renderer

The MeshRenderer is a mesh renderer component that uses mesh objects (e.g., cuboids) as the geometry data source. When an entity is equipped with a mesh renderer component, simply set its mesh and material to render the object.

Usage

In the editor Hierarchy Panel, you can quickly create a node with a cuboid mesh renderer attached ( Hierarchy Panel -> Right-click -> 3D Object -> Cuboid ).

image-20231007153753006

Alternatively, you can manually attach a mesh renderer to an existing node in the scene and assign any mesh and material ( Select Node -> Inspector Panel -> Add Component -> Mesh Renderer ).

image-20231007153753006

Here's how to use it in code:

const cubeEntity = rootEntity.createChild("cube");
const cube = cubeEntity.addComponent(MeshRenderer);
cube.mesh = PrimitiveMesh.createCuboid(engine, 2, 2, 2);
cube.setMaterial(new BlinnPhongMaterial(engine));

Properties

In the editor, you can conveniently configure properties of the mesh renderer.

image-20231007153753006
PropertyDescription
materialMaterial information for the object to be rendered
meshMesh information for the object to be rendered
receiveShadowsWhether to receive shadows
castShadowsWhether to cast shadows
priorityRender priority. Lower values indicate higher priority. Default is 0

Compared to the basic Renderer, the mesh renderer also supports vertex color settings (vertex color data is included in the mesh's vertex information).

PropertyDescription
enableVertexColorWhether to support vertex colors

Methods

The mesh renderer does not add any new methods. However, note that a mesh often contains multiple sub-meshes. If you want each sub-mesh to use different materials, specify the corresponding mesh index during setup. Otherwise, the same material will be applied to all sub-meshes by default.

Was this page helpful?