@adatechnology/game-terrain-three 0.3.1 → 0.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.
- package/dist/{chunk-JAVYWW3G.js → chunk-B5EA72GU.js} +23 -69
- package/dist/chunk-B5EA72GU.js.map +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.global.js +344 -74
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +326 -8
- package/dist/index.js.map +1 -1
- package/dist/testing.d.ts +6 -4
- package/dist/testing.js +5 -3
- package/package.json +3 -3
- package/dist/chunk-JAVYWW3G.js.map +0 -1
package/dist/index.global.js
CHANGED
|
@@ -26,10 +26,12 @@ var GameTerrainThree = (() => {
|
|
|
26
26
|
createSurfaceMaterial: () => createSurfaceMaterial,
|
|
27
27
|
createTerrainRenderer: () => createTerrainRenderer,
|
|
28
28
|
createTerrainTestModule: () => createTerrainTestModule,
|
|
29
|
+
terrainLotsGround: () => terrainLotsGround,
|
|
29
30
|
terrainProfileName: () => terrainProfileName
|
|
30
31
|
});
|
|
31
32
|
|
|
32
33
|
// ../game-contracts/dist/index.js
|
|
34
|
+
var DEFAULT_BLAST_IMPULSE = { bodyArea: 0.7, lift: 0.15, minSpeed: 0.3, tntPerJoule: 0.24 / 2e5 };
|
|
33
35
|
var DEFAULT_COST_ALLOCATION_BYTES = 1024 * 1024;
|
|
34
36
|
var DEFERRED_QUEUE_ID = {
|
|
35
37
|
DESTRUCTION_EVENTS: "destruction.events",
|
|
@@ -129,7 +131,7 @@ var GameTerrainThree = (() => {
|
|
|
129
131
|
}
|
|
130
132
|
return segments;
|
|
131
133
|
}
|
|
132
|
-
var TERRAIN_PATTERNS = ["plain", "grass", "soil", "sand", "asphalt", "concrete", "tile", "planks", "stone"];
|
|
134
|
+
var TERRAIN_PATTERNS = ["plain", "grass", "soil", "sand", "asphalt", "concrete", "tile", "planks", "stone", "mud", "gravel", "clay", "snow", "cobble", "paver"];
|
|
133
135
|
|
|
134
136
|
// src/surface-material.ts
|
|
135
137
|
var patternIndex = (pattern) => Math.max(0, TERRAIN_PATTERNS.indexOf(pattern ?? "plain"));
|
|
@@ -170,9 +172,51 @@ vec3 terrainSurface(vec3 base, vec2 xz, float kind) {
|
|
|
170
172
|
float grain = tsNoise(vec2(along * 3.0, xz.y * 70.0)) * 0.6 + tsNoise(vec2(along * 11.0, xz.y * 180.0)) * 0.4;
|
|
171
173
|
return base * (0.72 + 0.56 * tsHash(vec2(row, floor(along / 2.4)))) * (0.75 + 0.5 * grain) * (1.0 - 0.75 * seam);
|
|
172
174
|
}
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
175
|
+
if (k < 8.5) {
|
|
176
|
+
vec2 cell = floor(xz / 0.22);
|
|
177
|
+
float seams = max(tsLine(xz.x, 0.22, 0.012), tsLine(xz.y, 0.22, 0.012));
|
|
178
|
+
return base * (0.7 + 0.6 * tsHash(cell)) * (0.85 + 0.3 * tsFbm(xz * 16.0)) * (1.0 - 0.55 * seams);
|
|
179
|
+
}
|
|
180
|
+
if (k < 9.5) {
|
|
181
|
+
float wet = smoothstep(0.42, 0.62, tsFbm(xz * 2.6));
|
|
182
|
+
return base * (0.65 + 0.7 * tsFbm(xz * 11.0)) * mix(1.25, 0.55, wet);
|
|
183
|
+
}
|
|
184
|
+
if (k < 10.5) {
|
|
185
|
+
vec2 grid = xz / 0.045;
|
|
186
|
+
vec2 cell = floor(grid);
|
|
187
|
+
vec2 inside = fract(grid) - 0.5 + (vec2(tsHash(cell), tsHash(cell + 9.0)) - 0.5) * 0.5;
|
|
188
|
+
float stone = 1.0 - smoothstep(0.22, 0.5, length(inside));
|
|
189
|
+
return base * (0.45 + 1.15 * tsHash(cell + 4.0)) * (0.35 + 0.85 * stone);
|
|
190
|
+
}
|
|
191
|
+
if (k < 11.5) {
|
|
192
|
+
vec2 p = xz / 0.45 + (vec2(tsNoise(xz * 3.0), tsNoise(xz * 3.0 + 5.0)) - 0.5) * 0.7;
|
|
193
|
+
vec2 cell = floor(p);
|
|
194
|
+
float nearest = 8.0;
|
|
195
|
+
float second = 8.0;
|
|
196
|
+
for (int j = -1; j <= 1; j++) {
|
|
197
|
+
for (int i = -1; i <= 1; i++) {
|
|
198
|
+
vec2 other = cell + vec2(float(i), float(j));
|
|
199
|
+
vec2 at = other + vec2(tsHash(other), tsHash(other + 3.0));
|
|
200
|
+
float d = length(at - p);
|
|
201
|
+
if (d < nearest) { second = nearest; nearest = d; } else if (d < second) second = d;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
float crack = 1.0 - smoothstep(0.0, 0.06, second - nearest);
|
|
205
|
+
return base * (0.82 + 0.3 * tsFbm(xz * 9.0)) * (1.0 - 0.78 * crack);
|
|
206
|
+
}
|
|
207
|
+
if (k < 12.5) return min(base * (0.97 + 0.08 * tsFbm(xz * 1.8)) + 0.05 * tsNoise(xz * 140.0), vec3(1.0));
|
|
208
|
+
if (k < 13.5) {
|
|
209
|
+
float row = floor(xz.y / 0.2);
|
|
210
|
+
float along = xz.x - mod(abs(row), 2.0) * 0.1;
|
|
211
|
+
vec2 cell = vec2(floor(along / 0.3), row);
|
|
212
|
+
float seam = max(tsLine(xz.y, 0.2, 0.014), tsLine(along, 0.3, 0.014));
|
|
213
|
+
return base * (0.72 + 0.6 * tsHash(cell)) * (0.82 + 0.36 * tsFbm(xz * 22.0)) * (1.0 - 0.8 * seam);
|
|
214
|
+
}
|
|
215
|
+
float row = floor(xz.y / 0.2);
|
|
216
|
+
float along = xz.x - mod(abs(row), 2.0) * 0.1;
|
|
217
|
+
vec2 cell = vec2(floor(along / 0.2), row);
|
|
218
|
+
float seam = max(tsLine(xz.y, 0.2, 0.008), tsLine(along, 0.2, 0.008));
|
|
219
|
+
return base * (0.86 + 0.26 * tsHash(cell)) * (0.92 + 0.16 * tsNoise(xz * 70.0)) * (1.0 - 0.7 * seam);
|
|
176
220
|
}
|
|
177
221
|
`
|
|
178
222
|
);
|
|
@@ -372,12 +416,164 @@ ${SURFACE_GLSL}`).replace("#include <color_fragment>", "#include <color_fragment
|
|
|
372
416
|
return geometry;
|
|
373
417
|
}
|
|
374
418
|
|
|
419
|
+
// src/decal-layers.ts
|
|
420
|
+
var TEXTURE_SIZE = 128;
|
|
421
|
+
var DECAL_LIFT = 8e-3;
|
|
422
|
+
var RIPPLE_SECONDS = 1.6;
|
|
423
|
+
var CRACK_ARMS = 7;
|
|
424
|
+
var DARK_GROUND_PRINT_TONE = 0.1;
|
|
425
|
+
var KIND_TONE = { crack: 0.16, print: 0.55, rut: 0.5, splat: 1, ripple: 3 };
|
|
426
|
+
var KIND_ASPECT = { crack: 1, print: 0.55, rut: 0.5, splat: 1, ripple: 1 };
|
|
427
|
+
var hash = (value) => {
|
|
428
|
+
const raw = Math.sin(value * 91.17) * 43758.5453;
|
|
429
|
+
return raw - Math.floor(raw);
|
|
430
|
+
};
|
|
431
|
+
var ellipse = (u, v, cu, cv, ru, rv) => Math.hypot((u - cu) / ru, (v - cv) / rv);
|
|
432
|
+
function segmentDistance(px, py, ax, ay, bx, by) {
|
|
433
|
+
const dx = bx - ax;
|
|
434
|
+
const dy = by - ay;
|
|
435
|
+
const t = Math.max(0, Math.min(1, ((px - ax) * dx + (py - ay) * dy) / (dx * dx + dy * dy)));
|
|
436
|
+
return Math.hypot(px - ax - dx * t, py - ay - dy * t);
|
|
437
|
+
}
|
|
438
|
+
function crackSegments() {
|
|
439
|
+
const segments = [];
|
|
440
|
+
for (let arm = 0; arm < CRACK_ARMS; arm++) {
|
|
441
|
+
let angle = arm / CRACK_ARMS * 6.283 + hash(arm) * 0.5;
|
|
442
|
+
let [x, y] = [0, 0];
|
|
443
|
+
for (let step = 0; step < 5; step++) {
|
|
444
|
+
const length = 0.075 + hash(arm * 7 + step) * 0.05;
|
|
445
|
+
const nextX = x + Math.cos(angle) * length;
|
|
446
|
+
const nextY = y + Math.sin(angle) * length;
|
|
447
|
+
segments.push([x, y, nextX, nextY]);
|
|
448
|
+
if (step > 0 && hash(arm * 13 + step) > 0.55) {
|
|
449
|
+
const branch = angle + (hash(arm + step * 3) > 0.5 ? 0.7 : -0.7);
|
|
450
|
+
segments.push([nextX, nextY, nextX + Math.cos(branch) * length * 0.8, nextY + Math.sin(branch) * length * 0.8]);
|
|
451
|
+
}
|
|
452
|
+
x = nextX;
|
|
453
|
+
y = nextY;
|
|
454
|
+
angle += (hash(arm * 3 + step * 11) - 0.5) * 0.9;
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
return segments;
|
|
458
|
+
}
|
|
459
|
+
var SHAPES = {
|
|
460
|
+
crack() {
|
|
461
|
+
const segments = crackSegments();
|
|
462
|
+
return (u, v) => {
|
|
463
|
+
let nearest = Infinity;
|
|
464
|
+
for (const [ax, ay, bx, by] of segments) nearest = Math.min(nearest, segmentDistance(u, v, ax, ay, bx, by));
|
|
465
|
+
return 1 - Math.min(1, Math.max(0, (nearest - 4e-3) / 8e-3));
|
|
466
|
+
};
|
|
467
|
+
},
|
|
468
|
+
print: () => (u, v) => {
|
|
469
|
+
const sole = ellipse(u, v, 0, 0.17, 0.42, 0.28);
|
|
470
|
+
const heel = ellipse(u, v, 0, -0.27, 0.32, 0.18);
|
|
471
|
+
const inside = Math.min(sole, heel);
|
|
472
|
+
return inside > 1 ? 0 : 0.85 * (Math.sin(v * 70) > -0.3 ? 1 : 0.55);
|
|
473
|
+
},
|
|
474
|
+
rut: () => (u, v) => Math.abs(u) > 0.46 || Math.abs(v) > 0.5 ? 0 : Math.sin(v * 44 + Math.abs(u) * 18) > -0.2 ? 0.8 : 0.45,
|
|
475
|
+
splat() {
|
|
476
|
+
return (u, v) => {
|
|
477
|
+
const angle = Math.atan2(v, u);
|
|
478
|
+
const edge = 0.3 + 0.08 * Math.sin(angle * 5) + 0.05 * Math.sin(angle * 13 + 1) + 0.04 * Math.sin(angle * 23 + 2);
|
|
479
|
+
const body = 1 - Math.max(0, Math.min(1, (Math.hypot(u, v) - edge) / 0.03));
|
|
480
|
+
return Math.max(body, ellipse(u, v, 0.38, 0.12, 0.05, 0.04) < 1 || ellipse(u, v, -0.22, -0.36, 0.06, 0.05) < 1 ? 1 : 0);
|
|
481
|
+
};
|
|
482
|
+
},
|
|
483
|
+
ripple: () => (u, v) => {
|
|
484
|
+
const r = Math.hypot(u, v);
|
|
485
|
+
return r > 0.5 ? 0 : Math.max(0, Math.sin(r * 42)) * (1 - r * 2) ** 0.5;
|
|
486
|
+
}
|
|
487
|
+
};
|
|
488
|
+
function createAlphaTexture(THREE, alphaAt) {
|
|
489
|
+
const size = TEXTURE_SIZE;
|
|
490
|
+
const data = new Uint8Array(size * size * 4);
|
|
491
|
+
for (let y = 0; y < size; y++) {
|
|
492
|
+
for (let x = 0; x < size; x++) {
|
|
493
|
+
const at = (y * size + x) * 4;
|
|
494
|
+
data[at] = data[at + 1] = data[at + 2] = 255;
|
|
495
|
+
data[at + 3] = Math.round(Math.max(0, Math.min(1, alphaAt((x + 0.5) / size - 0.5, (y + 0.5) / size - 0.5))) * 255);
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
const texture = new THREE.DataTexture(data, size, size, THREE.RGBAFormat);
|
|
499
|
+
texture.magFilter = THREE.LinearFilter;
|
|
500
|
+
texture.minFilter = THREE.LinearFilter;
|
|
501
|
+
texture.needsUpdate = true;
|
|
502
|
+
return texture;
|
|
503
|
+
}
|
|
504
|
+
var KINDS = Object.keys(SHAPES);
|
|
505
|
+
function createDecalLayers(THREE, terrain) {
|
|
506
|
+
const group = new THREE.Group();
|
|
507
|
+
group.name = "terrain-decals";
|
|
508
|
+
const geometry = new THREE.PlaneGeometry(1, 1);
|
|
509
|
+
geometry.rotateX(-Math.PI / 2);
|
|
510
|
+
const layers = KINDS.map((kind) => {
|
|
511
|
+
const texture = createAlphaTexture(THREE, SHAPES[kind]());
|
|
512
|
+
const material = new THREE.MeshStandardMaterial({ map: texture, transparent: true, depthWrite: false, roughness: kind === "ripple" ? 0.2 : 1, polygonOffset: true, polygonOffsetFactor: -3, polygonOffsetUnits: -3 });
|
|
513
|
+
const mesh = new THREE.InstancedMesh(geometry, material, terrain.budget.maxDecals);
|
|
514
|
+
mesh.name = `terrain-decal-${kind}`;
|
|
515
|
+
mesh.count = 0;
|
|
516
|
+
mesh.frustumCulled = false;
|
|
517
|
+
mesh.receiveShadow = true;
|
|
518
|
+
mesh.renderOrder = 2;
|
|
519
|
+
group.add(mesh);
|
|
520
|
+
return { kind, mesh, material, texture };
|
|
521
|
+
});
|
|
522
|
+
const matrix = new THREE.Matrix4();
|
|
523
|
+
const rotation = new THREE.Matrix4();
|
|
524
|
+
const scale = new THREE.Matrix4();
|
|
525
|
+
const colour = new THREE.Color();
|
|
526
|
+
let seen = -1;
|
|
527
|
+
const place = (decal) => {
|
|
528
|
+
const water = terrain.waterAt(decal.x, decal.z);
|
|
529
|
+
const grow = decal.kind === "ripple" ? 0.5 + decal.age / RIPPLE_SECONDS * 1.5 : 1;
|
|
530
|
+
const size = decal.radius * 2 * grow;
|
|
531
|
+
rotation.makeRotationY(decal.angle);
|
|
532
|
+
scale.makeScale(size * KIND_ASPECT[decal.kind], 1, size);
|
|
533
|
+
matrix.multiplyMatrices(rotation, scale);
|
|
534
|
+
matrix.setPosition(decal.x, (decal.kind === "ripple" ? water?.level ?? terrain.heightAt(decal.x, decal.z) : terrain.heightAt(decal.x, decal.z)) + DECAL_LIFT, decal.z);
|
|
535
|
+
return true;
|
|
536
|
+
};
|
|
537
|
+
return {
|
|
538
|
+
group,
|
|
539
|
+
sync() {
|
|
540
|
+
const decals = terrain.decals();
|
|
541
|
+
const rippling = decals.some((decal) => decal.kind === "ripple");
|
|
542
|
+
if (seen === terrain.decalsVersion && !rippling) return;
|
|
543
|
+
seen = terrain.decalsVersion;
|
|
544
|
+
for (const layer of layers) {
|
|
545
|
+
let count = 0;
|
|
546
|
+
for (const decal of decals) {
|
|
547
|
+
if (decal.kind !== layer.kind || !place(decal)) continue;
|
|
548
|
+
layer.mesh.setMatrixAt(count, matrix);
|
|
549
|
+
const [r, g, b] = terrain.material(decal.material).color;
|
|
550
|
+
const fade = decal.kind === "ripple" ? Math.max(0, 1 - decal.age / RIPPLE_SECONDS) : 1;
|
|
551
|
+
const tone = (decal.kind === "print" || decal.kind === "rut") && r < 0.5 ? DARK_GROUND_PRINT_TONE : KIND_TONE[decal.kind];
|
|
552
|
+
layer.mesh.setColorAt(count, colour.setRGB(Math.min(1, r * tone + (decal.kind === "ripple" ? 0.5 : 0)) * fade, Math.min(1, g * tone + (decal.kind === "ripple" ? 0.55 : 0)) * fade, Math.min(1, b * tone + (decal.kind === "ripple" ? 0.6 : 0)) * fade));
|
|
553
|
+
count++;
|
|
554
|
+
}
|
|
555
|
+
layer.mesh.count = count;
|
|
556
|
+
layer.mesh.instanceMatrix.needsUpdate = true;
|
|
557
|
+
if (layer.mesh.instanceColor) layer.mesh.instanceColor.needsUpdate = true;
|
|
558
|
+
}
|
|
559
|
+
},
|
|
560
|
+
dispose() {
|
|
561
|
+
geometry.dispose();
|
|
562
|
+
for (const layer of layers) {
|
|
563
|
+
layer.material.dispose();
|
|
564
|
+
layer.texture.dispose();
|
|
565
|
+
}
|
|
566
|
+
group.removeFromParent();
|
|
567
|
+
}
|
|
568
|
+
};
|
|
569
|
+
}
|
|
570
|
+
|
|
375
571
|
// src/layers.ts
|
|
376
572
|
var MARK_LIFT = 6e-3;
|
|
377
573
|
var MARK_REACH = 1.5;
|
|
378
574
|
var MARK_TEXTURE_SIZE = 64;
|
|
379
575
|
var MARK_DARKEN = 0.85;
|
|
380
|
-
var PIECE_SHAPE = { clods: [1, 0.85, 1], chips: [1, 0.6, 0.8], shards: [1.3, 0.2, 1], splinters: [0.3, 0.25, 2.4], dust: [1, 0.8, 1] };
|
|
576
|
+
var PIECE_SHAPE = { clods: [1, 0.85, 1], chips: [1, 0.6, 0.8], shards: [1.3, 0.2, 1], splinters: [0.3, 0.25, 2.4], dust: [1, 0.8, 1], blocks: [1, 0.42, 0.65] };
|
|
381
577
|
function createMarkTexture(THREE) {
|
|
382
578
|
const size = MARK_TEXTURE_SIZE;
|
|
383
579
|
const data = new Uint8Array(size * size * 4);
|
|
@@ -587,6 +783,121 @@ ${SURFACE_GLSL}`).replace("#include <color_fragment>", "#include <color_fragment
|
|
|
587
783
|
};
|
|
588
784
|
}
|
|
589
785
|
|
|
786
|
+
// src/zone-layer.ts
|
|
787
|
+
var LABEL_LIFT = 0.025;
|
|
788
|
+
var LABEL_HEIGHT = 0.42;
|
|
789
|
+
var LABEL_MAX_WIDTH = 3;
|
|
790
|
+
var WATER_COLOUR = 2906728;
|
|
791
|
+
var WATER_OPACITY = 0.62;
|
|
792
|
+
var WATER_ROUGHNESS = 0.08;
|
|
793
|
+
var WAVE_SIZE = 64;
|
|
794
|
+
var WAVE_TILES_PER_METRE = 0.6;
|
|
795
|
+
var WAVE_SPEED = 0.012;
|
|
796
|
+
function buildSign(THREE, text) {
|
|
797
|
+
if (typeof document === "undefined") return null;
|
|
798
|
+
const canvas = document.createElement("canvas");
|
|
799
|
+
canvas.width = 512;
|
|
800
|
+
canvas.height = 72;
|
|
801
|
+
const context = canvas.getContext("2d");
|
|
802
|
+
if (!context) return null;
|
|
803
|
+
context.fillStyle = "rgba(0,0,0,0.65)";
|
|
804
|
+
context.fillRect(0, 0, 512, 72);
|
|
805
|
+
context.fillStyle = "#fff";
|
|
806
|
+
context.font = "bold 46px sans-serif";
|
|
807
|
+
context.textAlign = "center";
|
|
808
|
+
context.textBaseline = "middle";
|
|
809
|
+
context.fillText(text, 256, 38);
|
|
810
|
+
const mesh = new THREE.Mesh(new THREE.PlaneGeometry(LABEL_MAX_WIDTH, LABEL_HEIGHT), new THREE.MeshBasicMaterial({ map: new THREE.CanvasTexture(canvas), transparent: true, depthWrite: false }));
|
|
811
|
+
mesh.rotation.x = -Math.PI / 2;
|
|
812
|
+
return mesh;
|
|
813
|
+
}
|
|
814
|
+
function createWaveTexture(THREE) {
|
|
815
|
+
const data = new Uint8Array(WAVE_SIZE * WAVE_SIZE * 4);
|
|
816
|
+
const tau = Math.PI * 2 / WAVE_SIZE;
|
|
817
|
+
for (let y = 0; y < WAVE_SIZE; y++) {
|
|
818
|
+
for (let x = 0; x < WAVE_SIZE; x++) {
|
|
819
|
+
const dx = Math.cos(x * tau * 2 + y * tau) * 0.5 + Math.cos(x * tau * 5 - y * tau * 2) * 0.3;
|
|
820
|
+
const dy = Math.cos(y * tau * 3 + x * tau) * 0.5 + Math.cos(y * tau * 4 - x * tau * 3) * 0.3;
|
|
821
|
+
const at = (y * WAVE_SIZE + x) * 4;
|
|
822
|
+
data[at] = Math.round((dx * 0.25 + 0.5) * 255);
|
|
823
|
+
data[at + 1] = Math.round((dy * 0.25 + 0.5) * 255);
|
|
824
|
+
data[at + 2] = 255;
|
|
825
|
+
data[at + 3] = 255;
|
|
826
|
+
}
|
|
827
|
+
}
|
|
828
|
+
const texture = new THREE.DataTexture(data, WAVE_SIZE, WAVE_SIZE, THREE.RGBAFormat);
|
|
829
|
+
texture.wrapS = texture.wrapT = THREE.RepeatWrapping;
|
|
830
|
+
texture.magFilter = THREE.LinearFilter;
|
|
831
|
+
texture.minFilter = THREE.LinearFilter;
|
|
832
|
+
texture.needsUpdate = true;
|
|
833
|
+
return texture;
|
|
834
|
+
}
|
|
835
|
+
function createZoneLayer(THREE, terrain) {
|
|
836
|
+
const group = markKitOrigin(new THREE.Group(), { owner: "game-terrain-three", kind: "ground" });
|
|
837
|
+
group.name = "terrain-zones";
|
|
838
|
+
const waves = createWaveTexture(THREE);
|
|
839
|
+
const water = new THREE.MeshStandardMaterial({ color: WATER_COLOUR, transparent: true, opacity: WATER_OPACITY, roughness: WATER_ROUGHNESS, metalness: 0.1, normalMap: waves, depthWrite: false });
|
|
840
|
+
let drawnFor = null;
|
|
841
|
+
const throwAway = () => {
|
|
842
|
+
for (const child of [...group.children]) {
|
|
843
|
+
group.remove(child);
|
|
844
|
+
const mesh = child;
|
|
845
|
+
mesh.geometry.dispose();
|
|
846
|
+
if (mesh.material !== water) {
|
|
847
|
+
const material = mesh.material;
|
|
848
|
+
material.map?.dispose();
|
|
849
|
+
material.dispose();
|
|
850
|
+
}
|
|
851
|
+
}
|
|
852
|
+
};
|
|
853
|
+
const isWater = (surface) => terrain.profileList.some((profile) => profile.id === surface && profile.water);
|
|
854
|
+
const draw = (layout) => {
|
|
855
|
+
throwAway();
|
|
856
|
+
const [x0, z0, x1, z1] = terrain.bounds;
|
|
857
|
+
const rects = isWater(layout.surface) ? [[x0, z0, x1, z1]] : [];
|
|
858
|
+
for (const zone of layout.zones ?? []) {
|
|
859
|
+
if (isWater(zone.surface)) rects.push(zone.rect);
|
|
860
|
+
if (!zone.label) continue;
|
|
861
|
+
const sign = buildSign(THREE, zone.label);
|
|
862
|
+
if (!sign) continue;
|
|
863
|
+
const [ax, , bx, bz] = zone.rect;
|
|
864
|
+
sign.scale.x = Math.min(1, (bx - ax - 0.1) / LABEL_MAX_WIDTH);
|
|
865
|
+
sign.position.set((ax + bx) / 2, LABEL_LIFT, bz - LABEL_HEIGHT / 2 - 0.03);
|
|
866
|
+
sign.renderOrder = 3;
|
|
867
|
+
group.add(sign);
|
|
868
|
+
}
|
|
869
|
+
for (const [ax, az, bx, bz] of rects) {
|
|
870
|
+
const plane = new THREE.PlaneGeometry(bx - ax, bz - az);
|
|
871
|
+
plane.rotateX(-Math.PI / 2);
|
|
872
|
+
const uv = plane.getAttribute("uv");
|
|
873
|
+
for (let i = 0; i < uv.count; i++) uv.setXY(i, uv.getX(i) * (bx - ax) * WAVE_TILES_PER_METRE, uv.getY(i) * (bz - az) * WAVE_TILES_PER_METRE);
|
|
874
|
+
const mesh = new THREE.Mesh(plane, water);
|
|
875
|
+
mesh.name = "terrain-water";
|
|
876
|
+
mesh.position.set((ax + bx) / 2, terrain.waterAt((ax + bx) / 2, (az + bz) / 2)?.level ?? 0, (az + bz) / 2);
|
|
877
|
+
mesh.renderOrder = 1;
|
|
878
|
+
group.add(mesh);
|
|
879
|
+
}
|
|
880
|
+
};
|
|
881
|
+
return {
|
|
882
|
+
group,
|
|
883
|
+
sync() {
|
|
884
|
+
const layout = terrain.layout();
|
|
885
|
+
if (layout !== drawnFor) {
|
|
886
|
+
drawnFor = layout;
|
|
887
|
+
draw(layout);
|
|
888
|
+
}
|
|
889
|
+
const shift = Date.now() % 1e6 * 1e-3 * WAVE_SPEED;
|
|
890
|
+
waves.offset.set(shift, shift * 0.7);
|
|
891
|
+
},
|
|
892
|
+
dispose() {
|
|
893
|
+
throwAway();
|
|
894
|
+
water.dispose();
|
|
895
|
+
waves.dispose();
|
|
896
|
+
group.removeFromParent();
|
|
897
|
+
}
|
|
898
|
+
};
|
|
899
|
+
}
|
|
900
|
+
|
|
590
901
|
// src/rebar.ts
|
|
591
902
|
var BAR_RADIUS = 6e-3;
|
|
592
903
|
var EXPOSED_MARGIN = 2e-3;
|
|
@@ -705,7 +1016,9 @@ ${SURFACE_GLSL}`).replace("#include <color_fragment>", "#include <color_fragment
|
|
|
705
1016
|
const marks = createMarkLayer(THREE, terrain, options.markDistance ?? DEFAULT_MARK_DISTANCE);
|
|
706
1017
|
const debris = createDebrisLayer(THREE, terrain);
|
|
707
1018
|
const cracks = createCrackLayer(THREE, terrain);
|
|
708
|
-
|
|
1019
|
+
const decals = createDecalLayers(THREE, terrain);
|
|
1020
|
+
const zones = createZoneLayer(THREE, terrain);
|
|
1021
|
+
group.add(marks.mesh, cracks.mesh, debris.mesh, decals.group, zones.group);
|
|
709
1022
|
let pristineStale = true;
|
|
710
1023
|
let pristineBuilt = false;
|
|
711
1024
|
let pristineCount = 0;
|
|
@@ -815,6 +1128,8 @@ ${SURFACE_GLSL}`).replace("#include <color_fragment>", "#include <color_fragment
|
|
|
815
1128
|
marks.sync(camera);
|
|
816
1129
|
cracks.sync();
|
|
817
1130
|
debris.sync();
|
|
1131
|
+
decals.sync();
|
|
1132
|
+
zones.sync();
|
|
818
1133
|
},
|
|
819
1134
|
stats: () => ({ chunkMeshes: drawn.size, pristineChunks: pristineCount, marksDrawn: marks.mesh.count, debrisDrawn: debris.mesh.count, crackQuads: cracks.mesh.geometry.drawRange.count / 6 }),
|
|
820
1135
|
dispose() {
|
|
@@ -826,6 +1141,8 @@ ${SURFACE_GLSL}`).replace("#include <color_fragment>", "#include <color_fragment
|
|
|
826
1141
|
marks.dispose();
|
|
827
1142
|
cracks.dispose();
|
|
828
1143
|
debris.dispose();
|
|
1144
|
+
decals.dispose();
|
|
1145
|
+
zones.dispose();
|
|
829
1146
|
group.removeFromParent();
|
|
830
1147
|
}
|
|
831
1148
|
};
|
|
@@ -844,35 +1161,36 @@ ${SURFACE_GLSL}`).replace("#include <color_fragment>", "#include <color_fragment
|
|
|
844
1161
|
name: "Terrain",
|
|
845
1162
|
group: "Terrain",
|
|
846
1163
|
weight: "Concrete block (60 kg)",
|
|
847
|
-
surfaces: { dirt: "Dirt", lawn: "Lawn", sand: "Sand", road: "Asphalt", concrete_slab: "Concrete slab", suspended_slab: "Slab over a void", wood_floor: "Wood floor", tile_floor: "Tile", stone_paving: "Stone paving" }
|
|
1164
|
+
surfaces: { dirt: "Dirt", lawn: "Lawn", sand: "Sand", road: "Asphalt", concrete_slab: "Concrete slab", suspended_slab: "Slab over a void", wood_floor: "Wood floor", tile_floor: "Tile", stone_paving: "Stone paving", mud: "Mud", gravel_bed: "Gravel", dry_clay: "Dry clay", snow: "Snow", cobblestone: "Cobblestones", paver_floor: "Concrete pavers", shallow_water: "Shallow water" }
|
|
848
1165
|
},
|
|
849
1166
|
"pt-BR": {
|
|
850
1167
|
name: "Terreno",
|
|
851
1168
|
group: "Terreno",
|
|
852
1169
|
weight: "Bloco de concreto (60 kg)",
|
|
853
|
-
surfaces: { dirt: "Terra", lawn: "Grama", sand: "Areia", road: "Asfalto", concrete_slab: "Laje de concreto", suspended_slab: "Laje sobre v\xE3o", wood_floor: "Assoalho", tile_floor: "Cer\xE2mica", stone_paving: "Pedra" }
|
|
1170
|
+
surfaces: { dirt: "Terra", lawn: "Grama", sand: "Areia", road: "Asfalto", concrete_slab: "Laje de concreto", suspended_slab: "Laje sobre v\xE3o", wood_floor: "Assoalho", tile_floor: "Cer\xE2mica", stone_paving: "Pedra", mud: "Lama", gravel_bed: "Cascalho", dry_clay: "Barro seco", snow: "Neve", cobblestone: "Paralelep\xEDpedo", paver_floor: "Bloquete", shallow_water: "\xC1gua rasa" }
|
|
854
1171
|
}
|
|
855
1172
|
};
|
|
856
1173
|
var locale = (id) => LOCALES[id] ?? LOCALES.en;
|
|
857
1174
|
|
|
858
1175
|
// src/test-area/test-module.ts
|
|
859
|
-
var TERRAIN_STRIPS = ["
|
|
860
|
-
var
|
|
861
|
-
var
|
|
862
|
-
var
|
|
863
|
-
var
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
zones: TERRAIN_STRIPS.map((surface, index) => ({ rect: stripRect(index), surface }))
|
|
1176
|
+
var TERRAIN_STRIPS = ["lawn", "dirt", "sand", "mud", "dry_clay", "gravel_bed", "snow", "shallow_water", "road", "cobblestone", "paver_floor", "stone_paving", "concrete_slab", "suspended_slab", "tile_floor", "wood_floor"];
|
|
1177
|
+
var LOT_WIDTH = 3.4;
|
|
1178
|
+
var LOT_DEPTH = 3.8;
|
|
1179
|
+
var LOTS_PER_ROW = 8;
|
|
1180
|
+
var LOTS_Z1 = -1.4;
|
|
1181
|
+
var lotRect = (index) => {
|
|
1182
|
+
const row = Math.floor(index / LOTS_PER_ROW);
|
|
1183
|
+
const x0 = (index % LOTS_PER_ROW - LOTS_PER_ROW / 2) * LOT_WIDTH;
|
|
1184
|
+
const z1 = LOTS_Z1 - (1 - row) * LOT_DEPTH;
|
|
1185
|
+
return [x0, z1 - LOT_DEPTH, x0 + LOT_WIDTH, z1];
|
|
870
1186
|
};
|
|
1187
|
+
function terrainLotsGround(locale2 = "en") {
|
|
1188
|
+
const text = locale(locale2);
|
|
1189
|
+
return { surface: "concrete_slab", zones: TERRAIN_STRIPS.map((surface, index) => ({ rect: lotRect(index), surface, label: text.surfaces[surface] })) };
|
|
1190
|
+
}
|
|
1191
|
+
var TERRAIN_AREA_GROUND = terrainLotsGround();
|
|
871
1192
|
var WEIGHT_SIDE = 0.32;
|
|
872
1193
|
var WEIGHT_HEIGHT = 4;
|
|
873
|
-
var LABEL_Y = 0.02;
|
|
874
|
-
var LABEL_WIDTH = 2.6;
|
|
875
|
-
var LABEL_HEIGHT = 0.5;
|
|
876
1194
|
function weightSpec() {
|
|
877
1195
|
return { name: "Weight", parts: [{ id: "block", material: "concrete", shape: { kind: "box", size: [WEIGHT_SIDE, WEIGHT_SIDE, WEIGHT_SIDE] }, position: [0, WEIGHT_SIDE / 2, 0] }], joints: [] };
|
|
878
1196
|
}
|
|
@@ -885,71 +1203,23 @@ ${SURFACE_GLSL}`).replace("#include <color_fragment>", "#include <color_fragment
|
|
|
885
1203
|
root.add(mesh);
|
|
886
1204
|
return root;
|
|
887
1205
|
}
|
|
888
|
-
function buildLabel(THREE, text, x) {
|
|
889
|
-
if (typeof document === "undefined") return null;
|
|
890
|
-
const canvas = document.createElement("canvas");
|
|
891
|
-
canvas.width = 512;
|
|
892
|
-
canvas.height = 96;
|
|
893
|
-
const context = canvas.getContext("2d");
|
|
894
|
-
if (!context) return null;
|
|
895
|
-
context.fillStyle = "rgba(0,0,0,0.55)";
|
|
896
|
-
context.fillRect(0, 0, 512, 96);
|
|
897
|
-
context.fillStyle = "#fff";
|
|
898
|
-
context.font = "bold 54px sans-serif";
|
|
899
|
-
context.textAlign = "center";
|
|
900
|
-
context.textBaseline = "middle";
|
|
901
|
-
context.fillText(text, 256, 50);
|
|
902
|
-
const mesh = new THREE.Mesh(new THREE.PlaneGeometry(LABEL_WIDTH, LABEL_HEIGHT), new THREE.MeshBasicMaterial({ map: new THREE.CanvasTexture(canvas), transparent: true }));
|
|
903
|
-
markKitOrigin(mesh, { owner: "game-terrain-three", kind: "room" });
|
|
904
|
-
mesh.rotation.set(-Math.PI / 2, 0, Math.PI);
|
|
905
|
-
mesh.position.set(x, LABEL_Y, STRIP_Z0 - LABEL_HEIGHT);
|
|
906
|
-
return mesh;
|
|
907
|
-
}
|
|
908
1206
|
function createTerrainTestModule(options = {}) {
|
|
909
|
-
let labels = [];
|
|
910
1207
|
const text = locale(options.locale ?? "en");
|
|
911
1208
|
return {
|
|
912
1209
|
id: "terrain",
|
|
913
1210
|
name: text.name,
|
|
914
1211
|
group: text.group,
|
|
915
|
-
ground:
|
|
1212
|
+
ground: terrainLotsGround(options.locale ?? "en"),
|
|
916
1213
|
items() {
|
|
917
1214
|
return [{ id: "terrain_weight", name: text.weight, build: (THREE) => buildWeight(THREE), spec: weightSpec, movable: true }];
|
|
918
1215
|
},
|
|
919
1216
|
area() {
|
|
920
|
-
for (const label of labels) label.visible = true;
|
|
921
1217
|
return {
|
|
922
1218
|
placements: TERRAIN_STRIPS.map((_, index) => {
|
|
923
|
-
const [x0] =
|
|
924
|
-
return { item: "terrain_weight", position: [x0 +
|
|
1219
|
+
const [x0, z0] = lotRect(index);
|
|
1220
|
+
return { item: "terrain_weight", position: [x0 + LOT_WIDTH / 2, WEIGHT_HEIGHT, z0 + 1.2] };
|
|
925
1221
|
}),
|
|
926
|
-
view: { eye: [0, 1.7, 1.5], target: [0, 0,
|
|
927
|
-
};
|
|
928
|
-
},
|
|
929
|
-
attach(host) {
|
|
930
|
-
const THREE = host.THREE;
|
|
931
|
-
const scene = host.scene;
|
|
932
|
-
labels = TERRAIN_STRIPS.flatMap((surface, index) => {
|
|
933
|
-
const [x0] = stripRect(index);
|
|
934
|
-
const label = buildLabel(THREE, text.surfaces[surface], x0 + STRIP_WIDTH / 2);
|
|
935
|
-
if (!label) return [];
|
|
936
|
-
label.visible = false;
|
|
937
|
-
scene.add(label);
|
|
938
|
-
return [label];
|
|
939
|
-
});
|
|
940
|
-
const stop = host.onClear?.(() => {
|
|
941
|
-
for (const label of labels) label.visible = false;
|
|
942
|
-
});
|
|
943
|
-
return () => {
|
|
944
|
-
stop?.();
|
|
945
|
-
for (const label of labels) {
|
|
946
|
-
label.removeFromParent();
|
|
947
|
-
const mesh = label;
|
|
948
|
-
mesh.geometry.dispose();
|
|
949
|
-
mesh.material.map?.dispose();
|
|
950
|
-
mesh.material.dispose();
|
|
951
|
-
}
|
|
952
|
-
labels = [];
|
|
1222
|
+
view: { eye: [0, 1.7, 1.5], target: [0, 0, -6] }
|
|
953
1223
|
};
|
|
954
1224
|
}
|
|
955
1225
|
};
|