@combeenation/3d-viewer 12.4.1 → 13.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.
- package/dist/lib-cjs/buildinfo.json +1 -1
- package/dist/lib-cjs/commonjs.tsconfig.tsbuildinfo +1 -1
- package/dist/lib-cjs/index.d.ts +63 -63
- package/dist/lib-cjs/index.js +81 -114
- package/dist/lib-cjs/index.js.map +1 -1
- package/dist/lib-cjs/internal/cbnCustomBabylonLoaderPlugin.d.ts +10 -0
- package/dist/lib-cjs/internal/cbnCustomBabylonLoaderPlugin.js +124 -0
- package/dist/lib-cjs/internal/cbnCustomBabylonLoaderPlugin.js.map +1 -0
- package/dist/lib-cjs/internal/cloningHelper.d.ts +19 -0
- package/dist/lib-cjs/internal/cloningHelper.js +165 -0
- package/dist/lib-cjs/internal/cloningHelper.js.map +1 -0
- package/dist/lib-cjs/internal/deviceHelper.d.ts +9 -0
- package/dist/lib-cjs/{api/util → internal}/deviceHelper.js +6 -10
- package/dist/lib-cjs/internal/deviceHelper.js.map +1 -0
- package/dist/lib-cjs/internal/geometryHelper.d.ts +21 -0
- package/dist/lib-cjs/{api/util → internal}/geometryHelper.js +57 -24
- package/dist/lib-cjs/internal/geometryHelper.js.map +1 -0
- package/dist/lib-cjs/internal/metadataHelper.d.ts +26 -0
- package/dist/lib-cjs/internal/metadataHelper.js +51 -0
- package/dist/lib-cjs/internal/metadataHelper.js.map +1 -0
- package/dist/lib-cjs/internal/paintableHelper.d.ts +40 -0
- package/dist/lib-cjs/internal/paintableHelper.js +287 -0
- package/dist/lib-cjs/internal/paintableHelper.js.map +1 -0
- package/dist/lib-cjs/internal/tagsHelper.d.ts +12 -0
- package/dist/lib-cjs/internal/tagsHelper.js +38 -0
- package/dist/lib-cjs/internal/tagsHelper.js.map +1 -0
- package/dist/lib-cjs/manager/cameraManager.d.ts +51 -0
- package/dist/lib-cjs/manager/cameraManager.js +154 -0
- package/dist/lib-cjs/manager/cameraManager.js.map +1 -0
- package/dist/lib-cjs/manager/debugManager.d.ts +60 -0
- package/dist/lib-cjs/manager/debugManager.js +218 -0
- package/dist/lib-cjs/manager/debugManager.js.map +1 -0
- package/dist/lib-cjs/manager/eventManager.d.ts +52 -0
- package/dist/lib-cjs/manager/eventManager.js +72 -0
- package/dist/lib-cjs/manager/eventManager.js.map +1 -0
- package/dist/lib-cjs/{api/manager → manager}/gltfExportManager.d.ts +29 -34
- package/dist/lib-cjs/{api/manager → manager}/gltfExportManager.js +99 -120
- package/dist/lib-cjs/manager/gltfExportManager.js.map +1 -0
- package/dist/lib-cjs/manager/materialManager.d.ts +35 -0
- package/dist/lib-cjs/manager/materialManager.js +126 -0
- package/dist/lib-cjs/manager/materialManager.js.map +1 -0
- package/dist/lib-cjs/manager/modelManager.d.ts +145 -0
- package/dist/lib-cjs/manager/modelManager.js +381 -0
- package/dist/lib-cjs/manager/modelManager.js.map +1 -0
- package/dist/lib-cjs/manager/parameterManager.d.ts +210 -0
- package/dist/lib-cjs/manager/parameterManager.js +515 -0
- package/dist/lib-cjs/manager/parameterManager.js.map +1 -0
- package/dist/lib-cjs/manager/sceneManager.d.ts +45 -0
- package/dist/lib-cjs/manager/sceneManager.js +65 -0
- package/dist/lib-cjs/manager/sceneManager.js.map +1 -0
- package/dist/lib-cjs/manager/screenshotManager.d.ts +36 -0
- package/dist/lib-cjs/manager/screenshotManager.js +40 -0
- package/dist/lib-cjs/manager/screenshotManager.js.map +1 -0
- package/dist/lib-cjs/manager/textureManager.d.ts +12 -0
- package/dist/lib-cjs/manager/textureManager.js +44 -0
- package/dist/lib-cjs/manager/textureManager.js.map +1 -0
- package/dist/lib-cjs/viewer.d.ts +117 -0
- package/dist/lib-cjs/viewer.js +222 -0
- package/dist/lib-cjs/viewer.js.map +1 -0
- package/dist/lib-cjs/{api/classes/viewerError.d.ts → viewerError.d.ts} +6 -1
- package/dist/lib-cjs/{api/classes/viewerError.js → viewerError.js} +6 -1
- package/dist/lib-cjs/viewerError.js.map +1 -0
- package/package.json +10 -11
- package/src/dev.ts +14 -37
- package/src/{types.d.ts → globalTypes.d.ts} +8 -18
- package/src/index.ts +79 -113
- package/src/internal/cbnCustomBabylonLoaderPlugin.ts +149 -0
- package/src/internal/cloningHelper.ts +225 -0
- package/src/internal/deviceHelper.ts +25 -0
- package/src/{api/util → internal}/geometryHelper.ts +63 -24
- package/src/internal/metadataHelper.ts +63 -0
- package/src/internal/paintableHelper.ts +310 -0
- package/src/internal/tagsHelper.ts +41 -0
- package/src/manager/cameraManager.ts +236 -0
- package/src/manager/debugManager.ts +245 -0
- package/src/manager/eventManager.ts +72 -0
- package/src/{api/manager → manager}/gltfExportManager.ts +132 -125
- package/src/manager/materialManager.ts +135 -0
- package/src/manager/modelManager.ts +456 -0
- package/src/manager/parameterManager.ts +652 -0
- package/src/manager/sceneManager.ts +101 -0
- package/src/manager/screenshotManager.ts +59 -0
- package/src/manager/textureManager.ts +32 -0
- package/src/viewer.ts +296 -0
- package/src/{api/classes/viewerError.ts → viewerError.ts} +6 -1
- package/dist/lib-cjs/api/classes/animationInterface.d.ts +0 -8
- package/dist/lib-cjs/api/classes/animationInterface.js +0 -3
- package/dist/lib-cjs/api/classes/animationInterface.js.map +0 -1
- package/dist/lib-cjs/api/classes/dottedPath.d.ts +0 -79
- package/dist/lib-cjs/api/classes/dottedPath.js +0 -167
- package/dist/lib-cjs/api/classes/dottedPath.js.map +0 -1
- package/dist/lib-cjs/api/classes/element.d.ts +0 -153
- package/dist/lib-cjs/api/classes/element.js +0 -703
- package/dist/lib-cjs/api/classes/element.js.map +0 -1
- package/dist/lib-cjs/api/classes/event.d.ts +0 -401
- package/dist/lib-cjs/api/classes/event.js +0 -425
- package/dist/lib-cjs/api/classes/event.js.map +0 -1
- package/dist/lib-cjs/api/classes/eventBroadcaster.d.ts +0 -26
- package/dist/lib-cjs/api/classes/eventBroadcaster.js +0 -50
- package/dist/lib-cjs/api/classes/eventBroadcaster.js.map +0 -1
- package/dist/lib-cjs/api/classes/fuzzyMap.d.ts +0 -7
- package/dist/lib-cjs/api/classes/fuzzyMap.js +0 -22
- package/dist/lib-cjs/api/classes/fuzzyMap.js.map +0 -1
- package/dist/lib-cjs/api/classes/parameter.d.ts +0 -410
- package/dist/lib-cjs/api/classes/parameter.js +0 -643
- package/dist/lib-cjs/api/classes/parameter.js.map +0 -1
- package/dist/lib-cjs/api/classes/parameterObservable.d.ts +0 -36
- package/dist/lib-cjs/api/classes/parameterObservable.js +0 -73
- package/dist/lib-cjs/api/classes/parameterObservable.js.map +0 -1
- package/dist/lib-cjs/api/classes/parameterizable.d.ts +0 -15
- package/dist/lib-cjs/api/classes/parameterizable.js +0 -103
- package/dist/lib-cjs/api/classes/parameterizable.js.map +0 -1
- package/dist/lib-cjs/api/classes/placementAnimation.d.ts +0 -45
- package/dist/lib-cjs/api/classes/placementAnimation.js +0 -177
- package/dist/lib-cjs/api/classes/placementAnimation.js.map +0 -1
- package/dist/lib-cjs/api/classes/variant.d.ts +0 -261
- package/dist/lib-cjs/api/classes/variant.js +0 -873
- package/dist/lib-cjs/api/classes/variant.js.map +0 -1
- package/dist/lib-cjs/api/classes/variantInstance.d.ts +0 -53
- package/dist/lib-cjs/api/classes/variantInstance.js +0 -126
- package/dist/lib-cjs/api/classes/variantInstance.js.map +0 -1
- package/dist/lib-cjs/api/classes/variantParameterizable.d.ts +0 -17
- package/dist/lib-cjs/api/classes/variantParameterizable.js +0 -87
- package/dist/lib-cjs/api/classes/variantParameterizable.js.map +0 -1
- package/dist/lib-cjs/api/classes/viewer.d.ts +0 -215
- package/dist/lib-cjs/api/classes/viewer.js +0 -709
- package/dist/lib-cjs/api/classes/viewer.js.map +0 -1
- package/dist/lib-cjs/api/classes/viewerError.js.map +0 -1
- package/dist/lib-cjs/api/classes/viewerLight.d.ts +0 -66
- package/dist/lib-cjs/api/classes/viewerLight.js +0 -345
- package/dist/lib-cjs/api/classes/viewerLight.js.map +0 -1
- package/dist/lib-cjs/api/internal/lensRendering.d.ts +0 -8
- package/dist/lib-cjs/api/internal/lensRendering.js +0 -12
- package/dist/lib-cjs/api/internal/lensRendering.js.map +0 -1
- package/dist/lib-cjs/api/internal/sceneSetup.d.ts +0 -13
- package/dist/lib-cjs/api/internal/sceneSetup.js +0 -228
- package/dist/lib-cjs/api/internal/sceneSetup.js.map +0 -1
- package/dist/lib-cjs/api/manager/animationManager.d.ts +0 -30
- package/dist/lib-cjs/api/manager/animationManager.js +0 -127
- package/dist/lib-cjs/api/manager/animationManager.js.map +0 -1
- package/dist/lib-cjs/api/manager/gltfExportManager.js.map +0 -1
- package/dist/lib-cjs/api/manager/sceneManager.d.ts +0 -33
- package/dist/lib-cjs/api/manager/sceneManager.js +0 -129
- package/dist/lib-cjs/api/manager/sceneManager.js.map +0 -1
- package/dist/lib-cjs/api/manager/tagManager.d.ts +0 -118
- package/dist/lib-cjs/api/manager/tagManager.js +0 -531
- package/dist/lib-cjs/api/manager/tagManager.js.map +0 -1
- package/dist/lib-cjs/api/manager/textureLoadManager.d.ts +0 -22
- package/dist/lib-cjs/api/manager/textureLoadManager.js +0 -108
- package/dist/lib-cjs/api/manager/textureLoadManager.js.map +0 -1
- package/dist/lib-cjs/api/manager/variantInstanceManager.d.ts +0 -106
- package/dist/lib-cjs/api/manager/variantInstanceManager.js +0 -291
- package/dist/lib-cjs/api/manager/variantInstanceManager.js.map +0 -1
- package/dist/lib-cjs/api/store/specStorage.d.ts +0 -32
- package/dist/lib-cjs/api/store/specStorage.js +0 -66
- package/dist/lib-cjs/api/store/specStorage.js.map +0 -1
- package/dist/lib-cjs/api/util/babylonHelper.d.ts +0 -238
- package/dist/lib-cjs/api/util/babylonHelper.js +0 -826
- package/dist/lib-cjs/api/util/babylonHelper.js.map +0 -1
- package/dist/lib-cjs/api/util/debugHelper.d.ts +0 -9
- package/dist/lib-cjs/api/util/debugHelper.js +0 -94
- package/dist/lib-cjs/api/util/debugHelper.js.map +0 -1
- package/dist/lib-cjs/api/util/deviceHelper.d.ts +0 -9
- package/dist/lib-cjs/api/util/deviceHelper.js.map +0 -1
- package/dist/lib-cjs/api/util/geometryHelper.d.ts +0 -17
- package/dist/lib-cjs/api/util/geometryHelper.js.map +0 -1
- package/dist/lib-cjs/api/util/globalTypes.d.ts +0 -490
- package/dist/lib-cjs/api/util/globalTypes.js +0 -2
- package/dist/lib-cjs/api/util/globalTypes.js.map +0 -1
- package/dist/lib-cjs/api/util/resourceHelper.d.ts +0 -58
- package/dist/lib-cjs/api/util/resourceHelper.js +0 -215
- package/dist/lib-cjs/api/util/resourceHelper.js.map +0 -1
- package/dist/lib-cjs/api/util/sceneLoaderHelper.d.ts +0 -58
- package/dist/lib-cjs/api/util/sceneLoaderHelper.js +0 -229
- package/dist/lib-cjs/api/util/sceneLoaderHelper.js.map +0 -1
- package/dist/lib-cjs/api/util/stringHelper.d.ts +0 -13
- package/dist/lib-cjs/api/util/stringHelper.js +0 -33
- package/dist/lib-cjs/api/util/stringHelper.js.map +0 -1
- package/dist/lib-cjs/api/util/structureHelper.d.ts +0 -9
- package/dist/lib-cjs/api/util/structureHelper.js +0 -58
- package/dist/lib-cjs/api/util/structureHelper.js.map +0 -1
- package/src/api/classes/animationInterface.ts +0 -10
- package/src/api/classes/dottedPath.ts +0 -181
- package/src/api/classes/element.ts +0 -766
- package/src/api/classes/event.ts +0 -457
- package/src/api/classes/eventBroadcaster.ts +0 -52
- package/src/api/classes/fuzzyMap.ts +0 -21
- package/src/api/classes/parameter.ts +0 -686
- package/src/api/classes/parameterObservable.ts +0 -73
- package/src/api/classes/parameterizable.ts +0 -87
- package/src/api/classes/placementAnimation.ts +0 -162
- package/src/api/classes/variant.ts +0 -965
- package/src/api/classes/variantInstance.ts +0 -123
- package/src/api/classes/variantParameterizable.ts +0 -83
- package/src/api/classes/viewer.ts +0 -751
- package/src/api/classes/viewerLight.ts +0 -335
- package/src/api/internal/debugViewer.ts +0 -90
- package/src/api/internal/lensRendering.ts +0 -9
- package/src/api/internal/sceneSetup.ts +0 -208
- package/src/api/manager/animationManager.ts +0 -143
- package/src/api/manager/sceneManager.ts +0 -134
- package/src/api/manager/tagManager.ts +0 -572
- package/src/api/manager/textureLoadManager.ts +0 -107
- package/src/api/manager/variantInstanceManager.ts +0 -306
- package/src/api/store/specStorage.ts +0 -68
- package/src/api/util/babylonHelper.ts +0 -915
- package/src/api/util/debugHelper.ts +0 -121
- package/src/api/util/deviceHelper.ts +0 -31
- package/src/api/util/globalTypes.ts +0 -566
- package/src/api/util/resourceHelper.ts +0 -201
- package/src/api/util/sceneLoaderHelper.ts +0 -247
- package/src/api/util/stringHelper.ts +0 -30
- package/src/api/util/structureHelper.ts +0 -62
|
@@ -1,751 +0,0 @@
|
|
|
1
|
-
import buildInfo from '../../buildinfo.json';
|
|
2
|
-
import { sceneSetup } from '../internal/sceneSetup';
|
|
3
|
-
import { AnimationManager } from '../manager/animationManager';
|
|
4
|
-
import { GltfExportManager } from '../manager/gltfExportManager';
|
|
5
|
-
import { SceneManager } from '../manager/sceneManager';
|
|
6
|
-
import { TagManager } from '../manager/tagManager';
|
|
7
|
-
import { VariantInstanceManager } from '../manager/variantInstanceManager';
|
|
8
|
-
import { SpecStorage } from '../store/specStorage';
|
|
9
|
-
import { backgroundDomeName, envHelperMetadataName } from '../util/babylonHelper';
|
|
10
|
-
import { hideWorldCoordinates, showWorldCoordinates } from '../util/debugHelper';
|
|
11
|
-
import { getIsScaledDownDevice } from '../util/deviceHelper';
|
|
12
|
-
import { debounce, loadJson } from '../util/resourceHelper';
|
|
13
|
-
import { getCustomCbnBabylonLoaderPlugin } from '../util/sceneLoaderHelper';
|
|
14
|
-
import { replaceDots } from '../util/stringHelper';
|
|
15
|
-
import { isNodeIncludedInExclusionList } from '../util/structureHelper';
|
|
16
|
-
import * as Index from './../../index';
|
|
17
|
-
import { AnimationInterface } from './animationInterface';
|
|
18
|
-
import { Event } from './event';
|
|
19
|
-
import { EventBroadcaster } from './eventBroadcaster';
|
|
20
|
-
import { Parameter } from './parameter';
|
|
21
|
-
import { VariantInstance } from './variantInstance';
|
|
22
|
-
import { ArcRotateCamera } from '@babylonjs/core/Cameras/arcRotateCamera';
|
|
23
|
-
import { PickingInfo } from '@babylonjs/core/Collisions/pickingInfo';
|
|
24
|
-
import { BoundingInfo } from '@babylonjs/core/Culling/boundingInfo';
|
|
25
|
-
import { Engine } from '@babylonjs/core/Engines/engine';
|
|
26
|
-
import { IPointerEvent } from '@babylonjs/core/Events/deviceInputEvents';
|
|
27
|
-
import { EnvironmentHelper } from '@babylonjs/core/Helpers/environmentHelper';
|
|
28
|
-
import { PhotoDome } from '@babylonjs/core/Helpers/photoDome';
|
|
29
|
-
import { HighlightLayer } from '@babylonjs/core/Layers/highlightLayer';
|
|
30
|
-
import { ISceneLoaderPlugin, SceneLoader } from '@babylonjs/core/Loading/sceneLoader';
|
|
31
|
-
import { Vector3 } from '@babylonjs/core/Maths/math.vector';
|
|
32
|
-
import { Mesh } from '@babylonjs/core/Meshes/mesh';
|
|
33
|
-
import { ScreenshotTools } from '@babylonjs/core/Misc/screenshotTools';
|
|
34
|
-
import { WebXRSessionManager } from '@babylonjs/core/XR/webXRSessionManager';
|
|
35
|
-
import { Scene } from '@babylonjs/core/scene';
|
|
36
|
-
import { isString } from 'lodash-es';
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* The main exposed object. This is the entry point into the application
|
|
40
|
-
*
|
|
41
|
-
* ```js
|
|
42
|
-
* const canvas = document.getElementById( 'babylon-canvas' );
|
|
43
|
-
* const viewer = Viewer( canvas, '/path/to/index.json' );
|
|
44
|
-
* ```
|
|
45
|
-
* The class does nothing on its own and needs to {@link bootstrap}
|
|
46
|
-
*/
|
|
47
|
-
export class Viewer extends EventBroadcaster {
|
|
48
|
-
protected _scene: Scene | null = null;
|
|
49
|
-
|
|
50
|
-
protected _animationManager: AnimationManager | null = null;
|
|
51
|
-
|
|
52
|
-
protected _sceneManager: SceneManager | null = null;
|
|
53
|
-
|
|
54
|
-
protected _tagManager: TagManager | null = null;
|
|
55
|
-
|
|
56
|
-
protected _gltfExportManager: GltfExportManager | null = null;
|
|
57
|
-
|
|
58
|
-
protected _variantInstances: VariantInstanceManager | null = null;
|
|
59
|
-
|
|
60
|
-
// defaults to `false` as material cloning should be the edge case
|
|
61
|
-
protected _cloneMaterialsOnMutation: boolean = false;
|
|
62
|
-
|
|
63
|
-
protected _isRenderLoopPaused: boolean = false;
|
|
64
|
-
|
|
65
|
-
protected _nodeNamingStrategyHandler: NodeNamingStrategyHandler | null = null;
|
|
66
|
-
|
|
67
|
-
static version = buildInfo.version;
|
|
68
|
-
|
|
69
|
-
// these are constants for calculating the camera settings, depending on the bounding box size of the meshes to zoom
|
|
70
|
-
// the algorithms and constant values are directly taken from the Babylon.js repository
|
|
71
|
-
private static readonly _autofocusConstants = {
|
|
72
|
-
minZ: 100,
|
|
73
|
-
wheelPrecision: 100,
|
|
74
|
-
panningSensibility: 5000,
|
|
75
|
-
pinchPrecision: 200,
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* Help function for automatically creating a valid Spec from a list of variant names and dedicated GLB/babylon URLs.
|
|
80
|
-
* This data is most likely coming from babylon assets from the Combeenation system but other sources are also valid.
|
|
81
|
-
*/
|
|
82
|
-
public static generateSpec(genData: SpecGenerationData[]): AutoSpecStructureJson {
|
|
83
|
-
// dots in the variant name indicate inheritance, but this should not be the case for an auto-generated spec
|
|
84
|
-
// therefore dots are exchanged with slashes
|
|
85
|
-
const safeGenData: SpecGenerationData[] = genData.map(data => ({ ...data, name: replaceDots(data.name) }));
|
|
86
|
-
|
|
87
|
-
const spec: AutoSpecStructureJson = {
|
|
88
|
-
// common scene settings as suggested in the viewer docs
|
|
89
|
-
scene: {
|
|
90
|
-
engine: {
|
|
91
|
-
antialiasing: true,
|
|
92
|
-
options: {
|
|
93
|
-
preserveDrawingBuffer: true,
|
|
94
|
-
stencil: true,
|
|
95
|
-
xrCompatible: false,
|
|
96
|
-
},
|
|
97
|
-
// important for visual quality on iOS devices, this setting will set the hardware scaling proportional to the
|
|
98
|
-
// devices pixel ratio
|
|
99
|
-
adaptToDeviceRatio: true,
|
|
100
|
-
// limit texture size on iOS devices by default, in this way models (and AR exports) tend to work smoothly
|
|
101
|
-
// 1024 px should still be fine on mobiles
|
|
102
|
-
limitTextureSize: {
|
|
103
|
-
devices: 'iPhone',
|
|
104
|
-
size: 1024,
|
|
105
|
-
},
|
|
106
|
-
},
|
|
107
|
-
scene: {
|
|
108
|
-
globals: {},
|
|
109
|
-
},
|
|
110
|
-
},
|
|
111
|
-
setup: {
|
|
112
|
-
// create one instance for each input entry
|
|
113
|
-
// name and variant are named accordingly from the input, instance will be hidden by default and lazy loading
|
|
114
|
-
// is activated
|
|
115
|
-
instances: safeGenData.map(instanceData => ({
|
|
116
|
-
name: instanceData.name,
|
|
117
|
-
variant: instanceData.name,
|
|
118
|
-
lazy: true,
|
|
119
|
-
parameters: {
|
|
120
|
-
[Parameter.VISIBLE]: false,
|
|
121
|
-
},
|
|
122
|
-
})),
|
|
123
|
-
},
|
|
124
|
-
// variants definition is also mapped to the input array, using the name as key and url as glTF source
|
|
125
|
-
// no elements are created here, since this should be done automatically from the system
|
|
126
|
-
// => create one element which contains all root nodes of the imported 3d file (GLB or babylon)
|
|
127
|
-
variants: safeGenData.reduce((accVariants, curVariant) => {
|
|
128
|
-
accVariants[curVariant.name] = {
|
|
129
|
-
glTF: curVariant.url,
|
|
130
|
-
};
|
|
131
|
-
|
|
132
|
-
return accVariants;
|
|
133
|
-
}, {} as { [id: string]: StructureJson }),
|
|
134
|
-
};
|
|
135
|
-
|
|
136
|
-
return spec;
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
/**
|
|
140
|
-
* Returns all modules which are exported by the viewers index file.
|
|
141
|
-
*
|
|
142
|
-
* Needed by the [Combeenation viewer control](https://docs.combeenation.com/docs/3d-viewer-control) in situations where the viewer is injected from external code.
|
|
143
|
-
*
|
|
144
|
-
* See [Combeenation docs](https://docs.combeenation.com/docs/3d-viewer-control-with-custom-js) for more details.
|
|
145
|
-
*/
|
|
146
|
-
public static getAllViewerModules() {
|
|
147
|
-
return Index;
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
/**
|
|
151
|
-
* Constructor
|
|
152
|
-
*/
|
|
153
|
-
public constructor(public readonly canvas: HTMLCanvasElement, protected structureJson: string | StructureJson) {
|
|
154
|
-
super();
|
|
155
|
-
this._tagManager = new TagManager(this);
|
|
156
|
-
this._nodeNamingStrategyHandler = (node, payload) => {
|
|
157
|
-
const suffix: string[] = [];
|
|
158
|
-
// (1) instance part
|
|
159
|
-
const variantInstances = this.variantInstances.allWithVariantName(payload.variant.name);
|
|
160
|
-
if (variantInstances.length > 0) {
|
|
161
|
-
suffix.push(payload.variantInstance.name);
|
|
162
|
-
}
|
|
163
|
-
// (2) element part
|
|
164
|
-
if (payload.variant.elements.length > 0) {
|
|
165
|
-
const nodeElements = payload.variant.elements.filter(
|
|
166
|
-
e => e.nodesFlat.filter(n => n.metadata?.cloneSource?.id === node.id).length > 0
|
|
167
|
-
);
|
|
168
|
-
if (nodeElements.length > 0) {
|
|
169
|
-
suffix.push(payload.variantParameterizable.name);
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
// (3) merge together
|
|
173
|
-
const originalName = node.metadata?.originalName || node.name;
|
|
174
|
-
return [originalName, ...suffix.filter(s => !!s)].join('.');
|
|
175
|
-
};
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
/**
|
|
179
|
-
* Gets the Babylon.js Scene that is attached to the instance.
|
|
180
|
-
*
|
|
181
|
-
* @throws Error if the `scene` has not been initialized.
|
|
182
|
-
*/
|
|
183
|
-
get scene(): Scene {
|
|
184
|
-
if (!this._scene) {
|
|
185
|
-
throw new Error(`Scene has not been initialized.`);
|
|
186
|
-
}
|
|
187
|
-
return this._scene;
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
/**
|
|
191
|
-
* Gets the {@link SceneManager} attached to the viewer.
|
|
192
|
-
*
|
|
193
|
-
* @throws Error if the {@link SceneManager} has not been initialized.
|
|
194
|
-
*/
|
|
195
|
-
get sceneManager(): SceneManager {
|
|
196
|
-
if (!this._sceneManager) {
|
|
197
|
-
throw new Error(`SceneManager has not been initialized.`);
|
|
198
|
-
}
|
|
199
|
-
return this._sceneManager;
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
/**
|
|
203
|
-
* Gets the {@link GltfExportManager} attached to the viewer.
|
|
204
|
-
*
|
|
205
|
-
* @throws Error if the {@link GltfExportManager} has not been initialized.
|
|
206
|
-
*/
|
|
207
|
-
get gltfExportManager(): GltfExportManager {
|
|
208
|
-
if (!this._gltfExportManager) {
|
|
209
|
-
throw new Error(`GltfExportManager has not been initialized.`);
|
|
210
|
-
}
|
|
211
|
-
return this._gltfExportManager;
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
/**
|
|
215
|
-
* Gets the Babylon.js Engine that is attached to the viewer.
|
|
216
|
-
*/
|
|
217
|
-
get engine(): Engine {
|
|
218
|
-
return this.scene.getEngine();
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
/**
|
|
222
|
-
* Gets the {@link VariantInstanceManager} attached to the viewer.
|
|
223
|
-
*
|
|
224
|
-
* @throws Error if the {@link VariantInstanceManager} has not been initialized.
|
|
225
|
-
*/
|
|
226
|
-
get variantInstances(): VariantInstanceManager {
|
|
227
|
-
if (!this._variantInstances) {
|
|
228
|
-
throw Error(`There is no variantInstanceManager.`);
|
|
229
|
-
}
|
|
230
|
-
return this._variantInstances;
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
/**
|
|
234
|
-
* Gets the {@link AnimationManager} attached to the viewer.
|
|
235
|
-
*
|
|
236
|
-
* @throws Error if the {@link AnimationManager} has not been initialized.
|
|
237
|
-
*/
|
|
238
|
-
get animationManager(): AnimationManager {
|
|
239
|
-
if (!this._animationManager) {
|
|
240
|
-
throw new Error(`There is no animationManager instance.`);
|
|
241
|
-
}
|
|
242
|
-
return this._animationManager;
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
get tagManager(): TagManager {
|
|
246
|
-
if (!this._tagManager) {
|
|
247
|
-
throw new Error(`There is no tagManager instance.`);
|
|
248
|
-
}
|
|
249
|
-
return this._tagManager;
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
/**
|
|
253
|
-
* Gets the `cloneMaterialsOnMutation` flag, as defined in the spec
|
|
254
|
-
*/
|
|
255
|
-
get cloneMaterialsOnMutation(): boolean {
|
|
256
|
-
return this._cloneMaterialsOnMutation;
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
/**
|
|
260
|
-
* Gets the strategy handler for naming cloned nodes.
|
|
261
|
-
*/
|
|
262
|
-
get nodeNamingStrategyHandler(): NodeNamingStrategyHandler {
|
|
263
|
-
if (!this._nodeNamingStrategyHandler) {
|
|
264
|
-
throw new Error(`The NodeNamingStrategyHandler has not been registered yet.`);
|
|
265
|
-
}
|
|
266
|
-
return this._nodeNamingStrategyHandler;
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
/**
|
|
270
|
-
* Sets the strategy handler for naming cloned nodes.\
|
|
271
|
-
* Check the docs of the tag managers [renaming](https://3dviewer.docs.combeenation.com/pages/documentation/Tag-Manager.html#uniqueness-of-node-and-tag-names)
|
|
272
|
-
* chapter for further details.
|
|
273
|
-
*/
|
|
274
|
-
set nodeNamingStrategyHandler(value: NodeNamingStrategyHandler) {
|
|
275
|
-
if (!value || typeof value !== 'function') {
|
|
276
|
-
throw new Error(`The NodeNamingStrategyHandler is not a callable function.`);
|
|
277
|
-
}
|
|
278
|
-
this._nodeNamingStrategyHandler = value;
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
/**
|
|
282
|
-
* Starts the application. This will
|
|
283
|
-
* * load the given "index" JSON file
|
|
284
|
-
* * setup the scene with the "scene" JSON file
|
|
285
|
-
* * create an (optional) default setup with different variant settings
|
|
286
|
-
* * sets up resizing by attaching a debounced version of {@link resize}
|
|
287
|
-
*
|
|
288
|
-
* @throws Error if any of the files is not found/valid
|
|
289
|
-
*
|
|
290
|
-
* @emits {@link Event.BOOTSTRAP_START}
|
|
291
|
-
* @emits {@link Event.BOOTSTRAP_END}
|
|
292
|
-
*/
|
|
293
|
-
public async bootstrap(tagManagerParameterValues?: TagManagerParameterValue[]): Promise<Viewer> {
|
|
294
|
-
this.broadcastEvent(Event.BOOTSTRAP_START, this);
|
|
295
|
-
let indexJson;
|
|
296
|
-
if (isString(this.structureJson)) {
|
|
297
|
-
indexJson = await loadJson<StructureJson>(this.structureJson);
|
|
298
|
-
} else {
|
|
299
|
-
indexJson = this.structureJson;
|
|
300
|
-
}
|
|
301
|
-
if (!indexJson.scene) {
|
|
302
|
-
throw new Error(`No "scene" property found for bootstrapping.`);
|
|
303
|
-
}
|
|
304
|
-
// fill spec store
|
|
305
|
-
SpecStorage.createFromSpec(indexJson);
|
|
306
|
-
// init custom loader plugin
|
|
307
|
-
this.initCbnBabylonLoaderPlugin();
|
|
308
|
-
// load scene
|
|
309
|
-
if (isString(indexJson.scene)) {
|
|
310
|
-
const sceneJson = await loadJson<SceneJson>(indexJson.scene);
|
|
311
|
-
indexJson.scene = sceneJson;
|
|
312
|
-
}
|
|
313
|
-
this._scene = await this.initScene();
|
|
314
|
-
// set initial tag manager parameter values
|
|
315
|
-
if (tagManagerParameterValues) {
|
|
316
|
-
await this.tagManager.setParameterValues(tagManagerParameterValues);
|
|
317
|
-
}
|
|
318
|
-
// create instance manager
|
|
319
|
-
this._variantInstances = await VariantInstanceManager.create(this);
|
|
320
|
-
// create optional default instances
|
|
321
|
-
if (indexJson.setup) {
|
|
322
|
-
if (isString(indexJson.setup)) {
|
|
323
|
-
const setupJson = await loadJson<SetupJson>(indexJson.setup);
|
|
324
|
-
indexJson.setup = setupJson;
|
|
325
|
-
}
|
|
326
|
-
this.printInstanceDefinitions(indexJson.setup);
|
|
327
|
-
await this.createVariantInstances();
|
|
328
|
-
}
|
|
329
|
-
this.broadcastEvent(Event.VARIANT_INSTANCES_READY, this);
|
|
330
|
-
// create gltf export manager
|
|
331
|
-
this._gltfExportManager = await GltfExportManager.create(this);
|
|
332
|
-
// resize handler
|
|
333
|
-
window.addEventListener('resize', debounce(this.resize.bind(this), 100));
|
|
334
|
-
// wait until scene is completely ready
|
|
335
|
-
await this.scene.whenReadyAsync();
|
|
336
|
-
// event broadcasting
|
|
337
|
-
this.broadcastEvent(Event.BOOTSTRAP_END, this);
|
|
338
|
-
// render loop
|
|
339
|
-
this.engine.runRenderLoop(() => {
|
|
340
|
-
if (!this._isRenderLoopPaused) this.scene.render();
|
|
341
|
-
});
|
|
342
|
-
return this;
|
|
343
|
-
}
|
|
344
|
-
|
|
345
|
-
/**
|
|
346
|
-
* Enables the Babylon.js [Inspector](https://doc.babylonjs.com/toolsAndResources/tools/inspector).\
|
|
347
|
-
* Due to the additional size of the inspector, this function is only available in "development" builds!
|
|
348
|
-
*
|
|
349
|
-
* @returns Signalizes if inspector could be loaded
|
|
350
|
-
*/
|
|
351
|
-
public async enableDebugLayer(options?: IInspectorOptions): Promise<boolean> {
|
|
352
|
-
if (process.env.NODE_ENV === 'development') {
|
|
353
|
-
const inspModule = await import(/* webpackChunkName: "inspector"*/ '@babylonjs/inspector');
|
|
354
|
-
|
|
355
|
-
if (!options && window.Cbn) {
|
|
356
|
-
// special case for usage in Combeenation configurator:
|
|
357
|
-
// if no options are set the inspector will be rendered into the parent element of the configurator
|
|
358
|
-
// in this way the configurator layout itself will not be affected by the inspector
|
|
359
|
-
const cfgrParentEl = window.Cbn.utils.Viewer3dHelper.getCfgrParentDomElementForInspector();
|
|
360
|
-
inspModule.Inspector.Show(this.scene, { globalRoot: cfgrParentEl });
|
|
361
|
-
} else {
|
|
362
|
-
inspModule.Inspector.Show(this.scene, options ?? {});
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
// load additional packages for certain inspector features like "node material editor"
|
|
366
|
-
// this is done after showing the debug layer to save time
|
|
367
|
-
await import(/* webpackChunkName: "node-material-editor" */ '@babylonjs/node-editor');
|
|
368
|
-
await import(/* webpackChunkName: "node-geometry-editor" */ '@babylonjs/node-geometry-editor');
|
|
369
|
-
|
|
370
|
-
return true;
|
|
371
|
-
} else {
|
|
372
|
-
// inspector not available, set according warning message in console
|
|
373
|
-
if (window.Cbn) {
|
|
374
|
-
console.warn(`Inspector not loaded.
|
|
375
|
-
The inspector can only be used in development builds (e.g. during development with watch mode, in the configurator preview, ...)
|
|
376
|
-
but not in production (e.g. production build of Custom JS, published configurator, ...).`);
|
|
377
|
-
} else {
|
|
378
|
-
console.warn(`Inspector not loaded.
|
|
379
|
-
The inspector can only be used in development builds.`);
|
|
380
|
-
}
|
|
381
|
-
|
|
382
|
-
return false;
|
|
383
|
-
}
|
|
384
|
-
}
|
|
385
|
-
|
|
386
|
-
/**
|
|
387
|
-
* Destroys all registered {@link VariantInstance}s that are registered
|
|
388
|
-
*/
|
|
389
|
-
public destroyVariantInstances(): Viewer {
|
|
390
|
-
this.variantInstances.all.forEach(variantInstance => {
|
|
391
|
-
this.variantInstances.destroy(variantInstance.name);
|
|
392
|
-
});
|
|
393
|
-
return this;
|
|
394
|
-
}
|
|
395
|
-
|
|
396
|
-
/**
|
|
397
|
-
* Trigger a resize event for the `Engine`
|
|
398
|
-
*/
|
|
399
|
-
public resize(): Viewer {
|
|
400
|
-
this.engine.resize();
|
|
401
|
-
return this;
|
|
402
|
-
}
|
|
403
|
-
|
|
404
|
-
/**
|
|
405
|
-
* A convenience method for directly getting a Node from a {@link VariantInstance} and an {@link Element} by its
|
|
406
|
-
* {@link DottedPath}s.
|
|
407
|
-
*/
|
|
408
|
-
public async getNode(
|
|
409
|
-
variantInstanceName: string,
|
|
410
|
-
elementDottedPath: DottedPathArgument,
|
|
411
|
-
nodeDottedPath: DottedPathArgument
|
|
412
|
-
): Promise<TransformNode> {
|
|
413
|
-
const variantInstance = await this.variantInstances.get(variantInstanceName);
|
|
414
|
-
return variantInstance.getNode(elementDottedPath, nodeDottedPath);
|
|
415
|
-
}
|
|
416
|
-
|
|
417
|
-
/**
|
|
418
|
-
* A convenience method for directly getting a Node from a {@link VariantInstance} and an {@link Element} by its
|
|
419
|
-
* {@link DottedPath}s.
|
|
420
|
-
*/
|
|
421
|
-
public async getMesh(
|
|
422
|
-
variantInstanceName: string,
|
|
423
|
-
elementDottedPath: DottedPathArgument,
|
|
424
|
-
meshDottedPath: DottedPathArgument
|
|
425
|
-
): Promise<Mesh | null> {
|
|
426
|
-
const variantInstance = await this.variantInstances.get(variantInstanceName);
|
|
427
|
-
return variantInstance.getMesh(elementDottedPath, meshDottedPath);
|
|
428
|
-
}
|
|
429
|
-
|
|
430
|
-
/**
|
|
431
|
-
* Switches the camera
|
|
432
|
-
*
|
|
433
|
-
* @emits {@link Event.CAMERA_SWITCHED}
|
|
434
|
-
*/
|
|
435
|
-
public switchCamera(newCamera: string, reset: boolean = true): Viewer {
|
|
436
|
-
const camera = this.scene.getCameraByName(newCamera);
|
|
437
|
-
if (camera) {
|
|
438
|
-
const activeCamera = this.scene.activeCamera;
|
|
439
|
-
if (activeCamera) {
|
|
440
|
-
activeCamera.detachControl(this.engine.getRenderingCanvas()!);
|
|
441
|
-
}
|
|
442
|
-
if (reset) {
|
|
443
|
-
camera.restoreState();
|
|
444
|
-
}
|
|
445
|
-
this.scene.setActiveCameraByName(newCamera);
|
|
446
|
-
camera.attachControl(this.engine.getRenderingCanvas()!);
|
|
447
|
-
this.broadcastEvent(Event.CAMERA_SWITCHED, camera);
|
|
448
|
-
} else {
|
|
449
|
-
throw new Error(`Given camera "${newCamera}" not found.`);
|
|
450
|
-
}
|
|
451
|
-
// TODO: put traceable observers to new camera (@see element)
|
|
452
|
-
return this;
|
|
453
|
-
}
|
|
454
|
-
|
|
455
|
-
/**
|
|
456
|
-
* Moves or animates the active camera to given `placement`.
|
|
457
|
-
*/
|
|
458
|
-
public async moveActiveCameraTo(
|
|
459
|
-
placement: string | PlacementDefinition,
|
|
460
|
-
animation?: string | AnimationDefinition
|
|
461
|
-
): Promise<AnimationInterface> {
|
|
462
|
-
return this.animationManager.animateToPlacement(this.sceneManager.activeCamera, placement, animation);
|
|
463
|
-
}
|
|
464
|
-
|
|
465
|
-
/**
|
|
466
|
-
* Takes a sceenshot the the current scene. The result is a string containing a base64 encoded image
|
|
467
|
-
*/
|
|
468
|
-
public screenshot(settings?: ScreenshotSettings): Promise<string> {
|
|
469
|
-
return new Promise((resolve, reject) => {
|
|
470
|
-
if (!this.engine) {
|
|
471
|
-
return reject('Engine is null');
|
|
472
|
-
}
|
|
473
|
-
if (!this.scene) {
|
|
474
|
-
return reject('Scene is null');
|
|
475
|
-
}
|
|
476
|
-
this.scene.render(); // in combination with a render target, we need to refresh the scene manually to get the latest view
|
|
477
|
-
ScreenshotTools.CreateScreenshotUsingRenderTarget(
|
|
478
|
-
this.engine,
|
|
479
|
-
this.sceneManager.activeCamera,
|
|
480
|
-
settings?.size ?? { width: this.canvas.clientWidth, height: this.canvas.clientHeight },
|
|
481
|
-
resolve,
|
|
482
|
-
settings?.mimeType ?? 'image/png',
|
|
483
|
-
settings?.samples ?? 1,
|
|
484
|
-
settings?.antialiasing ?? false,
|
|
485
|
-
settings?.fileName,
|
|
486
|
-
settings?.renderSprites ?? false
|
|
487
|
-
);
|
|
488
|
-
});
|
|
489
|
-
}
|
|
490
|
-
|
|
491
|
-
/**
|
|
492
|
-
* Checks whether the browser is capable of handling XR.
|
|
493
|
-
*/
|
|
494
|
-
public async isBrowserARCapable(): Promise<boolean> {
|
|
495
|
-
return await WebXRSessionManager.IsSessionSupportedAsync('immersive-ar');
|
|
496
|
-
}
|
|
497
|
-
|
|
498
|
-
/**
|
|
499
|
-
* Calculates the bounding box information from all visible meshes on the scene.
|
|
500
|
-
*/
|
|
501
|
-
public calculateBoundingInfo(excludeGeometry?: ExcludedGeometryList): BoundingInfo {
|
|
502
|
-
if (this.scene.meshes.length === 0) {
|
|
503
|
-
throw new Error('There are currently no meshes on the scene.');
|
|
504
|
-
}
|
|
505
|
-
this.scene.render(); // CB-6062: workaround for BoundingBox not respecting render loop
|
|
506
|
-
const { max, min } = this.scene.meshes
|
|
507
|
-
.filter(mesh => {
|
|
508
|
-
const isEnabled = mesh.isEnabled();
|
|
509
|
-
// ignore meshes with invalid bounding infos
|
|
510
|
-
const hasValidBBoxInfo = mesh.getBoundingInfo().boundingSphere.radius > 0;
|
|
511
|
-
// ignore meshes with infinite distance, typically these are sky boxes
|
|
512
|
-
const hasInfiniteDistance = mesh.infiniteDistance;
|
|
513
|
-
// ignore excluded meshes
|
|
514
|
-
const isExcluded = excludeGeometry ? isNodeIncludedInExclusionList(mesh, excludeGeometry) : false;
|
|
515
|
-
return isEnabled && hasValidBBoxInfo && !hasInfiniteDistance && !isExcluded;
|
|
516
|
-
})
|
|
517
|
-
.reduce(
|
|
518
|
-
(accBBoxMinMax, curMesh, idx) => {
|
|
519
|
-
const bBox = curMesh.getBoundingInfo().boundingBox;
|
|
520
|
-
// use the first entry in the array as default value and get the resulting maximum/minimum values
|
|
521
|
-
const max = idx === 0 ? bBox.maximumWorld : Vector3.Maximize(accBBoxMinMax.max, bBox.maximumWorld);
|
|
522
|
-
const min = idx === 0 ? bBox.minimumWorld : Vector3.Minimize(accBBoxMinMax.min, bBox.minimumWorld);
|
|
523
|
-
return { max, min };
|
|
524
|
-
},
|
|
525
|
-
{ max: new Vector3(), min: new Vector3() }
|
|
526
|
-
);
|
|
527
|
-
|
|
528
|
-
const boundingInfo = new BoundingInfo(min, max);
|
|
529
|
-
return boundingInfo;
|
|
530
|
-
}
|
|
531
|
-
|
|
532
|
-
/**
|
|
533
|
-
* Focuses the camera to see every visible mesh in scene and tries to optimize wheel precision and panning
|
|
534
|
-
*/
|
|
535
|
-
public async autofocusActiveCamera(settings?: AutofocusSettings) {
|
|
536
|
-
// first check some preconditions
|
|
537
|
-
const activeCamera = this.scene.activeCamera;
|
|
538
|
-
if (!activeCamera) {
|
|
539
|
-
throw new Error('No active camera found when using autofocus feature.');
|
|
540
|
-
}
|
|
541
|
-
if (!(activeCamera instanceof ArcRotateCamera)) {
|
|
542
|
-
const cameraClsName = activeCamera.getClassName();
|
|
543
|
-
throw new Error(`Camera of type "${cameraClsName}" is not implemented yet to use autofocus feature.`);
|
|
544
|
-
}
|
|
545
|
-
|
|
546
|
-
let exclude = settings?.exclude || [];
|
|
547
|
-
|
|
548
|
-
// Exclude shown photo dome or environment helper from bounding box calculation
|
|
549
|
-
const photoDome = this.scene.getNodeByName(backgroundDomeName) as undefined | PhotoDome;
|
|
550
|
-
const photoDomeMeshes = photoDome?.getChildMeshes();
|
|
551
|
-
if (photoDomeMeshes?.length) {
|
|
552
|
-
exclude = [...exclude, ...photoDomeMeshes];
|
|
553
|
-
}
|
|
554
|
-
|
|
555
|
-
const envHelper = this.scene.metadata?.[envHelperMetadataName] as undefined | EnvironmentHelper;
|
|
556
|
-
if (envHelper?.rootMesh) {
|
|
557
|
-
exclude = [...exclude, envHelper.rootMesh];
|
|
558
|
-
}
|
|
559
|
-
|
|
560
|
-
// get bounding box of all visible meshes, this is the base for the autofocus algorithm
|
|
561
|
-
const boundingInfo = this.calculateBoundingInfo(exclude);
|
|
562
|
-
|
|
563
|
-
const radius = boundingInfo.boundingSphere.radius;
|
|
564
|
-
const center = boundingInfo.boundingSphere.center;
|
|
565
|
-
const diameter = radius * 2;
|
|
566
|
-
|
|
567
|
-
// set lower radius limit on edge of bounding sphere to make sure that we can't dive into the meshes
|
|
568
|
-
activeCamera.lowerRadiusLimit = radius;
|
|
569
|
-
|
|
570
|
-
// additional settings
|
|
571
|
-
// constants for division are taken directly from Babylon.js repository
|
|
572
|
-
activeCamera.minZ = Math.min(radius / Viewer._autofocusConstants.minZ, 1);
|
|
573
|
-
if (settings?.adjustWheelPrecision !== false) {
|
|
574
|
-
activeCamera.wheelPrecision = Viewer._autofocusConstants.wheelPrecision / radius;
|
|
575
|
-
}
|
|
576
|
-
if (settings?.adjustPanningSensibility !== false) {
|
|
577
|
-
activeCamera.panningSensibility = Viewer._autofocusConstants.panningSensibility / diameter;
|
|
578
|
-
}
|
|
579
|
-
if (settings?.adjustPinchPrecision !== false) {
|
|
580
|
-
activeCamera.pinchPrecision = Viewer._autofocusConstants.pinchPrecision / radius;
|
|
581
|
-
}
|
|
582
|
-
|
|
583
|
-
const radiusFactor = settings?.radiusFactor ?? 1.5;
|
|
584
|
-
const alpha = (settings?.alpha ?? -90) * (Math.PI / 180);
|
|
585
|
-
const beta = (settings?.beta ?? 90) * (Math.PI / 180);
|
|
586
|
-
|
|
587
|
-
const newCameraPosition = {
|
|
588
|
-
alpha: alpha,
|
|
589
|
-
beta: beta,
|
|
590
|
-
// this calculation is a bit "simplified", as it doesn't consider the viewport ratio or the frustum angle
|
|
591
|
-
// but it's also done this way in the Babylon.js repository, so it should be fine for us
|
|
592
|
-
radius: diameter * radiusFactor,
|
|
593
|
-
target: center,
|
|
594
|
-
};
|
|
595
|
-
|
|
596
|
-
await this.animationManager.animateToPlacement(activeCamera, newCameraPosition, settings?.animation);
|
|
597
|
-
}
|
|
598
|
-
|
|
599
|
-
/**
|
|
600
|
-
* Resets everything by calling {@link destroy} to clear all references and {@link bootstrap} to setup a clean
|
|
601
|
-
* environment
|
|
602
|
-
*/
|
|
603
|
-
public async reset(tagManagerParameterValues?: TagManagerParameterValue[]): Promise<Viewer> {
|
|
604
|
-
await this.destroy();
|
|
605
|
-
return this.bootstrap(tagManagerParameterValues);
|
|
606
|
-
}
|
|
607
|
-
|
|
608
|
-
/**
|
|
609
|
-
* Destroys
|
|
610
|
-
*
|
|
611
|
-
* * all {@link VariantInstance}s using {@link destroyVariantInstances}
|
|
612
|
-
* * calling `dispose` on the `Engine` and `Scene`
|
|
613
|
-
*/
|
|
614
|
-
public destroy(): Viewer {
|
|
615
|
-
this.destroyVariantInstances();
|
|
616
|
-
this.engine.dispose();
|
|
617
|
-
SpecStorage.destroy();
|
|
618
|
-
return this;
|
|
619
|
-
}
|
|
620
|
-
|
|
621
|
-
/**
|
|
622
|
-
* Show world coordinate system with given dimension (for debugging purpose).
|
|
623
|
-
*/
|
|
624
|
-
public showWorldCoordinates(dimension: number) {
|
|
625
|
-
showWorldCoordinates(dimension);
|
|
626
|
-
}
|
|
627
|
-
|
|
628
|
-
/**
|
|
629
|
-
* Hide world coordinate system.
|
|
630
|
-
*/
|
|
631
|
-
public hideWorldCoordinates() {
|
|
632
|
-
hideWorldCoordinates();
|
|
633
|
-
}
|
|
634
|
-
|
|
635
|
-
/**
|
|
636
|
-
* Pause render loop.
|
|
637
|
-
*/
|
|
638
|
-
public pauseRendering() {
|
|
639
|
-
this._isRenderLoopPaused = true;
|
|
640
|
-
}
|
|
641
|
-
|
|
642
|
-
/**
|
|
643
|
-
* Resume render loop when paused.
|
|
644
|
-
*/
|
|
645
|
-
public resumeRendering() {
|
|
646
|
-
this._isRenderLoopPaused = false;
|
|
647
|
-
}
|
|
648
|
-
|
|
649
|
-
/**
|
|
650
|
-
* Prints defined instances from SetupJson to the console.
|
|
651
|
-
*/
|
|
652
|
-
protected printInstanceDefinitions(setupJson: SetupJson) {
|
|
653
|
-
console.info(
|
|
654
|
-
'The following variant instances have been read from the given spec: ',
|
|
655
|
-
setupJson.instances.map(o => o.name)
|
|
656
|
-
);
|
|
657
|
-
}
|
|
658
|
-
|
|
659
|
-
/**
|
|
660
|
-
* @emits {@link Event.SCENE_PROCESSING_START}
|
|
661
|
-
* @emits {@link Event.SCENE_PROCESSING_END}
|
|
662
|
-
*/
|
|
663
|
-
protected async initScene(): Promise<Scene> {
|
|
664
|
-
const sceneJson = SpecStorage.get<SceneJson>('scene');
|
|
665
|
-
this.broadcastEvent(Event.SCENE_PROCESSING_START, sceneJson);
|
|
666
|
-
const engine = new Engine(
|
|
667
|
-
this.canvas as HTMLCanvasElement,
|
|
668
|
-
sceneJson.engine?.antialiasing ?? false,
|
|
669
|
-
sceneJson.engine?.options,
|
|
670
|
-
sceneJson.engine?.adaptToDeviceRatio ?? false
|
|
671
|
-
);
|
|
672
|
-
|
|
673
|
-
const isScaledDownDevice = getIsScaledDownDevice();
|
|
674
|
-
if (isScaledDownDevice) {
|
|
675
|
-
// reduce texture size if required
|
|
676
|
-
engine.getCaps().maxTextureSize = (sceneJson.engine!.limitTextureSize as LimitTextureSizeConfig).size;
|
|
677
|
-
}
|
|
678
|
-
|
|
679
|
-
if (sceneJson.engine?.useParallelShaderCompile === false) {
|
|
680
|
-
engine.getCaps().parallelShaderCompile = undefined;
|
|
681
|
-
}
|
|
682
|
-
|
|
683
|
-
const scene = await sceneSetup(engine, sceneJson);
|
|
684
|
-
if (sceneJson.meshPicking) {
|
|
685
|
-
new HighlightLayer('default', scene);
|
|
686
|
-
scene.onPointerPick = (pointerEvent: IPointerEvent, pickInfo: PickingInfo) => {
|
|
687
|
-
if (!pickInfo.hit) {
|
|
688
|
-
return;
|
|
689
|
-
}
|
|
690
|
-
const mesh = pickInfo.pickedMesh;
|
|
691
|
-
this.broadcastEvent(Event.MESH_PICKED, mesh, mesh?.metadata.element, mesh?.metadata.variant);
|
|
692
|
-
if (mesh?.metadata.element) {
|
|
693
|
-
this.broadcastEvent(Event.ELEMENT_PICKED, mesh.metadata.element);
|
|
694
|
-
}
|
|
695
|
-
if (mesh?.metadata.variant) {
|
|
696
|
-
if (mesh.metadata.variant.inheritedParameters[Parameter.HIGHLIGHT_ENABLED]) {
|
|
697
|
-
mesh.metadata.variant.toggleHighlight();
|
|
698
|
-
}
|
|
699
|
-
this.broadcastEvent(Event.VARIANT_PICKED, mesh.metadata.variant);
|
|
700
|
-
}
|
|
701
|
-
};
|
|
702
|
-
}
|
|
703
|
-
|
|
704
|
-
this._sceneManager = await SceneManager.create(scene);
|
|
705
|
-
this._animationManager = await AnimationManager.create(scene);
|
|
706
|
-
if (sceneJson.cloneMaterialsOnMutation !== undefined) {
|
|
707
|
-
this._cloneMaterialsOnMutation = sceneJson.cloneMaterialsOnMutation;
|
|
708
|
-
}
|
|
709
|
-
// register observers for tag manager
|
|
710
|
-
this.tagManager.registerNewObjectObservers(scene);
|
|
711
|
-
this.broadcastEvent(Event.SCENE_PROCESSING_END, scene);
|
|
712
|
-
|
|
713
|
-
return scene;
|
|
714
|
-
}
|
|
715
|
-
|
|
716
|
-
/**
|
|
717
|
-
* Register custom file loader for babylon files which adds "missing-material" metadata to meshes which reference
|
|
718
|
-
* materials that are not present in the `materials` section of the given babylon file.
|
|
719
|
-
*
|
|
720
|
-
* Required for babylon files & materials loaded from "Combeenation configurator assets".
|
|
721
|
-
*/
|
|
722
|
-
protected initCbnBabylonLoaderPlugin() {
|
|
723
|
-
const previousLoaderPlugin = SceneLoader.GetPluginForExtension('.babylon') as ISceneLoaderPlugin;
|
|
724
|
-
const customLoaderPlugin = getCustomCbnBabylonLoaderPlugin(previousLoaderPlugin);
|
|
725
|
-
SceneLoader.RegisterPlugin(customLoaderPlugin);
|
|
726
|
-
}
|
|
727
|
-
|
|
728
|
-
/**
|
|
729
|
-
* Batch creation of multiple {@link VariantInstance} objects with a {@link SetupJson} object passed
|
|
730
|
-
*/
|
|
731
|
-
protected async createVariantInstances(): Promise<VariantInstance[]> {
|
|
732
|
-
const setupJson = SpecStorage.get<SetupJson>('setup');
|
|
733
|
-
const instances: VariantInstance[] = [];
|
|
734
|
-
for (const instanceDefinition of setupJson.instances) {
|
|
735
|
-
// don't create the instance right away if `lazy` is set, register it for later creation (on first usage) instead
|
|
736
|
-
// however if the variant should be `visible` by default, `lazy` loading doesn't make sense and should therefore
|
|
737
|
-
// be overruled by the `visible` flag
|
|
738
|
-
if (instanceDefinition.lazy && instanceDefinition.parameters?.visible !== true) {
|
|
739
|
-
this.variantInstances.register(instanceDefinition);
|
|
740
|
-
continue;
|
|
741
|
-
}
|
|
742
|
-
const instance = await this.variantInstances.create(
|
|
743
|
-
instanceDefinition.variant,
|
|
744
|
-
instanceDefinition.name,
|
|
745
|
-
instanceDefinition.parameters
|
|
746
|
-
);
|
|
747
|
-
instances.push(instance);
|
|
748
|
-
}
|
|
749
|
-
return instances;
|
|
750
|
-
}
|
|
751
|
-
}
|