roamwright 0.61.29 → 0.61.31
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/crowd-batches.js +10 -4
- package/rendering/crowd-lifecycle.js +2 -4
- package/rendering/crowd-rig.js +6 -7
- package/rendering/glow-mesh.js +66 -0
- package/rendering/index.js +3 -1
- package/rendering/road-traffic.js +268 -0
- package/rendering/ruins-fittings.js +7 -25
- package/rendering/strata-cliffs.js +34 -11
- package/rendering/textures.js +2 -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,
|