@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
package/src/dev.ts
CHANGED
|
@@ -1,29 +1,19 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Viewer } from '.';
|
|
2
2
|
import {
|
|
3
|
-
|
|
4
|
-
beforeBootstrap,
|
|
5
|
-
createSpec,
|
|
6
|
-
createTagManagerParameterValues,
|
|
3
|
+
afterViewerSetup,
|
|
7
4
|
createUIelements,
|
|
5
|
+
getDefaultSceneSettings,
|
|
8
6
|
getMaterial,
|
|
9
|
-
|
|
7
|
+
getViewerSettings,
|
|
10
8
|
} from '../assets/index';
|
|
9
|
+
import { mockMaterials } from '../assets/mock-materials';
|
|
11
10
|
import { set } from 'lodash-es';
|
|
12
11
|
|
|
13
|
-
const loadingElement = document.getElementById('loading') as HTMLDivElement;
|
|
14
|
-
|
|
15
|
-
Emitter.on(Event.BOOTSTRAP_START, () => {
|
|
16
|
-
loadingElement!.style.display = 'block';
|
|
17
|
-
});
|
|
18
|
-
Emitter.on(Event.BOOTSTRAP_END, () => {
|
|
19
|
-
loadingElement!.style.display = 'none';
|
|
20
|
-
});
|
|
21
|
-
|
|
22
12
|
document.addEventListener('DOMContentLoaded', main);
|
|
23
13
|
|
|
24
14
|
window.Cbn = {
|
|
25
15
|
Assets: {
|
|
26
|
-
async getMaterial(materialId: string) {
|
|
16
|
+
async getMaterial(materialId: string): Promise<object> {
|
|
27
17
|
//! this creates a new function on the object that uses the imported function of the same name..
|
|
28
18
|
const material = await getMaterial(materialId);
|
|
29
19
|
if (material) return material;
|
|
@@ -34,11 +24,10 @@ window.Cbn = {
|
|
|
34
24
|
assertMaterialExists(materialId: string): boolean {
|
|
35
25
|
return true;
|
|
36
26
|
},
|
|
37
|
-
reportDuplicateNodeName(nodeNameOrArrayOfNodeNames: string | string[]): void {},
|
|
38
27
|
},
|
|
39
28
|
utils: {
|
|
40
29
|
Viewer3dHelper: {
|
|
41
|
-
getCfgrParentDomElementForInspector() {
|
|
30
|
+
getCfgrParentDomElementForInspector(): HTMLElement | undefined {
|
|
42
31
|
// render in parent of viewer
|
|
43
32
|
return document.querySelector<HTMLElement>('display-container') ?? undefined;
|
|
44
33
|
},
|
|
@@ -46,25 +35,13 @@ window.Cbn = {
|
|
|
46
35
|
},
|
|
47
36
|
};
|
|
48
37
|
|
|
49
|
-
async function main() {
|
|
50
|
-
const viewer = await bootstrapViewer();
|
|
51
|
-
// "Export" for console testing...
|
|
52
|
-
set(window, 'viewer', viewer);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
async function bootstrapViewer() {
|
|
38
|
+
async function main(): Promise<void> {
|
|
56
39
|
const canvas = document.getElementById('babylon-canvas') as HTMLCanvasElement;
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
const viewer = new Viewer(canvas, createSpec());
|
|
61
|
-
await beforeBootstrap(viewer);
|
|
62
|
-
try {
|
|
63
|
-
await viewer.bootstrap(createTagManagerParameterValues(viewer));
|
|
64
|
-
} catch (e) {
|
|
65
|
-
console.error(e);
|
|
66
|
-
}
|
|
67
|
-
await afterBootstrap(viewer);
|
|
40
|
+
const viewer = new Viewer(canvas, getViewerSettings(), getDefaultSceneSettings());
|
|
41
|
+
|
|
42
|
+
await afterViewerSetup(viewer);
|
|
68
43
|
await createUIelements(viewer);
|
|
69
|
-
|
|
44
|
+
|
|
45
|
+
// "Export" for console testing...
|
|
46
|
+
set(window, 'viewer', viewer);
|
|
70
47
|
}
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
/**
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Enhancement of Typescripts default `Partial` typing, which only creates shallow partials
|
|
3
|
+
*/
|
|
4
|
+
type DeepPartial<T> = {
|
|
5
|
+
[K in keyof T]?: T[K] extends object ? DeepPartial<T[K]> : T[K];
|
|
6
|
+
};
|
|
4
7
|
|
|
5
8
|
interface Window {
|
|
6
9
|
Cbn:
|
|
@@ -8,39 +11,26 @@ interface Window {
|
|
|
8
11
|
| {
|
|
9
12
|
Assets: {
|
|
10
13
|
/**
|
|
11
|
-
* Retrieve material definition from configurator
|
|
14
|
+
* Retrieve material definition from configurator.
|
|
12
15
|
* Implementation depends on the Combeenation environment the viewer is used in
|
|
13
16
|
* - Configurator: Access pre-fetched material JSON objects from Cbn client => synchronous
|
|
14
17
|
* - Asset Editor: Load content from material asset on demand => asynchronous!
|
|
15
18
|
*
|
|
16
|
-
* @param materialId
|
|
17
|
-
*
|
|
18
19
|
* @return Undefined if no definition for the given material name exists, otherwise an "JSON object" which can
|
|
19
20
|
* be passed to `BABYLON.Material.Parse` to create a runtime material object.
|
|
20
21
|
*/
|
|
21
22
|
getMaterial(materialId: string): Promise<object | undefined>;
|
|
22
23
|
|
|
23
24
|
/**
|
|
24
|
-
* Checks if a definition for a given material name exists in the configurator and issues a warning if not
|
|
25
|
-
*
|
|
26
|
-
* @param materialId
|
|
25
|
+
* Checks if a definition for a given material name exists in the configurator and issues a warning if not
|
|
27
26
|
*/
|
|
28
27
|
assertMaterialExists(materialId: string): boolean;
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Warns user about duplicate nodeNames on scene.
|
|
32
|
-
*
|
|
33
|
-
* @param nodeNameOrArrayOfNodeNames
|
|
34
|
-
*/
|
|
35
|
-
reportDuplicateNodeName(nodeNameOrArrayOfNodeNames: string | string[]): void;
|
|
36
28
|
};
|
|
37
29
|
utils: {
|
|
38
30
|
Viewer3dHelper: {
|
|
39
31
|
/**
|
|
40
32
|
* Returns parent DOM element of a Combeenation configurator, which can be used as root for the inspector.
|
|
41
33
|
* Also adjusts styling of some configurator parent sub elements to fix the inspector layout.
|
|
42
|
-
*
|
|
43
|
-
* @return
|
|
44
34
|
*/
|
|
45
35
|
getCfgrParentDomElementForInspector(): HTMLElement | undefined;
|
|
46
36
|
};
|
package/src/index.ts
CHANGED
|
@@ -1,116 +1,82 @@
|
|
|
1
|
-
/// <reference path="
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
import
|
|
11
|
-
import
|
|
12
|
-
import
|
|
13
|
-
import
|
|
14
|
-
import
|
|
15
|
-
import
|
|
16
|
-
import { ViewerError, ViewerErrorIds } from './api/classes/viewerError';
|
|
17
|
-
import { ViewerLight } from './api/classes/viewerLight';
|
|
18
|
-
import { AnimationManager } from './api/manager/animationManager';
|
|
19
|
-
import { GltfExportManager } from './api/manager/gltfExportManager';
|
|
20
|
-
import { SceneManager } from './api/manager/sceneManager';
|
|
21
|
-
import { TagManager } from './api/manager/tagManager';
|
|
22
|
-
import { VariantInstanceManager } from './api/manager/variantInstanceManager';
|
|
23
|
-
import { SpecStorage } from './api/store/specStorage';
|
|
24
|
-
import * as BabylonHelper from './api/util/babylonHelper';
|
|
25
|
-
import { Animation as BabylonAnimation } from '@babylonjs/core/Animations/animation';
|
|
26
|
-
import { ArcRotateCamera } from '@babylonjs/core/Cameras/arcRotateCamera';
|
|
27
|
-
import { Engine } from '@babylonjs/core/Engines/engine';
|
|
28
|
-
import { DirectionalLight } from '@babylonjs/core/Lights/directionalLight';
|
|
29
|
-
import { HemisphericLight } from '@babylonjs/core/Lights/hemisphericLight';
|
|
30
|
-
import { BackgroundMaterial } from '@babylonjs/core/Materials/Background/backgroundMaterial';
|
|
31
|
-
import { NodeMaterial } from '@babylonjs/core/Materials/Node';
|
|
1
|
+
/// <reference path="globalTypes.d.ts" />
|
|
2
|
+
// Babylon.js extensions
|
|
3
|
+
import '@babylonjs/loaders/glTF/2.0/Extensions/KHR_draco_mesh_compression';
|
|
4
|
+
import '@babylonjs/loaders/glTF/2.0/Extensions/KHR_materials_clearcoat';
|
|
5
|
+
import '@babylonjs/loaders/glTF/2.0/Extensions/KHR_materials_ior';
|
|
6
|
+
import '@babylonjs/loaders/glTF/2.0/Extensions/KHR_materials_pbrSpecularGlossiness';
|
|
7
|
+
import '@babylonjs/loaders/glTF/2.0/Extensions/KHR_materials_sheen';
|
|
8
|
+
import '@babylonjs/loaders/glTF/2.0/Extensions/KHR_materials_specular';
|
|
9
|
+
import '@babylonjs/loaders/glTF/2.0/Extensions/KHR_materials_translucency';
|
|
10
|
+
import '@babylonjs/loaders/glTF/2.0/Extensions/KHR_materials_transmission';
|
|
11
|
+
import '@babylonjs/loaders/glTF/2.0/Extensions/KHR_materials_unlit';
|
|
12
|
+
import '@babylonjs/loaders/glTF/2.0/Extensions/KHR_materials_variants';
|
|
13
|
+
import '@babylonjs/loaders/glTF/2.0/Extensions/KHR_texture_basisu';
|
|
14
|
+
import '@babylonjs/loaders/glTF/2.0/Extensions/KHR_texture_transform';
|
|
15
|
+
import '@babylonjs/serializers/glTF/2.0/Extensions/KHR_texture_transform';
|
|
32
16
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
17
|
+
// Babylon.js modules
|
|
18
|
+
// All used Babylyon.js modules should be re-exported here.
|
|
19
|
+
// In this way consumers have access to all of them as well via an import of "@combeenation/3d-viewer" instead of having
|
|
20
|
+
// to make single imports from "@babylonjs/..."
|
|
21
|
+
// When using Babylon.js modules inside the viewer repo make sure to import from the viewer root as well.
|
|
22
|
+
// E.g. `import { BaseTexture, Material, Node } from '../index';`
|
|
23
|
+
export * from '@babylonjs/core/abstractScene';
|
|
24
|
+
export * from '@babylonjs/core/Animations';
|
|
25
|
+
export * from '@babylonjs/core/assetContainer';
|
|
26
|
+
export * from '@babylonjs/core/Buffers';
|
|
27
|
+
export * from '@babylonjs/core/Cameras/arcRotateCamera';
|
|
28
|
+
export * from '@babylonjs/core/Cameras/camera';
|
|
29
|
+
export * from '@babylonjs/core/Culling';
|
|
30
|
+
export * from '@babylonjs/core/Debug/axesViewer';
|
|
31
|
+
export * from '@babylonjs/core/Debug/debugLayer';
|
|
32
|
+
export * from '@babylonjs/core/Engines/engine';
|
|
33
|
+
export * from '@babylonjs/core/Engines/thinEngine';
|
|
34
|
+
export * from '@babylonjs/core/Lights';
|
|
35
|
+
export * from '@babylonjs/core/Loading';
|
|
36
|
+
export * from '@babylonjs/core/Materials/material';
|
|
37
|
+
export * from '@babylonjs/core/Materials/PBR';
|
|
38
|
+
export * from '@babylonjs/core/Materials/standardMaterial';
|
|
39
|
+
export * from '@babylonjs/core/Materials/Textures';
|
|
40
|
+
export * from '@babylonjs/core/Maths';
|
|
41
|
+
export * from '@babylonjs/core/Meshes/abstractMesh';
|
|
42
|
+
export * from '@babylonjs/core/Meshes/geometry';
|
|
43
|
+
export * from '@babylonjs/core/Meshes/instancedMesh';
|
|
44
|
+
export * from '@babylonjs/core/Meshes/mesh';
|
|
45
|
+
export * from '@babylonjs/core/Meshes/meshBuilder';
|
|
46
|
+
export * from '@babylonjs/core/Meshes/transformNode';
|
|
47
|
+
export * from '@babylonjs/core/Misc/interfaces/screenshotSize';
|
|
48
|
+
export * from '@babylonjs/core/Misc/screenshotTools';
|
|
49
|
+
export * from '@babylonjs/core/Morph';
|
|
50
|
+
export * from '@babylonjs/core/node';
|
|
51
|
+
export * from '@babylonjs/core/Rendering/utilityLayerRenderer';
|
|
52
|
+
export * from '@babylonjs/core/scene';
|
|
53
|
+
export * from '@babylonjs/core/types';
|
|
54
|
+
export * from '@babylonjs/loaders/glTF/2.0/glTFLoader';
|
|
55
|
+
export * from '@babylonjs/serializers/glTF/2.0/glTFSerializer';
|
|
40
56
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
import { MeshBuilder } from '@babylonjs/core/Meshes/meshBuilder';
|
|
53
|
-
import { TransformNode } from '@babylonjs/core/Meshes/transformNode';
|
|
57
|
+
// Additional Babylon.js modules
|
|
58
|
+
// These are not used in the "@combeenation/3d-viewer" repository directly, but required in consuming code for various
|
|
59
|
+
// reasons
|
|
60
|
+
// for checking camera collions with ground and wall meshes
|
|
61
|
+
export * from '@babylonjs/core/Collisions';
|
|
62
|
+
// for Scene.createDefaultEnvironment
|
|
63
|
+
export * from '@babylonjs/core/Helpers/sceneHelpers';
|
|
64
|
+
// support BackgroundMaterial on Combeenation platform
|
|
65
|
+
export * from '@babylonjs/core/Materials/Background';
|
|
66
|
+
// support NodeMaterial on Combeenation platform
|
|
67
|
+
export * from '@babylonjs/core/Materials/Node';
|
|
54
68
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
*
|
|
67
|
-
|
|
68
|
-
export
|
|
69
|
-
AnimationManager,
|
|
70
|
-
AnimationInterface,
|
|
71
|
-
Variant,
|
|
72
|
-
VariantInstanceManager,
|
|
73
|
-
Viewer,
|
|
74
|
-
ParameterObservable,
|
|
75
|
-
Parameterizable,
|
|
76
|
-
VariantParameterizable,
|
|
77
|
-
ViewerLight,
|
|
78
|
-
emitter as Emitter,
|
|
79
|
-
EventEmitter,
|
|
80
|
-
Event,
|
|
81
|
-
Parameter,
|
|
82
|
-
VariantInstance,
|
|
83
|
-
Color3,
|
|
84
|
-
Color4,
|
|
85
|
-
Vector3,
|
|
86
|
-
AbstractMesh,
|
|
87
|
-
InstancedMesh,
|
|
88
|
-
Mesh,
|
|
89
|
-
TransformNode,
|
|
90
|
-
Node,
|
|
91
|
-
Material,
|
|
92
|
-
PBRMaterial,
|
|
93
|
-
StandardMaterial,
|
|
94
|
-
NodeMaterial,
|
|
95
|
-
BackgroundMaterial,
|
|
96
|
-
Scene,
|
|
97
|
-
Engine,
|
|
98
|
-
ArcRotateCamera,
|
|
99
|
-
DynamicTexture,
|
|
100
|
-
CubeTexture,
|
|
101
|
-
MeshBuilder,
|
|
102
|
-
Texture,
|
|
103
|
-
BabylonAnimation,
|
|
104
|
-
HemisphericLight,
|
|
105
|
-
DirectionalLight,
|
|
106
|
-
Element,
|
|
107
|
-
EventBroadcaster,
|
|
108
|
-
SceneManager,
|
|
109
|
-
PlacementAnimation,
|
|
110
|
-
BabylonHelper,
|
|
111
|
-
GltfExportManager,
|
|
112
|
-
SpecStorage,
|
|
113
|
-
TagManager,
|
|
114
|
-
ViewerError,
|
|
115
|
-
ViewerErrorIds,
|
|
116
|
-
};
|
|
69
|
+
// Viewer modules
|
|
70
|
+
// all viewer modules that are not located in "internal" should be exported from here
|
|
71
|
+
export * from './viewer';
|
|
72
|
+
export * from './viewerError';
|
|
73
|
+
export * from './manager/cameraManager';
|
|
74
|
+
export * from './manager/debugManager';
|
|
75
|
+
export * from './manager/eventManager';
|
|
76
|
+
export * from './manager/gltfExportManager';
|
|
77
|
+
export * from './manager/materialManager';
|
|
78
|
+
export * from './manager/modelManager';
|
|
79
|
+
export * from './manager/parameterManager';
|
|
80
|
+
export * from './manager/sceneManager';
|
|
81
|
+
export * from './manager/screenshotManager';
|
|
82
|
+
export * from './manager/textureManager';
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { AssetContainer, ISceneLoaderPlugin, InstancedMesh, Scene, SceneLoader } from '../index';
|
|
2
|
+
import { cloneMorphTargetManager } from './cloningHelper';
|
|
3
|
+
import { setInternalMetadataValue } from './metadataHelper';
|
|
4
|
+
import { deleteAllTags, getTags, setTagsAsString } from './tagsHelper';
|
|
5
|
+
import { isArray, isString } from 'lodash-es';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Create and return a custom loader plugin to be registered with SceneLoader, that allows
|
|
9
|
+
* us to run our own code against the input data before using the standard procedure to
|
|
10
|
+
* import.
|
|
11
|
+
* The main use case is to mark missing material in meshes, which will get loaded on demand at the first time the
|
|
12
|
+
* dedicated mesh gets visible.
|
|
13
|
+
* This is the case if the babylon file is a Combeenation "3d asset" which comes without materials, as the materials
|
|
14
|
+
* are defined as "material assets".
|
|
15
|
+
*/
|
|
16
|
+
export function registerCustomCbnBabylonLoaderPlugin(): void {
|
|
17
|
+
// get original plugin for babylon files
|
|
18
|
+
// we only want to manipulate Combeenation 3d assets, which are represented as babylon files
|
|
19
|
+
// the plugin is not used for GLB files, "local" babylon are also not really affected by this plugin
|
|
20
|
+
const previousLoaderPlugin = SceneLoader.GetPluginForExtension('.babylon') as ISceneLoaderPlugin;
|
|
21
|
+
|
|
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
|
+
const dataParsed = JSON.parse(data);
|
|
29
|
+
const importedContainer = previousLoaderPlugin.loadAssetContainer(scene, data, rootUrl);
|
|
30
|
+
|
|
31
|
+
_addMissingMaterialMetadata(dataParsed, importedContainer);
|
|
32
|
+
_reconstructTagsForInstancedMeshes(dataParsed, importedContainer);
|
|
33
|
+
_unifyMorphTargetManagerIds(importedContainer, scene);
|
|
34
|
+
|
|
35
|
+
return importedContainer;
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
SceneLoader.RegisterPlugin(customLoader);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
type InstanceData = {
|
|
43
|
+
name: string;
|
|
44
|
+
tags?: string;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
function _isMeshInstanceData(data: any): data is InstanceData {
|
|
48
|
+
const hasName = isString(data.name);
|
|
49
|
+
const hasValidTags = !data.tags || isString(data.tags);
|
|
50
|
+
return hasName && hasValidTags;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
type MeshData = {
|
|
54
|
+
name: string;
|
|
55
|
+
materialId?: string;
|
|
56
|
+
instances?: unknown[];
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
function _isMeshData(data: any): data is MeshData {
|
|
60
|
+
const hasName = isString(data.name);
|
|
61
|
+
const hasValidMaterialId = !data.materialId || isString(data.materialId);
|
|
62
|
+
|
|
63
|
+
return hasName && hasValidMaterialId;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
type DataWithMeshes = { meshes: unknown[] };
|
|
67
|
+
|
|
68
|
+
function _isDataWithMeshes(data: any): data is DataWithMeshes {
|
|
69
|
+
return data && isArray(data.meshes);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Internal function that compares the original meshes on a .babylon file with what was loaded,
|
|
74
|
+
* and tags missing materials with respective metadata on respective meshes.
|
|
75
|
+
* @param dataParsed original data
|
|
76
|
+
* @param container loaded data
|
|
77
|
+
*/
|
|
78
|
+
function _addMissingMaterialMetadata(dataParsed: unknown, container: AssetContainer): void {
|
|
79
|
+
if (!_isDataWithMeshes(dataParsed)) return;
|
|
80
|
+
|
|
81
|
+
const validatedMeshes = dataParsed.meshes.filter(_isMeshData);
|
|
82
|
+
|
|
83
|
+
container.meshes.forEach(importedMesh => {
|
|
84
|
+
const parsedMesh = validatedMeshes.find(mesh => mesh.name === importedMesh.name);
|
|
85
|
+
|
|
86
|
+
const materialOnImportedMesh = importedMesh.material?.id;
|
|
87
|
+
const materialOnOriginalMesh = parsedMesh?.materialId;
|
|
88
|
+
|
|
89
|
+
if (materialOnOriginalMesh && materialOnImportedMesh !== materialOnOriginalMesh) {
|
|
90
|
+
window.Cbn?.Assets.assertMaterialExists(materialOnOriginalMesh);
|
|
91
|
+
setInternalMetadataValue(importedMesh, 'deferredMaterial', materialOnOriginalMesh);
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Help function for manipulating tags of instances meshes after parsing.
|
|
98
|
+
* Per default babylon attaches the tags of the source mesh to the instance, **but only** if no tags are set for the
|
|
99
|
+
* instanced mesh. If the instanced mesh has dedicated tags set, the ones from the source mesh are **not** copied over.
|
|
100
|
+
* In this case it's not possible to have tags on the source mesh but not on the instance, which is a problem with our
|
|
101
|
+
* tagging system in the viewer and the Combeenation asset editor as well.
|
|
102
|
+
* This function rejects the default tag import algorithm and just copies the tags of the original parsed node without
|
|
103
|
+
* any parent synchronization.
|
|
104
|
+
*
|
|
105
|
+
* @param dataParsed original data
|
|
106
|
+
* @param container loaded data
|
|
107
|
+
*/
|
|
108
|
+
function _reconstructTagsForInstancedMeshes(dataParsed: unknown, container: AssetContainer): void {
|
|
109
|
+
if (!_isDataWithMeshes(dataParsed)) return;
|
|
110
|
+
|
|
111
|
+
const validatedMeshes = dataParsed.meshes.filter(_isMeshData);
|
|
112
|
+
|
|
113
|
+
container.meshes.forEach(importedMesh => {
|
|
114
|
+
if (importedMesh instanceof InstancedMesh) {
|
|
115
|
+
// remove all tags from the imported mesh if there are some, since these tags are probably coming from the
|
|
116
|
+
// source mesh, if no tags are set there is no need for further operation though
|
|
117
|
+
const hasTags = getTags(importedMesh);
|
|
118
|
+
if (hasTags) {
|
|
119
|
+
deleteAllTags(importedMesh);
|
|
120
|
+
|
|
121
|
+
// get tags of parsed instanced mesh and set them on the imported instanced mesh
|
|
122
|
+
const parsedSourceMesh = validatedMeshes.find(mesh => mesh.name === importedMesh.sourceMesh.name);
|
|
123
|
+
const validatedSourceMeshInstances = parsedSourceMesh?.instances?.filter(_isMeshInstanceData);
|
|
124
|
+
const parsedInstancedMesh = validatedSourceMeshInstances?.find(mesh => mesh.name === importedMesh.name);
|
|
125
|
+
const parsedTags = parsedInstancedMesh?.tags;
|
|
126
|
+
if (parsedTags) {
|
|
127
|
+
setTagsAsString(importedMesh, parsedTags);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Morph target managers from different assets may receive the same id, which leads to erroneous morph target
|
|
136
|
+
* assignments. We can't change the id, but we can create a clone which then creates a new unique id.
|
|
137
|
+
*/
|
|
138
|
+
function _unifyMorphTargetManagerIds(container: AssetContainer, scene: Scene): void {
|
|
139
|
+
[...container.morphTargetManagers].forEach(sourceMTM => {
|
|
140
|
+
const clonedMTM = cloneMorphTargetManager(sourceMTM, container);
|
|
141
|
+
|
|
142
|
+
// clone function adds morph target manager to scene right, which we don't want here as we are only loading the
|
|
143
|
+
// asset container
|
|
144
|
+
scene.removeMorphTargetManager(clonedMTM);
|
|
145
|
+
|
|
146
|
+
// original morph target manager with bad id is not needed anymore and can be disposed
|
|
147
|
+
sourceMTM.dispose();
|
|
148
|
+
});
|
|
149
|
+
}
|