@khr3/launchers 0.2.9 → 0.3.1

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.
Files changed (107) hide show
  1. package/AGENTS.md +3 -3
  2. package/CLAUDE.md +1 -5
  3. package/LICENSE +1 -1
  4. package/README.md +39 -32
  5. package/dist/KhrLauncher.d.ts +46 -0
  6. package/dist/KhrLauncher.js +316 -0
  7. package/dist/KhrLauncher.js.map +1 -0
  8. package/dist/armory/engine/assemblyVerifier.d.ts +48 -0
  9. package/dist/armory/engine/assemblyVerifier.js +443 -0
  10. package/dist/armory/engine/assemblyVerifier.js.map +1 -0
  11. package/dist/armory/engine/audioSynth.d.ts +26 -0
  12. package/dist/armory/engine/audioSynth.js +256 -0
  13. package/dist/armory/engine/audioSynth.js.map +1 -0
  14. package/dist/armory/engine/ballistics.d.ts +125 -0
  15. package/dist/armory/engine/ballistics.js +399 -0
  16. package/dist/armory/engine/ballistics.js.map +1 -0
  17. package/dist/armory/engine/bvhExploder.d.ts +43 -0
  18. package/dist/armory/engine/bvhExploder.js +326 -0
  19. package/dist/armory/engine/bvhExploder.js.map +1 -0
  20. package/dist/armory/engine/dispose.d.ts +6 -0
  21. package/dist/armory/engine/dispose.js +54 -0
  22. package/dist/armory/engine/dispose.js.map +1 -0
  23. package/dist/armory/engine/glbPhysicsExporter.d.ts +116 -0
  24. package/dist/armory/engine/glbPhysicsExporter.js +1960 -0
  25. package/dist/armory/engine/glbPhysicsExporter.js.map +1 -0
  26. package/dist/armory/engine/jointGraph.d.ts +5 -0
  27. package/dist/armory/engine/jointGraph.js +50 -0
  28. package/dist/armory/engine/jointGraph.js.map +1 -0
  29. package/dist/armory/engine/materials.d.ts +87 -0
  30. package/dist/armory/engine/materials.js +1089 -0
  31. package/dist/armory/engine/materials.js.map +1 -0
  32. package/dist/armory/engine/meshSegmenter.d.ts +44 -0
  33. package/dist/armory/engine/meshSegmenter.js +527 -0
  34. package/dist/armory/engine/meshSegmenter.js.map +1 -0
  35. package/dist/armory/engine/orthoExtruder.d.ts +33 -0
  36. package/dist/armory/engine/orthoExtruder.js +549 -0
  37. package/dist/armory/engine/orthoExtruder.js.map +1 -0
  38. package/dist/armory/engine/parts/boltRifleBuilder.d.ts +16 -0
  39. package/dist/armory/engine/parts/boltRifleBuilder.js +233 -0
  40. package/dist/armory/engine/parts/boltRifleBuilder.js.map +1 -0
  41. package/dist/armory/engine/parts/cadKernel.d.ts +39 -0
  42. package/dist/armory/engine/parts/cadKernel.js +367 -0
  43. package/dist/armory/engine/parts/cadKernel.js.map +1 -0
  44. package/dist/armory/engine/parts/fireControlGroup.d.ts +29 -0
  45. package/dist/armory/engine/parts/fireControlGroup.js +428 -0
  46. package/dist/armory/engine/parts/fireControlGroup.js.map +1 -0
  47. package/dist/armory/engine/parts/magazineBuilder.d.ts +14 -0
  48. package/dist/armory/engine/parts/magazineBuilder.js +146 -0
  49. package/dist/armory/engine/parts/magazineBuilder.js.map +1 -0
  50. package/dist/armory/engine/parts/muzzleDevices.d.ts +8 -0
  51. package/dist/armory/engine/parts/muzzleDevices.js +72 -0
  52. package/dist/armory/engine/parts/muzzleDevices.js.map +1 -0
  53. package/dist/armory/engine/parts/picatinnyRail.d.ts +49 -0
  54. package/dist/armory/engine/parts/picatinnyRail.js +474 -0
  55. package/dist/armory/engine/parts/picatinnyRail.js.map +1 -0
  56. package/dist/armory/engine/parts/pistolVariants.d.ts +28 -0
  57. package/dist/armory/engine/parts/pistolVariants.js +318 -0
  58. package/dist/armory/engine/parts/pistolVariants.js.map +1 -0
  59. package/dist/armory/engine/parts/revolverBuilder.d.ts +49 -0
  60. package/dist/armory/engine/parts/revolverBuilder.js +475 -0
  61. package/dist/armory/engine/parts/revolverBuilder.js.map +1 -0
  62. package/dist/armory/engine/proceduralGeometry.d.ts +113 -0
  63. package/dist/armory/engine/proceduralGeometry.js +1591 -0
  64. package/dist/armory/engine/proceduralGeometry.js.map +1 -0
  65. package/dist/armory/engine/renderState.d.ts +2 -0
  66. package/dist/armory/engine/renderState.js +20 -0
  67. package/dist/armory/engine/renderState.js.map +1 -0
  68. package/dist/armory/engine/simSolver.d.ts +127 -0
  69. package/dist/armory/engine/simSolver.js +736 -0
  70. package/dist/armory/engine/simSolver.js.map +1 -0
  71. package/dist/armory/engine/weaponSpecs.d.ts +277 -0
  72. package/dist/armory/engine/weaponSpecs.js +1311 -0
  73. package/dist/armory/engine/weaponSpecs.js.map +1 -0
  74. package/dist/armory/engine/webglContext.d.ts +1 -0
  75. package/dist/armory/engine/webglContext.js +14 -0
  76. package/dist/armory/engine/webglContext.js.map +1 -0
  77. package/dist/armory/types/physicsSchema.d.ts +205 -0
  78. package/dist/armory/types/physicsSchema.js +2 -0
  79. package/dist/armory/types/physicsSchema.js.map +1 -0
  80. package/dist/index.d.ts +7 -0
  81. package/dist/index.js +8 -0
  82. package/dist/index.js.map +1 -1
  83. package/dist/inertia.d.ts +3 -9
  84. package/dist/inertia.js +6 -6
  85. package/dist/inertia.js.map +1 -1
  86. package/dist/launcherKhr.d.ts +3 -9
  87. package/dist/launcherKhr.js +3 -15
  88. package/dist/launcherKhr.js.map +1 -1
  89. package/dist/launcherParts.d.ts +3 -8
  90. package/dist/launcherParts.js +19 -39
  91. package/dist/launcherParts.js.map +1 -1
  92. package/dist/react.d.ts +3 -0
  93. package/dist/react.js +4 -0
  94. package/dist/react.js.map +1 -0
  95. package/dist/recipes.d.ts +18 -12
  96. package/dist/recipes.js +103 -2
  97. package/dist/recipes.js.map +1 -1
  98. package/dist/runtime.js +3 -2
  99. package/dist/runtime.js.map +1 -1
  100. package/dist/schema.d.ts +2 -1
  101. package/dist/schema.js +18 -0
  102. package/dist/schema.js.map +1 -1
  103. package/dist/three.d.ts +54 -0
  104. package/dist/three.js +58 -0
  105. package/dist/three.js.map +1 -0
  106. package/docs/api-reference.md +49 -299
  107. package/package.json +63 -8
