@combeenation/3d-viewer 5.1.2 → 5.2.0-alpha4
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 -1
- package/dist/lib-cjs/api/classes/dottedPath.d.ts +79 -79
- package/dist/lib-cjs/api/classes/dottedPath.js +166 -187
- package/dist/lib-cjs/api/classes/dottedPath.js.map +1 -1
- package/dist/lib-cjs/api/classes/element.d.ts +149 -149
- package/dist/lib-cjs/api/classes/element.js +668 -823
- package/dist/lib-cjs/api/classes/element.js.map +1 -1
- package/dist/lib-cjs/api/classes/event.d.ts +326 -326
- package/dist/lib-cjs/api/classes/event.js +349 -371
- package/dist/lib-cjs/api/classes/event.js.map +1 -1
- package/dist/lib-cjs/api/classes/eventBroadcaster.d.ts +26 -26
- package/dist/lib-cjs/api/classes/eventBroadcaster.js +49 -53
- package/dist/lib-cjs/api/classes/eventBroadcaster.js.map +1 -1
- package/dist/lib-cjs/api/classes/parameter.d.ts +336 -336
- package/dist/lib-cjs/api/classes/parameter.js +461 -471
- package/dist/lib-cjs/api/classes/parameter.js.map +1 -1
- package/dist/lib-cjs/api/classes/parameterObservable.d.ts +36 -36
- package/dist/lib-cjs/api/classes/parameterObservable.js +97 -101
- package/dist/lib-cjs/api/classes/parameterObservable.js.map +1 -1
- package/dist/lib-cjs/api/classes/parameterizable.d.ts +15 -15
- package/dist/lib-cjs/api/classes/parameterizable.js +102 -149
- package/dist/lib-cjs/api/classes/parameterizable.js.map +1 -1
- package/dist/lib-cjs/api/classes/placementAnimation.d.ts +45 -44
- package/dist/lib-cjs/api/classes/placementAnimation.js +175 -163
- package/dist/lib-cjs/api/classes/placementAnimation.js.map +1 -1
- package/dist/lib-cjs/api/classes/variant.d.ts +234 -234
- package/dist/lib-cjs/api/classes/variant.js +836 -1203
- package/dist/lib-cjs/api/classes/variant.js.map +1 -1
- package/dist/lib-cjs/api/classes/variantInstance.d.ts +45 -45
- package/dist/lib-cjs/api/classes/variantInstance.js +101 -108
- package/dist/lib-cjs/api/classes/variantInstance.js.map +1 -1
- package/dist/lib-cjs/api/classes/variantParameterizable.d.ts +17 -17
- package/dist/lib-cjs/api/classes/variantParameterizable.js +88 -99
- package/dist/lib-cjs/api/classes/variantParameterizable.js.map +1 -1
- package/dist/lib-cjs/api/classes/viewer.d.ts +187 -184
- package/dist/lib-cjs/api/classes/viewer.js +593 -731
- package/dist/lib-cjs/api/classes/viewer.js.map +1 -1
- package/dist/lib-cjs/api/classes/viewerLight.d.ts +66 -66
- package/dist/lib-cjs/api/classes/viewerLight.js +343 -392
- package/dist/lib-cjs/api/classes/viewerLight.js.map +1 -1
- 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/lensRendering.js.map +1 -1
- package/dist/lib-cjs/api/internal/sceneSetup.d.ts +13 -13
- package/dist/lib-cjs/api/internal/sceneSetup.js +225 -238
- package/dist/lib-cjs/api/internal/sceneSetup.js.map +1 -1
- package/dist/lib-cjs/api/manager/animationManager.d.ts +30 -29
- package/dist/lib-cjs/api/manager/animationManager.js +126 -130
- package/dist/lib-cjs/api/manager/animationManager.js.map +1 -1
- package/dist/lib-cjs/api/manager/gltfExportManager.d.ts +65 -65
- package/dist/lib-cjs/api/manager/gltfExportManager.js +196 -223
- package/dist/lib-cjs/api/manager/gltfExportManager.js.map +1 -1
- package/dist/lib-cjs/api/manager/sceneManager.d.ts +31 -31
- package/dist/lib-cjs/api/manager/sceneManager.js +127 -152
- package/dist/lib-cjs/api/manager/sceneManager.js.map +1 -1
- package/dist/lib-cjs/api/manager/variantInstanceManager.d.ts +92 -92
- package/dist/lib-cjs/api/manager/variantInstanceManager.js +260 -335
- package/dist/lib-cjs/api/manager/variantInstanceManager.js.map +1 -1
- package/dist/lib-cjs/api/store/specStorage.d.ts +24 -24
- package/dist/lib-cjs/api/store/specStorage.js +50 -51
- package/dist/lib-cjs/api/store/specStorage.js.map +1 -1
- package/dist/lib-cjs/api/util/babylonHelper.d.ts +174 -174
- package/dist/lib-cjs/api/util/babylonHelper.js +591 -611
- package/dist/lib-cjs/api/util/babylonHelper.js.map +1 -1
- package/dist/lib-cjs/api/util/globalTypes.d.ts +366 -366
- 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 +201 -257
- package/dist/lib-cjs/api/util/resourceHelper.js.map +1 -1
- package/dist/lib-cjs/api/util/sceneLoaderHelper.d.ts +35 -35
- package/dist/lib-cjs/api/util/sceneLoaderHelper.js +141 -140
- package/dist/lib-cjs/api/util/sceneLoaderHelper.js.map +1 -1
- package/dist/lib-cjs/api/util/stringHelper.d.ts +9 -9
- package/dist/lib-cjs/api/util/stringHelper.js +23 -25
- package/dist/lib-cjs/api/util/stringHelper.js.map +1 -1
- package/dist/lib-cjs/api/util/structureHelper.d.ts +9 -9
- package/dist/lib-cjs/api/util/structureHelper.js +48 -48
- package/dist/lib-cjs/api/util/structureHelper.js.map +1 -1
- package/dist/lib-cjs/buildinfo.json +3 -3
- package/dist/lib-cjs/index.d.ts +51 -49
- package/dist/lib-cjs/index.js +110 -89
- package/dist/lib-cjs/index.js.map +1 -1
- package/dist/lib-es6/api/classes/animationInterface.d.ts +8 -8
- package/dist/lib-es6/api/classes/animationInterface.js +1 -1
- package/dist/lib-es6/api/classes/dottedPath.d.ts +79 -79
- package/dist/lib-es6/api/classes/dottedPath.js +162 -184
- package/dist/lib-es6/api/classes/dottedPath.js.map +1 -1
- package/dist/lib-es6/api/classes/element.d.ts +149 -149
- package/dist/lib-es6/api/classes/element.js +664 -820
- package/dist/lib-es6/api/classes/element.js.map +1 -1
- package/dist/lib-es6/api/classes/event.d.ts +326 -326
- package/dist/lib-es6/api/classes/event.js +345 -368
- package/dist/lib-es6/api/classes/event.js.map +1 -1
- package/dist/lib-es6/api/classes/eventBroadcaster.d.ts +26 -26
- package/dist/lib-es6/api/classes/eventBroadcaster.js +42 -50
- package/dist/lib-es6/api/classes/eventBroadcaster.js.map +1 -1
- package/dist/lib-es6/api/classes/parameter.d.ts +336 -336
- package/dist/lib-es6/api/classes/parameter.js +457 -468
- package/dist/lib-es6/api/classes/parameter.js.map +1 -1
- package/dist/lib-es6/api/classes/parameterObservable.d.ts +36 -36
- package/dist/lib-es6/api/classes/parameterObservable.js +93 -98
- package/dist/lib-es6/api/classes/parameterObservable.js.map +1 -1
- package/dist/lib-es6/api/classes/parameterizable.d.ts +15 -15
- package/dist/lib-es6/api/classes/parameterizable.js +98 -146
- package/dist/lib-es6/api/classes/parameterizable.js.map +1 -1
- package/dist/lib-es6/api/classes/placementAnimation.d.ts +45 -44
- package/dist/lib-es6/api/classes/placementAnimation.js +171 -160
- package/dist/lib-es6/api/classes/placementAnimation.js.map +1 -1
- package/dist/lib-es6/api/classes/variant.d.ts +234 -234
- package/dist/lib-es6/api/classes/variant.js +832 -1198
- package/dist/lib-es6/api/classes/variant.js.map +1 -1
- package/dist/lib-es6/api/classes/variantInstance.d.ts +45 -45
- package/dist/lib-es6/api/classes/variantInstance.js +97 -105
- package/dist/lib-es6/api/classes/variantInstance.js.map +1 -1
- package/dist/lib-es6/api/classes/variantParameterizable.d.ts +17 -17
- package/dist/lib-es6/api/classes/variantParameterizable.js +84 -96
- package/dist/lib-es6/api/classes/variantParameterizable.js.map +1 -1
- package/dist/lib-es6/api/classes/viewer.d.ts +187 -184
- package/dist/lib-es6/api/classes/viewer.js +586 -728
- package/dist/lib-es6/api/classes/viewer.js.map +1 -1
- package/dist/lib-es6/api/classes/viewerLight.d.ts +66 -66
- package/dist/lib-es6/api/classes/viewerLight.js +316 -389
- package/dist/lib-es6/api/classes/viewerLight.js.map +1 -1
- package/dist/lib-es6/api/internal/lensRendering.d.ts +8 -8
- package/dist/lib-es6/api/internal/lensRendering.js +8 -8
- package/dist/lib-es6/api/internal/lensRendering.js.map +1 -1
- package/dist/lib-es6/api/internal/sceneSetup.d.ts +13 -13
- package/dist/lib-es6/api/internal/sceneSetup.js +197 -233
- package/dist/lib-es6/api/internal/sceneSetup.js.map +1 -1
- package/dist/lib-es6/api/manager/animationManager.d.ts +30 -29
- package/dist/lib-es6/api/manager/animationManager.js +122 -127
- package/dist/lib-es6/api/manager/animationManager.js.map +1 -1
- package/dist/lib-es6/api/manager/gltfExportManager.d.ts +65 -65
- package/dist/lib-es6/api/manager/gltfExportManager.js +192 -220
- package/dist/lib-es6/api/manager/gltfExportManager.js.map +1 -1
- package/dist/lib-es6/api/manager/sceneManager.d.ts +31 -31
- package/dist/lib-es6/api/manager/sceneManager.js +123 -149
- package/dist/lib-es6/api/manager/sceneManager.js.map +1 -1
- package/dist/lib-es6/api/manager/variantInstanceManager.d.ts +92 -92
- package/dist/lib-es6/api/manager/variantInstanceManager.js +256 -332
- package/dist/lib-es6/api/manager/variantInstanceManager.js.map +1 -1
- package/dist/lib-es6/api/store/specStorage.d.ts +24 -24
- package/dist/lib-es6/api/store/specStorage.js +46 -48
- package/dist/lib-es6/api/store/specStorage.js.map +1 -1
- package/dist/lib-es6/api/util/babylonHelper.d.ts +174 -174
- package/dist/lib-es6/api/util/babylonHelper.js +561 -581
- package/dist/lib-es6/api/util/babylonHelper.js.map +1 -1
- package/dist/lib-es6/api/util/globalTypes.d.ts +366 -366
- package/dist/lib-es6/api/util/globalTypes.js +1 -1
- package/dist/lib-es6/api/util/resourceHelper.d.ts +58 -58
- package/dist/lib-es6/api/util/resourceHelper.js +191 -247
- package/dist/lib-es6/api/util/resourceHelper.js.map +1 -1
- package/dist/lib-es6/api/util/sceneLoaderHelper.d.ts +35 -35
- package/dist/lib-es6/api/util/sceneLoaderHelper.js +131 -133
- package/dist/lib-es6/api/util/sceneLoaderHelper.js.map +1 -1
- package/dist/lib-es6/api/util/stringHelper.d.ts +9 -9
- package/dist/lib-es6/api/util/stringHelper.js +19 -21
- package/dist/lib-es6/api/util/stringHelper.js.map +1 -1
- package/dist/lib-es6/api/util/structureHelper.d.ts +9 -9
- package/dist/lib-es6/api/util/structureHelper.js +45 -45
- package/dist/lib-es6/api/util/structureHelper.js.map +1 -1
- package/dist/lib-es6/buildinfo.json +3 -3
- package/dist/lib-es6/index.d.ts +51 -49
- package/dist/lib-es6/index.js +48 -50
- package/dist/lib-es6/index.js.map +1 -1
- package/dist/lib-full/lens-rendering.js +2 -0
- package/dist/lib-full/lens-rendering.js.map +1 -0
- package/dist/lib-full/main.js +3 -0
- package/dist/lib-full/main.js.LICENSE.txt +9 -0
- package/dist/lib-full/main.js.map +1 -0
- package/package.json +76 -88
- package/src/api/classes/animationInterface.ts +10 -10
- package/src/api/classes/dottedPath.ts +181 -181
- package/src/api/classes/element.ts +716 -716
- package/src/api/classes/event.ts +367 -367
- package/src/api/classes/eventBroadcaster.ts +52 -52
- package/src/api/classes/parameter.ts +494 -494
- package/src/api/classes/parameterObservable.ts +100 -100
- package/src/api/classes/parameterizable.ts +87 -87
- package/src/api/classes/placementAnimation.ts +161 -160
- package/src/api/classes/variant.ts +904 -905
- package/src/api/classes/variantInstance.ts +97 -97
- package/src/api/classes/variantParameterizable.ts +85 -85
- package/src/api/classes/viewer.ts +669 -668
- package/src/api/classes/viewerLight.ts +334 -334
- package/src/api/internal/debugViewer.ts +90 -90
- package/src/api/internal/lensRendering.ts +9 -10
- package/src/api/internal/sceneSetup.ts +204 -204
- package/src/api/manager/animationManager.ts +143 -142
- package/src/api/manager/gltfExportManager.ts +191 -191
- package/src/api/manager/sceneManager.ts +127 -127
- package/src/api/manager/variantInstanceManager.ts +265 -265
- package/src/api/store/specStorage.ts +51 -51
- package/src/api/util/babylonHelper.ts +663 -663
- package/src/api/util/globalTypes.ts +413 -413
- package/src/api/util/resourceHelper.ts +189 -189
- package/src/api/util/sceneLoaderHelper.ts +148 -147
- package/src/api/util/stringHelper.ts +23 -23
- package/src/api/util/structureHelper.ts +49 -49
- package/src/buildinfo.json +3 -3
- package/src/dev.ts +61 -64
- package/src/index.ts +96 -94
- package/src/types.d.ts +28 -28
- package/dist/lib-cjs/api/classes/elementParameterizable.d.ts +0 -14
- package/dist/lib-cjs/api/classes/elementParameterizable.js +0 -135
- package/dist/lib-cjs/api/classes/elementParameterizable.js.map +0 -1
- package/dist/lib-cjs/api/internal/debugViewer.d.ts +0 -13
- package/dist/lib-cjs/api/internal/debugViewer.js +0 -87
- package/dist/lib-cjs/api/internal/debugViewer.js.map +0 -1
- package/dist/lib-es6/api/internal/debugViewer.d.ts +0 -13
- package/dist/lib-es6/api/internal/debugViewer.js +0 -84
- package/dist/lib-es6/api/internal/debugViewer.js.map +0 -1
- package/dist/webpack-stats.json +0 -0
- package/src/commonjs.tsconfig.json +0 -10
- package/src/declaration.tsconfig.json +0 -8
- package/src/es6.tsconfig.json +0 -10
- package/src/pagesconfig.json +0 -81
- package/src/tsconfig.json +0 -33
- package/src/tsconfig.types.json +0 -9
|
@@ -1,147 +1,148 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { ISceneLoaderPlugin } from '@babylonjs/core/Loading/sceneLoader';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
6
|
-
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
* @
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
return
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
* @param
|
|
45
|
-
* @
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
*
|
|
66
|
-
*
|
|
67
|
-
* @param
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
const
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
};
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
*
|
|
92
|
-
*
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
//
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
if
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
//
|
|
107
|
-
//
|
|
108
|
-
// * `
|
|
109
|
-
// *
|
|
110
|
-
// * `parentMesh`
|
|
111
|
-
// * `parentMesh` is disabled
|
|
112
|
-
// * `
|
|
113
|
-
//
|
|
114
|
-
//
|
|
115
|
-
//
|
|
116
|
-
//
|
|
117
|
-
//
|
|
118
|
-
//
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
*
|
|
130
|
-
* @param
|
|
131
|
-
* @
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
// `
|
|
137
|
-
//
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
1
|
+
import { injectNodeMetadata } from './babylonHelper';
|
|
2
|
+
import { ISceneLoaderPlugin } from '@babylonjs/core/Loading/sceneLoader';
|
|
3
|
+
import { Material } from '@babylonjs/core/Materials/material';
|
|
4
|
+
import { InstancedMesh } from '@babylonjs/core/Meshes/instancedMesh';
|
|
5
|
+
import { AssetContainer } from '@babylonjs/core/assetContainer';
|
|
6
|
+
//! overload DOM API Node due to name-clash with BJS
|
|
7
|
+
import { Node as BjsNode } from '@babylonjs/core/node';
|
|
8
|
+
import { Scene } from '@babylonjs/core/scene';
|
|
9
|
+
import { Nullable } from '@babylonjs/core/types';
|
|
10
|
+
import has from 'lodash-es/has';
|
|
11
|
+
|
|
12
|
+
const missingMaterialMetadataName = 'missingMaterial';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Create and return a custom loader plugin to be registered with SceneLoader, that allows
|
|
16
|
+
* us to run our own code against the input data before using the standard procedure to
|
|
17
|
+
* import.
|
|
18
|
+
* @param previousLoaderPlugin the actual loader that's executed after manipulating the input data
|
|
19
|
+
* @returns Custom loader plugin to be registered with SceneLoader.RegisterPlugin()
|
|
20
|
+
*/
|
|
21
|
+
const getCustomCbnBabylonLoaderPlugin = function (previousLoaderPlugin: ISceneLoaderPlugin): ISceneLoaderPlugin {
|
|
22
|
+
const customLoader: ISceneLoaderPlugin = {
|
|
23
|
+
name: 'cbnCustomBabylonLoader',
|
|
24
|
+
extensions: '.babylon',
|
|
25
|
+
importMesh: previousLoaderPlugin.importMesh,
|
|
26
|
+
load: previousLoaderPlugin.load,
|
|
27
|
+
loadAssetContainer: function (scene, data, rootUrl, onError) {
|
|
28
|
+
//* 1) --- manipulate ORIGINAL data
|
|
29
|
+
const dataParsed = JSON.parse(data);
|
|
30
|
+
//* 2) --- call default (non-custom) loading method
|
|
31
|
+
const importedContainer = previousLoaderPlugin.loadAssetContainer(scene, data, rootUrl);
|
|
32
|
+
//* 3) --- manipulate IMPORTED data
|
|
33
|
+
addMissingMaterialMetadata(dataParsed, importedContainer);
|
|
34
|
+
//* 4) --- return imported data
|
|
35
|
+
return importedContainer;
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
return customLoader;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Return an observer to be applied to meshes in order to post-load missing materials
|
|
43
|
+
* upon set enabled/visible.
|
|
44
|
+
* @param targetMeshOrInstance AbstractMesh the observer will be applied to
|
|
45
|
+
* @param concerningMesh Mesh to look for missing materials on, and create/apply to (when found).
|
|
46
|
+
* @returns observer
|
|
47
|
+
*/
|
|
48
|
+
const getMaterialPostLoadObserver = function (targetMeshOrInstance: AbstractMesh, concerningMesh: Mesh) {
|
|
49
|
+
return (_eventData: any, _eventState: any) => {
|
|
50
|
+
const hasBeenEnabled = concerningMesh.isEnabled(true);
|
|
51
|
+
const materialMissing = has(concerningMesh.metadata, missingMaterialMetadataName);
|
|
52
|
+
if (!hasBeenEnabled || !materialMissing) return;
|
|
53
|
+
// get id of missing material
|
|
54
|
+
const missingMatId = concerningMesh.metadata[missingMaterialMetadataName];
|
|
55
|
+
// try to find material on the scene
|
|
56
|
+
const existingMat = concerningMesh.getScene().getMaterialById(missingMatId);
|
|
57
|
+
// assign either existing material or freshly created one
|
|
58
|
+
concerningMesh.material = existingMat || getMaterialFromCbnAssets(missingMatId, concerningMesh.getScene());
|
|
59
|
+
// since the material is there now, we do not need the related metadata tag anymore
|
|
60
|
+
delete concerningMesh.metadata[missingMaterialMetadataName];
|
|
61
|
+
};
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Internal function that compares the original meshes on a .babylon file with what was loaded,
|
|
66
|
+
* and tags missing materials with respective metadata on respective meshes.
|
|
67
|
+
* @param dataParsed original data
|
|
68
|
+
* @param container loaded data
|
|
69
|
+
*/
|
|
70
|
+
const addMissingMaterialMetadata = function (dataParsed: any, container: AssetContainer) {
|
|
71
|
+
container.meshes.forEach(currMeshImported => {
|
|
72
|
+
for (const currMeshOriginal of dataParsed.meshes) {
|
|
73
|
+
if (currMeshOriginal.name !== currMeshImported.name) continue;
|
|
74
|
+
// we're dealing with the original version of the current imported mesh now
|
|
75
|
+
const materialOnImportedMesh = currMeshImported.material?.id;
|
|
76
|
+
const materialOnOriginalMesh = currMeshOriginal.materialId;
|
|
77
|
+
if (!materialOnOriginalMesh || materialOnImportedMesh === materialOnOriginalMesh) continue;
|
|
78
|
+
// TODO: Just for easier debugging. Remove before publishment...
|
|
79
|
+
console.info(
|
|
80
|
+
`Adding "${missingMaterialMetadataName}" info on mesh "${currMeshOriginal.name}" with material "${currMeshOriginal.materialId}"`
|
|
81
|
+
);
|
|
82
|
+
// if we're here, the imported mesh has different material than original one
|
|
83
|
+
window.Cbn?.Assets.assertMaterialExists(materialOnOriginalMesh);
|
|
84
|
+
injectNodeMetadata(currMeshImported, { [missingMaterialMetadataName]: materialOnOriginalMesh }, false);
|
|
85
|
+
break;
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Adds an "onEnabledStateChanged" observer to the given mesh and all its parents:
|
|
92
|
+
* The added observer (`getMaterialPostLoadObserver`) handles creation of missing materials once the given node is
|
|
93
|
+
* enabled.
|
|
94
|
+
*/
|
|
95
|
+
const addMissingMaterialObserver = function (node: BjsNode) {
|
|
96
|
+
// set the concerning node, i.e. the node the observer should check for missing material.
|
|
97
|
+
// for instanced meshes, we want the sourcemesh here.
|
|
98
|
+
const concerningNode = node instanceof InstancedMesh ? node.sourceMesh : (node as Mesh);
|
|
99
|
+
|
|
100
|
+
// observer is pointless if concerning node has no missing material
|
|
101
|
+
if (!has(concerningNode.metadata, missingMaterialMetadataName)) return;
|
|
102
|
+
|
|
103
|
+
// for each of our AbstractMeshes, set an observer on the AbstractMesh itself and all of its parents.
|
|
104
|
+
let currNode: Nullable<BjsNode> = node;
|
|
105
|
+
while (currNode) {
|
|
106
|
+
// Note HAR: Using `addOnce` could be wrong in certain situations.
|
|
107
|
+
// E.g.:
|
|
108
|
+
// * 2 meshes `parentMesh` & `parentMesh.concerningMesh`
|
|
109
|
+
// * `concerningMesh` is having the missing material flag
|
|
110
|
+
// * Both `parentMesh` & `concerningMesh` are disabled
|
|
111
|
+
// * `parentMesh` is enabled -> material should **not** be created as `concerningMesh` is still disabled
|
|
112
|
+
// * `parentMesh` is disabled
|
|
113
|
+
// * `concerningMesh` is enabled -> material should **not** be created as `concerningMesh` is still invisible
|
|
114
|
+
// because its `parentMesh` is ATM disabled
|
|
115
|
+
// * `parentMesh` & `concerningMesh` are both enable
|
|
116
|
+
// -> material should be created as `concerningMesh` is now actually visible but it isn't, as all observers were
|
|
117
|
+
// only fired once 🔥
|
|
118
|
+
//
|
|
119
|
+
// However: Using `add` instead of `addOnce` requires rather complicated manual clean up work...
|
|
120
|
+
|
|
121
|
+
// add observer. needed only once per node, hence addOnce()
|
|
122
|
+
node.onEnabledStateChangedObservable.addOnce(getMaterialPostLoadObserver(currNode as AbstractMesh, concerningNode));
|
|
123
|
+
// console.log('## observer set on: ' + meshOrInstance.name);
|
|
124
|
+
currNode = currNode.parent;
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Look up the provided materials (see library import) and create and return one if found.
|
|
130
|
+
* @param materialId BabylonJs material-id. E.g. 'concrete".
|
|
131
|
+
* @param scene BabylonJs scene
|
|
132
|
+
* @returns PBRMaterial | null
|
|
133
|
+
*/
|
|
134
|
+
export const getMaterialFromCbnAssets = function (materialId: string, scene: Scene): Material | null {
|
|
135
|
+
const materialDefinition = window.Cbn?.Assets.getMaterial(materialId);
|
|
136
|
+
// The generic `Material.Parse` actually returns a more specific material like `BABYLON.StandardMaterial`,
|
|
137
|
+
// `BABYLON.PBRMaterial` or stuff like `BABYLON.PBRMetallicRoughnessMaterial` etc. based on the given `customType`
|
|
138
|
+
// within the material JSON definition
|
|
139
|
+
const material = materialDefinition && Material.Parse(materialDefinition, scene, '');
|
|
140
|
+
return material || null;
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
export {
|
|
144
|
+
getCustomCbnBabylonLoaderPlugin,
|
|
145
|
+
getMaterialPostLoadObserver,
|
|
146
|
+
missingMaterialMetadataName,
|
|
147
|
+
addMissingMaterialObserver,
|
|
148
|
+
};
|
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Creates a random uuidv4.
|
|
3
|
-
*/
|
|
4
|
-
const uuidv4 = function () {
|
|
5
|
-
// @ts-ignore
|
|
6
|
-
return ([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, c =>
|
|
7
|
-
(c ^ (crypto.getRandomValues(new Uint8Array(1))[0] & (15 >> (c / 4)))).toString(16)
|
|
8
|
-
);
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Converts a string from camel case to snake case.
|
|
13
|
-
*/
|
|
14
|
-
const camelToSnakeCase = function (str: string): string {
|
|
15
|
-
return str
|
|
16
|
-
.replace(/([A-Z])/g, ' $1')
|
|
17
|
-
.trim()
|
|
18
|
-
.split(' ')
|
|
19
|
-
.join('_')
|
|
20
|
-
.toLowerCase();
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
export { uuidv4, camelToSnakeCase };
|
|
1
|
+
/**
|
|
2
|
+
* Creates a random uuidv4.
|
|
3
|
+
*/
|
|
4
|
+
const uuidv4 = function () {
|
|
5
|
+
// @ts-ignore
|
|
6
|
+
return ([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, c =>
|
|
7
|
+
(c ^ (crypto.getRandomValues(new Uint8Array(1))[0] & (15 >> (c / 4)))).toString(16)
|
|
8
|
+
);
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Converts a string from camel case to snake case.
|
|
13
|
+
*/
|
|
14
|
+
const camelToSnakeCase = function (str: string): string {
|
|
15
|
+
return str
|
|
16
|
+
.replace(/([A-Z])/g, ' $1')
|
|
17
|
+
.trim()
|
|
18
|
+
.split(' ')
|
|
19
|
+
.join('_')
|
|
20
|
+
.toLowerCase();
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export { uuidv4, camelToSnakeCase };
|
|
@@ -1,49 +1,49 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Variant } from '../classes/variant';
|
|
3
|
-
import { VariantInstance } from '../classes/variantInstance';
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Find out if a mesh is part of a list of excluded geometry
|
|
8
|
-
* @param mesh BJS mesh
|
|
9
|
-
* @param list list of excluded geometry
|
|
10
|
-
* @returns boolean based on whether mesh (or one of its parents) was found in list
|
|
11
|
-
*/
|
|
12
|
-
const isMeshIncludedInExclusionList = function (mesh: Mesh, list: ExcludedGeometryList): boolean {
|
|
13
|
-
const checkMesh = (inputMesh: Mesh, meshToCheck: Mesh) => {
|
|
14
|
-
return inputMesh.uniqueId === meshToCheck.uniqueId;
|
|
15
|
-
};
|
|
16
|
-
const checkElement = (inputEl: Element, meshToCheck: Mesh) => {
|
|
17
|
-
return inputEl.meshesFlat.some(m => checkMesh(m, meshToCheck));
|
|
18
|
-
};
|
|
19
|
-
const checkVariant = (inputVariant: Variant, meshToCheck: Mesh) => {
|
|
20
|
-
return inputVariant.elements.some(el => checkElement(el, meshToCheck));
|
|
21
|
-
};
|
|
22
|
-
const checkVariantInstance = (inputVarInst: VariantInstance, meshToCheck: Mesh) => {
|
|
23
|
-
return inputVarInst.variant.elements.some(el => checkElement(el, meshToCheck));
|
|
24
|
-
};
|
|
25
|
-
const check = (geometryToExclude: ExcludedGeometry, mesh: Mesh) => {
|
|
26
|
-
if (geometryToExclude instanceof VariantInstance) {
|
|
27
|
-
return checkVariantInstance(geometryToExclude, mesh);
|
|
28
|
-
}
|
|
29
|
-
if (geometryToExclude instanceof Variant) {
|
|
30
|
-
return checkVariant(geometryToExclude, mesh);
|
|
31
|
-
}
|
|
32
|
-
if (geometryToExclude instanceof Element) {
|
|
33
|
-
return checkElement(geometryToExclude, mesh);
|
|
34
|
-
}
|
|
35
|
-
if (geometryToExclude instanceof Mesh) {
|
|
36
|
-
return checkMesh(geometryToExclude, mesh);
|
|
37
|
-
}
|
|
38
|
-
return false;
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
let isExcluded = list.some(geometryToExclude => check(geometryToExclude, mesh));
|
|
42
|
-
if (!isExcluded && mesh.parent instanceof Mesh) {
|
|
43
|
-
isExcluded = isMeshIncludedInExclusionList(mesh.parent, list);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
return isExcluded;
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
export { isMeshIncludedInExclusionList };
|
|
1
|
+
import { Element } from '../classes/element';
|
|
2
|
+
import { Variant } from '../classes/variant';
|
|
3
|
+
import { VariantInstance } from '../classes/variantInstance';
|
|
4
|
+
import { Mesh } from '@babylonjs/core/Meshes/mesh';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Find out if a mesh is part of a list of excluded geometry
|
|
8
|
+
* @param mesh BJS mesh
|
|
9
|
+
* @param list list of excluded geometry
|
|
10
|
+
* @returns boolean based on whether mesh (or one of its parents) was found in list
|
|
11
|
+
*/
|
|
12
|
+
const isMeshIncludedInExclusionList = function (mesh: Mesh, list: ExcludedGeometryList): boolean {
|
|
13
|
+
const checkMesh = (inputMesh: Mesh, meshToCheck: Mesh) => {
|
|
14
|
+
return inputMesh.uniqueId === meshToCheck.uniqueId;
|
|
15
|
+
};
|
|
16
|
+
const checkElement = (inputEl: Element, meshToCheck: Mesh) => {
|
|
17
|
+
return inputEl.meshesFlat.some(m => checkMesh(m, meshToCheck));
|
|
18
|
+
};
|
|
19
|
+
const checkVariant = (inputVariant: Variant, meshToCheck: Mesh) => {
|
|
20
|
+
return inputVariant.elements.some(el => checkElement(el, meshToCheck));
|
|
21
|
+
};
|
|
22
|
+
const checkVariantInstance = (inputVarInst: VariantInstance, meshToCheck: Mesh) => {
|
|
23
|
+
return inputVarInst.variant.elements.some(el => checkElement(el, meshToCheck));
|
|
24
|
+
};
|
|
25
|
+
const check = (geometryToExclude: ExcludedGeometry, mesh: Mesh) => {
|
|
26
|
+
if (geometryToExclude instanceof VariantInstance) {
|
|
27
|
+
return checkVariantInstance(geometryToExclude, mesh);
|
|
28
|
+
}
|
|
29
|
+
if (geometryToExclude instanceof Variant) {
|
|
30
|
+
return checkVariant(geometryToExclude, mesh);
|
|
31
|
+
}
|
|
32
|
+
if (geometryToExclude instanceof Element) {
|
|
33
|
+
return checkElement(geometryToExclude, mesh);
|
|
34
|
+
}
|
|
35
|
+
if (geometryToExclude instanceof Mesh) {
|
|
36
|
+
return checkMesh(geometryToExclude, mesh);
|
|
37
|
+
}
|
|
38
|
+
return false;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
let isExcluded = list.some(geometryToExclude => check(geometryToExclude, mesh));
|
|
42
|
+
if (!isExcluded && mesh.parent instanceof Mesh) {
|
|
43
|
+
isExcluded = isMeshIncludedInExclusionList(mesh.parent, list);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return isExcluded;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
export { isMeshIncludedInExclusionList };
|
package/src/buildinfo.json
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": "@VERSION@"
|
|
3
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"version": "@VERSION@"
|
|
3
|
+
}
|
package/src/dev.ts
CHANGED
|
@@ -1,64 +1,61 @@
|
|
|
1
|
-
import { Event } from '
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
Emitter.on(Event.
|
|
19
|
-
loadingElement!.style.display = '
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
return
|
|
36
|
-
},
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
await createUIelements(viewer);
|
|
63
|
-
return viewer;
|
|
64
|
-
}
|
|
1
|
+
import { Emitter, Event, Viewer } from '.';
|
|
2
|
+
import {
|
|
3
|
+
afterBootstrap,
|
|
4
|
+
beforeBootstrap,
|
|
5
|
+
createSpec,
|
|
6
|
+
createUIelements,
|
|
7
|
+
getMaterial,
|
|
8
|
+
mockMaterials,
|
|
9
|
+
} from '../assets/index';
|
|
10
|
+
import { set } from 'lodash-es';
|
|
11
|
+
|
|
12
|
+
const loadingElement = document.getElementById('loading') as HTMLDivElement;
|
|
13
|
+
|
|
14
|
+
Emitter.on(Event.BOOTSTRAP_START, () => {
|
|
15
|
+
Emitter.on(Event.LOADING_START, () => {
|
|
16
|
+
loadingElement!.style.display = 'block';
|
|
17
|
+
});
|
|
18
|
+
Emitter.on(Event.VARIANT_CREATED, () => {
|
|
19
|
+
loadingElement!.style.display = 'none';
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
document.addEventListener('DOMContentLoaded', main);
|
|
24
|
+
|
|
25
|
+
window.Cbn = {
|
|
26
|
+
Assets: {
|
|
27
|
+
getMaterial(materialId: string) {
|
|
28
|
+
const material = getMaterial(materialId);
|
|
29
|
+
if (material) return material;
|
|
30
|
+
|
|
31
|
+
// Fallback to random mock material
|
|
32
|
+
return mockMaterials[Math.floor(Math.random() * mockMaterials.length)];
|
|
33
|
+
},
|
|
34
|
+
assertMaterialExists(materialId: string): boolean {
|
|
35
|
+
return true;
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
async function main() {
|
|
41
|
+
const viewer = await bootstrapViewer();
|
|
42
|
+
// "Export" for console testing...
|
|
43
|
+
set(window, 'viewer', viewer);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
async function bootstrapViewer() {
|
|
47
|
+
const canvas = document.getElementById('babylon-canvas') as HTMLCanvasElement;
|
|
48
|
+
if (!canvas) {
|
|
49
|
+
throw new Error('Missing "canvas" element');
|
|
50
|
+
}
|
|
51
|
+
const viewer = new Viewer(canvas, createSpec());
|
|
52
|
+
await beforeBootstrap(viewer);
|
|
53
|
+
try {
|
|
54
|
+
await viewer.bootstrap();
|
|
55
|
+
} catch (e) {
|
|
56
|
+
console.error(e);
|
|
57
|
+
}
|
|
58
|
+
await afterBootstrap(viewer);
|
|
59
|
+
await createUIelements(viewer);
|
|
60
|
+
return viewer;
|
|
61
|
+
}
|