@combeenation/3d-viewer 7.0.0-beta3 → 7.1.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@combeenation/3d-viewer",
3
- "version": "7.0.0-beta3",
3
+ "version": "7.1.0-alpha1",
4
4
  "description": "Combeenation 3D Viewer",
5
5
  "homepage": "https://github.com/Combeenation/3d-viewer#readme",
6
6
  "bugs": {
@@ -30,7 +30,7 @@ export const emitter = new EventEmitter();
30
30
  * viewer.on(Event.SCENE_PROCESSING_END, scene => {
31
31
  * scene.clearColor = new Color4(0, 0, 0, 0);
32
32
  * });
33
- * await viewer.bootstrap();
33
+ * await viewer.bootstrap([]);
34
34
  * ```
35
35
  */
36
36
  export class Event {
@@ -268,7 +268,7 @@ export class Event {
268
268
  * * {@link Viewer}
269
269
  *
270
270
  * Payload:
271
- * * viewer: {@link viewer}
271
+ * * viewer: {@link Viewer}
272
272
  */
273
273
  public static readonly VARIANT_INSTANCES_READY = 'variantInstancesReady';
274
274
 
@@ -31,7 +31,7 @@ export abstract class ParameterObservable extends EventBroadcaster {
31
31
  * The {@link ParameterObserver} gets 3 parameters: the {@link ParameterObservable}, the old {@link ParameterValue}
32
32
  * and the new {@link ParameterValue}.
33
33
  *
34
- * See {@page ../../../doc/documentation/Parameters.md} for an example.
34
+ * See [Parameters](https://3dviewer.docs.combeenation.com/pages/documentation/Parameters.html) for an example.
35
35
  */
36
36
  public addParameterObserver(parameter: string, observer: ParameterObserver): ParameterObservable {
37
37
  if (this.parameterObservers.has(parameter)) {
@@ -270,7 +270,7 @@ export class Viewer extends EventBroadcaster {
270
270
  * @emits {@link Event.BOOTSTRAP_START}
271
271
  * @emits {@link Event.BOOTSTRAP_END}
272
272
  */
273
- public async bootstrap(tagManagerParameterValues?: TagManagerParameterValue[]): Promise<Viewer> {
273
+ public async bootstrap(tagManagerParameterValues: TagManagerParameterValue[]): Promise<Viewer> {
274
274
  this.broadcastEvent(Event.BOOTSTRAP_START, this);
275
275
  let indexJson;
276
276
  if (isString(this.structureJson)) {
@@ -565,9 +565,9 @@ export class Viewer extends EventBroadcaster {
565
565
  * Resets everything by calling {@link destroy} to clear all references and {@link bootstrap} to setup a clean
566
566
  * environment
567
567
  */
568
- public async reset(): Promise<Viewer> {
568
+ public async reset(tagManagerParameterValues: TagManagerParameterValue[]): Promise<Viewer> {
569
569
  await this.destroy();
570
- return this.bootstrap();
570
+ return this.bootstrap(tagManagerParameterValues);
571
571
  }
572
572
 
573
573
  /**
@@ -416,12 +416,13 @@ const setMaterial = function (node: TransformNode, materialId: string, deep: boo
416
416
  }
417
417
  } else {
418
418
  // create material and apply it when textures have been loaded
419
- const material = getOrCreateMaterial(node.getScene(), materialId, variant);
420
- applyMaterial(material, node).then(() => emitter.emit(Event.MESH_MATERIAL_APPLIED, node, material));
419
+ getOrCreateMaterial(node.getScene(), materialId, variant).then(material => {
420
+ applyMaterial(material, node).then(() => emitter.emit(Event.MESH_MATERIAL_APPLIED, node, material));
421
421
 
422
- if (hasMissingMaterial) {
423
- delete node.metadata[missingMaterialMetadataName];
424
- }
422
+ if (hasMissingMaterial) {
423
+ delete node.metadata[missingMaterialMetadataName];
424
+ }
425
+ });
425
426
  }
426
427
  }
427
428
  // recursively set materials on children (if desired)
@@ -436,11 +437,11 @@ const setMaterial = function (node: TransformNode, materialId: string, deep: boo
436
437
  * Gets the Material either from the given {@link Variant}, the given scene or tries to create it from an Combeenation
437
438
  * material asset when inside a Combeenation configurator.
438
439
  */
439
- const getOrCreateMaterial = function (scene: Scene, materialId: string, variant?: Variant): Material {
440
+ const getOrCreateMaterial = async function (scene: Scene, materialId: string, variant?: Variant): Promise<Material> {
440
441
  let chosenMaterial: Material | undefined | null;
441
442
  chosenMaterial = variant?.inheritedMaterials.find(mat => mat.id === materialId);
442
443
  chosenMaterial = chosenMaterial || scene.materials.find(mat => mat.id === materialId);
443
- chosenMaterial = chosenMaterial || createMaterialFromCbnAssets(materialId, scene);
444
+ chosenMaterial = chosenMaterial || (await createMaterialFromCbnAssets(materialId, scene));
444
445
  if (chosenMaterial) {
445
446
  return chosenMaterial as Material;
446
447
  }
@@ -456,6 +456,10 @@ type SpecGenerationData = {
456
456
  url: string;
457
457
  };
458
458
 
459
+ /**
460
+ * Key = Old tag name\
461
+ * Value = New tag name
462
+ */
459
463
  type TagMapping = {
460
464
  [tagName: string]: string;
461
465
  };
@@ -67,7 +67,7 @@ export const getMaterialPostLoadObserver = function (concerningMesh: Mesh) {
67
67
  // get id of missing material
68
68
  const missingMatId = concerningMesh.metadata[missingMaterialMetadataName];
69
69
  // get material and apply it on the concerning mesh after all textures have been loaded
70
- const material = getOrCreateMaterial(concerningMesh.getScene(), missingMatId);
70
+ const material = await getOrCreateMaterial(concerningMesh.getScene(), missingMatId);
71
71
  applyMaterial(material, concerningMesh).then(() =>
72
72
  emitter.emit(Event.MESH_MATERIAL_APPLIED, concerningMesh, material)
73
73
  );
@@ -160,8 +160,8 @@ export const removeMissingMaterialObserver = function (node: BjsNode) {
160
160
  * @param scene Babylon.js scene
161
161
  * @returns PBRMaterial | null
162
162
  */
163
- export const createMaterialFromCbnAssets = function (materialId: string, scene: Scene): Material | null {
164
- const materialDefinition = window.Cbn?.Assets.getMaterial(materialId);
163
+ export const createMaterialFromCbnAssets = async function (materialId: string, scene: Scene): Promise<Material | null> {
164
+ const materialDefinition = await window.Cbn?.Assets.getMaterial(materialId);
165
165
  // The generic `Material.Parse` actually returns a more specific material like `BABYLON.StandardMaterial`,
166
166
  // `BABYLON.PBRMaterial` or stuff like `BABYLON.PBRMetallicRoughnessMaterial` etc. based on the given `customType`
167
167
  // within the material JSON definition
package/src/dev.ts CHANGED
@@ -23,7 +23,7 @@ document.addEventListener('DOMContentLoaded', main);
23
23
 
24
24
  window.Cbn = {
25
25
  Assets: {
26
- getMaterial(materialId: string) {
26
+ async getMaterial(materialId: string) {
27
27
  //! this creates a new function on the object that uses the imported function of the same name..
28
28
  const material = getMaterial(materialId);
29
29
  if (material) return material;
package/src/types.d.ts CHANGED
@@ -8,14 +8,17 @@ interface Window {
8
8
  | {
9
9
  Assets: {
10
10
  /**
11
- * Retrieve material definition from configurator
11
+ * Retrieve material definition from configurator\
12
+ * Implementation depends on the Combeenation environment the viewer is used in
13
+ * - Configurator: Access pre-fetched material JSON objects from Cbn client => synchronous
14
+ * - Asset Editor: Load content from material asset on demand => asynchronous!
12
15
  *
13
16
  * @param materialId
14
17
  *
15
18
  * @return Undefined if no definition for the given material name exists, otherwise an "JSON object" which can
16
19
  * be passed to `BABYLON.Material.Parse` to create a runtime material object.
17
20
  */
18
- getMaterial(materialId: string): object | undefined;
21
+ getMaterial(materialId: string): Promise<object | undefined>;
19
22
 
20
23
  /**
21
24
  * Checks if a definition for a given material name exists in the configurator and issues a warning if not.