@@ -0,0 +1,1089 @@
1
+ import * as THREE from 'three';
2
+ let cachedBundle = null;
3
+ let trimSheetRefCount = 0;
4
+ const _wireTint = new THREE.Color();
5
+ const _wireLiftLight = new THREE.Color(0xe2e8f0);
6
+ function disposeBundleTextures(bundle) {
7
+ bundle.albedoTex.dispose();
8
+ bundle.normalTex.dispose();
9
+ bundle.roughnessTex.dispose();
10
+ bundle.maskTex.dispose();
11
+ bundle.checkerTex.dispose();
12
+ }
13
+ export function getTrimSheetRefCount() {
14
+ return trimSheetRefCount;
15
+ }
16
+ /**
17
+ * Explicitly releases the cached procedural trim-sheet textures immediately.
18
+ */
19
+ export function disposeTrimSheetBundle() {
20
+ if (cachedBundle) {
21
+ disposeBundleTextures(cachedBundle);
22
+ cachedBundle = null;
23
+ }
24
+ trimSheetRefCount = 0;
25
+ }
26
+ function acquireTrimSheetBundle() {
27
+ const b = getTrimSheetBundle();
28
+ if (b)
29
+ trimSheetRefCount += 1;
30
+ return b;
31
+ }
32
+ function releaseTrimSheetBundle() {
33
+ if (trimSheetRefCount > 0) {
34
+ trimSheetRefCount -= 1;
35
+ }
36
+ if (trimSheetRefCount === 0 && cachedBundle) {
37
+ disposeBundleTextures(cachedBundle);
38
+ cachedBundle = null;
39
+ }
40
+ }
41
+ /**
42
+ * Collects all `THREE.Texture` instances referenced by a material or material array
43
+ * (including standard PBR maps and `ShaderMaterial` uniform values).
44
+ */
45
+ export function collectMaterialTextures(material, target = new Set()) {
46
+ if (!material)
47
+ return target;
48
+ const list = Array.isArray(material) ? material : [material];
49
+ for (const mat of list) {
50
+ const rec = mat;
51
+ for (const val of Object.values(rec)) {
52
+ if (val instanceof THREE.Texture) {
53
+ target.add(val);
54
+ }
55
+ }
56
+ if (mat instanceof THREE.ShaderMaterial && mat.uniforms) {
57
+ for (const u of Object.values(mat.uniforms)) {
58
+ if (u && u.value instanceof THREE.Texture) {
59
+ target.add(u.value);
60
+ }
61
+ }
62
+ }
63
+ }
64
+ return target;
65
+ }
66
+ /**
67
+ * Collects all `THREE.Texture` instances referenced across an `Object3D` hierarchy.
68
+ */
69
+ export function collectObject3DTextures(root, target = new Set()) {
70
+ root.traverse((obj) => {
71
+ const meshLike = obj;
72
+ if (meshLike.material) {
73
+ collectMaterialTextures(meshLike.material, target);
74
+ }
75
+ });
76
+ return target;
77
+ }
78
+ /**
79
+ * Disposes all unique geometries, materials, and textures owned by an `Object3D` subtree.
80
+ * Supports `skipTextures` / `skipMaterials` sets when ownership of shared maps has transferred.
81
+ */
82
+ export function disposeObject3DResources(root, opts) {
83
+ const geos = new Set();
84
+ const mats = new Set();
85
+ const texs = new Set();
86
+ root.traverse((obj) => {
87
+ const meshLike = obj;
88
+ if (meshLike.geometry instanceof THREE.BufferGeometry) {
89
+ geos.add(meshLike.geometry);
90
+ }
91
+ if (meshLike.material) {
92
+ const mList = Array.isArray(meshLike.material) ? meshLike.material : [meshLike.material];
93
+ for (const m of mList) {
94
+ if (!opts?.skipMaterials?.has(m)) {
95
+ mats.add(m);
96
+ }
97
+ collectMaterialTextures(m, texs);
98
+ }
99
+ }
100
+ });
101
+ geos.forEach((g) => g.dispose());
102
+ let disposedTexCount = 0;
103
+ texs.forEach((t) => {
104
+ if (!opts?.skipTextures?.has(t)) {
105
+ t.dispose();
106
+ disposedTexCount += 1;
107
+ }
108
+ });
109
+ mats.forEach((m) => m.dispose());
110
+ return {
111
+ geometries: geos.size,
112
+ materials: mats.size,
113
+ textures: disposedTexCount,
114
+ };
115
+ }
116
+ /**
117
+ * Generates the unified HD 1024x1024 4-band trim sheet atlas (albedo, normal, roughness, mask).
118
+ *
119
+ * UV trim bands (v = 0 at bottom, v = 1 at top; canvas y = 0 at top, y = 1023 at bottom):
120
+ * - Band 3 (v in [0.75, 1.00]): Directional CNC-brushed / Parkerized ordnance steel
121
+ * - Band 2 (v in [0.50, 0.75]): High-definition 1:1 diamond laser-stippled polymer
122
+ * - Band 1 (v in [0.25, 0.50]): Hand-rubbed straight-grain walnut
123
+ * - Band 0 (v in [0.00, 0.25]): Machined slide serrations, ribs, and helical coils
124
+ */
125
+ export function getTrimSheetBundle() {
126
+ if (typeof document === 'undefined')
127
+ return null;
128
+ if (cachedBundle)
129
+ return cachedBundle;
130
+ const size = 1024;
131
+ const bandPx = size / 4;
132
+ const heights = new Float32Array(size * size);
133
+ let seed = 4242;
134
+ const rand = () => {
135
+ seed = (seed * 16807) % 2147483647;
136
+ return (seed - 1) / 2147483646;
137
+ };
138
+ const rowGrain = Array.from({ length: size }, () => rand() - 0.5);
139
+ const colGrain = Array.from({ length: size }, () => rand() - 0.5);
140
+ const albedoCanvas = document.createElement('canvas');
141
+ albedoCanvas.width = size;
142
+ albedoCanvas.height = size;
143
+ const aCtx = albedoCanvas.getContext('2d');
144
+ const aImg = aCtx.createImageData(size, size);
145
+ const roughnessCanvas = document.createElement('canvas');
146
+ roughnessCanvas.width = size;
147
+ roughnessCanvas.height = size;
148
+ const rCtx = roughnessCanvas.getContext('2d');
149
+ const rImg = rCtx.createImageData(size, size);
150
+ const maskCanvas = document.createElement('canvas');
151
+ maskCanvas.width = size;
152
+ maskCanvas.height = size;
153
+ const mCtx = maskCanvas.getContext('2d');
154
+ const mImg = mCtx.createImageData(size, size);
155
+ for (let y = 0; y < size; y++) {
156
+ const band = y < bandPx ? 3 : y < bandPx * 2 ? 2 : y < bandPx * 3 ? 1 : 0;
157
+ const localY = y % bandPx;
158
+ for (let x = 0; x < size; x++) {
159
+ let h = 0.55;
160
+ let shade = 236;
161
+ let roughByte = 200;
162
+ if (band === 3) {
163
+ const microHone = rowGrain[y] * 0.042 +
164
+ Math.sin(y * 1.15) * 0.014 +
165
+ Math.sin(y * 0.28 + Math.sin((x / size) * Math.PI * 4) * 0.25) * 0.011;
166
+ const phosphate = colGrain[(x * 3 + y * 7) % size] * 0.021;
167
+ const borderWear = localY < 9 ? (9 - localY) * 0.013 : localY > bandPx - 10 ? (localY - (bandPx - 10)) * 0.013 : 0;
168
+ h = 0.52 + microHone + phosphate + borderWear * 0.55;
169
+ shade = Math.round(227 + (microHone + phosphate) * 145 + borderWear * 185);
170
+ roughByte = Math.round(212 - (microHone + phosphate) * 185 - borderWear * 215);
171
+ }
172
+ else if (band === 2) {
173
+ const cell = 10;
174
+ const gx = x % cell;
175
+ const gy = localY % cell;
176
+ const rowShift = Math.floor(localY / cell) % 2 === 0 ? 0 : 5;
177
+ const cx = ((gx + rowShift) % cell) - 4.5;
178
+ const cy = gy - 4.5;
179
+ const manhattan = (Math.abs(cx) + Math.abs(cy)) / 5.4;
180
+ const pyramid = Math.max(0, Math.min(1, 1.08 - manhattan));
181
+ const flatTop = Math.min(0.86, pyramid);
182
+ const matteNoise = colGrain[(x * 5 + y * 13) % size] * 0.028;
183
+ h = 0.38 + flatTop * 0.28 + matteNoise;
184
+ shade = Math.round(196 + flatTop * 36 + matteNoise * 75);
185
+ roughByte = Math.round(246 - flatTop * 22);
186
+ }
187
+ else if (band === 1) {
188
+ const driftY = y + Math.sin((x / size) * Math.PI * 2) * 3.8 + colGrain[x] * 0.9;
189
+ const rowA = ((Math.floor(driftY) % size) + size) % size;
190
+ const rowB = (rowA + 1) % size;
191
+ const frac = driftY - Math.floor(driftY);
192
+ const fiberStreak = rowGrain[rowA] * (1 - frac) + rowGrain[rowB] * frac;
193
+ const broadGrowthRing = Math.sin((localY / bandPx) * Math.PI * 6.0 + Math.sin((x / size) * Math.PI * 2) * 0.35) *
194
+ 0.3;
195
+ const vesselPore = colGrain[(x + y * 19) % size] < -0.43 && (x + y * 3) % 11 < 2 ? -0.21 : 0;
196
+ const woodVal = broadGrowthRing * 0.48 + fiberStreak * 0.68 + vesselPore;
197
+ h = 0.48 + woodVal * 0.16;
198
+ shade = Math.round(205 + woodVal * 72);
199
+ roughByte = Math.round(210 - woodVal * 38 - vesselPore * 115);
200
+ }
201
+ else {
202
+ const period = 28;
203
+ const phase = ((x % period) + period) % period;
204
+ const normP = phase / period;
205
+ const crown = normP < 0.18
206
+ ? normP / 0.18
207
+ : normP < 0.58
208
+ ? 1.0
209
+ : normP < 0.76
210
+ ? 1.0 - (normP - 0.58) / 0.18
211
+ : 0.0;
212
+ const brush = rowGrain[y] * 0.025 + Math.sin(y * 1.4) * 0.008;
213
+ h = 0.18 + crown * 0.66 + brush;
214
+ shade = Math.round(132 + crown * 114 + brush * 85);
215
+ roughByte = Math.round(244 - crown * 64);
216
+ }
217
+ heights[y * size + x] = h;
218
+ const pIdx = (y * size + x) * 4;
219
+ const clampedShade = Math.max(118, Math.min(253, shade));
220
+ aImg.data[pIdx] = clampedShade;
221
+ aImg.data[pIdx + 1] = clampedShade;
222
+ aImg.data[pIdx + 2] = clampedShade;
223
+ aImg.data[pIdx + 3] = 255;
224
+ const clampedRough = Math.max(130, Math.min(255, roughByte));
225
+ rImg.data[pIdx] = clampedRough;
226
+ rImg.data[pIdx + 1] = clampedRough;
227
+ rImg.data[pIdx + 2] = clampedRough;
228
+ rImg.data[pIdx + 3] = 255;
229
+ const factor = 0.58 + h * 0.42;
230
+ const baseRgb = band === 3
231
+ ? [56, 189, 248]
232
+ : band === 2
233
+ ? [245, 158, 11]
234
+ : band === 1
235
+ ? [16, 185, 129]
236
+ : [168, 85, 247];
237
+ mImg.data[pIdx] = Math.min(255, Math.round(baseRgb[0] * factor));
238
+ mImg.data[pIdx + 1] = Math.min(255, Math.round(baseRgb[1] * factor));
239
+ mImg.data[pIdx + 2] = Math.min(255, Math.round(baseRgb[2] * factor));
240
+ mImg.data[pIdx + 3] = 255;
241
+ }
242
+ }
243
+ aCtx.putImageData(aImg, 0, 0);
244
+ rCtx.putImageData(rImg, 0, 0);
245
+ mCtx.putImageData(mImg, 0, 0);
246
+ mCtx.strokeStyle = 'rgba(11, 15, 23, 0.88)';
247
+ mCtx.lineWidth = 3;
248
+ [bandPx, bandPx * 2, bandPx * 3].forEach((py) => {
249
+ mCtx.beginPath();
250
+ mCtx.moveTo(0, py);
251
+ mCtx.lineTo(size, py);
252
+ mCtx.stroke();
253
+ });
254
+ const normalCanvas = document.createElement('canvas');
255
+ normalCanvas.width = size;
256
+ normalCanvas.height = size;
257
+ const nCtx = normalCanvas.getContext('2d');
258
+ const nImg = nCtx.createImageData(size, size);
259
+ const strength = 0.62;
260
+ const sampleH = (x, y) => {
261
+ const wx = ((x % size) + size) % size;
262
+ const bandStart = Math.floor(Math.max(0, Math.min(size - 1, y)) / bandPx) * bandPx;
263
+ const wy = Math.max(bandStart, Math.min(bandStart + bandPx - 1, y));
264
+ return heights[wy * size + wx];
265
+ };
266
+ for (let y = 0; y < size; y++) {
267
+ for (let x = 0; x < size; x++) {
268
+ const tl = sampleH(x - 1, y - 1);
269
+ const t = sampleH(x, y - 1);
270
+ const tr = sampleH(x + 1, y - 1);
271
+ const l = sampleH(x - 1, y);
272
+ const r = sampleH(x + 1, y);
273
+ const bl = sampleH(x - 1, y + 1);
274
+ const b = sampleH(x, y + 1);
275
+ const br = sampleH(x + 1, y + 1);
276
+ const dx = (tr + 2 * r + br - (tl + 2 * l + bl)) * strength;
277
+ const dy = (bl + 2 * b + br - (tl + 2 * t + tr)) * strength;
278
+ const nx = -dx;
279
+ const ny = -dy;
280
+ const nz = 1.0;
281
+ const invLen = 1.0 / Math.sqrt(nx * nx + ny * ny + nz * nz);
282
+ const pIdx = (y * size + x) * 4;
283
+ nImg.data[pIdx] = Math.round((nx * invLen * 0.5 + 0.5) * 255);
284
+ nImg.data[pIdx + 1] = Math.round((ny * invLen * 0.5 + 0.5) * 255);
285
+ nImg.data[pIdx + 2] = Math.round((nz * invLen * 0.5 + 0.5) * 255);
286
+ nImg.data[pIdx + 3] = 255;
287
+ }
288
+ }
289
+ nCtx.putImageData(nImg, 0, 0);
290
+ const checkerCanvas = document.createElement('canvas');
291
+ checkerCanvas.width = size;
292
+ checkerCanvas.height = size;
293
+ const cCtx = checkerCanvas.getContext('2d');
294
+ const gridCount = 32;
295
+ const cell = size / gridCount;
296
+ for (let cy = 0; cy < gridCount; cy++) {
297
+ for (let cx = 0; cx < gridCount; cx++) {
298
+ const even = (cx + cy) % 2 === 0;
299
+ cCtx.fillStyle = even ? '#1e293b' : '#475569';
300
+ cCtx.fillRect(cx * cell, cy * cell, cell, cell);
301
+ }
302
+ }
303
+ cCtx.strokeStyle = '#38bdf8';
304
+ cCtx.lineWidth = 3;
305
+ [bandPx, bandPx * 2, bandPx * 3].forEach((py) => {
306
+ cCtx.beginPath();
307
+ cCtx.moveTo(0, py);
308
+ cCtx.lineTo(size, py);
309
+ cCtx.stroke();
310
+ });
311
+ const makeTex = (canvas, srgb) => {
312
+ const tex = new THREE.CanvasTexture(canvas);
313
+ tex.colorSpace = srgb ? THREE.SRGBColorSpace : THREE.NoColorSpace;
314
+ tex.wrapS = THREE.RepeatWrapping;
315
+ tex.wrapT = THREE.ClampToEdgeWrapping;
316
+ tex.anisotropy = 16;
317
+ return tex;
318
+ };
319
+ cachedBundle = {
320
+ albedoCanvas,
321
+ normalCanvas,
322
+ roughnessCanvas,
323
+ maskCanvas,
324
+ checkerCanvas,
325
+ albedoTex: makeTex(albedoCanvas, true),
326
+ normalTex: makeTex(normalCanvas, false),
327
+ roughnessTex: makeTex(roughnessCanvas, false),
328
+ maskTex: makeTex(maskCanvas, true),
329
+ checkerTex: makeTex(checkerCanvas, true),
330
+ };
331
+ return cachedBundle;
332
+ }
333
+ export function exportTrimSheetPng(kind) {
334
+ const bundle = getTrimSheetBundle();
335
+ if (!bundle)
336
+ return;
337
+ const canvas = kind === 'mask'
338
+ ? bundle.maskCanvas
339
+ : kind === 'albedo'
340
+ ? bundle.albedoCanvas
341
+ : bundle.normalCanvas;
342
+ canvas.toBlob((blob) => {
343
+ if (!blob)
344
+ return;
345
+ const url = URL.createObjectURL(blob);
346
+ const a = document.createElement('a');
347
+ a.href = url;
348
+ a.download = `khr_armory_trim_${kind}_1024.png`;
349
+ document.body.appendChild(a);
350
+ a.click();
351
+ document.body.removeChild(a);
352
+ URL.revokeObjectURL(url);
353
+ }, 'image/png');
354
+ }
355
+ /**
356
+ * Generates an alpha-cutout RGBA silhouette texture + flat-shaded `MeshStandardMaterial`
357
+ * for the terminal `2-gon` (2-triangle quad) far-distance cartridge LOD.
358
+ */
359
+ export function createAmmoBillboardResources(payload) {
360
+ const w = 128;
361
+ const h = 256;
362
+ const data = new Uint8Array(w * h * 4);
363
+ const isShotgun = payload === 'hull-12ga';
364
+ const isRocket = payload === 'warhead-85mm';
365
+ const isGrenade = payload === 'grenade-40mm';
366
+ const isBottleneck = payload === 'spire-556' || payload === 'rifle-762';
367
+ const caseRgb = isShotgun
368
+ ? [185, 34, 34]
369
+ : isRocket
370
+ ? [82, 99, 67]
371
+ : [217, 171, 74];
372
+ const tipRgb = isShotgun
373
+ ? [155, 28, 28]
374
+ : isRocket
375
+ ? [75, 89, 66]
376
+ : isGrenade
377
+ ? [217, 138, 43]
378
+ : [196, 115, 63];
379
+ for (let py = 0; py < h; py++) {
380
+ const v = 1 - py / (h - 1);
381
+ let halfFrac = 0;
382
+ let isTip = false;
383
+ if (isRocket) {
384
+ isTip = v > 0.42;
385
+ if (v < 0.08)
386
+ halfFrac = 0.56;
387
+ else if (v < 0.42)
388
+ halfFrac = 0.42;
389
+ else if (v < 0.78)
390
+ halfFrac = 0.72 * Math.sin(((v - 0.34) / 0.52) * Math.PI * 0.65);
391
+ else
392
+ halfFrac = Math.max(0.08, 0.72 * (1 - (v - 0.78) / 0.24));
393
+ }
394
+ else if (isShotgun) {
395
+ isTip = v > 0.24;
396
+ halfFrac = v < 0.04 ? 0.76 : 0.68;
397
+ }
398
+ else if (isGrenade) {
399
+ isTip = v > 0.52;
400
+ halfFrac = v < 0.05 ? 0.76 : v < 0.52 ? 0.72 : 0.72 * Math.sqrt(Math.max(0, 1 - Math.pow((v - 0.52) / 0.48, 2)));
401
+ }
402
+ else if (isBottleneck) {
403
+ isTip = v > 0.72;
404
+ if (v < 0.04)
405
+ halfFrac = 0.74;
406
+ else if (v < 0.07)
407
+ halfFrac = 0.62;
408
+ else if (v < 0.56)
409
+ halfFrac = 0.72 - (v - 0.07) * 0.05;
410
+ else if (v < 0.66)
411
+ halfFrac = 0.69 - ((v - 0.56) / 0.1) * 0.22;
412
+ else if (v < 0.72)
413
+ halfFrac = 0.47;
414
+ else
415
+ halfFrac = 0.45 * Math.max(0, 1 - Math.pow((v - 0.72) / 0.28, 1.55));
416
+ }
417
+ else {
418
+ isTip = v > 0.66;
419
+ if (v < 0.04)
420
+ halfFrac = 0.74;
421
+ else if (v < 0.07)
422
+ halfFrac = 0.64;
423
+ else if (v < 0.66)
424
+ halfFrac = 0.71;
425
+ else
426
+ halfFrac = 0.68 * Math.max(0, 1 - Math.pow((v - 0.66) / 0.34, 1.65));
427
+ }
428
+ for (let px = 0; px < w; px++) {
429
+ const nx = (px / (w - 1)) * 2 - 1;
430
+ const idx = (py * w + px) * 4;
431
+ if (Math.abs(nx) <= halfFrac && halfFrac > 0.01) {
432
+ const cylHighlight = Math.sqrt(Math.max(0.08, 1 - Math.pow(nx / Math.max(0.05, halfFrac), 2)));
433
+ const shade = 0.58 + 0.46 * cylHighlight;
434
+ const base = isTip ? tipRgb : caseRgb;
435
+ data[idx] = Math.min(255, Math.round(base[0] * shade));
436
+ data[idx + 1] = Math.min(255, Math.round(base[1] * shade));
437
+ data[idx + 2] = Math.min(255, Math.round(base[2] * shade));
438
+ data[idx + 3] = 255;
439
+ }
440
+ else {
441
+ data[idx] = 0;
442
+ data[idx + 1] = 0;
443
+ data[idx + 2] = 0;
444
+ data[idx + 3] = 0;
445
+ }
446
+ }
447
+ }
448
+ let texture;
449
+ if (typeof document !== 'undefined') {
450
+ const canvas = document.createElement('canvas');
451
+ canvas.width = w;
452
+ canvas.height = h;
453
+ const ctx = canvas.getContext('2d');
454
+ const imgData = ctx.createImageData(w, h);
455
+ imgData.data.set(data);
456
+ ctx.putImageData(imgData, 0, 0);
457
+ const cTex = new THREE.CanvasTexture(canvas);
458
+ cTex.colorSpace = THREE.SRGBColorSpace;
459
+ cTex.anisotropy = 16;
460
+ texture = cTex;
461
+ }
462
+ else {
463
+ const dTex = new THREE.DataTexture(data, w, h, THREE.RGBAFormat);
464
+ dTex.colorSpace = THREE.SRGBColorSpace;
465
+ dTex.flipY = true;
466
+ dTex.needsUpdate = true;
467
+ texture = dTex;
468
+ }
469
+ const material = new THREE.MeshStandardMaterial({
470
+ name: `Mat_AmmoBillboard2Gon_${payload}`,
471
+ map: typeof document !== 'undefined' ? texture : null,
472
+ alphaTest: 0.5,
473
+ side: THREE.DoubleSide,
474
+ roughness: 0.34,
475
+ metalness: isShotgun ? 0.12 : 0.78,
476
+ flatShading: true,
477
+ });
478
+ return {
479
+ texture,
480
+ material,
481
+ dispose: () => {
482
+ material.dispose();
483
+ texture.dispose();
484
+ },
485
+ };
486
+ }
487
+ export function createArmoryMaterials(initialFinish = 'parkerized') {
488
+ const bundle = acquireTrimSheetBundle();
489
+ const sharedBundleTextures = new Set(bundle
490
+ ? [
491
+ bundle.albedoTex,
492
+ bundle.normalTex,
493
+ bundle.roughnessTex,
494
+ bundle.maskTex,
495
+ bundle.checkerTex,
496
+ ]
497
+ : []);
498
+ const albedoMap = bundle?.albedoTex ?? null;
499
+ const normalMap = bundle?.normalTex ?? null;
500
+ const roughnessMap = bundle?.roughnessTex ?? null;
501
+ const receiverShell = new THREE.MeshStandardMaterial({
502
+ name: 'Mat_ReceiverSteel_4140',
503
+ color: 0x3b424c,
504
+ map: albedoMap,
505
+ normalMap,
506
+ roughnessMap,
507
+ normalScale: new THREE.Vector2(0.18, 0.18),
508
+ roughness: 0.42,
509
+ metalness: 0.68,
510
+ });
511
+ const receiverXray = new THREE.MeshStandardMaterial({
512
+ name: 'Mat_ReceiverXray',
513
+ color: 0x38bdf8,
514
+ emissive: 0x0c4a6e,
515
+ emissiveIntensity: 0.35,
516
+ roughness: 0.2,
517
+ metalness: 0.1,
518
+ transparent: true,
519
+ opacity: 0.16,
520
+ depthWrite: false,
521
+ side: THREE.DoubleSide,
522
+ });
523
+ const slideSteel = new THREE.MeshStandardMaterial({
524
+ name: 'Mat_SlideMachinedSteel',
525
+ color: 0x586270,
526
+ map: albedoMap,
527
+ normalMap,
528
+ roughnessMap,
529
+ normalScale: new THREE.Vector2(0.2, 0.2),
530
+ roughness: 0.29,
531
+ metalness: 0.78,
532
+ });
533
+ const darkGunmetal = new THREE.MeshStandardMaterial({
534
+ name: 'Mat_DarkGunmetalNitride',
535
+ color: 0x262b33,
536
+ map: albedoMap,
537
+ normalMap,
538
+ roughnessMap,
539
+ normalScale: new THREE.Vector2(0.18, 0.18),
540
+ roughness: 0.36,
541
+ metalness: 0.72,
542
+ });
543
+ const machinedRail = new THREE.MeshStandardMaterial({
544
+ name: 'Mat_PicatinnyRail_7075T6',
545
+ color: 0x464e59,
546
+ map: albedoMap,
547
+ normalMap,
548
+ roughnessMap,
549
+ normalScale: new THREE.Vector2(0.16, 0.16),
550
+ roughness: 0.33,
551
+ metalness: 0.74,
552
+ });
553
+ const polymerGrip = new THREE.MeshStandardMaterial({
554
+ name: 'Mat_PolymerGrip_Stippled',
555
+ color: 0x22262d,
556
+ map: albedoMap,
557
+ normalMap,
558
+ roughnessMap,
559
+ normalScale: new THREE.Vector2(0.22, 0.22),
560
+ roughness: 0.78,
561
+ metalness: 0.04,
562
+ });
563
+ const woodForend = new THREE.MeshStandardMaterial({
564
+ name: 'Mat_WalnutForend',
565
+ color: 0x7c4724,
566
+ map: albedoMap,
567
+ normalMap,
568
+ roughnessMap,
569
+ normalScale: new THREE.Vector2(0.18, 0.18),
570
+ roughness: 0.44,
571
+ metalness: 0.02,
572
+ });
573
+ const oliveTube = new THREE.MeshStandardMaterial({
574
+ name: 'Mat_OliveDrabSteel',
575
+ color: 0x4b5942,
576
+ map: albedoMap,
577
+ normalMap,
578
+ roughnessMap,
579
+ normalScale: new THREE.Vector2(0.16, 0.16),
580
+ roughness: 0.48,
581
+ metalness: 0.36,
582
+ });
583
+ // PVD gold-bronze finish for internal mechanism parts
584
+ const internalMechanism = new THREE.MeshStandardMaterial({
585
+ name: 'Mat_FCG_TiN_Mechanism',
586
+ color: 0xc99732,
587
+ map: albedoMap,
588
+ normalMap,
589
+ roughnessMap,
590
+ normalScale: new THREE.Vector2(0.14, 0.14),
591
+ roughness: 0.28,
592
+ metalness: 0.88,
593
+ });
594
+ const brass = new THREE.MeshStandardMaterial({
595
+ name: 'Mat_CartridgeBrass_C260',
596
+ color: 0xd9ab4a,
597
+ roughness: 0.24,
598
+ metalness: 0.9,
599
+ });
600
+ const copperTip = new THREE.MeshStandardMaterial({
601
+ name: 'Mat_CopperJacket_FMJ',
602
+ color: 0xc4733f,
603
+ roughness: 0.28,
604
+ metalness: 0.85,
605
+ });
606
+ const shotgunHullRed = new THREE.MeshStandardMaterial({
607
+ name: 'Mat_12GaHull_Polymer',
608
+ color: 0xb92222,
609
+ roughness: 0.52,
610
+ metalness: 0.06,
611
+ });
612
+ const warheadOlive = new THREE.MeshStandardMaterial({
613
+ name: 'Mat_WarheadOlive',
614
+ color: 0x526343,
615
+ roughness: 0.44,
616
+ metalness: 0.34,
617
+ });
618
+ const smokeCanisterAmber = new THREE.MeshStandardMaterial({
619
+ name: 'Mat_SmokeCanister40mm_Amber',
620
+ color: 0xd98a2b,
621
+ roughness: 0.38,
622
+ metalness: 0.48,
623
+ });
624
+ const emissiveAccent = new THREE.MeshStandardMaterial({
625
+ name: 'Mat_OpticEmissiveAccent',
626
+ color: 0x38bdf8,
627
+ emissive: 0x38bdf8,
628
+ emissiveIntensity: 1.05,
629
+ roughness: 0.25,
630
+ metalness: 0.2,
631
+ });
632
+ const uvMaskMat = new THREE.MeshBasicMaterial({
633
+ name: 'Mat_UV_Mask_IDs',
634
+ map: bundle?.maskTex ?? null,
635
+ });
636
+ const uvCheckerMat = new THREE.MeshStandardMaterial({
637
+ name: 'Mat_UV_Checkerboard',
638
+ map: bundle?.checkerTex ?? null,
639
+ roughness: 0.55,
640
+ metalness: 0.1,
641
+ });
642
+ const redDotShader = new THREE.ShaderMaterial({
643
+ uniforms: { uTime: { value: 0 } },
644
+ vertexShader: `
645
+ varying vec2 vUv;
646
+ void main() {
647
+ vUv = uv;
648
+ gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
649
+ }
650
+ `,
651
+ fragmentShader: `
652
+ uniform float uTime;
653
+ varying vec2 vUv;
654
+ void main() {
655
+ vec2 p = vUv - vec2(0.5);
656
+ float r = length(p);
657
+ float dotCore = smoothstep(0.07, 0.018, r);
658
+ float halo = smoothstep(0.18, 0.04, r) * 0.4;
659
+ float ret = clamp(dotCore + halo, 0.0, 1.0);
660
+ vec3 col = mix(vec3(0.08, 0.06, 0.08), vec3(1.0, 0.16, 0.32) * 2.0, ret);
661
+ gl_FragColor = vec4(col, max(0.15, ret));
662
+ }
663
+ `,
664
+ transparent: true,
665
+ depthWrite: false,
666
+ side: THREE.DoubleSide,
667
+ });
668
+ const holoShader = new THREE.ShaderMaterial({
669
+ uniforms: { uTime: { value: 0 } },
670
+ vertexShader: `
671
+ varying vec2 vUv;
672
+ void main() {
673
+ vUv = uv;
674
+ gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
675
+ }
676
+ `,
677
+ fragmentShader: `
678
+ uniform float uTime;
679
+ varying vec2 vUv;
680
+ void main() {
681
+ vec2 p = vUv - vec2(0.5);
682
+ float r = length(p);
683
+ float a = atan(p.y, p.x);
684
+ float cDot = smoothstep(0.048, 0.02, r);
685
+ float ring = smoothstep(0.024, 0.006, abs(r - 0.27)) * step(0.18, abs(sin(a * 2.0)));
686
+ float ticks = step(0.3, abs(p.x)) * step(abs(p.x), 0.4) * smoothstep(0.022, 0.006, abs(p.y))
687
+ + step(0.3, abs(p.y)) * step(abs(p.y), 0.4) * smoothstep(0.022, 0.006, abs(p.x));
688
+ float ret = clamp(cDot + ring + ticks, 0.0, 1.0);
689
+ vec3 col = mix(vec3(0.06, 0.16, 0.24), vec3(0.22, 0.78, 1.0) * 1.9, ret);
690
+ gl_FragColor = vec4(col, max(0.16, ret * 0.95));
691
+ }
692
+ `,
693
+ transparent: true,
694
+ depthWrite: false,
695
+ side: THREE.DoubleSide,
696
+ });
697
+ const zoomScopeShader = new THREE.ShaderMaterial({
698
+ uniforms: {
699
+ uTime: { value: 0 },
700
+ uScopeTex: { value: null },
701
+ uHasFeed: { value: 0.0 },
702
+ uZoom: { value: 8.0 },
703
+ },
704
+ vertexShader: `
705
+ varying vec2 vUv;
706
+ void main() {
707
+ vUv = uv;
708
+ gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
709
+ }
710
+ `,
711
+ fragmentShader: `
712
+ uniform float uTime;
713
+ uniform sampler2D uScopeTex;
714
+ uniform float uHasFeed;
715
+ uniform float uZoom;
716
+ varying vec2 vUv;
717
+
718
+ void main() {
719
+ vec2 p = vUv - vec2(0.5);
720
+ float r = length(p);
721
+ float circleMask = smoothstep(0.5, 0.472, r);
722
+ if (circleMask <= 0.01) discard;
723
+
724
+ // Subtle optical lens pincushion + glass edge chromatic tint
725
+ vec2 distUv = vec2(0.5) + p * (1.0 + r * r * 0.24);
726
+ vec3 sceneCol = vec3(0.05, 0.07, 0.10);
727
+ if (uHasFeed > 0.5) {
728
+ float ca = r * 0.008;
729
+ float cr = texture2D(uScopeTex, distUv + vec2(ca, 0.0)).r;
730
+ float cg = texture2D(uScopeTex, distUv).g;
731
+ float cb = texture2D(uScopeTex, distUv - vec2(ca, 0.0)).b;
732
+ sceneCol = vec3(cr, cg, cb) * 1.08;
733
+ } else {
734
+ float grad = 0.22 + 0.18 * (1.0 - r * 1.4);
735
+ sceneCol = vec3(0.06, 0.12, 0.17) * grad;
736
+ }
737
+
738
+ // First-Focal-Plane Mil-Dot reticle + BDC holdover stadia
739
+ float fineH = smoothstep(0.0055, 0.0018, abs(p.y)) * step(abs(p.x), 0.44);
740
+ float fineV = smoothstep(0.0055, 0.0018, abs(p.x)) * step(abs(p.y), 0.44);
741
+ float heavyH = smoothstep(0.014, 0.006, abs(p.y)) * step(0.24, abs(p.x)) * step(abs(p.x), 0.47);
742
+ float heavyV = smoothstep(0.014, 0.006, abs(p.x)) * step(0.24, abs(p.y)) * step(abs(p.y), 0.47);
743
+
744
+ // Mil-dot stadia ticks along horizontal and vertical axes
745
+ float tickSpacing = 0.065;
746
+ float tx = abs(mod(p.x + tickSpacing * 0.5, tickSpacing) - tickSpacing * 0.5);
747
+ float ty = abs(mod(p.y + tickSpacing * 0.5, tickSpacing) - tickSpacing * 0.5);
748
+ float hTicks = smoothstep(0.0055, 0.002, tx) * step(abs(p.y), 0.022) * step(0.04, abs(p.x)) * step(abs(p.x), 0.23);
749
+ float vTicks = smoothstep(0.0055, 0.002, ty) * step(abs(p.x), 0.022) * step(0.04, abs(p.y)) * step(abs(p.y), 0.23);
750
+
751
+ // Illuminated center aimpoint chevron/dot
752
+ float centerDot = smoothstep(0.015, 0.005, r);
753
+ float blackRet = clamp(fineH + fineV + heavyH + heavyV + hTicks + vTicks, 0.0, 1.0);
754
+
755
+ // Eye-box scope shadow vignette & anti-reflective cyan coating rim
756
+ float eyeShadow = smoothstep(0.495, 0.36, r);
757
+ vec3 col = sceneCol * (0.28 + 0.72 * eyeShadow);
758
+ col = mix(col, vec3(0.02, 0.02, 0.03), blackRet * 0.92);
759
+ col = mix(col, vec3(1.0, 0.22, 0.26) * 1.45, centerDot);
760
+ col += vec3(0.08, 0.34, 0.44) * smoothstep(0.41, 0.48, r) * 0.45;
761
+
762
+ gl_FragColor = vec4(col, circleMask * 0.98);
763
+ }
764
+ `,
765
+ transparent: true,
766
+ depthWrite: false,
767
+ side: THREE.DoubleSide,
768
+ });
769
+ const thermalIrShader = new THREE.ShaderMaterial({
770
+ uniforms: {
771
+ uTime: { value: 0 },
772
+ uScopeTex: { value: null },
773
+ uHasFeed: { value: 0.0 },
774
+ uPalette: { value: 0.0 }, // 0 = Ironbow, 1 = White-Hot, 2 = NV Green
775
+ },
776
+ vertexShader: `
777
+ varying vec2 vUv;
778
+ void main() {
779
+ vUv = uv;
780
+ gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
781
+ }
782
+ `,
783
+ fragmentShader: `
784
+ uniform float uTime;
785
+ uniform sampler2D uScopeTex;
786
+ uniform float uHasFeed;
787
+ uniform float uPalette;
788
+ varying vec2 vUv;
789
+
790
+ vec3 ironbow(float h) {
791
+ vec3 c0 = vec3(0.04, 0.02, 0.16);
792
+ vec3 c1 = vec3(0.32, 0.04, 0.46);
793
+ vec3 c2 = vec3(0.84, 0.22, 0.14);
794
+ vec3 c3 = vec3(0.99, 0.78, 0.18);
795
+ vec3 c4 = vec3(1.00, 0.98, 0.94);
796
+ if (h < 0.28) return mix(c0, c1, h / 0.28);
797
+ if (h < 0.56) return mix(c1, c2, (h - 0.28) / 0.28);
798
+ if (h < 0.82) return mix(c2, c3, (h - 0.56) / 0.26);
799
+ return mix(c3, c4, clamp((h - 0.82) / 0.18, 0.0, 1.0));
800
+ }
801
+
802
+ void main() {
803
+ vec2 p = vUv - vec2(0.5);
804
+ float r = length(p);
805
+ float mask = smoothstep(0.5, 0.47, r);
806
+ if (mask <= 0.01) discard;
807
+
808
+ float heat = 0.08;
809
+ if (uHasFeed > 0.5) {
810
+ vec3 raw = texture2D(uScopeTex, vUv).rgb;
811
+ // Emissive warm targets (high red/orange/yellow) spike sharply into white-hot FLIR signatures
812
+ float luma = dot(raw, vec3(0.299, 0.587, 0.114));
813
+ float warmBoost = max(0.0, raw.r - raw.b * 0.65) * 1.45 + max(0.0, raw.r + raw.g - 1.1) * 0.9;
814
+ heat = clamp(luma * 0.62 + warmBoost * 0.75, 0.04, 1.0);
815
+ } else {
816
+ float angle = atan(p.y, p.x);
817
+ float sweepAngle = mod(uTime * 1.8, 6.28318) - 3.14159;
818
+ float diff = mod(angle - sweepAngle + 6.28318, 6.28318);
819
+ heat = clamp(0.14 + smoothstep(0.95, 0.0, diff) * 0.52, 0.0, 1.0);
820
+ }
821
+
822
+ // Subtle Dreamcast++/PS2 microbolometer scanline & sensor noise
823
+ float scan = 0.93 + 0.07 * sin(vUv.y * 190.0 + uTime * 3.0);
824
+ float grain = (fract(sin(dot(vUv * 120.0 + uTime, vec2(12.9898, 78.233))) * 43758.5453) - 0.5) * 0.045;
825
+ heat = clamp(heat * scan + grain, 0.0, 1.0);
826
+
827
+ vec3 col;
828
+ if (uPalette < 0.5) {
829
+ col = ironbow(heat);
830
+ } else if (uPalette < 1.5) {
831
+ col = vec3(pow(heat, 0.85));
832
+ } else {
833
+ col = mix(vec3(0.01, 0.07, 0.03), vec3(0.26, 1.0, 0.48), pow(heat, 0.88));
834
+ }
835
+
836
+ // Digital FLIR reticle brackets + center gap crosshair
837
+ float crossH = smoothstep(0.008, 0.002, abs(p.y)) * step(0.05, abs(p.x)) * step(abs(p.x), 0.28);
838
+ float crossV = smoothstep(0.008, 0.002, abs(p.x)) * step(0.05, abs(p.y)) * step(abs(p.y), 0.28);
839
+ float boxEdgeX = step(0.29, abs(p.x)) * step(abs(p.x), 0.31) * step(0.16, abs(p.y)) * step(abs(p.y), 0.31);
840
+ float boxEdgeY = step(0.29, abs(p.y)) * step(abs(p.y), 0.31) * step(0.16, abs(p.x)) * step(abs(p.x), 0.31);
841
+ float hudMask = clamp(crossH + crossV + boxEdgeX + boxEdgeY, 0.0, 1.0);
842
+ vec3 hudCol = uPalette < 0.5 ? vec3(0.32, 0.98, 0.82) : uPalette < 1.5 ? vec3(0.95, 0.26, 0.22) : vec3(0.85, 1.0, 0.9);
843
+ col = mix(col, hudCol, hudMask * 0.86);
844
+
845
+ float eyeVig = smoothstep(0.5, 0.39, r);
846
+ col *= 0.32 + 0.68 * eyeVig;
847
+
848
+ gl_FragColor = vec4(col, mask * 0.98);
849
+ }
850
+ `,
851
+ transparent: true,
852
+ depthWrite: false,
853
+ side: THREE.DoubleSide,
854
+ });
855
+ const applyFinishPreset = (finish) => {
856
+ if (finish === 'stainless') {
857
+ // Two-Tone 416R Brushed Stainless Slide + Blued Ordnance Frame + Smoked Walnut
858
+ receiverShell.color.setHex(0x272c33);
859
+ receiverShell.roughness = 0.44;
860
+ receiverShell.metalness = 0.78;
861
+ slideSteel.color.setHex(0xbcc4ce);
862
+ slideSteel.roughness = 0.23;
863
+ slideSteel.metalness = 0.95;
864
+ darkGunmetal.color.setHex(0x1d2026);
865
+ darkGunmetal.roughness = 0.35;
866
+ darkGunmetal.metalness = 0.86;
867
+ machinedRail.color.setHex(0x8a939e);
868
+ machinedRail.roughness = 0.26;
869
+ machinedRail.metalness = 0.92;
870
+ polymerGrip.color.setHex(0x1a1c20);
871
+ polymerGrip.roughness = 0.84;
872
+ polymerGrip.metalness = 0.04;
873
+ woodForend.color.setHex(0x5e3319);
874
+ woodForend.roughness = 0.46;
875
+ woodForend.metalness = 0.02;
876
+ oliveTube.color.setHex(0x4b5446);
877
+ oliveTube.roughness = 0.48;
878
+ oliveTube.metalness = 0.52;
879
+ }
880
+ else if (finish === 'blackout') {
881
+ // Midnight Melonite QPQ Nitride + Stealth Carbon Polymer + Ebonized Walnut
882
+ receiverShell.color.setHex(0x181b20);
883
+ receiverShell.roughness = 0.38;
884
+ receiverShell.metalness = 0.82;
885
+ slideSteel.color.setHex(0x23272f);
886
+ slideSteel.roughness = 0.29;
887
+ slideSteel.metalness = 0.9;
888
+ darkGunmetal.color.setHex(0x131519);
889
+ darkGunmetal.roughness = 0.34;
890
+ darkGunmetal.metalness = 0.86;
891
+ machinedRail.color.setHex(0x292e36);
892
+ machinedRail.roughness = 0.32;
893
+ machinedRail.metalness = 0.86;
894
+ polymerGrip.color.setHex(0x131518);
895
+ polymerGrip.roughness = 0.86;
896
+ polymerGrip.metalness = 0.03;
897
+ woodForend.color.setHex(0x36241a);
898
+ woodForend.roughness = 0.52;
899
+ woodForend.metalness = 0.02;
900
+ oliveTube.color.setHex(0x232922);
901
+ oliveTube.roughness = 0.5;
902
+ oliveTube.metalness = 0.46;
903
+ }
904
+ else if (finish === 'fde-tan') {
905
+ // Cerakote H-265 Flat Dark Earth + Burnt Bronze Upper + Coyote Polymer
906
+ receiverShell.color.setHex(0x9a8260);
907
+ receiverShell.roughness = 0.58;
908
+ receiverShell.metalness = 0.22;
909
+ slideSteel.color.setHex(0x786449);
910
+ slideSteel.roughness = 0.42;
911
+ slideSteel.metalness = 0.54;
912
+ darkGunmetal.color.setHex(0x282623);
913
+ darkGunmetal.roughness = 0.38;
914
+ darkGunmetal.metalness = 0.82;
915
+ machinedRail.color.setHex(0x63533d);
916
+ machinedRail.roughness = 0.4;
917
+ machinedRail.metalness = 0.62;
918
+ polymerGrip.color.setHex(0x846f50);
919
+ polymerGrip.roughness = 0.84;
920
+ polymerGrip.metalness = 0.04;
921
+ woodForend.color.setHex(0x784626);
922
+ woodForend.roughness = 0.48;
923
+ woodForend.metalness = 0.02;
924
+ oliveTube.color.setHex(0x7d7052);
925
+ oliveTube.roughness = 0.56;
926
+ oliveTube.metalness = 0.28;
927
+ }
928
+ else {
929
+ receiverShell.color.setHex(0x3b424c);
930
+ receiverShell.roughness = 0.42;
931
+ receiverShell.metalness = 0.68;
932
+ slideSteel.color.setHex(0x586270);
933
+ slideSteel.roughness = 0.29;
934
+ slideSteel.metalness = 0.78;
935
+ darkGunmetal.color.setHex(0x262b33);
936
+ darkGunmetal.roughness = 0.36;
937
+ darkGunmetal.metalness = 0.72;
938
+ machinedRail.color.setHex(0x464e59);
939
+ machinedRail.roughness = 0.33;
940
+ machinedRail.metalness = 0.74;
941
+ polymerGrip.color.setHex(0x22262d);
942
+ polymerGrip.roughness = 0.78;
943
+ polymerGrip.metalness = 0.04;
944
+ woodForend.color.setHex(0x7c4724);
945
+ woodForend.roughness = 0.44;
946
+ woodForend.metalness = 0.02;
947
+ oliveTube.color.setHex(0x4b5942);
948
+ oliveTube.roughness = 0.48;
949
+ oliveTube.metalness = 0.36;
950
+ }
951
+ };
952
+ const syncMaterialWireframe = (m, isWire) => {
953
+ if (m.userData.baseEmissiveHex === undefined) {
954
+ m.userData.baseEmissiveHex = m.emissive.getHex();
955
+ m.userData.baseEmissiveIntensity = m.emissiveIntensity;
956
+ }
957
+ m.wireframe = isWire;
958
+ if (isWire) {
959
+ _wireTint.copy(m.color).lerp(_wireLiftLight, 0.48);
960
+ m.emissive.copy(_wireTint);
961
+ m.emissiveIntensity = 0.88;
962
+ }
963
+ else {
964
+ m.emissive.setHex(m.userData.baseEmissiveHex);
965
+ m.emissiveIntensity = m.userData.baseEmissiveIntensity;
966
+ }
967
+ };
968
+ const solidMats = [
969
+ receiverShell,
970
+ slideSteel,
971
+ darkGunmetal,
972
+ machinedRail,
973
+ polymerGrip,
974
+ woodForend,
975
+ oliveTube,
976
+ internalMechanism,
977
+ brass,
978
+ copperTip,
979
+ shotgunHullRed,
980
+ warheadOlive,
981
+ smokeCanisterAmber,
982
+ emissiveAccent,
983
+ ];
984
+ const applyFinishWithWireSync = (finish) => {
985
+ applyFinishPreset(finish);
986
+ solidMats.forEach((m) => {
987
+ if (m.wireframe) {
988
+ syncMaterialWireframe(m, true);
989
+ }
990
+ });
991
+ };
992
+ applyFinishWithWireSync(initialFinish);
993
+ solidMats.forEach((m) => {
994
+ m.flatShading = true;
995
+ m.userData.baseEmissiveHex = m.emissive.getHex();
996
+ m.userData.baseEmissiveIntensity = m.emissiveIntensity;
997
+ m.needsUpdate = true;
998
+ });
999
+ receiverXray.flatShading = true;
1000
+ uvCheckerMat.flatShading = true;
1001
+ const applyUvInspectMode = (mode, root, xrayReceiver, receiverMeshes) => {
1002
+ const isWire = mode === 'wireframe';
1003
+ solidMats.forEach((m) => {
1004
+ syncMaterialWireframe(m, isWire);
1005
+ });
1006
+ const receiverSet = new Set(receiverMeshes);
1007
+ root.traverse((obj) => {
1008
+ if (!(obj instanceof THREE.Mesh))
1009
+ return;
1010
+ if (obj.userData.opticLensType)
1011
+ return; // Keep optical shaders transparent
1012
+ if (!obj.userData.basePbrMat) {
1013
+ obj.userData.basePbrMat = obj.material;
1014
+ }
1015
+ const baseMat = obj.userData.basePbrMat;
1016
+ if (baseMat instanceof THREE.MeshStandardMaterial && !solidMats.includes(baseMat)) {
1017
+ syncMaterialWireframe(baseMat, isWire);
1018
+ }
1019
+ if (mode === 'uv-mask') {
1020
+ obj.material = uvMaskMat;
1021
+ }
1022
+ else if (mode === 'uv-checker') {
1023
+ obj.material = uvCheckerMat;
1024
+ }
1025
+ else if (receiverSet.has(obj) && xrayReceiver) {
1026
+ obj.material = receiverXray;
1027
+ }
1028
+ else {
1029
+ obj.material = baseMat;
1030
+ }
1031
+ });
1032
+ };
1033
+ let isDisposed = false;
1034
+ const dispose = () => {
1035
+ if (isDisposed)
1036
+ return;
1037
+ isDisposed = true;
1038
+ const allOwnedMats = [
1039
+ ...solidMats,
1040
+ receiverXray,
1041
+ uvMaskMat,
1042
+ uvCheckerMat,
1043
+ redDotShader,
1044
+ holoShader,
1045
+ zoomScopeShader,
1046
+ thermalIrShader,
1047
+ ];
1048
+ const perRigTextures = new Set();
1049
+ for (const m of allOwnedMats) {
1050
+ collectMaterialTextures(m, perRigTextures);
1051
+ }
1052
+ perRigTextures.forEach((tex) => {
1053
+ if (!sharedBundleTextures.has(tex)) {
1054
+ tex.dispose();
1055
+ }
1056
+ });
1057
+ allOwnedMats.forEach((m) => m.dispose());
1058
+ if (bundle) {
1059
+ releaseTrimSheetBundle();
1060
+ }
1061
+ };
1062
+ return {
1063
+ receiverShell,
1064
+ receiverXray,
1065
+ slideSteel,
1066
+ darkGunmetal,
1067
+ machinedRail,
1068
+ polymerGrip,
1069
+ woodForend,
1070
+ oliveTube,
1071
+ internalMechanism,
1072
+ brass,
1073
+ copperTip,
1074
+ shotgunHullRed,
1075
+ warheadOlive,
1076
+ smokeCanisterAmber,
1077
+ emissiveAccent,
1078
+ uvMaskMat,
1079
+ uvCheckerMat,
1080
+ redDotShader,
1081
+ holoShader,
1082
+ zoomScopeShader,
1083
+ thermalIrShader,
1084
+ applyFinishPreset: applyFinishWithWireSync,
1085
+ applyUvInspectMode,
1086
+ dispose,
1087
+ };
1088
+ }
1089
+ //# sourceMappingURL=materials.js.map