# Roofs

"The roof is the number-one giveaway of a beginner build." A flat lid the same size as the
walls says nothing; a roof with pitch, overhang, planes and a finished ridge says everything
about the style. Do the roof before you commit to a palette: its shape sets the silhouette and
its colour is a large share of the palette.

## What a good roof has

For an ordinary building with a conventional roof. A dome, a flat deck, a green roof, an open
frame or no roof at all can be exactly right; then ask what the roof is doing for the build
(shelter, silhouette, a focal point, a clean line) and do that deliberately.

1. **Pitch** that suits the style (below). Flat roofs on a pitched style are the classic tell.
2. **An overhang** of one or two cells past the walls, on every side that has an eave. A roof
   that cuts straight into the wall looks unfinished. The overhang casts the shadow line that
   makes the walls read as walls. Give gable ends an overhang too.
3. **More than one plane.** A single huge slope is dull. Add a cross gable, a dormer, a
   lean-to, a hip on one end, a change of height between wings, or a break in the pitch.
4. **A finished ridge and edges.** Cap the ridge with slabs, inverted stairs or another
   material. Edge the eave with a row of upside-down stairs or slabs for thickness.
5. **A thick-looking edge.** Real roofs have thickness. Add a layer under the eave (slabs or
   trapdoors, upside-down stairs) so the edge is not paper thin.
6. **Material contrast with the wall.** A dark roof over light walls (or the reverse) is the
   easiest way to get value contrast.
7. **Things on it**: chimneys, dormers, vents, finials, weathervanes.

## Pitch in voxels

| Pitch | How | Reads as |
| --- | --- | --- |
| Gentle, 1 up for 2 across | Alternate rows of slabs and stairs | Low, wide: farmhouse, Mediterranean, modern pitched |
| 45 degrees, 1 for 1 | A diagonal of stairs | The standard house roof |
| Steep, 2 up for 1 across | Each step is a full block topped by a stair | Gothic, timber, thatch. Thatch needs about 45 degrees at least |
| Flat | Slabs with a parapet | Modern, industrial, desert, castle tops |

Mass it first with plain boxes. This is a gable roof over the 21 by 13 shell from the
[workflow](workflow.md), with a one-cell overhang on every side, as stepped slices:

```call
fill {"where": {"box": [-1, 7, -1, 21, 7, 13]}, "semantic": "Roof"}
fill {"where": {"box": [-1, 8, 0, 21, 8, 12]}, "semantic": "Roof"}
fill {"where": {"box": [-1, 9, 1, 21, 9, 11]}, "semantic": "Roof"}
fill {"where": {"box": [-1, 10, 2, 21, 10, 10]}, "semantic": "Roof"}
fill {"where": {"box": [-1, 11, 3, 21, 11, 9]}, "semantic": "Roof"}
fill {"where": {"box": [-1, 12, 4, 21, 12, 8]}, "semantic": "Roof"}
fill {"where": {"box": [-1, 13, 5, 21, 13, 7]}, "semantic": "Roof"}
fill {"where": {"box": [-1, 14, 6, 21, 14, 6]}, "semantic": "Roof"}
```

Look at it in `clay` from the side. Is the pitch right? Is the overhang visible? Then replace
the steps with stairs and slabs, which smooth the profile and give you the half-step options
(`place` with `facing` and `up`).

**Which way a roof stair faces.** A stair's `facing` is the way it *climbs*: its tall back is on
that side and its steps face the opposite way. So every stair on a slope faces **up** the slope,
toward the ridge. For the ridge above (it runs along X), the north slope rises toward the south
and the south slope rises toward the north:

```call-live
fill {"where": {"box": [-1, 7, -1, 21, 7, -1]}, "semantic": "Roof", "facing": "south", "up": "up"}
fill {"where": {"box": [-1, 7, 13, 21, 7, 13]}, "semantic": "Roof", "facing": "north", "up": "up"}
```

(one row per height step, the same way, with the row moving one cell toward the ridge each time).
Stairs placed the other way round read as a slatted, upside-down staircase: from the end
(`capture_sheet` elevations, or a `side` view) the roof edge should be one clean diagonal, with
the steps' flat treads showing on the outside and the tall backs against the roof below the
ridge. If you see a saw tooth, or the roof looks like a stack of thin slats, flip the `facing`.

## Let the kit work out the slope

In `run_script`, `voxyl.kit.surface` covers a footprint with a stepped surface over a **height
field** and works out the geometry, and **you** say what each cell is made of: the kit never picks
a block or assumes a shape, so the roof comes from your project's own palette (stairs, slabs,
plain blocks, roof shapes, thatch, snow layers). The field is any function
`(x, z) => height in blocks` (`null` where there is no roof), so the pitch, the footprint and the
holes are yours. Heights come in half blocks.

