@combeenation/3d-viewer 4.0.0-beta3 → 4.0.0-beta4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (92) hide show
  1. package/README.md +112 -112
  2. package/dist/lib-cjs/api/classes/animationInterface.d.ts +8 -8
  3. package/dist/lib-cjs/api/classes/animationInterface.js +1 -1
  4. package/dist/lib-cjs/api/classes/dottedPath.d.ts +79 -79
  5. package/dist/lib-cjs/api/classes/dottedPath.js +190 -190
  6. package/dist/lib-cjs/api/classes/element.d.ts +125 -125
  7. package/dist/lib-cjs/api/classes/element.js +682 -682
  8. package/dist/lib-cjs/api/classes/elementParameterizable.d.ts +14 -14
  9. package/dist/lib-cjs/api/classes/elementParameterizable.js +134 -134
  10. package/dist/lib-cjs/api/classes/event.d.ts +312 -312
  11. package/dist/lib-cjs/api/classes/event.js +357 -357
  12. package/dist/lib-cjs/api/classes/eventBroadcaster.d.ts +26 -26
  13. package/dist/lib-cjs/api/classes/eventBroadcaster.js +53 -53
  14. package/dist/lib-cjs/api/classes/parameter.d.ts +165 -165
  15. package/dist/lib-cjs/api/classes/parameter.js +267 -267
  16. package/dist/lib-cjs/api/classes/parameterObservable.d.ts +36 -36
  17. package/dist/lib-cjs/api/classes/parameterObservable.js +126 -126
  18. package/dist/lib-cjs/api/classes/parameterizable.d.ts +15 -15
  19. package/dist/lib-cjs/api/classes/parameterizable.js +149 -149
  20. package/dist/lib-cjs/api/classes/placementAnimation.d.ts +38 -38
  21. package/dist/lib-cjs/api/classes/placementAnimation.js +138 -138
  22. package/dist/lib-cjs/api/classes/variant.d.ts +190 -190
  23. package/dist/lib-cjs/api/classes/variant.js +873 -873
  24. package/dist/lib-cjs/api/classes/variantInstance.d.ts +41 -41
  25. package/dist/lib-cjs/api/classes/variantInstance.js +98 -98
  26. package/dist/lib-cjs/api/classes/variantParameterizable.d.ts +17 -17
  27. package/dist/lib-cjs/api/classes/variantParameterizable.js +92 -92
  28. package/dist/lib-cjs/api/classes/viewer.d.ts +128 -128
  29. package/dist/lib-cjs/api/classes/viewer.js +486 -486
  30. package/dist/lib-cjs/api/classes/viewerLight.d.ts +65 -66
  31. package/dist/lib-cjs/api/classes/viewerLight.js +322 -389
  32. package/dist/lib-cjs/api/classes/viewerLight.js.map +1 -1
  33. package/dist/lib-cjs/api/internal/debugViewer.d.ts +13 -13
  34. package/dist/lib-cjs/api/internal/debugViewer.js +87 -87
  35. package/dist/lib-cjs/api/internal/lensRendering.d.ts +8 -8
  36. package/dist/lib-cjs/api/internal/lensRendering.js +11 -11
  37. package/dist/lib-cjs/api/internal/sceneSetup.d.ts +6 -6
  38. package/dist/lib-cjs/api/internal/sceneSetup.js +227 -227
  39. package/dist/lib-cjs/api/manager/animationManager.d.ts +29 -29
  40. package/dist/lib-cjs/api/manager/animationManager.js +121 -121
  41. package/dist/lib-cjs/api/manager/sceneManager.d.ts +32 -32
  42. package/dist/lib-cjs/api/manager/sceneManager.js +132 -132
  43. package/dist/lib-cjs/api/manager/variantInstanceManager.d.ts +90 -90
  44. package/dist/lib-cjs/api/manager/variantInstanceManager.js +321 -321
  45. package/dist/lib-cjs/api/store/specStorage.d.ts +24 -24
  46. package/dist/lib-cjs/api/store/specStorage.js +51 -51
  47. package/dist/lib-cjs/api/util/babylonHelper.d.ts +125 -125
  48. package/dist/lib-cjs/api/util/babylonHelper.js +368 -368
  49. package/dist/lib-cjs/api/util/globalTypes.d.ts +279 -279
  50. package/dist/lib-cjs/api/util/globalTypes.js +1 -1
  51. package/dist/lib-cjs/api/util/resourceHelper.d.ts +51 -48
  52. package/dist/lib-cjs/api/util/resourceHelper.js +243 -240
  53. package/dist/lib-cjs/api/util/resourceHelper.js.map +1 -1
  54. package/dist/lib-cjs/api/util/stringHelper.d.ts +9 -9
  55. package/dist/lib-cjs/api/util/stringHelper.js +25 -25
  56. package/dist/lib-cjs/buildinfo.json +3 -3
  57. package/dist/lib-cjs/index.d.ts +46 -46
  58. package/dist/lib-cjs/index.js +82 -82
  59. package/dist/webpack-stats.json +0 -0
  60. package/package.json +83 -83
  61. package/src/api/classes/animationInterface.ts +11 -11
  62. package/src/api/classes/dottedPath.ts +189 -189
  63. package/src/api/classes/element.ts +617 -617
  64. package/src/api/classes/elementParameterizable.ts +78 -78
  65. package/src/api/classes/event.ts +355 -355
  66. package/src/api/classes/eventBroadcaster.ts +54 -54
  67. package/src/api/classes/parameter.ts +277 -277
  68. package/src/api/classes/parameterObservable.ts +121 -121
  69. package/src/api/classes/placementAnimation.ts +133 -133
  70. package/src/api/classes/variant.ts +670 -670
  71. package/src/api/classes/variantInstance.ts +81 -81
  72. package/src/api/classes/viewer.ts +421 -421
  73. package/src/api/internal/debugViewer.ts +81 -81
  74. package/src/api/internal/lensRendering.ts +10 -10
  75. package/src/api/internal/sceneSetup.ts +203 -203
  76. package/src/api/manager/animationManager.ts +116 -116
  77. package/src/api/manager/sceneManager.ts +105 -105
  78. package/src/api/manager/variantInstanceManager.ts +236 -236
  79. package/src/api/store/specStorage.ts +53 -53
  80. package/src/api/util/babylonHelper.ts +392 -392
  81. package/src/api/util/globalTypes.ts +318 -318
  82. package/src/api/util/resourceHelper.ts +187 -184
  83. package/src/buildinfo.json +2 -2
  84. package/src/commonjs.tsconfig.json +13 -13
  85. package/src/declaration.tsconfig.json +10 -10
  86. package/src/dev.ts +46 -46
  87. package/src/es6.tsconfig.json +13 -13
  88. package/src/index.ts +87 -87
  89. package/src/pagesconfig.json +57 -57
  90. package/src/tsconfig.json +43 -43
  91. package/src/tsconfig.types.json +9 -9
  92. package/src/types.d.ts +4 -4
