@combeenation/3d-viewer 7.0.0-beta1 → 7.0.0-beta3

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 (35) hide show
  1. package/README.md +1 -1
  2. package/dist/lib-cjs/api/classes/viewer.d.ts +8 -6
  3. package/dist/lib-cjs/api/classes/viewer.js +13 -12
  4. package/dist/lib-cjs/api/classes/viewer.js.map +1 -1
  5. package/dist/lib-cjs/api/classes/viewerLight.d.ts +1 -1
  6. package/dist/lib-cjs/api/classes/viewerLight.js +1 -1
  7. package/dist/lib-cjs/api/manager/animationManager.d.ts +1 -1
  8. package/dist/lib-cjs/api/manager/animationManager.js +1 -1
  9. package/dist/lib-cjs/api/manager/sceneManager.d.ts +1 -1
  10. package/dist/lib-cjs/api/manager/sceneManager.js +1 -1
  11. package/dist/lib-cjs/api/manager/tagManager.d.ts +2 -2
  12. package/dist/lib-cjs/api/manager/tagManager.js +2 -2
  13. package/dist/lib-cjs/api/manager/variantInstanceManager.d.ts +5 -0
  14. package/dist/lib-cjs/api/manager/variantInstanceManager.js +5 -0
  15. package/dist/lib-cjs/api/manager/variantInstanceManager.js.map +1 -1
  16. package/dist/lib-cjs/api/util/babylonHelper.js +5 -0
  17. package/dist/lib-cjs/api/util/babylonHelper.js.map +1 -1
  18. package/dist/lib-cjs/api/util/globalTypes.d.ts +13 -5
  19. package/dist/lib-cjs/api/util/resourceHelper.d.ts +1 -1
  20. package/dist/lib-cjs/api/util/resourceHelper.js +1 -1
  21. package/dist/lib-cjs/api/util/sceneLoaderHelper.d.ts +2 -2
  22. package/dist/lib-cjs/api/util/sceneLoaderHelper.js +2 -2
  23. package/dist/lib-cjs/buildinfo.json +1 -1
  24. package/dist/lib-cjs/commonjs.tsconfig.tsbuildinfo +1 -1
  25. package/package.json +1 -1
  26. package/src/api/classes/viewer.ts +15 -14
  27. package/src/api/classes/viewerLight.ts +1 -1
  28. package/src/api/manager/animationManager.ts +1 -1
  29. package/src/api/manager/sceneManager.ts +1 -1
  30. package/src/api/manager/tagManager.ts +2 -2
  31. package/src/api/manager/variantInstanceManager.ts +5 -0
  32. package/src/api/util/babylonHelper.ts +5 -0
  33. package/src/api/util/globalTypes.ts +12 -5
  34. package/src/api/util/resourceHelper.ts +1 -1
  35. package/src/api/util/sceneLoaderHelper.ts +2 -2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@combeenation/3d-viewer",
3
- "version": "7.0.0-beta1",
3
+ "version": "7.0.0-beta3",
4
4
  "description": "Combeenation 3D Viewer",
5
5
  "homepage": "https://github.com/Combeenation/3d-viewer#readme",
