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