itowns 2.44.3-next.4 → 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 (217) 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 -608
  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 -726
  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/TileGeometry.js +0 -40
  100. package/lib/Core/TileMesh.js +0 -108
  101. package/lib/Core/View.js +0 -1109
  102. package/lib/Layer/C3DTilesLayer.js +0 -455
  103. package/lib/Layer/ColorLayer.js +0 -128
  104. package/lib/Layer/CopcLayer.js +0 -58
  105. package/lib/Layer/ElevationLayer.js +0 -107
  106. package/lib/Layer/EntwinePointTileLayer.js +0 -64
  107. package/lib/Layer/FeatureGeometryLayer.js +0 -63
  108. package/lib/Layer/GeoidLayer.js +0 -80
  109. package/lib/Layer/GeometryLayer.js +0 -202
  110. package/lib/Layer/InfoLayer.js +0 -64
  111. package/lib/Layer/LabelLayer.js +0 -452
  112. package/lib/Layer/Layer.js +0 -304
  113. package/lib/Layer/LayerUpdateState.js +0 -89
  114. package/lib/Layer/LayerUpdateStrategy.js +0 -80
  115. package/lib/Layer/OGC3DTilesLayer.js +0 -387
  116. package/lib/Layer/OrientedImageLayer.js +0 -222
  117. package/lib/Layer/PointCloudLayer.js +0 -359
  118. package/lib/Layer/Potree2Layer.js +0 -164
  119. package/lib/Layer/PotreeLayer.js +0 -65
  120. package/lib/Layer/RasterLayer.js +0 -27
  121. package/lib/Layer/ReferencingLayerProperties.js +0 -62
  122. package/lib/Layer/TiledGeometryLayer.js +0 -403
  123. package/lib/Loader/LASLoader.js +0 -193
  124. package/lib/Loader/Potree2BrotliLoader.js +0 -261
  125. package/lib/Loader/Potree2Loader.js +0 -207
  126. package/lib/Main.js +0 -115
  127. package/lib/MainBundle.js +0 -4
  128. package/lib/Parser/B3dmParser.js +0 -174
  129. package/lib/Parser/CameraCalibrationParser.js +0 -94
  130. package/lib/Parser/GDFParser.js +0 -72
  131. package/lib/Parser/GTXParser.js +0 -75
  132. package/lib/Parser/GeoJsonParser.js +0 -212
  133. package/lib/Parser/GpxParser.js +0 -25
  134. package/lib/Parser/ISGParser.js +0 -71
  135. package/lib/Parser/KMLParser.js +0 -25
  136. package/lib/Parser/LASParser.js +0 -137
  137. package/lib/Parser/MapBoxUrlParser.js +0 -83
  138. package/lib/Parser/PntsParser.js +0 -131
  139. package/lib/Parser/Potree2BinParser.js +0 -92
  140. package/lib/Parser/PotreeBinParser.js +0 -106
  141. package/lib/Parser/PotreeCinParser.js +0 -29
  142. package/lib/Parser/ShapefileParser.js +0 -78
  143. package/lib/Parser/VectorTileParser.js +0 -202
  144. package/lib/Parser/XbilParser.js +0 -108
  145. package/lib/Parser/deprecated/LegacyGLTFLoader.js +0 -1386
  146. package/lib/Parser/iGLTFLoader.js +0 -168
  147. package/lib/Process/3dTilesProcessing.js +0 -304
  148. package/lib/Process/FeatureProcessing.js +0 -76
  149. package/lib/Process/LayeredMaterialNodeProcessing.js +0 -221
  150. package/lib/Process/ObjectRemovalHelper.js +0 -97
  151. package/lib/Process/handlerNodeError.js +0 -23
  152. package/lib/Provider/3dTilesProvider.js +0 -149
  153. package/lib/Provider/DataSourceProvider.js +0 -8
  154. package/lib/Provider/Fetcher.js +0 -229
  155. package/lib/Provider/PointCloudProvider.js +0 -45
  156. package/lib/Provider/TileProvider.js +0 -16
  157. package/lib/Provider/URLBuilder.js +0 -105
  158. package/lib/Renderer/Camera.js +0 -281
  159. package/lib/Renderer/Color.js +0 -56
  160. package/lib/Renderer/ColorLayersOrdering.js +0 -115
  161. package/lib/Renderer/CommonMaterial.js +0 -31
  162. package/lib/Renderer/Label2DRenderer.js +0 -190
  163. package/lib/Renderer/LayeredMaterial.js +0 -243
  164. package/lib/Renderer/OBB.js +0 -153
  165. package/lib/Renderer/OrientedImageCamera.js +0 -118
  166. package/lib/Renderer/OrientedImageMaterial.js +0 -167
  167. package/lib/Renderer/PointsMaterial.js +0 -485
  168. package/lib/Renderer/RasterTile.js +0 -209
  169. package/lib/Renderer/RenderMode.js +0 -31
  170. package/lib/Renderer/Shader/ShaderChunk.js +0 -160
  171. package/lib/Renderer/Shader/ShaderUtils.js +0 -47
  172. package/lib/Renderer/SphereHelper.js +0 -23
  173. package/lib/Renderer/WebXR.js +0 -51
  174. package/lib/Renderer/c3DEngine.js +0 -214
  175. package/lib/Source/C3DTilesGoogleSource.js +0 -74
  176. package/lib/Source/C3DTilesIonSource.js +0 -54
  177. package/lib/Source/C3DTilesSource.js +0 -30
  178. package/lib/Source/CopcSource.js +0 -115
  179. package/lib/Source/EntwinePointTileSource.js +0 -62
  180. package/lib/Source/FileSource.js +0 -189
  181. package/lib/Source/OGC3DTilesGoogleSource.js +0 -29
  182. package/lib/Source/OGC3DTilesIonSource.js +0 -34
  183. package/lib/Source/OGC3DTilesSource.js +0 -21
  184. package/lib/Source/OrientedImageSource.js +0 -59
  185. package/lib/Source/Potree2Source.js +0 -167
  186. package/lib/Source/PotreeSource.js +0 -82
  187. package/lib/Source/Source.js +0 -223
  188. package/lib/Source/TMSSource.js +0 -143
  189. package/lib/Source/VectorTilesSource.js +0 -178
  190. package/lib/Source/WFSSource.js +0 -165
  191. package/lib/Source/WMSSource.js +0 -130
  192. package/lib/Source/WMTSSource.js +0 -86
  193. package/lib/ThreeExtended/capabilities/WebGL.js +0 -69
  194. package/lib/ThreeExtended/libs/ktx-parse.module.js +0 -470
  195. package/lib/ThreeExtended/libs/zstddec.module.js +0 -29
  196. package/lib/ThreeExtended/loaders/DDSLoader.js +0 -200
  197. package/lib/ThreeExtended/loaders/DRACOLoader.js +0 -399
  198. package/lib/ThreeExtended/loaders/GLTFLoader.js +0 -2876
  199. package/lib/ThreeExtended/loaders/KTX2Loader.js +0 -625
  200. package/lib/ThreeExtended/utils/BufferGeometryUtils.js +0 -846
  201. package/lib/ThreeExtended/utils/WorkerPool.js +0 -70
  202. package/lib/Utils/CameraUtils.js +0 -555
  203. package/lib/Utils/DEMUtils.js +0 -350
  204. package/lib/Utils/FeaturesUtils.js +0 -156
  205. package/lib/Utils/Gradients.js +0 -16
  206. package/lib/Utils/OrientationUtils.js +0 -457
  207. package/lib/Utils/ThreeUtils.js +0 -115
  208. package/lib/Utils/gui/C3DTilesStyle.js +0 -216
  209. package/lib/Utils/gui/Main.js +0 -7
  210. package/lib/Utils/gui/Minimap.js +0 -154
  211. package/lib/Utils/gui/Navigation.js +0 -245
  212. package/lib/Utils/gui/Scale.js +0 -107
  213. package/lib/Utils/gui/Searchbar.js +0 -234
  214. package/lib/Utils/gui/Widget.js +0 -80
  215. package/lib/Utils/placeObjectOnGround.js +0 -137
  216. package/lib/Worker/LASLoaderWorker.js +0 -19
  217. package/lib/Worker/Potree2Worker.js +0 -21
