@combeenation/3d-viewer 7.1.3 → 8.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/README.md +111 -111
- package/dist/lib-cjs/api/classes/animationInterface.d.ts +8 -8
- package/dist/lib-cjs/api/classes/animationInterface.js +2 -2
- package/dist/lib-cjs/api/classes/dottedPath.d.ts +79 -79
- package/dist/lib-cjs/api/classes/dottedPath.js +166 -166
- package/dist/lib-cjs/api/classes/element.d.ts +153 -153
- package/dist/lib-cjs/api/classes/element.js +672 -672
- package/dist/lib-cjs/api/classes/event.d.ts +401 -401
- package/dist/lib-cjs/api/classes/event.js +424 -424
- package/dist/lib-cjs/api/classes/eventBroadcaster.d.ts +26 -26
- package/dist/lib-cjs/api/classes/eventBroadcaster.js +49 -49
- package/dist/lib-cjs/api/classes/fuzzyMap.d.ts +7 -7
- package/dist/lib-cjs/api/classes/fuzzyMap.js +21 -21
- package/dist/lib-cjs/api/classes/parameter.d.ts +351 -351
- package/dist/lib-cjs/api/classes/parameter.js +524 -524
- package/dist/lib-cjs/api/classes/parameterObservable.d.ts +36 -36
- package/dist/lib-cjs/api/classes/parameterObservable.js +72 -72
- package/dist/lib-cjs/api/classes/parameterizable.d.ts +15 -15
- package/dist/lib-cjs/api/classes/parameterizable.js +102 -102
- package/dist/lib-cjs/api/classes/placementAnimation.d.ts +45 -45
- package/dist/lib-cjs/api/classes/placementAnimation.js +176 -176
- package/dist/lib-cjs/api/classes/variant.d.ts +253 -253
- package/dist/lib-cjs/api/classes/variant.js +858 -858
- package/dist/lib-cjs/api/classes/variantInstance.d.ts +53 -53
- package/dist/lib-cjs/api/classes/variantInstance.js +125 -125
- package/dist/lib-cjs/api/classes/variantParameterizable.d.ts +17 -17
- package/dist/lib-cjs/api/classes/variantParameterizable.js +86 -86
- package/dist/lib-cjs/api/classes/viewer.d.ts +213 -213
- package/dist/lib-cjs/api/classes/viewer.js +716 -716
- package/dist/lib-cjs/api/classes/viewer.js.map +1 -1
- package/dist/lib-cjs/api/classes/viewerError.d.ts +43 -43
- package/dist/lib-cjs/api/classes/viewerError.js +55 -55
- package/dist/lib-cjs/api/classes/viewerLight.d.ts +66 -66
- package/dist/lib-cjs/api/classes/viewerLight.js +348 -348
- package/dist/lib-cjs/api/internal/lensRendering.d.ts +8 -8
- package/dist/lib-cjs/api/internal/lensRendering.js +11 -11
- package/dist/lib-cjs/api/internal/sceneSetup.d.ts +13 -13
- package/dist/lib-cjs/api/internal/sceneSetup.js +226 -226
- package/dist/lib-cjs/api/manager/animationManager.d.ts +30 -30
- package/dist/lib-cjs/api/manager/animationManager.js +126 -126
- package/dist/lib-cjs/api/manager/gltfExportManager.d.ts +102 -79
- package/dist/lib-cjs/api/manager/gltfExportManager.js +320 -242
- package/dist/lib-cjs/api/manager/gltfExportManager.js.map +1 -1
- package/dist/lib-cjs/api/manager/sceneManager.d.ts +33 -33
- package/dist/lib-cjs/api/manager/sceneManager.js +128 -128
- package/dist/lib-cjs/api/manager/tagManager.d.ts +116 -116
- package/dist/lib-cjs/api/manager/tagManager.js +444 -444
- package/dist/lib-cjs/api/manager/textureLoadManager.d.ts +22 -22
- package/dist/lib-cjs/api/manager/textureLoadManager.js +97 -97
- package/dist/lib-cjs/api/manager/variantInstanceManager.d.ts +106 -106
- package/dist/lib-cjs/api/manager/variantInstanceManager.js +292 -292
- package/dist/lib-cjs/api/store/specStorage.d.ts +32 -32
- package/dist/lib-cjs/api/store/specStorage.js +65 -65
- package/dist/lib-cjs/api/util/babylonHelper.d.ts +235 -235
- package/dist/lib-cjs/api/util/babylonHelper.js +753 -753
- package/dist/lib-cjs/api/util/globalTypes.d.ts +457 -455
- package/dist/lib-cjs/api/util/globalTypes.js +1 -1
- package/dist/lib-cjs/api/util/resourceHelper.d.ts +58 -58
- package/dist/lib-cjs/api/util/resourceHelper.js +203 -203
- package/dist/lib-cjs/api/util/sceneLoaderHelper.d.ts +44 -44
- package/dist/lib-cjs/api/util/sceneLoaderHelper.js +175 -175
- package/dist/lib-cjs/api/util/stringHelper.d.ts +13 -13
- package/dist/lib-cjs/api/util/stringHelper.js +32 -32
- package/dist/lib-cjs/api/util/structureHelper.d.ts +9 -9
- package/dist/lib-cjs/api/util/structureHelper.js +57 -57
- package/dist/lib-cjs/buildinfo.json +3 -3
- package/dist/lib-cjs/commonjs.tsconfig.tsbuildinfo +1 -1
- package/dist/lib-cjs/index.d.ts +54 -54
- package/dist/lib-cjs/index.js +117 -117
- package/package.json +81 -81
- package/src/api/classes/animationInterface.ts +10 -10
- package/src/api/classes/dottedPath.ts +181 -181
- package/src/api/classes/element.ts +733 -733
- package/src/api/classes/event.ts +457 -457
- package/src/api/classes/eventBroadcaster.ts +52 -52
- package/src/api/classes/fuzzyMap.ts +21 -21
- package/src/api/classes/parameter.ts +561 -561
- package/src/api/classes/parameterObservable.ts +73 -73
- package/src/api/classes/parameterizable.ts +87 -87
- package/src/api/classes/placementAnimation.ts +162 -162
- package/src/api/classes/variant.ts +949 -949
- package/src/api/classes/variantInstance.ts +123 -123
- package/src/api/classes/variantParameterizable.ts +83 -83
- package/src/api/classes/viewer.ts +772 -772
- package/src/api/classes/viewerError.ts +63 -63
- package/src/api/classes/viewerLight.ts +339 -339
- package/src/api/internal/debugViewer.ts +90 -90
- package/src/api/internal/lensRendering.ts +9 -9
- package/src/api/internal/sceneSetup.ts +205 -205
- package/src/api/manager/animationManager.ts +143 -143
- package/src/api/manager/gltfExportManager.ts +297 -237
- package/src/api/manager/sceneManager.ts +134 -134
- package/src/api/manager/tagManager.ts +477 -477
- package/src/api/manager/textureLoadManager.ts +95 -95
- package/src/api/manager/variantInstanceManager.ts +309 -309
- package/src/api/store/specStorage.ts +68 -68
- package/src/api/util/babylonHelper.ts +823 -823
- package/src/api/util/globalTypes.ts +527 -525
- package/src/api/util/resourceHelper.ts +191 -191
- package/src/api/util/sceneLoaderHelper.ts +170 -170
- package/src/api/util/stringHelper.ts +30 -30
- package/src/api/util/structureHelper.ts +58 -58
- package/src/buildinfo.json +3 -3
- package/src/dev.ts +62 -62
- package/src/index.ts +103 -103
- package/src/types.d.ts +38 -38
|
@@ -1,176 +1,176 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.createMaterialFromCbnAssets = exports.removeMissingMaterialObserver = exports.addMissingMaterialObserver = exports.addMissingMaterialMetadata = exports.getMaterialPostLoadObserver = exports.getCustomCbnBabylonLoaderPlugin = exports.missingMaterialMetadataName = void 0;
|
|
16
|
-
const event_1 = require("../classes/event");
|
|
17
|
-
const babylonHelper_1 = require("./babylonHelper");
|
|
18
|
-
const resourceHelper_1 = require("./resourceHelper");
|
|
19
|
-
const material_1 = require("@babylonjs/core/Materials/material");
|
|
20
|
-
const instancedMesh_1 = require("@babylonjs/core/Meshes/instancedMesh");
|
|
21
|
-
const has_1 = __importDefault(require("lodash-es/has"));
|
|
22
|
-
// map for keeping track of active "node enable" observers
|
|
23
|
-
const enableObserverMap = {};
|
|
24
|
-
exports.missingMaterialMetadataName = 'missingMaterial';
|
|
25
|
-
/**
|
|
26
|
-
* Create and return a custom loader plugin to be registered with SceneLoader, that allows
|
|
27
|
-
* us to run our own code against the input data before using the standard procedure to
|
|
28
|
-
* import.
|
|
29
|
-
* @param previousLoaderPlugin the actual loader that's executed after manipulating the input data
|
|
30
|
-
* @returns Custom loader plugin to be registered with SceneLoader.RegisterPlugin()
|
|
31
|
-
*/
|
|
32
|
-
const getCustomCbnBabylonLoaderPlugin = function (previousLoaderPlugin) {
|
|
33
|
-
const customLoader = {
|
|
34
|
-
name: 'cbnCustomBabylonLoader',
|
|
35
|
-
extensions: '.babylon',
|
|
36
|
-
importMesh: previousLoaderPlugin.importMesh,
|
|
37
|
-
load: previousLoaderPlugin.load,
|
|
38
|
-
loadAssetContainer: function (scene, data, rootUrl, onError) {
|
|
39
|
-
//* 1) --- manipulate ORIGINAL data
|
|
40
|
-
const dataParsed = JSON.parse(data);
|
|
41
|
-
//* 2) --- call default (non-custom) loading method
|
|
42
|
-
const importedContainer = previousLoaderPlugin.loadAssetContainer(scene, data, rootUrl);
|
|
43
|
-
//* 3) --- manipulate IMPORTED data
|
|
44
|
-
(0, exports.addMissingMaterialMetadata)(dataParsed, importedContainer);
|
|
45
|
-
//* 4) --- return imported data
|
|
46
|
-
return importedContainer;
|
|
47
|
-
},
|
|
48
|
-
};
|
|
49
|
-
return customLoader;
|
|
50
|
-
};
|
|
51
|
-
exports.getCustomCbnBabylonLoaderPlugin = getCustomCbnBabylonLoaderPlugin;
|
|
52
|
-
/**
|
|
53
|
-
* Return an observer to be applied to meshes in order to post-load missing materials
|
|
54
|
-
* upon set enabled/visible.
|
|
55
|
-
*
|
|
56
|
-
* @param concerningMesh Mesh to look for missing materials on, and create/apply to (when found).
|
|
57
|
-
* @returns observer
|
|
58
|
-
*/
|
|
59
|
-
const getMaterialPostLoadObserver = function (concerningMesh) {
|
|
60
|
-
return () => __awaiter(this, void 0, void 0, function* () {
|
|
61
|
-
var _a;
|
|
62
|
-
const scene = concerningMesh.getScene();
|
|
63
|
-
// can't check `isEnabled` immediatly, since the enabled state of parents and childs is not synced yet
|
|
64
|
-
// postpone one cycle to ensure a correct parent-child enable relation
|
|
65
|
-
yield (0, resourceHelper_1.sleep)(0);
|
|
66
|
-
const hasBeenEnabled = concerningMesh.isEnabled(true);
|
|
67
|
-
const materialMissing = (0, has_1.default)(concerningMesh.metadata, exports.missingMaterialMetadataName);
|
|
68
|
-
if (!hasBeenEnabled || !materialMissing)
|
|
69
|
-
return;
|
|
70
|
-
// get id of missing material
|
|
71
|
-
const missingMatId = concerningMesh.metadata[exports.missingMaterialMetadataName];
|
|
72
|
-
// get material and apply it on the concerning mesh after all textures have been loaded
|
|
73
|
-
const material = yield (0, babylonHelper_1.getOrCreateMaterial)(concerningMesh.getScene(), missingMatId);
|
|
74
|
-
(0, babylonHelper_1.applyMaterial)(material, concerningMesh).then(() => event_1.emitter.emit(event_1.Event.MESH_MATERIAL_APPLIED, concerningMesh, material));
|
|
75
|
-
// since the material is there now, we do not need the related metadata tag anymore
|
|
76
|
-
delete concerningMesh.metadata[exports.missingMaterialMetadataName];
|
|
77
|
-
// remove all "enable" observers that were assigned to the concerning mesh
|
|
78
|
-
// the mesh got visible and therefore the observers are not needed anymore
|
|
79
|
-
(_a = enableObserverMap[concerningMesh.id]) === null || _a === void 0 ? void 0 : _a.forEach(entry => {
|
|
80
|
-
const currNode = scene.getMeshById(entry.currNodeId);
|
|
81
|
-
currNode === null || currNode === void 0 ? void 0 : currNode.onEnabledStateChangedObservable.remove(entry.observer);
|
|
82
|
-
});
|
|
83
|
-
// also remove from the local observer map
|
|
84
|
-
delete enableObserverMap[concerningMesh.id];
|
|
85
|
-
});
|
|
86
|
-
};
|
|
87
|
-
exports.getMaterialPostLoadObserver = getMaterialPostLoadObserver;
|
|
88
|
-
/**
|
|
89
|
-
* Internal function that compares the original meshes on a .babylon file with what was loaded,
|
|
90
|
-
* and tags missing materials with respective metadata on respective meshes.
|
|
91
|
-
* @param dataParsed original data
|
|
92
|
-
* @param container loaded data
|
|
93
|
-
*/
|
|
94
|
-
const addMissingMaterialMetadata = function (dataParsed, container) {
|
|
95
|
-
container.meshes.forEach(currMeshImported => {
|
|
96
|
-
var _a, _b;
|
|
97
|
-
for (const currMeshOriginal of dataParsed.meshes) {
|
|
98
|
-
if (currMeshOriginal.name !== currMeshImported.name)
|
|
99
|
-
continue;
|
|
100
|
-
// we're dealing with the original version of the current imported mesh now
|
|
101
|
-
const materialOnImportedMesh = (_a = currMeshImported.material) === null || _a === void 0 ? void 0 : _a.id;
|
|
102
|
-
const materialOnOriginalMesh = currMeshOriginal.materialId;
|
|
103
|
-
if (!materialOnOriginalMesh || materialOnImportedMesh === materialOnOriginalMesh)
|
|
104
|
-
continue;
|
|
105
|
-
// if we're here, the imported mesh has different material than original one
|
|
106
|
-
(_b = window.Cbn) === null || _b === void 0 ? void 0 : _b.Assets.assertMaterialExists(materialOnOriginalMesh);
|
|
107
|
-
(0, babylonHelper_1.injectNodeMetadata)(currMeshImported, { [exports.missingMaterialMetadataName]: materialOnOriginalMesh }, false);
|
|
108
|
-
break;
|
|
109
|
-
}
|
|
110
|
-
});
|
|
111
|
-
};
|
|
112
|
-
exports.addMissingMaterialMetadata = addMissingMaterialMetadata;
|
|
113
|
-
/**
|
|
114
|
-
* Adds an "onEnabledStateChanged" observer to the given mesh and all its parents:
|
|
115
|
-
* The added observer (`getMaterialPostLoadObserver`) handles creation of missing materials once the given node is
|
|
116
|
-
* enabled.
|
|
117
|
-
*/
|
|
118
|
-
const addMissingMaterialObserver = function (node) {
|
|
119
|
-
// set the concerning node, i.e. the node the observer should check for missing material.
|
|
120
|
-
// for instanced meshes, we want the sourcemesh here.
|
|
121
|
-
const concerningNode = node instanceof instancedMesh_1.InstancedMesh ? node.sourceMesh : node;
|
|
122
|
-
// observer is pointless if concerning node has no missing material
|
|
123
|
-
if (!(0, has_1.default)(concerningNode.metadata, exports.missingMaterialMetadataName))
|
|
124
|
-
return;
|
|
125
|
-
// for each of our AbstractMeshes, set an observer on the AbstractMesh itself and all of its parents.
|
|
126
|
-
let currNode = node;
|
|
127
|
-
while (currNode) {
|
|
128
|
-
const callback = (0, exports.getMaterialPostLoadObserver)(concerningNode);
|
|
129
|
-
const observer = currNode.onEnabledStateChangedObservable.add(callback);
|
|
130
|
-
// store the observer in a local map to keep track of the active "enable" observers
|
|
131
|
-
// observers will be removed when the concerning node gets enabled
|
|
132
|
-
if (!enableObserverMap[concerningNode.id]) {
|
|
133
|
-
enableObserverMap[concerningNode.id] = [];
|
|
134
|
-
}
|
|
135
|
-
enableObserverMap[concerningNode.id].push({ currNodeId: currNode.id, observer });
|
|
136
|
-
currNode = currNode.parent;
|
|
137
|
-
}
|
|
138
|
-
};
|
|
139
|
-
exports.addMissingMaterialObserver = addMissingMaterialObserver;
|
|
140
|
-
const removeMissingMaterialObserver = function (node) {
|
|
141
|
-
var _a;
|
|
142
|
-
// set the concerning node, i.e. the node the observer should check for missing material.
|
|
143
|
-
// for instanced meshes, we want the sourcemesh here.
|
|
144
|
-
const concerningNode = node instanceof instancedMesh_1.InstancedMesh ? node.sourceMesh : node;
|
|
145
|
-
let currNode = node;
|
|
146
|
-
while (currNode) {
|
|
147
|
-
(_a = enableObserverMap[concerningNode.id]) === null || _a === void 0 ? void 0 : _a.forEach(entry => {
|
|
148
|
-
if (entry.currNodeId === (currNode === null || currNode === void 0 ? void 0 : currNode.id)) {
|
|
149
|
-
currNode.onEnabledStateChangedObservable.remove(entry.observer);
|
|
150
|
-
}
|
|
151
|
-
});
|
|
152
|
-
currNode = currNode.parent;
|
|
153
|
-
}
|
|
154
|
-
delete enableObserverMap[concerningNode.id];
|
|
155
|
-
};
|
|
156
|
-
exports.removeMissingMaterialObserver = removeMissingMaterialObserver;
|
|
157
|
-
/**
|
|
158
|
-
* Look up the provided materials (see library import) and create and return one if found.
|
|
159
|
-
*
|
|
160
|
-
* @param materialId Babylon.js material-id. E.g. 'concrete".
|
|
161
|
-
* @param scene Babylon.js scene
|
|
162
|
-
* @returns PBRMaterial | null
|
|
163
|
-
*/
|
|
164
|
-
const createMaterialFromCbnAssets = function (materialId, scene) {
|
|
165
|
-
var _a;
|
|
166
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
167
|
-
const materialDefinition = yield ((_a = window.Cbn) === null || _a === void 0 ? void 0 : _a.Assets.getMaterial(materialId));
|
|
168
|
-
// The generic `Material.Parse` actually returns a more specific material like `BABYLON.StandardMaterial`,
|
|
169
|
-
// `BABYLON.PBRMaterial` or stuff like `BABYLON.PBRMetallicRoughnessMaterial` etc. based on the given `customType`
|
|
170
|
-
// within the material JSON definition
|
|
171
|
-
const material = materialDefinition && material_1.Material.Parse(materialDefinition, scene, '');
|
|
172
|
-
return material || null;
|
|
173
|
-
});
|
|
174
|
-
};
|
|
175
|
-
exports.createMaterialFromCbnAssets = createMaterialFromCbnAssets;
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.createMaterialFromCbnAssets = exports.removeMissingMaterialObserver = exports.addMissingMaterialObserver = exports.addMissingMaterialMetadata = exports.getMaterialPostLoadObserver = exports.getCustomCbnBabylonLoaderPlugin = exports.missingMaterialMetadataName = void 0;
|
|
16
|
+
const event_1 = require("../classes/event");
|
|
17
|
+
const babylonHelper_1 = require("./babylonHelper");
|
|
18
|
+
const resourceHelper_1 = require("./resourceHelper");
|
|
19
|
+
const material_1 = require("@babylonjs/core/Materials/material");
|
|
20
|
+
const instancedMesh_1 = require("@babylonjs/core/Meshes/instancedMesh");
|
|
21
|
+
const has_1 = __importDefault(require("lodash-es/has"));
|
|
22
|
+
// map for keeping track of active "node enable" observers
|
|
23
|
+
const enableObserverMap = {};
|
|
24
|
+
exports.missingMaterialMetadataName = 'missingMaterial';
|
|
25
|
+
/**
|
|
26
|
+
* Create and return a custom loader plugin to be registered with SceneLoader, that allows
|
|
27
|
+
* us to run our own code against the input data before using the standard procedure to
|
|
28
|
+
* import.
|
|
29
|
+
* @param previousLoaderPlugin the actual loader that's executed after manipulating the input data
|
|
30
|
+
* @returns Custom loader plugin to be registered with SceneLoader.RegisterPlugin()
|
|
31
|
+
*/
|
|
32
|
+
const getCustomCbnBabylonLoaderPlugin = function (previousLoaderPlugin) {
|
|
33
|
+
const customLoader = {
|
|
34
|
+
name: 'cbnCustomBabylonLoader',
|
|
35
|
+
extensions: '.babylon',
|
|
36
|
+
importMesh: previousLoaderPlugin.importMesh,
|
|
37
|
+
load: previousLoaderPlugin.load,
|
|
38
|
+
loadAssetContainer: function (scene, data, rootUrl, onError) {
|
|
39
|
+
//* 1) --- manipulate ORIGINAL data
|
|
40
|
+
const dataParsed = JSON.parse(data);
|
|
41
|
+
//* 2) --- call default (non-custom) loading method
|
|
42
|
+
const importedContainer = previousLoaderPlugin.loadAssetContainer(scene, data, rootUrl);
|
|
43
|
+
//* 3) --- manipulate IMPORTED data
|
|
44
|
+
(0, exports.addMissingMaterialMetadata)(dataParsed, importedContainer);
|
|
45
|
+
//* 4) --- return imported data
|
|
46
|
+
return importedContainer;
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
return customLoader;
|
|
50
|
+
};
|
|
51
|
+
exports.getCustomCbnBabylonLoaderPlugin = getCustomCbnBabylonLoaderPlugin;
|
|
52
|
+
/**
|
|
53
|
+
* Return an observer to be applied to meshes in order to post-load missing materials
|
|
54
|
+
* upon set enabled/visible.
|
|
55
|
+
*
|
|
56
|
+
* @param concerningMesh Mesh to look for missing materials on, and create/apply to (when found).
|
|
57
|
+
* @returns observer
|
|
58
|
+
*/
|
|
59
|
+
const getMaterialPostLoadObserver = function (concerningMesh) {
|
|
60
|
+
return () => __awaiter(this, void 0, void 0, function* () {
|
|
61
|
+
var _a;
|
|
62
|
+
const scene = concerningMesh.getScene();
|
|
63
|
+
// can't check `isEnabled` immediatly, since the enabled state of parents and childs is not synced yet
|
|
64
|
+
// postpone one cycle to ensure a correct parent-child enable relation
|
|
65
|
+
yield (0, resourceHelper_1.sleep)(0);
|
|
66
|
+
const hasBeenEnabled = concerningMesh.isEnabled(true);
|
|
67
|
+
const materialMissing = (0, has_1.default)(concerningMesh.metadata, exports.missingMaterialMetadataName);
|
|
68
|
+
if (!hasBeenEnabled || !materialMissing)
|
|
69
|
+
return;
|
|
70
|
+
// get id of missing material
|
|
71
|
+
const missingMatId = concerningMesh.metadata[exports.missingMaterialMetadataName];
|
|
72
|
+
// get material and apply it on the concerning mesh after all textures have been loaded
|
|
73
|
+
const material = yield (0, babylonHelper_1.getOrCreateMaterial)(concerningMesh.getScene(), missingMatId);
|
|
74
|
+
(0, babylonHelper_1.applyMaterial)(material, concerningMesh).then(() => event_1.emitter.emit(event_1.Event.MESH_MATERIAL_APPLIED, concerningMesh, material));
|
|
75
|
+
// since the material is there now, we do not need the related metadata tag anymore
|
|
76
|
+
delete concerningMesh.metadata[exports.missingMaterialMetadataName];
|
|
77
|
+
// remove all "enable" observers that were assigned to the concerning mesh
|
|
78
|
+
// the mesh got visible and therefore the observers are not needed anymore
|
|
79
|
+
(_a = enableObserverMap[concerningMesh.id]) === null || _a === void 0 ? void 0 : _a.forEach(entry => {
|
|
80
|
+
const currNode = scene.getMeshById(entry.currNodeId);
|
|
81
|
+
currNode === null || currNode === void 0 ? void 0 : currNode.onEnabledStateChangedObservable.remove(entry.observer);
|
|
82
|
+
});
|
|
83
|
+
// also remove from the local observer map
|
|
84
|
+
delete enableObserverMap[concerningMesh.id];
|
|
85
|
+
});
|
|
86
|
+
};
|
|
87
|
+
exports.getMaterialPostLoadObserver = getMaterialPostLoadObserver;
|
|
88
|
+
/**
|
|
89
|
+
* Internal function that compares the original meshes on a .babylon file with what was loaded,
|
|
90
|
+
* and tags missing materials with respective metadata on respective meshes.
|
|
91
|
+
* @param dataParsed original data
|
|
92
|
+
* @param container loaded data
|
|
93
|
+
*/
|
|
94
|
+
const addMissingMaterialMetadata = function (dataParsed, container) {
|
|
95
|
+
container.meshes.forEach(currMeshImported => {
|
|
96
|
+
var _a, _b;
|
|
97
|
+
for (const currMeshOriginal of dataParsed.meshes) {
|
|
98
|
+
if (currMeshOriginal.name !== currMeshImported.name)
|
|
99
|
+
continue;
|
|
100
|
+
// we're dealing with the original version of the current imported mesh now
|
|
101
|
+
const materialOnImportedMesh = (_a = currMeshImported.material) === null || _a === void 0 ? void 0 : _a.id;
|
|
102
|
+
const materialOnOriginalMesh = currMeshOriginal.materialId;
|
|
103
|
+
if (!materialOnOriginalMesh || materialOnImportedMesh === materialOnOriginalMesh)
|
|
104
|
+
continue;
|
|
105
|
+
// if we're here, the imported mesh has different material than original one
|
|
106
|
+
(_b = window.Cbn) === null || _b === void 0 ? void 0 : _b.Assets.assertMaterialExists(materialOnOriginalMesh);
|
|
107
|
+
(0, babylonHelper_1.injectNodeMetadata)(currMeshImported, { [exports.missingMaterialMetadataName]: materialOnOriginalMesh }, false);
|
|
108
|
+
break;
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
};
|
|
112
|
+
exports.addMissingMaterialMetadata = addMissingMaterialMetadata;
|
|
113
|
+
/**
|
|
114
|
+
* Adds an "onEnabledStateChanged" observer to the given mesh and all its parents:
|
|
115
|
+
* The added observer (`getMaterialPostLoadObserver`) handles creation of missing materials once the given node is
|
|
116
|
+
* enabled.
|
|
117
|
+
*/
|
|
118
|
+
const addMissingMaterialObserver = function (node) {
|
|
119
|
+
// set the concerning node, i.e. the node the observer should check for missing material.
|
|
120
|
+
// for instanced meshes, we want the sourcemesh here.
|
|
121
|
+
const concerningNode = node instanceof instancedMesh_1.InstancedMesh ? node.sourceMesh : node;
|
|
122
|
+
// observer is pointless if concerning node has no missing material
|
|
123
|
+
if (!(0, has_1.default)(concerningNode.metadata, exports.missingMaterialMetadataName))
|
|
124
|
+
return;
|
|
125
|
+
// for each of our AbstractMeshes, set an observer on the AbstractMesh itself and all of its parents.
|
|
126
|
+
let currNode = node;
|
|
127
|
+
while (currNode) {
|
|
128
|
+
const callback = (0, exports.getMaterialPostLoadObserver)(concerningNode);
|
|
129
|
+
const observer = currNode.onEnabledStateChangedObservable.add(callback);
|
|
130
|
+
// store the observer in a local map to keep track of the active "enable" observers
|
|
131
|
+
// observers will be removed when the concerning node gets enabled
|
|
132
|
+
if (!enableObserverMap[concerningNode.id]) {
|
|
133
|
+
enableObserverMap[concerningNode.id] = [];
|
|
134
|
+
}
|
|
135
|
+
enableObserverMap[concerningNode.id].push({ currNodeId: currNode.id, observer });
|
|
136
|
+
currNode = currNode.parent;
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
exports.addMissingMaterialObserver = addMissingMaterialObserver;
|
|
140
|
+
const removeMissingMaterialObserver = function (node) {
|
|
141
|
+
var _a;
|
|
142
|
+
// set the concerning node, i.e. the node the observer should check for missing material.
|
|
143
|
+
// for instanced meshes, we want the sourcemesh here.
|
|
144
|
+
const concerningNode = node instanceof instancedMesh_1.InstancedMesh ? node.sourceMesh : node;
|
|
145
|
+
let currNode = node;
|
|
146
|
+
while (currNode) {
|
|
147
|
+
(_a = enableObserverMap[concerningNode.id]) === null || _a === void 0 ? void 0 : _a.forEach(entry => {
|
|
148
|
+
if (entry.currNodeId === (currNode === null || currNode === void 0 ? void 0 : currNode.id)) {
|
|
149
|
+
currNode.onEnabledStateChangedObservable.remove(entry.observer);
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
currNode = currNode.parent;
|
|
153
|
+
}
|
|
154
|
+
delete enableObserverMap[concerningNode.id];
|
|
155
|
+
};
|
|
156
|
+
exports.removeMissingMaterialObserver = removeMissingMaterialObserver;
|
|
157
|
+
/**
|
|
158
|
+
* Look up the provided materials (see library import) and create and return one if found.
|
|
159
|
+
*
|
|
160
|
+
* @param materialId Babylon.js material-id. E.g. 'concrete".
|
|
161
|
+
* @param scene Babylon.js scene
|
|
162
|
+
* @returns PBRMaterial | null
|
|
163
|
+
*/
|
|
164
|
+
const createMaterialFromCbnAssets = function (materialId, scene) {
|
|
165
|
+
var _a;
|
|
166
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
167
|
+
const materialDefinition = yield ((_a = window.Cbn) === null || _a === void 0 ? void 0 : _a.Assets.getMaterial(materialId));
|
|
168
|
+
// The generic `Material.Parse` actually returns a more specific material like `BABYLON.StandardMaterial`,
|
|
169
|
+
// `BABYLON.PBRMaterial` or stuff like `BABYLON.PBRMetallicRoughnessMaterial` etc. based on the given `customType`
|
|
170
|
+
// within the material JSON definition
|
|
171
|
+
const material = materialDefinition && material_1.Material.Parse(materialDefinition, scene, '');
|
|
172
|
+
return material || null;
|
|
173
|
+
});
|
|
174
|
+
};
|
|
175
|
+
exports.createMaterialFromCbnAssets = createMaterialFromCbnAssets;
|
|
176
176
|
//# sourceMappingURL=sceneLoaderHelper.js.map
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Creates a random uuidv4.
|
|
3
|
-
*/
|
|
4
|
-
declare const uuidv4: () => string;
|
|
5
|
-
/**
|
|
6
|
-
* Converts a string from camel case to snake case.
|
|
7
|
-
*/
|
|
8
|
-
declare const camelToSnakeCase: (str: string) => string;
|
|
9
|
-
/**
|
|
10
|
-
* Replaces all dots from the input string with a desired character ('/' by default)
|
|
11
|
-
*/
|
|
12
|
-
declare const replaceDots: (str: string, replaceChar?: string) => string;
|
|
13
|
-
export { uuidv4, camelToSnakeCase, replaceDots };
|
|
1
|
+
/**
|
|
2
|
+
* Creates a random uuidv4.
|
|
3
|
+
*/
|
|
4
|
+
declare const uuidv4: () => string;
|
|
5
|
+
/**
|
|
6
|
+
* Converts a string from camel case to snake case.
|
|
7
|
+
*/
|
|
8
|
+
declare const camelToSnakeCase: (str: string) => string;
|
|
9
|
+
/**
|
|
10
|
+
* Replaces all dots from the input string with a desired character ('/' by default)
|
|
11
|
+
*/
|
|
12
|
+
declare const replaceDots: (str: string, replaceChar?: string) => string;
|
|
13
|
+
export { uuidv4, camelToSnakeCase, replaceDots };
|
|
@@ -1,33 +1,33 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.replaceDots = exports.camelToSnakeCase = exports.uuidv4 = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* Creates a random uuidv4.
|
|
6
|
-
*/
|
|
7
|
-
const uuidv4 = function () {
|
|
8
|
-
return ([1e7].toString() + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, c => {
|
|
9
|
-
const cNum = parseInt(c);
|
|
10
|
-
return (cNum ^ (crypto.getRandomValues(new Uint8Array(1))[0] & (15 >> (cNum / 4)))).toString(16);
|
|
11
|
-
});
|
|
12
|
-
};
|
|
13
|
-
exports.uuidv4 = uuidv4;
|
|
14
|
-
/**
|
|
15
|
-
* Converts a string from camel case to snake case.
|
|
16
|
-
*/
|
|
17
|
-
const camelToSnakeCase = function (str) {
|
|
18
|
-
return str
|
|
19
|
-
.replace(/([A-Z])/g, ' $1')
|
|
20
|
-
.trim()
|
|
21
|
-
.split(' ')
|
|
22
|
-
.join('_')
|
|
23
|
-
.toLowerCase();
|
|
24
|
-
};
|
|
25
|
-
exports.camelToSnakeCase = camelToSnakeCase;
|
|
26
|
-
/**
|
|
27
|
-
* Replaces all dots from the input string with a desired character ('/' by default)
|
|
28
|
-
*/
|
|
29
|
-
const replaceDots = function (str, replaceChar = '/') {
|
|
30
|
-
return str.split('.').join(replaceChar);
|
|
31
|
-
};
|
|
32
|
-
exports.replaceDots = replaceDots;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.replaceDots = exports.camelToSnakeCase = exports.uuidv4 = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Creates a random uuidv4.
|
|
6
|
+
*/
|
|
7
|
+
const uuidv4 = function () {
|
|
8
|
+
return ([1e7].toString() + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, c => {
|
|
9
|
+
const cNum = parseInt(c);
|
|
10
|
+
return (cNum ^ (crypto.getRandomValues(new Uint8Array(1))[0] & (15 >> (cNum / 4)))).toString(16);
|
|
11
|
+
});
|
|
12
|
+
};
|
|
13
|
+
exports.uuidv4 = uuidv4;
|
|
14
|
+
/**
|
|
15
|
+
* Converts a string from camel case to snake case.
|
|
16
|
+
*/
|
|
17
|
+
const camelToSnakeCase = function (str) {
|
|
18
|
+
return str
|
|
19
|
+
.replace(/([A-Z])/g, ' $1')
|
|
20
|
+
.trim()
|
|
21
|
+
.split(' ')
|
|
22
|
+
.join('_')
|
|
23
|
+
.toLowerCase();
|
|
24
|
+
};
|
|
25
|
+
exports.camelToSnakeCase = camelToSnakeCase;
|
|
26
|
+
/**
|
|
27
|
+
* Replaces all dots from the input string with a desired character ('/' by default)
|
|
28
|
+
*/
|
|
29
|
+
const replaceDots = function (str, replaceChar = '/') {
|
|
30
|
+
return str.split('.').join(replaceChar);
|
|
31
|
+
};
|
|
32
|
+
exports.replaceDots = replaceDots;
|
|
33
33
|
//# sourceMappingURL=stringHelper.js.map
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { Mesh } from '@babylonjs/core/Meshes/mesh';
|
|
2
|
-
/**
|
|
3
|
-
* Find out if a mesh is part of a list of excluded geometry
|
|
4
|
-
* @param mesh BJS mesh
|
|
5
|
-
* @param list list of excluded geometry
|
|
6
|
-
* @returns boolean based on whether mesh (or one of its parents) was found in list
|
|
7
|
-
*/
|
|
8
|
-
declare const isMeshIncludedInExclusionList: (mesh: Mesh, list: ExcludedGeometryList) => boolean;
|
|
9
|
-
export { isMeshIncludedInExclusionList };
|
|
1
|
+
import { Mesh } from '@babylonjs/core/Meshes/mesh';
|
|
2
|
+
/**
|
|
3
|
+
* Find out if a mesh is part of a list of excluded geometry
|
|
4
|
+
* @param mesh BJS mesh
|
|
5
|
+
* @param list list of excluded geometry
|
|
6
|
+
* @returns boolean based on whether mesh (or one of its parents) was found in list
|
|
7
|
+
*/
|
|
8
|
+
declare const isMeshIncludedInExclusionList: (mesh: Mesh, list: ExcludedGeometryList) => boolean;
|
|
9
|
+
export { isMeshIncludedInExclusionList };
|
|
@@ -1,58 +1,58 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isMeshIncludedInExclusionList = void 0;
|
|
4
|
-
const element_1 = require("../classes/element");
|
|
5
|
-
const variant_1 = require("../classes/variant");
|
|
6
|
-
const variantInstance_1 = require("../classes/variantInstance");
|
|
7
|
-
const mesh_1 = require("@babylonjs/core/Meshes/mesh");
|
|
8
|
-
const tags_1 = require("@babylonjs/core/Misc/tags");
|
|
9
|
-
/**
|
|
10
|
-
* Find out if a mesh is part of a list of excluded geometry
|
|
11
|
-
* @param mesh BJS mesh
|
|
12
|
-
* @param list list of excluded geometry
|
|
13
|
-
* @returns boolean based on whether mesh (or one of its parents) was found in list
|
|
14
|
-
*/
|
|
15
|
-
const isMeshIncludedInExclusionList = function (mesh, list) {
|
|
16
|
-
const checkMesh = (inputMesh, meshToCheck) => {
|
|
17
|
-
return inputMesh.uniqueId === meshToCheck.uniqueId;
|
|
18
|
-
};
|
|
19
|
-
const checkElement = (inputEl, meshToCheck) => {
|
|
20
|
-
return inputEl.meshesFlat.some(m => checkMesh(m, meshToCheck));
|
|
21
|
-
};
|
|
22
|
-
const checkVariant = (inputVariant, meshToCheck) => {
|
|
23
|
-
return inputVariant.elements.some(el => checkElement(el, meshToCheck));
|
|
24
|
-
};
|
|
25
|
-
const checkVariantInstance = (inputVarInst, meshToCheck) => {
|
|
26
|
-
return inputVarInst.variant.elements.some(el => checkElement(el, meshToCheck));
|
|
27
|
-
};
|
|
28
|
-
const checkTagManagerSubject = (inputSubject, meshToCheck) => {
|
|
29
|
-
const nameMatches = inputSubject.nodeName && inputSubject.nodeName === meshToCheck.name;
|
|
30
|
-
const tagMatches = inputSubject.tagName && tags_1.Tags.MatchesQuery(mesh, inputSubject.tagName);
|
|
31
|
-
return nameMatches || tagMatches;
|
|
32
|
-
};
|
|
33
|
-
const check = (geometryToExclude, mesh) => {
|
|
34
|
-
if (geometryToExclude instanceof variantInstance_1.VariantInstance) {
|
|
35
|
-
return checkVariantInstance(geometryToExclude, mesh);
|
|
36
|
-
}
|
|
37
|
-
if (geometryToExclude instanceof variant_1.Variant) {
|
|
38
|
-
return checkVariant(geometryToExclude, mesh);
|
|
39
|
-
}
|
|
40
|
-
if (geometryToExclude instanceof element_1.Element) {
|
|
41
|
-
return checkElement(geometryToExclude, mesh);
|
|
42
|
-
}
|
|
43
|
-
if (geometryToExclude instanceof mesh_1.Mesh) {
|
|
44
|
-
return checkMesh(geometryToExclude, mesh);
|
|
45
|
-
}
|
|
46
|
-
if (geometryToExclude.tagName || geometryToExclude.nodeName) {
|
|
47
|
-
return checkTagManagerSubject(geometryToExclude, mesh);
|
|
48
|
-
}
|
|
49
|
-
return false;
|
|
50
|
-
};
|
|
51
|
-
let isExcluded = list.some(geometryToExclude => check(geometryToExclude, mesh));
|
|
52
|
-
if (!isExcluded && mesh.parent instanceof mesh_1.Mesh) {
|
|
53
|
-
isExcluded = isMeshIncludedInExclusionList(mesh.parent, list);
|
|
54
|
-
}
|
|
55
|
-
return isExcluded;
|
|
56
|
-
};
|
|
57
|
-
exports.isMeshIncludedInExclusionList = isMeshIncludedInExclusionList;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isMeshIncludedInExclusionList = void 0;
|
|
4
|
+
const element_1 = require("../classes/element");
|
|
5
|
+
const variant_1 = require("../classes/variant");
|
|
6
|
+
const variantInstance_1 = require("../classes/variantInstance");
|
|
7
|
+
const mesh_1 = require("@babylonjs/core/Meshes/mesh");
|
|
8
|
+
const tags_1 = require("@babylonjs/core/Misc/tags");
|
|
9
|
+
/**
|
|
10
|
+
* Find out if a mesh is part of a list of excluded geometry
|
|
11
|
+
* @param mesh BJS mesh
|
|
12
|
+
* @param list list of excluded geometry
|
|
13
|
+
* @returns boolean based on whether mesh (or one of its parents) was found in list
|
|
14
|
+
*/
|
|
15
|
+
const isMeshIncludedInExclusionList = function (mesh, list) {
|
|
16
|
+
const checkMesh = (inputMesh, meshToCheck) => {
|
|
17
|
+
return inputMesh.uniqueId === meshToCheck.uniqueId;
|
|
18
|
+
};
|
|
19
|
+
const checkElement = (inputEl, meshToCheck) => {
|
|
20
|
+
return inputEl.meshesFlat.some(m => checkMesh(m, meshToCheck));
|
|
21
|
+
};
|
|
22
|
+
const checkVariant = (inputVariant, meshToCheck) => {
|
|
23
|
+
return inputVariant.elements.some(el => checkElement(el, meshToCheck));
|
|
24
|
+
};
|
|
25
|
+
const checkVariantInstance = (inputVarInst, meshToCheck) => {
|
|
26
|
+
return inputVarInst.variant.elements.some(el => checkElement(el, meshToCheck));
|
|
27
|
+
};
|
|
28
|
+
const checkTagManagerSubject = (inputSubject, meshToCheck) => {
|
|
29
|
+
const nameMatches = inputSubject.nodeName && inputSubject.nodeName === meshToCheck.name;
|
|
30
|
+
const tagMatches = inputSubject.tagName && tags_1.Tags.MatchesQuery(mesh, inputSubject.tagName);
|
|
31
|
+
return nameMatches || tagMatches;
|
|
32
|
+
};
|
|
33
|
+
const check = (geometryToExclude, mesh) => {
|
|
34
|
+
if (geometryToExclude instanceof variantInstance_1.VariantInstance) {
|
|
35
|
+
return checkVariantInstance(geometryToExclude, mesh);
|
|
36
|
+
}
|
|
37
|
+
if (geometryToExclude instanceof variant_1.Variant) {
|
|
38
|
+
return checkVariant(geometryToExclude, mesh);
|
|
39
|
+
}
|
|
40
|
+
if (geometryToExclude instanceof element_1.Element) {
|
|
41
|
+
return checkElement(geometryToExclude, mesh);
|
|
42
|
+
}
|
|
43
|
+
if (geometryToExclude instanceof mesh_1.Mesh) {
|
|
44
|
+
return checkMesh(geometryToExclude, mesh);
|
|
45
|
+
}
|
|
46
|
+
if (geometryToExclude.tagName || geometryToExclude.nodeName) {
|
|
47
|
+
return checkTagManagerSubject(geometryToExclude, mesh);
|
|
48
|
+
}
|
|
49
|
+
return false;
|
|
50
|
+
};
|
|
51
|
+
let isExcluded = list.some(geometryToExclude => check(geometryToExclude, mesh));
|
|
52
|
+
if (!isExcluded && mesh.parent instanceof mesh_1.Mesh) {
|
|
53
|
+
isExcluded = isMeshIncludedInExclusionList(mesh.parent, list);
|
|
54
|
+
}
|
|
55
|
+
return isExcluded;
|
|
56
|
+
};
|
|
57
|
+
exports.isMeshIncludedInExclusionList = isMeshIncludedInExclusionList;
|
|
58
58
|
//# sourceMappingURL=structureHelper.js.map
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": "
|
|
3
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"version": "8.0.0"
|
|
3
|
+
}
|