@sanox/sangine-core 0.4.2 → 0.4.4

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 (33) hide show
  1. package/dist/assetFetcher.d.ts +3 -0
  2. package/dist/assetFetcher.d.ts.map +1 -0
  3. package/dist/index.cjs.js +1 -1
  4. package/dist/index.es.js +118 -117
  5. package/dist/rendererService.d.ts.map +1 -1
  6. package/dist/wasm/basis-decode/wasm_basis_decode.6c648416.js +283 -0
  7. package/dist/wasm/basis-decode/wasm_basis_decode.d.ts +3 -15
  8. package/dist/wasm/basis-decode/wasm_basis_decode_bg.6c648416.wasm +0 -0
  9. package/dist/wasm/basis-decode/wasm_basis_decode_bg.wasm.d.ts +1 -7
  10. package/dist/wasm/{basis-decode/wasm_basis_decode.a8b7eebd.js → decode/wasm_decode.b6df9f4e.js} +28 -14
  11. package/dist/wasm/decode/wasm_decode.d.ts +61 -0
  12. package/dist/wasm/{basis-decode/wasm_basis_decode_bg.a8b7eebd.wasm → decode/wasm_decode_bg.b6df9f4e.wasm} +0 -0
  13. package/dist/wasm/decode/wasm_decode_bg.wasm.d.ts +17 -0
  14. package/dist/wasm/sangine/{sangine.10c8ee57.js → sangine.48c42a65.js} +1 -1
  15. package/dist/wasm/sangine/sangine.d.ts +1 -1
  16. package/dist/wasm/sangine/{sangine_bg.10c8ee57.wasm → sangine_bg.48c42a65.wasm} +0 -0
  17. package/dist/wasm/sangine/sangine_bg.wasm.d.ts +1 -1
  18. package/dist/wasm/sbo-decode/{wasm_sbo_decode.5c359661.js → wasm_sbo_decode.db6e2054.js} +39 -6
  19. package/dist/wasm/sbo-decode/wasm_sbo_decode_bg.db6e2054.wasm +0 -0
  20. package/dist/wasm-hashes/basis-decode.d.ts +1 -1
  21. package/dist/wasm-hashes/decode.d.ts +2 -0
  22. package/dist/wasm-hashes/decode.d.ts.map +1 -0
  23. package/dist/wasm-hashes/sangine.d.ts +1 -1
  24. package/dist/wasm-hashes/sbo-decode.d.ts +1 -1
  25. package/dist/worker/decodeWorkerImpl.d.ts.map +1 -1
  26. package/dist/worker/pool.d.ts +1 -1
  27. package/dist/worker/pool.d.ts.map +1 -1
  28. package/dist/worker/workerTask.d.ts +12 -0
  29. package/dist/worker/workerTask.d.ts.map +1 -0
  30. package/package.json +1 -1
  31. package/dist/wasm/sbo-decode/wasm_sbo_decode_bg.5c359661.wasm +0 -0
  32. /package/dist/wasm/{basis-decode → decode}/snippets/basisu_c_sys-273c0aeb51b100af/wasm/basisu_transcoder.js +0 -0
  33. /package/dist/wasm/{basis-decode → decode}/snippets/basisu_c_sys-273c0aeb51b100af/wasm/basisu_transcoder.wasm +0 -0
