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,228 +0,0 @@
1
- import * as THREE from 'three';
2
- import GeometryLayer from "./GeometryLayer.js";
3
- import OrientedImageMaterial from "../Renderer/OrientedImageMaterial.js";
4
- import GeoJsonParser from "../Parser/GeoJsonParser.js";
5
- import CameraCalibrationParser from "../Parser/CameraCalibrationParser.js";
6
- import Coordinates from "../Core/Geographic/Coordinates.js";
7
- import OrientationUtils from "../Utils/OrientationUtils.js";
8
- const coord = new Coordinates('EPSG:4978', 0, 0, 0);
9
- const commandCancellation = cmd => cmd.requester.id !== cmd.layer.currentPano.id;
10
- function updatePano(context, camera, layer) {
11
- const newPano = layer.mostNearPano(camera.position);
12
- // detection of oriented image change
13
- const currentId = layer.currentPano ? layer.currentPano.id : undefined;
14
- if (newPano && currentId != newPano.id) {
15
- layer.currentPano = newPano;
16
-
17
- // callback to indicate current pano has changed
18
- layer.onPanoChanged({
19
- previousPanoPosition: layer.getPreviousPano() ? layer.getPreviousPano().position : undefined,
20
- currentPanoPosition: layer.getCurrentPano().position,
21
- nextPanoPosition: layer.getNextPano().position
22
- });
23
- // prepare informations about the needed textures
24
- const panoCameras = newPano.geometries[0].properties.idSensors;
25
- const imagesInfo = layer.cameras.map(cam => ({
26
- cameraId: cam.name,
27
- panoId: newPano.id,
28
- as: () => {}
29
- })).filter(info => !panoCameras || panoCameras.includes(info.cameraId));
30
- const command = {
31
- layer,
32
- // put informations about image URL as extent to be used by generic DataSourceProvider, OrientedImageSource will use that.
33
- extentsSource: imagesInfo,
34
- view: context.view,
35
- requester: newPano,
36
- earlyDropFunction: commandCancellation
37
- };
38
-
39
- // async call to scheduler to get textures
40
- context.scheduler.execute(command).then(textures => {
41
- if (newPano.id === layer.currentPano.id) {
42
- layer.material.setTextures(textures, newPano, layer.getCamerasNameFromFeature(newPano));
43
- layer.material.updateUniforms(context.camera.camera3D);
44
- context.view.notifyChange(layer, true);
45
- }
46
- }, () => {});
47
- }
48
- }
49
- function updateBackground(layer) {
50
- if (layer.background && layer.currentPano) {
51
- layer.background.position.copy(layer.currentPano.position);
52
- layer.background.updateMatrixWorld();
53
- layer.background.material = layer.material || layer.background.material;
54
- }
55
- }
56
- function createBackground(radius) {
57
- if (!radius || radius <= 0) {
58
- return undefined;
59
- }
60
- const geometry = new THREE.SphereGeometry(radius, 32, 32);
61
- const material = new THREE.MeshPhongMaterial({
62
- color: 0x7777ff,
63
- side: THREE.DoubleSide,
64
- transparent: true,
65
- opacity: 0.5,
66
- wireframe: true
67
- });
68
- const sphere = new THREE.Mesh(geometry, material);
69
- sphere.visible = true;
70
- sphere.name = 'OrientedImageBackground';
71
- return sphere;
72
- }
73
-
74
- /**
75
- * OrientedImageLayer loads oriented images, and project these textures on the scene.
76
- * It is design to create an immersive view. </br>
77
- * It loads a set of panoramic position and orientation,
78
- * a set of camera calibration file (it's the same set of camera for each panoramic),
79
- * and a set of texture (each image for each camera for each panoramic), all organised in an {@link OrientedImageSource}. </br>
80
- * It creates an {@link OrientedImageMaterial} used to do projective texture mapping on the scene.
81
- * @extends GeometryLayer
82
- */
83
- class OrientedImageLayer extends GeometryLayer {
84
- /**
85
- * @param { string } id - The id of the layer, a unique name.
86
- * @param { Object } config - configuration of the layer
87
- * @param { number } config.backgroundDistance - Radius in meter of the sphere used as a background
88
- * @param { function } config.onPanoChanged - callback fired when current panoramic changes
89
- * @param { string } config.crs - crs projection of the view
90
- * @param { string } config.orientation - Json object, using GeoJSon format to represent points,
91
- * it's a set of panoramic position and orientation.
92
- * @param { string } config.calibrations - Json object, representing a set of camera.
93
- * see {@link CameraCalibrationParser}
94
- * @param { OrientedImageSource } config.source - Source used to build url of texture for each oriented image,
95
- * a tecture is need for each camera, for each panoramic.
96
- */
97
- constructor(id) {
98
- let config = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
99
- const {
100
- backgroundDistance,
101
- background = createBackground(backgroundDistance),
102
- onPanoChanged = () => {},
103
- getCamerasNameFromFeature = () => {},
104
- ...geometryOptions
105
- } = config;
106
- if (config.projection) {
107
- console.warn('OrientedImageLayer projection parameter is deprecated, use crs instead.');
108
- config.crs = config.crs || config.projection;
109
- }
110
- super(id, new THREE.Group(), geometryOptions);
111
- this.isOrientedImageLayer = true;
112
- this.background = background;
113
- if (this.background) {
114
- // Add layer id to easily identify the objects later on (e.g. to delete the geometries when deleting the layer)
115
- this.background.layer = this.background.layer ?? {};
116
- this.background.layer.id = this.background.layer.id ?? id;
117
- this.object3d.add(this.background);
118
- }
119
-
120
- // currentPano is the current point, means it's the closest from the camera
121
- this.currentPano = undefined;
122
-
123
- // store a callback to fire event when current panoramic change
124
- this.onPanoChanged = onPanoChanged;
125
-
126
- // function to get cameras name from panoramic feature
127
- this.getCamerasNameFromFeature = getCamerasNameFromFeature;
128
- const resolve = this.addInitializationStep();
129
- this.mergeFeatures = false;
130
- this.filteringExtent = false;
131
- this.accurate = true;
132
- const options = {
133
- out: this
134
- };
135
-
136
- // panos is an array of feature point, representing many panoramics.
137
- // for each point, there is a position and a quaternion attribute.
138
- this.source.whenReady.then(metadata => GeoJsonParser.parse(config.orientation || metadata.orientation, options).then(orientation => {
139
- this.panos = orientation.features;
140
-
141
- // the crs input is parsed in geojson parser
142
- // and returned in options.in
143
- const crsIn = options.in.crs;
144
- const crsOut = config.crs;
145
- const crs2crs = OrientationUtils.quaternionFromCRSToCRS(crsIn, crsOut);
146
- const quat = new THREE.Quaternion();
147
-
148
- // add position and quaternion attributes from point feature
149
- let i = 0;
150
- for (const pano of this.panos) {
151
- // set position
152
- coord.crs = pano.crs;
153
- coord.setFromArray(pano.vertices).applyMatrix4(orientation.matrix);
154
- pano.position = coord.toVector3();
155
-
156
- // set quaternion
157
- crs2crs(coord, quat);
158
- pano.quaternion = OrientationUtils.quaternionFromAttitude(pano.geometries[0].properties).premultiply(quat);
159
- pano.id = pano.geometries[0].properties.id;
160
- pano.index = i++;
161
- }
162
- }).then(() => {
163
- // array of cameras, represent the projective texture configuration for each panoramic.
164
- CameraCalibrationParser.parse(config.calibration || metadata.calibration, config).then(cameras => {
165
- this.cameras = cameras;
166
- // create the material
167
- this.material = new OrientedImageMaterial(this.cameras, config);
168
- resolve();
169
- });
170
- }));
171
- }
172
-
173
- // eslint-disable-next-line
174
- update() {}
175
- set boostLight(value) {
176
- this.material.uniforms.boostLight.value = value;
177
- }
178
- get boostLight() {
179
- return this.material.uniforms.boostLight.value;
180
- }
181
- preUpdate(context) {
182
- updatePano(context, context.camera.camera3D, this);
183
- this.material.updateUniforms(context.camera.camera3D);
184
- updateBackground(this);
185
- }
186
- getNextPano() {
187
- const index = (this.currentPano.index + 1) % this.panos.length;
188
- return this.panos[index];
189
- }
190
- getCurrentPano() {
191
- return this.currentPano;
192
- }
193
- getPreviousPano() {
194
- const index = (this.currentPano.index - 1) % this.panos.length;
195
- return this.panos[index];
196
- }
197
-
198
- /**
199
- * Delete background, but doesn't delete OrientedImageLayer.material. For the moment, this material visibility is set to false.
200
- * You need to replace OrientedImageLayer.material applied on each object, if you want to continue displaying them.
201
- * This issue (see #1018 {@link https://github.com/iTowns/itowns/issues/1018}) will be fixed when OrientedImageLayer will be a ColorLayer.
202
- * @param {boolean} [clearCache=false] Whether to clear the layer cache or not
203
- */
204
- delete(clearCache) {
205
- if (this.background) {
206
- // only delete geometries if it has some
207
- super.delete();
208
- }
209
- if (clearCache) {
210
- this.cache.clear();
211
- }
212
- this.material.visible = false;
213
- console.warn('You need to replace OrientedImageLayer.material applied on each object. This issue will be fixed when OrientedImageLayer will be a ColorLayer. the material visibility is set to false. To follow issue see https://github.com/iTowns/itowns/issues/1018');
214
- }
215
- mostNearPano(position) {
216
- let minDistance = Infinity;
217
- let nearPano;
218
- for (const pano of this.panos) {
219
- const distance = position.distanceTo(pano.position);
220
- if (distance < minDistance) {
221
- minDistance = distance;
222
- nearPano = pano;
223
- }
224
- }
225
- return nearPano;
226
- }
227
- }
228
- export default OrientedImageLayer;
@@ -1,405 +0,0 @@
1
- import * as THREE from 'three';
2
- import GeometryLayer from "./GeometryLayer.js";
3
- import PointsMaterial, { PNTS_MODE } from "../Renderer/PointsMaterial.js";
4
- import Picking from "../Core/Picking.js";
5
- const point = new THREE.Vector3();
6
- const bboxMesh = new THREE.Mesh();
7
- const box3 = new THREE.Box3();
8
- bboxMesh.geometry.boundingBox = box3;
9
- function initBoundingBox(elt, layer) {
10
- elt.tightbbox.getSize(box3.max);
11
- box3.max.multiplyScalar(0.5);
12
- box3.min.copy(box3.max).negate();
13
- elt.obj.boxHelper = new THREE.BoxHelper(bboxMesh);
14
- elt.obj.boxHelper.geometry = elt.obj.boxHelper.geometry.toNonIndexed();
15
- elt.obj.boxHelper.computeLineDistances();
16
- elt.obj.boxHelper.material = elt.childrenBitField ? new THREE.LineDashedMaterial({
17
- dashSize: 0.25,
18
- gapSize: 0.25
19
- }) : new THREE.LineBasicMaterial();
20
- elt.obj.boxHelper.material.color.setHex(0);
21
- elt.obj.boxHelper.material.linewidth = 2;
22
- elt.obj.boxHelper.frustumCulled = false;
23
- elt.obj.boxHelper.position.copy(elt.tightbbox.min).add(box3.max);
24
- elt.obj.boxHelper.autoUpdateMatrix = false;
25
- layer.bboxes.add(elt.obj.boxHelper);
26
- elt.obj.boxHelper.updateMatrix();
27
- elt.obj.boxHelper.updateMatrixWorld();
28
- }
29
- function computeSSEPerspective(context, pointSize, spacing, elt, distance) {
30
- if (distance <= 0) {
31
- return Infinity;
32
- }
33
- const pointSpacing = spacing / 2 ** elt.depth;
34
- // Estimate the onscreen distance between 2 points
35
- const onScreenSpacing = context.camera.preSSE * pointSpacing / distance;
36
- // [ P1 ]--------------[ P2 ]
37
- // <---------------------> = pointsSpacing (in world coordinates)
38
- // ~ onScreenSpacing (in pixels)
39
- // <------> = pointSize (in pixels)
40
- return Math.max(0.0, onScreenSpacing - pointSize);
41
- }
42
- function computeSSEOrthographic(context, pointSize, spacing, elt) {
43
- const pointSpacing = spacing / 2 ** elt.depth;
44
-
45
- // Given an identity view matrix, project pointSpacing from world space to
46
- // clip space. v' = vVP = vP
47
- const v = new THREE.Vector4(pointSpacing);
48
- v.applyMatrix4(context.camera.camera3D.projectionMatrix);
49
-
50
- // We map v' to the screen space and calculate the distance to the origin.
51
- const dx = v.x * 0.5 * context.camera.width;
52
- const dy = v.y * 0.5 * context.camera.height;
53
- const distance = Math.sqrt(dx * dx + dy * dy);
54
- return Math.max(0.0, distance - pointSize);
55
- }
56
- function computeScreenSpaceError(context, pointSize, spacing, elt, distance) {
57
- if (context.camera.camera3D.isOrthographicCamera) {
58
- return computeSSEOrthographic(context, pointSize, spacing, elt);
59
- }
60
- return computeSSEPerspective(context, pointSize, spacing, elt, distance);
61
- }
62
- function markForDeletion(elt) {
63
- if (elt.obj) {
64
- elt.obj.visible = false;
65
- }
66
- if (!elt.notVisibleSince) {
67
- elt.notVisibleSince = Date.now();
68
- // Set .sse to an invalid value
69
- elt.sse = -1;
70
- }
71
- for (const child of elt.children) {
72
- markForDeletion(child);
73
- }
74
- }
75
- function changeIntensityRange(layer) {
76
- layer.material.intensityRange?.set(layer.minIntensityRange, layer.maxIntensityRange);
77
- }
78
- function changeElevationRange(layer) {
79
- layer.material.elevationRange?.set(layer.minElevationRange, layer.maxElevationRange);
80
- }
81
- function changeAngleRange(layer) {
82
- layer.material.angleRange?.set(layer.minAngleRange, layer.maxAngleRange);
83
- }
84
-
85
- /**
86
- * The basis for all point clouds related layers.
87
- *
88
- * @property {boolean} isPointCloudLayer - Used to checkout whether this layer
89
- * is a PointCloudLayer. Default is `true`. You should not change this, as it is
90
- * used internally for optimisation.
91
- * @property {THREE.Group|THREE.Object3D} group - Contains the created
92
- * `THREE.Points` meshes, usually with an instance of a `THREE.Points` per node.
93
- * @property {THREE.Group|THREE.Object3D} bboxes - Contains the bounding boxes
94
- * (`THREE.Box3`) of the tree, usually one per node.
95
- * @property {number} octreeDepthLimit - The depth limit at which to stop
96
- * browsing the octree. Can be used to limit the browsing, without having to
97
- * edit manually the source of the point cloud. No limit by default (`-1`).
98
- * @property {number} [pointBudget=2000000] - Maximum number of points to
99
- * display at the same time. This influences the performance of rendering.
100
- * Default to two millions points.
101
- * @property {number} [sseThreshold=2] - Threshold of the **S**creen **S**pace
102
- * **E**rror. Default to `2`.
103
- * @property {number} [pointSize=4] - The size (in pixels) of the points.
104
- * Default to `4`.
105
- * @property {THREE.Material|PointsMaterial} [material=new PointsMaterial] - The
106
- * material to use to display the points of the cloud. Be default it is a new
107
- * `PointsMaterial`.
108
- * @property {number} [mode=PNTS_MODE.COLOR] - The displaying mode of the points.
109
- * Values are specified in `PointsMaterial`.
110
- * @property {number} [minIntensityRange=0] - The minimal intensity of the
111
- * layer. Changing this value will affect the material, if it has the
112
- * corresponding uniform. The value is normalized between 0 and 1.
113
- * @property {number} [maxIntensityRange=1] - The maximal intensity of the
114
- * layer. Changing this value will affect the material, if it has the
115
- * corresponding uniform. The value is normalized between 0 and 1.
116
- *
117
- * @extends GeometryLayer
118
- */
119
- class PointCloudLayer extends GeometryLayer {
120
- /**
121
- * Constructs a new instance of point cloud layer.
122
- * Constructs a new instance of a Point Cloud Layer. This should not be used
123
- * directly, but rather implemented using `extends`.
124
- *
125
- * @param {string} id - The id of the layer, that should be unique. It is
126
- * not mandatory, but an error will be emitted if this layer is added a
127
- * {@link View} that already has a layer going by that id.
128
- * @param {Object} [config] - Optional configuration, all elements in it
129
- * will be merged as is in the layer. For example, if the configuration
130
- * contains three elements `name, protocol, extent`, these elements will be
131
- * available using `layer.name` or something else depending on the property
132
- * name. See the list of properties to know which one can be specified.
133
- * @param {Source} config.source - Description and options of the source See @Layer.
134
- * @param {number} [options.minElevationRange] - Min value for the elevation range (default value will be taken from the source.metadata).
135
- * @param {number} [options.maxElevationRange] - Max value for the elevation range (default value will be taken from the source.metadata).
136
- */
137
- constructor(id) {
138
- let config = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
139
- const {
140
- object3d = new THREE.Group(),
141
- group = new THREE.Group(),
142
- bboxes = new THREE.Group(),
143
- octreeDepthLimit = -1,
144
- pointBudget = 2000000,
145
- pointSize = 2,
146
- sseThreshold = 2,
147
- minIntensityRange = 1,
148
- maxIntensityRange = 65536,
149
- minElevationRange,
150
- maxElevationRange,
151
- minAngleRange = -90,
152
- maxAngleRange = 90,
153
- material = {},
154
- mode = PNTS_MODE.COLOR,
155
- ...geometryLayerConfig
156
- } = config;
157
- super(id, object3d, geometryLayerConfig);
158
-
159
- /**
160
- * @type {boolean}
161
- * @readonly
162
- */
163
- this.isPointCloudLayer = true;
164
- this.protocol = 'pointcloud';
165
- this.group = group;
166
- this.object3d.add(this.group);
167
- this.bboxes = bboxes || new THREE.Group();
168
- this.bboxes.visible = false;
169
- this.object3d.add(this.bboxes);
170
- this.group.updateMatrixWorld();
171
-
172
- // default config
173
- /**
174
- * @type {number}
175
- */
176
- this.octreeDepthLimit = octreeDepthLimit;
177
-
178
- /**
179
- * @type {number}
180
- */
181
- this.pointBudget = pointBudget;
182
-
183
- /**
184
- * @type {number}
185
- */
186
- this.pointSize = pointSize;
187
-
188
- /**
189
- * @type {number}
190
- */
191
- this.sseThreshold = sseThreshold;
192
- this.defineLayerProperty('minIntensityRange', minIntensityRange, changeIntensityRange);
193
- this.defineLayerProperty('maxIntensityRange', maxIntensityRange, changeIntensityRange);
194
- this.defineLayerProperty('minElevationRange', minElevationRange, changeElevationRange);
195
- this.defineLayerProperty('maxElevationRange', maxElevationRange, changeElevationRange);
196
- this.defineLayerProperty('minAngleRange', minAngleRange, changeAngleRange);
197
- this.defineLayerProperty('maxAngleRange', maxAngleRange, changeAngleRange);
198
-
199
- /**
200
- * @type {THREE.Material}
201
- */
202
- this.material = material;
203
- if (!this.material.isMaterial) {
204
- this.material.intensityRange = new THREE.Vector2(this.minIntensityRange, this.maxIntensityRange);
205
- this.material.elevationRange = new THREE.Vector2(this.minElevationRange, this.maxElevationRange);
206
- this.material.angleRange = new THREE.Vector2(this.minAngleRange, this.maxAngleRange);
207
- this.material = new PointsMaterial(this.material);
208
- }
209
- this.mode = mode || PNTS_MODE.COLOR;
210
-
211
- /**
212
- * @type {PointCloudNode | undefined}
213
- */
214
- this.root = undefined;
215
- }
216
- preUpdate(context, changeSources) {
217
- // See https://cesiumjs.org/hosted-apps/massiveworlds/downloads/Ring/WorldScaleTerrainRendering.pptx
218
- // slide 17
219
- context.camera.preSSE = context.camera.height / (2 * Math.tan(THREE.MathUtils.degToRad(context.camera.camera3D.fov) * 0.5));
220
- if (this.material) {
221
- this.material.visible = this.visible;
222
- this.material.opacity = this.opacity;
223
- this.material.transparent = this.opacity < 1 || this.material.userData.needTransparency[this.material.mode];
224
- this.material.size = this.pointSize;
225
- this.material.scale = context.camera.preSSE;
226
- if (this.material.updateUniforms) {
227
- this.material.updateUniforms();
228
- }
229
- }
230
-
231
- // lookup lowest common ancestor of changeSources
232
- let commonAncestor;
233
- for (const source of changeSources.values()) {
234
- if (source.isCamera || source == this) {
235
- // if the change is caused by a camera move, no need to bother
236
- // to find common ancestor: we need to update the whole tree:
237
- // some invisible tiles may now be visible
238
- return [this.root];
239
- }
240
- if (source.obj === undefined) {
241
- continue;
242
- }
243
- // filter sources that belong to our layer
244
- if (source.obj.isPoints && source.obj.layer == this) {
245
- if (!commonAncestor) {
246
- commonAncestor = source;
247
- } else {
248
- commonAncestor = source.findCommonAncestor(commonAncestor);
249
- if (!commonAncestor) {
250
- return [this.root];
251
- }
252
- }
253
- }
254
- }
255
- if (commonAncestor) {
256
- return [commonAncestor];
257
- }
258
-
259
- // Start updating from hierarchy root
260
- return [this.root];
261
- }
262
- update(context, layer, elt) {
263
- elt.visible = false;
264
- if (this.octreeDepthLimit >= 0 && this.octreeDepthLimit < elt.depth) {
265
- markForDeletion(elt);
266
- return;
267
- }
268
-
269
- // pick the best bounding box
270
- const bbox = elt.tightbbox ? elt.tightbbox : elt.bbox;
271
- elt.visible = context.camera.isBox3Visible(bbox, this.object3d.matrixWorld);
272
- if (!elt.visible) {
273
- markForDeletion(elt);
274
- return;
275
- }
276
- elt.notVisibleSince = undefined;
277
- point.copy(context.camera.camera3D.position).sub(this.object3d.getWorldPosition(new THREE.Vector3()));
278
- point.applyQuaternion(this.object3d.getWorldQuaternion(new THREE.Quaternion()).invert());
279
-
280
- // only load geometry if this elements has points
281
- if (elt.numPoints !== 0) {
282
- if (elt.obj) {
283
- elt.obj.visible = true;
284
- } else if (!elt.promise) {
285
- const distance = Math.max(0.001, bbox.distanceToPoint(point));
286
- // Increase priority of nearest node
287
- const priority = computeScreenSpaceError(context, layer.pointSize, layer.spacing, elt, distance) / distance;
288
- elt.promise = context.scheduler.execute({
289
- layer,
290
- requester: elt,
291
- view: context.view,
292
- priority,
293
- redraw: true,
294
- earlyDropFunction: cmd => !cmd.requester.visible || !this.visible
295
- }).then(pts => {
296
- elt.obj = pts;
297
- // store tightbbox to avoid ping-pong (bbox = larger => visible, tight => invisible)
298
- elt.tightbbox = pts.tightbbox;
299
-
300
- // make sure to add it here, otherwise it might never
301
- // be added nor cleaned
302
- this.group.add(elt.obj);
303
- elt.obj.updateMatrixWorld(true);
304
- }).catch(err => {
305
- if (!err.isCancelledCommandException) {
306
- return err;
307
- }
308
- }).finally(() => {
309
- elt.promise = null;
310
- });
311
- }
312
- }
313
- if (elt.children && elt.children.length) {
314
- const distance = bbox.distanceToPoint(point);
315
- elt.sse = computeScreenSpaceError(context, layer.pointSize, layer.spacing, elt, distance) / this.sseThreshold;
316
- if (elt.sse >= 1) {
317
- return elt.children;
318
- } else {
319
- for (const child of elt.children) {
320
- markForDeletion(child);
321
- }
322
- }
323
- }
324
- }
325
- postUpdate() {
326
- this.displayedCount = 0;
327
- for (const pts of this.group.children) {
328
- if (pts.visible) {
329
- const count = pts.geometry.attributes.position.count;
330
- pts.geometry.setDrawRange(0, count);
331
- this.displayedCount += count;
332
- }
333
- }
334
- if (this.displayedCount > this.pointBudget) {
335
- // 2 different point count limit implementation, depending on the potree source
336
- if (this.supportsProgressiveDisplay) {
337
- // In this format, points are evenly distributed within a node,
338
- // so we can draw a percentage of each node and still get a correct
339
- // representation
340
- const reduction = this.pointBudget / this.displayedCount;
341
- for (const pts of this.group.children) {
342
- if (pts.visible) {
343
- const count = Math.floor(pts.geometry.drawRange.count * reduction);
344
- if (count > 0) {
345
- pts.geometry.setDrawRange(0, count);
346
- } else {
347
- pts.visible = false;
348
- }
349
- }
350
- }
351
- this.displayedCount *= reduction;
352
- } else {
353
- // This format doesn't require points to be evenly distributed, so
354
- // we're going to sort the nodes by "importance" (= on screen size)
355
- // and display only the first N nodes
356
- this.group.children.sort((p1, p2) => p2.userData.node.sse - p1.userData.node.sse);
357
- let limitHit = false;
358
- this.displayedCount = 0;
359
- for (const pts of this.group.children) {
360
- const count = pts.geometry.attributes.position.count;
361
- if (limitHit || this.displayedCount + count > this.pointBudget) {
362
- pts.visible = false;
363
- limitHit = true;
364
- } else {
365
- this.displayedCount += count;
366
- }
367
- }
368
- }
369
- }
370
- const now = Date.now();
371
- for (let i = this.group.children.length - 1; i >= 0; i--) {
372
- const obj = this.group.children[i];
373
- if (!obj.visible && now - obj.userData.node.notVisibleSince > 10000) {
374
- // remove from group
375
- this.group.children.splice(i, 1);
376
-
377
- // no need to dispose obj.material, as it is shared by all objects of this layer
378
- obj.geometry.dispose();
379
- obj.material = null;
380
- obj.geometry = null;
381
- obj.userData.node.obj = null;
382
- }
383
- }
384
- }
385
- pickObjectsAt(view, mouse, radius) {
386
- let target = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : [];
387
- return Picking.pickPointsAt(view, mouse, radius, this, target);
388
- }
389
- getObjectToUpdateForAttachedLayers(meta) {
390
- if (meta.obj) {
391
- const p = meta.parent;
392
- if (p && p.obj) {
393
- return {
394
- element: meta.obj,
395
- parent: p.obj
396
- };
397
- } else {
398
- return {
399
- element: meta.obj
400
- };
401
- }
402
- }
403
- }
404
- }
405
- export default PointCloudLayer;