reze-engine 0.41.2 → 0.41.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -78,7 +78,8 @@ engine/src/
78
78
  pmx-loader.ts PMX parser: mesh, bones, morphs, rigid bodies, joints
79
79
  vmd-loader.ts VMD motion parser · vmd-writer.ts VMD export (Shift-JIS)
80
80
  asset-reader.ts URL + local-folder asset resolution · folder-upload.ts
81
- tga-loader.ts TGA decoder (formats createImageBitmap can't read)
81
+ tga-loader.ts TGA decoder · dds-loader.ts DDS/BC1-3 · psd-loader.ts PSD
82
+ composite — the texture formats createImageBitmap can't read
82
83
  index.ts public exports
83
84
 
84
85
  graph/ shader-graph → WGSL compiler — materials as data
@@ -0,0 +1,12 @@
1
+ import type { DecodedImage } from "./tga-loader";
2
+ /** True when these bytes are a DDS, by magic rather than by file extension. */
3
+ export declare function isDds(buffer: ArrayBuffer): boolean;
4
+ /**
5
+ * Decode the top mip of a DDS to RGBA8.
6
+ *
7
+ * Only the first surface: the engine generates its own mip chain, and a cube map
8
+ * or an array reaching here is a texture slot that was never going to mean what
9
+ * the file meant anyway.
10
+ */
11
+ export declare function decodeDds(buffer: ArrayBuffer): DecodedImage;
12
+ //# sourceMappingURL=dds-loader.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dds-loader.d.ts","sourceRoot":"","sources":["../src/dds-loader.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAkBhD,+EAA+E;AAC/E,wBAAgB,KAAK,CAAC,MAAM,EAAE,WAAW,GAAG,OAAO,CAElD;AAmGD;;;;;;GAMG;AACH,wBAAgB,SAAS,CAAC,MAAM,EAAE,WAAW,GAAG,YAAY,CA+F3D"}
@@ -0,0 +1,246 @@
1
+ // DDS → RGBA8, decoded on the CPU.
2
+ //
3
+ // Stage models converted out of games ship their textures as DDS far more often
4
+ // than MMD character models do, and the browser cannot read one: createImageBitmap
5
+ // refuses it, and the TGA fallback reads the header as garbage and reports a
6
+ // height of zero. Every such material fell back to white.
7
+ //
8
+ // Decoded rather than uploaded as-is on purpose. WebGPU can sample BC formats
9
+ // natively, but only where the texture-compression-bc feature was requested at
10
+ // device creation — it is absent on much mobile hardware, and requesting a
11
+ // feature that may not exist to read a file that may not appear is a worse trade
12
+ // than spending a few milliseconds per texture at load.
13
+ const MAGIC = 0x20534444; // "DDS "
14
+ const fourCC = (s) => s.charCodeAt(0) | (s.charCodeAt(1) << 8) | (s.charCodeAt(2) << 16) | (s.charCodeAt(3) << 24);
15
+ const FOURCC_DXT1 = fourCC("DXT1");
16
+ const FOURCC_DXT3 = fourCC("DXT3");
17
+ const FOURCC_DXT5 = fourCC("DXT5");
18
+ const FOURCC_DX10 = fourCC("DX10");
19
+ // The DXGI formats worth answering. BC1/2/3 are what a converted stage carries;
20
+ // the two RGBA8 spellings turn up in tools that write a DX10 header for an
21
+ // uncompressed surface.
22
+ const DXGI_BC1 = new Set([70, 71, 72]);
23
+ const DXGI_BC2 = new Set([73, 74, 75]);
24
+ const DXGI_BC3 = new Set([76, 77, 78]);
25
+ const DXGI_RGBA8 = new Set([27, 28, 29]);
26
+ const DXGI_BGRA8 = new Set([87, 88, 91]);
27
+ /** True when these bytes are a DDS, by magic rather than by file extension. */
28
+ export function isDds(buffer) {
29
+ return buffer.byteLength >= 128 && new DataView(buffer).getUint32(0, true) === MAGIC;
30
+ }
31
+ function rgb565(c, out, o) {
32
+ const r = (c >> 11) & 0x1f;
33
+ const g = (c >> 5) & 0x3f;
34
+ const b = c & 0x1f;
35
+ // Bit-replication, not a shift: (r << 3) leaves white at 248 and tints every
36
+ // bright surface, which reads as a dull texture rather than a decode bug.
37
+ out[o] = (r << 3) | (r >> 2);
38
+ out[o + 1] = (g << 2) | (g >> 4);
39
+ out[o + 2] = (b << 3) | (b >> 2);
40
+ out[o + 3] = 255;
41
+ }
42
+ /**
43
+ * One BC1 colour block into `dst`.
44
+ *
45
+ * `opaque` forces the four-colour mode. BC1 on its own picks its mode per block
46
+ * from the endpoint order — c0 <= c1 means three colours and a transparent
47
+ * fourth — but when a BC1 block is the colour half of a BC2/BC3 pair the alpha
48
+ * lives in the other half and the four-colour mode is unconditional.
49
+ */
50
+ function bc1Block(v, off, dst, x0, y0, w, h, opaque) {
51
+ const c0 = v.getUint16(off, true);
52
+ const c1 = v.getUint16(off + 2, true);
53
+ const bits = v.getUint32(off + 4, true);
54
+ const pal = new Uint8Array(16);
55
+ rgb565(c0, pal, 0);
56
+ rgb565(c1, pal, 4);
57
+ if (c0 > c1 || opaque) {
58
+ for (let i = 0; i < 3; i++) {
59
+ pal[8 + i] = (2 * pal[i] + pal[4 + i] + 1) / 3;
60
+ pal[12 + i] = (pal[i] + 2 * pal[4 + i] + 1) / 3;
61
+ }
62
+ pal[11] = 255;
63
+ pal[15] = 255;
64
+ }
65
+ else {
66
+ for (let i = 0; i < 3; i++)
67
+ pal[8 + i] = (pal[i] + pal[4 + i]) >> 1;
68
+ pal[11] = 255;
69
+ // The fourth entry is transparent black in this mode — the 1-bit alpha.
70
+ pal[12] = 0;
71
+ pal[13] = 0;
72
+ pal[14] = 0;
73
+ pal[15] = 0;
74
+ }
75
+ for (let py = 0; py < 4; py++) {
76
+ for (let px = 0; px < 4; px++) {
77
+ const x = x0 + px;
78
+ const y = y0 + py;
79
+ if (x >= w || y >= h)
80
+ continue;
81
+ const idx = ((bits >> (2 * (4 * py + px))) & 3) * 4;
82
+ const o = (y * w + x) * 4;
83
+ dst[o] = pal[idx];
84
+ dst[o + 1] = pal[idx + 1];
85
+ dst[o + 2] = pal[idx + 2];
86
+ dst[o + 3] = pal[idx + 3];
87
+ }
88
+ }
89
+ }
90
+ /** BC3's 3-bit interpolated alpha block. */
91
+ function bc3Alpha(v, off, dst, x0, y0, w, h) {
92
+ const a0 = v.getUint8(off);
93
+ const a1 = v.getUint8(off + 1);
94
+ const a = new Uint8Array(8);
95
+ a[0] = a0;
96
+ a[1] = a1;
97
+ if (a0 > a1) {
98
+ for (let i = 1; i < 7; i++)
99
+ a[i + 1] = ((7 - i) * a0 + i * a1) / 7;
100
+ }
101
+ else {
102
+ for (let i = 1; i < 5; i++)
103
+ a[i + 1] = ((5 - i) * a0 + i * a1) / 5;
104
+ a[6] = 0;
105
+ a[7] = 255;
106
+ }
107
+ // 16 three-bit indices over six bytes; read as two 24-bit halves so the
108
+ // shifts stay inside the 32-bit range JS bit ops actually work in.
109
+ const lo = v.getUint8(off + 2) | (v.getUint8(off + 3) << 8) | (v.getUint8(off + 4) << 16);
110
+ const hi = v.getUint8(off + 5) | (v.getUint8(off + 6) << 8) | (v.getUint8(off + 7) << 16);
111
+ for (let i = 0; i < 16; i++) {
112
+ const x = x0 + (i & 3);
113
+ const y = y0 + (i >> 2);
114
+ if (x >= w || y >= h)
115
+ continue;
116
+ const bitsFor = i < 8 ? (lo >> (3 * i)) & 7 : (hi >> (3 * (i - 8))) & 7;
117
+ dst[(y * w + x) * 4 + 3] = a[bitsFor];
118
+ }
119
+ }
120
+ /** BC2's 4-bit explicit alpha block. */
121
+ function bc2Alpha(v, off, dst, x0, y0, w, h) {
122
+ for (let i = 0; i < 16; i++) {
123
+ const x = x0 + (i & 3);
124
+ const y = y0 + (i >> 2);
125
+ if (x >= w || y >= h)
126
+ continue;
127
+ const nib = v.getUint8(off + (i >> 1));
128
+ const a = i & 1 ? nib >> 4 : nib & 0x0f;
129
+ dst[(y * w + x) * 4 + 3] = (a << 4) | a;
130
+ }
131
+ }
132
+ /**
133
+ * Decode the top mip of a DDS to RGBA8.
134
+ *
135
+ * Only the first surface: the engine generates its own mip chain, and a cube map
136
+ * or an array reaching here is a texture slot that was never going to mean what
137
+ * the file meant anyway.
138
+ */
139
+ export function decodeDds(buffer) {
140
+ const v = new DataView(buffer);
141
+ if (buffer.byteLength < 128 || v.getUint32(0, true) !== MAGIC)
142
+ throw new Error("not a DDS");
143
+ const headerFlags = v.getUint32(8, true);
144
+ const height = v.getUint32(12, true);
145
+ const width = v.getUint32(16, true);
146
+ const pitch = v.getUint32(20, true);
147
+ if (width <= 0 || height <= 0)
148
+ throw new Error(`DDS bad dimensions ${width}x${height}`);
149
+ const pfFlags = v.getUint32(80, true);
150
+ const pfFourCC = v.getUint32(84, true);
151
+ const rgbBits = v.getUint32(88, true);
152
+ const rMask = v.getUint32(92, true);
153
+ const aMask = v.getUint32(104, true);
154
+ let data = 128;
155
+ let kind = null;
156
+ if (pfFlags & 0x4) {
157
+ if (pfFourCC === FOURCC_DXT1)
158
+ kind = "bc1";
159
+ else if (pfFourCC === FOURCC_DXT3)
160
+ kind = "bc2";
161
+ else if (pfFourCC === FOURCC_DXT5)
162
+ kind = "bc3";
163
+ else if (pfFourCC === FOURCC_DX10) {
164
+ const dxgi = v.getUint32(128, true);
165
+ data = 148; // 128 header + 20-byte DX10 extension
166
+ if (DXGI_BC1.has(dxgi))
167
+ kind = "bc1";
168
+ else if (DXGI_BC2.has(dxgi))
169
+ kind = "bc2";
170
+ else if (DXGI_BC3.has(dxgi))
171
+ kind = "bc3";
172
+ else if (DXGI_RGBA8.has(dxgi))
173
+ kind = "rgba";
174
+ else if (DXGI_BGRA8.has(dxgi))
175
+ kind = "bgra";
176
+ else
177
+ throw new Error(`DDS unsupported DXGI format ${dxgi}`);
178
+ }
179
+ else {
180
+ throw new Error(`DDS unsupported fourCC 0x${pfFourCC.toString(16)}`);
181
+ }
182
+ }
183
+ else if (pfFlags & 0x40 && (rgbBits === 32 || rgbBits === 24)) {
184
+ // Uncompressed. The masks are stated over the little-endian DWORD, so the
185
+ // channel owning the LOW byte is the one stored first: red low is RGBA,
186
+ // and the classic D3D A8R8G8B8 (red at 0x00ff0000) is BGRA in memory.
187
+ kind = rMask === 0x000000ff ? "rgba" : "bgra";
188
+ }
189
+ if (!kind)
190
+ throw new Error("DDS unsupported pixel format");
191
+ const rgba = new Uint8Array(width * height * 4);
192
+ if (kind === "rgba" || kind === "bgra") {
193
+ const bytes = rgbBits === 24 ? 3 : 4;
194
+ const hasAlpha = bytes === 4 && aMask !== 0;
195
+ // Rows can be padded, and the header says by how much — DDSD_PITCH means the
196
+ // pitch field is a byte stride rather than a total size. Reading past it
197
+ // shears the image diagonally, which looks like a corrupt texture.
198
+ const stride = headerFlags & 0x8 && pitch >= width * bytes ? pitch : width * bytes;
199
+ if (data + stride * height > buffer.byteLength)
200
+ throw new Error("DDS truncated");
201
+ const src = new Uint8Array(buffer, data);
202
+ for (let y = 0; y < height; y++) {
203
+ for (let x = 0; x < width; x++) {
204
+ const s = y * stride + x * bytes;
205
+ const o = (y * width + x) * 4;
206
+ if (kind === "bgra") {
207
+ rgba[o] = src[s + 2];
208
+ rgba[o + 1] = src[s + 1];
209
+ rgba[o + 2] = src[s];
210
+ }
211
+ else {
212
+ rgba[o] = src[s];
213
+ rgba[o + 1] = src[s + 1];
214
+ rgba[o + 2] = src[s + 2];
215
+ }
216
+ rgba[o + 3] = hasAlpha ? src[s + 3] : 255;
217
+ }
218
+ }
219
+ return { rgba, width, height };
220
+ }
221
+ const blockBytes = kind === "bc1" ? 8 : 16;
222
+ const bw = Math.max(1, (width + 3) >> 2);
223
+ const bh = Math.max(1, (height + 3) >> 2);
224
+ if (data + bw * bh * blockBytes > buffer.byteLength)
225
+ throw new Error("DDS truncated");
226
+ for (let by = 0; by < bh; by++) {
227
+ for (let bx = 0; bx < bw; bx++) {
228
+ const off = data + (by * bw + bx) * blockBytes;
229
+ const x0 = bx * 4;
230
+ const y0 = by * 4;
231
+ if (kind === "bc1") {
232
+ bc1Block(v, off, rgba, x0, y0, width, height, false);
233
+ }
234
+ else {
235
+ // Colour first so the alpha block can overwrite what BC1 wrote — in
236
+ // BC2/BC3 the colour half is always the opaque four-colour mode.
237
+ bc1Block(v, off + 8, rgba, x0, y0, width, height, true);
238
+ if (kind === "bc2")
239
+ bc2Alpha(v, off, rgba, x0, y0, width, height);
240
+ else
241
+ bc3Alpha(v, off, rgba, x0, y0, width, height);
242
+ }
243
+ }
244
+ }
245
+ return { rgba, width, height };
246
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"engine.d.ts","sourceRoot":"","sources":["../src/engine.ts"],"names":[],"mappings":"AACA,OAAO,EAAQ,IAAI,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAA;AACzC,OAAO,EAAE,KAAK,EAA0C,MAAM,SAAS,CAAA;AAMvE,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAA;AACvC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAA;AAClD,OAAO,EAQL,KAAK,WAAW,EACjB,MAAM,gBAAgB,CAAA;AAkBvB,OAAO,EAAgB,KAAK,cAAc,EAAE,KAAK,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAEnF,OAAO,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;AAClE,OAAO,KAAK,EACV,qBAAqB,EACrB,sBAAsB,EAEtB,UAAU,EACX,MAAM,qBAAqB,CAAA;AAa5B,MAAM,MAAM,cAAc,GACtB,SAAS,GACT,MAAM,GACN,MAAM,GACN,MAAM,GACN,KAAK,GACL,WAAW,GACX,OAAO,GACP,cAAc,GACd,aAAa,CAAA;AAEjB,MAAM,MAAM,iBAAiB,GAAG,OAAO,CAAC,MAAM,CAAC,cAAc,EAAE,MAAM,EAAE,CAAC,CAAC,CAAA;AAyHzE,KAAK,YAAY,GAAG;IAClB,KAAK,EAAE,UAAU,CAAA;IACjB,WAAW,EAAE,WAAW,CAAA;IACxB,SAAS,EAAE,SAAS,CAAA;IACpB,QAAQ,EAAE,iBAAiB,CAAA;IAC3B,kEAAkE;IAClE,oBAAoB,EAAE,iBAAiB,CAAA;IACvC,6EAA6E;IAC7E,gBAAgB,CAAC,EAAE,iBAAiB,CAAA;IACpC,aAAa,EAAE,SAAS,CAAA;IACxB;gFAC4E;IAC5E,MAAM,CAAC,EAAE,CAAC,UAAU,GAAG,IAAI,CAAC,EAAE,CAAA;IAC9B,OAAO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AAM,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI;IAU1D,0FAA0F;IAC1F,gBAAgB,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI;IAWzC,oFAAoF;IACpF,aAAa,CACX,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,MAAM,EACf,KAAK,EAAE,MAAM,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,GACvC,OAAO;IAiBV,OAAO,CAAC,aAAa;YASP,sBAAsB;IAwGpC,OAAO,CAAC,oBAAoB;IAoB5B,OAAO,CAAC,kBAAkB;IAiB1B,OAAO,CAAC,YAAY;IAKpB,OAAO,CAAC,aAAa;IAgBrB;;;;OAIG;IACH,OAAO,CAAC,yBAAyB;IA8DjC,OAAO,CAAC,mBAAmB;IAQ3B;;;;;;OAMG;IACH,OAAO,CAAC,aAAa;IA+BrB;;;;;;OAMG;IACH,OAAO,CAAC,iBAAiB;IAUzB,OAAO,CAAC,sBAAsB;IAM9B,OAAO,CAAC,2BAA2B;IAanC;2EACuE;IAEvE,SAAS,CAAC,2BAA2B,CAAC,IAAI,EAAE,oBAAoB,EAAE,IAAI,EAAE,aAAa,GAAG,IAAI;IAe5F;;;;;OAKG;IACH,OAAO,CAAC,gBAAgB;IAuBxB,OAAO,CAAC,mBAAmB;IAM3B,OAAO,CAAC,oBAAoB;IAqF5B,OAAO,CAAC,kBAAkB;IAqB1B,OAAO,CAAC,WAAW;CA6CpB"}
package/dist/engine.js CHANGED
@@ -1,5 +1,7 @@
1
1
  import { Camera } from "./camera";
2
+ import { decodeDds, isDds } from "./dds-loader";
2
3
  import { Mat4, Quat, Vec3 } from "./math";
4
+ import { decodePsd, isPsd } from "./psd-loader";
3
5
  import { MATERIAL_MORPH_MULTIPLY } from "./model";
4
6
  import { MORPH_COMPUTE_WGSL } from "./shaders/passes/morph";
5
7
  import { decodeTga } from "./tga-loader";
@@ -648,6 +650,14 @@ export class Engine {
648
650
  target: options?.camera?.target ?? d.camera.target,
649
651
  fov: options?.camera?.fov ?? d.camera.fov,
650
652
  };
653
+ // Built HERE and not in setupCamera, because a host holds the Engine before
654
+ // init() resolves — the reference is assigned, then init is awaited — and it
655
+ // reads the camera in that window. isCameraVmdEnabled() on a camera that did
656
+ // not exist yet threw "Cannot read properties of undefined (reading
657
+ // 'vmdDriven')", which surfaces as the whole page failing to load. The Camera
658
+ // is pure math, so nothing about it needed the device; only its aspect and
659
+ // its input listeners do, and those still wait for a sized canvas.
660
+ this.camera = new Camera(Math.PI, Math.PI / 2.5, this.cameraConfig.distance, this.cameraConfig.target, this.cameraConfig.fov);
651
661
  this.onRaycast = options?.onRaycast;
652
662
  this.onGizmoDrag = options?.onGizmoDrag;
653
663
  this.bloomSettings = Engine.mergeBloomDefaults(options?.bloom);
@@ -2577,7 +2587,8 @@ export class Engine {
2577
2587
  size: 40 * 4,
2578
2588
  usage: GPUBufferUsage.UNIFORM | GPUBufferUsage.COPY_DST,
2579
2589
  });