@@ -1,608 +0,0 @@
1
- import * as THREE from 'three';
2
- import Earcut from 'earcut';
3
- import { FEATURE_TYPES } from "../Core/Feature.js";
4
- import ReferLayerProperties from "../Layer/ReferencingLayerProperties.js";
5
- import { deprecatedFeature2MeshOptions } from "../Core/Deprecated/Undeprecator.js";
6
- import Extent from "../Core/Geographic/Extent.js";
7
- import Crs from "../Core/Geographic/Crs.js";
8
- import OrientationUtils from "../Utils/OrientationUtils.js";
9
- import Coordinates from "../Core/Geographic/Coordinates.js";
10
- import Style, { StyleContext } from "../Core/Style.js";
11
- const coord = new Coordinates('EPSG:4326', 0, 0, 0);
12
- const context = new StyleContext();
13
- const defaultStyle = new Style();
14
- let style;
15
- const dim_ref = new THREE.Vector2();
16
- const dim = new THREE.Vector2();
17
- const normal = new THREE.Vector3();
18
- const baseCoord = new THREE.Vector3();
19
- const topCoord = new THREE.Vector3();
20
- const inverseScale = new THREE.Vector3();
21
- const extent = new Extent('EPSG:4326', 0, 0, 0, 0);
22
- const _color = new THREE.Color();
23
- const maxValueUint8 = 2 ** 8 - 1;
24
- const maxValueUint16 = 2 ** 16 - 1;
25
- const maxValueUint32 = 2 ** 32 - 1;
26
- const crsWGS84 = 'EPSG:4326';
27
- class FeatureMesh extends THREE.Group {
28
- #currentCrs;
29
- #originalCrs;
30
- #collection = (() => new THREE.Group())();
31
- #place = (() => new THREE.Group())();
32
- constructor(meshes, collection) {
33
- super();
34
- this.meshes = new THREE.Group().add(...meshes);
35
- this.#collection = new THREE.Group().add(this.meshes);
36
- this.#collection.quaternion.copy(collection.quaternion);
37
- this.#collection.position.copy(collection.position);
38
- this.#collection.scale.copy(collection.scale);
39
- this.#collection.updateMatrix();
40
- this.#originalCrs = collection.crs;
41
- this.#currentCrs = this.#originalCrs;
42
- this.extent = collection.extent;
43
- this.add(this.#place.add(this.#collection));
44
- }
45
- as(crs) {
46
- if (this.#currentCrs !== crs) {
47
- this.#currentCrs = crs;
48
- if (crs == this.#originalCrs) {
49
- // reset transformation
50
- this.place.position.set(0, 0, 0);
51
- this.position.set(0, 0, 0);
52
- this.scale.set(1, 1, 1);
53
- this.quaternion.identity();
54
- } else {
55
- // calculate the scale transformation to transform the feature.extent
56
- // to feature.extent.as(crs)
57
- coord.crs = Crs.formatToEPSG(this.#originalCrs);
58
- extent.copy(this.extent).applyMatrix4(this.#collection.matrix);
59
- extent.as(coord.crs, extent);
60
- extent.spatialEuclideanDimensions(dim_ref);
61
- extent.planarDimensions(dim);
62
- if (dim.x && dim.y) {
63
- this.scale.copy(dim_ref).divide(dim).setZ(1);
64
- }
65
-
66
- // Position and orientation
67
- // remove original position
68
- this.#place.position.copy(this.#collection.position).negate();
69
-
70
- // get mesh coordinate
71
- coord.setFromVector3(this.#collection.position);
72
-
73
- // get method to calculate orientation
74
- const crsInput = this.#originalCrs == 'EPSG:3857' ? crsWGS84 : this.#originalCrs;
75
- const crs2crs = OrientationUtils.quaternionFromCRSToCRS(crsInput, crs);
76
- // calculate orientation to crs
77
- crs2crs(coord.as(crsWGS84), this.quaternion);
78
-
79
- // transform position to crs
80
- coord.as(crs, coord).toVector3(this.position);
81
- }
82
- }
83
- return this;
84
- }
85
- }
86
- function toColor(color) {
87
- if (color) {
88
- if (color.type == 'Color') {
89
- return color;
90
- } else {
91
- return _color.set(color);
92
- }
93
- } else {
94
- return _color.set(Math.random() * 0xffffff);
95
- }
96
- }
97
- function getIntArrayFromSize(data, size) {
98
- if (size <= maxValueUint8) {
99
- return new Uint8Array(data);
100
- } else if (size <= maxValueUint16) {
101
- return new Uint16Array(data);
102
- } else {
103
- return new Uint32Array(data);
104
- }
105
- }
106
- function separateMeshes(object3D) {
107
- const meshes = [];
108
- object3D.updateMatrixWorld();
109
- object3D.traverse(element => {
110
- if (element instanceof THREE.Mesh) {
111
- element.updateMatrixWorld();
112
- element.geometry.applyMatrix4(element.matrixWorld);
113
- meshes.push(element);
114
- }
115
- });
116
- return meshes;
117
- }
118
-
119
- /**
120
- * Add indices for the side faces.
121
- * We loop over the contour and create a side face made of two triangles.
122
- *
123
- * For a ring made of (n) coordinates, there are (n*2) vertices.
124
- * The (n) first vertices are on the roof, the (n) other vertices are on the floor.
125
- *
126
- * If index (i) is on the roof, index (i+length) is on the floor.
127
- *
128
- * @param {number[]} indices - Array of indices to push to
129
- * @param {number} length - Total vertices count in the geom (excluding the extrusion ones)
130
- * @param {number} offset
131
- * @param {number} count
132
- * @param {boolean} isClockWise - Wrapping direction
133
- */
134
- function addExtrudedPolygonSideFaces(indices, length, offset, count, isClockWise) {
135
- // loop over contour length, and for each point of the contour,
136
- // add indices to make two triangle, that make the side face
137
- const startIndice = indices.length;
138
- indices.length += (count - 1) * 6;
139
- for (let i = offset, j = startIndice; i < offset + count - 1; ++i, ++j) {
140
- if (isClockWise) {
141
- // first triangle indices
142
- indices[j] = i;
143
- indices[++j] = i + length;
144
- indices[++j] = i + 1;
145
- // second triangle indices
146
- indices[++j] = i + 1;
147
- indices[++j] = i + length;
148
- indices[++j] = i + length + 1;
149
- } else {
150
- // first triangle indices
151
- indices[j] = i + length;
152
- indices[++j] = i;
153
- indices[++j] = i + length + 1;
154
- // second triangle indices
155
- indices[++j] = i + length + 1;
156
- indices[++j] = i;
157
- indices[++j] = i + 1;
158
- }
159
- }
160
- }
161
- function featureToPoint(feature, options) {
162
- const ptsIn = feature.vertices;
163
- const colors = new Uint8Array(ptsIn.length);
164
- const batchIds = new Uint32Array(ptsIn.length);
165
- const batchId = options.batchId || ((p, id) => id);
166
- let featureId = 0;
167
- const vertices = new Float32Array(ptsIn);
168
- inverseScale.setFromMatrixScale(context.collection.matrixWorldInverse);
169
- normal.set(0, 0, 1).multiply(inverseScale);
170
- const pointMaterialSize = [];
171
- context.setFeature(feature);
172
- for (const geometry of feature.geometries) {
173
- const start = geometry.indices[0].offset;
174
- const count = geometry.indices[0].count;
175
- const id = batchId(geometry.properties, featureId);
176
- context.setGeometry(geometry);
177
- for (let v = start * 3, j = start; j < start + count; v += 3, j += 1) {
178
- if (feature.normals) {
179
- normal.fromArray(feature.normals, v).multiply(inverseScale);
180
- }
181
- const localCoord = context.setLocalCoordinatesFromArray(feature.vertices, v);
182
- style.setContext(context);
183
- const {
184
- base_altitude,
185
- color,
186
- radius
187
- } = style.point;
188
- coord.copy(localCoord).applyMatrix4(context.collection.matrixWorld);
189
- if (coord.crs == 'EPSG:4978') {
190
- // altitude convertion from geocentered to elevation (from ground)
191
- coord.as('EPSG:4326', coord);
192
- }
193
-
194
- // Calculate the new coordinates using the elevation shift (baseCoord)
195
- baseCoord.copy(normal).multiplyScalar(base_altitude - coord.z).add(localCoord)
196
- // and update the geometry buffer (vertices).
197
- .toArray(vertices, v);
198
- toColor(color).multiplyScalar(255).toArray(colors, v);
199
- if (!pointMaterialSize.includes(radius)) {
200
- pointMaterialSize.push(radius);
201
- }
202
- batchIds[j] = id;
203
- }
204
- featureId++;
205
- }
206
- const geom = new THREE.BufferGeometry();
207
- geom.setAttribute('position', new THREE.BufferAttribute(vertices, 3));
208
- geom.setAttribute('color', new THREE.BufferAttribute(colors, 3, true));
209
- geom.setAttribute('batchId', new THREE.BufferAttribute(batchIds, 1));
210
- options.pointMaterial.size = pointMaterialSize[0];
211
- if (pointMaterialSize.length > 1) {
212
- // TODO CREATE material for each feature
213
- console.warn('Too many differents point.radius, only the first one will be used');
214
- }
215
- return new THREE.Points(geom, options.pointMaterial);
216
- }
217
- function featureToLine(feature, options) {
218
- const ptsIn = feature.vertices;
219
- const colors = new Uint8Array(ptsIn.length);
220
- const count = ptsIn.length / 3;
221
- const batchIds = new Uint32Array(count);
222
- const batchId = options.batchId || ((p, id) => id);
223
- let featureId = 0;
224
- const vertices = new Float32Array(ptsIn.length);
225
- const geom = new THREE.BufferGeometry();
226
- const lineMaterialWidth = [];
227
- context.setFeature(feature);
228
- const countIndices = (count - feature.geometries.length) * 2;
229
- const indices = getIntArrayFromSize(countIndices, count);
230
- let i = 0;
231
- inverseScale.setFromMatrixScale(context.collection.matrixWorldInverse);
232
- normal.set(0, 0, 1).multiply(inverseScale);
233
- // Multi line case
234
- for (const geometry of feature.geometries) {
235
- context.setGeometry(geometry);
236
- const id = batchId(geometry.properties, featureId);
237
- const start = geometry.indices[0].offset;
238
- // To avoid integer overflow with indice value (16 bits)
239
- if (start > 0xffff) {
240
- console.warn('Feature to Line: integer overflow, too many points in lines');
241
- break;
242
- }
243
- const count = geometry.indices[0].count;
244
- const end = start + count;
245
- for (let v = start * 3, j = start; j < end; v += 3, j += 1) {
246
- if (j < end - 1) {
247
- if (j < 0xffff) {
248
- indices[i++] = j;
249
- indices[i++] = j + 1;
250
- } else {
251
- break;
252
- }
253
- }
254
- if (feature.normals) {
255
- normal.fromArray(feature.normals, v).multiply(inverseScale);
256
- }
257
- const localCoord = context.setLocalCoordinatesFromArray(feature.vertices, v);
258
- style.setContext(context);
259
- const {
260
- base_altitude,
261
- color,
262
- width
263
- } = style.stroke;
264
- coord.copy(localCoord).applyMatrix4(context.collection.matrixWorld);
265
- if (coord.crs == 'EPSG:4978') {
266
- // altitude convertion from geocentered to elevation (from ground)
267
- coord.as('EPSG:4326', coord);
268
- }
269
-
270
- // Calculate the new coordinates using the elevation shift (baseCoord)
271
- baseCoord.copy(normal).multiplyScalar(base_altitude - coord.z).add(localCoord)
272
- // and update the geometry buffer (vertices).
273
- .toArray(vertices, v);
274
- toColor(color).multiplyScalar(255).toArray(colors, v);
275
- if (!lineMaterialWidth.includes(width)) {
276
- lineMaterialWidth.push(width);
277
- }
278
- batchIds[j] = id;
279
- }
280
- featureId++;
281
- }
282
- options.lineMaterial.linewidth = lineMaterialWidth[0];
283
- if (lineMaterialWidth.length > 1) {
284
- // TODO CREATE material for each feature
285
- console.warn('Too many differents stroke.width, only the first one will be used');
286
- }
287
- geom.setAttribute('position', new THREE.BufferAttribute(vertices, 3));
288
- geom.setAttribute('color', new THREE.BufferAttribute(colors, 3, true));
289
- geom.setAttribute('batchId', new THREE.BufferAttribute(batchIds, 1));
290
- geom.setIndex(new THREE.BufferAttribute(indices, 1));
291
- return new THREE.LineSegments(geom, options.lineMaterial);
292
- }
293
- function featureToPolygon(feature, options) {
294
- const vertices = new Float32Array(feature.vertices);
295
- const colors = new Uint8Array(feature.vertices.length);
296
- const indices = [];
297
- const batchIds = new Uint32Array(vertices.length / 3);
298
- const batchId = options.batchId || ((p, id) => id);
299
- context.setFeature(feature);
300
- inverseScale.setFromMatrixScale(context.collection.matrixWorldInverse);
301
- normal.set(0, 0, 1).multiply(inverseScale);
302
- let featureId = 0;
303
- for (const geometry of feature.geometries) {
304
- const start = geometry.indices[0].offset;
305
- // To avoid integer overflow with index value (32 bits)
306
- if (start > maxValueUint32) {
307
- console.warn('Feature to Polygon: integer overflow, too many points in polygons');
308
- break;
309
- }
310
- context.setGeometry(geometry);
311
- const lastIndice = geometry.indices.slice(-1)[0];
312
- const end = lastIndice.offset + lastIndice.count;
313
- const startIn = start * 3;
314
- const id = batchId(geometry.properties, featureId);
315
- for (let i = startIn, b = start; i < startIn + (end - start) * 3; i += 3, b += 1) {
316
- if (feature.normals) {
317
- normal.fromArray(feature.normals, i).multiply(inverseScale);
318
- }
319
- const localCoord = context.setLocalCoordinatesFromArray(feature.vertices, i);
320
- style.setContext(context);
321
- const {
322
- base_altitude,
323
- color
324
- } = style.fill;
325
- coord.copy(localCoord).applyMatrix4(context.collection.matrixWorld);
326
- if (coord.crs == 'EPSG:4978') {
327
- // altitude convertion from geocentered to elevation (from ground)
328
- coord.as('EPSG:4326', coord);
329
- }
330
-
331
- // Calculate the new coordinates using the elevation shift (baseCoord)
332
- baseCoord.copy(normal).multiplyScalar(base_altitude - coord.z).add(localCoord)
333
- // and update the geometry buffer (vertices).
334
- .toArray(vertices, i);
335
- toColor(color).multiplyScalar(255).toArray(colors, i);
336
- batchIds[b] = id;
337
- }
338
- featureId++;
339
- const geomVertices = vertices.slice(start * 3, end * 3);
340
- const holesOffsets = geometry.indices.map(i => i.offset - start).slice(1);
341
- const triangles = Earcut(geomVertices, holesOffsets, 3);
342
- const startIndice = indices.length;
343
- indices.length += triangles.length;
344
- for (let i = 0; i < triangles.length; i++) {
345
- indices[startIndice + i] = triangles[i] + start;
346
- }
347
- }
348
- const geom = new THREE.BufferGeometry();
349
- geom.setAttribute('position', new THREE.BufferAttribute(vertices, 3));
350
- geom.setAttribute('color', new THREE.BufferAttribute(colors, 3, true));
351
- geom.setAttribute('batchId', new THREE.BufferAttribute(batchIds, 1));
352
- geom.setIndex(new THREE.BufferAttribute(getIntArrayFromSize(indices, vertices.length / 3), 1));
353
- return new THREE.Mesh(geom, options.polygonMaterial);
354
- }
355
- function area(contour, offset, count) {
356
- offset *= 3;
357
- const n = offset + count * 3;
358
- let a = 0.0;
359
- for (let p = n - 3, q = offset; q < n; p = q, q += 3) {
360
- a += contour[p] * contour[q + 1] - contour[q] * contour[p + 1];
361
- }
362
- return a * 0.5;
363
- }
364
- function featureToExtrudedPolygon(feature, options) {
365
- const ptsIn = feature.vertices;
366
- const vertices = new Float32Array(ptsIn.length * 2);
367
- const totalVertices = ptsIn.length / 3;
368
- const colors = new Uint8Array(ptsIn.length * 2);
369
- const indices = [];
370
- const batchIds = new Uint32Array(vertices.length / 3);
371
- const batchId = options.batchId || ((p, id) => id);
372
- let featureId = 0;
373
- context.setFeature(feature);
374
- inverseScale.setFromMatrixScale(context.collection.matrixWorldInverse);
375
- normal.set(0, 0, 1).multiply(inverseScale);
376
- coord.setCrs(context.collection.crs);
377
- for (const geometry of feature.geometries) {
378
- context.setGeometry(geometry);
379
- const start = geometry.indices[0].offset;
380
- const lastIndice = geometry.indices.slice(-1)[0];
381
- const end = lastIndice.offset + lastIndice.count;
382
- const count = end - start;
383
- const isClockWise = geometry.indices[0].ccw ?? area(ptsIn, start, count) < 0;
384
- const startIn = start * 3;
385
- const startTop = start + totalVertices;
386
- const id = batchId(geometry.properties, featureId);
387
- for (let i = startIn, t = startIn + ptsIn.length, b = start; i < startIn + count * 3; i += 3, t += 3, b += 1) {
388
- if (feature.normals) {
389
- normal.fromArray(feature.normals, i).multiply(inverseScale);
390
- }
391
- const localCoord = context.setLocalCoordinatesFromArray(ptsIn, i);
392
- style.setContext(context);
393
- const {
394
- base_altitude,
395
- extrusion_height,
396
- color
397
- } = style.fill;
398
- coord.copy(localCoord).applyMatrix4(context.collection.matrixWorld);
399
- if (coord.crs == 'EPSG:4978') {
400
- // altitude convertion from geocentered to elevation (from ground)
401
- coord.as('EPSG:4326', coord);
402
- }
403
-
404
- // Calculate the new base coordinates using the elevation shift (baseCoord)
405
- baseCoord.copy(normal).multiplyScalar(base_altitude - coord.z).add(localCoord)
406
- // and update the geometry buffer (vertices).
407
- .toArray(vertices, i);
408
- batchIds[b] = id;
409
-
410
- // populate top geometry buffers
411
- topCoord.copy(normal).multiplyScalar(extrusion_height).add(baseCoord).toArray(vertices, t);
412
- batchIds[b + totalVertices] = id;
413
-
414
- // coloring base and top mesh
415
- const meshColor = toColor(color).multiplyScalar(255);
416
- meshColor.toArray(colors, t); // top
417
- meshColor.multiplyScalar(0.5).toArray(colors, i); // base is half dark
418
- }
419
- featureId++;
420
- const geomVertices = vertices.slice(startTop * 3, (end + totalVertices) * 3);
421
- const holesOffsets = geometry.indices.map(i => i.offset - start).slice(1);
422
- const triangles = Earcut(geomVertices, holesOffsets, 3);
423
- const startIndice = indices.length;
424
- indices.length += triangles.length;
425
- for (let i = 0; i < triangles.length; i++) {
426
- indices[startIndice + i] = triangles[i] + startTop;
427
- }
428
-
429
- // add extruded contour
430
- addExtrudedPolygonSideFaces(indices, totalVertices, geometry.indices[0].offset, geometry.indices[0].count, isClockWise);
431
-
432
- // add extruded holes
433
- for (let i = 1; i < geometry.indices.length; i++) {
434
- const indice = geometry.indices[i];
435
- addExtrudedPolygonSideFaces(indices, totalVertices, indice.offset, indice.count, !(indice.ccw ?? isClockWise));
436
- }
437
- }
438
- const geom = new THREE.BufferGeometry();
439
- geom.setAttribute('position', new THREE.BufferAttribute(vertices, 3));
440
- geom.setAttribute('color', new THREE.BufferAttribute(colors, 3, true));
441
- geom.setAttribute('batchId', new THREE.BufferAttribute(batchIds, 1));
442
- geom.setIndex(new THREE.BufferAttribute(getIntArrayFromSize(indices, vertices.length / 3), 1));
443
- return new THREE.Mesh(geom, options.polygonMaterial);
444
- }
445
-
446
- /**
447
- * Created Instanced object from mesh
448
- *
449
- * @param {THREE.MESH} mesh Model 3D to instanciate
450
- * @param {*} count number of instances to create (int)
451
- * @param {*} ptsIn positions of instanced (array double)
452
- * @returns {THREE.InstancedMesh} Instanced mesh
453
- */
454
- function createInstancedMesh(mesh, count, ptsIn) {
455
- const instancedMesh = new THREE.InstancedMesh(mesh.geometry, mesh.material, count);
456
- let index = 0;
457
- for (let i = 0; i < count * 3; i += 3) {
458
- const mat = new THREE.Matrix4();
459
- mat.setPosition(ptsIn[i], ptsIn[i + 1], ptsIn[i + 2]);
460
- instancedMesh.setMatrixAt(index, mat);
461
- index++;
462
- }
463
- instancedMesh.instanceMatrix.needsUpdate = true;
464
- return instancedMesh;
465
- }
466
-
467
- /**
468
- * Convert a {@link Feature} of type POINT to a Instanced meshes
469
- *
470
- * @param {Object} feature
471
- * @returns {THREE.Mesh} mesh or GROUP of THREE.InstancedMesh
472
- */
473
- function pointsToInstancedMeshes(feature) {
474
- const ptsIn = feature.vertices;
475
- const count = feature.geometries.length;
476
- const modelObject = style.point.model.object;
477
- if (modelObject instanceof THREE.Mesh) {
478
- return createInstancedMesh(modelObject, count, ptsIn);
479
- } else if (modelObject instanceof THREE.Object3D) {
480
- const group = new THREE.Group();
481
- // Get independent meshes from more complexe object
482
- const meshes = separateMeshes(modelObject);
483
- meshes.forEach(mesh => group.add(createInstancedMesh(mesh, count, ptsIn)));
484
- return group;
485
- } else {
486
- throw new Error('The format of the model object provided in the style (layer.style.point.model.object) is not supported. Only THREE.Mesh or THREE.Object3D are supported.');
487
- }
488
- }
489
-
490
- /**
491
- * Convert a {@link Feature} to a Mesh
492
- * @param {Feature} feature - the feature to convert
493
- * @param {Object} options - options controlling the conversion
494
- *
495
- * @return {THREE.Mesh} mesh or GROUP of THREE.InstancedMesh
496
- */
497
- function featureToMesh(feature, options) {
498
- if (!feature.vertices) {
499
- return;
500
- }
501
- let mesh;
502
- switch (feature.type) {
503
- case FEATURE_TYPES.POINT:
504
- if (style.point?.model?.object) {
505
- try {
506
- mesh = pointsToInstancedMeshes(feature);
507
- mesh.isInstancedMesh = true;
508
- } catch (e) {
509
- mesh = featureToPoint(feature, options);
510
- }
511
- } else {
512
- mesh = featureToPoint(feature, options);
513
- }
514
- break;
515
- case FEATURE_TYPES.LINE:
516
- mesh = featureToLine(feature, options);
517
- break;
518
- case FEATURE_TYPES.POLYGON:
519
- if (style.fill && Object.keys(style.fill).includes('extrusion_height')) {
520
- mesh = featureToExtrudedPolygon(feature, options);
521
- } else {
522
- mesh = featureToPolygon(feature, options);
523
- }
524
- break;
525
- default:
526
- }
527
- if (!mesh.isInstancedMesh) {
528
- mesh.material.vertexColors = true;
529
- mesh.material.color = new THREE.Color(0xffffff);
530
- }
531
- mesh.feature = feature;
532
- return mesh;
533
- }
534
-
535
- /**
536
- * @module Feature2Mesh
537
- */
538
- export default {
539
- /**
540
- * Return a function that converts [Features]{@link module:GeoJsonParser} to Meshes. Feature collection will be converted to a
541
- * a THREE.Group.
542
- *
543
- * @param {Object} options - options controlling the conversion
544
- * @param {function} [options.batchId] - optional function to create batchId attribute.
545
- * It is passed the feature property and the feature index. As the batchId is using an unsigned int structure on 32 bits,
546
- * the batchId could be between 0 and 4,294,967,295.
547
- * @param {StyleOptions} [options.style] - optional style properties. Only needed if the convert is used without instancing
548
- * a layer beforehand.
549
- * @return {function}
550
- * @example <caption>Example usage of batchId with featureId.</caption>
551
- * view.addLayer({
552
- * id: 'WFS Buildings',
553
- * type: 'geometry',
554
- * update: itowns.FeatureProcessing.update,
555
- * convert: itowns.Feature2Mesh.convert({
556
- * batchId: (property, featureId) => featureId,
557
- * }),
558
- * filter: acceptFeature,
559
- * source,
560
- * });
561
- *
562
- * @example <caption>Example usage of batchId with property.</caption>
563
- * view.addLayer({
564
- * id: 'WFS Buildings',
565
- * type: 'geometry',
566
- * update: itowns.FeatureProcessing.update,
567
- * convert: itowns.Feature2Mesh.convert({
568
- * batchId: (property, featureId) => property.house ? 10 : featureId,
569
- * }),
570
- * filter: acceptFeature,
571
- * source,
572
- * });
573
- */
574
- convert() {
575
- let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
576
- deprecatedFeature2MeshOptions(options);
577
- return function (collection) {
578
- if (!collection) {
579
- return;
580
- }
581
- if (!options.pointMaterial) {
582
- // Opacity and wireframe refered with layer properties
583
- // TODO: next step is move these properties to Style
584
- options.pointMaterial = ReferLayerProperties(new THREE.PointsMaterial(), this);
585
- options.lineMaterial = ReferLayerProperties(new THREE.LineBasicMaterial(), this);
586
- options.polygonMaterial = ReferLayerProperties(new THREE.MeshBasicMaterial(), this);
587
- }
588
-
589
- // In the case we didn't instanciate the layer (this) before the convert, we can pass
590
- // style properties (@link StyleOptions) using options.style.
591
- // This is usually done in some tests and if you want to use Feature2Mesh.convert()
592
- // as in examples/source_file_gpx_3d.html.
593
- style = this?.style || (options.style ? new Style(options.style) : defaultStyle);
594
- context.setCollection(collection);
595
- const features = collection.features;
596
- if (!features || features.length == 0) {
597
- return;
598
- }
599
- const meshes = features.map(feature => {
600
- const mesh = featureToMesh(feature, options);
601
- mesh.layer = this;
602
- return mesh;
603
- });
604
- const featureNode = new FeatureMesh(meshes, collection);
605
- return featureNode;
606
- };
607
- }
608
- };