@combeenation/3d-viewer 12.1.1 → 12.2.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@combeenation/3d-viewer",
3
- "version": "12.1.1",
3
+ "version": "12.2.0",
4
4
  "description": "Combeenation 3D Viewer",
5
5
  "homepage": "https://github.com/Combeenation/3d-viewer#readme",
6
6
  "bugs": {
@@ -34,6 +34,7 @@ import { PBRMaterial } from '@babylonjs/core/Materials/PBR/pbrMaterial';
34
34
  import { Material } from '@babylonjs/core/Materials/material';
35
35
  import { Color3 } from '@babylonjs/core/Maths/math.color';
36
36
  import { AbstractMesh } from '@babylonjs/core/Meshes/abstractMesh';
37
+ import { InstancedMesh } from '@babylonjs/core/Meshes/instancedMesh';
37
38
  import { Mesh } from '@babylonjs/core/Meshes/mesh';
38
39
  import { TransformNode } from '@babylonjs/core/Meshes/transformNode';
39
40
  import { Tags } from '@babylonjs/core/Misc/tags';
@@ -78,7 +79,7 @@ export class Element extends VariantParameterizable {
78
79
  // this can only be done after the cloning process of the whole tree is finished, as we can't be sure if all
79
80
  // instanced meshes or all sources meshes are cloning prior
80
81
  const reassignSourceMesh = (node: TransformNode) => {
81
- if (node.constructor.name === 'InstancedMesh') {
82
+ if (node instanceof InstancedMesh) {
82
83
  // find the cloned instance and source mesh
83
84
  const clonedInstance = node as InstancedMesh;
84
85
  const originalInstance = clonedInstance.metadata.cloneSource as InstancedMesh;
@@ -7,7 +7,7 @@ import { TagManager } from '../manager/tagManager';
7
7
  import { VariantInstanceManager } from '../manager/variantInstanceManager';
8
8
  import { SpecStorage } from '../store/specStorage';
9
9
  import { backgroundDomeName, envHelperMetadataName } from '../util/babylonHelper';
10
- import { showWorldCoordinates } from '../util/debugHelper';
10
+ import { hideWorldCoordinates, isWorldCoordinatesDebugNode, showWorldCoordinates } from '../util/debugHelper';
11
11
  import { getIsScaledDownDevice } from '../util/deviceHelper';
12
12
  import { debounce, loadJson } from '../util/resourceHelper';
13
13
  import { getCustomCbnBabylonLoaderPlugin } from '../util/sceneLoaderHelper';
@@ -509,14 +509,23 @@ The inspector can only be used in development builds.`);
509
509
  .filter(mesh => {
510
510
  const isEnabled = mesh.isEnabled();
511
511
  // ignore the existing bounding box mesh for calculating the current one
512
- const isNotBBoxMesh = Viewer.BOUNDING_BOX_NAME !== mesh.id;
512
+ const isNotBBoxMesh = Viewer.BOUNDING_BOX_NAME !== mesh.name;
513
+ // ignore debug world coordinates nodes
514
+ const isNotWorldCoordinatesDebugNode = !isWorldCoordinatesDebugNode(mesh.name);
513
515
  // ignore meshes with invalid bounding infos
514
516
  const hasValidBBoxInfo = mesh.getBoundingInfo().boundingSphere.radius > 0;
515
517
  // ignore meshes with infinite distance, typically these are sky boxes
516
518
  const hasInfiniteDistance = mesh.infiniteDistance;
517
519
  // ignore excluded meshes
518
520
  const isExcluded = excludeGeometry ? isNodeIncludedInExclusionList(mesh, excludeGeometry) : false;
519
- return isEnabled && isNotBBoxMesh && hasValidBBoxInfo && !hasInfiniteDistance && !isExcluded;
521
+ return (
522
+ isEnabled &&
523
+ isNotBBoxMesh &&
524
+ isNotWorldCoordinatesDebugNode &&
525
+ hasValidBBoxInfo &&
526
+ !hasInfiniteDistance &&
527
+ !isExcluded
528
+ );
520
529
  })
521
530
  .reduce(
522
531
  (accBBoxMinMax, curMesh, idx) => {
@@ -627,12 +636,19 @@ The inspector can only be used in development builds.`);
627
636
  }
628
637
 
629
638
  /**
630
- * Show coordinate system with given dimension (for debugging purpose).
639
+ * Show world coordinate system with given dimension (for debugging purpose).
631
640
  */
632
641
  public showWorldCoordinates(dimension: number) {
633
642
  showWorldCoordinates(this.scene, dimension);
634
643
  }
635
644
 
645
+ /**
646
+ * Hide world coordinate system.
647
+ */
648
+ public hideWorldCoordinates() {
649
+ hideWorldCoordinates(this.scene);
650
+ }
651
+
636
652
  /**
637
653
  * Pause render loop.
638
654
  */
@@ -1,5 +1,6 @@
1
1
  import { Viewer } from '../classes/viewer';
2
2
  import { injectMetadata } from '../util/babylonHelper';
3
+ import { isWorldCoordinatesDebugNode } from '../util/debugHelper';
3
4
  import { getIsScaledDownDevice } from '../util/deviceHelper';
4
5
  import { bakeGeometryOfMesh, createMeshFromInstancedMesh, resetTransformation } from '../util/geometryHelper';
5
6
  import { isNodeIncludedInExclusionList } from '../util/structureHelper';
@@ -282,6 +283,9 @@ export class GltfExportManager {
282
283
  if (node.name === Viewer.BOUNDING_BOX_NAME) {
283
284
  return false;
284
285
  }
286
+ if (isWorldCoordinatesDebugNode(node.name)) {
287
+ return false;
288
+ }
285
289
  if (!node.isEnabled()) {
286
290
  return false;
287
291
  }
@@ -114,7 +114,7 @@ const cloneTransformNode = function (
114
114
  // if the cloned node is of type InstancedMesh, due to a bug(?),
115
115
  // the InstancedMesh.isEnabled state may have changed after cloning.
116
116
  // in that case, set the clone's enabled state to the original's state
117
- if (node.constructor.name === 'InstancedMesh') {
117
+ if (node instanceof InstancedMesh) {
118
118
  clone.setEnabled(node.isEnabled(false));
119
119
 
120
120
  // tags are not cloned for instanced meshes by default
@@ -16,27 +16,48 @@ const _DEBUG_AXIS_MAP: Record<DebugAxisKeys, DebugAxisConfig> = {
16
16
  };
17
17
 
18
18
  const _WORLD_COORD_ROOT_KEY = '__world_coordinates__';
19
+ let _AXES_VIEWER: AxesViewer;
19
20
 
20
21
  /**
21
22
  * Create debug coordinate system located in world origin.
22
23
  * This function is based on Babylon.js `AxesViewer`, axis texts are added manually.
23
24
  */
24
25
  export function showWorldCoordinates(scene: Scene, dimension: number) {
25
- const existingRoot = scene.getTransformNodeByName(_WORLD_COORD_ROOT_KEY);
26
- if (existingRoot) {
27
- // make sure to remove already existing debug coordinate systems
28
- existingRoot.dispose();
29
- }
26
+ // make sure to remove already existing debug coordinate systems
27
+ hideWorldCoordinates(scene);
30
28
 
31
29
  const worldCoordRoot = new TransformNode(_WORLD_COORD_ROOT_KEY, scene);
32
30
  // axes viewer coordinate system is a bit too large
33
31
  // multiply with unify factor to create arrows which exactly match the length of the input dimension
34
32
  const factor = _getWorldCoordinatesAxesUnifyFactor();
35
- const axesViewer = new AxesViewer(scene, dimension * factor);
33
+ _AXES_VIEWER = new AxesViewer(scene, dimension * factor);
34
+
35
+ _prepareWorldCoordinateAxis('X', _AXES_VIEWER.xAxis, worldCoordRoot, dimension, scene);
36
+ _prepareWorldCoordinateAxis('Y', _AXES_VIEWER.yAxis, worldCoordRoot, dimension, scene);
37
+ _prepareWorldCoordinateAxis('Z', _AXES_VIEWER.zAxis, worldCoordRoot, dimension, scene);
38
+ }
39
+
40
+ /**
41
+ * Remove meshes and materials that are associated with the debug world coordinates system
42
+ */
43
+ export function hideWorldCoordinates(scene: Scene) {
44
+ _AXES_VIEWER?.dispose();
36
45
 
37
- _prepareWorldCoordinateAxis('X', axesViewer.xAxis, worldCoordRoot, dimension, scene);
38
- _prepareWorldCoordinateAxis('Y', axesViewer.yAxis, worldCoordRoot, dimension, scene);
39
- _prepareWorldCoordinateAxis('Z', axesViewer.zAxis, worldCoordRoot, dimension, scene);
46
+ const worldCoordRoot = scene.getTransformNodeByName(_WORLD_COORD_ROOT_KEY);
47
+ if (worldCoordRoot) {
48
+ worldCoordRoot.dispose(false, true);
49
+ }
50
+ }
51
+
52
+ /**
53
+ * Checks if the node is generated by the `showWorldCoordinates` function.
54
+ * These nodes need special treatment in certain cases, for example the `autofocusActiveCamera` function should ignore
55
+ * the values and GLB exports should also not include the nodes.
56
+ */
57
+ export function isWorldCoordinatesDebugNode(nodeName: string) {
58
+ // ATM this is a plain name check, as we have some reserved names in the viewer (see Viewer.BOUNDING_BOX_NAME)
59
+ // Other solutions could be storing this info in the metadata or in a different global node store
60
+ return nodeName.startsWith(_WORLD_COORD_ROOT_KEY);
40
61
  }
41
62
 
42
63
  /**