`cell(c)` is called for every cell and returns what goes there: `{semantic, facing?, up?, ...}`,
`null` to skip it, or a list to place several. `c.kind` says what the cell is: `slope` (the roof
climbs here), `half` (its height ends on a half block), `level` (a ridge or flat: nothing beside it
is higher), `under` (below the surface). `c.toward` is the side the roof climbs toward, which is
what a stair takes as its `facing`.

```call-live
run_script {"source": "const box = [-1, -1, 21, 13];\nconst main = voxyl.kit.height.gable({ box, base: 7, rise: 1 });\nvoxyl.kit.surface({ height: main, box, cell: (c) =>\n  c.kind === 'slope' ? { semantic: 'Roof', facing: c.toward }\n  : c.kind === 'half' ? { semantic: 'RoofSlab', up: 'up' }\n  : { semantic: 'Ridge' } });"}
```

That is a stair roof with slabs for half steps and a block ridge. Another palette is another
`cell`: a thatch roof is `semantic: "Thatch"` for every cell, a roof of shaped tiles is
`{semantic: "Tile", facing: c.toward}`, snow on top is a second cell above the surface.

- `kit.height.gable`, `hip` and `shed` take `{box, base, rise}`: `base` is the height of the rim,
  `rise` is blocks gained per cell inward (1 is 45 degrees, `0.5` gentle, `2` steep) or a function
  of the distance `d` from the rim (`d => d < 3 ? 2 * d : 6 + 0.5 * (d - 3)` is a gambrel). `ridge`
  caps the height for a flat top.
- `kit.height.union(a, b)` takes the higher of two fields: an L, a T or a cross gable, with the
  valleys where they meet. `kit.height.cut(field, [x0, z0, x1, z1])` leaves a hole (a skylight, a
  courtyard, a notch).
- Write your own field for anything else: `(x, z) => 6 + Math.abs(x - 10) * 0.5`.
- The cell also says its `height`, which `edges` are the rim, its neighbours' heights and `rise`
  (how much higher the climb is), so eaves, caps, gable trim and a different block per height are
  all one `cell` function. `thickness` (or `to`) adds `under` cells so you cannot see through it.
- Corners: a hip's corner cell climbs toward one neighbour. A palette with corner stairs can look at
  `c.neighbors` and choose.

## Two ways to build the surface

- **Stairs and slabs** as whole-block roles (`Roof` with `placement: "stairs"`). They exist in
  every game version, so they are the safe choice. Use inverted stairs under the eaves.
- **Roof shapes** from `describe_shapes`: Roof Tile, Outer and Inner Corner, Gabled and Hip
  Ridge, Gabled and Hip Valley, and the sloped tiles. They are parts, not whole blocks: they
  take a whole cell in one of 24 orientations (`up` is where the top points; like a stair,
  each climbs toward its `facing`, so `c.toward` goes straight in), and they join into ridges,
  valleys and corners without the stepped look.
  They depend on the user's target supporting them, so check before using them for a build
  that must export to plain blocks.

Place hip roofs from the outside in, and valleys where two planes meet. Inner and outer
corners are where roofs go wrong; check them in a close `capture`.

## Roof types

- **Gable** (two slopes, a triangle at each end): the default. Fill the triangle with a
  framed wall (timber and plaster), a window, or a louvre. Never leave a blank triangle.
- **Hip** (four slopes): calmer and more formal. Good for towers and pavilions.
- **Cross gable and dormers**: break a long ridge. A dormer is a small gable that sits on the
  slope with its own window.
- **Mansard** (a steep lower slope under a shallow upper one): city, Victorian.
- **A-frame**: roof is the wall. Steep, simple, needs interesting ends.
- **Pyramid, conical, spire**: towers; conical roofs need a larger tower radius to work.
- **Dome**: needs diameter. Do not try one under about nine cells.
- **Lean-to / shed** (one slope): sheds, porches, additions.
- **Flat with parapet**: put things on it (water tanks, vents, a stair box, pipes, planters).
  A flat roof with nothing on it is a lid.

## Materials and weathering

- Use **two materials** at least: a base and a weathering tone in patches, or a base and a
  ridge. Apply wear with a reason: lighter on ridges (sun), darker along valleys and at
  drains ([gradients-and-wear.md](gradients-and-wear.md)).
- Match the region and the means: thatch or sod for humble or rural, wood shingle for many
  regions, slate or dark stone for wealth and cities, tile or terracotta for warm climates.
- Do not mix thatch types. Do not leave a smooth, perfect plane of one block over a long run.

## The underside

The roof's blocks should not show from inside. Build rafters under it (a row of inverted
stairs, fences or logs spanning the shortest dimension), and keep a clear floor-to-ridge
space if the build has an attic or a high ceiling. Check it with `xray` or a section.

## Roof check

- Is the pitch right for the style, and is there an overhang on every side?
- More than one plane, or a feature (dormer, chimney) breaking a long run?
- Ridge, edge and eave all finished?
- Does the roof have contrast with the wall?
- Does it read from the sides and the back, not only the front?
