roamwright 0.61.29 → 0.61.30
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/examples/fliers.js +33 -0
- package/examples/land-features.js +19 -0
- package/examples/troops.js +37 -0
- package/geometry/bridge-masonry.js +414 -0
- package/geometry/index.js +7 -0
- package/motion/crawler-pack.js +138 -2
- package/motion/index.js +1 -1
- package/package.json +1 -1
- package/rendering/crawler-pack.js +44 -1
- package/rendering/index.js +2 -1
- package/rendering/road-traffic.js +268 -0
package/examples/fliers.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import * as THREE from 'three';
|
|
2
2
|
import {
|
|
3
|
+
buildAshlarWall,
|
|
3
4
|
createDaylightSky,
|
|
4
5
|
createGiantSpiderPack,
|
|
5
6
|
createOrbitCamera,
|
|
6
7
|
createStreetLamps,
|
|
8
|
+
createWallCrawlers,
|
|
7
9
|
scatterTrees,
|
|
8
10
|
scatterTussocks,
|
|
9
11
|
snakeGeometry,
|
|
@@ -265,6 +267,36 @@ snakes.castShadow = true;
|
|
|
265
267
|
snakes.computeBoundingSphere();
|
|
266
268
|
worldGroup.add(snakes);
|
|
267
269
|
|
|
270
|
+
// Weathered coursed-stone ashlar wall behind the crawler clearing with wall-dashing spiders running across its sunlit face.
|
|
271
|
+
const ruinWall = new GB();
|
|
272
|
+
const wallBaseY = groundAt(11, -9.6);
|
|
273
|
+
buildAshlarWall(ruinWall, random, {
|
|
274
|
+
x0: 8.0,
|
|
275
|
+
z0: -9.6,
|
|
276
|
+
x1: 14.0,
|
|
277
|
+
z1: -9.6,
|
|
278
|
+
y: wallBaseY - 0.15,
|
|
279
|
+
height: 2.35,
|
|
280
|
+
thickness: 0.52,
|
|
281
|
+
ragged: 0.12,
|
|
282
|
+
});
|
|
283
|
+
const ruinWallMesh = ruinWall.mesh(new THREE.MeshStandardMaterial({ vertexColors: true, roughness: 0.92 }), worldGroup);
|
|
284
|
+
ruinWallMesh.castShadow = ruinWallMesh.receiveShadow = true;
|
|
285
|
+
const wallSpiders = createWallCrawlers({
|
|
286
|
+
count: 8,
|
|
287
|
+
origin: { x: 0, z: -9.6 },
|
|
288
|
+
x0: 8.2,
|
|
289
|
+
x1: 13.8,
|
|
290
|
+
y0: wallBaseY,
|
|
291
|
+
height: 1.9,
|
|
292
|
+
halfWidth: 0.28,
|
|
293
|
+
sides: [1],
|
|
294
|
+
size: 0.85,
|
|
295
|
+
shapes,
|
|
296
|
+
random,
|
|
297
|
+
});
|
|
298
|
+
worldGroup.add(wallSpiders.mesh);
|
|
299
|
+
|
|
268
300
|
createDaylightSky({
|
|
269
301
|
scene,
|
|
270
302
|
renderer,
|
|
@@ -334,6 +366,7 @@ function stepFliers(dt, t) {
|
|
|
334
366
|
const cz = -7.5 + Math.sin(t * 0.25) * 2.2;
|
|
335
367
|
crawlerPack.position.set(cx, groundAt(cx, cz), cz);
|
|
336
368
|
crawlerPack.userData.tick(dt);
|
|
369
|
+
wallSpiders.crawl(t);
|
|
337
370
|
}
|
|
338
371
|
// Advance once so every flock, swarm and glider is in mid-flight on frame 1.
|
|
339
372
|
stepFliers(1 / 60, 1.5);
|
|
@@ -4,6 +4,7 @@ import {
|
|
|
4
4
|
GeometryBuilder,
|
|
5
5
|
buildBarnDoors,
|
|
6
6
|
buildHaystacks,
|
|
7
|
+
buildSegmentalBridge,
|
|
7
8
|
buildStonePile,
|
|
8
9
|
createCragLibrary,
|
|
9
10
|
createFigureAssembler,
|
|
@@ -19,6 +20,7 @@ import {
|
|
|
19
20
|
meshStreamBanks,
|
|
20
21
|
mulberry32,
|
|
21
22
|
planDrystoneWall,
|
|
23
|
+
planRoadBridges,
|
|
22
24
|
planSprings,
|
|
23
25
|
planStreamBanks,
|
|
24
26
|
tuftGeometry,
|
|
@@ -26,6 +28,7 @@ import {
|
|
|
26
28
|
import { instanceArrays, instancedMesh, putInstance } from 'roamwright/geometry/instances.js';
|
|
27
29
|
import { C, TRS } from 'roamwright/geometry/primitives.js';
|
|
28
30
|
import { SRGB2LIN } from 'roamwright/math/color.js';
|
|
31
|
+
import { spacedCurve } from 'roamwright/math/curve.js';
|
|
29
32
|
import { lerp, TAU } from 'roamwright/math/scalar.js';
|
|
30
33
|
|
|
31
34
|
// Roads, river springhead, stoned banks, crag boulders, drystone farmstead with barn doors, haystacks, stone pile,
|
|
@@ -72,6 +75,22 @@ export function buildLandFeatures({ worldGroup, camera, land, waters, groundExac
|
|
|
72
75
|
crag: fineness => crags.crag(fineness),
|
|
73
76
|
});
|
|
74
77
|
|
|
78
|
+
// Segmental stone arch bridge where the valley road crosses the river near the ford.
|
|
79
|
+
const plannedBridges = planRoadBridges({
|
|
80
|
+
roads: land.roads.map(r => ({ fine: spacedCurve(r.pts, 1.5), w: r.w })),
|
|
81
|
+
rivers: [{ kind: 'stream', name: 'river', fine: spacedCurve(riverPts, 1.5), w: river.width }],
|
|
82
|
+
ground: groundExact,
|
|
83
|
+
streamThreshold: 6,
|
|
84
|
+
});
|
|
85
|
+
if (plannedBridges.bridges.length) {
|
|
86
|
+
const bridgeBuilder = new GeometryBuilder();
|
|
87
|
+
const bridgeRng = mulberry32(seed * 83);
|
|
88
|
+
for (const crossing of plannedBridges.bridges) {
|
|
89
|
+
buildSegmentalBridge(bridgeBuilder, crossing, { ground: groundExact, random: bridgeRng, rise: 2.8, archMargin: 2 });
|
|
90
|
+
}
|
|
91
|
+
bridgeBuilder.mesh(new THREE.MeshStandardMaterial({ vertexColors: true, roughness: 0.92 }), worldGroup);
|
|
92
|
+
}
|
|
93
|
+
|
|
75
94
|
const wallRng = mulberry32(seed * 53);
|
|
76
95
|
const wallCorners = [
|
|
77
96
|
[168, 62],
|
package/examples/troops.js
CHANGED
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
createHouseKitMaterials,
|
|
7
7
|
createHouseKitMeshes,
|
|
8
8
|
createOrbitCamera,
|
|
9
|
+
createRoadTrafficRenderer,
|
|
9
10
|
createSpaces,
|
|
10
11
|
createTroopDirector,
|
|
11
12
|
createTroopMounts,
|
|
@@ -164,6 +165,41 @@ const director = createTroopDirector({
|
|
|
164
165
|
});
|
|
165
166
|
|
|
166
167
|
const plainSpace = { id: 'plain', group: worldGroup, ground: groundHeight };
|
|
168
|
+
const convoySystem = createRoadTrafficRenderer({
|
|
169
|
+
entries: [['supply_road', 'merchant']],
|
|
170
|
+
specs: {
|
|
171
|
+
merchant: {
|
|
172
|
+
pace: 0.95,
|
|
173
|
+
members: [
|
|
174
|
+
['rider', 6.5, 0.8],
|
|
175
|
+
['cart', 0, 1.0],
|
|
176
|
+
['walker', 3.1, 2.1],
|
|
177
|
+
],
|
|
178
|
+
},
|
|
179
|
+
},
|
|
180
|
+
roads: [
|
|
181
|
+
{
|
|
182
|
+
id: 'supply_road',
|
|
183
|
+
pts: [
|
|
184
|
+
[-120, -28],
|
|
185
|
+
[120, -28],
|
|
186
|
+
],
|
|
187
|
+
},
|
|
188
|
+
],
|
|
189
|
+
ground: groundHeight,
|
|
190
|
+
group: worldGroup,
|
|
191
|
+
spaceId: 'plain',
|
|
192
|
+
camera,
|
|
193
|
+
random: rng,
|
|
194
|
+
tones: [0x8a6a48, 0x6a5a44, 0x7a6a4a],
|
|
195
|
+
addCrowd: (list, tones, cx, cz, near, kind, _beasts, spaceId) => crowdSystem.addCrowd(list, tones, cx, cz, near, kind, null, spaceId),
|
|
196
|
+
loadAssets: () => ({
|
|
197
|
+
makeMounts: troopMounts.makeMounts,
|
|
198
|
+
makeHerd: troopMounts.makeHerd,
|
|
199
|
+
orderBeasts: troopMounts.orderBeasts,
|
|
200
|
+
makeVehicles,
|
|
201
|
+
}),
|
|
202
|
+
});
|
|
167
203
|
const tickHost = director.raiseHost(
|
|
168
204
|
plainSpace,
|
|
169
205
|
'field',
|
|
@@ -302,6 +338,7 @@ function draw() {
|
|
|
302
338
|
frame++;
|
|
303
339
|
rig.clampCamera();
|
|
304
340
|
tickHost(dt);
|
|
341
|
+
convoySystem?.tick(dt);
|
|
305
342
|
updater.updateCrowds();
|
|
306
343
|
renderer.render(scene, camera);
|
|
307
344
|
requestAnimationFrame(draw);
|
|
@@ -0,0 +1,414 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Arched stone bridge masonry builders paired with `planRoadBridges`: a full semicircular-arch bridge with dressed
|
|
3
|
+
* voussoirs, string course, coped parapets, parapet piers and splayed wing walls ({@link buildArchBridge}), and a lower
|
|
4
|
+
* segmental-arch stream bridge with splayed wings, end posts and optional parapet colliders ({@link buildSegmentalBridge}).
|
|
5
|
+
* Ground-height tags (`builder.tg` / `builder.tv`) are populated at footings so moss-aware stone shaders darken damp bases.
|
|
6
|
+
* @module
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { dim } from '../math/color.js';
|
|
10
|
+
import { mulberry32 } from '../math/random.js';
|
|
11
|
+
import { GB } from './builder.js';
|
|
12
|
+
import { C as defaultColor, TRS as defaultTransform, box as defaultBox } from './primitives.js';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Default proportions (metres) and weathered stone colour for a semicircular-arch masonry bridge ({@link buildArchBridge}).
|
|
16
|
+
*/
|
|
17
|
+
export const ARCH_BRIDGE_DEFAULTS = Object.freeze({
|
|
18
|
+
/** Roadway half-width inside the parapets in metres. */
|
|
19
|
+
halfWidth: 3.4,
|
|
20
|
+
/** Roadway deck slab thickness below `frame.y` in metres. */
|
|
21
|
+
deckThickness: 0.9,
|
|
22
|
+
/** Extra roadway slab overhang beyond each parapet face in metres. */
|
|
23
|
+
deckOverhang: 0.3,
|
|
24
|
+
/** Semicircular arch radius in metres. */
|
|
25
|
+
archRadius: 11.6,
|
|
26
|
+
/** Spandrel masonry depth between the arch crown and the roadway soffit in metres. */
|
|
27
|
+
crownClearance: 0.75,
|
|
28
|
+
/** Step along the span for masonry pier columns in metres. */
|
|
29
|
+
columnStep: 0.65,
|
|
30
|
+
/** Width of each masonry column slice along the span in metres. */
|
|
31
|
+
columnWidth: 0.66,
|
|
32
|
+
/** Trim inset from the negative span end before the first masonry column in metres. */
|
|
33
|
+
startInset: 0.3,
|
|
34
|
+
/** Bank footing depth below local ground or soffit in metres. */
|
|
35
|
+
footDepth: 1.2,
|
|
36
|
+
/** Number of wedge voussoirs around the semicircular arch ring. */
|
|
37
|
+
voussoirs: 23,
|
|
38
|
+
/** Ground clearance below which arch-ring voussoirs buried in the bank are skipped, in metres. */
|
|
39
|
+
voussoirBankMargin: 0.4,
|
|
40
|
+
/** Parapet wall height above the roadway in metres. */
|
|
41
|
+
parapetHeight: 0.95,
|
|
42
|
+
/** Parapet wall thickness in metres. */
|
|
43
|
+
parapetThickness: 0.46,
|
|
44
|
+
/** Parapet coping stone height in metres. */
|
|
45
|
+
copingHeight: 0.16,
|
|
46
|
+
/** Parapet coping stone width in metres. */
|
|
47
|
+
copingWidth: 0.62,
|
|
48
|
+
/** Wing-wall outward reach beyond the abutment end along the span in metres. */
|
|
49
|
+
wingReach: 2.4,
|
|
50
|
+
/** Wing-wall lateral offset outside the parapet in metres. */
|
|
51
|
+
wingOffset: 1.5,
|
|
52
|
+
/** Wing-wall length in metres. */
|
|
53
|
+
wingLength: 5.6,
|
|
54
|
+
/** Wing-wall thickness in metres. */
|
|
55
|
+
wingThickness: 0.6,
|
|
56
|
+
/** Wing-wall splay angle in radians. */
|
|
57
|
+
wingSplay: 0.5,
|
|
58
|
+
/** Base dressed-stone sRGB hex colour. */
|
|
59
|
+
stoneColor: 0x8f8776,
|
|
60
|
+
/** Per-stone brightness jitter passed to the colour helper. */
|
|
61
|
+
stoneJitter: 0.1,
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Default proportions (metres) and rubble-stone colour for a segmental-arch stream bridge ({@link buildSegmentalBridge}).
|
|
66
|
+
*/
|
|
67
|
+
export const SEGMENTAL_BRIDGE_DEFAULTS = Object.freeze({
|
|
68
|
+
/** Extra arch clear span beyond `frame.river` width in metres. */
|
|
69
|
+
archMargin: 3,
|
|
70
|
+
/** Vertical rise of the segmental arch from springing to crown in metres. */
|
|
71
|
+
rise: 2.3,
|
|
72
|
+
/** Roadway deck slab thickness below `frame.y` in metres. */
|
|
73
|
+
deckThickness: 0.75,
|
|
74
|
+
/** Extra roadway slab overhang beyond each parapet face in metres. */
|
|
75
|
+
deckOverhang: 0.25,
|
|
76
|
+
/** Spandrel masonry depth between the arch crown and the roadway soffit in metres. */
|
|
77
|
+
crownClearance: 0.45,
|
|
78
|
+
/** Step along the span for masonry columns in metres. */
|
|
79
|
+
columnStep: 0.5,
|
|
80
|
+
/** Width of each masonry column slice along the span in metres. */
|
|
81
|
+
columnWidth: 0.51,
|
|
82
|
+
/** Bank footing depth below ground or springing in metres. */
|
|
83
|
+
footDepth: 1,
|
|
84
|
+
/** Number of intervals across the voussoir ring (`voussoirSegments + 1` stones). */
|
|
85
|
+
voussoirSegments: 12,
|
|
86
|
+
/** Parapet wall height above the roadway in metres. */
|
|
87
|
+
parapetHeight: 0.8,
|
|
88
|
+
/** Parapet wall thickness in metres. */
|
|
89
|
+
parapetThickness: 0.42,
|
|
90
|
+
/** Parapet coping stone height in metres. */
|
|
91
|
+
copingHeight: 0.14,
|
|
92
|
+
/** Parapet coping stone width in metres. */
|
|
93
|
+
copingWidth: 0.56,
|
|
94
|
+
/** Parapet collider half-thickness in metres. */
|
|
95
|
+
colliderHalfThickness: 0.22,
|
|
96
|
+
/** Wing-wall outward centre offset past the span end in metres. */
|
|
97
|
+
wingReach: 1.6,
|
|
98
|
+
/** Wing-wall lateral offset outside the parapet in metres. */
|
|
99
|
+
wingOffset: 0.9,
|
|
100
|
+
/** Wing-wall length in metres. */
|
|
101
|
+
wingLength: 3.6,
|
|
102
|
+
/** Wing-wall splay angle in radians. */
|
|
103
|
+
wingSplay: 0.45,
|
|
104
|
+
/** End post centre offset past the span end in metres. */
|
|
105
|
+
postReach: 3.3,
|
|
106
|
+
/** End post lateral offset outside the parapet in metres. */
|
|
107
|
+
postOffset: 1.7,
|
|
108
|
+
/** End post width and depth in metres. */
|
|
109
|
+
postSize: 0.7,
|
|
110
|
+
/** End post height in metres. */
|
|
111
|
+
postHeight: 1.9,
|
|
112
|
+
/** Base rubble-stone sRGB hex colour. */
|
|
113
|
+
stoneColor: 0x8a8170,
|
|
114
|
+
/** Per-stone brightness jitter passed to the colour helper. */
|
|
115
|
+
stoneJitter: 0.12,
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
function bridgeAxes(frame) {
|
|
119
|
+
const rot = frame.rot ?? 0,
|
|
120
|
+
dx = frame.dx ?? Math.cos(rot),
|
|
121
|
+
dz = frame.dz ?? -Math.sin(rot),
|
|
122
|
+
px = frame.px ?? -dz,
|
|
123
|
+
pz = frame.pz ?? dx;
|
|
124
|
+
return {
|
|
125
|
+
rot,
|
|
126
|
+
at: (u, v) => [frame.x + dx * u + px * v, frame.z + dz * u + pz * v],
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Builds a single great semicircular-arch stone bridge across a gorge or wide river: pier columns stepping around the
|
|
132
|
+
* arch opening, roadway slab, flanking voussoir rings, string courses, coped parapets, parapet pillars and splayed wing walls.
|
|
133
|
+
*
|
|
134
|
+
* @param {GB} [builder] Geometry builder to append stone parts into (defaults to a new `GB`).
|
|
135
|
+
* @param {{ x: number, z: number, y: number, len: number, rot?: number, dx?: number, dz?: number, px?: number, pz?: number }} frame Planned bridge frame from `planBridgeFrame` or `planRoadBridges`.
|
|
136
|
+
* @param {object} [options]
|
|
137
|
+
* @param {(x: number, z: number) => number} [options.ground] Terrain height sampler in metres (defaults to flat `0`).
|
|
138
|
+
* @param {() => number} [options.random] Repeatable PRNG stream for stone shade variation.
|
|
139
|
+
* @param {number} [options.halfWidth=ARCH_BRIDGE_DEFAULTS.halfWidth] Roadway half-width in metres.
|
|
140
|
+
* @param {number} [options.deckThickness=ARCH_BRIDGE_DEFAULTS.deckThickness] Deck slab thickness in metres.
|
|
141
|
+
* @param {number} [options.deckOverhang=ARCH_BRIDGE_DEFAULTS.deckOverhang] Extra deck overhang on each side in metres.
|
|
142
|
+
* @param {number} [options.archRadius=ARCH_BRIDGE_DEFAULTS.archRadius] Semicircular arch radius in metres.
|
|
143
|
+
* @param {number} [options.crownClearance=ARCH_BRIDGE_DEFAULTS.crownClearance] Spandrel thickness above the arch crown in metres.
|
|
144
|
+
* @param {number} [options.columnStep=ARCH_BRIDGE_DEFAULTS.columnStep] Column spacing along the span in metres.
|
|
145
|
+
* @param {number} [options.columnWidth=ARCH_BRIDGE_DEFAULTS.columnWidth] Column width along the span in metres.
|
|
146
|
+
* @param {number} [options.startInset=ARCH_BRIDGE_DEFAULTS.startInset] Inset before the first column at `-len / 2` in metres.
|
|
147
|
+
* @param {number} [options.footDepth=ARCH_BRIDGE_DEFAULTS.footDepth] Bank footing depth below ground or soffit in metres.
|
|
148
|
+
* @param {number} [options.voussoirs=ARCH_BRIDGE_DEFAULTS.voussoirs] Number of voussoirs around the arch ring.
|
|
149
|
+
* @param {number} [options.voussoirBankMargin=ARCH_BRIDGE_DEFAULTS.voussoirBankMargin] Ground margin below which buried voussoirs are skipped.
|
|
150
|
+
* @param {number} [options.parapetHeight=ARCH_BRIDGE_DEFAULTS.parapetHeight] Parapet height above roadway in metres.
|
|
151
|
+
* @param {number} [options.parapetThickness=ARCH_BRIDGE_DEFAULTS.parapetThickness] Parapet thickness in metres.
|
|
152
|
+
* @param {number} [options.copingHeight=ARCH_BRIDGE_DEFAULTS.copingHeight] Parapet coping height in metres.
|
|
153
|
+
* @param {number} [options.copingWidth=ARCH_BRIDGE_DEFAULTS.copingWidth] Parapet coping width in metres.
|
|
154
|
+
* @param {number[] | null} [options.pillars] Span offsets along `u` for parapet pillars (defaults to `[-len/2, -archRadius, 0, archRadius, len/2]`).
|
|
155
|
+
* @param {number} [options.wingReach=ARCH_BRIDGE_DEFAULTS.wingReach] Wing-wall centre reach past `len / 2` in metres.
|
|
156
|
+
* @param {number} [options.wingOffset=ARCH_BRIDGE_DEFAULTS.wingOffset] Wing-wall lateral offset outside the parapet in metres.
|
|
157
|
+
* @param {number} [options.wingLength=ARCH_BRIDGE_DEFAULTS.wingLength] Wing-wall length in metres.
|
|
158
|
+
* @param {number} [options.wingThickness=ARCH_BRIDGE_DEFAULTS.wingThickness] Wing-wall thickness in metres.
|
|
159
|
+
* @param {number} [options.wingSplay=ARCH_BRIDGE_DEFAULTS.wingSplay] Wing-wall splay angle in radians.
|
|
160
|
+
* @param {number} [options.stoneColor=ARCH_BRIDGE_DEFAULTS.stoneColor] Base dressed-stone sRGB hex colour.
|
|
161
|
+
* @param {number} [options.stoneJitter=ARCH_BRIDGE_DEFAULTS.stoneJitter] Colour jitter amplitude.
|
|
162
|
+
* @param {boolean} [options.tagGround=true] Populate `builder.tg` / `builder.tv` with ground heights for base-moss shaders.
|
|
163
|
+
* @param {((x: number, z: number, hx: number, hz: number, rot: number) => void) | null} [options.addCollider=null] Optional parapet box collider callback.
|
|
164
|
+
* @param {import('three').BufferGeometry} [options.boxShape] Unit box geometry for rotated voussoirs.
|
|
165
|
+
* @param {(hex: number, jitter?: number, rng?: () => number) => number[]} [options.color] Linear RGB colour helper.
|
|
166
|
+
* @param {Function} [options.transform] Transform matrix helper (`TRS`).
|
|
167
|
+
* @returns {GB} The builder that received the bridge masonry.
|
|
168
|
+
*/
|
|
169
|
+
export function buildArchBridge(builder = new GB(), frame, options = {}) {
|
|
170
|
+
const {
|
|
171
|
+
ground = () => 0,
|
|
172
|
+
random = mulberry32(17),
|
|
173
|
+
halfWidth = ARCH_BRIDGE_DEFAULTS.halfWidth,
|
|
174
|
+
deckThickness = ARCH_BRIDGE_DEFAULTS.deckThickness,
|
|
175
|
+
deckOverhang = ARCH_BRIDGE_DEFAULTS.deckOverhang,
|
|
176
|
+
archRadius = ARCH_BRIDGE_DEFAULTS.archRadius,
|
|
177
|
+
crownClearance = ARCH_BRIDGE_DEFAULTS.crownClearance,
|
|
178
|
+
columnStep = ARCH_BRIDGE_DEFAULTS.columnStep,
|
|
179
|
+
columnWidth = ARCH_BRIDGE_DEFAULTS.columnWidth,
|
|
180
|
+
startInset = ARCH_BRIDGE_DEFAULTS.startInset,
|
|
181
|
+
footDepth = ARCH_BRIDGE_DEFAULTS.footDepth,
|
|
182
|
+
voussoirs = ARCH_BRIDGE_DEFAULTS.voussoirs,
|
|
183
|
+
voussoirBankMargin = ARCH_BRIDGE_DEFAULTS.voussoirBankMargin,
|
|
184
|
+
parapetHeight = ARCH_BRIDGE_DEFAULTS.parapetHeight,
|
|
185
|
+
parapetThickness = ARCH_BRIDGE_DEFAULTS.parapetThickness,
|
|
186
|
+
copingHeight = ARCH_BRIDGE_DEFAULTS.copingHeight,
|
|
187
|
+
copingWidth = ARCH_BRIDGE_DEFAULTS.copingWidth,
|
|
188
|
+
pillars = null,
|
|
189
|
+
wingReach = ARCH_BRIDGE_DEFAULTS.wingReach,
|
|
190
|
+
wingOffset = ARCH_BRIDGE_DEFAULTS.wingOffset,
|
|
191
|
+
wingLength = ARCH_BRIDGE_DEFAULTS.wingLength,
|
|
192
|
+
wingThickness = ARCH_BRIDGE_DEFAULTS.wingThickness,
|
|
193
|
+
wingSplay = ARCH_BRIDGE_DEFAULTS.wingSplay,
|
|
194
|
+
stoneColor = ARCH_BRIDGE_DEFAULTS.stoneColor,
|
|
195
|
+
stoneJitter = ARCH_BRIDGE_DEFAULTS.stoneJitter,
|
|
196
|
+
tagGround = true,
|
|
197
|
+
addCollider = null,
|
|
198
|
+
boxShape = defaultBox,
|
|
199
|
+
color = defaultColor,
|
|
200
|
+
transform = defaultTransform,
|
|
201
|
+
} = options;
|
|
202
|
+
|
|
203
|
+
const shade = k => dim(color(stoneColor, stoneJitter, random), k),
|
|
204
|
+
halfLen = frame.len / 2,
|
|
205
|
+
top = frame.y,
|
|
206
|
+
soffit = top - deckThickness,
|
|
207
|
+
cy = soffit - crownClearance - archRadius,
|
|
208
|
+
halfStep = columnStep / 2,
|
|
209
|
+
{ rot, at } = bridgeAxes(frame),
|
|
210
|
+
pillarOffsets = pillars ?? [-halfLen, -archRadius, 0, archRadius, halfLen];
|
|
211
|
+
|
|
212
|
+
if (tagGround) builder.tg ??= [];
|
|
213
|
+
for (let u = -halfLen + startInset; u < halfLen; u += columnStep) {
|
|
214
|
+
// Solid masonry into the banks, stepping open along the semicircular arch intrados.
|
|
215
|
+
const center = u + halfStep,
|
|
216
|
+
[x, z] = at(center, 0),
|
|
217
|
+
inside = Math.abs(center) < archRadius,
|
|
218
|
+
y0 = inside ? cy + Math.sqrt(archRadius * archRadius - center ** 2) : Math.min(ground(x, z), soffit) - footDepth;
|
|
219
|
+
if (tagGround) builder.tv = ground(x, z);
|
|
220
|
+
builder.box(x, y0, z, columnWidth, soffit - y0, halfWidth * 2, shade(0.92 + random() * 0.14), rot);
|
|
221
|
+
}
|
|
222
|
+
{
|
|
223
|
+
const [x, z] = at(0, 0);
|
|
224
|
+
builder.box(x, soffit, z, frame.len, deckThickness, halfWidth * 2 + deckOverhang * 2, shade(0.78), rot);
|
|
225
|
+
}
|
|
226
|
+
for (const side of [-1, 1]) {
|
|
227
|
+
for (let k = 0; k < voussoirs; k++) {
|
|
228
|
+
const an = (Math.PI * (k + 0.5)) / voussoirs,
|
|
229
|
+
u = -Math.cos(an) * (archRadius + 0.32),
|
|
230
|
+
y = cy + Math.sin(an) * (archRadius + 0.32),
|
|
231
|
+
[x, z] = at(u, side * (halfWidth + 0.07));
|
|
232
|
+
if (y < ground(x, z) - voussoirBankMargin) continue;
|
|
233
|
+
builder.add(boxShape, shade(k % 2 ? 1.08 : 0.96), transform(x, y - 0.42, z, 1.5, 0.84, 0.36, rot, 0, Math.PI / 2 - an));
|
|
234
|
+
}
|
|
235
|
+
{
|
|
236
|
+
const [x, z] = at(0, side * (halfWidth + 0.1));
|
|
237
|
+
builder.box(x, soffit - 0.12, z, frame.len, 0.26, 0.3, shade(1.1), rot);
|
|
238
|
+
}
|
|
239
|
+
{
|
|
240
|
+
const [x, z] = at(0, side * (halfWidth + 0.05));
|
|
241
|
+
builder.box(x, top, z, frame.len, parapetHeight, parapetThickness, shade(0.96), rot);
|
|
242
|
+
builder.box(x, top + parapetHeight, z, frame.len + 0.3, copingHeight, copingWidth, shade(1.12), rot);
|
|
243
|
+
}
|
|
244
|
+
for (const u of pillarOffsets) {
|
|
245
|
+
const [x, z] = at(u, side * (halfWidth + 0.05));
|
|
246
|
+
builder.box(x, top, z, 0.9, 1.5, 0.74, shade(1.0), rot);
|
|
247
|
+
builder.box(x, top + 1.5, z, 1.06, 0.18, 0.9, shade(1.14), rot);
|
|
248
|
+
}
|
|
249
|
+
for (const end of [-1, 1]) {
|
|
250
|
+
const [x, z] = at(end * (halfLen + wingReach), side * (halfWidth + wingOffset));
|
|
251
|
+
if (tagGround) builder.tv = ground(x, z);
|
|
252
|
+
builder.box(
|
|
253
|
+
x,
|
|
254
|
+
ground(x, z) - 1.5,
|
|
255
|
+
z,
|
|
256
|
+
wingLength,
|
|
257
|
+
top + 0.7 - ground(x, z) + 1.5,
|
|
258
|
+
wingThickness,
|
|
259
|
+
shade(0.94),
|
|
260
|
+
rot + end * side * wingSplay,
|
|
261
|
+
);
|
|
262
|
+
}
|
|
263
|
+
if (addCollider) {
|
|
264
|
+
const [x, z] = at(0, side * (halfWidth + 0.05));
|
|
265
|
+
addCollider(x, z, halfLen, parapetThickness * 0.5, rot);
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
return builder;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
* Builds a country stream bridge: a single segmental arch of rubble stone with dressed voussoirs, coped low parapets,
|
|
273
|
+
* splayed wing walls with end posts meeting the banks, and optional parapet walk colliders.
|
|
274
|
+
*
|
|
275
|
+
* @param {GB} [builder] Geometry builder to append stone parts into (defaults to a new `GB`).
|
|
276
|
+
* @param {{ x: number, z: number, y: number, len: number, w?: number, river?: number, rot?: number, dx?: number, dz?: number, px?: number, pz?: number }} frame Planned stream bridge frame from `planRoadBridges`.
|
|
277
|
+
* @param {object} [options]
|
|
278
|
+
* @param {(x: number, z: number) => number} [options.ground] Terrain height sampler in metres (defaults to flat `0`).
|
|
279
|
+
* @param {() => number} [options.random] Repeatable PRNG stream for stone shade variation.
|
|
280
|
+
* @param {number} [options.archSpan] Explicit clear arch span in metres (defaults to `(frame.river ?? Math.max(4, frame.len - 10)) + archMargin`).
|
|
281
|
+
* @param {number} [options.archMargin=SEGMENTAL_BRIDGE_DEFAULTS.archMargin] Extra clear span beyond `frame.river` in metres.
|
|
282
|
+
* @param {number} [options.rise=SEGMENTAL_BRIDGE_DEFAULTS.rise] Segmental arch rise in metres.
|
|
283
|
+
* @param {number} [options.deckThickness=SEGMENTAL_BRIDGE_DEFAULTS.deckThickness] Deck slab thickness in metres.
|
|
284
|
+
* @param {number} [options.deckOverhang=SEGMENTAL_BRIDGE_DEFAULTS.deckOverhang] Extra deck overhang on each side in metres.
|
|
285
|
+
* @param {number} [options.crownClearance=SEGMENTAL_BRIDGE_DEFAULTS.crownClearance] Spandrel thickness above the arch crown in metres.
|
|
286
|
+
* @param {number} [options.columnStep=SEGMENTAL_BRIDGE_DEFAULTS.columnStep] Column spacing along the span in metres.
|
|
287
|
+
* @param {number} [options.columnWidth=SEGMENTAL_BRIDGE_DEFAULTS.columnWidth] Column width along the span in metres.
|
|
288
|
+
* @param {number} [options.footDepth=SEGMENTAL_BRIDGE_DEFAULTS.footDepth] Bank footing depth below ground or springing in metres.
|
|
289
|
+
* @param {number} [options.voussoirSegments=SEGMENTAL_BRIDGE_DEFAULTS.voussoirSegments] Intervals across the arch ring (`voussoirSegments + 1` voussoirs).
|
|
290
|
+
* @param {number} [options.parapetHeight=SEGMENTAL_BRIDGE_DEFAULTS.parapetHeight] Parapet height above roadway in metres.
|
|
291
|
+
* @param {number} [options.parapetThickness=SEGMENTAL_BRIDGE_DEFAULTS.parapetThickness] Parapet thickness in metres.
|
|
292
|
+
* @param {number} [options.copingHeight=SEGMENTAL_BRIDGE_DEFAULTS.copingHeight] Parapet coping height in metres.
|
|
293
|
+
* @param {number} [options.copingWidth=SEGMENTAL_BRIDGE_DEFAULTS.copingWidth] Parapet coping width in metres.
|
|
294
|
+
* @param {number} [options.colliderHalfThickness=SEGMENTAL_BRIDGE_DEFAULTS.colliderHalfThickness] Parapet collider half-thickness in metres.
|
|
295
|
+
* @param {number} [options.wingReach=SEGMENTAL_BRIDGE_DEFAULTS.wingReach] Wing-wall centre reach past `len / 2` in metres.
|
|
296
|
+
* @param {number} [options.wingOffset=SEGMENTAL_BRIDGE_DEFAULTS.wingOffset] Wing-wall lateral offset outside the parapet in metres.
|
|
297
|
+
* @param {number} [options.wingLength=SEGMENTAL_BRIDGE_DEFAULTS.wingLength] Wing-wall length in metres.
|
|
298
|
+
* @param {number} [options.wingSplay=SEGMENTAL_BRIDGE_DEFAULTS.wingSplay] Wing-wall splay angle in radians.
|
|
299
|
+
* @param {number} [options.postReach=SEGMENTAL_BRIDGE_DEFAULTS.postReach] End-post reach past `len / 2` in metres.
|
|
300
|
+
* @param {number} [options.postOffset=SEGMENTAL_BRIDGE_DEFAULTS.postOffset] End-post lateral offset outside the parapet in metres.
|
|
301
|
+
* @param {number} [options.postSize=SEGMENTAL_BRIDGE_DEFAULTS.postSize] End-post horizontal width in metres.
|
|
302
|
+
* @param {number} [options.postHeight=SEGMENTAL_BRIDGE_DEFAULTS.postHeight] End-post height in metres.
|
|
303
|
+
* @param {number} [options.stoneColor=SEGMENTAL_BRIDGE_DEFAULTS.stoneColor] Base rubble-stone sRGB hex colour.
|
|
304
|
+
* @param {number} [options.stoneJitter=SEGMENTAL_BRIDGE_DEFAULTS.stoneJitter] Colour jitter amplitude.
|
|
305
|
+
* @param {boolean} [options.tagGround=true] Populate `builder.tg` / `builder.tv` with ground heights for base-moss shaders.
|
|
306
|
+
* @param {((x: number, z: number, hx: number, hz: number, rot: number) => void) | null} [options.addCollider=null] Optional parapet box collider callback.
|
|
307
|
+
* @param {import('three').BufferGeometry} [options.boxShape] Unit box geometry for rotated voussoirs.
|
|
308
|
+
* @param {(hex: number, jitter?: number, rng?: () => number) => number[]} [options.color] Linear RGB colour helper.
|
|
309
|
+
* @param {Function} [options.transform] Transform matrix helper (`TRS`).
|
|
310
|
+
* @returns {GB} The builder that received the bridge masonry.
|
|
311
|
+
*/
|
|
312
|
+
export function buildSegmentalBridge(builder = new GB(), frame, options = {}) {
|
|
313
|
+
const {
|
|
314
|
+
ground = () => 0,
|
|
315
|
+
random = mulberry32(23),
|
|
316
|
+
archMargin = SEGMENTAL_BRIDGE_DEFAULTS.archMargin,
|
|
317
|
+
archSpan = (frame.river ?? Math.max(4, frame.len - 10)) + archMargin,
|
|
318
|
+
rise = SEGMENTAL_BRIDGE_DEFAULTS.rise,
|
|
319
|
+
deckThickness = SEGMENTAL_BRIDGE_DEFAULTS.deckThickness,
|
|
320
|
+
deckOverhang = SEGMENTAL_BRIDGE_DEFAULTS.deckOverhang,
|
|
321
|
+
crownClearance = SEGMENTAL_BRIDGE_DEFAULTS.crownClearance,
|
|
322
|
+
columnStep = SEGMENTAL_BRIDGE_DEFAULTS.columnStep,
|
|
323
|
+
columnWidth = SEGMENTAL_BRIDGE_DEFAULTS.columnWidth,
|
|
324
|
+
footDepth = SEGMENTAL_BRIDGE_DEFAULTS.footDepth,
|
|
325
|
+
voussoirSegments = SEGMENTAL_BRIDGE_DEFAULTS.voussoirSegments,
|
|
326
|
+
parapetHeight = SEGMENTAL_BRIDGE_DEFAULTS.parapetHeight,
|
|
327
|
+
parapetThickness = SEGMENTAL_BRIDGE_DEFAULTS.parapetThickness,
|
|
328
|
+
copingHeight = SEGMENTAL_BRIDGE_DEFAULTS.copingHeight,
|
|
329
|
+
copingWidth = SEGMENTAL_BRIDGE_DEFAULTS.copingWidth,
|
|
330
|
+
colliderHalfThickness = SEGMENTAL_BRIDGE_DEFAULTS.colliderHalfThickness,
|
|
331
|
+
wingReach = SEGMENTAL_BRIDGE_DEFAULTS.wingReach,
|
|
332
|
+
wingOffset = SEGMENTAL_BRIDGE_DEFAULTS.wingOffset,
|
|
333
|
+
wingLength = SEGMENTAL_BRIDGE_DEFAULTS.wingLength,
|
|
334
|
+
wingSplay = SEGMENTAL_BRIDGE_DEFAULTS.wingSplay,
|
|
335
|
+
postReach = SEGMENTAL_BRIDGE_DEFAULTS.postReach,
|
|
336
|
+
postOffset = SEGMENTAL_BRIDGE_DEFAULTS.postOffset,
|
|
337
|
+
postSize = SEGMENTAL_BRIDGE_DEFAULTS.postSize,
|
|
338
|
+
postHeight = SEGMENTAL_BRIDGE_DEFAULTS.postHeight,
|
|
339
|
+
stoneColor = SEGMENTAL_BRIDGE_DEFAULTS.stoneColor,
|
|
340
|
+
stoneJitter = SEGMENTAL_BRIDGE_DEFAULTS.stoneJitter,
|
|
341
|
+
tagGround = true,
|
|
342
|
+
addCollider = null,
|
|
343
|
+
boxShape = defaultBox,
|
|
344
|
+
color = defaultColor,
|
|
345
|
+
transform = defaultTransform,
|
|
346
|
+
} = options;
|
|
347
|
+
|
|
348
|
+
const shade = k => dim(color(stoneColor, stoneJitter, random), k),
|
|
349
|
+
radius = ((archSpan * archSpan) / 4 + rise * rise) / (2 * rise),
|
|
350
|
+
top = frame.y,
|
|
351
|
+
soffit = top - deckThickness,
|
|
352
|
+
crown = soffit - crownClearance,
|
|
353
|
+
cy = crown - radius,
|
|
354
|
+
halfWidth = frame.w ?? 3,
|
|
355
|
+
halfLen = frame.len / 2,
|
|
356
|
+
halfStep = columnStep / 2,
|
|
357
|
+
{ rot, at } = bridgeAxes(frame);
|
|
358
|
+
|
|
359
|
+
if (tagGround) builder.tg ??= [];
|
|
360
|
+
for (let u = -halfLen; u < halfLen; u += columnStep) {
|
|
361
|
+
const c = u + halfStep,
|
|
362
|
+
[x, z] = at(c, 0),
|
|
363
|
+
y0 = Math.abs(c) < archSpan / 2 ? cy + Math.sqrt(radius * radius - c * c) : Math.min(ground(x, z), crown - rise) - footDepth;
|
|
364
|
+
if (tagGround) builder.tv = ground(x, z);
|
|
365
|
+
builder.box(x, y0, z, columnWidth, soffit - y0, halfWidth * 2, shade(0.9 + random() * 0.16), rot);
|
|
366
|
+
}
|
|
367
|
+
{
|
|
368
|
+
const [x, z] = at(0, 0);
|
|
369
|
+
builder.box(x, soffit, z, frame.len, deckThickness, halfWidth * 2 + deckOverhang * 2, shade(0.8), rot);
|
|
370
|
+
}
|
|
371
|
+
const a0 = Math.asin(Math.min(1, archSpan / 2 / radius));
|
|
372
|
+
for (const side of [-1, 1]) {
|
|
373
|
+
for (let k = 0; k <= voussoirSegments; k++) {
|
|
374
|
+
const an = -a0 + (2 * a0 * k) / voussoirSegments,
|
|
375
|
+
u = Math.sin(an) * (radius + 0.25),
|
|
376
|
+
y = cy + Math.cos(an) * (radius + 0.25),
|
|
377
|
+
[x, z] = at(u, side * (halfWidth + 0.04));
|
|
378
|
+
builder.add(boxShape, shade(k % 2 ? 1.1 : 0.98), transform(x, y - 0.32, z, 0.9, 0.64, 0.3, rot, 0, -an));
|
|
379
|
+
}
|
|
380
|
+
{
|
|
381
|
+
const [x, z] = at(0, side * (halfWidth + 0.05));
|
|
382
|
+
builder.box(x, top, z, frame.len, parapetHeight, parapetThickness, shade(0.95), rot);
|
|
383
|
+
builder.box(x, top + parapetHeight, z, frame.len + 0.2, copingHeight, copingWidth, shade(1.12), rot);
|
|
384
|
+
}
|
|
385
|
+
for (const end of [-1, 1]) {
|
|
386
|
+
const [x, z] = at(end * (halfLen + wingReach), side * (halfWidth + wingOffset)),
|
|
387
|
+
y = ground(x, z);
|
|
388
|
+
if (tagGround) builder.tv = y;
|
|
389
|
+
builder.box(x, y - 1.2, z, wingLength, top + parapetHeight - y + 1.2, parapetThickness, shade(0.93), rot + end * side * wingSplay);
|
|
390
|
+
const [px, pz] = at(end * (halfLen + postReach), side * (halfWidth + postOffset));
|
|
391
|
+
builder.box(px, ground(px, pz) - 0.6, pz, postSize, postHeight, postSize, shade(1.02), rot);
|
|
392
|
+
}
|
|
393
|
+
if (addCollider) {
|
|
394
|
+
const [x, z] = at(0, side * (halfWidth + 0.05));
|
|
395
|
+
addCollider(x, z, halfLen, colliderHalfThickness, rot);
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
return builder;
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
/**
|
|
402
|
+
* Convenience dispatcher that builds either a great semicircular-arch stone bridge (`style: 'arch'`) or a country
|
|
403
|
+
* segmental-arch stream bridge (`style: 'segmental'`) into `builder`. Defaults to `'segmental'` when `frame.river` is
|
|
404
|
+
* present and `'arch'` otherwise.
|
|
405
|
+
*
|
|
406
|
+
* @param {GB} [builder] Geometry builder to append stone parts into.
|
|
407
|
+
* @param {object} frame Planned bridge frame from `planBridgeFrame` or `planRoadBridges`.
|
|
408
|
+
* @param {object} [options] Options forwarded to {@link buildArchBridge} or {@link buildSegmentalBridge}, plus optional `style: 'arch' | 'segmental'`.
|
|
409
|
+
* @returns {GB}
|
|
410
|
+
*/
|
|
411
|
+
export function buildStoneBridge(builder = new GB(), frame, options = {}) {
|
|
412
|
+
const style = options.style ?? (frame.river != null ? 'segmental' : 'arch');
|
|
413
|
+
return style === 'segmental' ? buildSegmentalBridge(builder, frame, options) : buildArchBridge(builder, frame, options);
|
|
414
|
+
}
|
package/geometry/index.js
CHANGED
|
@@ -95,6 +95,13 @@ export { SPRING_COLOURS, SPRING_HEAD, planSpringRocks, planSprings, springFrame,
|
|
|
95
95
|
export { planShoreReeds } from './shore-reeds.js';
|
|
96
96
|
export { roadRibbon } from './road-ribbon.js';
|
|
97
97
|
export { bridgeSpanPath, bridgeSpanPaths, planBridgeFrame, planRoadBridges } from './road-bridges.js';
|
|
98
|
+
export {
|
|
99
|
+
ARCH_BRIDGE_DEFAULTS,
|
|
100
|
+
SEGMENTAL_BRIDGE_DEFAULTS,
|
|
101
|
+
buildArchBridge,
|
|
102
|
+
buildSegmentalBridge,
|
|
103
|
+
buildStoneBridge,
|
|
104
|
+
} from './bridge-masonry.js';
|
|
98
105
|
export {
|
|
99
106
|
AVENUE_CEDAR,
|
|
100
107
|
PAVED_ROAD,
|
package/motion/crawler-pack.js
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Stepped pack-crawler motion solver: moves a group of ground crawlers together with a parent anchor, tracking heading
|
|
3
3
|
* and speed (ignoring teleport jumps), loosely wandering each member around its pack slot, turning smoothly into the
|
|
4
|
-
* heading, clamping each body to the terrain below it, and selecting its baked gait moment.
|
|
5
|
-
*
|
|
4
|
+
* heading, clamping each body to the terrain below it, and selecting its baked gait moment. Beside the pack,
|
|
5
|
+
* {@link createWallCrawlerMotion} drives crawlers that dash a little way along a vertical wall and wait. Worker-safe
|
|
6
|
+
* arithmetic only (no Three.js dependency) and zero per-frame allocations.
|
|
6
7
|
* @module
|
|
7
8
|
*/
|
|
8
9
|
|
|
9
10
|
import { wrapRadians } from '../math/periodic.js';
|
|
11
|
+
import { mulberry32 } from '../math/random.js';
|
|
10
12
|
|
|
11
13
|
/**
|
|
12
14
|
* Default crawler-pack motion parameters (metres, seconds, radians) and a seven-member formation `[side, ahead, scale]`.
|
|
@@ -108,3 +110,137 @@ export function createCrawlerPackMotion({
|
|
|
108
110
|
|
|
109
111
|
return { members, step };
|
|
110
112
|
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Default wall-dashing crawler parameters (metres, seconds) for {@link createWallCrawlerMotion}: each crawler dashes
|
|
116
|
+
* across its wall face for the first share of each leg, then pauses until the next leg begins.
|
|
117
|
+
*/
|
|
118
|
+
export const WALL_CRAWLER_DEFAULTS = Object.freeze({
|
|
119
|
+
/** Number of crawlers placed along the opposing walls. */
|
|
120
|
+
count: 16,
|
|
121
|
+
/** Uniform scale applied to the crawler geometry (e.g. a hand-sized spider). */
|
|
122
|
+
size: 0.55,
|
|
123
|
+
/** Horizontal inset kept clear of each passage end in metres. */
|
|
124
|
+
marginX: 0.8,
|
|
125
|
+
/** Vertical inset kept clear of floor and ceiling in metres. */
|
|
126
|
+
marginY: 0.6,
|
|
127
|
+
/** Small offset inward from the wall plane so legs sit on stone without z-fighting, in metres. */
|
|
128
|
+
wallOffset: 0.008,
|
|
129
|
+
/** Minimum horizontal dash amplitude in metres. */
|
|
130
|
+
reachMin: 0.5,
|
|
131
|
+
/** Random span added to horizontal dash amplitude in metres. */
|
|
132
|
+
reachSpan: 1.1,
|
|
133
|
+
/** Minimum leg cadence in legs per second. */
|
|
134
|
+
paceMin: 0.25,
|
|
135
|
+
/** Random span added to leg cadence in legs per second. */
|
|
136
|
+
paceSpan: 0.4,
|
|
137
|
+
/** Initial phase spread in legs. */
|
|
138
|
+
phaseSpan: 30,
|
|
139
|
+
/** Inverse share of each leg spent dashing (`2.2` dashes for ~45% of each leg, then waits). */
|
|
140
|
+
dashRate: 2.2,
|
|
141
|
+
/** Vertical dash amplitude in metres. */
|
|
142
|
+
verticalReach: 0.45,
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Creates a zero-allocation motion controller for crawlers dashing and pausing along vertical passage walls.
|
|
147
|
+
* Each crawler alternates dashes and waits along its wall plane (`z = origin.z ± (halfWidth - wallOffset)`),
|
|
148
|
+
* computing its world position and wall-aligned pitch/roll (`rx`, `rz`) with belly to the stone and head along travel.
|
|
149
|
+
*
|
|
150
|
+
* @param {object} [options]
|
|
151
|
+
* @param {number} [options.count=WALL_CRAWLER_DEFAULTS.count] Number of wall crawlers.
|
|
152
|
+
* @param {{ x: number, z: number }} [options.origin] Local-to-world horizontal origin in metres (defaults to `{ x: 0, z: 0 }`).
|
|
153
|
+
* @param {number} [options.x0=-10] Minimum local X extent along the wall in metres.
|
|
154
|
+
* @param {number} [options.x1=0] Maximum local X extent along the wall in metres.
|
|
155
|
+
* @param {number} [options.y0=0] Floor elevation at the base of the wall in metres.
|
|
156
|
+
* @param {number} [options.height=3.1] Wall height above `y0` in metres.
|
|
157
|
+
* @param {number} [options.halfWidth=1.3] Half-width between opposing walls in metres.
|
|
158
|
+
* @param {number[] | null} [options.sides=null] Optional wall-side signs (`+1` or `-1`) cycled per crawler; omit to alternate `-1, +1`.
|
|
159
|
+
* @param {() => number} [options.random] Repeatable PRNG stream (5 draws per crawler).
|
|
160
|
+
* @param {number} [options.marginX=WALL_CRAWLER_DEFAULTS.marginX] End-of-wall horizontal inset in metres.
|
|
161
|
+
* @param {number} [options.marginY=WALL_CRAWLER_DEFAULTS.marginY] Floor/ceiling vertical inset in metres.
|
|
162
|
+
* @param {number} [options.wallOffset=WALL_CRAWLER_DEFAULTS.wallOffset] Inward clearance from wall plane in metres.
|
|
163
|
+
* @param {number} [options.reachMin=WALL_CRAWLER_DEFAULTS.reachMin] Minimum horizontal dash reach in metres.
|
|
164
|
+
* @param {number} [options.reachSpan=WALL_CRAWLER_DEFAULTS.reachSpan] Random horizontal reach span in metres.
|
|
165
|
+
* @param {number} [options.paceMin=WALL_CRAWLER_DEFAULTS.paceMin] Minimum leg cadence in legs/s.
|
|
166
|
+
* @param {number} [options.paceSpan=WALL_CRAWLER_DEFAULTS.paceSpan] Random cadence span in legs/s.
|
|
167
|
+
* @param {number} [options.phaseSpan=WALL_CRAWLER_DEFAULTS.phaseSpan] Initial leg phase spread.
|
|
168
|
+
* @param {number} [options.dashRate=WALL_CRAWLER_DEFAULTS.dashRate] Speed factor for the active dash share of each leg.
|
|
169
|
+
* @param {number} [options.verticalReach=WALL_CRAWLER_DEFAULTS.verticalReach] Vertical dash amplitude in metres.
|
|
170
|
+
* @returns {{
|
|
171
|
+
* runs: Array<{ x: number, y: number, sg: number, reach: number, pace: number, phase: number, leg: number, startX: number, startY: number, dx: number, dy: number, roll: number, posX: number, posY: number, posZ: number, rx: number, rz: number }>,
|
|
172
|
+
* step: (t: number) => void,
|
|
173
|
+
* }}
|
|
174
|
+
*/
|
|
175
|
+
export function createWallCrawlerMotion({
|
|
176
|
+
count = WALL_CRAWLER_DEFAULTS.count,
|
|
177
|
+
origin = { x: 0, z: 0 },
|
|
178
|
+
x0 = -10,
|
|
179
|
+
x1 = 0,
|
|
180
|
+
y0 = 0,
|
|
181
|
+
height = 3.1,
|
|
182
|
+
halfWidth = 1.3,
|
|
183
|
+
sides = null,
|
|
184
|
+
random = mulberry32(31),
|
|
185
|
+
marginX = WALL_CRAWLER_DEFAULTS.marginX,
|
|
186
|
+
marginY = WALL_CRAWLER_DEFAULTS.marginY,
|
|
187
|
+
wallOffset = WALL_CRAWLER_DEFAULTS.wallOffset,
|
|
188
|
+
reachMin = WALL_CRAWLER_DEFAULTS.reachMin,
|
|
189
|
+
reachSpan = WALL_CRAWLER_DEFAULTS.reachSpan,
|
|
190
|
+
paceMin = WALL_CRAWLER_DEFAULTS.paceMin,
|
|
191
|
+
paceSpan = WALL_CRAWLER_DEFAULTS.paceSpan,
|
|
192
|
+
phaseSpan = WALL_CRAWLER_DEFAULTS.phaseSpan,
|
|
193
|
+
dashRate = WALL_CRAWLER_DEFAULTS.dashRate,
|
|
194
|
+
verticalReach = WALL_CRAWLER_DEFAULTS.verticalReach,
|
|
195
|
+
} = {}) {
|
|
196
|
+
const ox = origin.x,
|
|
197
|
+
oz = origin.z,
|
|
198
|
+
wallZ = halfWidth - wallOffset,
|
|
199
|
+
runs = Array.from({ length: count }, (_, i) => {
|
|
200
|
+
const sg = sides ? sides[i % sides.length] : i % 2 ? 1 : -1;
|
|
201
|
+
return {
|
|
202
|
+
x: x0 + marginX + random() * (x1 - x0 - marginX * 2),
|
|
203
|
+
y: y0 + marginY + random() * (height - marginY * 2),
|
|
204
|
+
sg,
|
|
205
|
+
reach: reachMin + random() * reachSpan,
|
|
206
|
+
pace: paceMin + random() * paceSpan,
|
|
207
|
+
phase: random() * phaseSpan,
|
|
208
|
+
leg: -1,
|
|
209
|
+
startX: 0,
|
|
210
|
+
startY: 0,
|
|
211
|
+
dx: 0,
|
|
212
|
+
dy: 0,
|
|
213
|
+
roll: 0,
|
|
214
|
+
posX: 0,
|
|
215
|
+
posY: 0,
|
|
216
|
+
posZ: oz + sg * wallZ,
|
|
217
|
+
rx: (sg * Math.PI) / 2,
|
|
218
|
+
rz: 0,
|
|
219
|
+
};
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
function step(t) {
|
|
223
|
+
for (let i = 0; i < runs.length; i++) {
|
|
224
|
+
const s = runs[i],
|
|
225
|
+
u = t * s.pace + s.phase,
|
|
226
|
+
leg = Math.floor(u),
|
|
227
|
+
f = Math.min(1, (u - leg) * dashRate), // runs for the first part of each leg, then waits
|
|
228
|
+
e = f * f * (3 - 2 * f);
|
|
229
|
+
// Endpoints and wall-plane bearing stay fixed until the next dash begins.
|
|
230
|
+
if (s.leg !== leg) {
|
|
231
|
+
s.leg = leg;
|
|
232
|
+
s.startX = Math.sin(leg * 2.4 + i) * s.reach;
|
|
233
|
+
s.startY = Math.cos(leg * 1.7 + i * 2) * verticalReach;
|
|
234
|
+
s.dx = Math.sin((leg + 1) * 2.4 + i) * s.reach - s.startX;
|
|
235
|
+
s.dy = Math.cos((leg + 1) * 1.7 + i * 2) * verticalReach - s.startY;
|
|
236
|
+
s.roll = s.sg * (Math.atan2(s.dy, s.dx) - Math.PI / 2);
|
|
237
|
+
}
|
|
238
|
+
s.posX = ox + s.x + s.startX + s.dx * e;
|
|
239
|
+
s.posY = s.y + s.startY + s.dy * e;
|
|
240
|
+
s.posZ = oz + s.sg * wallZ;
|
|
241
|
+
s.rz = s.roll;
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
return { runs, step };
|
|
246
|
+
}
|
package/motion/index.js
CHANGED
|
@@ -19,7 +19,7 @@ export { horsePose } from './animal-bearing.js';
|
|
|
19
19
|
export { caninePose } from './animal-canine-bearing.js';
|
|
20
20
|
export { catPose } from './animal-cat-bearing.js';
|
|
21
21
|
export { herdArrays } from './animal-herd-cast.js';
|
|
22
|
-
export { CRAWLER_PACK_DEFAULTS, createCrawlerPackMotion } from './crawler-pack.js';
|
|
22
|
+
export { CRAWLER_PACK_DEFAULTS, WALL_CRAWLER_DEFAULTS, createCrawlerPackMotion, createWallCrawlerMotion } from './crawler-pack.js';
|
|
23
23
|
export { createCrawlFlight } from './flier-swarm-flight.js';
|
|
24
24
|
export { CARPET_DEFAULTS, createCarpetFlight } from './flier-carpet-flight.js';
|
|
25
25
|
export { createLampSwarmFlight, pickNearestAnchors } from './flier-lamp-swarm.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "roamwright",
|
|
3
|
-
"version": "0.61.
|
|
3
|
+
"version": "0.61.30",
|
|
4
4
|
"description": "A procedural worldbuilding engine built on top of Three.js. Generate landscapes with rivers and changing weather, animate crowds, and explore on foot or in flight.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"threejs",
|
|
@@ -6,8 +6,10 @@
|
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
import * as THREE from 'three';
|
|
9
|
+
import { spiderGeometry } from '../geometry/crawl-shapes.js';
|
|
9
10
|
import { GIANT_SPIDER_GAIT, GIANT_SPIDER_LOOK, giantSpiderMoments } from '../geometry/crawler-giant-spider.js';
|
|
10
|
-
import {
|
|
11
|
+
import { TRS } from '../geometry/primitives.js';
|
|
12
|
+
import { CRAWLER_PACK_DEFAULTS, WALL_CRAWLER_DEFAULTS, createCrawlerPackMotion, createWallCrawlerMotion } from '../motion/crawler-pack.js';
|
|
11
13
|
|
|
12
14
|
/**
|
|
13
15
|
* Builds a `THREE.Group` containing a pack of ground crawlers driven by `createCrawlerPackMotion`, switching each member's
|
|
@@ -89,3 +91,44 @@ export function createGiantSpiderPack(options = {}) {
|
|
|
89
91
|
});
|
|
90
92
|
return createCrawlerPack({ ...options, moments });
|
|
91
93
|
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Builds an `InstancedMesh` of wall-dashing crawlers (defaulting to {@link spiderGeometry}) driven by
|
|
97
|
+
* {@link createWallCrawlerMotion}. Calling `crawl(t)` updates every instance matrix in place with zero per-frame allocations.
|
|
98
|
+
*
|
|
99
|
+
* @param {object} [options] Options forwarded to {@link createWallCrawlerMotion}, plus rendering parameters below.
|
|
100
|
+
* @param {THREE.BufferGeometry} [options.geometry] Shared crawler geometry (defaults to `spiderGeometry(shapes, look)`).
|
|
101
|
+
* @param {object} [options.shapes] Unit shapes passed to `spiderGeometry` when `geometry` is omitted.
|
|
102
|
+
* @param {object} [options.look] Linear colours passed to `spiderGeometry` when `geometry` is omitted.
|
|
103
|
+
* @param {THREE.Material} [options.material] Shared material (defaults to vertex-coloured `MeshStandardMaterial`).
|
|
104
|
+
* @param {number} [options.size=WALL_CRAWLER_DEFAULTS.size] Uniform crawler scale factor.
|
|
105
|
+
* @param {Function} [options.transform=TRS] Transform matrix helper (`TRS`).
|
|
106
|
+
* @returns {{ mesh: THREE.InstancedMesh, crawl: (t: number) => void, motion: ReturnType<typeof createWallCrawlerMotion> }}
|
|
107
|
+
*/
|
|
108
|
+
export function createWallCrawlers({
|
|
109
|
+
geometry = null,
|
|
110
|
+
shapes,
|
|
111
|
+
look,
|
|
112
|
+
material = new THREE.MeshStandardMaterial({ vertexColors: true, roughness: 0.7, flatShading: true }),
|
|
113
|
+
size = WALL_CRAWLER_DEFAULTS.size,
|
|
114
|
+
transform = TRS,
|
|
115
|
+
...motionOptions
|
|
116
|
+
} = {}) {
|
|
117
|
+
const motion = createWallCrawlerMotion(motionOptions),
|
|
118
|
+
{ runs } = motion,
|
|
119
|
+
geo = geometry ?? spiderGeometry(shapes, look),
|
|
120
|
+
mesh = new THREE.InstancedMesh(geo, material, runs.length);
|
|
121
|
+
mesh.frustumCulled = false;
|
|
122
|
+
|
|
123
|
+
const crawl = t => {
|
|
124
|
+
motion.step(t);
|
|
125
|
+
for (let i = 0; i < runs.length; i++) {
|
|
126
|
+
const s = runs[i];
|
|
127
|
+
// Lying on the wall: belly to the stone, head pointing along the dash.
|
|
128
|
+
mesh.setMatrixAt(i, transform(s.posX, s.posY, s.posZ, size, size, size, 0, s.rx, s.rz));
|
|
129
|
+
}
|
|
130
|
+
mesh.instanceMatrix.needsUpdate = true;
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
return { mesh, crawl, motion };
|
|
134
|
+
}
|
package/rendering/index.js
CHANGED
|
@@ -43,6 +43,7 @@ export { GROUND_DRAPE_FRAGMENT, createGroundDrape, createGroundDrapeMaterial } f
|
|
|
43
43
|
export { meshStreamBanks } from './stream-banks.js';
|
|
44
44
|
export { meshSprings } from './stream-springs.js';
|
|
45
45
|
export { layRoads } from './road-ribbons.js';
|
|
46
|
+
export { DEFAULT_TRAFFIC_OXEN, OXEN_DRAWING, createRoadTrafficRenderer } from './road-traffic.js';
|
|
46
47
|
export { createAvenueHandover, farRoadPavingMaterial, layPavedRoad, layRoadAvenue } from './paved-road.js';
|
|
47
48
|
export { PAVED_GROUND_LIMITS, createPavedGroundMaterial } from './paved-ground.js';
|
|
48
49
|
export { TUFT_SHADER, createGrassTuft, createTuftMaterial } from './plant-tuft.js';
|
|
@@ -89,7 +90,7 @@ export { buildCamel } from './animal-camel-figure.js';
|
|
|
89
90
|
export { buildCanine } from './animal-canine-figure.js';
|
|
90
91
|
export { createFlierShapes, createSwarm, FLY_WINGS } from './flier-swarm.js';
|
|
91
92
|
export { CARPET_LEVELS, canineStrideSteps, createCanineStrideCast, createCarpetSwarm } from './flier-carpet.js';
|
|
92
|
-
export { createCrawlerPack, createGiantSpiderPack } from './crawler-pack.js';
|
|
93
|
+
export { createCrawlerPack, createGiantSpiderPack, createWallCrawlers } from './crawler-pack.js';
|
|
93
94
|
export { updateNearGroups } from './detail-range.js';
|
|
94
95
|
export { createPenFlocks, packPenAnimals } from './pen-flocks.js';
|
|
95
96
|
export { createLongFlierCompany } from './flier-long-body-company.js';
|
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Road convoy rendering and lifecycle controller paired with `createRoadTraffic`: registers convoy travellers
|
|
3
|
+
* into a world's crowd system, lazily raises instanced horses, oxen, carts and wagons when the viewer approaches,
|
|
4
|
+
* warms vehicle shaders before first draw, and updates every convoy member per frame with zero allocations.
|
|
5
|
+
* @module
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import * as THREE from 'three';
|
|
9
|
+
import { mulberry32 } from '../math/random.js';
|
|
10
|
+
import { ROAD_TRAFFIC, createRoadTraffic } from '../motion/road-traffic.js';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Default ox coat colours (sRGB hex) assigned randomly to draught teams pulling carts and wagons.
|
|
14
|
+
*/
|
|
15
|
+
export const DEFAULT_TRAFFIC_OXEN = Object.freeze([0x8a6a4a, 0x6a5040, 0xb0a090, 0x5a4232, 0x9a8a70]);
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Number of draught oxen harnessed to each vehicle kind.
|
|
19
|
+
*/
|
|
20
|
+
export const OXEN_DRAWING = Object.freeze({ cart: 1, wagon: 2 });
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Builds a road-traffic convoy renderer and per-frame updater for one land or space.
|
|
24
|
+
*
|
|
25
|
+
* Each entry `[roadId, convoyKind]` places a convoy from `specs[convoyKind]` along `roads`, registers its walkers and
|
|
26
|
+
* riders with `addCrowd`, and lazily invokes `loadAssets()` once the camera comes within `raise` metres of any convoy.
|
|
27
|
+
* Vehicle groups are warmed through `warmShaders` on the first frame a cart or wagon is seen.
|
|
28
|
+
*
|
|
29
|
+
* @param {object} options
|
|
30
|
+
* @param {Array<[string, string]>} options.entries Pairs `[roadId, convoyKind]` to populate on the land's roads.
|
|
31
|
+
* @param {Record<string, { pace: number, body?: string, members: Array<[string, number, number]> }>} options.specs Convoy templates keyed by `convoyKind`.
|
|
32
|
+
* @param {Array<{ id: string, pts: Array<[number, number]> }>} options.roads Road polylines with ids matching `entries`.
|
|
33
|
+
* @param {(x: number, z: number) => number} options.ground Surface elevation sampler in metres.
|
|
34
|
+
* @param {THREE.Group} options.group Parent group receiving the lazily raised convoy mounts, herd and vehicles group.
|
|
35
|
+
* @param {THREE.Camera} options.camera Viewer camera whose position controls lazy raise and draw distance.
|
|
36
|
+
* @param {(people: object[], tones: number[], cx: number, cz: number, near: number, kind: string, beasts: unknown, spaceId: string) => object} options.addCrowd Crowd registration callback that converts traveller specs into live crowd figures in place.
|
|
37
|
+
* @param {() => Promise<{ makeHerd?: Function, makeMounts?: Function, orderBeasts?: Function, makeVehicles?: Function }> | { makeHerd?: Function, makeMounts?: Function, orderBeasts?: Function, makeVehicles?: Function }} [options.loadAssets=() => ({})] Lazy loader returning the beast and vehicle instancing builders; a vehicle or beast with no builder is not drawn.
|
|
38
|
+
* @param {string} [options.spaceId='world'] Space identifier forwarded to `addCrowd`.
|
|
39
|
+
* @param {() => number} [options.random] Repeatable PRNG stream for convoy spacing, traveller variation and coat picks.
|
|
40
|
+
* @param {number[]} [options.tones] Garment palette (sRGB hex) forwarded to `addCrowd`.
|
|
41
|
+
* @param {((crowd: object, bodyId: string) => void) | null} [options.nameBody=null] Optional nameplate binder for convoys whose spec sets `body`.
|
|
42
|
+
* @param {(rank: number) => boolean} [options.isTravelling] Daily schedule predicate receiving convoy `rank` in `[0, 1)`.
|
|
43
|
+
* @param {(x: number, y: number, z: number, radius: number, shadow: boolean, exact: boolean) => boolean} [options.inView] Frustum/visibility test for individual convoy members.
|
|
44
|
+
* @param {(group: THREE.Group) => Promise<void>} [options.warmShaders] Async shader warm-up hook called before vehicle meshes enter the scene.
|
|
45
|
+
* @param {Array<number | THREE.Color>} [options.oxCoats=DEFAULT_TRAFFIC_OXEN] Draught ox coat colours.
|
|
46
|
+
* @param {number} [options.drawn=ROAD_TRAFFIC.drawn] Distance in metres from `camera` within which beasts and vehicles draw.
|
|
47
|
+
* @param {number} [options.raise=ROAD_TRAFFIC.raise] Distance in metres from `camera` that triggers `loadAssets()`.
|
|
48
|
+
* @param {number} [options.minSpan=30] Minimum usable road length (after trimming both ends) in metres.
|
|
49
|
+
* @param {object} [options.trafficOptions] Optional parameters forwarded to `createRoadTraffic`.
|
|
50
|
+
* @returns {{ tick: (dt: number) => void, convoys: object[], dispose: () => void } | null}
|
|
51
|
+
*/
|
|
52
|
+
export function createRoadTrafficRenderer({
|
|
53
|
+
entries,
|
|
54
|
+
specs,
|
|
55
|
+
roads,
|
|
56
|
+
ground,
|
|
57
|
+
group,
|
|
58
|
+
camera,
|
|
59
|
+
addCrowd,
|
|
60
|
+
loadAssets = () => ({}),
|
|
61
|
+
spaceId = 'world',
|
|
62
|
+
random = mulberry32(61),
|
|
63
|
+
tones = [0x8a6a48, 0x6a5a44, 0x7a6a4a],
|
|
64
|
+
nameBody = null,
|
|
65
|
+
isTravelling = () => true,
|
|
66
|
+
inView = () => true,
|
|
67
|
+
warmShaders = () => Promise.resolve(),
|
|
68
|
+
oxCoats = DEFAULT_TRAFFIC_OXEN,
|
|
69
|
+
drawn: drawnRange = ROAD_TRAFFIC.drawn,
|
|
70
|
+
raise: raiseRange = ROAD_TRAFFIC.raise,
|
|
71
|
+
minSpan = 30,
|
|
72
|
+
trafficOptions = {},
|
|
73
|
+
}) {
|
|
74
|
+
if (!entries?.length) return null;
|
|
75
|
+
|
|
76
|
+
const { road: roadOf, setOut, traveller: travellerOf, placeOn, goOn } = createRoadTraffic(trafficOptions),
|
|
77
|
+
trim = trafficOptions.trim ?? ROAD_TRAFFIC.trim,
|
|
78
|
+
team = ROAD_TRAFFIC.team,
|
|
79
|
+
shafts = ROAD_TRAFFIC.shafts,
|
|
80
|
+
drawnSq = drawnRange * drawnRange,
|
|
81
|
+
raiseSq = raiseRange * raiseRange,
|
|
82
|
+
oxen = oxCoats.map(c => (c && c.isColor ? c : new THREE.Color(c))),
|
|
83
|
+
byId = new Map(),
|
|
84
|
+
onRoad = new Map(), // convoys per road so each sets out spaced along it
|
|
85
|
+
convoys = [],
|
|
86
|
+
folk = [], // travellers of every unnamed convoy share one crowd
|
|
87
|
+
named = [], // each convoy with a spec `body` gets its own crowd for its nameplate
|
|
88
|
+
counts = { cart: 0, wagon: 0, rider: 0, walker: 0, ox: 0 };
|
|
89
|
+
|
|
90
|
+
for (let i = 0; i < entries.length; i++) {
|
|
91
|
+
const id = entries[i][0];
|
|
92
|
+
onRoad.set(id, (onRoad.get(id) ?? 0) + 1);
|
|
93
|
+
}
|
|
94
|
+
const placed = new Map();
|
|
95
|
+
for (let i = 0; i < entries.length; i++) {
|
|
96
|
+
const [id, kind] = entries[i],
|
|
97
|
+
r = roads.find(q => q.id === id),
|
|
98
|
+
k = placed.get(id) ?? 0;
|
|
99
|
+
placed.set(id, k + 1);
|
|
100
|
+
if (!r) continue;
|
|
101
|
+
if (!byId.has(id)) byId.set(id, roadOf(r.pts, ground));
|
|
102
|
+
const road = byId.get(id),
|
|
103
|
+
spec = specs[kind],
|
|
104
|
+
span = road.way.length - 2 * trim;
|
|
105
|
+
if (!spec || span < minSpan) continue;
|
|
106
|
+
const c = setOut(road, spec.pace, { order: k, count: onRoad.get(id), random });
|
|
107
|
+
c.spec = spec;
|
|
108
|
+
c.members = [];
|
|
109
|
+
let front = -Infinity,
|
|
110
|
+
back = Infinity;
|
|
111
|
+
for (let j = 0; j < spec.members.length; j++) {
|
|
112
|
+
const ahead = spec.members[j][1];
|
|
113
|
+
if (ahead > front) front = ahead;
|
|
114
|
+
if (ahead < back) back = ahead;
|
|
115
|
+
}
|
|
116
|
+
c.front = front;
|
|
117
|
+
c.back = back;
|
|
118
|
+
const people = spec.body ? [] : folk;
|
|
119
|
+
if (spec.body) named.push({ people, body: spec.body });
|
|
120
|
+
for (let j = 0; j < spec.members.length; j++) {
|
|
121
|
+
const [what, ahead, side] = spec.members[j],
|
|
122
|
+
m = { what, ahead, side, figure: null, people, at: 0, coat: (random() * 97) | 0, tint: oxen[(random() * oxen.length) | 0] };
|
|
123
|
+
c.members.push(m);
|
|
124
|
+
if (what === 'walker' || what === 'rider') {
|
|
125
|
+
m.at = people.length;
|
|
126
|
+
people.push((m.figure = travellerOf(what, spec.pace, random)));
|
|
127
|
+
}
|
|
128
|
+
counts[what] = (counts[what] ?? 0) + 1;
|
|
129
|
+
counts.ox += OXEN_DRAWING[what] ?? 0;
|
|
130
|
+
}
|
|
131
|
+
convoys.push(c);
|
|
132
|
+
}
|
|
133
|
+
if (!convoys.length) return null;
|
|
134
|
+
|
|
135
|
+
if (folk.length) addCrowd(folk, tones, 0, 0, Infinity, 'plain', null, spaceId);
|
|
136
|
+
for (let i = 0; i < named.length; i++) {
|
|
137
|
+
const crowd = addCrowd(named[i].people, tones, 0, 0, Infinity, 'plain', null, spaceId);
|
|
138
|
+
if (nameBody) nameBody(crowd, named[i].body);
|
|
139
|
+
}
|
|
140
|
+
// Each crowd replaced its traveller entries with live crowd figures: keep direct references.
|
|
141
|
+
for (let i = 0; i < convoys.length; i++) {
|
|
142
|
+
const members = convoys[i].members;
|
|
143
|
+
for (let j = 0; j < members.length; j++) if (members[j].figure) members[j].figure = members[j].people[members[j].at];
|
|
144
|
+
}
|
|
145
|
+
const everyone = folk.concat(...named.map(n => n.people));
|
|
146
|
+
|
|
147
|
+
let drawn = null,
|
|
148
|
+
asked = false,
|
|
149
|
+
disposed = false;
|
|
150
|
+
|
|
151
|
+
const raise = async () => {
|
|
152
|
+
const { makeHerd, makeMounts, orderBeasts, makeVehicles } = await loadAssets();
|
|
153
|
+
if (disposed) return;
|
|
154
|
+
const beasts = orderBeasts ? orderBeasts() : null,
|
|
155
|
+
convoy = new THREE.Group(),
|
|
156
|
+
vehicles = new THREE.Group(),
|
|
157
|
+
carts = counts.cart && makeVehicles ? makeVehicles(vehicles, counts.cart, 'cart', random) : null,
|
|
158
|
+
wagons = counts.wagon && makeVehicles ? makeVehicles(vehicles, counts.wagon, 'wagon', random) : null;
|
|
159
|
+
await beasts;
|
|
160
|
+
if (disposed) return;
|
|
161
|
+
let preparing;
|
|
162
|
+
drawn = {
|
|
163
|
+
convoy,
|
|
164
|
+
mounts: counts.rider && makeMounts ? makeMounts(convoy, counts.rider, 0) : null,
|
|
165
|
+
herd: counts.ox && makeHerd ? makeHerd(convoy, counts.ox) : null,
|
|
166
|
+
carts,
|
|
167
|
+
wagons,
|
|
168
|
+
vehiclesReady: false,
|
|
169
|
+
prepareVehicles() {
|
|
170
|
+
// A passing rider can raise the convoy while every cart is outside the view.
|
|
171
|
+
preparing ??= warmShaders(vehicles).then(() => {
|
|
172
|
+
if (disposed) return;
|
|
173
|
+
convoy.add(vehicles);
|
|
174
|
+
drawn.vehiclesReady = true;
|
|
175
|
+
});
|
|
176
|
+
},
|
|
177
|
+
};
|
|
178
|
+
group.add(convoy);
|
|
179
|
+
// A rider is drawn from the frame there is a horse under them (`out: -1` lets the crowd show them at once).
|
|
180
|
+
for (let i = 0; i < everyone.length; i++) {
|
|
181
|
+
const f = everyone[i];
|
|
182
|
+
if (f.mounted) {
|
|
183
|
+
f.home = undefined;
|
|
184
|
+
f.out = -1;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
everyone.length = 0; // release the setup-only traveller list once riders are revealed
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
function drawVehicle(c, m, p) {
|
|
191
|
+
if (!drawn.vehiclesReady) {
|
|
192
|
+
drawn.prepareVehicles();
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
const { x, y, z, yaw } = p;
|
|
196
|
+
// a builder a world left out draws nothing of its kind: the people still walk
|
|
197
|
+
if (m.what === 'cart') {
|
|
198
|
+
drawn.carts?.vehicle(x, y, z, yaw, c.travel);
|
|
199
|
+
const ox = placeOn(c, m.ahead + shafts, m.side);
|
|
200
|
+
drawn.herd?.beast(ox.x, ox.y, ox.z, ox.yaw, c.v, c.travel, m.tint, 1);
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
drawn.wagons?.vehicle(x, y, z, yaw, c.travel);
|
|
204
|
+
for (let side = -1; side <= 1; side += 2) {
|
|
205
|
+
const ox = placeOn(c, m.ahead + team.ahead, m.side + team.apart * side);
|
|
206
|
+
drawn.herd?.beast(ox.x, ox.y, ox.z, ox.yaw, c.v, c.travel + side * 0.3, m.tint, 1);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
function moveMembers(c) {
|
|
211
|
+
const show = drawn && c.near,
|
|
212
|
+
members = c.members;
|
|
213
|
+
for (let i = 0; i < members.length; i++) {
|
|
214
|
+
const m = members[i],
|
|
215
|
+
p = placeOn(c, m.ahead, m.side),
|
|
216
|
+
seen = show && inView(p.x, p.y + 1, p.z, 3.4, false, true);
|
|
217
|
+
if (m.figure) {
|
|
218
|
+
const g = m.figure;
|
|
219
|
+
g.ax = p.x;
|
|
220
|
+
g.az = p.z;
|
|
221
|
+
g.yaw = p.yaw;
|
|
222
|
+
g.speed = c.v; // walking at the convoy's pace, or standing (0)
|
|
223
|
+
g.travel = c.travel + g.ph;
|
|
224
|
+
if (m.what === 'rider' && seen) drawn.mounts?.horse(p.x, p.y, p.z, p.yaw, c.v, c.travel + g.ph, m.coat, g.s, 0);
|
|
225
|
+
} else if (seen) drawVehicle(c, m, p);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
function tick(dt) {
|
|
230
|
+
if (disposed) return;
|
|
231
|
+
const cx = camera.position.x,
|
|
232
|
+
cz = camera.position.z;
|
|
233
|
+
if (drawn) {
|
|
234
|
+
drawn.mounts?.begin();
|
|
235
|
+
drawn.herd?.begin();
|
|
236
|
+
drawn.carts?.begin();
|
|
237
|
+
drawn.wagons?.begin();
|
|
238
|
+
}
|
|
239
|
+
for (let i = 0; i < convoys.length; i++) {
|
|
240
|
+
const c = convoys[i],
|
|
241
|
+
head = placeOn(c, 0, 0),
|
|
242
|
+
d2 = (head.x - cx) ** 2 + (head.z - cz) ** 2;
|
|
243
|
+
if (!asked && d2 < raiseSq) {
|
|
244
|
+
asked = true;
|
|
245
|
+
raise();
|
|
246
|
+
}
|
|
247
|
+
c.near = d2 < drawnSq;
|
|
248
|
+
goOn(c, dt, convoys, isTravelling(c.rank));
|
|
249
|
+
moveMembers(c);
|
|
250
|
+
}
|
|
251
|
+
if (drawn) {
|
|
252
|
+
drawn.mounts?.end();
|
|
253
|
+
drawn.herd?.end();
|
|
254
|
+
drawn.carts?.end();
|
|
255
|
+
drawn.wagons?.end();
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
function dispose() {
|
|
260
|
+
disposed = true;
|
|
261
|
+
if (drawn?.convoy) group.remove(drawn.convoy);
|
|
262
|
+
drawn = null;
|
|
263
|
+
everyone.length = 0;
|
|
264
|
+
convoys.length = 0;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
return { tick, convoys, dispose };
|
|
268
|
+
}
|