itowns 2.44.3-next.4 → 2.44.3-next.41

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 (217) hide show
  1. package/README.md +3 -129
  2. package/examples/3dtiles_loader.html +123 -48
  3. package/examples/config.json +3 -10
  4. package/examples/copc_simple_loader.html +15 -5
  5. package/examples/effects_stereo.html +2 -2
  6. package/examples/entwine_3d_loader.html +3 -1
  7. package/examples/entwine_simple_loader.html +1 -1
  8. package/examples/images/itowns_logo.svg +123 -0
  9. package/examples/js/plugins/COGParser.js +1 -1
  10. package/examples/jsm/OGC3DTilesHelper.js +6 -1
  11. package/examples/layers/JSONLayers/GeoidMNT.json +3 -1
  12. package/examples/misc_collada.html +2 -2
  13. package/examples/source_file_geojson_3d.html +0 -1
  14. package/examples/source_file_kml_raster_usgs.html +0 -1
  15. package/examples/source_stream_wfs_raster.html +0 -7
  16. package/examples/vector_tile_mapbox_raster.html +91 -0
  17. package/examples/view_3d_map_webxr.html +3 -1
  18. package/examples/view_multi_25d.html +2 -2
  19. package/package.json +21 -75
  20. package/CODING.md +0 -120
  21. package/CONTRIBUTING.md +0 -150
  22. package/CONTRIBUTORS.md +0 -55
  23. package/LICENSE.md +0 -44
  24. package/changelog.md +0 -1361
  25. package/dist/455.js +0 -2
  26. package/dist/455.js.map +0 -1
  27. package/dist/debug.js +0 -3
  28. package/dist/debug.js.LICENSE.txt +0 -13
  29. package/dist/debug.js.map +0 -1
  30. package/dist/itowns.js +0 -3
  31. package/dist/itowns.js.LICENSE.txt +0 -7
  32. package/dist/itowns.js.map +0 -1
  33. package/dist/itowns_lasparser.js +0 -2
  34. package/dist/itowns_lasparser.js.map +0 -1
  35. package/dist/itowns_lasworker.js +0 -2
  36. package/dist/itowns_lasworker.js.map +0 -1
  37. package/dist/itowns_potree2worker.js +0 -2
  38. package/dist/itowns_potree2worker.js.map +0 -1
  39. package/dist/itowns_widgets.js +0 -2
  40. package/dist/itowns_widgets.js.map +0 -1
  41. package/examples/.eslintrc.cjs +0 -35
  42. package/examples/3dtiles_25d.html +0 -120
  43. package/examples/3dtiles_basic.html +0 -94
  44. package/examples/3dtiles_batch_table.html +0 -86
  45. package/examples/3dtiles_ion.html +0 -126
  46. package/examples/3dtiles_pointcloud.html +0 -95
  47. package/examples/jsm/.eslintrc.cjs +0 -38
  48. package/lib/Controls/FirstPersonControls.js +0 -308
  49. package/lib/Controls/FlyControls.js +0 -175
  50. package/lib/Controls/GlobeControls.js +0 -1162
  51. package/lib/Controls/PlanarControls.js +0 -1025
  52. package/lib/Controls/StateControl.js +0 -429
  53. package/lib/Controls/StreetControls.js +0 -392
  54. package/lib/Converter/Feature2Mesh.js +0 -608
  55. package/lib/Converter/Feature2Texture.js +0 -170
  56. package/lib/Converter/convertToTile.js +0 -75
  57. package/lib/Converter/textureConverter.js +0 -44
  58. package/lib/Core/3DTiles/C3DTBatchTable.js +0 -131
  59. package/lib/Core/3DTiles/C3DTBatchTableHierarchyExtension.js +0 -96
  60. package/lib/Core/3DTiles/C3DTBoundingVolume.js +0 -157
  61. package/lib/Core/3DTiles/C3DTExtensions.js +0 -97
  62. package/lib/Core/3DTiles/C3DTFeature.js +0 -110
  63. package/lib/Core/3DTiles/C3DTilesEnums.js +0 -20
  64. package/lib/Core/3DTiles/C3DTileset.js +0 -99
  65. package/lib/Core/3DTiles/utils/BinaryPropertyAccessor.js +0 -100
  66. package/lib/Core/AnimationPlayer.js +0 -142
  67. package/lib/Core/CopcNode.js +0 -174
  68. package/lib/Core/Deprecated/Undeprecator.js +0 -75
  69. package/lib/Core/EntwinePointTileNode.js +0 -126
  70. package/lib/Core/Feature.js +0 -490
  71. package/lib/Core/Geographic/CoordStars.js +0 -80
  72. package/lib/Core/Geographic/Coordinates.js +0 -320
  73. package/lib/Core/Geographic/Crs.js +0 -175
  74. package/lib/Core/Geographic/Extent.js +0 -726
  75. package/lib/Core/Geographic/GeoidGrid.js +0 -109
  76. package/lib/Core/Label.js +0 -222
  77. package/lib/Core/MainLoop.js +0 -211
  78. package/lib/Core/Math/Ellipsoid.js +0 -144
  79. package/lib/Core/Picking.js +0 -255
  80. package/lib/Core/PointCloudNode.js +0 -42
  81. package/lib/Core/Potree2Node.js +0 -206
  82. package/lib/Core/Potree2PointAttributes.js +0 -139
  83. package/lib/Core/PotreeNode.js +0 -101
  84. package/lib/Core/Prefab/Globe/Atmosphere.js +0 -299
  85. package/lib/Core/Prefab/Globe/BuilderEllipsoidTile.js +0 -110
  86. package/lib/Core/Prefab/Globe/GlobeLayer.js +0 -145
  87. package/lib/Core/Prefab/Globe/SkyShader.js +0 -78
  88. package/lib/Core/Prefab/GlobeView.js +0 -161
  89. package/lib/Core/Prefab/Planar/PlanarLayer.js +0 -53
  90. package/lib/Core/Prefab/Planar/PlanarTileBuilder.js +0 -72
  91. package/lib/Core/Prefab/PlanarView.js +0 -62
  92. package/lib/Core/Prefab/TileBuilder.js +0 -80
  93. package/lib/Core/Prefab/computeBufferTileGeometry.js +0 -183
  94. package/lib/Core/Scheduler/Cache.js +0 -256
  95. package/lib/Core/Scheduler/CancelledCommandException.js +0 -15
  96. package/lib/Core/Scheduler/Scheduler.js +0 -294
  97. package/lib/Core/Style.js +0 -1121
  98. package/lib/Core/System/Capabilities.js +0 -63
  99. package/lib/Core/TileGeometry.js +0 -40
  100. package/lib/Core/TileMesh.js +0 -108
  101. package/lib/Core/View.js +0 -1109
  102. package/lib/Layer/C3DTilesLayer.js +0 -455
  103. package/lib/Layer/ColorLayer.js +0 -128
  104. package/lib/Layer/CopcLayer.js +0 -58
  105. package/lib/Layer/ElevationLayer.js +0 -107
  106. package/lib/Layer/EntwinePointTileLayer.js +0 -64
  107. package/lib/Layer/FeatureGeometryLayer.js +0 -63
  108. package/lib/Layer/GeoidLayer.js +0 -80
  109. package/lib/Layer/GeometryLayer.js +0 -202
  110. package/lib/Layer/InfoLayer.js +0 -64
  111. package/lib/Layer/LabelLayer.js +0 -452
  112. package/lib/Layer/Layer.js +0 -304
  113. package/lib/Layer/LayerUpdateState.js +0 -89
  114. package/lib/Layer/LayerUpdateStrategy.js +0 -80
  115. package/lib/Layer/OGC3DTilesLayer.js +0 -387
  116. package/lib/Layer/OrientedImageLayer.js +0 -222
  117. package/lib/Layer/PointCloudLayer.js +0 -359
  118. package/lib/Layer/Potree2Layer.js +0 -164
  119. package/lib/Layer/PotreeLayer.js +0 -65
  120. package/lib/Layer/RasterLayer.js +0 -27
  121. package/lib/Layer/ReferencingLayerProperties.js +0 -62
  122. package/lib/Layer/TiledGeometryLayer.js +0 -403
  123. package/lib/Loader/LASLoader.js +0 -193
  124. package/lib/Loader/Potree2BrotliLoader.js +0 -261
  125. package/lib/Loader/Potree2Loader.js +0 -207
  126. package/lib/Main.js +0 -115
  127. package/lib/MainBundle.js +0 -4
  128. package/lib/Parser/B3dmParser.js +0 -174
  129. package/lib/Parser/CameraCalibrationParser.js +0 -94
  130. package/lib/Parser/GDFParser.js +0 -72
  131. package/lib/Parser/GTXParser.js +0 -75
  132. package/lib/Parser/GeoJsonParser.js +0 -212
  133. package/lib/Parser/GpxParser.js +0 -25
  134. package/lib/Parser/ISGParser.js +0 -71
  135. package/lib/Parser/KMLParser.js +0 -25
  136. package/lib/Parser/LASParser.js +0 -137
  137. package/lib/Parser/MapBoxUrlParser.js +0 -83
  138. package/lib/Parser/PntsParser.js +0 -131
  139. package/lib/Parser/Potree2BinParser.js +0 -92
  140. package/lib/Parser/PotreeBinParser.js +0 -106
  141. package/lib/Parser/PotreeCinParser.js +0 -29
  142. package/lib/Parser/ShapefileParser.js +0 -78
  143. package/lib/Parser/VectorTileParser.js +0 -202
  144. package/lib/Parser/XbilParser.js +0 -108
  145. package/lib/Parser/deprecated/LegacyGLTFLoader.js +0 -1386
  146. package/lib/Parser/iGLTFLoader.js +0 -168
  147. package/lib/Process/3dTilesProcessing.js +0 -304
  148. package/lib/Process/FeatureProcessing.js +0 -76
  149. package/lib/Process/LayeredMaterialNodeProcessing.js +0 -221
  150. package/lib/Process/ObjectRemovalHelper.js +0 -97
  151. package/lib/Process/handlerNodeError.js +0 -23
  152. package/lib/Provider/3dTilesProvider.js +0 -149
  153. package/lib/Provider/DataSourceProvider.js +0 -8
  154. package/lib/Provider/Fetcher.js +0 -229
  155. package/lib/Provider/PointCloudProvider.js +0 -45
  156. package/lib/Provider/TileProvider.js +0 -16
  157. package/lib/Provider/URLBuilder.js +0 -105
  158. package/lib/Renderer/Camera.js +0 -281
  159. package/lib/Renderer/Color.js +0 -56
  160. package/lib/Renderer/ColorLayersOrdering.js +0 -115
  161. package/lib/Renderer/CommonMaterial.js +0 -31
  162. package/lib/Renderer/Label2DRenderer.js +0 -190
  163. package/lib/Renderer/LayeredMaterial.js +0 -243
  164. package/lib/Renderer/OBB.js +0 -153
  165. package/lib/Renderer/OrientedImageCamera.js +0 -118
  166. package/lib/Renderer/OrientedImageMaterial.js +0 -167
  167. package/lib/Renderer/PointsMaterial.js +0 -485
  168. package/lib/Renderer/RasterTile.js +0 -209
  169. package/lib/Renderer/RenderMode.js +0 -31
  170. package/lib/Renderer/Shader/ShaderChunk.js +0 -160
  171. package/lib/Renderer/Shader/ShaderUtils.js +0 -47
  172. package/lib/Renderer/SphereHelper.js +0 -23
  173. package/lib/Renderer/WebXR.js +0 -51
  174. package/lib/Renderer/c3DEngine.js +0 -214
  175. package/lib/Source/C3DTilesGoogleSource.js +0 -74
  176. package/lib/Source/C3DTilesIonSource.js +0 -54
  177. package/lib/Source/C3DTilesSource.js +0 -30
  178. package/lib/Source/CopcSource.js +0 -115
  179. package/lib/Source/EntwinePointTileSource.js +0 -62
  180. package/lib/Source/FileSource.js +0 -189
  181. package/lib/Source/OGC3DTilesGoogleSource.js +0 -29
  182. package/lib/Source/OGC3DTilesIonSource.js +0 -34
  183. package/lib/Source/OGC3DTilesSource.js +0 -21
  184. package/lib/Source/OrientedImageSource.js +0 -59
  185. package/lib/Source/Potree2Source.js +0 -167
  186. package/lib/Source/PotreeSource.js +0 -82
  187. package/lib/Source/Source.js +0 -223
  188. package/lib/Source/TMSSource.js +0 -143
  189. package/lib/Source/VectorTilesSource.js +0 -178
  190. package/lib/Source/WFSSource.js +0 -165
  191. package/lib/Source/WMSSource.js +0 -130
  192. package/lib/Source/WMTSSource.js +0 -86
  193. package/lib/ThreeExtended/capabilities/WebGL.js +0 -69
  194. package/lib/ThreeExtended/libs/ktx-parse.module.js +0 -470
  195. package/lib/ThreeExtended/libs/zstddec.module.js +0 -29
  196. package/lib/ThreeExtended/loaders/DDSLoader.js +0 -200
  197. package/lib/ThreeExtended/loaders/DRACOLoader.js +0 -399
  198. package/lib/ThreeExtended/loaders/GLTFLoader.js +0 -2876
  199. package/lib/ThreeExtended/loaders/KTX2Loader.js +0 -625
  200. package/lib/ThreeExtended/utils/BufferGeometryUtils.js +0 -846
  201. package/lib/ThreeExtended/utils/WorkerPool.js +0 -70
  202. package/lib/Utils/CameraUtils.js +0 -555
  203. package/lib/Utils/DEMUtils.js +0 -350
  204. package/lib/Utils/FeaturesUtils.js +0 -156
  205. package/lib/Utils/Gradients.js +0 -16
  206. package/lib/Utils/OrientationUtils.js +0 -457
  207. package/lib/Utils/ThreeUtils.js +0 -115
  208. package/lib/Utils/gui/C3DTilesStyle.js +0 -216
  209. package/lib/Utils/gui/Main.js +0 -7
  210. package/lib/Utils/gui/Minimap.js +0 -154
  211. package/lib/Utils/gui/Navigation.js +0 -245
  212. package/lib/Utils/gui/Scale.js +0 -107
  213. package/lib/Utils/gui/Searchbar.js +0 -234
  214. package/lib/Utils/gui/Widget.js +0 -80
  215. package/lib/Utils/placeObjectOnGround.js +0 -137
  216. package/lib/Worker/LASLoaderWorker.js +0 -19
  217. package/lib/Worker/Potree2Worker.js +0 -21
