itowns 2.44.3-next.8 → 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 (219) hide show
  1. package/README.md +3 -129
  2. package/examples/3dtiles_loader.html +123 -48
  3. package/examples/config.json +3 -10
  4. package/examples/copc_simple_loader.html +15 -5
  5. package/examples/effects_stereo.html +2 -2
  6. package/examples/entwine_3d_loader.html +3 -1
  7. package/examples/entwine_simple_loader.html +1 -1
  8. package/examples/images/itowns_logo.svg +123 -0
  9. package/examples/js/plugins/COGParser.js +1 -1
  10. package/examples/jsm/OGC3DTilesHelper.js +6 -1
  11. package/examples/layers/JSONLayers/GeoidMNT.json +3 -1
  12. package/examples/misc_collada.html +2 -2
  13. package/examples/source_file_geojson_3d.html +0 -1
  14. package/examples/source_file_kml_raster_usgs.html +0 -1
  15. package/examples/source_stream_wfs_raster.html +0 -7
  16. package/examples/vector_tile_mapbox_raster.html +91 -0
  17. package/examples/view_3d_map_webxr.html +3 -1
  18. package/examples/view_multi_25d.html +2 -2
  19. package/package.json +21 -75
  20. package/CODING.md +0 -120
  21. package/CONTRIBUTING.md +0 -150
  22. package/CONTRIBUTORS.md +0 -55
  23. package/LICENSE.md +0 -44
  24. package/changelog.md +0 -1361
  25. package/dist/455.js +0 -2
  26. package/dist/455.js.map +0 -1
  27. package/dist/debug.js +0 -3
  28. package/dist/debug.js.LICENSE.txt +0 -13
  29. package/dist/debug.js.map +0 -1
  30. package/dist/itowns.js +0 -3
  31. package/dist/itowns.js.LICENSE.txt +0 -7
  32. package/dist/itowns.js.map +0 -1
  33. package/dist/itowns_lasparser.js +0 -2
  34. package/dist/itowns_lasparser.js.map +0 -1
  35. package/dist/itowns_lasworker.js +0 -2
  36. package/dist/itowns_lasworker.js.map +0 -1
  37. package/dist/itowns_potree2worker.js +0 -2
  38. package/dist/itowns_potree2worker.js.map +0 -1
  39. package/dist/itowns_widgets.js +0 -2
  40. package/dist/itowns_widgets.js.map +0 -1
  41. package/examples/.eslintrc.cjs +0 -35
  42. package/examples/3dtiles_25d.html +0 -120
  43. package/examples/3dtiles_basic.html +0 -94
  44. package/examples/3dtiles_batch_table.html +0 -86
  45. package/examples/3dtiles_ion.html +0 -126
  46. package/examples/3dtiles_pointcloud.html +0 -95
  47. package/examples/jsm/.eslintrc.cjs +0 -38
  48. package/lib/Controls/FirstPersonControls.js +0 -308
  49. package/lib/Controls/FlyControls.js +0 -175
  50. package/lib/Controls/GlobeControls.js +0 -1162
  51. package/lib/Controls/PlanarControls.js +0 -1025
  52. package/lib/Controls/StateControl.js +0 -429
  53. package/lib/Controls/StreetControls.js +0 -392
  54. package/lib/Converter/Feature2Mesh.js +0 -615
  55. package/lib/Converter/Feature2Texture.js +0 -170
  56. package/lib/Converter/convertToTile.js +0 -75
  57. package/lib/Converter/textureConverter.js +0 -44
  58. package/lib/Core/3DTiles/C3DTBatchTable.js +0 -131
  59. package/lib/Core/3DTiles/C3DTBatchTableHierarchyExtension.js +0 -96
  60. package/lib/Core/3DTiles/C3DTBoundingVolume.js +0 -157
  61. package/lib/Core/3DTiles/C3DTExtensions.js +0 -97
  62. package/lib/Core/3DTiles/C3DTFeature.js +0 -110
  63. package/lib/Core/3DTiles/C3DTilesEnums.js +0 -20
  64. package/lib/Core/3DTiles/C3DTileset.js +0 -99
  65. package/lib/Core/3DTiles/utils/BinaryPropertyAccessor.js +0 -100
  66. package/lib/Core/AnimationPlayer.js +0 -142
  67. package/lib/Core/CopcNode.js +0 -174
  68. package/lib/Core/Deprecated/Undeprecator.js +0 -75
  69. package/lib/Core/EntwinePointTileNode.js +0 -126
  70. package/lib/Core/Feature.js +0 -490
  71. package/lib/Core/Geographic/CoordStars.js +0 -80
  72. package/lib/Core/Geographic/Coordinates.js +0 -320
  73. package/lib/Core/Geographic/Crs.js +0 -175
  74. package/lib/Core/Geographic/Extent.js +0 -534
  75. package/lib/Core/Geographic/GeoidGrid.js +0 -109
  76. package/lib/Core/Label.js +0 -222
  77. package/lib/Core/MainLoop.js +0 -211
  78. package/lib/Core/Math/Ellipsoid.js +0 -144
  79. package/lib/Core/Picking.js +0 -255
  80. package/lib/Core/PointCloudNode.js +0 -42
  81. package/lib/Core/Potree2Node.js +0 -206
  82. package/lib/Core/Potree2PointAttributes.js +0 -139
  83. package/lib/Core/PotreeNode.js +0 -101
  84. package/lib/Core/Prefab/Globe/Atmosphere.js +0 -299
  85. package/lib/Core/Prefab/Globe/BuilderEllipsoidTile.js +0 -110
  86. package/lib/Core/Prefab/Globe/GlobeLayer.js +0 -145
  87. package/lib/Core/Prefab/Globe/SkyShader.js +0 -78
  88. package/lib/Core/Prefab/GlobeView.js +0 -161
  89. package/lib/Core/Prefab/Planar/PlanarLayer.js +0 -53
  90. package/lib/Core/Prefab/Planar/PlanarTileBuilder.js +0 -72
  91. package/lib/Core/Prefab/PlanarView.js +0 -62
  92. package/lib/Core/Prefab/TileBuilder.js +0 -80
  93. package/lib/Core/Prefab/computeBufferTileGeometry.js +0 -183
  94. package/lib/Core/Scheduler/Cache.js +0 -256
  95. package/lib/Core/Scheduler/CancelledCommandException.js +0 -15
  96. package/lib/Core/Scheduler/Scheduler.js +0 -294
  97. package/lib/Core/Style.js +0 -1121
  98. package/lib/Core/System/Capabilities.js +0 -63
  99. package/lib/Core/Tile/Tile.js +0 -219
  100. package/lib/Core/Tile/TileGrid.js +0 -46
  101. package/lib/Core/TileGeometry.js +0 -40
  102. package/lib/Core/TileMesh.js +0 -109
  103. package/lib/Core/View.js +0 -1109
  104. package/lib/Layer/C3DTilesLayer.js +0 -455
  105. package/lib/Layer/ColorLayer.js +0 -128
  106. package/lib/Layer/CopcLayer.js +0 -58
  107. package/lib/Layer/ElevationLayer.js +0 -107
  108. package/lib/Layer/EntwinePointTileLayer.js +0 -64
  109. package/lib/Layer/FeatureGeometryLayer.js +0 -63
  110. package/lib/Layer/GeoidLayer.js +0 -80
  111. package/lib/Layer/GeometryLayer.js +0 -202
  112. package/lib/Layer/InfoLayer.js +0 -64
  113. package/lib/Layer/LabelLayer.js +0 -456
  114. package/lib/Layer/Layer.js +0 -304
  115. package/lib/Layer/LayerUpdateState.js +0 -89
  116. package/lib/Layer/LayerUpdateStrategy.js +0 -80
  117. package/lib/Layer/OGC3DTilesLayer.js +0 -387
  118. package/lib/Layer/OrientedImageLayer.js +0 -222
  119. package/lib/Layer/PointCloudLayer.js +0 -359
  120. package/lib/Layer/Potree2Layer.js +0 -164
  121. package/lib/Layer/PotreeLayer.js +0 -65
  122. package/lib/Layer/RasterLayer.js +0 -27
  123. package/lib/Layer/ReferencingLayerProperties.js +0 -62
  124. package/lib/Layer/TiledGeometryLayer.js +0 -403
  125. package/lib/Loader/LASLoader.js +0 -193
  126. package/lib/Loader/Potree2BrotliLoader.js +0 -261
  127. package/lib/Loader/Potree2Loader.js +0 -207
  128. package/lib/Main.js +0 -115
  129. package/lib/MainBundle.js +0 -4
  130. package/lib/Parser/B3dmParser.js +0 -174
  131. package/lib/Parser/CameraCalibrationParser.js +0 -94
  132. package/lib/Parser/GDFParser.js +0 -72
  133. package/lib/Parser/GTXParser.js +0 -75
  134. package/lib/Parser/GeoJsonParser.js +0 -212
  135. package/lib/Parser/GpxParser.js +0 -25
  136. package/lib/Parser/ISGParser.js +0 -71
  137. package/lib/Parser/KMLParser.js +0 -25
  138. package/lib/Parser/LASParser.js +0 -137
  139. package/lib/Parser/MapBoxUrlParser.js +0 -83
  140. package/lib/Parser/PntsParser.js +0 -131
  141. package/lib/Parser/Potree2BinParser.js +0 -92
  142. package/lib/Parser/PotreeBinParser.js +0 -106
  143. package/lib/Parser/PotreeCinParser.js +0 -29
  144. package/lib/Parser/ShapefileParser.js +0 -78
  145. package/lib/Parser/VectorTileParser.js +0 -202
  146. package/lib/Parser/XbilParser.js +0 -119
  147. package/lib/Parser/deprecated/LegacyGLTFLoader.js +0 -1386
  148. package/lib/Parser/iGLTFLoader.js +0 -168
  149. package/lib/Process/3dTilesProcessing.js +0 -304
  150. package/lib/Process/FeatureProcessing.js +0 -76
  151. package/lib/Process/LayeredMaterialNodeProcessing.js +0 -221
  152. package/lib/Process/ObjectRemovalHelper.js +0 -97
  153. package/lib/Process/handlerNodeError.js +0 -23
  154. package/lib/Provider/3dTilesProvider.js +0 -149
  155. package/lib/Provider/DataSourceProvider.js +0 -8
  156. package/lib/Provider/Fetcher.js +0 -229
  157. package/lib/Provider/PointCloudProvider.js +0 -45
  158. package/lib/Provider/TileProvider.js +0 -16
  159. package/lib/Provider/URLBuilder.js +0 -116
  160. package/lib/Renderer/Camera.js +0 -281
  161. package/lib/Renderer/Color.js +0 -56
  162. package/lib/Renderer/ColorLayersOrdering.js +0 -115
  163. package/lib/Renderer/CommonMaterial.js +0 -31
  164. package/lib/Renderer/Label2DRenderer.js +0 -190
  165. package/lib/Renderer/LayeredMaterial.js +0 -243
  166. package/lib/Renderer/OBB.js +0 -153
  167. package/lib/Renderer/OrientedImageCamera.js +0 -118
  168. package/lib/Renderer/OrientedImageMaterial.js +0 -167
  169. package/lib/Renderer/PointsMaterial.js +0 -485
  170. package/lib/Renderer/RasterTile.js +0 -209
  171. package/lib/Renderer/RenderMode.js +0 -31
  172. package/lib/Renderer/Shader/ShaderChunk.js +0 -160
  173. package/lib/Renderer/Shader/ShaderUtils.js +0 -47
  174. package/lib/Renderer/SphereHelper.js +0 -23
  175. package/lib/Renderer/WebXR.js +0 -51
  176. package/lib/Renderer/c3DEngine.js +0 -214
  177. package/lib/Source/C3DTilesGoogleSource.js +0 -74
  178. package/lib/Source/C3DTilesIonSource.js +0 -54
  179. package/lib/Source/C3DTilesSource.js +0 -30
  180. package/lib/Source/CopcSource.js +0 -115
  181. package/lib/Source/EntwinePointTileSource.js +0 -62
  182. package/lib/Source/FileSource.js +0 -189
  183. package/lib/Source/OGC3DTilesGoogleSource.js +0 -29
  184. package/lib/Source/OGC3DTilesIonSource.js +0 -34
  185. package/lib/Source/OGC3DTilesSource.js +0 -21
  186. package/lib/Source/OrientedImageSource.js +0 -59
  187. package/lib/Source/Potree2Source.js +0 -167
  188. package/lib/Source/PotreeSource.js +0 -82
  189. package/lib/Source/Source.js +0 -223
  190. package/lib/Source/TMSSource.js +0 -145
  191. package/lib/Source/VectorTilesSource.js +0 -178
  192. package/lib/Source/WFSSource.js +0 -168
  193. package/lib/Source/WMSSource.js +0 -133
  194. package/lib/Source/WMTSSource.js +0 -86
  195. package/lib/ThreeExtended/capabilities/WebGL.js +0 -69
  196. package/lib/ThreeExtended/libs/ktx-parse.module.js +0 -470
  197. package/lib/ThreeExtended/libs/zstddec.module.js +0 -29
  198. package/lib/ThreeExtended/loaders/DDSLoader.js +0 -200
  199. package/lib/ThreeExtended/loaders/DRACOLoader.js +0 -399
  200. package/lib/ThreeExtended/loaders/GLTFLoader.js +0 -2876
  201. package/lib/ThreeExtended/loaders/KTX2Loader.js +0 -625
  202. package/lib/ThreeExtended/utils/BufferGeometryUtils.js +0 -846
  203. package/lib/ThreeExtended/utils/WorkerPool.js +0 -70
  204. package/lib/Utils/CameraUtils.js +0 -555
  205. package/lib/Utils/DEMUtils.js +0 -350
  206. package/lib/Utils/FeaturesUtils.js +0 -156
  207. package/lib/Utils/Gradients.js +0 -16
  208. package/lib/Utils/OrientationUtils.js +0 -457
  209. package/lib/Utils/ThreeUtils.js +0 -115
  210. package/lib/Utils/gui/C3DTilesStyle.js +0 -215
  211. package/lib/Utils/gui/Main.js +0 -7
  212. package/lib/Utils/gui/Minimap.js +0 -154
  213. package/lib/Utils/gui/Navigation.js +0 -245
  214. package/lib/Utils/gui/Scale.js +0 -107
  215. package/lib/Utils/gui/Searchbar.js +0 -234
  216. package/lib/Utils/gui/Widget.js +0 -80
  217. package/lib/Utils/placeObjectOnGround.js +0 -137
  218. package/lib/Worker/LASLoaderWorker.js +0 -19
  219. 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,211 +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
