@combeenation/3d-viewer 14.0.1-rc1 → 15.0.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.
Files changed (81) hide show
  1. package/README.md +9 -9
  2. package/dist/lib-cjs/buildinfo.json +3 -3
  3. package/dist/lib-cjs/commonjs.tsconfig.tsbuildinfo +1 -1
  4. package/dist/lib-cjs/index.d.ts +51 -62
  5. package/dist/lib-cjs/index.js +84 -94
  6. package/dist/lib-cjs/index.js.map +1 -1
  7. package/dist/lib-cjs/internal/cbn-custom-babylon-loader-plugin.d.ts +10 -10
  8. package/dist/lib-cjs/internal/cbn-custom-babylon-loader-plugin.js +131 -131
  9. package/dist/lib-cjs/internal/cbn-custom-babylon-loader-plugin.js.map +1 -1
  10. package/dist/lib-cjs/internal/cloning-helper.d.ts +19 -19
  11. package/dist/lib-cjs/internal/cloning-helper.js +163 -163
  12. package/dist/lib-cjs/internal/device-helper.d.ts +9 -9
  13. package/dist/lib-cjs/internal/device-helper.js +24 -24
  14. package/dist/lib-cjs/internal/geometry-helper.d.ts +21 -21
  15. package/dist/lib-cjs/internal/geometry-helper.js +145 -145
  16. package/dist/lib-cjs/internal/metadata-helper.d.ts +26 -26
  17. package/dist/lib-cjs/internal/metadata-helper.js +50 -50
  18. package/dist/lib-cjs/internal/paintable-helper.d.ts +40 -40
  19. package/dist/lib-cjs/internal/paintable-helper.js +234 -286
  20. package/dist/lib-cjs/internal/paintable-helper.js.map +1 -1
  21. package/dist/lib-cjs/internal/svg-helper.d.ts +4 -0
  22. package/dist/lib-cjs/internal/svg-helper.js +67 -0
  23. package/dist/lib-cjs/internal/svg-helper.js.map +1 -0
  24. package/dist/lib-cjs/internal/tags-helper.d.ts +12 -12
  25. package/dist/lib-cjs/internal/tags-helper.js +39 -37
  26. package/dist/lib-cjs/internal/tags-helper.js.map +1 -1
  27. package/dist/lib-cjs/internal/texture-parameter-helper.d.ts +37 -0
  28. package/dist/lib-cjs/internal/texture-parameter-helper.js +287 -0
  29. package/dist/lib-cjs/internal/texture-parameter-helper.js.map +1 -0
  30. package/dist/lib-cjs/manager/camera-manager.d.ts +110 -110
  31. package/dist/lib-cjs/manager/camera-manager.js +209 -206
  32. package/dist/lib-cjs/manager/camera-manager.js.map +1 -1
  33. package/dist/lib-cjs/manager/debug-manager.d.ts +60 -60
  34. package/dist/lib-cjs/manager/debug-manager.js +217 -217
  35. package/dist/lib-cjs/manager/event-manager.d.ts +52 -52
  36. package/dist/lib-cjs/manager/event-manager.js +71 -71
  37. package/dist/lib-cjs/manager/gltf-export-manager.d.ts +75 -84
  38. package/dist/lib-cjs/manager/gltf-export-manager.js +286 -290
  39. package/dist/lib-cjs/manager/gltf-export-manager.js.map +1 -1
  40. package/dist/lib-cjs/manager/material-manager.d.ts +35 -35
  41. package/dist/lib-cjs/manager/material-manager.js +125 -125
  42. package/dist/lib-cjs/manager/model-manager.d.ts +145 -145
  43. package/dist/lib-cjs/manager/model-manager.js +382 -382
  44. package/dist/lib-cjs/manager/parameter-manager.d.ts +228 -210
  45. package/dist/lib-cjs/manager/parameter-manager.js +573 -514
  46. package/dist/lib-cjs/manager/parameter-manager.js.map +1 -1
  47. package/dist/lib-cjs/manager/scene-manager.d.ts +45 -45
  48. package/dist/lib-cjs/manager/scene-manager.js +64 -64
  49. package/dist/lib-cjs/manager/texture-manager.d.ts +12 -12
  50. package/dist/lib-cjs/manager/texture-manager.js +43 -43
  51. package/dist/lib-cjs/viewer-error.d.ts +49 -48
  52. package/dist/lib-cjs/viewer-error.js +61 -60
  53. package/dist/lib-cjs/viewer-error.js.map +1 -1
  54. package/dist/lib-cjs/viewer.d.ts +115 -115
  55. package/dist/lib-cjs/viewer.js +217 -217
  56. package/dist/lib-cjs/viewer.js.map +1 -1
  57. package/package.json +94 -91
  58. package/src/buildinfo.json +3 -3
  59. package/src/dev.ts +47 -47
  60. package/src/global-types.d.ts +39 -39
  61. package/src/index.ts +71 -81
  62. package/src/internal/cbn-custom-babylon-loader-plugin.ts +159 -159
  63. package/src/internal/cloning-helper.ts +225 -225
  64. package/src/internal/device-helper.ts +25 -25
  65. package/src/internal/geometry-helper.ts +181 -181
  66. package/src/internal/metadata-helper.ts +63 -63
  67. package/src/internal/paintable-helper.ts +258 -310
  68. package/src/internal/svg-helper.ts +52 -0
  69. package/src/internal/tags-helper.ts +43 -41
  70. package/src/internal/texture-parameter-helper.ts +353 -0
  71. package/src/manager/camera-manager.ts +368 -365
  72. package/src/manager/debug-manager.ts +245 -245
  73. package/src/manager/event-manager.ts +72 -72
  74. package/src/manager/gltf-export-manager.ts +356 -357
  75. package/src/manager/material-manager.ts +135 -135
  76. package/src/manager/model-manager.ts +458 -458
  77. package/src/manager/parameter-manager.ts +730 -652
  78. package/src/manager/scene-manager.ts +101 -101
  79. package/src/manager/texture-manager.ts +32 -32
  80. package/src/viewer-error.ts +69 -68
  81. package/src/viewer.ts +290 -290
