@combeenation/3d-viewer 4.0.0-beta4 → 4.0.0-beta5
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 +114 -112
- 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 +190 -190
- package/dist/lib-cjs/api/classes/element.d.ts +130 -125
- package/dist/lib-cjs/api/classes/element.js +743 -682
- package/dist/lib-cjs/api/classes/element.js.map +1 -1
- package/dist/lib-cjs/api/classes/elementParameterizable.d.ts +14 -14
- package/dist/lib-cjs/api/classes/elementParameterizable.js +134 -134
- package/dist/lib-cjs/api/classes/event.d.ts +326 -312
- package/dist/lib-cjs/api/classes/event.js +371 -357
- 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 +53 -53
- package/dist/lib-cjs/api/classes/parameter.d.ts +259 -165
- package/dist/lib-cjs/api/classes/parameter.js +387 -267
- 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 -126
- 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 +149 -149
- package/dist/lib-cjs/api/classes/placementAnimation.d.ts +38 -38
- package/dist/lib-cjs/api/classes/placementAnimation.js +149 -138
- package/dist/lib-cjs/api/classes/placementAnimation.js.map +1 -1
- package/dist/lib-cjs/api/classes/variant.d.ts +234 -190
- package/dist/lib-cjs/api/classes/variant.js +1147 -873
- package/dist/lib-cjs/api/classes/variant.js.map +1 -1
- package/dist/lib-cjs/api/classes/variantInstance.d.ts +45 -41
- package/dist/lib-cjs/api/classes/variantInstance.js +108 -98
- 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 +92 -92
- package/dist/lib-cjs/api/classes/viewer.d.ts +131 -128
- package/dist/lib-cjs/api/classes/viewer.js +560 -486
- package/dist/lib-cjs/api/classes/viewer.js.map +1 -1
- package/dist/lib-cjs/api/classes/viewerLight.d.ts +66 -65
- package/dist/lib-cjs/api/classes/viewerLight.js +389 -322
- package/dist/lib-cjs/api/classes/viewerLight.js.map +1 -1
- package/dist/lib-cjs/api/internal/debugViewer.d.ts +13 -13
- package/dist/lib-cjs/api/internal/debugViewer.js +87 -87
- 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 +10 -6
- package/dist/lib-cjs/api/internal/sceneSetup.js +231 -227
- 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 +121 -121
- package/dist/lib-cjs/api/manager/sceneManager.d.ts +32 -32
- package/dist/lib-cjs/api/manager/sceneManager.js +132 -132
- package/dist/lib-cjs/api/manager/variantInstanceManager.d.ts +90 -90
- package/dist/lib-cjs/api/manager/variantInstanceManager.js +321 -321
- 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 +175 -125
- package/dist/lib-cjs/api/util/babylonHelper.js +520 -368
- package/dist/lib-cjs/api/util/babylonHelper.js.map +1 -1
- package/dist/lib-cjs/api/util/globalTypes.d.ts +333 -279
- package/dist/lib-cjs/api/util/globalTypes.js +1 -1
- package/dist/lib-cjs/api/util/resourceHelper.d.ts +53 -51
- package/dist/lib-cjs/api/util/resourceHelper.js +240 -243
- 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/buildinfo.json +3 -3
- package/dist/lib-cjs/index.d.ts +48 -46
- package/dist/lib-cjs/index.js +86 -82
- package/dist/lib-cjs/index.js.map +1 -1
- package/package.json +83 -83
- package/src/api/classes/animationInterface.ts +11 -11
- package/src/api/classes/dottedPath.ts +189 -189
- package/src/api/classes/element.ts +644 -617
- package/src/api/classes/event.ts +370 -355
- package/src/api/classes/eventBroadcaster.ts +54 -54
- package/src/api/classes/parameter.ts +408 -277
- package/src/api/classes/parameterObservable.ts +99 -121
- package/src/api/classes/{elementParameterizable.ts → parameterizable.ts} +89 -78
- package/src/api/classes/placementAnimation.ts +143 -133
- package/src/api/classes/variant.ts +817 -670
- package/src/api/classes/variantInstance.ts +88 -81
- package/src/api/classes/variantParameterizable.ts +73 -0
- package/src/api/classes/viewer.ts +478 -421
- package/src/api/classes/viewerLight.ts +330 -0
- package/src/api/internal/debugViewer.ts +81 -81
- package/src/api/internal/lensRendering.ts +10 -10
- package/src/api/internal/sceneSetup.ts +194 -204
- package/src/api/manager/animationManager.ts +116 -116
- package/src/api/manager/sceneManager.ts +105 -105
- package/src/api/manager/variantInstanceManager.ts +236 -236
- package/src/api/store/specStorage.ts +53 -53
- package/src/api/util/babylonHelper.ts +553 -392
- package/src/api/util/globalTypes.ts +380 -319
- package/src/api/util/resourceHelper.ts +184 -187
- package/src/api/util/stringHelper.ts +26 -0
- package/src/buildinfo.json +2 -2
- package/src/commonjs.tsconfig.json +13 -13
- package/src/declaration.tsconfig.json +10 -10
- package/src/dev.ts +42 -46
- package/src/es6.tsconfig.json +13 -13
- package/src/index.ts +91 -87
- package/src/pagesconfig.json +61 -57
- package/src/tsconfig.json +43 -43
- package/src/tsconfig.types.json +9 -9
- package/src/types.d.ts +4 -4
- package/dist/webpack-stats.json +0 -0
|
@@ -1,204 +1,194 @@
|
|
|
1
|
-
|
|
2
|
-
import { Engine } from '@babylonjs/core/Engines/engine';
|
|
3
|
-
import '@babylonjs/core/
|
|
4
|
-
import '@babylonjs/core/
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
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
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
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
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
//
|
|
130
|
-
//
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
if( sceneJson.scene.globals.aa ) {
|
|
138
|
-
defaultPipeline.fxaaEnabled = true; //implicitly does FxaaPostProcess()
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
defaultPipeline.
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
if( sceneJson.scene.globals['camera-settings'].
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
//
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
*/
|
|
196
|
-
|
|
197
|
-
// TODO: shadows don't work with HemishpericLight
|
|
198
|
-
|
|
199
|
-
return scene;
|
|
200
|
-
};
|
|
201
|
-
|
|
202
|
-
export {
|
|
203
|
-
sceneSetup
|
|
204
|
-
}
|
|
1
|
+
import { Camera } from '@babylonjs/core/Cameras/camera';
|
|
2
|
+
import { Engine } from '@babylonjs/core/Engines/engine';
|
|
3
|
+
import '@babylonjs/core/Helpers/sceneHelpers';
|
|
4
|
+
import '@babylonjs/core/Materials/Textures/Loaders/ddsTextureLoader';
|
|
5
|
+
import { Color4 } from '@babylonjs/core/Maths/math.color';
|
|
6
|
+
import { Vector3 } from '@babylonjs/core/Maths/math.vector';
|
|
7
|
+
import { GroundMesh } from '@babylonjs/core/Meshes/groundMesh';
|
|
8
|
+
import { MeshBuilder } from '@babylonjs/core/Meshes/meshBuilder';
|
|
9
|
+
import { DefaultRenderingPipeline } from '@babylonjs/core/PostProcesses/RenderPipeline/Pipelines/defaultRenderingPipeline';
|
|
10
|
+
import { Scene } from '@babylonjs/core/scene';
|
|
11
|
+
import { get, isEmpty, set } from 'lodash-es';
|
|
12
|
+
import { Parameter } from '../classes/parameter';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* @param scene
|
|
16
|
+
* @param name
|
|
17
|
+
* @param definition
|
|
18
|
+
*/
|
|
19
|
+
const processGround = async function( scene: Scene, name: string, definition: GroundDefinition ): Promise<Mesh | GroundMesh> {
|
|
20
|
+
return new Promise( resolve => {
|
|
21
|
+
const _resolve = ( ground: Mesh ) => {
|
|
22
|
+
if( definition.receiveShadows !== undefined ) {
|
|
23
|
+
ground.receiveShadows = definition.receiveShadows;
|
|
24
|
+
}
|
|
25
|
+
resolve( ground );
|
|
26
|
+
};
|
|
27
|
+
switch( definition.type ) {
|
|
28
|
+
case 'baked':
|
|
29
|
+
if( !definition.meshId ) {
|
|
30
|
+
throw new Error( `A baked ground must define a "meshId".` );
|
|
31
|
+
}
|
|
32
|
+
_resolve( scene.getMeshByID( definition.meshId ) as Mesh );
|
|
33
|
+
break;
|
|
34
|
+
case 'ground':
|
|
35
|
+
_resolve( MeshBuilder.CreateGround(
|
|
36
|
+
name,
|
|
37
|
+
definition,
|
|
38
|
+
scene
|
|
39
|
+
) );
|
|
40
|
+
break;
|
|
41
|
+
case 'heightmap':
|
|
42
|
+
if( !definition.url ) {
|
|
43
|
+
throw new Error( `A heightmap ground must define an "url".` );
|
|
44
|
+
}
|
|
45
|
+
definition.onReady = ( _ground: GroundMesh ) => {
|
|
46
|
+
_resolve( _ground );
|
|
47
|
+
};
|
|
48
|
+
MeshBuilder.CreateGroundFromHeightMap(
|
|
49
|
+
name,
|
|
50
|
+
definition.url,
|
|
51
|
+
definition,
|
|
52
|
+
scene,
|
|
53
|
+
);
|
|
54
|
+
break;
|
|
55
|
+
default:
|
|
56
|
+
throw new Error( `Ground of type "${definition.type}" not implemented (yet).` );
|
|
57
|
+
}
|
|
58
|
+
} );
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* @param scene
|
|
63
|
+
*/
|
|
64
|
+
const defaultCamera = async function( scene: Scene ): Promise<Camera> {
|
|
65
|
+
return await processCamera( scene, 'default_camera', {
|
|
66
|
+
type: 'arc',
|
|
67
|
+
active: true,
|
|
68
|
+
} );
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* @param scene
|
|
73
|
+
* @param name
|
|
74
|
+
* @param cameraSetup
|
|
75
|
+
*/
|
|
76
|
+
const processCamera = async function( scene: Scene, name: string, cameraSetup: CameraDefinition ): Promise<Camera> {
|
|
77
|
+
let camera: Camera;
|
|
78
|
+
let target = Vector3.Zero();
|
|
79
|
+
if( cameraSetup.target ) {
|
|
80
|
+
target = Parameter.parseVector( cameraSetup.target );
|
|
81
|
+
}
|
|
82
|
+
switch( cameraSetup.type ) {
|
|
83
|
+
case 'arc':
|
|
84
|
+
// @ts-ignore
|
|
85
|
+
const arcCameraModule = await import(/* webpackChunkName: "arc-rotate-camera" */ '@babylonjs/core/Cameras/arcRotateCamera');
|
|
86
|
+
camera = new arcCameraModule.ArcRotateCamera( name, Math.PI / 4, Math.PI / 4, 2, target, scene );
|
|
87
|
+
camera.metadata = {
|
|
88
|
+
alpha: Math.PI / 4,
|
|
89
|
+
beta: Math.PI / 4,
|
|
90
|
+
radius: 2
|
|
91
|
+
};
|
|
92
|
+
break;
|
|
93
|
+
}
|
|
94
|
+
if( cameraSetup.active ) {
|
|
95
|
+
camera.attachControl( scene.getEngine().getRenderingCanvas()!, true );
|
|
96
|
+
}
|
|
97
|
+
if( cameraSetup.fov ) {
|
|
98
|
+
camera.fov = cameraSetup.fov;
|
|
99
|
+
}
|
|
100
|
+
camera.storeState();
|
|
101
|
+
return camera;
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* @param engine
|
|
106
|
+
* @param sceneJson
|
|
107
|
+
*/
|
|
108
|
+
const sceneSetup = async function(engine: Engine, sceneJson: SceneJson): Promise<Scene> {
|
|
109
|
+
const scene = new Scene( engine );
|
|
110
|
+
scene.clearColor = new Color4(0, 0, 0, 0);
|
|
111
|
+
// cameras
|
|
112
|
+
const cameras: Camera[] = [];
|
|
113
|
+
const cameraDefinitions = get( sceneJson.scene, 'cameras' ) as CameraDefinitions;
|
|
114
|
+
if( !isEmpty( cameraDefinitions ) ) {
|
|
115
|
+
for( let cameraName in cameraDefinitions ) {
|
|
116
|
+
cameras.push( await processCamera( scene, cameraName, cameraDefinitions[cameraName] ) );
|
|
117
|
+
}
|
|
118
|
+
} else {
|
|
119
|
+
const camera = await defaultCamera( scene );
|
|
120
|
+
cameras.push( camera );
|
|
121
|
+
}
|
|
122
|
+
// grounds
|
|
123
|
+
const groundDefinitions = get( sceneJson.scene, 'grounds' ) as GroundDefinitions;
|
|
124
|
+
if( !isEmpty( groundDefinitions ) ) {
|
|
125
|
+
for( const groundName in groundDefinitions ) {
|
|
126
|
+
await processGround( scene, groundName, groundDefinitions[groundName] );
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
// TODO: try to split this away from the default rendering pipeline to save module imports
|
|
130
|
+
// The "hdr" setting had negative effect on rendering in Safari. Everything looked a little "edgy". I'm not completely
|
|
131
|
+
// sure if disabling it comes with other negative side effects I don't see right now, so we should probably
|
|
132
|
+
// investigate this a little more in detail at some point.
|
|
133
|
+
const defaultPipeline = new DefaultRenderingPipeline( 'default-rendering-pipeline', false, scene );
|
|
134
|
+
/* DISABLED: causes problems with Internet Explorer
|
|
135
|
+
defaultPipeline.imageProcessingEnabled = true;
|
|
136
|
+
*/
|
|
137
|
+
if( sceneJson.scene.globals.aa ) {
|
|
138
|
+
defaultPipeline.fxaaEnabled = true; //implicitly does FxaaPostProcess()
|
|
139
|
+
}
|
|
140
|
+
// Set samples regardless of fxaa setting since we don't want to use fxaa but still increase the sample count
|
|
141
|
+
defaultPipeline.samples = 8;
|
|
142
|
+
if( sceneJson.scene.globals['camera-settings'] ) {
|
|
143
|
+
if( sceneJson.scene.globals['camera-settings']!.sharpen && sceneJson.scene.globals['camera-settings']!.sharpen.enabled ) {
|
|
144
|
+
defaultPipeline.sharpenEnabled = true; //implicitly does SharpenPostProcess()
|
|
145
|
+
//defaultPipeline.sharpen.colorAmount = 1;
|
|
146
|
+
//defaultPipeline.sharpen.edgeAmount = 0;
|
|
147
|
+
}
|
|
148
|
+
if( sceneJson.scene.globals['camera-settings']!.bloom && sceneJson.scene.globals['camera-settings']!.bloom.enabled ) {
|
|
149
|
+
defaultPipeline.bloomEnabled = true;
|
|
150
|
+
if( sceneJson.scene.globals['camera-settings']!.bloom.size ) {
|
|
151
|
+
defaultPipeline.bloomScale = sceneJson.scene.globals['camera-settings']!.bloom.size;
|
|
152
|
+
}
|
|
153
|
+
if( sceneJson.scene.globals['camera-settings']!.bloom.threshold ) {
|
|
154
|
+
defaultPipeline.bloomThreshold = sceneJson.scene.globals['camera-settings']!.bloom.threshold;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
if( sceneJson.scene.globals['camera-settings']!.contrast ) {
|
|
158
|
+
scene.imageProcessingConfiguration.contrast = sceneJson.scene.globals['camera-settings']!.contrast;
|
|
159
|
+
}
|
|
160
|
+
if( sceneJson.scene.globals['camera-settings']!.exposure ) {
|
|
161
|
+
scene.imageProcessingConfiguration.exposure = sceneJson.scene.globals['camera-settings']!.exposure;
|
|
162
|
+
}
|
|
163
|
+
if( sceneJson.scene.globals['camera-settings']!.dof && sceneJson.scene.globals['camera-settings']!.dof.enabled ) {
|
|
164
|
+
//@ts-ignore
|
|
165
|
+
const module = await import(/* webpackChunkName: "lens-rendering" */ './lensRendering');
|
|
166
|
+
new module.LensRenderingPipeline( 'lens-rendering', sceneJson.scene.globals['camera-settings']!.dof.settings, scene, 1.0, cameras );
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
// TODO: make this dynamic
|
|
170
|
+
/*
|
|
171
|
+
const texture = new HDRCubeTexture("/assets/small_cave_1k.hdr", scene, 256);
|
|
172
|
+
texture.gammaSpace = false;
|
|
173
|
+
scene.environmentTexture = texture;
|
|
174
|
+
// scene.environmentTexture.
|
|
175
|
+
|
|
176
|
+
const skyboxMaterial = new StandardMaterial("skyBox", scene);
|
|
177
|
+
skyboxMaterial.backFaceCulling = false;
|
|
178
|
+
skyboxMaterial.reflectionTexture = texture;
|
|
179
|
+
skyboxMaterial.reflectionTexture.coordinatesMode = Texture.SKYBOX_MODE;
|
|
180
|
+
skyboxMaterial.disableLighting = false;
|
|
181
|
+
// TODO: replace with BoxBuilder
|
|
182
|
+
const skybox = MeshBuilder.CreateBox("skyBox", {size: 1000.0}, scene);
|
|
183
|
+
skybox.isPickable = false; //never pick a skybox
|
|
184
|
+
skybox.infiniteDistance = true;
|
|
185
|
+
skybox.material = skyboxMaterial;
|
|
186
|
+
*/
|
|
187
|
+
|
|
188
|
+
// TODO: shadows don't work with HemishpericLight
|
|
189
|
+
return scene;
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
export {
|
|
193
|
+
sceneSetup
|
|
194
|
+
};
|
|
@@ -1,117 +1,117 @@
|
|
|
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
|
-
|
|
13
|
-
export class AnimationManager {
|
|
14
|
-
|
|
15
|
-
public animations: AnimationInterface[] = [];
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Constructor.
|
|
19
|
-
*/
|
|
20
|
-
protected constructor( protected scene: Scene ) {
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Creates an {@link AnimationManager} based on given BabylonJS scene.
|
|
25
|
-
*/
|
|
26
|
-
public static async create( scene: BabylonScene ): Promise<AnimationManager> {
|
|
27
|
-
return new AnimationManager( scene );
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* @deprecated Use viewer.moveCameraTo().
|
|
32
|
-
*/
|
|
33
|
-
public resetCamera(animate: boolean = false) {
|
|
34
|
-
//TODO currently only works for arcrotate. are there any other cameras?
|
|
35
|
-
let activeCamera = this.scene.activeCamera as Nullable<ArcRotateCamera>;
|
|
36
|
-
if( ! activeCamera ) {
|
|
37
|
-
throw new Error( 'There is no active camera' );
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
const initAlpha = activeCamera.metadata.alpha;
|
|
41
|
-
const initBeta = activeCamera.metadata.beta;
|
|
42
|
-
const initRadius = activeCamera.metadata.radius;
|
|
43
|
-
|
|
44
|
-
if( animate ) {
|
|
45
|
-
this.animateArcRotateCamera(initAlpha, initBeta, initRadius);
|
|
46
|
-
} else {
|
|
47
|
-
activeCamera.alpha = initAlpha;
|
|
48
|
-
activeCamera.beta = initBeta;
|
|
49
|
-
activeCamera.radius = initRadius;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* @deprecated Use viewer.moveCameraTo().
|
|
55
|
-
*/
|
|
56
|
-
public animateArcRotateCamera(targetAlpha: number, targetBeta: number, targetRadius: number) {
|
|
57
|
-
let activeCamera = this.scene.activeCamera as Nullable<ArcRotateCamera>;
|
|
58
|
-
if( ! activeCamera ) {
|
|
59
|
-
throw new Error( 'There is no active camera' );
|
|
60
|
-
}
|
|
61
|
-
const alphaAnimation = new BabylonAnimation( 'alphaAnimation', 'alpha', 30, BabylonAnimation.ANIMATIONTYPE_FLOAT, BabylonAnimation.ANIMATIONLOOPMODE_CONSTANT );
|
|
62
|
-
const betaAnimation = new BabylonAnimation( 'betaAnimation', 'beta', 30, BabylonAnimation.ANIMATIONTYPE_FLOAT, BabylonAnimation.ANIMATIONLOOPMODE_CONSTANT );
|
|
63
|
-
const radiusAnimation = new BabylonAnimation( 'radiusAnimation', 'radius', 30, BabylonAnimation.ANIMATIONTYPE_FLOAT, BabylonAnimation.ANIMATIONLOOPMODE_CONSTANT );
|
|
64
|
-
alphaAnimation.setKeys([{
|
|
65
|
-
frame : 0,
|
|
66
|
-
value : activeCamera.alpha
|
|
67
|
-
}, {
|
|
68
|
-
frame : 100,
|
|
69
|
-
value : targetAlpha
|
|
70
|
-
}]);
|
|
71
|
-
betaAnimation.setKeys([{
|
|
72
|
-
frame : 0,
|
|
73
|
-
value : activeCamera.beta
|
|
74
|
-
}, {
|
|
75
|
-
frame : 100,
|
|
76
|
-
value : targetBeta
|
|
77
|
-
}]);
|
|
78
|
-
radiusAnimation.setKeys( [{
|
|
79
|
-
frame : 0,
|
|
80
|
-
value : activeCamera.radius
|
|
81
|
-
}, {
|
|
82
|
-
frame : 100,
|
|
83
|
-
value : targetRadius
|
|
84
|
-
}]);
|
|
85
|
-
activeCamera.animations.push(alphaAnimation);
|
|
86
|
-
activeCamera.animations.push(betaAnimation);
|
|
87
|
-
activeCamera.animations.push(radiusAnimation);
|
|
88
|
-
|
|
89
|
-
let animation = this.scene.beginAnimation(activeCamera, 0, 100, false, 10);
|
|
90
|
-
animation.disposeOnEnd = true;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
* Stops and kills all running animations.
|
|
95
|
-
*/
|
|
96
|
-
public killAllAnimations() {
|
|
97
|
-
this.animations.forEach( animation => animation.kill() );
|
|
98
|
-
this.animations = [];
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
* @see {@link PlacementAnimation.play}
|
|
103
|
-
*/
|
|
104
|
-
public async animateToPlacement( mutable: object,
|
|
105
|
-
placement: PlacementDefinition | string,
|
|
106
|
-
animation?: AnimationDefinition | string ): Promise<AnimationInterface> {
|
|
107
|
-
const _animation = new PlacementAnimation( mutable, placement, animation );
|
|
108
|
-
this.animations.push( _animation );
|
|
109
|
-
const animationPromise = _animation.play();
|
|
110
|
-
animationPromise.then( a => {
|
|
111
|
-
remove( this.animations, _a => _a === a );
|
|
112
|
-
a.kill();
|
|
113
|
-
} );
|
|
114
|
-
return await animationPromise;
|
|
115
|
-
}
|
|
116
|
-
|
|
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
|
+
|
|
13
|
+
export class AnimationManager {
|
|
14
|
+
|
|
15
|
+
public animations: AnimationInterface[] = [];
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Constructor.
|
|
19
|
+
*/
|
|
20
|
+
protected constructor( protected scene: Scene ) {
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Creates an {@link AnimationManager} based on given BabylonJS scene.
|
|
25
|
+
*/
|
|
26
|
+
public static async create( scene: BabylonScene ): Promise<AnimationManager> {
|
|
27
|
+
return new AnimationManager( scene );
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* @deprecated Use viewer.moveCameraTo().
|
|
32
|
+
*/
|
|
33
|
+
public resetCamera(animate: boolean = false) {
|
|
34
|
+
//TODO currently only works for arcrotate. are there any other cameras?
|
|
35
|
+
let activeCamera = this.scene.activeCamera as Nullable<ArcRotateCamera>;
|
|
36
|
+
if( ! activeCamera ) {
|
|
37
|
+
throw new Error( 'There is no active camera' );
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const initAlpha = activeCamera.metadata.alpha;
|
|
41
|
+
const initBeta = activeCamera.metadata.beta;
|
|
42
|
+
const initRadius = activeCamera.metadata.radius;
|
|
43
|
+
|
|
44
|
+
if( animate ) {
|
|
45
|
+
this.animateArcRotateCamera(initAlpha, initBeta, initRadius);
|
|
46
|
+
} else {
|
|
47
|
+
activeCamera.alpha = initAlpha;
|
|
48
|
+
activeCamera.beta = initBeta;
|
|
49
|
+
activeCamera.radius = initRadius;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* @deprecated Use viewer.moveCameraTo().
|
|
55
|
+
*/
|
|
56
|
+
public animateArcRotateCamera(targetAlpha: number, targetBeta: number, targetRadius: number) {
|
|
57
|
+
let activeCamera = this.scene.activeCamera as Nullable<ArcRotateCamera>;
|
|
58
|
+
if( ! activeCamera ) {
|
|
59
|
+
throw new Error( 'There is no active camera' );
|
|
60
|
+
}
|
|
61
|
+
const alphaAnimation = new BabylonAnimation( 'alphaAnimation', 'alpha', 30, BabylonAnimation.ANIMATIONTYPE_FLOAT, BabylonAnimation.ANIMATIONLOOPMODE_CONSTANT );
|
|
62
|
+
const betaAnimation = new BabylonAnimation( 'betaAnimation', 'beta', 30, BabylonAnimation.ANIMATIONTYPE_FLOAT, BabylonAnimation.ANIMATIONLOOPMODE_CONSTANT );
|
|
63
|
+
const radiusAnimation = new BabylonAnimation( 'radiusAnimation', 'radius', 30, BabylonAnimation.ANIMATIONTYPE_FLOAT, BabylonAnimation.ANIMATIONLOOPMODE_CONSTANT );
|
|
64
|
+
alphaAnimation.setKeys([{
|
|
65
|
+
frame : 0,
|
|
66
|
+
value : activeCamera.alpha
|
|
67
|
+
}, {
|
|
68
|
+
frame : 100,
|
|
69
|
+
value : targetAlpha
|
|
70
|
+
}]);
|
|
71
|
+
betaAnimation.setKeys([{
|
|
72
|
+
frame : 0,
|
|
73
|
+
value : activeCamera.beta
|
|
74
|
+
}, {
|
|
75
|
+
frame : 100,
|
|
76
|
+
value : targetBeta
|
|
77
|
+
}]);
|
|
78
|
+
radiusAnimation.setKeys( [{
|
|
79
|
+
frame : 0,
|
|
80
|
+
value : activeCamera.radius
|
|
81
|
+
}, {
|
|
82
|
+
frame : 100,
|
|
83
|
+
value : targetRadius
|
|
84
|
+
}]);
|
|
85
|
+
activeCamera.animations.push(alphaAnimation);
|
|
86
|
+
activeCamera.animations.push(betaAnimation);
|
|
87
|
+
activeCamera.animations.push(radiusAnimation);
|
|
88
|
+
|
|
89
|
+
let animation = this.scene.beginAnimation(activeCamera, 0, 100, false, 10);
|
|
90
|
+
animation.disposeOnEnd = true;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Stops and kills all running animations.
|
|
95
|
+
*/
|
|
96
|
+
public killAllAnimations() {
|
|
97
|
+
this.animations.forEach( animation => animation.kill() );
|
|
98
|
+
this.animations = [];
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* @see {@link PlacementAnimation.play}
|
|
103
|
+
*/
|
|
104
|
+
public async animateToPlacement( mutable: object,
|
|
105
|
+
placement: PlacementDefinition | string,
|
|
106
|
+
animation?: AnimationDefinition | string ): Promise<AnimationInterface> {
|
|
107
|
+
const _animation = new PlacementAnimation( mutable, placement, animation );
|
|
108
|
+
this.animations.push( _animation );
|
|
109
|
+
const animationPromise = _animation.play();
|
|
110
|
+
animationPromise.then( a => {
|
|
111
|
+
remove( this.animations, _a => _a === a );
|
|
112
|
+
a.kill();
|
|
113
|
+
} );
|
|
114
|
+
return await animationPromise;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
117
|
}
|