- attachedLayer.cache.flush();
46
- }
47
- }
48
- } else if (sub.elements) {
49
- for (let i = 0; i < sub.elements.length; i++) {
50
- if (!sub.elements[i].isObject3D) {
51
- throw new Error(`
52
- Invalid object for attached layer to update.
53
- Must be a THREE.Object and have a THREE.Material`);
54
- }
55
- // update attached layers
56
- for (const attachedLayer of geometryLayer.attachedLayers) {
57
- if (attachedLayer.ready) {
58
- attachedLayer.update(context, attachedLayer, sub.elements[i], sub.parent);
59
- attachedLayer.cache.flush();
60
- }
61
- }
62
- }
63
- }
64
- }
65
- updateElements(context, geometryLayer, newElementsToUpdate);
66
- }
67
- }
68
- function filterChangeSources(updateSources, geometryLayer) {
69
- let fullUpdate = false;
70
- const filtered = new Set();
71
- updateSources.forEach(src => {
72
- if (src === geometryLayer || src.isCamera) {
73
- geometryLayer.info.clear();
74
- fullUpdate = true;
75
- } else if (src.layer === geometryLayer) {
76
- filtered.add(src);
77
- }
78
- });
79
- return fullUpdate ? new Set([geometryLayer]) : filtered;
80
- }
81
- class MainLoop extends EventDispatcher {
82
- #needsRedraw = false;
83
- #updateLoopRestarted = true;
84
- #lastTimestamp = 0;
85
- constructor(scheduler, engine) {
86
- super();
87
- this.renderingState = RENDERING_PAUSED;
88
- this.scheduler = scheduler;
89
- this.gfxEngine = engine; // TODO: remove me
90
- }
91
- scheduleViewUpdate(view, forceRedraw) {
92
- this.#needsRedraw |= forceRedraw;
93
- if (this.renderingState !== RENDERING_SCHEDULED) {
94
- this.renderingState = RENDERING_SCHEDULED;
95
- // TODO Fix asynchronization between xr and MainLoop render loops.
96
- // WebGLRenderer#setAnimationLoop must be used for WebXR projects.
97
- // (see WebXR#initializeWebXR).
98
- if (!this.gfxEngine.renderer.xr.isPresenting) {
99
- requestAnimationFrame(timestamp => {
100
- this.step(view, timestamp);
101
- });
102
- }
103
- }
104
- }
105
- #update(view, updateSources, dt) {
106
- const context = {
107
- camera: view.camera,
108
- engine: this.gfxEngine,
109
- scheduler: this.scheduler,
110
- view
111
- };
112
-
113
- // replace layer with their parent where needed
114
- updateSources.forEach(src => {
115
- const layer = src.layer || src;
116
- if (layer.isLayer && layer.parent) {
117
- updateSources.add(layer.parent);
118
- }
119
- });
120
- for (const geometryLayer of view.getLayers((x, y) => !y)) {
121
- context.geometryLayer = geometryLayer;
122
- if (geometryLayer.ready && geometryLayer.visible && !geometryLayer.frozen) {
123
- view.execFrameRequesters(MAIN_LOOP_EVENTS.BEFORE_LAYER_UPDATE, dt, this.#updateLoopRestarted, geometryLayer);
124
-
125
- // Filter updateSources that are relevant for the geometryLayer
126
- const srcs = filterChangeSources(updateSources, geometryLayer);
127
- if (srcs.size > 0) {
128
- // pre update attached layer
129
- for (const attachedLayer of geometryLayer.attachedLayers) {
130
- if (attachedLayer.ready && attachedLayer.preUpdate) {
131
- attachedLayer.preUpdate(context, srcs);
132
- }
133
- }
134
- // `preUpdate` returns an array of elements to update
135
- const elementsToUpdate = geometryLayer.preUpdate(context, srcs);
136
- // `update` is called in `updateElements`.
137
- updateElements(context, geometryLayer, elementsToUpdate);
138
- // `postUpdate` is called when this geom layer update process is finished
139
- geometryLayer.postUpdate(context, geometryLayer, updateSources);
140
- }
141
-
142
- // Clear the cache of expired resources
143
- geometryLayer.cache.flush();
144
- view.execFrameRequesters(MAIN_LOOP_EVENTS.AFTER_LAYER_UPDATE, dt, this.#updateLoopRestarted, geometryLayer);
145
- }
146
- }
147
- }
148
- step(view, timestamp) {
149
- const dt = timestamp - this.#lastTimestamp;
150
- view._executeFrameRequestersRemovals();
151
- view.execFrameRequesters(MAIN_LOOP_EVENTS.UPDATE_START, dt, this.#updateLoopRestarted);
152
- const willRedraw = this.#needsRedraw;
153
- this.#lastTimestamp = timestamp;
154
-
155
- // Reset internal state before calling _update (so future calls to View.notifyChange()
156
- // can properly change it)
157
- this.#needsRedraw = false;
158
- this.renderingState = RENDERING_PAUSED;
159
- const updateSources = new Set(view._changeSources);
160
- view._changeSources.clear();
161
-
162
- // update camera
163
- const dim = this.gfxEngine.getWindowSize();
164
- view.execFrameRequesters(MAIN_LOOP_EVENTS.BEFORE_CAMERA_UPDATE, dt, this.#updateLoopRestarted);
165
- view.camera.update(dim.x, dim.y);
166
- view.execFrameRequesters(MAIN_LOOP_EVENTS.AFTER_CAMERA_UPDATE, dt, this.#updateLoopRestarted);
167
-
168
- // Disable camera's matrix auto update to make sure the camera's
169
- // world matrix is never updated mid-update.
170
- // Otherwise inconsistencies can appear because object visibility
171
- // testing and object drawing could be performed using different
172
- // camera matrixWorld.
173
- // Note: this is required at least because WEBGLRenderer calls
174
- // camera.updateMatrixWorld()
175
- const oldAutoUpdate = view.camera3D.matrixAutoUpdate;
176
- view.camera3D.matrixAutoUpdate = false;
177
-
178
- // update data-structure
179
- this.#update(view, updateSources, dt);
180
- if (this.scheduler.commandsWaitingExecutionCount() == 0) {
181
- this.dispatchEvent({
182
- type: 'command-queue-empty'
183
- });
184
- }
185
-
186
- // Redraw *only* if needed.
187
- // (redraws only happen when this.#needsRedraw is true, which in turn only happens when
188
- // view.notifyChange() is called with redraw=true)
189
- // As such there's no continuous update-loop, instead we use a ad-hoc update/render
190
- // mechanism.
191
- if (willRedraw) {
192
- this.#renderView(view, dt);
193
- }
194
-
195
- // next time, we'll consider that we've just started the loop if we are still PAUSED now
196
- this.#updateLoopRestarted = this.renderingState === RENDERING_PAUSED;
197
- view.camera3D.matrixAutoUpdate = oldAutoUpdate;
198
- view.execFrameRequesters(MAIN_LOOP_EVENTS.UPDATE_END, dt, this.#updateLoopRestarted);
199
- }
200
- #renderView(view, dt) {
201
- view.execFrameRequesters(MAIN_LOOP_EVENTS.BEFORE_RENDER, dt, this.#updateLoopRestarted);
202
- if (view.render) {
203
- view.render();
204
- } else {
205
- // use default rendering method
206
- this.gfxEngine.renderView(view);
207
- }
208
- view.execFrameRequesters(MAIN_LOOP_EVENTS.AFTER_RENDER, dt, this.#updateLoopRestarted);
209
- }
210
- }
211
- export default MainLoop;
@@ -1,144 +0,0 @@
1
- import * as THREE from 'three';
2
- import proj4 from 'proj4';
3
- import Coordinates from "../Geographic/Coordinates.js";
4
- export const ellipsoidSizes = new THREE.Vector3(proj4.WGS84.a, proj4.WGS84.a, proj4.WGS84.b);
5
- const normal = new THREE.Vector3();
6
- class Ellipsoid {
7
- constructor() {
8
- let size = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ellipsoidSizes;
9
- this.size = new THREE.Vector3();
10
- this._radiiSquared = new THREE.Vector3();
11
- this._invRadiiSquared = new THREE.Vector3();
12
- this.eccentricity = 0;
13
- this.setSize(size);
14
- }
15
- geodeticSurfaceNormal(cartesian) {
16
- let target = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : new THREE.Vector3();
17
- return cartesian.toVector3(target).multiply(this._invRadiiSquared).normalize();
18
- }
19
- geodeticSurfaceNormalCartographic(coordCarto) {
20
- let target = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : new THREE.Vector3();
21
- const longitude = THREE.MathUtils.degToRad(coordCarto.longitude);
22
- const latitude = THREE.MathUtils.degToRad(coordCarto.latitude);
23
- const cosLatitude = Math.cos(latitude);
24
- return target.set(cosLatitude * Math.cos(longitude), cosLatitude * Math.sin(longitude), Math.sin(latitude));
25
- }
26
- setSize(size) {
27
- this.size.set(size.x, size.y, size.z);
28
- this._radiiSquared.multiplyVectors(size, size);
29
- this._invRadiiSquared.x = size.x == 0 ? 0 : 1 / this._radiiSquared.x;
30
- this._invRadiiSquared.y = size.y == 0 ? 0 : 1 / this._radiiSquared.y;
31
- this._invRadiiSquared.z = size.z == 0 ? 0 : 1 / this._radiiSquared.z;
32
- this.eccentricity = Math.sqrt(this._radiiSquared.x - this._radiiSquared.z) / this.size.x;
33
- }
34
- cartographicToCartesian(coordCarto) {
35
- let target = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : new THREE.Vector3();
36
- normal.copy(coordCarto.geodesicNormal);
37
- target.multiplyVectors(this._radiiSquared, normal);
38
- const gamma = Math.sqrt(normal.dot(target));
39
- target.divideScalar(gamma);
40
- normal.multiplyScalar(coordCarto.altitude);
41
- return target.add(normal);
42
- }
43
-
44
- /**
45
- * Convert cartesian coordinates to geographic according to the current ellipsoid of revolution.
46
- * @param {Object} position - The coordinate to convert
47
- * @param {number} position.x
48
- * @param {number} position.y
49
- * @param {number} position.z
50
- * @param {Coordinate} [target] coordinate to copy result
51
- * @returns {Coordinate} an object describing the coordinates on the reference ellipsoid, angles are in degree
52
- */
53
- cartesianToCartographic(position) {
54
- let target = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : new Coordinates('EPSG:4326', 0, 0, 0);
55
- // for details, see for example http://www.linz.govt.nz/data/geodetic-system/coordinate-conversion/geodetic-datum-conversions/equations-used-datum
56
- // TODO the following is only valable for oblate ellipsoid of revolution. do we want to support triaxial ellipsoid?
57
- const R = Math.sqrt(position.x * position.x + position.y * position.y + position.z * position.z);
58
- const a = this.size.x; // x
59
- const b = this.size.z; // z
60
- const e = Math.abs((a * a - b * b) / (a * a));
61
- const f = 1 - Math.sqrt(1 - e);
62
- const rsqXY = Math.sqrt(position.x * position.x + position.y * position.y);
63
- const theta = Math.atan2(position.y, position.x);
64
- const nu = Math.atan(position.z / rsqXY * (1 - f + e * a / R));
65
- const sinu = Math.sin(nu);
66
- const cosu = Math.cos(nu);
67
- const phi = Math.atan((position.z * (1 - f) + e * a * sinu * sinu * sinu) / ((1 - f) * (rsqXY - e * a * cosu * cosu * cosu)));
68
- const h = rsqXY * Math.cos(phi) + position.z * Math.sin(phi) - a * Math.sqrt(1 - e * Math.sin(phi) * Math.sin(phi));
69
- return target.setFromValues(THREE.MathUtils.radToDeg(theta), THREE.MathUtils.radToDeg(phi), h);
70
- }
71
- cartographicToCartesianArray(coordCartoArray) {
72
- const cartesianArray = [];
73
- for (let i = 0; i < coordCartoArray.length; i++) {
74
- cartesianArray.push(this.cartographicToCartesian(coordCartoArray[i]));
75
- }
76
- return cartesianArray;
77
- }
78
- intersection(ray) {
79
- const EPSILON = 0.0001;
80
- const O_C = ray.origin;
81
- const dir = ray.direction;
82
- // normalizeVector( dir );
83
-
84
- const a = dir.x * dir.x * this._invRadiiSquared.x + dir.y * dir.y * this._invRadiiSquared.y + dir.z * dir.z * this._invRadiiSquared.z;
85
- 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;
86
- 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;
87
- let d = b * b - 4 * a * c;
88
- if (d < 0 || a === 0 || b === 0 || c === 0) {
89
- return false;
90
- }
91
- d = Math.sqrt(d);
92
- const t1 = (-b + d) / (2 * a);
93
- const t2 = (-b - d) / (2 * a);
94
- if (t1 <= EPSILON && t2 <= EPSILON) {
95
- return false;
96
- } // both intersections are behind the ray origin
97
- // var back = (t1 <= EPSILON || t2 <= EPSILON); // If only one intersection (t>0) then we are inside the ellipsoid and the intersection is at the back of the ellipsoid
98
- let t = 0;
99
- if (t1 <= EPSILON) {
100
- t = t2;
101
- } else if (t2 <= EPSILON) {
102
- t = t1;
103
- } else {
104
- t = t1 < t2 ? t1 : t2;
105
- }
106
- if (t < EPSILON) {
107
- return false;
108
- } // Too close to intersection
109
-
110
- const inter = new THREE.Vector3();
111
- inter.addVectors(ray.origin, dir.clone().setLength(t));
112
- return inter;
113
- }
114
- computeDistance(coordCarto1, coordCarto2) {
115
- console.warn('computeDistance is renamed to geodesicDistance');
116
- this.geodesicDistance(coordCarto1, coordCarto2);
117
- }
118
-
119
- /**
120
- * Calculate the geodesic distance, between coordCarto1 and coordCarto2.
121
- * It's most short distance on ellipsoid surface between coordCarto1 and coordCarto2.
122
- * It's called orthodromy.
123
- *
124
- * @param {Coordinates} coordCarto1 The coordinate carto 1
125
- * @param {Coordinates} coordCarto2 The coordinate carto 2
126
- * @return {number} The orthodromic distance between the two given coordinates.
127
- */
128
- geodesicDistance(coordCarto1, coordCarto2) {
129
- // The formula uses the distance on approximated sphere,
130
- // with the nearest local radius of curvature of the ellipsoid
131
- // https://geodesie.ign.fr/contenu/fichiers/Distance_longitude_latitude.pdf
132
- const longitude1 = THREE.MathUtils.degToRad(coordCarto1.longitude);
133
- const latitude1 = THREE.MathUtils.degToRad(coordCarto1.latitude);
134
- const longitude2 = THREE.MathUtils.degToRad(coordCarto2.longitude);
135
- const latitude2 = THREE.MathUtils.degToRad(coordCarto2.latitude);
136
- const distRad = Math.acos(Math.sin(latitude1) * Math.sin(latitude2) + Math.cos(latitude1) * Math.cos(latitude2) * Math.cos(longitude2 - longitude1));
137
- const e = this.eccentricity;
138
- const es = (e * Math.sin((latitude1 + latitude2) * 0.5)) ** 2;
139
- const rho = this.size.x * (1 - e ** 2) / (1 - es) ** (3 / 2);
140
- const N = this.size.x / Math.sqrt(1 - es);
141
- return distRad * Math.sqrt(rho * N);
142
- }
143
- }
144
- export default Ellipsoid;