itowns 2.44.3-next.9 → 2.45.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (214) hide show
  1. package/README.md +3 -129
  2. package/examples/3dtiles_loader.html +20 -6
  3. package/examples/config.json +1 -0
  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/jsm/.eslintrc.cjs +0 -38
  43. package/lib/Controls/FirstPersonControls.js +0 -308
  44. package/lib/Controls/FlyControls.js +0 -175
  45. package/lib/Controls/GlobeControls.js +0 -1162
  46. package/lib/Controls/PlanarControls.js +0 -1025
  47. package/lib/Controls/StateControl.js +0 -429
  48. package/lib/Controls/StreetControls.js +0 -392
  49. package/lib/Converter/Feature2Mesh.js +0 -615
  50. package/lib/Converter/Feature2Texture.js +0 -170
  51. package/lib/Converter/convertToTile.js +0 -75
  52. package/lib/Converter/textureConverter.js +0 -44
  53. package/lib/Core/3DTiles/C3DTBatchTable.js +0 -131
  54. package/lib/Core/3DTiles/C3DTBatchTableHierarchyExtension.js +0 -96
  55. package/lib/Core/3DTiles/C3DTBoundingVolume.js +0 -157
  56. package/lib/Core/3DTiles/C3DTExtensions.js +0 -97
  57. package/lib/Core/3DTiles/C3DTFeature.js +0 -110
  58. package/lib/Core/3DTiles/C3DTilesEnums.js +0 -20
  59. package/lib/Core/3DTiles/C3DTileset.js +0 -99
  60. package/lib/Core/3DTiles/utils/BinaryPropertyAccessor.js +0 -100
  61. package/lib/Core/AnimationPlayer.js +0 -142
  62. package/lib/Core/CopcNode.js +0 -174
  63. package/lib/Core/Deprecated/Undeprecator.js +0 -75
  64. package/lib/Core/EntwinePointTileNode.js +0 -126
  65. package/lib/Core/Feature.js +0 -490
  66. package/lib/Core/Geographic/CoordStars.js +0 -80
  67. package/lib/Core/Geographic/Coordinates.js +0 -320
  68. package/lib/Core/Geographic/Crs.js +0 -175
  69. package/lib/Core/Geographic/Extent.js +0 -534
  70. package/lib/Core/Geographic/GeoidGrid.js +0 -109
  71. package/lib/Core/Label.js +0 -222
  72. package/lib/Core/MainLoop.js +0 -211
  73. package/lib/Core/Math/Ellipsoid.js +0 -144
  74. package/lib/Core/Picking.js +0 -255
  75. package/lib/Core/PointCloudNode.js +0 -42
  76. package/lib/Core/Potree2Node.js +0 -206
  77. package/lib/Core/Potree2PointAttributes.js +0 -139
  78. package/lib/Core/PotreeNode.js +0 -101
  79. package/lib/Core/Prefab/Globe/Atmosphere.js +0 -299
  80. package/lib/Core/Prefab/Globe/BuilderEllipsoidTile.js +0 -110
  81. package/lib/Core/Prefab/Globe/GlobeLayer.js +0 -145
  82. package/lib/Core/Prefab/Globe/SkyShader.js +0 -78
  83. package/lib/Core/Prefab/GlobeView.js +0 -161
  84. package/lib/Core/Prefab/Planar/PlanarLayer.js +0 -53
  85. package/lib/Core/Prefab/Planar/PlanarTileBuilder.js +0 -72
  86. package/lib/Core/Prefab/PlanarView.js +0 -62
  87. package/lib/Core/Prefab/TileBuilder.js +0 -80
  88. package/lib/Core/Prefab/computeBufferTileGeometry.js +0 -183
  89. package/lib/Core/Scheduler/Cache.js +0 -256
  90. package/lib/Core/Scheduler/CancelledCommandException.js +0 -15
  91. package/lib/Core/Scheduler/Scheduler.js +0 -294
  92. package/lib/Core/Style.js +0 -1121
  93. package/lib/Core/System/Capabilities.js +0 -63
  94. package/lib/Core/Tile/Tile.js +0 -219
  95. package/lib/Core/Tile/TileGrid.js +0 -46
  96. package/lib/Core/TileGeometry.js +0 -40
  97. package/lib/Core/TileMesh.js +0 -109
  98. package/lib/Core/View.js +0 -1109
  99. package/lib/Layer/C3DTilesLayer.js +0 -456
  100. package/lib/Layer/ColorLayer.js +0 -128
  101. package/lib/Layer/CopcLayer.js +0 -58
  102. package/lib/Layer/ElevationLayer.js +0 -107
  103. package/lib/Layer/EntwinePointTileLayer.js +0 -64
  104. package/lib/Layer/FeatureGeometryLayer.js +0 -63
  105. package/lib/Layer/GeoidLayer.js +0 -80
  106. package/lib/Layer/GeometryLayer.js +0 -202
  107. package/lib/Layer/InfoLayer.js +0 -64
  108. package/lib/Layer/LabelLayer.js +0 -456
  109. package/lib/Layer/Layer.js +0 -304
  110. package/lib/Layer/LayerUpdateState.js +0 -89
  111. package/lib/Layer/LayerUpdateStrategy.js +0 -80
  112. package/lib/Layer/OGC3DTilesLayer.js +0 -412
  113. package/lib/Layer/OrientedImageLayer.js +0 -222
  114. package/lib/Layer/PointCloudLayer.js +0 -359
  115. package/lib/Layer/Potree2Layer.js +0 -164
  116. package/lib/Layer/PotreeLayer.js +0 -65
  117. package/lib/Layer/RasterLayer.js +0 -27
  118. package/lib/Layer/ReferencingLayerProperties.js +0 -62
  119. package/lib/Layer/TiledGeometryLayer.js +0 -403
  120. package/lib/Loader/LASLoader.js +0 -193
  121. package/lib/Loader/Potree2BrotliLoader.js +0 -261
  122. package/lib/Loader/Potree2Loader.js +0 -207
  123. package/lib/Main.js +0 -115
  124. package/lib/MainBundle.js +0 -4
  125. package/lib/Parser/B3dmParser.js +0 -174
  126. package/lib/Parser/CameraCalibrationParser.js +0 -94
  127. package/lib/Parser/GDFParser.js +0 -72
  128. package/lib/Parser/GTXParser.js +0 -75
  129. package/lib/Parser/GeoJsonParser.js +0 -212
  130. package/lib/Parser/GpxParser.js +0 -25
  131. package/lib/Parser/ISGParser.js +0 -71
  132. package/lib/Parser/KMLParser.js +0 -25
  133. package/lib/Parser/LASParser.js +0 -137
  134. package/lib/Parser/MapBoxUrlParser.js +0 -83
  135. package/lib/Parser/PntsParser.js +0 -131
  136. package/lib/Parser/Potree2BinParser.js +0 -92
  137. package/lib/Parser/PotreeBinParser.js +0 -106
  138. package/lib/Parser/PotreeCinParser.js +0 -29
  139. package/lib/Parser/ShapefileParser.js +0 -78
  140. package/lib/Parser/VectorTileParser.js +0 -202
  141. package/lib/Parser/XbilParser.js +0 -119
  142. package/lib/Parser/deprecated/LegacyGLTFLoader.js +0 -1386
  143. package/lib/Parser/iGLTFLoader.js +0 -168
  144. package/lib/Process/3dTilesProcessing.js +0 -304
  145. package/lib/Process/FeatureProcessing.js +0 -76
  146. package/lib/Process/LayeredMaterialNodeProcessing.js +0 -221
  147. package/lib/Process/ObjectRemovalHelper.js +0 -97
  148. package/lib/Process/handlerNodeError.js +0 -23
  149. package/lib/Provider/3dTilesProvider.js +0 -149
  150. package/lib/Provider/DataSourceProvider.js +0 -8
  151. package/lib/Provider/Fetcher.js +0 -229
  152. package/lib/Provider/PointCloudProvider.js +0 -45
  153. package/lib/Provider/TileProvider.js +0 -16
  154. package/lib/Provider/URLBuilder.js +0 -116
  155. package/lib/Renderer/Camera.js +0 -281
  156. package/lib/Renderer/Color.js +0 -56
  157. package/lib/Renderer/ColorLayersOrdering.js +0 -115
  158. package/lib/Renderer/CommonMaterial.js +0 -31
  159. package/lib/Renderer/Label2DRenderer.js +0 -190
  160. package/lib/Renderer/LayeredMaterial.js +0 -243
  161. package/lib/Renderer/OBB.js +0 -153
  162. package/lib/Renderer/OrientedImageCamera.js +0 -118
  163. package/lib/Renderer/OrientedImageMaterial.js +0 -167
  164. package/lib/Renderer/PointsMaterial.js +0 -485
  165. package/lib/Renderer/RasterTile.js +0 -209
  166. package/lib/Renderer/RenderMode.js +0 -31
  167. package/lib/Renderer/Shader/ShaderChunk.js +0 -160
  168. package/lib/Renderer/Shader/ShaderUtils.js +0 -47
  169. package/lib/Renderer/SphereHelper.js +0 -23
  170. package/lib/Renderer/WebXR.js +0 -51
  171. package/lib/Renderer/c3DEngine.js +0 -214
  172. package/lib/Source/C3DTilesGoogleSource.js +0 -74
  173. package/lib/Source/C3DTilesIonSource.js +0 -54
  174. package/lib/Source/C3DTilesSource.js +0 -30
  175. package/lib/Source/CopcSource.js +0 -115
  176. package/lib/Source/EntwinePointTileSource.js +0 -62
  177. package/lib/Source/FileSource.js +0 -189
  178. package/lib/Source/OGC3DTilesGoogleSource.js +0 -29
  179. package/lib/Source/OGC3DTilesIonSource.js +0 -34
  180. package/lib/Source/OGC3DTilesSource.js +0 -21
  181. package/lib/Source/OrientedImageSource.js +0 -59
  182. package/lib/Source/Potree2Source.js +0 -167
  183. package/lib/Source/PotreeSource.js +0 -82
  184. package/lib/Source/Source.js +0 -223
  185. package/lib/Source/TMSSource.js +0 -145
  186. package/lib/Source/VectorTilesSource.js +0 -178
  187. package/lib/Source/WFSSource.js +0 -168
  188. package/lib/Source/WMSSource.js +0 -133
  189. package/lib/Source/WMTSSource.js +0 -86
  190. package/lib/ThreeExtended/capabilities/WebGL.js +0 -69
  191. package/lib/ThreeExtended/libs/ktx-parse.module.js +0 -470
  192. package/lib/ThreeExtended/libs/zstddec.module.js +0 -29
  193. package/lib/ThreeExtended/loaders/DDSLoader.js +0 -200
  194. package/lib/ThreeExtended/loaders/DRACOLoader.js +0 -399
  195. package/lib/ThreeExtended/loaders/GLTFLoader.js +0 -2876
  196. package/lib/ThreeExtended/loaders/KTX2Loader.js +0 -625
  197. package/lib/ThreeExtended/utils/BufferGeometryUtils.js +0 -846
  198. package/lib/ThreeExtended/utils/WorkerPool.js +0 -70
  199. package/lib/Utils/CameraUtils.js +0 -555
  200. package/lib/Utils/DEMUtils.js +0 -350
  201. package/lib/Utils/FeaturesUtils.js +0 -156
  202. package/lib/Utils/Gradients.js +0 -16
  203. package/lib/Utils/OrientationUtils.js +0 -457
  204. package/lib/Utils/ThreeUtils.js +0 -115
  205. package/lib/Utils/gui/C3DTilesStyle.js +0 -215
  206. package/lib/Utils/gui/Main.js +0 -7
  207. package/lib/Utils/gui/Minimap.js +0 -154
  208. package/lib/Utils/gui/Navigation.js +0 -245
  209. package/lib/Utils/gui/Scale.js +0 -107
  210. package/lib/Utils/gui/Searchbar.js +0 -234
  211. package/lib/Utils/gui/Widget.js +0 -80
  212. package/lib/Utils/placeObjectOnGround.js +0 -137
  213. package/lib/Worker/LASLoaderWorker.js +0 -19
  214. package/lib/Worker/Potree2Worker.js +0 -21
