> ## Documentation Index
> Fetch the complete documentation index at: https://docs.ploterr.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Style instanced blocks

> Give the repeated blocks of a storey your own materials and colours, one block type or one copy at a time.

A storey draws the copies of one block instanced: one `THREE.InstancedMesh` draws a body of every copy. Thus a storey with 40 chairs draws each chair body one time, not 40 times. The copies stay real elements with their own ids and edits.

[Live example](https://floorkit-examples.ploterr.com/floorkit/guides/style-instanced-blocks?embed=1)

## Before you start

You have a session with a storey that has two or more copies of one block. See [Place furniture](https://docs.ploterr.com/floorkit/guides/place-furniture.md).

## Find the objects that draw the copies

Each object that draws copies has the name `instanced:<assetRef>:<bodyKey>` and the data `userData.floorkitInstanced`. Its `kind` is `surface`, `symbol-fill` or `symbol-lines`. The walls, slabs, roofs, columns, beams, stairs and railings of a storey draw through batches with the kind `batched` or `batched-outline`, and the lines and plan fills of a storey through `merged-lines` and `merged-fill`; the code below does not touch them. To style these elements, set their appearance.

```typescript theme={null}
import * as THREE from 'three';
import { isInstancedDrawable, type BuildingSession } from '@opengeometry/floorkit';

export function styleBlock(
  session: BuildingSession,
  assetRef: string,
  material: THREE.Material,
): void {
  session.root.traverse((object) => {
    if (!isInstancedDrawable(object) || !(object instanceof THREE.InstancedMesh)) return;
    const { kind, assetRef: drawn } = object.userData.floorkitInstanced;
    if (kind === 'surface' && drawn === assetRef) object.material = material;
  });
}
```

* Set the material on the instanced object, not on the copies. The copies are not drawn.
* Floorkit sets the material only when it makes the object. After an edit of a storey, the new object of the same name gets your material again.
* A new build of the session (an asset edit) makes new objects. Call `styleBlock` again in `session.subscribe`.

## Colour one copy

`elementIds[i]` is the element of instance `i`. One element can own several instances, such as the balusters of a railing.

```typescript theme={null}
export function colourCopy(
  mesh: THREE.InstancedMesh,
  elementId: string,
  colour: THREE.Color,
): void {
  const elementIds: readonly string[] = mesh.userData.floorkitInstanced.elementIds;
  elementIds.forEach((id, index) => {
    if (id === elementId) mesh.setColorAt(index, colour);
  });
  if (mesh.instanceColor) mesh.instanceColor.needsUpdate = true;
}
```

## Pick a copy

A raycaster hits the instanced object, not the copy. `instancedElementId(hit)` gives the id of the copy. A hit on a batched wall or slab has `batchId`; `instancedElementId(hit)` gives the id of that element too. See [instanced drawables](https://docs.ploterr.com/floorkit/api/architecture/instanced-drawables.md).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.