@sanox/sangine-core 0.5.1 → 0.5.2
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/index.cjs.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var f=Object.defineProperty;var g=(a,e,t)=>e in a?f(a,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):a[e]=t;var d=(a,e,t)=>g(a,typeof e!="symbol"?e+"":e,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const y="sangine-assets-v2";let l=null;async function m(a,e,t){if(typeof caches>"u"){const n=await fetch(t);if(!n.ok)throw new Error(`fetch ${t} failed: ${n.status}`);return n.arrayBuffer()}l??(l=caches.open(y));const i=await l,o=`https://sangine-asset-cache/${a}/${e}`,r=await i.match(o);if(r)return r.arrayBuffer();const s=await fetch(t);if(!s.ok)throw new Error(`fetch ${t} failed: ${s.status}`);return i.put(o,s.clone()).catch(()=>{}),s.arrayBuffer()}const u="/static/sangine/wasm",_="
|
|
1
|
+
"use strict";var f=Object.defineProperty;var g=(a,e,t)=>e in a?f(a,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):a[e]=t;var d=(a,e,t)=>g(a,typeof e!="symbol"?e+"":e,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const y="sangine-assets-v2";let l=null;async function m(a,e,t){if(typeof caches>"u"){const n=await fetch(t);if(!n.ok)throw new Error(`fetch ${t} failed: ${n.status}`);return n.arrayBuffer()}l??(l=caches.open(y));const i=await l,o=`https://sangine-asset-cache/${a}/${e}`,r=await i.match(o);if(r)return r.arrayBuffer();const s=await fetch(t);if(!s.ok)throw new Error(`fetch ${t} failed: ${s.status}`);return i.put(o,s.clone()).catch(()=>{}),s.arrayBuffer()}const u="/static/sangine/wasm",_="27a3889c";class A{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((i,o)=>{const r=this.idle.pop();r?this.dispatch(r,e,t,i,o):this.queue.push({request:e,transfer:t,resolve:i,reject:o})})}dispatch(e,t,i,o,r){const s=h=>{o(h.data),c(),this.release(e)},n=h=>{r(h),c(),this.release(e)},c=()=>{e.removeEventListener("message",s),e.removeEventListener("error",n)};e.addEventListener("message",s,{once:!0}),e.addEventListener("error",n,{once:!0}),e.postMessage(t,i??[])}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 b{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,i)=>{this._resolveReady=t,this._rejectReady=i}),this.config=e}async init(){if(!(typeof window>"u")){if(this._inited)return this._readyPromise;try{const t=await import(new URL(`${u}/sangine/sangine.${_}.js`,window.location.origin).toString());await t.default(),this.wasm=t,this._inited=!0;const i=Math.min(this.config.numWorkers??(navigator.hardwareConcurrency||2)-1,2);this.decodePool=new A(()=>this.config.createDecodeWorker(),Math.max(i,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 i of this.callbackRegistry[e].actionChanged)i(t)}handleMeasurementCreated(e,t){for(const i of this.callbackRegistry[e].measurementCreated)i(t)}handleAssetsDownloading(e,t){this.assetsDownloadingRegistry[e]=t;for(const i of this.callbackRegistry[e].assetsDownloading)i(t)}handleUserInteractionStarted(e){for(const t of this.callbackRegistry[e].userInteractionStarted)t()}handleAnnotationCreated(e,t){for(const i of this.callbackRegistry[e].annotationCreated)i(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):"assetsDownloading"in t?this.handleAssetsDownloading(e,t.assetsDownloading.downloading):"annotationCreated"in t&&this.handleAnnotationCreated(e,t.annotationCreated)}createWindow(e,t,i){if(!this.wasm)throw new Error("WASM not initialized");let o;const r=new Promise(n=>{o=n}),s=this.wasm.create_window(e,t,i);return this.windowCreatedPromiseResolveRegistry[s]=o,this.callbackRegistry[s]={actionChanged:[],measurementCreated:[],assetsDownloading:[],userInteractionStarted:[],annotationCreated:[]},this.userActionRegistry[s]="watching",this.windowCreatedPromiseRegistry[s]=r,s}getAssetsDownloading(e){return this.assetsDownloadingRegistry[e]||!1}readUserAction(e){return this.userActionRegistry[e]}windowReady(e){return this.windowCreatedPromiseRegistry[e]}registerCallback(e,t,i){this.callbackRegistry[e][t].push(i)}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]}setAnnotationProps(e,t,i){if(!this.wasm)throw new Error("WASM not initialized");this.wasm.annotation_set_props(e,t,i)}setAnnotationKind(e,t,i){if(!this.wasm)throw new Error("WASM not initialized");this.wasm.annotation_set_kind(e,t,i)}addAnnotation(e,t,i){if(!this.wasm)throw new Error("WASM not initialized");this.wasm.annotation_insert(e,t,i)}finishAnnotation(e){if(!this.wasm)throw new Error("WASM not initialized");this.wasm.annotation_finish(e)}annotationRemoveLastPoint(e){if(!this.wasm)throw new Error("WASM not initialized");this.wasm.annotation_remove_last_point(e)}removeAnnotation(e,t){if(!this.wasm)throw new Error("WASM not initialized");this.wasm.annotation_remove(e,t)}animateToAnnotation(e,t){if(!this.wasm)throw new Error("WASM not initialized");this.wasm.animate_to_annotation(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:s,encoding:n,format:c}=e["texture-file"],h=await m("texture",r,s);return n==="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:i}=e["model-part-mesh"],o=await m("mesh",t,i);return this.decodePool.run({kind:"model-sbo",bytes:o},[o])}destroy(){var e;(e=this.decodePool)==null||e.terminate()}}const R="b6df9f4e",p=0;function M(a){let e=!1,t=null;async function i(){if(e)return;const r=await import(new URL(`${u}/decode/wasm_decode.${R}.js`,a.location.origin).href);await r.default(),await r.init_basis(),t=r,e=!0}a.onmessage=async o=>{const r=o.data;try{if(r.kind==="texture-basis"){await i();const s=new Uint8Array(r.bytes),n=t.transcode_basis(s,r.format);a.postMessage({success:!0,width:n.width,height:n.height,data:n.data.buffer,format:n.format},[n.data.buffer])}else if(r.kind==="texture-image"){const s=new Blob([r.bytes]),n=await createImageBitmap(s),c=new OffscreenCanvas(n.width,n.height),h=c.getContext("2d");if(h===null)throw new Error("Couldnt create canvas");h.drawImage(n,0,0);const w=h.getImageData(0,0,c.width,c.height);a.postMessage({success:!0,width:c.width,height:c.height,data:w.data.buffer,format:p},[w.data.buffer])}else if(r.kind==="model-sbo"){await i();const s=new Uint8Array(r.bytes),n=t.decode_sbo(s);a.postMessage({success:!0,data:n.buffer},[n.buffer])}else{const s=r;throw new Error(`unknown task kind: ${s.kind}`)}}catch(s){a.postMessage({success:!1,error:s.message})}}}exports.RendererService=b;exports.registerDecodeWorker=M;
|
package/dist/index.es.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
var
|
|
2
|
-
var g = (a, e, t) => e in a ?
|
|
1
|
+
var f = Object.defineProperty;
|
|
2
|
+
var g = (a, e, t) => e in a ? f(a, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : a[e] = t;
|
|
3
3
|
var h = (a, e, t) => g(a, typeof e != "symbol" ? e + "" : e, t);
|
|
4
4
|
const y = "sangine-assets-v2";
|
|
5
5
|
let l = null;
|
|
@@ -17,7 +17,7 @@ async function m(a, e, t) {
|
|
|
17
17
|
return i.put(o, s.clone()).catch(() => {
|
|
18
18
|
}), s.arrayBuffer();
|
|
19
19
|
}
|
|
20
|
-
const
|
|
20
|
+
const u = "/static/sangine/wasm", _ = "27a3889c";
|
|
21
21
|
class A {
|
|
22
22
|
constructor(e, t) {
|
|
23
23
|
h(this, "workers");
|
|
@@ -76,7 +76,7 @@ class M {
|
|
|
76
76
|
if (this._inited) return this._readyPromise;
|
|
77
77
|
try {
|
|
78
78
|
const t = await import(new URL(
|
|
79
|
-
`${
|
|
79
|
+
`${u}/sangine/sangine.${_}.js`,
|
|
80
80
|
window.location.origin
|
|
81
81
|
).toString());
|
|
82
82
|
await t.default(), this.wasm = t, this._inited = !0;
|
|
@@ -248,7 +248,7 @@ function E(a) {
|
|
|
248
248
|
async function i() {
|
|
249
249
|
if (e) return;
|
|
250
250
|
const n = await import(new URL(
|
|
251
|
-
`${
|
|
251
|
+
`${u}/decode/wasm_decode.${b}.js`,
|
|
252
252
|
a.location.origin
|
|
253
253
|
).href);
|
|
254
254
|
await n.default(), await n.init_basis(), t = n, e = !0;
|
|
@@ -2752,57 +2752,57 @@ function __wbg_get_imports() {
|
|
|
2752
2752
|
arg0.writeTexture(arg1, arg2, arg3, arg4);
|
|
2753
2753
|
}, arguments); },
|
|
2754
2754
|
__wbindgen_cast_0000000000000001: function(arg0, arg1) {
|
|
2755
|
-
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [Externref], shim_idx:
|
|
2755
|
+
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [Externref], shim_idx: 1640, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
|
|
2756
2756
|
const ret = makeMutClosure(arg0, arg1, wasm_bindgen__convert__closures_____invoke__h00cde4323839146b);
|
|
2757
2757
|
return ret;
|
|
2758
2758
|
},
|
|
2759
2759
|
__wbindgen_cast_0000000000000002: function(arg0, arg1) {
|
|
2760
|
-
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [Externref], shim_idx:
|
|
2760
|
+
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [Externref], shim_idx: 3977, ret: Result(Unit), inner_ret: Some(Result(Unit)) }, mutable: true }) -> Externref`.
|
|
2761
2761
|
const ret = makeMutClosure(arg0, arg1, wasm_bindgen__convert__closures_____invoke__hd8590da73942d3e0);
|
|
2762
2762
|
return ret;
|
|
2763
2763
|
},
|
|
2764
2764
|
__wbindgen_cast_0000000000000003: function(arg0, arg1) {
|
|
2765
|
-
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [NamedExternref("Array<any>"), NamedExternref("ResizeObserver")], shim_idx:
|
|
2765
|
+
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [NamedExternref("Array<any>"), NamedExternref("ResizeObserver")], shim_idx: 1647, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
|
|
2766
2766
|
const ret = makeMutClosure(arg0, arg1, wasm_bindgen__convert__closures_____invoke__h6ff3e7511bd758a3);
|
|
2767
2767
|
return ret;
|
|
2768
2768
|
},
|
|
2769
2769
|
__wbindgen_cast_0000000000000004: function(arg0, arg1) {
|
|
2770
|
-
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [NamedExternref("Array<any>")], shim_idx:
|
|
2770
|
+
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [NamedExternref("Array<any>")], shim_idx: 1640, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
|
|
2771
2771
|
const ret = makeMutClosure(arg0, arg1, wasm_bindgen__convert__closures_____invoke__h00cde4323839146b_3);
|
|
2772
2772
|
return ret;
|
|
2773
2773
|
},
|
|
2774
2774
|
__wbindgen_cast_0000000000000005: function(arg0, arg1) {
|
|
2775
|
-
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [NamedExternref("Event")], shim_idx:
|
|
2775
|
+
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [NamedExternref("Event")], shim_idx: 1640, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
|
|
2776
2776
|
const ret = makeMutClosure(arg0, arg1, wasm_bindgen__convert__closures_____invoke__h00cde4323839146b_4);
|
|
2777
2777
|
return ret;
|
|
2778
2778
|
},
|
|
2779
2779
|
__wbindgen_cast_0000000000000006: function(arg0, arg1) {
|
|
2780
|
-
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [NamedExternref("FocusEvent")], shim_idx:
|
|
2780
|
+
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [NamedExternref("FocusEvent")], shim_idx: 1640, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
|
|
2781
2781
|
const ret = makeMutClosure(arg0, arg1, wasm_bindgen__convert__closures_____invoke__h00cde4323839146b_5);
|
|
2782
2782
|
return ret;
|
|
2783
2783
|
},
|
|
2784
2784
|
__wbindgen_cast_0000000000000007: function(arg0, arg1) {
|
|
2785
|
-
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [NamedExternref("KeyboardEvent")], shim_idx:
|
|
2785
|
+
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [NamedExternref("KeyboardEvent")], shim_idx: 1640, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
|
|
2786
2786
|
const ret = makeMutClosure(arg0, arg1, wasm_bindgen__convert__closures_____invoke__h00cde4323839146b_6);
|
|
2787
2787
|
return ret;
|
|
2788
2788
|
},
|
|
2789
2789
|
__wbindgen_cast_0000000000000008: function(arg0, arg1) {
|
|
2790
|
-
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [NamedExternref("PageTransitionEvent")], shim_idx:
|
|
2790
|
+
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [NamedExternref("PageTransitionEvent")], shim_idx: 1640, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
|
|
2791
2791
|
const ret = makeMutClosure(arg0, arg1, wasm_bindgen__convert__closures_____invoke__h00cde4323839146b_7);
|
|
2792
2792
|
return ret;
|
|
2793
2793
|
},
|
|
2794
2794
|
__wbindgen_cast_0000000000000009: function(arg0, arg1) {
|
|
2795
|
-
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [NamedExternref("PointerEvent")], shim_idx:
|
|
2795
|
+
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [NamedExternref("PointerEvent")], shim_idx: 1640, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
|
|
2796
2796
|
const ret = makeMutClosure(arg0, arg1, wasm_bindgen__convert__closures_____invoke__h00cde4323839146b_8);
|
|
2797
2797
|
return ret;
|
|
2798
2798
|
},
|
|
2799
2799
|
__wbindgen_cast_000000000000000a: function(arg0, arg1) {
|
|
2800
|
-
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [NamedExternref("WheelEvent")], shim_idx:
|
|
2800
|
+
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [NamedExternref("WheelEvent")], shim_idx: 1640, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
|
|
2801
2801
|
const ret = makeMutClosure(arg0, arg1, wasm_bindgen__convert__closures_____invoke__h00cde4323839146b_9);
|
|
2802
2802
|
return ret;
|
|
2803
2803
|
},
|
|
2804
2804
|
__wbindgen_cast_000000000000000b: function(arg0, arg1) {
|
|
2805
|
-
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [], shim_idx:
|
|
2805
|
+
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [], shim_idx: 1645, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
|
|
2806
2806
|
const ret = makeMutClosure(arg0, arg1, wasm_bindgen__convert__closures_____invoke__hdb7f99c0126c5c28);
|
|
2807
2807
|
return ret;
|
|
2808
2808
|
},
|
|
@@ -3371,7 +3371,7 @@ async function __wbg_init(module_or_path) {
|
|
|
3371
3371
|
}
|
|
3372
3372
|
|
|
3373
3373
|
if (module_or_path === undefined) {
|
|
3374
|
-
module_or_path = new URL('sangine_bg.
|
|
3374
|
+
module_or_path = new URL('sangine_bg.27a3889c.wasm', import.meta.url);
|
|
3375
3375
|
}
|
|
3376
3376
|
const imports = __wbg_get_imports();
|
|
3377
3377
|
|
|
Binary file
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const SANGINE_HASH = "
|
|
1
|
+
export declare const SANGINE_HASH = "27a3889c";
|
|
2
2
|
//# sourceMappingURL=sangine.d.ts.map
|