@@ -1,245 +1,245 @@
1
- import {
2
- AxesViewer,
3
- BoundingSphere,
4
- Color3,
5
- DynamicTexture,
6
- IInspectorOptions,
7
- MeshBuilder,
8
- Scene,
9
- StandardMaterial,
10
- TransformNode,
11
- UtilityLayerRenderer,
12
- Vector3,
13
- Viewer,
14
- ViewerEvent,
15
- } from '../index';
16
-
17
- type DebugAxisKeys = 'X' | 'Y' | 'Z';
18
- type DebugAxisConfig = { color: Color3; position: Vector3 };
19
-
20
- /**
21
- * Manager for debugging functionalities
22
- */
23
- export class DebugManager {
24
- protected static _DEBUG_AXIS_MAP: Record<DebugAxisKeys, DebugAxisConfig> = {
25
- X: { color: Color3.Red().scale(0.5), position: new Vector3(1, 0, 0) },
26
- Y: { color: Color3.Green().scale(0.5), position: new Vector3(0, 1, 0) },
27
- Z: { color: Color3.Blue().scale(0.5), position: new Vector3(0, 0, 1) },
28
- };
29
- protected static _WORLD_COORD_ROOT_KEY = '__world_coordinates__';
30
- protected static _BOUNDING_SPHERE_KEY = '__bounding_sphere__';
31
-
32
- protected _axesViewer: AxesViewer | null = null;
33
- protected _showBoundingSphereForAutofocus: boolean = false;
34
-
35
- /** @internal */
36
- public constructor(protected viewer: Viewer) {}
37
-
38
- /**
39
- * Assign callback for drawing bounding sphere on autofocusing
40
- * @internal
41
- */
42
- public registerAutofocusStartListener(): void {
43
- this.viewer.eventManager.addListener(ViewerEvent.AutofocusStart, boundingSphere =>
44
- this._drawBoundingSphereForAutofocus(boundingSphere)
45
- );
46
- }
47
-
48
- /**
49
- * Enables the Babylon.js [Inspector](https://doc.babylonjs.com/toolsAndResources/tools/inspector).\
50
- * Due to the additional size of the inspector, this function is only available in "development" builds!
51
- *
52
- * @returns Signalizes if inspector could be loaded
53
- */
54
- public async showInspector(options?: IInspectorOptions): Promise<boolean> {
55
- if (process.env.NODE_ENV === 'development') {
56
- const inspModule = await import(/* webpackChunkName: "inspector"*/ '@babylonjs/inspector');
57
-
58
- if (!options && window.Cbn) {
59
- // special case for usage in Combeenation configurator:
60
- // if no options are set the inspector will be rendered into the parent element of the configurator
61
- // in this way the configurator layout itself will not be affected by the inspector
62
- const cfgrParentEl = window.Cbn.utils.Viewer3dHelper.getCfgrParentDomElementForInspector();
63
- inspModule.Inspector.Show(this.viewer.scene, { globalRoot: cfgrParentEl });
64
- } else {
65
- inspModule.Inspector.Show(this.viewer.scene, options ?? {});
66
- }
67
-
68
- // load additional packages for certain inspector features like "node material editor"
69
- // this is done after showing the debug layer to save time
70
- await import(/* webpackChunkName: "node-material-editor" */ '@babylonjs/node-editor');
71
- await import(/* webpackChunkName: "node-geometry-editor" */ '@babylonjs/node-geometry-editor');
72
-
73
- return true;
74
- } else {
75
- // inspector not available, set according warning message in console
76
- if (window.Cbn) {
77
- console.warn(`Inspector not loaded.
78
- The inspector can only be used in development builds (e.g. during development with watch mode, in the configurator preview, ...)
79
- but not in production (e.g. production build of Custom JS, published configurator, ...).`);
80
- } else {
81
- console.warn(`Inspector not loaded.
82
- The inspector can only be used in development builds.`);
83
- }
84
-
85
- return false;
86
- }
87
- }
88
-
89
- public hideInspector(): void {
90
- this.viewer.scene.debugLayer?.hide();
91
- }
92
-
93
- /**
94
- * Show world coordinate system with given dimension.\
95
- * This is especially usefull when working on project with tricky positioning. (e.g. clones)
96
- */
97
- public showWorldCoordinates(dimension: number): void {
98
- // make sure to remove already existing debug coordinate systems
99
- this.hideWorldCoordinates();
100
-
101
- // draw in utility layer, so that there is no interaction with the actually scene content
102
- // (e.g. glb export, autofocus)
103
- const utilityLayerScene = UtilityLayerRenderer.DefaultUtilityLayer.utilityLayerScene;
104
-
105
- const worldCoordRoot = new TransformNode(DebugManager._WORLD_COORD_ROOT_KEY, utilityLayerScene);
106
- // axes viewer coordinate system is a bit too large
107
- // multiply with unify factor to create arrows which exactly match the length of the input dimension
108
- const factor = DebugManager._getWorldCoordinatesAxesUnifyFactor();
109
- this._axesViewer = new AxesViewer(utilityLayerScene, dimension * factor);
110
-
111
- DebugManager._prepareWorldCoordinateAxis('X', this._axesViewer.xAxis, worldCoordRoot, dimension, utilityLayerScene);
112
- DebugManager._prepareWorldCoordinateAxis('Y', this._axesViewer.yAxis, worldCoordRoot, dimension, utilityLayerScene);
113
- DebugManager._prepareWorldCoordinateAxis('Z', this._axesViewer.zAxis, worldCoordRoot, dimension, utilityLayerScene);
114
- }
115
-
116
- public hideWorldCoordinates(): void {
117
- const utilityLayerScene = UtilityLayerRenderer.DefaultUtilityLayer.utilityLayerScene;
118
-
119
- this._axesViewer?.dispose();
120
- this._axesViewer = null;
121
-
122
- const worldCoordRoot = utilityLayerScene.getTransformNodeByName(DebugManager._WORLD_COORD_ROOT_KEY);
123
- if (worldCoordRoot) {
124
- worldCoordRoot.dispose(false, true);
125
- }
126
- }
127
-
128
- /**
129
- * Draws a wireframe bounding sphere on the next call of {@link CameraManager.autofocusActiveCamera}.\
130
- * This is usefull for checking which parts of the scene get centered.
131
- */
132
- public showBoundingSphereForAutofocus(): void {
133
- this._showBoundingSphereForAutofocus = true;
134
- }
135
-
136
- public hideBoundingSphereForAutofocus(): void {
137
- this._showBoundingSphereForAutofocus = false;
138
- this._removeBoundingSphereForAutofocus();
139
- }
140
-
141
- /**
142
- * Adjust and enhance coordinate axes to fulfill our needs.
143
- * - moves nodes into common root
144
- * - adds text node
145
- */
146
- protected static _prepareWorldCoordinateAxis(
147
- text: 'X' | 'Y' | 'Z',
148
- axis: TransformNode,
149
- root: TransformNode,
150
- dimension: number,
151
- utilityLayerScene: Scene
152
- ): void {
153
- // create unique names
154
- axis.name = `${DebugManager._WORLD_COORD_ROOT_KEY}.${text}`;
155
- axis.parent = root;
156
-
157
- // create text mesh via dynamic texture
158
- const dynamicTexture = new DynamicTexture(
159
- `${DebugManager._WORLD_COORD_ROOT_KEY}.${text}`,
160
- 50,
161
- utilityLayerScene,
162
- true
163
- );
164
- dynamicTexture.hasAlpha = true;
165
- // 42.5 is a magic offset, so that the text is vertically centered for font size 50px
166
- // horizontal centering works well with the standard behaviour of Babylon.js (setting "null" as "width")
167
- dynamicTexture.drawText(text, null, 42.5, 'bold 50px Arial', 'white', 'transparent', true);
168
-
169
- const material = new StandardMaterial(`${DebugManager._WORLD_COORD_ROOT_KEY}.${text}`, utilityLayerScene);
170
- material.disableLighting = true;
171
- material.emissiveColor = DebugManager._DEBUG_AXIS_MAP[text].color;
172
- material.diffuseTexture = dynamicTexture;
173
-
174
- const plane = MeshBuilder.CreatePlane(
175
- `${DebugManager._WORLD_COORD_ROOT_KEY}.${text}.TextPlane`,
176
- { size: dimension / 10 },
177
- utilityLayerScene
178
- );
179
- // make sure that text is located outside of arrow
180
- plane.position = DebugManager._DEBUG_AXIS_MAP[text].position.multiplyByFloats(
181
- dimension * 1.05,
182
- dimension * 1.05,
183
- dimension * 1.05
184
- );
185
- plane.parent = root;
186
- plane.material = material;
187
- // will be rendered on top of "default" meshes => taken from Babylon.js repo "AxesViewer" implementation
188
- plane.renderingGroupId = 2;
189
- // setting billboard mode ensures, that the text is always readable
190
- plane.billboardMode = TransformNode.BILLBOARDMODE_ALL;
191
- }
192
-
193
- /**
194
- * Calculate factor for creating world coordinate axes with exactly one unit in length
195
- */
196
- protected static _getWorldCoordinatesAxesUnifyFactor(): number {
197
- // These constants are taken from the Babylon.js repository
198
- const coneZPosOffset = 0.3;
199
- const coneHeight = 0.075;
200
- const baseScaling = 4;
201
-
202
- // cone is moved 0.3 units away from the center
203
- // the origin of the cone will be located on 1.2, if combined with the base scaling of 4
204
- // invert that offset to get the origin to 1
205
- // also consider the cone height to move the tip of the cone to 1 instead the center
206
- const factor = 1 / ((coneZPosOffset + coneHeight / 2) * baseScaling);
207
-
208
- return factor;
209
- }
210
-
211
- /**
212
- * Visualize bounding sphere which is used to zoom in via `autofocusActiveCamera` function
213
- */
214
- protected _drawBoundingSphereForAutofocus(boundingSphere: BoundingSphere): void {
215
- if (!this._showBoundingSphereForAutofocus) {
216
- return;
217
- }
218
-
219
- this._removeBoundingSphereForAutofocus();
220
-
221
- const utilityLayerScene = UtilityLayerRenderer.DefaultUtilityLayer.utilityLayerScene;
222
- let boundingMaterial = utilityLayerScene.getMaterialByName(DebugManager._BOUNDING_SPHERE_KEY);
223
- if (!boundingMaterial) {
224
- boundingMaterial = new StandardMaterial(DebugManager._BOUNDING_SPHERE_KEY, utilityLayerScene);
225
- boundingMaterial.wireframe = true;
226
- boundingMaterial.alpha = 0.1;
227
- (boundingMaterial as StandardMaterial).emissiveColor = new Color3(1, 1, 1);
228
- }
229
-
230
- const sphere = MeshBuilder.CreateSphere(
231
- DebugManager._BOUNDING_SPHERE_KEY,
232
- { diameter: boundingSphere.radius * 2 },
233
- utilityLayerScene
234
- );
235
- sphere.position = boundingSphere.center;
236
- sphere.material = boundingMaterial;
237
- sphere.isPickable = false;
238
- }
239
-
240
- protected _removeBoundingSphereForAutofocus(): void {
241
- const utilityLayerScene = UtilityLayerRenderer.DefaultUtilityLayer.utilityLayerScene;
242
- const existingSphere = utilityLayerScene.getMeshByName(DebugManager._BOUNDING_SPHERE_KEY);
243
- existingSphere?.dispose();
244
- }
245
- }
1
+ import {
2
+ AxesViewer,
3
+ BoundingSphere,
4
+ Color3,
5
+ DynamicTexture,
6
+ IInspectorOptions,
7
+ MeshBuilder,
8
+ Scene,
9
+ StandardMaterial,
10
+ TransformNode,
11
+ UtilityLayerRenderer,
12
+ Vector3,
13
+ Viewer,
14
+ ViewerEvent,
15
+ } from '../index';
16
+
17
+ type DebugAxisKeys = 'X' | 'Y' | 'Z';
18
+ type DebugAxisConfig = { color: Color3; position: Vector3 };
19
+
20
+ /**
21
+ * Manager for debugging functionalities
22
+ */
23
+ export class DebugManager {
24
+ protected static _DEBUG_AXIS_MAP: Record<DebugAxisKeys, DebugAxisConfig> = {
25
+ X: { color: Color3.Red().scale(0.5), position: new Vector3(1, 0, 0) },
26
+ Y: { color: Color3.Green().scale(0.5), position: new Vector3(0, 1, 0) },
27
+ Z: { color: Color3.Blue().scale(0.5), position: new Vector3(0, 0, 1) },
28
+ };
29
+ protected static _WORLD_COORD_ROOT_KEY = '__world_coordinates__';
30
+ protected static _BOUNDING_SPHERE_KEY = '__bounding_sphere__';
31
+
32
+ protected _axesViewer: AxesViewer | null = null;
33
+ protected _showBoundingSphereForAutofocus: boolean = false;
34
+
35
+ /** @internal */
36
+ public constructor(protected viewer: Viewer) {}
37
+
38
+ /**
39
+ * Assign callback for drawing bounding sphere on autofocusing
40
+ * @internal
41
+ */
42
+ public registerAutofocusStartListener(): void {
43
+ this.viewer.eventManager.addListener(ViewerEvent.AutofocusStart, boundingSphere =>
44
+ this._drawBoundingSphereForAutofocus(boundingSphere)
45
+ );
46
+ }
47
+
48
+ /**
49
+ * Enables the Babylon.js [Inspector](https://doc.babylonjs.com/toolsAndResources/tools/inspector).\
50
+ * Due to the additional size of the inspector, this function is only available in "development" builds!
51
+ *
52
+ * @returns Signalizes if inspector could be loaded
53
+ */
54
+ public async showInspector(options?: IInspectorOptions): Promise<boolean> {
55
+ if (process.env.NODE_ENV === 'development') {
56
+ const inspModule = await import(/* webpackChunkName: "inspector"*/ '@babylonjs/inspector');
57
+
58
+ if (!options && window.Cbn) {
59
+ // special case for usage in Combeenation configurator:
60
+ // if no options are set the inspector will be rendered into the parent element of the configurator
61
+ // in this way the configurator layout itself will not be affected by the inspector
62
+ const cfgrParentEl = window.Cbn.utils.Viewer3dHelper.getCfgrParentDomElementForInspector();
63
+ inspModule.Inspector.Show(this.viewer.scene, { globalRoot: cfgrParentEl });
64
+ } else {
65
+ inspModule.Inspector.Show(this.viewer.scene, options ?? {});
66
+ }
67
+
68
+ // load additional packages for certain inspector features like "node material editor"
69
+ // this is done after showing the debug layer to save time
70
+ await import(/* webpackChunkName: "node-material-editor" */ '@babylonjs/node-editor');
71
+ await import(/* webpackChunkName: "node-geometry-editor" */ '@babylonjs/node-geometry-editor');
72
+
73
+ return true;
74
+ } else {
75
+ // inspector not available, set according warning message in console
76
+ if (window.Cbn) {
77
+ console.warn(`Inspector not loaded.
78
+ The inspector can only be used in development builds (e.g. during development with watch mode, in the configurator preview, ...)
79
+ but not in production (e.g. production build of Custom JS, published configurator, ...).`);
80
+ } else {
81
+ console.warn(`Inspector not loaded.
82
+ The inspector can only be used in development builds.`);
83
+ }
84
+
85
+ return false;
86
+ }
87
+ }
88
+
89
+ public hideInspector(): void {
90
+ this.viewer.scene.debugLayer?.hide();
91
+ }
92
+
93
+ /**
94
+ * Show world coordinate system with given dimension.\
95
+ * This is especially usefull when working on project with tricky positioning. (e.g. clones)
96
+ */
97
+ public showWorldCoordinates(dimension: number): void {
98
+ // make sure to remove already existing debug coordinate systems
99
+ this.hideWorldCoordinates();
100
+
101
+ // draw in utility layer, so that there is no interaction with the actually scene content
102
+ // (e.g. glb export, autofocus)
103
+ const utilityLayerScene = UtilityLayerRenderer.DefaultUtilityLayer.utilityLayerScene;
104
+
105
+ const worldCoordRoot = new TransformNode(DebugManager._WORLD_COORD_ROOT_KEY, utilityLayerScene);
106
+ // axes viewer coordinate system is a bit too large
107
+ // multiply with unify factor to create arrows which exactly match the length of the input dimension
108
+ const factor = DebugManager._getWorldCoordinatesAxesUnifyFactor();
109
+ this._axesViewer = new AxesViewer(utilityLayerScene, dimension * factor);
110
+
111
+ DebugManager._prepareWorldCoordinateAxis('X', this._axesViewer.xAxis, worldCoordRoot, dimension, utilityLayerScene);
112
+ DebugManager._prepareWorldCoordinateAxis('Y', this._axesViewer.yAxis, worldCoordRoot, dimension, utilityLayerScene);
113
+ DebugManager._prepareWorldCoordinateAxis('Z', this._axesViewer.zAxis, worldCoordRoot, dimension, utilityLayerScene);
114
+ }
115
+
116
+ public hideWorldCoordinates(): void {
117
+ const utilityLayerScene = UtilityLayerRenderer.DefaultUtilityLayer.utilityLayerScene;
118
+
119
+ this._axesViewer?.dispose();
120
+ this._axesViewer = null;
121
+
122
+ const worldCoordRoot = utilityLayerScene.getTransformNodeByName(DebugManager._WORLD_COORD_ROOT_KEY);
123
+ if (worldCoordRoot) {
124
+ worldCoordRoot.dispose(false, true);
125
+ }
126
+ }
127
+
128
+ /**
129
+ * Draws a wireframe bounding sphere on the next call of {@link CameraManager.autofocusActiveCamera}.\
130
+ * This is usefull for checking which parts of the scene get centered.
131
+ */
132
+ public showBoundingSphereForAutofocus(): void {
133
+ this._showBoundingSphereForAutofocus = true;
134
+ }
135
+
136
+ public hideBoundingSphereForAutofocus(): void {
137
+ this._showBoundingSphereForAutofocus = false;
138
+ this._removeBoundingSphereForAutofocus();
139
+ }
140
+
141
+ /**
142
+ * Adjust and enhance coordinate axes to fulfill our needs.
143
+ * - moves nodes into common root
144
+ * - adds text node
145
+ */
146
+ protected static _prepareWorldCoordinateAxis(
147
+ text: 'X' | 'Y' | 'Z',
148
+ axis: TransformNode,
149
+ root: TransformNode,
150
+ dimension: number,
151
+ utilityLayerScene: Scene
152
+ ): void {
153
+ // create unique names
154
+ axis.name = `${DebugManager._WORLD_COORD_ROOT_KEY}.${text}`;
155
+ axis.parent = root;
156
+
157
+ // create text mesh via dynamic texture
158
+ const dynamicTexture = new DynamicTexture(
159
+ `${DebugManager._WORLD_COORD_ROOT_KEY}.${text}`,
160
+ 50,
161
+ utilityLayerScene,
162
+ true
163
+ );
164
+ dynamicTexture.hasAlpha = true;
165
+ // 42.5 is a magic offset, so that the text is vertically centered for font size 50px
166
+ // horizontal centering works well with the standard behaviour of Babylon.js (setting "null" as "width")
167
+ dynamicTexture.drawText(text, null, 42.5, 'bold 50px Arial', 'white', 'transparent', true);
168
+
169
+ const material = new StandardMaterial(`${DebugManager._WORLD_COORD_ROOT_KEY}.${text}`, utilityLayerScene);
170
+ material.disableLighting = true;
171
+ material.emissiveColor = DebugManager._DEBUG_AXIS_MAP[text].color;
172
+ material.diffuseTexture = dynamicTexture;
173
+
174
+ const plane = MeshBuilder.CreatePlane(
175
+ `${DebugManager._WORLD_COORD_ROOT_KEY}.${text}.TextPlane`,
176
+ { size: dimension / 10 },
177
+ utilityLayerScene
178
+ );
179
+ // make sure that text is located outside of arrow
180
+ plane.position = DebugManager._DEBUG_AXIS_MAP[text].position.multiplyByFloats(
181
+ dimension * 1.05,
182
+ dimension * 1.05,
183
+ dimension * 1.05
184
+ );
185
+ plane.parent = root;
186
+ plane.material = material;
187
+ // will be rendered on top of "default" meshes => taken from Babylon.js repo "AxesViewer" implementation
188
+ plane.renderingGroupId = 2;
189
+ // setting billboard mode ensures, that the text is always readable
190
+ plane.billboardMode = TransformNode.BILLBOARDMODE_ALL;
191
+ }
192
+
193
+ /**
194
+ * Calculate factor for creating world coordinate axes with exactly one unit in length
195
+ */
196
+ protected static _getWorldCoordinatesAxesUnifyFactor(): number {
197
+ // These constants are taken from the Babylon.js repository
198
+ const coneZPosOffset = 0.3;
199
+ const coneHeight = 0.075;
200
+ const baseScaling = 4;
201
+
202
+ // cone is moved 0.3 units away from the center
203
+ // the origin of the cone will be located on 1.2, if combined with the base scaling of 4
204
+ // invert that offset to get the origin to 1
205
+ // also consider the cone height to move the tip of the cone to 1 instead the center
206
+ const factor = 1 / ((coneZPosOffset + coneHeight / 2) * baseScaling);
207
+
208
+ return factor;
209
+ }
210
+
211
+ /**
212
+ * Visualize bounding sphere which is used to zoom in via `autofocusActiveCamera` function
213
+ */
214
+ protected _drawBoundingSphereForAutofocus(boundingSphere: BoundingSphere): void {
215
+ if (!this._showBoundingSphereForAutofocus) {
216
+ return;
217
+ }
218
+
219
+ this._removeBoundingSphereForAutofocus();
220
+
221
+ const utilityLayerScene = UtilityLayerRenderer.DefaultUtilityLayer.utilityLayerScene;
222
+ let boundingMaterial = utilityLayerScene.getMaterialByName(DebugManager._BOUNDING_SPHERE_KEY);
223
+ if (!boundingMaterial) {
224
+ boundingMaterial = new StandardMaterial(DebugManager._BOUNDING_SPHERE_KEY, utilityLayerScene);
225
+ boundingMaterial.wireframe = true;
226
+ boundingMaterial.alpha = 0.1;
227
+ (boundingMaterial as StandardMaterial).emissiveColor = new Color3(1, 1, 1);
228
+ }
229
+
230
+ const sphere = MeshBuilder.CreateSphere(
231
+ DebugManager._BOUNDING_SPHERE_KEY,
232
+ { diameter: boundingSphere.radius * 2 },
233
+ utilityLayerScene
234
+ );
235
+ sphere.position = boundingSphere.center;
236
+ sphere.material = boundingMaterial;
237
+ sphere.isPickable = false;
238
+ }
239
+
240
+ protected _removeBoundingSphereForAutofocus(): void {
241
+ const utilityLayerScene = UtilityLayerRenderer.DefaultUtilityLayer.utilityLayerScene;
242
+ const existingSphere = utilityLayerScene.getMeshByName(DebugManager._BOUNDING_SPHERE_KEY);
243
+ existingSphere?.dispose();
244
+ }
245
+ }
@@ -1,72 +1,72 @@
1
- import { Viewer } from '../index';
2
- import EventEmitter from 'eventemitter3';
3
-
4
- // NOTE: ATM we expose only very few events, due to the following reasons:
5
- // - Code is generally asynchronous and can be awaited by consumer
6
- // - We don't want to bloat the code with events that are never used
7
-
8
- /**
9
- * Events that are fired by the viewer
10
- */
11
- export enum ViewerEvent {
12
- /**
13
- * Requested material is not available in the scene yet and is about to be created
14
- * @param materialId
15
- */
16
- MaterialCreationStart = 'MaterialCreationStart',
17
- /**
18
- * Material creation has been finished, that includes:
19
- * - Load definition from Combeenation server
20
- * - Load all textures
21
- * - Compile shader
22
- * @param materialId
23
- * @param allMaterialsCreated signalizes that no more materials are currently being created
24
- */
25
- MaterialCreationEnd = 'MaterialCreationEnd',
26
- /**
27
- * Bounding sphere for autofocusing camera has been calculated.
28
- * This is used internally for debugging purposes.
29
- * @param boundingSphere
30
- */
31
- AutofocusStart = 'AutofocusStart',
32
- }
33
-
34
- /**
35
- * Manager for eventing system, which ATM is only a slim wrapper about the "eventemitter3" library
36
- */
37
- export class EventManager {
38
- protected _eventEmitter: EventEmitter;
39
-
40
- /** @internal */
41
- public constructor(protected viewer: Viewer) {
42
- this._eventEmitter = new EventEmitter();
43
- }
44
-
45
- /**
46
- * Used @internal to fire a viewer event
47
- */
48
- public fireEvent(event: ViewerEvent, ...args: any[]): void {
49
- this._eventEmitter.emit(event, ...args);
50
- }
51
-
52
- /**
53
- * Add listener to certain viewer event
54
- */
55
- public addListener(event: ViewerEvent, fn: EventEmitter.ListenerFn): void {
56
- this._eventEmitter.addListener(event, fn);
57
- }
58
-
59
- /**
60
- * Remove listener to viewer event
61
- */
62
- public removeListener(event: ViewerEvent, fn: EventEmitter.ListenerFn): void {
63
- this._eventEmitter.removeListener(event, fn);
64
- }
65
-
66
- /**
67
- * Used @internal to clean eventing sytem before viewer destruction
68
- */
69
- public removeAllListeners(event?: ViewerEvent): void {
70
- this._eventEmitter.removeAllListeners(event);
71
- }
72
- }
1
+ import { Viewer } from '../index';
2
+ import EventEmitter from 'eventemitter3';
3
+
4
+ // NOTE: ATM we expose only very few events, due to the following reasons:
5
+ // - Code is generally asynchronous and can be awaited by consumer
6
+ // - We don't want to bloat the code with events that are never used
7
+
8
+ /**
9
+ * Events that are fired by the viewer
10
+ */
11
+ export enum ViewerEvent {
12
+ /**
13
+ * Requested material is not available in the scene yet and is about to be created
14
+ * @param materialId
15
+ */
16
+ MaterialCreationStart = 'MaterialCreationStart',
17
+ /**
18
+ * Material creation has been finished, that includes:
19
+ * - Load definition from Combeenation server
20
+ * - Load all textures
21
+ * - Compile shader
22
+ * @param materialId
23
+ * @param allMaterialsCreated signalizes that no more materials are currently being created
24
+ */
25
+ MaterialCreationEnd = 'MaterialCreationEnd',
26
+ /**
27
+ * Bounding sphere for autofocusing camera has been calculated.
28
+ * This is used internally for debugging purposes.
29
+ * @param boundingSphere
30
+ */
31
+ AutofocusStart = 'AutofocusStart',
32
+ }
33
+
34
+ /**
35
+ * Manager for eventing system, which ATM is only a slim wrapper about the "eventemitter3" library
36
+ */
37
+ export class EventManager {
38
+ protected _eventEmitter: EventEmitter;
39
+
40
+ /** @internal */
41
+ public constructor(protected viewer: Viewer) {
42
+ this._eventEmitter = new EventEmitter();
43
+ }
44
+
45
+ /**
46
+ * Used @internal to fire a viewer event
47
+ */
48
+ public fireEvent(event: ViewerEvent, ...args: any[]): void {
49
+ this._eventEmitter.emit(event, ...args);
50
+ }
51
+
52
+ /**
53
+ * Add listener to certain viewer event
54
+ */
55
+ public addListener(event: ViewerEvent, fn: EventEmitter.ListenerFn): void {
56
+ this._eventEmitter.addListener(event, fn);
57
+ }
58
+
59
+ /**
60
+ * Remove listener to viewer event
61
+ */
62
+ public removeListener(event: ViewerEvent, fn: EventEmitter.ListenerFn): void {
63
+ this._eventEmitter.removeListener(event, fn);
64
+ }
65
+
66
+ /**
67
+ * Used @internal to clean eventing sytem before viewer destruction
68
+ */
69
+ public removeAllListeners(event?: ViewerEvent): void {
70
+ this._eventEmitter.removeAllListeners(event);
71
+ }
72
+ }