roamwright 0.61.13 → 0.61.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +24 -22
- package/examples/ruins.html +60 -0
- package/examples/ruins.js +326 -0
- package/examples/town-fittings.html +52 -0
- package/examples/town-fittings.js +464 -0
- package/geometry/harbour-kit.js +200 -0
- package/geometry/paved-road.js +443 -0
- package/geometry/plant-garden.js +92 -0
- package/geometry/ruins-hill.js +392 -0
- package/geometry/ruins-mound.js +484 -0
- package/geometry/ruins-rubble.js +161 -0
- package/geometry/storm-wall.js +98 -0
- package/geometry/strata-rocks.js +270 -0
- package/geometry/town-garden.js +343 -0
- package/index.js +37 -1
- package/package.json +1 -1
- package/rendering/lamp-maps.js +87 -0
- package/rendering/paved-ground.js +218 -0
- package/rendering/paved-road.js +353 -0
- package/rendering/plant-garden.js +51 -0
- package/rendering/storm-wall.js +238 -0
- package/rendering/street-lamps.js +101 -1
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure typed-array geometry builder for a curved multi-layer storm curtain wall (sandstorm, blizzard, or ash wall):
|
|
3
|
+
* concentric vertical strips following a circular arc with ground-conforming footings, scrolling UVs, and per-vertex
|
|
4
|
+
* arc-end and layer-depth attributes. Worker-safe and free of Three.js.
|
|
5
|
+
* @module
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/** Default subdivision and layout constants for a layered storm wall mesh. */
|
|
9
|
+
export const STORM_WALL_DEFAULTS = {
|
|
10
|
+
layers: 5,
|
|
11
|
+
along: 150,
|
|
12
|
+
up: 10,
|
|
13
|
+
footSink: 8,
|
|
14
|
+
uvScale: 210,
|
|
15
|
+
layerUvOffset: 0.37,
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Generates vertex attribute and index typed arrays for a concentric multi-curtain storm wall arc.
|
|
20
|
+
* @param {object} options
|
|
21
|
+
* @param {number} [options.x=0] - Arc centre world X coordinate in metres.
|
|
22
|
+
* @param {number} [options.z=0] - Arc centre world Z coordinate in metres.
|
|
23
|
+
* @param {number} [options.radius=1200] - Mean arc radius in metres.
|
|
24
|
+
* @param {number} [options.sweep=1.5] - Half-angle of the arc on each side of `+x` in radians.
|
|
25
|
+
* @param {number} [options.width=150] - Radial thickness spanned across all curtain layers in metres.
|
|
26
|
+
* @param {number} [options.height=300] - Curtain wall height in metres.
|
|
27
|
+
* @param {(x: number, z: number) => number} [options.ground] - Ground height sampler `(x, z) => y` in metres (defaults to 0).
|
|
28
|
+
* @param {number} [options.layers=5] - Number of concentric curtain sheets.
|
|
29
|
+
* @param {number} [options.along=150] - Horizontal segments along the arc.
|
|
30
|
+
* @param {number} [options.up=10] - Vertical segments from foot to crest.
|
|
31
|
+
* @param {number} [options.footSink=8] - Metres the bottom edge sinks below ground so slopes never expose a gap.
|
|
32
|
+
* @param {number} [options.uvScale=210] - Arc-length metres per U repeat.
|
|
33
|
+
* @param {number} [options.layerUvOffset=0.37] - U phase shift per curtain layer so layers never align.
|
|
34
|
+
* @returns {{ position: Float32Array, uv: Float32Array, aEdge: Float32Array, index: Uint16Array | Uint32Array }} Typed mesh arrays.
|
|
35
|
+
*/
|
|
36
|
+
export function stormWallArrays({
|
|
37
|
+
x: cx = 0,
|
|
38
|
+
z: cz = 0,
|
|
39
|
+
radius = 1200,
|
|
40
|
+
sweep = 1.5,
|
|
41
|
+
width = 150,
|
|
42
|
+
height = 300,
|
|
43
|
+
ground = () => 0,
|
|
44
|
+
layers = STORM_WALL_DEFAULTS.layers,
|
|
45
|
+
along = STORM_WALL_DEFAULTS.along,
|
|
46
|
+
up = STORM_WALL_DEFAULTS.up,
|
|
47
|
+
footSink = STORM_WALL_DEFAULTS.footSink,
|
|
48
|
+
uvScale = STORM_WALL_DEFAULTS.uvScale,
|
|
49
|
+
layerUvOffset = STORM_WALL_DEFAULTS.layerUvOffset,
|
|
50
|
+
} = {}) {
|
|
51
|
+
const row = up + 1;
|
|
52
|
+
const vertsPerLayer = (along + 1) * row;
|
|
53
|
+
const totalVerts = layers * vertsPerLayer;
|
|
54
|
+
const position = new Float32Array(totalVerts * 3);
|
|
55
|
+
const uv = new Float32Array(totalVerts * 2);
|
|
56
|
+
const aEdge = new Float32Array(totalVerts * 2);
|
|
57
|
+
const index = totalVerts > 65535 ? new Uint32Array(layers * along * up * 6) : new Uint16Array(layers * along * up * 6);
|
|
58
|
+
const layerSpan = layers > 1 ? layers - 1 : 1;
|
|
59
|
+
|
|
60
|
+
let p = 0;
|
|
61
|
+
let u = 0;
|
|
62
|
+
let e = 0;
|
|
63
|
+
let idx = 0;
|
|
64
|
+
for (let layer = 0; layer < layers; layer++) {
|
|
65
|
+
const r = radius + (layers > 1 ? layer / layerSpan - 0.5 : 0) * width;
|
|
66
|
+
const base = layer * vertsPerLayer;
|
|
67
|
+
const layerShare = layers > 1 ? layer / layerSpan : 0.5;
|
|
68
|
+
for (let i = 0; i <= along; i++) {
|
|
69
|
+
const t = i / along;
|
|
70
|
+
const a = (t * 2 - 1) * sweep;
|
|
71
|
+
const x = cx + Math.cos(a) * r;
|
|
72
|
+
const z = cz + Math.sin(a) * r;
|
|
73
|
+
const foot = Math.max(ground(x, z), 0) - footSink;
|
|
74
|
+
const stU = (a * r) / uvScale + layer * layerUvOffset;
|
|
75
|
+
const edgeT = Math.min(t, 1 - t);
|
|
76
|
+
for (let j = 0; j <= up; j++) {
|
|
77
|
+
const v = j / up;
|
|
78
|
+
position[p++] = x;
|
|
79
|
+
position[p++] = foot + v * height;
|
|
80
|
+
position[p++] = z;
|
|
81
|
+
uv[u++] = stU;
|
|
82
|
+
uv[u++] = v;
|
|
83
|
+
aEdge[e++] = edgeT;
|
|
84
|
+
aEdge[e++] = layerShare;
|
|
85
|
+
if (i && j) {
|
|
86
|
+
const k = base + i * row + j;
|
|
87
|
+
index[idx++] = k - row - 1;
|
|
88
|
+
index[idx++] = k - row;
|
|
89
|
+
index[idx++] = k;
|
|
90
|
+
index[idx++] = k - row - 1;
|
|
91
|
+
index[idx++] = k;
|
|
92
|
+
index[idx++] = k - 1;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return { position, uv, aEdge, index };
|
|
98
|
+
}
|
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Instanced weathered boulders and bedded rock outcrops: wind-worn stones shaped from superquadric
|
|
3
|
+
* noise lumps and dipping strata outcrops with jointed ledges, weathered caps and foot scree.
|
|
4
|
+
* Pure geometry builders, worker-safe.
|
|
5
|
+
* @module
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import * as THREE from 'three';
|
|
9
|
+
import { createNoise } from '../math/noise.js';
|
|
10
|
+
import { TAU, lerp, sstep } from '../math/scalar.js';
|
|
11
|
+
import { GB } from './builder.js';
|
|
12
|
+
import { lump } from './primitives.js';
|
|
13
|
+
|
|
14
|
+
/** Default depth in metres a loose weathered stone extends below its origin so it sits cleanly on slopes. */
|
|
15
|
+
export const WORN_STONE_FOOT = -0.3;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Default shape descriptors for four loose weathered stone varieties (worn block, cobble, flat slab,
|
|
19
|
+
* uneven lump). Dimensions (`long`, `high`, `deep`) are in metres.
|
|
20
|
+
*/
|
|
21
|
+
export const WORN_STONE_FORMS = Object.freeze([
|
|
22
|
+
Object.freeze({ square: 2.7, long: 1.1, high: 0.7, deep: 0.8, wander: 0.14 }),
|
|
23
|
+
Object.freeze({ square: 2.1, long: 1.0, high: 0.76, deep: 0.9, wander: 0.1 }),
|
|
24
|
+
Object.freeze({ square: 2.9, long: 1.18, high: 0.5, deep: 0.76, wander: 0.12 }),
|
|
25
|
+
Object.freeze({ square: 2.3, long: 0.96, high: 0.66, deep: 0.86, wander: 0.2 }),
|
|
26
|
+
]);
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Default shape descriptors for smaller scree stones lying around an outcrop's foot.
|
|
30
|
+
*/
|
|
31
|
+
export const SCREE_STONE_FORMS = Object.freeze([
|
|
32
|
+
Object.freeze({ square: 2.5, long: 1.1, high: 0.72, deep: 0.86, wander: 0.16 }),
|
|
33
|
+
Object.freeze({ square: 2.2, long: 1.0, high: 0.7, deep: 0.9, wander: 0.12 }),
|
|
34
|
+
Object.freeze({ square: 2.8, long: 1.16, high: 0.56, deep: 0.78, wander: 0.14 }),
|
|
35
|
+
]);
|
|
36
|
+
|
|
37
|
+
/** Default seeds for the three distinct outcrop outline variations. */
|
|
38
|
+
export const OUTCROP_SEEDS = Object.freeze([11, 23, 37]);
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Default bedding, column density, dip and scree settings for {@link beddedOutcrop}.
|
|
42
|
+
* Heights and offsets are in metres.
|
|
43
|
+
*/
|
|
44
|
+
export const OUTCROP_SHAPE = Object.freeze({
|
|
45
|
+
/** Column count around a near-detail outcrop. */
|
|
46
|
+
round: 16,
|
|
47
|
+
/** Column count around a far-detail outcrop (must divide `round`). */
|
|
48
|
+
farRound: 8,
|
|
49
|
+
/** Fractional height where each rock bed ends, bottom to top. */
|
|
50
|
+
bedTops: Object.freeze([0.2, 0.46, 0.64, 0.86]),
|
|
51
|
+
/** Brightness shade factor for each bed, bottom to top. */
|
|
52
|
+
bedShades: Object.freeze([0.78, 0.92, 0.84, 0.96]),
|
|
53
|
+
/** Radial setback per successive bed in local metres. */
|
|
54
|
+
setBack: 0.09,
|
|
55
|
+
/** Base depth below ground in local metres. */
|
|
56
|
+
foot: -0.18,
|
|
57
|
+
/** Crest height of the top bed in local metres. */
|
|
58
|
+
high: 0.34,
|
|
59
|
+
/** Bed dip slope along the outcrop's length. */
|
|
60
|
+
dip: 0.16,
|
|
61
|
+
/** Number of fallen scree stones placed around the outcrop foot. */
|
|
62
|
+
scree: 6,
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
const _u = [0, 0, 0];
|
|
66
|
+
const _v = [0, 0, 0];
|
|
67
|
+
const _m4 = new THREE.Matrix4();
|
|
68
|
+
const _pos = new THREE.Vector3();
|
|
69
|
+
const _quat = new THREE.Quaternion();
|
|
70
|
+
const _euler = new THREE.Euler();
|
|
71
|
+
const _scale = new THREE.Vector3();
|
|
72
|
+
|
|
73
|
+
let fallbackNoise = null;
|
|
74
|
+
const defaultNoise = () => (fallbackNoise ??= createNoise().vnoise);
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Append a flat-shaded quad `(a, b, c, d)` (anticlockwise from front) into a geometry builder,
|
|
78
|
+
* with `low` linear RGB on `(a, b)` and `high` on `(c, d)`.
|
|
79
|
+
*
|
|
80
|
+
* @param {Pick<import('./builder.js').GB, 'raw'>} builder - Destination geometry builder.
|
|
81
|
+
* @param {number[]} a - First lower corner `[x, y, z]`.
|
|
82
|
+
* @param {number[]} b - Second lower corner `[x, y, z]`.
|
|
83
|
+
* @param {number[]} c - Second upper corner `[x, y, z]`.
|
|
84
|
+
* @param {number[]} d - First upper corner `[x, y, z]`.
|
|
85
|
+
* @param {number[]} low - Linear RGB colour `[r, g, b]` for the lower edge.
|
|
86
|
+
* @param {number[]} high - Linear RGB colour `[r, g, b]` for the upper edge.
|
|
87
|
+
*/
|
|
88
|
+
export function flatQuad(builder, a, b, c, d, low, high) {
|
|
89
|
+
for (let k = 0; k < 3; k++) {
|
|
90
|
+
_u[k] = b[k] - a[k];
|
|
91
|
+
_v[k] = d[k] - a[k];
|
|
92
|
+
}
|
|
93
|
+
const nx = _u[1] * _v[2] - _u[2] * _v[1];
|
|
94
|
+
const ny = _u[2] * _v[0] - _u[0] * _v[2];
|
|
95
|
+
const nz = _u[0] * _v[1] - _u[1] * _v[0];
|
|
96
|
+
const len = Math.hypot(nx, ny, nz) || 1;
|
|
97
|
+
const rx = nx / len;
|
|
98
|
+
const ry = ny / len;
|
|
99
|
+
const rz = nz / len;
|
|
100
|
+
builder.raw(a[0], a[1], a[2], rx, ry, rz, low[0], low[1], low[2]);
|
|
101
|
+
builder.raw(b[0], b[1], b[2], rx, ry, rz, low[0], low[1], low[2]);
|
|
102
|
+
builder.raw(c[0], c[1], c[2], rx, ry, rz, high[0], high[1], high[2]);
|
|
103
|
+
builder.raw(a[0], a[1], a[2], rx, ry, rz, low[0], low[1], low[2]);
|
|
104
|
+
builder.raw(c[0], c[1], c[2], rx, ry, rz, high[0], high[1], high[2]);
|
|
105
|
+
builder.raw(d[0], d[1], d[2], rx, ry, rz, high[0], high[1], high[2]);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Quantize a noise value `n` in `[0, 1]` into `steps` flat plateaus joined by steep ramps,
|
|
110
|
+
* modelling rock fractured cleanly along geological joints.
|
|
111
|
+
*
|
|
112
|
+
* @param {number} n - Input noise value in `[0, 1]`.
|
|
113
|
+
* @param {number} steps - Number of fracture steps.
|
|
114
|
+
* @returns {number} Stepped value in `[0, 1]`.
|
|
115
|
+
*/
|
|
116
|
+
export function jointed(n, steps) {
|
|
117
|
+
const u = n * steps;
|
|
118
|
+
const k = Math.floor(u);
|
|
119
|
+
return (k + sstep(0.7, 1, u - k)) / steps;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Build a wind-worn boulder or cobble geometry with smooth normals and white vertex colours (ready
|
|
124
|
+
* for per-instance tinting). `detail` 2 emits 320 triangles, `detail` 1 emits 80, and `detail` 0 emits 20.
|
|
125
|
+
*
|
|
126
|
+
* @param {number} detail - Icosahedron subdivision level (`0`, `1` or `2`).
|
|
127
|
+
* @param {number} seed - Seed offset into the surface noise field.
|
|
128
|
+
* @param {{ square: number, long: number, high: number, deep: number, wander: number }} form - Proportions in metres and superquadric exponent.
|
|
129
|
+
* @param {object} [options]
|
|
130
|
+
* @param {(x: number, z: number, salt: number) => number} [options.noise] - Value noise in `[0, 1)`.
|
|
131
|
+
* @param {number} [options.foot=-0.3] - Flat underside clip height in local metres.
|
|
132
|
+
* @returns {import('three').BufferGeometry}
|
|
133
|
+
*/
|
|
134
|
+
export function wornStone(detail, seed, { square, long, high, deep, wander }, options = {}) {
|
|
135
|
+
const noise = options.noise ?? defaultNoise();
|
|
136
|
+
const foot = options.foot ?? WORN_STONE_FOOT;
|
|
137
|
+
const g = lump(detail, (dir, out) => {
|
|
138
|
+
const boxiness = Math.abs(dir.x) ** square + Math.abs(dir.y) ** square + Math.abs(dir.z) ** square;
|
|
139
|
+
const broad = noise(dir.x * 2.3 + seed, dir.z * 2.3 + dir.y * 1.7, 612) - 0.5;
|
|
140
|
+
const grain = noise(dir.x * 5.1 + seed, dir.y * 5.1 + dir.z * 4.3, 613) - 0.5;
|
|
141
|
+
const r = (1 + wander * (broad + 0.5 * grain)) / boxiness ** (1 / square);
|
|
142
|
+
return out.set((dir.x * r * long) / 2, Math.max((dir.y * r * high) / 2, foot), (dir.z * r * deep) / 2);
|
|
143
|
+
});
|
|
144
|
+
g.setAttribute('color', new THREE.Float32BufferAttribute(new Float32Array(g.attributes.position.count * 3).fill(1), 3));
|
|
145
|
+
return g;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Build a low outcrop of dipping, jointed sedimentary beds with dust-covered ledges, a weathered
|
|
150
|
+
* cap and fallen scree stones around its base. Vertex colours sit around white for per-instance tinting.
|
|
151
|
+
*
|
|
152
|
+
* @param {number} seed - Outline and joint fracture seed.
|
|
153
|
+
* @param {boolean} [far=false] - When true, builds the coarser far-LOD outcrop sharing the same footprint.
|
|
154
|
+
* @param {object} [options]
|
|
155
|
+
* @param {(x: number, z: number, salt: number) => number} [options.noise] - Value noise in `[0, 1)`.
|
|
156
|
+
* @param {import('three').BufferGeometry[]} [options.screeStones] - Near scree stone geometries.
|
|
157
|
+
* @param {import('three').BufferGeometry[]} [options.farScreeStones] - Far scree stone geometries.
|
|
158
|
+
* @param {typeof GB} [options.Builder] - Geometry builder constructor (defaults to `GB`).
|
|
159
|
+
* @param {Partial<typeof OUTCROP_SHAPE>} [options.shape] - Overrides to {@link OUTCROP_SHAPE}.
|
|
160
|
+
* @returns {import('three').BufferGeometry}
|
|
161
|
+
*/
|
|
162
|
+
export function beddedOutcrop(seed, far = false, options = {}) {
|
|
163
|
+
const noise = options.noise ?? defaultNoise();
|
|
164
|
+
const Builder = options.Builder ?? GB;
|
|
165
|
+
const cfg = options.shape ? { ...OUTCROP_SHAPE, ...options.shape } : OUTCROP_SHAPE;
|
|
166
|
+
const b = new Builder();
|
|
167
|
+
const columns = far ? cfg.farRound : cfg.round;
|
|
168
|
+
const step = cfg.round / columns;
|
|
169
|
+
const scree = far
|
|
170
|
+
? (options.farScreeStones ?? SCREE_STONE_FORMS.map((form, i) => wornStone(0, 9 + 4 * i, form, { noise })))
|
|
171
|
+
: (options.screeStones ?? SCREE_STONE_FORMS.map((form, i) => wornStone(1, 9 + 4 * i, form, { noise })));
|
|
172
|
+
const long = 1.2 + 0.25 * noise(seed, 3.7, 905);
|
|
173
|
+
const edge = i => {
|
|
174
|
+
const a = (i / cfg.round) * TAU;
|
|
175
|
+
const r = 0.5 * (0.62 + 0.65 * noise(Math.cos(a) * 2.2 + seed, Math.sin(a) * 2.2, 901));
|
|
176
|
+
return [Math.cos(a) * r * long, Math.sin(a) * r];
|
|
177
|
+
};
|
|
178
|
+
const point = (i, k, top) => {
|
|
179
|
+
const [x, z] = edge(i % cfg.round);
|
|
180
|
+
const block = 1 - cfg.setBack * k - 0.24 * (jointed(noise(x * 3.1 + k * 5.3, z * 3.1 + seed, 902), 3) - 0.3) - 0.04 * top;
|
|
181
|
+
const up = top ? cfg.bedTops[k] : k ? cfg.bedTops[k - 1] : 0;
|
|
182
|
+
return [x * block, lerp(cfg.foot, cfg.high, up) + cfg.dip * x * up, z * block];
|
|
183
|
+
};
|
|
184
|
+
const dust = [1, 0.95, 0.87];
|
|
185
|
+
for (let k = 0; k < cfg.bedTops.length; k++) {
|
|
186
|
+
const shade = cfg.bedShades[k];
|
|
187
|
+
const last = k === cfg.bedTops.length - 1;
|
|
188
|
+
for (let i = 0; i < cfg.round; i += step) {
|
|
189
|
+
const p = point(i, k, 0);
|
|
190
|
+
const q = point(i + step, k, 0);
|
|
191
|
+
const r = point(i + step, k, 1);
|
|
192
|
+
const s = point(i, k, 1);
|
|
193
|
+
const weather = shade * (0.92 + 0.08 * noise(i * 0.7 + seed, k * 1.3, 903));
|
|
194
|
+
flatQuad(b, q, p, s, r, [weather * 0.8, weather * 0.79, weather * 0.78], [weather, weather, weather]);
|
|
195
|
+
if (last) continue;
|
|
196
|
+
flatQuad(b, r, s, point(i, k + 1, 0), point(i + step, k + 1, 0), dust, dust);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
const top = cfg.bedTops.length - 1;
|
|
200
|
+
const inner = i => {
|
|
201
|
+
const [x, y, z] = point(i, top, 1);
|
|
202
|
+
return [x * 0.55, y + 0.025 + 0.02 * noise(i * 1.1, seed + 6, 909), z * 0.55];
|
|
203
|
+
};
|
|
204
|
+
const middle = [0, lerp(cfg.foot, cfg.high, cfg.bedTops[top]) + 0.045, 0];
|
|
205
|
+
const cap = [0.94, 0.92, 0.88];
|
|
206
|
+
for (let i = 0; i < cfg.round; i += step) {
|
|
207
|
+
flatQuad(b, point(i + step, top, 1), point(i, top, 1), inner(i), inner(i + step), cap, cap);
|
|
208
|
+
flatQuad(b, inner(i + step), inner(i), middle, middle, cap, cap);
|
|
209
|
+
}
|
|
210
|
+
for (let n = 0; n < cfg.scree; n++) {
|
|
211
|
+
const a = (n / cfg.scree) * TAU + noise(n, seed, 904) * 0.8;
|
|
212
|
+
const [x, z] = edge(Math.round((a / TAU) * cfg.round) % cfg.round);
|
|
213
|
+
const out = 1.08 + 0.3 * noise(n * 1.7, seed + 2, 906);
|
|
214
|
+
const size = 0.07 + 0.08 * noise(n * 2.3, seed + 4, 907);
|
|
215
|
+
_euler.set(n, a, n * 0.7, 'XYZ');
|
|
216
|
+
_quat.setFromEuler(_euler);
|
|
217
|
+
b.add(
|
|
218
|
+
scree[n % scree.length],
|
|
219
|
+
[0.86, 0.84, 0.81],
|
|
220
|
+
_m4.compose(_pos.set(x * out, size * 0.2, z * out), _quat, _scale.set(size * 1.3, size * 0.7, size)),
|
|
221
|
+
);
|
|
222
|
+
}
|
|
223
|
+
return b.build(true);
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* Create a world-bound rock shape library producing near and far weathered loose stones and bedded
|
|
228
|
+
* outcrops from a supplied noise function and optional form/seed tables.
|
|
229
|
+
*
|
|
230
|
+
* @param {object} [options]
|
|
231
|
+
* @param {(x: number, z: number, salt: number) => number} [options.noise] - Seeded value noise (`createNoise().vnoise`).
|
|
232
|
+
* @param {readonly object[]} [options.stoneForms] - Loose stone form descriptors (defaults to {@link WORN_STONE_FORMS}).
|
|
233
|
+
* @param {readonly object[]} [options.screeForms] - Outcrop foot scree descriptors (defaults to {@link SCREE_STONE_FORMS}).
|
|
234
|
+
* @param {readonly number[]} [options.outcropSeeds] - Seeds for the outcrop variants (defaults to {@link OUTCROP_SEEDS}).
|
|
235
|
+
* @param {number} [options.foot=-0.3] - Flat underside clip height for worn stones in metres.
|
|
236
|
+
* @param {typeof GB} [options.Builder] - Geometry builder class.
|
|
237
|
+
* @param {Partial<typeof OUTCROP_SHAPE>} [options.shape] - Overrides to {@link OUTCROP_SHAPE}.
|
|
238
|
+
* @returns {{
|
|
239
|
+
* stones: import('three').BufferGeometry[],
|
|
240
|
+
* farStones: import('three').BufferGeometry[],
|
|
241
|
+
* screeStones: import('three').BufferGeometry[],
|
|
242
|
+
* farScreeStones: import('three').BufferGeometry[],
|
|
243
|
+
* outcrop: (seed: number, far?: boolean) => import('three').BufferGeometry,
|
|
244
|
+
* outcropShapes: () => import('three').BufferGeometry[],
|
|
245
|
+
* farOutcropShapes: () => import('three').BufferGeometry[],
|
|
246
|
+
* }}
|
|
247
|
+
*/
|
|
248
|
+
export function createRockShapes(options = {}) {
|
|
249
|
+
const noise = options.noise ?? defaultNoise();
|
|
250
|
+
const stoneForms = options.stoneForms ?? WORN_STONE_FORMS;
|
|
251
|
+
const screeForms = options.screeForms ?? SCREE_STONE_FORMS;
|
|
252
|
+
const outcropSeeds = options.outcropSeeds ?? OUTCROP_SEEDS;
|
|
253
|
+
const foot = options.foot ?? WORN_STONE_FOOT;
|
|
254
|
+
const Builder = options.Builder ?? GB;
|
|
255
|
+
const shape = options.shape;
|
|
256
|
+
const stones = stoneForms.map((form, i) => wornStone(2, 7 + 4 * i, form, { noise, foot }));
|
|
257
|
+
const farStones = stoneForms.map((form, i) => wornStone(1, 7 + 4 * i, form, { noise, foot }));
|
|
258
|
+
const screeStones = screeForms.map((form, i) => wornStone(1, 9 + 4 * i, form, { noise, foot }));
|
|
259
|
+
const farScreeStones = screeForms.map((form, i) => wornStone(0, 9 + 4 * i, form, { noise, foot }));
|
|
260
|
+
const outcrop = (seed, far = false) => beddedOutcrop(seed, far, { noise, screeStones, farScreeStones, Builder, shape });
|
|
261
|
+
return {
|
|
262
|
+
stones,
|
|
263
|
+
farStones,
|
|
264
|
+
screeStones,
|
|
265
|
+
farScreeStones,
|
|
266
|
+
outcrop,
|
|
267
|
+
outcropShapes: () => outcropSeeds.map(seed => outcrop(seed, false)),
|
|
268
|
+
farOutcropShapes: () => outcropSeeds.map(seed => outcrop(seed, true)),
|
|
269
|
+
};
|
|
270
|
+
}
|