@combeenation/3d-viewer 20.0.1 → 21.0.0-alpha1

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.
@@ -25,6 +25,7 @@ export class DebugManager {
25
25
 
26
26
  protected _axesViewer: AxesViewer | null = null;
27
27
  protected _showBoundingSphereForAutofocus: boolean = false;
28
+ protected _parentDomElementForInspector: HTMLElement | null = null;
28
29
 
29
30
  /** @internal */
30
31
  public constructor(protected viewer: Viewer) {}
@@ -40,7 +41,16 @@ export class DebugManager {
40
41
  }
41
42
 
42
43
  /**
43
- * Enables the Babylon.js [Inspector](https://doc.babylonjs.com/legacy/inspector/).\
44
+ * Registers a parent DOM element to use as root for the Babylon.js inspector.
45
+ * When set and no explicit `options` are passed to {@link showInspector}, this element will be used
46
+ * as `globalRoot`, which avoids interference with the surrounding application layout.
47
+ */
48
+ public registerParentDomElementForInspector(el: HTMLElement): void {
49
+ this._parentDomElementForInspector = el;
50
+ }
51
+
52
+ /**
53
+ * Enables the Babylon.js [Inspector](https://doc.babylonjs.com/legacy/inspector()).\
44
54
  * Due to the additional size of the inspector, this function is only available in "development" builds!
45
55
  *
46
56
  * @returns Signalizes if inspector could be loaded
@@ -49,12 +59,16 @@ export class DebugManager {
49
59
  if (process.env.NODE_ENV === 'development') {
50
60
  const inspModule = await import(/* webpackChunkName: "inspector"*/ '@babylonjs/inspector');
51
61
 
