@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.
Files changed (106) hide show
  1. package/README.md +114 -112
  2. package/dist/lib-cjs/api/classes/animationInterface.d.ts +8 -8
  3. package/dist/lib-cjs/api/classes/animationInterface.js +1 -1
  4. package/dist/lib-cjs/api/classes/dottedPath.d.ts +79 -79
  5. package/dist/lib-cjs/api/classes/dottedPath.js +190 -190
  6. package/dist/lib-cjs/api/classes/element.d.ts +130 -125
  7. package/dist/lib-cjs/api/classes/element.js +743 -682
  8. package/dist/lib-cjs/api/classes/element.js.map +1 -1
  9. package/dist/lib-cjs/api/classes/elementParameterizable.d.ts +14 -14
  10. package/dist/lib-cjs/api/classes/elementParameterizable.js +134 -134
  11. package/dist/lib-cjs/api/classes/event.d.ts +326 -312
  12. package/dist/lib-cjs/api/classes/event.js +371 -357
  13. package/dist/lib-cjs/api/classes/event.js.map +1 -1
  14. package/dist/lib-cjs/api/classes/eventBroadcaster.d.ts +26 -26
  15. package/dist/lib-cjs/api/classes/eventBroadcaster.js +53 -53
  16. package/dist/lib-cjs/api/classes/parameter.d.ts +259 -165
  17. package/dist/lib-cjs/api/classes/parameter.js +387 -267
  18. package/dist/lib-cjs/api/classes/parameter.js.map +1 -1
  19. package/dist/lib-cjs/api/classes/parameterObservable.d.ts +36 -36
  20. package/dist/lib-cjs/api/classes/parameterObservable.js +101 -126
  21. package/dist/lib-cjs/api/classes/parameterObservable.js.map +1 -1
  22. package/dist/lib-cjs/api/classes/parameterizable.d.ts +15 -15
  23. package/dist/lib-cjs/api/classes/parameterizable.js +149 -149
  24. package/dist/lib-cjs/api/classes/placementAnimation.d.ts +38 -38
  25. package/dist/lib-cjs/api/classes/placementAnimation.js +149 -138
  26. package/dist/lib-cjs/api/classes/placementAnimation.js.map +1 -1
  27. package/dist/lib-cjs/api/classes/variant.d.ts +234 -190
  28. package/dist/lib-cjs/api/classes/variant.js +1147 -873
  29. package/dist/lib-cjs/api/classes/variant.js.map +1 -1
  30. package/dist/lib-cjs/api/classes/variantInstance.d.ts +45 -41
  31. package/dist/lib-cjs/api/classes/variantInstance.js +108 -98
  32. package/dist/lib-cjs/api/classes/variantInstance.js.map +1 -1
  33. package/dist/lib-cjs/api/classes/variantParameterizable.d.ts +17 -17
  34. package/dist/lib-cjs/api/classes/variantParameterizable.js +92 -92
  35. package/dist/lib-cjs/api/classes/viewer.d.ts +131 -128
  36. package/dist/lib-cjs/api/classes/viewer.js +560 -486
  37. package/dist/lib-cjs/api/classes/viewer.js.map +1 -1
  38. package/dist/lib-cjs/api/classes/viewerLight.d.ts +66 -65
  39. package/dist/lib-cjs/api/classes/viewerLight.js +389 -322
  40. package/dist/lib-cjs/api/classes/viewerLight.js.map +1 -1
  41. package/dist/lib-cjs/api/internal/debugViewer.d.ts +13 -13
  42. package/dist/lib-cjs/api/internal/debugViewer.js +87 -87
  43. package/dist/lib-cjs/api/internal/lensRendering.d.ts +8 -8
  44. package/dist/lib-cjs/api/internal/lensRendering.js +11 -11
  45. package/dist/lib-cjs/api/internal/sceneSetup.d.ts +10 -6
  46. package/dist/lib-cjs/api/internal/sceneSetup.js +231 -227
  47. package/dist/lib-cjs/api/internal/sceneSetup.js.map +1 -1
  48. package/dist/lib-cjs/api/manager/animationManager.d.ts +29 -29
  49. package/dist/lib-cjs/api/manager/animationManager.js +121 -121
  50. package/dist/lib-cjs/api/manager/sceneManager.d.ts +32 -32
  51. package/dist/lib-cjs/api/manager/sceneManager.js +132 -132
  52. package/dist/lib-cjs/api/manager/variantInstanceManager.d.ts +90 -90
  53. package/dist/lib-cjs/api/manager/variantInstanceManager.js +321 -321
  54. package/dist/lib-cjs/api/store/specStorage.d.ts +24 -24
  55. package/dist/lib-cjs/api/store/specStorage.js +51 -51
  56. package/dist/lib-cjs/api/util/babylonHelper.d.ts +175 -125
  57. package/dist/lib-cjs/api/util/babylonHelper.js +520 -368
  58. package/dist/lib-cjs/api/util/babylonHelper.js.map +1 -1
  59. package/dist/lib-cjs/api/util/globalTypes.d.ts +333 -279
  60. package/dist/lib-cjs/api/util/globalTypes.js +1 -1
  61. package/dist/lib-cjs/api/util/resourceHelper.d.ts +53 -51
  62. package/dist/lib-cjs/api/util/resourceHelper.js +240 -243
  63. package/dist/lib-cjs/api/util/resourceHelper.js.map +1 -1
  64. package/dist/lib-cjs/api/util/stringHelper.d.ts +9 -9
  65. package/dist/lib-cjs/api/util/stringHelper.js +25 -25
  66. package/dist/lib-cjs/buildinfo.json +3 -3
  67. package/dist/lib-cjs/index.d.ts +48 -46
  68. package/dist/lib-cjs/index.js +86 -82
  69. package/dist/lib-cjs/index.js.map +1 -1
  70. package/package.json +83 -83
  71. package/src/api/classes/animationInterface.ts +11 -11
  72. package/src/api/classes/dottedPath.ts +189 -189
  73. package/src/api/classes/element.ts +644 -617
  74. package/src/api/classes/event.ts +370 -355
  75. package/src/api/classes/eventBroadcaster.ts +54 -54
  76. package/src/api/classes/parameter.ts +408 -277
  77. package/src/api/classes/parameterObservable.ts +99 -121
  78. package/src/api/classes/{elementParameterizable.ts → parameterizable.ts} +89 -78
  79. package/src/api/classes/placementAnimation.ts +143 -133
  80. package/src/api/classes/variant.ts +817 -670
  81. package/src/api/classes/variantInstance.ts +88 -81
  82. package/src/api/classes/variantParameterizable.ts +73 -0
  83. package/src/api/classes/viewer.ts +478 -421
  84. package/src/api/classes/viewerLight.ts +330 -0
  85. package/src/api/internal/debugViewer.ts +81 -81
  86. package/src/api/internal/lensRendering.ts +10 -10
  87. package/src/api/internal/sceneSetup.ts +194 -204
  88. package/src/api/manager/animationManager.ts +116 -116
  89. package/src/api/manager/sceneManager.ts +105 -105
  90. package/src/api/manager/variantInstanceManager.ts +236 -236
  91. package/src/api/store/specStorage.ts +53 -53
  92. package/src/api/util/babylonHelper.ts +553 -392
  93. package/src/api/util/globalTypes.ts +380 -319
  94. package/src/api/util/resourceHelper.ts +184 -187
  95. package/src/api/util/stringHelper.ts +26 -0
  96. package/src/buildinfo.json +2 -2
  97. package/src/commonjs.tsconfig.json +13 -13
  98. package/src/declaration.tsconfig.json +10 -10
  99. package/src/dev.ts +42 -46
  100. package/src/es6.tsconfig.json +13 -13
  101. package/src/index.ts +91 -87
  102. package/src/pagesconfig.json +61 -57
  103. package/src/tsconfig.json +43 -43
  104. package/src/tsconfig.types.json +9 -9
  105. package/src/types.d.ts +4 -4
  106. package/dist/webpack-stats.json +0 -0