@@ -1,185 +1,188 @@
1
- import { emitter, Event } from '../classes/event';
2
-
3
- /**
4
- * Loads any kind of response from given path.
5
- * @emits {@link Event.LOADING_START}
6
- * @emits {@link Event.LOADING_END}
7
- */
8
- const load = async function( path: string ): Promise<Response> {
9
- emitter.emit( Event.LOADING_START, path );
10
- let data = await fetch( path );
11
- emitter.emit( Event.LOADING_END, path );
12
- return data;
13
- };
14
-
15
- /**
16
- * Loads a JSON from a given path.
17
- * @emits {@link Event.LOADING_START}
18
- * @emits {@link Event.LOADING_END}
19
- */
20
- const loadJson = async function<T>( path: string ): Promise<T> {
21
- const response = await load(path);
22
- return response.json();
23
- };
24
-
25
- /**
26
- * Loads a Text from a given path.
27
- * @emits {@link Event.LOADING_START}
28
- * @emits {@link Event.LOADING_END}
29
- */
30
- const loadText = async function( path: string ): Promise<string> {
31
- const response = await load(path);
32
- return response.text();
33
- };
34
-
35
- /**
36
- * Debounces: it limits the rate at which a function can fire.
37
- */
38
- const debounce = function( func: Function, wait: number, immediate: boolean = false ) {
39
- let timeout: any;
40
- return function() {
41
- // @ts-ignore
42
- const context = this;
43
- const args = arguments;
44
- const later = function() {
45
- timeout = null;
46
- if( !immediate ) {
47
- func.apply( context, args );
48
- }
49
- };
50
- const callNow = immediate && !timeout;
51
- clearTimeout( timeout );
52
- timeout = setTimeout( later, wait );
53
- if( callNow ) {
54
- func.apply( context, args );
55
- }
56
- };
57
- };
58
-
59
- /**
60
- * Creates a random uuidv4.
61
- */
62
- const uuidv4 = function() {
63
- // @ts-ignore
64
- return ([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace( /[018]/g, c =>
65
- (c ^ crypto.getRandomValues( new Uint8Array( 1 ) )[0] & 15 >> c / 4).toString( 16 )
66
- );
67
- };
68
-
69
- /**
70
- * Merges multiple maps.
71
- */
72
- const mergeMaps = function <TKey, TValue>( ...maps: Map<TKey, TValue>[] ): Map<TKey, TValue> {
73
- const resultMap = new Map<TKey, TValue>();
74
- maps.forEach( map => {
75
- map.forEach( ( v, k ) => {
76
- resultMap.set( k, v );
77
- } );
78
- } );
79
- return resultMap;
80
- };
81
-
82
- /**
83
- * Creates a HTML image element based on a SVG string, whereas all the embedded assets in the SVG
84
- * (eg: fonts, images) are already loaded and exchanged by their base64 representation.\
85
- * There the output image can exist as "standalone" image and may be used for example as a paintable.
86
- *
87
- * !!CAUTION!!: The used functions within this code section are very well evaluated since most alternatives
88
- * somehow don't work in Safari, as mentioned in the following BJS forum entries:
89
- * - https://forum.babylonjs.com/t/drawing-svg-content-text-into-dynamictexture-doesnt-work-in-safari-v15/25048
90
- * - https://forum.babylonjs.com/t/texture-createfrombase64string-doesnt-seem-to-work-for-ios-devices-initially/25502
91
- */
92
- const createImageFromSvg = async function( svgSrc: string ): Promise<HTMLImageElement> {
93
- // replace assets with their base64 versions in svg source code
94
- const svgWithAssetsEmbedded = await _embedAssets( svgSrc );
95
-
96
- // create data string which can be used as an image source
97
- const svgEncoded = 'data:image/svg+xml,' + encodeURIComponent(svgWithAssetsEmbedded)
98
-
99
- return createImageFromImgSrc(svgEncoded);
100
- };
101
-
102
- /**
103
- * Creates an HTML image element from a dedicated image source.\
104
- * Also waits until the image has loaded.
105
- *
106
- * !!CAUTION!!: The `setTimeout` after loading is finished is required due to a Safari bug:
107
- * - https://bugs.webkit.org/show_bug.cgi?id=39059
108
- * - https://bugs.webkit.org/show_bug.cgi?id=219770
109
- *
110
- * It's not 100% ensured that the timeout solves the issue in any case, but there is no other way unfortunately.\
111
- * => Keep an eye on it in future projects
112
- */
113
- const createImageFromImgSrc = async function ( imgSrc: string ): Promise<HTMLImageElement> {
114
- let img = new Image();
115
-
116
- await new Promise(resolve => {
117
- img.onload = () => {
118
- setTimeout(resolve, 0);
119
- }
120
- img.src = imgSrc;
121
- });
122
-
123
- return img;
124
- }
125
-
126
- /**
127
- * Replaces all supported image & font URLs in the given SVG with their base64 representation.
128
- */
129
- const _embedAssets = async function( svgSrc: string ): Promise<string> {
130
- const _imageExtensions = ['png', 'gif', 'jpg', 'jpeg', 'svg', 'bmp'];
131
- const _fontExtensions = ['woff2', 'woff', 'ttf', 'otf'];
132
- const _assetExtensions = [..._imageExtensions, ..._fontExtensions];
133
- // Regex copied from https://stackoverflow.com/a/8943487/1273551, not "stress tested"...
134
- const urlRegex = /(\bhttps?:\/\/[-A-Z0-9+&@#/%?=~_|!:,.;]*[-A-Z0-9+&@#/%=~_|])/gi;
135
- const allUrls = svgSrc.match( urlRegex ) as string[];
136
- const assetUrls = allUrls.filter(
137
- url => _assetExtensions.some(
138
- extension => url.toLowerCase().endsWith( `.${extension}` )
139
- )
140
- );
141
- const assetBase64Fetcher = assetUrls.map( _fetchBase64AssetUrl );
142
- const assetFetcherResults = await Promise.all( assetBase64Fetcher );
143
- return assetFetcherResults.reduce(
144
- ( svgSrc, x ) => svgSrc.replace( x.url, x.base64 ), svgSrc
145
- );
146
- };
147
-
148
- /**
149
- * Fetch asset (image or font) and convert it to base64 string representation.
150
- */
151
- const _fetchBase64AssetUrl = async function( assetUrl: string ): Promise<{ url: string, base64: string }> {
152
- // TODO: Cache known base64 representation and only fetch/convert when not already known.
153
- // Usually the fetch shouldn't hit the network but the browser cache since the SVG was already drawn.
154
- // See comments of "createImageBitmapFromSvg" for some considerations...
155
- return new Promise( async (resolve, reject) => {
156
- const resp = await fetch( assetUrl );
157
- const blob = await resp.blob();
158
- const reader = new FileReader();
159
- reader.onloadend = event => {
160
- const target = event.target;
161
- if( !target ) {
162
- return reject( `Asset with URL "${assetUrl}" could not be loaded.` );
163
- }
164
- const result = target.result;
165
- if( !result ) {
166
- return reject( `Asset with URL "${assetUrl}" returned an empty result.` );
167
- }
168
- resolve( {
169
- url: assetUrl,
170
- base64: result.toString() as string,
171
- } );
172
- };
173
- reader.readAsDataURL( blob );
174
- } );
175
- };
176
-
177
- export {
178
- loadJson,
179
- loadText,
180
- debounce,
181
- uuidv4,
182
- mergeMaps,
183
- createImageFromSvg,
184
- createImageFromImgSrc
1
+ import { emitter, Event } from '../classes/event';
2
+
3
+ /**
4
+ * Loads any kind of response from given path.
5
+ * @emits {@link Event.LOADING_START}
6
+ * @emits {@link Event.LOADING_END}
7
+ */
8
+ const load = async function( path: string ): Promise<Response> {
9
+ emitter.emit( Event.LOADING_START, path );
10
+ let data = await fetch( path );
11
+ emitter.emit( Event.LOADING_END, path );
12
+ return data;
13
+ };
14
+
15
+ /**
16
+ * Loads a JSON from a given path.
17
+ * @emits {@link Event.LOADING_START}
18
+ * @emits {@link Event.LOADING_END}
19
+ */
20
+ const loadJson = async function<T>( path: string ): Promise<T> {
21
+ const response = await load(path);
22
+ return response.json();
23
+ };
24
+
25
+ /**
26
+ * Loads a Text from a given path.
27
+ * @emits {@link Event.LOADING_START}
28
+ * @emits {@link Event.LOADING_END}
29
+ */
30
+ const loadText = async function( path: string ): Promise<string> {
31
+ const response = await load(path);
32
+ return response.text();
33
+ };
34
+
35
+ /**
36
+ * Debounces: it limits the rate at which a function can fire.
37
+ */
38
+ const debounce = function( func: Function, wait: number, immediate: boolean = false ) {
39
+ let timeout: any;
40
+ return function() {
41
+ // @ts-ignore
42
+ const context = this;
43
+ const args = arguments;
44
+ const later = function() {
45
+ timeout = null;
46
+ if( !immediate ) {
47
+ func.apply( context, args );
48
+ }
49
+ };
50
+ const callNow = immediate && !timeout;
51
+ clearTimeout( timeout );
52
+ timeout = setTimeout( later, wait );
53
+ if( callNow ) {
54
+ func.apply( context, args );
55
+ }
56
+ };
57
+ };
58
+
59
+ /**
60
+ * Creates a random uuidv4.
61
+ */
62
+ const uuidv4 = function() {
63
+ // @ts-ignore
64
+ return ([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace( /[018]/g, c =>
65
+ (c ^ crypto.getRandomValues( new Uint8Array( 1 ) )[0] & 15 >> c / 4).toString( 16 )
66
+ );
67
+ };
68
+
69
+ /**
70
+ * Merges multiple maps.
71
+ */
72
+ const mergeMaps = function <TKey, TValue>( ...maps: Map<TKey, TValue>[] ): Map<TKey, TValue> {
73
+ const resultMap = new Map<TKey, TValue>();
74
+ maps.forEach( map => {
75
+ map.forEach( ( v, k ) => {
76
+ resultMap.set( k, v );
77
+ } );
78
+ } );
79
+ return resultMap;
80
+ };
81
+
82
+ /**
83
+ * Creates a HTML image element based on a SVG string, whereas all the embedded assets in the SVG
84
+ * (eg: fonts, images) are already loaded and exchanged by their base64 representation.\
85
+ * There the output image can exist as "standalone" image and may be used for example as a paintable.
86
+ *
87
+ * !!CAUTION!!: The used functions within this code section are very well evaluated since most alternatives
88
+ * somehow don't work in Safari, as mentioned in the following BJS forum entries:
89
+ * - https://forum.babylonjs.com/t/drawing-svg-content-text-into-dynamictexture-doesnt-work-in-safari-v15/25048
90
+ * - https://forum.babylonjs.com/t/texture-createfrombase64string-doesnt-seem-to-work-for-ios-devices-initially/25502
91
+ */
92
+ const createImageFromSvg = async function( svgSrc: string ): Promise<HTMLImageElement> {
93
+ // replace assets with their base64 versions in svg source code
94
+ const svgWithAssetsEmbedded = await _embedAssets( svgSrc );
95
+
96
+ // create data string which can be used as an image source
97
+ const svgEncoded = 'data:image/svg+xml,' + encodeURIComponent(svgWithAssetsEmbedded)
98
+
99
+ return createImageFromImgSrc(svgEncoded);
100
+ };
101
+
102
+ /**
103
+ * Creates an HTML image element from a dedicated image source.\
104
+ * Also waits until the image has loaded.
105
+ *
106
+ * !!CAUTION!!: The `setTimeout` after loading is finished is required due to a Safari bug:
107
+ * - https://bugs.webkit.org/show_bug.cgi?id=39059
108
+ * - https://bugs.webkit.org/show_bug.cgi?id=219770
109
+ *
110
+ * It's not 100% ensured that the timeout solves the issue in every case, but there is no other way unfortunately.\
111
+ * => Keep an eye on it in future projects
112
+ *
113
+ * @param imgSrc Theoretically every source is valid which is also supported by [HTMLImageElement.src](https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/src).\
114
+ * Known exceptions are SVGs with embedded assets that are provided as object URL. (see comments in {@link createImageFromSvg})
115
+ */
116
+ const createImageFromImgSrc = async function ( imgSrc: string ): Promise<HTMLImageElement> {
117
+ let img = new Image();
118
+
119
+ await new Promise(resolve => {
120
+ img.onload = () => {
121
+ setTimeout(resolve, 0);
122
+ }
123
+ img.src = imgSrc;
124
+ });
125
+
126
+ return img;
127
+ }
128
+
129
+ /**
130
+ * Replaces all supported image & font URLs in the given SVG with their base64 representation.
131
+ */
132
+ const _embedAssets = async function( svgSrc: string ): Promise<string> {
133
+ const _imageExtensions = ['png', 'gif', 'jpg', 'jpeg', 'svg', 'bmp'];
134
+ const _fontExtensions = ['woff2', 'woff', 'ttf', 'otf'];
135
+ const _assetExtensions = [..._imageExtensions, ..._fontExtensions];
136
+ // Regex copied from https://stackoverflow.com/a/8943487/1273551, not "stress tested"...
137
+ const urlRegex = /(\bhttps?:\/\/[-A-Z0-9+&@#/%?=~_|!:,.;]*[-A-Z0-9+&@#/%=~_|])/gi;
138
+ const allUrls = svgSrc.match( urlRegex ) as string[];
139
+ const assetUrls = allUrls.filter(
140
+ url => _assetExtensions.some(
141
+ extension => url.toLowerCase().endsWith( `.${extension}` )
142
+ )
143
+ );
144
+ const assetBase64Fetcher = assetUrls.map( _fetchBase64AssetUrl );
145
+ const assetFetcherResults = await Promise.all( assetBase64Fetcher );
146
+ return assetFetcherResults.reduce(
147
+ ( svgSrc, x ) => svgSrc.replace( x.url, x.base64 ), svgSrc
148
+ );
149
+ };
150
+
151
+ /**
152
+ * Fetch asset (image or font) and convert it to base64 string representation.
153
+ */
154
+ const _fetchBase64AssetUrl = async function( assetUrl: string ): Promise<{ url: string, base64: string }> {
155
+ // TODO: Cache known base64 representation and only fetch/convert when not already known.
156
+ // Usually the fetch shouldn't hit the network but the browser cache since the SVG was already drawn.
157
+ // See comments of "createImageBitmapFromSvg" for some considerations...
158
+ return new Promise( async (resolve, reject) => {
159
+ const resp = await fetch( assetUrl );
160
+ const blob = await resp.blob();
161
+ const reader = new FileReader();
162
+ reader.onloadend = event => {
163
+ const target = event.target;
164
+ if( !target ) {
165
+ return reject( `Asset with URL "${assetUrl}" could not be loaded.` );
166
+ }
167
+ const result = target.result;
168
+ if( !result ) {
169
+ return reject( `Asset with URL "${assetUrl}" returned an empty result.` );
170
+ }
171
+ resolve( {
172
+ url: assetUrl,
173
+ base64: result.toString() as string,
174
+ } );
175
+ };
176
+ reader.readAsDataURL( blob );
177
+ } );
178
+ };
179
+
180
+ export {
181
+ loadJson,
182
+ loadText,
183
+ debounce,
184
+ uuidv4,
185
+ mergeMaps,
186
+ createImageFromSvg,
187
+ createImageFromImgSrc
185
188
  };
@@ -1,3 +1,3 @@
1
- {
2
- "version": "@VERSION@"
1
+ {
2
+ "version": "@VERSION@"
3
3
  }
@@ -1,13 +1,13 @@
1
- {
2
- "extends": "./tsconfig",
3
- "exclude": [
4
- "dev.ts",
5
- "assets"
6
- ],
7
- "compilerOptions": {
8
- "module": "commonjs",
9
- "moduleResolution": "node",
10
- "outDir": "../dist/lib-cjs",
11
- "declaration": true
12
- }
13
- }
1
+ {
2
+ "extends": "./tsconfig",
3
+ "exclude": [
4
+ "dev.ts",
5
+ "assets"
6
+ ],
7
+ "compilerOptions": {
8
+ "module": "commonjs",
9
+ "moduleResolution": "node",
10
+ "outDir": "../dist/lib-cjs",
11
+ "declaration": true
12
+ }
13
+ }
@@ -1,10 +1,10 @@
1
- {
2
- "extends": "./tsconfig",
3
- "compilerOptions": {
4
- "declaration": true,
5
- "outDir": "../dist/types",
6
- "emitDeclarationOnly": true
7
- }
8
-
9
-
10
- }
1
+ {
2
+ "extends": "./tsconfig",
3
+ "compilerOptions": {
4
+ "declaration": true,
5
+ "outDir": "../dist/types",
6
+ "emitDeclarationOnly": true
7
+ }
8
+
9
+
10
+ }
package/src/dev.ts CHANGED
@@ -1,47 +1,47 @@
1
- import '@babylonjs/core';
2
- import { Event } from 'api/classes/event';
3
- import { set } from 'lodash-es';
4
-
5
- import { Emitter, Viewer } from '.';
6
-
7
- /**
8
- * (i) HERE YOU @TODO (1) ADJUST THE CURRENT DEMO YOU ARE WORKING ON.
9
- */
10
- import { createSpec, beforeBootstrap, afterBootstrap, createUIelements } from '../assets/hulahoop/main';
11
- const loadingElement = document.getElementById( 'loading' ) as HTMLDivElement;
12
-
13
- Emitter.on( Event.BOOTSTRAP_START, () => {
14
- Emitter.on( Event.LOADING_START, () => {
15
- loadingElement!.style.display = 'block';
16
- } );
17
- Emitter.on( Event.VARIANT_CREATED, () => {
18
- loadingElement!.style.display = 'none';
19
- } );
20
- } );
21
-
22
- document.addEventListener('DOMContentLoaded', main );
23
-
24
- async function main() {
25
- const viewer = await bootstrapViewer();
26
- // "Export" for console testing...
27
- set( window, 'viewerInstance', viewer);
28
- }
29
-
30
- async function bootstrapViewer() {
31
- const canvas = document.getElementById( 'babylon-canvas' ) as HTMLCanvasElement;
32
- if( !canvas ) {
33
- throw new Error( 'Missing "canvas" element' );
34
- }
35
- const viewer = new Viewer(canvas, createSpec());
36
- await beforeBootstrap(viewer);
37
- try {
38
- await viewer.bootstrap();
39
- } catch (e) {
40
- console.error(e);
41
- }
42
- await afterBootstrap( viewer );
43
- await createUIelements( viewer );
44
- console.info( ' --- UI Initialized ---');
45
-
46
- return viewer;
1
+ import '@babylonjs/core';
2
+ import { Event } from 'api/classes/event';
3
+ import { set } from 'lodash-es';
4
+
5
+ import { Emitter, Viewer } from '.';
6
+
7
+ /**
8
+ * (i) HERE YOU @TODO (1) ADJUST THE CURRENT DEMO YOU ARE WORKING ON.
9
+ */
10
+ import { createSpec, beforeBootstrap, afterBootstrap, createUIelements } from '../assets/hulahoop/main';
11
+ const loadingElement = document.getElementById( 'loading' ) as HTMLDivElement;
12
+
13
+ Emitter.on( Event.BOOTSTRAP_START, () => {
14
+ Emitter.on( Event.LOADING_START, () => {
15
+ loadingElement!.style.display = 'block';
16
+ } );
17
+ Emitter.on( Event.VARIANT_CREATED, () => {
18
+ loadingElement!.style.display = 'none';
19
+ } );
20
+ } );
21
+
22
+ document.addEventListener('DOMContentLoaded', main );
23
+
24
+ async function main() {
25
+ const viewer = await bootstrapViewer();
26
+ // "Export" for console testing...
27
+ set( window, 'viewerInstance', viewer);
28
+ }
29
+
30
+ async function bootstrapViewer() {
31
+ const canvas = document.getElementById( 'babylon-canvas' ) as HTMLCanvasElement;
32
+ if( !canvas ) {
33
+ throw new Error( 'Missing "canvas" element' );
34
+ }
35
+ const viewer = new Viewer(canvas, createSpec());
36
+ await beforeBootstrap(viewer);
37
+ try {
38
+ await viewer.bootstrap();
39
+ } catch (e) {
40
+ console.error(e);
41
+ }
42
+ await afterBootstrap( viewer );
43
+ await createUIelements( viewer );
44
+ console.info( ' --- UI Initialized ---');
45
+
46
+ return viewer;
47
47
  }
@@ -1,13 +1,13 @@
1
- {
2
- "extends": "./tsconfig",
3
- "exclude": [
4
- "dev.ts",
5
- "assets"
6
- ],
7
- "compilerOptions": {
8
- "module": "es6",
9
- "moduleResolution": "node",
10
- "outDir": "../dist/lib-es6",
11
- "declaration": true
12
- }
13
- }
1
+ {
2
+ "extends": "./tsconfig",
3
+ "exclude": [
4
+ "dev.ts",
5
+ "assets"
6
+ ],
7
+ "compilerOptions": {
8
+ "module": "es6",
9
+ "moduleResolution": "node",
10
+ "outDir": "../dist/lib-es6",
11
+ "declaration": true
12
+ }
13
+ }