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
package/lib/Core/Label.js DELETED
@@ -1,222 +0,0 @@
1
- import * as THREE from 'three';
2
- import DEMUtils from "../Utils/DEMUtils.js";
3
- import Coordinates from "./Geographic/Coordinates.js";
4
- const coord = new Coordinates('EPSG:4326');
5
- let rect;
6
-
7
- // set it once
8
- let STYLE_TRANSFORM = '';
9
- if (document.documentElement.style.transform !== undefined) {
10
- STYLE_TRANSFORM = 'transform';
11
- } else if (document.documentElement.style.webkitTransform !== undefined) {
12
- STYLE_TRANSFORM = 'webkitTransform';
13
- } else if (document.documentElement.style.mozTransform !== undefined) {
14
- STYLE_TRANSFORM = 'mozTransform';
15
- } else if (document.documentElement.style.oTransform !== undefined) {
16
- STYLE_TRANSFORM = 'oTransform';
17
- } else {
18
- STYLE_TRANSFORM = 'transform';
19
- }
20
-
21
- /**
22
- * An object that handles the display of a text and/or an icon, linked to a 3D
23
- * position. The content of the `Label` is managed through a DOM object, in a
24
- * `<div>` handled by the `Label2DRenderer`.
25
- *
26
- * @property {boolean} isLabel - Used to checkout whether this object is a
27
- * Label. Default is true. You should not change this, as it is used internally
28
- * for optimisation.
29
- * @property {Element} content - The DOM object that contains the content of the
30
- * label. The style and the position are applied on this object. All labels
31
- * contain the `itowns-label` class, as well as a specific class related to the
32
- * layer linked to it: `itowns-label-[layer-id]` (replace `[layer-id]` by the
33
- * correct string).
34
- * @property {THREE.Vector3} position - The position in the 3D world of the
35
- * label.
36
- * @property {number} padding - sets the padding area on all four sides of an element at once.
37
- * @property {Coordinates} coordinates - The coordinates of the label.
38
- * @property {number} order - Order of the label that will be read from the
39
- * style. It helps sorting and prioritizing a Label during render.
40
- */
41
- class Label extends THREE.Object3D {
42
- /**
43
- * @param {Element|string} content - The content; can be a
44
- * string, with or without HTML tags in it, or it can be an Element.
45
- * @param {Coordinates} coordinates - The world coordinates, where to place
46
- * the Label.
47
- * @param {Style} style - The style to apply to the content. Once the style
48
- * is applied, it cannot be changed directly. However, if it really needed,
49
- * it can be accessed through `label.content.style`, but it is highly
50
- * discouraged to do so.
51
- */
52
- constructor() {
53
- let content = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
54
- let coordinates = arguments.length > 1 ? arguments[1] : undefined;
55
- let style = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
56
- if (coordinates == undefined) {
57
- throw new Error('coordinates are mandatory to add a Label');
58
- }
59
- if (arguments.length > 3) {
60
- console.warn('Deprecated argument sprites in Label constructor. Sprites must be configured in style argument.');
61
- }
62
- super();
63
- let _visible = this.visible;
64
- // can't do an ES6 setter/getter here
65
- Object.defineProperty(this, 'visible', {
66
- set(v) {
67
- if (v != _visible) {
68
- // avoid changing the style
69
- _visible = v;
70
- this.content.style.display = v ? 'block' : 'none';
71
- // TODO: add smooth transition for fade in/out
72
- }
73
- },
74
- get() {
75
- return _visible;
76
- }
77
- });
78
- this.isLabel = true;
79
- this.coordinates = coordinates;
80
- this.projectedPosition = {
81
- x: 0,
82
- y: 0
83
- };
84
- this.boundaries = {
85
- left: 0,
86
- right: 0,
87
- top: 0,
88
- bottom: 0
89
- };
90
- if (typeof content === 'string') {
91
- this.content = document.createElement('div');
92
- this.content.textContent = style.text.field;
93
- } else {
94
- this.content = content.cloneNode(true);
95
- }
96
- this.content.classList.add('itowns-label');
97
- this.content.style.userSelect = 'none';
98
- this.content.style.position = 'absolute';
99
- if (style.isStyle) {
100
- this.anchor = style.getTextAnchorPosition();
101
- this.styleOffset = style.text.offset;
102
- if (typeof content === 'string') {
103
- if (style.text.haloWidth > 0) {
104
- this.content.classList.add('itowns-stroke-single');
105
- }
106
- style.applyToHTML(this.content).then(icon => {
107
- if (icon) {
108
- // Not sure if that test is needed...
109
- this.icon = icon;
110
- }
111
- });
112
- }
113
- } else {
114
- this.anchor = [0, 0];
115
- this.styleOffset = [0, 0];
116
- }
117
- this.iconOffset = {
118
- left: 0,
119
- right: 0,
120
- top: 0,
121
- bottom: 0
122
- };
123
- this.zoom = {
124
- min: style.zoom && style.zoom.min != undefined ? style.zoom.min : 2,
125
- max: style.zoom && style.zoom.max != undefined ? style.zoom.max : 24
126
- };
127
- this.order = style.order || 0;
128
- // Padding value, to avoid labels being too close to each other.
129
- this.padding = 2;
130
- }
131
-
132
- /**
133
- * Moves a label on the screen, using screen coordinates. It updates the
134
- * boundaries as it moves it.
135
- *
136
- * @param {number} x - X coordinates in pixels, from left.
137
- * @param {number} y - Y coordinates in pixels, from top.
138
- */
139
- updateProjectedPosition(x, y) {
140
- const X = Math.round(x);
141
- const Y = Math.round(y);
142
- if (X != this.projectedPosition.x || Y != this.projectedPosition.y) {
143
- this.projectedPosition.x = X;
144
- this.projectedPosition.y = Y;
145
- this.boundaries.left = x + this.offset.left - this.padding;
146
- this.boundaries.right = x + this.offset.right + this.padding;
147
- this.boundaries.top = y + this.offset.top - this.padding;
148
- this.boundaries.bottom = y + this.offset.bottom + this.padding;
149
-
150
- // The boundaries of the label are the union of the boundaries of the text
151
- // and the boundaries of the icon, if it exists.
152
- // Checking if this.icon is not only zeros is mandatory, to prevent case
153
- // when a boundary is set to x or y coordinate
154
- if (this.iconOffset.left !== 0 || this.iconOffset.right !== 0 || this.iconOffset.top !== 0 || this.iconOffset.bottom !== 0) {
155
- this.boundaries.left = Math.min(this.boundaries.left, x + this.iconOffset.left);
156
- this.boundaries.right = Math.max(this.boundaries.right, x + this.iconOffset.right);
157
- this.boundaries.top = Math.min(this.boundaries.top, y + this.iconOffset.top);
158
- this.boundaries.bottom = Math.max(this.boundaries.bottom, y + this.iconOffset.bottom);
159
- }
160
- }
161
- }
162
- updateCSSPosition() {
163
- // translate all content according to its given anchor
164
- this.content.style[STYLE_TRANSFORM] = `translate(${this.projectedPosition.x + this.offset.left}px, ${this.projectedPosition.y + this.offset.top}px)`;
165
-
166
- // translate possible icon inside content to cancel anchoring on it, so that it can later be positioned
167
- // according to its own anchor
168
- if (this.icon) {
169
- this.icon.style[STYLE_TRANSFORM] = `translate(${-this.offset.left}px, ${-this.offset.top}px)`;
170
- }
171
- }
172
-
173
- /**
174
- * Updates the screen dimensions of the label, using
175
- * `getBoundingClientRect`. It updates `width` and `height` property of the
176
- * label, and the boundaries.
177
- */
178
- initDimensions() {
179
- if (!this.offset) {
180
- rect = this.content.getBoundingClientRect();
181
- const width = Math.round(rect.width);
182
- const height = Math.round(rect.height);
183
- this.offset = {
184
- left: width * this.anchor[0] + this.styleOffset[0],
185
- top: height * this.anchor[1] + this.styleOffset[1]
186
- };
187
- this.offset.right = this.offset.left + width;
188
- this.offset.bottom = this.offset.top + height;
189
- if (this.icon) {
190
- rect = this.icon.getBoundingClientRect();
191
- this.iconOffset = {
192
- left: Math.floor(rect.x),
193
- top: Math.floor(rect.y),
194
- right: Math.ceil(rect.x + rect.width),
195
- bottom: Math.ceil(rect.y + rect.height)
196
- };
197
- }
198
- }
199
- }
200
- update3dPosition(crs) {
201
- this.coordinates.as(crs, coord).toVector3(this.position);
202
- this.updateMatrixWorld();
203
- }
204
- updateElevationFromLayer(layer, nodes) {
205
- if (layer.attachedLayers.filter(l => l.isElevationLayer).length == 0) {
206
- return;
207
- }
208
- let elevation = Math.max(0, DEMUtils.getElevationValueAt(layer, this.coordinates, DEMUtils.FAST_READ_Z, nodes));
209
- if (isNaN(elevation)) {
210
- elevation = Math.max(0, DEMUtils.getElevationValueAt(layer, this.coordinates, DEMUtils.FAST_READ_Z));
211
- }
212
- if (!isNaN(elevation) && elevation != this.coordinates.z) {
213
- this.coordinates.z = elevation;
214
- }
215
- }
216
- updateHorizonCullingPoint() {
217
- if (this.horizonCullingPoint) {
218
- this.getWorldPosition(this.horizonCullingPoint);
219
- }
220
- }
221
- }
222
- export default Label;
@@ -1,209 +0,0 @@
1
- import { EventDispatcher } from 'three';
2
- export const RENDERING_PAUSED = 0;
3
- export const RENDERING_SCHEDULED = 1;
4
-
5
- /**
6
- * MainLoop's update events list that are fired using
7
- * {@link View#execFrameRequesters}.
8
- *
9
- * @property UPDATE_START {string} fired at the start of the update
10
- * @property BEFORE_CAMERA_UPDATE {string} fired before the camera update
11
- * @property AFTER_CAMERA_UPDATE {string} fired after the camera update
12
- * @property BEFORE_LAYER_UPDATE {string} fired before the layer update
13
- * @property AFTER_LAYER_UPDATE {string} fired after the layer update
14
- * @property BEFORE_RENDER {string} fired before the render
15
- * @property AFTER_RENDER {string} fired after the render
16
- * @property UPDATE_END {string} fired at the end of the update
17
- */
18
-
19
- export const MAIN_LOOP_EVENTS = {
20
- UPDATE_START: 'update_start',
21
- BEFORE_CAMERA_UPDATE: 'before_camera_update',
22
- AFTER_CAMERA_UPDATE: 'after_camera_update',
23
- BEFORE_LAYER_UPDATE: 'before_layer_update',
24
- AFTER_LAYER_UPDATE: 'after_layer_update',
25
- BEFORE_RENDER: 'before_render',
26
- AFTER_RENDER: 'after_render',
27
- UPDATE_END: 'update_end'
28
- };
29
- function updateElements(context, geometryLayer, elements) {
30
- if (!elements) {
31
- return;
32
- }
33
- for (const element of elements) {
34
- // update element
35
- // TODO find a way to notify attachedLayers when geometryLayer deletes some elements
36
- // and then update Debug.js:addGeometryLayerDebugFeatures
37
- const newElementsToUpdate = geometryLayer.update(context, geometryLayer, element);
38
- const sub = geometryLayer.getObjectToUpdateForAttachedLayers(element);
39
- if (sub) {
40
- if (sub.element) {
41
- // update attached layers
42
- for (const attachedLayer of geometryLayer.attachedLayers) {
43
- if (attachedLayer.ready) {
44
- attachedLayer.update(context, attachedLayer, sub.element, sub.parent);
45
- }
46
- }
47
- } else if (sub.elements) {
48
- for (let i = 0; i < sub.elements.length; i++) {
49
- if (!sub.elements[i].isObject3D) {
50
- throw new Error(`
51
- Invalid object for attached layer to update.
52
- Must be a THREE.Object and have a THREE.Material`);
53
- }
54
- // update attached layers
55
- for (const attachedLayer of geometryLayer.attachedLayers) {
56
- if (attachedLayer.ready) {
57
- attachedLayer.update(context, attachedLayer, sub.elements[i], sub.parent);
58
- }
59
- }
60
- }
61
- }
62
- }
63
- updateElements(context, geometryLayer, newElementsToUpdate);
64
- }
65
- }
66
- function filterChangeSources(updateSources, geometryLayer) {
67
- let fullUpdate = false;
68
- const filtered = new Set();
69
- updateSources.forEach(src => {
70
- if (src === geometryLayer || src.isCamera) {
71
- geometryLayer.info.clear();
72
- fullUpdate = true;
73
- } else if (src.layer === geometryLayer) {
74
- filtered.add(src);
75
- }
76
- });
77
- return fullUpdate ? new Set([geometryLayer]) : filtered;
78
- }
79
- class MainLoop extends EventDispatcher {
80
- #needsRedraw = false;
81
- #updateLoopRestarted = true;
82
- #lastTimestamp = 0;
83
- constructor(scheduler, engine) {
84
- super();
85
- this.renderingState = RENDERING_PAUSED;
86
- this.scheduler = scheduler;
87
- this.gfxEngine = engine; // TODO: remove me
88
- }
89
- scheduleViewUpdate(view, forceRedraw) {
90
- this.#needsRedraw |= forceRedraw;
91
- if (this.renderingState !== RENDERING_SCHEDULED) {
92
- this.renderingState = RENDERING_SCHEDULED;
93
- // TODO Fix asynchronization between xr and MainLoop render loops.
94
- // WebGLRenderer#setAnimationLoop must be used for WebXR projects.
95
- // (see WebXR#initializeWebXR).
96
- if (!this.gfxEngine.renderer.xr.isPresenting) {
97
- requestAnimationFrame(timestamp => {
98
- this.step(view, timestamp);
99
- });
100
- }
101
- }
102
- }
103
- #update(view, updateSources, dt) {
104
- const context = {
105
- camera: view.camera,
106
- engine: this.gfxEngine,
107
- scheduler: this.scheduler,
108
- view
109
- };
110
-
111
- // replace layer with their parent where needed
112
- updateSources.forEach(src => {
113
- const layer = src.layer || src;
114
- if (layer.isLayer && layer.parent) {
115
- updateSources.add(layer.parent);
116
- }
117
- });
118
- for (const geometryLayer of view.getLayers((x, y) => !y)) {
119
- context.geometryLayer = geometryLayer;
120
- if (geometryLayer.ready && geometryLayer.visible && !geometryLayer.frozen) {
121
- view.execFrameRequesters(MAIN_LOOP_EVENTS.BEFORE_LAYER_UPDATE, dt, this.#updateLoopRestarted, geometryLayer);
122
-
123
- // Filter updateSources that are relevant for the geometryLayer
124
- const srcs = filterChangeSources(updateSources, geometryLayer);
125
- if (srcs.size > 0) {
126
- // pre update attached layer
127
- for (const attachedLayer of geometryLayer.attachedLayers) {
128
- if (attachedLayer.ready && attachedLayer.preUpdate) {
129
- attachedLayer.preUpdate(context, srcs);
130
- }
131
- }
132
- // `preUpdate` returns an array of elements to update
133
- const elementsToUpdate = geometryLayer.preUpdate(context, srcs);
134
- // `update` is called in `updateElements`.
135
- updateElements(context, geometryLayer, elementsToUpdate);
136
- // `postUpdate` is called when this geom layer update process is finished
137
- geometryLayer.postUpdate(context, geometryLayer, updateSources);
138
- }
139
-
140
- // Clear the cache of expired resources
141
-
142
- view.execFrameRequesters(MAIN_LOOP_EVENTS.AFTER_LAYER_UPDATE, dt, this.#updateLoopRestarted, geometryLayer);
143
- }
144
- }
145
- }
146
- step(view, timestamp) {
147
- const dt = timestamp - this.#lastTimestamp;
148
- view._executeFrameRequestersRemovals();
149
- view.execFrameRequesters(MAIN_LOOP_EVENTS.UPDATE_START, dt, this.#updateLoopRestarted);
150
- const willRedraw = this.#needsRedraw;
151
- this.#lastTimestamp = timestamp;
152
-
153
- // Reset internal state before calling _update (so future calls to View.notifyChange()
154
- // can properly change it)
155
- this.#needsRedraw = false;
156
- this.renderingState = RENDERING_PAUSED;
157
- const updateSources = new Set(view._changeSources);
158
- view._changeSources.clear();
159
-
160
- // update camera
161
- const dim = this.gfxEngine.getWindowSize();
162
- view.execFrameRequesters(MAIN_LOOP_EVENTS.BEFORE_CAMERA_UPDATE, dt, this.#updateLoopRestarted);
163
- view.camera.update(dim.x, dim.y);
164
- view.execFrameRequesters(MAIN_LOOP_EVENTS.AFTER_CAMERA_UPDATE, dt, this.#updateLoopRestarted);
165
-
166
- // Disable camera's matrix auto update to make sure the camera's
167
- // world matrix is never updated mid-update.
168
- // Otherwise inconsistencies can appear because object visibility
169
- // testing and object drawing could be performed using different
170
- // camera matrixWorld.
171
- // Note: this is required at least because WEBGLRenderer calls
172
- // camera.updateMatrixWorld()
173
- const oldAutoUpdate = view.camera3D.matrixAutoUpdate;
174
- view.camera3D.matrixAutoUpdate = false;
175
-
176
- // update data-structure
177
- this.#update(view, updateSources, dt);
178
- if (this.scheduler.commandsWaitingExecutionCount() == 0) {
179
- this.dispatchEvent({
180
- type: 'command-queue-empty'
181
- });
182
- }
183
-
184
- // Redraw *only* if needed.
185
- // (redraws only happen when this.#needsRedraw is true, which in turn only happens when
186
- // view.notifyChange() is called with redraw=true)
187
- // As such there's no continuous update-loop, instead we use a ad-hoc update/render
188
- // mechanism.
189
- if (willRedraw) {
190
- this.#renderView(view, dt);
191
- }
192
-
193
- // next time, we'll consider that we've just started the loop if we are still PAUSED now
194
- this.#updateLoopRestarted = this.renderingState === RENDERING_PAUSED;
195
- view.camera3D.matrixAutoUpdate = oldAutoUpdate;
196
- view.execFrameRequesters(MAIN_LOOP_EVENTS.UPDATE_END, dt, this.#updateLoopRestarted);
197
- }
198
- #renderView(view, dt) {
199
- view.execFrameRequesters(MAIN_LOOP_EVENTS.BEFORE_RENDER, dt, this.#updateLoopRestarted);
200
- if (view.render) {
201
- view.render();
202
- } else {
203
- // use default rendering method
204
- this.gfxEngine.renderView(view);
205
- }
206
- view.execFrameRequesters(MAIN_LOOP_EVENTS.AFTER_RENDER, dt, this.#updateLoopRestarted);
207
- }
208
- }
209
- export default MainLoop;
@@ -1,185 +0,0 @@
1
- import * as THREE from 'three';
2
- import proj4 from 'proj4';
3
- import Coordinates from "../Geographic/Coordinates.js";
4
-
5
- /**
6
- * Length of the semi-axes of the WGS84 ellipsoid.
7
- * @internal
8
- */
9
- export const ellipsoidSizes = new THREE.Vector3(proj4.WGS84.a, proj4.WGS84.a, proj4.WGS84.b);
10
- const normal = new THREE.Vector3();
11
- class Ellipsoid {
12
- /**
13
- * Length of the semi-axes of the ellipsoid.
14
- */
15
-
16
- /**
17
- * Eccentricity of the ellipsoid.
18
- */
19
-
20
- /**
21
- * @param size - Length of the semi-axes of the ellipsoid. Defaults to those
22
- * defined by the WGS84 ellipsoid.
23
- */
24
- constructor() {
25
- let size = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ellipsoidSizes;
26
- this.size = new THREE.Vector3();
27
- this._radiiSquared = new THREE.Vector3();
28
- this._invRadiiSquared = new THREE.Vector3();
29
- this.eccentricity = 0;
30
- this.setSize(size);
31
- }
32
-
33
- /**
34
- * Computes the normal vector to an ellipsoid at the given cartesian
35
- * coordinate `(x, y, z)`.
36
- *
37
- * @param cartesian - The given cartesian coordinate.
38
- * @param target - An object to store this vector to. If this is not
39
- * specified, a new vector will be created.
40
- */
41
- geodeticSurfaceNormal(cartesian) {
42
- let target = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : new THREE.Vector3();
43
- return cartesian.toVector3(target).multiply(this._invRadiiSquared).normalize();
44
- }
45
-
46
- /**
47
- * Computes the normal vector to an ellipsoid at the given geographic
48
- * coordinate `(longitude, latitude, altitude)`.
49
- *
50
- * @param coordCarto - The given geographic coordinate.
51
- * @param target - An object to store this vector to. If this is not
52
- * specified, a new vector will be created.
53
- */
54
- geodeticSurfaceNormalCartographic(coordCarto) {
55
- let target = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : new THREE.Vector3();
56
- const longitude = THREE.MathUtils.degToRad(coordCarto.longitude);
57
- const latitude = THREE.MathUtils.degToRad(coordCarto.latitude);
58
- const cosLatitude = Math.cos(latitude);
59
- return target.set(cosLatitude * Math.cos(longitude), cosLatitude * Math.sin(longitude), Math.sin(latitude));
60
- }
61
-
62
- /**
63
- * Sets the length of the semi-axes of this ellipsoid from a 3-dimensional
64
- * vector-like object. The object shall have both `x`, `y` and `z`
65
- * properties.
66
- *
67
- * @param size - The source vector.
68
- */
69
- setSize(size) {
70
- this.size.set(size.x, size.y, size.z);
71
- this._radiiSquared.multiplyVectors(size, size);
72
- this._invRadiiSquared.x = size.x === 0 ? 0 : 1 / this._radiiSquared.x;
73
- this._invRadiiSquared.y = size.y === 0 ? 0 : 1 / this._radiiSquared.y;
74
- this._invRadiiSquared.z = size.z === 0 ? 0 : 1 / this._radiiSquared.z;
75
- this.eccentricity = Math.sqrt(this._radiiSquared.x - this._radiiSquared.z) / this.size.x;
76
- return this;
77
- }
78
- cartographicToCartesian(coordCarto) {
79
- let target = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : new THREE.Vector3();
80
- normal.copy(coordCarto.geodesicNormal);
81
- target.multiplyVectors(this._radiiSquared, normal);
82
- const gamma = Math.sqrt(normal.dot(target));
83
- target.divideScalar(gamma);
84
- normal.multiplyScalar(coordCarto.altitude);
85
- return target.add(normal);
86
- }
87
-
88
- /**
89
- * Convert cartesian coordinates to geographic according to the current
90
- * ellipsoid of revolution.
91
- * @param position - The coordinate to convert
92
- * @param target - coordinate to copy result
93
- * @returns an object describing the coordinates on the reference ellipsoid,
94
- * angles are in degree
95
- */
96
- cartesianToCartographic(position) {
97
- let target = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : new Coordinates('EPSG:4326', 0, 0, 0);
98
- // for details, see for example http://www.linz.govt.nz/data/geodetic-system/coordinate-conversion/geodetic-datum-conversions/equations-used-datum
99
- // TODO the following is only valable for oblate ellipsoid of
100
- // revolution. do we want to support triaxial ellipsoid?
101
- const R = Math.sqrt(position.x * position.x + position.y * position.y + position.z * position.z);
102
- const a = this.size.x; // x
103
- const b = this.size.z; // z
104
- const e = Math.abs((a * a - b * b) / (a * a));
105
- const f = 1 - Math.sqrt(1 - e);
106
- const rsqXY = Math.sqrt(position.x * position.x + position.y * position.y);
107
- const theta = Math.atan2(position.y, position.x);
108
- const nu = Math.atan(position.z / rsqXY * (1 - f + e * a / R));
109
- const sinu = Math.sin(nu);
110
- const cosu = Math.cos(nu);
111
- const phi = Math.atan((position.z * (1 - f) + e * a * sinu * sinu * sinu) / ((1 - f) * (rsqXY - e * a * cosu * cosu * cosu)));
112
- const h = rsqXY * Math.cos(phi) + position.z * Math.sin(phi) - a * Math.sqrt(1 - e * Math.sin(phi) * Math.sin(phi));
113
- return target.setFromValues(THREE.MathUtils.radToDeg(theta), THREE.MathUtils.radToDeg(phi), h);
114
- }
115
- cartographicToCartesianArray(coordCartoArray) {
116
- const cartesianArray = [];
117
- for (let i = 0; i < coordCartoArray.length; i++) {
118
- cartesianArray.push(this.cartographicToCartesian(coordCartoArray[i]));
119
- }
120
- return cartesianArray;
121
- }
122
- intersection(ray) {
123
- const EPSILON = 0.0001;
124
- const O_C = ray.origin;
125
- const dir = ray.direction;
126
- // normalizeVector( dir );
127
-
128
- const a = dir.x * dir.x * this._invRadiiSquared.x + dir.y * dir.y * this._invRadiiSquared.y + dir.z * dir.z * this._invRadiiSquared.z;
129
- const b = 2 * O_C.x * dir.x * this._invRadiiSquared.x + 2 * O_C.y * dir.y * this._invRadiiSquared.y + 2 * O_C.z * dir.z * this._invRadiiSquared.z;
130
- const c = O_C.x * O_C.x * this._invRadiiSquared.x + O_C.y * O_C.y * this._invRadiiSquared.y + O_C.z * O_C.z * this._invRadiiSquared.z - 1;
131
- let d = b * b - 4 * a * c;
132
- if (d < 0 || a === 0 || b === 0 || c === 0) {
133
- return false;
134
- }
135
- d = Math.sqrt(d);
136
- const t1 = (-b + d) / (2 * a);
137
- const t2 = (-b - d) / (2 * a);
138
- if (t1 <= EPSILON && t2 <= EPSILON) {
139
- // both intersections are behind the ray origin
140
- return false;
141
- }
142
- let t = 0;
143
- if (t1 <= EPSILON) {
144
- t = t2;
145
- } else if (t2 <= EPSILON) {
146
- t = t1;
147
- } else {
148
- t = t1 < t2 ? t1 : t2;
149
- }
150
- if (t < EPSILON) {
151
- return false;
152
- } // Too close to intersection
153
-
154
- const inter = new THREE.Vector3();
155
- inter.addVectors(ray.origin, dir.clone().setLength(t));
156
- return inter;
157
- }
158
-
159
- /**
160
- * Calculate the geodesic distance, between coordCarto1 and coordCarto2.
161
- * It's most short distance on ellipsoid surface between coordCarto1 and
162
- * coordCarto2.
163
- * It's called orthodromy.
164
- *
165
- * @param coordCarto1 - The coordinate carto 1
166
- * @param coordCarto2 - The coordinate carto 2
167
- * @returns The orthodromic distance between the two given coordinates.
168
- */
169
- geodesicDistance(coordCarto1, coordCarto2) {
170
- // The formula uses the distance on approximated sphere,
171
- // with the nearest local radius of curvature of the ellipsoid
172
- // https://geodesie.ign.fr/contenu/fichiers/Distance_longitude_latitude.pdf
173
- const longitude1 = THREE.MathUtils.degToRad(coordCarto1.longitude);
174
- const latitude1 = THREE.MathUtils.degToRad(coordCarto1.latitude);
175
- const longitude2 = THREE.MathUtils.degToRad(coordCarto2.longitude);
176
- const latitude2 = THREE.MathUtils.degToRad(coordCarto2.latitude);
177
- const distRad = Math.acos(Math.sin(latitude1) * Math.sin(latitude2) + Math.cos(latitude1) * Math.cos(latitude2) * Math.cos(longitude2 - longitude1));
178
- const e = this.eccentricity;
179
- const es = (e * Math.sin((latitude1 + latitude2) * 0.5)) ** 2;
180
- const rho = this.size.x * (1 - e ** 2) / (1 - es) ** (3 / 2);
181
- const N = this.size.x / Math.sqrt(1 - es);
182
- return distRad * Math.sqrt(rho * N);
183
- }
184
- }
185
- export default Ellipsoid;