Skip to content

Village

github-actions[bot] edited this page Nov 12, 2026 · 6 revisions

Village

Village stands houses and a scanned building on the meadow, beside a pond of still water. A character can walk into each house at its front door.

Houses of fieldstone, timber framing, brick and boards stand in wind-bent grass beyond a small pond, with trees, cliffs and mountains behind

examples/village.mojo draws this picture. The modules live in extensions/village/. A village joins three subjects in one scene:

See Extensions. To put people and animals in the village and walk through it, see Village walk.

Draw one frame

from core.assets import Assets
from core.scene import Scene
from extensions.vegetation.meadow import meadow_camera, meadow_renderer
from extensions.village.village import Village, VillageParameters
from extensions.water.pebbles import pebble_bed
from render.jpeg import decode
from std.pathlib import Path
from units.si import METER, SECOND, Duration, Length

var renderer = meadow_renderer(1280, 720)
var assets = Assets()
var scene = Scene()
var parameters = VillageParameters()
var bed = pebble_bed(decode(Path("assets/pebbles.jpg").read_bytes()))
var village = Village(scene, assets, renderer, parameters, bed^, None)
var camera = meadow_camera(parameters.meadow, 1280, 720, Length(0.0, METER))
_ = village.update(scene, assets, camera, Duration(2.0, SECOND))
var image = village.render(renderer, scene, assets, camera)

Village adds the meadow, the houses and the scanned building to the scene. None gives a village with no scanned building. update grows the grass for one camera and one time, and moves the water's clock on to that time. Call update before each render.

Village.terrain gives what carries and stops a character: the ground, and each house's walls, floor and steps. The furniture and the scanned building are solid lots. Village.doors holds every door. See Village houses.

render draws the scene, and then composes the pond's water into the picture. Do not draw the scene with renderer.render alone: that picture has no water.

Draw an hour

keep_hour sets the village for the hour of a DayCycle. It puts the sun or the moon where the hour does. From dusk to dawn it lights the lamps and the windows. Give the same hour to render, so it darkens the water and draws the night sky, the stars and the moon:

from extensions.village.day import DayCycle

var night = DayCycle(21.5)
village.keep_hour(scene, night)
_ = village.update(scene, assets, camera, Duration(2.0, SECOND))
night.light(scene)
var image = village.render(renderer, scene, assets, camera, night)

Call DayCycle.light after update, because the meadow's sun sets its lights again there. examples/village.mojo --hour=21.5 draws the village at that hour.

Add a scanned building

Fetch a scan first. Then give its id to the example:

sh tools/tool.sh .venv/bin/mojo building_scans fetch seem-church
mojo run -I . examples/village.mojo out/village-church.png seem-church

The id names a scan in assets/building_scans/manifest.json. A path to a scan file that extensions.scan.files reads works too. A scan's license can require a credit. See Scanned buildings.

In code, cut the building out of its scan, and give it to Village:

from extensions.scan.files import read_scan
from extensions.village.scanned import cut_building

var cut = cut_building(read_scan(path).geometry, frame, Length(0.5, METER))
var village = Village(scene, assets, renderer, parameters, bed^, cut^)

On a four-core Linux host, the example cuts the Seem church out of its scan in 1.2 seconds. The village builds in 3.2 seconds. The render takes about 20 seconds at 1280 by 720, with the church or without it.

The parts

Module Holds
house.mojo Facade, HouseParameters, fieldstone, lime_plaster, front_wall, house_model, house_lot and footing.
house_view.mojo Hinge, StandingHouse, door_leaf, facade_look and stand_house.
interior.mojo Doorway, HouseInterior and house_interior.
terrain.mojo WallSpan, Floor, Terrain, wall_push and view_entry.
doors.mojo Doors.
props.mojo PropKind, Prop, StandingProps and stand_props.
sheet.mojo Sheet.
dressing.mojo Glow, warm, warmth, prism, rug, patchwork, table_setting, jars, books, lantern and herbs.
gathering.mojo GatherKind, Spot, GatherParameters, Satchel and Gathering. See Village gathering.
hud.mojo draw_hud, draw_text and the prompts. See Village gathering.
day.mojo DayCycle and dim_water. See Village day and night.
skills.mojo SkillKind, Skills, skill_of, level_of, ore_strikes, forage_bonus and fish_haste. See Village skills.
combat.mojo, battle.mojo, foes.mojo, arms.mojo, blade.mojo, slashes.mojo, battle_hud.mojo The player's sword, the bandits and the dummies, and what a fight shows. See Village combat.
critters.mojo Haunt, default_haunts, wing_color and Critters. See Village critters.
talk.mojo ErrandState, Errand, Speaker, default_speakers and Talk. See Village errands.
weather.mojo WeatherKind, WeatherLook, weather_look, cloud_cover and Weather. See Village weather.
surfaces.mojo The textures, HouseLooks and house_looks.
scanned.mojo CutBuilding, cut_building, grid_voxel, linear_splats, scan_lot and stand_scan.
air.mojo bloom and ground_mist. See Village weather.
pond.mojo PondLook and water_mask.
puffs.mojo Puff, chimney_smoke, dust_puffs and draw_puffs.
shore.mojo ShoreParameters, StandingShore and stand_shore.
village.mojo HousePlacement, VillageParameters, pond_basin and Village.

