@adatechnology/game-terrain 0.8.0 → 0.9.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.
- package/README.md +1 -0
- package/dist/index.d.ts +121 -2
- package/dist/index.global.js +375 -7
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +375 -7
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
var TERRAIN_MATERIALS = [
|
|
3
3
|
{
|
|
4
4
|
id: "turf",
|
|
5
|
+
rolling: 0.15,
|
|
6
|
+
rollingDamping: 1.5,
|
|
7
|
+
dig: { effort: 1.3 },
|
|
5
8
|
debris: "clods",
|
|
6
9
|
rimShare: 0.25,
|
|
7
10
|
reposeDegrees: 55,
|
|
@@ -17,6 +20,9 @@ var TERRAIN_MATERIALS = [
|
|
|
17
20
|
},
|
|
18
21
|
{
|
|
19
22
|
id: "soil",
|
|
23
|
+
rolling: 0.08,
|
|
24
|
+
rollingDamping: 0.6,
|
|
25
|
+
dig: { effort: 1 },
|
|
20
26
|
debris: "clods",
|
|
21
27
|
rimShare: 0.35,
|
|
22
28
|
reposeDegrees: 40,
|
|
@@ -32,6 +38,9 @@ var TERRAIN_MATERIALS = [
|
|
|
32
38
|
},
|
|
33
39
|
{
|
|
34
40
|
id: "sand",
|
|
41
|
+
rolling: 0.3,
|
|
42
|
+
rollingDamping: 2,
|
|
43
|
+
dig: { effort: 0.8 },
|
|
35
44
|
debris: "dust",
|
|
36
45
|
rimShare: 0.5,
|
|
37
46
|
reposeDegrees: 33,
|
|
@@ -47,6 +56,9 @@ var TERRAIN_MATERIALS = [
|
|
|
47
56
|
},
|
|
48
57
|
{
|
|
49
58
|
id: "gravel",
|
|
59
|
+
rolling: 0.08,
|
|
60
|
+
rollingDamping: 1,
|
|
61
|
+
dig: { effort: 1.6 },
|
|
50
62
|
debris: "chips",
|
|
51
63
|
rimShare: 0.15,
|
|
52
64
|
reposeDegrees: 38,
|
|
@@ -63,6 +75,8 @@ var TERRAIN_MATERIALS = [
|
|
|
63
75
|
},
|
|
64
76
|
{
|
|
65
77
|
id: "asphalt",
|
|
78
|
+
rolling: 0.015,
|
|
79
|
+
rollingDamping: 0.35,
|
|
66
80
|
debris: "chips",
|
|
67
81
|
color: [0.05, 0.05, 0.055],
|
|
68
82
|
pattern: "asphalt",
|
|
@@ -77,6 +91,8 @@ var TERRAIN_MATERIALS = [
|
|
|
77
91
|
},
|
|
78
92
|
{
|
|
79
93
|
id: "concrete",
|
|
94
|
+
rolling: 0.015,
|
|
95
|
+
rollingDamping: 0.3,
|
|
80
96
|
debris: "chips",
|
|
81
97
|
color: [0.33, 0.33, 0.31],
|
|
82
98
|
pattern: "concrete",
|
|
@@ -92,6 +108,7 @@ var TERRAIN_MATERIALS = [
|
|
|
92
108
|
},
|
|
93
109
|
{
|
|
94
110
|
id: "mortar",
|
|
111
|
+
rollingDamping: 0.3,
|
|
95
112
|
debris: "chips",
|
|
96
113
|
color: [0.42, 0.4, 0.36],
|
|
97
114
|
pattern: "plain",
|
|
@@ -105,6 +122,8 @@ var TERRAIN_MATERIALS = [
|
|
|
105
122
|
},
|
|
106
123
|
{
|
|
107
124
|
id: "ceramic",
|
|
125
|
+
rolling: 8e-3,
|
|
126
|
+
rollingDamping: 0.1,
|
|
108
127
|
debris: "shards",
|
|
109
128
|
color: [0.72, 0.7, 0.66],
|
|
110
129
|
pattern: "tile",
|
|
@@ -119,6 +138,8 @@ var TERRAIN_MATERIALS = [
|
|
|
119
138
|
},
|
|
120
139
|
{
|
|
121
140
|
id: "wood_hard",
|
|
141
|
+
rolling: 0.01,
|
|
142
|
+
rollingDamping: 0.12,
|
|
122
143
|
debris: "splinters",
|
|
123
144
|
color: [0.3, 0.16, 0.07],
|
|
124
145
|
pattern: "planks",
|
|
@@ -132,6 +153,8 @@ var TERRAIN_MATERIALS = [
|
|
|
132
153
|
},
|
|
133
154
|
{
|
|
134
155
|
id: "stone",
|
|
156
|
+
rolling: 0.015,
|
|
157
|
+
rollingDamping: 0.3,
|
|
135
158
|
debris: "chips",
|
|
136
159
|
color: [0.23, 0.22, 0.2],
|
|
137
160
|
pattern: "stone",
|
|
@@ -146,6 +169,10 @@ var TERRAIN_MATERIALS = [
|
|
|
146
169
|
},
|
|
147
170
|
{
|
|
148
171
|
id: "mud",
|
|
172
|
+
rolling: 0.3,
|
|
173
|
+
rollingDamping: 3,
|
|
174
|
+
// the shovel lifts it, and the hole fills in behind the blade
|
|
175
|
+
dig: { effort: 1.4, closes: true },
|
|
149
176
|
debris: "clods",
|
|
150
177
|
rimShare: 0.15,
|
|
151
178
|
reposeDegrees: 18,
|
|
@@ -164,6 +191,9 @@ var TERRAIN_MATERIALS = [
|
|
|
164
191
|
},
|
|
165
192
|
{
|
|
166
193
|
id: "clay",
|
|
194
|
+
rolling: 0.05,
|
|
195
|
+
rollingDamping: 0.4,
|
|
196
|
+
dig: { effort: 2.2 },
|
|
167
197
|
debris: "chips",
|
|
168
198
|
color: [0.47, 0.27, 0.14],
|
|
169
199
|
pattern: "clay",
|
|
@@ -176,8 +206,27 @@ var TERRAIN_MATERIALS = [
|
|
|
176
206
|
fire: { maxScorch: 0.35, scorchPerSecond: 0.05 },
|
|
177
207
|
cracks: 4
|
|
178
208
|
},
|
|
209
|
+
{
|
|
210
|
+
// laterite, a soil baked hard (piçarra): no shovel goes in; only a heavy blow or a charge sinks or cracks it
|
|
211
|
+
id: "laterite",
|
|
212
|
+
rolling: 0.05,
|
|
213
|
+
rollingDamping: 0.4,
|
|
214
|
+
debris: "chips",
|
|
215
|
+
rimShare: 0.2,
|
|
216
|
+
color: [0.36, 0.17, 0.08],
|
|
217
|
+
pattern: "soil",
|
|
218
|
+
hits: {
|
|
219
|
+
ballistic: { specificEnergy: 5e7, aspect: 0.2, thresholdJoules: 200 },
|
|
220
|
+
blunt: { specificEnergy: 8e7, aspect: 0.1, thresholdJoules: 600 },
|
|
221
|
+
slash: { specificEnergy: 2e8, aspect: 0.1, thresholdJoules: 400 },
|
|
222
|
+
explosive: { specificEnergy: 3e8, aspect: 0.18 }
|
|
223
|
+
}
|
|
224
|
+
},
|
|
179
225
|
{
|
|
180
226
|
id: "snow",
|
|
227
|
+
rolling: 0.1,
|
|
228
|
+
rollingDamping: 1.2,
|
|
229
|
+
dig: { effort: 0.6 },
|
|
181
230
|
debris: "dust",
|
|
182
231
|
rimShare: 0.4,
|
|
183
232
|
reposeDegrees: 38,
|
|
@@ -194,6 +243,8 @@ var TERRAIN_MATERIALS = [
|
|
|
194
243
|
},
|
|
195
244
|
{
|
|
196
245
|
id: "cobble",
|
|
246
|
+
rolling: 0.03,
|
|
247
|
+
rollingDamping: 0.6,
|
|
197
248
|
debris: "blocks",
|
|
198
249
|
color: [0.2, 0.19, 0.18],
|
|
199
250
|
pattern: "cobble",
|
|
@@ -208,6 +259,8 @@ var TERRAIN_MATERIALS = [
|
|
|
208
259
|
},
|
|
209
260
|
{
|
|
210
261
|
id: "paver",
|
|
262
|
+
rolling: 0.015,
|
|
263
|
+
rollingDamping: 0.3,
|
|
211
264
|
debris: "blocks",
|
|
212
265
|
color: [0.36, 0.33, 0.3],
|
|
213
266
|
pattern: "paver",
|
|
@@ -238,6 +291,10 @@ var TERRAIN_PROFILES = [
|
|
|
238
291
|
{ id: "snow", strata: [{ material: "snow", thickness: 0.3 }, { material: "soil", thickness: 1.5 }, { material: "stone", thickness: 0.5 }] },
|
|
239
292
|
{ id: "cobblestone", strata: [{ material: "cobble", thickness: 0.12 }, { material: "sand", thickness: 0.06 }, { material: "gravel", thickness: 0.2 }, { material: "soil", thickness: 1.2 }] },
|
|
240
293
|
// rock at the surface (an outcrop, a quarry floor): a blast only spalls it and a shot chips it
|
|
294
|
+
// a yard as it is dug: topsoil, the clay under it, rock deep down
|
|
295
|
+
{ id: "yard", strata: [{ material: "soil", thickness: 0.35 }, { material: "clay", thickness: 1.6 }, { material: "stone", thickness: 1 }] },
|
|
296
|
+
// ground baked hard (laterite over rock): no shovel goes in
|
|
297
|
+
{ id: "hardpan", strata: [{ material: "laterite", thickness: 0.8 }, { material: "stone", thickness: 1.5 }] },
|
|
241
298
|
{ id: "bedrock", surfacePattern: "rock", strata: [{ material: "stone", thickness: 3 }] },
|
|
242
299
|
{ id: "paver_floor", strata: [{ material: "paver", thickness: 0.08 }, { material: "sand", thickness: 0.05 }, { material: "gravel", thickness: 0.15 }, { material: "soil", thickness: 1.2 }] },
|
|
243
300
|
// a pond deep enough to stand chest-high in: a charge on its bed goes off under the water
|
|
@@ -473,6 +530,58 @@ function voidUnder(grid, spec) {
|
|
|
473
530
|
return { depth, mean: sum / count, fraction: open / count };
|
|
474
531
|
}
|
|
475
532
|
|
|
533
|
+
// src/height-patch.ts
|
|
534
|
+
var cellCoordinate = (v, origin, count, cellSize) => Math.max(0, Math.min(count - 1e-6, (v - origin) / cellSize));
|
|
535
|
+
var blendHeights = (near, far, t) => near * (1 - t) + far * t;
|
|
536
|
+
var patchColumns = new Int32Array(0);
|
|
537
|
+
var patchBlendX = new Float64Array(0);
|
|
538
|
+
var patchNear = new Float64Array(0);
|
|
539
|
+
var patchFar = new Float64Array(0);
|
|
540
|
+
function heightPatchGrid(patch, xs, zs, out) {
|
|
541
|
+
const width = xs.length;
|
|
542
|
+
const depth = zs.length;
|
|
543
|
+
if (out.length < width * depth) throw new RangeError(`heightPatchGrid: out holds ${out.length} heights, the grid has ${width * depth}`);
|
|
544
|
+
const { cellSize, originX, originZ, columns, rows, column0, row0, heights } = patch;
|
|
545
|
+
const stride = patch.width;
|
|
546
|
+
if (patchColumns.length < width) {
|
|
547
|
+
patchColumns = new Int32Array(width);
|
|
548
|
+
patchBlendX = new Float64Array(width);
|
|
549
|
+
patchNear = new Float64Array(width);
|
|
550
|
+
patchFar = new Float64Array(width);
|
|
551
|
+
}
|
|
552
|
+
for (let i = 0; i < width; i++) {
|
|
553
|
+
const fx = cellCoordinate(xs[i], originX, columns, cellSize);
|
|
554
|
+
const column = (fx | 0) - column0;
|
|
555
|
+
if (column < 0 || column + 1 >= stride) throw new RangeError(`heightPatchGrid: x ${xs[i]} is past the patch`);
|
|
556
|
+
patchColumns[i] = column;
|
|
557
|
+
patchBlendX[i] = fx - (fx | 0);
|
|
558
|
+
}
|
|
559
|
+
let blended = -1;
|
|
560
|
+
for (let j = 0; j < depth; j++) {
|
|
561
|
+
const fz = cellCoordinate(zs[j], originZ, rows, cellSize);
|
|
562
|
+
const row = (fz | 0) - row0;
|
|
563
|
+
if (row < 0 || row + 1 >= patch.depth) throw new RangeError(`heightPatchGrid: z ${zs[j]} is past the patch`);
|
|
564
|
+
const tz = fz - (fz | 0);
|
|
565
|
+
if (row !== blended) {
|
|
566
|
+
blended = row;
|
|
567
|
+
for (let i = 0; i < width; i++) {
|
|
568
|
+
const index = row * stride + patchColumns[i];
|
|
569
|
+
const tx = patchBlendX[i];
|
|
570
|
+
patchNear[i] = blendHeights(heights[index], heights[index + 1], tx);
|
|
571
|
+
patchFar[i] = blendHeights(heights[index + stride], heights[index + stride + 1], tx);
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
for (let i = 0; i < width; i++) out[j * width + i] = blendHeights(patchNear[i], patchFar[i], tz);
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
var samePatch = (a, b) => {
|
|
578
|
+
if (a.cellSize !== b.cellSize || a.originX !== b.originX || a.originZ !== b.originZ || a.columns !== b.columns || a.rows !== b.rows) return false;
|
|
579
|
+
if (a.column0 !== b.column0 || a.row0 !== b.row0 || a.width !== b.width || a.depth !== b.depth) return false;
|
|
580
|
+
const count = a.width * a.depth;
|
|
581
|
+
for (let k = 0; k < count; k++) if (a.heights[k] !== b.heights[k]) return false;
|
|
582
|
+
return true;
|
|
583
|
+
};
|
|
584
|
+
|
|
476
585
|
// src/marks.ts
|
|
477
586
|
var SAME_HOLE = 0.75;
|
|
478
587
|
function createMarkStore(budget) {
|
|
@@ -771,6 +880,28 @@ function createTerrain(options) {
|
|
|
771
880
|
dirty.add(chunk2);
|
|
772
881
|
}
|
|
773
882
|
}
|
|
883
|
+
for (const excavation of layout.excavations ?? []) excavate(excavation);
|
|
884
|
+
}
|
|
885
|
+
function excavate(excavation) {
|
|
886
|
+
const [ex0, ez0, ex1, ez1] = excavation.rect;
|
|
887
|
+
const column0 = clampIndex(Math.floor((ex0 - x0) / cellSize + 1e-6), columns);
|
|
888
|
+
const column1 = clampIndex(Math.ceil((ex1 - x0) / cellSize - 1e-6), columns);
|
|
889
|
+
const row0 = clampIndex(Math.floor((ez0 - z0) / cellSize + 1e-6), rows);
|
|
890
|
+
const row1 = clampIndex(Math.ceil((ez1 - z0) / cellSize - 1e-6), rows);
|
|
891
|
+
const alongX = (excavation.along ?? (ex1 - ex0 >= ez1 - ez0 ? "x" : "z")) === "x";
|
|
892
|
+
const from = alongX ? ex0 : ez0, length = Math.max(1e-6, alongX ? ex1 - ex0 : ez1 - ez0);
|
|
893
|
+
const far = excavation.toDepth ?? excavation.depth;
|
|
894
|
+
for (let row = row0; row <= row1; row++) {
|
|
895
|
+
for (let column = column0; column <= column1; column++) {
|
|
896
|
+
const index = row * stride + column;
|
|
897
|
+
const at = alongX ? x0 + column * cellSize : z0 + row * cellSize;
|
|
898
|
+
const t = Math.max(0, Math.min(1, (at - from) / length));
|
|
899
|
+
const depth = excavation.depth + (far - excavation.depth) * t;
|
|
900
|
+
if (depth <= dug[index]) continue;
|
|
901
|
+
dug[index] = depth;
|
|
902
|
+
touchVertex(column, row);
|
|
903
|
+
}
|
|
904
|
+
}
|
|
774
905
|
}
|
|
775
906
|
function layBeds() {
|
|
776
907
|
const steps = new Uint8Array(vertexCount);
|
|
@@ -805,17 +936,110 @@ function createTerrain(options) {
|
|
|
805
936
|
}
|
|
806
937
|
if (decalList.length !== before) decalsVersion++;
|
|
807
938
|
}
|
|
939
|
+
const cellCoordinate2 = (v, origin, count) => cellCoordinate(v, origin, count, cellSize);
|
|
940
|
+
const heightOfVertex = (index) => base[index] - dug[index] + loose[index];
|
|
941
|
+
const blendCell = (index, tx, tz) => blendHeights(blendHeights(heightOfVertex(index), heightOfVertex(index + 1), tx), blendHeights(heightOfVertex(index + stride), heightOfVertex(index + stride + 1), tx), tz);
|
|
808
942
|
function heightAt(x, z) {
|
|
809
943
|
if (!contains(x, z)) return options.baseHeight?.(x, z) ?? 0;
|
|
810
|
-
const fx =
|
|
811
|
-
const fz =
|
|
944
|
+
const fx = cellCoordinate2(x, x0, columns);
|
|
945
|
+
const fz = cellCoordinate2(z, z0, rows);
|
|
812
946
|
const column = fx | 0;
|
|
813
947
|
const row = fz | 0;
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
948
|
+
return blendCell(row * stride + column, fx - column, fz - row);
|
|
949
|
+
}
|
|
950
|
+
let gridColumns = new Int32Array(0);
|
|
951
|
+
let gridBlendX = new Float64Array(0);
|
|
952
|
+
let gridRows = new Int32Array(0);
|
|
953
|
+
let gridBlendZ = new Float64Array(0);
|
|
954
|
+
let gridNear = new Float64Array(0);
|
|
955
|
+
let gridFar = new Float64Array(0);
|
|
956
|
+
function heightGrid(xs, zs, out) {
|
|
957
|
+
const width = xs.length;
|
|
958
|
+
const depth = zs.length;
|
|
959
|
+
if (out.length < width * depth) throw new RangeError(`heightGrid: out holds ${out.length} heights, the grid has ${width * depth}`);
|
|
960
|
+
if (gridColumns.length < width) {
|
|
961
|
+
gridColumns = new Int32Array(width);
|
|
962
|
+
gridBlendX = new Float64Array(width);
|
|
963
|
+
}
|
|
964
|
+
if (gridRows.length < depth) {
|
|
965
|
+
gridRows = new Int32Array(depth);
|
|
966
|
+
gridBlendZ = new Float64Array(depth);
|
|
967
|
+
}
|
|
968
|
+
for (let i = 0; i < width; i++) {
|
|
969
|
+
const x = xs[i];
|
|
970
|
+
const fx = cellCoordinate2(x, x0, columns);
|
|
971
|
+
gridColumns[i] = x >= x0 && x <= x1 ? fx | 0 : -1;
|
|
972
|
+
gridBlendX[i] = fx - (fx | 0);
|
|
973
|
+
}
|
|
974
|
+
for (let j = 0; j < depth; j++) {
|
|
975
|
+
const z = zs[j];
|
|
976
|
+
const fz = cellCoordinate2(z, z0, rows);
|
|
977
|
+
gridRows[j] = z >= z0 && z <= z1 ? fz | 0 : -1;
|
|
978
|
+
gridBlendZ[j] = fz - (fz | 0);
|
|
979
|
+
}
|
|
980
|
+
if (gridNear.length < width) {
|
|
981
|
+
gridNear = new Float64Array(width);
|
|
982
|
+
gridFar = new Float64Array(width);
|
|
983
|
+
}
|
|
984
|
+
let blended = -2;
|
|
985
|
+
for (let j = 0; j < depth; j++) {
|
|
986
|
+
const row = gridRows[j];
|
|
987
|
+
const tz = gridBlendZ[j];
|
|
988
|
+
if (row < 0) {
|
|
989
|
+
for (let i = 0; i < width; i++) out[j * width + i] = options.baseHeight?.(xs[i], zs[j]) ?? 0;
|
|
990
|
+
continue;
|
|
991
|
+
}
|
|
992
|
+
if (row !== blended) {
|
|
993
|
+
blended = row;
|
|
994
|
+
for (let i = 0; i < width; i++) {
|
|
995
|
+
const column = gridColumns[i];
|
|
996
|
+
if (column < 0) continue;
|
|
997
|
+
const index = row * stride + column;
|
|
998
|
+
const tx = gridBlendX[i];
|
|
999
|
+
gridNear[i] = blendHeights(heightOfVertex(index), heightOfVertex(index + 1), tx);
|
|
1000
|
+
gridFar[i] = blendHeights(heightOfVertex(index + stride), heightOfVertex(index + stride + 1), tx);
|
|
1001
|
+
}
|
|
1002
|
+
}
|
|
1003
|
+
for (let i = 0; i < width; i++) {
|
|
1004
|
+
if (gridColumns[i] < 0) {
|
|
1005
|
+
out[j * width + i] = options.baseHeight?.(xs[i], zs[j]) ?? 0;
|
|
1006
|
+
continue;
|
|
1007
|
+
}
|
|
1008
|
+
out[j * width + i] = blendHeights(gridNear[i], gridFar[i], tz);
|
|
1009
|
+
}
|
|
1010
|
+
}
|
|
1011
|
+
}
|
|
1012
|
+
function heightPatch(minX, maxX, minZ, maxZ, into) {
|
|
1013
|
+
if (!(minX >= x0 && maxX <= x1 && minZ >= z0 && maxZ <= z1)) return null;
|
|
1014
|
+
const column0 = cellCoordinate2(minX, x0, columns) | 0;
|
|
1015
|
+
const row0 = cellCoordinate2(minZ, z0, rows) | 0;
|
|
1016
|
+
const width = (cellCoordinate2(maxX, x0, columns) | 0) + 2 - column0;
|
|
1017
|
+
const depth = (cellCoordinate2(maxZ, z0, rows) | 0) + 2 - row0;
|
|
1018
|
+
const heights = into && into.length >= width * depth ? into : new Float64Array(width * depth);
|
|
1019
|
+
for (let j = 0; j < depth; j++) {
|
|
1020
|
+
const from = (row0 + j) * stride + column0;
|
|
1021
|
+
for (let i = 0; i < width; i++) heights[j * width + i] = heightOfVertex(from + i);
|
|
1022
|
+
}
|
|
1023
|
+
return { cellSize, originX: x0, originZ: z0, columns, rows, column0, row0, width, depth, heights };
|
|
1024
|
+
}
|
|
1025
|
+
function heightRange(minX, maxX, minZ, maxZ) {
|
|
1026
|
+
if (!contains(minX, minZ) || !contains(maxX, maxZ)) return null;
|
|
1027
|
+
const cellOf = (v, origin, count) => Math.floor(Math.max(0, Math.min(count - 1e-6, (v - origin) / cellSize)));
|
|
1028
|
+
const column0 = cellOf(minX, x0, columns);
|
|
1029
|
+
const column1 = cellOf(maxX, x0, columns) + 1;
|
|
1030
|
+
const row0 = cellOf(minZ, z0, rows);
|
|
1031
|
+
const row1 = cellOf(maxZ, z0, rows) + 1;
|
|
1032
|
+
let low = Infinity;
|
|
1033
|
+
let high = -Infinity;
|
|
1034
|
+
for (let row = row0; row <= row1; row++) {
|
|
1035
|
+
for (let column = column0; column <= column1; column++) {
|
|
1036
|
+
const index = row * stride + column;
|
|
1037
|
+
const h = base[index] - dug[index] + loose[index];
|
|
1038
|
+
if (h < low) low = h;
|
|
1039
|
+
if (h > high) high = h;
|
|
1040
|
+
}
|
|
1041
|
+
}
|
|
1042
|
+
return { low, high };
|
|
819
1043
|
}
|
|
820
1044
|
const vertexOf = (x, z) => {
|
|
821
1045
|
const column = clampIndex(Math.round((x - x0) / cellSize), columns);
|
|
@@ -862,6 +1086,20 @@ function createTerrain(options) {
|
|
|
862
1086
|
const index = row * stride + column;
|
|
863
1087
|
return materials.get(stratumMaterialAtDepth(profileList[profileIndex[index]], dug[index]));
|
|
864
1088
|
}
|
|
1089
|
+
function surfaceMaterialAt(x, z) {
|
|
1090
|
+
const column = clampIndex(Math.round((x - x0) / cellSize), columns);
|
|
1091
|
+
const row = clampIndex(Math.round((z - z0) / cellSize), rows);
|
|
1092
|
+
const index = row * stride + column;
|
|
1093
|
+
const which = profileIndex[index];
|
|
1094
|
+
const depth = Math.min(maxDepthOf[which], dug[index] + marks.depthAt(x, z));
|
|
1095
|
+
return materials.get(stratumMaterialAtDepth(profileList[which], depth));
|
|
1096
|
+
}
|
|
1097
|
+
function rollingAt(x, z) {
|
|
1098
|
+
return surfaceMaterialAt(x, z).rolling;
|
|
1099
|
+
}
|
|
1100
|
+
function rollingDampingAt(x, z) {
|
|
1101
|
+
return surfaceMaterialAt(x, z).rollingDamping;
|
|
1102
|
+
}
|
|
865
1103
|
function columnAt(x, z) {
|
|
866
1104
|
const { index } = vertexOf(x, z);
|
|
867
1105
|
const which = profileIndex[index];
|
|
@@ -883,6 +1121,109 @@ function createTerrain(options) {
|
|
|
883
1121
|
loose[index] = loose[index] + amount - filled;
|
|
884
1122
|
}
|
|
885
1123
|
const isSoftExposed = (index) => materials.get(stratumAtDepth(profileList[profileIndex[index]], dug[index]).stratum.material).reposeDegrees !== void 0;
|
|
1124
|
+
function verticesUnder(x, z, size) {
|
|
1125
|
+
const nu = Math.max(1, Math.round(size[0] / cellSize)), nv = Math.max(1, Math.round(size[1] / cellSize));
|
|
1126
|
+
const column0 = clampIndex(Math.round((x - x0) / cellSize - (nu - 1) / 2), columns), column1 = clampIndex(column0 + nu - 1, columns);
|
|
1127
|
+
const row0 = clampIndex(Math.round((z - z0) / cellSize - (nv - 1) / 2), rows), row1 = clampIndex(row0 + nv - 1, rows);
|
|
1128
|
+
const out = [];
|
|
1129
|
+
for (let row = row0; row <= row1; row++) for (let column = column0; column <= column1; column++) out.push(row * stride + column);
|
|
1130
|
+
return out;
|
|
1131
|
+
}
|
|
1132
|
+
const touchIndex = (index) => touchVertex(index % stride, Math.floor(index / stride));
|
|
1133
|
+
const materialAtVertex = (index) => loose[index] > 1e-4 ? materials.get("soil") : materials.get(stratumAtDepth(profileList[profileIndex[index]], dug[index]).stratum.material);
|
|
1134
|
+
function digVertex(index, depth) {
|
|
1135
|
+
let left = depth;
|
|
1136
|
+
while (left > 1e-6) {
|
|
1137
|
+
if (loose[index] > 1e-6) {
|
|
1138
|
+
const take2 = Math.min(loose[index], left);
|
|
1139
|
+
loose[index] = loose[index] - take2;
|
|
1140
|
+
left -= take2;
|
|
1141
|
+
continue;
|
|
1142
|
+
}
|
|
1143
|
+
const profile = profileList[profileIndex[index]];
|
|
1144
|
+
const layer = stratumAtDepth(profile, dug[index]);
|
|
1145
|
+
if (!materials.get(layer.stratum.material)?.dig || dug[index] >= maxDepthOf[profileIndex[index]] - 1e-6) break;
|
|
1146
|
+
const take = Math.min(left, layer.top + layer.stratum.thickness - dug[index]);
|
|
1147
|
+
if (take <= 1e-6) break;
|
|
1148
|
+
dug[index] = dug[index] + take;
|
|
1149
|
+
left -= take;
|
|
1150
|
+
}
|
|
1151
|
+
return depth - left;
|
|
1152
|
+
}
|
|
1153
|
+
function heapAt(x, z, volume) {
|
|
1154
|
+
if (volume <= 0) return;
|
|
1155
|
+
const radius = Math.max(cellSize * 2, Math.cbrt(volume) * 1.6);
|
|
1156
|
+
const indices = verticesUnder(x, z, [2 * radius, 2 * radius]);
|
|
1157
|
+
const weight = (index) => {
|
|
1158
|
+
const px = x0 + index % stride * cellSize, pz = z0 + Math.floor(index / stride) * cellSize;
|
|
1159
|
+
const q = Math.hypot(px - x, pz - z) / radius;
|
|
1160
|
+
return q < 1 ? 1 - q * q : 0;
|
|
1161
|
+
};
|
|
1162
|
+
const total = indices.reduce((sum, i) => sum + weight(i), 0);
|
|
1163
|
+
if (total <= 0) return;
|
|
1164
|
+
const cellArea = cellSize * cellSize;
|
|
1165
|
+
for (const index of indices) {
|
|
1166
|
+
const w = weight(index);
|
|
1167
|
+
if (w <= 0) continue;
|
|
1168
|
+
loose[index] = loose[index] + volume * w / (total * cellArea);
|
|
1169
|
+
sliding.add(index);
|
|
1170
|
+
touchIndex(index);
|
|
1171
|
+
}
|
|
1172
|
+
emitDeform(x, z, radius);
|
|
1173
|
+
}
|
|
1174
|
+
function dig(spec) {
|
|
1175
|
+
const size = spec.size ?? [0.3, 0.3], depth = spec.depth ?? 0.2;
|
|
1176
|
+
const centre = vertexOf(spec.x, spec.z).index;
|
|
1177
|
+
if (profileList[profileIndex[centre]].water) return { volume: 0, material: "water", effort: 0, refused: "water" };
|
|
1178
|
+
const met = materialAtVertex(centre);
|
|
1179
|
+
if (!met.dig) return { volume: 0, material: met.id, effort: 0, refused: met.id };
|
|
1180
|
+
if (met.dig.closes) return { volume: 0, material: met.id, effort: met.dig.effort, closes: true };
|
|
1181
|
+
const cellArea = cellSize * cellSize;
|
|
1182
|
+
const tally = /* @__PURE__ */ new Map();
|
|
1183
|
+
let volume = 0;
|
|
1184
|
+
for (const index of verticesUnder(spec.x, spec.z, size)) {
|
|
1185
|
+
const before = dug[index];
|
|
1186
|
+
const went = digVertex(index, depth);
|
|
1187
|
+
if (went <= 0) continue;
|
|
1188
|
+
tallyLowered(tally, index, dug[index] - before);
|
|
1189
|
+
volume += went * cellArea;
|
|
1190
|
+
sliding.add(index);
|
|
1191
|
+
touchIndex(index);
|
|
1192
|
+
}
|
|
1193
|
+
marks.removeInside(spec.x, spec.z, Math.max(size[0], size[1]) / 2);
|
|
1194
|
+
emitDeform(spec.x, spec.z, Math.max(size[0], size[1]));
|
|
1195
|
+
emitGroundLoss(tally, "dig", 0);
|
|
1196
|
+
if (spec.dump) heapAt(spec.dump.x, spec.dump.z, volume);
|
|
1197
|
+
return { volume, material: met.id, effort: volume > 0 ? met.dig.effort : 0 };
|
|
1198
|
+
}
|
|
1199
|
+
function fill(spec) {
|
|
1200
|
+
const cellArea = cellSize * cellSize;
|
|
1201
|
+
let taken = 0;
|
|
1202
|
+
const source = verticesUnder(spec.from.x, spec.from.z, [2 * spec.from.radius, 2 * spec.from.radius]).filter((i) => loose[i] > 1e-6);
|
|
1203
|
+
for (const index of source) {
|
|
1204
|
+
if (taken >= spec.volume) break;
|
|
1205
|
+
const take = Math.min(loose[index], (spec.volume - taken) / cellArea);
|
|
1206
|
+
loose[index] = loose[index] - take;
|
|
1207
|
+
taken += take * cellArea;
|
|
1208
|
+
sliding.add(index);
|
|
1209
|
+
touchIndex(index);
|
|
1210
|
+
}
|
|
1211
|
+
if (taken <= 0) return 0;
|
|
1212
|
+
emitDeform(spec.from.x, spec.from.z, spec.from.radius);
|
|
1213
|
+
const target = verticesUnder(spec.x, spec.z, spec.size ?? [0.3, 0.3]).sort((a, b) => dug[b] - dug[a]);
|
|
1214
|
+
let left = taken;
|
|
1215
|
+
for (const index of target) {
|
|
1216
|
+
if (left <= 1e-9) break;
|
|
1217
|
+
const amount = Math.min(left / cellArea, Math.max(dug[index], left / cellArea / target.length));
|
|
1218
|
+
addToVertex(index, amount, true);
|
|
1219
|
+
left -= amount * cellArea;
|
|
1220
|
+
sliding.add(index);
|
|
1221
|
+
touchIndex(index);
|
|
1222
|
+
}
|
|
1223
|
+
if (left > 1e-9) heapAt(spec.x, spec.z, left);
|
|
1224
|
+
emitDeform(spec.x, spec.z, Math.max(...spec.size ?? [0.3, 0.3]));
|
|
1225
|
+
return taken;
|
|
1226
|
+
}
|
|
886
1227
|
function stampBowl(x, z, radius, depth, rimVolume, lossSource = "crater") {
|
|
887
1228
|
const reach = radius * RIM_REACH;
|
|
888
1229
|
const column0 = clampIndex(Math.floor((x - reach - x0) / cellSize), columns);
|
|
@@ -1389,6 +1730,14 @@ function createTerrain(options) {
|
|
|
1389
1730
|
slideTally.clear();
|
|
1390
1731
|
}
|
|
1391
1732
|
}
|
|
1733
|
+
const settledArea = { minX: Infinity, minZ: Infinity, maxX: -Infinity, maxZ: -Infinity };
|
|
1734
|
+
function emitSettledArea() {
|
|
1735
|
+
if (settledArea.minX > settledArea.maxX) return;
|
|
1736
|
+
const { minX, minZ, maxX, maxZ } = settledArea;
|
|
1737
|
+
settledArea.minX = settledArea.minZ = Infinity;
|
|
1738
|
+
settledArea.maxX = settledArea.maxZ = -Infinity;
|
|
1739
|
+
emitDeform((minX + maxX) / 2, (minZ + maxZ) / 2, Math.hypot(maxX - minX, maxZ - minZ) / 2 + cellSize * 2);
|
|
1740
|
+
}
|
|
1392
1741
|
function settle(piece) {
|
|
1393
1742
|
const material = materials.get(piece.material);
|
|
1394
1743
|
if (!material || material.reposeDegrees === void 0 || material.scatters) return false;
|
|
@@ -1398,6 +1747,11 @@ function createTerrain(options) {
|
|
|
1398
1747
|
addToVertex(index, 4 / 3 * Math.PI * piece.radius ** 3 / (cellSize * cellSize), false);
|
|
1399
1748
|
sliding.add(index);
|
|
1400
1749
|
touchVertex(column, row);
|
|
1750
|
+
const px = x0 + column * cellSize, pz = z0 + row * cellSize;
|
|
1751
|
+
settledArea.minX = Math.min(settledArea.minX, px);
|
|
1752
|
+
settledArea.maxX = Math.max(settledArea.maxX, px);
|
|
1753
|
+
settledArea.minZ = Math.min(settledArea.minZ, pz);
|
|
1754
|
+
settledArea.maxZ = Math.max(settledArea.maxZ, pz);
|
|
1401
1755
|
return true;
|
|
1402
1756
|
}
|
|
1403
1757
|
function applyHit(hit) {
|
|
@@ -1478,6 +1832,7 @@ function createTerrain(options) {
|
|
|
1478
1832
|
burning.clear();
|
|
1479
1833
|
random = createRandom(seed);
|
|
1480
1834
|
applyLayout(currentLayout);
|
|
1835
|
+
emitDeform((x0 + x1) / 2, (z0 + z1) / 2, Math.hypot(x1 - x0, z1 - z0) / 2);
|
|
1481
1836
|
}
|
|
1482
1837
|
applyLayout(currentLayout);
|
|
1483
1838
|
return {
|
|
@@ -1507,6 +1862,9 @@ function createTerrain(options) {
|
|
|
1507
1862
|
reset();
|
|
1508
1863
|
},
|
|
1509
1864
|
heightAt,
|
|
1865
|
+
heightGrid,
|
|
1866
|
+
heightPatch,
|
|
1867
|
+
heightRange,
|
|
1510
1868
|
footAt,
|
|
1511
1869
|
walkFactorAt,
|
|
1512
1870
|
waterAt,
|
|
@@ -1519,10 +1877,14 @@ function createTerrain(options) {
|
|
|
1519
1877
|
vertexHeight,
|
|
1520
1878
|
vertexMaterial,
|
|
1521
1879
|
columnAt,
|
|
1880
|
+
rollingAt,
|
|
1881
|
+
rollingDampingAt,
|
|
1522
1882
|
contains,
|
|
1523
1883
|
raycast,
|
|
1524
1884
|
strike,
|
|
1525
1885
|
burn,
|
|
1886
|
+
dig,
|
|
1887
|
+
fill,
|
|
1526
1888
|
applyHit,
|
|
1527
1889
|
bear: bearAll,
|
|
1528
1890
|
voidUnder: (x, z, radius) => voidUnder(grid, { x, z, radius }),
|
|
@@ -1532,6 +1894,7 @@ function createTerrain(options) {
|
|
|
1532
1894
|
},
|
|
1533
1895
|
update(dt) {
|
|
1534
1896
|
debrisStore.update(dt, { heightAt, gravity, settle });
|
|
1897
|
+
emitSettledArea();
|
|
1535
1898
|
updateSlides();
|
|
1536
1899
|
updateFire(dt);
|
|
1537
1900
|
for (let i = decalList.length - 1; i >= 0; i--) {
|
|
@@ -1587,6 +1950,7 @@ function createTerrain(options) {
|
|
|
1587
1950
|
decalList.push(...(snapshot.decals ?? []).map((decal) => ({ ...decal })));
|
|
1588
1951
|
decalSerial = decalList.reduce((highest, decal) => Math.max(highest, decal.id), decalSerial);
|
|
1589
1952
|
for (let chunkIndex = 0; chunkIndex < touched.length; chunkIndex++) markChunk(chunkIndex);
|
|
1953
|
+
emitDeform((x0 + x1) / 2, (z0 + z1) / 2, Math.hypot(x1 - x0, z1 - z0) / 2);
|
|
1590
1954
|
}
|
|
1591
1955
|
};
|
|
1592
1956
|
}
|
|
@@ -1751,10 +2115,14 @@ export {
|
|
|
1751
2115
|
TERRAIN_PATTERNS,
|
|
1752
2116
|
TERRAIN_PROFILES,
|
|
1753
2117
|
VOID_MIN_DEPTH,
|
|
2118
|
+
blendHeights,
|
|
2119
|
+
cellCoordinate,
|
|
1754
2120
|
crackLines,
|
|
1755
2121
|
createFootprints,
|
|
1756
2122
|
createTerrain,
|
|
1757
2123
|
createTerrainImpl,
|
|
2124
|
+
heightPatchGrid,
|
|
2125
|
+
samePatch,
|
|
1758
2126
|
waterLift
|
|
1759
2127
|
};
|
|
1760
2128
|
//# sourceMappingURL=index.js.map
|