> ## 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.

# Add a roof

> Make a flat, gable, hip or shed roof from one outline.

export const LiveExample = ({path, title = 'Live example', height = 460}) => {
  return <Frame>
      <iframe src={`https://floorkit-examples.ploterr.com/floorkit/${path}?embed=1`} ref={frame => {
    if (!frame || !['localhost', '127.0.0.1'].includes(window.location.hostname)) return;
    const local = `http://localhost:5555/${path}?embed=1`;
    if (frame.src !== local) frame.src = local;
  }} title={title} loading="lazy" allow="fullscreen" style={{
    width: '100%',
    height: `${height}px`,
    border: 0,
    display: 'block'
  }} />
    </Frame>;
};

A roof starts from the outline of the walls below it. You select the roof type and the pitch, and Floorkit makes the roof planes.

<LiveExample path="guides/add-a-roof" />

## Before you start

You have a session from [Start a building](/floorkit/guides/start-a-building).

## Write the roof

This gable roof sits on the room from [Draw a wall](/floorkit/guides/draw-a-wall). Its outline is the outer face of the walls, 0.1 metres outside the wall path. Its eave is 3 metres above the storey elevation, at the top of the walls.

```typescript theme={null}
import { RoofType, type BmRoof, type BuildingSession } from '@opengeometry/floorkit';

export const mainRoof: BmRoof = {
  id: 'main-roof',
  profile: {
    outerRing: [
      [-0.1, -0.1],
      [6.1, -0.1],
      [6.1, 4.1],
      [-0.1, 4.1],
    ],
  },
  roofType: RoofType.GABLE,
  pitch: 30,
  overhang: 0.3,
  thickness: 0.2,
  baseOffset: 3,
};
```

## Add it to the storey

A roof is an entry in the `roofs` list of its storey.

```typescript theme={null}
export function addRoof(session: BuildingSession): void {
  session.apply(
    {
      kind: 'add-element',
      buildingId: 'building',
      storeyId: 'ground',
      list: 'roofs',
      element: mainRoof,
    },
    session.revision,
  );
}
```

The `add-element` command adds the roof to the list, and the session builds it. You keep the session and its undo history. The command rejects an id that the list has.

## Roof types

| `roofType` | Shape | Note |
| - | - | - |
| `RoofType.FLAT` | One level plate | The outline can have holes |
| `RoofType.GABLE` | Two planes that meet at a ridge | Set `ridgeDirection` to turn the ridge |
| `RoofType.HIP` | A plane on each side | The outline must be convex |
| `RoofType.SHED` | One sloped plane | |

In a JSON file, write the type as text: `"GABLE"`.

## Rules

* `pitch` is in degrees. `overhang` and `thickness` are in metres.
* `baseOffset` is the distance from the storey elevation to the eave.
* `overhang` moves the roof edge outward from the outline.
* A pitched roof cannot have holes.

## Next

<CardGroup cols={2}>
  <Card title="Add a stair" icon="stairs" href="/floorkit/guides/add-a-stair">
    Connect two storeys.
  </Card>

  <Card title="Roof API" icon="code" href="/floorkit/api/architecture/roof">
    See each option of a roof.
  </Card>
</CardGroup>


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