Mercurial > hg > orthanc-stone
annotate Platforms/Wasm/stone-framework-loader.ts @ 1324:4d8d642f7036 broker
Added a NullLayer scene layer type that allows
"booking" a scene depth entry.
author | Benjamin Golinvaux <bgo@osimis.io> |
---|---|
date | Tue, 24 Mar 2020 16:24:26 +0100 |
parents | daf43666bbc2 |
children |
rev | line source |
---|---|
466
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
1 /** |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
2 * This file contains primitives to interface with WebAssembly and |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
3 * with the Stone framework. |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
4 **/ |
526
548eed46f535
introduced a Logger class that displays timing and source (C++/JS)
Alain Mazy <alain@mazy.be>
parents:
466
diff
changeset
|
5 import * as Logger from './logger' |
466
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
6 |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
7 export declare type InitializationCallback = () => void; |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
8 |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
9 //export declare var StoneFrameworkModule : any; |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
10 export var StoneFrameworkModule : any; |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
11 |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
12 //const ASSETS_FOLDER : string = "assets/lib"; |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
13 //const WASM_FILENAME : string = "orthanc-framework"; |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
14 |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
15 export class Framework |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
16 { |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
17 private static singleton_ : Framework = null; |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
18 private static wasmModuleName_ : string = null; |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
19 |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
20 public static Configure(wasmModuleName: string) { |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
21 this.wasmModuleName_ = wasmModuleName; |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
22 } |
238
126c9c0c9333
SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents:
237
diff
changeset
|
23 |
466
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
24 private constructor(verbose : boolean) |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
25 { |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
26 //this.ccall('Initialize', null, [ 'number' ], [ verbose ]); |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
27 } |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
28 |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
29 |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
30 public ccall( name: string, |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
31 returnType: string, |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
32 argTypes: Array<string>, |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
33 argValues: Array<any>) : any |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
34 { |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
35 return (<any> window).StoneFrameworkModule.ccall(name, returnType, argTypes, argValues); |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
36 } |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
37 |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
38 |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
39 public cwrap( name: string, |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
40 returnType: string, |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
41 argTypes: Array<string>) : any |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
42 { |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
43 return (<any> window).StoneFrameworkModule.cwrap(name, returnType, argTypes); |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
44 } |
238
126c9c0c9333
SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents:
237
diff
changeset
|
45 |
466
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
46 |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
47 public static GetInstance() : Framework |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
48 { |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
49 if (Framework.singleton_ == null) { |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
50 throw new Error('The WebAssembly module is not loaded yet'); |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
51 } else { |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
52 return Framework.singleton_; |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
53 } |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
54 } |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
55 |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
56 |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
57 public static Initialize( verbose: boolean, |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
58 callback: InitializationCallback) |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
59 { |
526
548eed46f535
introduced a Logger class that displays timing and source (C++/JS)
Alain Mazy <alain@mazy.be>
parents:
466
diff
changeset
|
60 Logger.defaultLogger.debug('Initializing WebAssembly Module'); |
466
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
61 |
603
70992b38aa8a
new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents:
526
diff
changeset
|
62 (<any> window).errorFromCpp = function(text:any) { Logger.defaultLogger.errorFromCpp(text); }; |
70992b38aa8a
new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents:
526
diff
changeset
|
63 (<any> window).warningFromCpp = function(text:any) { Logger.defaultLogger.warningFromCpp(text); }; |
70992b38aa8a
new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents:
526
diff
changeset
|
64 (<any> window).infoFromCpp = function(text:any) { Logger.defaultLogger.infoFromCpp(text); }; |
70992b38aa8a
new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents:
526
diff
changeset
|
65 (<any> window).debugFromCpp = function(text:any) { Logger.defaultLogger.debugFromCpp(text); }; |
70992b38aa8a
new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents:
526
diff
changeset
|
66 |
466
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
67 // (<any> window). |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
68 (<any> window).StoneFrameworkModule = { |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
69 preRun: [ |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
70 function() { |
526
548eed46f535
introduced a Logger class that displays timing and source (C++/JS)
Alain Mazy <alain@mazy.be>
parents:
466
diff
changeset
|
71 Logger.defaultLogger.debug('Loading the Stone Framework using WebAssembly'); |
223 | 72 } |
466
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
73 ], |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
74 postRun: [ |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
75 function() { |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
76 // This function is called by ".js" wrapper once the ".wasm" |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
77 // WebAssembly module has been loaded and compiled by the |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
78 // browser |
526
548eed46f535
introduced a Logger class that displays timing and source (C++/JS)
Alain Mazy <alain@mazy.be>
parents:
466
diff
changeset
|
79 Logger.defaultLogger.debug('WebAssembly is ready'); |
466
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
80 Framework.singleton_ = new Framework(verbose); |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
81 callback(); |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
82 } |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
83 ], |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
84 totalDependencies: 0 |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
85 }; |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
86 |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
87 // Dynamic loading of the JavaScript wrapper around WebAssembly |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
88 var script = document.createElement('script'); |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
89 script.type = 'application/javascript'; |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
90 //script.src = "orthanc-stone.js"; // ASSETS_FOLDER + '/' + WASM_FILENAME + '.js'; |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
91 script.src = this.wasmModuleName_ + ".js";// "OrthancStoneSimpleViewer.js"; // ASSETS_FOLDER + '/' + WASM_FILENAME + '.js'; |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
92 script.async = true; |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
93 document.head.appendChild(script); |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
94 } |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
95 } |