@combeenation/3d-viewer 17.1.0 → 18.0.0-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 (58) hide show
  1. package/dist/lib-cjs/buildinfo.json +1 -1
  2. package/dist/lib-cjs/commonjs.tsconfig.tsbuildinfo +1 -1
  3. package/dist/lib-cjs/index.d.ts +8 -0
  4. package/dist/lib-cjs/index.js +8 -0
  5. package/dist/lib-cjs/index.js.map +1 -1
  6. package/dist/lib-cjs/internal/asset-helper.d.ts +32 -0
  7. package/dist/lib-cjs/internal/asset-helper.js +105 -0
  8. package/dist/lib-cjs/internal/asset-helper.js.map +1 -0
  9. package/dist/lib-cjs/internal/cbn-custom-babylon-loader-plugin.d.ts +18 -0
  10. package/dist/lib-cjs/internal/cbn-custom-babylon-loader-plugin.js +22 -3
  11. package/dist/lib-cjs/internal/cbn-custom-babylon-loader-plugin.js.map +1 -1
  12. package/dist/lib-cjs/internal/cloning-helper.js +1 -1
  13. package/dist/lib-cjs/internal/cloning-helper.js.map +1 -1
  14. package/dist/lib-cjs/internal/texture-parameter-helper.js +26 -7
  15. package/dist/lib-cjs/internal/texture-parameter-helper.js.map +1 -1
  16. package/dist/lib-cjs/manager/camera-manager.d.ts +23 -2
  17. package/dist/lib-cjs/manager/camera-manager.js +91 -24
  18. package/dist/lib-cjs/manager/camera-manager.js.map +1 -1
  19. package/dist/lib-cjs/manager/debug-manager.d.ts +1 -1
  20. package/dist/lib-cjs/manager/debug-manager.js +3 -3
  21. package/dist/lib-cjs/manager/debug-manager.js.map +1 -1
  22. package/dist/lib-cjs/manager/dimension-line-manager.d.ts +126 -0
  23. package/dist/lib-cjs/manager/dimension-line-manager.js +138 -0
  24. package/dist/lib-cjs/manager/dimension-line-manager.js.map +1 -0
  25. package/dist/lib-cjs/manager/html-anchor-manager.d.ts +93 -0
  26. package/dist/lib-cjs/manager/html-anchor-manager.js +228 -0
  27. package/dist/lib-cjs/manager/html-anchor-manager.js.map +1 -0
  28. package/dist/lib-cjs/manager/model-manager.d.ts +11 -34
  29. package/dist/lib-cjs/manager/model-manager.js +47 -107
  30. package/dist/lib-cjs/manager/model-manager.js.map +1 -1
  31. package/dist/lib-cjs/manager/parameter-manager.d.ts +17 -12
  32. package/dist/lib-cjs/manager/parameter-manager.js +78 -69
  33. package/dist/lib-cjs/manager/parameter-manager.js.map +1 -1
  34. package/dist/lib-cjs/manager/scene-manager.d.ts +111 -5
  35. package/dist/lib-cjs/manager/scene-manager.js +276 -10
  36. package/dist/lib-cjs/manager/scene-manager.js.map +1 -1
  37. package/dist/lib-cjs/viewer-error.d.ts +1 -0
  38. package/dist/lib-cjs/viewer-error.js +1 -0
  39. package/dist/lib-cjs/viewer-error.js.map +1 -1
  40. package/dist/lib-cjs/viewer.d.ts +9 -14
  41. package/dist/lib-cjs/viewer.js +16 -38
  42. package/dist/lib-cjs/viewer.js.map +1 -1
  43. package/package.json +22 -12
  44. package/src/index.ts +8 -0
  45. package/src/internal/asset-helper.ts +115 -0
  46. package/src/internal/cbn-custom-babylon-loader-plugin.ts +30 -3
  47. package/src/internal/cloning-helper.ts +1 -1
  48. package/src/internal/texture-parameter-helper.ts +25 -8
  49. package/src/manager/camera-manager.ts +153 -39
  50. package/src/manager/debug-manager.ts +3 -3
  51. package/src/manager/dimension-line-manager.ts +255 -0
  52. package/src/manager/html-anchor-manager.ts +332 -0
  53. package/src/manager/model-manager.ts +55 -138
  54. package/src/manager/parameter-manager.ts +94 -75
  55. package/src/manager/scene-manager.ts +375 -10
  56. package/src/viewer-error.ts +1 -0
  57. package/src/viewer.ts +30 -56
  58. package/src/dev.ts +0 -47
