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