itowns 2.44.3-next.40 → 2.44.3-next.42

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