roamwright 0.61.16 → 0.61.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +25 -24
- package/examples/land-features.js +130 -9
- package/examples/land.html +2 -1
- package/examples/land.js +17 -2
- package/examples/ruins.html +3 -2
- package/examples/ruins.js +184 -37
- package/examples/world-map.html +162 -0
- package/examples/world-map.js +475 -0
- package/geometry/farm-props.js +59 -0
- package/geometry/field-map.js +147 -0
- package/geometry/instances.js +40 -0
- package/geometry/plant-tuft.js +138 -0
- package/geometry/ruins-breach.js +329 -0
- package/geometry/ruins-crater.js +269 -0
- package/geometry/ruins-masonry.js +323 -0
- package/geometry/ruins-walls.js +272 -0
- package/geometry/strata-mesa.js +114 -0
- package/geometry/strata-rocks.js +73 -2
- package/index.js +109 -1
- package/package.json +1 -1
- package/rendering/contact-shadows.js +56 -0
- package/rendering/crowd-lifecycle.js +80 -0
- package/rendering/farm-plough.js +145 -0
- package/rendering/map-glyphs.js +494 -0
- package/rendering/map-input.js +143 -0
- package/rendering/map-labels.js +181 -0
- package/rendering/map-relief.js +330 -0
- package/rendering/map-signs.js +124 -0
- package/rendering/place-names.js +408 -0
- package/rendering/plant-tuft.js +190 -0
- package/rendering/portrait-studio.js +213 -0
- package/rendering/ruins-fittings.js +199 -0
- package/rendering/ruins-mound.js +103 -0
- package/rendering/screen-pick.js +75 -0
- package/runtime/build-freshness.js +133 -0
- package/runtime/compass-strip.js +232 -0
- package/runtime/context-lost.js +108 -0
- package/runtime/doorways.js +98 -0
- package/runtime/hud-frame.js +74 -0
- package/runtime/map-relief.js +236 -0
- package/runtime/map-spot.js +120 -0
- package/runtime/map-view.js +229 -0
- package/runtime/panel-shell.js +90 -0
- package/runtime/relation-graph.js +163 -0
- package/runtime/stage-frame.js +263 -0
- package/runtime/url-router.js +162 -0
- package/runtime/way-back.js +71 -0
- package/runtime/whereabouts.js +210 -0
- package/runtime/world-controls.js +265 -0
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8" />
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
6
|
+
<meta name="theme-color" content="#152c2c" />
|
|
7
|
+
<title>World map and wayfinding · Roamwright</title>
|
|
8
|
+
<link rel="stylesheet" href="./showcase.css" />
|
|
9
|
+
<style>
|
|
10
|
+
aside#wayfinding {
|
|
11
|
+
position: absolute;
|
|
12
|
+
top: 56px;
|
|
13
|
+
left: 50%;
|
|
14
|
+
transform: translateX(-50%);
|
|
15
|
+
z-index: 2;
|
|
16
|
+
display: flex;
|
|
17
|
+
flex-direction: column;
|
|
18
|
+
align-items: center;
|
|
19
|
+
gap: 4px;
|
|
20
|
+
pointer-events: none;
|
|
21
|
+
}
|
|
22
|
+
#compass {
|
|
23
|
+
position: relative;
|
|
24
|
+
width: min(360px, 76vw);
|
|
25
|
+
height: 28px;
|
|
26
|
+
overflow: hidden;
|
|
27
|
+
border: 1px solid #f7edcf48;
|
|
28
|
+
border-radius: 0.45rem;
|
|
29
|
+
background: #0f2324d8;
|
|
30
|
+
}
|
|
31
|
+
#compass-strip {
|
|
32
|
+
position: absolute;
|
|
33
|
+
top: 0;
|
|
34
|
+
left: 0;
|
|
35
|
+
height: 100%;
|
|
36
|
+
will-change: transform;
|
|
37
|
+
}
|
|
38
|
+
#compass-strip span,
|
|
39
|
+
#compass-strip i {
|
|
40
|
+
position: absolute;
|
|
41
|
+
top: 4px;
|
|
42
|
+
transform: translateX(-50%);
|
|
43
|
+
font-size: 11px;
|
|
44
|
+
color: #d9e8e3;
|
|
45
|
+
}
|
|
46
|
+
#compass-strip span.c {
|
|
47
|
+
font-weight: 700;
|
|
48
|
+
color: #fff6df;
|
|
49
|
+
}
|
|
50
|
+
#compass-strip span.n {
|
|
51
|
+
color: #ffb25a;
|
|
52
|
+
}
|
|
53
|
+
#compass-strip i {
|
|
54
|
+
top: 10px;
|
|
55
|
+
width: 1px;
|
|
56
|
+
height: 6px;
|
|
57
|
+
background: #f7edcf55;
|
|
58
|
+
}
|
|
59
|
+
#compass-strip .mk {
|
|
60
|
+
position: absolute;
|
|
61
|
+
bottom: 2px;
|
|
62
|
+
width: 5px;
|
|
63
|
+
height: 5px;
|
|
64
|
+
border-radius: 50%;
|
|
65
|
+
background: #62e6cb;
|
|
66
|
+
transform: translateX(-50%);
|
|
67
|
+
}
|
|
68
|
+
#compass-strip .mk.wp {
|
|
69
|
+
background: #ffb25a;
|
|
70
|
+
}
|
|
71
|
+
#compass-strip .mk b {
|
|
72
|
+
display: none;
|
|
73
|
+
}
|
|
74
|
+
#where-line {
|
|
75
|
+
padding: 3px 10px;
|
|
76
|
+
border-radius: 0.35rem;
|
|
77
|
+
background: #0f2324cc;
|
|
78
|
+
font-size: 12px;
|
|
79
|
+
color: #f3ecd9;
|
|
80
|
+
white-space: nowrap;
|
|
81
|
+
}
|
|
82
|
+
#pick-card {
|
|
83
|
+
position: absolute;
|
|
84
|
+
right: clamp(10px, 1.8vw, 22px);
|
|
85
|
+
top: 62px;
|
|
86
|
+
z-index: 2;
|
|
87
|
+
max-width: 240px;
|
|
88
|
+
padding: 8px 11px;
|
|
89
|
+
border: 1px solid #f7edcf48;
|
|
90
|
+
border-radius: 0.45rem;
|
|
91
|
+
background: #0f2324e4;
|
|
92
|
+
color: #f3ecd9;
|
|
93
|
+
font-size: 12px;
|
|
94
|
+
pointer-events: auto;
|
|
95
|
+
}
|
|
96
|
+
#pick-card b {
|
|
97
|
+
display: block;
|
|
98
|
+
font-size: 13px;
|
|
99
|
+
color: #fff6df;
|
|
100
|
+
}
|
|
101
|
+
#pick-card small {
|
|
102
|
+
display: block;
|
|
103
|
+
color: #8ff0dc;
|
|
104
|
+
margin: 2px 0 4px;
|
|
105
|
+
}
|
|
106
|
+
#pick-card p {
|
|
107
|
+
margin: 0;
|
|
108
|
+
color: #d9e8e3;
|
|
109
|
+
}
|
|
110
|
+
</style>
|
|
111
|
+
<script type="importmap">
|
|
112
|
+
{
|
|
113
|
+
"imports": {
|
|
114
|
+
"three": "../node_modules/three/build/three.module.js",
|
|
115
|
+
"three/addons/": "../node_modules/three/examples/jsm/",
|
|
116
|
+
"roamwright": "../index.js",
|
|
117
|
+
"roamwright/": "../"
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
</script>
|
|
121
|
+
</head>
|
|
122
|
+
<body>
|
|
123
|
+
<canvas
|
|
124
|
+
tabindex="0"
|
|
125
|
+
aria-label="Interactive cartographic atlas and shaded terrain map with collision-free labels, signs and relief"
|
|
126
|
+
></canvas>
|
|
127
|
+
<header>
|
|
128
|
+
<a class="back" href="../index.html"><span aria-hidden="true">←</span> Roamwright</a>
|
|
129
|
+
<div class="meta">
|
|
130
|
+
<a class="source" href="https://github.com/enestaylan/roamwright/blob/main/examples/world-map.js">Source</a>
|
|
131
|
+
<form method="get">
|
|
132
|
+
<label for="seed">Seed</label>
|
|
133
|
+
<input id="seed" name="seed" type="number" step="1" min="-2147483648" max="2147483647" value="42" required />
|
|
134
|
+
<button type="submit" title="Generate another archipelago" aria-label="Generate another archipelago">→</button>
|
|
135
|
+
</form>
|
|
136
|
+
</div>
|
|
137
|
+
</header>
|
|
138
|
+
<aside id="wayfinding" aria-label="Compass and whereabouts">
|
|
139
|
+
<div id="compass"><div id="compass-strip"></div></div>
|
|
140
|
+
<div id="where-line"></div>
|
|
141
|
+
</aside>
|
|
142
|
+
<aside id="pick-card" hidden aria-label="Selected place">
|
|
143
|
+
<b id="pick-name"></b>
|
|
144
|
+
<small id="pick-kind"></small>
|
|
145
|
+
<p id="pick-desc"></p>
|
|
146
|
+
</aside>
|
|
147
|
+
<footer>
|
|
148
|
+
<div class="caption">
|
|
149
|
+
<h1>World map and wayfinding</h1>
|
|
150
|
+
<p>Shaded atlas relief, baked terrain sheets, collision-free lettering, interactive pan/zoom/tap, and a live compass strip.</p>
|
|
151
|
+
</div>
|
|
152
|
+
<div class="tools">
|
|
153
|
+
<div class="views" role="group" aria-label="Map view">
|
|
154
|
+
<button type="button" data-view="atlas" aria-pressed="true">Atlas</button>
|
|
155
|
+
<button type="button" data-view="terrain" aria-pressed="false">Terrain sheet</button>
|
|
156
|
+
<button type="button" data-view="parchment" aria-pressed="false">Parchment</button>
|
|
157
|
+
</div>
|
|
158
|
+
</div>
|
|
159
|
+
</footer>
|
|
160
|
+
<script type="module" src="./world-map.js"></script>
|
|
161
|
+
</body>
|
|
162
|
+
</html>
|
|
@@ -0,0 +1,475 @@
|
|
|
1
|
+
import {
|
|
2
|
+
bearingOf,
|
|
3
|
+
bindMapInput,
|
|
4
|
+
clusterMapPoints,
|
|
5
|
+
createAtlasRelief,
|
|
6
|
+
createCompassStrip,
|
|
7
|
+
createMapLabelSet,
|
|
8
|
+
createNoise,
|
|
9
|
+
createWhereabouts,
|
|
10
|
+
distanceText,
|
|
11
|
+
drawMapCompass,
|
|
12
|
+
drawMapGlyph,
|
|
13
|
+
drawMapLabel,
|
|
14
|
+
drawMapScaleBar,
|
|
15
|
+
formatSpotCard,
|
|
16
|
+
frameMapSheet,
|
|
17
|
+
mulberry32,
|
|
18
|
+
paintMapPick,
|
|
19
|
+
paintMapVisitor,
|
|
20
|
+
paintTerrainSheet,
|
|
21
|
+
pickMapHit,
|
|
22
|
+
rectUnionOutline,
|
|
23
|
+
roundedDistance,
|
|
24
|
+
sheetMaxZoom,
|
|
25
|
+
sheetMinZoom,
|
|
26
|
+
spacedCaps,
|
|
27
|
+
} from 'roamwright';
|
|
28
|
+
import { clamp, sstep } from 'roamwright/math/scalar.js';
|
|
29
|
+
import { readSeed } from './stage.js';
|
|
30
|
+
|
|
31
|
+
const seed = readSeed(42);
|
|
32
|
+
const random = mulberry32(seed);
|
|
33
|
+
const noise = createNoise(seed);
|
|
34
|
+
|
|
35
|
+
const byId = id => document.getElementById(id);
|
|
36
|
+
const canvas = document.querySelector('canvas');
|
|
37
|
+
const ctx = canvas.getContext('2d');
|
|
38
|
+
const [whereLine, pickCard, pickName, pickKind, pickDesc] = ['where-line', 'pick-card', 'pick-name', 'pick-kind', 'pick-desc'].map(byId);
|
|
39
|
+
const pairs = flat => Array.from({ length: flat.length / 2 }, (_, i) => [flat[i * 2], flat[i * 2 + 1]]);
|
|
40
|
+
|
|
41
|
+
const SHEET_W = 1600;
|
|
42
|
+
const SHEET_H = 1000;
|
|
43
|
+
const LAND_SIZE = 2000;
|
|
44
|
+
const STRIDE = 192;
|
|
45
|
+
|
|
46
|
+
// Generate a seeded western continent and eastern archipelago with bays and peninsulas.
|
|
47
|
+
function makeIslandPoly(cx, cy, rx, ry, sides, lobeAmp = 0.28, phase = 0) {
|
|
48
|
+
const poly = [];
|
|
49
|
+
for (let i = 0; i < sides; i++) {
|
|
50
|
+
const a = (i / sides) * Math.PI * 2;
|
|
51
|
+
const lobe = 1 + lobeAmp * Math.sin(a * 2 + phase) + 0.14 * Math.cos(a * 3 - phase * 0.7);
|
|
52
|
+
const warp = (0.76 + 0.36 * noise.fbm(Math.cos(a) * 1.6 + cx * 0.01, Math.sin(a) * 1.6 + cy * 0.01, 3, 19)) * lobe;
|
|
53
|
+
poly.push([cx + Math.cos(a) * rx * warp, cy + Math.sin(a) * ry * warp]);
|
|
54
|
+
}
|
|
55
|
+
return poly;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const westPoly = makeIslandPoly(440, 490, 310, 240, 18, 0.24, 0.4);
|
|
59
|
+
const eastPoly = makeIslandPoly(1145, 490, 275, 245, 16, 0.22, -0.8);
|
|
60
|
+
const islePoly = makeIslandPoly(830, 755, 108, 66, 11, 0.18, 1.1);
|
|
61
|
+
|
|
62
|
+
const frameBox = { x: 960, y: 290, side: 360 };
|
|
63
|
+
const frameOutline = rectUnionOutline([frameBox]);
|
|
64
|
+
|
|
65
|
+
const atlasRelief = createAtlasRelief({
|
|
66
|
+
sheetWidth: SHEET_W,
|
|
67
|
+
sheetHeight: SHEET_H,
|
|
68
|
+
seed: seed * 17 + 4411,
|
|
69
|
+
lands: [{ poly: westPoly }, { poly: eastPoly }, { poly: islePoly }],
|
|
70
|
+
relief: [
|
|
71
|
+
{
|
|
72
|
+
k: 'range',
|
|
73
|
+
pts: pairs([280, 360 + (random() - 0.5) * 40, 430, 430 + (random() - 0.5) * 40, 560, 560 + (random() - 0.5) * 30]),
|
|
74
|
+
w: 28,
|
|
75
|
+
size: 6,
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
k: 'range',
|
|
79
|
+
pts: pairs([1020, 350 + (random() - 0.5) * 30, 1180, 410 + (random() - 0.5) * 30, 1280, 520 + (random() - 0.5) * 30]),
|
|
80
|
+
w: 22,
|
|
81
|
+
size: 5.5,
|
|
82
|
+
},
|
|
83
|
+
{ k: 'forest', at: [390, 570], r: [95, 75], turn: 0.25 },
|
|
84
|
+
{ k: 'forest', at: [1090, 540], r: [85, 65], turn: -0.3 },
|
|
85
|
+
{ k: 'desert', at: [570, 390], r: [88, 62], turn: -0.2 },
|
|
86
|
+
{ k: 'plateau', at: [1220, 580], r: [52, 34], turn: 0.35 },
|
|
87
|
+
{ k: 'water', at: [1135, 470], r: [32, 22], turn: 0.1 },
|
|
88
|
+
],
|
|
89
|
+
rivers: [pairs([420, 440, 480, 500, 540, 560, 620, 620, 690, 660]), pairs([1150, 390, 1135, 470, 1080, 540, 1010, 610])],
|
|
90
|
+
routes: [
|
|
91
|
+
{ n: 'Eastbound Merchant Passage', book: 1, pts: pairs([690, 640, 835, 665, 980, 585]) },
|
|
92
|
+
{ n: 'Northern Trade Run', book: 2, pts: pairs([660, 360, 810, 285, 985, 360]) },
|
|
93
|
+
],
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
// Bake a procedural island heightfield for the Terrain sheet and Parchment views.
|
|
97
|
+
const heights = new Float32Array(STRIDE * STRIDE);
|
|
98
|
+
const colors = new Uint8Array(STRIDE * STRIDE * 3);
|
|
99
|
+
for (let j = 0; j < STRIDE; j++) {
|
|
100
|
+
for (let i = 0; i < STRIDE; i++) {
|
|
101
|
+
const nx = (i / (STRIDE - 1)) * 2 - 1;
|
|
102
|
+
const nz = (j / (STRIDE - 1)) * 2 - 1;
|
|
103
|
+
const radial = Math.hypot(nx * 1.05, nz * 1.15);
|
|
104
|
+
const shape = 1 - sstep(0.42, 0.94, radial + 0.16 * noise.fbm(nx * 2.2, nz * 2.2, 3, 31));
|
|
105
|
+
const ridge = 42 * noise.ridged(nx * 2.8, nz * 2.8, 4, 17);
|
|
106
|
+
const h = -12 + shape * (24 + ridge + 14 * noise.fbm(nx * 3.4, nz * 3.4, 3, 5));
|
|
107
|
+
const k = j * STRIDE + i;
|
|
108
|
+
heights[k] = h;
|
|
109
|
+
const meadow = sstep(2, 16, h);
|
|
110
|
+
const rock = sstep(28, 46, h);
|
|
111
|
+
colors[k * 3] = clamp(Math.round(196 * (1 - meadow) + 122 * meadow * (1 - rock) + 150 * rock), 0, 255);
|
|
112
|
+
colors[k * 3 + 1] = clamp(Math.round(178 * (1 - meadow) + 142 * meadow * (1 - rock) + 146 * rock), 0, 255);
|
|
113
|
+
colors[k * 3 + 2] = clamp(Math.round(132 * (1 - meadow) + 92 * meadow * (1 - rock) + 138 * rock), 0, 255);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
const land = {
|
|
118
|
+
id: 'isle',
|
|
119
|
+
name: 'Alder Reach',
|
|
120
|
+
x0: -LAND_SIZE / 2,
|
|
121
|
+
z0: -LAND_SIZE / 2,
|
|
122
|
+
size: LAND_SIZE,
|
|
123
|
+
stride: STRIDE,
|
|
124
|
+
colors,
|
|
125
|
+
depth: k => -heights[k],
|
|
126
|
+
normal(k, out) {
|
|
127
|
+
const i = k % STRIDE;
|
|
128
|
+
const j = (k / STRIDE) | 0;
|
|
129
|
+
const hL = heights[j * STRIDE + Math.max(0, i - 1)];
|
|
130
|
+
const hR = heights[j * STRIDE + Math.min(STRIDE - 1, i + 1)];
|
|
131
|
+
const hU = heights[Math.max(0, j - 1) * STRIDE + i];
|
|
132
|
+
const hD = heights[Math.min(STRIDE - 1, j + 1) * STRIDE + i];
|
|
133
|
+
const dx = (hL - hR) * 0.12;
|
|
134
|
+
const dz = (hU - hD) * 0.12;
|
|
135
|
+
const len = Math.hypot(dx, 1, dz);
|
|
136
|
+
out[0] = dx / len;
|
|
137
|
+
out[1] = 1 / len;
|
|
138
|
+
out[2] = dz / len;
|
|
139
|
+
return out;
|
|
140
|
+
},
|
|
141
|
+
toAtlas: (x, z) => [
|
|
142
|
+
frameBox.x + ((x + LAND_SIZE / 2) / LAND_SIZE) * frameBox.side,
|
|
143
|
+
frameBox.y + ((z + LAND_SIZE / 2) / LAND_SIZE) * frameBox.side,
|
|
144
|
+
],
|
|
145
|
+
fromAtlas: (x, y) => [
|
|
146
|
+
((x - frameBox.x) / frameBox.side) * LAND_SIZE - LAND_SIZE / 2,
|
|
147
|
+
((y - frameBox.y) / frameBox.side) * LAND_SIZE - LAND_SIZE / 2,
|
|
148
|
+
],
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
const shadedSheet = paintTerrainSheet(land, true, { noise: noise.vnoise });
|
|
152
|
+
const parchmentSheet = paintTerrainSheet(land, false, { noise: noise.vnoise });
|
|
153
|
+
|
|
154
|
+
const atlasPlaces = [
|
|
155
|
+
{ n: 'Highhaven', x: 640, y: 610, k: 'cities', kind: 'Harbour city', desc: 'Walled trading port at the river mouth.' },
|
|
156
|
+
{ n: 'Cairnwatch', x: 350, y: 455, k: 'holy', kind: 'Sanctuary', desc: 'Stone citadel overlooking the western pass.' },
|
|
157
|
+
{ n: 'Alderford', x: 1090, y: 495, k: 'cities', kind: 'City', desc: 'Timber and stone town beside the central lake.' },
|
|
158
|
+
{ n: 'Saltmere', x: 1240, y: 435, k: 'town', kind: 'Town', desc: 'Quarry town below the eastern ridge.' },
|
|
159
|
+
{ n: 'South Beacon', x: 835, y: 745, k: 'enter', kind: 'Lighthouse', desc: 'Enterable stone tower guarding the channel.' },
|
|
160
|
+
{ n: 'Old Crossing', x: 520, y: 530, k: 'battle', kind: 'Historic ford', desc: 'Stone bridgehead across the valley river.' },
|
|
161
|
+
];
|
|
162
|
+
|
|
163
|
+
const landPlaces = [
|
|
164
|
+
{ id: 'alderford', space: 'isle', kind: 'city', name: 'Alderford', x: -120, z: 60, desc: 'Market town on the sheltered cove.' },
|
|
165
|
+
{
|
|
166
|
+
id: 'ridgekeep',
|
|
167
|
+
space: 'isle',
|
|
168
|
+
kind: 'landmark',
|
|
169
|
+
name: 'Ridgekeep',
|
|
170
|
+
x: 240,
|
|
171
|
+
z: -180,
|
|
172
|
+
enter: true,
|
|
173
|
+
desc: 'Enterable stone watchtower on the northern crest.',
|
|
174
|
+
},
|
|
175
|
+
{
|
|
176
|
+
id: 'oldmill',
|
|
177
|
+
space: 'isle',
|
|
178
|
+
kind: 'landmark',
|
|
179
|
+
name: 'The Old Mill',
|
|
180
|
+
x: -340,
|
|
181
|
+
z: -160,
|
|
182
|
+
desc: 'Watermill at the head of the valley stream.',
|
|
183
|
+
},
|
|
184
|
+
{
|
|
185
|
+
id: 'cove',
|
|
186
|
+
space: 'isle',
|
|
187
|
+
kind: 'region',
|
|
188
|
+
name: 'Emerald Reach',
|
|
189
|
+
x: 60,
|
|
190
|
+
z: 290,
|
|
191
|
+
desc: 'Broad coastal grassland facing the south strait.',
|
|
192
|
+
},
|
|
193
|
+
];
|
|
194
|
+
|
|
195
|
+
const landMarkers = [
|
|
196
|
+
{ x: -100, z: 45, title: 'Harbour Fair' },
|
|
197
|
+
{ x: -80, z: 58, title: 'Timber Quay' },
|
|
198
|
+
{ x: 210, z: -140, title: 'Signal Fire' },
|
|
199
|
+
];
|
|
200
|
+
|
|
201
|
+
const landRoads = [pairs([-340, -160, -210, -50, -120, 60, 80, -30, 240, -180])];
|
|
202
|
+
const landRivers = [pairs([160, -420, 60, -210, -10, -40, -90, 120, -180, 390])];
|
|
203
|
+
|
|
204
|
+
const visitor = { x: -40, z: 120, yaw: 0.45 };
|
|
205
|
+
const state = {
|
|
206
|
+
mode: 'atlas',
|
|
207
|
+
wx: SHEET_W * 0.5,
|
|
208
|
+
wy: SHEET_H * 0.5,
|
|
209
|
+
wz: 1,
|
|
210
|
+
cx: 0,
|
|
211
|
+
cz: 0,
|
|
212
|
+
zoom: 1,
|
|
213
|
+
w: 1,
|
|
214
|
+
h: 1,
|
|
215
|
+
dpr: 1,
|
|
216
|
+
k: 1,
|
|
217
|
+
hits: [],
|
|
218
|
+
sel: { x: 640, z: 610, world: true, name: 'Highhaven', kind: 'Harbour city', desc: 'Walled trading port at the river mouth.' },
|
|
219
|
+
};
|
|
220
|
+
const mv = { x0: 0, z0: 0, k: 1, w: 1, h: 1, u: 1, mini: false };
|
|
221
|
+
|
|
222
|
+
const wb = createWhereabouts({
|
|
223
|
+
getLocations: () => landPlaces,
|
|
224
|
+
getSpace: () => ({ id: 'isle', flyable: true, name: 'Alder Reach' }),
|
|
225
|
+
});
|
|
226
|
+
const camProxy = { x: visitor.x, z: visitor.z, yaw: visitor.yaw };
|
|
227
|
+
const compass = createCompassStrip({
|
|
228
|
+
getStrip: () => document.getElementById('compass-strip'),
|
|
229
|
+
getContainer: () => document.getElementById('compass'),
|
|
230
|
+
getLocations: () => landPlaces,
|
|
231
|
+
getCamera: () => camProxy,
|
|
232
|
+
getWaypoint: () => ({ pos: { x: 240, z: -180 }, title: 'Ridgekeep' }),
|
|
233
|
+
kindOf: wb.kindOf,
|
|
234
|
+
placeOf(loc, out) {
|
|
235
|
+
if (!wb.placeOf(loc)) return false;
|
|
236
|
+
out.x = wb.placeAt.x;
|
|
237
|
+
out.z = wb.placeAt.z;
|
|
238
|
+
return true;
|
|
239
|
+
},
|
|
240
|
+
bearingOf,
|
|
241
|
+
roundDistance: roundedDistance,
|
|
242
|
+
formatDistance: distanceText,
|
|
243
|
+
});
|
|
244
|
+
compass.build();
|
|
245
|
+
|
|
246
|
+
function showPick(sel) {
|
|
247
|
+
state.sel = sel;
|
|
248
|
+
pickCard.hidden = !sel;
|
|
249
|
+
if (!sel) return;
|
|
250
|
+
pickName.textContent = sel.name;
|
|
251
|
+
pickKind.textContent = sel.kind || '';
|
|
252
|
+
pickDesc.textContent = sel.desc || '';
|
|
253
|
+
}
|
|
254
|
+
showPick(state.sel);
|
|
255
|
+
|
|
256
|
+
function resize() {
|
|
257
|
+
state.dpr = Math.min(window.devicePixelRatio || 1, 2);
|
|
258
|
+
const w = Math.max(1, window.innerWidth);
|
|
259
|
+
const h = Math.max(1, window.innerHeight);
|
|
260
|
+
state.w = canvas.width = Math.round(w * state.dpr);
|
|
261
|
+
state.h = canvas.height = Math.round(h * state.dpr);
|
|
262
|
+
}
|
|
263
|
+
window.addEventListener('resize', resize);
|
|
264
|
+
resize();
|
|
265
|
+
|
|
266
|
+
function zoomBy(factor) {
|
|
267
|
+
if (state.mode === 'atlas') state.wz = clamp(state.wz * factor, 1, 8);
|
|
268
|
+
else state.zoom = clamp(state.zoom * factor, sheetMinZoom(state.w, state.h), sheetMaxZoom(land.size));
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
bindMapInput(canvas, {
|
|
272
|
+
getSize: () => ({ w: state.w, h: state.h }),
|
|
273
|
+
onPan(dx, dy) {
|
|
274
|
+
const step = state.dpr / state.k;
|
|
275
|
+
if (state.mode === 'atlas') {
|
|
276
|
+
state.wx -= dx * step;
|
|
277
|
+
state.wy -= dy * step;
|
|
278
|
+
} else {
|
|
279
|
+
state.cx -= dx * step;
|
|
280
|
+
state.cz -= dy * step;
|
|
281
|
+
}
|
|
282
|
+
},
|
|
283
|
+
onZoom: zoomBy,
|
|
284
|
+
onTap(px, py) {
|
|
285
|
+
const hit = pickMapHit(state.hits, px, py, state.dpr);
|
|
286
|
+
if (hit) {
|
|
287
|
+
showPick(hit.sel);
|
|
288
|
+
return;
|
|
289
|
+
}
|
|
290
|
+
const sx = mv.x0 + px / mv.k;
|
|
291
|
+
const sz = mv.z0 + py / mv.k;
|
|
292
|
+
if (state.mode === 'atlas') {
|
|
293
|
+
const [lx, lz] = land.fromAtlas(sx, sz);
|
|
294
|
+
showPick(formatSpotCard({ land, x: lx, z: lz, at: { x: sx, z: sz, world: true }, namedPlaces: landPlaces }));
|
|
295
|
+
} else {
|
|
296
|
+
showPick(formatSpotCard({ land, x: sx, z: sz, at: { x: sx, z: sz, world: false }, namedPlaces: landPlaces }));
|
|
297
|
+
}
|
|
298
|
+
},
|
|
299
|
+
});
|
|
300
|
+
|
|
301
|
+
for (const btn of document.querySelectorAll('[data-view]')) {
|
|
302
|
+
btn.addEventListener('click', () => {
|
|
303
|
+
state.mode = btn.dataset.view;
|
|
304
|
+
for (const other of document.querySelectorAll('[data-view]')) {
|
|
305
|
+
other.setAttribute('aria-pressed', String(other === btn));
|
|
306
|
+
}
|
|
307
|
+
if (state.mode === 'atlas') {
|
|
308
|
+
showPick({ x: 640, z: 610, world: true, name: 'Highhaven', kind: 'Harbour city', desc: 'Walled trading port at the river mouth.' });
|
|
309
|
+
} else {
|
|
310
|
+
showPick({ x: -120, z: 60, world: false, name: 'Alderford', kind: 'City', desc: 'Market town on the sheltered cove.' });
|
|
311
|
+
}
|
|
312
|
+
});
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
function paintAtlas() {
|
|
316
|
+
[state.wx, state.wy] = frameMapSheet(mv, {
|
|
317
|
+
cx: state.wx,
|
|
318
|
+
cz: state.wy,
|
|
319
|
+
zoom: state.wz,
|
|
320
|
+
originX: 0,
|
|
321
|
+
originZ: 0,
|
|
322
|
+
sheetWidth: SHEET_W,
|
|
323
|
+
sheetHeight: SHEET_H,
|
|
324
|
+
canvasWidth: state.w,
|
|
325
|
+
canvasHeight: state.h,
|
|
326
|
+
dpr: state.dpr,
|
|
327
|
+
whole: false,
|
|
328
|
+
});
|
|
329
|
+
state.k = mv.k;
|
|
330
|
+
const X = x => (x - mv.x0) * mv.k;
|
|
331
|
+
const Y = y => (y - mv.z0) * mv.k;
|
|
332
|
+
const u = mv.u;
|
|
333
|
+
state.hits.length = 0;
|
|
334
|
+
|
|
335
|
+
ctx.setTransform(1, 0, 0, 1, 0, 0);
|
|
336
|
+
ctx.drawImage(atlasRelief.getCanvas(mv), 0, 0);
|
|
337
|
+
|
|
338
|
+
// Framed explorable region overlay.
|
|
339
|
+
ctx.fillStyle = 'rgba(98,230,203,.12)';
|
|
340
|
+
ctx.fillRect(X(frameBox.x), Y(frameBox.y), frameBox.side * mv.k, frameBox.side * mv.k);
|
|
341
|
+
ctx.strokeStyle = '#62e6cb';
|
|
342
|
+
ctx.lineWidth = 1.8 * u;
|
|
343
|
+
ctx.beginPath();
|
|
344
|
+
for (let i = 0; i < frameOutline.length; i += 4) {
|
|
345
|
+
ctx.moveTo(X(frameOutline[i]), Y(frameOutline[i + 1]));
|
|
346
|
+
ctx.lineTo(X(frameOutline[i + 2]), Y(frameOutline[i + 3]));
|
|
347
|
+
}
|
|
348
|
+
ctx.stroke();
|
|
349
|
+
|
|
350
|
+
const labels = createMapLabelSet(ctx, state.w, state.h, u);
|
|
351
|
+
labels.on(spacedCaps('Westreach'), X(410), Y(485), 16 * u, { italic: true, must: true });
|
|
352
|
+
labels.on(spacedCaps('East Isles'), X(1160), Y(690), 15 * u, { italic: true, must: true });
|
|
353
|
+
labels.on('Alder Reach', X(frameBox.x + frameBox.side / 2), Y(frameBox.y) - 10 * u, 12 * u, { color: '#8ff0dc', must: true });
|
|
354
|
+
|
|
355
|
+
for (const p of atlasPlaces) {
|
|
356
|
+
const px = X(p.x);
|
|
357
|
+
const py = Y(p.y);
|
|
358
|
+
drawMapGlyph(ctx, p.k, px, py, u * (p.k === 'cities' ? 1.15 : 0.95));
|
|
359
|
+
labels.keep(px, py, 8 * u);
|
|
360
|
+
if (!(state.sel?.world && state.sel.name === p.n)) {
|
|
361
|
+
labels.beside(p.n, px, py, (p.k === 'cities' ? 13 : 11) * u, { must: p.k === 'cities', gap: 13 });
|
|
362
|
+
}
|
|
363
|
+
state.hits.push({ x: px, y: py, r: 14 * u, sel: { x: p.x, z: p.y, world: true, name: p.n, kind: p.kind, desc: p.desc } });
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
const [vx, vy] = land.toAtlas(visitor.x, visitor.z);
|
|
367
|
+
paintMapVisitor(ctx, X(vx), Y(vy), u, camProxy.yaw);
|
|
368
|
+
labels.keep(X(vx), Y(vy), 14 * u);
|
|
369
|
+
labels.flush();
|
|
370
|
+
drawMapCompass(ctx, state.w - 30 * u, state.h - 80 * u, u);
|
|
371
|
+
drawMapLabel(ctx, 'not to scale', state.w - 50 * u, state.h - 76 * u, 10.5 * u, {
|
|
372
|
+
italic: true,
|
|
373
|
+
color: 'rgba(243,236,217,.65)',
|
|
374
|
+
align: 'right',
|
|
375
|
+
});
|
|
376
|
+
if (state.sel?.world) paintMapPick(ctx, X(state.sel.x), Y(state.sel.z), u, state.sel.name);
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
function paintLandSheet() {
|
|
380
|
+
[state.cx, state.cz] = frameMapSheet(mv, {
|
|
381
|
+
cx: state.cx,
|
|
382
|
+
cz: state.cz,
|
|
383
|
+
zoom: state.zoom,
|
|
384
|
+
originX: land.x0,
|
|
385
|
+
originZ: land.z0,
|
|
386
|
+
sheetWidth: land.size,
|
|
387
|
+
sheetHeight: land.size,
|
|
388
|
+
canvasWidth: state.w,
|
|
389
|
+
canvasHeight: state.h,
|
|
390
|
+
dpr: state.dpr,
|
|
391
|
+
whole: false,
|
|
392
|
+
});
|
|
393
|
+
state.k = mv.k;
|
|
394
|
+
const X = x => (x - mv.x0) * mv.k;
|
|
395
|
+
const Z = z => (z - mv.z0) * mv.k;
|
|
396
|
+
const u = mv.u;
|
|
397
|
+
state.hits.length = 0;
|
|
398
|
+
|
|
399
|
+
ctx.setTransform(1, 0, 0, 1, 0, 0);
|
|
400
|
+
ctx.fillStyle = '#0b1114';
|
|
401
|
+
ctx.fillRect(0, 0, state.w, state.h);
|
|
402
|
+
ctx.imageSmoothingEnabled = true;
|
|
403
|
+
ctx.imageSmoothingQuality = 'high';
|
|
404
|
+
ctx.drawImage(state.mode === 'terrain' ? shadedSheet : parchmentSheet, X(land.x0), Z(land.z0), land.size * mv.k, land.size * mv.k);
|
|
405
|
+
|
|
406
|
+
// Rivers & roads
|
|
407
|
+
ctx.strokeStyle = '#5a9cc4';
|
|
408
|
+
ctx.lineWidth = Math.max(2 * u, 12 * mv.k);
|
|
409
|
+
ctx.lineCap = 'round';
|
|
410
|
+
for (const r of landRivers) {
|
|
411
|
+
ctx.beginPath();
|
|
412
|
+
r.forEach(([rx, rz], i) => (i ? ctx.lineTo(X(rx), Z(rz)) : ctx.moveTo(X(rx), Z(rz))));
|
|
413
|
+
ctx.stroke();
|
|
414
|
+
}
|
|
415
|
+
for (const r of landRoads) {
|
|
416
|
+
ctx.beginPath();
|
|
417
|
+
r.forEach(([rx, rz], i) => (i ? ctx.lineTo(X(rx), Z(rz)) : ctx.moveTo(X(rx), Z(rz))));
|
|
418
|
+
ctx.strokeStyle = 'rgba(30,22,14,.8)';
|
|
419
|
+
ctx.lineWidth = 3.2 * u;
|
|
420
|
+
ctx.setLineDash([]);
|
|
421
|
+
ctx.stroke();
|
|
422
|
+
ctx.strokeStyle = '#ecd9a8';
|
|
423
|
+
ctx.lineWidth = 1.5 * u;
|
|
424
|
+
ctx.setLineDash([5 * u, 3.5 * u]);
|
|
425
|
+
ctx.stroke();
|
|
426
|
+
}
|
|
427
|
+
ctx.setLineDash([]);
|
|
428
|
+
|
|
429
|
+
const labels = createMapLabelSet(ctx, state.w, state.h, u);
|
|
430
|
+
if (state.sel && !state.sel.world) {
|
|
431
|
+
labels.keep(X(state.sel.x), Z(state.sel.z) - 22 * u, 30 * u);
|
|
432
|
+
}
|
|
433
|
+
for (const loc of landPlaces) {
|
|
434
|
+
const px = X(loc.x);
|
|
435
|
+
const py = Z(loc.z);
|
|
436
|
+
if (loc.kind === 'region') {
|
|
437
|
+
labels.on(spacedCaps(loc.name), px, py, 13 * u, { italic: true, color: 'rgba(243,236,217,.85)' });
|
|
438
|
+
continue;
|
|
439
|
+
}
|
|
440
|
+
const glyph = loc.kind === 'city' ? 'cities' : loc.enter ? 'enter' : 'landmarks';
|
|
441
|
+
drawMapGlyph(ctx, glyph, px, py, u * 1.15);
|
|
442
|
+
labels.keep(px, py, 10 * u);
|
|
443
|
+
if (!(state.sel && !state.sel.world && state.sel.name === loc.name)) {
|
|
444
|
+
labels.beside(loc.name, px, py, (loc.kind === 'city' ? 15 : 12) * u, { must: true });
|
|
445
|
+
}
|
|
446
|
+
state.hits.push({ x: px, y: py, r: 15 * u, sel: { x: loc.x, z: loc.z, world: false, name: loc.name, kind: loc.kind, desc: loc.desc } });
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
for (const cluster of clusterMapPoints(landMarkers, X, Z, 20 * u)) {
|
|
450
|
+
const count = cluster.list.length;
|
|
451
|
+
drawMapGlyph(ctx, 'scenes', cluster.x, cluster.y, u * (count > 1 ? 1.6 : 1.2));
|
|
452
|
+
labels.keep(cluster.x, cluster.y, 12 * u);
|
|
453
|
+
labels.beside(count > 1 ? `${count} events` : cluster.list[0].title, cluster.x, cluster.y, 10 * u, { italic: true, color: '#ffd9a0' });
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
paintMapVisitor(ctx, X(visitor.x), Z(visitor.z), u, camProxy.yaw);
|
|
457
|
+
labels.flush();
|
|
458
|
+
drawMapScaleBar(ctx, { w: state.w, h: state.h - 118 * u, k: mv.k, u });
|
|
459
|
+
if (state.sel && !state.sel.world) paintMapPick(ctx, X(state.sel.x), Z(state.sel.z), u, state.sel.name);
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
let last = performance.now();
|
|
463
|
+
function tick(now) {
|
|
464
|
+
const dt = Math.min(0.1, (now - last) / 1000);
|
|
465
|
+
last = now;
|
|
466
|
+
camProxy.yaw = 0.45 + Math.sin(now * 0.00035) * 0.65;
|
|
467
|
+
compass.update(dt);
|
|
468
|
+
if (wb.update(visitor.x, visitor.z) || !whereLine.textContent) {
|
|
469
|
+
whereLine.textContent = wb.where.way ? `${wb.where.name} · ${wb.where.way}` : wb.where.name;
|
|
470
|
+
}
|
|
471
|
+
if (state.mode === 'atlas') paintAtlas();
|
|
472
|
+
else paintLandSheet();
|
|
473
|
+
requestAnimationFrame(tick);
|
|
474
|
+
}
|
|
475
|
+
requestAnimationFrame(tick);
|
package/geometry/farm-props.js
CHANGED
|
@@ -40,6 +40,29 @@ export const FARM_STONE_PILE = Object.freeze({
|
|
|
40
40
|
colorJitter: 0.24,
|
|
41
41
|
});
|
|
42
42
|
|
|
43
|
+
/**
|
|
44
|
+
* Default plank count, framing dimensions (in metres) and weathered timber sRGB colours for braced
|
|
45
|
+
* double barn doors built by {@link buildBarnDoors}.
|
|
46
|
+
*/
|
|
47
|
+
export const FARM_BARN_DOORS = Object.freeze({
|
|
48
|
+
planks: 14,
|
|
49
|
+
plankStep: 0.22,
|
|
50
|
+
plankWidth: 0.215,
|
|
51
|
+
plankHeight: 2.7,
|
|
52
|
+
plankThickness: 0.13,
|
|
53
|
+
plankColor: 0x68523b,
|
|
54
|
+
plankJitter: 0.23,
|
|
55
|
+
frameColor: 0x5b4936,
|
|
56
|
+
jambOffset: 1.6,
|
|
57
|
+
jambWidth: 0.23,
|
|
58
|
+
jambHeight: 3,
|
|
59
|
+
lintelWidth: 3.42,
|
|
60
|
+
lintelHeight: 0.21,
|
|
61
|
+
lintelDepth: 0.24,
|
|
62
|
+
braceThickness: 0.1,
|
|
63
|
+
zOutset: 0.19,
|
|
64
|
+
});
|
|
65
|
+
|
|
43
66
|
/**
|
|
44
67
|
* Build one or more tall farmyard haystacks (by default a pair side by side) with weathered, bulging straw bodies and loose
|
|
45
68
|
* projecting straw wisps into a geometry builder.
|
|
@@ -105,3 +128,39 @@ export function buildStonePile(builder, random = Math.random, options = {}) {
|
|
|
105
128
|
);
|
|
106
129
|
}
|
|
107
130
|
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Build a pair of vertical-planked, diagonally braced double barn doors framed by heavy jamb posts
|
|
134
|
+
* and a lintel into a wood geometry builder.
|
|
135
|
+
*
|
|
136
|
+
* @param {Pick<import('./builder.js').GB, 'box' | 'add'>} builder - Destination wood geometry builder.
|
|
137
|
+
* @param {() => number} [random=Math.random] - Repeatable random stream in `[0, 1)`.
|
|
138
|
+
* @param {object} [options]
|
|
139
|
+
* @param {number} [options.depth=5.9] - Barn depth in metres used to position the door face when `z` is omitted.
|
|
140
|
+
* @param {number} [options.z] - Explicit local Z position of the door plane in metres (overrides `depth * 0.5 + shape.zOutset`).
|
|
141
|
+
* @param {import('three').BufferGeometry} [options.box] - Unit box geometry for diagonal timber braces (defaults to `primitives.box`).
|
|
142
|
+
* @param {Partial<typeof FARM_BARN_DOORS>} [options.shape] - Overrides for {@link FARM_BARN_DOORS}.
|
|
143
|
+
*/
|
|
144
|
+
export function buildBarnDoors(builder, random = Math.random, options = {}) {
|
|
145
|
+
const cfg = options.shape ? { ...FARM_BARN_DOORS, ...options.shape } : FARM_BARN_DOORS;
|
|
146
|
+
const braceBox = options.box ?? box;
|
|
147
|
+
const doorZ = options.z ?? (options.depth ?? 5.9) * 0.5 + cfg.zOutset;
|
|
148
|
+
const timber = C(cfg.frameColor);
|
|
149
|
+
const half = (cfg.planks - 1) * 0.5;
|
|
150
|
+
for (let j = 0; j < cfg.planks; j++) {
|
|
151
|
+
builder.box(
|
|
152
|
+
(j - half) * cfg.plankStep,
|
|
153
|
+
0.02 + (j % 3) * 0.015,
|
|
154
|
+
doorZ,
|
|
155
|
+
cfg.plankWidth,
|
|
156
|
+
cfg.plankHeight,
|
|
157
|
+
cfg.plankThickness,
|
|
158
|
+
C(cfg.plankColor, cfg.plankJitter, random),
|
|
159
|
+
);
|
|
160
|
+
}
|
|
161
|
+
for (const sign of [-1, 1]) {
|
|
162
|
+
builder.box(sign * cfg.jambOffset, -0.12, doorZ, cfg.jambWidth, cfg.jambHeight, cfg.jambWidth, timber);
|
|
163
|
+
stick(builder, [sign * 0.16, 0.28, doorZ + 0.075], [sign * 1.43, 2.38, doorZ + 0.075], cfg.braceThickness, timber, braceBox);
|
|
164
|
+
}
|
|
165
|
+
builder.box(0, cfg.plankHeight, doorZ, cfg.lintelWidth, cfg.lintelHeight, cfg.lintelDepth, timber);
|
|
166
|
+
}
|