@combeenation/3d-viewer 5.0.0-ar2 → 5.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.
@@ -11,6 +11,8 @@ import { VariantInstance } from '../classes/variantInstance';
11
11
  * {@link Viewer} instance via its {@link Viewer.variantInstances}
12
12
  */
13
13
  export class VariantInstanceManager extends EventBroadcaster {
14
+ protected variantInstancePromises: Map<string, Promise<VariantInstance>> = new Map();
15
+
14
16
  protected variantInstances: Map<string, VariantInstance> = new Map();
15
17
 
16
18
  protected variantInstanceDefinitions: Map<string, VariantInstanceDefinition> = new Map();
@@ -61,19 +63,35 @@ export class VariantInstanceManager extends EventBroadcaster {
61
63
  /**
62
64
  * Retrieves a {@link VariantInstance}.
63
65
  * If the instance has been created, the created instance will be returned.
64
- * If the instance is registered, the instance will be created.
66
+ * If the instance is registered, the instance will be created and returned.
67
+ * if the instance has already been requested and is currently pending, the dedicated promise will be returned.
65
68
  * If none of these apply, an Error is thrown.
66
69
  *
67
70
  * @emits {@link Event.VARIANT_INSTANCE_CREATED}
68
71
  */
69
72
  public async get(name: string): Promise<VariantInstance> {
73
+ // 1) see if we have an instance of that name already and return it if found
70
74
  if (this.variantInstances.has(name)) {
71
- return this.variantInstances.get(name)!;
75
+ return this.variantInstances.get(name)!; // cannot be null, hence the exclamation mark
76
+ }
77
+
78
+ // 2) try to get promise from list of requested instances and return it if found
79
+ if (this.variantInstancePromises.has(name)) {
80
+ return this.variantInstancePromises.get(name)!;
72
81
  }
82
+
83
+ // 3) see if there's a definition of that name, create an instance from it and store the related promise
73
84
  if (this.variantInstanceDefinitions.has(name)) {
74
- const definition = this.variantInstanceDefinitions.get(name)!;
75
- return await this.createFromDefinition(definition);
85
+ const definition = this.variantInstanceDefinitions.get(name)!; // cannot be null
86
+ const vip = this.createFromDefinition(definition);
87
+ this.variantInstancePromises.set(name, vip);
88
+ // remove promise after it has been finished
89
+ vip.then(() => this.variantInstancePromises.delete(name));
90
+
91
+ return vip;
76
92
  }
93
+
94
+ //* if we are here, no instance definition of that name exists. throw error.
77
95
  throw Error(`VariantInstance with name "${name}" neither created nor configured.`);
78
96
  }
79
97
 
@@ -232,6 +232,11 @@ type ScreenshotSettings = {
232
232
  renderSprites?: boolean;
233
233
  };
234
234
 
235
+ /**
236
+ * Use this to define geometry to be excluded from autofocus, GLB export, etc.
237
+ */
238
+ type ExcludedGeometry = (Mesh | VariantInstance | Variant | VariantElement)[];
239
+
235
240
  type AutofocusSettings = {
236
241
  /**
237
242
  * Can be used to customize the margins shown around the 3d model when calling {@link autofocusActiveCamera}.\
@@ -247,6 +252,8 @@ type AutofocusSettings = {
247
252
  beta?: number;
248
253
  /** Optional animation for the focusing camera movement */
249
254
  animation?: string | AnimationDefinition;
255
+ /** Optional list of geometry to be excluded from consideration */
256
+ exclude?: ExcludedGeometry;
250
257
  };
251
258
 
252
259
  type LightDefinitions = {
@@ -0,0 +1,43 @@
1
+ import { Mesh } from '@babylonjs/core/Meshes/mesh';
2
+ import { Variant } from '../classes/variant';
3
+ import { VariantInstance } from '../classes/variantInstance';
4
+ import { Element } from '../classes/element';
5
+
6
+ /**
7
+ * Find out if a mesh is part of a list of excluded geometry
8
+ * @param mesh BJS mesh
9
+ * @param list list of excluded geometry
10
+ * @returns boolean based on whether mesh was found in list
11
+ */
12
+ const isMeshIncludedInExclusionList = function (mesh: Mesh, list: ExcludedGeometry): boolean {
13
+ const checkMesh = (inputMesh: Mesh, meshToCheck: Mesh) => {
14
+ return inputMesh.uniqueId === meshToCheck.uniqueId;
15
+ };
16
+ const checkElement = (inputEl: Element, meshToCheck: Mesh) => {
17
+ return inputEl.meshesFlat.some(m => checkMesh(m, meshToCheck));
18
+ };
19
+ const checkVariant = (inputVariant: Variant, meshToCheck: Mesh) => {
20
+ return inputVariant.elements.some(el => checkElement(el, meshToCheck));
21
+ };
22
+ const checkVariantInstance = (inputVarInst: VariantInstance, meshToCheck: Mesh) => {
23
+ return inputVarInst.variant.elements.some(el => checkElement(el, meshToCheck));
24
+ };
25
+ const isExcluded = list.some(geometryToExclude => {
26
+ if (geometryToExclude instanceof VariantInstance) {
27
+ return checkVariantInstance(geometryToExclude, mesh);
28
+ }
29
+ if (geometryToExclude instanceof Variant) {
30
+ return checkVariant(geometryToExclude, mesh);
31
+ }
32
+ if (geometryToExclude instanceof Element) {
33
+ return checkElement(geometryToExclude, mesh);
34
+ }
35
+ if (geometryToExclude instanceof Mesh) {
36
+ return checkMesh(geometryToExclude, mesh);
37
+ }
38
+ return false;
39
+ });
40
+ return isExcluded;
41
+ };
42
+
43
+ export { isMeshIncludedInExclusionList };
@@ -26,6 +26,10 @@
26
26
  {
27
27
  "title": "Version 4.3.0",
28
28
  "source": "./doc/release-notes/version-details/4-3-0.md"
29
+ },
30
+ {
31
+ "title": "Version 5.0.0",
32
+ "source": "./doc/release-notes/version-details/5-0-0.md"
29
33
  }
30
34
  ]
31
35
  }