@@ -1,392 +0,0 @@
1
- import TWEEN from '@tweenjs/tween.js';
2
- import * as THREE from 'three';
3
- import { MAIN_LOOP_EVENTS } from "../Core/MainLoop.js";
4
- import FirstPersonControls from "./FirstPersonControls.js";
5
- const material = new THREE.MeshBasicMaterial({
6
- color: 0xffffff,
7
- depthTest: false,
8
- transparent: true,
9
- opacity: 0.5
10
- });
11
- function createCircle() {
12
- const geomCircle = new THREE.CircleGeometry(1, 32);
13
- return new THREE.Mesh(geomCircle, material);
14
- }
15
- function createRectangle() {
16
- const geomPlane = new THREE.PlaneGeometry(4, 2, 1);
17
- const rectangle = new THREE.Mesh(geomPlane, material);
18
- rectangle.rotateX(-Math.PI * 0.5);
19
- return rectangle;
20
- }
21
-
22
- // update a surfaces node
23
- function updateSurfaces(surfaces, position, norm) {
24
- surfaces.position.copy(position);
25
- surfaces.up.copy(position).normalize();
26
- surfaces.lookAt(norm);
27
- surfaces.updateMatrixWorld(true);
28
- }
29
-
30
- // vector use in the pick method
31
- const target = new THREE.Vector3();
32
- const normal = new THREE.Vector3();
33
- const normalMatrix = new THREE.Matrix3();
34
- const up = new THREE.Vector3();
35
- const startQuaternion = new THREE.Quaternion();
36
- function pick(event, view, buildingsLayer) {
37
- let pickGround = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : () => {};
38
- let pickObject = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : () => {};
39
- let pickNothing = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : () => {};
40
- // get real distance to ground, with a specific method to pick on the elevation layer
41
- view.getPickingPositionFromDepth(view.eventToViewCoords(event), target);
42
- const distanceToGround = view.camera3D.position.distanceTo(target);
43
-
44
- // pick on building layer
45
- const buildings = buildingsLayer ? view.pickObjectsAt(event, -1, buildingsLayer) : [];
46
-
47
- // to detect pick on building, compare first picked building distance to ground distance
48
- if (buildings.length && buildings[0].distance < distanceToGround) {
49
- // pick buildings
50
- // callback
51
- normalMatrix.getNormalMatrix(buildings[0].object.matrixWorld);
52
- normal.copy(buildings[0].face.normal).applyNormalMatrix(normalMatrix);
53
- pickObject(buildings[0].point, normal);
54
- } else if (view.tileLayer) {
55
- const far = view.camera3D.far * 0.95;
56
- if (distanceToGround < far) {
57
- // compute normal
58
- if (view.tileLayer.isGlobeLayer) {
59
- up.copy(target).multiplyScalar(1.1);
60
- } else {
61
- up.set(0, 0, 1);
62
- }
63
-
64
- // callback
65
- pickGround(target, up);
66
- } else {
67
- // callback
68
- pickNothing();
69
- }
70
- } else {
71
- pickNothing();
72
- }
73
- }
74
-
75
- // default function to compute time (in millis), used for the animation to move to a distance (in meter)
76
- function computeTime(distance) {
77
- return 100 + Math.sqrt(distance) * 30;
78
- }
79
-
80
- /**
81
- * Camera controls that can follow a path.
82
- * It is used to simulate a street view.
83
- * It stores a currentPosition and nextPosition, and do a camera traveling to go to next position.
84
- * It also manages picking on the ground and on other object, like building.
85
- * <ul> It manages 2 surfaces, used as helpers for the end user :
86
- * <li> a circle is shown when mouse is moving on the ground </li>
87
- * <li> a rectangle is shown when mouse is moving on other 3d object </li>
88
- * </ul>
89
- * <ul>
90
- * This controls is designed
91
- * <li> to move forward when user click on the ground (click and go) </li>
92
- * <li> to rotate the camera when user click on other object (click to look at) </li>
93
- * </ul>
94
- * <ul> Bindings inherited from FirstPersonControls
95
- * <li><b> up + down keys : </b> forward/backward </li>
96
- * <li><b> left + right keys: </b> strafing movements </li>
97
- * <li><b> pageUp + pageDown: </b> vertical movements </li>
98
- * <li><b> mouse click+drag: </b> pitch and yaw movements (as looking at a panorama) </li>
99
- * </ul>
100
- * <ul> Bindings added
101
- * <li><b> keys Z : </b> Move camera to the next position </li>
102
- * <li><b> keys S : </b> Move camera to the previous position </li>
103
- * <li><b> keys A : </b> Set camera to current position and look at next position</li>
104
- * <li><b> keys Q : </b> Set camera to current position and look at previous position</li>
105
- * </ul>
106
- * Note that it only works in globe view.
107
- * @property {number} keyGoToNextPosition key code to go to next position, default to 90 for key Z
108
- * @property {number} keyGoToPreviousPosition key code to go to previous position, default to 83 for key S
109
- * @property {number} keySetCameraToCurrentPositionAndLookAtNext key code set camera to current position, default to 65 for key A
110
- * @property {number} keySetCameraToCurrentPositionAndLookAtPrevious key code set camera to current position, default to 81 for key Q
111
- * @extends FirstPersonControls
112
- */
113
- class StreetControls extends FirstPersonControls {
114
- /**
115
- * @param { View } view - View where this control will be used
116
- * @param { Object } options - Configuration of this controls
117
- * @param { number } [options.wallMaxDistance=1000] - Maximum distance to click on a wall, in meter.
118
- * @param { number } [options.animationDurationWall=200] - Time in millis for the animation when clicking on a wall.
119
- * @param { THREE.Mesh } [options.surfaceGround] - Surface helper to see when mouse is on the ground, default is a transparent circle.
120
- * @param { THREE.Mesh } [options.surfaceWall] - Surface helper to see when mouse is on a wall, default is a transparent rectangle.
121
- * @param { string } [options.buildingsLayer='Buildings'] - Name of the building layer (used to pick on wall).
122
- * @param { function } [options.computeTime] - Function to compute time (in millis), used for the animation to move to a distance (in meter)
123
- * @param { number } [options.offset=4] - Altitude in meter up to the ground to move to when click on a target on the ground.
124
- */
125
- constructor(view) {
126
- let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
127
- super(view, options);
128
- this.isStreetControls = true;
129
- this._onMouseOut = super.onMouseUp.bind(this);
130
- view.domElement.addEventListener('mouseout', this._onMouseOut);
131
-
132
- // two positions used by this control : current and next
133
- this.previousPosition = undefined;
134
- this.currentPosition = undefined;
135
- this.nextPosition = undefined;
136
- this.keyGoToNextPosition = 90;
137
- this.keyGoToPreviousPosition = 83;
138
- this.keySetCameraToCurrentPositionAndLookAtNext = 65;
139
- this.keySetCameraToCurrentPositionAndLookAtPrevious = 81;
140
-
141
- // Tween is used to make smooth animations
142
- this.tweenGroup = new TWEEN.Group();
143
-
144
- // init surfaces used as helper for end user
145
- this.surfaceGround = options.surfaceGround || createCircle();
146
- this.surfaceWall = options.surfaceWall || createRectangle();
147
-
148
- // surfaces is an object3D containing the two surfaces
149
- this.surfaces = new THREE.Object3D();
150
- this.surfaces.add(this.surfaceGround);
151
- this.surfaces.add(this.surfaceWall);
152
- this.view.scene.add(this.surfaces);
153
- this.wallMaxDistance = options.wallMaxDistance || 1000;
154
- this.animationDurationWall = options.animationDurationWall || 200;
155
- this.buildingsLayer = options.buildingsLayer;
156
- this.computeTime = options.computeTime || computeTime;
157
- this.offset = options.offset || 4;
158
- this.transformationPositionPickOnTheGround = options.transformationPositionPickOnTheGround || (position => position);
159
- this.end = this.camera.clone();
160
- }
161
- setCurrentPosition(newCurrentPosition) {
162
- this.currentPosition = newCurrentPosition;
163
- }
164
- setNextPosition(newNextPosition) {
165
- this.nextPosition = newNextPosition;
166
- }
167
- setPreviousPosition(newPreviousPosition) {
168
- this.previousPosition = newPreviousPosition;
169
- }
170
- onMouseUp(event) {
171
- if (this.enabled == false) {
172
- return;
173
- }
174
- super.onMouseUp();
175
- if (this._stateOnMouseDrag) {
176
- this._stateOnMouseDrag = false;
177
- } else {
178
- pick(event, this.view, this.buildingsLayer, this.onClickOnGround.bind(this), this.onClickOnWall.bind(this));
179
- }
180
- }
181
- onMouseMove(event) {
182
- if (this.enabled == false) {
183
- return;
184
- }
185
- super.onMouseMove(event);
186
- if (this._isMouseDown) {
187
- // state mouse drag (move + mouse click)
188
- this._stateOnMouseDrag = true;
189
- this.stopAnimations();
190
- } else if (!this.tween) {
191
- // mouse pick and manage surfaces
192
- pick(event, this.view, this.buildingsLayer, (groundTarget, normal) => {
193
- updateSurfaces(this.surfaces, groundTarget, normal);
194
- this.surfaceGround.visible = true;
195
- this.surfaceWall.visible = false;
196
- }, (wallTarget, normal) => {
197
- updateSurfaces(this.surfaces, wallTarget, normal);
198
- this.surfaceWall.visible = true;
199
- this.surfaceGround.visible = false;
200
- });
201
- this.view.notifyChange(this.surfaces);
202
- }
203
- }
204
-
205
- /**
206
- * Sets the camera to the current position (stored in this controls), looking at the next position (also stored in this controls).
207
- *
208
- * @param { boolean } lookAtPrevious look at the previous position rather than the next one
209
- */
210
- setCameraToCurrentPosition(lookAtPrevious) {
211
- if (lookAtPrevious) {
212
- this.setCameraOnPosition(this.currentPosition, this.previousPosition);
213
- } else {
214
- this.setCameraOnPosition(this.currentPosition, this.nextPosition);
215
- }
216
- }
217
-
218
- /**
219
- * Set the camera on a position, looking at another position.
220
- *
221
- * @param { THREE.Vector3 } position The position to set the camera
222
- * @param { THREE.Vector3 } lookAt The position where the camera look at.
223
- */
224
- setCameraOnPosition(position, lookAt) {
225
- if (!position || !lookAt) {
226
- return;
227
- }
228
- this.camera.position.copy(position);
229
- if (this.view.tileLayer && this.view.tileLayer.isGlobeLayer) {
230
- this.camera.up.copy(position).normalize();
231
- } else {
232
- this.camera.up.set(0, 0, 1);
233
- }
234
- this.camera.lookAt(lookAt);
235
- this.camera.updateMatrixWorld();
236
- this.reset();
237
- }
238
-
239
- /**
240
- * Method called when user click on the ground.</br>
241
- * Note that this funtion contains default values that can be overrided, by overriding this class.
242
- *
243
- * @param {THREE.Vector3} position - The position
244
- */
245
- onClickOnGround(position) {
246
- position = this.transformationPositionPickOnTheGround(position);
247
- if (this.view.tileLayer && this.view.tileLayer.isGlobeLayer) {
248
- up.copy(position).normalize();
249
- } else {
250
- up.set(0, 0, 1);
251
- }
252
- position.add(up.multiplyScalar(this.offset));
253
-
254
- // compute time to go there
255
- const distance = this.camera.position.distanceTo(position);
256
- // 500 millis constant, plus an amount of time depending of the distance (but not linearly)
257
- const time = this.computeTime(distance);
258
-
259
- // move the camera
260
- this.moveCameraTo(position, time);
261
- }
262
-
263
- /**
264
- * Method called when user click on oject that is not the ground.</br>
265
- * Note that this function contains default values that can be overrided, by overriding this class.
266
- *
267
- * @param {THREE.Vector3} position - The position
268
- */
269
- onClickOnWall(position) {
270
- const distance = this.camera.position.distanceTo(position);
271
-
272
- // can't click on a wall that is at 1km distance.
273
- if (distance < this.wallMaxDistance) {
274
- this.animateCameraLookAt(position, this.animationDurationWall);
275
- }
276
- }
277
-
278
- /**
279
- * Animate the camera to make it look at a position, in a given time
280
- *
281
- * @param { THREE.Vector3 } position - Position to look at
282
- * @param { number } time - Time in millisecond
283
- */
284
- animateCameraLookAt(position, time) {
285
- // stop existing animation
286
- this.stopAnimations();
287
- // prepare start point and end point
288
- startQuaternion.copy(this.camera.quaternion);
289
- this.end.copy(this.camera);
290
- this.end.lookAt(position);
291
- this.tween = new TWEEN.Tween({
292
- t: 0
293
- }).to({
294
- t: 1
295
- }, time).easing(TWEEN.Easing.Quadratic.Out).onComplete(() => {
296
- this.stopAnimations();
297
- }).onUpdate(d => {
298
- // 'manually' slerp the Quaternion to avoid rotation issues
299
- this.camera.quaternion.slerpQuaternions(startQuaternion, this.end.quaternion, d.t);
300
- }).start();
301
- this.tweenGroup.add(this.tween);
302
- this.animationFrameRequester = () => {
303
- this.tweenGroup.update();
304
- // call reset from super class FirsPersonControls to make mouse rotation managed by FirstPersonControl still aligned
305
- this.reset();
306
- this.view.notifyChange(this.camera);
307
- };
308
- this.view.addFrameRequester(MAIN_LOOP_EVENTS.BEFORE_RENDER, this.animationFrameRequester);
309
- this.view.notifyChange(this.camera);
310
- }
311
-
312
- /**
313
- * Move the camera smoothly to the position, in a given time.
314
- *
315
- * @param { THREE.Vector3 } position - Destination of the movement.
316
- * @param { number } time - Time in millisecond
317
- * @return { Promise }
318
- */
319
- moveCameraTo(position) {
320
- let time = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 50;
321
- if (!position) {
322
- return Promise.resolve();
323
- }
324
- let resolve;
325
- const promise = new Promise(r => {
326
- resolve = r;
327
- });
328
- this.stopAnimations();
329
- this.tween = new TWEEN.Tween(this.camera.position) // Create a new tween that modifies camera position
330
- .to(position.clone(), time).easing(TWEEN.Easing.Quadratic.Out) // Use an easing function to make the animation smooth.
331
- .onComplete(() => {
332
- this.stopAnimations();
333
- resolve();
334
- }).start();
335
- this.tweenGroup.add(this.tween);
336
- this.animationFrameRequester = () => {
337
- this.tweenGroup.update();
338
- this.view.notifyChange(this.camera);
339
- };
340
- this.view.addFrameRequester(MAIN_LOOP_EVENTS.BEFORE_RENDER, this.animationFrameRequester);
341
- this.view.notifyChange(this.camera);
342
- return promise;
343
- }
344
- stopAnimations() {
345
- if (this.tween) {
346
- this.tween.stop();
347
- this.tween = undefined;
348
- this.tweenGroup.removeAll();
349
- }
350
- if (this.animationFrameRequester) {
351
- this.view.removeFrameRequester(MAIN_LOOP_EVENTS.BEFORE_RENDER, this.animationFrameRequester);
352
- this.animationFrameRequester = null;
353
- }
354
- }
355
-
356
- /**
357
- * Move the camera to the 'currentPosition' stored in this control.
358
- */
359
- moveCameraToCurrentPosition() {
360
- this.moveCameraTo(this.currentPosition);
361
- }
362
- onKeyDown(e) {
363
- if (this.enabled == false) {
364
- return;
365
- }
366
- super.onKeyDown(e);
367
-
368
- // key to move to next position (default to Z)
369
- if (e.keyCode == this.keyGoToNextPosition) {
370
- this.moveCameraTo(this.nextPosition);
371
- }
372
- // key to move to previous position (default to S)
373
- if (e.keyCode == this.keyGoToPreviousPosition) {
374
- this.moveCameraTo(this.previousPosition);
375
- }
376
- // key to set to camera to current position looking at next position (default to A)
377
- if (e.keyCode == this.keySetCameraToCurrentPositionAndLookAtNext) {
378
- this.setCameraToCurrentPosition();
379
- this.view.notifyChange(this.view.camera3D);
380
- }
381
- // key to set to camera to current position looking at previous position (default to Q)
382
- if (e.keyCode == this.keySetCameraToCurrentPositionAndLookAtPrevious) {
383
- this.setCameraToCurrentPosition(true);
384
- this.view.notifyChange(this.view.camera3D);
385
- }
386
- }
387
- dispose() {
388
- this.view.domElement.removeEventListener('mouseout', this._onMouseOut, false);
389
- super.dispose();
390
- }
391
- }
392
- export default StreetControls;