genshin-engine 4.3.3 → 4.4.0

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.
@@ -1,490 +0,0 @@
1
- import { Color, MathUtils } from "three";
2
- // src/random/createSeededRandom.ts
3
- const createSeededRandom = (seed) => {
4
- let state = seed;
5
- return () => {
6
- state = state + 1831565813 >>> 0;
7
- let mixed = Math.imul(state ^ state >>> 15, 1 | state);
8
- mixed ^= mixed + Math.imul(mixed ^ mixed >>> 7, 61 | mixed);
9
- return ((mixed ^ mixed >>> 14) >>> 0) / 2 ** 32;
10
- };
11
- };
12
- // src/models/terrain/GroundLayer.ts
13
- let GroundLayer = /* @__PURE__ */ function(GroundLayer) {
14
- GroundLayer["Earth"] = "Earth";
15
- GroundLayer["Grass"] = "Grass";
16
- GroundLayer["Path"] = "Path";
17
- GroundLayer["Rock"] = "Rock";
18
- GroundLayer["Sand"] = "Sand";
19
- GroundLayer["Snow"] = "Snow";
20
- return GroundLayer;
21
- }({});
22
- const GroundLayers = Object.values(GroundLayer);
23
- // src/models/terrain/TerrainFeatureKind.ts
24
- let TerrainFeatureKind = /* @__PURE__ */ function(TerrainFeatureKind) {
25
- TerrainFeatureKind["Cliff"] = "cliff";
26
- TerrainFeatureKind["Plateau"] = "plateau";
27
- TerrainFeatureKind["Ridge"] = "ridge";
28
- return TerrainFeatureKind;
29
- }({});
30
- // src/noise/createSimplexNoise.ts
31
- const SKEW = (Math.sqrt(3) - 1) / 2;
32
- const UNSKEW = (3 - Math.sqrt(3)) / 6;
33
- const GRADIENTS_X = [
34
- 1,
35
- -1,
36
- 1,
37
- -1,
38
- 1,
39
- -1,
40
- 0,
41
- 0
42
- ];
43
- const GRADIENTS_Y = [
44
- 1,
45
- 1,
46
- -1,
47
- -1,
48
- 0,
49
- 0,
50
- 1,
51
- -1
52
- ];
53
- const NOISE_SCALE = 70;
54
- const getCornerContribution = (gradientIndex, offsetX, offsetY) => {
55
- const falloff = .5 - offsetX * offsetX - offsetY * offsetY;
56
- if (falloff < 0) return 0;
57
- const gradient = gradientIndex & 7;
58
- return falloff ** 4 * ((GRADIENTS_X[gradient] ?? 0) * offsetX + (GRADIENTS_Y[gradient] ?? 0) * offsetY);
59
- };
60
- const createSimplexNoise = (seed) => {
61
- const random = createSeededRandom(seed);
62
- const table = Uint8Array.from({ length: 256 }, (_value, index) => index);
63
- for (let index = table.length - 1; index > 0; index--) {
64
- const swapIndex = Math.floor(random() * (index + 1));
65
- [table[index], table[swapIndex]] = [table[swapIndex] ?? 0, table[index] ?? 0];
66
- }
67
- const permutation = Uint8Array.from({ length: 512 }, (_value, index) => table[index & 255] ?? 0);
68
- return (x, y) => {
69
- const skew = (x + y) * SKEW;
70
- const cellX = Math.floor(x + skew);
71
- const cellY = Math.floor(y + skew);
72
- const unskew = (cellX + cellY) * UNSKEW;
73
- const offsetX = x - cellX + unskew;
74
- const offsetY = y - cellY + unskew;
75
- const middleX = offsetX > offsetY ? 1 : 0;
76
- const middleY = 1 - middleX;
77
- const tableX = cellX & 255;
78
- const tableY = cellY & 255;
79
- return NOISE_SCALE * (getCornerContribution(permutation[tableX + (permutation[tableY] ?? 0)] ?? 0, offsetX, offsetY) + getCornerContribution(permutation[tableX + middleX + (permutation[tableY + middleY] ?? 0)] ?? 0, offsetX - middleX + UNSKEW, offsetY - middleY + UNSKEW) + getCornerContribution(permutation[tableX + 1 + (permutation[tableY + 1] ?? 0)] ?? 0, offsetX - 1 + 2 * UNSKEW, offsetY - 1 + 2 * UNSKEW));
80
- };
81
- };
82
- // src/terrain/constants.ts
83
- const TILE_INDEX_OFFSET = 2 ** 19;
84
- const TILE_INDEX_SPAN = 2 ** 20;
85
- const TERRAIN_LAYER = 1;
86
- const TERRAIN_RING_INITIAL_TILE_COUNT = 64;
87
- const TERRAIN_CELL_SIZE = 64;
88
- const GAUSSIAN_REACH_WIDTHS = 3;
89
- const TERRAIN_HEIGHT_PADDING = 2;
90
- // src/terrain/getTerrainTileLevel.ts
91
- const getTerrainTileLevel = (key) => Math.floor(key / TILE_INDEX_SPAN / TILE_INDEX_SPAN);
92
- // src/terrain/measureSegment.ts
93
- const measurement = /* @__PURE__ */ new Float64Array(2);
94
- const measureSegment = ({ endX, endZ, startX, startZ }, x, z) => {
95
- const directionX = endX - startX;
96
- const directionZ = endZ - startZ;
97
- const length = Math.hypot(directionX, directionZ);
98
- const offsetX = x - startX;
99
- const offsetZ = z - startZ;
100
- const along = (offsetX * directionX + offsetZ * directionZ) / length;
101
- measurement[0] = (directionX * offsetZ - directionZ * offsetX) / length;
102
- measurement[1] = Math.max(0, -along, along - length);
103
- return measurement;
104
- };
105
- // src/terrain/getCliffBlend.ts
106
- const getCliffBlend = (feature, x, z) => {
107
- const measurement = measureSegment(feature, x, z);
108
- const across = measurement[0] ?? 0;
109
- const beyond = measurement[1] ?? 0;
110
- const { falloff, width } = feature;
111
- return MathUtils.smoothstep(across, -falloff, falloff) * (1 - MathUtils.smoothstep(across, width, width + falloff)) * (1 - MathUtils.smoothstep(beyond, 0, falloff));
112
- };
113
- // src/terrain/getPlateauBlend.ts
114
- const getPlateauBlend = (feature, x, z) => {
115
- const { falloff, radius, x: centreX, z: centreZ } = feature;
116
- return 1 - MathUtils.smoothstep(Math.hypot(x - centreX, z - centreZ), radius, radius + falloff);
117
- };
118
- // src/terrain/getRidgeBlend.ts
119
- const getRidgeBlend = (feature, x, z) => {
120
- const measurement = measureSegment(feature, x, z);
121
- const across = measurement[0] ?? 0;
122
- const beyond = measurement[1] ?? 0;
123
- const { width } = feature;
124
- return Math.exp(-(across ** 2 + beyond ** 2) / (2 * width * width));
125
- };
126
- // src/terrain/TerrainFeatureKindBlendMap.ts
127
- const TerrainFeatureKindBlendMap = {
128
- ["cliff"]: getCliffBlend,
129
- ["plateau"]: getPlateauBlend,
130
- ["ridge"]: getRidgeBlend
131
- };
132
- // src/terrain/blendGridNodes.ts
133
- const blendGridNodes = (values, sizeX, sizeZ, column, row) => {
134
- const left = Math.floor(column);
135
- const near = Math.floor(row);
136
- const right = Math.min(left + 1, sizeX - 1);
137
- const far = Math.min(near + 1, sizeZ - 1);
138
- const across = column - left;
139
- const along = row - near;
140
- return ((values[near * sizeX + left] ?? 0) * (1 - across) + (values[near * sizeX + right] ?? 0) * across) * (1 - along) + ((values[far * sizeX + left] ?? 0) * (1 - across) + (values[far * sizeX + right] ?? 0) * across) * along;
141
- };
142
- // src/terrain/getTerrainTileColumn.ts
143
- const getTerrainTileColumn = (key) => key % TILE_INDEX_SPAN - TILE_INDEX_OFFSET;
144
- // src/terrain/getTerrainTileRow.ts
145
- const getTerrainTileRow = (key) => Math.floor(key / TILE_INDEX_SPAN) % TILE_INDEX_SPAN - TILE_INDEX_OFFSET;
146
- // src/terrain/computeTerrainTile.ts
147
- const writeNormal = (normals, offset, heights, paddedIndex, paddedSide, reach, step) => {
148
- const height = heights[paddedIndex] ?? 0;
149
- const normalX = (heights[paddedIndex - reach] ?? height) - (heights[paddedIndex + reach] ?? height);
150
- const normalY = 2 * reach * step;
151
- const normalZ = (heights[paddedIndex - reach * paddedSide] ?? height) - (heights[paddedIndex + reach * paddedSide] ?? height);
152
- const length = Math.hypot(normalX, normalY, normalZ);
153
- normals[offset] = normalX / length;
154
- normals[offset + 1] = normalY / length;
155
- normals[offset + 2] = normalZ / length;
156
- return normalY / length;
157
- };
158
- const computeTerrainTile = ({ cellsPerSide, finestTileSize, getHeight, key, writeColor }) => {
159
- const level = getTerrainTileLevel(key);
160
- const size = finestTileSize * 2 ** level;
161
- const step = size / cellsPerSide;
162
- const left = getTerrainTileColumn(key) * size;
163
- const back = getTerrainTileRow(key) * size;
164
- const side = cellsPerSide + 1;
165
- const paddedSide = side + 4;
166
- const heights = new Float32Array(paddedSide * paddedSide);
167
- for (let row = 0; row < paddedSide; row++) for (let column = 0; column < paddedSide; column++) heights[row * paddedSide + column] = getHeight(left + (column - 2) * step, back + (row - 2) * step);
168
- const vertexCount = side * side;
169
- const positions = new Float32Array(vertexCount * 3);
170
- const normals = new Float32Array(vertexCount * 3);
171
- const colors = new Float32Array(vertexCount * 3);
172
- const coarsePositions = new Float32Array(vertexCount * 4);
173
- const coarseNormals = new Float32Array(vertexCount * 3);
174
- const coarseColors = new Float32Array(vertexCount * 3);
175
- for (let row = 0; row < side; row++) for (let column = 0; column < side; column++) {
176
- const paddedIndex = (row + 2) * paddedSide + column + 2;
177
- const height = heights[paddedIndex] ?? 0;
178
- const index = row * side + column;
179
- const offset = index * 3;
180
- const x = column * step;
181
- const z = row * step;
182
- positions[offset] = x;
183
- positions[offset + 1] = height;
184
- positions[offset + 2] = z;
185
- writeColor(colors, offset, height, 1 - writeNormal(normals, offset, heights, paddedIndex, paddedSide, 1, step), left + x, back + z);
186
- const coarseColumn = column - column % 2;
187
- const coarseRow = row - row % 2;
188
- const coarseOffset = index * 4;
189
- coarsePositions[coarseOffset] = coarseColumn * step;
190
- coarsePositions[coarseOffset + 1] = heights[(coarseRow + 2) * paddedSide + coarseColumn + 2] ?? height;
191
- coarsePositions[coarseOffset + 2] = coarseRow * step;
192
- coarsePositions[coarseOffset + 3] = level;
193
- if (coarseColumn !== column || coarseRow !== row) {
194
- const evenOffset = (coarseRow * side + coarseColumn) * 3;
195
- for (let component = 0; component < 3; component++) {
196
- coarseNormals[offset + component] = coarseNormals[evenOffset + component] ?? 0;
197
- coarseColors[offset + component] = coarseColors[evenOffset + component] ?? 0;
198
- }
199
- continue;
200
- }
201
- writeColor(coarseColors, offset, height, 1 - writeNormal(coarseNormals, offset, heights, paddedIndex, paddedSide, 2, step), left + x, back + z);
202
- }
203
- return {
204
- coarseColors,
205
- coarseNormals,
206
- coarsePositions,
207
- colors,
208
- key,
209
- normals,
210
- positions
211
- };
212
- };
213
- // src/terrain/fileByCell.ts
214
- const NO_ITEMS = [];
215
- const toCellKey = (column, row) => `${column},${row}`;
216
- const fileByCell = (items, getBounds) => {
217
- const cellItemsMap = /* @__PURE__ */ new Map();
218
- for (const item of items) {
219
- const { maxX, maxZ, minX, minZ } = getBounds(item);
220
- for (let column = Math.floor(minX / 64); column <= Math.floor(maxX / 64); column++) for (let row = Math.floor(minZ / 64); row <= Math.floor(maxZ / 64); row++) {
221
- const key = toCellKey(column, row);
222
- const cellItems = cellItemsMap.get(key);
223
- if (cellItems) cellItems.push(item);
224
- else cellItemsMap.set(key, [item]);
225
- }
226
- }
227
- return (x, z) => cellItemsMap.get(toCellKey(Math.floor(x / 64), Math.floor(z / 64))) ?? NO_ITEMS;
228
- };
229
- // src/terrain/getGaussianHillBlend.ts
230
- const getGaussianHillBlend = ({ width, x: hillX, z: hillZ }, x, z) => {
231
- const reach = 3 * width;
232
- const acrossX = x - hillX;
233
- const acrossZ = z - hillZ;
234
- if (Math.abs(acrossX) > reach || Math.abs(acrossZ) > reach) return 0;
235
- return Math.exp(-(acrossX ** 2 + acrossZ ** 2) / (2 * width * width));
236
- };
237
- // src/terrain/createGaussianHillsHeight.ts
238
- const createGaussianHillsHeight = ({ base, hills }) => {
239
- const getHills = fileByCell(hills, ({ width, x, z }) => {
240
- const reach = 3 * width;
241
- return {
242
- maxX: x + reach,
243
- maxZ: z + reach,
244
- minX: x - reach,
245
- minZ: z - reach
246
- };
247
- });
248
- return (x, z) => {
249
- let total = base;
250
- for (const hill of getHills(x, z)) total += hill.height * getGaussianHillBlend(hill, x, z);
251
- return total;
252
- };
253
- };
254
- // src/terrain/getSegmentBounds.ts
255
- const getSegmentBounds = (startX, startZ, endX, endZ, reach) => ({
256
- maxX: Math.max(startX, endX) + reach,
257
- maxZ: Math.max(startZ, endZ) + reach,
258
- minX: Math.min(startX, endX) - reach,
259
- minZ: Math.min(startZ, endZ) - reach
260
- });
261
- // src/terrain/sampleGroundLayerField.ts
262
- const sampleGroundLayerField = ({ cellSize, layers, origin, size }, x, z, weights) => {
263
- const sizeX = size[0] ?? 1;
264
- const sizeZ = size[1] ?? 1;
265
- const column = Math.min(Math.max((x - (origin[0] ?? 0)) / cellSize, 0), sizeX - 1);
266
- const row = Math.min(Math.max((z - (origin[1] ?? 0)) / cellSize, 0), sizeZ - 1);
267
- let total = 0;
268
- for (const layer of GroundLayers) {
269
- const shares = layers[layer];
270
- const share = shares === void 0 ? 0 : blendGridNodes(shares, sizeX, sizeZ, column, row);
271
- weights[layer] = share;
272
- total += share;
273
- }
274
- if (total === 0) {
275
- weights["Grass"] = 1;
276
- return;
277
- }
278
- for (const layer of GroundLayers) weights[layer] /= total;
279
- };
280
- // src/terrain/createGroundLayerWeights.ts
281
- const getBandAmount = ({ end, start }, value) => end >= start ? MathUtils.smoothstep(value, start, end) : 1 - MathUtils.smoothstep(value, end, start);
282
- const layOver = (weights, layer, amount) => {
283
- if (amount === 0) return;
284
- for (const groundLayer of GroundLayers) weights[groundLayer] *= 1 - amount;
285
- weights[layer] += amount;
286
- };
287
- const createGroundLayerWeights = ({ earthSlope, layerField, pathFalloff, paths, rockSlope, sandHeight, snowHeight }) => {
288
- const weights = {
289
- ["Earth"]: 0,
290
- ["Grass"]: 0,
291
- ["Path"]: 0,
292
- ["Rock"]: 0,
293
- ["Sand"]: 0,
294
- ["Snow"]: 0
295
- };
296
- const getPaths = fileByCell(paths, ({ endX, endZ, startX, startZ, width }) => getSegmentBounds(startX, startZ, endX, endZ, width / 2 + pathFalloff));
297
- return (height, slope, x, z) => {
298
- if (layerField) sampleGroundLayerField(layerField, x, z, weights);
299
- else {
300
- for (const groundLayer of GroundLayers) weights[groundLayer] = 0;
301
- weights["Grass"] = 1;
302
- }
303
- if (earthSlope) layOver(weights, "Earth", getBandAmount(earthSlope, slope));
304
- if (sandHeight) layOver(weights, "Sand", getBandAmount(sandHeight, height));
305
- if (snowHeight) layOver(weights, "Snow", getBandAmount(snowHeight, height));
306
- let pathAmount = 0;
307
- for (const path of getPaths(x, z)) {
308
- const measurement = measureSegment(path, x, z);
309
- const halfWidth = path.width / 2;
310
- const distance = Math.hypot(measurement[0] ?? 0, measurement[1] ?? 0);
311
- pathAmount = Math.max(pathAmount, 1 - MathUtils.smoothstep(distance, halfWidth, halfWidth + pathFalloff));
312
- }
313
- layOver(weights, "Path", pathAmount);
314
- if (rockSlope) layOver(weights, "Rock", getBandAmount(rockSlope, slope));
315
- return weights;
316
- };
317
- };
318
- // src/terrain/createGroundPaintColor.ts
319
- const createGroundPaintColor = (groundPaint, seed) => {
320
- const { layerColors, patchScale } = groundPaint;
321
- const getWeights = createGroundLayerWeights(groundPaint);
322
- const noise = createSimplexNoise(seed);
323
- const linearLayerColors = GroundLayers.map((layer) => ({
324
- color: new Color(layerColors[layer].color),
325
- layer,
326
- patchColor: new Color(layerColors[layer].patchColor)
327
- }));
328
- const layerColor = new Color();
329
- return (colors, offset, height, slope, x, z) => {
330
- const weights = getWeights(height, slope, x, z);
331
- const patch = (noise(x / patchScale, z / patchScale) + 1) / 2;
332
- let red = 0;
333
- let green = 0;
334
- let blue = 0;
335
- for (const { color, layer, patchColor } of linearLayerColors) {
336
- const weight = weights[layer];
337
- if (weight === 0) continue;
338
- layerColor.lerpColors(color, patchColor, patch);
339
- red += layerColor.r * weight;
340
- green += layerColor.g * weight;
341
- blue += layerColor.b * weight;
342
- }
343
- colors[offset] = red;
344
- colors[offset + 1] = green;
345
- colors[offset + 2] = blue;
346
- };
347
- };
348
- // src/terrain/sampleTerrainResidualFade.ts
349
- const sampleTerrainResidualFade = ({ cellSize, clearings, origin, size, weights }, x, z) => {
350
- const sizeX = size[0] ?? 1;
351
- const sizeZ = size[1] ?? 1;
352
- const column = (x - (origin[0] ?? 0)) / cellSize;
353
- const row = (z - (origin[1] ?? 0)) / cellSize;
354
- if (column < 0 || row < 0 || column > sizeX - 1 || row > sizeZ - 1) return 0;
355
- let weight = blendGridNodes(weights, sizeX, sizeZ, column, row);
356
- for (const { falloff, radius, x: centreX, z: centreZ } of clearings) weight *= MathUtils.smoothstep(Math.hypot(x - centreX, z - centreZ), radius, radius + falloff);
357
- return weight;
358
- };
359
- // src/terrain/createResidualHeight.ts
360
- const createResidualHeight = ({ amplitude, fade, octaves, scale, seed }) => {
361
- const noise = createSimplexNoise(seed);
362
- return (x, z) => {
363
- const weight = fade ? sampleTerrainResidualFade(fade, x, z) : 1;
364
- if (weight === 0) return 0;
365
- let total = 0;
366
- let octaveAmplitude = amplitude;
367
- let frequency = 1 / scale;
368
- for (let octave = 0; octave < octaves; octave++) {
369
- total += octaveAmplitude * noise(x * frequency, z * frequency);
370
- octaveAmplitude /= 2;
371
- frequency *= 2;
372
- }
373
- return weight * total;
374
- };
375
- };
376
- // src/terrain/getTerrainFeatureBounds.ts
377
- const TerrainFeatureKindBoundsMap = {
378
- ["cliff"]: (feature) => {
379
- const { endX, endZ, falloff, startX, startZ, width } = feature;
380
- return getSegmentBounds(startX, startZ, endX, endZ, width + falloff);
381
- },
382
- ["plateau"]: (feature) => {
383
- const { falloff, radius, x, z } = feature;
384
- const reach = radius + falloff;
385
- return {
386
- maxX: x + reach,
387
- maxZ: z + reach,
388
- minX: x - reach,
389
- minZ: z - reach
390
- };
391
- },
392
- ["ridge"]: (feature) => {
393
- const { endX, endZ, startX, startZ, width } = feature;
394
- return getSegmentBounds(startX, startZ, endX, endZ, 3 * width);
395
- }
396
- };
397
- const getTerrainFeatureBounds = (feature) => TerrainFeatureKindBoundsMap[feature.kind](feature);
398
- // src/terrain/createTerrainFeaturesBlend.ts
399
- const createTerrainFeaturesBlend = (features) => {
400
- const getFeatures = fileByCell(features, getTerrainFeatureBounds);
401
- return (x, z) => {
402
- let blend = 0;
403
- for (const feature of getFeatures(x, z)) blend = Math.max(blend, TerrainFeatureKindBlendMap[feature.kind](feature, x, z));
404
- return blend;
405
- };
406
- };
407
- // src/terrain/createTerrainFeaturesHeight.ts
408
- const createTerrainFeaturesHeight = (features) => {
409
- const getFeatures = fileByCell(features, getTerrainFeatureBounds);
410
- return (x, z) => {
411
- let total = 0;
412
- for (const feature of getFeatures(x, z)) total += feature.height * TerrainFeatureKindBlendMap[feature.kind](feature, x, z);
413
- return total;
414
- };
415
- };
416
- // src/terrain/getTerrainShapeLevel.ts
417
- const getTerrainShapeLevel = ({ base, hills }, baseUnder) => {
418
- if (hills.length === 0) return void 0;
419
- let minX = Infinity;
420
- let maxX = -Infinity;
421
- let minZ = Infinity;
422
- let maxZ = -Infinity;
423
- let maxWidth = 0;
424
- for (const { width, x, z } of hills) {
425
- minX = Math.min(minX, x);
426
- maxX = Math.max(maxX, x);
427
- minZ = Math.min(minZ, z);
428
- maxZ = Math.max(maxZ, z);
429
- maxWidth = Math.max(maxWidth, width);
430
- }
431
- return {
432
- falloff: 3 * maxWidth,
433
- height: base - baseUnder,
434
- kind: "plateau",
435
- radius: Math.hypot(maxX - minX, maxZ - minZ) / 2,
436
- x: (minX + maxX) / 2,
437
- z: (minZ + maxZ) / 2
438
- };
439
- };
440
- // src/terrain/createTerrainShapeHeight.ts
441
- const createTerrainShapeHeight = (shape, ...overlays) => {
442
- const shapes = [shape, ...overlays];
443
- const features = shapes.flatMap((layer) => layer.features ?? []);
444
- const levels = overlays.flatMap((overlay) => getTerrainShapeLevel(overlay, shape.base) ?? []);
445
- const getHillsHeight = createGaussianHillsHeight({
446
- base: shape.base,
447
- hills: shapes.flatMap(({ hills }) => hills)
448
- });
449
- const getFeaturesHeight = createTerrainFeaturesHeight([...features, ...levels]);
450
- const residualHeights = shapes.flatMap(({ residual }) => residual ? [createResidualHeight(residual)] : []);
451
- if (residualHeights.length === 0) return (x, z) => getHillsHeight(x, z) + getFeaturesHeight(x, z);
452
- const getFeaturesBlend = createTerrainFeaturesBlend(features);
453
- return (x, z) => {
454
- const residualShare = 1 - getFeaturesBlend(x, z);
455
- let residualHeight = 0;
456
- if (residualShare > 0) for (const getResidualHeight of residualHeights) residualHeight += residualShare * getResidualHeight(x, z);
457
- return getHillsHeight(x, z) + getFeaturesHeight(x, z) + residualHeight;
458
- };
459
- };
460
- // src/vegetation/computeScatterPoints.ts
461
- const CELL_SIZE_PER_SPACING = 1 / Math.SQRT2;
462
- const CELL_REACH = Math.ceil(Math.SQRT2);
463
- const checkIsCrowded = (cells, cellsPerSide, points, spacing, column, row, x, z) => {
464
- for (let neighbourRow = Math.max(0, row - CELL_REACH); neighbourRow <= Math.min(cellsPerSide - 1, row + CELL_REACH); neighbourRow++) for (let neighbourColumn = Math.max(0, column - CELL_REACH); neighbourColumn <= Math.min(cellsPerSide - 1, column + CELL_REACH); neighbourColumn++) {
465
- const pointIndex = cells[neighbourRow * cellsPerSide + neighbourColumn] ?? -1;
466
- if (pointIndex === -1) continue;
467
- const distanceX = (points[pointIndex * 2] ?? 0) - x;
468
- const distanceZ = (points[pointIndex * 2 + 1] ?? 0) - z;
469
- if (distanceX * distanceX + distanceZ * distanceZ < spacing * spacing) return true;
470
- }
471
- return false;
472
- };
473
- const computeScatterPoints = ({ candidateCount, checkIsAccepted, seed, size, spacing }) => {
474
- const random = createSeededRandom(seed);
475
- const cellSize = spacing * CELL_SIZE_PER_SPACING;
476
- const cellsPerSide = Math.ceil(size / cellSize);
477
- const cells = new Int32Array(cellsPerSide * cellsPerSide).fill(-1);
478
- const points = [];
479
- for (let candidate = 0; candidate < candidateCount; candidate++) {
480
- const x = random() * size;
481
- const z = random() * size;
482
- const column = Math.floor(x / cellSize);
483
- const row = Math.floor(z / cellSize);
484
- if (!checkIsAccepted(x, z) || checkIsCrowded(cells, cellsPerSide, points, spacing, column, row, x, z)) continue;
485
- cells[row * cellsPerSide + column] = points.length / 2;
486
- points.push(x, z);
487
- }
488
- return Float32Array.from(points);
489
- };
490
- export { TERRAIN_RING_INITIAL_TILE_COUNT as A, getCliffBlend as C, TERRAIN_CELL_SIZE as D, GAUSSIAN_REACH_WIDTHS as E, GroundLayer as F, GroundLayers as I, createSeededRandom as L, TILE_INDEX_SPAN as M, createSimplexNoise as N, TERRAIN_HEIGHT_PADDING as O, TerrainFeatureKind as P, getPlateauBlend as S, getTerrainTileLevel as T, getTerrainTileRow as _, createTerrainFeaturesBlend as a, TerrainFeatureKindBlendMap as b, sampleTerrainResidualFade as c, sampleGroundLayerField as d, getSegmentBounds as f, computeTerrainTile as g, fileByCell as h, createTerrainFeaturesHeight as i, TILE_INDEX_OFFSET as j, TERRAIN_LAYER as k, createGroundPaintColor as l, getGaussianHillBlend as m, createTerrainShapeHeight as n, getTerrainFeatureBounds as o, createGaussianHillsHeight as p, getTerrainShapeLevel as r, createResidualHeight as s, computeScatterPoints as t, createGroundLayerWeights as u, getTerrainTileColumn as v, measureSegment as w, getRidgeBlend as x, blendGridNodes as y };
@@ -1,147 +0,0 @@
1
- declare enum TerrainFeatureKind {
2
- Cliff = "cliff",
3
- Plateau = "plateau",
4
- Ridge = "ridge"
5
- }
6
- interface CliffFeature {
7
- endX: number;
8
- endZ: number;
9
- falloff: number;
10
- height: number;
11
- kind: TerrainFeatureKind.Cliff;
12
- startX: number;
13
- startZ: number;
14
- width: number;
15
- }
16
- interface GaussianHill {
17
- height: number;
18
- width: number;
19
- x: number;
20
- z: number;
21
- }
22
- interface GaussianHills {
23
- base: number;
24
- hills: GaussianHill[];
25
- }
26
- interface GroundBand {
27
- end: number;
28
- start: number;
29
- }
30
- declare enum GroundLayer {
31
- Earth = "Earth",
32
- Grass = "Grass",
33
- Path = "Path",
34
- Rock = "Rock",
35
- Sand = "Sand",
36
- Snow = "Snow"
37
- }
38
- declare const GroundLayers: readonly GroundLayer[];
39
- interface GroundLayerColors {
40
- color: number;
41
- patchColor: number;
42
- }
43
- interface GroundLayerField {
44
- cellSize: number;
45
- layers: Partial<Record<GroundLayer, readonly number[]>>;
46
- origin: readonly number[];
47
- size: readonly number[];
48
- }
49
- interface GroundPathSegment {
50
- endX: number;
51
- endZ: number;
52
- startX: number;
53
- startZ: number;
54
- width: number;
55
- }
56
- interface GroundPaint {
57
- earthSlope?: GroundBand;
58
- layerColors: Record<GroundLayer, GroundLayerColors>;
59
- layerField?: GroundLayerField;
60
- patchScale: number;
61
- pathFalloff: number;
62
- paths: GroundPathSegment[];
63
- rockSlope?: GroundBand;
64
- sandHeight?: GroundBand;
65
- snowHeight?: GroundBand;
66
- }
67
- interface PlateauFeature {
68
- falloff: number;
69
- height: number;
70
- kind: TerrainFeatureKind.Plateau;
71
- radius: number;
72
- x: number;
73
- z: number;
74
- }
75
- interface RidgeFeature {
76
- endX: number;
77
- endZ: number;
78
- height: number;
79
- kind: TerrainFeatureKind.Ridge;
80
- startX: number;
81
- startZ: number;
82
- width: number;
83
- }
84
- type TerrainFeature = CliffFeature | PlateauFeature | RidgeFeature;
85
- interface TerrainOptions {
86
- cellsPerSide: number;
87
- finestRange: number;
88
- finestTileSize: number;
89
- levelCount: number;
90
- maxHeight: number;
91
- minHeight: number;
92
- }
93
- interface TerrainResidualClearing {
94
- falloff: number;
95
- radius: number;
96
- x: number;
97
- z: number;
98
- }
99
- interface TerrainResidualFade {
100
- cellSize: number;
101
- clearings: readonly TerrainResidualClearing[];
102
- origin: readonly number[];
103
- size: readonly number[];
104
- weights: readonly number[];
105
- }
106
- interface TerrainResidual {
107
- amplitude: number;
108
- fade?: TerrainResidualFade;
109
- octaves: number;
110
- scale: number;
111
- seed: number;
112
- }
113
- interface TerrainTile {
114
- coarseColors: Float32Array;
115
- coarseNormals: Float32Array;
116
- coarsePositions: Float32Array;
117
- colors: Float32Array;
118
- key: number;
119
- normals: Float32Array;
120
- positions: Float32Array;
121
- }
122
- interface TerrainShape extends GaussianHills {
123
- features?: TerrainFeature[];
124
- residual?: TerrainResidual;
125
- }
126
- interface TerrainTileOptions extends Pick<TerrainOptions, "cellsPerSide" | "finestTileSize"> {
127
- getHeight: (x: number, z: number) => number;
128
- key: number;
129
- writeColor: (colors: Float32Array, offset: number, height: number, slope: number, x: number, z: number) => void;
130
- }
131
- interface ScatterOptions {
132
- candidateCount: number;
133
- checkIsAccepted: (x: number, z: number) => boolean;
134
- seed: number;
135
- size: number;
136
- spacing: number;
137
- }
138
- declare const createSeededRandom: (seed: number) => (() => number);
139
- declare const computeTerrainTile: ({ cellsPerSide, finestTileSize, getHeight, key, writeColor }: TerrainTileOptions) => TerrainTile;
140
- declare const createGroundLayerWeights: ({ earthSlope, layerField, pathFalloff, paths, rockSlope, sandHeight, snowHeight }: Pick<GroundPaint, "earthSlope" | "layerField" | "pathFalloff" | "paths" | "rockSlope" | "sandHeight" | "snowHeight">) => ((height: number, slope: number, x: number, z: number) => Readonly<Record<GroundLayer, number>>);
141
- declare const createGroundPaintColor: (groundPaint: GroundPaint, seed: number) => TerrainTileOptions["writeColor"];
142
- declare const createTerrainShapeHeight: (shape: TerrainShape, ...overlays: TerrainShape[]) => ((x: number, z: number) => number);
143
- declare const getTerrainTileColumn: (key: number) => number;
144
- declare const getTerrainTileLevel: (key: number) => number;
145
- declare const getTerrainTileRow: (key: number) => number;
146
- declare const computeScatterPoints: ({ candidateCount, checkIsAccepted, seed, size, spacing }: ScatterOptions) => Float32Array;
147
- export { CliffFeature as A, GroundLayerField as C, GroundBand as D, GroundLayers as E, GaussianHills as O, GroundPathSegment as S, GroundLayer as T, TerrainOptions as _, createTerrainShapeHeight as a, PlateauFeature as b, computeTerrainTile as c, TerrainTileOptions as d, TerrainShape as f, TerrainResidualClearing as g, TerrainResidualFade as h, getTerrainTileColumn as i, TerrainFeatureKind as j, GaussianHill as k, createSeededRandom as l, TerrainResidual as m, getTerrainTileRow as n, createGroundPaintColor as o, TerrainTile as p, getTerrainTileLevel as r, createGroundLayerWeights as s, computeScatterPoints as t, ScatterOptions as u, TerrainFeature as v, GroundLayerColors as w, GroundPaint as x, RidgeFeature as y };
@@ -1,2 +0,0 @@
1
- import { E as GroundLayers, T as GroundLayer, a as createTerrainShapeHeight, c as computeTerrainTile, i as getTerrainTileColumn, l as createSeededRandom, n as getTerrainTileRow, o as createGroundPaintColor, r as getTerrainTileLevel, s as createGroundLayerWeights, t as computeScatterPoints } from "./terrainWorker-BjxpqdfH.js";
2
- export { GroundLayer, GroundLayers, computeScatterPoints, computeTerrainTile, createGroundLayerWeights, createGroundPaintColor, createSeededRandom, createTerrainShapeHeight, getTerrainTileColumn, getTerrainTileLevel, getTerrainTileRow };
@@ -1 +0,0 @@
1
- export { F as GroundLayer, I as GroundLayers, t as computeScatterPoints, g as computeTerrainTile, u as createGroundLayerWeights, l as createGroundPaintColor, L as createSeededRandom, n as createTerrainShapeHeight, v as getTerrainTileColumn, T as getTerrainTileLevel, _ as getTerrainTileRow } from "./terrainWorker-Bgj3rmZs.js";