@@ -1,204 +1,194 @@
1
-
2
- import { Engine } from '@babylonjs/core/Engines/engine';
3
- import '@babylonjs/core/Materials/Textures/Loaders/ddsTextureLoader';
4
- import '@babylonjs/core/Helpers/sceneHelpers';
5
- import { StandardMaterial } from '@babylonjs/core/Materials/standardMaterial';
6
- import { HDRCubeTexture } from '@babylonjs/core/Materials/Textures/hdrCubeTexture';
7
- import { Texture } from '@babylonjs/core/Materials/Textures/texture';
8
- import { Color3, Color4 } from '@babylonjs/core/Maths/math.color';
9
- import { Vector3 } from '@babylonjs/core/Maths/math.vector';
10
- import { MeshBuilder } from '@babylonjs/core/Meshes/meshBuilder';
11
- import { DefaultRenderingPipeline } from '@babylonjs/core/PostProcesses/RenderPipeline/Pipelines/defaultRenderingPipeline';
12
- import { Scene } from '@babylonjs/core/scene';
13
- import type { HemisphericLight } from '@babylonjs/core/Lights/hemisphericLight';
14
- import { Camera } from '@babylonjs/core/Cameras/camera';
15
- import { Light } from '@babylonjs/core/Lights/light';
16
- import { Parameter } from '../classes/parameter';
17
-
18
-
19
- const defaultLightning = async function(scene: Scene) {
20
- const defaultSetup: LightDefinition = {
21
- type: 'hemispheric',
22
- };
23
-
24
- const defaultLight = await processLight(scene, 'default_light', defaultSetup) as HemisphericLight;
25
- defaultLight.groundColor = Color3.Black();
26
- defaultLight.diffuse = Color3.White();
27
-
28
- return defaultLight;
29
- };
30
-
31
-
32
- const processLight = async function(scene: Scene, name: string, lightSetup: LightDefinition) {
33
-
34
- let light: Light;
35
-
36
- switch(lightSetup.type ) {
37
- case 'hemispheric':
38
- // @ts-ignore
39
- const hemisphericLightModule = await import(/* webpackChunkName: "hemispheric-light" */ '@babylonjs/core/Lights/hemisphericLight');
40
- light = new hemisphericLightModule.HemisphericLight( name, Vector3.Up(), scene);
41
- break;
42
- case 'point':
43
- // @ts-ignore
44
- const pointLightModule = await import(/* webpackChunkName: "point-light" */ '@babylonjs/core/Lights/pointLight');
45
- light = new pointLightModule.PointLight( name, Vector3.Up(), scene);
46
- break;
47
- }
48
-
49
- return light;
50
- };
51
-
52
-
53
- const defaultCamera = async function(scene: Scene) {
54
-
55
- const cameraSetup: CameraDefinition = {
56
- type: 'arc',
57
- active: true,
58
- };
59
-
60
- const defaultCamera = await processCamera(scene, 'default_camera', cameraSetup);
61
-
62
- return defaultCamera;
63
- };
64
-
65
- const processCamera = async function(scene: Scene, name: string, cameraSetup: CameraDefinition) {
66
-
67
- let camera: Camera;
68
-
69
- let target = Vector3.Zero();
70
- if(cameraSetup.target) {
71
- target = Parameter.parseVector(cameraSetup.target);
72
- }
73
-
74
- switch(cameraSetup.type ) {
75
- case 'arc':
76
- // @ts-ignore
77
- const arcCameraModule = await import(/* webpackChunkName: "arc-rotate-camera" */ '@babylonjs/core/Cameras/arcRotateCamera');
78
- camera = new arcCameraModule.ArcRotateCamera(name, Math.PI / 4, Math.PI / 4, 2, target, scene );
79
- camera.metadata = {
80
- alpha: Math.PI / 4,
81
- beta: Math.PI / 4,
82
- radius: 2
83
- };
84
- break;
85
-
86
- }
87
-
88
- if(cameraSetup.active) {
89
- camera.attachControl( scene.getEngine().getRenderingCanvas()!, true );
90
- }
91
-
92
- if( cameraSetup.fov ) {
93
- camera.fov = cameraSetup.fov;
94
- }
95
-
96
- camera.storeState();
97
- return camera;
98
- };
99
-
100
- const sceneSetup = async function(engine: Engine, sceneJson: SceneJson) {
101
- const scene = new Scene( engine );
102
- scene.clearColor = new Color4(0, 0, 0, 0);
103
-
104
- let cameras: Camera[] = [];
105
- //there is either no "cameras" or "cameras" is empty
106
- if( ! sceneJson.scene.hasOwnProperty('cameras') || (sceneJson.scene.cameras && ! Object.keys(sceneJson.scene.cameras).length ) ) {
107
- const camera = await defaultCamera(scene);
108
-
109
- cameras.push(camera);
110
- } else {
111
- for(let camera in sceneJson.scene.cameras) {
112
- cameras.push(await processCamera(scene, camera, sceneJson.scene.cameras[camera]));
113
- }
114
- }
115
-
116
-
117
- //there is either no "lights" or "lights" is empty
118
- if( ! sceneJson.scene.hasOwnProperty('lights') || (sceneJson.scene.lights && ! Object.keys(sceneJson.scene.lights).length ) ) {
119
- // await defaultLightning(scene);
120
- } else {
121
- for(let light in sceneJson.scene.lights) {
122
- await processLight(scene, light, sceneJson.scene.lights[light]);
123
- }
124
- }
125
-
126
-
127
- // TODO: try to split this away from the default rendering pipeline to save module imports
128
- // The "hdr" setting had negative effect on rendering in Safari. Everything looked a little "edgy". I'm not completely
129
- // sure if disabling it comes with other negative side effects I don't see right now, so we should probably
130
- // investigate this a little more in detail at some point.
131
- const defaultPipeline = new DefaultRenderingPipeline( 'default-rendering-pipeline', false, scene );
132
-
133
- /* DISABLED: causes problems with Internet Explorer
134
- defaultPipeline.imageProcessingEnabled = true;
135
- */
136
-
137
- if( sceneJson.scene.globals.aa ) {
138
- defaultPipeline.fxaaEnabled = true; //implicitly does FxaaPostProcess()
139
- }
140
-
141
- // Set samples regardless of fxaa setting since we don't want to use fxaa but still increase the sample count
142
- defaultPipeline.samples = 8;
143
-
144
- if( sceneJson.scene.globals['camera-settings'] ) {
145
- if( sceneJson.scene.globals['camera-settings'].sharpen && sceneJson.scene.globals['camera-settings'].sharpen.enabled ) {
146
- defaultPipeline.sharpenEnabled = true; //implicitly does SharpenPostProcess()
147
- //defaultPipeline.sharpen.colorAmount = 1;
148
- //defaultPipeline.sharpen.edgeAmount = 0;
149
- }
150
-
151
- if( sceneJson.scene.globals['camera-settings'].bloom && sceneJson.scene.globals['camera-settings'].bloom.enabled ) {
152
- defaultPipeline.bloomEnabled = true;
153
-
154
- if( sceneJson.scene.globals['camera-settings'].bloom.size ) {
155
- defaultPipeline.bloomScale = sceneJson.scene.globals['camera-settings'].bloom.size;
156
- }
157
-
158
- if( sceneJson.scene.globals['camera-settings'].bloom.threshold ) {
159
- defaultPipeline.bloomThreshold = sceneJson.scene.globals['camera-settings'].bloom.threshold;
160
- }
161
- }
162
-
163
- if( sceneJson.scene.globals['camera-settings'].contrast ) {
164
- scene.imageProcessingConfiguration.contrast = sceneJson.scene.globals['camera-settings'].contrast;
165
- }
166
-
167
- if( sceneJson.scene.globals['camera-settings'].exposure ) {
168
- scene.imageProcessingConfiguration.exposure = sceneJson.scene.globals['camera-settings'].exposure;
169
- }
170
-
171
- if( sceneJson.scene.globals['camera-settings'].dof && sceneJson.scene.globals['camera-settings'].dof.enabled ) {
172
- //@ts-ignore
173
- const module = await import(/* webpackChunkName: "lens-rendering" */ './lensRendering');
174
- new module.LensRenderingPipeline( 'lens-rendering', sceneJson.scene.globals['camera-settings'].dof!.settings, scene, 1.0, cameras );
175
- }
176
- }
177
-
178
- // TODO: make this dynamic
179
- /*
180
- const texture = new HDRCubeTexture("/assets/small_cave_1k.hdr", scene, 256);
181
- texture.gammaSpace = false;
182
- scene.environmentTexture = texture;
183
- // scene.environmentTexture.
184
-
185
- const skyboxMaterial = new StandardMaterial("skyBox", scene);
186
- skyboxMaterial.backFaceCulling = false;
187
- skyboxMaterial.reflectionTexture = texture;
188
- skyboxMaterial.reflectionTexture.coordinatesMode = Texture.SKYBOX_MODE;
189
- skyboxMaterial.disableLighting = false;
190
- // TODO: replace with BoxBuilder
191
- const skybox = MeshBuilder.CreateBox("skyBox", {size: 1000.0}, scene);
192
- skybox.isPickable = false; //never pick a skybox
193
- skybox.infiniteDistance = true;
194
- skybox.material = skyboxMaterial;
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
  }