The default village

VillageParameters() holds the meadow of Vegetation, with these additions:

Part Where it stands
A pond 12 meters across and 1.2 meters deep Right of the trail, 11 meters ahead of the camera.
A stone cottage of one story, 7 by 5.5 meters, under slates Left of the trail, about 25 meters away, turned 80 degrees.
A brick house of three stories, 9 by 7 meters, under weathered tiles West of the green, about 55 meters away, turned 90 degrees to face it.
A framed cottage of one story, 6.5 by 5 meters, under thatch South of the green, about 60 meters away, facing it.
A framed house of two stories, 8 by 6 meters, under warm tiles Right of the trail, across it from the green, about 55 meters away, turned -80 degrees.
A boarded barn of one story 4.2 meters tall, 13 by 8 meters, under gray tiles Ahead, about 90 meters away, turned -12 degrees.
The scanned building, if there is one On the right, about 110 meters away, turned 28 degrees.

Three houses face the green round the well. The green holds a bench, a trough, a handcart, a signpost where the paths meet the trail, and three lamp posts.

The houses' textures are 128 texels on a side.

Oaks

The village's open and round trees grow as oaks. oak gives a tree an oak's wood and keeps its crown and its leaves:

Part The meadow's tree An oak
Twig tips, and so by the pipe model the trunk and the limbs As thick as the crown says Twice as thick
The thinnest wood drawn As the crown says Twice as thick, so the same branches are drawn
Flare at the trunk's foot As the crown says Twice as much, at most 3
Bark Pale with dark patches Gray-brown, with dark furrows four times as close

The meadow's own scene keeps its pale trees. See Vegetation.

The water's ocean spectrum is 256 texels on a side, and its glare is 128 texels. Its caustic grid is 64, as in the still, and its caustic texture is 256 texels on a side. The water's clock starts at 5 seconds, as the Clearwater page's does.

Props

VillageParameters.props lists the things that stand about the village. Each Prop is a PropKind, a place, a turn and a length. stand_props draws them with the houses' materials, in one mesh for each material.

Kind What it is Its length
WELL A round stone wall, two posts, a beam, a little roof and a bucket Its radius
BARREL Oak staves with two iron hoops Its radius
CRATE A box of boards with slats on its edges Its side
HAY_BALE A bale of hay, tied with two cords Its length
FENCE Posts at most 2 meters apart, and two rails, a meter tall Its length
BENCH A plank on two trestles Its length
WOODPILE Split logs stacked under a board lid, their ends out, 0.6 meters deep and 1.15 meters tall Its length
CART A handcart: a bed of boards on two spoked wheels, with two shafts Its bed's length
SIGNPOST A post with two pointing arms Its height
WASHING_LINE Two posts, a line between them, and cloths of three colors Its length
TROUGH A trough of boards on legs, full of water Its length
SCARECROW A post and a cross arm in a coat, a straw head and a hat Its height
CROPS A garden bed of three rows of cabbages Its length
LAMP_POST An iron post on a stone foot, with a lantern that glows from dusk to dawn Its height
HEDGE A clipped hedge of leaves, 1.4 meters tall and 0.9 meters deep Its length

The default village has the green's props, and barrels, crates and hay before the barn. A hedge runs between the barn's yard and the green. Fences close a garden behind the stone cottage, with a gate on its south side. Three beds of cabbages and a scarecrow stand in it, and a washing line stands beside it. A bench stands before the framed house. A woodpile stands outside the hearth's gable of each house with a hearth: woodpile_by places it, and hearthed says which houses have one.

Each fence and each hedge is a wall span of the terrain. Crops stop nobody. Each other prop is a solid lot. The residents' routes keep off the props. A lamp post's glowing glass hangs from StandingProps.lit, and its cold glass from StandingProps.daylit. The game shows one of them with the houses' lamps.

The ground at the foot of each building is dark with grime, out to GRIME_REACH, 0.9 meters, from its lot. See lot_grime in Vegetation.

Chimney smoke

Smoke rises from the pot of each house with a hearth. StandingHouse.chimney holds the top of the pot, and Village.chimneys holds each pot in the world. Village.smoke gives the puffs over every chimney at a time.

Part Value
Puffs over a chimney at once SMOKE_PUFFS, 14
A puff's life SMOKE_LIFE, 8 seconds
How fast a puff rises SMOKE_RISE, 0.55 meters a second, slowing as it rises
How fast the wind carries it SMOKE_DRIFT, 0.6 meters a second, along the meadow's wind
How large it grows From 0.22 meters across its middle to 1.42 meters

A puff has no state of its own. chimney_smoke finds it from the time alone, so the same time gives the same smoke.

The renderers draw opaque triangles only. So draw_puffs blends each puff into the finished frame as a soft disc that faces the camera. A pixel nearer than the puff's middle keeps its color, so smoke behind a wall does not show through it. The puffs are drawn far to near. render draws the smoke into the still, and the game draws it after the night's sky, dimmer at night. dust_puffs gives the dust that a foot kicks up.

