@carbonenginejs/runtime-resource 0.7.0 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. package/NOTICE +1 -1
  2. package/README.md +67 -537
  3. package/dist/formats/dds/core/bc6h.js +288 -0
  4. package/dist/formats/dds/core/bc6h.js.map +1 -0
  5. package/dist/formats/dds/core/bc7.js +251 -0
  6. package/dist/formats/dds/core/bc7.js.map +1 -0
  7. package/dist/formats/dds/core/helpers.js +6 -3
  8. package/dist/formats/dds/core/helpers.js.map +1 -1
  9. package/dist/formats/gr2/CjsGr2Format.js +46 -0
  10. package/dist/formats/gr2/CjsGr2Format.js.map +1 -0
  11. package/dist/formats/gr2/core/CjsFormatGr2.js +273 -0
  12. package/dist/formats/gr2/core/CjsFormatGr2.js.map +1 -0
  13. package/dist/formats/gr2/core/bitknit2.js +280 -0
  14. package/dist/formats/gr2/core/bitknit2.js.map +1 -0
  15. package/dist/formats/gr2/core/curves.js +1047 -0
  16. package/dist/formats/gr2/core/curves.js.map +1 -0
  17. package/dist/formats/gr2/core/gsf.js +72 -0
  18. package/dist/formats/gr2/core/gsf.js.map +1 -0
  19. package/dist/formats/gr2/core/helpers.js +332 -0
  20. package/dist/formats/gr2/core/helpers.js.map +1 -0
  21. package/dist/formats/gr2/core/json.js +622 -0
  22. package/dist/formats/gr2/core/json.js.map +1 -0
  23. package/dist/formats/gr2/core/oodle1.js +388 -0
  24. package/dist/formats/gr2/core/oodle1.js.map +1 -0
  25. package/dist/formats/gr2/core/reader.js +617 -0
  26. package/dist/formats/gr2/core/reader.js.map +1 -0
  27. package/dist/formats/gr2/core/tangents.js +48 -0
  28. package/dist/formats/gr2/core/tangents.js.map +1 -0
  29. package/dist/formats/gr2/core/targets.js +351 -0
  30. package/dist/formats/gr2/core/targets.js.map +1 -0
  31. package/dist/formats/gr2/index.js +3 -0
  32. package/dist/formats/gr2/index.js.map +1 -0
  33. package/dist/formats/index.js +7 -0
  34. package/dist/formats/index.js.map +1 -1
  35. package/dist/index.js +1 -0
  36. package/dist/index.js.map +1 -1
  37. package/dist/resources/Tr2TexturePipelineStepGenerateMips.js +22 -0
  38. package/dist/resources/Tr2TexturePipelineStepGenerateMips.js.map +1 -0
  39. package/dist/resources/TriGeometryRes.js +24 -1
  40. package/dist/resources/TriGeometryRes.js.map +1 -1
  41. package/docs/README.md +69 -0
  42. package/docs/architecture.md +86 -0
  43. package/docs/concepts/resource-lifecycle.md +217 -0
  44. package/docs/formats/README.md +104 -0
  45. package/{FORMAT-PROVENANCE.md → docs/formats/provenance.md} +34 -5
  46. package/docs/formats/stl.md +37 -0
  47. package/docs/formats/wwise.md +44 -0
  48. package/docs/reference/events.md +92 -0
  49. package/docs/reference/motherlode-cache.md +244 -0
  50. package/docs/reference/queues.md +102 -0
  51. package/docs/reference/reload.md +107 -0
  52. package/docs/reference/texture-arrays.md +113 -0
  53. package/docs/reference/texture-pipeline.md +53 -0
  54. package/docs/roadmap.md +104 -0
  55. package/format-notices/gr2/LICENSE +21 -0
  56. package/format-notices/gr2/NOTICE +60 -0
  57. package/format-notices/gr2/THIRD-PARTY-NOTICES.md +93 -0
  58. package/package.json +51 -50
  59. package/resource-lifecycle.md +0 -679
