@adatechnology/game-terrain-three 0.1.2 → 0.3.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 +134 -0
- package/dist/chunk-JAVYWW3G.js.map +1 -0
- package/dist/index.d.ts +6 -12
- package/dist/index.global.js +201 -7
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +103 -118
- package/dist/index.js.map +1 -1
- package/dist/testing.d.ts +14 -0
- package/dist/testing.js +11 -0
- package/dist/testing.js.map +1 -0
- package/package.json +7 -3
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
// src/test-area/test-module.ts
|
|
2
|
+
import { markKitOrigin } from "@adatechnology/game-contracts";
|
|
3
|
+
|
|
4
|
+
// src/test-area/locale.ts
|
|
5
|
+
var PROFILE_NAMES = {
|
|
6
|
+
en: { lawn: "Lawn", dirt: "Dirt", sand: "Sand", road: "Asphalt road", concrete_slab: "Concrete slab", suspended_slab: "Slab over a void", tile_floor: "Tile floor", wood_floor: "Wood floor", stone_paving: "Stone paving" },
|
|
7
|
+
"pt-BR": { lawn: "Grama", dirt: "Terra", sand: "Areia", road: "Asfalto", concrete_slab: "Laje de concreto", suspended_slab: "Laje sobre v\xE3o", tile_floor: "Piso cer\xE2mico", wood_floor: "Assoalho", stone_paving: "Cal\xE7amento de pedra" }
|
|
8
|
+
};
|
|
9
|
+
function terrainProfileName(profileId, localeId) {
|
|
10
|
+
return (PROFILE_NAMES[localeId] ?? PROFILE_NAMES.en)[profileId] ?? profileId;
|
|
11
|
+
}
|
|
12
|
+
var LOCALES = {
|
|
13
|
+
en: {
|
|
14
|
+
name: "Terrain",
|
|
15
|
+
group: "Terrain",
|
|
16
|
+
weight: "Concrete block (60 kg)",
|
|
17
|
+
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" }
|
|
18
|
+
},
|
|
19
|
+
"pt-BR": {
|
|
20
|
+
name: "Terreno",
|
|
21
|
+
group: "Terreno",
|
|
22
|
+
weight: "Bloco de concreto (60 kg)",
|
|
23
|
+
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" }
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
var locale = (id) => LOCALES[id] ?? LOCALES.en;
|
|
27
|
+
|
|
28
|
+
// src/test-area/test-module.ts
|
|
29
|
+
var TERRAIN_STRIPS = ["dirt", "lawn", "sand", "road", "concrete_slab", "suspended_slab", "wood_floor", "tile_floor", "stone_paving"];
|
|
30
|
+
var STRIP_WIDTH = 3;
|
|
31
|
+
var STRIP_Z0 = 4;
|
|
32
|
+
var STRIP_Z1 = 13;
|
|
33
|
+
var stripRect = (index) => {
|
|
34
|
+
const x0 = (index - TERRAIN_STRIPS.length / 2) * STRIP_WIDTH;
|
|
35
|
+
return [x0, STRIP_Z0, x0 + STRIP_WIDTH, STRIP_Z1];
|
|
36
|
+
};
|
|
37
|
+
var TERRAIN_AREA_GROUND = {
|
|
38
|
+
surface: "concrete_slab",
|
|
39
|
+
zones: TERRAIN_STRIPS.map((surface, index) => ({ rect: stripRect(index), surface }))
|
|
40
|
+
};
|
|
41
|
+
var WEIGHT_SIDE = 0.32;
|
|
42
|
+
var WEIGHT_HEIGHT = 4;
|
|
43
|
+
var LABEL_Y = 0.02;
|
|
44
|
+
var LABEL_WIDTH = 2.6;
|
|
45
|
+
var LABEL_HEIGHT = 0.5;
|
|
46
|
+
function weightSpec() {
|
|
47
|
+
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: [] };
|
|
48
|
+
}
|
|
49
|
+
function buildWeight(THREE) {
|
|
50
|
+
const mesh = new THREE.Mesh(new THREE.BoxGeometry(WEIGHT_SIDE, WEIGHT_SIDE, WEIGHT_SIDE), new THREE.MeshStandardMaterial({ color: 11842734, roughness: 0.9 }));
|
|
51
|
+
mesh.name = "block";
|
|
52
|
+
mesh.position.y = WEIGHT_SIDE / 2;
|
|
53
|
+
mesh.castShadow = true;
|
|
54
|
+
const root = markKitOrigin(new THREE.Group(), { owner: "game-terrain-three", kind: "item" });
|
|
55
|
+
root.add(mesh);
|
|
56
|
+
return root;
|
|
57
|
+
}
|
|
58
|
+
function buildLabel(THREE, text, x) {
|
|
59
|
+
if (typeof document === "undefined") return null;
|
|
60
|
+
const canvas = document.createElement("canvas");
|
|
61
|
+
canvas.width = 512;
|
|
62
|
+
canvas.height = 96;
|
|
63
|
+
const context = canvas.getContext("2d");
|
|
64
|
+
if (!context) return null;
|
|
65
|
+
context.fillStyle = "rgba(0,0,0,0.55)";
|
|
66
|
+
context.fillRect(0, 0, 512, 96);
|
|
67
|
+
context.fillStyle = "#fff";
|
|
68
|
+
context.font = "bold 54px sans-serif";
|
|
69
|
+
context.textAlign = "center";
|
|
70
|
+
context.textBaseline = "middle";
|
|
71
|
+
context.fillText(text, 256, 50);
|
|
72
|
+
const mesh = new THREE.Mesh(new THREE.PlaneGeometry(LABEL_WIDTH, LABEL_HEIGHT), new THREE.MeshBasicMaterial({ map: new THREE.CanvasTexture(canvas), transparent: true }));
|
|
73
|
+
markKitOrigin(mesh, { owner: "game-terrain-three", kind: "room" });
|
|
74
|
+
mesh.rotation.set(-Math.PI / 2, 0, Math.PI);
|
|
75
|
+
mesh.position.set(x, LABEL_Y, STRIP_Z0 - LABEL_HEIGHT);
|
|
76
|
+
return mesh;
|
|
77
|
+
}
|
|
78
|
+
function createTerrainTestModule(options = {}) {
|
|
79
|
+
let labels = [];
|
|
80
|
+
const text = locale(options.locale ?? "en");
|
|
81
|
+
return {
|
|
82
|
+
id: "terrain",
|
|
83
|
+
name: text.name,
|
|
84
|
+
group: text.group,
|
|
85
|
+
ground: TERRAIN_AREA_GROUND,
|
|
86
|
+
items() {
|
|
87
|
+
return [{ id: "terrain_weight", name: text.weight, build: (THREE) => buildWeight(THREE), spec: weightSpec, movable: true }];
|
|
88
|
+
},
|
|
89
|
+
area() {
|
|
90
|
+
for (const label of labels) label.visible = true;
|
|
91
|
+
return {
|
|
92
|
+
placements: TERRAIN_STRIPS.map((_, index) => {
|
|
93
|
+
const [x0] = stripRect(index);
|
|
94
|
+
return { item: "terrain_weight", position: [x0 + STRIP_WIDTH / 2, WEIGHT_HEIGHT, STRIP_Z1 - 1.2] };
|
|
95
|
+
}),
|
|
96
|
+
view: { eye: [0, 1.7, 1.5], target: [0, 0, 8] }
|
|
97
|
+
};
|
|
98
|
+
},
|
|
99
|
+
attach(host) {
|
|
100
|
+
const THREE = host.THREE;
|
|
101
|
+
const scene = host.scene;
|
|
102
|
+
labels = TERRAIN_STRIPS.flatMap((surface, index) => {
|
|
103
|
+
const [x0] = stripRect(index);
|
|
104
|
+
const label = buildLabel(THREE, text.surfaces[surface], x0 + STRIP_WIDTH / 2);
|
|
105
|
+
if (!label) return [];
|
|
106
|
+
label.visible = false;
|
|
107
|
+
scene.add(label);
|
|
108
|
+
return [label];
|
|
109
|
+
});
|
|
110
|
+
const stop = host.onClear?.(() => {
|
|
111
|
+
for (const label of labels) label.visible = false;
|
|
112
|
+
});
|
|
113
|
+
return () => {
|
|
114
|
+
stop?.();
|
|
115
|
+
for (const label of labels) {
|
|
116
|
+
label.removeFromParent();
|
|
117
|
+
const mesh = label;
|
|
118
|
+
mesh.geometry.dispose();
|
|
119
|
+
mesh.material.map?.dispose();
|
|
120
|
+
mesh.material.dispose();
|
|
121
|
+
}
|
|
122
|
+
labels = [];
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
export {
|
|
129
|
+
terrainProfileName,
|
|
130
|
+
TERRAIN_STRIPS,
|
|
131
|
+
TERRAIN_AREA_GROUND,
|
|
132
|
+
createTerrainTestModule
|
|
133
|
+
};
|
|
134
|
+
//# sourceMappingURL=chunk-JAVYWW3G.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/test-area/test-module.ts","../src/test-area/locale.ts"],"sourcesContent":["import type * as THREE_NS from 'three'\nimport { markKitOrigin } from '@adatechnology/game-contracts'\nimport type { DestructibleSpec, GroundLayout, ModuleArea, ModuleHost, TestableItem, TestableModule } from '@adatechnology/game-contracts'\nimport { locale as localeTable } from './locale'\n\ntype ThreeLib = typeof THREE_NS\n\n/** The strips of the area, side by side, one of each ground. */\nexport const TERRAIN_STRIPS = ['dirt', 'lawn', 'sand', 'road', 'concrete_slab', 'suspended_slab', 'wood_floor', 'tile_floor', 'stone_paving'] as const\nconst STRIP_WIDTH = 3\nconst STRIP_Z0 = 4\nconst STRIP_Z1 = 13\nconst stripRect = (index: number): readonly [number, number, number, number] => {\n const x0 = (index - TERRAIN_STRIPS.length / 2) * STRIP_WIDTH\n return [x0, STRIP_Z0, x0 + STRIP_WIDTH, STRIP_Z1]\n}\nexport const TERRAIN_AREA_GROUND: GroundLayout = {\n surface: 'concrete_slab',\n zones: TERRAIN_STRIPS.map((surface, index) => ({ rect: stripRect(index), surface })),\n}\n\nconst WEIGHT_SIDE = 0.32\nconst WEIGHT_HEIGHT = 4\nconst LABEL_Y = 0.02\nconst LABEL_WIDTH = 2.6\nconst LABEL_HEIGHT = 0.5\n\nfunction weightSpec(): DestructibleSpec {\n 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: [] }\n}\n\nfunction buildWeight(THREE: ThreeLib): THREE_NS.Object3D {\n const mesh = new THREE.Mesh(new THREE.BoxGeometry(WEIGHT_SIDE, WEIGHT_SIDE, WEIGHT_SIDE), new THREE.MeshStandardMaterial({ color: 0xb4b4ae, roughness: 0.9 }))\n mesh.name = 'block'\n mesh.position.y = WEIGHT_SIDE / 2\n mesh.castShadow = true\n const root = markKitOrigin(new THREE.Group(), { owner: 'game-terrain-three', kind: 'item' })\n root.add(mesh)\n return root\n}\n\nfunction buildLabel(THREE: ThreeLib, text: string, x: number): THREE_NS.Object3D | null {\n if (typeof document === 'undefined') return null\n const canvas = document.createElement('canvas')\n canvas.width = 512\n canvas.height = 96\n const context = canvas.getContext('2d')\n if (!context) return null\n context.fillStyle = 'rgba(0,0,0,0.55)'\n context.fillRect(0, 0, 512, 96)\n context.fillStyle = '#fff'\n context.font = 'bold 54px sans-serif'\n context.textAlign = 'center'\n context.textBaseline = 'middle'\n context.fillText(text, 256, 50)\n const mesh = new THREE.Mesh(new THREE.PlaneGeometry(LABEL_WIDTH, LABEL_HEIGHT), new THREE.MeshBasicMaterial({ map: new THREE.CanvasTexture(canvas), transparent: true }))\n // read from the start of the area, looking along +z\n markKitOrigin(mesh, { owner: 'game-terrain-three', kind: 'room' })\n mesh.rotation.set(-Math.PI / 2, 0, Math.PI)\n mesh.position.set(x, LABEL_Y, STRIP_Z0 - LABEL_HEIGHT)\n return mesh\n}\n\n/**\n * The ground bench: a strip of each surface side by side to shoot, blow up, burn and drop weights on. Opening the area lays the strips (`ground`) and drops a concrete block\n * on each from four metres.\n */\nexport function createTerrainTestModule(options: { readonly locale?: string } = {}): TestableModule {\n let labels: THREE_NS.Object3D[] = []\n const text = localeTable(options.locale ?? 'en')\n return {\n id: 'terrain',\n name: text.name,\n group: text.group,\n ground: TERRAIN_AREA_GROUND,\n items(): TestableItem[] {\n return [{ id: 'terrain_weight', name: text.weight, build: (THREE) => buildWeight(THREE as ThreeLib), spec: weightSpec, movable: true }]\n },\n area(): ModuleArea {\n for (const label of labels) label.visible = true\n return {\n placements: TERRAIN_STRIPS.map((_, index) => {\n const [x0] = stripRect(index)\n return { item: 'terrain_weight', position: [x0 + STRIP_WIDTH / 2, WEIGHT_HEIGHT, STRIP_Z1 - 1.2] }\n }),\n view: { eye: [0, 1.7, 1.5], target: [0, 0, 8] },\n }\n },\n attach(host: ModuleHost): () => void {\n const THREE = host.THREE as ThreeLib\n const scene = host.scene as THREE_NS.Scene\n labels = TERRAIN_STRIPS.flatMap((surface, index) => {\n const [x0] = stripRect(index)\n const label = buildLabel(THREE, text.surfaces[surface], x0 + STRIP_WIDTH / 2)\n if (!label) return []\n label.visible = false\n scene.add(label)\n return [label]\n })\n const stop = host.onClear?.(() => {\n for (const label of labels) label.visible = false\n })\n return () => {\n stop?.()\n // each label is built for this attach (its own plane, material and canvas texture): freed when the area goes\n for (const label of labels) {\n label.removeFromParent()\n const mesh = label as THREE_NS.Mesh<THREE_NS.BufferGeometry, THREE_NS.MeshBasicMaterial>\n mesh.geometry.dispose()\n mesh.material.map?.dispose()\n mesh.material.dispose()\n }\n labels = []\n }\n },\n }\n}\n","import type { TERRAIN_STRIPS } from './test-module'\n\n/** The ground profiles of the catalogue (`TERRAIN_PROFILES` of game-terrain) by name, for a HUD that says what the floor under the aim is. */\nconst PROFILE_NAMES: Record<string, Record<string, string>> = {\n en: { lawn: 'Lawn', dirt: 'Dirt', sand: 'Sand', road: 'Asphalt road', concrete_slab: 'Concrete slab', suspended_slab: 'Slab over a void', tile_floor: 'Tile floor', wood_floor: 'Wood floor', stone_paving: 'Stone paving' },\n 'pt-BR': { lawn: 'Grama', dirt: 'Terra', sand: 'Areia', road: 'Asfalto', concrete_slab: 'Laje de concreto', suspended_slab: 'Laje sobre vão', tile_floor: 'Piso cerâmico', wood_floor: 'Assoalho', stone_paving: 'Calçamento de pedra' },\n}\n\n/** The name of a ground profile in the locale (`en` when the locale is unknown); a profile a game added without a name answers its id. */\nexport function terrainProfileName(profileId: string, localeId: string): string {\n return (PROFILE_NAMES[localeId] ?? PROFILE_NAMES.en!)[profileId] ?? profileId\n}\n\ninterface TerrainText {\n readonly name: string\n readonly group: string\n readonly weight: string\n readonly surfaces: Record<(typeof TERRAIN_STRIPS)[number], string>\n}\n\nconst LOCALES: Record<string, TerrainText> = {\n en: {\n name: 'Terrain',\n group: 'Terrain',\n weight: 'Concrete block (60 kg)',\n 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' },\n },\n 'pt-BR': {\n name: 'Terreno',\n group: 'Terreno',\n weight: 'Bloco de concreto (60 kg)',\n surfaces: { dirt: 'Terra', lawn: 'Grama', sand: 'Areia', road: 'Asfalto', concrete_slab: 'Laje de concreto', suspended_slab: 'Laje sobre vão', wood_floor: 'Assoalho', tile_floor: 'Cerâmica', stone_paving: 'Pedra' },\n },\n}\n\nexport const locale = (id: string): TerrainText => LOCALES[id] ?? LOCALES.en!\n"],"mappings":";AACA,SAAS,qBAAqB;;;ACE9B,IAAM,gBAAwD;AAAA,EAC5D,IAAI,EAAE,MAAM,QAAQ,MAAM,QAAQ,MAAM,QAAQ,MAAM,gBAAgB,eAAe,iBAAiB,gBAAgB,oBAAoB,YAAY,cAAc,YAAY,cAAc,cAAc,eAAe;AAAA,EAC3N,SAAS,EAAE,MAAM,SAAS,MAAM,SAAS,MAAM,SAAS,MAAM,WAAW,eAAe,oBAAoB,gBAAgB,qBAAkB,YAAY,oBAAiB,YAAY,YAAY,cAAc,yBAAsB;AACzO;AAGO,SAAS,mBAAmB,WAAmB,UAA0B;AAC9E,UAAQ,cAAc,QAAQ,KAAK,cAAc,IAAK,SAAS,KAAK;AACtE;AASA,IAAM,UAAuC;AAAA,EAC3C,IAAI;AAAA,IACF,MAAM;AAAA,IACN,OAAO;AAAA,IACP,QAAQ;AAAA,IACR,UAAU,EAAE,MAAM,QAAQ,MAAM,QAAQ,MAAM,QAAQ,MAAM,WAAW,eAAe,iBAAiB,gBAAgB,oBAAoB,YAAY,cAAc,YAAY,QAA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2
|
import { Terrain } from '@adatechnology/game-terrain';
|
|
3
|
-
|
|
3
|
+
export { TERRAIN_AREA_GROUND, TERRAIN_STRIPS, createTerrainTestModule } from './testing.js';
|
|
4
|
+
import '@adatechnology/game-contracts';
|
|
4
5
|
|
|
5
6
|
type ThreeLib$1 = typeof THREE_NS;
|
|
6
7
|
interface TerrainRendererOptions {
|
|
@@ -26,6 +27,7 @@ interface TerrainRenderer {
|
|
|
26
27
|
readonly pristineChunks: number;
|
|
27
28
|
readonly marksDrawn: number;
|
|
28
29
|
readonly debrisDrawn: number;
|
|
30
|
+
readonly crackQuads: number;
|
|
29
31
|
};
|
|
30
32
|
dispose(): void;
|
|
31
33
|
}
|
|
@@ -36,15 +38,7 @@ type ThreeLib = typeof THREE_NS;
|
|
|
36
38
|
/** The ground's material: the colour of what is exposed comes per vertex, flat so that the edge between two materials stays sharp, its pattern (blades of grass, grout, planks) is drawn per pixel from the world position so that it never tiles or stretches. */
|
|
37
39
|
declare function createSurfaceMaterial(THREE: ThreeLib): THREE_NS.MeshStandardMaterial;
|
|
38
40
|
|
|
39
|
-
/** The
|
|
40
|
-
declare
|
|
41
|
-
declare const TERRAIN_AREA_GROUND: GroundLayout;
|
|
42
|
-
/**
|
|
43
|
-
* The ground bench: a strip of each surface side by side to shoot, blow up, burn and drop weights on. Opening the area lays the strips (`ground`) and drops a concrete block
|
|
44
|
-
* on each from four metres.
|
|
45
|
-
*/
|
|
46
|
-
declare function createTerrainTestModule(options?: {
|
|
47
|
-
readonly locale?: string;
|
|
48
|
-
}): TestableModule;
|
|
41
|
+
/** The name of a ground profile in the locale (`en` when the locale is unknown); a profile a game added without a name answers its id. */
|
|
42
|
+
declare function terrainProfileName(profileId: string, localeId: string): string;
|
|
49
43
|
|
|
50
|
-
export {
|
|
44
|
+
export { type TerrainRenderer, type TerrainRendererOptions, createSurfaceMaterial, createTerrainRenderer, terrainProfileName };
|
package/dist/index.global.js
CHANGED
|
@@ -25,10 +25,24 @@ var GameTerrainThree = (() => {
|
|
|
25
25
|
TERRAIN_STRIPS: () => TERRAIN_STRIPS,
|
|
26
26
|
createSurfaceMaterial: () => createSurfaceMaterial,
|
|
27
27
|
createTerrainRenderer: () => createTerrainRenderer,
|
|
28
|
-
createTerrainTestModule: () => createTerrainTestModule
|
|
28
|
+
createTerrainTestModule: () => createTerrainTestModule,
|
|
29
|
+
terrainProfileName: () => terrainProfileName
|
|
29
30
|
});
|
|
30
31
|
|
|
31
32
|
// ../game-contracts/dist/index.js
|
|
33
|
+
var DEFAULT_COST_ALLOCATION_BYTES = 1024 * 1024;
|
|
34
|
+
var DEFERRED_QUEUE_ID = {
|
|
35
|
+
DESTRUCTION_EVENTS: "destruction.events",
|
|
36
|
+
BREACH_PAINT: "floorplan.breach-paint",
|
|
37
|
+
AUDIO_VOICES: "audio.voices",
|
|
38
|
+
VEHICLE_CREASE: "vehicles.crease"
|
|
39
|
+
};
|
|
40
|
+
var DEFERRED_PRIORITY = {
|
|
41
|
+
[DEFERRED_QUEUE_ID.DESTRUCTION_EVENTS]: { priority: 300, phase: "present" },
|
|
42
|
+
[DEFERRED_QUEUE_ID.BREACH_PAINT]: { priority: 250, phase: "present" },
|
|
43
|
+
[DEFERRED_QUEUE_ID.AUDIO_VOICES]: { priority: 200, phase: "idle", reserveMs: 1 },
|
|
44
|
+
[DEFERRED_QUEUE_ID.VEHICLE_CREASE]: { priority: 100, phase: "idle" }
|
|
45
|
+
};
|
|
32
46
|
var KIT_ORIGIN_KEY = "kitOrigin";
|
|
33
47
|
function markKitOrigin(object, origin) {
|
|
34
48
|
const node = object;
|
|
@@ -36,8 +50,85 @@ var GameTerrainThree = (() => {
|
|
|
36
50
|
node.userData[KIT_ORIGIN_KEY] = { ...origin };
|
|
37
51
|
return object;
|
|
38
52
|
}
|
|
53
|
+
var SURFACE_IDS = ["concrete", "asphalt", "wood", "tile", "dirt", "grass", "gravel", "sand", "metal", "water", "glass", "carpet"];
|
|
54
|
+
var GAIT_IDS = ["walk", "run"];
|
|
55
|
+
var LANDING_IDS = ["light", "heavy"];
|
|
56
|
+
var BODY_SOUND_IDS = [
|
|
57
|
+
"jump",
|
|
58
|
+
"cloth_rustle",
|
|
59
|
+
"body_fall",
|
|
60
|
+
"fall_damage",
|
|
61
|
+
"player_hurt",
|
|
62
|
+
"player_breath_run",
|
|
63
|
+
"player_death",
|
|
64
|
+
"bite",
|
|
65
|
+
"grab",
|
|
66
|
+
"punch_swing",
|
|
67
|
+
"punch_hit_body",
|
|
68
|
+
"punch_hit_face",
|
|
69
|
+
"punch_hit_object",
|
|
70
|
+
"kick_swing",
|
|
71
|
+
"kick_hit",
|
|
72
|
+
"kick_hit_object",
|
|
73
|
+
"shove_two_hands",
|
|
74
|
+
"knife_swing",
|
|
75
|
+
"knife_stab",
|
|
76
|
+
"knife_slash",
|
|
77
|
+
"knife_hit_object",
|
|
78
|
+
"blunt_swing",
|
|
79
|
+
"blunt_hit",
|
|
80
|
+
"blunt_hit_object",
|
|
81
|
+
"axe_swing",
|
|
82
|
+
"axe_chop",
|
|
83
|
+
"axe_hit_object"
|
|
84
|
+
];
|
|
85
|
+
var footstepSoundId = (surface, gait) => `footstep_${surface}_${gait}`;
|
|
86
|
+
var FOOTSTEP_SOUND_IDS = SURFACE_IDS.flatMap((surface) => GAIT_IDS.map((gait) => footstepSoundId(surface, gait)));
|
|
87
|
+
var LAND_SOUND_IDS = SURFACE_IDS.flatMap((surface) => LANDING_IDS.map((landing) => `land_${surface}_${landing}`));
|
|
88
|
+
var BODY_FOLEY_IDS = [...FOOTSTEP_SOUND_IDS, ...LAND_SOUND_IDS, ...BODY_SOUND_IDS];
|
|
39
89
|
|
|
40
90
|
// ../game-terrain/dist/index.js
|
|
91
|
+
function createRandom(seed) {
|
|
92
|
+
let state = seed | 0;
|
|
93
|
+
return () => {
|
|
94
|
+
state = state + 1831565813 | 0;
|
|
95
|
+
let mixed = Math.imul(state ^ state >>> 15, 1 | state);
|
|
96
|
+
mixed = mixed + Math.imul(mixed ^ mixed >>> 7, 61 | mixed) ^ mixed;
|
|
97
|
+
return ((mixed ^ mixed >>> 14) >>> 0) / 4294967296;
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
var HAIRLINE = 15e-4;
|
|
101
|
+
var SEGMENTS = 4;
|
|
102
|
+
var BRANCH_CHANCE = 0.45;
|
|
103
|
+
function crackLines(crack) {
|
|
104
|
+
const random = createRandom(crack.seed);
|
|
105
|
+
const segments = [];
|
|
106
|
+
const widthAt = (distance) => Math.max(HAIRLINE, crack.width * (1 - distance / crack.reach));
|
|
107
|
+
for (let ray = 0; ray < crack.rays; ray++) {
|
|
108
|
+
let angle = ray / crack.rays * Math.PI * 2 + (random() - 0.5) * 0.6;
|
|
109
|
+
const length = crack.reach * (0.45 + 0.55 * random());
|
|
110
|
+
let x = crack.x;
|
|
111
|
+
let z = crack.z;
|
|
112
|
+
let run = 0;
|
|
113
|
+
for (let segment = 0; segment < SEGMENTS; segment++) {
|
|
114
|
+
const step = length / SEGMENTS * (0.75 + 0.5 * random());
|
|
115
|
+
angle += (random() - 0.5) * 0.5;
|
|
116
|
+
const nx = x + Math.cos(angle) * step;
|
|
117
|
+
const nz = z + Math.sin(angle) * step;
|
|
118
|
+
segments.push({ x0: x, z0: z, x1: nx, z1: nz, w0: widthAt(run), w1: widthAt(run + step) });
|
|
119
|
+
if (segment > 0 && random() < BRANCH_CHANCE) {
|
|
120
|
+
const side = angle + (random() < 0.5 ? -1 : 1) * (0.45 + random() * 0.5);
|
|
121
|
+
const branch = step * (0.5 + 0.6 * random());
|
|
122
|
+
const w = widthAt(run + step) * 0.6;
|
|
123
|
+
segments.push({ x0: nx, z0: nz, x1: nx + Math.cos(side) * branch, z1: nz + Math.sin(side) * branch, w0: Math.max(HAIRLINE, w), w1: HAIRLINE });
|
|
124
|
+
}
|
|
125
|
+
run += step;
|
|
126
|
+
x = nx;
|
|
127
|
+
z = nz;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
return segments;
|
|
131
|
+
}
|
|
41
132
|
var TERRAIN_PATTERNS = ["plain", "grass", "soil", "sand", "asphalt", "concrete", "tile", "planks", "stone"];
|
|
42
133
|
|
|
43
134
|
// src/surface-material.ts
|
|
@@ -409,6 +500,92 @@ ${SURFACE_GLSL}`).replace("#include <color_fragment>", "#include <color_fragment
|
|
|
409
500
|
}
|
|
410
501
|
};
|
|
411
502
|
}
|
|
503
|
+
var CRACK_LIFT = 4e-3;
|
|
504
|
+
var MAX_CRACK_QUADS = 8192;
|
|
505
|
+
var CRACK_SHADE = 0.22;
|
|
506
|
+
var DARK_SURFACE = 0.1;
|
|
507
|
+
var DUST_LIFT = 2;
|
|
508
|
+
var DUST_GREY = 0.12;
|
|
509
|
+
function createCrackLayer(THREE, terrain) {
|
|
510
|
+
const positions = new Float32Array(MAX_CRACK_QUADS * 4 * 3);
|
|
511
|
+
const colours = new Float32Array(MAX_CRACK_QUADS * 4 * 3);
|
|
512
|
+
const indices = new Uint32Array(MAX_CRACK_QUADS * 6);
|
|
513
|
+
for (let quad = 0; quad < MAX_CRACK_QUADS; quad++) {
|
|
514
|
+
const first = quad * 4;
|
|
515
|
+
indices.set([first, first + 2, first + 1, first + 1, first + 2, first + 3], quad * 6);
|
|
516
|
+
}
|
|
517
|
+
const geometry = new THREE.BufferGeometry();
|
|
518
|
+
const position = new THREE.BufferAttribute(positions, 3);
|
|
519
|
+
const colour = new THREE.BufferAttribute(colours, 3);
|
|
520
|
+
position.setUsage(THREE.DynamicDrawUsage);
|
|
521
|
+
colour.setUsage(THREE.DynamicDrawUsage);
|
|
522
|
+
geometry.setAttribute("position", position);
|
|
523
|
+
geometry.setAttribute("color", colour);
|
|
524
|
+
geometry.setIndex(new THREE.BufferAttribute(indices, 1));
|
|
525
|
+
geometry.setDrawRange(0, 0);
|
|
526
|
+
const material = new THREE.MeshBasicMaterial({ vertexColors: true, transparent: true, opacity: 0.9, depthWrite: false, polygonOffset: true, polygonOffsetFactor: -3, polygonOffsetUnits: -3 });
|
|
527
|
+
const mesh = new THREE.Mesh(geometry, material);
|
|
528
|
+
mesh.name = "terrain-cracks";
|
|
529
|
+
mesh.frustumCulled = false;
|
|
530
|
+
mesh.renderOrder = 2;
|
|
531
|
+
let seen = -1;
|
|
532
|
+
let groundMoved = false;
|
|
533
|
+
const stopListening = terrain.onDeform(() => {
|
|
534
|
+
groundMoved = true;
|
|
535
|
+
});
|
|
536
|
+
const lift = (x, z) => terrain.heightAt(x, z) + CRACK_LIFT;
|
|
537
|
+
return {
|
|
538
|
+
mesh,
|
|
539
|
+
sync() {
|
|
540
|
+
const cracks = terrain.cracks();
|
|
541
|
+
if (seen === terrain.cracksVersion && !(groundMoved && cracks.length > 0)) return;
|
|
542
|
+
seen = terrain.cracksVersion;
|
|
543
|
+
groundMoved = false;
|
|
544
|
+
let quad = 0;
|
|
545
|
+
for (let n = cracks.length - 1; n >= 0 && quad < MAX_CRACK_QUADS; n--) {
|
|
546
|
+
const crack = cracks[n];
|
|
547
|
+
const tone = terrain.material(crack.material).color;
|
|
548
|
+
const dark = tone[0] * 0.3 + tone[1] * 0.59 + tone[2] * 0.11 < DARK_SURFACE;
|
|
549
|
+
const k = dark ? DUST_LIFT : CRACK_SHADE;
|
|
550
|
+
const r = dark ? Math.min(1, tone[0] * k + DUST_GREY) : tone[0] * k;
|
|
551
|
+
const g = dark ? Math.min(1, tone[1] * k + DUST_GREY) : tone[1] * k;
|
|
552
|
+
const b = dark ? Math.min(1, tone[2] * k + DUST_GREY) : tone[2] * k;
|
|
553
|
+
for (const s of crackLines(crack)) {
|
|
554
|
+
if (quad >= MAX_CRACK_QUADS) break;
|
|
555
|
+
if (!terrain.contains(s.x0, s.z0) || !terrain.contains(s.x1, s.z1)) continue;
|
|
556
|
+
const length = Math.hypot(s.x1 - s.x0, s.z1 - s.z0);
|
|
557
|
+
if (length < 1e-5) continue;
|
|
558
|
+
const ax = -(s.z1 - s.z0) / length;
|
|
559
|
+
const az = (s.x1 - s.x0) / length;
|
|
560
|
+
const corners = [
|
|
561
|
+
[s.x0 + ax * s.w0 * 0.5, s.z0 + az * s.w0 * 0.5],
|
|
562
|
+
[s.x0 - ax * s.w0 * 0.5, s.z0 - az * s.w0 * 0.5],
|
|
563
|
+
[s.x1 + ax * s.w1 * 0.5, s.z1 + az * s.w1 * 0.5],
|
|
564
|
+
[s.x1 - ax * s.w1 * 0.5, s.z1 - az * s.w1 * 0.5]
|
|
565
|
+
];
|
|
566
|
+
corners.forEach(([x, z], corner) => {
|
|
567
|
+
const at = (quad * 4 + corner) * 3;
|
|
568
|
+
positions[at] = x;
|
|
569
|
+
positions[at + 1] = lift(x, z);
|
|
570
|
+
positions[at + 2] = z;
|
|
571
|
+
colours[at] = r;
|
|
572
|
+
colours[at + 1] = g;
|
|
573
|
+
colours[at + 2] = b;
|
|
574
|
+
});
|
|
575
|
+
quad++;
|
|
576
|
+
}
|
|
577
|
+
}
|
|
578
|
+
position.needsUpdate = true;
|
|
579
|
+
colour.needsUpdate = true;
|
|
580
|
+
geometry.setDrawRange(0, quad * 6);
|
|
581
|
+
},
|
|
582
|
+
dispose() {
|
|
583
|
+
stopListening();
|
|
584
|
+
geometry.dispose();
|
|
585
|
+
material.dispose();
|
|
586
|
+
}
|
|
587
|
+
};
|
|
588
|
+
}
|
|
412
589
|
|
|
413
590
|
// src/rebar.ts
|
|
414
591
|
var BAR_RADIUS = 6e-3;
|
|
@@ -527,7 +704,8 @@ ${SURFACE_GLSL}`).replace("#include <color_fragment>", "#include <color_fragment
|
|
|
527
704
|
const drawn = /* @__PURE__ */ new Map();
|
|
528
705
|
const marks = createMarkLayer(THREE, terrain, options.markDistance ?? DEFAULT_MARK_DISTANCE);
|
|
529
706
|
const debris = createDebrisLayer(THREE, terrain);
|
|
530
|
-
|
|
707
|
+
const cracks = createCrackLayer(THREE, terrain);
|
|
708
|
+
group.add(marks.mesh, cracks.mesh, debris.mesh);
|
|
531
709
|
let pristineStale = true;
|
|
532
710
|
let pristineBuilt = false;
|
|
533
711
|
let pristineCount = 0;
|
|
@@ -613,7 +791,8 @@ ${SURFACE_GLSL}`).replace("#include <color_fragment>", "#include <color_fragment
|
|
|
613
791
|
return {
|
|
614
792
|
group,
|
|
615
793
|
sync(camera) {
|
|
616
|
-
const
|
|
794
|
+
const laidAnew = terrain.dirtyChunkCount >= terrain.chunksX * terrain.chunksZ;
|
|
795
|
+
const limit = firstSync || laidAnew ? Infinity : void 0;
|
|
617
796
|
firstSync = false;
|
|
618
797
|
for (const chunk of terrain.drainDirtyChunks(limit)) {
|
|
619
798
|
if (chunk.pristine) {
|
|
@@ -634,9 +813,10 @@ ${SURFACE_GLSL}`).replace("#include <color_fragment>", "#include <color_fragment
|
|
|
634
813
|
}
|
|
635
814
|
}
|
|
636
815
|
marks.sync(camera);
|
|
816
|
+
cracks.sync();
|
|
637
817
|
debris.sync();
|
|
638
818
|
},
|
|
639
|
-
stats: () => ({ chunkMeshes: drawn.size, pristineChunks: pristineCount, marksDrawn: marks.mesh.count, debrisDrawn: debris.mesh.count }),
|
|
819
|
+
stats: () => ({ chunkMeshes: drawn.size, pristineChunks: pristineCount, marksDrawn: marks.mesh.count, debrisDrawn: debris.mesh.count, crackQuads: cracks.mesh.geometry.drawRange.count / 6 }),
|
|
640
820
|
dispose() {
|
|
641
821
|
for (const index of [...drawn.keys()]) drop(index);
|
|
642
822
|
for (const geometry of spareGeometries) geometry.dispose();
|
|
@@ -644,13 +824,21 @@ ${SURFACE_GLSL}`).replace("#include <color_fragment>", "#include <color_fragment
|
|
|
644
824
|
surface.dispose();
|
|
645
825
|
rebarMaterial.dispose();
|
|
646
826
|
marks.dispose();
|
|
827
|
+
cracks.dispose();
|
|
647
828
|
debris.dispose();
|
|
648
829
|
group.removeFromParent();
|
|
649
830
|
}
|
|
650
831
|
};
|
|
651
832
|
}
|
|
652
833
|
|
|
653
|
-
// src/locale.ts
|
|
834
|
+
// src/test-area/locale.ts
|
|
835
|
+
var PROFILE_NAMES = {
|
|
836
|
+
en: { lawn: "Lawn", dirt: "Dirt", sand: "Sand", road: "Asphalt road", concrete_slab: "Concrete slab", suspended_slab: "Slab over a void", tile_floor: "Tile floor", wood_floor: "Wood floor", stone_paving: "Stone paving" },
|
|
837
|
+
"pt-BR": { lawn: "Grama", dirt: "Terra", sand: "Areia", road: "Asfalto", concrete_slab: "Laje de concreto", suspended_slab: "Laje sobre v\xE3o", tile_floor: "Piso cer\xE2mico", wood_floor: "Assoalho", stone_paving: "Cal\xE7amento de pedra" }
|
|
838
|
+
};
|
|
839
|
+
function terrainProfileName(profileId, localeId) {
|
|
840
|
+
return (PROFILE_NAMES[localeId] ?? PROFILE_NAMES.en)[profileId] ?? profileId;
|
|
841
|
+
}
|
|
654
842
|
var LOCALES = {
|
|
655
843
|
en: {
|
|
656
844
|
name: "Terrain",
|
|
@@ -667,7 +855,7 @@ ${SURFACE_GLSL}`).replace("#include <color_fragment>", "#include <color_fragment
|
|
|
667
855
|
};
|
|
668
856
|
var locale = (id) => LOCALES[id] ?? LOCALES.en;
|
|
669
857
|
|
|
670
|
-
// src/test-module.ts
|
|
858
|
+
// src/test-area/test-module.ts
|
|
671
859
|
var TERRAIN_STRIPS = ["dirt", "lawn", "sand", "road", "concrete_slab", "suspended_slab", "wood_floor", "tile_floor", "stone_paving"];
|
|
672
860
|
var STRIP_WIDTH = 3;
|
|
673
861
|
var STRIP_Z0 = 4;
|
|
@@ -754,7 +942,13 @@ ${SURFACE_GLSL}`).replace("#include <color_fragment>", "#include <color_fragment
|
|
|
754
942
|
});
|
|
755
943
|
return () => {
|
|
756
944
|
stop?.();
|
|
757
|
-
for (const label of labels)
|
|
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
|
+
}
|
|
758
952
|
labels = [];
|
|
759
953
|
};
|
|
760
954
|
}
|