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