itowns 2.45.1-next.0 → 2.45.1-next.1

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 (185) hide show
  1. package/dist/455.js +2 -0
  2. package/dist/455.js.map +1 -0
  3. package/dist/debug.js +3 -0
  4. package/dist/debug.js.LICENSE.txt +13 -0
  5. package/dist/debug.js.map +1 -0
  6. package/dist/itowns.js +3 -0
  7. package/dist/itowns.js.LICENSE.txt +5 -0
  8. package/dist/itowns.js.map +1 -0
  9. package/dist/itowns_lasparser.js +2 -0
  10. package/dist/itowns_lasparser.js.map +1 -0
  11. package/dist/itowns_lasworker.js +2 -0
  12. package/dist/itowns_lasworker.js.map +1 -0
  13. package/dist/itowns_potree2worker.js +2 -0
  14. package/dist/itowns_potree2worker.js.map +1 -0
  15. package/dist/itowns_widgets.js +2 -0
  16. package/dist/itowns_widgets.js.map +1 -0
  17. package/lib/Controls/FirstPersonControls.js +308 -0
  18. package/lib/Controls/FlyControls.js +175 -0
  19. package/lib/Controls/GlobeControls.js +1178 -0
  20. package/lib/Controls/PlanarControls.js +1025 -0
  21. package/lib/Controls/StateControl.js +432 -0
  22. package/lib/Controls/StreetControls.js +392 -0
  23. package/lib/Converter/Feature2Mesh.js +612 -0
  24. package/lib/Converter/Feature2Texture.js +174 -0
  25. package/lib/Converter/convertToTile.js +70 -0
  26. package/lib/Converter/textureConverter.js +43 -0
  27. package/lib/Core/3DTiles/C3DTBatchTable.js +131 -0
  28. package/lib/Core/3DTiles/C3DTBatchTableHierarchyExtension.js +96 -0
  29. package/lib/Core/3DTiles/C3DTBoundingVolume.js +156 -0
  30. package/lib/Core/3DTiles/C3DTExtensions.js +97 -0
  31. package/lib/Core/3DTiles/C3DTFeature.js +110 -0
  32. package/lib/Core/3DTiles/C3DTilesEnums.js +20 -0
  33. package/lib/Core/3DTiles/C3DTileset.js +99 -0
  34. package/lib/Core/3DTiles/utils/BinaryPropertyAccessor.js +100 -0
  35. package/lib/Core/AnimationPlayer.js +142 -0
  36. package/lib/Core/CopcNode.js +174 -0
  37. package/lib/Core/Deprecated/Undeprecator.js +74 -0
  38. package/lib/Core/EntwinePointTileNode.js +126 -0
  39. package/lib/Core/Feature.js +488 -0
  40. package/lib/Core/Geographic/GeoidGrid.js +108 -0
  41. package/lib/Core/Label.js +222 -0
  42. package/lib/Core/MainLoop.js +209 -0
  43. package/lib/Core/Picking.js +255 -0
  44. package/lib/Core/PointCloudNode.js +42 -0
  45. package/lib/Core/Potree2Node.js +206 -0
  46. package/lib/Core/Potree2PointAttributes.js +139 -0
  47. package/lib/Core/PotreeNode.js +101 -0
  48. package/lib/Core/Prefab/Globe/Atmosphere.js +293 -0
  49. package/lib/Core/Prefab/Globe/GlobeLayer.js +152 -0
  50. package/lib/Core/Prefab/Globe/GlobeTileBuilder.js +110 -0
  51. package/lib/Core/Prefab/Globe/SkyShader.js +78 -0
  52. package/lib/Core/Prefab/GlobeView.js +155 -0
  53. package/lib/Core/Prefab/Planar/PlanarLayer.js +59 -0
  54. package/lib/Core/Prefab/Planar/PlanarTileBuilder.js +71 -0
  55. package/lib/Core/Prefab/PlanarView.js +62 -0
  56. package/lib/Core/Prefab/TileBuilder.js +82 -0
  57. package/lib/Core/Prefab/computeBufferTileGeometry.js +248 -0
  58. package/lib/Core/Scheduler/Cache.js +17 -0
  59. package/lib/Core/Scheduler/CancelledCommandException.js +15 -0
  60. package/lib/Core/Scheduler/Scheduler.js +294 -0
  61. package/lib/Core/Style.js +660 -0
  62. package/lib/Core/StyleOptions.js +486 -0
  63. package/lib/Core/System/Capabilities.js +63 -0
  64. package/lib/Core/Tile/Tile.js +205 -0
  65. package/lib/Core/Tile/TileGrid.js +49 -0
  66. package/lib/Core/TileGeometry.js +124 -0
  67. package/lib/Core/TileMesh.js +108 -0
  68. package/lib/Core/View.js +1115 -0
  69. package/lib/Layer/C3DTilesLayer.js +459 -0
  70. package/lib/Layer/ColorLayer.js +154 -0
  71. package/lib/Layer/CopcLayer.js +63 -0
  72. package/lib/Layer/ElevationLayer.js +139 -0
  73. package/lib/Layer/EntwinePointTileLayer.js +71 -0
  74. package/lib/Layer/FeatureGeometryLayer.js +77 -0
  75. package/lib/Layer/GeoidLayer.js +80 -0
  76. package/lib/Layer/GeometryLayer.js +233 -0
  77. package/lib/Layer/InfoLayer.js +64 -0
  78. package/lib/Layer/LabelLayer.js +469 -0
  79. package/lib/Layer/Layer.js +335 -0
  80. package/lib/Layer/LayerUpdateState.js +89 -0
  81. package/lib/Layer/LayerUpdateStrategy.js +80 -0
  82. package/lib/Layer/OGC3DTilesLayer.js +543 -0
  83. package/lib/Layer/OrientedImageLayer.js +227 -0
  84. package/lib/Layer/PointCloudLayer.js +405 -0
  85. package/lib/Layer/Potree2Layer.js +171 -0
  86. package/lib/Layer/PotreeLayer.js +72 -0
  87. package/lib/Layer/RasterLayer.js +37 -0
  88. package/lib/Layer/ReferencingLayerProperties.js +62 -0
  89. package/lib/Layer/TiledGeometryLayer.js +459 -0
  90. package/lib/Loader/LASLoader.js +193 -0
  91. package/lib/Loader/Potree2BrotliLoader.js +261 -0
  92. package/lib/Loader/Potree2Loader.js +207 -0
  93. package/lib/Main.js +113 -0
  94. package/lib/MainBundle.js +4 -0
  95. package/lib/Parser/B3dmParser.js +174 -0
  96. package/lib/Parser/CameraCalibrationParser.js +94 -0
  97. package/lib/Parser/GDFParser.js +72 -0
  98. package/lib/Parser/GTXParser.js +75 -0
  99. package/lib/Parser/GeoJsonParser.js +212 -0
  100. package/lib/Parser/GpxParser.js +25 -0
  101. package/lib/Parser/ISGParser.js +71 -0
  102. package/lib/Parser/KMLParser.js +25 -0
  103. package/lib/Parser/LASParser.js +137 -0
  104. package/lib/Parser/MapBoxUrlParser.js +83 -0
  105. package/lib/Parser/PntsParser.js +131 -0
  106. package/lib/Parser/Potree2BinParser.js +92 -0
  107. package/lib/Parser/PotreeBinParser.js +106 -0
  108. package/lib/Parser/PotreeCinParser.js +29 -0
  109. package/lib/Parser/ShapefileParser.js +78 -0
  110. package/lib/Parser/VectorTileParser.js +215 -0
  111. package/lib/Parser/XbilParser.js +120 -0
  112. package/lib/Parser/deprecated/LegacyGLTFLoader.js +1386 -0
  113. package/lib/Parser/iGLTFLoader.js +168 -0
  114. package/lib/Process/3dTilesProcessing.js +304 -0
  115. package/lib/Process/FeatureProcessing.js +76 -0
  116. package/lib/Process/LayeredMaterialNodeProcessing.js +229 -0
  117. package/lib/Process/ObjectRemovalHelper.js +97 -0
  118. package/lib/Process/handlerNodeError.js +23 -0
  119. package/lib/Provider/3dTilesProvider.js +149 -0
  120. package/lib/Provider/DataSourceProvider.js +24 -0
  121. package/lib/Provider/Fetcher.js +233 -0
  122. package/lib/Provider/PointCloudProvider.js +45 -0
  123. package/lib/Provider/TileProvider.js +16 -0
  124. package/lib/Provider/URLBuilder.js +116 -0
  125. package/lib/Renderer/Camera.js +281 -0
  126. package/lib/Renderer/Color.js +56 -0
  127. package/lib/Renderer/ColorLayersOrdering.js +115 -0
  128. package/lib/Renderer/CommonMaterial.js +31 -0
  129. package/lib/Renderer/Label2DRenderer.js +192 -0
  130. package/lib/Renderer/LayeredMaterial.js +243 -0
  131. package/lib/Renderer/OBB.js +150 -0
  132. package/lib/Renderer/OrientedImageCamera.js +118 -0
  133. package/lib/Renderer/OrientedImageMaterial.js +167 -0
  134. package/lib/Renderer/PointsMaterial.js +485 -0
  135. package/lib/Renderer/RasterTile.js +243 -0
  136. package/lib/Renderer/RenderMode.js +31 -0
  137. package/lib/Renderer/Shader/ShaderChunk.js +160 -0
  138. package/lib/Renderer/Shader/ShaderUtils.js +47 -0
  139. package/lib/Renderer/SphereHelper.js +17 -0
  140. package/lib/Renderer/WebXR.js +51 -0
  141. package/lib/Renderer/c3DEngine.js +214 -0
  142. package/lib/Source/C3DTilesGoogleSource.js +74 -0
  143. package/lib/Source/C3DTilesIonSource.js +54 -0
  144. package/lib/Source/C3DTilesSource.js +30 -0
  145. package/lib/Source/CopcSource.js +126 -0
  146. package/lib/Source/EntwinePointTileSource.js +72 -0
  147. package/lib/Source/FileSource.js +188 -0
  148. package/lib/Source/OGC3DTilesGoogleSource.js +29 -0
  149. package/lib/Source/OGC3DTilesIonSource.js +34 -0
  150. package/lib/Source/OGC3DTilesSource.js +21 -0
  151. package/lib/Source/OrientedImageSource.js +59 -0
  152. package/lib/Source/Potree2Source.js +167 -0
  153. package/lib/Source/PotreeSource.js +82 -0
  154. package/lib/Source/Source.js +202 -0
  155. package/lib/Source/TMSSource.js +144 -0
  156. package/lib/Source/VectorTilesSource.js +182 -0
  157. package/lib/Source/WFSSource.js +170 -0
  158. package/lib/Source/WMSSource.js +167 -0
  159. package/lib/Source/WMTSSource.js +92 -0
  160. package/lib/ThreeExtended/capabilities/WebGL.js +69 -0
  161. package/lib/ThreeExtended/libs/ktx-parse.module.js +506 -0
  162. package/lib/ThreeExtended/libs/zstddec.module.js +29 -0
  163. package/lib/ThreeExtended/loaders/DDSLoader.js +200 -0
  164. package/lib/ThreeExtended/loaders/DRACOLoader.js +400 -0
  165. package/lib/ThreeExtended/loaders/GLTFLoader.js +2879 -0
  166. package/lib/ThreeExtended/loaders/KTX2Loader.js +709 -0
  167. package/lib/ThreeExtended/math/ColorSpaces.js +59 -0
  168. package/lib/ThreeExtended/utils/BufferGeometryUtils.js +846 -0
  169. package/lib/ThreeExtended/utils/WorkerPool.js +70 -0
  170. package/lib/Utils/CameraUtils.js +554 -0
  171. package/lib/Utils/DEMUtils.js +350 -0
  172. package/lib/Utils/FeaturesUtils.js +156 -0
  173. package/lib/Utils/Gradients.js +16 -0
  174. package/lib/Utils/ThreeUtils.js +115 -0
  175. package/lib/Utils/gui/C3DTilesStyle.js +218 -0
  176. package/lib/Utils/gui/Main.js +7 -0
  177. package/lib/Utils/gui/Minimap.js +152 -0
  178. package/lib/Utils/gui/Navigation.js +245 -0
  179. package/lib/Utils/gui/Scale.js +104 -0
  180. package/lib/Utils/gui/Searchbar.js +234 -0
  181. package/lib/Utils/gui/Widget.js +80 -0
  182. package/lib/Utils/placeObjectOnGround.js +136 -0
  183. package/lib/Worker/LASLoaderWorker.js +19 -0
  184. package/lib/Worker/Potree2Worker.js +21 -0
  185. package/package.json +2 -2
@@ -0,0 +1,392 @@
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;