roamwright 0.61.22 → 0.61.23
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.html +1 -0
- package/examples/fliers.js +41 -1
- package/examples/town-fittings.js +17 -8
- package/geometry/crawl-shapes.js +86 -1
- package/geometry/crawler-giant-spider.js +100 -0
- package/geometry/harbour-kit.js +178 -8
- package/geometry/plant-garden.js +88 -0
- package/geometry/road-bridges.js +74 -0
- package/geometry/town-garden.js +3 -44
- package/index.js +18 -4
- package/motion/crawler-pack.js +110 -0
- package/package.json +1 -1
- package/rendering/crawler-pack.js +91 -0
- package/scripts/bundle.mjs +17 -5
- package/scripts/vendor.mjs +209 -36
package/examples/fliers.html
CHANGED
|
@@ -45,6 +45,7 @@
|
|
|
45
45
|
<button type="button" data-view="crag" aria-pressed="true">Crag & lantern</button>
|
|
46
46
|
<button type="button" data-view="corvid" aria-pressed="false">Corvid</button>
|
|
47
47
|
<button type="button" data-view="skies" aria-pressed="false">Sky flocks</button>
|
|
48
|
+
<button type="button" data-view="crawlers" aria-pressed="false">Crawlers</button>
|
|
48
49
|
</div>
|
|
49
50
|
</div>
|
|
50
51
|
</footer>
|
package/examples/fliers.js
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
import * as THREE from 'three';
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
createDaylightSky,
|
|
4
|
+
createGiantSpiderPack,
|
|
5
|
+
createOrbitCamera,
|
|
6
|
+
createStreetLamps,
|
|
7
|
+
scatterTrees,
|
|
8
|
+
scatterTussocks,
|
|
9
|
+
snakeGeometry,
|
|
10
|
+
} from 'roamwright';
|
|
3
11
|
import { sstep } from 'roamwright/math/scalar.js';
|
|
4
12
|
import { GB } from 'roamwright/geometry/builder.js';
|
|
5
13
|
import { C, TRS } from 'roamwright/geometry/primitives.js';
|
|
@@ -230,6 +238,33 @@ const company = createLongFlierCompany({ count: 4, shapes: longFlierArrays(), ti
|
|
|
230
238
|
worldGroup.add(company.group);
|
|
231
239
|
const flier = { x: 0, y: 0, z: 0, ry: 0, rx: 0, rz: 0 };
|
|
232
240
|
|
|
241
|
+
// Ground crawlers on the meadow clearing east of the lantern: a small pack of giant spiders and basking snakes.
|
|
242
|
+
const crawlerPack = createGiantSpiderPack({
|
|
243
|
+
ground: groundAt,
|
|
244
|
+
places: [
|
|
245
|
+
[0, 1.0, 0.85],
|
|
246
|
+
[-1.9, -0.4, 0.78],
|
|
247
|
+
[1.8, -0.6, 0.82],
|
|
248
|
+
],
|
|
249
|
+
});
|
|
250
|
+
crawlerPack.position.set(11, groundAt(11, -7), -7);
|
|
251
|
+
worldGroup.add(crawlerPack);
|
|
252
|
+
|
|
253
|
+
const snakeGeo = snakeGeometry(shapes, undefined, { tagged: false });
|
|
254
|
+
const snakeMat = new THREE.MeshStandardMaterial({ vertexColors: true, roughness: 0.65, flatShading: true });
|
|
255
|
+
const snakes = new THREE.InstancedMesh(snakeGeo, snakeMat, 4);
|
|
256
|
+
[
|
|
257
|
+
[8.4, -4.6, 0.6],
|
|
258
|
+
[9.8, -4.2, -1.1],
|
|
259
|
+
[12.4, -4.8, 2.2],
|
|
260
|
+
[10.7, -3.5, 0.2],
|
|
261
|
+
].forEach(([sx, sz, yaw], i) => {
|
|
262
|
+
snakes.setMatrixAt(i, TRS(sx, groundAt(sx, sz), sz, 1, 1, 1, yaw));
|
|
263
|
+
});
|
|
264
|
+
snakes.castShadow = true;
|
|
265
|
+
snakes.computeBoundingSphere();
|
|
266
|
+
worldGroup.add(snakes);
|
|
267
|
+
|
|
233
268
|
createDaylightSky({
|
|
234
269
|
scene,
|
|
235
270
|
renderer,
|
|
@@ -254,6 +289,7 @@ const views = {
|
|
|
254
289
|
crag: { eye: [2.2, 2.9, 12.6], target: [-1.4, 2.5, -3.2] },
|
|
255
290
|
corvid: { eye: [1.8, 1.35, 3.4], target: [-0.5, 0.7, 0.7] },
|
|
256
291
|
skies: { eye: [6, 5.5, 18], target: [-4, 15, -24] },
|
|
292
|
+
crawlers: { eye: [11.2, 3.4, 0.8], target: [10.8, 0.8, -7.2] },
|
|
257
293
|
};
|
|
258
294
|
|
|
259
295
|
const rig = createOrbitCamera({
|
|
@@ -294,6 +330,10 @@ function stepFliers(dt, t) {
|
|
|
294
330
|
company.place(i, flier, (Math.sin(t * 0.5 + i) + 1) / 2);
|
|
295
331
|
}
|
|
296
332
|
company.draw(camera);
|
|
333
|
+
const cx = 11 + Math.cos(t * 0.25) * 3.2;
|
|
334
|
+
const cz = -7.5 + Math.sin(t * 0.25) * 2.2;
|
|
335
|
+
crawlerPack.position.set(cx, groundAt(cx, cz), cz);
|
|
336
|
+
crawlerPack.userData.tick(dt);
|
|
297
337
|
}
|
|
298
338
|
// Advance once so every flock, swarm and glider is in mid-flight on frame 1.
|
|
299
339
|
stepFliers(1 / 60, 1.5);
|
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
createHouseKitMaterials,
|
|
11
11
|
createHouseKitMeshes,
|
|
12
12
|
createOrbitCamera,
|
|
13
|
+
createPlantList,
|
|
13
14
|
createShipKit,
|
|
14
15
|
createShipMeshes,
|
|
15
16
|
createSimpleWater,
|
|
@@ -35,7 +36,7 @@ import { townFrame } from 'roamwright/geometry/land-town-ground.js';
|
|
|
35
36
|
import { sstep, TAU } from 'roamwright/math/scalar.js';
|
|
36
37
|
import { initExample } from './stage.js';
|
|
37
38
|
|
|
38
|
-
const { canvas, renderer, camera, scene, worldGroup, seed,
|
|
39
|
+
const { canvas, renderer, camera, scene, worldGroup, seed, noise, hash, shapes } = initExample({
|
|
39
40
|
fallbackSeed: 42,
|
|
40
41
|
fov: 42,
|
|
41
42
|
});
|
|
@@ -101,6 +102,8 @@ const townWorks = createTownWorks({
|
|
|
101
102
|
well: props.propWell,
|
|
102
103
|
},
|
|
103
104
|
});
|
|
105
|
+
const tints = createPlantTints({ fbm: noise.fbm, vnoise: noise.vnoise, hash });
|
|
106
|
+
const gardenPlants = createGardenPlants({ crownBlob: tints.crownBlob, crownTint: tints.crownTint });
|
|
104
107
|
const townGarden = createTownGarden({
|
|
105
108
|
shapes,
|
|
106
109
|
color: C,
|
|
@@ -113,9 +116,8 @@ const townGarden = createTownGarden({
|
|
|
113
116
|
kitFrame: houseKit.kitFrame,
|
|
114
117
|
levelFloor: townWorks.levelFloor,
|
|
115
118
|
benchProp: props.propBench,
|
|
119
|
+
createPlantList: () => createPlantList({ frame: houseKit.kitFrame, hash, colourDrift: tints.standColourDrift }),
|
|
116
120
|
});
|
|
117
|
-
const tints = createPlantTints({ fbm: noise.fbm, vnoise: noise.vnoise, hash });
|
|
118
|
-
const gardenPlants = createGardenPlants({ crownBlob: tints.crownBlob, crownTint: tints.crownTint });
|
|
119
121
|
|
|
120
122
|
const fort = createCityFortification({ ground: groundAt, shapes, color: C, transform: TRS, houseKit });
|
|
121
123
|
const frame = townFrame({
|
|
@@ -197,18 +199,26 @@ const harbourKit = createHarbourKit({
|
|
|
197
199
|
moor: (spec, x, sea, z, yaw, len, rng) => mooredSpecs.push({ spec, x, sea, z, yaw, len, seed: (rng() * 1e6) | 0 }),
|
|
198
200
|
warship: SHIP_PRESETS.galley,
|
|
199
201
|
props: {
|
|
202
|
+
crane: props.propCrane,
|
|
200
203
|
crates: props.propCrates,
|
|
201
204
|
goods: props.propGoods,
|
|
202
205
|
netRack: props.propNetRack,
|
|
203
206
|
standard: props.propStandard,
|
|
204
207
|
tollBooth: props.propTollBooth,
|
|
205
208
|
},
|
|
209
|
+
hash,
|
|
206
210
|
});
|
|
207
211
|
|
|
208
|
-
//
|
|
209
|
-
const
|
|
210
|
-
K.stone
|
|
211
|
-
|
|
212
|
+
// Dressed stone quayside apron, timber pier and working harbour gear along the merchant waterfront.
|
|
213
|
+
const buildRng = mulberry32(seed * 17 + 5);
|
|
214
|
+
harbourKit.quayside(K.stone, buildRng, 118, QUAY_Y, 0xd6ccb4, -72);
|
|
215
|
+
harbourKit.pier(K.wood, buildRng, frame, -54, 34, QUAY_Y);
|
|
216
|
+
harbourKit.harbourGear(K.kit, buildRng, frame, -116, 12, QUAY_Y, 0, {
|
|
217
|
+
half: 118,
|
|
218
|
+
spare: x => Math.abs(x + 54) < 7,
|
|
219
|
+
stairX: -72,
|
|
220
|
+
anchorage: [42, 58],
|
|
221
|
+
});
|
|
212
222
|
|
|
213
223
|
const harbourPlan = {
|
|
214
224
|
town: {
|
|
@@ -234,7 +244,6 @@ const harbourPlan = {
|
|
|
234
244
|
},
|
|
235
245
|
};
|
|
236
246
|
|
|
237
|
-
const buildRng = mulberry32(seed * 17 + 5);
|
|
238
247
|
const palms = [];
|
|
239
248
|
townGarden.townGardens(K, buildRng, harbourPlan, palms);
|
|
240
249
|
harbourKit.harbourStores(K, buildRng, harbourPlan);
|
package/geometry/crawl-shapes.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
import { GB } from './builder.js';
|
|
8
|
-
import { TRS, plainUnitShapes } from './primitives.js';
|
|
8
|
+
import { TRS, plainUnitShapes, stick } from './primitives.js';
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* Default beetle linear colours: `shell` (wing cases, head, legs) and `sheen` (thorax gloss).
|
|
@@ -24,6 +24,29 @@ export const RAT_LOOK = {
|
|
|
24
24
|
bare: [0.3, 0.2, 0.17],
|
|
25
25
|
};
|
|
26
26
|
|
|
27
|
+
/**
|
|
28
|
+
* Default fire-ant linear colours: `body` (abdomen, thorax and head beads).
|
|
29
|
+
*/
|
|
30
|
+
export const ANT_LOOK = {
|
|
31
|
+
body: [0.22, 0.05, 0.02],
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Default ground-snake linear colours: `scales` (segmented body and flat head).
|
|
36
|
+
*/
|
|
37
|
+
export const SNAKE_LOOK = {
|
|
38
|
+
scales: [0.1, 0.08, 0.045],
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Default hand-sized spider linear colours: `abdomen`, `thorax` and `legs`.
|
|
43
|
+
*/
|
|
44
|
+
export const SPIDER_LOOK = {
|
|
45
|
+
abdomen: [0.02, 0.018, 0.016],
|
|
46
|
+
thorax: [0.05, 0.03, 0.02],
|
|
47
|
+
legs: [0.02, 0.018, 0.016],
|
|
48
|
+
};
|
|
49
|
+
|
|
27
50
|
/**
|
|
28
51
|
* A thumb-sized beetle facing +z: wing cases, thorax, head, and six legs.
|
|
29
52
|
*
|
|
@@ -69,3 +92,65 @@ export function ratGeometry(shapes = plainUnitShapes(), look = RAT_LOOK) {
|
|
|
69
92
|
);
|
|
70
93
|
return b.build();
|
|
71
94
|
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* A small ant about its feet, facing +z: three segmented body beads (abdomen, thorax, head).
|
|
98
|
+
*
|
|
99
|
+
* @param {object} [shapes=plainUnitShapes()] Unit shapes library providing `sph`.
|
|
100
|
+
* @param {typeof ANT_LOOK} [look=ANT_LOOK] Linear vertex colours.
|
|
101
|
+
* @param {object} [options]
|
|
102
|
+
* @param {boolean} [options.tagged=true] Include a zeroed `aTag` attribute for figure-shader instancing.
|
|
103
|
+
* @returns {import('three').BufferGeometry}
|
|
104
|
+
*/
|
|
105
|
+
export function antGeometry(shapes = plainUnitShapes(), look = ANT_LOOK, { tagged = true } = {}) {
|
|
106
|
+
const b = tagged ? Object.assign(new GB(), { tg: [] }) : new GB(),
|
|
107
|
+
{ body } = look;
|
|
108
|
+
b.add(shapes.sph, body, TRS(0, 0.012, -0.018, 0.011, 0.01, 0.016));
|
|
109
|
+
b.add(shapes.sph, body, TRS(0, 0.012, 0, 0.007, 0.007, 0.009));
|
|
110
|
+
b.add(shapes.sph, body, TRS(0, 0.013, 0.014, 0.008, 0.008, 0.008));
|
|
111
|
+
return b.build(true);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* A ground snake about its middle, facing +z: a sinuous S-curved body tapering toward the tail and a flat head.
|
|
116
|
+
*
|
|
117
|
+
* @param {object} [shapes=plainUnitShapes()] Unit shapes library providing `sph`.
|
|
118
|
+
* @param {typeof SNAKE_LOOK} [look=SNAKE_LOOK] Linear vertex colours.
|
|
119
|
+
* @param {object} [options]
|
|
120
|
+
* @param {boolean} [options.tagged=true] Include a zeroed `aTag` attribute for figure-shader instancing.
|
|
121
|
+
* @returns {import('three').BufferGeometry}
|
|
122
|
+
*/
|
|
123
|
+
export function snakeGeometry(shapes = plainUnitShapes(), look = SNAKE_LOOK, { tagged = true } = {}) {
|
|
124
|
+
const b = tagged ? Object.assign(new GB(), { tg: [] }) : new GB(),
|
|
125
|
+
{ scales } = look,
|
|
126
|
+
bend = u => Math.sin(u * 7) * 0.12;
|
|
127
|
+
for (let k = 0; k < 10; k++) {
|
|
128
|
+
const u0 = k / 10,
|
|
129
|
+
u1 = (k + 1) / 10;
|
|
130
|
+
stick(b, [bend(u0), 0.03, -0.7 + u0 * 1.3], [bend(u1), 0.03, -0.7 + u1 * 1.3], 0.012 + 0.022 * u0, scales);
|
|
131
|
+
}
|
|
132
|
+
b.add(shapes.sph, scales, TRS(bend(1), 0.035, 0.63, 0.04, 0.025, 0.06));
|
|
133
|
+
return b.build(true);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* A hand-sized spider about its middle, belly down and facing +z: two body lobes and eight bent legs.
|
|
138
|
+
*
|
|
139
|
+
* @param {object} [shapes=plainUnitShapes()] Unit shapes library providing `sph`.
|
|
140
|
+
* @param {typeof SPIDER_LOOK} [look=SPIDER_LOOK] Linear vertex colours.
|
|
141
|
+
* @returns {import('three').BufferGeometry}
|
|
142
|
+
*/
|
|
143
|
+
export function spiderGeometry(shapes = plainUnitShapes(), look = SPIDER_LOOK) {
|
|
144
|
+
const b = new GB(),
|
|
145
|
+
{ abdomen, thorax, legs } = look;
|
|
146
|
+
b.add(shapes.sph, abdomen, TRS(0, 0.01, -0.03, 0.05, 0.035, 0.07));
|
|
147
|
+
b.add(shapes.sph, thorax, TRS(0, 0.012, 0.035, 0.04, 0.03, 0.045));
|
|
148
|
+
for (let k = 0; k < 8; k++) {
|
|
149
|
+
const sg = k < 4 ? 1 : -1,
|
|
150
|
+
a = ((k % 4) - 1.5) * 0.55,
|
|
151
|
+
knee = [sg * 0.06 * Math.cos(a), 0.05, 0.03 + 0.06 * Math.sin(a)];
|
|
152
|
+
stick(b, [sg * 0.015, 0.02, 0.03], knee, 0.006, legs);
|
|
153
|
+
stick(b, knee, [sg * 0.12 * Math.cos(a), 0, 0.03 + 0.12 * Math.sin(a)], 0.004, legs);
|
|
154
|
+
}
|
|
155
|
+
return b.build(true);
|
|
156
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Articulated giant spider gait-moment geometry builder for stepped crawler packs (`createCrawlerPack`,
|
|
3
|
+
* `createGiantSpiderPack`): builds each still phase of an alternating four-leg tetrapod gait with cephalothorax,
|
|
4
|
+
* banded abdomen, fangs, four eyes, and eight three-segment legs. Worker-safe.
|
|
5
|
+
* @module
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { dim } from '../math/color.js';
|
|
9
|
+
import { GB } from './builder.js';
|
|
10
|
+
import { C, TRS, plainUnitShapes, stick } from './primitives.js';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Default giant spider colours (sRGB hex or linear RGB `[r, g, b]`): dusty brown hide, paler dorsal blaze and leg
|
|
14
|
+
* bands, and dark eyes.
|
|
15
|
+
*/
|
|
16
|
+
export const GIANT_SPIDER_LOOK = Object.freeze({
|
|
17
|
+
hide: 0x4a3c2e,
|
|
18
|
+
band: 0x8a7458,
|
|
19
|
+
eye: 0x060606,
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Default giant spider gait proportions (metres and radians): `legs` rows are `[angleFromForward, reach, hipZ]`.
|
|
24
|
+
*/
|
|
25
|
+
export const GIANT_SPIDER_GAIT = Object.freeze({
|
|
26
|
+
moments: 8,
|
|
27
|
+
stride: 0.9,
|
|
28
|
+
hipY: 0.52,
|
|
29
|
+
kneeUp: 0.5,
|
|
30
|
+
lift: 0.18,
|
|
31
|
+
legs: Object.freeze([
|
|
32
|
+
Object.freeze([0.42, 1.25, 0.2]),
|
|
33
|
+
Object.freeze([1.05, 1.08, 0.1]),
|
|
34
|
+
Object.freeze([1.75, 1.0, 0.0]),
|
|
35
|
+
Object.freeze([2.45, 1.15, -0.1]),
|
|
36
|
+
]),
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
const resolveColor = col => (Array.isArray(col) ? col : C(col));
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Builds one still moment of a giant spider's alternating tetrapod gait at cycle phase `u` (`0` to `1`), facing +z with
|
|
43
|
+
* grounded feet at `y = 0`.
|
|
44
|
+
*
|
|
45
|
+
* @param {number} u Gait cycle phase in `[0, 1)`.
|
|
46
|
+
* @param {object} [options]
|
|
47
|
+
* @param {object} [options.shapes=plainUnitShapes()] Unit shapes library providing `sph`.
|
|
48
|
+
* @param {{ hide?: number | number[], band?: number | number[], eye?: number | number[] }} [options.look=GIANT_SPIDER_LOOK] Hide, band and eye colours (sRGB hex or linear RGB).
|
|
49
|
+
* @param {typeof GIANT_SPIDER_GAIT} [options.gait=GIANT_SPIDER_GAIT] Stride, hip height, leg geometry and lift parameters.
|
|
50
|
+
* @returns {import('three').BufferGeometry}
|
|
51
|
+
*/
|
|
52
|
+
export function giantSpiderMoment(u, { shapes = plainUnitShapes(), look = GIANT_SPIDER_LOOK, gait = GIANT_SPIDER_GAIT } = {}) {
|
|
53
|
+
const b = new GB(),
|
|
54
|
+
hide = resolveColor(look.hide ?? GIANT_SPIDER_LOOK.hide),
|
|
55
|
+
band = resolveColor(look.band ?? GIANT_SPIDER_LOOK.band),
|
|
56
|
+
eye = resolveColor(look.eye ?? GIANT_SPIDER_LOOK.eye),
|
|
57
|
+
hipY = gait.hipY ?? GIANT_SPIDER_GAIT.hipY,
|
|
58
|
+
stride = gait.stride ?? GIANT_SPIDER_GAIT.stride,
|
|
59
|
+
kneeUp = gait.kneeUp ?? GIANT_SPIDER_GAIT.kneeUp,
|
|
60
|
+
lift = gait.lift ?? GIANT_SPIDER_GAIT.lift,
|
|
61
|
+
legs = gait.legs ?? GIANT_SPIDER_GAIT.legs,
|
|
62
|
+
bob = 0.03 * Math.cos(u * Math.PI * 4); // body dips each time an alternating set of legs lands
|
|
63
|
+
b.add(shapes.sph, hide, TRS(0, hipY + bob, 0.12, 0.42, 0.26, 0.5));
|
|
64
|
+
b.add(shapes.sph, dim(hide, 0.85), TRS(0, hipY + 0.1 + bob, -0.5, 0.6, 0.5, 0.82, -0.25));
|
|
65
|
+
b.add(shapes.sph, band, TRS(0, hipY + 0.31 + bob, -0.48, 0.3, 0.06, 0.5, -0.25));
|
|
66
|
+
for (const s of [-1, 1]) {
|
|
67
|
+
stick(b, [s * 0.06, hipY - 0.02 + bob, 0.34], [s * 0.05, hipY - 0.2 + bob, 0.42], 0.06, dim(hide, 0.7));
|
|
68
|
+
b.add(shapes.sph, eye, TRS(s * 0.05, hipY + 0.1 + bob, 0.34, 0.05, 0.05, 0.05));
|
|
69
|
+
b.add(shapes.sph, eye, TRS(s * 0.11, hipY + 0.08 + bob, 0.3, 0.04, 0.04, 0.04));
|
|
70
|
+
}
|
|
71
|
+
for (let k = 0; k < 8; k++) {
|
|
72
|
+
const side = k < 4 ? 1 : -1,
|
|
73
|
+
[angle, reach, along] = legs[k % 4],
|
|
74
|
+
first = (k % 2 === 0) === side > 0, // alternating tetrapod sets: left 1,3 with right 2,4
|
|
75
|
+
t = (u + (first ? 0 : 0.5)) % 1,
|
|
76
|
+
stance = t < 0.5,
|
|
77
|
+
swing = stance ? 0 : Math.sin(((t - 0.5) / 0.5) * Math.PI),
|
|
78
|
+
slide = (stance ? 0.5 - t / 0.5 : -0.5 + (t - 0.5) / 0.5) * stride * 0.5,
|
|
79
|
+
hip = [side * 0.13, hipY + bob, along],
|
|
80
|
+
foot = [side * Math.sin(angle) * reach, lift * swing, Math.cos(angle) * reach + slide],
|
|
81
|
+
knee = [hip[0] + (foot[0] - hip[0]) * 0.42, Math.max(hip[1], foot[1]) + kneeUp - 0.1 * swing, hip[2] + (foot[2] - hip[2]) * 0.42],
|
|
82
|
+
ankle = [foot[0] * 0.92 + hip[0] * 0.08, foot[1] + 0.16, foot[2] * 0.92 + hip[2] * 0.08];
|
|
83
|
+
stick(b, hip, knee, 0.075, hide);
|
|
84
|
+
stick(b, knee, ankle, 0.055, band);
|
|
85
|
+
stick(b, ankle, foot, 0.035, hide);
|
|
86
|
+
}
|
|
87
|
+
return b.build();
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Builds an array of `moments` evenly spaced gait geometries for a giant spider.
|
|
92
|
+
*
|
|
93
|
+
* @param {object} [options] Forwarded to {@link giantSpiderMoment}, plus `moments` count.
|
|
94
|
+
* @param {number} [options.moments=8] Number of gait phases to bake.
|
|
95
|
+
* @returns {import('three').BufferGeometry[]}
|
|
96
|
+
*/
|
|
97
|
+
export function giantSpiderMoments(options = {}) {
|
|
98
|
+
const count = options.moments ?? options.gait?.moments ?? GIANT_SPIDER_GAIT.moments;
|
|
99
|
+
return Array.from({ length: count }, (_, i) => giantSpiderMoment(i / count, options));
|
|
100
|
+
}
|
package/geometry/harbour-kit.js
CHANGED
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Procedural harbour works kit beside the ship kit and breakwater seawall:
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
2
|
+
* Procedural harbour works kit beside the ship kit and breakwater seawall: stone quayside aprons, coping, bollards,
|
|
3
|
+
* mooring rings and water stairs (`quayside`), walkable quay decks (`quayDeck`), timber piers on piles (`pier`), working
|
|
4
|
+
* harbour gear with cranes, cargo, drying nets and moored/anchored craft (`harbourGear`), waterfront warehouse and shop
|
|
5
|
+
* rows with passages and landed cargo stacks (`harbourStores`), quay approach furniture including gate, toll booth,
|
|
6
|
+
* standards, drying nets, carved stone loads and palms (`harbourLanding`), fortified naval fleet dockyards with moored
|
|
7
|
+
* warships, gangways, spare-spar ricks, outer anchorage and dividing yard wall (`navalYard`), plus curving breakwater
|
|
8
|
+
* moles and beacon lighthouses (`seawall`, `mole`, `moleLight` via `createSeawall`). Worker-safe.
|
|
7
9
|
* @module
|
|
8
10
|
*/
|
|
9
11
|
|
|
12
|
+
import * as THREE from 'three';
|
|
10
13
|
import { dim } from '../math/color.js';
|
|
14
|
+
import { createHash } from '../math/random.js';
|
|
11
15
|
import { TAU } from '../math/scalar.js';
|
|
12
16
|
import { createCityFortification } from './fort-city-walls.js';
|
|
13
17
|
import { createSeawall } from './fort-seawall.js';
|
|
@@ -18,14 +22,67 @@ import { createTownHouses } from './town-houses.js';
|
|
|
18
22
|
import { createTownWorks, placeInTown } from './town-works.js';
|
|
19
23
|
|
|
20
24
|
const DEFAULT_PASSAGE = 4; // width of passages through waterfront store rows to the street behind, metres
|
|
25
|
+
const DEFAULT_HASH = createHash(0);
|
|
21
26
|
const noop = () => {};
|
|
22
27
|
const DEFAULT_HARBOUR_PROPS = {
|
|
28
|
+
crane: noop,
|
|
23
29
|
crates: noop,
|
|
24
30
|
goods: noop,
|
|
25
31
|
netRack: noop,
|
|
26
32
|
standard: noop,
|
|
27
33
|
tollBooth: noop,
|
|
28
34
|
};
|
|
35
|
+
const DEFAULT_BOAT_SPEC = (_len, open) => (open ? SHIP_PRESETS.rowingBoat : SHIP_PRESETS.cog);
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Default waterfront dimensions and colours (metres and sRGB hex / linear RGB) shared by `quayside`, `quayDeck`,
|
|
39
|
+
* `pier` and `harbourGear`.
|
|
40
|
+
*/
|
|
41
|
+
export const HARBOUR_WATERFRONT = Object.freeze({
|
|
42
|
+
apron: 54,
|
|
43
|
+
bollardStep: 8,
|
|
44
|
+
bollardFrom: 10,
|
|
45
|
+
craneEdge: 1.3,
|
|
46
|
+
pierWidth: 4.2,
|
|
47
|
+
timberColor: 0x5a4632,
|
|
48
|
+
plankColor: 0x6e5a44,
|
|
49
|
+
ringColor: [0.05, 0.045, 0.04],
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Default offset in metres forward from the quay edge (`z = 0`) where a harbour crane stands so its jib clears the wall.
|
|
54
|
+
*/
|
|
55
|
+
export const CRANE_EDGE = HARBOUR_WATERFRONT.craneEdge;
|
|
56
|
+
|
|
57
|
+
let defaultRing = null;
|
|
58
|
+
function getDefaultRing() {
|
|
59
|
+
return (defaultRing ??= new THREE.TorusGeometry(0.16, 0.025, 4, 10));
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Snaps a crane's along-quay coordinate `x` to the midpoint between two bollards so it stands clear of bollards and windlasses.
|
|
64
|
+
* @param {number} x - Desired along-quay coordinate in metres.
|
|
65
|
+
* @param {number} half - Quay half-length in metres.
|
|
66
|
+
* @param {number} [bollardFrom=10] - Distance from each quay end to the first bollard in metres.
|
|
67
|
+
* @param {number} [bollardStep=8] - Spacing between bollards in metres.
|
|
68
|
+
* @returns {number} Snapped along-quay coordinate in metres.
|
|
69
|
+
*/
|
|
70
|
+
export function craneX(x, half, bollardFrom = HARBOUR_WATERFRONT.bollardFrom, bollardStep = HARBOUR_WATERFRONT.bollardStep) {
|
|
71
|
+
return -half + bollardFrom + bollardStep * (Math.round((x + half - bollardFrom) / bollardStep - 0.5) + 0.5);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Computes the walkable stone floor record for a quay apron in a harbour frame (`u` along quay, `v` inland).
|
|
76
|
+
* @param {{ yaw: number, world: (u: number, v: number) => [number, number] }} frame - Port local-to-world frame.
|
|
77
|
+
* @param {number} half - Quay half-length in metres.
|
|
78
|
+
* @param {number} top - Quay apron surface elevation in metres.
|
|
79
|
+
* @param {number} [apron=54] - Paved apron depth inland from the quay edge in metres.
|
|
80
|
+
* @returns {{ surface: string, x: number, z: number, hx: number, hz: number, c: number, s: number, y: number }}
|
|
81
|
+
*/
|
|
82
|
+
export function quayDeck(frame, half, top, apron = HARBOUR_WATERFRONT.apron) {
|
|
83
|
+
const [x, z] = frame.world(0, apron / 2 - 1.1);
|
|
84
|
+
return { surface: 'stone', x, z, hx: half, hz: apron / 2 + 1.1, c: Math.cos(frame.yaw), s: Math.sin(frame.yaw), y: top };
|
|
85
|
+
}
|
|
29
86
|
|
|
30
87
|
/**
|
|
31
88
|
* Creates a harbour works builder bound to unit shapes, house-kit placers, town-house builder, ship mooring hook,
|
|
@@ -38,9 +95,20 @@ const DEFAULT_HARBOUR_PROPS = {
|
|
|
38
95
|
* @param {Function} [options.placeHouse] - Planned-town house placer (`createTownHouses().placeHouse`).
|
|
39
96
|
* @param {Function} [options.quayGate] - Quay approach gateway builder (`createCityFortification().quayGate`).
|
|
40
97
|
* @param {Function} [options.carvedLoad] - Carved stone load builder `(kit, rng, x, z, ry, stone)` (`createTownWorks().carvedChest`).
|
|
41
|
-
* @param {Function} [options.moor] - Vessel mooring callback `(spec, x, sea, z, yaw, len, rng)`.
|
|
98
|
+
* @param {Function} [options.moor] - Vessel mooring callback `(spec, x, sea, z, yaw, len, rng, fishing?)`.
|
|
99
|
+
* @param {(len: number, open?: boolean) => object} [options.boatSpec] - Vessel preset builder for harbour craft.
|
|
42
100
|
* @param {object} [options.warship] - Ship specification passed to `moor` for naval yard berths (`SHIP_PRESETS.galley`).
|
|
43
|
-
* @param {object} [options.props] - Harbour prop builders `{ crates, goods, netRack, standard, tollBooth }`.
|
|
101
|
+
* @param {object} [options.props] - Harbour prop builders `{ crane, crates, goods, netRack, standard, tollBooth }`.
|
|
102
|
+
* @param {(a: number, b: number, salt: number) => number} [options.hash] - Deterministic 2D hash for mooring ring placement.
|
|
103
|
+
* @param {THREE.BufferGeometry} [options.ring] - Mooring ring geometry (defaults to a small torus).
|
|
104
|
+
* @param {number} [options.apron=54] - Paved quay apron depth inland from the edge in metres.
|
|
105
|
+
* @param {number} [options.bollardStep=8] - Spacing between quay bollards in metres.
|
|
106
|
+
* @param {number} [options.bollardFrom=10] - Distance from each quay end to the first bollard in metres.
|
|
107
|
+
* @param {number} [options.craneEdge=1.3] - Forward offset from the quay edge where cranes stand in metres.
|
|
108
|
+
* @param {number} [options.pierWidth=4.2] - Timber pier deck width in metres.
|
|
109
|
+
* @param {number} [options.timberColor=0x5a4632] - Pier pile and cross-beam sRGB hex colour.
|
|
110
|
+
* @param {number} [options.plankColor=0x6e5a44] - Pier deck plank sRGB hex colour.
|
|
111
|
+
* @param {number[]} [options.ringColor=[0.05, 0.045, 0.04]] - Linear RGB colour for iron mooring rings.
|
|
44
112
|
* @param {number} [options.passage=4] - Width of passages left between waterfront store rows in metres.
|
|
45
113
|
* @param {Function} [options.battlement] - Breakwater mole battlement builder forwarded to `createSeawall`.
|
|
46
114
|
* @param {Function} [options.floor] - Breakwater walkable deck builder forwarded to `createSeawall`.
|
|
@@ -50,6 +118,12 @@ const DEFAULT_HARBOUR_PROPS = {
|
|
|
50
118
|
* @param {number} [options.panelLength=9] - Target masonry chord length per mole segment in metres.
|
|
51
119
|
* @param {number} [options.bedDepth=-11] - Mole footing elevation in metres.
|
|
52
120
|
* @returns {{
|
|
121
|
+
* CRANE_EDGE: number,
|
|
122
|
+
* craneX: (x: number, half: number) => number,
|
|
123
|
+
* quayside: (gb: object, rng: () => number, half: number, top: number, stone: number, stairX: number) => void,
|
|
124
|
+
* quayDeck: (frame: object, half: number, top: number) => object,
|
|
125
|
+
* pier: (wd: object, rng: () => number, frame: object, x: number, len: number, top: number) => object,
|
|
126
|
+
* harbourGear: (kit: object, rng: () => number, frame: object, x0: number, x1: number, top: number, sea: number, opts: object) => Array<object>,
|
|
53
127
|
* harbourStores: (K: object, rng: () => number, plan: object) => void,
|
|
54
128
|
* harbourLanding: (K: object, rng: () => number, plan: object, palms: Array<number[]>) => void,
|
|
55
129
|
* navalYard: (K: object, rng: () => number, sea: number) => void,
|
|
@@ -62,6 +136,7 @@ export function createHarbourKit(options = {}) {
|
|
|
62
136
|
const shapes = options.shapes ?? createUnitShapes();
|
|
63
137
|
const color = options.color ?? defaultColor;
|
|
64
138
|
const transform = options.transform ?? defaultTransform;
|
|
139
|
+
const hash = options.hash ?? DEFAULT_HASH;
|
|
65
140
|
let kitFallback = null;
|
|
66
141
|
const getKit = () => (kitFallback ??= createHouseKit({ shapes }));
|
|
67
142
|
const kitAt = options.kitAt ?? getKit().kitAt;
|
|
@@ -75,9 +150,21 @@ export function createHarbourKit(options = {}) {
|
|
|
75
150
|
const carvedLoad =
|
|
76
151
|
options.carvedLoad ?? ((...args) => (worksFallback ??= createTownWorks({ shapes, color, transform, kitAt })).carvedChest(...args));
|
|
77
152
|
const moor = options.moor ?? noop;
|
|
153
|
+
const boatSpec = options.boatSpec ?? DEFAULT_BOAT_SPEC;
|
|
78
154
|
const warship = options.warship ?? SHIP_PRESETS.galley;
|
|
79
155
|
const props = { ...DEFAULT_HARBOUR_PROPS, ...options.props };
|
|
80
156
|
const passage = options.passage ?? DEFAULT_PASSAGE;
|
|
157
|
+
const apron = options.apron ?? HARBOUR_WATERFRONT.apron;
|
|
158
|
+
const bollardStep = options.bollardStep ?? HARBOUR_WATERFRONT.bollardStep;
|
|
159
|
+
const bollardFrom = options.bollardFrom ?? HARBOUR_WATERFRONT.bollardFrom;
|
|
160
|
+
const craneEdge = options.craneEdge ?? HARBOUR_WATERFRONT.craneEdge;
|
|
161
|
+
const pierWidth = options.pierWidth ?? HARBOUR_WATERFRONT.pierWidth;
|
|
162
|
+
const timberColor = options.timberColor ?? HARBOUR_WATERFRONT.timberColor;
|
|
163
|
+
const plankColor = options.plankColor ?? HARBOUR_WATERFRONT.plankColor;
|
|
164
|
+
const ringColor = options.ringColor ?? HARBOUR_WATERFRONT.ringColor;
|
|
165
|
+
const ringGeometry = () => options.ring ?? getDefaultRing();
|
|
166
|
+
const snapCraneX = (x, half) => craneX(x, half, bollardFrom, bollardStep);
|
|
167
|
+
const deckForQuay = (frame, half, top) => quayDeck(frame, half, top, apron);
|
|
81
168
|
|
|
82
169
|
const { seawall, mole, moleLight } = createSeawall({
|
|
83
170
|
shapes,
|
|
@@ -94,6 +181,76 @@ export function createHarbourKit(options = {}) {
|
|
|
94
181
|
|
|
95
182
|
const setDown = (K, rng, u, v, ry, prop, y) => placeInTown(kitAt, K, rng, u, v, ry, prop, y);
|
|
96
183
|
|
|
184
|
+
// Dressed stone quay in the port's local frame (x along quay, +z out over water): flagstone apron with course joints,
|
|
185
|
+
// sea wall down into the water, coping, bollards, iron mooring rings, and a stone water stair at `stairX`.
|
|
186
|
+
function quayside(gb, rng, half, top, stone, stairX) {
|
|
187
|
+
const st = (k = 1) => dim(color(stone, 0.06, rng), k);
|
|
188
|
+
const ring = ringGeometry();
|
|
189
|
+
gb.box(0, top - 0.55, -apron / 2, half * 2, 0.55, apron, st());
|
|
190
|
+
for (let x = -half + 3; x < half; x += 6) gb.box(x, top - 0.02, -apron / 2, 0.08, 0.03, apron, st(0.8));
|
|
191
|
+
gb.box(0, -4, 1, half * 2, top + 4.05, 2.2, st(0.78));
|
|
192
|
+
gb.box(0, top, 0.1, half * 2, 0.2, 0.8, st(1.08));
|
|
193
|
+
for (let x = -half + bollardFrom; x <= half - bollardFrom; x += bollardStep) {
|
|
194
|
+
gb.add(shapes.cyl6, st(0.7), transform(x, top + 0.05, -0.6, 0.46, 0.6, 0.46));
|
|
195
|
+
if (hash(x, 1, 94) < 0.5) gb.add(ring, ringColor, transform(x + 3, top - 0.8, 1.12));
|
|
196
|
+
}
|
|
197
|
+
for (let k = 0; k < 9; k++) gb.box(stairX, top - 0.2 - k * 0.42, 0.6 + k * 0.4, 3, 0.42, 0.42, st(0.9));
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
// Timber pier running out over the water (+z) from the quay at `x`: piles, cross-beams and plank deck. Returns its floor.
|
|
201
|
+
function pier(wd, rng, frame, x, len, top) {
|
|
202
|
+
const tim = color(timberColor, 0.1, rng);
|
|
203
|
+
for (let z = 3; z <= len; z += 4.5)
|
|
204
|
+
for (const s of [-1, 1]) {
|
|
205
|
+
wd.add(
|
|
206
|
+
shapes.cyl6,
|
|
207
|
+
dim(tim, 0.7),
|
|
208
|
+
transform(x + s * (pierWidth / 2 - 0.25), -5, z, 0.42, top + 5.4 + (rng() < 0.2 ? 0.7 : 0), 0.42),
|
|
209
|
+
);
|
|
210
|
+
wd.box(x, top - 0.42, z, pierWidth, 0.24, 0.26, dim(tim, 0.8));
|
|
211
|
+
}
|
|
212
|
+
for (let z = 2.2; z < len; z += 0.42)
|
|
213
|
+
wd.box(x + (rng() - 0.5) * 0.06, top - 0.16, z, pierWidth + (rng() - 0.5) * 0.2, 0.09, 0.38, color(plankColor, 0.14, rng));
|
|
214
|
+
const [cx, cz] = frame.world(x, -(2.2 + len) / 2);
|
|
215
|
+
return { x: cx, z: cz, hx: pierWidth / 2, hz: (len - 2.2) / 2 + 0.6, c: Math.cos(frame.yaw), s: Math.sin(frame.yaw), y: top - 0.07 };
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
// Working gear along a quay between `x0` and `x1`: cranes between bollards, apron cargo and drying nets, plus fishing boats
|
|
219
|
+
// moored alongside and vessels riding at anchor offshore.
|
|
220
|
+
function harbourGear(kit, rng, frame, x0, x1, top, sea, { half, spare = () => false, stairX, anchorage = [70, 150] }) {
|
|
221
|
+
const goods = [];
|
|
222
|
+
const place = (x, z, y, ry, fn) => {
|
|
223
|
+
const [wx, wz] = frame.world(x, -z);
|
|
224
|
+
kitAt(kit, wx, y, wz, frame.yaw + ry, false, fn, rng);
|
|
225
|
+
};
|
|
226
|
+
for (let x = x0 + 22; x < x1 - 10; x += 58 + rng() * 30) {
|
|
227
|
+
const at = snapCraneX(x, half);
|
|
228
|
+
if (!spare(at) && Math.abs(at - stairX) > 5) place(at, craneEdge, top, 0, props.crane);
|
|
229
|
+
}
|
|
230
|
+
for (let x = x0 + 6; x < x1 - 6; x += 9 + rng() * 12) {
|
|
231
|
+
if (spare(x)) continue;
|
|
232
|
+
const z = -9 - rng() * 22,
|
|
233
|
+
pick = rng();
|
|
234
|
+
goods.push({ u: x, v: -z, cargo: pick < 0.8 });
|
|
235
|
+
place(
|
|
236
|
+
x,
|
|
237
|
+
z,
|
|
238
|
+
top,
|
|
239
|
+
rng() * 6.28,
|
|
240
|
+
pick < 0.45 ? props.goods : pick < 0.8 ? (B, r) => props.crates(B, r, 2 + ((rng() * 3) | 0)) : props.netRack,
|
|
241
|
+
);
|
|
242
|
+
}
|
|
243
|
+
const ride = (x, z, y, ry, len, open, fishing = false) => {
|
|
244
|
+
const [wx, wz] = frame.world(x, -z),
|
|
245
|
+
[ox, oz] = frame.world(x, -z - 1);
|
|
246
|
+
moor(boatSpec(len, open), wx, y, wz, frame.yaw + ry, len, rng, fishing ? [ox - wx, oz - wz] : null);
|
|
247
|
+
};
|
|
248
|
+
for (let x = x0 + 14; x < x1 - 14; x += 26 + rng() * 34)
|
|
249
|
+
if (!spare(x)) ride(x, 5.6 + rng() * 1.2, sea, Math.PI / 2, 8 + rng() * 6, rng() < 0.5, true);
|
|
250
|
+
for (let k = 0; k < 6; k++) ride(x0 + rng() * (x1 - x0), anchorage[0] + rng() * anchorage[1], sea, rng() * 6.28, 11 + rng() * 8, true);
|
|
251
|
+
return goods;
|
|
252
|
+
}
|
|
253
|
+
|
|
97
254
|
// Two- and three-storey waterfront stores along the back of a quay, with ground-floor shops under awnings, passages
|
|
98
255
|
// through to the street behind, and landed cargo stacked before their doors.
|
|
99
256
|
function harbourStores(K, rng, plan) {
|
|
@@ -196,5 +353,18 @@ export function createHarbourKit(options = {}) {
|
|
|
196
353
|
for (const v of [22, 29]) K.stone.box(from - 5, q - 0.5, -v, 2.2, 5.6, 2.2, dim(stone, 1.0));
|
|
197
354
|
}
|
|
198
355
|
|
|
199
|
-
return {
|
|
356
|
+
return {
|
|
357
|
+
CRANE_EDGE: craneEdge,
|
|
358
|
+
craneX: snapCraneX,
|
|
359
|
+
quayside,
|
|
360
|
+
quayDeck: deckForQuay,
|
|
361
|
+
pier,
|
|
362
|
+
harbourGear,
|
|
363
|
+
harbourStores,
|
|
364
|
+
harbourLanding,
|
|
365
|
+
navalYard,
|
|
366
|
+
seawall,
|
|
367
|
+
mole,
|
|
368
|
+
moleLight,
|
|
369
|
+
};
|
|
200
370
|
}
|