@@ -0,0 +1,617 @@
1
+ import { decompressBitKnit2 } from './bitknit2.js';
2
+ import { decompressOodle1 } from './oodle1.js';
3
+
4
+ /**
5
+ * Low-level pure-JavaScript Granny .gr2 reader.
6
+ *
7
+ * The reader walks Granny's embedded reflection type tree, applies pointer
8
+ * fixups, decompresses sections through {@link decompressGr2Section}, and
9
+ * reconstructs a shared object graph.
10
+ */
11
+
12
+ /**
13
+ * Granny member type ids used by the reflected type tree.
14
+ *
15
+ * These values mirror the granny_member_type enum and are exposed for callers
16
+ * that need to inspect raw type metadata.
17
+ */
18
+ const GRANNY_MEMBER_TYPES = Object.freeze({
19
+ End: 0,
20
+ Inline: 1,
21
+ Reference: 2,
22
+ ReferenceToArray: 3,
23
+ ArrayOfReferences: 4,
24
+ VariantReference: 5,
25
+ UnsupportedRemove: 6,
26
+ ReferenceToVariantArray: 7,
27
+ String: 8,
28
+ Transform: 9,
29
+ Real32: 10,
30
+ Int8: 11,
31
+ UInt8: 12,
32
+ BinormalInt8: 13,
33
+ NormalUInt8: 14,
34
+ Int16: 15,
35
+ UInt16: 16,
36
+ BinormalInt16: 17,
37
+ NormalUInt16: 18,
38
+ Int32: 19,
39
+ UInt32: 20,
40
+ Real16: 21,
41
+ EmptyReference: 22
42
+ });
43
+ const M = GRANNY_MEMBER_TYPES;
44
+ /** Size in bytes of a reflected Granny transform member. */
45
+ const GRANNY_TRANSFORM_SIZE = 68;
46
+ const TRANSFORM_SIZE = GRANNY_TRANSFORM_SIZE;
47
+
48
+ /**
49
+ * Known GR2 file magic values mapped to their pointer size in bytes.
50
+ *
51
+ * The reader currently supports little-endian 32-bit and 64-bit Granny files.
52
+ */
53
+ const GR2_MAGICS = Object.freeze({
54
+ "29de6cc0baa4532b25f5b7a5f666e2ee": 4,
55
+ "e59b495e6f631f141e13eba990beedc4": 8
56
+ });
57
+ const MAGICS = GR2_MAGICS;
58
+ const HEX_BYTES = Array.from({
59
+ length: 256
60
+ }, (_, value) => value.toString(16).padStart(2, "0"));
61
+ const UTF8_DECODER = new TextDecoder("utf-8");
62
+
63
+ /**
64
+ * Convert bytes to a lowercase hexadecimal string without relying on Node's Buffer.
65
+ *
66
+ * @param {Uint8Array} bytes Source bytes.
67
+ * @returns {string} Two hexadecimal characters per byte.
68
+ */
69
+ function bytesToHex(bytes) {
70
+ let out = "";
71
+ for (let i = 0; i < bytes.length; i++) out += HEX_BYTES[bytes[i]];
72
+ return out;
73
+ }
74
+
75
+ /**
76
+ * Decode UTF-8 bytes using the browser and Node standard Encoding API.
77
+ *
78
+ * @param {Uint8Array} bytes UTF-8 encoded bytes.
79
+ * @returns {string} Decoded text.
80
+ */
81
+ function decodeUtf8(bytes) {
82
+ return UTF8_DECODER.decode(bytes);
83
+ }
84
+
85
+ /**
86
+ * Convert an IEEE 754 binary16 value to a JavaScript number.
87
+ *
88
+ * @param {number} h Unsigned 16-bit half-float bits.
89
+ * @returns {number} Decoded floating-point value.
90
+ */
91
+ function half2float(h) {
92
+ const s = (h & 0x8000) >> 15,
93
+ e = (h & 0x7c00) >> 10,
94
+ f = h & 0x03ff;
95
+ if (e === 0) return (s ? -1 : 1) * Math.pow(2, -14) * (f / 1024);
96
+ if (e === 0x1f) return f ? NaN : s ? -Infinity : Infinity;
97
+ return (s ? -1 : 1) * Math.pow(2, e - 15) * (1 + f / 1024);
98
+ }
99
+
100
+ /** Compression format id for uncompressed GR2 sections. */
101
+ const GR2_COMPRESSION_NONE = 0;
102
+
103
+ /** Compression format id for legacy Granny Oodle0 sections. */
104
+ const GR2_COMPRESSION_OODLE0 = 1;
105
+
106
+ /** Compression format id for legacy Granny Oodle1 sections. */
107
+ const GR2_COMPRESSION_OODLE1 = 2;
108
+
109
+ /** Compression format id for Granny BitKnit2 sections. */
110
+ const GR2_COMPRESSION_BITKNIT2 = 4;
111
+
112
+ /**
113
+ * Decompress one GR2 section payload according to its section-directory format.
114
+ *
115
+ * @param {number} format Section compression format id.
116
+ * @param {Uint8Array} bytes Compressed section payload.
117
+ * @param {number} expandedSize Expected decompressed byte length.
118
+ * @param {{first16: number, first8: number}} sec Section metadata used by Oodle1 streams.
119
+ * @returns {Uint8Array} Raw section bytes, decompressed when needed.
120
+ * @throws {Error} If the format is not supported or the codec rejects the stream.
121
+ */
122
+ function decompressGr2Section(format, bytes, expandedSize, sec) {
123
+ if (format === GR2_COMPRESSION_NONE) return bytes;
124
+ if (format === GR2_COMPRESSION_OODLE0 || format === GR2_COMPRESSION_OODLE1) return decompressOodle1(bytes, expandedSize, {
125
+ first16: sec.first16,
126
+ first8: sec.first8
127
+ });
128
+ if (format === GR2_COMPRESSION_BITKNIT2) return decompressBitKnit2(bytes, expandedSize);
129
+ throw new Error(`section needs codec: format ${format} (0=None,2=Oodle1,4=BitKnit2)`);
130
+ }
131
+
132
+ /**
133
+ * Reflected Granny file graph produced by the low-level reader.
134
+ *
135
+ * @typedef {object} RawGr2ReadResult
136
+ * @property {number} version Granny file format revision from the file header.
137
+ * @property {number} secCount Number of sections in the source file.
138
+ * @property {object} fileInfo Reflected `granny_file_info` object graph with
139
+ * references resolved to shared JavaScript objects.
140
+ */
141
+
142
+ /**
143
+ * Parse raw `.gr2` bytes into the reflected Granny object graph.
144
+ *
145
+ * This is the low-level reader used by the package entry point. It decompresses
146
+ * sections, applies pointer fixups, walks the embedded type tree, and preserves
147
+ * pointer identity for repeated references in the resulting object graph.
148
+ *
149
+ * @param {Uint8Array|Buffer} buf Raw `.gr2` file bytes.
150
+ * @returns {RawGr2ReadResult} Parsed Granny file metadata and object graph.
151
+ * @throws {Error} If the file magic, compression format, or reflected graph is
152
+ * unsupported or malformed.
153
+ */
154
+ function readGr2Raw(buf) {
155
+ const dv0 = new DataView(buf.buffer, buf.byteOffset, buf.byteLength);
156
+ /**
157
+ * Read a little-endian uint32 from the original file bytes.
158
+ *
159
+ * @param {number} o Byte offset in the file buffer.
160
+ * @returns {number} Unsigned 32-bit integer.
161
+ */
162
+ const fu32 = o => dv0.getUint32(o, true),
163
+ magic = bytesToHex(buf.subarray(0, 16)),
164
+ P = MAGICS[magic];
165
+ if (!P) throw new Error("unknown gr2 magic " + magic);
166
+ const MEMBER_DEF_SIZE = 20 + 3 * P,
167
+ H = 32,
168
+ version = fu32(H),
169
+ secBase = H + fu32(H + 12),
170
+ secCount = fu32(H + 16),
171
+ rootTypeSec = fu32(H + 20),
172
+ rootTypeOff = fu32(H + 24),
173
+ rootObjSec = fu32(H + 28),
174
+ rootObjOff = fu32(H + 32);
175
+ const secs = [];
176
+ for (let i = 0; i < secCount; i++) {
177
+ const b = secBase + i * 44;
178
+ secs.push({
179
+ format: fu32(b),
180
+ dataOffset: fu32(b + 4),
181
+ dataSize: fu32(b + 8),
182
+ expandedSize: fu32(b + 12),
183
+ first16: fu32(b + 20),
184
+ first8: fu32(b + 24),
185
+ pFixOff: fu32(b + 28),
186
+ pFixCnt: fu32(b + 32)
187
+ });
188
+ }
189
+ const sectionBase = new Array(secCount);
190
+ let total = 0;
191
+ const datas = secs.map(s => {
192
+ const raw = buf.subarray(s.dataOffset, s.dataOffset + s.dataSize);
193
+ return decompressGr2Section(s.format, raw, s.expandedSize, s);
194
+ });
195
+ for (let i = 0; i < secCount; i++) {
196
+ sectionBase[i] = total;
197
+ total += secs[i].expandedSize;
198
+ }
199
+ const mem = new Uint8Array(total);
200
+ for (let i = 0; i < secCount; i++) {
201
+ mem.set(datas[i], sectionBase[i]);
202
+ }
203
+ const dv = new DataView(mem.buffer);
204
+
205
+ /**
206
+ * Read a little-endian uint32 from the relocated section memory.
207
+ *
208
+ * @param {number} o Byte offset in relocated section memory.
209
+ * @returns {number} Unsigned 32-bit integer.
210
+ */
211
+ const u32 = o => dv.getUint32(o, true);
212
+
213
+ /**
214
+ * Read a little-endian int32 from the relocated section memory.
215
+ *
216
+ * @param {number} o Byte offset in relocated section memory.
217
+ * @returns {number} Signed 32-bit integer.
218
+ */
219
+ const i32 = o => dv.getInt32(o, true);
220
+
221
+ /**
222
+ * Read a little-endian float32 from the relocated section memory.
223
+ *
224
+ * @param {number} o Byte offset in relocated section memory.
225
+ * @returns {number} Float32 value widened to a JavaScript number.
226
+ */
227
+ const f32 = o => dv.getFloat32(o, true);
228
+ const reloc = new Map();
229
+ for (let i = 0; i < secCount; i++) {
230
+ const s = secs[i];
231
+ if (s.pFixCnt === 0) continue;
232
+ let rel;
233
+ if (s.format === 4) {
234
+ const csz = fu32(s.pFixOff);
235
+ rel = decompressBitKnit2(buf.subarray(s.pFixOff + 4, s.pFixOff + 4 + csz), s.pFixCnt * 12);
236
+ } else {
237
+ rel = buf.subarray(s.pFixOff, s.pFixOff + s.pFixCnt * 12);
238
+ }
239
+ const rdv = new DataView(rel.buffer, rel.byteOffset, rel.byteLength);
240
+ for (let k = 0; k < s.pFixCnt; k++) {
241
+ const b = k * 12,
242
+ from = rdv.getUint32(b, true),
243
+ toSec = rdv.getUint32(b + 4, true),
244
+ toOff = rdv.getUint32(b + 8, true);
245
+ reloc.set(sectionBase[i] + from, sectionBase[toSec] + toOff);
246
+ }
247
+ }
248
+ const NULL = -1;
249
+
250
+ /**
251
+ * Resolve a relocated pointer field from a global section-memory offset.
252
+ *
253
+ * @param {number} g Global offset of the pointer field.
254
+ * @returns {number} Global target offset, or the null sentinel when absent.
255
+ */
256
+ const ptr = g => reloc.has(g) ? reloc.get(g) : NULL;
257
+
258
+ /**
259
+ * Read a null-terminated UTF-8 string from relocated section memory.
260
+ *
261
+ * @param {number} g Global string offset, or the null sentinel.
262
+ * @returns {string|null} Decoded string, or null for absent references.
263
+ */
264
+ function readString(g) {
265
+ if (g < 0) return null;
266
+ let end = g;
267
+ while (end < mem.length && mem[end] !== 0) end++;
268
+ return decodeUtf8(mem.subarray(g, end));
269
+ }
270
+ const typeCache = new Map();
271
+
272
+ /**
273
+ * Read and cache a reflected Granny type definition.
274
+ *
275
+ * @param {number} g Global offset of the first member definition.
276
+ * @returns {{type: number, name: string|null, refType: number, arrayWidth: number}[]} Member descriptors.
277
+ */
278
+ function readType(g) {
279
+ if (typeCache.has(g)) return typeCache.get(g);
280
+ const members = [];
281
+ let t = g;
282
+ while (true) {
283
+ const type = u32(t);
284
+ if (type === M.End) break;
285
+ members.push({
286
+ type,
287
+ name: readString(ptr(t + 4)),
288
+ refType: ptr(t + 4 + P),
289
+ arrayWidth: i32(t + 4 + 2 * P)
290
+ });
291
+ t += MEMBER_DEF_SIZE;
292
+ if (members.length > 4096) throw new Error("type member overflow");
293
+ }
294
+ typeCache.set(g, members);
295
+ return members;
296
+ }
297
+ const sizeCache = new Map();
298
+
299
+ /**
300
+ * Compute the byte size of an object for a reflected Granny type.
301
+ *
302
+ * @param {number} typeOff Global type-definition offset.
303
+ * @returns {number} Object size in bytes.
304
+ */
305
+ function objectSize(typeOff) {
306
+ if (sizeCache.has(typeOff)) return sizeCache.get(typeOff);
307
+ sizeCache.set(typeOff, 0);
308
+ let sz = 0;
309
+ for (const m of readType(typeOff)) {
310
+ sz += memberSize(m);
311
+ }
312
+ sizeCache.set(typeOff, sz);
313
+ return sz;
314
+ }
315
+
316
+ /**
317
+ * Compute the byte width of one reflected member.
318
+ *
319
+ * @param {{type: number, refType: number, arrayWidth: number}} m Member descriptor.
320
+ * @returns {number} Member size in bytes.
321
+ */
322
+ function memberSize(m) {
323
+ const w = m.arrayWidth > 0 ? m.arrayWidth : 1;
324
+ switch (m.type) {
325
+ case M.Inline:
326
+ return objectSize(m.refType) * w;
327
+ case M.Reference:
328
+ case M.String:
329
+ return P;
330
+ case M.EmptyReference:
331
+ return 4;
332
+ case M.ReferenceToArray:
333
+ case M.ArrayOfReferences:
334
+ return 4 + P;
335
+ case M.VariantReference:
336
+ return 2 * P;
337
+ case M.ReferenceToVariantArray:
338
+ return 2 * P + 4;
339
+ case M.Transform:
340
+ return TRANSFORM_SIZE;
341
+ case M.Real32:
342
+ case M.Int32:
343
+ case M.UInt32:
344
+ return 4 * w;
345
+ case M.Int16:
346
+ case M.UInt16:
347
+ case M.BinormalInt16:
348
+ case M.NormalUInt16:
349
+ case M.Real16:
350
+ return 2 * w;
351
+ case M.Int8:
352
+ case M.UInt8:
353
+ case M.BinormalInt8:
354
+ case M.NormalUInt8:
355
+ return 1 * w;
356
+ default:
357
+ return 0;
358
+ }
359
+ }
360
+ const layoutCache = new Map();
361
+
362
+ /**
363
+ * Compute and cache the fixed per-member byte layout of a reflected type.
364
+ *
365
+ * Granny types are static structural definitions, so every instance of a
366
+ * given type has an identical member layout; this only needs to run once
367
+ * per type instead of once per object instance (as recomputing offsets
368
+ * with {@link memberSize} inside {@link readObject} would).
369
+ *
370
+ * @param {number} typeOff Global type-definition offset.
371
+ * @returns {{members: object[], offsets: number[]}} Cached member list and
372
+ * each member's byte offset relative to the start of the object.
373
+ */
374
+ function typeLayout(typeOff) {
375
+ if (layoutCache.has(typeOff)) return layoutCache.get(typeOff);
376
+ const members = readType(typeOff),
377
+ offsets = new Array(members.length);
378
+ let size = 0;
379
+ for (let i = 0; i < members.length; i++) {
380
+ offsets[i] = size;
381
+ size += memberSize(members[i]);
382
+ }
383
+ const layout = {
384
+ members,
385
+ offsets
386
+ };
387
+ layoutCache.set(typeOff, layout);
388
+ return layout;
389
+ }
390
+
391
+ /**
392
+ * Byte stride between consecutive elements of a fixed-width numeric member type.
393
+ *
394
+ * @param {number} type Granny member type id.
395
+ * @returns {number} Element stride in bytes.
396
+ */
397
+ function numericStride(type) {
398
+ switch (type) {
399
+ case M.Real32:
400
+ case M.Int32:
401
+ case M.UInt32:
402
+ return 4;
403
+ case M.Int16:
404
+ case M.UInt16:
405
+ case M.BinormalInt16:
406
+ case M.NormalUInt16:
407
+ case M.Real16:
408
+ return 2;
409
+ default:
410
+ // Int8, UInt8, BinormalInt8, NormalUInt8
411
+ return 1;
412
+ }
413
+ }
414
+
415
+ /**
416
+ * Read one fixed-width numeric value from relocated memory.
417
+ *
418
+ * @param {number} type Granny member type id.
419
+ * @param {number} o Global byte offset of the value.
420
+ * @returns {number} Decoded value.
421
+ */
422
+ function numericAt(type, o) {
423
+ switch (type) {
424
+ case M.Real32:
425
+ return f32(o);
426
+ case M.Int32:
427
+ return i32(o);
428
+ case M.UInt32:
429
+ return u32(o);
430
+ case M.Int16:
431
+ case M.BinormalInt16:
432
+ return dv.getInt16(o, true);
433
+ case M.UInt16:
434
+ case M.NormalUInt16:
435
+ return dv.getUint16(o, true);
436
+ case M.Real16:
437
+ return half2float(dv.getUint16(o, true));
438
+ case M.Int8:
439
+ case M.BinormalInt8:
440
+ return dv.getInt8(o);
441
+ case M.UInt8:
442
+ case M.NormalUInt8:
443
+ return mem[o];
444
+ }
445
+ }
446
+
447
+ /**
448
+ * Read a scalar or fixed-width numeric member from relocated memory.
449
+ *
450
+ * @param {{type: number, arrayWidth: number}} m Numeric member descriptor.
451
+ * @param {number} off Global offset of the numeric field.
452
+ * @returns {number|number[]} Decoded scalar or array.
453
+ */
454
+ function numeric(m, off) {
455
+ const w = m.arrayWidth > 0 ? m.arrayWidth : 1;
456
+ if (w === 1) return numericAt(m.type, off);
457
+ const stride = numericStride(m.type),
458
+ out = new Array(w);
459
+ for (let i = 0; i < w; i++) {
460
+ out[i] = numericAt(m.type, off + i * stride);
461
+ }
462
+ return out;
463
+ }
464
+
465
+ /**
466
+ * Read a Granny transform struct from relocated memory.
467
+ *
468
+ * @param {number} o Global offset of the transform bytes.
469
+ * @returns {{flags: number, position: number[], orientation: number[], scaleShear: number[]}} Decoded transform.
470
+ */
471
+ function readTransform(o) {
472
+ return {
473
+ flags: u32(o),
474
+ position: [f32(o + 4), f32(o + 8), f32(o + 12)],
475
+ orientation: [f32(o + 16), f32(o + 20), f32(o + 24), f32(o + 28)],
476
+ scaleShear: [f32(o + 32), f32(o + 36), f32(o + 40), f32(o + 44), f32(o + 48), f32(o + 52), f32(o + 56), f32(o + 60), f32(o + 64)]
477
+ };
478
+ }
479
+ let depth = 0;
480
+ const objCache = new Map(); // typeOff -> Map<objOff, object>
481
+
482
+ /**
483
+ * Read a reflected object graph node, preserving pointer identity and cycles.
484
+ *
485
+ * @param {number} typeOff Global type-definition offset.
486
+ * @param {number} objOff Global object-data offset.
487
+ * @returns {object|null} Decoded object, or null for absent references.
488
+ */
489
+ function readObject(typeOff, objOff) {
490
+ if (typeOff < 0 || objOff < 0) return null;
491
+ let byOff = objCache.get(typeOff);
492
+ if (byOff === undefined) {
493
+ byOff = new Map();
494
+ objCache.set(typeOff, byOff);
495
+ } else {
496
+ const cached = byOff.get(objOff);
497
+ if (cached !== undefined) return cached;
498
+ }
499
+ if (++depth > 200) {
500
+ depth--;
501
+ throw new Error("recursion too deep");
502
+ }
503
+ const obj = {};
504
+ byOff.set(objOff, obj);
505
+ const {
506
+ members,
507
+ offsets
508
+ } = typeLayout(typeOff);
509
+ for (let idx = 0; idx < members.length; idx++) {
510
+ const m = members[idx],
511
+ field = objOff + offsets[idx];
512
+ let name = m.name || "_";
513
+ if (Object.prototype.hasOwnProperty.call(obj, name)) {
514
+ let n = 2;
515
+ while (Object.prototype.hasOwnProperty.call(obj, name + "" + n)) n++;
516
+ name = name + "" + n;
517
+ }
518
+ switch (m.type) {
519
+ case M.String:
520
+ obj[name] = readString(ptr(field));
521
+ break;
522
+ case M.Reference:
523
+ obj[name] = readObject(m.refType, ptr(field));
524
+ break;
525
+ case M.Transform:
526
+ obj[name] = readTransform(field);
527
+ break;
528
+ case M.Inline:
529
+ {
530
+ const w = m.arrayWidth > 0 ? m.arrayWidth : 1,
531
+ os = objectSize(m.refType);
532
+ if (m.arrayWidth > 1) {
533
+ obj[name] = [];
534
+ for (let i = 0; i < w; i++) {
535
+ obj[name].push(readObject(m.refType, field + i * os));
536
+ }
537
+ } else {
538
+ obj[name] = readObject(m.refType, field);
539
+ }
540
+ break;
541
+ }
542
+ case M.ReferenceToArray:
543
+ {
544
+ const count = i32(field),
545
+ p = ptr(field + 4),
546
+ os = objectSize(m.refType),
547
+ a = [];
548
+ for (let i = 0; i < count; i++) {
549
+ a.push(readObject(m.refType, p + i * os));
550
+ }
551
+ obj[name] = a;
552
+ break;
553
+ }
554
+ case M.ArrayOfReferences:
555
+ {
556
+ const count = i32(field),
557
+ p = ptr(field + 4),
558
+ a = [];
559
+ for (let i = 0; i < count; i++) {
560
+ a.push(readObject(m.refType, ptr(p + i * P)));
561
+ }
562
+ obj[name] = a;
563
+ break;
564
+ }
565
+ case M.VariantReference:
566
+ obj[name] = readObject(ptr(field), ptr(field + P));
567
+ break;
568
+ case M.ReferenceToVariantArray:
569
+ {
570
+ const vt = ptr(field),
571
+ count = i32(field + P),
572
+ p = ptr(field + P + 4),
573
+ a = [],
574
+ os = vt >= 0 ? objectSize(vt) : 0;
575
+ for (let i = 0; i < count; i++) {
576
+ a.push(readObject(vt, p + i * os));
577
+ }
578
+ if (vt >= 0) Object.defineProperty(a, "__type", {
579
+ value: readType(vt),
580
+ enumerable: false
581
+ });
582
+ obj[name] = a;
583
+ break;
584
+ }
585
+ case M.Real32:
586
+ case M.Int8:
587
+ case M.UInt8:
588
+ case M.BinormalInt8:
589
+ case M.NormalUInt8:
590
+ case M.Int16:
591
+ case M.UInt16:
592
+ case M.BinormalInt16:
593
+ case M.NormalUInt16:
594
+ case M.Int32:
595
+ case M.UInt32:
596
+ case M.Real16:
597
+ obj[name] = numeric(m, field);
598
+ break;
599
+ default:
600
+ obj[name] = null;
601
+ }
602
+ }
603
+ depth--;
604
+ return obj;
605
+ }
606
+ const rootTypeG = sectionBase[rootTypeSec] + rootTypeOff,
607
+ rootObjG = sectionBase[rootObjSec] + rootObjOff,
608
+ fileInfo = readObject(rootTypeG, rootObjG);
609
+ return {
610
+ version,
611
+ secCount,
612
+ fileInfo
613
+ };
614
+ }
615
+
616
+ export { GR2_COMPRESSION_BITKNIT2, GR2_COMPRESSION_NONE, GR2_COMPRESSION_OODLE0, GR2_COMPRESSION_OODLE1, GR2_MAGICS, GRANNY_MEMBER_TYPES, GRANNY_TRANSFORM_SIZE, bytesToHex, decodeUtf8, decompressGr2Section, readGr2Raw };
617
+ //# sourceMappingURL=reader.js.map