roamwright 0.61.22 → 0.61.24
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/tools/README.md +2 -1
- package/tools/build-checks.cjs +188 -0
- package/tools/build-checks.test.cjs +36 -0
- package/tools/page-driver.cjs +4 -1
- package/tools/scene-bench.cjs +38 -1
package/geometry/plant-garden.js
CHANGED
|
@@ -8,11 +8,25 @@ import * as THREE from 'three';
|
|
|
8
8
|
import { createNoise } from '../math/noise.js';
|
|
9
9
|
import { createHash } from '../math/random.js';
|
|
10
10
|
import { addShape, partsGeometry, shapeParts } from './foliage.js';
|
|
11
|
+
import { partitionInstances } from './instances.js';
|
|
11
12
|
import { createPlantTints } from './plant-tints.js';
|
|
12
13
|
|
|
13
14
|
const BLOSSOMS = 6;
|
|
14
15
|
const DEFAULT_LOBE_DETAIL = 1; // icosahedron subdivided once: 80 triangles per lobe
|
|
15
16
|
const DEFAULT_BASE_COLOR = 0xffffff; // shaded in white so per-instance colours tint each plant
|
|
17
|
+
const DEFAULT_CELL_SIZE = 64; // spatial partition cell width in metres
|
|
18
|
+
const DEFAULT_HASH = createHash(0);
|
|
19
|
+
const _drift = [1, 1, 1];
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Default draw reach in metres beyond a garden plant list's own bounding radius for each plant shape.
|
|
23
|
+
*/
|
|
24
|
+
export const GARDEN_PLANT_SEEN = Object.freeze({
|
|
25
|
+
shrub: 320,
|
|
26
|
+
hedge: 260,
|
|
27
|
+
bloom: 200,
|
|
28
|
+
crop: 170,
|
|
29
|
+
});
|
|
16
30
|
|
|
17
31
|
/**
|
|
18
32
|
* Default unit-plant lobe tables standing on `y = 0`: each entry is `[x, y, z, width, height, depth]` in local metres.
|
|
@@ -90,3 +104,77 @@ export function createGardenPlantShapes(options = {}) {
|
|
|
90
104
|
|
|
91
105
|
return { plantShape, geometries };
|
|
92
106
|
}
|
|
107
|
+
|
|
108
|
+
function seenBounds(shape, matrices, seen) {
|
|
109
|
+
let x0 = Infinity;
|
|
110
|
+
let x1 = -Infinity;
|
|
111
|
+
let z0 = Infinity;
|
|
112
|
+
let z1 = -Infinity;
|
|
113
|
+
for (let i = 12; i < matrices.length; i += 16) {
|
|
114
|
+
x0 = Math.min(x0, matrices[i]);
|
|
115
|
+
x1 = Math.max(x1, matrices[i]);
|
|
116
|
+
z0 = Math.min(z0, matrices[i + 2]);
|
|
117
|
+
z1 = Math.max(z1, matrices[i + 2]);
|
|
118
|
+
}
|
|
119
|
+
return {
|
|
120
|
+
x: (x0 + x1) / 2,
|
|
121
|
+
z: (z0 + z1) / 2,
|
|
122
|
+
range: Math.hypot(x1 - x0, z1 - z0) / 2 + (seen[shape] ?? 260),
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Creates a garden and field plant collector that gathers world matrices and tinted colours per plant shape
|
|
128
|
+
* (transforming each local matrix by `frame` when supplied, optionally applying spatial colour drift), and emits
|
|
129
|
+
* spatially partitioned instanced-plant orders (`plant.orders()`) with per-shape draw reach.
|
|
130
|
+
*
|
|
131
|
+
* @param {object} [options] - Frame, colour-drift, partitioning and visibility reach options.
|
|
132
|
+
* @param {THREE.Matrix4 | null} [options.frame=null] - Current parent transform frame (e.g. `kitFrame`) multiplied ahead of each matrix.
|
|
133
|
+
* @param {(a: number, b: number, salt: number) => number} [options.hash] - Deterministic `[0, 1)` 2D hash for per-plant colour drift share.
|
|
134
|
+
* @param {((x: number, z: number, share: number, out: number[], strength: number) => void) | null} [options.colourDrift=null] - Optional spatial stand colour drift callback (`createPlantTints().standColourDrift`).
|
|
135
|
+
* @param {number} [options.bloomDrift=0.12] - Colour drift strength applied to `'bloom'` plants.
|
|
136
|
+
* @param {number} [options.foliageDrift=0.85] - Colour drift strength applied to non-bloom plant shapes.
|
|
137
|
+
* @param {Record<string, number>} [options.seen=GARDEN_PLANT_SEEN] - Extra draw reach in metres per plant shape.
|
|
138
|
+
* @param {number} [options.cellSize=64] - Spatial partition cell width in metres passed to `partitionInstances`.
|
|
139
|
+
* @param {string[]} [options.kinds=['shrub', 'hedge', 'bloom', 'crop']] - Plant shape buckets to initialize.
|
|
140
|
+
* @returns {((shape: string, tone: number[], matrix: THREE.Matrix4) => void) & { orders: () => Array<{ plants: { shape: string, cells: object[] }, seen: { x: number, z: number, range: number } }> }}
|
|
141
|
+
*/
|
|
142
|
+
export function createPlantList({
|
|
143
|
+
frame = null,
|
|
144
|
+
hash = DEFAULT_HASH,
|
|
145
|
+
colourDrift = null,
|
|
146
|
+
bloomDrift = 0.12,
|
|
147
|
+
foliageDrift = 0.85,
|
|
148
|
+
seen = GARDEN_PLANT_SEEN,
|
|
149
|
+
cellSize = DEFAULT_CELL_SIZE,
|
|
150
|
+
kinds = ['shrub', 'hedge', 'bloom', 'crop'],
|
|
151
|
+
} = {}) {
|
|
152
|
+
const of = Object.fromEntries(kinds.map(kind => [kind, { m: [], t: [] }]));
|
|
153
|
+
const at = new THREE.Matrix4();
|
|
154
|
+
const plant = (shape, tone, m) => {
|
|
155
|
+
if (frame) at.multiplyMatrices(frame, m);
|
|
156
|
+
else at.copy(m);
|
|
157
|
+
if (colourDrift) {
|
|
158
|
+
const wx = at.elements[12];
|
|
159
|
+
const wz = at.elements[14];
|
|
160
|
+
const share = hash(Math.round(wx * 11), Math.round(wz * 11), 439);
|
|
161
|
+
colourDrift(wx, wz, share, _drift, shape === 'bloom' ? bloomDrift : foliageDrift);
|
|
162
|
+
of[shape].m.push(...at.elements);
|
|
163
|
+
of[shape].t.push(tone[0] * _drift[0], tone[1] * _drift[1], tone[2] * _drift[2]);
|
|
164
|
+
} else {
|
|
165
|
+
of[shape].m.push(...at.elements);
|
|
166
|
+
of[shape].t.push(tone[0], tone[1], tone[2]);
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
plant.orders = () =>
|
|
170
|
+
Object.keys(of)
|
|
171
|
+
.filter(shape => of[shape].t.length)
|
|
172
|
+
.map(shape => ({
|
|
173
|
+
plants: {
|
|
174
|
+
shape,
|
|
175
|
+
cells: partitionInstances({ matrices: new Float32Array(of[shape].m), colours: new Float32Array(of[shape].t) }, cellSize),
|
|
176
|
+
},
|
|
177
|
+
seen: seenBounds(shape, of[shape].m, seen),
|
|
178
|
+
}));
|
|
179
|
+
return plant;
|
|
180
|
+
}
|
package/geometry/road-bridges.js
CHANGED
|
@@ -63,6 +63,7 @@ export function planBridgeFrame(road, index, len, halfWidth, ground, { tangentSp
|
|
|
63
63
|
* @param {number} [options.streamWidthMargin=0.4] Extra masonry half-width beyond road half-width in metres.
|
|
64
64
|
* @param {number} [options.tangentSpan=10] Vertex step for local tangent estimation.
|
|
65
65
|
* @param {number} [options.lift=0.12] Deck lift above the higher bank in metres.
|
|
66
|
+
* @param {Array<{ x: number, z: number, len: number, halfWidth?: number, rot?: number, y?: number, lift?: number, surface?: string, kind?: string }> | null} [options.fixed=null] Optional explicit bridge spans (such as fixed stone arches or harbour bridges not derived from road/river crossings) appended to `bridges` and `decks`.
|
|
66
67
|
* @returns {{ bridge: object | null, bridges: Array<object> }}
|
|
67
68
|
*/
|
|
68
69
|
export function planRoadBridges({
|
|
@@ -79,6 +80,7 @@ export function planRoadBridges({
|
|
|
79
80
|
streamWidthMargin = 0.4,
|
|
80
81
|
tangentSpan = 10,
|
|
81
82
|
lift = 0.12,
|
|
83
|
+
fixed = null,
|
|
82
84
|
}) {
|
|
83
85
|
const frameOpts = { tangentSpan, lift, decks },
|
|
84
86
|
outflow = rivers.find(r => r.kind === 'outflow')?.fine;
|
|
@@ -123,5 +125,77 @@ export function planRoadBridges({
|
|
|
123
125
|
}
|
|
124
126
|
}
|
|
125
127
|
|
|
128
|
+
if (fixed?.length) {
|
|
129
|
+
for (let i = 0; i < fixed.length; i++) {
|
|
130
|
+
const spec = fixed[i],
|
|
131
|
+
rot = spec.rot ?? 0,
|
|
132
|
+
dx = Math.cos(rot),
|
|
133
|
+
dz = -Math.sin(rot),
|
|
134
|
+
halfWidth = spec.halfWidth ?? 3,
|
|
135
|
+
spanLift = spec.lift ?? lift,
|
|
136
|
+
y =
|
|
137
|
+
spec.y ??
|
|
138
|
+
Math.max(
|
|
139
|
+
ground(spec.x - (dx * spec.len) / 2, spec.z - (dz * spec.len) / 2),
|
|
140
|
+
ground(spec.x + (dx * spec.len) / 2, spec.z + (dz * spec.len) / 2),
|
|
141
|
+
) + spanLift;
|
|
142
|
+
if (decks) {
|
|
143
|
+
const deck = { x: spec.x, z: spec.z, hx: spec.len / 2, hz: halfWidth, c: Math.cos(rot), s: Math.sin(rot), y };
|
|
144
|
+
if (spec.surface) deck.surface = spec.surface;
|
|
145
|
+
decks.push(deck);
|
|
146
|
+
}
|
|
147
|
+
bridges.push({
|
|
148
|
+
x: spec.x,
|
|
149
|
+
z: spec.z,
|
|
150
|
+
y,
|
|
151
|
+
len: spec.len,
|
|
152
|
+
rot,
|
|
153
|
+
dx,
|
|
154
|
+
dz,
|
|
155
|
+
px: -dz,
|
|
156
|
+
pz: dx,
|
|
157
|
+
w: halfWidth,
|
|
158
|
+
kind: spec.kind ?? 'stone',
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
126
163
|
return { bridge, bridges };
|
|
127
164
|
}
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Samples a centreline crossing path `Array<[x, y, z]>` along a planned bridge frame from abutment to abutment.
|
|
168
|
+
*
|
|
169
|
+
* @param {{ x: number, z: number, y: number, len: number, rot?: number, dx?: number, dz?: number }} frame Bridge frame from `planBridgeFrame` or `planRoadBridges`.
|
|
170
|
+
* @param {object} [options]
|
|
171
|
+
* @param {number} [options.segments=4] Number of intervals along the span (returns `segments + 1` points).
|
|
172
|
+
* @param {number} [options.margin=0] Extra approach distance in metres past each abutment.
|
|
173
|
+
* @param {number} [options.lift=0] Vertical offset in metres above the bridge deck `frame.y`.
|
|
174
|
+
* @returns {Array<[number, number, number]>}
|
|
175
|
+
*/
|
|
176
|
+
export function bridgeSpanPath(frame, { segments = 4, margin = 0, lift = 0 } = {}) {
|
|
177
|
+
const count = Math.max(1, Math.floor(segments)),
|
|
178
|
+
dx = frame.dx ?? Math.cos(frame.rot ?? 0),
|
|
179
|
+
dz = frame.dz ?? -Math.sin(frame.rot ?? 0),
|
|
180
|
+
half = frame.len / 2 + margin,
|
|
181
|
+
y = frame.y + lift,
|
|
182
|
+
points = new Array(count + 1);
|
|
183
|
+
for (let i = 0; i <= count; i++) {
|
|
184
|
+
const along = -half + (2 * half * i) / count;
|
|
185
|
+
points[i] = [frame.x + dx * along, y, frame.z + dz * along];
|
|
186
|
+
}
|
|
187
|
+
return points;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* Extracts crossing span paths for every bridge returned by {@link planRoadBridges} (both the primary bridge and any
|
|
192
|
+
* stream or fixed stone bridges), or for a plain array of bridge frames.
|
|
193
|
+
*
|
|
194
|
+
* @param {{ bridge?: object | null, bridges?: Array<object> } | Array<object>} planned Planned bridge output or frame list.
|
|
195
|
+
* @param {object} [options] Forwarded to {@link bridgeSpanPath}.
|
|
196
|
+
* @returns {Array<{ frame: object, path: Array<[number, number, number]> }>}
|
|
197
|
+
*/
|
|
198
|
+
export function bridgeSpanPaths(planned, options = {}) {
|
|
199
|
+
const list = Array.isArray(planned) ? planned : [...(planned?.bridge ? [planned.bridge] : []), ...(planned?.bridges ?? [])];
|
|
200
|
+
return list.map(frame => ({ frame, path: bridgeSpanPath(frame, options) }));
|
|
201
|
+
}
|
package/geometry/town-garden.js
CHANGED
|
@@ -6,13 +6,12 @@
|
|
|
6
6
|
* @module
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import * as THREE from 'three';
|
|
10
9
|
import { dim } from '../math/color.js';
|
|
11
10
|
import { mulberry32 as defaultRandom, pickR as defaultPick } from '../math/random.js';
|
|
12
11
|
import { TAU } from '../math/scalar.js';
|
|
13
12
|
import { createHouseKit } from './house-kit.js';
|
|
14
13
|
import { kitTilled as defaultKitTilled } from './house-kit-marks.js';
|
|
15
|
-
import {
|
|
14
|
+
import { createPlantList as defaultCreatePlantList } from './plant-garden.js';
|
|
16
15
|
import { C as defaultColor, createUnitShapes, TRS as defaultTransform } from './primitives.js';
|
|
17
16
|
import { createTownWorks, DEFAULT_TOWN_PROPS, placeInTown, townFacing } from './town-works.js';
|
|
18
17
|
|
|
@@ -41,7 +40,6 @@ const DEFAULT_PALETTE = {
|
|
|
41
40
|
bloom: [0xc44838, 0xd8963a, 0xd8c8a0, 0x8e4a7a],
|
|
42
41
|
};
|
|
43
42
|
const DEFAULT_RENDER = [0xebe3d0, 0xe4d9c0, 0xf0e9da];
|
|
44
|
-
const DEFAULT_SEEN = { shrub: 320, hedge: 260, bloom: 200, crop: 170 };
|
|
45
43
|
|
|
46
44
|
/**
|
|
47
45
|
* Returns a point `s` metres along the perimeter of rectangle `[x0, x1, z0, z1]`, starting at `(x0, z0)`.
|
|
@@ -58,45 +56,6 @@ export function alongRim([x0, x1, z0, z1], s) {
|
|
|
58
56
|
return [x0, z1 - (s - w)];
|
|
59
57
|
}
|
|
60
58
|
|
|
61
|
-
function defaultPlantList(kitFrame) {
|
|
62
|
-
const of = { shrub: { m: [], t: [] }, hedge: { m: [], t: [] }, bloom: { m: [], t: [] }, crop: { m: [], t: [] } };
|
|
63
|
-
const at = new THREE.Matrix4();
|
|
64
|
-
const plant = (shape, tone, m) => {
|
|
65
|
-
if (kitFrame) at.multiplyMatrices(kitFrame, m);
|
|
66
|
-
else at.copy(m);
|
|
67
|
-
of[shape].m.push(...at.elements);
|
|
68
|
-
of[shape].t.push(tone[0], tone[1], tone[2]);
|
|
69
|
-
};
|
|
70
|
-
plant.orders = () =>
|
|
71
|
-
Object.keys(of)
|
|
72
|
-
.filter(shape => of[shape].t.length)
|
|
73
|
-
.map(shape => {
|
|
74
|
-
const mats = of[shape].m;
|
|
75
|
-
let x0 = Infinity;
|
|
76
|
-
let x1 = -Infinity;
|
|
77
|
-
let z0 = Infinity;
|
|
78
|
-
let z1 = -Infinity;
|
|
79
|
-
for (let i = 12; i < mats.length; i += 16) {
|
|
80
|
-
x0 = Math.min(x0, mats[i]);
|
|
81
|
-
x1 = Math.max(x1, mats[i]);
|
|
82
|
-
z0 = Math.min(z0, mats[i + 2]);
|
|
83
|
-
z1 = Math.max(z1, mats[i + 2]);
|
|
84
|
-
}
|
|
85
|
-
return {
|
|
86
|
-
plants: {
|
|
87
|
-
shape,
|
|
88
|
-
cells: partitionInstances({ matrices: new Float32Array(mats), colours: new Float32Array(of[shape].t) }, 64),
|
|
89
|
-
},
|
|
90
|
-
seen: {
|
|
91
|
-
x: (x0 + x1) / 2,
|
|
92
|
-
z: (z0 + z1) / 2,
|
|
93
|
-
range: Math.hypot(x1 - x0, z1 - z0) / 2 + (DEFAULT_SEEN[shape] ?? 260),
|
|
94
|
-
},
|
|
95
|
-
};
|
|
96
|
-
});
|
|
97
|
-
return plant;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
59
|
/**
|
|
101
60
|
* Creates a walled town-garden builder bound to unit shapes, house-kit primitives, props, palettes and plant collection.
|
|
102
61
|
* @param {object} [options] - Geometry, house-kit, prop, palette and plant-collector bindings.
|
|
@@ -111,7 +70,7 @@ function defaultPlantList(kitFrame) {
|
|
|
111
70
|
* @param {Function} [options.kitPop] - House-kit `kitPop()` helper.
|
|
112
71
|
* @param {Function} [options.kitTilled] - House-kit raked-earth decal helper (`kitTilled`).
|
|
113
72
|
* @param {Function} [options.kitAt] - House-kit `kitAt` prop placer.
|
|
114
|
-
* @param {
|
|
73
|
+
* @param {import('three').Matrix4} [options.kitFrame] - House-kit current frame matrix (used by the default plant collector).
|
|
115
74
|
* @param {Function} [options.facing] - Direction-to-yaw helper (`townFacing`).
|
|
116
75
|
* @param {Function} [options.levelFloor] - Flat deck levelling helper (`createTownWorks().levelFloor`).
|
|
117
76
|
* @param {Function} [options.benchProp] - Bench prop builder `(kit, rng) => void`.
|
|
@@ -148,7 +107,7 @@ export function createTownGarden(options = {}) {
|
|
|
148
107
|
const benchProp = options.benchProp ?? DEFAULT_TOWN_PROPS.bench;
|
|
149
108
|
const palette = { ...DEFAULT_PALETTE, ...options.palette };
|
|
150
109
|
const renderPalette = options.renderPalette ?? DEFAULT_RENDER;
|
|
151
|
-
const createPlantList = options.createPlantList ?? (() =>
|
|
110
|
+
const createPlantList = options.createPlantList ?? (() => defaultCreatePlantList({ frame: kitFrame ?? getKit().kitFrame }));
|
|
152
111
|
|
|
153
112
|
const setDown = (K, rng, u, v, ry, prop, y) => placeInTown(kitAt, K, rng, u, v, ry, prop, y);
|
|
154
113
|
// A bed's own deterministic stream keyed by its corner so planting changes never perturb the rest of the town.
|
package/index.js
CHANGED
|
@@ -99,7 +99,7 @@ export { SPRING_COLOURS, SPRING_HEAD, planSpringRocks, planSprings, springFrame,
|
|
|
99
99
|
export { meshSprings } from './rendering/stream-springs.js';
|
|
100
100
|
export { planShoreReeds } from './geometry/shore-reeds.js';
|
|
101
101
|
export { roadRibbon } from './geometry/road-ribbon.js';
|
|
102
|
-
export { planBridgeFrame, planRoadBridges } from './geometry/road-bridges.js';
|
|
102
|
+
export { bridgeSpanPath, bridgeSpanPaths, planBridgeFrame, planRoadBridges } from './geometry/road-bridges.js';
|
|
103
103
|
export { layRoads } from './rendering/road-ribbons.js';
|
|
104
104
|
export {
|
|
105
105
|
AVENUE_CEDAR,
|
|
@@ -165,7 +165,7 @@ export { ARCADE_BAY, ARCADE_WALK, createTownWorks, townFacing } from './geometry
|
|
|
165
165
|
export { createTownLights, distantTownLights } from './geometry/town-lights.js';
|
|
166
166
|
export { createCourtyardInn } from './geometry/town-courtyard-inn.js';
|
|
167
167
|
export { alongRim, createTownGarden } from './geometry/town-garden.js';
|
|
168
|
-
export { createGardenPlantShapes, GARDEN_PLANT_LOBES } from './geometry/plant-garden.js';
|
|
168
|
+
export { createGardenPlantShapes, createPlantList, GARDEN_PLANT_LOBES, GARDEN_PLANT_SEEN } from './geometry/plant-garden.js';
|
|
169
169
|
export { createGardenPlants } from './rendering/plant-garden.js';
|
|
170
170
|
export { CITY_GLOW_FALLOFF, createCityGlow, createStreetLampNight, createStreetLamps } from './rendering/street-lamps.js';
|
|
171
171
|
export { createLampLightMap } from './rendering/lamp-light-map.js';
|
|
@@ -204,7 +204,7 @@ export { createRoomMaterials } from './rendering/room-materials.js';
|
|
|
204
204
|
export { finishRoom } from './rendering/room-space.js';
|
|
205
205
|
|
|
206
206
|
// ── Vessels ──────────────────────────────────────────────────────────────
|
|
207
|
-
export { createHarbourKit } from './geometry/harbour-kit.js';
|
|
207
|
+
export { CRANE_EDGE, HARBOUR_WATERFRONT, craneX, createHarbourKit, quayDeck } from './geometry/harbour-kit.js';
|
|
208
208
|
export { createShipKit } from './geometry/ship-kit.js';
|
|
209
209
|
export { SHIP_PRESETS } from './geometry/ship-presets.js';
|
|
210
210
|
export { createShipMeshes } from './rendering/ship-meshes.js';
|
|
@@ -232,7 +232,21 @@ export { herdArrays } from './motion/animal-herd-cast.js';
|
|
|
232
232
|
export { createFlierShapes, createSwarm, FLY_WINGS } from './rendering/flier-swarm.js';
|
|
233
233
|
export { CARPET_LEVELS, canineStrideSteps, createCanineStrideCast, createCarpetSwarm } from './rendering/flier-carpet.js';
|
|
234
234
|
export { FLY_LOOK, flyShape } from './geometry/flier-shapes.js';
|
|
235
|
-
export {
|
|
235
|
+
export {
|
|
236
|
+
ANT_LOOK,
|
|
237
|
+
BEETLE_LOOK,
|
|
238
|
+
RAT_LOOK,
|
|
239
|
+
SNAKE_LOOK,
|
|
240
|
+
SPIDER_LOOK,
|
|
241
|
+
antGeometry,
|
|
242
|
+
beetleGeometry,
|
|
243
|
+
ratGeometry,
|
|
244
|
+
snakeGeometry,
|
|
245
|
+
spiderGeometry,
|
|
246
|
+
} from './geometry/crawl-shapes.js';
|
|
247
|
+
export { GIANT_SPIDER_GAIT, GIANT_SPIDER_LOOK, giantSpiderMoment, giantSpiderMoments } from './geometry/crawler-giant-spider.js';
|
|
248
|
+
export { CRAWLER_PACK_DEFAULTS, createCrawlerPackMotion } from './motion/crawler-pack.js';
|
|
249
|
+
export { createCrawlerPack, createGiantSpiderPack } from './rendering/crawler-pack.js';
|
|
236
250
|
export { createCrawlFlight } from './motion/flier-swarm-flight.js';
|
|
237
251
|
export { CARPET_DEFAULTS, createCarpetFlight } from './motion/flier-carpet-flight.js';
|
|
238
252
|
export { createLampSwarmFlight, pickNearestAnchors } from './motion/flier-lamp-swarm.js';
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stepped pack-crawler motion solver: moves a group of ground crawlers together with a parent anchor, tracking heading
|
|
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. Worker-safe arithmetic only
|
|
5
|
+
* (no Three.js dependency) and zero per-frame allocations.
|
|
6
|
+
* @module
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { wrapRadians } from '../math/periodic.js';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Default crawler-pack motion parameters (metres, seconds, radians) and a seven-member formation `[side, ahead, scale]`.
|
|
13
|
+
*/
|
|
14
|
+
export const CRAWLER_PACK_DEFAULTS = Object.freeze({
|
|
15
|
+
moments: 8,
|
|
16
|
+
stride: 0.9,
|
|
17
|
+
mill: 0.45,
|
|
18
|
+
turn: 6,
|
|
19
|
+
jump: 3,
|
|
20
|
+
moveThreshold: 0.3,
|
|
21
|
+
wander: 0.25,
|
|
22
|
+
phaseStep: 0.37,
|
|
23
|
+
places: Object.freeze([
|
|
24
|
+
Object.freeze([0, 1.2, 1.05]),
|
|
25
|
+
Object.freeze([-2.1, 0.2, 0.95]),
|
|
26
|
+
Object.freeze([2.0, 0.5, 1]),
|
|
27
|
+
Object.freeze([-0.9, -1.9, 0.9]),
|
|
28
|
+
Object.freeze([1.3, -2.2, 1.1]),
|
|
29
|
+
Object.freeze([-2.9, -2.6, 0.85]),
|
|
30
|
+
Object.freeze([3.1, -1.6, 0.92]),
|
|
31
|
+
]),
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Creates a zero-allocation per-frame motion controller for a pack of ground crawlers sharing a moving origin.
|
|
36
|
+
*
|
|
37
|
+
* @param {object} [options]
|
|
38
|
+
* @param {Array<[number, number, number]>} [options.places=CRAWLER_PACK_DEFAULTS.places] Per-member `[side, ahead, scale]` slots in pack frame (metres).
|
|
39
|
+
* @param {number} [options.moments=8] Number of baked gait phases.
|
|
40
|
+
* @param {number} [options.stride=0.9] Metres travelled per gait cycle at scale 1.
|
|
41
|
+
* @param {number} [options.mill=0.45] Base gait cycles per second while the pack stands still.
|
|
42
|
+
* @param {number} [options.turn=6] Heading turn rate in inverse seconds.
|
|
43
|
+
* @param {number} [options.jump=3] Frame displacement in metres beyond which the pack is treated as teleported rather than running.
|
|
44
|
+
* @param {number} [options.moveThreshold=0.3] Minimum pack speed in metres per second to update heading and run instead of milling.
|
|
45
|
+
* @param {number} [options.wander=0.25] Loose lateral/longitudinal slot-wander amplitude in metres.
|
|
46
|
+
* @param {number} [options.phaseStep=0.37] Initial gait phase stagger between successive pack members.
|
|
47
|
+
* @returns {{
|
|
48
|
+
* members: Array<{ x: number, z: number, scale: number, phase: number, localX: number, localY: number, localZ: number, yaw: number, shown: number }>,
|
|
49
|
+
* step: (dt: number, packX: number, packY: number, packZ: number, ground: (x: number, z: number) => number) => void,
|
|
50
|
+
* }}
|
|
51
|
+
*/
|
|
52
|
+
export function createCrawlerPackMotion({
|
|
53
|
+
places = CRAWLER_PACK_DEFAULTS.places,
|
|
54
|
+
moments = CRAWLER_PACK_DEFAULTS.moments,
|
|
55
|
+
stride = CRAWLER_PACK_DEFAULTS.stride,
|
|
56
|
+
mill = CRAWLER_PACK_DEFAULTS.mill,
|
|
57
|
+
turn = CRAWLER_PACK_DEFAULTS.turn,
|
|
58
|
+
jump = CRAWLER_PACK_DEFAULTS.jump,
|
|
59
|
+
moveThreshold = CRAWLER_PACK_DEFAULTS.moveThreshold,
|
|
60
|
+
wander = CRAWLER_PACK_DEFAULTS.wander,
|
|
61
|
+
phaseStep = CRAWLER_PACK_DEFAULTS.phaseStep,
|
|
62
|
+
} = {}) {
|
|
63
|
+
const members = places.map(([x, z, scale], i) => ({
|
|
64
|
+
x,
|
|
65
|
+
z,
|
|
66
|
+
scale,
|
|
67
|
+
phase: i * phaseStep,
|
|
68
|
+
localX: x,
|
|
69
|
+
localY: 0,
|
|
70
|
+
localZ: z,
|
|
71
|
+
yaw: 0,
|
|
72
|
+
shown: 0,
|
|
73
|
+
}));
|
|
74
|
+
let lastX = 0,
|
|
75
|
+
lastZ = 0,
|
|
76
|
+
heading = 0,
|
|
77
|
+
started = false;
|
|
78
|
+
|
|
79
|
+
function step(dt, packX, packY, packZ, ground) {
|
|
80
|
+
const dx = packX - lastX,
|
|
81
|
+
dz = packZ - lastZ,
|
|
82
|
+
moved = Math.hypot(dx, dz),
|
|
83
|
+
speed = started && dt > 0 && moved < jump ? moved / dt : 0; // a jump is the pack set down somewhere, not a run
|
|
84
|
+
lastX = packX;
|
|
85
|
+
lastZ = packZ;
|
|
86
|
+
started = true;
|
|
87
|
+
if (speed > moveThreshold) heading = Math.atan2(dx, dz);
|
|
88
|
+
const sin = Math.sin(heading),
|
|
89
|
+
cos = Math.cos(heading),
|
|
90
|
+
k = 1 - Math.exp(-turn * dt);
|
|
91
|
+
for (let i = 0; i < members.length; i++) {
|
|
92
|
+
const m = members[i],
|
|
93
|
+
w = wander * Math.sin(m.phase * 1.3 + i),
|
|
94
|
+
lx = m.x + w,
|
|
95
|
+
lz = m.z + 0.6 * w,
|
|
96
|
+
rx = lx * cos + lz * sin,
|
|
97
|
+
rz = -lx * sin + lz * cos,
|
|
98
|
+
wx = packX + lx * cos + lz * sin,
|
|
99
|
+
wz = packZ - lx * sin + lz * cos;
|
|
100
|
+
m.phase += dt * (speed > moveThreshold ? speed / (stride * m.scale) : mill * (0.7 + 0.1 * i));
|
|
101
|
+
m.localX = rx;
|
|
102
|
+
m.localY = ground(wx, wz) - packY;
|
|
103
|
+
m.localZ = rz;
|
|
104
|
+
m.yaw += wrapRadians(heading - m.yaw) * k;
|
|
105
|
+
m.shown = Math.floor(m.phase * moments) % moments;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
return { members, step };
|
|
110
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "roamwright",
|
|
3
|
-
"version": "0.61.
|
|
3
|
+
"version": "0.61.24",
|
|
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",
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Three.js group builder for a stepped pack of ground crawlers (`createCrawlerPack`) and the default giant spider pack
|
|
3
|
+
* preset (`createGiantSpiderPack`): displays one baked gait-moment mesh per pack member each frame via `pack.userData.tick(dt)`
|
|
4
|
+
* with zero per-frame allocations.
|
|
5
|
+
* @module
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import * as THREE from 'three';
|
|
9
|
+
import { GIANT_SPIDER_GAIT, GIANT_SPIDER_LOOK, giantSpiderMoments } from '../geometry/crawler-giant-spider.js';
|
|
10
|
+
import { CRAWLER_PACK_DEFAULTS, createCrawlerPackMotion } from '../motion/crawler-pack.js';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Builds a `THREE.Group` containing a pack of ground crawlers driven by `createCrawlerPackMotion`, switching each member's
|
|
14
|
+
* visible gait-moment mesh inside `pack.userData.tick(dt)` without per-frame allocations.
|
|
15
|
+
*
|
|
16
|
+
* @param {object} options
|
|
17
|
+
* @param {THREE.BufferGeometry[]} options.moments Baked gait-moment geometries shared by every pack member.
|
|
18
|
+
* @param {Array<[number, number, number]>} [options.places=CRAWLER_PACK_DEFAULTS.places] Per-member `[side, ahead, scale]` slots in metres.
|
|
19
|
+
* @param {THREE.Material} [options.material] Shared material (defaults to flat-shaded vertex-coloured `MeshStandardMaterial`).
|
|
20
|
+
* @param {(x: number, z: number) => number} [options.ground] World terrain height sampler in metres (defaults to flat `0`).
|
|
21
|
+
* @param {number} [options.stride=CRAWLER_PACK_DEFAULTS.stride] Metres per gait cycle at scale 1.
|
|
22
|
+
* @param {number} [options.mill=CRAWLER_PACK_DEFAULTS.mill] Idle milling cycles per second.
|
|
23
|
+
* @param {number} [options.turn=CRAWLER_PACK_DEFAULTS.turn] Heading turn rate in inverse seconds.
|
|
24
|
+
* @param {number} [options.jump=CRAWLER_PACK_DEFAULTS.jump] Teleport jump threshold in metres.
|
|
25
|
+
* @param {number} [options.moveThreshold=CRAWLER_PACK_DEFAULTS.moveThreshold] Minimum running speed in metres per second.
|
|
26
|
+
* @param {number} [options.wander=CRAWLER_PACK_DEFAULTS.wander] Slot-wander amplitude in metres.
|
|
27
|
+
* @param {boolean} [options.castShadow=true] Whether member meshes cast shadows.
|
|
28
|
+
* @returns {THREE.Group} Pack group whose `userData.tick(dt)` advances the pack.
|
|
29
|
+
*/
|
|
30
|
+
export function createCrawlerPack({
|
|
31
|
+
moments,
|
|
32
|
+
places = CRAWLER_PACK_DEFAULTS.places,
|
|
33
|
+
material = new THREE.MeshStandardMaterial({ vertexColors: true, roughness: 0.7, flatShading: true }),
|
|
34
|
+
ground = () => 0,
|
|
35
|
+
castShadow = true,
|
|
36
|
+
...motionOptions
|
|
37
|
+
}) {
|
|
38
|
+
const pack = new THREE.Group(),
|
|
39
|
+
motion = createCrawlerPackMotion({
|
|
40
|
+
places,
|
|
41
|
+
moments: moments.length,
|
|
42
|
+
...motionOptions,
|
|
43
|
+
}),
|
|
44
|
+
bodies = motion.members.map(member => {
|
|
45
|
+
const body = new THREE.Group();
|
|
46
|
+
for (let i = 0; i < moments.length; i++) {
|
|
47
|
+
const mesh = new THREE.Mesh(moments[i], material);
|
|
48
|
+
mesh.castShadow = castShadow;
|
|
49
|
+
mesh.visible = false;
|
|
50
|
+
body.add(mesh);
|
|
51
|
+
}
|
|
52
|
+
body.scale.setScalar(member.scale);
|
|
53
|
+
pack.add(body);
|
|
54
|
+
return { body, shown: 0 };
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
pack.userData.tick = dt => {
|
|
58
|
+
motion.step(dt, pack.position.x, pack.position.y, pack.position.z, ground);
|
|
59
|
+
for (let i = 0; i < bodies.length; i++) {
|
|
60
|
+
const entry = bodies[i],
|
|
61
|
+
member = motion.members[i];
|
|
62
|
+
entry.body.position.set(member.localX, member.localY, member.localZ);
|
|
63
|
+
entry.body.rotation.y = member.yaw;
|
|
64
|
+
if (member.shown !== entry.shown) {
|
|
65
|
+
entry.body.children[entry.shown].visible = false;
|
|
66
|
+
entry.shown = member.shown;
|
|
67
|
+
}
|
|
68
|
+
entry.body.children[member.shown].visible = true;
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
return pack;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Convenience preset that builds a giant spider pack using {@link giantSpiderMoments} and {@link createCrawlerPack}.
|
|
77
|
+
*
|
|
78
|
+
* @param {object} [options] Combined options for {@link giantSpiderMoments} (`shapes`, `look`, `gait`) and {@link createCrawlerPack} (`places`, `material`, `ground`, `stride`, `mill`, `turn`, `jump`, `castShadow`, or pre-baked `moments`).
|
|
79
|
+
* @returns {THREE.Group}
|
|
80
|
+
*/
|
|
81
|
+
export function createGiantSpiderPack(options = {}) {
|
|
82
|
+
const moments =
|
|
83
|
+
options.moments ??
|
|
84
|
+
giantSpiderMoments({
|
|
85
|
+
moments: options.gait?.moments ?? GIANT_SPIDER_GAIT.moments,
|
|
86
|
+
shapes: options.shapes,
|
|
87
|
+
look: options.look ?? GIANT_SPIDER_LOOK,
|
|
88
|
+
gait: options.gait ?? GIANT_SPIDER_GAIT,
|
|
89
|
+
});
|
|
90
|
+
return createCrawlerPack({ ...options, moments });
|
|
91
|
+
}
|
package/scripts/bundle.mjs
CHANGED
|
@@ -8,7 +8,7 @@ import { join, relative, resolve, sep } from 'node:path';
|
|
|
8
8
|
import { pathToFileURL } from 'node:url';
|
|
9
9
|
import { linkApp } from './app-parts.mjs';
|
|
10
10
|
import { checkedLiteral, walkReach } from './module-graph.mjs';
|
|
11
|
-
import { buildRoamwright, buildThree, engineImports, pruneEngine, usedEngineExports } from './vendor.mjs';
|
|
11
|
+
import { buildRoamwright, buildThree, engineImports, partitionOptionalEngine, pruneEngine, usedEngineExports } from './vendor.mjs';
|
|
12
12
|
|
|
13
13
|
const STATIC = ['import-statement'];
|
|
14
14
|
|
|
@@ -140,12 +140,24 @@ export async function bundleApp({
|
|
|
140
140
|
const engineUsedBy = paths => engineImports([...paths].flatMap(p => imports.get(p)));
|
|
141
141
|
|
|
142
142
|
await buildThree(esbuild, { resolveModule });
|
|
143
|
+
const allEngine = engineUsedBy(imports.keys());
|
|
144
|
+
const startupEngine = engineUsedBy([...page, ...everyLand]);
|
|
145
|
+
const workerStartupEngine = engineUsedBy(reach(workerEntries, STATIC));
|
|
146
|
+
const workerJobsEngine = engineUsedBy(workers);
|
|
147
|
+
const optionalGroups = partitionOptionalEngine(allEngine, {
|
|
148
|
+
excluded: new Set([...workerStartupEngine, ...workerJobsEngine, ...startupEngine]),
|
|
149
|
+
lands: landEntries.map(p => engineUsedBy(reach([resolve(p)]))),
|
|
150
|
+
staticLands: lands.map(land => engineUsedBy(land)),
|
|
151
|
+
});
|
|
143
152
|
const engine = await buildRoamwright(esbuild, {
|
|
144
|
-
all:
|
|
153
|
+
all: allEngine,
|
|
145
154
|
used: usedEngineExports(outputFiles, metafile.outputs, { parse }),
|
|
146
|
-
startup:
|
|
147
|
-
workerStartup:
|
|
148
|
-
workerJobs:
|
|
155
|
+
startup: startupEngine,
|
|
156
|
+
workerStartup: workerStartupEngine,
|
|
157
|
+
workerJobs: workerJobsEngine,
|
|
158
|
+
optionalGroups,
|
|
159
|
+
rollup,
|
|
160
|
+
terser,
|
|
149
161
|
revision,
|
|
150
162
|
compactShaders,
|
|
151
163
|
resolveModule,
|