52
- if (!options && window.Cbn) {
62
+ const parentEl =
63
+ this._parentDomElementForInspector ??
64
+ // fallback to legacy `window.Cbn` call to support "old" cfgrs (pre Editor V2)
65
+ window.Cbn?.utils?.Viewer3dHelper?.getCfgrParentDomElementForInspector?.();
66
+
67
+ if (!options && parentEl) {
53
68
  // special case for usage in Combeenation configurator:
54
69
  // if no options are set the inspector will be rendered into the parent element of the configurator
55
70
  // in this way the configurator layout itself will not be affected by the inspector
56
- const cfgrParentEl = window.Cbn.utils.Viewer3dHelper.getCfgrParentDomElementForInspector();
57
- inspModule.Inspector.Show(this.viewer.scene, { globalRoot: cfgrParentEl });
71
+ inspModule.Inspector.Show(this.viewer.scene, { globalRoot: parentEl });
58
72
  } else {
59
73
  inspModule.Inspector.Show(this.viewer.scene, options ?? {});
60
74
  }
@@ -30,12 +30,17 @@ export class MaterialManager {
30
30
  */
31
31
  public static readonly CBN_FALLBACK_MATERIAL_NAME = '$fallback';
32
32
 
33
+ protected _materialDefinitions: { [materialId: string]: object } = {};
33
34
  protected _clonedMaterials: { [name: string]: Material } = {};
34
35
  protected _createMaterialPromises: { [materialId: string]: Promise<Material | null> } = {};
35
36
 
36
37
  /** @internal */
37
38
  public constructor(protected viewer: Viewer) {}
38
39
 
40
+ public registerMaterials(materialDefinitions: { [materialId: string]: object }): void {
41
+ this._materialDefinitions = materialDefinitions;
42
+ }
43
+
39
44
  /**
40
45
  * Assigns material with certain id to desired mesh.\
41
46
  * Creates the material if not already available (see {@link getOrCreateMaterial}).
@@ -56,9 +61,9 @@ export class MaterialManager {
56
61
 
57
62
  /**
58
63
  * Returns material with certain id if already available in the scene.\
59
- * If this is not the case material is created from a
60
- * "[Material asset](https://docs.combeenation.com/docs/howto-create-and-use-babylon-and-material-asset)"
61
- * on the Combeenation server.\
64
+ * If this is not the case, material is created from registered material definitions, which are most likely coming
65
+ * from "[Material assets](https://docs.combeenation.com/docs/howto-create-and-use-babylon-and-material-asset)" on the
66
+ * Combeenation server.\
62
67
  * Waits until textures of material are fully loaded and shader is compiled. In this way "flickering" effects
63
68
  * will be avoided, since the material would be incomplete without its loaded textures.
64
69
  *
@@ -78,7 +83,7 @@ export class MaterialManager {
78
83
  this.viewer.eventManager.fireEvent(ViewerEvent.MaterialCreationStart, materialId);
79
84
 
80
85
  // request not pending, call the dedicated function
81
- const newCreationProm = this._createFromMaterialAsset(materialId, mesh);
86
+ const newCreationProm = this._createFromMaterialDefinition(materialId, mesh);
82
87
  // store the promise in a global map, so that subsequent requests can reference it
83
88
  this._createMaterialPromises[materialId] = newCreationProm;
84
89
  chosenMaterial = await newCreationProm;
@@ -153,7 +158,28 @@ export class MaterialManager {
153
158
  Object.keys(this._clonedMaterials).forEach(materialId => this.deleteClonedMaterial(materialId));
154
159
  }
155
160
 
156
- protected async _createFromMaterialAsset(materialId: string, mesh?: AbstractMesh): Promise<Material | null> {
161
+ /**
162
+ * Get material defintion from registered material definitions or from legacy `Cbn.Assets.getMaterial` call
163
+ *
164
+ * @internal
165
+ */
166
+ public async getMaterialDefinition(materialId: string): Promise<object | undefined> {
167
+ let definition: object | undefined = this._materialDefinitions[materialId];
168
+ if (!definition && window.Cbn?.Assets?.getMaterial) {
169
+ // fallback to legacy `Cbn.Assets.getMaterial` call to support "old" cfgrs (pre Editor V2)
170
+ definition = await window.Cbn.Assets.getMaterial(materialId);
171
+ }
172
+
173
+ if (!definition) {
174
+ console.warn(
175
+ `Material definition for "${materialId}" couldn't be found. Material might not be registered or Material Asset from Combeenation server does not exist or is not connected to the configurator.`
176
+ );
177
+ }
178
+
179
+ return definition;
180
+ }
181
+
182
+ protected async _createFromMaterialDefinition(materialId: string, mesh?: AbstractMesh): Promise<Material | null> {
157
183
  if (materialId === MaterialManager.CBN_FALLBACK_MATERIAL_NAME) {
158
184
  const fallbackMaterial = new StandardMaterial(MaterialManager.CBN_FALLBACK_MATERIAL_NAME, this.viewer.scene);
159
185
  fallbackMaterial.disableLighting = true;
@@ -161,16 +187,8 @@ export class MaterialManager {
161
187
  return fallbackMaterial;
162
188
  }
163
189
 
164
- if (!window.Cbn) {
165
- return null;
166
- }
167
-
168
- const materialDefinition = await window.Cbn.Assets.getMaterial(materialId);
169
-
190
+ const materialDefinition = await this.getMaterialDefinition(materialId);
170
191
  if (!materialDefinition) {
171
- console.warn(
172
- `Trying to create material "${materialId}" from Combeenation asset but according asset does not exist or is not connected to the configurator.`
173
- );
174
192
  return null;
175
193
  }
176
194
 
@@ -584,7 +584,7 @@ export class ParameterManager {
584
584
  */
585
585
  protected _addBuiltInParameterObservers(): void {
586
586
  createBuiltInParameter(this, this.viewer.materialManager);
587
- createBuiltInTextureParameter(this, this.viewer.scene);
587
+ createBuiltInTextureParameter(this, this.viewer.materialManager, this.viewer.scene);
588
588
  createPaintableParameter(this, this.viewer.scene);
589
589
  }
590
590