Lots

Each building stands on a Lot: its footprint, turned about +y. Village puts the lots into MeadowParameters.lots before it builds the meadow. So no grass grows on a lot or on the bare apron around it, and no tree or bush stands there. The ground under a lot is mottled dirt. See Ponds and lots.

A worn footpath 0.8 meters wide leads from each house's front door to the trail. door_path gives it as two lots with narrow aprons. The first runs 3.5 meters straight out from the door. The second runs on to the nearest point of the trail. A door with no trail within 60 meters, or on ground with no trail, has only the first.

Houses

Each house is a canonical building model with a hall, a front door, windows and furniture. The village draws it with its own view, on a stone plinth, under a gable roof. See Village houses.

Scanned buildings

A scan of a building also holds its ground: paths, graves, a lawn or a street. cut_building keeps only the building:

  1. It fills an occupancy grid of the scan. grid_voxel starts the voxel at the size that you give, and doubles it until the grid holds at most 4,194,304 voxels.
  2. It finds the ground as a terrain surface of column tops. The surface must cover a quarter of the plan, and two columns of it differ by 2 meters at most.
  3. It cuts the grid into parts above the ground, of 20 voxels or more. See Scan parts.
  4. It copies the splats of the largest part.

A scan of a room has its floor as its ground, so do not use one for a village.

stand_scan stands the cut building as one Gaussian splat object. The middle of its footprint stands at the point that you give, and the building is turned about +y. Its foot is 15 centimeters below the lowest ground under its corners, so no gap shows on a slope.

A scan's colors are sRGB, as a screen shows them. The renderer blends splats as linear light, and tone maps the frame after. So stand_scan gives the scene a copy of the splats from linear_splats. Each color byte of the copy is linear light, and its opacity is kept. The copy has no spherical harmonics, because their shading adds to the sRGB color and has no exact linear form. The building keeps its colors and loses its sheen, which changes with the view.

Water

The pond's water is a WaterScene. Its sun is the meadow's sun, so the water's glints agree with the grass's shadows.

render composes the water into the picture at the ground's water_level. The water is an endless plane, and the composition tests it against the depth of each pixel. The ground outside the basin lies above the water, so the water shows only in the basin. Grass and trees in front of the water keep their pixels.

When the renderer supersamples, render composes the water into each sample before it averages them. So a grass blade that covers one sample of a pixel does not keep the whole pixel from the water.

update moves the water's clock on to the frame's time. An earlier time leaves the clock where it is, because the water's state moves only forward.

The basin and the ripples

pond_basin gives the water the pond's own basin. The water's bed is level in the middle and rises to the shore, as the ground does. So the water grows shallow toward its edge. Where it is shallower than 35 centimeters, its bed turns to mud. See Water.

The water's ripple window lies over the pond, one meter wider than the pond. Village.splash taps the water at a point on the next update. The game taps the pond in three ways:

What Where How often
Rain At random points of the pond 40 drops a second in a downpour, fewer in lighter rain
A wading player At the player's feet, while the player moves faster than 0.3 meters a second Every 0.18 seconds
A bite at a fishing float At the float Every frame of the bite

The shore

stand_shore dresses the pond's edge. VillageParameters.shore holds how much of each part it draws:

Part Count Where
Reeds 16 clumps of 5 to 11 blades, in four beds Where the water is at most 15 centimeters deep, and on the mud up to 12 centimeters above it
Cattails In about a third of the clumps Near the top of every fourth blade
Stones 30 On the damp band, from 6 centimeters under the water to 12 centimeters above it
Lily pads 14, some with a flower Where the water is 60 centimeters deep or more

Nothing of the shore stands on a lot or its apron, and nothing of it stops a character. No grass blade roots under the water, no seed head stands on the wet shore, and no litter lies on the bed. The mud is darkest at the water's edge, and it dries over the 12 centimeters above it.

What the water mirrors

PondLook finishes the water after the composition. render and the game both use it:

  1. The village. Each pixel above the water is mirrored in the water's plane. The mirror image shows at the water's Fresnel share, at most 85 percent, and it trembles a pixel or two. Where the frame does not show what the water would mirror, the water keeps its own sky.
  2. The fog. The water fades into the scene's fog by its distance, as the triangles do.
  3. The stars. At night, the water mirrors the stars of the sky. See Village day and night.

Limits

  • The water mirrors only what the frame shows. A house out of the frame, or behind another one, is not in the water. The water's own sky is the Clearwater sky, not the sky cube.
  • On a GPU that composes the water, the water does not mirror the village, the fog or the stars. The chimneys do not smoke there.
  • A puff of smoke is lit by the hour, not by the sun. It casts no shadow, and the fog does not fade it.
  • A house is a box of stories under one gable roof. It has no porch and no wing. Its upper stories have no stairs.
  • A scanned building's splats are lit by the scan's own light, not by the meadow's sun. They cast no shadow.
  • A lot keeps plants off the ground, but it does not level the ground. The plinth and the sunk foot fill the slope.

Home

Tutorials

How-to

Reference

Explanation

Clone this wiki locally