@@ -1,70 +0,0 @@
1
- /**
2
- * @author Deepkolos / https://github.com/deepkolos
3
- */
4
-
5
- export class WorkerPool {
6
- constructor() {
7
- let pool = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 4;
8
- this.pool = pool;
9
- this.queue = [];
10
- this.workers = [];
11
- this.workersResolve = [];
12
- this.workerStatus = 0;
13
- }
14
- _initWorker(workerId) {
15
- if (!this.workers[workerId]) {
16
- const worker = this.workerCreator();
17
- worker.addEventListener('message', this._onMessage.bind(this, workerId));
18
- this.workers[workerId] = worker;
19
- }
20
- }
21
- _getIdleWorker() {
22
- for (let i = 0; i < this.pool; i++) if (!(this.workerStatus & 1 << i)) return i;
23
- return -1;
24
- }
25
- _onMessage(workerId, msg) {
26
- const resolve = this.workersResolve[workerId];
27
- resolve && resolve(msg);
28
- if (this.queue.length) {
29
- const {
30
- resolve,
31
- msg,
32
- transfer
33
- } = this.queue.shift();
34
- this.workersResolve[workerId] = resolve;
35
- this.workers[workerId].postMessage(msg, transfer);
36
- } else {
37
- this.workerStatus ^= 1 << workerId;
38
- }
39
- }
40
- setWorkerCreator(workerCreator) {
41
- this.workerCreator = workerCreator;
42
- }
43
- setWorkerLimit(pool) {
44
- this.pool = pool;
45
- }
46
- postMessage(msg, transfer) {
47
- return new Promise(resolve => {
48
- const workerId = this._getIdleWorker();
49
- if (workerId !== -1) {
50
- this._initWorker(workerId);
51
- this.workerStatus |= 1 << workerId;
52
- this.workersResolve[workerId] = resolve;
53
- this.workers[workerId].postMessage(msg, transfer);
54
- } else {
55
- this.queue.push({
56
- resolve,
57
- msg,
58
- transfer
59
- });
60
- }
61
- });
62
- }
63
- dispose() {
64
- this.workers.forEach(worker => worker.terminate());
65
- this.workersResolve.length = 0;
66
- this.workers.length = 0;
67
- this.queue.length = 0;
68
- this.workerStatus = 0;
69
- }
70
- }
@@ -1,555 +0,0 @@
1
- import * as THREE from 'three';
2
- import TWEEN from '@tweenjs/tween.js';
3
- import DEMUtils from "./DEMUtils.js";
4
- import { MAIN_LOOP_EVENTS } from "../Core/MainLoop.js";
5
- import Coordinates from "../Core/Geographic/Coordinates.js";
6
- import Ellipsoid from "../Core/Math/Ellipsoid.js";
7
- import OBB from "../Renderer/OBB.js";
8
- import { VIEW_EVENTS } from "../Core/View.js";
9
- THREE.Object3D.DEFAULT_UP.set(0, 0, 1);
10
- const targetPosition = new THREE.Vector3();
11
- const targetCoord = new Coordinates('EPSG:4326', 0, 0, 0);
12
- const ellipsoid = new Ellipsoid();
13
- const rigs = [];
14
- const obb = new OBB();
15
- const size = new THREE.Vector3();
16
- const deferred = () => {
17
- let resolve;
18
- let reject;
19
- return {
20
- promise: new Promise((re, rej) => {
21
- resolve = re;
22
- reject = rej;
23
- }),
24
- resolve,
25
- reject
26
- };
27
- };
28
-
29
- // Wrap angle in degrees to [-180 180]
30
- function wrapTo180(angle) {
31
- return angle - Math.floor((angle + 180.0) / 360) * 360;
32
- }
33
- function tileLayer(view) {
34
- return view.getLayers(l => l.isTiledGeometryLayer)[0];
35
- }
36
- export function getLookAtFromMath(view, camera) {
37
- const direction = new THREE.Vector3(0, 0, 0.5);
38
- direction.unproject(camera);
39
- direction.sub(camera.position).normalize();
40
- if (view.referenceCrs == 'EPSG:4978') {
41
- // Intersect Ellispoid
42
- return ellipsoid.intersection({
43
- direction,
44
- origin: camera.position
45
- });
46
- } else {
47
- // Intersect plane
48
- const distance = camera.position.z / direction.z;
49
- return direction.multiplyScalar(distance).add(camera.position);
50
- }
51
- }
52
- function proxyProperty(view, camera, rig, key) {
53
- rig.proxy.position[key] = camera.position[key];
54
- Object.defineProperty(camera.position, key, {
55
- get: () => rig.proxy.position[key],
56
- set: newValue => {
57
- rig.removeProxy(view, camera);
58
- camera.position[key] = newValue;
59
- }
60
- });
61
- }
62
-
63
- // the rig is used to manipulate the camera
64
- // It consists of a tree of 3D objects, each element is assigned a task
65
- //
66
- // Transformation
67
- //
68
- // rig position on Coordinate (for the globe is rotation)
69
- // |
70
- // └── sealevel position on altitude zero
71
- // |
72
- // └── target position on DEM, and rotation (pitch and heading)
73
- // |
74
- // └── camera distance to target
75
- //
76
- // When all transformations are calculated,
77
- // this.camera's transformation is applied to view.camera.camera
78
- class CameraRig extends THREE.Object3D {
79
- constructor() {
80
- super();
81
- // seaLevel is on rig's z axis, it's at altitude zero
82
- this.seaLevel = new THREE.Object3D();
83
- // target is on seaLevel's z axis and target.position.z is the DEM altitude
84
- this.target = new THREE.Object3D();
85
- this.target.rotation.order = 'ZXY';
86
- // camera look at target
87
- this.camera = new THREE.Camera();
88
- this.add(this.seaLevel);
89
- this.seaLevel.add(this.target);
90
- this.target.add(this.camera);
91
- // target's geographic coordinate
92
- this.coord = new Coordinates('EPSG:4978', 0, 0);
93
- // sea level's worldPoistion
94
- this.targetWorldPosition = new THREE.Vector3();
95
- this.removeAll = () => {};
96
- this._onChangeCallback = null;
97
- }
98
-
99
- // apply rig.camera's transformation to camera
100
- applyTransformToCamera(view, camera) {
101
- if (this.proxy) {
102
- camera.quaternion._onChange(this._onChangeCallback);
103
- this.camera.matrixWorld.decompose(this.proxy.position, camera.quaternion, camera.scale);
104
- camera.quaternion._onChange(() => this.removeProxy(view, camera));
105
- } else {
106
- this.camera.matrixWorld.decompose(camera.position, camera.quaternion, camera.scale);
107
- }
108
- view.dispatchEvent({
109
- type: VIEW_EVENTS.CAMERA_MOVED,
110
- coord: this.coord,
111
- range: this.range,
112
- heading: this.heading,
113
- tilt: this.tilt
114
- });
115
- }
116
- setProxy(view, camera) {
117
- if (!this.proxy && view && camera) {
118
- this.proxy = {
119
- position: new THREE.Vector3()
120
- };
121
- Object.keys(camera.position).forEach(key => proxyProperty(view, camera, this, key));
122
- this._onChangeCallback = camera.quaternion._onChangeCallback;
123
- camera.quaternion._onChange(() => this.removeProxy(view, camera));
124
- }
125
- }
126
- removeProxy(view, camera) {
127
- this.stop(view);
128
- if (this.proxy && view && camera) {
129
- Object.keys(camera.position).forEach(key => Object.defineProperty(camera.position, key, {
130
- value: this.proxy.position[key],
131
- writable: true
132
- }));
133
- camera.quaternion._onChange(this._onChangeCallback);
134
- this.proxy = null;
135
- }
136
- }
137
- setTargetFromCoordinate(view, coord) {
138
- // compute precise coordinate (coord) altitude and clamp it above seaLevel
139
- coord.as(tileLayer(view).extent.crs, this.coord);
140
- const altitude = Math.max(0, DEMUtils.getElevationValueAt(tileLayer(view), this.coord, DEMUtils.PRECISE_READ_Z) || this.coord.z);
141
- this.coord.z = altitude;
142
- // adjust target's position with clamped altitude
143
- this.coord.as(view.referenceCrs).toVector3(targetPosition);
144
- if (view.referenceCrs == 'EPSG:4978') {
145
- // ellipsoid geocentric projection
146
- this.lookAt(targetPosition);
147
- this.seaLevel.position.set(0, 0, targetPosition.length() - altitude);
148
- } else {
149
- // planar projection
150
- this.position.set(targetPosition.x, targetPosition.y, 0);
151
- this.seaLevel.position.set(0, 0, 0);
152
- }
153
- // place camera's target
154
- this.target.position.set(0, 0, altitude);
155
- }
156
-
157
- // set rig's objects transformation from camera's position and target's position
158
- setFromPositions(view, cameraPosition) {
159
- this.setTargetFromCoordinate(view, new Coordinates(view.referenceCrs, targetPosition));
160
- this.target.rotation.set(0, 0, 0);
161
- this.updateMatrixWorld(true);
162
- this.camera.position.copy(cameraPosition);
163
- this.target.worldToLocal(this.camera.position);
164
- const range = this.camera.position.length();
165
- this.target.rotation.x = Math.asin(this.camera.position.z / range);
166
- const cosPlanXY = THREE.MathUtils.clamp(this.camera.position.y / (Math.cos(this.target.rotation.x) * range), -1, 1);
167
- this.target.rotation.z = Math.sign(-this.camera.position.x || 1) * Math.acos(cosPlanXY);
168
- this.camera.position.set(0, range, 0);
169
- }
170
-
171
- // set from target's coordinate, rotation and range between target and camera
172
- applyParams(view, params) {
173
- if (params.coord) {
174
- this.setTargetFromCoordinate(view, params.coord);
175
- }
176
- if (params.tilt != undefined) {
177
- this.target.rotation.x = THREE.MathUtils.degToRad(params.tilt);
178
- }
179
- if (params.heading != undefined) {
180
- this.target.rotation.z = THREE.MathUtils.degToRad(-wrapTo180(params.heading + 180));
181
- }
182
- if (params.range) {
183
- this.camera.position.set(0, params.range, 0);
184
- }
185
- this.camera.rotation.set(-Math.PI * 0.5, 0, Math.PI);
186
- this.updateMatrixWorld(true);
187
- this.targetWorldPosition.setFromMatrixPosition(this.seaLevel.matrixWorld);
188
- }
189
- getParams() {
190
- return {
191
- coord: this.coord.clone(),
192
- tilt: this.tilt,
193
- heading: this.heading,
194
- range: this.range,
195
- targetWorldPosition: this.targetWorldPosition
196
- };
197
- }
198
- setfromCamera(view, camera, pickedPosition) {
199
- camera.updateMatrixWorld(true);
200
- if (pickedPosition == undefined) {
201
- pickedPosition = view.getPickingPositionFromDepth() || getLookAtFromMath(view, camera);
202
- }
203
- const range = pickedPosition && !isNaN(pickedPosition.x) ? camera.position.distanceTo(pickedPosition) : 100;
204
- camera.localToWorld(targetPosition.set(0, 0, -range));
205
- this.setFromPositions(view, camera.position);
206
- }
207
- copyObject3D(rig) {
208
- this.copy(rig, false);
209
- this.seaLevel.copy(rig.seaLevel, false);
210
- this.target.copy(rig.target, false);
211
- this.camera.copy(rig.camera);
212
- return this;
213
- }
214
- animateCameraToLookAtTarget(view, camera, params) {
215
- params.easing = params.easing || TWEEN.Easing.Quartic.InOut;
216
- this.setfromCamera(view, camera);
217
- const tweenGroup = new TWEEN.Group();
218
- this.start = (this.start || new CameraRig()).copyObject3D(this);
219
- this.end = (this.end || new CameraRig()).copyObject3D(this);
220
- const time = params.time || 2500;
221
- const factor = {
222
- t: 0
223
- };
224
- const animations = [];
225
- const def = deferred();
226
- this.addPlaceTargetOnGround(view, camera, params.coord, factor);
227
- this.end.applyParams(view, params);
228
- // compute the angle along z-axis between the starting position and the end position
229
- const difference = this.end.target.rotation.z - this.start.target.rotation.z;
230
- // if that angle is superior to 180°, recompute the rotation as the complementary angle.
231
- if (Math.abs(difference) > Math.PI) {
232
- this.end.target.rotation.z = this.start.target.rotation.z + difference - Math.sign(difference) * 2 * Math.PI;
233
- }
234
- animations.push(new TWEEN.Tween(factor).to({
235
- t: 1
236
- }, time).easing(params.easing).onUpdate(d => {
237
- // rotate to coord destination in geocentric projection
238
- if (view.referenceCrs == 'EPSG:4978') {
239
- this.quaternion.slerpQuaternions(this.start.quaternion, this.end.quaternion, d.t);
240
- }
241
- // camera rotation
242
- this.camera.quaternion.slerpQuaternions(this.start.camera.quaternion, this.end.camera.quaternion, d.t);
243
- // camera's target rotation
244
- this.target.rotation.set(0, 0, 0);
245
- this.target.rotateZ(THREE.MathUtils.lerp(this.start.target.rotation.z, this.end.target.rotation.z, d.t));
246
- this.target.rotateX(THREE.MathUtils.lerp(this.start.target.rotation.x, this.end.target.rotation.x, d.t));
247
- }));
248
-
249
- // translate to coordinate destination in planar projection
250
- if (view.referenceCrs != 'EPSG:4978') {
251
- animations.push(new TWEEN.Tween(this.position).to(this.end.position, time).easing(params.easing));
252
- }
253
-
254
- // translate to altitude zero
255
- animations.push(new TWEEN.Tween(this.seaLevel.position).to(this.end.seaLevel.position, time).easing(params.easing));
256
-
257
- // translate camera position
258
- animations.push(new TWEEN.Tween(this.camera.position).to(this.end.camera.position, time).easing(params.easing));
259
- tweenGroup.add(...animations);
260
-
261
- // update animations, transformation and view
262
- this.animationFrameRequester = () => {
263
- tweenGroup.update();
264
- this.updateMatrixWorld(true);
265
- this.applyTransformToCamera(view, camera);
266
- this.targetWorldPosition.setFromMatrixPosition(this.seaLevel.matrixWorld);
267
- if (params.callback) {
268
- params.callback(this);
269
- }
270
- targetCoord.crs = view.referenceCrs;
271
- targetCoord.setFromVector3(this.targetWorldPosition).as(tileLayer(view).extent.crs, this.coord);
272
- view.notifyChange(camera);
273
- };
274
- this.removeAll = function (o) {
275
- this.removeAll = () => {};
276
- tweenGroup.removeAll();
277
- if (this.animationFrameRequester) {
278
- view.removeFrameRequester(MAIN_LOOP_EVENTS.BEFORE_RENDER, this.animationFrameRequester);
279
- }
280
- def.resolve(o !== undefined);
281
- this.animationFrameRequester = null;
282
- };
283
-
284
- // Waiting last animation complete,
285
- // we assume that the animation that completes last is the one that was started last
286
- animations[animations.length - 1].onComplete(this.removeAll);
287
- animations.forEach(anim => anim.start());
288
- view.addFrameRequester(MAIN_LOOP_EVENTS.BEFORE_RENDER, this.animationFrameRequester);
289
- view.notifyChange(camera);
290
- return def;
291
- }
292
- stop(view) {
293
- this.removePlaceTargetOnGround(view);
294
- this.removeAll();
295
- }
296
-
297
- // update target position to coordinate's altitude
298
- addPlaceTargetOnGround(view, camera, coord) {
299
- let options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {
300
- t: 1.0
301
- };
302
- this.removePlaceTargetOnGround(view);
303
- if (view && camera) {
304
- const startAltitude = this.target.position.z;
305
- this.placeTargetOnGround = () => {
306
- const altitude = Math.max(0, DEMUtils.getElevationValueAt(tileLayer(view), coord || this.coord, DEMUtils.PRECISE_READ_Z) || 0);
307
- this.target.position.z = startAltitude * (1.0 - options.t) + altitude * options.t;
308
- this.target.updateMatrixWorld(true);
309
- this.applyTransformToCamera(view, camera);
310
- };
311
- this.placeTargetOnGround();
312
- view.addFrameRequester(MAIN_LOOP_EVENTS.BEFORE_RENDER, this.placeTargetOnGround);
313
- }
314
- }
315
- removePlaceTargetOnGround(view) {
316
- if (view && this.placeTargetOnGround) {
317
- view.removeFrameRequester(MAIN_LOOP_EVENTS.BEFORE_RENDER, this.placeTargetOnGround);
318
- this.placeTargetOnGround = null;
319
- }
320
- }
321
- get tilt() {
322
- return THREE.MathUtils.radToDeg(this.target.rotation.x);
323
- }
324
- get heading() {
325
- return -wrapTo180(THREE.MathUtils.radToDeg(this.target.rotation.z) + 180);
326
- }
327
- get range() {
328
- return this.camera.position.y;
329
- }
330
- }
331
- export function getRig(camera) {
332
- rigs[camera.uuid] = rigs[camera.uuid] || new CameraRig();
333
- return rigs[camera.uuid];
334
- }
335
-
336
- /**
337
- * @module CameraUtils
338
- */
339
- export default {
340
- /**
341
- * @typedef {Object} CameraTransformOptions
342
- * @property {Coordinate} [coord=currentCoordinate] Camera look at geographic coordinate
343
- * @property {Number} [tilt=currentTilt] camera's tilt, in degree
344
- * @property {Number} [heading=currentHeading] camera's heading, in degree
345
- * @property {Number} [range=currentRange] camera distance to target coordinate, in meter
346
- * @property {Number} [time=2500] duration of the animation, in ms
347
- * @property {boolean} [proxy=true] use proxy to handling camera's transformation. if proxy == true, other camera's transformation stops rig's transformation
348
- * @property {Number} [easing=TWEEN.Easing.Quartic.InOut] in and out easing animation
349
- * @property {function} [callback] callback call each animation's frame (params are current cameraTransform and worldTargetPosition)
350
- * @property {boolean} [stopPlaceOnGroundAtEnd=false] stop place target on the ground at animation ending
351
- */
352
- /**
353
- * Default value for option to stop place target
354
- * on the ground at animation ending.
355
- * Default value is false.
356
- */
357
- defaultStopPlaceOnGroundAtEnd: false,
358
- Easing: TWEEN.Easing,
359
- /**
360
- * Stop camera's animation
361
- *
362
- * @param {View} view The camera view
363
- * @param {Camera} camera The camera to stop animation
364
- */
365
- stop(view, camera) {
366
- getRig(camera).stop(view);
367
- },
368
- /**
369
- * Gets the current parameters transform camera looking at target.
370
- *
371
- * @param {View} view The camera view
372
- * @param {Camera} camera The camera to get transform
373
- * @param {THREE.Vector3} [target] - The optional target
374
- * @return {CameraUtils~CameraTransformOptions} The transform camera looking at target
375
- */
376
- getTransformCameraLookingAtTarget(view, camera, target) {
377
- const rig = getRig(camera);
378
- rig.setfromCamera(view, camera, target);
379
- return rig.getParams();
380
- },
381
- /**
382
- * Apply transform to camera
383
- *
384
- * @param {View} view The camera view
385
- * @param {Camera} camera The camera to transform
386
- * @param {CameraUtils~CameraTransformOptions|Extent} params The parameters
387
- * @return {Promise} promise with resolve final CameraUtils~CameraTransformOptions
388
- */
389
- transformCameraToLookAtTarget(view, camera) {
390
- let params = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
391
- if (params.isExtent) {
392
- params = this.getCameraTransformOptionsFromExtent(view, camera, params);
393
- }
394
- params.proxy = params.proxy === undefined || params.proxy;
395
- const rig = getRig(camera);
396
- rig.stop(view);
397
- rig.setfromCamera(view, camera);
398
- if (params.proxy) {
399
- rig.setProxy(view, camera);
400
- }
401
- rig.applyParams(view, params);
402
- rig.addPlaceTargetOnGround(view, camera, params.coord);
403
- rig.applyTransformToCamera(view, camera);
404
- view.notifyChange(camera);
405
- return Promise.resolve(rig.getParams());
406
- },
407
- /**
408
- * Compute the CameraTransformOptions that allow a given camera to display a given extent in its entirety.
409
- *
410
- * @param {View} view The camera view
411
- * @param {THREE.Camera} camera The camera to get the CameraTransformOptions from
412
- * @param {Extent} extent The extent the camera must display
413
- *
414
- * @return {CameraUtils~CameraTransformOptions} The CameraTransformOptions allowing camera to display the extent.
415
- */
416
- getCameraTransformOptionsFromExtent(view, camera, extent) {
417
- const cameraTransformOptions = {
418
- coord: new Coordinates(extent.crs, 0, 0, 0),
419
- heading: 0,
420
- tilt: view.isPlanarView ? 90 : 89.9
421
- };
422
- let dimensions;
423
- if (view.isGlobeView) {
424
- extent = extent.as('EPSG:4326');
425
- // compute extent's bounding box dimensions
426
- obb.setFromExtent(extent);
427
- // /!\ WARNING x and y are inverted, see issue #XXXX
428
- obb.box3D.getSize(size);
429
- dimensions = {
430
- x: size.y,
431
- y: size.x
432
- };
433
- } else {
434
- extent = extent.as(view.referenceCrs);
435
- dimensions = extent.planarDimensions();
436
- }
437
- extent.center(cameraTransformOptions.coord);
438
- if (camera.isOrthographicCamera) {
439
- // setup camera zoom
440
- if (dimensions.x / dimensions.y > camera.aspect) {
441
- camera.zoom = (camera.right - camera.left) / dimensions.x;
442
- } else {
443
- camera.zoom = (camera.top - camera.bottom) / dimensions.y;
444
- }
445
- camera.updateProjectionMatrix();
446
-
447
- // setup camera placement
448
- cameraTransformOptions.range = 1000;
449
- } else if (camera.isPerspectiveCamera) {
450
- // setup range for camera placement
451
- const verticalFOV = THREE.MathUtils.degToRad(camera.fov);
452
- if (dimensions.x / dimensions.y > camera.aspect) {
453
- const focal = view.domElement.clientHeight * 0.5 / Math.tan(verticalFOV * 0.5);
454
- const horizontalFOV = 2 * Math.atan(view.domElement.clientWidth * 0.5 / focal);
455
- cameraTransformOptions.range = dimensions.x / (2 * Math.tan(horizontalFOV * 0.5));
456
- } else {
457
- cameraTransformOptions.range = dimensions.y / (2 * Math.tan(verticalFOV * 0.5));
458
- }
459
- }
460
- return cameraTransformOptions;
461
- },
462
- /**
463
- * Apply transform to camera with animation
464
- *
465
- * @param {View} view The camera view
466
- * @param {Camera} camera The camera to animate
467
- * @param {CameraUtils~CameraTransformOptions} params The parameters
468
- * @return {Promise} promise with resolve final CameraUtils~CameraTransformOptions
469
- */
470
- animateCameraToLookAtTarget(view, camera) {
471
- let params = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
472
- params.proxy = params.proxy === undefined || params.proxy;
473
- const rig = getRig(camera);
474
- rig.stop(view);
475
- if (params.proxy) {
476
- rig.setProxy(view, camera);
477
- }
478
- return rig.animateCameraToLookAtTarget(view, camera, params).promise.then(finished => {
479
- const stopPlaceOnGround = params.stopPlaceOnGroundAtEnd === undefined ? this.defaultStopPlaceOnGroundAtEnd : params.stopPlaceOnGroundAtEnd;
480
- const newTransformation = rig.getParams();
481
- if (stopPlaceOnGround) {
482
- rig.stop(view);
483
- }
484
- newTransformation.finished = finished;
485
- return newTransformation;
486
- });
487
- },
488
- /**
489
- * chain animation transform to camera
490
- *
491
- * @param {View} view The camera view
492
- * @param {Camera} camera The camera to animate
493
- * @param {CameraUtils~CameraTransformOptions[]} params array parameters, each parameters transforms are apply to camera, in serial
494
- * @return {Promise} promise with resolve final CameraUtils~CameraTransformOptions
495
- */
496
- sequenceAnimationsToLookAtTarget(view, camera) {
497
- let params = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [{}];
498
- // convert each param to a function
499
- const funcs = params.map(param => () => this.animateCameraToLookAtTarget(view, camera, param));
500
-
501
- // execute Promises in serial
502
- return (funcs => funcs.reduce((promise, func) => promise.then(result => {
503
- const finished = result.length ? result[result.length - 1].finished : true;
504
- if (finished) {
505
- return func().then(Array.prototype.concat.bind(result));
506
- } else {
507
- return Promise.resolve([{
508
- finished: false
509
- }]);
510
- }
511
- }), Promise.resolve([])))(funcs);
512
- },
513
- /**
514
- * Gets the difference camera transformation
515
- *
516
- * @param {CameraUtils~CameraTransformOptions} first param to compare with the second
517
- * @param {CameraUtils~CameraTransformOptions} second param to compare with the first
518
- * @return {object} The difference parameters
519
- */
520
- getDiffParams(first, second) {
521
- if (!first || !second) {
522
- return;
523
- }
524
- let diff;
525
- if (Math.abs(first.range - second.range) / first.range > 0.001) {
526
- diff = diff || {};
527
- diff.range = {
528
- previous: first.range,
529
- new: second.range
530
- };
531
- }
532
- if (Math.abs(first.tilt - second.tilt) > 0.1) {
533
- diff = diff || {};
534
- diff.tilt = {
535
- previous: first.tilt,
536
- new: second.tilt
537
- };
538
- }
539
- if (Math.abs(first.heading - second.heading) > 0.1) {
540
- diff = diff || {};
541
- diff.heading = {
542
- previous: first.heading,
543
- new: second.heading
544
- };
545
- }
546
- if (Math.abs(first.coord.x - second.coord.x) > 0.000001 || Math.abs(first.coord.y - second.coord.y) > 0.000001) {
547
- diff = diff || {};
548
- diff.coord = {
549
- previous: first.coord,
550
- new: second.coord
551
- };
552
- }
553
- return diff;
554
- }
555
- };