2580
- this.camera = new Camera(Math.PI, Math.PI / 2.5, this.cameraConfig.distance, this.cameraConfig.target, this.cameraConfig.fov);
2590
+ // The camera came up with the engine (see the constructor). What waits for
2591
+ // init is only what needs a device and a sized canvas.
2581
2592
  this.camera.aspect = this.canvas.width / this.canvas.height;
2582
2593
  this.camera.attachControl(this.canvas);
2583
2594
  }
@@ -3941,21 +3952,28 @@ export class Engine {
3941
3952
  console.warn(`[reze] texture read failed: ${logicalPath}`, e instanceof Error ? e.message : e);
3942
3953
  return null;
3943
3954
  }
3944
- // Decode to either an ImageBitmap (web-native formats) or raw RGBA (TGA). .tga skips
3945
- // straight to the TGA decoder (createImageBitmap can't read it); other extensions try
3946
- // the browser decoder first, then fall back to TGA in case a .spa/.sph/etc. is TGA
3947
- // under its extension. Every failure is logged and soft never throws to the caller.
3955
+ // Decode to either an ImageBitmap (web-native formats) or raw RGBA (TGA, DDS, PSD).
3956
+ //
3957
+ // DDS and PSD are recognised by their MAGIC rather than their extension, because
3958
+ // the extension lies often enough to mattera converted stage's .tga is
3959
+ // sometimes a DDS, and a repacked texture folder is full of .png that never
3960
+ // stopped being Photoshop files. TGA has no magic to key on, so .tga skips
3961
+ // straight to its decoder (createImageBitmap can't read it) and every other
3962
+ // extension tries the browser first, then falls back to TGA in case a
3963
+ // .spa/.sph/etc. is TGA underneath. Every failure is logged and soft — this
3964
+ // never throws to the caller; the material just gets the white texture.
3948
3965
  let source = null;
