@combeenation/3d-viewer 5.0.1 → 5.0.3-beta2

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 (109) hide show
  1. package/README.md +111 -114
  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 +187 -187
  6. package/dist/lib-cjs/api/classes/element.d.ts +139 -139
  7. package/dist/lib-cjs/api/classes/element.js +794 -794
  8. package/dist/lib-cjs/api/classes/element.js.map +1 -1
  9. package/dist/lib-cjs/api/classes/elementParameterizable.d.ts +14 -0
  10. package/dist/lib-cjs/api/classes/elementParameterizable.js +135 -0
  11. package/dist/lib-cjs/api/classes/elementParameterizable.js.map +1 -0
  12. package/dist/lib-cjs/api/classes/event.d.ts +326 -326
  13. package/dist/lib-cjs/api/classes/event.js +371 -371
  14. package/dist/lib-cjs/api/classes/eventBroadcaster.d.ts +26 -26
  15. package/dist/lib-cjs/api/classes/eventBroadcaster.js +53 -53
  16. package/dist/lib-cjs/api/classes/parameter.d.ts +316 -259
  17. package/dist/lib-cjs/api/classes/parameter.js +451 -388
  18. package/dist/lib-cjs/api/classes/parameter.js.map +1 -1
  19. package/dist/lib-cjs/api/classes/parameterObservable.d.ts +36 -36
  20. package/dist/lib-cjs/api/classes/parameterObservable.js +101 -101
  21. package/dist/lib-cjs/api/classes/parameterizable.d.ts +15 -15
  22. package/dist/lib-cjs/api/classes/parameterizable.js +149 -149
  23. package/dist/lib-cjs/api/classes/placementAnimation.d.ts +44 -44
  24. package/dist/lib-cjs/api/classes/placementAnimation.js +163 -163
  25. package/dist/lib-cjs/api/classes/variant.d.ts +234 -234
  26. package/dist/lib-cjs/api/classes/variant.js +1154 -1154
  27. package/dist/lib-cjs/api/classes/variantInstance.d.ts +45 -45
  28. package/dist/lib-cjs/api/classes/variantInstance.js +108 -108
  29. package/dist/lib-cjs/api/classes/variantParameterizable.d.ts +17 -17
  30. package/dist/lib-cjs/api/classes/variantParameterizable.js +99 -99
  31. package/dist/lib-cjs/api/classes/viewer.d.ts +177 -175
  32. package/dist/lib-cjs/api/classes/viewer.js +717 -701
  33. package/dist/lib-cjs/api/classes/viewer.js.map +1 -1
  34. package/dist/lib-cjs/api/classes/viewerLight.d.ts +66 -66
  35. package/dist/lib-cjs/api/classes/viewerLight.js +392 -392
  36. package/dist/lib-cjs/api/internal/debugViewer.d.ts +13 -13
  37. package/dist/lib-cjs/api/internal/debugViewer.js +86 -86
  38. package/dist/lib-cjs/api/internal/lensRendering.d.ts +8 -8
  39. package/dist/lib-cjs/api/internal/lensRendering.js +11 -11
  40. package/dist/lib-cjs/api/internal/sceneSetup.d.ts +13 -10
  41. package/dist/lib-cjs/api/internal/sceneSetup.js +238 -234
  42. package/dist/lib-cjs/api/internal/sceneSetup.js.map +1 -1
  43. package/dist/lib-cjs/api/manager/animationManager.d.ts +29 -29
  44. package/dist/lib-cjs/api/manager/animationManager.js +130 -130
  45. package/dist/lib-cjs/api/manager/gltfExportManager.d.ts +65 -65
  46. package/dist/lib-cjs/api/manager/gltfExportManager.js +223 -222
  47. package/dist/lib-cjs/api/manager/gltfExportManager.js.map +1 -1
  48. package/dist/lib-cjs/api/manager/sceneManager.d.ts +31 -32
  49. package/dist/lib-cjs/api/manager/sceneManager.js +153 -132
  50. package/dist/lib-cjs/api/manager/sceneManager.js.map +1 -1
  51. package/dist/lib-cjs/api/manager/variantInstanceManager.d.ts +92 -92
  52. package/dist/lib-cjs/api/manager/variantInstanceManager.js +335 -335
  53. package/dist/lib-cjs/api/store/specStorage.d.ts +24 -24
  54. package/dist/lib-cjs/api/store/specStorage.js +51 -51
  55. package/dist/lib-cjs/api/util/babylonHelper.d.ts +174 -166
  56. package/dist/lib-cjs/api/util/babylonHelper.js +575 -497
  57. package/dist/lib-cjs/api/util/babylonHelper.js.map +1 -1
  58. package/dist/lib-cjs/api/util/globalTypes.d.ts +366 -356
  59. package/dist/lib-cjs/api/util/globalTypes.js +1 -1
  60. package/dist/lib-cjs/api/util/resourceHelper.d.ts +58 -53
  61. package/dist/lib-cjs/api/util/resourceHelper.js +257 -242
  62. package/dist/lib-cjs/api/util/resourceHelper.js.map +1 -1
  63. package/dist/lib-cjs/api/util/stringHelper.d.ts +9 -9
  64. package/dist/lib-cjs/api/util/stringHelper.js +25 -25
  65. package/dist/lib-cjs/api/util/structureHelper.d.ts +9 -9
  66. package/dist/lib-cjs/api/util/structureHelper.js +48 -44
  67. package/dist/lib-cjs/api/util/structureHelper.js.map +1 -1
  68. package/dist/lib-cjs/buildinfo.json +3 -3
  69. package/dist/lib-cjs/index.d.ts +49 -49
  70. package/dist/lib-cjs/index.js +89 -89
  71. package/dist/webpack-stats.json +0 -0
  72. package/package.json +87 -87
  73. package/src/api/classes/animationInterface.ts +10 -10
  74. package/src/api/classes/dottedPath.ts +181 -181
  75. package/src/api/classes/element.ts +690 -692
  76. package/src/api/classes/event.ts +367 -367
  77. package/src/api/classes/eventBroadcaster.ts +52 -52
  78. package/src/api/classes/parameter.ts +474 -405
  79. package/src/api/classes/parameterObservable.ts +100 -100
  80. package/src/api/classes/parameterizable.ts +87 -87
  81. package/src/api/classes/placementAnimation.ts +160 -160
  82. package/src/api/classes/variant.ts +845 -845
  83. package/src/api/classes/variantInstance.ts +97 -97
  84. package/src/api/classes/variantParameterizable.ts +85 -85
  85. package/src/api/classes/viewer.ts +650 -624
  86. package/src/api/classes/viewerLight.ts +334 -334
  87. package/src/api/internal/debugViewer.ts +90 -90
  88. package/src/api/internal/lensRendering.ts +10 -10
  89. package/src/api/internal/sceneSetup.ts +204 -201
  90. package/src/api/manager/animationManager.ts +142 -142
  91. package/src/api/manager/gltfExportManager.ts +191 -191
  92. package/src/api/manager/sceneManager.ts +128 -102
  93. package/src/api/manager/variantInstanceManager.ts +265 -265
  94. package/src/api/store/specStorage.ts +51 -51
  95. package/src/api/util/babylonHelper.ts +628 -538
  96. package/src/api/util/globalTypes.ts +413 -402
  97. package/src/api/util/resourceHelper.ts +189 -173
  98. package/src/api/util/stringHelper.ts +23 -23
  99. package/src/api/util/structureHelper.ts +49 -43
  100. package/src/buildinfo.json +3 -3
  101. package/src/commonjs.tsconfig.json +10 -10
  102. package/src/declaration.tsconfig.json +8 -8
  103. package/src/dev.ts +42 -42
  104. package/src/es6.tsconfig.json +10 -10
  105. package/src/index.ts +94 -94
  106. package/src/pagesconfig.json +77 -73
  107. package/src/tsconfig.json +32 -32
  108. package/src/tsconfig.types.json +9 -9
  109. package/src/types.d.ts +3 -3
