@anhldh/gltf-lod-pipeline 0.0.7

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.
@@ -0,0 +1,401 @@
1
+ /* @ts-self-types="./pmrem_wasm.d.ts" */
2
+
3
+ /**
4
+ * @param {Uint8Array} input
5
+ * @returns {Uint8Array}
6
+ */
7
+ export function pmrem_exr(input) {
8
+ try {
9
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
10
+ const ptr0 = passArray8ToWasm0(input, wasm.__wbindgen_export);
11
+ const len0 = WASM_VECTOR_LEN;
12
+ wasm.pmrem_exr(retptr, ptr0, len0);
13
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
14
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
15
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
16
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
17
+ if (r3) {
18
+ throw takeObject(r2);
19
+ }
20
+ var v2 = getArrayU8FromWasm0(r0, r1).slice();
21
+ wasm.__wbindgen_export2(r0, r1 * 1, 1);
22
+ return v2;
23
+ } finally {
24
+ wasm.__wbindgen_add_to_stack_pointer(16);
25
+ }
26
+ }
27
+
28
+ /**
29
+ * Generate PMREM EXR bytes from input EXR, after downscaling the equirectangular source to target width.
30
+ * If `target_width` is >= source width, no resizing is performed.
31
+ * @param {Uint8Array} input
32
+ * @param {number} target_width
33
+ * @returns {Uint8Array}
34
+ */
35
+ export function pmrem_exr_resized(input, target_width) {
36
+ try {
37
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
38
+ const ptr0 = passArray8ToWasm0(input, wasm.__wbindgen_export);
39
+ const len0 = WASM_VECTOR_LEN;
40
+ wasm.pmrem_exr_resized(retptr, ptr0, len0, target_width);
41
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
42
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
43
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
44
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
45
+ if (r3) {
46
+ throw takeObject(r2);
47
+ }
48
+ var v2 = getArrayU8FromWasm0(r0, r1).slice();
49
+ wasm.__wbindgen_export2(r0, r1 * 1, 1);
50
+ return v2;
51
+ } finally {
52
+ wasm.__wbindgen_add_to_stack_pointer(16);
53
+ }
54
+ }
55
+
56
+ /**
57
+ * PMREM with optional downscale and filter selection ("lanczos"|"bicubic"|"bilinear").
58
+ * @param {Uint8Array} input
59
+ * @param {number} target_width
60
+ * @param {string} filter
61
+ * @returns {Uint8Array}
62
+ */
63
+ export function pmrem_exr_resized_with_filter(input, target_width, filter) {
64
+ try {
65
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
66
+ const ptr0 = passArray8ToWasm0(input, wasm.__wbindgen_export);
67
+ const len0 = WASM_VECTOR_LEN;
68
+ const ptr1 = passStringToWasm0(filter, wasm.__wbindgen_export, wasm.__wbindgen_export3);
69
+ const len1 = WASM_VECTOR_LEN;
70
+ wasm.pmrem_exr_resized_with_filter(retptr, ptr0, len0, target_width, ptr1, len1);
71
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
72
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
73
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
74
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
75
+ if (r3) {
76
+ throw takeObject(r2);
77
+ }
78
+ var v3 = getArrayU8FromWasm0(r0, r1).slice();
79
+ wasm.__wbindgen_export2(r0, r1 * 1, 1);
80
+ return v3;
81
+ } finally {
82
+ wasm.__wbindgen_add_to_stack_pointer(16);
83
+ }
84
+ }
85
+
86
+ /**
87
+ * Resize equirectangular EXR to target width (maintain aspect), returning EXR bytes.
88
+ * @param {Uint8Array} input
89
+ * @param {number} target_width
90
+ * @returns {Uint8Array}
91
+ */
92
+ export function resize_equirect_exr(input, target_width) {
93
+ try {
94
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
95
+ const ptr0 = passArray8ToWasm0(input, wasm.__wbindgen_export);
96
+ const len0 = WASM_VECTOR_LEN;
97
+ wasm.resize_equirect_exr(retptr, ptr0, len0, target_width);
98
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
99
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
100
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
101
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
102
+ if (r3) {
103
+ throw takeObject(r2);
104
+ }
105
+ var v2 = getArrayU8FromWasm0(r0, r1).slice();
106
+ wasm.__wbindgen_export2(r0, r1 * 1, 1);
107
+ return v2;
108
+ } finally {
109
+ wasm.__wbindgen_add_to_stack_pointer(16);
110
+ }
111
+ }
112
+
113
+ /**
114
+ * Resize equirectangular EXR to target width with chosen filter ("lanczos"|"bicubic"|"bilinear").
115
+ * @param {Uint8Array} input
116
+ * @param {number} target_width
117
+ * @param {string} filter
118
+ * @returns {Uint8Array}
119
+ */
120
+ export function resize_equirect_exr_with_filter(input, target_width, filter) {
121
+ try {
122
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
123
+ const ptr0 = passArray8ToWasm0(input, wasm.__wbindgen_export);
124
+ const len0 = WASM_VECTOR_LEN;
125
+ const ptr1 = passStringToWasm0(filter, wasm.__wbindgen_export, wasm.__wbindgen_export3);
126
+ const len1 = WASM_VECTOR_LEN;
127
+ wasm.resize_equirect_exr_with_filter(retptr, ptr0, len0, target_width, ptr1, len1);
128
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
129
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
130
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
131
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
132
+ if (r3) {
133
+ throw takeObject(r2);
134
+ }
135
+ var v3 = getArrayU8FromWasm0(r0, r1).slice();
136
+ wasm.__wbindgen_export2(r0, r1 * 1, 1);
137
+ return v3;
138
+ } finally {
139
+ wasm.__wbindgen_add_to_stack_pointer(16);
140
+ }
141
+ }
142
+
143
+ /**
144
+ * Split a PMREM CubeUV EXR buffer into cube face EXR images per mip level, packaged as a ZIP.
145
+ * @param {Uint8Array} input
146
+ * @returns {Uint8Array}
147
+ */
148
+ export function split_pmrem_exr_to_zip(input) {
149
+ try {
150
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
151
+ const ptr0 = passArray8ToWasm0(input, wasm.__wbindgen_export);
152
+ const len0 = WASM_VECTOR_LEN;
153
+ wasm.split_pmrem_exr_to_zip(retptr, ptr0, len0);
154
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
155
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
156
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
157
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
158
+ if (r3) {
159
+ throw takeObject(r2);
160
+ }
161
+ var v2 = getArrayU8FromWasm0(r0, r1).slice();
162
+ wasm.__wbindgen_export2(r0, r1 * 1, 1);
163
+ return v2;
164
+ } finally {
165
+ wasm.__wbindgen_add_to_stack_pointer(16);
166
+ }
167
+ }
168
+
169
+ function __wbg_get_imports() {
170
+ const import0 = {
171
+ __proto__: null,
172
+ __wbindgen_cast_0000000000000001: function(arg0, arg1) {
173
+ // Cast intrinsic for `Ref(String) -> Externref`.
174
+ const ret = getStringFromWasm0(arg0, arg1);
175
+ return addHeapObject(ret);
176
+ },
177
+ };
178
+ return {
179
+ __proto__: null,
180
+ "./pmrem_wasm_bg.js": import0,
181
+ };
182
+ }
183
+
184
+ function addHeapObject(obj) {
185
+ if (heap_next === heap.length) heap.push(heap.length + 1);
186
+ const idx = heap_next;
187
+ heap_next = heap[idx];
188
+
189
+ heap[idx] = obj;
190
+ return idx;
191
+ }
192
+
193
+ function dropObject(idx) {
194
+ if (idx < 1028) return;
195
+ heap[idx] = heap_next;
196
+ heap_next = idx;
197
+ }
198
+
199
+ function getArrayU8FromWasm0(ptr, len) {
200
+ ptr = ptr >>> 0;
201
+ return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
202
+ }
203
+
204
+ let cachedDataViewMemory0 = null;
205
+ function getDataViewMemory0() {
206
+ if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
207
+ cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
208
+ }
209
+ return cachedDataViewMemory0;
210
+ }
211
+
212
+ function getStringFromWasm0(ptr, len) {
213
+ ptr = ptr >>> 0;
214
+ return decodeText(ptr, len);
215
+ }
216
+
217
+ let cachedUint8ArrayMemory0 = null;
218
+ function getUint8ArrayMemory0() {
219
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
220
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
221
+ }
222
+ return cachedUint8ArrayMemory0;
223
+ }
224
+
225
+ function getObject(idx) { return heap[idx]; }
226
+
227
+ let heap = new Array(1024).fill(undefined);
228
+ heap.push(undefined, null, true, false);
229
+
230
+ let heap_next = heap.length;
231
+
232
+ function passArray8ToWasm0(arg, malloc) {
233
+ const ptr = malloc(arg.length * 1, 1) >>> 0;
234
+ getUint8ArrayMemory0().set(arg, ptr / 1);
235
+ WASM_VECTOR_LEN = arg.length;
236
+ return ptr;
237
+ }
238
+
239
+ function passStringToWasm0(arg, malloc, realloc) {
240
+ if (realloc === undefined) {
241
+ const buf = cachedTextEncoder.encode(arg);
242
+ const ptr = malloc(buf.length, 1) >>> 0;
243
+ getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
244
+ WASM_VECTOR_LEN = buf.length;
245
+ return ptr;
246
+ }
247
+
248
+ let len = arg.length;
249
+ let ptr = malloc(len, 1) >>> 0;
250
+
251
+ const mem = getUint8ArrayMemory0();
252
+
253
+ let offset = 0;
254
+
255
+ for (; offset < len; offset++) {
256
+ const code = arg.charCodeAt(offset);
257
+ if (code > 0x7F) break;
258
+ mem[ptr + offset] = code;
259
+ }
260
+ if (offset !== len) {
261
+ if (offset !== 0) {
262
+ arg = arg.slice(offset);
263
+ }
264
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
265
+ const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
266
+ const ret = cachedTextEncoder.encodeInto(arg, view);
267
+
268
+ offset += ret.written;
269
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
270
+ }
271
+
272
+ WASM_VECTOR_LEN = offset;
273
+ return ptr;
274
+ }
275
+
276
+ function takeObject(idx) {
277
+ const ret = getObject(idx);
278
+ dropObject(idx);
279
+ return ret;
280
+ }
281
+
282
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
283
+ cachedTextDecoder.decode();
284
+ const MAX_SAFARI_DECODE_BYTES = 2146435072;
285
+ let numBytesDecoded = 0;
286
+ function decodeText(ptr, len) {
287
+ numBytesDecoded += len;
288
+ if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
289
+ cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
290
+ cachedTextDecoder.decode();
291
+ numBytesDecoded = len;
292
+ }
293
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
294
+ }
295
+
296
+ const cachedTextEncoder = new TextEncoder();
297
+
298
+ if (!('encodeInto' in cachedTextEncoder)) {
299
+ cachedTextEncoder.encodeInto = function (arg, view) {
300
+ const buf = cachedTextEncoder.encode(arg);
301
+ view.set(buf);
302
+ return {
303
+ read: arg.length,
304
+ written: buf.length
305
+ };
306
+ };
307
+ }
308
+
309
+ let WASM_VECTOR_LEN = 0;
310
+
311
+ let wasmModule, wasm;
312
+ function __wbg_finalize_init(instance, module) {
313
+ wasm = instance.exports;
314
+ wasmModule = module;
315
+ cachedDataViewMemory0 = null;
316
+ cachedUint8ArrayMemory0 = null;
317
+ return wasm;
318
+ }
319
+
320
+ async function __wbg_load(module, imports) {
321
+ if (typeof Response === 'function' && module instanceof Response) {
322
+ if (typeof WebAssembly.instantiateStreaming === 'function') {
323
+ try {
324
+ return await WebAssembly.instantiateStreaming(module, imports);
325
+ } catch (e) {
326
+ const validResponse = module.ok && expectedResponseType(module.type);
327
+
328
+ if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
329
+ console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
330
+
331
+ } else { throw e; }
332
+ }
333
+ }
334
+
335
+ const bytes = await module.arrayBuffer();
336
+ return await WebAssembly.instantiate(bytes, imports);
337
+ } else {
338
+ const instance = await WebAssembly.instantiate(module, imports);
339
+
340
+ if (instance instanceof WebAssembly.Instance) {
341
+ return { instance, module };
342
+ } else {
343
+ return instance;
344
+ }
345
+ }
346
+
347
+ function expectedResponseType(type) {
348
+ switch (type) {
349
+ case 'basic': case 'cors': case 'default': return true;
350
+ }
351
+ return false;
352
+ }
353
+ }
354
+
355
+ function initSync(module) {
356
+ if (wasm !== undefined) return wasm;
357
+
358
+
359
+ if (module !== undefined) {
360
+ if (Object.getPrototypeOf(module) === Object.prototype) {
361
+ ({module} = module)
362
+ } else {
363
+ console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
364
+ }
365
+ }
366
+
367
+ const imports = __wbg_get_imports();
368
+ if (!(module instanceof WebAssembly.Module)) {
369
+ module = new WebAssembly.Module(module);
370
+ }
371
+ const instance = new WebAssembly.Instance(module, imports);
372
+ return __wbg_finalize_init(instance, module);
373
+ }
374
+
375
+ async function __wbg_init(module_or_path) {
376
+ if (wasm !== undefined) return wasm;
377
+
378
+
379
+ if (module_or_path !== undefined) {
380
+ if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
381
+ ({module_or_path} = module_or_path)
382
+ } else {
383
+ console.warn('using deprecated parameters for the initialization function; pass a single object instead')
384
+ }
385
+ }
386
+
387
+ if (module_or_path === undefined) {
388
+ module_or_path = new URL('pmrem_wasm_bg.wasm', import.meta.url);
389
+ }
390
+ const imports = __wbg_get_imports();
391
+
392
+ if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
393
+ module_or_path = fetch(module_or_path);
394
+ }
395
+
396
+ const { instance, module } = await __wbg_load(await module_or_path, imports);
397
+
398
+ return __wbg_finalize_init(instance, module);
399
+ }
400
+
401
+ export { initSync, __wbg_init as default };
package/package.json ADDED
@@ -0,0 +1,64 @@
1
+ {
2
+ "name": "@anhldh/gltf-lod-pipeline",
3
+ "version": "0.0.7",
4
+ "description": "CLI pipeline for generating glTF LOD variants with texture, mesh, and geometry optimizations.",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "import": "./dist/index.js",
11
+ "types": "./dist/index.d.ts"
12
+ }
13
+ },
14
+ "bin": {
15
+ "gltf-lod-pipeline": "./dist/index.js"
16
+ },
17
+ "files": [
18
+ "dist"
19
+ ],
20
+ "engines": {
21
+ "node": ">=18"
22
+ },
23
+ "scripts": {
24
+ "build:model": "tsx src/lib/cli/index.ts transform",
25
+ "stats:model": "tsx src/lib/cli/index.ts stats",
26
+ "dev": "tsup --watch",
27
+ "build": "rm -rf dist && tsup",
28
+ "lint": "eslint .",
29
+ "start": "node dist/index.js",
30
+ "prepublishOnly": "npm run build"
31
+ },
32
+ "dependencies": {
33
+ "@donmccurdy/caporal": "^0.0.10",
34
+ "@gltf-transform/core": "^4.3.0",
35
+ "@gltf-transform/extensions": "^4.3.0",
36
+ "@gltf-transform/functions": "^4.3.0",
37
+ "command-exists": "^1.2.9",
38
+ "command-line-args": "^6.0.2",
39
+ "draco3dgltf": "^1.5.7",
40
+ "glob": "^13.0.6",
41
+ "meshoptimizer": "^1.1.0",
42
+ "micromatch": "^4.0.8",
43
+ "ndarray": "^1.0.19",
44
+ "ndarray-lanczos": "^0.3.0",
45
+ "ndarray-pixels": "^5.0.1",
46
+ "p-limit": "^7.3.0",
47
+ "semver": "^7.7.4",
48
+ "sharp": "^0.34.5",
49
+ "tmp": "^0.2.5",
50
+ "uuid": "^13.0.0",
51
+ "xxhash-wasm": "^1.1.0"
52
+ },
53
+ "devDependencies": {
54
+ "@eslint/js": "^9.39.4",
55
+ "@types/node": "^24.12.2",
56
+ "@types/tmp": "^0.2.6",
57
+ "eslint": "^9.39.4",
58
+ "globals": "^17.4.0",
59
+ "tsup": "^8.5.1",
60
+ "tsx": "^4.21.0",
61
+ "typescript": "^5",
62
+ "typescript-eslint": "^8.58.0"
63
+ }
64
+ }