@hackbuild/bake 0.0.0-stage → 0.1.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.
@@ -0,0 +1,495 @@
1
+ /* @ts-self-types="./bake.d.ts" */
2
+
3
+ export class Baked {
4
+ static __wrap(ptr) {
5
+ const obj = Object.create(Baked.prototype);
6
+ obj.__wbg_ptr = ptr;
7
+ BakedFinalization.register(obj, obj.__wbg_ptr, obj);
8
+ return obj;
9
+ }
10
+ __destroy_into_raw() {
11
+ const ptr = this.__wbg_ptr;
12
+ this.__wbg_ptr = 0;
13
+ BakedFinalization.unregister(this);
14
+ return ptr;
15
+ }
16
+ free() {
17
+ const ptr = this.__destroy_into_raw();
18
+ wasm.__wbg_baked_free(ptr, 0);
19
+ }
20
+ /**
21
+ * @returns {Uint8Array}
22
+ */
23
+ bytes() {
24
+ const ret = wasm.baked_bytes(this.__wbg_ptr);
25
+ var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
26
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
27
+ return v1;
28
+ }
29
+ /**
30
+ * @returns {string}
31
+ */
32
+ report() {
33
+ let deferred1_0;
34
+ let deferred1_1;
35
+ try {
36
+ const ret = wasm.baked_report(this.__wbg_ptr);
37
+ deferred1_0 = ret[0];
38
+ deferred1_1 = ret[1];
39
+ return getStringFromWasm0(ret[0], ret[1]);
40
+ } finally {
41
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
42
+ }
43
+ }
44
+ }
45
+ if (Symbol.dispose) Baked.prototype[Symbol.dispose] = Baked.prototype.free;
46
+
47
+ /**
48
+ * @param {string} input_json
49
+ * @returns {Baked}
50
+ */
51
+ export function bakeClips(input_json) {
52
+ const ptr0 = passStringToWasm0(input_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
53
+ const len0 = WASM_VECTOR_LEN;
54
+ const ret = wasm.bakeClips(ptr0, len0);
55
+ if (ret[2]) {
56
+ throw takeFromExternrefTable0(ret[1]);
57
+ }
58
+ return Baked.__wrap(ret[0]);
59
+ }
60
+
61
+ /**
62
+ * Files as parallel lists: names joined by newlines, byte lengths, and the
63
+ * concatenated bytes. Returns `{ ok, failures }` as JSON.
64
+ * @param {string} lock_text
65
+ * @param {string} names
66
+ * @param {Uint32Array} lengths
67
+ * @param {Uint8Array} bytes
68
+ * @param {string} forbid
69
+ * @returns {string}
70
+ */
71
+ export function checkLock(lock_text, names, lengths, bytes, forbid) {
72
+ let deferred7_0;
73
+ let deferred7_1;
74
+ try {
75
+ const ptr0 = passStringToWasm0(lock_text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
76
+ const len0 = WASM_VECTOR_LEN;
77
+ const ptr1 = passStringToWasm0(names, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
78
+ const len1 = WASM_VECTOR_LEN;
79
+ const ptr2 = passArray32ToWasm0(lengths, wasm.__wbindgen_malloc);
80
+ const len2 = WASM_VECTOR_LEN;
81
+ const ptr3 = passArray8ToWasm0(bytes, wasm.__wbindgen_malloc);
82
+ const len3 = WASM_VECTOR_LEN;
83
+ const ptr4 = passStringToWasm0(forbid, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
84
+ const len4 = WASM_VECTOR_LEN;
85
+ const ret = wasm.checkLock(ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3, ptr4, len4);
86
+ var ptr6 = ret[0];
87
+ var len6 = ret[1];
88
+ if (ret[3]) {
89
+ ptr6 = 0; len6 = 0;
90
+ throw takeFromExternrefTable0(ret[2]);
91
+ }
92
+ deferred7_0 = ptr6;
93
+ deferred7_1 = len6;
94
+ return getStringFromWasm0(ptr6, len6);
95
+ } finally {
96
+ wasm.__wbindgen_free(deferred7_0, deferred7_1, 1);
97
+ }
98
+ }
99
+
100
+ /**
101
+ * @param {number} seed
102
+ * @returns {Float64Array}
103
+ */
104
+ export function goldenTrace(seed) {
105
+ const ret = wasm.goldenTrace(seed);
106
+ var v1 = getArrayF64FromWasm0(ret[0], ret[1]).slice();
107
+ wasm.__wbindgen_free(ret[0], ret[1] * 8, 8);
108
+ return v1;
109
+ }
110
+
111
+ /**
112
+ * @param {Uint8Array} glb
113
+ * @returns {string}
114
+ */
115
+ export function listTextures(glb) {
116
+ let deferred3_0;
117
+ let deferred3_1;
118
+ try {
119
+ const ptr0 = passArray8ToWasm0(glb, wasm.__wbindgen_malloc);
120
+ const len0 = WASM_VECTOR_LEN;
121
+ const ret = wasm.listTextures(ptr0, len0);
122
+ var ptr2 = ret[0];
123
+ var len2 = ret[1];
124
+ if (ret[3]) {
125
+ ptr2 = 0; len2 = 0;
126
+ throw takeFromExternrefTable0(ret[2]);
127
+ }
128
+ deferred3_0 = ptr2;
129
+ deferred3_1 = len2;
130
+ return getStringFromWasm0(ptr2, len2);
131
+ } finally {
132
+ wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
133
+ }
134
+ }
135
+
136
+ /**
137
+ * `limits`: baseColor, emissive, normal, orm, other. Replacement images
138
+ * arrive as parallel lists: image index, byte length, concatenated bytes,
139
+ * and mime types joined by newlines.
140
+ * @param {Uint8Array} glb
141
+ * @param {number} ratio
142
+ * @param {number} error
143
+ * @param {boolean} lock_border
144
+ * @param {Uint32Array} limits
145
+ * @param {Uint32Array} images
146
+ * @param {Uint32Array} lengths
147
+ * @param {Uint8Array} bytes
148
+ * @param {string} mimes
149
+ * @returns {Baked}
150
+ */
151
+ export function optimizeGlb(glb, ratio, error, lock_border, limits, images, lengths, bytes, mimes) {
152
+ const ptr0 = passArray8ToWasm0(glb, wasm.__wbindgen_malloc);
153
+ const len0 = WASM_VECTOR_LEN;
154
+ const ptr1 = passArray32ToWasm0(limits, wasm.__wbindgen_malloc);
155
+ const len1 = WASM_VECTOR_LEN;
156
+ const ptr2 = passArray32ToWasm0(images, wasm.__wbindgen_malloc);
157
+ const len2 = WASM_VECTOR_LEN;
158
+ const ptr3 = passArray32ToWasm0(lengths, wasm.__wbindgen_malloc);
159
+ const len3 = WASM_VECTOR_LEN;
160
+ const ptr4 = passArray8ToWasm0(bytes, wasm.__wbindgen_malloc);
161
+ const len4 = WASM_VECTOR_LEN;
162
+ const ptr5 = passStringToWasm0(mimes, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
163
+ const len5 = WASM_VECTOR_LEN;
164
+ const ret = wasm.optimizeGlb(ptr0, len0, ratio, error, lock_border, ptr1, len1, ptr2, len2, ptr3, len3, ptr4, len4, ptr5, len5);
165
+ if (ret[2]) {
166
+ throw takeFromExternrefTable0(ret[1]);
167
+ }
168
+ return Baked.__wrap(ret[0]);
169
+ }
170
+
171
+ /**
172
+ * @param {Uint8Array} bytes
173
+ * @returns {string}
174
+ */
175
+ export function sha256Hex(bytes) {
176
+ let deferred2_0;
177
+ let deferred2_1;
178
+ try {
179
+ const ptr0 = passArray8ToWasm0(bytes, wasm.__wbindgen_malloc);
180
+ const len0 = WASM_VECTOR_LEN;
181
+ const ret = wasm.sha256Hex(ptr0, len0);
182
+ deferred2_0 = ret[0];
183
+ deferred2_1 = ret[1];
184
+ return getStringFromWasm0(ret[0], ret[1]);
185
+ } finally {
186
+ wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
187
+ }
188
+ }
189
+
190
+ /**
191
+ * @param {number} seed
192
+ * @returns {string}
193
+ */
194
+ export function syntheticClips(seed) {
195
+ let deferred1_0;
196
+ let deferred1_1;
197
+ try {
198
+ const ret = wasm.syntheticClips(seed);
199
+ deferred1_0 = ret[0];
200
+ deferred1_1 = ret[1];
201
+ return getStringFromWasm0(ret[0], ret[1]);
202
+ } finally {
203
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
204
+ }
205
+ }
206
+
207
+ /**
208
+ * @param {number} seed
209
+ * @param {number} grid
210
+ * @returns {Uint8Array}
211
+ */
212
+ export function syntheticGlb(seed, grid) {
213
+ const ret = wasm.syntheticGlb(seed, grid);
214
+ var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
215
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
216
+ return v1;
217
+ }
218
+
219
+ /**
220
+ * Entries as JSON in, assets.lock.json text out.
221
+ * @param {string} entries_json
222
+ * @returns {string}
223
+ */
224
+ export function writeLock(entries_json) {
225
+ let deferred3_0;
226
+ let deferred3_1;
227
+ try {
228
+ const ptr0 = passStringToWasm0(entries_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
229
+ const len0 = WASM_VECTOR_LEN;
230
+ const ret = wasm.writeLock(ptr0, len0);
231
+ var ptr2 = ret[0];
232
+ var len2 = ret[1];
233
+ if (ret[3]) {
234
+ ptr2 = 0; len2 = 0;
235
+ throw takeFromExternrefTable0(ret[2]);
236
+ }
237
+ deferred3_0 = ptr2;
238
+ deferred3_1 = len2;
239
+ return getStringFromWasm0(ptr2, len2);
240
+ } finally {
241
+ wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
242
+ }
243
+ }
244
+ function __wbg_get_imports() {
245
+ const import0 = {
246
+ __proto__: null,
247
+ __wbg_Error_30c8987f7c2ed4e2: function(arg0, arg1) {
248
+ const ret = Error(getStringFromWasm0(arg0, arg1));
249
+ return ret;
250
+ },
251
+ __wbg___wbindgen_throw_41e9ee4f547fc59a: function(arg0, arg1) {
252
+ throw new Error(getStringFromWasm0(arg0, arg1));
253
+ },
254
+ __wbindgen_init_externref_table: function() {
255
+ const table = wasm.__wbindgen_externrefs;
256
+ const offset = table.grow(4);
257
+ table.set(0, undefined);
258
+ table.set(offset + 0, undefined);
259
+ table.set(offset + 1, null);
260
+ table.set(offset + 2, true);
261
+ table.set(offset + 3, false);
262
+ },
263
+ };
264
+ return {
265
+ __proto__: null,
266
+ "./bake_bg.js": import0,
267
+ };
268
+ }
269
+
270
+ const BakedFinalization = (typeof FinalizationRegistry === 'undefined')
271
+ ? { register: () => {}, unregister: () => {} }
272
+ : new FinalizationRegistry(ptr => wasm.__wbg_baked_free(ptr, 1));
273
+
274
+ function getArrayF64FromWasm0(ptr, len) {
275
+ ptr = ptr >>> 0;
276
+ return getFloat64ArrayMemory0().subarray(ptr / 8, ptr / 8 + len);
277
+ }
278
+
279
+ function getArrayU8FromWasm0(ptr, len) {
280
+ ptr = ptr >>> 0;
281
+ return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
282
+ }
283
+
284
+ let cachedFloat64ArrayMemory0 = null;
285
+ function getFloat64ArrayMemory0() {
286
+ if (cachedFloat64ArrayMemory0 === null || cachedFloat64ArrayMemory0.byteLength === 0) {
287
+ cachedFloat64ArrayMemory0 = new Float64Array(wasm.memory.buffer);
288
+ }
289
+ return cachedFloat64ArrayMemory0;
290
+ }
291
+
292
+ function getStringFromWasm0(ptr, len) {
293
+ return decodeText(ptr >>> 0, len);
294
+ }
295
+
296
+ let cachedUint32ArrayMemory0 = null;
297
+ function getUint32ArrayMemory0() {
298
+ if (cachedUint32ArrayMemory0 === null || cachedUint32ArrayMemory0.byteLength === 0) {
299
+ cachedUint32ArrayMemory0 = new Uint32Array(wasm.memory.buffer);
300
+ }
301
+ return cachedUint32ArrayMemory0;
302
+ }
303
+
304
+ let cachedUint8ArrayMemory0 = null;
305
+ function getUint8ArrayMemory0() {
306
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
307
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
308
+ }
309
+ return cachedUint8ArrayMemory0;
310
+ }
311
+
312
+ function passArray32ToWasm0(arg, malloc) {
313
+ const ptr = malloc(arg.length * 4, 4) >>> 0;
314
+ getUint32ArrayMemory0().set(arg, ptr / 4);
315
+ WASM_VECTOR_LEN = arg.length;
316
+ return ptr;
317
+ }
318
+
319
+ function passArray8ToWasm0(arg, malloc) {
320
+ const ptr = malloc(arg.length * 1, 1) >>> 0;
321
+ getUint8ArrayMemory0().set(arg, ptr / 1);
322
+ WASM_VECTOR_LEN = arg.length;
323
+ return ptr;
324
+ }
325
+
326
+ function passStringToWasm0(arg, malloc, realloc) {
327
+ if (realloc === undefined) {
328
+ const buf = cachedTextEncoder.encode(arg);
329
+ const ptr = malloc(buf.length, 1) >>> 0;
330
+ getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
331
+ WASM_VECTOR_LEN = buf.length;
332
+ return ptr;
333
+ }
334
+
335
+ let len = arg.length;
336
+ let ptr = malloc(len, 1) >>> 0;
337
+
338
+ const mem = getUint8ArrayMemory0();
339
+
340
+ let offset = 0;
341
+
342
+ for (; offset < len; offset++) {
343
+ const code = arg.charCodeAt(offset);
344
+ if (code > 0x7F) break;
345
+ mem[ptr + offset] = code;
346
+ }
347
+ if (offset !== len) {
348
+ if (offset !== 0) {
349
+ arg = arg.slice(offset);
350
+ }
351
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
352
+ const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
353
+ const ret = cachedTextEncoder.encodeInto(arg, view);
354
+
355
+ offset += ret.written;
356
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
357
+ }
358
+
359
+ WASM_VECTOR_LEN = offset;
360
+ return ptr;
361
+ }
362
+
363
+ function takeFromExternrefTable0(idx) {
364
+ const value = wasm.__wbindgen_externrefs.get(idx);
365
+ wasm.__externref_table_dealloc(idx);
366
+ return value;
367
+ }
368
+
369
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
370
+ cachedTextDecoder.decode();
371
+ const MAX_SAFARI_DECODE_BYTES = 2146435072;
372
+ let numBytesDecoded = 0;
373
+ function decodeText(ptr, len) {
374
+ numBytesDecoded += len;
375
+ if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
376
+ cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
377
+ cachedTextDecoder.decode();
378
+ numBytesDecoded = len;
379
+ }
380
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
381
+ }
382
+
383
+ const cachedTextEncoder = new TextEncoder();
384
+
385
+ if (!('encodeInto' in cachedTextEncoder)) {
386
+ cachedTextEncoder.encodeInto = function (arg, view) {
387
+ const buf = cachedTextEncoder.encode(arg);
388
+ view.set(buf);
389
+ return {
390
+ read: arg.length,
391
+ written: buf.length
392
+ };
393
+ };
394
+ }
395
+
396
+ let WASM_VECTOR_LEN = 0;
397
+
398
+ let wasmModule, wasmInstance, wasm;
399
+ function __wbg_finalize_init(instance, module) {
400
+ wasmInstance = instance;
401
+ wasm = instance.exports;
402
+ wasmModule = module;
403
+ cachedFloat64ArrayMemory0 = null;
404
+ cachedUint32ArrayMemory0 = null;
405
+ cachedUint8ArrayMemory0 = null;
406
+ wasm.__wbindgen_start();
407
+ return wasm;
408
+ }
409
+
410
+ async function __wbg_load(module, imports) {
411
+ if (typeof Response === 'function' && module instanceof Response) {
412
+ if (!module.ok) {
413
+ throw new Error(`failed to fetch Wasm: ${module.status} ${module.statusText} fetching '${module.url}'`);
414
+ }
415
+
416
+ if (typeof WebAssembly.instantiateStreaming === 'function') {
417
+ try {
418
+ return await WebAssembly.instantiateStreaming(module, imports);
419
+ } catch (e) {
420
+ const validResponse = expectedResponseType(module.type);
421
+
422
+ if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
423
+ 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);
424
+
425
+ } else { throw e; }
426
+ }
427
+ }
428
+
429
+ const bytes = await module.arrayBuffer();
430
+ return await WebAssembly.instantiate(bytes, imports);
431
+ } else {
432
+ const instance = await WebAssembly.instantiate(module, imports);
433
+
434
+ if (instance instanceof WebAssembly.Instance) {
435
+ return { instance, module };
436
+ } else {
437
+ return instance;
438
+ }
439
+ }
440
+
441
+ function expectedResponseType(type) {
442
+ switch (type) {
443
+ case 'basic': case 'cors': case 'default': return true;
444
+ }
445
+ return false;
446
+ }
447
+ }
448
+
449
+ function initSync(module) {
450
+ if (wasm !== undefined) return wasm;
451
+
452
+
453
+ if (module !== undefined) {
454
+ if (Object.getPrototypeOf(module) === Object.prototype) {
455
+ ({module} = module)
456
+ } else {
457
+ console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
458
+ }
459
+ }
460
+
461
+ const imports = __wbg_get_imports();
462
+ if (!(module instanceof WebAssembly.Module)) {
463
+ module = new WebAssembly.Module(module);
464
+ }
465
+ const instance = new WebAssembly.Instance(module, imports);
466
+ return __wbg_finalize_init(instance, module);
467
+ }
468
+
469
+ async function __wbg_init(module_or_path) {
470
+ if (wasm !== undefined) return wasm;
471
+
472
+
473
+ if (module_or_path !== undefined) {
474
+ if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
475
+ ({module_or_path} = module_or_path)
476
+ } else {
477
+ console.warn('using deprecated parameters for the initialization function; pass a single object instead')
478
+ }
479
+ }
480
+
481
+ if (module_or_path === undefined) {
482
+ module_or_path = new URL('bake_bg.wasm', import.meta.url);
483
+ }
484
+ const imports = __wbg_get_imports();
485
+
486
+ if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
487
+ module_or_path = fetch(module_or_path);
488
+ }
489
+
490
+ const { instance, module } = await __wbg_load(await module_or_path, imports);
491
+
492
+ return __wbg_finalize_init(instance, module);
493
+ }
494
+
495
+ export { initSync, __wbg_init as default };
Binary file
@@ -0,0 +1,21 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+ export const memory: WebAssembly.Memory;
4
+ export const __wbg_baked_free: (a: number, b: number) => void;
5
+ export const bakeClips: (a: number, b: number) => [number, number, number];
6
+ export const baked_bytes: (a: number) => [number, number];
7
+ export const baked_report: (a: number) => [number, number];
8
+ export const checkLock: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number) => [number, number, number, number];
9
+ export const goldenTrace: (a: number) => [number, number];
10
+ export const listTextures: (a: number, b: number) => [number, number, number, number];
11
+ export const optimizeGlb: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number, k: number, l: number, m: number, n: number, o: number) => [number, number, number];
12
+ export const sha256Hex: (a: number, b: number) => [number, number];
13
+ export const syntheticClips: (a: number) => [number, number];
14
+ export const syntheticGlb: (a: number, b: number) => [number, number];
15
+ export const writeLock: (a: number, b: number) => [number, number, number, number];
16
+ export const __wbindgen_externrefs: WebAssembly.Table;
17
+ export const __wbindgen_malloc: (a: number, b: number) => number;
18
+ export const __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
19
+ export const __externref_table_dealloc: (a: number) => void;
20
+ export const __wbindgen_free: (a: number, b: number, c: number) => void;
21
+ export const __wbindgen_start: () => void;
@@ -0,0 +1,2 @@
1
+ export declare const wasmBase64: string;
2
+ export declare function wasmBytes(): Uint8Array;