3949
3966
  let rgba = null;
3950
3967
  let width;
3951
3968
  let height;
3969
+ const cpuDecoder = isDds(buffer) ? decodeDds : isPsd(buffer) ? decodePsd : null;
3952
3970
  const isTga = logicalPath.toLowerCase().endsWith(".tga");
3953
- if (!isTga) {
3971
+ if (!isTga && !cpuDecoder) {
3954
3972
  try {
3955
3973
  source = await createImageBitmap(new Blob([buffer]), { premultiplyAlpha: "none", colorSpaceConversion: "none" });
3956
3974
  }
3957
3975
  catch {
3958
- source = null; // not a browser-native image — try TGA below
3976
+ source = null; // not a browser-native image — try the CPU decoders below
3959
3977
  }
3960
3978
  }
3961
3979
  if (source) {
@@ -3964,7 +3982,7 @@ export class Engine {
3964
3982
  }
3965
3983
  else {
3966
3984
  try {
3967
- const img = decodeTga(buffer);
3985
+ const img = (cpuDecoder ?? decodeTga)(buffer);
3968
3986
  rgba = img.rgba;
3969
3987
  width = img.width;
3970
3988
  height = img.height;
@@ -0,0 +1,13 @@
1
+ import type { DecodedImage } from "./tga-loader";
2
+ /** True when these bytes are a PSD/PSB, by magic rather than by file extension. */
3
+ export declare function isPsd(buffer: ArrayBuffer): boolean;
4
+ /**
5
+ * Decode a PSD's composite to RGBA8.
6
+ *
7
+ * RGB, grayscale, indexed and duotone at 8 or 16 bits per channel, raw or RLE —
8
+ * which is every texture that has actually turned up. CMYK and Lab throw: they
9
+ * need a colour conversion that would be guesswork without a profile, and a
10
+ * silently wrong-coloured texture is worse than a missing one.
11
+ */
12
+ export declare function decodePsd(buffer: ArrayBuffer): DecodedImage;
13
+ //# sourceMappingURL=psd-loader.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"psd-loader.d.ts","sourceRoot":"","sources":["../src/psd-loader.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAsBhD,mFAAmF;AACnF,wBAAgB,KAAK,CAAC,MAAM,EAAE,WAAW,GAAG,OAAO,CAElD;AA2BD;;;;;;;GAOG;AACH,wBAAgB,SAAS,CAAC,MAAM,EAAE,WAAW,GAAG,YAAY,CAuH3D"}
@@ -0,0 +1,192 @@
1
+ // PSD → RGBA8, from the merged composite.
2
+ //
3
+ // MMD texture packs are often shipped as the artist's working files, so a
4
+ // material's texture path points at a .psd that no browser will decode. The
5
+ // layers are none of our business — Photoshop writes a flattened composite of
6
+ // the whole document at the end of the file, which is exactly the image the
7
+ // artist saw, so that is what this reads.
8
+ //
9
+ // (A file saved with "Maximize Compatibility" off has no useful composite. There
10
+ // is nothing to be done about that here beyond failing clearly: reconstructing it
11
+ // would mean compositing every layer, blend mode and clipping group — a Photoshop,
12
+ // not a texture loader.)
13
+ const MAGIC = 0x38425053; // "8BPS", big-endian — PSD is big-endian throughout
14
+ var ColorMode;
15
+ (function (ColorMode) {
16
+ ColorMode[ColorMode["Bitmap"] = 0] = "Bitmap";
17
+ ColorMode[ColorMode["Grayscale"] = 1] = "Grayscale";
18
+ ColorMode[ColorMode["Indexed"] = 2] = "Indexed";
19
+ ColorMode[ColorMode["RGB"] = 3] = "RGB";
20
+ ColorMode[ColorMode["CMYK"] = 4] = "CMYK";
21
+ ColorMode[ColorMode["Multichannel"] = 7] = "Multichannel";
22
+ ColorMode[ColorMode["Duotone"] = 8] = "Duotone";
23
+ ColorMode[ColorMode["Lab"] = 9] = "Lab";
24
+ })(ColorMode || (ColorMode = {}));
25
+ const MODE_NAMES = {
26
+ [ColorMode.Bitmap]: "bitmap",
27
+ [ColorMode.CMYK]: "CMYK",
28
+ [ColorMode.Multichannel]: "multichannel",
29
+ [ColorMode.Lab]: "Lab",
30
+ };
31
+ /** True when these bytes are a PSD/PSB, by magic rather than by file extension. */
32
+ export function isPsd(buffer) {
33
+ return buffer.byteLength >= 26 && new DataView(buffer).getUint32(0, false) === MAGIC;
34
+ }
35
+ /**
36
+ * PackBits, one row at a time.
37
+ *
38
+ * `end` bounds the row rather than the buffer: the row-length table says how many
39
+ * compressed bytes this row occupies, and trusting the control bytes past that
40
+ * would let one malformed row eat the next one's data.
41
+ */
42
+ function unpackBits(src, start, end, dst, at, limit) {
43
+ let i = start;
44
+ let o = at;
45
+ while (i < end && o < limit) {
46
+ const n = (src[i++] << 24) >> 24; // to signed
47
+ if (n >= 0) {
48
+ const count = Math.min(n + 1, limit - o, end - i);
49
+ for (let k = 0; k < count; k++)
50
+ dst[o++] = src[i++];
51
+ }
52
+ else if (n !== -128) {
53
+ // -128 is a no-op by the spec, not a run of 129.
54
+ const count = Math.min(1 - n, limit - o);
55
+ const b = src[i++];
56
+ for (let k = 0; k < count; k++)
57
+ dst[o++] = b;
58
+ }
59
+ }
60
+ return o;
61
+ }
62
+ /**
63
+ * Decode a PSD's composite to RGBA8.
64
+ *
65
+ * RGB, grayscale, indexed and duotone at 8 or 16 bits per channel, raw or RLE —
66
+ * which is every texture that has actually turned up. CMYK and Lab throw: they
67
+ * need a colour conversion that would be guesswork without a profile, and a
68
+ * silently wrong-coloured texture is worse than a missing one.
69
+ */
70
+ export function decodePsd(buffer) {
71
+ const v = new DataView(buffer);
72
+ if (buffer.byteLength < 26 || v.getUint32(0, false) !== MAGIC)
73
+ throw new Error("not a PSD");
74
+ const version = v.getUint16(4, false); // 1 = PSD, 2 = PSB
75
+ if (version !== 1 && version !== 2)
76
+ throw new Error(`PSD unsupported version ${version}`);
77
+ const channels = v.getUint16(12, false);
78
+ const height = v.getUint32(14, false);
79
+ const width = v.getUint32(18, false);
80
+ const depth = v.getUint16(22, false);
81
+ const mode = v.getUint16(24, false);
82
+ if (width <= 0 || height <= 0)
83
+ throw new Error(`PSD bad dimensions ${width}x${height}`);
84
+ if (depth !== 8 && depth !== 16)
85
+ throw new Error(`PSD unsupported bit depth ${depth}`);
86
+ if (mode in MODE_NAMES)
87
+ throw new Error(`PSD unsupported colour mode: ${MODE_NAMES[mode]}`);
88
+ // Three variable-length sections stand between the header and the pixels. Only
89
+ // the indexed palette is worth reading; the rest is skipped by its length.
90
+ let p = 26;
91
+ const colorDataLen = v.getUint32(p, false);
92
+ const colorData = p + 4;
93
+ p = colorData + colorDataLen;
94
+ p += 4 + v.getUint32(p, false); // image resources
95
+ // PSB states this length in 8 bytes. Only the low word can matter — the high
96
+ // one would mean a layer section larger than 4GB.
97
+ if (version === 2) {
98
+ p += 8 + v.getUint32(p + 4, false);
99
+ }
100
+ else {
101
+ p += 4 + v.getUint32(p, false);
102
+ }
103
+ if (p + 2 > buffer.byteLength)
104
+ throw new Error("PSD truncated before the composite");
105
+ const compression = v.getUint16(p, false);
106
+ p += 2;
107
+ // Only the channels that carry colour, plus one alpha. A PSD can hold spot and
108
+ // mask channels past those; they are stored after, so ignoring them is a matter
109
+ // of not reading that far.
110
+ const colourChannels = mode === ColorMode.RGB ? 3 : 1;
111
+ const hasAlpha = channels > colourChannels;
112
+ const used = colourChannels + (hasAlpha ? 1 : 0);
113
+ if (channels < colourChannels)
114
+ throw new Error(`PSD has ${channels} channel(s), expected ${colourChannels}`);
115
+ const bytesPerSample = depth === 16 ? 2 : 1;
116
+ const planeSamples = width * height;
117
+ const planeBytes = planeSamples * bytesPerSample;
118
+ const planes = new Uint8Array(used * planeBytes);
119
+ if (compression === 0) {
120
+ const need = used * planeBytes;
121
+ if (p + need > buffer.byteLength)
122
+ throw new Error("PSD truncated composite");
123
+ planes.set(new Uint8Array(buffer, p, need));
124
+ }
125
+ else if (compression === 1) {
126
+ // A table of per-row compressed lengths for EVERY channel comes first,
127
+ // including the channels being skipped — so the table is read in full even
128
+ // though only the first `used` channels' rows are decoded.
129
+ const countBytes = version === 2 ? 4 : 2;
130
+ const tableBytes = channels * height * countBytes;
131
+ if (p + tableBytes > buffer.byteLength)
132
+ throw new Error("PSD truncated row table");
133
+ const rowLengths = new Uint32Array(channels * height);
134
+ for (let i = 0; i < rowLengths.length; i++) {
135
+ rowLengths[i] = countBytes === 2 ? v.getUint16(p + i * 2, false) : v.getUint32(p + i * 4, false);
136
+ }
137
+ const src = new Uint8Array(buffer);
138
+ let at = p + tableBytes;
139
+ for (let c = 0; c < channels; c++) {
140
+ for (let y = 0; y < height; y++) {
141
+ const len = rowLengths[c * height + y];
142
+ if (at + len > buffer.byteLength)
143
+ throw new Error("PSD truncated composite");
144
+ if (c < used) {
145
+ const rowStart = c * planeBytes + y * width * bytesPerSample;
146
+ unpackBits(src, at, at + len, planes, rowStart, rowStart + width * bytesPerSample);
147
+ }
148
+ at += len;
149
+ }
150
+ }
151
+ }
152
+ else {
153
+ // 2 and 3 are the Zip codes. They appear on layer data, effectively never on
154
+ // the composite, and inflating would mean shipping a decompressor.
155
+ throw new Error(`PSD unsupported compression ${compression}`);
156
+ }
157
+ // 16-bit samples are big-endian; the high byte is the 8-bit value.
158
+ const sample = (plane, i) => depth === 16 ? planes[plane * planeBytes + i * 2] : planes[plane * planeBytes + i];
159
+ const rgba = new Uint8Array(planeSamples * 4);
160
+ if (mode === ColorMode.Indexed) {
161
+ // The palette is the colour mode data: 256 reds, then 256 greens, then blues.
162
+ if (colorDataLen < 768)
163
+ throw new Error("PSD indexed image has no palette");
164
+ const pal = new Uint8Array(buffer, colorData, 768);
165
+ for (let i = 0; i < planeSamples; i++) {
166
+ const idx = sample(0, i);
167
+ rgba[i * 4] = pal[idx];
168
+ rgba[i * 4 + 1] = pal[256 + idx];
169
+ rgba[i * 4 + 2] = pal[512 + idx];
170
+ rgba[i * 4 + 3] = hasAlpha ? sample(1, i) : 255;
171
+ }
172
+ return { rgba, width, height };
173
+ }
174
+ for (let i = 0; i < planeSamples; i++) {
175
+ if (mode === ColorMode.RGB) {
176
+ rgba[i * 4] = sample(0, i);
177
+ rgba[i * 4 + 1] = sample(1, i);
178
+ rgba[i * 4 + 2] = sample(2, i);
179
+ }
180
+ else {
181
+ // Grayscale and duotone: one plane across all three. Duotone's ink colours
182
+ // live in the colour mode data, and the spec's own advice is to treat the
183
+ // data as grayscale — which is what every other reader does.
184
+ const g = sample(0, i);
185
+ rgba[i * 4] = g;
186
+ rgba[i * 4 + 1] = g;
187
+ rgba[i * 4 + 2] = g;
188
+ }
189
+ rgba[i * 4 + 3] = hasAlpha ? sample(colourChannels, i) : 255;
190
+ }
191
+ return { rgba, width, height };
192
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "reze-engine",
3
- "version": "0.41.2",
3
+ "version": "0.41.3",
4
4
  "description": "A lightweight WebGPU engine for real-time 3D MMD/PMX model rendering",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -0,0 +1,236 @@
1
+ // DDS → RGBA8, decoded on the CPU.
2
+ //
3
+ // Stage models converted out of games ship their textures as DDS far more often
4
+ // than MMD character models do, and the browser cannot read one: createImageBitmap
5
+ // refuses it, and the TGA fallback reads the header as garbage and reports a
6
+ // height of zero. Every such material fell back to white.
7
+ //
8
+ // Decoded rather than uploaded as-is on purpose. WebGPU can sample BC formats
9
+ // natively, but only where the texture-compression-bc feature was requested at
10
+ // device creation — it is absent on much mobile hardware, and requesting a
11
+ // feature that may not exist to read a file that may not appear is a worse trade
12
+ // than spending a few milliseconds per texture at load.
13
+
14
+ import type { DecodedImage } from "./tga-loader"
15
+
16
+ const MAGIC = 0x20534444 // "DDS "
17
+ const fourCC = (s: string) => s.charCodeAt(0) | (s.charCodeAt(1) << 8) | (s.charCodeAt(2) << 16) | (s.charCodeAt(3) << 24)
18
+ const FOURCC_DXT1 = fourCC("DXT1")
19
+ const FOURCC_DXT3 = fourCC("DXT3")
20
+ const FOURCC_DXT5 = fourCC("DXT5")
21
+ const FOURCC_DX10 = fourCC("DX10")
22
+
23
+ // The DXGI formats worth answering. BC1/2/3 are what a converted stage carries;
24
+ // the two RGBA8 spellings turn up in tools that write a DX10 header for an
25
+ // uncompressed surface.
26
+ const DXGI_BC1 = new Set([70, 71, 72])
27
+ const DXGI_BC2 = new Set([73, 74, 75])
28
+ const DXGI_BC3 = new Set([76, 77, 78])
29
+ const DXGI_RGBA8 = new Set([27, 28, 29])
30
+ const DXGI_BGRA8 = new Set([87, 88, 91])
31
+
32
+ /** True when these bytes are a DDS, by magic rather than by file extension. */
33
+ export function isDds(buffer: ArrayBuffer): boolean {
34
+ return buffer.byteLength >= 128 && new DataView(buffer).getUint32(0, true) === MAGIC
35
+ }
36
+
37
+ function rgb565(c: number, out: Uint8Array, o: number): void {
38
+ const r = (c >> 11) & 0x1f
39
+ const g = (c >> 5) & 0x3f
40
+ const b = c & 0x1f
41
+ // Bit-replication, not a shift: (r << 3) leaves white at 248 and tints every
42
+ // bright surface, which reads as a dull texture rather than a decode bug.
43
+ out[o] = (r << 3) | (r >> 2)
44
+ out[o + 1] = (g << 2) | (g >> 4)
45
+ out[o + 2] = (b << 3) | (b >> 2)
46
+ out[o + 3] = 255
47
+ }
48
+
49
+ /**
50
+ * One BC1 colour block into `dst`.
51
+ *
52
+ * `opaque` forces the four-colour mode. BC1 on its own picks its mode per block
53
+ * from the endpoint order — c0 <= c1 means three colours and a transparent
54
+ * fourth — but when a BC1 block is the colour half of a BC2/BC3 pair the alpha
55
+ * lives in the other half and the four-colour mode is unconditional.
56
+ */
57
+ function bc1Block(v: DataView, off: number, dst: Uint8Array, x0: number, y0: number, w: number, h: number, opaque: boolean): void {
58
+ const c0 = v.getUint16(off, true)
59
+ const c1 = v.getUint16(off + 2, true)
60
+ const bits = v.getUint32(off + 4, true)
61
+ const pal = new Uint8Array(16)
62
+ rgb565(c0, pal, 0)
63
+ rgb565(c1, pal, 4)
64
+ if (c0 > c1 || opaque) {
65
+ for (let i = 0; i < 3; i++) {
66
+ pal[8 + i] = (2 * pal[i] + pal[4 + i] + 1) / 3
67
+ pal[12 + i] = (pal[i] + 2 * pal[4 + i] + 1) / 3
68
+ }
69
+ pal[11] = 255
70
+ pal[15] = 255
71
+ } else {
72
+ for (let i = 0; i < 3; i++) pal[8 + i] = (pal[i] + pal[4 + i]) >> 1
73
+ pal[11] = 255
74
+ // The fourth entry is transparent black in this mode — the 1-bit alpha.
75
+ pal[12] = 0
76
+ pal[13] = 0
77
+ pal[14] = 0
78
+ pal[15] = 0
79
+ }
80
+ for (let py = 0; py < 4; py++) {
81
+ for (let px = 0; px < 4; px++) {
82
+ const x = x0 + px
83
+ const y = y0 + py
84
+ if (x >= w || y >= h) continue
85
+ const idx = ((bits >> (2 * (4 * py + px))) & 3) * 4
86
+ const o = (y * w + x) * 4
87
+ dst[o] = pal[idx]
88
+ dst[o + 1] = pal[idx + 1]
89
+ dst[o + 2] = pal[idx + 2]
90
+ dst[o + 3] = pal[idx + 3]
91
+ }
92
+ }
93
+ }
94
+
95
+ /** BC3's 3-bit interpolated alpha block. */
96
+ function bc3Alpha(v: DataView, off: number, dst: Uint8Array, x0: number, y0: number, w: number, h: number): void {
97
+ const a0 = v.getUint8(off)
98
+ const a1 = v.getUint8(off + 1)
99
+ const a = new Uint8Array(8)
100
+ a[0] = a0
101
+ a[1] = a1
102
+ if (a0 > a1) {
103
+ for (let i = 1; i < 7; i++) a[i + 1] = ((7 - i) * a0 + i * a1) / 7
104
+ } else {
105
+ for (let i = 1; i < 5; i++) a[i + 1] = ((5 - i) * a0 + i * a1) / 5
106
+ a[6] = 0
107
+ a[7] = 255
108
+ }
109
+ // 16 three-bit indices over six bytes; read as two 24-bit halves so the
110
+ // shifts stay inside the 32-bit range JS bit ops actually work in.
111
+ const lo = v.getUint8(off + 2) | (v.getUint8(off + 3) << 8) | (v.getUint8(off + 4) << 16)
112
+ const hi = v.getUint8(off + 5) | (v.getUint8(off + 6) << 8) | (v.getUint8(off + 7) << 16)
113
+ for (let i = 0; i < 16; i++) {
114
+ const x = x0 + (i & 3)
115
+ const y = y0 + (i >> 2)
116
+ if (x >= w || y >= h) continue
117
+ const bitsFor = i < 8 ? (lo >> (3 * i)) & 7 : (hi >> (3 * (i - 8))) & 7
118
+ dst[(y * w + x) * 4 + 3] = a[bitsFor]
119
+ }
120
+ }
121
+
122
+ /** BC2's 4-bit explicit alpha block. */
123
+ function bc2Alpha(v: DataView, off: number, dst: Uint8Array, x0: number, y0: number, w: number, h: number): void {
124
+ for (let i = 0; i < 16; i++) {
125
+ const x = x0 + (i & 3)
126
+ const y = y0 + (i >> 2)
127
+ if (x >= w || y >= h) continue
128
+ const nib = v.getUint8(off + (i >> 1))
129
+ const a = i & 1 ? nib >> 4 : nib & 0x0f
130
+ dst[(y * w + x) * 4 + 3] = (a << 4) | a
131
+ }
132
+ }
133
+
134
+ /**
135
+ * Decode the top mip of a DDS to RGBA8.
136
+ *
137
+ * Only the first surface: the engine generates its own mip chain, and a cube map
138
+ * or an array reaching here is a texture slot that was never going to mean what
139
+ * the file meant anyway.
140
+ */
141
+ export function decodeDds(buffer: ArrayBuffer): DecodedImage {
142
+ const v = new DataView(buffer)
143
+ if (buffer.byteLength < 128 || v.getUint32(0, true) !== MAGIC) throw new Error("not a DDS")
144
+
145
+ const headerFlags = v.getUint32(8, true)
146
+ const height = v.getUint32(12, true)
147
+ const width = v.getUint32(16, true)
148
+ const pitch = v.getUint32(20, true)
149
+ if (width <= 0 || height <= 0) throw new Error(`DDS bad dimensions ${width}x${height}`)
150
+
151
+ const pfFlags = v.getUint32(80, true)
152
+ const pfFourCC = v.getUint32(84, true)
153
+ const rgbBits = v.getUint32(88, true)
154
+ const rMask = v.getUint32(92, true)
155
+ const aMask = v.getUint32(104, true)
156
+
157
+ let data = 128
158
+ let kind: "bc1" | "bc2" | "bc3" | "rgba" | "bgra" | null = null
159
+
160
+ if (pfFlags & 0x4) {
161
+ if (pfFourCC === FOURCC_DXT1) kind = "bc1"
162
+ else if (pfFourCC === FOURCC_DXT3) kind = "bc2"
163
+ else if (pfFourCC === FOURCC_DXT5) kind = "bc3"
164
+ else if (pfFourCC === FOURCC_DX10) {
165
+ const dxgi = v.getUint32(128, true)
166
+ data = 148 // 128 header + 20-byte DX10 extension
167
+ if (DXGI_BC1.has(dxgi)) kind = "bc1"
168
+ else if (DXGI_BC2.has(dxgi)) kind = "bc2"
169
+ else if (DXGI_BC3.has(dxgi)) kind = "bc3"
170
+ else if (DXGI_RGBA8.has(dxgi)) kind = "rgba"
171
+ else if (DXGI_BGRA8.has(dxgi)) kind = "bgra"
172
+ else throw new Error(`DDS unsupported DXGI format ${dxgi}`)
173
+ } else {
174
+ throw new Error(`DDS unsupported fourCC 0x${pfFourCC.toString(16)}`)
175
+ }
176
+ } else if (pfFlags & 0x40 && (rgbBits === 32 || rgbBits === 24)) {
177
+ // Uncompressed. The masks are stated over the little-endian DWORD, so the
178
+ // channel owning the LOW byte is the one stored first: red low is RGBA,
179
+ // and the classic D3D A8R8G8B8 (red at 0x00ff0000) is BGRA in memory.
180
+ kind = rMask === 0x000000ff ? "rgba" : "bgra"
181
+ }
182
+ if (!kind) throw new Error("DDS unsupported pixel format")
183
+
184
+ const rgba = new Uint8Array(width * height * 4)
185
+
186
+ if (kind === "rgba" || kind === "bgra") {
187
+ const bytes = rgbBits === 24 ? 3 : 4
188
+ const hasAlpha = bytes === 4 && aMask !== 0
189
+ // Rows can be padded, and the header says by how much — DDSD_PITCH means the
190
+ // pitch field is a byte stride rather than a total size. Reading past it
191
+ // shears the image diagonally, which looks like a corrupt texture.
192
+ const stride = headerFlags & 0x8 && pitch >= width * bytes ? pitch : width * bytes
193
+ if (data + stride * height > buffer.byteLength) throw new Error("DDS truncated")
194
+ const src = new Uint8Array(buffer, data)
195
+ for (let y = 0; y < height; y++) {
196
+ for (let x = 0; x < width; x++) {
197
+ const s = y * stride + x * bytes
198
+ const o = (y * width + x) * 4
199
+ if (kind === "bgra") {
200
+ rgba[o] = src[s + 2]
201
+ rgba[o + 1] = src[s + 1]
202
+ rgba[o + 2] = src[s]
203
+ } else {
204
+ rgba[o] = src[s]
205
+ rgba[o + 1] = src[s + 1]
206
+ rgba[o + 2] = src[s + 2]
207
+ }
208
+ rgba[o + 3] = hasAlpha ? src[s + 3] : 255
209
+ }
210
+ }
211
+ return { rgba, width, height }
212
+ }
213
+
214
+ const blockBytes = kind === "bc1" ? 8 : 16
215
+ const bw = Math.max(1, (width + 3) >> 2)
216
+ const bh = Math.max(1, (height + 3) >> 2)
217
+ if (data + bw * bh * blockBytes > buffer.byteLength) throw new Error("DDS truncated")
218
+
219
+ for (let by = 0; by < bh; by++) {
220
+ for (let bx = 0; bx < bw; bx++) {
221
+ const off = data + (by * bw + bx) * blockBytes
222
+ const x0 = bx * 4
223
+ const y0 = by * 4
224
+ if (kind === "bc1") {
225
+ bc1Block(v, off, rgba, x0, y0, width, height, false)
226
+ } else {
227
+ // Colour first so the alpha block can overwrite what BC1 wrote — in
228
+ // BC2/BC3 the colour half is always the opaque four-colour mode.
229
+ bc1Block(v, off + 8, rgba, x0, y0, width, height, true)
230
+ if (kind === "bc2") bc2Alpha(v, off, rgba, x0, y0, width, height)
231
+ else bc3Alpha(v, off, rgba, x0, y0, width, height)
232
+ }
233
+ }
234
+ }
235
+ return { rgba, width, height }
236
+ }
package/src/engine.ts CHANGED
@@ -1,5 +1,7 @@
1
1
  import { Camera } from "./camera"
2
+ import { decodeDds, isDds } from "./dds-loader"
2
3
  import { Mat4, Quat, Vec3 } from "./math"
4
+ import { decodePsd, isPsd } from "./psd-loader"
3
5
  import { Model, MATERIAL_MORPH_MULTIPLY, type Material } from "./model"
4
6
  import { MORPH_COMPUTE_WGSL } from "./shaders/passes/morph"
5
7
  import { decodeTga } from "./tga-loader"
@@ -660,7 +662,9 @@ export class Engine {
660
662
  private device!: GPUDevice
661
663
  private context!: GPUCanvasContext
662
664
  private presentationFormat!: GPUTextureFormat
663
- private camera!: Camera
665
+ // No `!`: the constructor assigns it, so the type is the guarantee. Every other
666
+ // `!` field here is genuinely absent until init() — this one no longer is.
667
+ private camera: Camera
664
668
  private cameraUniformBuffer!: GPUBuffer
665
669
  private cameraMatrixData = new Float32Array(36)
666
670
  // Blender-style scene config groups (resolved from EngineOptions)
@@ -987,6 +991,20 @@ export class Engine {
987
991
  target: options?.camera?.target ?? d.camera.target,
988
992
  fov: options?.camera?.fov ?? d.camera.fov,
989
993
  }
994
+ // Built HERE and not in setupCamera, because a host holds the Engine before
995
+ // init() resolves — the reference is assigned, then init is awaited — and it
996
+ // reads the camera in that window. isCameraVmdEnabled() on a camera that did
997
+ // not exist yet threw "Cannot read properties of undefined (reading
998
+ // 'vmdDriven')", which surfaces as the whole page failing to load. The Camera
999
+ // is pure math, so nothing about it needed the device; only its aspect and
1000
+ // its input listeners do, and those still wait for a sized canvas.
1001
+ this.camera = new Camera(
1002
+ Math.PI,
1003
+ Math.PI / 2.5,
1004
+ this.cameraConfig.distance,
1005
+ this.cameraConfig.target,
1006
+ this.cameraConfig.fov,
1007
+ )
990
1008
  this.onRaycast = options?.onRaycast
991
1009
  this.onGizmoDrag = options?.onGizmoDrag
992
1010
  this.bloomSettings = Engine.mergeBloomDefaults(options?.bloom)
@@ -3049,14 +3067,8 @@ export class Engine {
3049
3067
  usage: GPUBufferUsage.UNIFORM | GPUBufferUsage.COPY_DST,
3050
3068
  })
3051
3069
 
3052
- this.camera = new Camera(
3053
- Math.PI,
3054
- Math.PI / 2.5,
3055
- this.cameraConfig.distance,
3056
- this.cameraConfig.target,
3057
- this.cameraConfig.fov,
3058
- )
3059
-
3070
+ // The camera came up with the engine (see the constructor). What waits for
3071
+ // init is only what needs a device and a sized canvas.
3060
3072
  this.camera.aspect = this.canvas.width / this.canvas.height
3061
3073
  this.camera.attachControl(this.canvas)
3062
3074
  }
@@ -4623,21 +4635,28 @@ export class Engine {
4623
4635
  return null
4624
4636
  }
4625
4637
 
4626
- // Decode to either an ImageBitmap (web-native formats) or raw RGBA (TGA). .tga skips
4627
- // straight to the TGA decoder (createImageBitmap can't read it); other extensions try
4628
- // the browser decoder first, then fall back to TGA in case a .spa/.sph/etc. is TGA
4629
- // under its extension. Every failure is logged and soft never throws to the caller.
4638
+ // Decode to either an ImageBitmap (web-native formats) or raw RGBA (TGA, DDS, PSD).
4639
+ //
4640
+ // DDS and PSD are recognised by their MAGIC rather than their extension, because
4641
+ // the extension lies often enough to mattera converted stage's .tga is
4642
+ // sometimes a DDS, and a repacked texture folder is full of .png that never
4643
+ // stopped being Photoshop files. TGA has no magic to key on, so .tga skips
4644
+ // straight to its decoder (createImageBitmap can't read it) and every other
4645
+ // extension tries the browser first, then falls back to TGA in case a
4646
+ // .spa/.sph/etc. is TGA underneath. Every failure is logged and soft — this
4647
+ // never throws to the caller; the material just gets the white texture.
4630
4648
  let source: ImageBitmap | null = null
4631
4649
  let rgba: Uint8Array | null = null
4632
4650
  let width: number
4633
4651
  let height: number
4634
4652
 
4653
+ const cpuDecoder = isDds(buffer) ? decodeDds : isPsd(buffer) ? decodePsd : null
4635
4654
  const isTga = logicalPath.toLowerCase().endsWith(".tga")
4636
- if (!isTga) {
4655
+ if (!isTga && !cpuDecoder) {
4637
4656
  try {
4638
4657
  source = await createImageBitmap(new Blob([buffer]), { premultiplyAlpha: "none", colorSpaceConversion: "none" })
4639
4658
  } catch {
4640
- source = null // not a browser-native image — try TGA below
4659
+ source = null // not a browser-native image — try the CPU decoders below
4641
4660
  }
4642
4661
  }
4643
4662
 
@@ -4646,7 +4665,7 @@ export class Engine {
4646
4665
  height = source.height
4647
4666
  } else {
4648
4667
  try {
4649
- const img = decodeTga(buffer)
4668
+ const img = (cpuDecoder ?? decodeTga)(buffer)
4650
4669
  rgba = img.rgba
4651
4670
  width = img.width
4652
4671
  height = img.height
@@ -0,0 +1,193 @@
1
+ // PSD → RGBA8, from the merged composite.
2
+ //
3
+ // MMD texture packs are often shipped as the artist's working files, so a
4
+ // material's texture path points at a .psd that no browser will decode. The
5
+ // layers are none of our business — Photoshop writes a flattened composite of
6
+ // the whole document at the end of the file, which is exactly the image the
7
+ // artist saw, so that is what this reads.
8
+ //
9
+ // (A file saved with "Maximize Compatibility" off has no useful composite. There
10
+ // is nothing to be done about that here beyond failing clearly: reconstructing it
11
+ // would mean compositing every layer, blend mode and clipping group — a Photoshop,
12
+ // not a texture loader.)
13
+
14
+ import type { DecodedImage } from "./tga-loader"
15
+
16
+ const MAGIC = 0x38425053 // "8BPS", big-endian — PSD is big-endian throughout
17
+
18
+ const enum ColorMode {
19
+ Bitmap = 0,
20
+ Grayscale = 1,
21
+ Indexed = 2,
22
+ RGB = 3,
23
+ CMYK = 4,
24
+ Multichannel = 7,
25
+ Duotone = 8,
26
+ Lab = 9,
27
+ }
28
+
29
+ const MODE_NAMES: Record<number, string> = {
30
+ [ColorMode.Bitmap]: "bitmap",
31
+ [ColorMode.CMYK]: "CMYK",
32
+ [ColorMode.Multichannel]: "multichannel",
33
+ [ColorMode.Lab]: "Lab",
34
+ }
35
+
36
+ /** True when these bytes are a PSD/PSB, by magic rather than by file extension. */
37
+ export function isPsd(buffer: ArrayBuffer): boolean {
38
+ return buffer.byteLength >= 26 && new DataView(buffer).getUint32(0, false) === MAGIC
39
+ }
40
+
41
+ /**
42
+ * PackBits, one row at a time.
43
+ *
44
+ * `end` bounds the row rather than the buffer: the row-length table says how many
45
+ * compressed bytes this row occupies, and trusting the control bytes past that
46
+ * would let one malformed row eat the next one's data.
47
+ */
48
+ function unpackBits(src: Uint8Array, start: number, end: number, dst: Uint8Array, at: number, limit: number): number {
49
+ let i = start
50
+ let o = at
51
+ while (i < end && o < limit) {
52
+ const n = (src[i++] << 24) >> 24 // to signed
53
+ if (n >= 0) {
54
+ const count = Math.min(n + 1, limit - o, end - i)
55
+ for (let k = 0; k < count; k++) dst[o++] = src[i++]
56
+ } else if (n !== -128) {
57
+ // -128 is a no-op by the spec, not a run of 129.
58
+ const count = Math.min(1 - n, limit - o)
59
+ const b = src[i++]
60
+ for (let k = 0; k < count; k++) dst[o++] = b
61
+ }
62
+ }
63
+ return o
64
+ }
65
+
66
+ /**
67
+ * Decode a PSD's composite to RGBA8.
68
+ *
69
+ * RGB, grayscale, indexed and duotone at 8 or 16 bits per channel, raw or RLE —
70
+ * which is every texture that has actually turned up. CMYK and Lab throw: they
71
+ * need a colour conversion that would be guesswork without a profile, and a
72
+ * silently wrong-coloured texture is worse than a missing one.
73
+ */
74
+ export function decodePsd(buffer: ArrayBuffer): DecodedImage {
75
+ const v = new DataView(buffer)
76
+ if (buffer.byteLength < 26 || v.getUint32(0, false) !== MAGIC) throw new Error("not a PSD")
77
+
78
+ const version = v.getUint16(4, false) // 1 = PSD, 2 = PSB
79
+ if (version !== 1 && version !== 2) throw new Error(`PSD unsupported version ${version}`)
80
+ const channels = v.getUint16(12, false)
81
+ const height = v.getUint32(14, false)
82
+ const width = v.getUint32(18, false)
83
+ const depth = v.getUint16(22, false)
84
+ const mode = v.getUint16(24, false)
85
+
86
+ if (width <= 0 || height <= 0) throw new Error(`PSD bad dimensions ${width}x${height}`)
87
+ if (depth !== 8 && depth !== 16) throw new Error(`PSD unsupported bit depth ${depth}`)
88
+ if (mode in MODE_NAMES) throw new Error(`PSD unsupported colour mode: ${MODE_NAMES[mode]}`)
89
+
90
+ // Three variable-length sections stand between the header and the pixels. Only
91
+ // the indexed palette is worth reading; the rest is skipped by its length.
92
+ let p = 26
93
+ const colorDataLen = v.getUint32(p, false)
94
+ const colorData = p + 4
95
+ p = colorData + colorDataLen
96
+ p += 4 + v.getUint32(p, false) // image resources
97
+ // PSB states this length in 8 bytes. Only the low word can matter — the high
98
+ // one would mean a layer section larger than 4GB.
99
+ if (version === 2) {
100
+ p += 8 + v.getUint32(p + 4, false)
101
+ } else {
102
+ p += 4 + v.getUint32(p, false)
103
+ }
104
+ if (p + 2 > buffer.byteLength) throw new Error("PSD truncated before the composite")
105
+
106
+ const compression = v.getUint16(p, false)
107
+ p += 2
108
+
109
+ // Only the channels that carry colour, plus one alpha. A PSD can hold spot and
110
+ // mask channels past those; they are stored after, so ignoring them is a matter
111
+ // of not reading that far.
112
+ const colourChannels = mode === ColorMode.RGB ? 3 : 1
113
+ const hasAlpha = channels > colourChannels
114
+ const used = colourChannels + (hasAlpha ? 1 : 0)
115
+ if (channels < colourChannels) throw new Error(`PSD has ${channels} channel(s), expected ${colourChannels}`)
116
+
117
+ const bytesPerSample = depth === 16 ? 2 : 1
118
+ const planeSamples = width * height
119
+ const planeBytes = planeSamples * bytesPerSample
120
+ const planes = new Uint8Array(used * planeBytes)
121
+
122
+ if (compression === 0) {
123
+ const need = used * planeBytes
124
+ if (p + need > buffer.byteLength) throw new Error("PSD truncated composite")
125
+ planes.set(new Uint8Array(buffer, p, need))
126
+ } else if (compression === 1) {
127
+ // A table of per-row compressed lengths for EVERY channel comes first,
128
+ // including the channels being skipped — so the table is read in full even
129
+ // though only the first `used` channels' rows are decoded.
130
+ const countBytes = version === 2 ? 4 : 2
131
+ const tableBytes = channels * height * countBytes
132
+ if (p + tableBytes > buffer.byteLength) throw new Error("PSD truncated row table")
133
+ const rowLengths = new Uint32Array(channels * height)
134
+ for (let i = 0; i < rowLengths.length; i++) {
135
+ rowLengths[i] = countBytes === 2 ? v.getUint16(p + i * 2, false) : v.getUint32(p + i * 4, false)
136
+ }
137
+ const src = new Uint8Array(buffer)
138
+ let at = p + tableBytes
139
+ for (let c = 0; c < channels; c++) {
140
+ for (let y = 0; y < height; y++) {
141
+ const len = rowLengths[c * height + y]
142
+ if (at + len > buffer.byteLength) throw new Error("PSD truncated composite")
143
+ if (c < used) {
144
+ const rowStart = c * planeBytes + y * width * bytesPerSample
145
+ unpackBits(src, at, at + len, planes, rowStart, rowStart + width * bytesPerSample)
146
+ }
147
+ at += len
148
+ }
149
+ }
150
+ } else {
151
+ // 2 and 3 are the Zip codes. They appear on layer data, effectively never on
152
+ // the composite, and inflating would mean shipping a decompressor.
153
+ throw new Error(`PSD unsupported compression ${compression}`)
154
+ }
155
+
156
+ // 16-bit samples are big-endian; the high byte is the 8-bit value.
157
+ const sample = (plane: number, i: number): number =>
158
+ depth === 16 ? planes[plane * planeBytes + i * 2] : planes[plane * planeBytes + i]
159
+
160
+ const rgba = new Uint8Array(planeSamples * 4)
161
+
162
+ if (mode === ColorMode.Indexed) {
163
+ // The palette is the colour mode data: 256 reds, then 256 greens, then blues.
164
+ if (colorDataLen < 768) throw new Error("PSD indexed image has no palette")
165
+ const pal = new Uint8Array(buffer, colorData, 768)
166
+ for (let i = 0; i < planeSamples; i++) {
167
+ const idx = sample(0, i)
168
+ rgba[i * 4] = pal[idx]
169
+ rgba[i * 4 + 1] = pal[256 + idx]
170
+ rgba[i * 4 + 2] = pal[512 + idx]
171
+ rgba[i * 4 + 3] = hasAlpha ? sample(1, i) : 255
172
+ }
173
+ return { rgba, width, height }
174
+ }
175
+
176
+ for (let i = 0; i < planeSamples; i++) {
177
+ if (mode === ColorMode.RGB) {
178
+ rgba[i * 4] = sample(0, i)
179
+ rgba[i * 4 + 1] = sample(1, i)
180
+ rgba[i * 4 + 2] = sample(2, i)
181
+ } else {
182
+ // Grayscale and duotone: one plane across all three. Duotone's ink colours
183
+ // live in the colour mode data, and the spec's own advice is to treat the
184
+ // data as grayscale — which is what every other reader does.
185
+ const g = sample(0, i)
186
+ rgba[i * 4] = g
187
+ rgba[i * 4 + 1] = g
188
+ rgba[i * 4 + 2] = g
189
+ }
190
+ rgba[i * 4 + 3] = hasAlpha ? sample(colourChannels, i) : 255
191
+ }
192
+ return { rgba, width, height }
193
+ }