@sanox/sangine-core 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,2 @@
1
+ export declare const WASM_BASE_URL = "/static/sangine/wasm";
2
+ //# sourceMappingURL=consts.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"consts.d.ts","sourceRoot":"","sources":["../src/consts.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,aAAa,yBAAyB,CAAA"}
@@ -0,0 +1,138 @@
1
+ /**
2
+ * This file was automatically generated by json-schema-to-typescript.
3
+ * DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
4
+ * and run json-schema-to-typescript to regenerate this file.
5
+ */
6
+ /**
7
+ * This interface was referenced by `Schema`'s JSON-Schema
8
+ * via the `definition` "LodEnum".
9
+ */
10
+ export type LodEnum = "very-high" | "high" | "medium" | "low" | "very-low" | "preview" | "preview-low";
11
+ /**
12
+ * This interface was referenced by `Schema`'s JSON-Schema
13
+ * via the `definition` "TextureTypeEnum".
14
+ */
15
+ export type TextureTypeEnum = "diffuse" | "normal" | "offset";
16
+ /**
17
+ * This interface was referenced by `Schema`'s JSON-Schema
18
+ * via the `definition` "ObjTypeEnum".
19
+ */
20
+ export type ObjTypeEnum = "env" | "ooi";
21
+ /**
22
+ * This interface was referenced by `Schema`'s JSON-Schema
23
+ * via the `definition` "RendererAssetQuality".
24
+ */
25
+ export type RendererAssetQuality = "low" | "medium" | "high" | "ultra";
26
+ /**
27
+ * Events by the engine that are dispatched to host
28
+ *
29
+ * This interface was referenced by `Schema`'s JSON-Schema
30
+ * via the `definition` "SangineEvent".
31
+ */
32
+ export type SangineEvent = "ready" | {
33
+ actionChanged: {
34
+ action: UserAction;
35
+ };
36
+ } | {
37
+ measurementCreated: {
38
+ measurement: Measurement;
39
+ };
40
+ } | {
41
+ routeUnderConstructionUpdated: {
42
+ route: Route;
43
+ };
44
+ };
45
+ /**
46
+ * This interface was referenced by `Schema`'s JSON-Schema
47
+ * via the `definition` "UserAction".
48
+ */
49
+ export type UserAction = "watching" | "creatingRoute" | "measuring" | "setModelOrientation";
50
+ export interface Schema {
51
+ [k: string]: unknown;
52
+ }
53
+ /**
54
+ * This interface was referenced by `Schema`'s JSON-Schema
55
+ * via the `definition` "CameraPos".
56
+ */
57
+ export interface CameraPos {
58
+ position: Vec3;
59
+ target: Vec3;
60
+ }
61
+ /**
62
+ * This interface was referenced by `Schema`'s JSON-Schema
63
+ * via the `definition` "Vec3".
64
+ */
65
+ export interface Vec3 {
66
+ x: number;
67
+ y: number;
68
+ z: number;
69
+ }
70
+ /**
71
+ * This interface was referenced by `Schema`'s JSON-Schema
72
+ * via the `definition` "Material".
73
+ */
74
+ export interface Material {
75
+ id: string;
76
+ identifier: string;
77
+ textures: Texture[];
78
+ }
79
+ /**
80
+ * This interface was referenced by `Schema`'s JSON-Schema
81
+ * via the `definition` "Texture".
82
+ */
83
+ export interface Texture {
84
+ downloadTemplate: string;
85
+ name: string;
86
+ resolutions: number[];
87
+ textureType?: TextureTypeEnum | null;
88
+ }
89
+ /**
90
+ * This interface was referenced by `Schema`'s JSON-Schema
91
+ * via the `definition` "Measurement".
92
+ */
93
+ export interface Measurement {
94
+ meters: number;
95
+ worldUnits: number;
96
+ }
97
+ /**
98
+ * This interface was referenced by `Schema`'s JSON-Schema
99
+ * via the `definition` "ModelCollection".
100
+ */
101
+ export interface ModelCollection {
102
+ materials: Material[];
103
+ modelParts: ModelPart[];
104
+ objType?: ObjTypeEnum | null;
105
+ }
106
+ /**
107
+ * This interface was referenced by `Schema`'s JSON-Schema
108
+ * via the `definition` "ModelPart".
109
+ */
110
+ export interface ModelPart {
111
+ aabb: number[];
112
+ center: number[];
113
+ downloadTemplate: string;
114
+ id: string;
115
+ lods: LodEnum[];
116
+ materials: string[];
117
+ }
118
+ /**
119
+ * This interface was referenced by `Schema`'s JSON-Schema
120
+ * via the `definition` "Route".
121
+ */
122
+ export interface Route {
123
+ id: string;
124
+ path: number[][];
125
+ }
126
+ /**
127
+ * This interface was referenced by `Schema`'s JSON-Schema
128
+ * via the `definition` "Scene".
129
+ */
130
+ export interface Scene {
131
+ initialCameraPos?: number[] | null;
132
+ initialCameraTarget?: number[] | null;
133
+ modelCollections: ModelCollection[];
134
+ northOrientation?: number | null;
135
+ routes: Route[];
136
+ scale?: number | null;
137
+ }
138
+ //# sourceMappingURL=gen-types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gen-types.d.ts","sourceRoot":"","sources":["../src/gen-types.ts"],"names":[],"mappings":"AACA;;;;GAIG;AAEH;;;GAGG;AACH,MAAM,MAAM,OAAO,GAAG,WAAW,GAAG,MAAM,GAAG,QAAQ,GAAG,KAAK,GAAG,UAAU,GAAG,SAAS,GAAG,aAAa,CAAC;AACvG;;;GAGG;AACH,MAAM,MAAM,eAAe,GAAG,SAAS,GAAG,QAAQ,GAAG,QAAQ,CAAC;AAC9D;;;GAGG;AACH,MAAM,MAAM,WAAW,GAAG,KAAK,GAAG,KAAK,CAAC;AACxC;;;GAGG;AACH,MAAM,MAAM,oBAAoB,GAAG,KAAK,GAAG,QAAQ,GAAG,MAAM,GAAG,OAAO,CAAC;AACvE;;;;;GAKG;AACH,MAAM,MAAM,YAAY,GACpB,OAAO,GACP;IACE,aAAa,EAAE;QACb,MAAM,EAAE,UAAU,CAAC;KACpB,CAAC;CACH,GACD;IACE,kBAAkB,EAAE;QAClB,WAAW,EAAE,WAAW,CAAC;KAC1B,CAAC;CACH,GACD;IACE,6BAA6B,EAAE;QAC7B,KAAK,EAAE,KAAK,CAAC;KACd,CAAC;CACH,CAAC;AACN;;;GAGG;AACH,MAAM,MAAM,UAAU,GAAG,UAAU,GAAG,eAAe,GAAG,WAAW,GAAG,qBAAqB,CAAC;AAE5F,MAAM,WAAW,MAAM;IACrB,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;CACtB;AACD;;;GAGG;AACH,MAAM,WAAW,SAAS;IACxB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AAC;IACnC,mBAAmB,CAAC,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC;IACtC,gBAAgB,EAAE,eAAe,EAAE,CAAC;IACpC,gBAAgB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACjC,MAAM,EAAE,KAAK,EAAE,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CACvB"}
@@ -0,0 +1 @@
1
+ "use strict";var f=Object.defineProperty;var y=(r,e,t)=>e in r?f(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t;var n=(r,e,t)=>y(r,typeof e!="symbol"?e+"":e,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const g="/static/sangine/wasm";class _{constructor(e,t){n(this,"workers");n(this,"idle");n(this,"queue",[]);this.workers=Array.from({length:t},e),this.idle=[...this.workers]}run(e){return new Promise((t,i)=>{const a=this.idle.pop();a?this.dispatch(a,e,t,i):this.queue.push({request:e,resolve:t,reject:i})})}dispatch(e,t,i,a){const o=d=>{i(d.data),c(),this.release(e)},s=d=>{a(d),c(),this.release(e)},c=()=>{e.removeEventListener("message",o),e.removeEventListener("error",s)};e.addEventListener("message",o,{once:!0}),e.addEventListener("error",s,{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)}terminate(){for(const e of this.workers)e.terminate()}}class R{constructor(e){n(this,"wasm",null);n(this,"callbackRegistry",{});n(this,"userActionRegistry",{});n(this,"windowCreatedPromiseRegistry",{});n(this,"windowCreatedPromiseResolveRegistry",{});n(this,"_inited",!1);n(this,"decodePool");n(this,"_readyPromise");n(this,"_resolveReady");n(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(`${g}/sangine/sangine.js`,window.location.origin).toString());await t.default(),this.wasm=t,this._inited=!0;const i=this.config.numWorkers??(navigator.hardwareConcurrency||2)-1;this.decodePool=new _(()=>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)}handleRouteUpdated(e,t){for(const i of this.callbackRegistry[e].routeUpdated)i(t)}handleSangineEvent(e,t){t==="ready"?this.windowCreatedPromiseResolveRegistry[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)}createWindow(e,t){if(!this.wasm)throw new Error("WASM not initialized");let i;const a=new Promise(s=>{i=s}),o=this.wasm.create_window(e,t);return this.windowCreatedPromiseResolveRegistry[o]=i,this.callbackRegistry[o]={actionChanged:[],routeUpdated:[],measurementCreated:[]},this.userActionRegistry[o]="watching",this.windowCreatedPromiseRegistry[o]=a,o}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]}setRouteHighlight(e,t,i){if(!this.wasm)throw new Error("WASM not initialized");this.wasm.set_route_highlight(e,t,i)}setRouteVisible(e,t,i){if(!this.wasm)throw new Error("WASM not initialized");this.wasm.set_route_visible(e,t,i)}animateToRoute(e,t){if(!this.wasm)throw new Error("WASM not initialized");this.wasm.animate_to_route(e,t)}setSunProperties(e,t,i,a,o,s,c){if(!this.wasm)throw new Error("WASM not initialized");this.wasm.set_sun_properties(e,t,i,a,o,s,c)}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,t){if(!this.decodePool)throw new Error("Renderer not initialized");return this.decodePool.run({kind:e,url:t})}destroy(){var e;(e=this.decodePool)==null||e.terminate()}}const u=Object.freeze({Webp:0,0:"Webp",Sbo:1,1:"Sbo"});typeof FinalizationRegistry>"u"||new FinalizationRegistry(r=>r.dtor(r.a,r.b));let b=new TextDecoder("utf-8",{ignoreBOM:!0,fatal:!0});b.decode();const l=new TextEncoder;"encodeInto"in l||(l.encodeInto=function(r,e){const t=l.encode(r);return e.set(t),{read:r.length,written:t.length}});function p(r){let e=!1,t=null;r.onmessage=async i=>{if(!e){const s=await import(new URL(`${g}/sbo-decode/wasm_sbo_decode.js`,r.location.origin).href);await s.default(),t=s,e=!0}const{data:a}=i;if(a.kind===u.Webp){const o=a.url;try{const s=await fetch(o);if(!s.ok)throw new Error(`HTTP error! status: ${s.status}`);const c=await s.blob(),d=await createImageBitmap(c),h=new OffscreenCanvas(d.width,d.height),w=h.getContext("2d");if(w===null)throw new Error("Couldnt create canvas");w.drawImage(d,0,0);const m=w.getImageData(0,0,h.width,h.height);r.postMessage({success:!0,width:h.width,height:h.height,data:m.data.buffer},[m.data.buffer])}catch(s){r.postMessage({success:!1,error:s.message})}}else if(a.kind===u.Sbo){const o=a.url,s=await fetch(o);if(!s.ok)throw new Error(`HTTP error! status: ${s.status}`);const c=await s.arrayBuffer(),d=new Uint8Array(c),h=t.decode_sbo(d);r.postMessage({success:!0,data:h.buffer},[h.buffer])}}}exports.DecodeKind=u;exports.RendererService=R;exports.registerDecodeWorker=p;
@@ -0,0 +1,4 @@
1
+ export { RendererService } from './rendererService';
2
+ export * from './types';
3
+ export { registerDecodeWorker } from './worker/decodeWorkerImpl';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AACnD,cAAc,SAAS,CAAA;AACvB,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAA"}
@@ -0,0 +1,256 @@
1
+ var f = Object.defineProperty;
2
+ var y = (s, e, t) => e in s ? f(s, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : s[e] = t;
3
+ var a = (s, e, t) => y(s, typeof e != "symbol" ? e + "" : e, t);
4
+ const g = "/static/sangine/wasm";
5
+ class _ {
6
+ constructor(e, t) {
7
+ a(this, "workers");
8
+ a(this, "idle");
9
+ a(this, "queue", []);
10
+ this.workers = Array.from({ length: t }, e), this.idle = [...this.workers];
11
+ }
12
+ run(e) {
13
+ return new Promise((t, i) => {
14
+ const n = this.idle.pop();
15
+ n ? this.dispatch(n, e, t, i) : this.queue.push({ request: e, resolve: t, reject: i });
16
+ });
17
+ }
18
+ dispatch(e, t, i, n) {
19
+ const o = (d) => {
20
+ i(d.data), h(), this.release(e);
21
+ }, r = (d) => {
22
+ n(d), h(), this.release(e);
23
+ }, h = () => {
24
+ e.removeEventListener("message", o), e.removeEventListener("error", r);
25
+ };
26
+ e.addEventListener("message", o, { once: !0 }), e.addEventListener("error", r, { once: !0 }), e.postMessage(t);
27
+ }
28
+ release(e) {
29
+ const t = this.queue.shift();
30
+ t ? this.dispatch(e, t.request, t.resolve, t.reject) : this.idle.push(e);
31
+ }
32
+ terminate() {
33
+ for (const e of this.workers)
34
+ e.terminate();
35
+ }
36
+ }
37
+ class p {
38
+ constructor(e) {
39
+ a(this, "wasm", null);
40
+ a(this, "callbackRegistry", {});
41
+ a(this, "userActionRegistry", {});
42
+ a(this, "windowCreatedPromiseRegistry", {});
43
+ a(this, "windowCreatedPromiseResolveRegistry", {});
44
+ a(this, "_inited", !1);
45
+ a(this, "decodePool");
46
+ a(this, "_readyPromise");
47
+ a(this, "_resolveReady");
48
+ a(this, "_rejectReady");
49
+ this.config = e, this._readyPromise = new Promise((t, i) => {
50
+ this._resolveReady = t, this._rejectReady = i;
51
+ }), this.config = e;
52
+ }
53
+ async init() {
54
+ if (!(typeof window > "u")) {
55
+ if (this._inited) return this._readyPromise;
56
+ try {
57
+ const t = await import(new URL(
58
+ `${g}/sangine/sangine.js`,
59
+ window.location.origin
60
+ ).toString());
61
+ await t.default(), this.wasm = t, this._inited = !0;
62
+ const i = this.config.numWorkers ?? (navigator.hardwareConcurrency || 2) - 1;
63
+ this.decodePool = new _(
64
+ () => this.config.createDecodeWorker(),
65
+ Math.max(i, 1)
66
+ ), this.wasm.register_asset_decoder(this.decodeAsset.bind(this)), this.wasm.register_event_listener(this.handleSangineEvent.bind(this)), this._resolveReady();
67
+ } catch (e) {
68
+ throw this._rejectReady(e), e;
69
+ }
70
+ return this._readyPromise;
71
+ }
72
+ }
73
+ ready() {
74
+ return this._readyPromise;
75
+ }
76
+ get inited() {
77
+ return this._inited;
78
+ }
79
+ getWasm() {
80
+ if (!this.wasm)
81
+ throw new Error("RendererService not initialized");
82
+ return this.wasm;
83
+ }
84
+ handleActionChanged(e, t) {
85
+ this.userActionRegistry[e] = t;
86
+ for (const i of this.callbackRegistry[e].actionChanged)
87
+ i(t);
88
+ }
89
+ handleMeasurementCreated(e, t) {
90
+ for (const i of this.callbackRegistry[e].measurementCreated)
91
+ i(t);
92
+ }
93
+ handleRouteUpdated(e, t) {
94
+ for (const i of this.callbackRegistry[e].routeUpdated)
95
+ i(t);
96
+ }
97
+ handleSangineEvent(e, t) {
98
+ t === "ready" ? this.windowCreatedPromiseResolveRegistry[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);
99
+ }
100
+ createWindow(e, t) {
101
+ if (!this.wasm) throw new Error("WASM not initialized");
102
+ let i;
103
+ const n = new Promise((r) => {
104
+ i = r;
105
+ }), o = this.wasm.create_window(e, t);
106
+ return this.windowCreatedPromiseResolveRegistry[o] = i, this.callbackRegistry[o] = {
107
+ actionChanged: [],
108
+ routeUpdated: [],
109
+ measurementCreated: []
110
+ }, this.userActionRegistry[o] = "watching", this.windowCreatedPromiseRegistry[o] = n, o;
111
+ }
112
+ readUserAction(e) {
113
+ return this.userActionRegistry[e];
114
+ }
115
+ windowReady(e) {
116
+ return this.windowCreatedPromiseRegistry[e];
117
+ }
118
+ registerCallback(e, t, i) {
119
+ this.callbackRegistry[e][t].push(i);
120
+ }
121
+ setWindowAction(e, t) {
122
+ if (!this.wasm) throw new Error("WASM not initialized");
123
+ this.wasm.set_window_action(e, t);
124
+ }
125
+ destroyWindow(e) {
126
+ if (!this.wasm) throw new Error("WASM not initialized");
127
+ this.wasm.destroy_window(e), delete this.callbackRegistry[e], delete this.userActionRegistry[e];
128
+ }
129
+ setRouteHighlight(e, t, i) {
130
+ if (!this.wasm) throw new Error("WASM not initialized");
131
+ this.wasm.set_route_highlight(e, t, i);
132
+ }
133
+ setRouteVisible(e, t, i) {
134
+ if (!this.wasm) throw new Error("WASM not initialized");
135
+ this.wasm.set_route_visible(e, t, i);
136
+ }
137
+ animateToRoute(e, t) {
138
+ if (!this.wasm) throw new Error("WASM not initialized");
139
+ this.wasm.animate_to_route(e, t);
140
+ }
141
+ setSunProperties(e, t, i, n, o, r, h) {
142
+ if (!this.wasm) throw new Error("WASM not initialized");
143
+ this.wasm.set_sun_properties(
144
+ e,
145
+ t,
146
+ i,
147
+ n,
148
+ o,
149
+ r,
150
+ h
151
+ );
152
+ }
153
+ setNorthCorrection(e, t) {
154
+ if (!this.wasm) throw new Error("WASM not initialized");
155
+ this.wasm.set_north_correction(e, t);
156
+ }
157
+ setGpuMemoryBudgetMb(e, t) {
158
+ if (!this.wasm) throw new Error("WASM not initialized");
159
+ this.wasm.set_gpu_memory_budget_mb(e, t);
160
+ }
161
+ setRenderQuality(e, t) {
162
+ if (!this.wasm) throw new Error("WASM not initialized");
163
+ this.wasm.set_render_quality(e, t);
164
+ }
165
+ readCameraPos(e) {
166
+ if (!this.wasm) throw new Error("WASM not initialized");
167
+ return this.wasm.read_camera_pos(e);
168
+ }
169
+ animateTo(e, t) {
170
+ if (!this.wasm) throw new Error("WASM not initialized");
171
+ this.wasm.animate_to(e, t);
172
+ }
173
+ setScale(e, t) {
174
+ if (!this.wasm) throw new Error("WASM not initialized");
175
+ this.wasm.set_window_scale(e, t);
176
+ }
177
+ async decodeAsset(e, t) {
178
+ if (!this.decodePool) throw new Error("Renderer not initialized");
179
+ return this.decodePool.run({ kind: e, url: t });
180
+ }
181
+ destroy() {
182
+ var e;
183
+ (e = this.decodePool) == null || e.terminate();
184
+ }
185
+ }
186
+ const m = Object.freeze({
187
+ Webp: 0,
188
+ 0: "Webp",
189
+ Sbo: 1,
190
+ 1: "Sbo"
191
+ });
192
+ typeof FinalizationRegistry > "u" || new FinalizationRegistry((s) => s.dtor(s.a, s.b));
193
+ let R = new TextDecoder("utf-8", { ignoreBOM: !0, fatal: !0 });
194
+ R.decode();
195
+ const l = new TextEncoder();
196
+ "encodeInto" in l || (l.encodeInto = function(s, e) {
197
+ const t = l.encode(s);
198
+ return e.set(t), {
199
+ read: s.length,
200
+ written: t.length
201
+ };
202
+ });
203
+ function A(s) {
204
+ let e = !1, t = null;
205
+ s.onmessage = async (i) => {
206
+ if (!e) {
207
+ const r = await import(new URL(
208
+ `${g}/sbo-decode/wasm_sbo_decode.js`,
209
+ s.location.origin
210
+ ).href);
211
+ await r.default(), t = r, e = !0;
212
+ }
213
+ const { data: n } = i;
214
+ if (n.kind === m.Webp) {
215
+ const o = n.url;
216
+ try {
217
+ const r = await fetch(o);
218
+ if (!r.ok)
219
+ throw new Error(`HTTP error! status: ${r.status}`);
220
+ const h = await r.blob(), d = await createImageBitmap(h), c = new OffscreenCanvas(d.width, d.height), w = c.getContext("2d");
221
+ if (w === null)
222
+ throw new Error("Couldnt create canvas");
223
+ w.drawImage(d, 0, 0);
224
+ const u = w.getImageData(0, 0, c.width, c.height);
225
+ s.postMessage(
226
+ {
227
+ success: !0,
228
+ width: c.width,
229
+ height: c.height,
230
+ data: u.data.buffer
231
+ },
232
+ [u.data.buffer]
233
+ );
234
+ } catch (r) {
235
+ s.postMessage({ success: !1, error: r.message });
236
+ }
237
+ } else if (n.kind === m.Sbo) {
238
+ const o = n.url, r = await fetch(o);
239
+ if (!r.ok)
240
+ throw new Error(`HTTP error! status: ${r.status}`);
241
+ const h = await r.arrayBuffer(), d = new Uint8Array(h), c = t.decode_sbo(d);
242
+ s.postMessage(
243
+ {
244
+ success: !0,
245
+ data: c.buffer
246
+ },
247
+ [c.buffer]
248
+ );
249
+ }
250
+ };
251
+ }
252
+ export {
253
+ m as DecodeKind,
254
+ p as RendererService,
255
+ A as registerDecodeWorker
256
+ };
@@ -0,0 +1,52 @@
1
+ import type { CameraPos, DecodeKind, Measurement, RendererAssetQuality, RendererConfig, Route, SangineEvent, Scene, UserAction } from './types.js';
2
+ import type * as SangineModule from './wasm-types/sangine';
3
+ type ActionChangedCallback = (action: UserAction) => void;
4
+ type RouteUpdatedCallback = (route: Route) => void;
5
+ type MeasurementCreatedCallback = (measurement: Measurement) => void;
6
+ interface CallbackMap {
7
+ actionChanged: ActionChangedCallback;
8
+ routeUpdated: RouteUpdatedCallback;
9
+ measurementCreated: MeasurementCreatedCallback;
10
+ }
11
+ export declare class RendererService {
12
+ private config;
13
+ private wasm;
14
+ private callbackRegistry;
15
+ private userActionRegistry;
16
+ private windowCreatedPromiseRegistry;
17
+ private windowCreatedPromiseResolveRegistry;
18
+ private _inited;
19
+ private decodePool?;
20
+ private _readyPromise;
21
+ private _resolveReady;
22
+ private _rejectReady;
23
+ constructor(config: RendererConfig);
24
+ init(): Promise<void>;
25
+ ready(): Promise<void>;
26
+ get inited(): boolean;
27
+ getWasm(): typeof SangineModule;
28
+ handleActionChanged(windowId: number, action: UserAction): void;
29
+ handleMeasurementCreated(windowId: number, measurement: Measurement): void;
30
+ handleRouteUpdated(windowId: number, route: Route): void;
31
+ handleSangineEvent(windowId: number, event: SangineEvent): void;
32
+ createWindow(containerId: string, scene: Scene): number;
33
+ readUserAction(windowId: number): UserAction;
34
+ windowReady(windowId: number): Promise<void>;
35
+ registerCallback<K extends keyof CallbackMap>(windowId: number, event: K, callback: CallbackMap[K]): void;
36
+ setWindowAction(windowId: number, action: UserAction): void;
37
+ destroyWindow(windowId: number): void;
38
+ setRouteHighlight(windowId: number, routeId: string, highlight: number): void;
39
+ setRouteVisible(windowId: number, routeId: string, visible: number): void;
40
+ animateToRoute(windowId: number, routeId: string): void;
41
+ setSunProperties(windowId: number, altitudeRad: number, azimuthRad: number, colorR: number, colorG: number, colorB: number, intensity: number): void;
42
+ setNorthCorrection(windowId: number, northCorrection: number): void;
43
+ setGpuMemoryBudgetMb(windowId: number, memoryMb: number): void;
44
+ setRenderQuality(windowId: number, quality: RendererAssetQuality): void;
45
+ readCameraPos(windowId: number): CameraPos;
46
+ animateTo(windowId: number, position: CameraPos): void;
47
+ setScale(windowId: number, scale: number): void;
48
+ decodeAsset(kind: DecodeKind, url: string): Promise<ArrayBuffer>;
49
+ destroy(): void;
50
+ }
51
+ export {};
52
+ //# sourceMappingURL=rend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,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,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC;IAKtE,OAAO;CAGR"}
@@ -0,0 +1,12 @@
1
+ import { type DecodeKind } from './wasm-types/sangine';
2
+ export * from './gen-types';
3
+ export { DecodeKind } from './wasm-types/sangine';
4
+ export interface DecodeTask {
5
+ kind: DecodeKind;
6
+ url: string;
7
+ }
8
+ export interface RendererConfig {
9
+ createDecodeWorker(): Worker;
10
+ numWorkers?: number;
11
+ }
12
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,sBAAsB,CAAA;AACtD,cAAc,aAAa,CAAA;AAC3B,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA;AAEjD,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,UAAU,CAAA;IAChB,GAAG,EAAE,MAAM,CAAA;CACZ;AAED,MAAM,WAAW,cAAc;IAC7B,kBAAkB,IAAI,MAAM,CAAA;IAC5B,UAAU,CAAC,EAAE,MAAM,CAAA;CACpB"}
@@ -0,0 +1,100 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+
4
+ export enum DecodeKind {
5
+ Webp = 0,
6
+ Sbo = 1,
7
+ }
8
+
9
+ export function animate_to(window_id: number, camera_target: any): void;
10
+
11
+ export function animate_to_route(window_id: number, route_id: string): void;
12
+
13
+ export function create_window(container_id: string, scene: any): number;
14
+
15
+ export function destroy_window(window_id: number): void;
16
+
17
+ /**
18
+ * Read camera as a vector of Vec3Js. First element is position, second is target.
19
+ */
20
+ export function read_camera_pos(window_id: number): any;
21
+
22
+ export function register_asset_decoder(decoder: Function): void;
23
+
24
+ export function register_event_listener(event_listener: Function): void;
25
+
26
+ export function run(): Promise<void>;
27
+
28
+ export function set_gpu_memory_budget_mb(window_id: number, memory_budget: number): void;
29
+
30
+ export function set_north_correction(window_id: number, north_correction: number): void;
31
+
32
+ export function set_render_quality(window_id: number, quality: any): void;
33
+
34
+ export function set_route_highlight(window_id: number, route_id: string, highlight: number): void;
35
+
36
+ export function set_route_visible(window_id: number, route_id: string, visible: number): void;
37
+
38
+ export function set_sun_properties(window_id: number, altitude_rad: number, azimuth_rad: number, color_r: number, color_g: number, color_b: number, intensity: number): void;
39
+
40
+ export function set_window_action(window_id: number, action: any): void;
41
+
42
+ export function set_window_scale(window_id: number, scale: number): void;
43
+
44
+ export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
45
+
46
+ export interface InitOutput {
47
+ readonly memory: WebAssembly.Memory;
48
+ readonly animate_to: (a: number, b: any) => [number, number];
49
+ readonly animate_to_route: (a: number, b: number, c: number) => [number, number];
50
+ readonly create_window: (a: number, b: number, c: any) => number;
51
+ readonly destroy_window: (a: number) => [number, number];
52
+ readonly read_camera_pos: (a: number) => [number, number, number];
53
+ readonly register_asset_decoder: (a: any) => void;
54
+ readonly register_event_listener: (a: any) => void;
55
+ readonly set_gpu_memory_budget_mb: (a: number, b: number) => [number, number];
56
+ readonly set_north_correction: (a: number, b: number) => [number, number];
57
+ readonly set_render_quality: (a: number, b: any) => [number, number];
58
+ readonly set_route_highlight: (a: number, b: number, c: number, d: number) => [number, number];
59
+ readonly set_route_visible: (a: number, b: number, c: number, d: number) => [number, number];
60
+ readonly set_sun_properties: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => [number, number];
61
+ readonly set_window_action: (a: number, b: any) => [number, number];
62
+ readonly set_window_scale: (a: number, b: number) => [number, number];
63
+ readonly run: () => void;
64
+ readonly wasm_bindgen__closure__destroy__h0f9502aef9ad7012: (a: number, b: number) => void;
65
+ readonly wasm_bindgen__closure__destroy__h756fff185ea9610f: (a: number, b: number) => void;
66
+ readonly wasm_bindgen__convert__closures_____invoke__h9bcfaf9db4ab96db: (a: number, b: number, c: any, d: any) => void;
67
+ readonly wasm_bindgen__convert__closures_____invoke__h355f794c725ec492: (a: number, b: number, c: any) => void;
68
+ readonly wasm_bindgen__convert__closures_____invoke__h11a2876e668b0630: (a: number, b: number, c: any) => void;
69
+ readonly wasm_bindgen__convert__closures_____invoke__h81c46bf303557186: (a: number, b: number) => void;
70
+ readonly __wbindgen_malloc: (a: number, b: number) => number;
71
+ readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
72
+ readonly __externref_table_alloc: () => number;
73
+ readonly __wbindgen_externrefs: WebAssembly.Table;
74
+ readonly __wbindgen_exn_store: (a: number) => void;
75
+ readonly __wbindgen_free: (a: number, b: number, c: number) => void;
76
+ readonly __externref_table_dealloc: (a: number) => void;
77
+ readonly __wbindgen_start: () => void;
78
+ }
79
+
80
+ export type SyncInitInput = BufferSource | WebAssembly.Module;
81
+
82
+ /**
83
+ * Instantiates the given `module`, which can either be bytes or
84
+ * a precompiled `WebAssembly.Module`.
85
+ *
86
+ * @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
87
+ *
88
+ * @returns {InitOutput}
89
+ */
90
+ export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
91
+
92
+ /**
93
+ * If `module_or_path` is {RequestInfo} or {URL}, makes a request and
94
+ * for everything else, calls `WebAssembly.instantiate` directly.
95
+ *
96
+ * @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
97
+ *
98
+ * @returns {Promise<InitOutput>}
99
+ */
100
+ export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;