@combeenation/3d-viewer 12.2.0 → 12.2.1
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/dist/lib-cjs/api/classes/viewer.d.ts +3 -3
- package/dist/lib-cjs/api/classes/viewer.js +31 -48
- package/dist/lib-cjs/api/classes/viewer.js.map +1 -1
- package/dist/lib-cjs/api/manager/gltfExportManager.js +0 -8
- package/dist/lib-cjs/api/manager/gltfExportManager.js.map +1 -1
- package/dist/lib-cjs/api/manager/tagManager.js +0 -5
- package/dist/lib-cjs/api/manager/tagManager.js.map +1 -1
- package/dist/lib-cjs/api/util/debugHelper.d.ts +2 -8
- package/dist/lib-cjs/api/util/debugHelper.js +22 -30
- package/dist/lib-cjs/api/util/debugHelper.js.map +1 -1
- package/dist/lib-cjs/buildinfo.json +1 -1
- package/dist/lib-cjs/commonjs.tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/api/classes/viewer.ts +11 -28
- package/src/api/manager/gltfExportManager.ts +0 -7
- package/src/api/manager/tagManager.ts +0 -4
- package/src/api/util/debugHelper.ts +24 -26
package/package.json
CHANGED
|
@@ -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 { hideWorldCoordinates,
|
|
10
|
+
import { hideWorldCoordinates, 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';
|
|
@@ -45,8 +45,6 @@ import { isString } from 'lodash-es';
|
|
|
45
45
|
* The class does nothing on its own and needs to {@link bootstrap}
|
|
46
46
|
*/
|
|
47
47
|
export class Viewer extends EventBroadcaster {
|
|
48
|
-
public static readonly BOUNDING_BOX_NAME = '__bounding_box__';
|
|
49
|
-
|
|
50
48
|
protected _scene: Scene | null = null;
|
|
51
49
|
|
|
52
50
|
protected _animationManager: AnimationManager | null = null;
|
|
@@ -498,9 +496,9 @@ The inspector can only be used in development builds.`);
|
|
|
498
496
|
}
|
|
499
497
|
|
|
500
498
|
/**
|
|
501
|
-
* Calculates the bounding box from all visible meshes on the scene.
|
|
499
|
+
* Calculates the bounding box information from all visible meshes on the scene.
|
|
502
500
|
*/
|
|
503
|
-
public
|
|
501
|
+
public calculateBoundingInfo(excludeGeometry?: ExcludedGeometryList): BoundingInfo {
|
|
504
502
|
if (this.scene.meshes.length === 0) {
|
|
505
503
|
throw new Error('There are currently no meshes on the scene.');
|
|
506
504
|
}
|
|
@@ -508,24 +506,13 @@ The inspector can only be used in development builds.`);
|
|
|
508
506
|
const { max, min } = this.scene.meshes
|
|
509
507
|
.filter(mesh => {
|
|
510
508
|
const isEnabled = mesh.isEnabled();
|
|
511
|
-
// ignore the existing bounding box mesh for calculating the current one
|
|
512
|
-
const isNotBBoxMesh = Viewer.BOUNDING_BOX_NAME !== mesh.name;
|
|
513
|
-
// ignore debug world coordinates nodes
|
|
514
|
-
const isNotWorldCoordinatesDebugNode = !isWorldCoordinatesDebugNode(mesh.name);
|
|
515
509
|
// ignore meshes with invalid bounding infos
|
|
516
510
|
const hasValidBBoxInfo = mesh.getBoundingInfo().boundingSphere.radius > 0;
|
|
517
511
|
// ignore meshes with infinite distance, typically these are sky boxes
|
|
518
512
|
const hasInfiniteDistance = mesh.infiniteDistance;
|
|
519
513
|
// ignore excluded meshes
|
|
520
514
|
const isExcluded = excludeGeometry ? isNodeIncludedInExclusionList(mesh, excludeGeometry) : false;
|
|
521
|
-
return
|
|
522
|
-
isEnabled &&
|
|
523
|
-
isNotBBoxMesh &&
|
|
524
|
-
isNotWorldCoordinatesDebugNode &&
|
|
525
|
-
hasValidBBoxInfo &&
|
|
526
|
-
!hasInfiniteDistance &&
|
|
527
|
-
!isExcluded
|
|
528
|
-
);
|
|
515
|
+
return isEnabled && hasValidBBoxInfo && !hasInfiniteDistance && !isExcluded;
|
|
529
516
|
})
|
|
530
517
|
.reduce(
|
|
531
518
|
(accBBoxMinMax, curMesh, idx) => {
|
|
@@ -538,12 +525,8 @@ The inspector can only be used in development builds.`);
|
|
|
538
525
|
{ max: new Vector3(), min: new Vector3() }
|
|
539
526
|
);
|
|
540
527
|
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
boundingBox = new Mesh(Viewer.BOUNDING_BOX_NAME, this.scene);
|
|
544
|
-
}
|
|
545
|
-
boundingBox.setBoundingInfo(new BoundingInfo(min, max));
|
|
546
|
-
return boundingBox;
|
|
528
|
+
const boundingInfo = new BoundingInfo(min, max);
|
|
529
|
+
return boundingInfo;
|
|
547
530
|
}
|
|
548
531
|
|
|
549
532
|
/**
|
|
@@ -575,10 +558,10 @@ The inspector can only be used in development builds.`);
|
|
|
575
558
|
}
|
|
576
559
|
|
|
577
560
|
// get bounding box of all visible meshes, this is the base for the autofocus algorithm
|
|
578
|
-
const
|
|
561
|
+
const boundingInfo = this.calculateBoundingInfo(exclude);
|
|
579
562
|
|
|
580
|
-
const radius =
|
|
581
|
-
const center =
|
|
563
|
+
const radius = boundingInfo.boundingSphere.radius;
|
|
564
|
+
const center = boundingInfo.boundingSphere.center;
|
|
582
565
|
const diameter = radius * 2;
|
|
583
566
|
|
|
584
567
|
// set lower radius limit on edge of bounding sphere to make sure that we can't dive into the meshes
|
|
@@ -639,14 +622,14 @@ The inspector can only be used in development builds.`);
|
|
|
639
622
|
* Show world coordinate system with given dimension (for debugging purpose).
|
|
640
623
|
*/
|
|
641
624
|
public showWorldCoordinates(dimension: number) {
|
|
642
|
-
showWorldCoordinates(
|
|
625
|
+
showWorldCoordinates(dimension);
|
|
643
626
|
}
|
|
644
627
|
|
|
645
628
|
/**
|
|
646
629
|
* Hide world coordinate system.
|
|
647
630
|
*/
|
|
648
631
|
public hideWorldCoordinates() {
|
|
649
|
-
hideWorldCoordinates(
|
|
632
|
+
hideWorldCoordinates();
|
|
650
633
|
}
|
|
651
634
|
|
|
652
635
|
/**
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Viewer } from '../classes/viewer';
|
|
2
2
|
import { injectMetadata } from '../util/babylonHelper';
|
|
3
|
-
import { isWorldCoordinatesDebugNode } from '../util/debugHelper';
|
|
4
3
|
import { getIsScaledDownDevice } from '../util/deviceHelper';
|
|
5
4
|
import { bakeGeometryOfMesh, createMeshFromInstancedMesh, resetTransformation } from '../util/geometryHelper';
|
|
6
5
|
import { isNodeIncludedInExclusionList } from '../util/structureHelper';
|
|
@@ -280,12 +279,6 @@ export class GltfExportManager {
|
|
|
280
279
|
return false;
|
|
281
280
|
}
|
|
282
281
|
// TODO: think of adding "BackgroundHelper" and nodes with "infiniteDistance" here as well, at least in AR mode
|
|
283
|
-
if (node.name === Viewer.BOUNDING_BOX_NAME) {
|
|
284
|
-
return false;
|
|
285
|
-
}
|
|
286
|
-
if (isWorldCoordinatesDebugNode(node.name)) {
|
|
287
|
-
return false;
|
|
288
|
-
}
|
|
289
282
|
if (!node.isEnabled()) {
|
|
290
283
|
return false;
|
|
291
284
|
}
|
|
@@ -299,10 +299,6 @@ export class TagManager {
|
|
|
299
299
|
created means that there is no scenario where new nodes should get TagManager parameters applied.
|
|
300
300
|
Instead, we check for the state to be enabled via the `onEnabledStateChangedObservable` below.
|
|
301
301
|
*/
|
|
302
|
-
//if (node.name === Viewer.BOUNDING_BOX_NAME || !this.viewer.variantInstances.areAllDefinitionsCreated) {
|
|
303
|
-
if (node.name === Viewer.BOUNDING_BOX_NAME) {
|
|
304
|
-
return;
|
|
305
|
-
}
|
|
306
302
|
const onEnabledStateChangedObserver = node.onEnabledStateChangedObservable.add(async state => {
|
|
307
303
|
if (!state) {
|
|
308
304
|
// if the node is disabled, means ignoring also "ghost nodes"
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { Vector3 } from '@babylonjs/core';
|
|
2
1
|
import { AxesViewer } from '@babylonjs/core/Debug/axesViewer';
|
|
3
2
|
import { DynamicTexture } from '@babylonjs/core/Materials/Textures/dynamicTexture';
|
|
4
3
|
import { StandardMaterial } from '@babylonjs/core/Materials/standardMaterial';
|
|
5
4
|
import { Color3 } from '@babylonjs/core/Maths/math.color';
|
|
5
|
+
import { Vector3 } from '@babylonjs/core/Maths/math.vector';
|
|
6
6
|
import { MeshBuilder } from '@babylonjs/core/Meshes/meshBuilder';
|
|
7
7
|
import { TransformNode } from '@babylonjs/core/Meshes/transformNode';
|
|
8
|
+
import { UtilityLayerRenderer } from '@babylonjs/core/Rendering/utilityLayerRenderer';
|
|
8
9
|
|
|
9
10
|
type DebugAxisKeys = 'X' | 'Y' | 'Z';
|
|
10
11
|
type DebugAxisConfig = { color: Color3; position: Vector3 };
|
|
@@ -22,44 +23,38 @@ let _AXES_VIEWER: AxesViewer;
|
|
|
22
23
|
* Create debug coordinate system located in world origin.
|
|
23
24
|
* This function is based on Babylon.js `AxesViewer`, axis texts are added manually.
|
|
24
25
|
*/
|
|
25
|
-
export function showWorldCoordinates(
|
|
26
|
+
export function showWorldCoordinates(dimension: number) {
|
|
26
27
|
// make sure to remove already existing debug coordinate systems
|
|
27
|
-
hideWorldCoordinates(
|
|
28
|
+
hideWorldCoordinates();
|
|
28
29
|
|
|
29
|
-
|
|
30
|
+
// draw in utility layer, so that there is no interaction with the actually scene content (eg: glb export, autofocus)
|
|
31
|
+
const utilityLayerScene = UtilityLayerRenderer.DefaultUtilityLayer.utilityLayerScene;
|
|
32
|
+
|
|
33
|
+
const worldCoordRoot = new TransformNode('__world_coordinates__', utilityLayerScene);
|
|
30
34
|
// axes viewer coordinate system is a bit too large
|
|
31
35
|
// multiply with unify factor to create arrows which exactly match the length of the input dimension
|
|
32
36
|
const factor = _getWorldCoordinatesAxesUnifyFactor();
|
|
33
|
-
_AXES_VIEWER = new AxesViewer(
|
|
37
|
+
_AXES_VIEWER = new AxesViewer(utilityLayerScene, dimension * factor);
|
|
34
38
|
|
|
35
|
-
_prepareWorldCoordinateAxis('X', _AXES_VIEWER.xAxis, worldCoordRoot, dimension,
|
|
36
|
-
_prepareWorldCoordinateAxis('Y', _AXES_VIEWER.yAxis, worldCoordRoot, dimension,
|
|
37
|
-
_prepareWorldCoordinateAxis('Z', _AXES_VIEWER.zAxis, worldCoordRoot, dimension,
|
|
39
|
+
_prepareWorldCoordinateAxis('X', _AXES_VIEWER.xAxis, worldCoordRoot, dimension, utilityLayerScene);
|
|
40
|
+
_prepareWorldCoordinateAxis('Y', _AXES_VIEWER.yAxis, worldCoordRoot, dimension, utilityLayerScene);
|
|
41
|
+
_prepareWorldCoordinateAxis('Z', _AXES_VIEWER.zAxis, worldCoordRoot, dimension, utilityLayerScene);
|
|
38
42
|
}
|
|
39
43
|
|
|
40
44
|
/**
|
|
41
45
|
* Remove meshes and materials that are associated with the debug world coordinates system
|
|
42
46
|
*/
|
|
43
|
-
export function hideWorldCoordinates(
|
|
47
|
+
export function hideWorldCoordinates() {
|
|
48
|
+
const utilityLayerScene = UtilityLayerRenderer.DefaultUtilityLayer.utilityLayerScene;
|
|
49
|
+
|
|
44
50
|
_AXES_VIEWER?.dispose();
|
|
45
51
|
|
|
46
|
-
const worldCoordRoot =
|
|
52
|
+
const worldCoordRoot = utilityLayerScene.getTransformNodeByName(_WORLD_COORD_ROOT_KEY);
|
|
47
53
|
if (worldCoordRoot) {
|
|
48
54
|
worldCoordRoot.dispose(false, true);
|
|
49
55
|
}
|
|
50
56
|
}
|
|
51
57
|
|
|
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);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
58
|
/**
|
|
64
59
|
* Adjust and enhance coordinate axes to fulfill our needs.
|
|
65
60
|
* - moves nodes into common root
|
|
@@ -70,26 +65,29 @@ function _prepareWorldCoordinateAxis(
|
|
|
70
65
|
axis: TransformNode,
|
|
71
66
|
root: TransformNode,
|
|
72
67
|
dimension: number,
|
|
73
|
-
|
|
68
|
+
utilityLayerScene: Scene
|
|
74
69
|
) {
|
|
75
70
|
// create unique names
|
|
76
71
|
axis.name = `${_WORLD_COORD_ROOT_KEY}.${text}`;
|
|
77
72
|
axis.parent = root;
|
|
78
|
-
axis.getChildMeshes().forEach((child, idx) => (child.name = `${_WORLD_COORD_ROOT_KEY}.${text}.cylinder_${idx}`));
|
|
79
73
|
|
|
80
74
|
// create text mesh via dynamic texture
|
|
81
|
-
const dynamicTexture = new DynamicTexture(`${_WORLD_COORD_ROOT_KEY}.${text}`, 50,
|
|
75
|
+
const dynamicTexture = new DynamicTexture(`${_WORLD_COORD_ROOT_KEY}.${text}`, 50, utilityLayerScene, true);
|
|
82
76
|
dynamicTexture.hasAlpha = true;
|
|
83
77
|
// 42.5 is a magic offset, so that the text is vertically centered for font size 50px
|
|
84
78
|
// horizontal centering works well with the standard behaviour of Babylon.js (setting "null" as "width")
|
|
85
79
|
dynamicTexture.drawText(text, null, 42.5, 'bold 50px Arial', 'white', 'transparent', true);
|
|
86
80
|
|
|
87
|
-
const material = new StandardMaterial(`${_WORLD_COORD_ROOT_KEY}.${text}`,
|
|
81
|
+
const material = new StandardMaterial(`${_WORLD_COORD_ROOT_KEY}.${text}`, utilityLayerScene);
|
|
88
82
|
material.disableLighting = true;
|
|
89
83
|
material.emissiveColor = _DEBUG_AXIS_MAP[text].color;
|
|
90
84
|
material.diffuseTexture = dynamicTexture;
|
|
91
85
|
|
|
92
|
-
const plane = MeshBuilder.CreatePlane(
|
|
86
|
+
const plane = MeshBuilder.CreatePlane(
|
|
87
|
+
`${_WORLD_COORD_ROOT_KEY}.${text}.TextPlane`,
|
|
88
|
+
{ size: dimension / 10 },
|
|
89
|
+
utilityLayerScene
|
|
90
|
+
);
|
|
93
91
|
// make sure that text is located outside of arrow
|
|
94
92
|
plane.position = _DEBUG_AXIS_MAP[text].position.multiplyByFloats(
|
|
95
93
|
dimension * 1.05,
|