@@ -0,0 +1,228 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.HtmlAnchorManager = void 0;
16
+ const __1 = require("..");
17
+ const html2canvas_1 = __importDefault(require("html2canvas"));
18
+ /**
19
+ * Manager for mapping html elements to 3d positions in the scene.\
20
+ * Common use cases are:
21
+ * - **Hotspot buttons**: Interactively add/remove elements in the scene or just show some info on hovering
22
+ * - **Input fields**: Interactively change the size of an element
23
+ * - **Info label**: Just shows some information on a certain position within the scene
24
+ *
25
+ * Html anchors are also used as dimension lables in the {@link DimensionLineManager}
26
+ */
27
+ class HtmlAnchorManager {
28
+ /** @internal */
29
+ constructor(viewer) {
30
+ this.viewer = viewer;
31
+ this._htmlAnchors = {};
32
+ this._anchorMeshMaterial = null;
33
+ const canvas = viewer.canvas;
34
+ if (!canvas) {
35
+ return;
36
+ }
37
+ // html element positions need to be updated after each camera render call
38
+ viewer.scene.onAfterRenderCameraObservable.add(() => {
39
+ Object.values(this._htmlAnchors).forEach(({ parentHtmlElement, anchorMesh, options }) => {
40
+ this._updateHtmlAnchor(parentHtmlElement, anchorMesh, viewer.scene.activeCamera, canvas.width, canvas.height, 1, options);
41
+ });
42
+ });
43
+ }
44
+ /**
45
+ * Assign a html element to a certain position in the scene.\
46
+ * The html elements 2d position will be updated on each camera render, so that the element appears like a "normal"
47
+ * mesh within the scene.
48
+ */
49
+ addHtmlAnchor(name, htmlElement, position, options) {
50
+ var _a;
51
+ const canvasParentHtmlElement = (_a = this.viewer.canvas) === null || _a === void 0 ? void 0 : _a.parentElement;
52
+ if (!canvasParentHtmlElement) {
53
+ console.warn(`No parent for desired html anchor available`);
54
+ return;
55
+ }
56
+ if (this._htmlAnchors[name]) {
57
+ console.warn(`Html anchor "${name}" already exists`);
58
+ return;
59
+ }
60
+ const { parentNode, enablePointerEvents } = options !== null && options !== void 0 ? options : {};
61
+ // create a parent for the input html element, which will receive the updated style and transform data
62
+ // in this way the original input element remains untouched
63
+ const parentHtmlElement = document.createElement('div');
64
+ parentHtmlElement.dataset.anchorName = name;
65
+ parentHtmlElement.style.position = 'absolute';
66
+ parentHtmlElement.style.margin = '0';
67
+ parentHtmlElement.appendChild(htmlElement);
68
+ if (!enablePointerEvents) {
69
+ parentHtmlElement.style.pointerEvents = 'none';
70
+ }
71
+ canvasParentHtmlElement.appendChild(parentHtmlElement);
72
+ // NOTE: creates a sphere with fixed size, which could be problematic in scene with "strange" dimensions
73
+ // add a property for the sphere size if required
74
+ const anchorMesh = __1.MeshBuilder.CreateSphere(`${HtmlAnchorManager._HTML_ANCHOR_KEY}_${name}`, { diameter: 0.01 });
75
+ anchorMesh.position = position;
76
+ anchorMesh.parent = parentNode !== null && parentNode !== void 0 ? parentNode : null;
77
+ // anchor mesh will be invisible, we only need it for positioning and occlusion check
78
+ anchorMesh.material = this._getOrCreateAnchorMeshMaterial();
79
+ anchorMesh.occlusionType = __1.AbstractMesh.OCCLUSION_TYPE_OPTIMISTIC;
80
+ anchorMesh.occlusionQueryAlgorithmType = __1.AbstractMesh.OCCLUSION_ALGORITHM_TYPE_CONSERVATIVE;
81
+ // it's important that the occlusion check mesh is rendered after all "normal" meshes, which should be taken into
82
+ // account for the occlusion check
83
+ anchorMesh.renderingGroupId = 1;
84
+ this._htmlAnchors[name] = { parentHtmlElement, anchorMesh, options };
85
+ }
86
+ /**
87
+ * Remove html anchor element and disposes all associated ressources
88
+ */
89
+ removeHtmlAnchor(name) {
90
+ const htmlAnchor = this._htmlAnchors[name];
91
+ if (!htmlAnchor) {
92
+ console.warn(`Html anchor "${name}" does not exist`);
93
+ return;
94
+ }
95
+ htmlAnchor.parentHtmlElement.remove();
96
+ htmlAnchor.anchorMesh.dispose();
97
+ delete this._htmlAnchors[name];
98
+ }
99
+ /**
100
+ * Removes html anchor elements, as defined by the `groups` input
101
+ *
102
+ * @param groups if set, only html anchors which are part of these groups will be removed\
103
+ * if left `undefined`, ALL html anchors will be removed
104
+ */
105
+ removeAllHtmlAnchors(groups) {
106
+ const anchorKeysToRemove = this.getHtmlAnchorKeys(groups, undefined,
107
+ // system groups should not be remove, as there is a dedicated workflow
108
+ // (e.g. `DimensionLineManager.removeDimensionLine`) to do this
109
+ false);
110
+ anchorKeysToRemove.forEach(name => this.removeHtmlAnchor(name));
111
+ }
112
+ /**
113
+ * Creates a screenshot of defined html anchors and returns the associated canvas.\
114
+ * This function is used @internal from the main screenshot function.
115
+ */
116
+ createScreenshotCanvas(size, camera, htmlAnchorKeys) {
117
+ var _a;
118
+ return __awaiter(this, void 0, void 0, function* () {
119
+ const canvasParentHtmlElement = (_a = this.viewer.canvas) === null || _a === void 0 ? void 0 : _a.parentElement;
120
+ if (!canvasParentHtmlElement) {
121
+ console.warn(`No parent for html anchors available`);
122
+ return new HTMLCanvasElement();
123
+ }
124
+ const htmlContainer = document.createElement('div');
125
+ htmlContainer.style.width = `${size.canvasWidth}px`;
126
+ htmlContainer.style.height = `${size.canvasHeight}px`;
127
+ // the `html2canvas` library requires the html to be present in the DOM
128
+ // that's why we create it top level and move it out of the viewport
129
+ // @reviewer: maybe there is a smoother method of doing that?
130
+ document.body.append(htmlContainer);
131
+ htmlContainer.style.position = 'absolute';
132
+ htmlContainer.style.top = `${-size.canvasHeight}px`;
133
+ htmlAnchorKeys.forEach(key => {
134
+ const { parentHtmlElement, anchorMesh, options } = this._htmlAnchors[key];
135
+ // create clones of html anchors, so that the position of the original elements remains untouched
136
+ const clonedHtmlNode = parentHtmlElement.cloneNode(true);
137
+ htmlContainer.append(clonedHtmlNode);
138
+ // reposition that cloned html element, so that it fits to the desired camera position
139
+ const baseScale = size.canvasHeight / this.viewer.canvas.height;
140
+ this._updateHtmlAnchor(clonedHtmlNode, anchorMesh, camera, size.canvasWidth, size.canvasHeight, baseScale, options);
141
+ });
142
+ const screenshotHtmlCanvas = yield (0, html2canvas_1.default)(htmlContainer, {
143
+ width: size.imageWidth,
144
+ height: size.imageHeight,
145
+ // apply difference of canvas and image size as offsets
146
+ x: (size.canvasWidth - size.imageWidth) / 2,
147
+ y: (size.canvasHeight - size.imageHeight) / 2,
148
+ logging: false,
149
+ backgroundColor: null,
150
+ });
151
+ htmlContainer.remove();
152
+ return screenshotHtmlCanvas;
153
+ });
154
+ }
155
+ /**
156
+ * Receive html anchor keys that pass the `includeGroups` and `excludeGroups` filter
157
+ * @param allowSystemGroups defines if html anchors created by the viewer should be considered (e.g. dimension line
158
+ * labels)
159
+ * @internal
160
+ */
161
+ getHtmlAnchorKeys(includeGroups, excludeGroups, allowSystemGroups) {
162
+ const anchorKeys = Object.keys(this._htmlAnchors).filter(name => {
163
+ var _a;
164
+ const group = (_a = this._htmlAnchors[name].options) === null || _a === void 0 ? void 0 : _a.group;
165
+ const passIncludeGroupFilter = includeGroups === undefined || (group !== undefined && includeGroups.includes(group));
166
+ const passExcludeGroupFilter = excludeGroups === undefined || group === undefined || !excludeGroups.includes(group);
167
+ // ATM only dimension labels are system html anchors
168
+ const passSystemGroupFilter = allowSystemGroups || group !== __1.DimensionLineManager.DIMENSION_LINE_KEY;
169
+ return passIncludeGroupFilter && passExcludeGroupFilter && passSystemGroupFilter;
170
+ });
171
+ return anchorKeys;
172
+ }
173
+ /**
174
+ * Check if input mesh is a html anchor mesh, created by this manager.\
175
+ * This check is done via the material, as all html anchor meshes have the generic `_anchorMeshMaterial` set.
176
+ * @internal
177
+ */
178
+ isHtmlAnchorMesh(mesh) {
179
+ return mesh.material === this._anchorMeshMaterial;
180
+ }
181
+ _updateHtmlAnchor(parentHtmlElement, anchorMesh, camera, width, height, baseScale, options) {
182
+ const { hideIfOccluded, scaleWithCameraDistance } = options !== null && options !== void 0 ? options : {};
183
+ const viewMatrix = camera.getViewMatrix();
184
+ const projectionMatrix = camera.getProjectionMatrix();
185
+ const transformMatrix = viewMatrix.multiply(projectionMatrix);
186
+ // convert into 2d space
187
+ const vertexScreenCoords = __1.Vector3.Project(__1.Vector3.Zero(), anchorMesh.getWorldMatrix(), transformMatrix, new __1.Viewport(0, 0, width, height));
188
+ // base scale is used if width and height don't equal the viewer canvas, which is the case for screenshots
189
+ let scale = baseScale;
190
+ if (scaleWithCameraDistance) {
191
+ const meshWorldPos = anchorMesh.getAbsolutePosition();
192
+ // calculate camera world position manually, as there is no help function like for meshes
193
+ const camWorldMatrix = camera.computeWorldMatrix();
194
+ const camWorldPos = camWorldMatrix.getTranslation();
195
+ const distance = __1.Vector3.Distance(meshWorldPos, camWorldPos);
196
+ const frustumSlopeY = Math.tan(camera.fov / 2);
197
+ // if the distance from camera to mesh gets larger, the html elements scaling will be decreased
198
+ // we also consider the cameras FOV, so scale 1 means, that the resulting vertical frustum of the camera
199
+ // distance equals 1
200
+ // ...this is probably too small in some scenarios, so we might have to add a general scale setting here
201
+ scale *= 1 / (distance * frustumSlopeY);
202
+ }
203
+ const elementXOffset = (parentHtmlElement.offsetWidth * scale) / 2;
204
+ const elementYOffset = (parentHtmlElement.offsetHeight * scale) / 2;
205
+ // finally move and scale the HTML element
206
+ parentHtmlElement.style.transform = `translate3d(calc(${vertexScreenCoords.x}px - 50%), calc(${vertexScreenCoords.y}px - 50%), 0px) scale(${scale})`;
207
+ // check for occlusion if desired
208
+ // we use the opacity setting, which could also be animated nicely if we want
209
+ const isInViewport = vertexScreenCoords.x - elementXOffset > 0 &&
210
+ vertexScreenCoords.x + elementXOffset < width &&
211
+ vertexScreenCoords.y - elementYOffset > 0 &&
212
+ vertexScreenCoords.y + elementYOffset < height;
213
+ const isOccluded = hideIfOccluded && anchorMesh.isOccluded;
214
+ parentHtmlElement.style.opacity = isInViewport && !isOccluded ? '1' : '0';
215
+ }
216
+ _getOrCreateAnchorMeshMaterial() {
217
+ if (this._anchorMeshMaterial) {
218
+ return this._anchorMeshMaterial;
219
+ }
220
+ this._anchorMeshMaterial = new __1.StandardMaterial('$matAnchorMesh');
221
+ this._anchorMeshMaterial.alpha = 0;
222
+ this.viewer.scene.removeMaterial(this._anchorMeshMaterial);
223
+ return this._anchorMeshMaterial;
224
+ }
225
+ }
226
+ exports.HtmlAnchorManager = HtmlAnchorManager;
227
+ HtmlAnchorManager._HTML_ANCHOR_KEY = '$htmlAnchor';
228
+ //# sourceMappingURL=html-anchor-manager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"html-anchor-manager.js","sourceRoot":"","sources":["../../../src/manager/html-anchor-manager.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,0BAYY;AACZ,8DAAsC;AAmCtC;;;;;;;;GAQG;AACH,MAAa,iBAAiB;IAa5B,gBAAgB;IAChB,YAA6B,MAAc;QAAd,WAAM,GAAN,MAAM,CAAQ;QAXjC,iBAAY,GAMlB,EAAE,CAAC;QAEG,wBAAmB,GAA4B,IAAI,CAAC;QAI5D,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;QAC7B,IAAI,CAAC,MAAM,EAAE;YACX,OAAO;SACR;QAED,0EAA0E;QAC1E,MAAM,CAAC,KAAK,CAAC,6BAA6B,CAAC,GAAG,CAAC,GAAG,EAAE;YAClD,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,OAAO,CAAC,CAAC,EAAE,iBAAiB,EAAE,UAAU,EAAE,OAAO,EAAE,EAAE,EAAE;gBACtF,IAAI,CAAC,iBAAiB,CACpB,iBAAiB,EACjB,UAAU,EACV,MAAM,CAAC,KAAK,CAAC,YAAa,EAC1B,MAAM,CAAC,KAAK,EACZ,MAAM,CAAC,MAAM,EACb,CAAC,EACD,OAAO,CACR,CAAC;YACJ,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC;IAED;;;;OAIG;IACI,aAAa,CAAC,IAAY,EAAE,WAAwB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AG,CAAC,CAAC;QACnE,MAAM,cAAc,GAAG,CAAC,iBAAiB,CAAC,YAAY,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC;QACpE,0CAA0C;QAC1C,iBAAiB,CAAC,KAAK,CAAC,SAAS,GAAG,oBAAoB,kBAAkB,CAAC,CAAC,mBAAmB,kBAAkB,CAAC,CAAC,yBAAyB,KAAK,GAAG,CAAC;QAErJ,iCAAiC;QACjC,6EAA6E;QAC7E,MAAM,YAAY,GAChB,kBAAkB,CAAC,CAAC,GAAG,cAAc,GAAG,CAAC;YACzC,kBAAkB,CAAC,CAAC,GAAG,cAAc,GAAG,KAAK;YAC7C,kBAAkB,CAAC,CAAC,GAAG,cAAc,GAAG,CAAC;YACzC,kBAAkB,CAAC,CAAC,GAAG,cAAc,GAAG,MAAM,CAAC;QACjD,MAAM,UAAU,GAAG,cAAc,IAAI,UAAU,CAAC,UAAU,CAAC;QAC3D,iBAAiB,CAAC,KAAK,CAAC,OAAO,GAAG,YAAY,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC;IAC5E,CAAC;IAES,8BAA8B;QACtC,IAAI,IAAI,CAAC,mBAAmB,EAAE;YAC5B,OAAO,IAAI,CAAC,mBAAmB,CAAC;SACjC;QAED,IAAI,CAAC,mBAAmB,GAAG,IAAI,oBAAgB,CAAC,gBAAgB,CAAC,CAAC;QAClE,IAAI,CAAC,mBAAmB,CAAC,KAAK,GAAG,CAAC,CAAC;QACnC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,cAAc,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAC;QAC3D,OAAO,IAAI,CAAC,mBAAmB,CAAC;IAClC,CAAC;;AAjRH,8CAkRC;AAjR2B,kCAAgB,GAAG,aAAa,CAAC"}
@@ -1,18 +1,5 @@
1
1
  import { AssetContainer, DecalConfiguration, TransformNode, Viewer } from '../index';