@@ -1,173 +1,189 @@
1
- import { emitter, Event } from '../classes/event';
2
-
3
- /**
4
- * Sleeps for a certain amount of microseconds.
5
- */
6
- const sleep = (ms: number) => new Promise(resolve => window.setTimeout(resolve, ms));
7
-
8
- /**
9
- * Loads any kind of response from given path.
10
- * @emits {@link Event.LOADING_START}
11
- * @emits {@link Event.LOADING_END}
12
- */
13
- const load = async function (path: string): Promise<Response> {
14
- emitter.emit(Event.LOADING_START, path);
15
- let data = await fetch(path);
16
- emitter.emit(Event.LOADING_END, path);
17
- return data;
18
- };
19
-
20
- /**
21
- * Loads a JSON from a given path.
22
- * @emits {@link Event.LOADING_START}
23
- * @emits {@link Event.LOADING_END}
24
- */
25
- const loadJson = async function <T>(path: string): Promise<T> {
26
- const response = await load(path);
27
- return response.json();
28
- };
29
-
30
- /**
31
- * Loads a Text from a given path.
32
- * @emits {@link Event.LOADING_START}
33
- * @emits {@link Event.LOADING_END}
34
- */
35
- const loadText = async function (path: string): Promise<string> {
36
- const response = await load(path);
37
- return response.text();
38
- };
39
-
40
- /**
41
- * Debounces: it limits the rate at which a function can fire.
42
- */
43
- const debounce = function (func: Function, wait: number, immediate: boolean = false) {
44
- let timeout: any;
45
- return function () {
46
- // @ts-ignore
47
- const context = this;
48
- const args = arguments;
49
- const later = function () {
50
- timeout = null;
51
- if (!immediate) {
52
- func.apply(context, args);
53
- }
54
- };
55
- const callNow = immediate && !timeout;
56
- clearTimeout(timeout);
57
- timeout = setTimeout(later, wait);
58
- if (callNow) {
59
- func.apply(context, args);
60
- }
61
- };
62
- };
63
-
64
- /**
65
- * Merges multiple maps.
66
- */
67
- const mergeMaps = function <TKey, TValue>(...maps: Map<TKey, TValue>[]): Map<TKey, TValue> {
68
- const resultMap = new Map<TKey, TValue>();
69
- maps.forEach(map => {
70
- map.forEach((v, k) => {
71
- resultMap.set(k, v);
72
- });
73
- });
74
- return resultMap;
75
- };
76
-
77
- /**
78
- * Creates a HTML image element based on a SVG string, whereas all the embedded assets in the SVG (eg: fonts, images)
79
- * are already loaded and exchanged by their base64 representation.\
80
- * There the output image can exist as "standalone" image and may be used for example as a paintable.
81
- *
82
- * !!CAUTION!!: The used functions within this code section are very well evaluated since most alternatives
83
- * somehow don't work in Safari, as mentioned in the following BJS forum entries:
84
- * - https://forum.babylonjs.com/t/drawing-svg-content-text-into-dynamictexture-doesnt-work-in-safari-v15/25048
85
- * - https://forum.babylonjs.com/t/texture-createfrombase64string-doesnt-seem-to-work-for-ios-devices-initially/25502
86
- */
87
- const createImageFromSvg = async function (svgSrc: string): Promise<HTMLImageElement> {
88
- // replace assets with their base64 versions in svg source code
89
- const svgWithAssetsEmbedded = await _embedAssets(svgSrc);
90
-
91
- // create data string which can be used as an image source
92
- const svgEncoded = 'data:image/svg+xml,' + encodeURIComponent(svgWithAssetsEmbedded);
93
-
94
- return createImageFromImgSrc(svgEncoded);
95
- };
96
-
97
- /**
98
- * Creates an HTML image element from a dedicated image source.\
99
- * Also waits until the image has loaded.
100
- *
101
- * !!CAUTION!!: The `setTimeout` after loading is finished is required due to a Safari bug:
102
- * - https://bugs.webkit.org/show_bug.cgi?id=39059
103
- * - https://bugs.webkit.org/show_bug.cgi?id=219770
104
- *
105
- * It's not 100% ensured that the timeout solves the issue in every case, but there is no other way unfortunately.\
106
- * => Keep an eye on it in future projects
107
- *
108
- * @param imgSrc Theoretically every source is valid which is also supported by
109
- * [HTMLImageElement.src](https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/src).\
110
- * Known exceptions are SVGs with embedded assets that are provided as object URL. See comments in
111
- * {@link createImageFromSvg} for further details.
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(url =>
137
- _assetExtensions.some(extension => url.toLowerCase().endsWith(`.${extension}`))
138
- );
139
- const assetBase64Fetcher = assetUrls.map(_fetchBase64AssetUrl);
140
- const assetFetcherResults = await Promise.all(assetBase64Fetcher);
141
- return assetFetcherResults.reduce((svgSrc, x) => svgSrc.replace(x.url, x.base64), svgSrc);
142
- };
143
-
144
- /**
145
- * Fetch asset (image or font) and convert it to base64 string representation.
146
- */
147
- const _fetchBase64AssetUrl = async function (assetUrl: string): Promise<{ url: string; base64: string }> {
148
- // TODO: Cache known base64 representation and only fetch/convert when not already known.
149
- // Usually the fetch shouldn't hit the network but the browser cache since the SVG was already drawn.
150
- // See comments of "createImageBitmapFromSvg" for some considerations...
151
- return new Promise(async (resolve, reject) => {
152
- const resp = await fetch(assetUrl);
153
- const blob = await resp.blob();
154
- const reader = new FileReader();
155
- reader.onloadend = event => {
156
- const target = event.target;
157
- if (!target) {
158
- return reject(`Asset with URL "${assetUrl}" could not be loaded.`);
159
- }
160
- const result = target.result;
161
- if (!result) {
162
- return reject(`Asset with URL "${assetUrl}" returned an empty result.`);
163
- }
164
- resolve({
165
- url: assetUrl,
166
- base64: result.toString() as string,
167
- });
168
- };
169
- reader.readAsDataURL(blob);
170
- });
171
- };
172
-
173
- export { sleep, loadJson, loadText, debounce, mergeMaps, createImageFromSvg, createImageFromImgSrc };
1
+ import { emitter, Event } from '../classes/event';
2
+
3
+ /**
4
+ * Sleeps for a certain amount of microseconds.
5
+ */
6
+ const sleep = (ms: number) => new Promise(resolve => window.setTimeout(resolve, ms));
7
+
8
+ /**
9
+ * Loads any kind of response from given path.
10
+ * @emits {@link Event.LOADING_START}
11
+ * @emits {@link Event.LOADING_END}
12
+ */
13
+ const load = async function (path: string): Promise<Response> {
14
+ emitter.emit(Event.LOADING_START, path);
15
+ let data = await fetch(path);
16
+ emitter.emit(Event.LOADING_END, path);
17
+ return data;
18
+ };
19
+
20
+ /**
21
+ * Loads a JSON from a given path.
22
+ * @emits {@link Event.LOADING_START}
23
+ * @emits {@link Event.LOADING_END}
24
+ */
25
+ const loadJson = async function <T>(path: string): Promise<T> {
26
+ const response = await load(path);
27
+ return response.json();
28
+ };
29
+
30
+ /**
31
+ * Loads a Text from a given path.
32
+ * @emits {@link Event.LOADING_START}
33
+ * @emits {@link Event.LOADING_END}
34
+ */
35
+ const loadText = async function (path: string): Promise<string> {
36
+ const response = await load(path);
37
+ return response.text();
38
+ };
39
+
40
+ /**
41
+ * Loads a Javascript ressource.\
42
+ * Usefull for including packages via CDN (eg: BabylonJS Inspector)
43
+ */
44
+ const loadJavascript = (url: string): Promise<void> =>
45
+ new Promise(resolve => {
46
+ const scriptEl = document.createElement('script');
47
+
48
+ scriptEl.setAttribute('src', url);
49
+ scriptEl.setAttribute('type', 'text/javascript');
50
+ scriptEl.setAttribute('crossorigin', 'anonymous');
51
+ scriptEl.onload = () => resolve();
52
+
53
+ document.head.appendChild(scriptEl);
54
+ });
55
+
56
+ /**
57
+ * Debounces: it limits the rate at which a function can fire.
58
+ */
59
+ const debounce = function (func: Function, wait: number, immediate: boolean = false) {
60
+ let timeout: any;
61
+ return function () {
62
+ // @ts-ignore
63
+ const context = this;
64
+ const args = arguments;
65
+ const later = function () {
66
+ timeout = null;
67
+ if (!immediate) {
68
+ func.apply(context, args);
69
+ }
70
+ };
71
+ const callNow = immediate && !timeout;
72
+ clearTimeout(timeout);
73
+ timeout = setTimeout(later, wait);
74
+ if (callNow) {
75
+ func.apply(context, args);
76
+ }
77
+ };
78
+ };
79
+
80
+ /**
81
+ * Merges multiple maps.
82
+ */
83
+ const mergeMaps = function <TKey, TValue>(...maps: Map<TKey, TValue>[]): Map<TKey, TValue> {
84
+ const resultMap = new Map<TKey, TValue>();
85
+ maps.forEach(map => {
86
+ map.forEach((v, k) => {
87
+ resultMap.set(k, v);
88
+ });
89
+ });
90
+ return resultMap;
91
+ };
92
+
93
+ /**
94
+ * Creates a HTML image element based on a SVG string, whereas all the embedded assets in the SVG (eg: fonts, images)
95
+ * are already loaded and exchanged by their base64 representation.\
96
+ * There the output image can exist as "standalone" image and may be used for example as a paintable.
97
+ *
98
+ * !!CAUTION!!: The used functions within this code section are very well evaluated since most alternatives
99
+ * somehow don't work in Safari, as mentioned in the following BJS forum entries:
100
+ * - https://forum.babylonjs.com/t/drawing-svg-content-text-into-dynamictexture-doesnt-work-in-safari-v15/25048
101
+ * - https://forum.babylonjs.com/t/texture-createfrombase64string-doesnt-seem-to-work-for-ios-devices-initially/25502
102
+ */
103
+ const createImageFromSvg = async function (svgSrc: string): Promise<HTMLImageElement> {
104
+ // replace assets with their base64 versions in svg source code
105
+ const svgWithAssetsEmbedded = await _embedAssets(svgSrc);
106
+
107
+ // create data string which can be used as an image source
108
+ const svgEncoded = 'data:image/svg+xml,' + encodeURIComponent(svgWithAssetsEmbedded);
109
+
110
+ return createImageFromImgSrc(svgEncoded);
111
+ };
112
+
113
+ /**
114
+ * Creates an HTML image element from a dedicated image source.\
115
+ * Also waits until the image has loaded.
116
+ *
117
+ * !!CAUTION!!: The `setTimeout` after loading is finished is required due to a Safari bug:
118
+ * - https://bugs.webkit.org/show_bug.cgi?id=39059
119
+ * - https://bugs.webkit.org/show_bug.cgi?id=219770
120
+ *
121
+ * It's not 100% ensured that the timeout solves the issue in every case, but there is no other way unfortunately.\
122
+ * => Keep an eye on it in future projects
123
+ *
124
+ * @param imgSrc Theoretically every source is valid which is also supported by
125
+ * [HTMLImageElement.src](https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/src).\
126
+ * Known exceptions are SVGs with embedded assets that are provided as object URL. See comments in
127
+ * {@link createImageFromSvg} for further details.
128
+ */
129
+ const createImageFromImgSrc = async function (imgSrc: string): Promise<HTMLImageElement> {
130
+ let img = new Image();
131
+
132
+ await new Promise(resolve => {
133
+ img.onload = () => {
134
+ setTimeout(resolve, 0);
135
+ };
136
+ img.src = imgSrc;
137
+ });
138
+
139
+ return img;
140
+ };
141
+
142
+ /**
143
+ * Replaces all supported image & font URLs in the given SVG with their base64 representation.
144
+ */
145
+ const _embedAssets = async function (svgSrc: string): Promise<string> {
146
+ const _imageExtensions = ['png', 'gif', 'jpg', 'jpeg', 'svg', 'bmp'];
147
+ const _fontExtensions = ['woff2', 'woff', 'ttf', 'otf'];
148
+ const _assetExtensions = [..._imageExtensions, ..._fontExtensions];
149
+ // Regex copied from https://stackoverflow.com/a/8943487/1273551, not "stress tested"...
150
+ const urlRegex = /(\bhttps?:\/\/[-A-Z0-9+&@#/%?=~_|!:,.;]*[-A-Z0-9+&@#/%=~_|])/gi;
151
+ const allUrls = svgSrc.match(urlRegex) as string[];
152
+ const assetUrls = allUrls.filter(url =>
153
+ _assetExtensions.some(extension => url.toLowerCase().endsWith(`.${extension}`))
154
+ );
155
+ const assetBase64Fetcher = assetUrls.map(_fetchBase64AssetUrl);
156
+ const assetFetcherResults = await Promise.all(assetBase64Fetcher);
157
+ return assetFetcherResults.reduce((svgSrc, x) => svgSrc.replace(x.url, x.base64), svgSrc);
158
+ };
159
+
160
+ /**
161
+ * Fetch asset (image or font) and convert it to base64 string representation.
162
+ */
163
+ const _fetchBase64AssetUrl = async function (assetUrl: string): Promise<{ url: string; base64: string }> {
164
+ // TODO: Cache known base64 representation and only fetch/convert when not already known.
165
+ // Usually the fetch shouldn't hit the network but the browser cache since the SVG was already drawn.
166
+ // See comments of "createImageBitmapFromSvg" for some considerations...
167
+ return new Promise(async (resolve, reject) => {
168
+ const resp = await fetch(assetUrl);
169
+ const blob = await resp.blob();
170
+ const reader = new FileReader();
171
+ reader.onloadend = event => {
172
+ const target = event.target;
173
+ if (!target) {
174
+ return reject(`Asset with URL "${assetUrl}" could not be loaded.`);
175
+ }
176
+ const result = target.result;
177
+ if (!result) {
178
+ return reject(`Asset with URL "${assetUrl}" returned an empty result.`);
179
+ }
180
+ resolve({
181
+ url: assetUrl,
182
+ base64: result.toString() as string,
183
+ });
184
+ };
185
+ reader.readAsDataURL(blob);
186
+ });
187
+ };
188
+
189
+ export { sleep, loadJson, loadText, loadJavascript, debounce, mergeMaps, createImageFromSvg, createImageFromImgSrc };
@@ -1,23 +1,23 @@
1
- /**
2
- * Creates a random uuidv4.
3
- */
4
- const uuidv4 = function () {
5
- // @ts-ignore
6
- return ([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, c =>
7
- (c ^ (crypto.getRandomValues(new Uint8Array(1))[0] & (15 >> (c / 4)))).toString(16)
8
- );
9
- };
10
-
11
- /**
12
- * Converts a string from camel case to snake case.
13
- */
14
- const camelToSnakeCase = function (str: string): string {
15
- return str
16
- .replace(/([A-Z])/g, ' $1')
17
- .trim()
18
- .split(' ')
19
- .join('_')
20
- .toLowerCase();
21
- };
22
-
23
- export { uuidv4, camelToSnakeCase };
1
+ /**
2
+ * Creates a random uuidv4.
3
+ */
4
+ const uuidv4 = function () {
5
+ // @ts-ignore
6
+ return ([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, c =>
7
+ (c ^ (crypto.getRandomValues(new Uint8Array(1))[0] & (15 >> (c / 4)))).toString(16)
8
+ );
9
+ };
10
+
11
+ /**
12
+ * Converts a string from camel case to snake case.
13
+ */
14
+ const camelToSnakeCase = function (str: string): string {
15
+ return str
16
+ .replace(/([A-Z])/g, ' $1')
17
+ .trim()
18
+ .split(' ')
19
+ .join('_')
20
+ .toLowerCase();
21
+ };
22
+
23
+ export { uuidv4, camelToSnakeCase };
@@ -1,43 +1,49 @@
1
- import { Mesh } from '@babylonjs/core/Meshes/mesh';
2
- import { Variant } from '../classes/variant';
3
- import { VariantInstance } from '../classes/variantInstance';
4
- import { Element } from '../classes/element';
5
-
6
- /**
7
- * Find out if a mesh is part of a list of excluded geometry
8
- * @param mesh BJS mesh
9
- * @param list list of excluded geometry
10
- * @returns boolean based on whether mesh was found in list
11
- */
12
- const isMeshIncludedInExclusionList = function (mesh: Mesh, list: ExcludedGeometry): boolean {
13
- const checkMesh = (inputMesh: Mesh, meshToCheck: Mesh) => {
14
- return inputMesh.uniqueId === meshToCheck.uniqueId;
15
- };
16
- const checkElement = (inputEl: Element, meshToCheck: Mesh) => {
17
- return inputEl.meshesFlat.some(m => checkMesh(m, meshToCheck));
18
- };
19
- const checkVariant = (inputVariant: Variant, meshToCheck: Mesh) => {
20
- return inputVariant.elements.some(el => checkElement(el, meshToCheck));
21
- };
22
- const checkVariantInstance = (inputVarInst: VariantInstance, meshToCheck: Mesh) => {
23
- return inputVarInst.variant.elements.some(el => checkElement(el, meshToCheck));
24
- };
25
- const isExcluded = list.some(geometryToExclude => {
26
- if (geometryToExclude instanceof VariantInstance) {
27
- return checkVariantInstance(geometryToExclude, mesh);
28
- }
29
- if (geometryToExclude instanceof Variant) {
30
- return checkVariant(geometryToExclude, mesh);
31
- }
32
- if (geometryToExclude instanceof Element) {
33
- return checkElement(geometryToExclude, mesh);
34
- }
35
- if (geometryToExclude instanceof Mesh) {
36
- return checkMesh(geometryToExclude, mesh);
37
- }
38
- return false;
39
- });
40
- return isExcluded;
41
- };
42
-
43
- export { isMeshIncludedInExclusionList };
1
+ import { Mesh } from '@babylonjs/core/Meshes/mesh';
2
+ import { Variant } from '../classes/variant';
3
+ import { VariantInstance } from '../classes/variantInstance';
4
+ import { Element } from '../classes/element';
5
+
6
+ /**
7
+ * Find out if a mesh is part of a list of excluded geometry
8
+ * @param mesh BJS mesh
9
+ * @param list list of excluded geometry
10
+ * @returns boolean based on whether mesh (or one of its parents) was found in list
11
+ */
12
+ const isMeshIncludedInExclusionList = function (mesh: Mesh, list: ExcludedGeometryList): boolean {
13
+ const checkMesh = (inputMesh: Mesh, meshToCheck: Mesh) => {
14
+ return inputMesh.uniqueId === meshToCheck.uniqueId;
15
+ };
16
+ const checkElement = (inputEl: Element, meshToCheck: Mesh) => {
17
+ return inputEl.meshesFlat.some(m => checkMesh(m, meshToCheck));
18
+ };
19
+ const checkVariant = (inputVariant: Variant, meshToCheck: Mesh) => {
20
+ return inputVariant.elements.some(el => checkElement(el, meshToCheck));
21
+ };
22
+ const checkVariantInstance = (inputVarInst: VariantInstance, meshToCheck: Mesh) => {
23
+ return inputVarInst.variant.elements.some(el => checkElement(el, meshToCheck));
24
+ };
25
+ const check = (geometryToExclude: ExcludedGeometry, mesh: Mesh) => {
26
+ if (geometryToExclude instanceof VariantInstance) {
27
+ return checkVariantInstance(geometryToExclude, mesh);
28
+ }
29
+ if (geometryToExclude instanceof Variant) {
30
+ return checkVariant(geometryToExclude, mesh);
31
+ }
32
+ if (geometryToExclude instanceof Element) {
33
+ return checkElement(geometryToExclude, mesh);
34
+ }
35
+ if (geometryToExclude instanceof Mesh) {
36
+ return checkMesh(geometryToExclude, mesh);
37
+ }
38
+ return false;
39
+ };
40
+
41
+ let isExcluded = list.some(geometryToExclude => check(geometryToExclude, mesh));
42
+ if (!isExcluded && mesh.parent instanceof Mesh) {
43
+ isExcluded = isMeshIncludedInExclusionList(mesh.parent, list);
44
+ }
45
+
46
+ return isExcluded;
47
+ };
48
+
49
+ export { isMeshIncludedInExclusionList };
@@ -1,3 +1,3 @@
1
- {
2
- "version": "@VERSION@"
3
- }
1
+ {
2
+ "version": "@VERSION@"
3
+ }
@@ -1,10 +1,10 @@
1
- {
2
- "extends": "./tsconfig",
3
- "exclude": ["dev.ts", "assets"],
4
- "compilerOptions": {
5
- "module": "commonjs",
6
- "moduleResolution": "node",
7
- "outDir": "../dist/lib-cjs",
8
- "declaration": true
9
- }
10
- }
1
+ {
2
+ "extends": "./tsconfig",
3
+ "exclude": ["dev.ts", "assets"],
4
+ "compilerOptions": {
5
+ "module": "commonjs",
6
+ "moduleResolution": "node",
7
+ "outDir": "../dist/lib-cjs",
8
+ "declaration": true
9
+ }
10
+ }
@@ -1,8 +1,8 @@
1
- {
2
- "extends": "./tsconfig",
3
- "compilerOptions": {
4
- "declaration": true,
5
- "outDir": "../dist/types",
6
- "emitDeclarationOnly": true
7
- }
8
- }
1
+ {
2
+ "extends": "./tsconfig",
3
+ "compilerOptions": {
4
+ "declaration": true,
5
+ "outDir": "../dist/types",
6
+ "emitDeclarationOnly": true
7
+ }
8
+ }
package/src/dev.ts CHANGED
@@ -1,42 +1,42 @@
1
- import { Event } from 'api/classes/event';
2
- import { set } from 'lodash-es';
3
-
4
- import { Emitter, Viewer } from '.';
5
-
6
- import { createSpec, beforeBootstrap, afterBootstrap, createUIelements } from '../assets/index';
7
-
8
- const loadingElement = document.getElementById('loading') as HTMLDivElement;
9
-
10
- Emitter.on(Event.BOOTSTRAP_START, () => {
11
- Emitter.on(Event.LOADING_START, () => {
12
- loadingElement!.style.display = 'block';
13
- });
14
- Emitter.on(Event.VARIANT_CREATED, () => {
15
- loadingElement!.style.display = 'none';
16
- });
17
- });
18
-
19
- document.addEventListener('DOMContentLoaded', main);
20
-
21
- async function main() {
22
- const viewer = await bootstrapViewer();
23
- // "Export" for console testing...
24
- set(window, 'viewer', viewer);
25
- }
26
-
27
- async function bootstrapViewer() {
28
- const canvas = document.getElementById('babylon-canvas') as HTMLCanvasElement;
29
- if (!canvas) {
30
- throw new Error('Missing "canvas" element');
31
- }
32
- const viewer = new Viewer(canvas, createSpec());
33
- await beforeBootstrap(viewer);
34
- try {
35
- await viewer.bootstrap();
36
- } catch (e) {
37
- console.error(e);
38
- }
39
- await afterBootstrap(viewer);
40
- await createUIelements(viewer);
41
- return viewer;
42
- }
1
+ import { Event } from 'api/classes/event';
2
+ import { set } from 'lodash-es';
3
+
4
+ import { Emitter, Viewer } from '.';
5
+
6
+ import { createSpec, beforeBootstrap, afterBootstrap, createUIelements } from '../assets/index';
7
+
8
+ const loadingElement = document.getElementById('loading') as HTMLDivElement;
9
+
10
+ Emitter.on(Event.BOOTSTRAP_START, () => {
11
+ Emitter.on(Event.LOADING_START, () => {
12
+ loadingElement!.style.display = 'block';
13
+ });
14
+ Emitter.on(Event.VARIANT_CREATED, () => {
15
+ loadingElement!.style.display = 'none';
16
+ });
17
+ });
18
+
19
+ document.addEventListener('DOMContentLoaded', main);
20
+
21
+ async function main() {
22
+ const viewer = await bootstrapViewer();
23
+ // "Export" for console testing...
24
+ set(window, 'viewer', viewer);
25
+ }
26
+
27
+ async function bootstrapViewer() {
28
+ const canvas = document.getElementById('babylon-canvas') as HTMLCanvasElement;
29
+ if (!canvas) {
30
+ throw new Error('Missing "canvas" element');
31
+ }
32
+ const viewer = new Viewer(canvas, createSpec());
33
+ await beforeBootstrap(viewer);
34
+ try {
35
+ await viewer.bootstrap();
36
+ } catch (e) {
37
+ console.error(e);
38
+ }
39
+ await afterBootstrap(viewer);
40
+ await createUIelements(viewer);
41
+ return viewer;
42
+ }