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