2
- /**
3
- * Contains cbn custom data, like decals.
4
- * This is just a temporary type, as the `loadAssetContainer` function only returns an asset container, which can be
5
- * altered by our file loader plugin.
6
- * After loading the model, `cbnData` is cropped and a pure asset container is available for further processing.
7
- *
8
- * @internal
9
- */
10
- export declare class ExtendedAssetContainer extends AssetContainer {
11
- cbnData?: CbnBabylonFileData;
12
- }
13
- declare type CbnBabylonFileData = {
14
- decals?: ParsedDecalConfiguration[];
15
- };
2
+ import { BaseAsset } from '../internal/asset-helper';
16
3
  export declare type ParsedDecalConfiguration = DecalConfiguration & {
17
4
  materialId?: string;
18
5
  tags?: string;
@@ -45,17 +32,12 @@ export declare type ModelCloneOptions = {
45
32
  nodeNamingStrategy?: NodeNamingStrategy;
46
33
  tagNamingStrategy?: TagNamingStrategy;
47
34
  };
48
- declare type Model = {
49
- name: string;
50
- url: string;
51
- state: ModelAssetState;
52
- assetContainer: AssetContainer;
53
- cbnBabylonFileData?: CbnBabylonFileData;
35
+ declare type ModelAsset = BaseAsset & {
36
+ decals?: ParsedDecalConfiguration[];
54
37
  isClone: boolean;
55
38
  sourceModelName?: string;
56
39
  visibilityCallId?: number;
57
40
  };
58
- declare type ModelAssetState = 'notLoaded' | 'loading' | 'loaded' | 'inScene';
59
41
  /**
60
42
  * Manager for handling 3d models.\
61
43
  * Responsible for loading models and handling their visibility.\
@@ -65,13 +47,12 @@ export declare class ModelManager {
65
47
  protected viewer: Viewer;
66
48
  /**
67
49
  * CAUTION: this has to be in sync with the Combeenation backend!
68
- * @internal
69
50
  */
70
51
  static readonly CBN_FALLBACK_MODEL_ASSET_NAME = "$fallback";
71
52
  protected _modelAssets: {
72
- [name: string]: Model;
53
+ [name: string]: ModelAsset;
73
54
  };
74
- protected _fallbackModelAsset: Model;
55
+ protected _fallbackModelAsset: ModelAsset;
75
56
  protected _loadModelPromises: {
76
57
  [modelName: string]: Promise<void>;
77
58
  };
@@ -84,6 +65,7 @@ export declare class ModelManager {
84
65
  * This function converts slash to dot notation, so that models can be target with slash and dot notation alike.
85
66
  */
86
67
  protected static _replaceSlashes(inputStr: string): string;
68
+ /** @internal */
87
69
  constructor(viewer: Viewer);
88
70
  /**
89
71
  * Creates content for the fallback model, which is actually just a black cube.
@@ -150,17 +132,17 @@ export declare class ModelManager {
150
132
  /**
151
133
  * Get model by name
152
134
  */
153
- protected _getModel(name: string): Model | undefined;
135
+ protected _getModel(name: string): ModelAsset | undefined;
154
136
  /**
155
137
  * Load model into scene, but don't show it immediately
156
138
  */
157
- protected _loadModel(model: Model): Promise<void>;
139
+ protected _loadModel(model: ModelAsset): Promise<void>;
158
140
  /**
159
141
  * Apply parameter to the model in the asset container.
160
142
  * This is typically done before the model is added to the scene to avoid changes on the visible model, which ensures
161
143
  * a smooth model switch behaviour.
162
144
  */
163
- protected _prepareModelForScene(model: Model): Promise<void>;
145
+ protected _prepareModelForScene(model: ModelAsset): Promise<void>;
164
146
  /**
165
147
  * Add assets of asset container to scene, do the scene preparation if required.
166
148
  * CAUTION: model is expected to be in the correct loading state already.
@@ -168,15 +150,10 @@ export declare class ModelManager {
168
150
  * @param skipPreparation optionally skip applying parameter values to model before showing it
169
151
  * (see {@link _prepareModelForScene})
170
152
  */
171
- protected _showModel(model: Model, skipPreparation?: boolean): Promise<void>;
153
+ protected _showModel(model: ModelAsset, skipPreparation?: boolean): Promise<void>;
172
154
  /**
173
155
  * Remove assets of asset container from scene
174
156
  */
175
- protected _hideModel(model: Model): void;
176
- /**
177
- * Creates and assigns each "deferred" material to the corresponding mesh, if the mesh is visible.
178
- * Model should be ready to use immediately after this function has done it's job.
179
- */
180
- protected _applyDeferredMaterialsForAllVisibleMeshes(model: Model): Promise<void>;
157
+ protected _hideModel(model: ModelAsset): void;
181
158
  }
182
159
  export {};
@@ -9,28 +9,18 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.ModelManager = exports.ExtendedAssetContainer = void 0;
12
+ exports.ModelManager = void 0;
13
13
  const index_1 = require("../index");
14
+ const asset_helper_1 = require("../internal/asset-helper");
14
15
  const cloning_helper_1 = require("../internal/cloning-helper");
15
- const metadata_helper_1 = require("../internal/metadata-helper");
16
16
  const lodash_es_1 = require("lodash-es");
17
- /**
18
- * Contains cbn custom data, like decals.
19
- * This is just a temporary type, as the `loadAssetContainer` function only returns an asset container, which can be
20
- * altered by our file loader plugin.
21
- * After loading the model, `cbnData` is cropped and a pure asset container is available for further processing.
22
- *
23
- * @internal
24
- */
25
- class ExtendedAssetContainer extends index_1.AssetContainer {
26
- }
27
- exports.ExtendedAssetContainer = ExtendedAssetContainer;
28
17
  /**
29
18
  * Manager for handling 3d models.\
30
19
  * Responsible for loading models and handling their visibility.\
31
20
  * Also contains advanced features like model cloning.
32
21
  */
33
22
  class ModelManager {
23
+ /** @internal */
34
24
  constructor(viewer) {
35
25
  this.viewer = viewer;
36
26
  this._modelAssets = {};
@@ -83,7 +73,7 @@ class ModelManager {
83
73
  for (const { name, url } of modelAssets) {
84
74
  const existingModel = this._modelAssets[name];
85
75
  if (existingModel) {
86
- console.warn(`Model ${name} is already registered`);
76
+ console.warn(`Model "${name}" is already registered`);
87
77
  return;
88
78
  }
89
79
  const model = { name, url, state: 'notLoaded', assetContainer: new index_1.AssetContainer(), isClone: false };
@@ -107,7 +97,7 @@ class ModelManager {
107
97
  });
108
98
  }
109
99
  if (model.state !== 'notLoaded') {
110
- console.warn(`Model ${name} is already loaded or currently loading`);
100
+ console.warn(`Model "${name}" is already loaded or currently loading`);
111
101
  return;
112
102
  }
113
103
  yield this._loadModel(model);
@@ -121,14 +111,14 @@ class ModelManager {
121
111
  * @returns Array of changed visibility status, combined with the corresponding model name
122
112
  */
123
113
  setModelVisibility(modelVisibility) {
124
- var _a;
125
114
  return __awaiter(this, void 0, void 0, function* () {
126
- const showModels = [];
127
- const hideModels = [];
115
+ const modelsToShow = [];
116
+ const modelsToHide = [];
128
117
  if (!(0, lodash_es_1.isArray)(modelVisibility)) {
129
118
  modelVisibility = [modelVisibility];
130
119
  }
131
- for (const entry of modelVisibility) {
120
+ const loadModelProms = modelVisibility.map((entry) => __awaiter(this, void 0, void 0, function* () {
121
+ var _a;
132
122
  const model = this._getModel(entry.name);
133
123
  if (!model) {
134
124
  throw new index_1.ViewerError({
@@ -139,50 +129,61 @@ class ModelManager {
139
129
  // there can be multiple "setModelVisibility" calls while the model is loading
140
130
  // loading can be awaited, but it has to be ensured, that the last call of "setModelVisibility" has priority
141
131
  // therefore we store the id of the call in the model
142
- const curVisibilityCallId = ((_a = model.visibilityCallId) !== null && _a !== void 0 ? _a : 0) + 1;
143
- model.visibilityCallId = curVisibilityCallId;
132
+ model.visibilityCallId = ((_a = model.visibilityCallId) !== null && _a !== void 0 ? _a : 0) + 1;
133
+ const curVisibilityCallId = model.visibilityCallId;
134
+ let showModel = false;
135
+ let hideModel = false;
144
136
  if (entry.visible) {
145
137
  if (model.state === 'notLoaded') {
146
138
  yield this._loadModel(model);
147
139
  // check if this is still the latest visibility call
148
140
  if (model.visibilityCallId === curVisibilityCallId) {
149
- showModels.push(model);
141
+ showModel = true;
150
142
  }
151
143
  }
152
144
  else if (model.state === 'loading') {
153
145
  yield this._loadModelPromises[model.name];
154
146
  if (model.visibilityCallId === curVisibilityCallId) {
155
- showModels.push(model);
147
+ showModel = true;
156
148
  }
157
149
  }
158
150
  else if (model.state === 'loaded') {
159
- showModels.push(model);
151
+ showModel = true;
160
152
  }
161
153
  }
162
154
  else {
163
155
  if (model.state === 'loading') {
164
156
  yield this._loadModelPromises[model.name];
165
157
  if (model.visibilityCallId === curVisibilityCallId) {
166
- hideModels.push(model);
158
+ hideModel = true;
167
159
  }
168
160
  }
169
161
  else if (model.state === 'inScene') {
170
- hideModels.push(model);
162
+ hideModel = true;
171
163
  }
172
164
  }
173
- }
174
- for (const showModel of showModels) {
175
- yield this._prepareModelForScene(showModel);
176
- }
177
- for (const showModel of showModels) {
178
- yield this._showModel(showModel, true);
179
- }
180
- for (const hideModel of hideModels) {
181
- this._hideModel(hideModel);
182
- }
165
+ if (showModel) {
166
+ yield this._prepareModelForScene(model);
167
+ modelsToShow.push(model);
168
+ }
169
+ else if (hideModel) {
170
+ modelsToHide.push(model);
171
+ }
172
+ }));
173
+ // model loading and preparation (e.g. create materials) is done simultaniously for all models to save time
174
+ // model (`ModelManager._loadModelPromises`) and material queues (`MaterialManager._createMaterialPromises`) are
175
+ // responsible for correct loading state handling of these instances
176
+ yield Promise.all(loadModelProms);
183
177
  const returnVal = [];
184
- showModels.forEach(showModel => returnVal.push({ name: showModel.name, visible: true }));
185
- hideModels.forEach(hideModel => returnVal.push({ name: hideModel.name, visible: false }));
178
+ modelsToShow.forEach(model => {
179
+ // show model is not async, as preparation has already been done
180
+ this._showModel(model, true);
181
+ returnVal.push({ name: model.name, visible: true });
182
+ });
183
+ modelsToHide.forEach(model => {
184
+ this._hideModel(model);
185
+ returnVal.push({ name: model.name, visible: false });
186
+ });
186
187
  return returnVal;
187
188
  });
188
189
  }
@@ -295,7 +296,7 @@ class ModelManager {
295
296
  * be useful e.g. for alterning decals.
296
297
  */
297
298
  getDecalsConfigurationOfModel(name) {
298
- var _a, _b;
299
+ var _a;
299
300
  return __awaiter(this, void 0, void 0, function* () {
300
301
  const model = this._getModel(name);
301
302
  if (!model) {
@@ -313,14 +314,14 @@ class ModelManager {
313
314
  if (model.state !== 'inScene') {
314
315
  yield this._prepareModelForScene(model);
315
316
  }
316
- return (_b = (_a = model.cbnBabylonFileData) === null || _a === void 0 ? void 0 : _a.decals) !== null && _b !== void 0 ? _b : [];
317
+ return (_a = model.decals) !== null && _a !== void 0 ? _a : [];
317
318
  });
318
319
  }
319
320
  /**
320
321
  * Get model by name
321
322
  */
322
323
  _getModel(name) {
323
- if (name === '$fallback') {
324
+ if (name === ModelManager.CBN_FALLBACK_MODEL_ASSET_NAME) {
324
325
  return this._fallbackModelAsset;
325
326
  }
326
327
  const replacedName = ModelManager._replaceSlashes(name);
@@ -333,53 +334,12 @@ class ModelManager {
333
334
  _loadModel(model) {
334
335
  return __awaiter(this, void 0, void 0, function* () {
335
336
  const loadModelPromise = () => __awaiter(this, void 0, void 0, function* () {
336
- model.state = 'loading';
337
- const curEnvTexture = this.viewer.scene.environmentTexture;
338
- const curEnvIntensity = this.viewer.scene.environmentIntensity;
339
- // CB-9240: Babylon.js doesn't recognize gzipped babylon files (`.babylon.gz`) as such, leading to a warning
340
- // message, therefore we overwrite the plugin extension actively for such files
341
- let pluginExtension;
342
- try {
343
- // URL constructor can throw for "valid" URL, which happened to be the case for the test asset environment where
344
- // the urls are relative (starting with ".")
345
- const urlObj = new URL(model.url);
346
- if (urlObj.pathname.endsWith('.babylon.gz')) {
347
- pluginExtension = '.babylon';
348
- }
349
- }
350
- catch (e) { }
351
- let assetContainer;
352
- try {
353
- const fullContainer = (yield index_1.SceneLoader.LoadAssetContainerAsync('', model.url, this.viewer.scene, undefined, pluginExtension));
354
- // crop and store custom cbn data from .babylon file
355
- model.cbnBabylonFileData = fullContainer.cbnData;
356
- delete fullContainer.cbnData;
357
- // from here it's a basic asset container again
358
- assetContainer = fullContainer;
359
- }
360
- catch (e) {
361
- throw new index_1.ViewerError({
362
- id: index_1.ViewerErrorIds.AssetLoadingFailed,
363
- message: e.message,
364
- });
365
- }
337
+ const { cbnData } = yield (0, asset_helper_1.loadAsset)(model, this.viewer);
338
+ model.decals = cbnData === null || cbnData === void 0 ? void 0 : cbnData.decals;
366
339
  // remove all lights and cameras from the asset, as this data should be handled globally in the scene instead of
367
340
  // being in a model context
368
- [...assetContainer.lights].forEach(light => light.dispose());
369
- [...assetContainer.cameras].forEach(camera => camera.dispose());
370
- // materials should be a "global" thing and not assigned to an asset container
371
- // this is not relevant in most of the cases, since materials are cropped from babylon models on the CBN server
372
- // anyway
373
- assetContainer.materials.forEach(material => {
374
- this.viewer.scene.addMaterial(material);
375
- material._parentContainer = null;
376
- });
377
- assetContainer.materials = [];
378
- // environment texture and intensity has been overwritten by load asset container function
379
- this.viewer.scene.environmentTexture = curEnvTexture;
380
- this.viewer.scene.environmentIntensity = curEnvIntensity;
381
- model.assetContainer = assetContainer;
382
- model.state = 'loaded';
341
+ [...model.assetContainer.lights].forEach(light => light.dispose());
342
+ [...model.assetContainer.cameras].forEach(camera => camera.dispose());
383
343
  delete this._loadModelPromises[model.name];
384
344
  });
385
345
  this._loadModelPromises[model.name] = loadModelPromise();
@@ -401,10 +361,7 @@ class ModelManager {
401
361
  const sourceModel = this._getModel(model.sourceModelName);
402
362
  yield this._prepareModelForScene(sourceModel);
403
363
  }
404
- yield this.viewer.parameterManager.applyAllParameterValuesToModel(model.assetContainer);
405
- // parameter manager did his job, now apply the deferred materials to all meshes that are not explicitely hidden by
406
- // the parameter manager
407
- yield this._applyDeferredMaterialsForAllVisibleMeshes(model);
364
+ yield (0, asset_helper_1.prepareAssetForScene)(model, this.viewer);
408
365
  });
409
366
  }
410
367
  /**
@@ -430,27 +387,10 @@ class ModelManager {
430
387
  model.assetContainer.removeFromScene();
431
388
  model.state = 'loaded';
432
389
  }
433
- /**
434
- * Creates and assigns each "deferred" material to the corresponding mesh, if the mesh is visible.
435
- * Model should be ready to use immediately after this function has done it's job.
436
- */
437
- _applyDeferredMaterialsForAllVisibleMeshes(model) {
438
- return __awaiter(this, void 0, void 0, function* () {
439
- for (const mesh of model.assetContainer.meshes) {
440
- const deferredMaterial = (0, metadata_helper_1.getInternalMetadataValue)(mesh, 'deferredMaterial');
441
- const rawVisibleValue = this.viewer.parameterManager.getParameterValueOfNode(mesh, index_1.BuiltInParameter.Visible);
442
- const visible = rawVisibleValue === undefined || index_1.ParameterManager.parseBoolean(rawVisibleValue) === true;
443
- if (deferredMaterial && visible) {
444
- yield this.viewer.materialManager.setMaterialOnMesh(deferredMaterial, mesh);
445
- }
446
- }
447
- });
448
- }
449
390
  }
450
391
  exports.ModelManager = ModelManager;
451
392
  /**
452
393
  * CAUTION: this has to be in sync with the Combeenation backend!
453
- * @internal
454
394
  */
455
395
  ModelManager.CBN_FALLBACK_MODEL_ASSET_NAME = '$fallback';
456
396
  //# sourceMappingURL=model-manager.js.map