@combeenation/3d-viewer 5.0.1 → 5.0.3-beta2
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 -114
- package/dist/lib-cjs/api/classes/animationInterface.d.ts +8 -8
- package/dist/lib-cjs/api/classes/animationInterface.js +1 -1
- package/dist/lib-cjs/api/classes/dottedPath.d.ts +79 -79
- package/dist/lib-cjs/api/classes/dottedPath.js +187 -187
- package/dist/lib-cjs/api/classes/element.d.ts +139 -139
- package/dist/lib-cjs/api/classes/element.js +794 -794
- package/dist/lib-cjs/api/classes/element.js.map +1 -1
- package/dist/lib-cjs/api/classes/elementParameterizable.d.ts +14 -0
- package/dist/lib-cjs/api/classes/elementParameterizable.js +135 -0
- package/dist/lib-cjs/api/classes/elementParameterizable.js.map +1 -0
- package/dist/lib-cjs/api/classes/event.d.ts +326 -326
- package/dist/lib-cjs/api/classes/event.js +371 -371
- package/dist/lib-cjs/api/classes/eventBroadcaster.d.ts +26 -26
- package/dist/lib-cjs/api/classes/eventBroadcaster.js +53 -53
- package/dist/lib-cjs/api/classes/parameter.d.ts +316 -259
- package/dist/lib-cjs/api/classes/parameter.js +451 -388
- 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 +101 -101
- package/dist/lib-cjs/api/classes/parameterizable.d.ts +15 -15
- package/dist/lib-cjs/api/classes/parameterizable.js +149 -149
- package/dist/lib-cjs/api/classes/placementAnimation.d.ts +44 -44
- package/dist/lib-cjs/api/classes/placementAnimation.js +163 -163
- package/dist/lib-cjs/api/classes/variant.d.ts +234 -234
- package/dist/lib-cjs/api/classes/variant.js +1154 -1154
- package/dist/lib-cjs/api/classes/variantInstance.d.ts +45 -45
- package/dist/lib-cjs/api/classes/variantInstance.js +108 -108
- package/dist/lib-cjs/api/classes/variantParameterizable.d.ts +17 -17
- package/dist/lib-cjs/api/classes/variantParameterizable.js +99 -99
- package/dist/lib-cjs/api/classes/viewer.d.ts +177 -175
- package/dist/lib-cjs/api/classes/viewer.js +717 -701
- 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 +392 -392
- package/dist/lib-cjs/api/internal/debugViewer.d.ts +13 -13
- package/dist/lib-cjs/api/internal/debugViewer.js +86 -86
- 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 -10
- package/dist/lib-cjs/api/internal/sceneSetup.js +238 -234
- package/dist/lib-cjs/api/internal/sceneSetup.js.map +1 -1
- package/dist/lib-cjs/api/manager/animationManager.d.ts +29 -29
- package/dist/lib-cjs/api/manager/animationManager.js +130 -130
- package/dist/lib-cjs/api/manager/gltfExportManager.d.ts +65 -65
- package/dist/lib-cjs/api/manager/gltfExportManager.js +223 -222
- package/dist/lib-cjs/api/manager/gltfExportManager.js.map +1 -1
- package/dist/lib-cjs/api/manager/sceneManager.d.ts +31 -32
- package/dist/lib-cjs/api/manager/sceneManager.js +153 -132
- 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 +335 -335
- package/dist/lib-cjs/api/store/specStorage.d.ts +24 -24
- package/dist/lib-cjs/api/store/specStorage.js +51 -51
- package/dist/lib-cjs/api/util/babylonHelper.d.ts +174 -166
- package/dist/lib-cjs/api/util/babylonHelper.js +575 -497
- package/dist/lib-cjs/api/util/babylonHelper.js.map +1 -1
- package/dist/lib-cjs/api/util/globalTypes.d.ts +366 -356
- package/dist/lib-cjs/api/util/globalTypes.js +1 -1
- package/dist/lib-cjs/api/util/resourceHelper.d.ts +58 -53
- package/dist/lib-cjs/api/util/resourceHelper.js +257 -242
- package/dist/lib-cjs/api/util/resourceHelper.js.map +1 -1
- package/dist/lib-cjs/api/util/stringHelper.d.ts +9 -9
- package/dist/lib-cjs/api/util/stringHelper.js +25 -25
- package/dist/lib-cjs/api/util/structureHelper.d.ts +9 -9
- package/dist/lib-cjs/api/util/structureHelper.js +48 -44
- 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 +49 -49
- package/dist/lib-cjs/index.js +89 -89
- package/dist/webpack-stats.json +0 -0
- package/package.json +87 -87
- package/src/api/classes/animationInterface.ts +10 -10
- package/src/api/classes/dottedPath.ts +181 -181
- package/src/api/classes/element.ts +690 -692
- package/src/api/classes/event.ts +367 -367
- package/src/api/classes/eventBroadcaster.ts +52 -52
- package/src/api/classes/parameter.ts +474 -405
- package/src/api/classes/parameterObservable.ts +100 -100
- package/src/api/classes/parameterizable.ts +87 -87
- package/src/api/classes/placementAnimation.ts +160 -160
- package/src/api/classes/variant.ts +845 -845
- package/src/api/classes/variantInstance.ts +97 -97
- package/src/api/classes/variantParameterizable.ts +85 -85
- package/src/api/classes/viewer.ts +650 -624
- package/src/api/classes/viewerLight.ts +334 -334
- package/src/api/internal/debugViewer.ts +90 -90
- package/src/api/internal/lensRendering.ts +10 -10
- package/src/api/internal/sceneSetup.ts +204 -201
- package/src/api/manager/animationManager.ts +142 -142
- package/src/api/manager/gltfExportManager.ts +191 -191
- package/src/api/manager/sceneManager.ts +128 -102
- package/src/api/manager/variantInstanceManager.ts +265 -265
- package/src/api/store/specStorage.ts +51 -51
- package/src/api/util/babylonHelper.ts +628 -538
- package/src/api/util/globalTypes.ts +413 -402
- package/src/api/util/resourceHelper.ts +189 -173
- package/src/api/util/stringHelper.ts +23 -23
- package/src/api/util/structureHelper.ts +49 -43
- package/src/buildinfo.json +3 -3
- package/src/commonjs.tsconfig.json +10 -10
- package/src/declaration.tsconfig.json +8 -8
- package/src/dev.ts +42 -42
- package/src/es6.tsconfig.json +10 -10
- package/src/index.ts +94 -94
- package/src/pagesconfig.json +77 -73
- package/src/tsconfig.json +32 -32
- package/src/tsconfig.types.json +9 -9
- package/src/types.d.ts +3 -3
|
@@ -1,142 +1,142 @@
|
|
|
1
|
-
import { Animation as BabylonAnimation } from '@babylonjs/core/Animations/animation';
|
|
2
|
-
import { ArcRotateCamera } from '@babylonjs/core/Cameras/arcRotateCamera';
|
|
3
|
-
import { Scene as BabylonScene, Scene } from '@babylonjs/core/scene';
|
|
4
|
-
import { Nullable } from '@babylonjs/core/types';
|
|
5
|
-
//import { CustomEase } from 'gsap/CustomEase';
|
|
6
|
-
//import { ExpoScaleEase, RoughEase, SlowMo } from 'gsap/EasePack';
|
|
7
|
-
import { remove } from 'lodash-es';
|
|
8
|
-
import { PlacementAnimation } from '../classes/placementAnimation';
|
|
9
|
-
|
|
10
|
-
//gsap.registerPlugin( CustomEase, ExpoScaleEase, RoughEase, SlowMo );
|
|
11
|
-
|
|
12
|
-
export class AnimationManager {
|
|
13
|
-
public animations: AnimationInterface[] = [];
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Constructor.
|
|
17
|
-
*/
|
|
18
|
-
protected constructor(protected scene: Scene) {}
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Creates an {@link AnimationManager} based on given BabylonJS scene.
|
|
22
|
-
*/
|
|
23
|
-
public static async create(scene: BabylonScene): Promise<AnimationManager> {
|
|
24
|
-
return new AnimationManager(scene);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* @deprecated Use viewer.moveCameraTo().
|
|
29
|
-
*/
|
|
30
|
-
public resetCamera(animate: boolean = false) {
|
|
31
|
-
//TODO currently only works for arcrotate. are there any other cameras?
|
|
32
|
-
let activeCamera = this.scene.activeCamera as Nullable<ArcRotateCamera>;
|
|
33
|
-
if (!activeCamera) {
|
|
34
|
-
throw new Error('There is no active camera');
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
const initAlpha = activeCamera.metadata.alpha;
|
|
38
|
-
const initBeta = activeCamera.metadata.beta;
|
|
39
|
-
const initRadius = activeCamera.metadata.radius;
|
|
40
|
-
|
|
41
|
-
if (animate) {
|
|
42
|
-
this.animateArcRotateCamera(initAlpha, initBeta, initRadius);
|
|
43
|
-
} else {
|
|
44
|
-
activeCamera.alpha = initAlpha;
|
|
45
|
-
activeCamera.beta = initBeta;
|
|
46
|
-
activeCamera.radius = initRadius;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* @deprecated Use viewer.moveCameraTo().
|
|
52
|
-
*/
|
|
53
|
-
public animateArcRotateCamera(targetAlpha: number, targetBeta: number, targetRadius: number) {
|
|
54
|
-
let activeCamera = this.scene.activeCamera as Nullable<ArcRotateCamera>;
|
|
55
|
-
if (!activeCamera) {
|
|
56
|
-
throw new Error('There is no active camera');
|
|
57
|
-
}
|
|
58
|
-
const alphaAnimation = new BabylonAnimation(
|
|
59
|
-
'alphaAnimation',
|
|
60
|
-
'alpha',
|
|
61
|
-
30,
|
|
62
|
-
BabylonAnimation.ANIMATIONTYPE_FLOAT,
|
|
63
|
-
BabylonAnimation.ANIMATIONLOOPMODE_CONSTANT
|
|
64
|
-
);
|
|
65
|
-
const betaAnimation = new BabylonAnimation(
|
|
66
|
-
'betaAnimation',
|
|
67
|
-
'beta',
|
|
68
|
-
30,
|
|
69
|
-
BabylonAnimation.ANIMATIONTYPE_FLOAT,
|
|
70
|
-
BabylonAnimation.ANIMATIONLOOPMODE_CONSTANT
|
|
71
|
-
);
|
|
72
|
-
const radiusAnimation = new BabylonAnimation(
|
|
73
|
-
'radiusAnimation',
|
|
74
|
-
'radius',
|
|
75
|
-
30,
|
|
76
|
-
BabylonAnimation.ANIMATIONTYPE_FLOAT,
|
|
77
|
-
BabylonAnimation.ANIMATIONLOOPMODE_CONSTANT
|
|
78
|
-
);
|
|
79
|
-
alphaAnimation.setKeys([
|
|
80
|
-
{
|
|
81
|
-
frame: 0,
|
|
82
|
-
value: activeCamera.alpha,
|
|
83
|
-
},
|
|
84
|
-
{
|
|
85
|
-
frame: 100,
|
|
86
|
-
value: targetAlpha,
|
|
87
|
-
},
|
|
88
|
-
]);
|
|
89
|
-
betaAnimation.setKeys([
|
|
90
|
-
{
|
|
91
|
-
frame: 0,
|
|
92
|
-
value: activeCamera.beta,
|
|
93
|
-
},
|
|
94
|
-
{
|
|
95
|
-
frame: 100,
|
|
96
|
-
value: targetBeta,
|
|
97
|
-
},
|
|
98
|
-
]);
|
|
99
|
-
radiusAnimation.setKeys([
|
|
100
|
-
{
|
|
101
|
-
frame: 0,
|
|
102
|
-
value: activeCamera.radius,
|
|
103
|
-
},
|
|
104
|
-
{
|
|
105
|
-
frame: 100,
|
|
106
|
-
value: targetRadius,
|
|
107
|
-
},
|
|
108
|
-
]);
|
|
109
|
-
activeCamera.animations.push(alphaAnimation);
|
|
110
|
-
activeCamera.animations.push(betaAnimation);
|
|
111
|
-
activeCamera.animations.push(radiusAnimation);
|
|
112
|
-
|
|
113
|
-
let animation = this.scene.beginAnimation(activeCamera, 0, 100, false, 10);
|
|
114
|
-
animation.disposeOnEnd = true;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
/**
|
|
118
|
-
* Stops and kills all running animations.
|
|
119
|
-
*/
|
|
120
|
-
public killAllAnimations() {
|
|
121
|
-
this.animations.forEach(animation => animation.kill());
|
|
122
|
-
this.animations = [];
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
/**
|
|
126
|
-
* @see {@link PlacementAnimation.play}
|
|
127
|
-
*/
|
|
128
|
-
public async animateToPlacement(
|
|
129
|
-
mutable: object,
|
|
130
|
-
placement: PlacementDefinition | string,
|
|
131
|
-
animation?: AnimationDefinition | string
|
|
132
|
-
): Promise<AnimationInterface> {
|
|
133
|
-
const _animation = new PlacementAnimation(mutable, placement, animation);
|
|
134
|
-
this.animations.push(_animation);
|
|
135
|
-
const animationPromise = _animation.play();
|
|
136
|
-
animationPromise.then(a => {
|
|
137
|
-
remove(this.animations, _a => _a === a);
|
|
138
|
-
a.kill();
|
|
139
|
-
});
|
|
140
|
-
return await animationPromise;
|
|
141
|
-
}
|
|
142
|
-
}
|
|
1
|
+
import { Animation as BabylonAnimation } from '@babylonjs/core/Animations/animation';
|
|
2
|
+
import { ArcRotateCamera } from '@babylonjs/core/Cameras/arcRotateCamera';
|
|
3
|
+
import { Scene as BabylonScene, Scene } from '@babylonjs/core/scene';
|
|
4
|
+
import { Nullable } from '@babylonjs/core/types';
|
|
5
|
+
//import { CustomEase } from 'gsap/CustomEase';
|
|
6
|
+
//import { ExpoScaleEase, RoughEase, SlowMo } from 'gsap/EasePack';
|
|
7
|
+
import { remove } from 'lodash-es';
|
|
8
|
+
import { PlacementAnimation } from '../classes/placementAnimation';
|
|
9
|
+
|
|
10
|
+
//gsap.registerPlugin( CustomEase, ExpoScaleEase, RoughEase, SlowMo );
|
|
11
|
+
|
|
12
|
+
export class AnimationManager {
|
|
13
|
+
public animations: AnimationInterface[] = [];
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Constructor.
|
|
17
|
+
*/
|
|
18
|
+
protected constructor(protected scene: Scene) {}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Creates an {@link AnimationManager} based on given BabylonJS scene.
|
|
22
|
+
*/
|
|
23
|
+
public static async create(scene: BabylonScene): Promise<AnimationManager> {
|
|
24
|
+
return new AnimationManager(scene);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* @deprecated Use viewer.moveCameraTo().
|
|
29
|
+
*/
|
|
30
|
+
public resetCamera(animate: boolean = false) {
|
|
31
|
+
//TODO currently only works for arcrotate. are there any other cameras?
|
|
32
|
+
let activeCamera = this.scene.activeCamera as Nullable<ArcRotateCamera>;
|
|
33
|
+
if (!activeCamera) {
|
|
34
|
+
throw new Error('There is no active camera');
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const initAlpha = activeCamera.metadata.alpha;
|
|
38
|
+
const initBeta = activeCamera.metadata.beta;
|
|
39
|
+
const initRadius = activeCamera.metadata.radius;
|
|
40
|
+
|
|
41
|
+
if (animate) {
|
|
42
|
+
this.animateArcRotateCamera(initAlpha, initBeta, initRadius);
|
|
43
|
+
} else {
|
|
44
|
+
activeCamera.alpha = initAlpha;
|
|
45
|
+
activeCamera.beta = initBeta;
|
|
46
|
+
activeCamera.radius = initRadius;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* @deprecated Use viewer.moveCameraTo().
|
|
52
|
+
*/
|
|
53
|
+
public animateArcRotateCamera(targetAlpha: number, targetBeta: number, targetRadius: number) {
|
|
54
|
+
let activeCamera = this.scene.activeCamera as Nullable<ArcRotateCamera>;
|
|
55
|
+
if (!activeCamera) {
|
|
56
|
+
throw new Error('There is no active camera');
|
|
57
|
+
}
|
|
58
|
+
const alphaAnimation = new BabylonAnimation(
|
|
59
|
+
'alphaAnimation',
|
|
60
|
+
'alpha',
|
|
61
|
+
30,
|
|
62
|
+
BabylonAnimation.ANIMATIONTYPE_FLOAT,
|
|
63
|
+
BabylonAnimation.ANIMATIONLOOPMODE_CONSTANT
|
|
64
|
+
);
|
|
65
|
+
const betaAnimation = new BabylonAnimation(
|
|
66
|
+
'betaAnimation',
|
|
67
|
+
'beta',
|
|
68
|
+
30,
|
|
69
|
+
BabylonAnimation.ANIMATIONTYPE_FLOAT,
|
|
70
|
+
BabylonAnimation.ANIMATIONLOOPMODE_CONSTANT
|
|
71
|
+
);
|
|
72
|
+
const radiusAnimation = new BabylonAnimation(
|
|
73
|
+
'radiusAnimation',
|
|
74
|
+
'radius',
|
|
75
|
+
30,
|
|
76
|
+
BabylonAnimation.ANIMATIONTYPE_FLOAT,
|
|
77
|
+
BabylonAnimation.ANIMATIONLOOPMODE_CONSTANT
|
|
78
|
+
);
|
|
79
|
+
alphaAnimation.setKeys([
|
|
80
|
+
{
|
|
81
|
+
frame: 0,
|
|
82
|
+
value: activeCamera.alpha,
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
frame: 100,
|
|
86
|
+
value: targetAlpha,
|
|
87
|
+
},
|
|
88
|
+
]);
|
|
89
|
+
betaAnimation.setKeys([
|
|
90
|
+
{
|
|
91
|
+
frame: 0,
|
|
92
|
+
value: activeCamera.beta,
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
frame: 100,
|
|
96
|
+
value: targetBeta,
|
|
97
|
+
},
|
|
98
|
+
]);
|
|
99
|
+
radiusAnimation.setKeys([
|
|
100
|
+
{
|
|
101
|
+
frame: 0,
|
|
102
|
+
value: activeCamera.radius,
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
frame: 100,
|
|
106
|
+
value: targetRadius,
|
|
107
|
+
},
|
|
108
|
+
]);
|
|
109
|
+
activeCamera.animations.push(alphaAnimation);
|
|
110
|
+
activeCamera.animations.push(betaAnimation);
|
|
111
|
+
activeCamera.animations.push(radiusAnimation);
|
|
112
|
+
|
|
113
|
+
let animation = this.scene.beginAnimation(activeCamera, 0, 100, false, 10);
|
|
114
|
+
animation.disposeOnEnd = true;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Stops and kills all running animations.
|
|
119
|
+
*/
|
|
120
|
+
public killAllAnimations() {
|
|
121
|
+
this.animations.forEach(animation => animation.kill());
|
|
122
|
+
this.animations = [];
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* @see {@link PlacementAnimation.play}
|
|
127
|
+
*/
|
|
128
|
+
public async animateToPlacement(
|
|
129
|
+
mutable: object,
|
|
130
|
+
placement: PlacementDefinition | string,
|
|
131
|
+
animation?: AnimationDefinition | string
|
|
132
|
+
): Promise<AnimationInterface> {
|
|
133
|
+
const _animation = new PlacementAnimation(mutable, placement, animation);
|
|
134
|
+
this.animations.push(_animation);
|
|
135
|
+
const animationPromise = _animation.play();
|
|
136
|
+
animationPromise.then(a => {
|
|
137
|
+
remove(this.animations, _a => _a === a);
|
|
138
|
+
a.kill();
|
|
139
|
+
});
|
|
140
|
+
return await animationPromise;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
@@ -1,191 +1,191 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
export class GltfExportManager {
|
|
10
|
-
/**
|
|
11
|
-
* Constructor.
|
|
12
|
-
*/
|
|
13
|
-
protected constructor(protected viewer: Viewer) {}
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Creates an {@link GltfExportManager}.
|
|
17
|
-
*/
|
|
18
|
-
public static async create(viewer: Viewer): Promise<GltfExportManager> {
|
|
19
|
-
return new GltfExportManager(viewer);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Exports selected nodes to a file.
|
|
24
|
-
* @param filename optional name of the exported .GLB file.
|
|
25
|
-
* @param exportOptions export options to be merged with default options.
|
|
26
|
-
* @param excluded optional list of geometry (meshes, elements, variants, variantInstances) to be excluded from export.
|
|
27
|
-
*/
|
|
28
|
-
public async exportGlb(
|
|
29
|
-
filename = 'glb-export.glb',
|
|
30
|
-
exportOptions: IExportOptions = {},
|
|
31
|
-
excluded?:
|
|
32
|
-
): Promise<File | undefined> {
|
|
33
|
-
this.exportPreProcess();
|
|
34
|
-
const glbData = await GLTF2Export.GLBAsync(
|
|
35
|
-
this.viewer.scene,
|
|
36
|
-
'dummy',
|
|
37
|
-
this.gltfExportOptions(exportOptions, excluded)
|
|
38
|
-
);
|
|
39
|
-
this.exportPostProcess();
|
|
40
|
-
const resBlob = glbData.glTFFiles['dummy.glb']; // should be only one file for glb
|
|
41
|
-
|
|
42
|
-
// check if result is valid, according to the typings this could also be a string
|
|
43
|
-
if (resBlob instanceof Blob) {
|
|
44
|
-
if (!filename.endsWith('.glb')) {
|
|
45
|
-
filename += '.glb';
|
|
46
|
-
}
|
|
47
|
-
return new File([resBlob], filename);
|
|
48
|
-
} else {
|
|
49
|
-
// result was not a valid blob
|
|
50
|
-
return undefined;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* Exports selected nodes to GLTF. This may result in more than one file, since textures are exported separately.
|
|
56
|
-
* @param filename name of the main (text-based) .GLTF file referring to separate texture files.
|
|
57
|
-
* @param exportOptions export options to be merged with default options.
|
|
58
|
-
* @param excluded optional list of geometry (meshes, elements, variants, variantInstances) to be excluded from export.
|
|
59
|
-
*/
|
|
60
|
-
public async exportGltfToFile(filename: string, exportOptions: IExportOptions = {}, excluded?:
|
|
61
|
-
this.exportPreProcess();
|
|
62
|
-
await GLTF2Export.GLTFAsync(this.viewer.scene, filename, this.gltfExportOptions(exportOptions, excluded)).then(
|
|
63
|
-
glb => {
|
|
64
|
-
glb.downloadFiles();
|
|
65
|
-
}
|
|
66
|
-
);
|
|
67
|
-
this.exportPostProcess();
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* Exports selected nodes to GLB. This results in one binary file.
|
|
72
|
-
* @param filename name of the .GLB file.
|
|
73
|
-
* @param exportOptions export options to be merged with default options.
|
|
74
|
-
* @param excluded optional list of geometry (meshes, elements, variants, variantInstances) to be excluded from export
|
|
75
|
-
*/
|
|
76
|
-
public async exportGlbToFile(filename: string, exportOptions: IExportOptions = {}, excluded?:
|
|
77
|
-
this.exportPreProcess();
|
|
78
|
-
await GLTF2Export.GLBAsync(this.viewer.scene, filename, this.gltfExportOptions(exportOptions, excluded)).then(
|
|
79
|
-
glb => {
|
|
80
|
-
glb.downloadFiles();
|
|
81
|
-
}
|
|
82
|
-
);
|
|
83
|
-
this.exportPostProcess();
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* Gets predefined {@link IExportOptions } merged with given ones.
|
|
88
|
-
*/
|
|
89
|
-
protected gltfExportOptions(mergeWithOptions: IExportOptions = {}, excluded?:
|
|
90
|
-
const defaultOptions = {
|
|
91
|
-
// includeCoordinateSystemConversionNodes: true,
|
|
92
|
-
shouldExportNode: function (node: any) {
|
|
93
|
-
if (!node.isEnabled()) {
|
|
94
|
-
return false;
|
|
95
|
-
}
|
|
96
|
-
if (node.isVisible === false) {
|
|
97
|
-
return false;
|
|
98
|
-
}
|
|
99
|
-
if (node.name === '__bounding_box__') {
|
|
100
|
-
return false;
|
|
101
|
-
}
|
|
102
|
-
if (excluded && node instanceof Mesh && isMeshIncludedInExclusionList(node, excluded)) {
|
|
103
|
-
return false;
|
|
104
|
-
}
|
|
105
|
-
return true;
|
|
106
|
-
},
|
|
107
|
-
};
|
|
108
|
-
return merge({}, defaultOptions, mergeWithOptions);
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
/**
|
|
112
|
-
* Stuff to be done before exporting to GLTF
|
|
113
|
-
*/
|
|
114
|
-
protected exportPreProcess() {
|
|
115
|
-
this.viewer.pauseRendering();
|
|
116
|
-
this.exchangeRefractionMaterials();
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
/**
|
|
120
|
-
* Stuff to be done after the GLTF export
|
|
121
|
-
*/
|
|
122
|
-
protected exportPostProcess() {
|
|
123
|
-
this.restoreRefractionMaterials();
|
|
124
|
-
this.viewer.resumeRendering();
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
/**
|
|
128
|
-
* Materials with refraction set are not exported properly.
|
|
129
|
-
* Exchange all such (relevant) materials with a more export-friendly version
|
|
130
|
-
*/
|
|
131
|
-
protected exchangeRefractionMaterials() {
|
|
132
|
-
for (const n of this.viewer.scene.getNodes()) {
|
|
133
|
-
if (!(n instanceof AbstractMesh)) continue;
|
|
134
|
-
if (!(n.material instanceof PBRMaterial)) continue;
|
|
135
|
-
if (!(n.material as PBRMaterial).subSurface.isRefractionEnabled) continue;
|
|
136
|
-
if ((n.material as PBRMaterial).transparencyMode !== PBRMaterial.PBRMATERIAL_OPAQUE) continue;
|
|
137
|
-
// if we're here, we have a node holding a material with set refraction whose transparencyMode is set to PBRMATERIAL_OPAQUE
|
|
138
|
-
n.material = this.createRefractionMaterialReplacement(n.material);
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
/**
|
|
143
|
-
* Restore original materials with set refraction.
|
|
144
|
-
*/
|
|
145
|
-
protected restoreRefractionMaterials() {
|
|
146
|
-
for (const n of this.viewer.scene.getNodes()) {
|
|
147
|
-
if (!(n instanceof AbstractMesh)) continue;
|
|
148
|
-
if (!(n.material instanceof PBRMaterial)) continue;
|
|
149
|
-
if (!this.isMaterialClonedForExport(n.material)) continue;
|
|
150
|
-
// at this point we have a pbrmaterial tagged as cloned in its metadata that's set on a mesh
|
|
151
|
-
|
|
152
|
-
// restore and dispose
|
|
153
|
-
const currMaterial = n.material;
|
|
154
|
-
const prevMaterial = this.viewer.scene.getMaterialByUniqueID(n.material.metadata.clonedFrom);
|
|
155
|
-
if (prevMaterial) {
|
|
156
|
-
n.material = prevMaterial; // restore previous material
|
|
157
|
-
currMaterial.dispose(false, true); // dispose of clone
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
/**
|
|
163
|
-
* Create an export-friendly replacement material for a material using refraction.
|
|
164
|
-
* @param mat Material to be replaced
|
|
165
|
-
*/
|
|
166
|
-
protected createRefractionMaterialReplacement(mat: PBRMaterial): PBRMaterial {
|
|
167
|
-
// if we're dealing with a clone already, return it instead of cloning
|
|
168
|
-
if (this.isMaterialClonedForExport(mat)) return mat;
|
|
169
|
-
|
|
170
|
-
// change material according to https://www.notion.so/combeenation/Glas-materials-don-t-look-glasy-after-export-d5fda2c6515e4420a8772744d3e6b460
|
|
171
|
-
let clonedMaterial = mat.clone(mat.name); // clone material. clone uses same name
|
|
172
|
-
clonedMaterial.metadata = { ...mat.metadata, clonedFrom: mat.uniqueId }; // create shallow copy of metadata on clone. see https://forum.babylonjs.com/t/the-metadata-of-the-mesh-cloned-by-the-instantiatemodelstoscene-method-is-a-shallow-copy/21563
|
|
173
|
-
clonedMaterial.refractionTexture = null;
|
|
174
|
-
clonedMaterial.metallicReflectanceTexture = null; // is this the correct one for metallic roughness?
|
|
175
|
-
clonedMaterial.alpha = 0.7;
|
|
176
|
-
clonedMaterial.albedoColor = new Color3(0.3, 0.3, 0.3);
|
|
177
|
-
clonedMaterial.transparencyMode = PBRMaterial.PBRMATERIAL_ALPHABLEND;
|
|
178
|
-
clonedMaterial.metallic = 0.65;
|
|
179
|
-
clonedMaterial.roughness = 0.15;
|
|
180
|
-
|
|
181
|
-
return clonedMaterial;
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
/**
|
|
185
|
-
* Inspect if a material was temporarily cloned for GLB export
|
|
186
|
-
* @param mat Material to be inspected
|
|
187
|
-
*/
|
|
188
|
-
protected isMaterialClonedForExport(mat: PBRMaterial): boolean {
|
|
189
|
-
return mat.metadata
|
|
190
|
-
}
|
|
191
|
-
}
|
|
1
|
+
import { PBRMaterial } from '@babylonjs/core/Materials/PBR/pbrMaterial';
|
|
2
|
+
import { Color3 } from '@babylonjs/core/Maths/math.color';
|
|
3
|
+
import { AbstractMesh } from '@babylonjs/core/Meshes/abstractMesh';
|
|
4
|
+
import { GLTF2Export, IExportOptions } from '@babylonjs/serializers/glTF/2.0';
|
|
5
|
+
import { isMeshIncludedInExclusionList } from '../util/structureHelper';
|
|
6
|
+
import { merge } from 'lodash-es';
|
|
7
|
+
import { Mesh } from '@babylonjs/core/Meshes/mesh';
|
|
8
|
+
|
|
9
|
+
export class GltfExportManager {
|
|
10
|
+
/**
|
|
11
|
+
* Constructor.
|
|
12
|
+
*/
|
|
13
|
+
protected constructor(protected viewer: Viewer) {}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Creates an {@link GltfExportManager}.
|
|
17
|
+
*/
|
|
18
|
+
public static async create(viewer: Viewer): Promise<GltfExportManager> {
|
|
19
|
+
return new GltfExportManager(viewer);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Exports selected nodes to a file.
|
|
24
|
+
* @param filename optional name of the exported .GLB file.
|
|
25
|
+
* @param exportOptions export options to be merged with default options.
|
|
26
|
+
* @param excluded optional list of geometry (meshes, elements, variants, variantInstances) to be excluded from export.
|
|
27
|
+
*/
|
|
28
|
+
public async exportGlb(
|
|
29
|
+
filename = 'glb-export.glb',
|
|
30
|
+
exportOptions: IExportOptions = {},
|
|
31
|
+
excluded?: ExcludedGeometryList
|
|
32
|
+
): Promise<File | undefined> {
|
|
33
|
+
this.exportPreProcess();
|
|
34
|
+
const glbData = await GLTF2Export.GLBAsync(
|
|
35
|
+
this.viewer.scene,
|
|
36
|
+
'dummy',
|
|
37
|
+
this.gltfExportOptions(exportOptions, excluded)
|
|
38
|
+
);
|
|
39
|
+
this.exportPostProcess();
|
|
40
|
+
const resBlob = glbData.glTFFiles['dummy.glb']; // should be only one file for glb
|
|
41
|
+
|
|
42
|
+
// check if result is valid, according to the typings this could also be a string
|
|
43
|
+
if (resBlob instanceof Blob) {
|
|
44
|
+
if (!filename.endsWith('.glb')) {
|
|
45
|
+
filename += '.glb';
|
|
46
|
+
}
|
|
47
|
+
return new File([resBlob], filename);
|
|
48
|
+
} else {
|
|
49
|
+
// result was not a valid blob
|
|
50
|
+
return undefined;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Exports selected nodes to GLTF. This may result in more than one file, since textures are exported separately.
|
|
56
|
+
* @param filename name of the main (text-based) .GLTF file referring to separate texture files.
|
|
57
|
+
* @param exportOptions export options to be merged with default options.
|
|
58
|
+
* @param excluded optional list of geometry (meshes, elements, variants, variantInstances) to be excluded from export.
|
|
59
|
+
*/
|
|
60
|
+
public async exportGltfToFile(filename: string, exportOptions: IExportOptions = {}, excluded?: ExcludedGeometryList) {
|
|
61
|
+
this.exportPreProcess();
|
|
62
|
+
await GLTF2Export.GLTFAsync(this.viewer.scene, filename, this.gltfExportOptions(exportOptions, excluded)).then(
|
|
63
|
+
glb => {
|
|
64
|
+
glb.downloadFiles();
|
|
65
|
+
}
|
|
66
|
+
);
|
|
67
|
+
this.exportPostProcess();
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Exports selected nodes to GLB. This results in one binary file.
|
|
72
|
+
* @param filename name of the .GLB file.
|
|
73
|
+
* @param exportOptions export options to be merged with default options.
|
|
74
|
+
* @param excluded optional list of geometry (meshes, elements, variants, variantInstances) to be excluded from export
|
|
75
|
+
*/
|
|
76
|
+
public async exportGlbToFile(filename: string, exportOptions: IExportOptions = {}, excluded?: ExcludedGeometryList) {
|
|
77
|
+
this.exportPreProcess();
|
|
78
|
+
await GLTF2Export.GLBAsync(this.viewer.scene, filename, this.gltfExportOptions(exportOptions, excluded)).then(
|
|
79
|
+
glb => {
|
|
80
|
+
glb.downloadFiles();
|
|
81
|
+
}
|
|
82
|
+
);
|
|
83
|
+
this.exportPostProcess();
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Gets predefined {@link IExportOptions } merged with given ones.
|
|
88
|
+
*/
|
|
89
|
+
protected gltfExportOptions(mergeWithOptions: IExportOptions = {}, excluded?: ExcludedGeometryList): IExportOptions {
|
|
90
|
+
const defaultOptions = {
|
|
91
|
+
// includeCoordinateSystemConversionNodes: true,
|
|
92
|
+
shouldExportNode: function (node: any) {
|
|
93
|
+
if (!node.isEnabled()) {
|
|
94
|
+
return false;
|
|
95
|
+
}
|
|
96
|
+
if (node.isVisible === false) {
|
|
97
|
+
return false;
|
|
98
|
+
}
|
|
99
|
+
if (node.name === '__bounding_box__') {
|
|
100
|
+
return false;
|
|
101
|
+
}
|
|
102
|
+
if (excluded && node instanceof Mesh && isMeshIncludedInExclusionList(node, excluded)) {
|
|
103
|
+
return false;
|
|
104
|
+
}
|
|
105
|
+
return true;
|
|
106
|
+
},
|
|
107
|
+
};
|
|
108
|
+
return merge({}, defaultOptions, mergeWithOptions);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Stuff to be done before exporting to GLTF
|
|
113
|
+
*/
|
|
114
|
+
protected exportPreProcess() {
|
|
115
|
+
this.viewer.pauseRendering();
|
|
116
|
+
this.exchangeRefractionMaterials();
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Stuff to be done after the GLTF export
|
|
121
|
+
*/
|
|
122
|
+
protected exportPostProcess() {
|
|
123
|
+
this.restoreRefractionMaterials();
|
|
124
|
+
this.viewer.resumeRendering();
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Materials with refraction set are not exported properly.
|
|
129
|
+
* Exchange all such (relevant) materials with a more export-friendly version
|
|
130
|
+
*/
|
|
131
|
+
protected exchangeRefractionMaterials() {
|
|
132
|
+
for (const n of this.viewer.scene.getNodes()) {
|
|
133
|
+
if (!(n instanceof AbstractMesh)) continue;
|
|
134
|
+
if (!(n.material instanceof PBRMaterial)) continue;
|
|
135
|
+
if (!(n.material as PBRMaterial).subSurface.isRefractionEnabled) continue;
|
|
136
|
+
if ((n.material as PBRMaterial).transparencyMode !== PBRMaterial.PBRMATERIAL_OPAQUE) continue;
|
|
137
|
+
// if we're here, we have a node holding a material with set refraction whose transparencyMode is set to PBRMATERIAL_OPAQUE
|
|
138
|
+
n.material = this.createRefractionMaterialReplacement(n.material);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Restore original materials with set refraction.
|
|
144
|
+
*/
|
|
145
|
+
protected restoreRefractionMaterials() {
|
|
146
|
+
for (const n of this.viewer.scene.getNodes()) {
|
|
147
|
+
if (!(n instanceof AbstractMesh)) continue;
|
|
148
|
+
if (!(n.material instanceof PBRMaterial)) continue;
|
|
149
|
+
if (!this.isMaterialClonedForExport(n.material)) continue;
|
|
150
|
+
// at this point we have a pbrmaterial tagged as cloned in its metadata that's set on a mesh
|
|
151
|
+
|
|
152
|
+
// restore and dispose
|
|
153
|
+
const currMaterial = n.material;
|
|
154
|
+
const prevMaterial = this.viewer.scene.getMaterialByUniqueID(n.material.metadata.clonedFrom);
|
|
155
|
+
if (prevMaterial) {
|
|
156
|
+
n.material = prevMaterial; // restore previous material
|
|
157
|
+
currMaterial.dispose(false, true); // dispose of clone
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Create an export-friendly replacement material for a material using refraction.
|
|
164
|
+
* @param mat Material to be replaced
|
|
165
|
+
*/
|
|
166
|
+
protected createRefractionMaterialReplacement(mat: PBRMaterial): PBRMaterial {
|
|
167
|
+
// if we're dealing with a clone already, return it instead of cloning
|
|
168
|
+
if (this.isMaterialClonedForExport(mat)) return mat;
|
|
169
|
+
|
|
170
|
+
// change material according to https://www.notion.so/combeenation/Glas-materials-don-t-look-glasy-after-export-d5fda2c6515e4420a8772744d3e6b460
|
|
171
|
+
let clonedMaterial = mat.clone(mat.name); // clone material. clone uses same name
|
|
172
|
+
clonedMaterial.metadata = { ...mat.metadata, clonedFrom: mat.uniqueId }; // create shallow copy of metadata on clone. see https://forum.babylonjs.com/t/the-metadata-of-the-mesh-cloned-by-the-instantiatemodelstoscene-method-is-a-shallow-copy/21563
|
|
173
|
+
clonedMaterial.refractionTexture = null;
|
|
174
|
+
clonedMaterial.metallicReflectanceTexture = null; // is this the correct one for metallic roughness?
|
|
175
|
+
clonedMaterial.alpha = 0.7;
|
|
176
|
+
clonedMaterial.albedoColor = new Color3(0.3, 0.3, 0.3);
|
|
177
|
+
clonedMaterial.transparencyMode = PBRMaterial.PBRMATERIAL_ALPHABLEND;
|
|
178
|
+
clonedMaterial.metallic = 0.65;
|
|
179
|
+
clonedMaterial.roughness = 0.15;
|
|
180
|
+
|
|
181
|
+
return clonedMaterial;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Inspect if a material was temporarily cloned for GLB export
|
|
186
|
+
* @param mat Material to be inspected
|
|
187
|
+
*/
|
|
188
|
+
protected isMaterialClonedForExport(mat: PBRMaterial): boolean {
|
|
189
|
+
return !!mat.metadata?.clonedFrom;
|
|
190
|
+
}
|
|
191
|
+
}
|