@@ -0,0 +1,3 @@
1
+ export type AssetKind = 'texture' | 'mesh';
2
+ export declare function fetchAndCache(kind: AssetKind, pk: string, url: string): Promise<ArrayBuffer>;
3
+ //# sourceMappingURL=assetFetcher.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"assetFetcher.d.ts","sourceRoot":"","sources":["../src/assetFetcher.ts"],"names":[],"mappings":"AAGA,MAAM,MAAM,SAAS,GAAG,SAAS,GAAG,MAAM,CAAA;AAE1C,wBAAsB,aAAa,CACjC,IAAI,EAAE,SAAS,EACf,EAAE,EAAE,MAAM,EACV,GAAG,EAAE,MAAM,GACV,OAAO,CAAC,WAAW,CAAC,CAiBtB"}
package/dist/index.cjs.js CHANGED
@@ -1 +1 @@
1
- "use strict";var M=Object.defineProperty;var E=(i,e,t)=>e in i?M(i,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[e]=t;var r=(i,e,t)=>E(i,typeof e!="symbol"?e+"":e,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const p="/static/sangine/wasm",W="10c8ee57";class C{constructor(e,t){r(this,"workers");r(this,"idle");r(this,"queue",[]);this.workers=Array.from({length:t},e),this.idle=[...this.workers]}run(e){return new Promise((t,s)=>{const d=this.idle.pop();d?this.dispatch(d,e,t,s):this.queue.push({request:e,resolve:t,reject:s})})}dispatch(e,t,s,d){const c=g=>{s(g.data),m(),this.release(e)},o=g=>{d(g),m(),this.release(e)},m=()=>{e.removeEventListener("message",c),e.removeEventListener("error",o)};e.addEventListener("message",c,{once:!0}),e.addEventListener("error",o,{once:!0}),e.postMessage(t)}release(e){const t=this.queue.shift();t?this.dispatch(e,t.request,t.resolve,t.reject):this.idle.push(e)}broadcast(e){for(const t of this.workers)t.postMessage(e)}terminate(){for(const e of this.workers)e.terminate()}}class P{constructor(e){r(this,"wasm",null);r(this,"callbackRegistry",{});r(this,"userActionRegistry",{});r(this,"assetsDownloadingRegistry",{});r(this,"windowCreatedPromiseRegistry",{});r(this,"windowCreatedPromiseResolveRegistry",{});r(this,"_inited",!1);r(this,"decodePool");r(this,"_readyPromise");r(this,"_resolveReady");r(this,"_rejectReady");this.config=e,this._readyPromise=new Promise((t,s)=>{this._resolveReady=t,this._rejectReady=s}),this.config=e}async init(){if(!(typeof window>"u")){if(this._inited)return this._readyPromise;try{const t=await import(new URL(`${p}/sangine/sangine.${W}.js`,window.location.origin).toString());await t.default(),this.wasm=t,this._inited=!0;const s=this.config.numWorkers??(navigator.hardwareConcurrency||2)-1;this.decodePool=new C(()=>this.config.createDecodeWorker(),Math.max(s,1)),this.wasm.register_asset_decoder(this.decodeAsset.bind(this)),this.wasm.register_event_listener(this.handleSangineEvent.bind(this)),this._resolveReady()}catch(e){throw this._rejectReady(e),e}return this._readyPromise}}ready(){return this._readyPromise}get inited(){return this._inited}getWasm(){if(!this.wasm)throw new Error("RendererService not initialized");return this.wasm}handleActionChanged(e,t){this.userActionRegistry[e]=t;for(const s of this.callbackRegistry[e].actionChanged)s(t)}handleMeasurementCreated(e,t){for(const s of this.callbackRegistry[e].measurementCreated)s(t)}handleRouteUpdated(e,t){for(const s of this.callbackRegistry[e].routeUpdated)s(t)}handleAssetsDownloading(e,t){this.assetsDownloadingRegistry[e]=t;for(const s of this.callbackRegistry[e].assetsDownloading)s(t)}handleUserInteractionStarted(e){for(const t of this.callbackRegistry[e].userInteractionStarted)t()}handleSangineEvent(e,t){t==="ready"?this.windowCreatedPromiseResolveRegistry[e]():t==="userInteractionStarted"?this.handleUserInteractionStarted(e):"actionChanged"in t?this.handleActionChanged(e,t.actionChanged.action):"measurementCreated"in t?this.handleMeasurementCreated(e,t.measurementCreated.measurement):"routeUnderConstructionUpdated"in t?this.handleRouteUpdated(e,t.routeUnderConstructionUpdated.route):"assetsDownloading"in t&&this.handleAssetsDownloading(e,t.assetsDownloading.downloading)}createWindow(e,t,s){if(!this.wasm)throw new Error("WASM not initialized");let d;const c=new Promise(m=>{d=m}),o=this.wasm.create_window(e,t,s);return this.windowCreatedPromiseResolveRegistry[o]=d,this.callbackRegistry[o]={actionChanged:[],routeUpdated:[],measurementCreated:[],assetsDownloading:[],userInteractionStarted:[]},this.userActionRegistry[o]="watching",this.windowCreatedPromiseRegistry[o]=c,o}getAssetsDownloading(e){return this.assetsDownloadingRegistry[e]||!1}readUserAction(e){return this.userActionRegistry[e]}windowReady(e){return this.windowCreatedPromiseRegistry[e]}registerCallback(e,t,s){this.callbackRegistry[e][t].push(s)}setWindowAction(e,t){if(!this.wasm)throw new Error("WASM not initialized");this.wasm.set_window_action(e,t)}destroyWindow(e){if(!this.wasm)throw new Error("WASM not initialized");this.wasm.destroy_window(e),delete this.callbackRegistry[e],delete this.userActionRegistry[e]}setRouteHighlight(e,t,s){if(!this.wasm)throw new Error("WASM not initialized");this.wasm.set_route_highlight(e,t,s)}setRouteVisible(e,t,s){if(!this.wasm)throw new Error("WASM not initialized");this.wasm.set_route_visible(e,t,s)}animateToRoute(e,t){if(!this.wasm)throw new Error("WASM not initialized");this.wasm.animate_to_route(e,t)}setSunProperties(e,t){if(!this.wasm)throw new Error("WASM not initialized");this.wasm.set_sun_properties(e,t)}setAmbientLighting(e,t){if(!this.wasm)throw new Error("WASM not initialized");this.wasm.set_ambient_lighting(e,t)}setLightingMode(e,t){if(!this.wasm)throw new Error("WASM not initialized");this.wasm.set_lighting_mode(e,t)}setNorthCorrection(e,t){if(!this.wasm)throw new Error("WASM not initialized");this.wasm.set_north_correction(e,t)}setGpuMemoryBudgetMb(e,t){if(!this.wasm)throw new Error("WASM not initialized");this.wasm.set_gpu_memory_budget_mb(e,t)}setRenderQuality(e,t){if(!this.wasm)throw new Error("WASM not initialized");this.wasm.set_render_quality(e,t)}readCameraPos(e){if(!this.wasm)throw new Error("WASM not initialized");return this.wasm.read_camera_pos(e)}animateTo(e,t){if(!this.wasm)throw new Error("WASM not initialized");this.wasm.animate_to(e,t)}setScale(e,t){if(!this.wasm)throw new Error("WASM not initialized");this.wasm.set_window_scale(e,t)}async decodeAsset(e){if(!this.decodePool)throw new Error("Renderer not initialized");return this.decodePool.run(e)}destroy(){var e;(e=this.decodePool)==null||e.terminate()}}const k="a8b7eebd",U="5c359661",D=0;function v(i){let e=!1,t=null,s=null,d=!1,c=null;async function o(f,a){if(c){const w=`https://sangine-asset-cache/${f}`,u=await c.match(w);if(u)return u;const l=await fetch(a);return l.ok&&await c.put(w,l.clone()),l}return fetch(a)}async function m(){if(e)return;const a=await import(new URL(`${p}/sbo-decode/wasm_sbo_decode.${U}.js`,i.location.origin).href);await a.default(),t=a,e=!0}async function g(){if(d)return;const a=await import(new URL(`${p}/basis-decode/wasm_basis_decode.${k}.js`,i.location.origin).href);await a.default(),await a.init_basis(),s=a,d=!0}i.onmessage=async f=>{const{data:a}=f;if(!c&&typeof caches<"u"&&(c=await caches.open("sangine-assets-v1")),"texture-file"in a)try{const{pk:w,url:u,format:l,encoding:_}=a["texture-file"];if(_==="ktx2"){await g();const h=await o(w,u);if(!h.ok)throw new Error(`HTTP error! status: ${h.status}`);const b=await h.arrayBuffer(),y=new Uint8Array(b),n=s.transcode_basis(y,l);i.postMessage({success:!0,width:n.width,height:n.height,data:n.data.buffer,format:n.format},[n.data.buffer])}else{const h=await o(w,u);if(!h.ok)throw new Error(`HTTP error! status: ${h.status}`);const b=await h.blob(),y=await createImageBitmap(b),n=new OffscreenCanvas(y.width,y.height),R=n.getContext("2d");if(R===null)throw new Error("Couldnt create canvas");R.drawImage(y,0,0);const S=R.getImageData(0,0,n.width,n.height);i.postMessage({success:!0,width:n.width,height:n.height,data:S.data.buffer,format:D},[S.data.buffer])}}catch(w){i.postMessage({success:!1,error:w.message})}else if("model-part-mesh"in a){await m();const{pk:w,url:u}=a["model-part-mesh"],l=await o(w,u);if(!l.ok)throw new Error(`HTTP error! status: ${l.status}`);const _=await l.arrayBuffer(),A=new Uint8Array(_),h=t.decode_sbo(A);i.postMessage({success:!0,data:h.buffer},[h.buffer])}}}exports.RendererService=P;exports.registerDecodeWorker=v;
1
+ "use strict";var g=Object.defineProperty;var f=(n,e,t)=>e in n?g(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t;var d=(n,e,t)=>f(n,typeof e!="symbol"?e+"":e,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const y="sangine-assets-v2";let l=null;async function u(n,e,t){if(typeof caches>"u"){const a=await fetch(t);if(!a.ok)throw new Error(`fetch ${t} failed: ${a.status}`);return a.arrayBuffer()}l??(l=caches.open(y));const s=await l,o=`https://sangine-asset-cache/${n}/${e}`,r=await s.match(o);if(r)return r.arrayBuffer();const i=await fetch(t);if(!i.ok)throw new Error(`fetch ${t} failed: ${i.status}`);return s.put(o,i.clone()).catch(()=>{}),i.arrayBuffer()}const m="/static/sangine/wasm",_="48c42a65";class b{constructor(e,t){d(this,"workers");d(this,"idle");d(this,"queue",[]);this.workers=Array.from({length:t},e),this.idle=[...this.workers]}run(e,t){return new Promise((s,o)=>{const r=this.idle.pop();r?this.dispatch(r,e,t,s,o):this.queue.push({request:e,transfer:t,resolve:s,reject:o})})}dispatch(e,t,s,o,r){const i=h=>{o(h.data),c(),this.release(e)},a=h=>{r(h),c(),this.release(e)},c=()=>{e.removeEventListener("message",i),e.removeEventListener("error",a)};e.addEventListener("message",i,{once:!0}),e.addEventListener("error",a,{once:!0}),e.postMessage(t,s??[])}release(e){const t=this.queue.shift();t?this.dispatch(e,t.request,t.transfer,t.resolve,t.reject):this.idle.push(e)}broadcast(e){for(const t of this.workers)t.postMessage(e)}terminate(){for(const e of this.workers)e.terminate()}}class R{constructor(e){d(this,"wasm",null);d(this,"callbackRegistry",{});d(this,"userActionRegistry",{});d(this,"assetsDownloadingRegistry",{});d(this,"windowCreatedPromiseRegistry",{});d(this,"windowCreatedPromiseResolveRegistry",{});d(this,"_inited",!1);d(this,"decodePool");d(this,"_readyPromise");d(this,"_resolveReady");d(this,"_rejectReady");this.config=e,this._readyPromise=new Promise((t,s)=>{this._resolveReady=t,this._rejectReady=s}),this.config=e}async init(){if(!(typeof window>"u")){if(this._inited)return this._readyPromise;try{const t=await import(new URL(`${m}/sangine/sangine.${_}.js`,window.location.origin).toString());await t.default(),this.wasm=t,this._inited=!0;const s=Math.min(this.config.numWorkers??(navigator.hardwareConcurrency||2)-1,2);this.decodePool=new b(()=>this.config.createDecodeWorker(),Math.max(s,1)),this.wasm.register_asset_decoder(this.decodeAsset.bind(this)),this.wasm.register_event_listener(this.handleSangineEvent.bind(this)),this._resolveReady()}catch(e){throw this._rejectReady(e),e}return this._readyPromise}}ready(){return this._readyPromise}get inited(){return this._inited}getWasm(){if(!this.wasm)throw new Error("RendererService not initialized");return this.wasm}handleActionChanged(e,t){this.userActionRegistry[e]=t;for(const s of this.callbackRegistry[e].actionChanged)s(t)}handleMeasurementCreated(e,t){for(const s of this.callbackRegistry[e].measurementCreated)s(t)}handleRouteUpdated(e,t){for(const s of this.callbackRegistry[e].routeUpdated)s(t)}handleAssetsDownloading(e,t){this.assetsDownloadingRegistry[e]=t;for(const s of this.callbackRegistry[e].assetsDownloading)s(t)}handleUserInteractionStarted(e){for(const t of this.callbackRegistry[e].userInteractionStarted)t()}handleSangineEvent(e,t){t==="ready"?this.windowCreatedPromiseResolveRegistry[e]():t==="userInteractionStarted"?this.handleUserInteractionStarted(e):"actionChanged"in t?this.handleActionChanged(e,t.actionChanged.action):"measurementCreated"in t?this.handleMeasurementCreated(e,t.measurementCreated.measurement):"routeUnderConstructionUpdated"in t?this.handleRouteUpdated(e,t.routeUnderConstructionUpdated.route):"assetsDownloading"in t&&this.handleAssetsDownloading(e,t.assetsDownloading.downloading)}createWindow(e,t,s){if(!this.wasm)throw new Error("WASM not initialized");let o;const r=new Promise(a=>{o=a}),i=this.wasm.create_window(e,t,s);return this.windowCreatedPromiseResolveRegistry[i]=o,this.callbackRegistry[i]={actionChanged:[],routeUpdated:[],measurementCreated:[],assetsDownloading:[],userInteractionStarted:[]},this.userActionRegistry[i]="watching",this.windowCreatedPromiseRegistry[i]=r,i}getAssetsDownloading(e){return this.assetsDownloadingRegistry[e]||!1}readUserAction(e){return this.userActionRegistry[e]}windowReady(e){return this.windowCreatedPromiseRegistry[e]}registerCallback(e,t,s){this.callbackRegistry[e][t].push(s)}setWindowAction(e,t){if(!this.wasm)throw new Error("WASM not initialized");this.wasm.set_window_action(e,t)}destroyWindow(e){if(!this.wasm)throw new Error("WASM not initialized");this.wasm.destroy_window(e),delete this.callbackRegistry[e],delete this.userActionRegistry[e]}setRouteHighlight(e,t,s){if(!this.wasm)throw new Error("WASM not initialized");this.wasm.set_route_highlight(e,t,s)}setRouteVisible(e,t,s){if(!this.wasm)throw new Error("WASM not initialized");this.wasm.set_route_visible(e,t,s)}animateToRoute(e,t){if(!this.wasm)throw new Error("WASM not initialized");this.wasm.animate_to_route(e,t)}setSunProperties(e,t){if(!this.wasm)throw new Error("WASM not initialized");this.wasm.set_sun_properties(e,t)}setAmbientLighting(e,t){if(!this.wasm)throw new Error("WASM not initialized");this.wasm.set_ambient_lighting(e,t)}setLightingMode(e,t){if(!this.wasm)throw new Error("WASM not initialized");this.wasm.set_lighting_mode(e,t)}setNorthCorrection(e,t){if(!this.wasm)throw new Error("WASM not initialized");this.wasm.set_north_correction(e,t)}setGpuMemoryBudgetMb(e,t){if(!this.wasm)throw new Error("WASM not initialized");this.wasm.set_gpu_memory_budget_mb(e,t)}setRenderQuality(e,t){if(!this.wasm)throw new Error("WASM not initialized");this.wasm.set_render_quality(e,t)}readCameraPos(e){if(!this.wasm)throw new Error("WASM not initialized");return this.wasm.read_camera_pos(e)}animateTo(e,t){if(!this.wasm)throw new Error("WASM not initialized");this.wasm.animate_to(e,t)}setScale(e,t){if(!this.wasm)throw new Error("WASM not initialized");this.wasm.set_window_scale(e,t)}async decodeAsset(e){if(!this.decodePool)throw new Error("Renderer not initialized");if("texture-file"in e){const{pk:r,url:i,encoding:a,format:c}=e["texture-file"],h=await u("texture",r,i);return a==="ktx2"?this.decodePool.run({kind:"texture-basis",bytes:h,format:c},[h]):this.decodePool.run({kind:"texture-image",bytes:h},[h])}const{pk:t,url:s}=e["model-part-mesh"],o=await u("mesh",t,s);return this.decodePool.run({kind:"model-sbo",bytes:o},[o])}destroy(){var e;(e=this.decodePool)==null||e.terminate()}}const p="b6df9f4e",A=0;function M(n){let e=!1,t=null;async function s(){if(e)return;const r=await import(new URL(`${m}/decode/wasm_decode.${p}.js`,n.location.origin).href);await r.default(),await r.init_basis(),t=r,e=!0}n.onmessage=async o=>{const r=o.data;try{if(r.kind==="texture-basis"){await s();const i=new Uint8Array(r.bytes),a=t.transcode_basis(i,r.format);n.postMessage({success:!0,width:a.width,height:a.height,data:a.data.buffer,format:a.format},[a.data.buffer])}else if(r.kind==="texture-image"){const i=new Blob([r.bytes]),a=await createImageBitmap(i),c=new OffscreenCanvas(a.width,a.height),h=c.getContext("2d");if(h===null)throw new Error("Couldnt create canvas");h.drawImage(a,0,0);const w=h.getImageData(0,0,c.width,c.height);n.postMessage({success:!0,width:c.width,height:c.height,data:w.data.buffer,format:A},[w.data.buffer])}else if(r.kind==="model-sbo"){await s();const i=new Uint8Array(r.bytes),a=t.decode_sbo(i);n.postMessage({success:!0,data:a.buffer},[a.buffer])}else{const i=r;throw new Error(`unknown task kind: ${i.kind}`)}}catch(i){n.postMessage({success:!1,error:i.message})}}}exports.RendererService=R;exports.registerDecodeWorker=M;
package/dist/index.es.js CHANGED
@@ -1,33 +1,49 @@
1
- var E = Object.defineProperty;
2
- var M = (i, e, t) => e in i ? E(i, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : i[e] = t;
3
- var r = (i, e, t) => M(i, typeof e != "symbol" ? e + "" : e, t);
4
- const p = "/static/sangine/wasm", C = "10c8ee57";
5
- class W {
1
+ var g = Object.defineProperty;
2
+ var f = (n, e, t) => e in n ? g(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t;
3
+ var d = (n, e, t) => f(n, typeof e != "symbol" ? e + "" : e, t);
4
+ const y = "sangine-assets-v2";
5
+ let l = null;
6
+ async function m(n, e, t) {
7
+ if (typeof caches > "u") {
8
+ const a = await fetch(t);
9
+ if (!a.ok) throw new Error(`fetch ${t} failed: ${a.status}`);
10
+ return a.arrayBuffer();
11
+ }
12
+ l ?? (l = caches.open(y));
13
+ const s = await l, o = `https://sangine-asset-cache/${n}/${e}`, r = await s.match(o);
14
+ if (r) return r.arrayBuffer();
15
+ const i = await fetch(t);
16
+ if (!i.ok) throw new Error(`fetch ${t} failed: ${i.status}`);
17
+ return s.put(o, i.clone()).catch(() => {
18
+ }), i.arrayBuffer();
19
+ }
20
+ const u = "/static/sangine/wasm", _ = "48c42a65";
21
+ class b {
6
22
  constructor(e, t) {
7
- r(this, "workers");
8
- r(this, "idle");
9
- r(this, "queue", []);
23
+ d(this, "workers");
24
+ d(this, "idle");
25
+ d(this, "queue", []);
10
26
  this.workers = Array.from({ length: t }, e), this.idle = [...this.workers];
11
27
  }
12
- run(e) {
13
- return new Promise((t, s) => {
14
- const d = this.idle.pop();
15
- d ? this.dispatch(d, e, t, s) : this.queue.push({ request: e, resolve: t, reject: s });
28
+ run(e, t) {
29
+ return new Promise((s, o) => {
30
+ const r = this.idle.pop();
31
+ r ? this.dispatch(r, e, t, s, o) : this.queue.push({ request: e, transfer: t, resolve: s, reject: o });
16
32
  });
17
33
  }
18
- dispatch(e, t, s, d) {
19
- const c = (g) => {
20
- s(g.data), m(), this.release(e);
21
- }, o = (g) => {
22
- d(g), m(), this.release(e);
23
- }, m = () => {
24
- e.removeEventListener("message", c), e.removeEventListener("error", o);
34
+ dispatch(e, t, s, o, r) {
35
+ const i = (h) => {
36
+ o(h.data), c(), this.release(e);
37
+ }, a = (h) => {
38
+ r(h), c(), this.release(e);
39
+ }, c = () => {
40
+ e.removeEventListener("message", i), e.removeEventListener("error", a);
25
41
  };
26
- e.addEventListener("message", c, { once: !0 }), e.addEventListener("error", o, { once: !0 }), e.postMessage(t);
42
+ e.addEventListener("message", i, { once: !0 }), e.addEventListener("error", a, { once: !0 }), e.postMessage(t, s ?? []);
27
43
  }
28
44
  release(e) {
29
45
  const t = this.queue.shift();
30
- t ? this.dispatch(e, t.request, t.resolve, t.reject) : this.idle.push(e);
46
+ t ? this.dispatch(e, t.request, t.transfer, t.resolve, t.reject) : this.idle.push(e);
31
47
  }
32
48
  broadcast(e) {
33
49
  for (const t of this.workers)
@@ -38,19 +54,19 @@ class W {
38
54
  e.terminate();
39
55
  }
40
56
  }
41
- class z {
57
+ class M {
42
58
  constructor(e) {
43
- r(this, "wasm", null);
44
- r(this, "callbackRegistry", {});
45
- r(this, "userActionRegistry", {});
46
- r(this, "assetsDownloadingRegistry", {});
47
- r(this, "windowCreatedPromiseRegistry", {});
48
- r(this, "windowCreatedPromiseResolveRegistry", {});
49
- r(this, "_inited", !1);
50
- r(this, "decodePool");
51
- r(this, "_readyPromise");
52
- r(this, "_resolveReady");
53
- r(this, "_rejectReady");
59
+ d(this, "wasm", null);
60
+ d(this, "callbackRegistry", {});
61
+ d(this, "userActionRegistry", {});
62
+ d(this, "assetsDownloadingRegistry", {});
63
+ d(this, "windowCreatedPromiseRegistry", {});
64
+ d(this, "windowCreatedPromiseResolveRegistry", {});
65
+ d(this, "_inited", !1);
66
+ d(this, "decodePool");
67
+ d(this, "_readyPromise");
68
+ d(this, "_resolveReady");
69
+ d(this, "_rejectReady");
54
70
  this.config = e, this._readyPromise = new Promise((t, s) => {
55
71
  this._resolveReady = t, this._rejectReady = s;
56
72
  }), this.config = e;
@@ -60,12 +76,15 @@ class z {
60
76
  if (this._inited) return this._readyPromise;
61
77
  try {
62
78
  const t = await import(new URL(
63
- `${p}/sangine/sangine.${C}.js`,
79
+ `${u}/sangine/sangine.${_}.js`,
64
80
  window.location.origin
65
81
  ).toString());
66
82
  await t.default(), this.wasm = t, this._inited = !0;
67
- const s = this.config.numWorkers ?? (navigator.hardwareConcurrency || 2) - 1;
68
- this.decodePool = new W(
83
+ const s = Math.min(
84
+ this.config.numWorkers ?? (navigator.hardwareConcurrency || 2) - 1,
85
+ 2
86
+ );
87
+ this.decodePool = new b(
69
88
  () => this.config.createDecodeWorker(),
70
89
  Math.max(s, 1)
71
90
  ), this.wasm.register_asset_decoder(this.decodeAsset.bind(this)), this.wasm.register_event_listener(this.handleSangineEvent.bind(this)), this._resolveReady();
@@ -113,17 +132,17 @@ class z {
113
132
  }
114
133
  createWindow(e, t, s) {
115
134
  if (!this.wasm) throw new Error("WASM not initialized");
116
- let d;
117
- const c = new Promise((m) => {
118
- d = m;
119
- }), o = this.wasm.create_window(e, t, s);
120
- return this.windowCreatedPromiseResolveRegistry[o] = d, this.callbackRegistry[o] = {
135
+ let o;
136
+ const r = new Promise((a) => {
137
+ o = a;
138
+ }), i = this.wasm.create_window(e, t, s);
139
+ return this.windowCreatedPromiseResolveRegistry[i] = o, this.callbackRegistry[i] = {
121
140
  actionChanged: [],
122
141
  routeUpdated: [],
123
142
  measurementCreated: [],
124
143
  assetsDownloading: [],
125
144
  userInteractionStarted: []
126
- }, this.userActionRegistry[o] = "watching", this.windowCreatedPromiseRegistry[o] = c, o;
145
+ }, this.userActionRegistry[i] = "watching", this.windowCreatedPromiseRegistry[i] = r, i;
127
146
  }
128
147
  getAssetsDownloading(e) {
129
148
  return this.assetsDownloadingRegistry[e] || !1;
@@ -195,92 +214,74 @@ class z {
195
214
  }
196
215
  async decodeAsset(e) {
197
216
  if (!this.decodePool) throw new Error("Renderer not initialized");
198
- return this.decodePool.run(e);
217
+ if ("texture-file" in e) {
218
+ const { pk: r, url: i, encoding: a, format: c } = e["texture-file"], h = await m("texture", r, i);
219
+ return a === "ktx2" ? this.decodePool.run({ kind: "texture-basis", bytes: h, format: c }, [h]) : this.decodePool.run({ kind: "texture-image", bytes: h }, [h]);
220
+ }
221
+ const { pk: t, url: s } = e["model-part-mesh"], o = await m("mesh", t, s);
222
+ return this.decodePool.run({ kind: "model-sbo", bytes: o }, [o]);
199
223
  }
200
224
  destroy() {
201
225
  var e;
202
226
  (e = this.decodePool) == null || e.terminate();
203
227
  }
204
228
  }
205
- const P = "a8b7eebd", k = "5c359661", U = 0;
206
- function v(i) {
207
- let e = !1, t = null, s = null, d = !1, c = null;
208
- async function o(f, a) {
209
- if (c) {
210
- const w = `https://sangine-asset-cache/${f}`, u = await c.match(w);
211
- if (u) return u;
212
- const l = await fetch(a);
213
- return l.ok && await c.put(w, l.clone()), l;
214
- }
215
- return fetch(a);
216
- }
217
- async function m() {
229
+ const R = "b6df9f4e", p = 0;
230
+ function E(n) {
231
+ let e = !1, t = null;
232
+ async function s() {
218
233
  if (e) return;
219
- const a = await import(new URL(
220
- `${p}/sbo-decode/wasm_sbo_decode.${k}.js`,
221
- i.location.origin
234
+ const r = await import(new URL(
235
+ `${u}/decode/wasm_decode.${R}.js`,
236
+ n.location.origin
222
237
  ).href);
223
- await a.default(), t = a, e = !0;
224
- }
225
- async function g() {
226
- if (d) return;
227
- const a = await import(new URL(
228
- `${p}/basis-decode/wasm_basis_decode.${P}.js`,
229
- i.location.origin
230
- ).href);
231
- await a.default(), await a.init_basis(), s = a, d = !0;
232
- }
233
- i.onmessage = async (f) => {
234
- const { data: a } = f;
235
- if (!c && typeof caches < "u" && (c = await caches.open("sangine-assets-v1")), "texture-file" in a)
236
- try {
237
- const { pk: w, url: u, format: l, encoding: _ } = a["texture-file"];
238
- if (_ === "ktx2") {
239
- await g();
240
- const h = await o(w, u);
241
- if (!h.ok) throw new Error(`HTTP error! status: ${h.status}`);
242
- const b = await h.arrayBuffer(), y = new Uint8Array(b), n = s.transcode_basis(y, l);
243
- i.postMessage(
244
- {
245
- success: !0,
246
- width: n.width,
247
- height: n.height,
248
- data: n.data.buffer,
249
- format: n.format
250
- },
251
- [n.data.buffer]
252
- );
253
- } else {
254
- const h = await o(w, u);
255
- if (!h.ok) throw new Error(`HTTP error! status: ${h.status}`);
256
- const b = await h.blob(), y = await createImageBitmap(b), n = new OffscreenCanvas(y.width, y.height), R = n.getContext("2d");
257
- if (R === null) throw new Error("Couldnt create canvas");
258
- R.drawImage(y, 0, 0);
259
- const S = R.getImageData(0, 0, n.width, n.height);
260
- i.postMessage(
261
- {
262
- success: !0,
263
- width: n.width,
264
- height: n.height,
265
- data: S.data.buffer,
266
- format: U
267
- },
268
- [S.data.buffer]
269
- );
270
- }
271
- } catch (w) {
272
- i.postMessage({ success: !1, error: w.message });
238
+ await r.default(), await r.init_basis(), t = r, e = !0;
239
+ }
240
+ n.onmessage = async (o) => {
241
+ const r = o.data;
242
+ try {
243
+ if (r.kind === "texture-basis") {
244
+ await s();
245
+ const i = new Uint8Array(r.bytes), a = t.transcode_basis(i, r.format);
246
+ n.postMessage(
247
+ {
248
+ success: !0,
249
+ width: a.width,
250
+ height: a.height,
251
+ data: a.data.buffer,
252
+ format: a.format
253
+ },
254
+ [a.data.buffer]
255
+ );
256
+ } else if (r.kind === "texture-image") {
257
+ const i = new Blob([r.bytes]), a = await createImageBitmap(i), c = new OffscreenCanvas(a.width, a.height), h = c.getContext("2d");
258
+ if (h === null) throw new Error("Couldnt create canvas");
259
+ h.drawImage(a, 0, 0);
260
+ const w = h.getImageData(0, 0, c.width, c.height);
261
+ n.postMessage(
262
+ {
263
+ success: !0,
264
+ width: c.width,
265
+ height: c.height,
266
+ data: w.data.buffer,
267
+ format: p
268
+ },
269
+ [w.data.buffer]
270
+ );
271
+ } else if (r.kind === "model-sbo") {
272
+ await s();
273
+ const i = new Uint8Array(r.bytes), a = t.decode_sbo(i);
274
+ n.postMessage({ success: !0, data: a.buffer }, [a.buffer]);
275
+ } else {
276
+ const i = r;
277
+ throw new Error(`unknown task kind: ${i.kind}`);
273
278
  }
274
- else if ("model-part-mesh" in a) {
275
- await m();
276
- const { pk: w, url: u } = a["model-part-mesh"], l = await o(w, u);
277
- if (!l.ok) throw new Error(`HTTP error! status: ${l.status}`);
278
- const _ = await l.arrayBuffer(), A = new Uint8Array(_), h = t.decode_sbo(A);
279
- i.postMessage({ success: !0, data: h.buffer }, [h.buffer]);
279
+ } catch (i) {
280
+ n.postMessage({ success: !1, error: i.message });
280
281
  }
281
282
  };
282
283
  }
283
284
  export {
284
- z as RendererService,
285
- v as registerDecodeWorker
285
+ M as RendererService,
286
+ E as registerDecodeWorker
286
287
  };
@@ -1 +1 @@
1
- {"version":3,"file":"rendererService.d.ts","sourceRoot":"","sources":["../src/rendererService.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,SAAS,EACT,UAAU,EACV,uBAAuB,EACvB,YAAY,EACZ,WAAW,EACX,oBAAoB,EACpB,cAAc,EACd,iBAAiB,EACjB,KAAK,EACL,YAAY,EACZ,KAAK,EACL,aAAa,EACb,UAAU,EACX,MAAM,YAAY,CAAA;AAEnB,OAAO,KAAK,KAAK,aAAa,MAAM,sBAAsB,CAAA;AAI1D,KAAK,qBAAqB,GAAG,CAAC,MAAM,EAAE,UAAU,KAAK,IAAI,CAAA;AACzD,KAAK,oBAAoB,GAAG,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAA;AAClD,KAAK,0BAA0B,GAAG,CAAC,WAAW,EAAE,WAAW,KAAK,IAAI,CAAA;AACpE,KAAK,yBAAyB,GAAG,CAAC,WAAW,EAAE,OAAO,KAAK,IAAI,CAAA;AAC/D,KAAK,YAAY,GAAG,MAAM,IAAI,CAAA;AAE9B,UAAU,WAAW;IACnB,aAAa,EAAE,qBAAqB,CAAA;IACpC,YAAY,EAAE,oBAA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AAO,EAAE,MAAM;IAKhD,gBAAgB,CAAC,QAAQ,EAAE,MAAM,EAAE,aAAa,EAAE,aAAa;IAK/D,kBAAkB,CAAC,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,uBAAuB;IAKxE,eAAe,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,YAAY;IAKpD,kBAAkB,CAAC,QAAQ,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM;IAK5D,oBAAoB,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM;IAKvD,gBAAgB,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,oBAAoB;IAKhE,aAAa,CAAC,QAAQ,EAAE,MAAM,GAAG,SAAS;IAK1C,SAAS,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,SAAS;IAK/C,QAAQ,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM;IAKlC,WAAW,CAAC,IAAI,EAAE,UAAU,GAAG,OAAO,CAAC,WAAW,CAAC;IAezD,OAAO;CAGR"}
@@ -0,0 +1,283 @@
1
+ /* @ts-self-types="./wasm_basis_decode.d.ts" */
2
+
3
+ //#region exports
4
+
5
+ /**
6
+ * Transcode a .basis file to a GPU-compressed (or RGBA32) format.
7
+ *
8
+ * `format`: 0=RGBA32, 1=ETC2_RGBA8, 2=ASTC_4×4, 3=BC7
9
+ *
10
+ * Returns a JS object `{ data: Uint8Array, width: u32, height: u32, format: u32 }`.
11
+ * @param {Uint8Array} data
12
+ * @param {number} format
13
+ * @returns {object}
14
+ */
15
+ export function transcode_basis(data, format) {
16
+ const ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_malloc);
17
+ const len0 = WASM_VECTOR_LEN;
18
+ _assertNum(format);
19
+ const ret = wasm.transcode_basis(ptr0, len0, format);
20
+ if (ret[2]) {
21
+ throw takeFromExternrefTable0(ret[1]);
22
+ }
23
+ return takeFromExternrefTable0(ret[0]);
24
+ }
25
+
26
+ //#endregion
27
+
28
+ //#region wasm imports
29
+ import * as import1 from "env"
30
+ import * as import2 from "env"
31
+ import * as import3 from "env"
32
+ import * as import4 from "env"
33
+ import * as import5 from "env"
34
+ import * as import6 from "env"
35
+ import * as import7 from "env"
36
+ import * as import8 from "env"
37
+ import * as import9 from "env"
38
+ import * as import10 from "env"
39
+
40
+ function __wbg_get_imports() {
41
+ const import0 = {
42
+ __proto__: null,
43
+ __wbg___wbindgen_throw_be289d5034ed271b: function(arg0, arg1) {
44
+ throw new Error(getStringFromWasm0(arg0, arg1));
45
+ },
46
+ __wbg_new_361308b2356cecd0: function() { return logError(function () {
47
+ const ret = new Object();
48
+ return ret;
49
+ }, arguments); },
50
+ __wbg_new_from_slice_a3d2629dc1826784: function() { return logError(function (arg0, arg1) {
51
+ const ret = new Uint8Array(getArrayU8FromWasm0(arg0, arg1));
52
+ return ret;
53
+ }, arguments); },
54
+ __wbg_set_6cb8631f80447a67: function() { return handleError(function (arg0, arg1, arg2) {
55
+ const ret = Reflect.set(arg0, arg1, arg2);
56
+ _assertBoolean(ret);
57
+ return ret;
58
+ }, arguments); },
59
+ __wbindgen_cast_0000000000000001: function() { return logError(function (arg0) {
60
+ // Cast intrinsic for `F64 -> Externref`.
61
+ const ret = arg0;
62
+ return ret;
63
+ }, arguments); },
64
+ __wbindgen_cast_0000000000000002: function() { return logError(function (arg0, arg1) {
65
+ // Cast intrinsic for `Ref(String) -> Externref`.
66
+ const ret = getStringFromWasm0(arg0, arg1);
67
+ return ret;
68
+ }, arguments); },
69
+ __wbindgen_init_externref_table: function() {
70
+ const table = wasm.__wbindgen_externrefs;
71
+ const offset = table.grow(4);
72
+ table.set(0, undefined);
73
+ table.set(offset + 0, undefined);
74
+ table.set(offset + 1, null);
75
+ table.set(offset + 2, true);
76
+ table.set(offset + 3, false);
77
+ },
78
+ };
79
+ return {
80
+ __proto__: null,
81
+ "./wasm_basis_decode_bg.js": import0,
82
+ "env": import1,
83
+ "env": import2,
84
+ "env": import3,
85
+ "env": import4,
86
+ "env": import5,
87
+ "env": import6,
88
+ "env": import7,
89
+ "env": import8,
90
+ "env": import9,
91
+ "env": import10,
92
+ };
93
+ }
94
+
95
+
96
+ //#endregion
97
+
98
+ //#region intrinsics
99
+ function addToExternrefTable0(obj) {
100
+ const idx = wasm.__externref_table_alloc();
101
+ wasm.__wbindgen_externrefs.set(idx, obj);
102
+ return idx;
103
+ }
104
+
105
+ function _assertBoolean(n) {
106
+ if (typeof(n) !== 'boolean') {
107
+ throw new Error(`expected a boolean argument, found ${typeof(n)}`);
108
+ }
109
+ }
110
+
111
+ function _assertNum(n) {
112
+ if (typeof(n) !== 'number') throw new Error(`expected a number argument, found ${typeof(n)}`);
113
+ }
114
+
115
+ function getArrayU8FromWasm0(ptr, len) {
116
+ ptr = ptr >>> 0;
117
+ return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
118
+ }
119
+
120
+ function getStringFromWasm0(ptr, len) {
121
+ ptr = ptr >>> 0;
122
+ return decodeText(ptr, len);
123
+ }
124
+
125
+ let cachedUint8ArrayMemory0 = null;
126
+ function getUint8ArrayMemory0() {
127
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
128
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
129
+ }
130
+ return cachedUint8ArrayMemory0;
131
+ }
132
+
133
+ function handleError(f, args) {
134
+ try {
135
+ return f.apply(this, args);
136
+ } catch (e) {
137
+ const idx = addToExternrefTable0(e);
138
+ wasm.__wbindgen_exn_store(idx);
139
+ }
140
+ }
141
+
142
+ function logError(f, args) {
143
+ try {
144
+ return f.apply(this, args);
145
+ } catch (e) {
146
+ let error = (function () {
147
+ try {
148
+ return e instanceof Error ? `${e.message}\n\nStack:\n${e.stack}` : e.toString();
149
+ } catch(_) {
150
+ return "<failed to stringify thrown value>";
151
+ }
152
+ }());
153
+ console.error("wasm-bindgen: imported JS function that was not marked as `catch` threw an error:", error);
154
+ throw e;
155
+ }
156
+ }
157
+
158
+ function passArray8ToWasm0(arg, malloc) {
159
+ const ptr = malloc(arg.length * 1, 1) >>> 0;
160
+ getUint8ArrayMemory0().set(arg, ptr / 1);
161
+ WASM_VECTOR_LEN = arg.length;
162
+ return ptr;
163
+ }
164
+
165
+ function takeFromExternrefTable0(idx) {
166
+ const value = wasm.__wbindgen_externrefs.get(idx);
167
+ wasm.__externref_table_dealloc(idx);
168
+ return value;
169
+ }
170
+
171
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
172
+ cachedTextDecoder.decode();
173
+ const MAX_SAFARI_DECODE_BYTES = 2146435072;
174
+ let numBytesDecoded = 0;
175
+ function decodeText(ptr, len) {
176
+ numBytesDecoded += len;
177
+ if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
178
+ cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
179
+ cachedTextDecoder.decode();
180
+ numBytesDecoded = len;
181
+ }
182
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
183
+ }
184
+
185
+ let WASM_VECTOR_LEN = 0;
186
+
187
+
188
+ //#endregion
189
+
190
+ //#region wasm loading
191
+ let wasmModule, wasm;
192
+ function __wbg_finalize_init(instance, module) {
193
+ wasm = instance.exports;
194
+ wasmModule = module;
195
+ cachedUint8ArrayMemory0 = null;
196
+ wasm.__wbindgen_start();
197
+ return wasm;
198
+ }
199
+
200
+ async function __wbg_load(module, imports) {
201
+ if (typeof Response === 'function' && module instanceof Response) {
202
+ if (typeof WebAssembly.instantiateStreaming === 'function') {
203
+ try {
204
+ return await WebAssembly.instantiateStreaming(module, imports);
205
+ } catch (e) {
206
+ const validResponse = module.ok && expectedResponseType(module.type);
207
+
208
+ if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
209
+ 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);
210
+
211
+ } else { throw e; }
212
+ }
213
+ }
214
+
215
+ const bytes = await module.arrayBuffer();
216
+ return await WebAssembly.instantiate(bytes, imports);
217
+ } else {
218
+ const instance = await WebAssembly.instantiate(module, imports);
219
+
220
+ if (instance instanceof WebAssembly.Instance) {
221
+ return { instance, module };
222
+ } else {
223
+ return instance;
224
+ }
225
+ }
226
+
227
+ function expectedResponseType(type) {
228
+ switch (type) {
229
+ case 'basic': case 'cors': case 'default': return true;
230
+ }
231
+ return false;
232
+ }
233
+ }
234
+
235
+ function initSync(module) {
236
+ if (wasm !== undefined) return wasm;
237
+
238
+
239
+ if (module !== undefined) {
240
+ if (Object.getPrototypeOf(module) === Object.prototype) {
241
+ ({module} = module)
242
+ } else {
243
+ console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
244
+ }
245
+ }
246
+
247
+ const imports = __wbg_get_imports();
248
+ if (!(module instanceof WebAssembly.Module)) {
249
+ module = new WebAssembly.Module(module);
250
+ }
251
+ const instance = new WebAssembly.Instance(module, imports);
252
+ return __wbg_finalize_init(instance, module);
253
+ }
254
+
255
+ async function __wbg_init(module_or_path) {
256
+ if (wasm !== undefined) return wasm;
257
+
258
+
259
+ if (module_or_path !== undefined) {
260
+ if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
261
+ ({module_or_path} = module_or_path)
262
+ } else {
263
+ console.warn('using deprecated parameters for the initialization function; pass a single object instead')
264
+ }
265
+ }
266
+
267
+ if (module_or_path === undefined) {
268
+ module_or_path = new URL('wasm_basis_decode_bg.6c648416.wasm', import.meta.url);
269
+ }
270
+ const imports = __wbg_get_imports();
271
+
272
+ if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
273
+ module_or_path = fetch(module_or_path);
274
+ }
275
+
276
+ const { instance, module } = await __wbg_load(await module_or_path, imports);
277
+
278
+ return __wbg_finalize_init(instance, module);
279
+ }
280
+
281
+ export { initSync, __wbg_init as default };
282
+ //#endregion
283
+ export { wasm as __wasm }
@@ -2,17 +2,11 @@
2
2
  /* eslint-disable */
3
3
 
4
4
  /**
5
- * Initialize the embedded basisu transcoder WASM.
6
- * Must be awaited once after the outer WASM module's `default()` init.
7
- */
8
- export function init_basis(): Promise<any>;
9
-
10
- /**
11
- * Transcode a KTX2/basis file to a GPU-compressed (or RGBA32) format.
5
+ * Transcode a .basis file to a GPU-compressed (or RGBA32) format.
12
6
  *
13
7
  * `format`: 0=RGBA32, 1=ETC2_RGBA8, 2=ASTC_4×4, 3=BC7
14
8
  *
15
- * Returns `{ data: Uint8Array, width: u32, height: u32, format: u32 }`.
9
+ * Returns a JS object `{ data: Uint8Array, width: u32, height: u32, format: u32 }`.
16
10
  */
17
11
  export function transcode_basis(data: Uint8Array, format: number): object;
18
12
 
@@ -21,16 +15,10 @@ export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembl
21
15
  export interface InitOutput {
22
16
  readonly memory: WebAssembly.Memory;
23
17
  readonly transcode_basis: (a: number, b: number, c: number) => [number, number, number];
24
- readonly init_basis: () => any;
25
- readonly wasm_bindgen__convert__closures_____invoke__h1a884335adcc7c22: (a: number, b: number, c: any) => [number, number];
26
- readonly wasm_bindgen__convert__closures_____invoke__hfcaf9f68983c0e6f: (a: number, b: number, c: any) => [number, number];
27
- readonly wasm_bindgen__convert__closures_____invoke__h16cb8cb7feea2290: (a: number, b: number, c: any, d: any) => void;
28
- readonly __wbindgen_malloc: (a: number, b: number) => number;
29
- readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
30
18
  readonly __wbindgen_exn_store: (a: number) => void;
31
19
  readonly __externref_table_alloc: () => number;
32
20
  readonly __wbindgen_externrefs: WebAssembly.Table;
33
- readonly __wbindgen_destroy_closure: (a: number, b: number) => void;
21
+ readonly __wbindgen_malloc: (a: number, b: number) => number;
34
22
  readonly __externref_table_dealloc: (a: number) => void;
35
23
  readonly __wbindgen_start: () => void;
36
24
  }
@@ -2,15 +2,9 @@
2
2
  /* eslint-disable */
3
3
  export const memory: WebAssembly.Memory;
4
4
  export const transcode_basis: (a: number, b: number, c: number) => [number, number, number];
5
- export const init_basis: () => any;
6
- export const wasm_bindgen__convert__closures_____invoke__h1a884335adcc7c22: (a: number, b: number, c: any) => [number, number];
7
- export const wasm_bindgen__convert__closures_____invoke__hfcaf9f68983c0e6f: (a: number, b: number, c: any) => [number, number];
8
- export const wasm_bindgen__convert__closures_____invoke__h16cb8cb7feea2290: (a: number, b: number, c: any, d: any) => void;
9
- export const __wbindgen_malloc: (a: number, b: number) => number;
10
- export const __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
11
5
  export const __wbindgen_exn_store: (a: number) => void;
12
6
  export const __externref_table_alloc: () => number;
13
7
  export const __wbindgen_externrefs: WebAssembly.Table;
14
- export const __wbindgen_destroy_closure: (a: number, b: number) => void;
8
+ export const __wbindgen_malloc: (a: number, b: number) => number;
15
9
  export const __externref_table_dealloc: (a: number) => void;
16
10
  export const __wbindgen_start: () => void;
@@ -1,7 +1,21 @@
1
- /* @ts-self-types="./wasm_basis_decode.d.ts" */
1
+ /* @ts-self-types="./wasm_decode.d.ts" */
2
2
  import * as import1 from "./snippets/basisu_c_sys-273c0aeb51b100af/wasm/basisu_transcoder.js"
3
3
 
4
4
 
5
+ /**
6
+ * @param {Uint8Array} data
7
+ * @returns {Uint8Array}
8
+ */
9
+ export function decode_sbo(data) {
10
+ const ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_malloc);
11
+ const len0 = WASM_VECTOR_LEN;
12
+ const ret = wasm.decode_sbo(ptr0, len0);
13
+ if (ret[2]) {
14
+ throw takeFromExternrefTable0(ret[1]);
15
+ }
16
+ return takeFromExternrefTable0(ret[0]);
17
+ }
18
+
5
19
  /**
6
20
  * Initialize the embedded basisu transcoder WASM.
7
21
  * Must be awaited once after the outer WASM module's `default()` init.
@@ -123,7 +137,7 @@ function __wbg_get_imports() {
123
137
  const a = state0.a;
124
138
  state0.a = 0;
125
139
  try {
126
- return wasm_bindgen__convert__closures_____invoke__h16cb8cb7feea2290(a, state0.b, arg0, arg1);
140
+ return wasm_bindgen__convert__closures_____invoke__h3d076a640fe381ba(a, state0.b, arg0, arg1);
127
141
  } finally {
128
142
  state0.a = a;
129
143
  }
@@ -184,13 +198,13 @@ function __wbg_get_imports() {
184
198
  return ret;
185
199
  },
186
200
  __wbindgen_cast_0000000000000001: function(arg0, arg1) {
187
- // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [Externref], shim_idx: 32, ret: Result(Unit), inner_ret: Some(Result(Unit)) }, mutable: true }) -> Externref`.
188
- const ret = makeMutClosure(arg0, arg1, wasm_bindgen__convert__closures_____invoke__h1a884335adcc7c22);
201
+ // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [Externref], shim_idx: 74, ret: Result(Unit), inner_ret: Some(Result(Unit)) }, mutable: true }) -> Externref`.
202
+ const ret = makeMutClosure(arg0, arg1, wasm_bindgen__convert__closures_____invoke__hffc9f1a16a180456);
189
203
  return ret;
190
204
  },
191
205
  __wbindgen_cast_0000000000000002: function(arg0, arg1) {
192
- // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [Externref], shim_idx: 42, ret: Result(Unit), inner_ret: Some(Result(Unit)) }, mutable: true }) -> Externref`.
193
- const ret = makeMutClosure(arg0, arg1, wasm_bindgen__convert__closures_____invoke__hfcaf9f68983c0e6f);
206
+ // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [Externref], shim_idx: 84, ret: Result(Unit), inner_ret: Some(Result(Unit)) }, mutable: true }) -> Externref`.
207
+ const ret = makeMutClosure(arg0, arg1, wasm_bindgen__convert__closures_____invoke__h09476be307b1e815);
194
208
  return ret;
195
209
  },
196
210
  __wbindgen_cast_0000000000000003: function(arg0) {
@@ -215,27 +229,27 @@ function __wbg_get_imports() {
215
229
  };
216
230
  return {
217
231
  __proto__: null,
218
- "./wasm_basis_decode_bg.js": import0,
232
+ "./wasm_decode_bg.js": import0,
219
233
  "./snippets/basisu_c_sys-273c0aeb51b100af/wasm/basisu_transcoder.js": import1,
220
234
  };
221
235
  }
222
236
 
223
- function wasm_bindgen__convert__closures_____invoke__h1a884335adcc7c22(arg0, arg1, arg2) {
224
- const ret = wasm.wasm_bindgen__convert__closures_____invoke__h1a884335adcc7c22(arg0, arg1, arg2);
237
+ function wasm_bindgen__convert__closures_____invoke__hffc9f1a16a180456(arg0, arg1, arg2) {
238
+ const ret = wasm.wasm_bindgen__convert__closures_____invoke__hffc9f1a16a180456(arg0, arg1, arg2);
225
239
  if (ret[1]) {
226
240
  throw takeFromExternrefTable0(ret[0]);
227
241
  }
228
242
  }
229
243
 
230
- function wasm_bindgen__convert__closures_____invoke__hfcaf9f68983c0e6f(arg0, arg1, arg2) {
231
- const ret = wasm.wasm_bindgen__convert__closures_____invoke__hfcaf9f68983c0e6f(arg0, arg1, arg2);
244
+ function wasm_bindgen__convert__closures_____invoke__h09476be307b1e815(arg0, arg1, arg2) {
245
+ const ret = wasm.wasm_bindgen__convert__closures_____invoke__h09476be307b1e815(arg0, arg1, arg2);
232
246
  if (ret[1]) {
233
247
  throw takeFromExternrefTable0(ret[0]);
234
248
  }
235
249
  }
236
250
 
237
- function wasm_bindgen__convert__closures_____invoke__h16cb8cb7feea2290(arg0, arg1, arg2, arg3) {
238
- wasm.wasm_bindgen__convert__closures_____invoke__h16cb8cb7feea2290(arg0, arg1, arg2, arg3);
251
+ function wasm_bindgen__convert__closures_____invoke__h3d076a640fe381ba(arg0, arg1, arg2, arg3) {
252
+ wasm.wasm_bindgen__convert__closures_____invoke__h3d076a640fe381ba(arg0, arg1, arg2, arg3);
239
253
  }
240
254
 
241
255
  function addToExternrefTable0(obj) {
@@ -537,7 +551,7 @@ async function __wbg_init(module_or_path) {
537
551
  }
538
552
 
539
553
  if (module_or_path === undefined) {
540
- module_or_path = new URL('wasm_basis_decode_bg.a8b7eebd.wasm', import.meta.url);
554
+ module_or_path = new URL('wasm_decode_bg.b6df9f4e.wasm', import.meta.url);
541
555
  }
542
556
  const imports = __wbg_get_imports();
543
557
 
@@ -0,0 +1,61 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+
4
+ export function decode_sbo(data: Uint8Array): Uint8Array;
5
+
6
+ /**
7
+ * Initialize the embedded basisu transcoder WASM.
8
+ * Must be awaited once after the outer WASM module's `default()` init.
9
+ */
10
+ export function init_basis(): Promise<any>;
11
+
12
+ /**
13
+ * Transcode a KTX2/basis file to a GPU-compressed (or RGBA32) format.
14
+ *
15
+ * `format`: 0=RGBA32, 1=ETC2_RGBA8, 2=ASTC_4×4, 3=BC7
16
+ *
17
+ * Returns `{ data: Uint8Array, width: u32, height: u32, format: u32 }`.
18
+ */
19
+ export function transcode_basis(data: Uint8Array, format: number): object;
20
+
21
+ export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
22
+
23
+ export interface InitOutput {
24
+ readonly memory: WebAssembly.Memory;
25
+ readonly decode_sbo: (a: number, b: number) => [number, number, number];
26
+ readonly init_basis: () => any;
27
+ readonly transcode_basis: (a: number, b: number, c: number) => [number, number, number];
28
+ readonly wasm_bindgen__convert__closures_____invoke__hffc9f1a16a180456: (a: number, b: number, c: any) => [number, number];
29
+ readonly wasm_bindgen__convert__closures_____invoke__h09476be307b1e815: (a: number, b: number, c: any) => [number, number];
30
+ readonly wasm_bindgen__convert__closures_____invoke__h3d076a640fe381ba: (a: number, b: number, c: any, d: any) => void;
31
+ readonly __wbindgen_malloc: (a: number, b: number) => number;
32
+ readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
33
+ readonly __wbindgen_exn_store: (a: number) => void;
34
+ readonly __externref_table_alloc: () => number;
35
+ readonly __wbindgen_externrefs: WebAssembly.Table;
36
+ readonly __wbindgen_destroy_closure: (a: number, b: number) => void;
37
+ readonly __externref_table_dealloc: (a: number) => void;
38
+ readonly __wbindgen_start: () => void;
39
+ }
40
+
41
+ export type SyncInitInput = BufferSource | WebAssembly.Module;
42
+
43
+ /**
44
+ * Instantiates the given `module`, which can either be bytes or
45
+ * a precompiled `WebAssembly.Module`.
46
+ *
47
+ * @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
48
+ *
49
+ * @returns {InitOutput}
50
+ */
51
+ export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
52
+
53
+ /**
54
+ * If `module_or_path` is {RequestInfo} or {URL}, makes a request and
55
+ * for everything else, calls `WebAssembly.instantiate` directly.
56
+ *
57
+ * @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
58
+ *
59
+ * @returns {Promise<InitOutput>}
60
+ */
61
+ export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;
@@ -0,0 +1,17 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+ export const memory: WebAssembly.Memory;
4
+ export const decode_sbo: (a: number, b: number) => [number, number, number];
5
+ export const init_basis: () => any;
6
+ export const transcode_basis: (a: number, b: number, c: number) => [number, number, number];
7
+ export const wasm_bindgen__convert__closures_____invoke__hffc9f1a16a180456: (a: number, b: number, c: any) => [number, number];
8
+ export const wasm_bindgen__convert__closures_____invoke__h09476be307b1e815: (a: number, b: number, c: any) => [number, number];
9
+ export const wasm_bindgen__convert__closures_____invoke__h3d076a640fe381ba: (a: number, b: number, c: any, d: any) => void;
10
+ export const __wbindgen_malloc: (a: number, b: number) => number;
11
+ export const __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
12
+ export const __wbindgen_exn_store: (a: number) => void;
13
+ export const __externref_table_alloc: () => number;
14
+ export const __wbindgen_externrefs: WebAssembly.Table;
15
+ export const __wbindgen_destroy_closure: (a: number, b: number) => void;
16
+ export const __externref_table_dealloc: (a: number) => void;
17
+ export const __wbindgen_start: () => void;
@@ -3324,7 +3324,7 @@ async function __wbg_init(module_or_path) {
3324
3324
  }
3325
3325
 
3326
3326
  if (module_or_path === undefined) {
3327
- module_or_path = new URL('sangine_bg.10c8ee57.wasm', import.meta.url);
3327
+ module_or_path = new URL('sangine_bg.48c42a65.wasm', import.meta.url);
3328
3328
  }
3329
3329
  const imports = __wbg_get_imports();
3330
3330
 
@@ -44,7 +44,6 @@ export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembl
44
44
 
45
45
  export interface InitOutput {
46
46
  readonly memory: WebAssembly.Memory;
47
- readonly run: () => void;
48
47
  readonly animate_to: (a: number, b: any) => [number, number];
49
48
  readonly animate_to_route: (a: number, b: number, c: number) => [number, number];
50
49
  readonly create_window: (a: number, b: number, c: any, d: number) => [number, number, number];
@@ -62,6 +61,7 @@ export interface InitOutput {
62
61
  readonly set_sun_properties: (a: number, b: any) => [number, number];
63
62
  readonly set_window_action: (a: number, b: any) => [number, number];
64
63
  readonly set_window_scale: (a: number, b: number) => [number, number];
64
+ readonly run: () => void;
65
65
  readonly wasm_bindgen__convert__closures_____invoke__hd8590da73942d3e0: (a: number, b: number, c: any) => [number, number];
66
66
  readonly wasm_bindgen__convert__closures_____invoke__h6ff3e7511bd758a3: (a: number, b: number, c: any, d: any) => void;
67
67
  readonly wasm_bindgen__convert__closures_____invoke__h00cde4323839146b: (a: number, b: number, c: any) => void;
@@ -1,7 +1,6 @@
1
1
  /* tslint:disable */
2
2
  /* eslint-disable */
3
3
  export const memory: WebAssembly.Memory;
4
- export const run: () => void;
5
4
  export const animate_to: (a: number, b: any) => [number, number];
6
5
  export const animate_to_route: (a: number, b: number, c: number) => [number, number];
7
6
  export const create_window: (a: number, b: number, c: any, d: number) => [number, number, number];
@@ -19,6 +18,7 @@ export const set_route_visible: (a: number, b: number, c: number, d: number) =>
19
18
  export const set_sun_properties: (a: number, b: any) => [number, number];
20
19
  export const set_window_action: (a: number, b: any) => [number, number];
21
20
  export const set_window_scale: (a: number, b: number) => [number, number];
21
+ export const run: () => void;
22
22
  export const wasm_bindgen__convert__closures_____invoke__hd8590da73942d3e0: (a: number, b: number, c: any) => [number, number];
23
23
  export const wasm_bindgen__convert__closures_____invoke__h6ff3e7511bd758a3: (a: number, b: number, c: any, d: any) => void;
24
24
  export const wasm_bindgen__convert__closures_____invoke__h00cde4323839146b: (a: number, b: number, c: any) => void;
@@ -1,5 +1,7 @@
1
1
  /* @ts-self-types="./wasm_sbo_decode.d.ts" */
2
2
 
3
+ //#region exports
4
+
3
5
  /**
4
6
  * @param {Uint8Array} data
5
7
  * @returns {Uint8Array}
@@ -13,21 +15,26 @@ export function decode_sbo(data) {
13
15
  }
14
16
  return takeFromExternrefTable0(ret[0]);
15
17
  }
18
+
19
+ //#endregion
20
+
21
+ //#region wasm imports
22
+
16
23
  function __wbg_get_imports() {
17
24
  const import0 = {
18
25
  __proto__: null,
19
- __wbg___wbindgen_throw_6b64449b9b9ed33c: function(arg0, arg1) {
26
+ __wbg___wbindgen_throw_be289d5034ed271b: function(arg0, arg1) {
20
27
  throw new Error(getStringFromWasm0(arg0, arg1));
21
28
  },
22
- __wbg_new_from_slice_b5ea43e23f6008c0: function(arg0, arg1) {
29
+ __wbg_new_from_slice_a3d2629dc1826784: function() { return logError(function (arg0, arg1) {
23
30
  const ret = new Uint8Array(getArrayU8FromWasm0(arg0, arg1));
24
31
  return ret;
25
- },
26
- __wbindgen_cast_0000000000000001: function(arg0, arg1) {
32
+ }, arguments); },
33
+ __wbindgen_cast_0000000000000001: function() { return logError(function (arg0, arg1) {
27
34
  // Cast intrinsic for `Ref(String) -> Externref`.
28
35
  const ret = getStringFromWasm0(arg0, arg1);
29
36
  return ret;
30
- },
37
+ }, arguments); },
31
38
  __wbindgen_init_externref_table: function() {
32
39
  const table = wasm.__wbindgen_externrefs;
33
40
  const offset = table.grow(4);
@@ -44,6 +51,10 @@ function __wbg_get_imports() {
44
51
  };
45
52
  }
46
53
 
54
+
55
+ //#endregion
56
+
57
+ //#region intrinsics
47
58
  function getArrayU8FromWasm0(ptr, len) {
48
59
  ptr = ptr >>> 0;
49
60
  return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
@@ -62,6 +73,22 @@ function getUint8ArrayMemory0() {
62
73
  return cachedUint8ArrayMemory0;
63
74
  }
64
75
 
76
+ function logError(f, args) {
77
+ try {
78
+ return f.apply(this, args);
79
+ } catch (e) {
80
+ let error = (function () {
81
+ try {
82
+ return e instanceof Error ? `${e.message}\n\nStack:\n${e.stack}` : e.toString();
83
+ } catch(_) {
84
+ return "<failed to stringify thrown value>";
85
+ }
86
+ }());
87
+ console.error("wasm-bindgen: imported JS function that was not marked as `catch` threw an error:", error);
88
+ throw e;
89
+ }
90
+ }
91
+
65
92
  function passArray8ToWasm0(arg, malloc) {
66
93
  const ptr = malloc(arg.length * 1, 1) >>> 0;
67
94
  getUint8ArrayMemory0().set(arg, ptr / 1);
@@ -91,6 +118,10 @@ function decodeText(ptr, len) {
91
118
 
92
119
  let WASM_VECTOR_LEN = 0;
93
120
 
121
+
122
+ //#endregion
123
+
124
+ //#region wasm loading
94
125
  let wasmModule, wasm;
95
126
  function __wbg_finalize_init(instance, module) {
96
127
  wasm = instance.exports;
@@ -168,7 +199,7 @@ async function __wbg_init(module_or_path) {
168
199
  }
169
200
 
170
201
  if (module_or_path === undefined) {
171
- module_or_path = new URL('wasm_sbo_decode_bg.5c359661.wasm', import.meta.url);
202
+ module_or_path = new URL('wasm_sbo_decode_bg.db6e2054.wasm', import.meta.url);
172
203
  }
173
204
  const imports = __wbg_get_imports();
174
205
 
@@ -182,3 +213,5 @@ async function __wbg_init(module_or_path) {
182
213
  }
183
214
 
184
215
  export { initSync, __wbg_init as default };
216
+ //#endregion
217
+ export { wasm as __wasm }
@@ -1,2 +1,2 @@
1
- export declare const BASIS_DECODE_HASH = "a8b7eebd";
1
+ export declare const BASIS_DECODE_HASH = "6c648416";
2
2
  //# sourceMappingURL=basis-decode.d.ts.map
@@ -0,0 +1,2 @@
1
+ export declare const DECODE_HASH = "b6df9f4e";
2
+ //# sourceMappingURL=decode.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"decode.d.ts","sourceRoot":"","sources":["../../src/wasm-hashes/decode.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,WAAW,aAAa,CAAA"}
@@ -1,2 +1,2 @@
1
- export declare const SANGINE_HASH = "10c8ee57";
1
+ export declare const SANGINE_HASH = "48c42a65";
2
2
  //# sourceMappingURL=sangine.d.ts.map
@@ -1,2 +1,2 @@
1
- export declare const SBO_DECODE_HASH = "5c359661";
1
+ export declare const SBO_DECODE_HASH = "db6e2054";
2
2
  //# sourceMappingURL=sbo-decode.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"decodeWorkerImpl.d.ts","sourceRoot":"","sources":["../../src/worker/decodeWorkerImpl.ts"],"names":[],"mappings":"AASA,QAAA,MAAM,aAAa,IAAI,CAAA;AACvB,QAAA,MAAM,iBAAiB,IAAI,CAAA;AAC3B,QAAA,MAAM,eAAe,IAAI,CAAA;AACzB,QAAA,MAAM,UAAU,IAAI,CAAA;AACpB,QAAA,MAAM,UAAU,IAAI,CAAA;AACpB,QAAA,MAAM,aAAa,IAAI,CAAA;AACvB,QAAA,MAAM,gBAAgB,IAAI,CAAA;AAE1B,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,0BAA0B,QA8HpE;AAED,OAAO,EACL,eAAe,EACf,aAAa,EACb,UAAU,EACV,gBAAgB,EAChB,iBAAiB,EACjB,UAAU,EACV,aAAa,GACd,CAAA"}
1
+ {"version":3,"file":"decodeWorkerImpl.d.ts","sourceRoot":"","sources":["../../src/worker/decodeWorkerImpl.ts"],"names":[],"mappings":"AAeA,QAAA,MAAM,aAAa,IAAI,CAAA;AACvB,QAAA,MAAM,iBAAiB,IAAI,CAAA;AAC3B,QAAA,MAAM,eAAe,IAAI,CAAA;AACzB,QAAA,MAAM,UAAU,IAAI,CAAA;AACpB,QAAA,MAAM,UAAU,IAAI,CAAA;AACpB,QAAA,MAAM,aAAa,IAAI,CAAA;AACvB,QAAA,MAAM,gBAAgB,IAAI,CAAA;AAE1B,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,0BAA0B,QAkEpE;AAED,OAAO,EACL,eAAe,EACf,aAAa,EACb,UAAU,EACV,gBAAgB,EAChB,iBAAiB,EACjB,UAAU,EACV,aAAa,GACd,CAAA"}
@@ -3,7 +3,7 @@ export declare class WorkerPool<Request, Response> {
3
3
  private idle;
4
4
  private queue;
5
5
  constructor(workerFactory: () => Worker, num: number);
6
- run(request: Request): Promise<Response>;
6
+ run(request: Request, transfer?: Transferable[]): Promise<Response>;
7
7
  private dispatch;
8
8
  private release;
9
9
  broadcast(message: unknown): void;
@@ -1 +1 @@
1
- {"version":3,"file":"pool.d.ts","sourceRoot":"","sources":["../../src/worker/pool.ts"],"names":[],"mappings":"AAAA,qBAAa,UAAU,CAAC,OAAO,EAAE,QAAQ;IACvC,OAAO,CAAC,OAAO,CAAU;IACzB,OAAO,CAAC,IAAI,CAAU;IACtB,OAAO,CAAC,KAAK,CAIL;gBAEI,aAAa,EAAE,MAAM,MAAM,EAAE,GAAG,EAAE,MAAM;IAKpD,GAAG,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC;IAWxC,OAAO,CAAC,QAAQ;IA4BhB,OAAO,CAAC,OAAO;IASR,SAAS,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI;IAMjC,SAAS;CAKjB"}
1
+ {"version":3,"file":"pool.d.ts","sourceRoot":"","sources":["../../src/worker/pool.ts"],"names":[],"mappings":"AAAA,qBAAa,UAAU,CAAC,OAAO,EAAE,QAAQ;IACvC,OAAO,CAAC,OAAO,CAAU;IACzB,OAAO,CAAC,IAAI,CAAU;IACtB,OAAO,CAAC,KAAK,CAKL;gBAEI,aAAa,EAAE,MAAM,MAAM,EAAE,GAAG,EAAE,MAAM;IAKpD,GAAG,CAAC,OAAO,EAAE,OAAO,EAAE,QAAQ,CAAC,EAAE,YAAY,EAAE,GAAG,OAAO,CAAC,QAAQ,CAAC;IAWnE,OAAO,CAAC,QAAQ;IA6BhB,OAAO,CAAC,OAAO;IASR,SAAS,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI;IAMjC,SAAS;CAKjB"}
@@ -0,0 +1,12 @@
1
+ export type WorkerDecodeTask = {
2
+ kind: 'texture-basis';
3
+ bytes: ArrayBuffer;
4
+ format: number;
5
+ } | {
6
+ kind: 'texture-image';
7
+ bytes: ArrayBuffer;
8
+ } | {
9
+ kind: 'model-sbo';
10
+ bytes: ArrayBuffer;
11
+ };
12
+ //# sourceMappingURL=workerTask.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"workerTask.d.ts","sourceRoot":"","sources":["../../src/worker/workerTask.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,gBAAgB,GACxB;IAAE,IAAI,EAAE,eAAe,CAAC;IAAC,KAAK,EAAE,WAAW,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GAC7D;IAAE,IAAI,EAAE,eAAe,CAAC;IAAC,KAAK,EAAE,WAAW,CAAA;CAAE,GAC7C;IAAE,IAAI,EAAE,WAAW,CAAC;IAAC,KAAK,EAAE,WAAW,CAAA;CAAE,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sanox/sangine-core",
3
- "version": "0.4.2",
3
+ "version": "0.4.4",
4
4
  "description": "Sangine core renderer runtime (WASM + workers)",
5
5
  "type": "module",
6
6
  "private": false,