@adatechnology/game-terrain-three 0.3.2 → 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 +343 -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,6 +26,7 @@ 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
|
|
|
@@ -130,7 +131,7 @@ var GameTerrainThree = (() => {
|
|
|
130
131
|
}
|
|
131
132
|
return segments;
|
|
132
133
|
}
|
|
133
|
-
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"];
|
|
134
135
|
|
|
135
136
|
// src/surface-material.ts
|
|
136
137
|
var patternIndex = (pattern) => Math.max(0, TERRAIN_PATTERNS.indexOf(pattern ?? "plain"));
|
|
@@ -171,9 +172,51 @@ vec3 terrainSurface(vec3 base, vec2 xz, float kind) {
|
|
|
171
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;
|
|
172
173
|
return base * (0.72 + 0.56 * tsHash(vec2(row, floor(along / 2.4)))) * (0.75 + 0.5 * grain) * (1.0 - 0.75 * seam);
|
|
173
174
|
}
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
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);
|
|
177
220
|
}
|
|
178
221
|
`
|
|
179
222
|
);
|
|
@@ -373,12 +416,164 @@ ${SURFACE_GLSL}`).replace("#include <color_fragment>", "#include <color_fragment
|
|
|
373
416
|
return geometry;
|
|
374
417
|
}
|
|
375
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
|
+
|
|
376
571
|
// src/layers.ts
|
|
377
572
|
var MARK_LIFT = 6e-3;
|
|
378
573
|
var MARK_REACH = 1.5;
|
|
379
574
|
var MARK_TEXTURE_SIZE = 64;
|
|
380
575
|
var MARK_DARKEN = 0.85;
|
|
381
|
-
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] };
|
|
382
577
|
function createMarkTexture(THREE) {
|
|
383
578
|
const size = MARK_TEXTURE_SIZE;
|
|
384
579
|
const data = new Uint8Array(size * size * 4);
|
|
@@ -588,6 +783,121 @@ ${SURFACE_GLSL}`).replace("#include <color_fragment>", "#include <color_fragment
|
|
|
588
783
|
};
|
|
589
784
|
}
|
|
590
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
|
+
|
|
591
901
|
// src/rebar.ts
|
|
592
902
|
var BAR_RADIUS = 6e-3;
|
|
593
903
|
var EXPOSED_MARGIN = 2e-3;
|
|
@@ -706,7 +1016,9 @@ ${SURFACE_GLSL}`).replace("#include <color_fragment>", "#include <color_fragment
|
|
|
706
1016
|
const marks = createMarkLayer(THREE, terrain, options.markDistance ?? DEFAULT_MARK_DISTANCE);
|
|
707
1017
|
const debris = createDebrisLayer(THREE, terrain);
|
|
708
1018
|
const cracks = createCrackLayer(THREE, terrain);
|
|
709
|
-
|
|
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);
|
|
710
1022
|
let pristineStale = true;
|
|
711
1023
|
let pristineBuilt = false;
|
|
712
1024
|
let pristineCount = 0;
|
|
@@ -816,6 +1128,8 @@ ${SURFACE_GLSL}`).replace("#include <color_fragment>", "#include <color_fragment
|
|
|
816
1128
|
marks.sync(camera);
|
|
817
1129
|
cracks.sync();
|
|
818
1130
|
debris.sync();
|
|
1131
|
+
decals.sync();
|
|
1132
|
+
zones.sync();
|
|
819
1133
|
},
|
|
820
1134
|
stats: () => ({ chunkMeshes: drawn.size, pristineChunks: pristineCount, marksDrawn: marks.mesh.count, debrisDrawn: debris.mesh.count, crackQuads: cracks.mesh.geometry.drawRange.count / 6 }),
|
|
821
1135
|
dispose() {
|
|
@@ -827,6 +1141,8 @@ ${SURFACE_GLSL}`).replace("#include <color_fragment>", "#include <color_fragment
|
|
|
827
1141
|
marks.dispose();
|
|
828
1142
|
cracks.dispose();
|
|
829
1143
|
debris.dispose();
|
|
1144
|
+
decals.dispose();
|
|
1145
|
+
zones.dispose();
|
|
830
1146
|
group.removeFromParent();
|
|
831
1147
|
}
|
|
832
1148
|
};
|
|
@@ -845,35 +1161,36 @@ ${SURFACE_GLSL}`).replace("#include <color_fragment>", "#include <color_fragment
|
|
|
845
1161
|
name: "Terrain",
|
|
846
1162
|
group: "Terrain",
|
|
847
1163
|
weight: "Concrete block (60 kg)",
|
|
848
|
-
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" }
|
|
849
1165
|
},
|
|
850
1166
|
"pt-BR": {
|
|
851
1167
|
name: "Terreno",
|
|
852
1168
|
group: "Terreno",
|
|
853
1169
|
weight: "Bloco de concreto (60 kg)",
|
|
854
|
-
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" }
|
|
855
1171
|
}
|
|
856
1172
|
};
|
|
857
1173
|
var locale = (id) => LOCALES[id] ?? LOCALES.en;
|
|
858
1174
|
|
|
859
1175
|
// src/test-area/test-module.ts
|
|
860
|
-
var TERRAIN_STRIPS = ["
|
|
861
|
-
var
|
|
862
|
-
var
|
|
863
|
-
var
|
|
864
|
-
var
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
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];
|
|
871
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();
|
|
872
1192
|
var WEIGHT_SIDE = 0.32;
|
|
873
1193
|
var WEIGHT_HEIGHT = 4;
|
|
874
|
-
var LABEL_Y = 0.02;
|
|
875
|
-
var LABEL_WIDTH = 2.6;
|
|
876
|
-
var LABEL_HEIGHT = 0.5;
|
|
877
1194
|
function weightSpec() {
|
|
878
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: [] };
|
|
879
1196
|
}
|
|
@@ -886,71 +1203,23 @@ ${SURFACE_GLSL}`).replace("#include <color_fragment>", "#include <color_fragment
|
|
|
886
1203
|
root.add(mesh);
|
|
887
1204
|
return root;
|
|
888
1205
|
}
|
|
889
|
-
function buildLabel(THREE, text, x) {
|
|
890
|
-
if (typeof document === "undefined") return null;
|
|
891
|
-
const canvas = document.createElement("canvas");
|
|
892
|
-
canvas.width = 512;
|
|
893
|
-
canvas.height = 96;
|
|
894
|
-
const context = canvas.getContext("2d");
|
|
895
|
-
if (!context) return null;
|
|
896
|
-
context.fillStyle = "rgba(0,0,0,0.55)";
|
|
897
|
-
context.fillRect(0, 0, 512, 96);
|
|
898
|
-
context.fillStyle = "#fff";
|
|
899
|
-
context.font = "bold 54px sans-serif";
|
|
900
|
-
context.textAlign = "center";
|
|
901
|
-
context.textBaseline = "middle";
|
|
902
|
-
context.fillText(text, 256, 50);
|
|
903
|
-
const mesh = new THREE.Mesh(new THREE.PlaneGeometry(LABEL_WIDTH, LABEL_HEIGHT), new THREE.MeshBasicMaterial({ map: new THREE.CanvasTexture(canvas), transparent: true }));
|
|
904
|
-
markKitOrigin(mesh, { owner: "game-terrain-three", kind: "room" });
|
|
905
|
-
mesh.rotation.set(-Math.PI / 2, 0, Math.PI);
|
|
906
|
-
mesh.position.set(x, LABEL_Y, STRIP_Z0 - LABEL_HEIGHT);
|
|
907
|
-
return mesh;
|
|
908
|
-
}
|
|
909
1206
|
function createTerrainTestModule(options = {}) {
|
|
910
|
-
let labels = [];
|
|
911
1207
|
const text = locale(options.locale ?? "en");
|
|
912
1208
|
return {
|
|
913
1209
|
id: "terrain",
|
|
914
1210
|
name: text.name,
|
|
915
1211
|
group: text.group,
|
|
916
|
-
ground:
|
|
1212
|
+
ground: terrainLotsGround(options.locale ?? "en"),
|
|
917
1213
|
items() {
|
|
918
1214
|
return [{ id: "terrain_weight", name: text.weight, build: (THREE) => buildWeight(THREE), spec: weightSpec, movable: true }];
|
|
919
1215
|
},
|
|
920
1216
|
area() {
|
|
921
|
-
for (const label of labels) label.visible = true;
|
|
922
1217
|
return {
|
|
923
1218
|
placements: TERRAIN_STRIPS.map((_, index) => {
|
|
924
|
-
const [x0] =
|
|
925
|
-
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] };
|
|
926
1221
|
}),
|
|
927
|
-
view: { eye: [0, 1.7, 1.5], target: [0, 0,
|
|
928
|
-
};
|
|
929
|
-
},
|
|
930
|
-
attach(host) {
|
|
931
|
-
const THREE = host.THREE;
|
|
932
|
-
const scene = host.scene;
|
|
933
|
-
labels = TERRAIN_STRIPS.flatMap((surface, index) => {
|
|
934
|
-
const [x0] = stripRect(index);
|
|
935
|
-
const label = buildLabel(THREE, text.surfaces[surface], x0 + STRIP_WIDTH / 2);
|
|
936
|
-
if (!label) return [];
|
|
937
|
-
label.visible = false;
|
|
938
|
-
scene.add(label);
|
|
939
|
-
return [label];
|
|
940
|
-
});
|
|
941
|
-
const stop = host.onClear?.(() => {
|
|
942
|
-
for (const label of labels) label.visible = false;
|
|
943
|
-
});
|
|
944
|
-
return () => {
|
|
945
|
-
stop?.();
|
|
946
|
-
for (const label of labels) {
|
|
947
|
-
label.removeFromParent();
|
|
948
|
-
const mesh = label;
|
|
949
|
-
mesh.geometry.dispose();
|
|
950
|
-
mesh.material.map?.dispose();
|
|
951
|
-
mesh.material.dispose();
|
|
952
|
-
}
|
|
953
|
-
labels = [];
|
|
1222
|
+
view: { eye: [0, 1.7, 1.5], target: [0, 0, -6] }
|
|
954
1223
|
};
|
|
955
1224
|
}
|
|
956
1225
|
};
|