6
6
  "bugs": {
@@ -58,8 +58,7 @@ export class Viewer extends EventBroadcaster {
58
58
 
59
59
  protected _variantInstances: VariantInstanceManager | null = null;
60
60
 
61
- // default value is `false` ATM for compatibility reasons
62
- // in the future material cloning should be the edge case
61
+ // defaults to `false` as material cloning should be the edge case
63
62
  protected _cloneMaterialsOnMutation: boolean = false;
64
63
 
65
64
  protected _isRenderLoopPaused: boolean = false;
@@ -71,7 +70,7 @@ export class Viewer extends EventBroadcaster {
71
70
  static version = buildInfo.version;
72
71
 
73
72
  // these are constants for calculating the camera settings, depending on the bounding box size of the meshes to zoom
74
- // the algorithms and constant values are directly taken from the BabylonJS repository
73
+ // the algorithms and constant values are directly taken from the Babylon.js repository
75
74
  private static readonly _autofocusConstants = {
76
75
  minZ: 100,
77
76
  wheelPrecision: 100,
@@ -80,15 +79,15 @@ export class Viewer extends EventBroadcaster {
80
79
  };
81
80
 
82
81
  /**
83
- * Help function for automatically creating a valid Spec from a list of variant names and dedicated GLB/Babylon URLs.
82
+ * Help function for automatically creating a valid Spec from a list of variant names and dedicated GLB/babylon URLs.
84
83
  * This data is most likely coming from babylon assets from the Combeenation system but other sources are also valid.
85
84
  */
86
- public static generateSpec(genData: SpecGenerationData[]): StructureJson {
85
+ public static generateSpec(genData: SpecGenerationData[]): AutoSpecStructureJson {
87
86
  // dots in the variant name indicate inheritance, but this should not be the case for an auto-generated spec
88
87
  // therefore dots are exchanged with slashes
89
88
  const safeGenData: SpecGenerationData[] = genData.map(data => ({ ...data, name: replaceDots(data.name) }));
90
89
 
91
- const spec: StructureJson = {
90
+ const spec: AutoSpecStructureJson = {
92
91
  // common scene settings as suggested in the viewer docs
93
92
  scene: {
94
93
  engine: {
@@ -118,7 +117,7 @@ export class Viewer extends EventBroadcaster {
118
117
  },
119
118
  // variants definition is also mapped to the input array, using the name as key and url as glTF source
120
119
  // no elements are created here, since this should be done automatically from the system
121
- // => create one element which contains all root nodes of the imported 3d file (GLB or Babylon)
120
+ // => create one element which contains all root nodes of the imported 3d file (GLB or babylon)
122
121
  variants: safeGenData.reduce((accVariants, curVariant) => {
123
122
  accVariants[curVariant.name] = {
124
123
  glTF: curVariant.url,
@@ -157,7 +156,7 @@ export class Viewer extends EventBroadcaster {
157
156
  }
158
157
 
159
158
  /**
160
- * Gets the BabylonJS Scene that is attached to the instance.
159
+ * Gets the Babylon.js Scene that is attached to the instance.
161
160
  *
162
161
  * @throws Error if the `scene` has not been initialized.
163
162
  */
@@ -193,7 +192,7 @@ export class Viewer extends EventBroadcaster {
193
192
  }
194
193
 
195
194
  /**
196
- * Gets the BabylonJS Engine that is attached to the viewer.
195
+ * Gets the Babylon.js Engine that is attached to the viewer.
197
196
  */
198
197
  get engine(): Engine {
199
198
  return this.scene.getEngine();
@@ -248,7 +247,9 @@ export class Viewer extends EventBroadcaster {
248
247
  }
249
248
 
250
249
  /**
251
- * Sets the strategy handler for naming cloned nodes.
250
+ * Sets the strategy handler for naming cloned nodes.\
251
+ * Check the docs of the tag managers [renaming](https://3dviewer.docs.combeenation.com/pages/documentation/Tag-Manager.html#uniqueness-of-node-and-tag-names)
252
+ * chapter for further details.
252
253
  */
253
254
  set nodeNamingStrategyHandler(value: NodeNamingStrategyHandler) {
254
255
  if (!value || typeof value !== 'function') {
@@ -321,7 +322,7 @@ export class Viewer extends EventBroadcaster {
321
322
  }
322
323
 
323
324
  /**
324
- * Enables the BabylonJS [Inspector](https://doc.babylonjs.com/toolsAndResources/tools/inspector).\
325
+ * Enables the Babylon.js [Inspector](https://doc.babylonjs.com/toolsAndResources/tools/inspector).\
325
326
  * Due to the additional size of the inspector, the CDN version is used instead of shipping the required code with
326
327
  * the viewer.\
327
328
  * This means that the code will be downloaded only when needed and calling `enableDebugLayer` can take a little while
@@ -329,7 +330,7 @@ export class Viewer extends EventBroadcaster {
329
330
  */
330
331
  public async enableDebugLayer(options?: IInspectorOptions) {
331
332
  if (!this._inspectorLoaded) {
332
- // CDN version of inspector requires the BabylonJS core to be available as CDN module as well
333
+ // CDN version of inspector requires the Babylon.js core to be available as CDN module as well
333
334
  await loadJavascript('https://cdn.jsdelivr.net/npm/babylonjs@5.6.0/babylon.min.js');
334
335
 
335
336
  DebugLayer.InspectorURL =
@@ -532,7 +533,7 @@ export class Viewer extends EventBroadcaster {
532
533
  activeCamera.lowerRadiusLimit = radius;
533
534
 
534
535
  // additional settings
535
- // constants for division are taken directly from BabylonJS repository
536
+ // constants for division are taken directly from Babylon.js repository
536
537
  activeCamera.minZ = Math.min(radius / Viewer._autofocusConstants.minZ, 1);
537
538
  if (settings?.adjustWheelPrecision !== false) {
538
539
  activeCamera.wheelPrecision = Viewer._autofocusConstants.wheelPrecision / radius;
@@ -552,7 +553,7 @@ export class Viewer extends EventBroadcaster {
552
553
  alpha: alpha,
553
554
  beta: beta,
554
555
  // this calculation is a bit "simplified", as it doesn't consider the viewport ratio or the frustum angle
555
- // but it's also done this way in the BabylonJs repository, so it should be fine for us
556
+ // but it's also done this way in the Babylon.js repository, so it should be fine for us
556
557
  radius: diameter * radiusFactor,
557
558
  target: center,
558
559
  };
@@ -22,7 +22,7 @@ import '@babylonjs/loaders/glTF/2.0/Extensions/KHR_lights_punctual';
22
22
  import { get, isEmpty, isString, set } from 'lodash-es';
23
23
 
24
24
  /**
25
- * A {@link ViewerLight} of a {@link Variant}. Acts as a container for BabylonJS lights. Lives only in the context of a
25
+ * A {@link ViewerLight} of a {@link Variant}. Acts as a container for Babylon.js lights. Lives only in the context of a
26
26
  * {@link Variant}.
27
27
  */
28
28
  export class ViewerLight extends VariantParameterizable {
@@ -19,7 +19,7 @@ export class AnimationManager {
19
19
  protected constructor(protected scene: BabylonScene) {}
20
20
 
21
21
  /**
22
- * Creates an {@link AnimationManager} based on given BabylonJS scene.
22
+ * Creates an {@link AnimationManager} based on given Babylon.js scene.
23
23
  */
24
24
  public static async create(scene: BabylonScene): Promise<AnimationManager> {
25
25
  return new AnimationManager(scene);
@@ -24,7 +24,7 @@ export class SceneManager extends ParameterObservable {
24
24
  }
25
25
 
26
26
  /**
27
- * Creates a {@link SceneManager} based on given BabylonJS scene.
27
+ * Creates a {@link SceneManager} based on given Babylon.js scene.
28
28
  */
29
29
  public static async create(scene: BabylonScene): Promise<SceneManager> {
30
30
  const sceneManager = new SceneManager(scene);
@@ -210,7 +210,7 @@ export class TagManager {
210
210
  }
211
211
 
212
212
  /**
213
- * Gets all nodes for given {@link TagManagerSubject} on the Babylon scene.
213
+ * Gets all nodes for given {@link TagManagerSubject} on the Babylon.js scene.
214
214
  */
215
215
  public getNodesBySubject(subject: TagManagerSubject, predicate?: (node: TransformNode) => boolean): TransformNode[] {
216
216
  let nodes: TransformNode[] = [];
@@ -232,7 +232,7 @@ export class TagManager {
232
232
  }
233
233
 
234
234
  /**
235
- * Registers observers that are called on every new node added to the Babylon scene. The observers ensure that each
235
+ * Registers observers that are called on every new node added to the Babylon.js scene. The observers ensure that each
236
236
  * new node gets the state of the {@link TagManager}'s {@link parameters} applied.
237
237
  */
238
238
  public registerNewTransformNodeObservers(scene: Scene) {
@@ -202,6 +202,11 @@ export class VariantInstanceManager extends EventBroadcaster {
202
202
  /**
203
203
  * Clones and registers a new {@link VariantInstance} with a new, unique name.
204
204
  *
205
+ * @param tagMapping Object for renaming tags on the clone, whereas the "key" is the tag name of orignal variant
206
+ * instance and the "value" is the new tag name that should be created from it.\
207
+ * Check the docs of the tag managers [renaming](https://3dviewer.docs.combeenation.com/pages/documentation/Tag-Manager.html#uniqueness-of-node-and-tag-names)
208
+ * chapter for further details.
209
+ *
205
210
  * @emits {@link Event.VARIANT_INSTANCE_CLONED}
206
211
  */
207
212
  public async clone(
@@ -110,6 +110,11 @@ const cloneTransformNode = function (
110
110
  if (node.constructor.name === 'InstancedMesh') {
111
111
  clone.setEnabled(node.isEnabled(false));
112
112
  }
113
+ // copying tags is a temporary workaround, as it doesn't work for TransformNodes ATM
114
+ // see https://forum.babylonjs.com/t/transformnode-clone-doesnt-contain-original-tags/38429/1
115
+ if (Tags?.HasTags(node)) {
116
+ Tags.AddTagsTo(clone, Tags.GetTags(node, true));
117
+ }
113
118
  }
114
119
  if (deep) {
115
120
  const children = node.getChildTransformNodes(true);
@@ -109,7 +109,7 @@ type EnvironmentDefinition = {
109
109
 
110
110
  type StructureJson = {
111
111
  /**
112
- * `scene` describes the visualisation of the Babylon `scene` such as the incidence of light and camera position. If a
112
+ * `scene` describes the visualisation of the babylon `scene` such as the incidence of light and camera position. If a
113
113
  * string is given, the {@link Viewer} will resolve the URL or path and pass the parsed JSON to this property.
114
114
  */
115
115
  scene?: string | SceneJson;
@@ -131,7 +131,7 @@ type StructureJson = {
131
131
  /**
132
132
  * `variants` is a declarative description of 3D-model variations in the configurator. Each variant itself is a
133
133
  * {@link StructureJson} which must at least define a `name` in the key of the list and the properties `glTF` and
134
- * `elements` in the value. FYI: BabylonJS's sandbox can show you the path of the 3D-model to properly define the
134
+ * `elements` in the value. FYI: Babylon.js's sandbox can show you the path of the 3D-model to properly define the
135
135
  * `paths`.
136
136
  *
137
137
  * Example Code
@@ -159,6 +159,12 @@ type StructureJson = {
159
159
  };
160
160
  };
161
161
 
162
+ type AutoSpecStructureJson = StructureJson & {
163
+ scene: SceneJson;
164
+ setup: SetupJson;
165
+ variants: { [id: string]: StructureJson };
166
+ };
167
+
162
168
  type SceneJson = {
163
169
  parameterDeclaration?: ParameterDeclarations;
164
170
  parameters?: ParameterBag;
@@ -174,7 +180,8 @@ type SceneJson = {
174
180
  animations?: AnimationDefinitions;
175
181
  placements?: PlacementDefinitions;
176
182
  /**
177
- * Information about [material cloning](pages/Release%20Notes/releases/4-3-0.html#material-cloning-on-mutation)
183
+ * Information about [material cloning](pages/Release%20Notes/releases/4-3-0.html#material-cloning-on-mutation).
184
+ * Default value is `false`.
178
185
  */
179
186
  cloneMaterialsOnMutation?: boolean;
180
187
  };
@@ -228,7 +235,7 @@ type SceneGlobals = {
228
235
  };
229
236
 
230
237
  /**
231
- * {@link Viewer.screenshot} internally uses Babylons [ScreenshotTools.CreateScreenshotUsingRenderTarget](https://doc.babylonjs.com/typedoc/classes/babylon.screenshottools#createscreenshotusingrendertarget). \
238
+ * {@link Viewer.screenshot} internally uses Babylon.js [ScreenshotTools.CreateScreenshotUsingRenderTarget](https://doc.babylonjs.com/typedoc/classes/babylon.screenshottools#createscreenshotusingrendertarget). \
232
239
  * See this link for additional info about the properties.
233
240
  */
234
241
  type ScreenshotSettings = {
@@ -432,7 +439,7 @@ type AnimationDefinitions = {
432
439
  type AnimationDefinition = GSAPTweenVars & { shortestWay?: boolean };
433
440
 
434
441
  /**
435
- * Extends Babylon JSs {@link IExportOptions} by some viewer specific settings
442
+ * Extends Babylon.js's {@link IExportOptions} by some viewer specific settings
436
443
  */
437
444
  interface IExportOptionsExtended extends IExportOptions {
438
445
  /**
@@ -39,7 +39,7 @@ const loadText = async function (path: string): Promise<string> {
39
39
 
40
40
  /**
41
41
  * Loads a Javascript ressource.\
42
- * Usefull for including packages via CDN (eg: BabylonJS Inspector)
42
+ * Usefull for including packages via CDN (eg: Babylon.js Inspector)
43
43
  */
44
44
  const loadJavascript = (url: string): Promise<void> =>
45
45
  new Promise(resolve => {
@@ -156,8 +156,8 @@ export const removeMissingMaterialObserver = function (node: BjsNode) {
156
156
  /**
157
157
  * Look up the provided materials (see library import) and create and return one if found.
158
158
  *
159
- * @param materialId BabylonJs material-id. E.g. 'concrete".
160
- * @param scene BabylonJs scene
159
+ * @param materialId Babylon.js material-id. E.g. 'concrete".
160
+ * @param scene Babylon.js scene
161
161
  * @returns PBRMaterial | null
162
162
  */
163
163
  export const createMaterialFromCbnAssets = function (materialId: string, scene: Scene): Material | null {