{
  "version": 1,
  "description": "A town street ready for a level, laid out along X and centred on the road (Y up, metres): the road with kerbs, pavements, lane markings, a zebra crossing and lamp posts on both pavements; on the -Z side a row of houses as wide as house_width, as many as fit, each with its own depth, plaster colour, roof (gable along the street, gable facing it or hipped), door colour and chimneys, and a fenced back garden with a tree; on the +Z side a park behind a hedge, with a winding promenade, entrances from the pavement, a round plaza, trees, bushes and benches. Everything stays within the street's length and 70 m across it (z from -35 to 35), on the ground at y = 0. Walls, roofs, lamps, fences, trees, bushes and benches come from TopoTopo's own architecture, street and nature packages; trees, bushes, benches, lamps and chimneys are packed instances.",
  "params": {
    "street_length": { "type": "float", "default": 80, "min": 40, "max": 200, "step": 1, "label": "street length", "desc": "length of the street along X (m)" },
    "road_width": { "type": "float", "default": 8, "min": 5, "max": 14, "step": 0.5, "label": "road width", "desc": "width of the road between the kerbs (m)" },
    "house_width": { "type": "float", "default": 10, "min": 6, "max": 16, "step": 0.5, "label": "house width", "desc": "frontage of each house (m); as many houses as fit along the street" },
    "floors": { "type": "int", "default": 2, "min": 1, "max": 4, "label": "floors", "desc": "floors of every house" },
    "lamp_spacing": { "type": "float", "default": 16, "min": 8, "max": 40, "step": 1, "label": "lamp spacing", "desc": "largest distance between lamp posts along a pavement (m), on both pavements" },
    "park_density": { "type": "float", "default": 0.5, "min": 0, "max": 1, "step": 0.05, "label": "park density", "desc": "how full of trees and bushes the park is" },
    "seed": { "type": "int", "default": 1, "min": 0, "max": 9999, "label": "seed", "desc": "changes the houses' details, the props and the trees, not the layout" }
  },
  "vars": { "street_length": 80, "road_width": 8, "house_width": 10, "floors": 2, "lamp_spacing": 16, "park_density": 0.5, "seed": 1 },
  "meta": { "render": { "views": ["persp"], "azimuth": 22, "elevation": 36, "size": "1600x900", "shading": "pbr", "grid": false } },
  "nodes": {
    "none": { "type": "points", "params": { "positions": [] } },

    "street_line": { "type": "line", "note": "the road's centre line, 5 cm up: the kerb and pavement slabs reach 5 cm below it, so they rest on the ground", "params": { "origin": ["=-street_length / 2", 0.05, 0], "direction": [1, 0, 0], "length": "=street_length", "points": 2 } },
    "road": { "type": "topotopo/street/road_strip", "in": ["street_line"], "params": { "width": "=road_width", "lanes": "=road_width >= 11 ? 4 : 2", "dash_length": "=street_length / (2 * round(street_length / 6))", "kerb_height": 0.15, "sidewalk_width": 3 } },
    "kerbs_and_pavements": { "type": "delete", "in": ["road"], "note": "the package's asphalt is a thin ribbon: a solid slab replaces it", "params": { "group": "@name=road_surface" } },
    "asphalt": { "type": "box", "params": { "size": ["=street_length", 0.05, "=road_width"], "center": [0, 0.025, 0] } },
    "asphalt_named": { "type": "attrib_create", "in": ["asphalt"], "params": { "name": "name", "class": "prim", "value": "road_surface" } },
    "asphalt_mat": { "type": "material", "in": ["asphalt_named"], "params": { "name": "asphalt", "base_color": "#3c3d42", "roughness": 0.9 } },
    "stripe": { "type": "box", "params": { "size": [3, 0.008, 0.5], "center": [0, 0.062, "=-(floor(road_width - 0.6) - 1) / 2"] } },
    "crossing": { "type": "copy_xform", "in": ["stripe"], "params": { "count": "=floor(road_width - 0.6)", "translate": [0, 0, 1], "copy_attrib": "" } },
    "crossing_named": { "type": "attrib_create", "in": ["crossing"], "params": { "name": "name", "class": "prim", "value": "road_crossing" } },
    "crossing_mat": { "type": "material", "in": ["crossing_named"], "params": { "name": "road_paint", "base_color": "#ecebe4", "roughness": 0.6 } },

    "lamp_line": { "type": "line", "note": "at the pavement top", "params": { "origin": ["=-street_length / 2", 0.19, 0], "direction": [1, 0, 0], "length": "=street_length", "points": 2 } },
    "lamp_pts": { "type": "points_along_curve", "in": ["lamp_line"], "note": "evenly spread, as many as keep them at most lamp_spacing apart", "params": { "count": "=ceil((street_length - 4) / lamp_spacing) + 1", "start_offset": 2, "end_offset": 2, "side_offset": "=road_width / 2 + 0.75", "both_sides": true } },
    "lamp_face_road": { "type": "wrangle", "in": ["lamp_pts"], "params": { "run_over": "points", "code": "f@yaw = @side < 0 ? 180 : 0;" } },
    "lamp": { "type": "topotopo/street/lamp_post", "params": { "height": 5.5, "arm_length": 1.2 } },
    "lamps": { "type": "copy_to_points", "in": ["lamp", "lamp_face_road"], "params": { "pack": true, "rotate_attrib": "yaw", "copy_attribs": "" } },
    "lamp_survey": {
      "type": "wrangle", "in": ["lamps"],
      "note": "measures the lamps as cooked: per pavement the largest gap between neighbours and the distance from the street's ends; lamp_rows counts the pavements lined with two or more lamps (0 when a lamp stands off both pavements)",
      "params": { "run_over": "detail", "code": "const lo = road_width / 2 + 0.15, hi = lo + 3, L = street_length;\nconst rows = { left: [], right: [] }; let off = 0;\nfor (let i = 0; i < npoints(0); i++) {\n  const P = point(0, 'P', i), az = Math.abs(P[2]);\n  if (az < lo || az > hi) { off++; continue; }\n  rows[P[2] > 0 ? 'left' : 'right'].push(P[0]);\n}\nlet gap = 0, end = 0, lined = 0;\nfor (const xs of [rows.left, rows.right]) {\n  xs.sort((a, b) => a - b);\n  if (xs.length >= 2) lined++;\n  if (!xs.length) continue;\n  end = Math.max(end, xs[0] + L / 2, L / 2 - xs[xs.length - 1]);\n  for (let j = 1; j < xs.length; j++) gap = Math.max(gap, xs[j] - xs[j - 1]);\n}\nsetdetailattrib(0, 'lamp_gap', gap);\nsetdetailattrib(0, 'lamp_end', end);\nsetdetailattrib(0, 'lamp_rows', off ? 0 : lined);" }
    },
    "lamps_both_sides": { "type": "assert", "in": ["lamp_survey"], "note": "both pavements carry a row of lamp posts, and none stands off them", "params": { "label": "lamps", "attrib": "lamp_rows", "attrib_class": "detail", "attrib_min": 2 } },
    "lamps_spacing": { "type": "assert", "in": ["lamps_both_sides"], "note": "neighbours along a pavement never more than lamp_spacing apart", "params": { "label": "lamps", "attrib": "lamp_gap", "attrib_class": "detail", "attrib_max": "=lamp_spacing + 0.001" } },
    "lamps_to_the_ends": { "type": "assert", "in": ["lamps_spacing"], "note": "the rows reach the street's ends: the first and last lamp stand within half a spacing of them", "params": { "label": "lamps", "attrib": "lamp_end", "attrib_class": "detail", "attrib_max": "=lamp_spacing / 2 + 0.001" } },
    "lamps_clean": { "type": "attrib_delete", "in": ["lamps_to_the_ends"], "params": { "names": "lamp_gap lamp_end lamp_rows" } },

    "street_parts": { "type": "merge", "in": ["kerbs_and_pavements", "asphalt_mat", "crossing_mat", "lamps_clean"] },
    "street_paint": { "type": "wrangle", "in": ["street_parts"], "note": "Cd follows each prim's material (the recoloured walls, roofs and doors too), for viewers and formats that show Cd", "params": { "run_over": "detail", "code": "const table = JSON.parse(detail(0, 'materials') || '{}');\nfor (let p = 0; p < nprims(0); p++) { const m = table[prim(0, 'material', p)]; if (m) setprimattrib(0, 'Cd', p, m.baseColor); }" } },
    "street_grounded": { "type": "assert", "in": ["street_paint"], "params": { "label": "grounded", "expr": "bbox.min.y >= -0.0001" } },
    "street": { "type": "assert", "in": ["street_grounded"], "params": { "label": "fits", "expr": "bbox.min.x >= -street_length / 2 - 0.001 && bbox.max.x <= street_length / 2 + 0.001 && bbox.min.z >= -35.001 && bbox.max.z <= 35.001" } },

    "lots": {
      "type": "wrangle", "in": ["none"],
      "note": "one point per house at the middle of its front wall: as many houses as fit with gaps of at least 1.6 m, spread evenly; each draws its details from the seed (neighbours never share a roof or a colour)",
      "params": { "run_over": "detail", "code": "const W = house_width, L = street_length, n = Math.max(1, Math.floor((L - 1.6) / (W + 1.6)));\nconst gap = (L - n * W) / (n + 1), zf = -(road_width / 2 + 3.3);\nlet roof = Math.floor(rand(seed, 0.5) * 3), col = Math.floor(rand(seed, 0.7) * 5);\nfor (let i = 0; i < n; i++) {\n  const r = (k) => rand(seed, i, k);\n  if (i > 0) { roof = (roof + 1 + Math.floor(r(1) * 2)) % 3; col = (col + 1 + Math.floor(r(2) * 4)) % 5; }\n  const p = addpoint(0, [-L / 2 + gap + W / 2 + i * (W + gap), 0, zf]);\n  setpointattrib(0, 'depth', p, 8 + Math.floor(r(3) * 4));\n  setpointattrib(0, 'roof', p, roof);\n  setpointattrib(0, 'pitch', p, roof === 2 ? 25 + Math.floor(r(4) * 10) : 32 + Math.floor(r(4) * 14));\n  setpointattrib(0, 'colour', p, col);\n  setpointattrib(0, 'tiles', p, Math.floor(r(5) * 3));\n  setpointattrib(0, 'door_colour', p, Math.floor(r(6) * 4));\n  setpointattrib(0, 'shop', p, r(7) < 0.5 ? 1 : 0);\n  setpointattrib(0, 'windows', p, Math.max(2, Math.floor(W / (2.1 + r(8)))));\n  setpointattrib(0, 'side_windows', p, r(9) < 0.5 ? 1 : 0);\n}" }
    },
    "house_each": {
      "type": "foreach", "in": ["lots"],
      "params": { "mode": "points", "body": { "nodes": {
        "lot": { "type": "input", "params": { "index": 0 } },
        "front_ground": { "type": "topotopo/architecture/wall_segment", "note": "a shop front (two wide windows) or a house front, door in the middle", "params": { "wall_length": "=house_width", "height": 3, "door": true, "windows": "=point('lot', 0, 'shop') ? 2 : point('lot', 0, 'windows') - 1", "window_width": "=point('lot', 0, 'shop') ? min(2.6, house_width / 3 - 0.6) : 1", "window_height": "=point('lot', 0, 'shop') ? 1.9 : 1.3", "sill_height": "=point('lot', 0, 'shop') ? 0.45 : 0.9" } },
        "upper": { "type": "topotopo/architecture/wall_segment", "params": { "wall_length": "=house_width", "height": 3, "windows": "=point('lot', 0, 'windows')" } },
        "upper_up": { "type": "transform", "in": ["upper"], "params": { "translate": [0, 3, 0] } },
        "front_upper": { "type": "copy_xform", "in": ["upper_up"], "params": { "count": "=floors - 1", "translate": [0, 3, 0], "copy_attrib": "" } },
        "front_stack": { "type": "merge", "in": ["front_ground", "front_upper"] },
        "front": { "type": "transform", "in": ["front_stack"], "params": { "translate": ["=-house_width / 2", 0, 0] } },
        "back_stack": { "type": "copy_xform", "in": ["upper"], "params": { "count": "=floors", "translate": [0, 3, 0], "copy_attrib": "" } },
        "back": { "type": "transform", "in": ["back_stack"], "params": { "rotate": [0, 180, 0], "translate": ["=house_width / 2", 0, "=-point('lot', 0, 'depth')"] } },
        "side": { "type": "topotopo/architecture/wall_segment", "params": { "wall_length": "=point('lot', 0, 'depth') + 0.25", "height": 3, "windows": "=point('lot', 0, 'side_windows') ? floor(point('lot', 0, 'depth') / 3.2) : 0" } },
        "side_stack": { "type": "copy_xform", "in": ["side"], "params": { "count": "=floors", "translate": [0, 3, 0], "copy_attrib": "" } },
        "right": { "type": "transform", "in": ["side_stack"], "params": { "rotate": [0, 90, 0], "translate": ["=house_width / 2", 0, 0.125] } },
        "left": { "type": "transform", "in": ["side_stack"], "params": { "rotate": [0, -90, 0], "translate": ["=-house_width / 2", 0, "=-point('lot', 0, 'depth') - 0.125"] } },
        "gable_along": { "type": "topotopo/architecture/roof_gable", "params": { "width": "=house_width + 0.25", "depth": "=point('lot', 0, 'depth') + 0.25", "pitch": "=point('lot', 0, 'pitch')", "overhang": 0.35 } },
        "gable_front_raw": { "type": "topotopo/architecture/roof_gable", "params": { "width": "=point('lot', 0, 'depth') + 0.25", "depth": "=house_width + 0.25", "pitch": "=point('lot', 0, 'pitch')", "overhang": 0.35 } },
        "gable_front": { "type": "transform", "in": ["gable_front_raw"], "params": { "rotate": [0, 90, 0] } },
        "hip": { "type": "topotopo/architecture/roof_hip", "params": { "width": "=house_width + 0.25", "depth": "=point('lot', 0, 'depth') + 0.25", "pitch": "=point('lot', 0, 'pitch')", "overhang": 0.4 } },
        "roof": { "type": "switch", "in": ["gable_along", "gable_front", "hip"], "params": { "index": "=point('lot', 0, 'roof')" } },
        "roof_up": { "type": "transform", "in": ["roof"], "params": { "translate": [0, "=floors * 3", "=-point('lot', 0, 'depth') / 2"] } },
        "house": { "type": "merge", "in": ["front", "back", "left", "right", "roof_up"] },
        "plaster": { "type": "material", "in": ["house"], "params": { "group": "@name=wall @name=roof_gables", "name": "=pick(['plaster_cream', 'plaster_ochre', 'plaster_rose', 'plaster_sage', 'plaster_grey'], point('lot', 0, 'colour'))", "base_color": "=pick([[0.92, 0.87, 0.76], [0.85, 0.67, 0.4], [0.82, 0.6, 0.55], [0.64, 0.71, 0.6], [0.76, 0.76, 0.74]], point('lot', 0, 'colour'))", "roughness": 0.85 } },
        "tiles": { "type": "material", "in": ["plaster"], "params": { "group": "@material=roof_tiles", "name": "=pick(['roof_tiles', 'roof_slate', 'roof_brown'], point('lot', 0, 'tiles'))", "base_color": "=pick([[0.6, 0.29, 0.21], [0.3, 0.32, 0.36], [0.45, 0.3, 0.22]], point('lot', 0, 'tiles'))", "roughness": 0.8 } },
        "door": { "type": "material", "in": ["tiles"], "params": { "group": "@name=door_leaf", "name": "=pick(['door_green', 'door_red', 'door_blue', 'door_black'], point('lot', 0, 'door_colour'))", "base_color": "=pick([[0.13, 0.33, 0.24], [0.55, 0.13, 0.12], [0.15, 0.25, 0.45], [0.1, 0.1, 0.11]], point('lot', 0, 'door_colour'))", "roughness": 0.5 } },
        "place": { "type": "transform", "in": ["door"], "params": { "translate": ["=point('lot', 0, 'P', 0)", 0, "=point('lot', 0, 'P', 2)"] } }
      }, "output": "place" } }
    },
    "chimney_pts": {
      "type": "wrangle", "in": ["lots"],
      "note": "one or two chimneys per house astride its ridge, their foot 1 m inside the roof",
      "params": { "run_over": "detail", "code": "const W = house_width, H = floors * 3;\nfor (let i = 0; i < npoints(0); i++) {\n  const P = point(0, 'P', i), D = point(0, 'depth', i), roof = point(0, 'roof', i), t = Math.tan(radians(point(0, 'pitch', i)));\n  const r = (k) => rand(seed, i, 20 + k), zc = P[2] - D / 2;\n  const n = roof !== 2 && r(0) < 0.4 ? 2 : 1;\n  for (let c = 0; c < n; c++) {\n    const s = n === 2 ? (c ? 1 : -1) : (r(1) < 0.5 ? -1 : 1);\n    let x = P[0], z = zc, ridge;\n    if (roof === 0) { ridge = (D + 0.25) / 2 * t; x += s * W * (0.22 + r(2) * 0.08); }\n    else if (roof === 1) { ridge = (W + 0.25) / 2 * t; z += s * D * (0.2 + r(2) * 0.06); }\n    else { ridge = (Math.min(W, D) + 0.25) / 2 * t; const run = Math.abs(W - D) / 2 * 0.6 * r(2); if (W >= D) x += s * run; else z += s * run; }\n    addpoint(0, [x, H + ridge - 1, z]);\n  }\n  removepoint(0, i);\n}" }
    },
    "chimney_stack": { "type": "box", "params": { "size": [0.6, 1.8, 0.6], "center": [0, 0.9, 0] } },
    "chimney_stack_named": { "type": "attrib_create", "in": ["chimney_stack"], "params": { "name": "name", "class": "prim", "value": "chimney" } },
    "chimney_brick": { "type": "material", "in": ["chimney_stack_named"], "params": { "name": "chimney_brick", "base_color": "#8e4f3c", "roughness": 0.9 } },
    "chimney_cap": { "type": "box", "params": { "size": [0.78, 0.12, 0.78], "center": [0, 1.86, 0] } },
    "chimney_cap_named": { "type": "attrib_create", "in": ["chimney_cap"], "params": { "name": "name", "class": "prim", "value": "chimney_cap" } },
    "chimney_cap_mat": { "type": "material", "in": ["chimney_cap_named"], "params": { "name": "concrete", "base_color": "#aaa59c", "roughness": 0.9 } },
    "chimney": { "type": "merge", "in": ["chimney_brick", "chimney_cap_mat"] },
    "chimneys": { "type": "copy_to_points", "in": ["chimney", "chimney_pts"], "params": { "pack": true } },
    "garden_lines": { "type": "wrangle", "in": ["lots"], "note": "the gardens behind the houses: a fence along the back, and one between every two houses and at both ends, from 2 m behind the fronts", "params": { "run_over": "detail", "code": "const L = street_length, zb = -33.5, zs = -(road_width / 2 + 3.3) - 2, n = npoints(0);\nconst line = (x0, z0, x1, z1) => addprim(0, 'polyline', [addpoint(0, [x0, 0, z0]), addpoint(0, [x1, 0, z1])]);\nline(-L / 2 + 0.3, zb, L / 2 - 0.3, zb);\nline(-L / 2 + 0.3, zs, -L / 2 + 0.3, zb);\nline(L / 2 - 0.3, zs, L / 2 - 0.3, zb);\nfor (let i = 0; i + 1 < n; i++) { const x = (point(0, 'P', i)[0] + point(0, 'P', i + 1)[0]) / 2; line(x, zs, x, zb); }\nfor (let i = 0; i < n; i++) removepoint(0, i);" } },
    "garden_fences": { "type": "topotopo/street/fence", "in": ["garden_lines"], "note": "one plank fence along every garden line", "params": { "style": "plank", "height": 1.2, "seed": "=seed % 1000" } },
    "garden_tree_sites": { "type": "wrangle", "in": ["lots"], "note": "a tree in the middle of every garden", "params": { "run_over": "points", "code": "const P = point(0, 'P', @ptnum), back = P[2] - @depth - 0.15;\n@P = [P[0] + (rand(@ptnum, seed, 31) - 0.5) * house_width * 0.3, 0, (back - 33.5) / 2];\ns@kind = rand(@ptnum, seed, 32) < 0.6 ? 'round' : 'conifer';\nf@yaw = Math.floor(rand(@ptnum, seed, 33) * 4) * 90;\nf@size = 0.85 + rand(@ptnum, seed, 34) * 0.25;" } },
    "garden_tree_sites_clean": { "type": "attrib_delete", "in": ["garden_tree_sites"], "params": { "names": "depth roof pitch colour tiles door_colour shop windows side_windows" } },
    "garden_tree_round": { "type": "topotopo/nature/tree_lowpoly", "params": { "style": "round", "height": 6, "canopy_radius": 2, "seed": "=(seed + 13) % 1000" } },
    "garden_tree_conifer": { "type": "topotopo/nature/tree_lowpoly", "params": { "style": "conifer", "height": 7, "canopy_radius": 1.7, "seed": "=(seed + 17) % 1000" } },
    "garden_tree_round_kind": { "type": "attrib_create", "in": ["garden_tree_round"], "params": { "name": "kind", "class": "prim", "value": "round" } },
    "garden_tree_conifer_kind": { "type": "attrib_create", "in": ["garden_tree_conifer"], "params": { "name": "kind", "class": "prim", "value": "conifer" } },
    "garden_tree_kit": { "type": "merge", "in": ["garden_tree_round_kind", "garden_tree_conifer_kind"] },
    "garden_trees": { "type": "copy_to_points", "in": ["garden_tree_kit", "garden_tree_sites_clean"], "params": { "pack": true, "piece_attrib": "kind", "variant_attrib": "kind", "rotate_attrib": "yaw", "scale_attrib": "size" } },
    "house_parts": { "type": "merge", "in": ["house_each", "chimneys", "garden_fences", "garden_trees"] },
    "house_paint": { "type": "wrangle", "in": ["house_parts"], "note": "Cd follows each prim's material (the recoloured walls, roofs and doors too), for viewers and formats that show Cd", "params": { "run_over": "detail", "code": "const table = JSON.parse(detail(0, 'materials') || '{}');\nfor (let p = 0; p < nprims(0); p++) { const m = table[prim(0, 'material', p)]; if (m) setprimattrib(0, 'Cd', p, m.baseColor); }" } },
    "houses_grounded": { "type": "assert", "in": ["house_paint"], "params": { "label": "grounded", "expr": "bbox.min.y >= -0.0001" } },
    "houses": { "type": "assert", "in": ["houses_grounded"], "params": { "label": "fits", "expr": "bbox.min.x >= -street_length / 2 - 0.001 && bbox.max.x <= street_length / 2 + 0.001 && bbox.min.z >= -35.001 && bbox.max.z <= 35.001" } },

    "park_rect": { "type": "grid", "note": "the park: from the pavement's back edge to 35 m from the road's centre, the whole street long", "params": { "size": ["=street_length", "=35 - road_width / 2 - 3.15"], "center": [0, 0, "=(35 + road_width / 2 + 3.15) / 2"], "divisions": [1, 1] } },
    "path_lines": {
      "type": "wrangle", "in": ["none"],
      "note": "the promenade winds along the park; entrances run from the pavement to it, the middle one opposite the zebra crossing",
      "params": { "run_over": "detail", "code": "const L = street_length, e = road_width / 2 + 3.15, D = 35 - e;\nconst zm = e + 0.45 * D, A = Math.min(2.5, 0.1 * D), k = Math.max(1, Math.round(L / 60));\nconst zAt = (x) => zm + A * Math.sin(2 * Math.PI * k * x / L + 0.6);\nconst n = Math.ceil((L + 2) / 1.5) + 1, pts = [];\nfor (let i = 0; i < n; i++) { const x = -L / 2 - 1 + (L + 2) * i / (n - 1); pts.push(addpoint(0, [x, 0, zAt(x)])); }\nsetprimattrib(0, 'path', addprim(0, 'polyline', pts), 'promenade');\nconst m = 2 * Math.floor(L / 100) + 1;\nfor (let j = 0; j < m; j++) {\n  const x = -L / 2 + (j + 0.5) * L / m;\n  setprimattrib(0, 'path', addprim(0, 'polyline', [addpoint(0, [x, 0, e - 1]), addpoint(0, [x, 0, zAt(x)])]), 'entrance');\n}\nsetdetailattrib(0, 'plaza_z', zAt(0));" }
    },
    "path_straps": { "type": "offset_curve", "in": ["path_lines"], "params": { "distance": 1.2, "cap": "butt", "join": "round" } },
    "plaza": { "type": "circle", "params": { "radius": "=min(5, 0.18 * (35 - road_width / 2 - 3.15))", "segments": 48, "center": [0, 0, "=detail('path_lines', 'plaza_z')"] } },
    "island": { "type": "circle", "params": { "radius": "=min(5, 0.18 * (35 - road_width / 2 - 3.15)) - 2.6", "segments": 32, "center": [0, 0, "=detail('path_lines', 'plaza_z')"] } },
    "path_network": { "type": "merge", "in": ["path_straps", "plaza"] },
    "path_union": { "type": "boolean2d", "in": ["path_network"], "params": { "operation": "union", "output": "outlines" } },
    "path_ring": { "type": "boolean2d", "in": ["path_union", "island"], "params": { "operation": "subtract", "output": "outlines" } },
    "path_area": { "type": "boolean2d", "in": ["path_ring", "park_rect"], "params": { "operation": "intersect", "output": "outlines" } },
    "lawn_area": { "type": "boolean2d", "in": ["park_rect", "path_area"], "params": { "operation": "subtract", "output": "outlines" } },
    "lawn_solid": { "type": "extrude", "in": ["lawn_area"], "params": { "height": 0.1, "plane": "xz" } },
    "lawn_named": { "type": "attrib_create", "in": ["lawn_solid"], "params": { "name": "name", "class": "prim", "value": "park_lawn" } },
    "lawn": { "type": "material", "in": ["lawn_named"], "params": { "name": "lawn", "base_color": "#6f9a4a", "roughness": 0.95 } },
    "path_solid": { "type": "extrude", "in": ["path_area"], "params": { "height": 0.08, "plane": "xz" } },
    "path_named": { "type": "attrib_create", "in": ["path_solid"], "params": { "name": "name", "class": "prim", "value": "park_paths" } },
    "paths": { "type": "material", "in": ["path_named"], "params": { "name": "gravel", "base_color": "#cdbf9f", "roughness": 0.95 } },

    "promenade": { "type": "delete", "in": ["path_lines"], "params": { "group": "@path=promenade", "keep": true } },
    "bench_line_pts": { "type": "points_along_curve", "in": ["promenade"], "params": { "spacing": 11, "start_offset": 5, "end_offset": 5, "side_offset": 1.75, "both_sides": true } },
    "no_bench_zone": { "type": "merge", "in": ["entrance_lines", "plaza"] },
    "entrance_lines": { "type": "delete", "in": ["path_lines"], "params": { "group": "@path=entrance", "keep": true } },
    "bench_clear": { "type": "prune", "in": ["bench_line_pts", "no_bench_zone"], "params": { "mode": "near_geometry", "distance": 2.6, "inside": true } },
    "bench_some": { "type": "prune", "in": ["bench_clear"], "params": { "mode": "density", "attrib": "keep", "fraction": 0.8, "seed": "=seed" } },
    "bench_face_path": { "type": "wrangle", "in": ["bench_some"], "note": "the seat (+Z) faces the path", "params": { "run_over": "points", "code": "const T = @tangent, s = @side;\nf@yaw = degrees(Math.atan2(s * T[2], -s * T[0]));\n@P.y = 0.1;" } },
    "plaza_bench_pts": { "type": "wrangle", "in": ["none", "path_lines"], "note": "four benches on the diagonals round the plaza, facing its middle", "params": { "run_over": "detail", "code": "const R = Math.min(5, 0.18 * (35 - road_width / 2 - 3.15)) + 0.9, zc = detail(1, 'plaza_z');\nfor (const a of [45, 135, 225, 315]) {\n  const t = radians(a), p = addpoint(0, [R * Math.cos(t), 0.1, zc + R * Math.sin(t)]);\n  setpointattrib(0, 'yaw', p, degrees(Math.atan2(-Math.cos(t), -Math.sin(t))));\n}" } },
    "bench_sites": { "type": "merge", "in": ["bench_face_path", "plaza_bench_pts"] },
    "bench_sites_clean": { "type": "attrib_delete", "in": ["bench_sites"], "params": { "names": "orient N up tangent curveu curve_id side path" } },
    "bench_long": { "type": "topotopo/street/bench", "params": { "bench_length": 1.8, "seed": "=seed % 1000" } },
    "bench_short": { "type": "topotopo/street/bench", "params": { "bench_length": 1.4, "backrest": false, "seed": "=(seed + 7) % 1000" } },
    "bench_long_kind": { "type": "attrib_create", "in": ["bench_long"], "params": { "name": "kind", "class": "prim", "value": "long" } },
    "bench_short_kind": { "type": "attrib_create", "in": ["bench_short"], "params": { "name": "kind", "class": "prim", "value": "short" } },
    "bench_kit": { "type": "merge", "in": ["bench_long_kind", "bench_short_kind"] },
    "benches": { "type": "copy_to_points", "in": ["bench_kit", "bench_sites_clean"], "params": { "pack": true, "piece_attrib": "kind", "variant_weights": { "long": 3, "short": 1 }, "seed": "=seed", "rotate_attrib": "yaw" } },

    "tree_rect": { "type": "grid", "note": "trees keep 3.5 m from the park's ends and back (their crowns stay inside) and 2.5 m from the pavement", "params": { "size": ["=street_length - 7", "=35 - road_width / 2 - 3.15 - 6"], "center": [0, 0, "=(35 - 3.5 + road_width / 2 + 3.15 + 2.5) / 2"], "divisions": [1, 1] } },
    "path_margin": { "type": "offset_curve", "in": ["path_area"], "params": { "distance": 1.5 } },
    "tree_ground": { "type": "boolean2d", "in": ["tree_rect", "path_margin"], "params": { "operation": "subtract", "output": "faces" } },
    "tree_scatter": { "type": "scatter", "in": ["tree_ground"], "params": { "generate_by": "density", "density": "=0.045 * park_density", "min_distance": 5, "seed": "=seed" } },
    "tree_scatter_on": { "type": "switch", "in": ["none", "tree_scatter"], "note": "an empty park at density 0", "params": { "index": "=park_density > 0 ? 1 : 0" } },
    "tree_scatter_up": { "type": "attrib_delete", "in": ["tree_scatter_on"], "note": "workaround: the scatter writes the ground normal N, which would turn the copies; drop it so the trees stand upright", "params": { "names": "N sourceprim" } },
    "tree_keep_out": { "type": "merge", "in": ["bench_sites_clean", "plaza_tree_site"] },
    "tree_clear": { "type": "prune", "in": ["tree_scatter_up", "tree_keep_out"], "params": { "mode": "near_geometry", "distance": 2.5, "inside": false } },
    "tree_sites": { "type": "wrangle", "in": ["tree_clear"], "note": "on the lawn; turned in quarter turns, so their bounds stay exact", "params": { "run_over": "points", "code": "@P.y = 0.1;\nf@yaw = Math.floor(rand(@ptnum, seed, 3) * 4) * 90;\nf@size = 0.85 + rand(@ptnum, seed, 4) * 0.3;" } },
    "tree_round": { "type": "topotopo/nature/tree_lowpoly", "params": { "style": "round", "height": 7, "canopy_radius": 2.4, "seed": "=seed % 1000" } },
    "tree_conifer": { "type": "topotopo/nature/tree_lowpoly", "params": { "style": "conifer", "height": 9, "canopy_radius": 2, "seed": "=(seed + 3) % 1000" } },
    "tree_poplar": { "type": "topotopo/nature/tree_lowpoly", "params": { "style": "poplar", "height": 10, "canopy_radius": 1.4, "seed": "=(seed + 5) % 1000" } },
    "tree_round_kind": { "type": "attrib_create", "in": ["tree_round"], "params": { "name": "kind", "class": "prim", "value": "round" } },
    "tree_conifer_kind": { "type": "attrib_create", "in": ["tree_conifer"], "params": { "name": "kind", "class": "prim", "value": "conifer" } },
    "tree_poplar_kind": { "type": "attrib_create", "in": ["tree_poplar"], "params": { "name": "kind", "class": "prim", "value": "poplar" } },
    "tree_kit": { "type": "merge", "in": ["tree_round_kind", "tree_conifer_kind", "tree_poplar_kind"] },
    "trees": { "type": "copy_to_points", "in": ["tree_kit", "tree_sites"], "params": { "pack": true, "piece_attrib": "kind", "variant_weights": { "round": 4, "conifer": 3, "poplar": 2 }, "seed": "=seed", "rotate_attrib": "yaw", "scale_attrib": "size" } },
    "plaza_tree_site": { "type": "points", "params": { "positions": [[0, 0.1, "=detail('path_lines', 'plaza_z')"]] } },
    "plaza_tree": { "type": "topotopo/nature/tree_lowpoly", "params": { "style": "round", "height": 8.5, "canopy_radius": 2.8, "seed": "=(seed + 11) % 1000" } },
    "plaza_tree_placed": { "type": "copy_to_points", "in": ["plaza_tree", "plaza_tree_site"], "params": { "pack": true } },
    "plaza_tree_on": { "type": "switch", "in": ["none", "plaza_tree_placed"], "params": { "index": "=park_density > 0 ? 1 : 0" } },

    "bush_rect": { "type": "grid", "note": "bushes keep 2.2 m from the park's ends and back (their bounds turned any way stay inside), and stay behind the hedge", "params": { "size": ["=street_length - 4.4", "=35 - road_width / 2 - 3.15 - 4.8"], "center": [0, 0, "=(35 - 2.2 + road_width / 2 + 3.15 + 2.6) / 2"], "divisions": [1, 1] } },
    "bush_margin": { "type": "offset_curve", "in": ["path_area"], "params": { "distance": 0.9 } },
    "bush_ground": { "type": "boolean2d", "in": ["bush_rect", "bush_margin"], "params": { "operation": "subtract", "output": "faces" } },
    "bush_scatter": { "type": "scatter", "in": ["bush_ground"], "params": { "generate_by": "density", "density": "=0.06 * park_density", "min_distance": 2.5, "seed": "=seed + 1" } },
    "bush_keep_out": { "type": "merge", "in": ["tree_sites", "bench_sites_clean", "plaza_tree_site"] },
    "bush_scatter_on": { "type": "switch", "in": ["none", "bush_scatter"], "params": { "index": "=park_density > 0 ? 1 : 0" } },
    "bush_scatter_up": { "type": "attrib_delete", "in": ["bush_scatter_on"], "note": "workaround: drop the scatter's N so the bushes stand upright", "params": { "names": "N sourceprim" } },
    "bush_clear": { "type": "prune", "in": ["bush_scatter_up", "bush_keep_out"], "params": { "mode": "near_geometry", "distance": 2, "inside": false } },
    "bush_sites": { "type": "wrangle", "in": ["bush_clear"], "params": { "run_over": "points", "code": "@P.y = 0.1;\nf@yaw = rand(@ptnum, seed, 5) * 360;\nf@size = 0.8 + rand(@ptnum, seed, 6) * 0.45;" } },
    "bush_a": { "type": "topotopo/nature/bush", "params": { "size": 2, "height": 1.3, "seed": "=seed % 1000" } },
    "bush_b": { "type": "topotopo/nature/bush", "params": { "size": 1.5, "height": 1, "blobs": 5, "seed": "=(seed + 2) % 1000" } },
    "bush_a_kind": { "type": "attrib_create", "in": ["bush_a"], "params": { "name": "kind", "class": "prim", "value": "a" } },
    "bush_b_kind": { "type": "attrib_create", "in": ["bush_b"], "params": { "name": "kind", "class": "prim", "value": "b" } },
    "bush_kit": { "type": "merge", "in": ["bush_a_kind", "bush_b_kind"] },
    "bushes": { "type": "copy_to_points", "in": ["bush_kit", "bush_sites"], "params": { "pack": true, "piece_attrib": "kind", "variant_weights": { "a": 1, "b": 1 }, "seed": "=seed + 1", "rotate_attrib": "yaw", "scale_attrib": "size" } },

    "hedge_lines": {
      "type": "wrangle", "in": ["none"],
      "note": "a hedge along the pavement, open where the entrances come in",
      "params": { "run_over": "detail", "code": "const L = street_length, z = road_width / 2 + 3.15 + 0.9, m = 2 * Math.floor(L / 100) + 1;\nlet x0 = -L / 2 + 1.6;\nconst run = (a, b) => { if (b - a > 1) addprim(0, 'polyline', [addpoint(0, [a, 0.1, z]), addpoint(0, [b, 0.1, z])]); };\nfor (let j = 0; j < m; j++) { const x = -L / 2 + (j + 0.5) * L / m; run(x0, x - 2.1); x0 = x + 2.1; }\nrun(x0, L / 2 - 1.6);" }
    },
    "hedge_pts": { "type": "points_along_curve", "in": ["hedge_lines"], "params": { "spacing": 1, "start_offset": 0.3, "end_offset": 0.3 } },
    "hedge_sites": { "type": "wrangle", "in": ["hedge_pts"], "params": { "run_over": "points", "code": "f@yaw = rand(@ptnum, seed, 7) * 360;\nf@size = 0.9 + rand(@ptnum, seed, 8) * 0.2;" } },
    "hedge_sites_clean": { "type": "attrib_delete", "in": ["hedge_sites"], "params": { "names": "orient N up tangent curveu curve_id" } },
    "hedge_bush": { "type": "topotopo/nature/bush", "params": { "size": 1.5, "height": 1, "blobs": 6, "seed": "=(seed + 4) % 1000" } },
    "hedge": { "type": "copy_to_points", "in": ["hedge_bush", "hedge_sites_clean"], "params": { "pack": true, "rotate_attrib": "yaw", "scale_attrib": "size" } },

    "park_parts": { "type": "merge", "in": ["lawn", "paths", "benches", "trees", "plaza_tree_on", "bushes", "hedge"] },
    "park_paint": { "type": "wrangle", "in": ["park_parts"], "note": "Cd follows each prim's material (the recoloured walls, roofs and doors too), for viewers and formats that show Cd", "params": { "run_over": "detail", "code": "const table = JSON.parse(detail(0, 'materials') || '{}');\nfor (let p = 0; p < nprims(0); p++) { const m = table[prim(0, 'material', p)]; if (m) setprimattrib(0, 'Cd', p, m.baseColor); }" } },
    "park_grounded": { "type": "assert", "in": ["park_paint"], "params": { "label": "grounded", "expr": "bbox.min.y >= -0.0001" } },
    "park": { "type": "assert", "in": ["park_grounded"], "params": { "label": "fits", "expr": "bbox.min.x >= -street_length / 2 - 0.001 && bbox.max.x <= street_length / 2 + 0.001 && bbox.min.z >= -35.001 && bbox.max.z <= 35.001" } },

    "ground": { "type": "grid", "params": { "size": ["=street_length", 70], "divisions": [1, 1] } },
    "ground_named": { "type": "attrib_create", "in": ["ground"], "params": { "name": "name", "class": "prim", "value": "ground" } },
    "ground_mat": { "type": "material", "in": ["ground_named"], "params": { "name": "grass", "base_color": "#7d9455", "roughness": 0.95 } },
    "ground_paint": { "type": "color", "in": ["ground_mat"], "params": { "class": "prim", "color": "#7d9455" } },
    "block_parts": { "type": "merge", "in": ["ground_paint", "street", "houses", "park"] },
    "block_grounded": { "type": "assert", "in": ["block_parts"], "note": "every point of the block (the instances' anchors too) on or above the ground; the instances' own bounds are checked by each part's asserts", "params": { "label": "grounded", "bbox_min": [-100000, 0, -100000], "tolerance": 0.0001 } },
    "block": { "type": "assert", "in": ["block_grounded"], "note": "every point of the block within the street's length and 70 m across; the instances' own bounds are checked by each part's asserts", "params": { "label": "fits", "bbox_min": ["=-street_length / 2", -100000, -35], "bbox_max": ["=street_length / 2", 100000, 35], "tolerance": 0.001 } }
  },
  "output": "block",
  "outputs": {
    "street": { "node": "street", "label": "Street", "kind": "scene", "tags": ["street", "road", "pavement", "lamp-posts", "level-design"], "description": "The road with kerbs, pavements, lane markings and a zebra crossing, and lamp posts on both pavements (packed instances)." },
    "houses": { "node": "houses", "label": "Houses", "kind": "scene", "tags": ["houses", "town", "terrace", "roofs", "level-design"], "description": "The row of houses along the -Z pavement: walls with windows and doors, gable or hip roofs and chimneys (packed instances), and behind them fenced back gardens with a tree each (packed instances)." },
    "park": { "node": "park", "label": "Park", "kind": "scene", "tags": ["park", "trees", "benches", "paths", "level-design"], "description": "The park along the +Z pavement: the lawn, gravel paths and a plaza, and trees, bushes and benches (packed instances)." },
    "block": { "node": "block", "label": "Block", "kind": "scene", "tags": ["street", "town", "block", "level-design", "scene"], "description": "The street, the houses and the park together on the ground: a 70 m deep level block as long as the street." }
  }
}
