@sanox/sangine-core 0.4.3 → 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.
- package/dist/assetFetcher.d.ts +3 -0
- package/dist/assetFetcher.d.ts.map +1 -0
- package/dist/index.cjs.js +1 -1
- package/dist/index.es.js +115 -109
- package/dist/rendererService.d.ts.map +1 -1
- package/dist/wasm/basis-decode/wasm_basis_decode.6c648416.js +283 -0
- package/dist/wasm/basis-decode/wasm_basis_decode.d.ts +3 -15
- package/dist/wasm/basis-decode/wasm_basis_decode_bg.6c648416.wasm +0 -0
- package/dist/wasm/basis-decode/wasm_basis_decode_bg.wasm.d.ts +1 -7
- package/dist/wasm/decode/{wasm_decode.bf116aa6.js → wasm_decode.b6df9f4e.js} +1 -1
- package/dist/wasm/decode/{wasm_decode_bg.bf116aa6.wasm → wasm_decode_bg.b6df9f4e.wasm} +0 -0
- package/dist/wasm/sangine/{sangine.10c8ee57.js → sangine.48c42a65.js} +1 -1
- package/dist/wasm/sangine/sangine.d.ts +1 -1
- package/dist/wasm/sangine/{sangine_bg.10c8ee57.wasm → sangine_bg.48c42a65.wasm} +0 -0
- package/dist/wasm/sangine/sangine_bg.wasm.d.ts +1 -1
- package/dist/wasm/sbo-decode/{wasm_sbo_decode.5c359661.js → wasm_sbo_decode.db6e2054.js} +39 -6
- package/dist/wasm/sbo-decode/wasm_sbo_decode_bg.db6e2054.wasm +0 -0
- package/dist/wasm-hashes/basis-decode.d.ts +2 -0
- package/dist/wasm-hashes/basis-decode.d.ts.map +1 -0
- package/dist/wasm-hashes/decode.d.ts +1 -1
- package/dist/wasm-hashes/sangine.d.ts +1 -1
- package/dist/wasm-hashes/sbo-decode.d.ts +2 -0
- package/dist/wasm-hashes/sbo-decode.d.ts.map +1 -0
- package/dist/worker/decodeWorkerImpl.d.ts.map +1 -1
- package/dist/worker/pool.d.ts +1 -1
- package/dist/worker/pool.d.ts.map +1 -1
- package/dist/worker/workerTask.d.ts +12 -0
- package/dist/worker/workerTask.d.ts.map +1 -0
- package/package.json +1 -1
- package/dist/wasm/basis-decode/snippets/basisu_c_sys-273c0aeb51b100af/wasm/basisu_transcoder.js +0 -2
- package/dist/wasm/basis-decode/snippets/basisu_c_sys-273c0aeb51b100af/wasm/basisu_transcoder.wasm +0 -0
- package/dist/wasm/basis-decode/wasm_basis_decode.a8b7eebd.js +0 -553
- package/dist/wasm/basis-decode/wasm_basis_decode_bg.a8b7eebd.wasm +0 -0
- package/dist/wasm/sbo-decode/wasm_sbo_decode_bg.5c359661.wasm +0 -0
|
@@ -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
|
|
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
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
const
|
|
5
|
-
|
|
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
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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((
|
|
14
|
-
const
|
|
15
|
-
|
|
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,
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
},
|
|
22
|
-
h
|
|
23
|
-
},
|
|
24
|
-
e.removeEventListener("message",
|
|
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",
|
|
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 E {
|
|
|
38
54
|
e.terminate();
|
|
39
55
|
}
|
|
40
56
|
}
|
|
41
|
-
class
|
|
57
|
+
class M {
|
|
42
58
|
constructor(e) {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
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,15 +76,15 @@ class P {
|
|
|
60
76
|
if (this._inited) return this._readyPromise;
|
|
61
77
|
try {
|
|
62
78
|
const t = await import(new URL(
|
|
63
|
-
`${
|
|
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
83
|
const s = Math.min(
|
|
68
84
|
this.config.numWorkers ?? (navigator.hardwareConcurrency || 2) - 1,
|
|
69
|
-
|
|
85
|
+
2
|
|
70
86
|
);
|
|
71
|
-
this.decodePool = new
|
|
87
|
+
this.decodePool = new b(
|
|
72
88
|
() => this.config.createDecodeWorker(),
|
|
73
89
|
Math.max(s, 1)
|
|
74
90
|
), this.wasm.register_asset_decoder(this.decodeAsset.bind(this)), this.wasm.register_event_listener(this.handleSangineEvent.bind(this)), this._resolveReady();
|
|
@@ -116,17 +132,17 @@ class P {
|
|
|
116
132
|
}
|
|
117
133
|
createWindow(e, t, s) {
|
|
118
134
|
if (!this.wasm) throw new Error("WASM not initialized");
|
|
119
|
-
let
|
|
120
|
-
const
|
|
121
|
-
|
|
122
|
-
}),
|
|
123
|
-
return this.windowCreatedPromiseResolveRegistry[
|
|
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] = {
|
|
124
140
|
actionChanged: [],
|
|
125
141
|
routeUpdated: [],
|
|
126
142
|
measurementCreated: [],
|
|
127
143
|
assetsDownloading: [],
|
|
128
144
|
userInteractionStarted: []
|
|
129
|
-
}, this.userActionRegistry[
|
|
145
|
+
}, this.userActionRegistry[i] = "watching", this.windowCreatedPromiseRegistry[i] = r, i;
|
|
130
146
|
}
|
|
131
147
|
getAssetsDownloading(e) {
|
|
132
148
|
return this.assetsDownloadingRegistry[e] || !1;
|
|
@@ -198,84 +214,74 @@ class P {
|
|
|
198
214
|
}
|
|
199
215
|
async decodeAsset(e) {
|
|
200
216
|
if (!this.decodePool) throw new Error("Renderer not initialized");
|
|
201
|
-
|
|
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]);
|
|
202
223
|
}
|
|
203
224
|
destroy() {
|
|
204
225
|
var e;
|
|
205
226
|
(e = this.decodePool) == null || e.terminate();
|
|
206
227
|
}
|
|
207
228
|
}
|
|
208
|
-
const
|
|
209
|
-
function
|
|
210
|
-
let e = !1, t = null
|
|
211
|
-
async function
|
|
212
|
-
if (s) {
|
|
213
|
-
const n = `https://sangine-asset-cache/${o}`, m = await s.match(n);
|
|
214
|
-
if (m) return m;
|
|
215
|
-
const w = await fetch(i);
|
|
216
|
-
return w.ok && await s.put(n, w.clone()), w;
|
|
217
|
-
}
|
|
218
|
-
return fetch(i);
|
|
219
|
-
}
|
|
220
|
-
async function l() {
|
|
229
|
+
const R = "b6df9f4e", p = 0;
|
|
230
|
+
function E(n) {
|
|
231
|
+
let e = !1, t = null;
|
|
232
|
+
async function s() {
|
|
221
233
|
if (e) return;
|
|
222
|
-
const
|
|
223
|
-
`${
|
|
224
|
-
|
|
234
|
+
const r = await import(new URL(
|
|
235
|
+
`${u}/decode/wasm_decode.${R}.js`,
|
|
236
|
+
n.location.origin
|
|
225
237
|
).href);
|
|
226
|
-
await
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
const
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
}
|
|
266
|
-
} catch (n) {
|
|
267
|
-
a.postMessage({ success: !1, error: n.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}`);
|
|
268
278
|
}
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
const { pk: n, url: m } = i["model-part-mesh"], w = await h(n, m);
|
|
272
|
-
if (!w.ok) throw new Error(`HTTP error! status: ${w.status}`);
|
|
273
|
-
const g = await w.arrayBuffer(), _ = new Uint8Array(g), c = t.decode_sbo(_);
|
|
274
|
-
a.postMessage({ success: !0, data: c.buffer }, [c.buffer]);
|
|
279
|
+
} catch (i) {
|
|
280
|
+
n.postMessage({ success: !1, error: i.message });
|
|
275
281
|
}
|
|
276
282
|
};
|
|
277
283
|
}
|
|
278
284
|
export {
|
|
279
|
-
|
|
280
|
-
|
|
285
|
+
M as RendererService,
|
|
286
|
+
E as registerDecodeWorker
|
|
281
287
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rendererService.d.ts","sourceRoot":"","sources":["../src/rendererService.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"rendererService.d.ts","sourceRoot":"","sources":["../src/rendererService.ts"],"names":[],"mappings":"AAEA,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;AAK1D,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,oBAAoB,CAAA;IAClC,kBAAkB,EAAE,0BAA0B,CAAA;IAC9C,iBAAiB,EAAE,yBAAyB,CAAA;IAC5C,sBAAsB,EAAE,YAAY,CAAA;CACrC;AAMD,qBAAa,eAAe;IAcd,OAAO,CAAC,MAAM;IAb1B,OAAO,CAAC,IAAI,CAA2B;IACvC,OAAO,CAAC,gBAAgB,CAA4C;IACpE,OAAO,CAAC,kBAAkB,CAAsC;IAChE,OAAO,CAAC,yBAAyB,CAAmC;IACpE,OAAO,CAAC,4BAA4B,CAAyC;IAC7E,OAAO,CAAC,mCAAmC,CAAsC;IACjF,OAAO,CAAC,OAAO,CAAiB;IAChC,OAAO,CAAC,UAAU,CAAC,CAA2C;IAE9D,OAAO,CAAC,aAAa,CAAe;IACpC,OAAO,CAAC,aAAa,CAAa;IAClC,OAAO,CAAC,YAAY,CAAyB;gBAEzB,MAAM,EAAE,cAAc;IAQpC,IAAI;IAmCV,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAItB,IAAI,MAAM,IAAI,OAAO,CAEpB;IAED,OAAO;IAOP,mBAAmB,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU;IAOxD,wBAAwB,CAAC,QAAQ,EAAE,MAAM,EAAE,WAAW,EAAE,WAAW;IAMnE,kBAAkB,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK;IAMjD,uBAAuB,CAAC,QAAQ,EAAE,MAAM,EAAE,WAAW,EAAE,OAAO;IAO9D,4BAA4B,CAAC,QAAQ,EAAE,MAAM;IAM7C,kBAAkB,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,YAAY;IAgBxD,YAAY,CAAC,WAAW,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,iBAAiB,GAAG,SAAS,GAAG,MAAM;IAuBhG,oBAAoB,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO;IAIlD,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,UAAU;IAI5C,WAAW,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAI5C,gBAAgB,CAAC,CAAC,SAAS,MAAM,WAAW,EAC1C,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,CAAC,EACR,QAAQ,EAAE,WAAW,CAAC,CAAC,CAAC;IAK1B,eAAe,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU;IAKpD,aAAa,CAAC,QAAQ,EAAE,MAAM;IAO9B,iBAAiB,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM;IAKtE,eAAe,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM;IAKlE,cAAc,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,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 }
|