# RenderComponent

Class · extends [`Component`](https://api.playcanvas.com/engine/classes/Component.md) · category: Graphics

Source: https://github.com/playcanvas/engine/blob/b5b983982a9860d21e0c1dafb2f85f72e2c01afb/src/framework/components/render/component.js#L61

The RenderComponent enables an [Entity](https://api.playcanvas.com/engine/classes/Entity.md) to render 3D meshes. The [type](https://api.playcanvas.com/engine/classes/RenderComponent.md#type) property can
be set to one of several predefined shapes (such as `box`, `sphere`, `cone` and so on).
Alternatively, the component can be configured to manage an arbitrary array of
[MeshInstance](https://api.playcanvas.com/engine/classes/MeshInstance.md)s. These can either be created programmatically or loaded from an
[Asset](https://api.playcanvas.com/engine/classes/Asset.md).

The [MeshInstance](https://api.playcanvas.com/engine/classes/MeshInstance.md)s managed by this component are positioned, rotated, and scaled in world
space by the world transformation matrix of the owner [Entity](https://api.playcanvas.com/engine/classes/Entity.md). This world matrix is
derived by combining the entity's local transformation (position, rotation, and scale) with the
world transformation matrix of its parent entity in the scene hierarchy.

You should never need to use the RenderComponent constructor directly. To add a RenderComponent
to an Entity, use [Entity#addComponent](https://api.playcanvas.com/engine/classes/Entity.md#addcomponent):

```javascript
const entity = new Entity();
entity.addComponent('render', {
    type: 'box'
});
```

Once the RenderComponent is added to the entity, you can access it via the [Entity#render](https://api.playcanvas.com/engine/classes/Entity.md#render)
property:

```javascript
entity.render.type = 'capsule';  // Set the render component's type

console.log(entity.render.type); // Get the render component's type and print it
```

Relevant Engine API examples:

- [Loading Render Assets](https://playcanvas.github.io/#/graphics/render-asset)
- [Primitive Shapes](https://playcanvas.github.io/#/graphics/shapes)
- [Spinning Cube](https://playcanvas.github.io/#/misc/hello-world)

## Properties

### isStatic

```ts
isStatic: boolean = false
```

Mark meshes as non-movable (optimization).

## Accessors

### asset

```ts
get asset(): number
set asset(value: number)
```

Gets the render asset id for the render component.

### batchGroupId

```ts
get batchGroupId(): number
set batchGroupId(value: number)
```

Gets the batch group for the mesh instances in this component (see [BatchGroup](https://api.playcanvas.com/engine/classes/BatchGroup.md)).

### castShadows

```ts
get castShadows(): boolean
set castShadows(value: boolean)
```

Gets whether attached meshes will cast shadows for lights that have shadow casting enabled.

### castShadowsLightmap

```ts
get castShadowsLightmap(): boolean
set castShadowsLightmap(value: boolean)
```

Gets whether meshes instances will cast shadows when rendering lightmaps.

### customAabb

```ts
get customAabb(): BoundingBox | null
set customAabb(value: BoundingBox | null)
```

Gets the custom object space bounding box that is used for visibility culling of attached
mesh instances.

### layers

```ts
get layers(): readonly number[]
set layers(value: readonly number[])
```

Gets the array of layer IDs ([Layer#id](https://api.playcanvas.com/engine/classes/Layer.md#id)) to which the mesh instances belong.

### lightmapped

```ts
get lightmapped(): boolean
set lightmapped(value: boolean)
```

Gets whether the component is affected by the runtime lightmapper.

### lightmapSizeMultiplier

```ts
get lightmapSizeMultiplier(): number
set lightmapSizeMultiplier(value: number)
```

Gets the lightmap resolution multiplier.

### material

```ts
get material(): Material
set material(value: Material)
```

Gets the material [Material](https://api.playcanvas.com/engine/classes/Material.md) that will be used to render the component.

### materialAssets

```ts
get materialAssets(): number[] | Asset[]
set materialAssets(value?: number[] | Asset[])
```

Gets the material assets that will be used to render the component.

### meshInstances

```ts
get meshInstances(): readonly MeshInstance[]
set meshInstances(value: readonly MeshInstance[])
```

Gets the array of meshInstances contained in the component. Use the setter to replace the
array; do not mutate the returned array.

### receiveShadows

```ts
get receiveShadows(): boolean
set receiveShadows(value: boolean)
```

Gets whether shadows will be cast on attached meshes.

### renderStyle

```ts
get renderStyle(): number
set renderStyle(renderStyle: number)
```

Gets the render style of this component's [MeshInstance](https://api.playcanvas.com/engine/classes/MeshInstance.md)s.

### rootBone

```ts
get rootBone(): Entity | null
set rootBone(value: Entity | null)
```

Gets the root bone entity for the render component.

### shadowCascadeMask

```ts
get shadowCascadeMask(): number
set shadowCascadeMask(value: number)
```

Gets the bitmask that controls which shadow cascades the attached meshes contribute to.

### type

```ts
get type(): "plane" | "box" | "asset" | "capsule" | "cone" | "cylinder" | "sphere" | "torus"
set type(value: "plane" | "box" | "asset" | "capsule" | "cone" | "cylinder" | "sphere" | "torus")
```

Gets the type of the component.

## Methods

### hide

```ts
hide(): void
```

Stop rendering [MeshInstance](https://api.playcanvas.com/engine/classes/MeshInstance.md)s without removing them from the scene hierarchy. This
method sets the [MeshInstance#visible](https://api.playcanvas.com/engine/classes/MeshInstance.md#visible) property of every MeshInstance to false. Note,
this does not remove the mesh instances from the scene hierarchy or draw call list. So the
render component still incurs some CPU overhead.

### show

```ts
show(): void
```

Enable rendering of the component's [MeshInstance](https://api.playcanvas.com/engine/classes/MeshInstance.md)s if hidden using [hide](https://api.playcanvas.com/engine/classes/RenderComponent.md#hide). This
method sets the [MeshInstance#visible](https://api.playcanvas.com/engine/classes/MeshInstance.md#visible) property on all mesh instances to true.

## Inherited from [Component](https://api.playcanvas.com/engine/classes/Component.md)

- `entity: Entity`
- `system: ComponentSystem`
- `get enabled(): boolean` · `set enabled(value: boolean)`
- `fire(name: string, arg1?: any, arg2?: any, arg3?: any, arg4?: any, arg5?: any, arg6?: any, arg7?: any, arg8?: any): EventHandler`
- `hasEvent(name: string): boolean`
- `off(name?: string, callback?: HandleEventCallback, scope?: any): EventHandler`
- `on(name: string, callback: HandleEventCallback, scope?: any): EventHandle`
- `once(name: string, callback: HandleEventCallback, scope?: any): EventHandle`
