@combeenation/3d-viewer 5.0.2-beta1 → 5.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@combeenation/3d-viewer",
3
3
  "description": "Combeenation 3D Viewer",
4
- "version": "5.0.2-beta1",
4
+ "version": "5.0.2",
5
5
  "homepage": "https://github.com/Combeenation/3d-viewer#readme",
6
6
  "keywords": [],
7
7
  "author": "",
@@ -43,10 +43,10 @@
43
43
  "format": "prettier --write ."
44
44
  },
45
45
  "dependencies": {
46
- "@babylonjs/core": "^5.6.0",
47
- "@babylonjs/inspector": "5.6.0",
46
+ "@babylonjs/core": "5.6.0",
48
47
  "@babylonjs/loaders": "5.6.0",
49
48
  "@babylonjs/materials": "5.6.0",
49
+ "@babylonjs/serializers": "5.6.0",
50
50
  "eventemitter3": "^4.0.0",
51
51
  "gsap": "^3.5.1",
52
52
  "lodash-es": "^4.17.15"
@@ -20,13 +20,14 @@ import { GltfExportManager } from '../manager/gltfExportManager';
20
20
  import { SceneManager } from '../manager/sceneManager';
21
21
  import { VariantInstanceManager } from '../manager/variantInstanceManager';
22
22
  import { SpecStorage } from '../store/specStorage';
23
- import { debounce, loadJson } from '../util/resourceHelper';
23
+ import { debounce, loadJavascript, loadJson } from '../util/resourceHelper';
24
24
  import { Event } from './event';
25
25
  import { EventBroadcaster } from './eventBroadcaster';
26
26
  import { Parameter } from './parameter';
27
27
  import { Variant } from './variant';
28
28
  import { VariantInstance } from './variantInstance';
29
29
  import { IPointerEvent } from '@babylonjs/core/Events/deviceInputEvents';
30
+ import { DebugLayer } from '@babylonjs/core/Debug/debugLayer';
30
31
 
31
32
  /**
32
33
  * The main exposed object. This is the entry point into the application
@@ -54,6 +55,8 @@ export class Viewer extends EventBroadcaster {
54
55
 
55
56
  protected _isRenderLoopPaused: boolean = false;
56
57
 
58
+ protected _inspectorLoaded: boolean = false;
59
+
57
60
  static version = version;
58
61
 
59
62
  /**
@@ -196,15 +199,20 @@ export class Viewer extends EventBroadcaster {
196
199
 
197
200
  /**
198
201
  * Enables the BabylonJS [Inspector](https://doc.babylonjs.com/toolsAndResources/tools/inspector).\
199
- * Due to the enormous additional package size of the inspector, this feature is only available in development builds.
202
+ * Due to the enormous additional package size of the inspector, the CDN version is used instead of the corresponding npm package.
200
203
  */
201
204
  public async enableDebugLayer(options?: IInspectorOptions) {
202
- if (process.env.NODE_ENV?.toLowerCase().includes('dev')) {
203
- await import(/* webpackChunkName: "debug-inspector" */ '@babylonjs/inspector');
204
- await this.scene.debugLayer.show(options);
205
- } else {
206
- console.warn('BabylonJS inspector is not supported in production builds!');
205
+ if (!this._inspectorLoaded) {
206
+ // CDN version of inspector requires the BabylonJS core to be available as CDN module as well
207
+ await loadJavascript('https://cdn.jsdelivr.net/npm/babylonjs@5.6.0/babylon.min.js');
208
+
209
+ DebugLayer.InspectorURL =
210
+ 'https://cdn.jsdelivr.net/npm/babylonjs-inspector@5.6.0/babylon.inspector.bundle.max.min.js';
211
+
212
+ this._inspectorLoaded = true;
207
213
  }
214
+
215
+ await this.scene.debugLayer.show(options);
208
216
  }
209
217
 
210
218
  /**
@@ -37,6 +37,22 @@ const loadText = async function (path: string): Promise<string> {
37
37
  return response.text();
38
38
  };
39
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
+
40
56
  /**
41
57
  * Debounces: it limits the rate at which a function can fire.
42
58
  */
@@ -170,4 +186,4 @@ const _fetchBase64AssetUrl = async function (assetUrl: string): Promise<{ url: s
170
186
  });
171
187
  };
172
188
 
173
- export { sleep, loadJson, loadText, debounce, mergeMaps, createImageFromSvg, createImageFromImgSrc };
189
+ export { sleep, loadJson, loadText, loadJavascript, debounce, mergeMaps, createImageFromSvg, createImageFromImgSrc };