itowns 2.45.1-next.0 → 2.45.1-next.1

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 (185) hide show
  1. package/dist/455.js +2 -0
  2. package/dist/455.js.map +1 -0
  3. package/dist/debug.js +3 -0
  4. package/dist/debug.js.LICENSE.txt +13 -0
  5. package/dist/debug.js.map +1 -0
  6. package/dist/itowns.js +3 -0
  7. package/dist/itowns.js.LICENSE.txt +5 -0
  8. package/dist/itowns.js.map +1 -0
  9. package/dist/itowns_lasparser.js +2 -0
  10. package/dist/itowns_lasparser.js.map +1 -0
  11. package/dist/itowns_lasworker.js +2 -0
  12. package/dist/itowns_lasworker.js.map +1 -0
  13. package/dist/itowns_potree2worker.js +2 -0
  14. package/dist/itowns_potree2worker.js.map +1 -0
  15. package/dist/itowns_widgets.js +2 -0
  16. package/dist/itowns_widgets.js.map +1 -0
  17. package/lib/Controls/FirstPersonControls.js +308 -0
  18. package/lib/Controls/FlyControls.js +175 -0
  19. package/lib/Controls/GlobeControls.js +1178 -0
  20. package/lib/Controls/PlanarControls.js +1025 -0
  21. package/lib/Controls/StateControl.js +432 -0
  22. package/lib/Controls/StreetControls.js +392 -0
  23. package/lib/Converter/Feature2Mesh.js +612 -0
  24. package/lib/Converter/Feature2Texture.js +174 -0
  25. package/lib/Converter/convertToTile.js +70 -0
  26. package/lib/Converter/textureConverter.js +43 -0
  27. package/lib/Core/3DTiles/C3DTBatchTable.js +131 -0
  28. package/lib/Core/3DTiles/C3DTBatchTableHierarchyExtension.js +96 -0
  29. package/lib/Core/3DTiles/C3DTBoundingVolume.js +156 -0
  30. package/lib/Core/3DTiles/C3DTExtensions.js +97 -0
  31. package/lib/Core/3DTiles/C3DTFeature.js +110 -0
  32. package/lib/Core/3DTiles/C3DTilesEnums.js +20 -0
  33. package/lib/Core/3DTiles/C3DTileset.js +99 -0
  34. package/lib/Core/3DTiles/utils/BinaryPropertyAccessor.js +100 -0
  35. package/lib/Core/AnimationPlayer.js +142 -0
  36. package/lib/Core/CopcNode.js +174 -0
  37. package/lib/Core/Deprecated/Undeprecator.js +74 -0
  38. package/lib/Core/EntwinePointTileNode.js +126 -0
  39. package/lib/Core/Feature.js +488 -0
  40. package/lib/Core/Geographic/GeoidGrid.js +108 -0
  41. package/lib/Core/Label.js +222 -0
  42. package/lib/Core/MainLoop.js +209 -0
  43. package/lib/Core/Picking.js +255 -0
  44. package/lib/Core/PointCloudNode.js +42 -0
  45. package/lib/Core/Potree2Node.js +206 -0
  46. package/lib/Core/Potree2PointAttributes.js +139 -0
  47. package/lib/Core/PotreeNode.js +101 -0
  48. package/lib/Core/Prefab/Globe/Atmosphere.js +293 -0
  49. package/lib/Core/Prefab/Globe/GlobeLayer.js +152 -0
  50. package/lib/Core/Prefab/Globe/GlobeTileBuilder.js +110 -0
  51. package/lib/Core/Prefab/Globe/SkyShader.js +78 -0
  52. package/lib/Core/Prefab/GlobeView.js +155 -0
  53. package/lib/Core/Prefab/Planar/PlanarLayer.js +59 -0
  54. package/lib/Core/Prefab/Planar/PlanarTileBuilder.js +71 -0
  55. package/lib/Core/Prefab/PlanarView.js +62 -0
  56. package/lib/Core/Prefab/TileBuilder.js +82 -0
  57. package/lib/Core/Prefab/computeBufferTileGeometry.js +248 -0
  58. package/lib/Core/Scheduler/Cache.js +17 -0
  59. package/lib/Core/Scheduler/CancelledCommandException.js +15 -0
  60. package/lib/Core/Scheduler/Scheduler.js +294 -0
  61. package/lib/Core/Style.js +660 -0
  62. package/lib/Core/StyleOptions.js +486 -0
  63. package/lib/Core/System/Capabilities.js +63 -0
  64. package/lib/Core/Tile/Tile.js +205 -0
  65. package/lib/Core/Tile/TileGrid.js +49 -0
  66. package/lib/Core/TileGeometry.js +124 -0
  67. package/lib/Core/TileMesh.js +108 -0
  68. package/lib/Core/View.js +1115 -0
  69. package/lib/Layer/C3DTilesLayer.js +459 -0
  70. package/lib/Layer/ColorLayer.js +154 -0
  71. package/lib/Layer/CopcLayer.js +63 -0
  72. package/lib/Layer/ElevationLayer.js +139 -0
  73. package/lib/Layer/EntwinePointTileLayer.js +71 -0
  74. package/lib/Layer/FeatureGeometryLayer.js +77 -0
  75. package/lib/Layer/GeoidLayer.js +80 -0
  76. package/lib/Layer/GeometryLayer.js +233 -0
  77. package/lib/Layer/InfoLayer.js +64 -0
  78. package/lib/Layer/LabelLayer.js +469 -0
  79. package/lib/Layer/Layer.js +335 -0
  80. package/lib/Layer/LayerUpdateState.js +89 -0
  81. package/lib/Layer/LayerUpdateStrategy.js +80 -0
  82. package/lib/Layer/OGC3DTilesLayer.js +543 -0
  83. package/lib/Layer/OrientedImageLayer.js +227 -0
  84. package/lib/Layer/PointCloudLayer.js +405 -0
  85. package/lib/Layer/Potree2Layer.js +171 -0
  86. package/lib/Layer/PotreeLayer.js +72 -0
  87. package/lib/Layer/RasterLayer.js +37 -0
  88. package/lib/Layer/ReferencingLayerProperties.js +62 -0
  89. package/lib/Layer/TiledGeometryLayer.js +459 -0
  90. package/lib/Loader/LASLoader.js +193 -0
  91. package/lib/Loader/Potree2BrotliLoader.js +261 -0
  92. package/lib/Loader/Potree2Loader.js +207 -0
  93. package/lib/Main.js +113 -0
  94. package/lib/MainBundle.js +4 -0
  95. package/lib/Parser/B3dmParser.js +174 -0
  96. package/lib/Parser/CameraCalibrationParser.js +94 -0
  97. package/lib/Parser/GDFParser.js +72 -0
  98. package/lib/Parser/GTXParser.js +75 -0
  99. package/lib/Parser/GeoJsonParser.js +212 -0
  100. package/lib/Parser/GpxParser.js +25 -0
  101. package/lib/Parser/ISGParser.js +71 -0
  102. package/lib/Parser/KMLParser.js +25 -0
  103. package/lib/Parser/LASParser.js +137 -0
  104. package/lib/Parser/MapBoxUrlParser.js +83 -0
  105. package/lib/Parser/PntsParser.js +131 -0
  106. package/lib/Parser/Potree2BinParser.js +92 -0
  107. package/lib/Parser/PotreeBinParser.js +106 -0
  108. package/lib/Parser/PotreeCinParser.js +29 -0
  109. package/lib/Parser/ShapefileParser.js +78 -0
  110. package/lib/Parser/VectorTileParser.js +215 -0
  111. package/lib/Parser/XbilParser.js +120 -0
  112. package/lib/Parser/deprecated/LegacyGLTFLoader.js +1386 -0
  113. package/lib/Parser/iGLTFLoader.js +168 -0
  114. package/lib/Process/3dTilesProcessing.js +304 -0
  115. package/lib/Process/FeatureProcessing.js +76 -0
  116. package/lib/Process/LayeredMaterialNodeProcessing.js +229 -0
  117. package/lib/Process/ObjectRemovalHelper.js +97 -0
  118. package/lib/Process/handlerNodeError.js +23 -0
  119. package/lib/Provider/3dTilesProvider.js +149 -0
  120. package/lib/Provider/DataSourceProvider.js +24 -0
  121. package/lib/Provider/Fetcher.js +233 -0
  122. package/lib/Provider/PointCloudProvider.js +45 -0
  123. package/lib/Provider/TileProvider.js +16 -0
  124. package/lib/Provider/URLBuilder.js +116 -0
  125. package/lib/Renderer/Camera.js +281 -0
  126. package/lib/Renderer/Color.js +56 -0
  127. package/lib/Renderer/ColorLayersOrdering.js +115 -0
  128. package/lib/Renderer/CommonMaterial.js +31 -0
  129. package/lib/Renderer/Label2DRenderer.js +192 -0
  130. package/lib/Renderer/LayeredMaterial.js +243 -0
  131. package/lib/Renderer/OBB.js +150 -0
  132. package/lib/Renderer/OrientedImageCamera.js +118 -0
  133. package/lib/Renderer/OrientedImageMaterial.js +167 -0
  134. package/lib/Renderer/PointsMaterial.js +485 -0
  135. package/lib/Renderer/RasterTile.js +243 -0
  136. package/lib/Renderer/RenderMode.js +31 -0
  137. package/lib/Renderer/Shader/ShaderChunk.js +160 -0
  138. package/lib/Renderer/Shader/ShaderUtils.js +47 -0
  139. package/lib/Renderer/SphereHelper.js +17 -0
  140. package/lib/Renderer/WebXR.js +51 -0
  141. package/lib/Renderer/c3DEngine.js +214 -0
  142. package/lib/Source/C3DTilesGoogleSource.js +74 -0
  143. package/lib/Source/C3DTilesIonSource.js +54 -0
  144. package/lib/Source/C3DTilesSource.js +30 -0
  145. package/lib/Source/CopcSource.js +126 -0
  146. package/lib/Source/EntwinePointTileSource.js +72 -0
  147. package/lib/Source/FileSource.js +188 -0
  148. package/lib/Source/OGC3DTilesGoogleSource.js +29 -0
  149. package/lib/Source/OGC3DTilesIonSource.js +34 -0
  150. package/lib/Source/OGC3DTilesSource.js +21 -0
  151. package/lib/Source/OrientedImageSource.js +59 -0
  152. package/lib/Source/Potree2Source.js +167 -0
  153. package/lib/Source/PotreeSource.js +82 -0
  154. package/lib/Source/Source.js +202 -0
  155. package/lib/Source/TMSSource.js +144 -0
  156. package/lib/Source/VectorTilesSource.js +182 -0
  157. package/lib/Source/WFSSource.js +170 -0
  158. package/lib/Source/WMSSource.js +167 -0
  159. package/lib/Source/WMTSSource.js +92 -0
  160. package/lib/ThreeExtended/capabilities/WebGL.js +69 -0
  161. package/lib/ThreeExtended/libs/ktx-parse.module.js +506 -0
  162. package/lib/ThreeExtended/libs/zstddec.module.js +29 -0
  163. package/lib/ThreeExtended/loaders/DDSLoader.js +200 -0
  164. package/lib/ThreeExtended/loaders/DRACOLoader.js +400 -0
  165. package/lib/ThreeExtended/loaders/GLTFLoader.js +2879 -0
  166. package/lib/ThreeExtended/loaders/KTX2Loader.js +709 -0
  167. package/lib/ThreeExtended/math/ColorSpaces.js +59 -0
  168. package/lib/ThreeExtended/utils/BufferGeometryUtils.js +846 -0
  169. package/lib/ThreeExtended/utils/WorkerPool.js +70 -0
  170. package/lib/Utils/CameraUtils.js +554 -0
  171. package/lib/Utils/DEMUtils.js +350 -0
  172. package/lib/Utils/FeaturesUtils.js +156 -0
  173. package/lib/Utils/Gradients.js +16 -0
  174. package/lib/Utils/ThreeUtils.js +115 -0
  175. package/lib/Utils/gui/C3DTilesStyle.js +218 -0
  176. package/lib/Utils/gui/Main.js +7 -0
  177. package/lib/Utils/gui/Minimap.js +152 -0
  178. package/lib/Utils/gui/Navigation.js +245 -0
  179. package/lib/Utils/gui/Scale.js +104 -0
  180. package/lib/Utils/gui/Searchbar.js +234 -0
  181. package/lib/Utils/gui/Widget.js +80 -0
  182. package/lib/Utils/placeObjectOnGround.js +136 -0
  183. package/lib/Worker/LASLoaderWorker.js +19 -0
  184. package/lib/Worker/Potree2Worker.js +21 -0
  185. package/package.json +2 -2
@@ -0,0 +1,205 @@
1
+ import * as THREE from 'three';
2
+ import { Coordinates, CRS, Extent } from '@itowns/geographic';
3
+ import { getInfoTms, getCountTiles } from "./TileGrid.js";
4
+ const _tmsCoord = new THREE.Vector2();
5
+ const _dimensionTile = new THREE.Vector2();
6
+ const r = {
7
+ row: 0,
8
+ col: 0,
9
+ invDiff: 0
10
+ };
11
+ function _rowColfromParent(tile, zoom) {
12
+ const diffLevel = tile.zoom - zoom;
13
+ const diff = 2 ** diffLevel;
14
+ r.invDiff = 1 / diff;
15
+ r.row = (tile.row - tile.row % diff) * r.invDiff;
16
+ r.col = (tile.col - tile.col % diff) * r.invDiff;
17
+ return r;
18
+ }
19
+ const _extent = new Extent('EPSG:4326');
20
+ const _extent2 = new Extent('EPSG:4326');
21
+ const _c = new Coordinates('EPSG:4326', 0, 0);
22
+ class Tile {
23
+ /**
24
+ * A tile is a geographical bounding rectangle uniquely defined by its zoom,
25
+ * row and column.
26
+ *
27
+ * @param crs - projection of limit values.
28
+ * @param zoom - `zoom` value. Default is 0.
29
+ * @param row - `row` value. Default is 0.
30
+ * @param col - `column` value. Default is 0.
31
+ */
32
+ constructor(crs) {
33
+ let zoom = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
34
+ let row = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
35
+ let col = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
36
+ this.isTile = true;
37
+ this.crs = crs;
38
+ this.zoom = zoom;
39
+ this.row = row;
40
+ this.col = col;
41
+ }
42
+
43
+ /**
44
+ * Returns a new tile with the same bounds and crs as this one.
45
+ */
46
+ clone() {
47
+ return new Tile(this.crs, this.zoom, this.row, this.col);
48
+ }
49
+
50
+ /**
51
+ * Converts this tile to the specified extent.
52
+ * @param crs - target's projection.
53
+ * @param target - The target to store the projected extent. If this not
54
+ * provided a new extent will be created.
55
+ */
56
+ toExtent(crs) {
57
+ let target = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : new Extent('EPSG:4326');
58
+ CRS.isValid(crs);
59
+ const {
60
+ epsg,
61
+ globalExtent,
62
+ globalDimension
63
+ } = getInfoTms(this.crs);
64
+ const countTiles = getCountTiles(this.crs, this.zoom);
65
+ _dimensionTile.set(1, 1).divide(countTiles).multiply(globalDimension);
66
+ target.west = globalExtent.west + (globalDimension.x - _dimensionTile.x * (countTiles.x - this.col));
67
+ target.east = target.west + _dimensionTile.x;
68
+ target.south = globalExtent.south + _dimensionTile.y * (countTiles.y - this.row - 1);
69
+ target.north = target.south + _dimensionTile.y;
70
+ target.crs = epsg;
71
+ return crs == epsg ? target : target.as(crs, target);
72
+ }
73
+
74
+ /**
75
+ * Checks whether another tile is inside this tile.
76
+ *
77
+ * @param extent - the tile to check.
78
+ */
79
+ isInside(tile) {
80
+ if (this.zoom == tile.zoom) {
81
+ return this.row == tile.row && this.col == tile.col;
82
+ } else if (this.zoom < tile.zoom) {
83
+ return false;
84
+ } else {
85
+ const r = _rowColfromParent(this, tile.zoom);
86
+ return r.row == tile.row && r.col == tile.col;
87
+ }
88
+ }
89
+
90
+ /**
91
+ * Returns the translation and scale to transform this tile to the input
92
+ * tile.
93
+ *
94
+ * @param tile - the input tile.
95
+ * @param target - copy the result to target.
96
+ */
97
+ offsetToParent(tile) {
98
+ let target = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : new THREE.Vector4();
99
+ if (this.crs != tile.crs) {
100
+ throw new Error('unsupported mix');
101
+ }
102
+ const r = _rowColfromParent(this, tile.zoom);
103
+ return target.set(this.col * r.invDiff - r.col, this.row * r.invDiff - r.row, r.invDiff, r.invDiff);
104
+ }
105
+
106
+ /**
107
+ * Returns the parent tile at the given level.
108
+ *
109
+ * @param levelParent - the level of the parent tile.
110
+ */
111
+ tiledExtentParent(levelParent) {
112
+ if (levelParent && levelParent < this.zoom) {
113
+ const r = _rowColfromParent(this, levelParent);
114
+ return new Tile(this.crs, levelParent, r.row, r.col);
115
+ } else {
116
+ return this;
117
+ }
118
+ }
119
+
120
+ /**
121
+ * Sets zoom, row and column values.
122
+ *
123
+ * @param zoom - zoom value.
124
+ * @param row - row value.
125
+ * @param col - column value.
126
+ */
127
+ set() {
128
+ let zoom = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
129
+ let row = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
130
+ let col = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
131
+ this.zoom = zoom;
132
+ this.row = row;
133
+ this.col = col;
134
+ return this;
135
+ }
136
+
137
+ /**
138
+ * Copies the passed tile to this tile.
139
+ * @param tile - tile to copy.
140
+ */
141
+ copy(tile) {
142
+ this.crs = tile.crs;
143
+ return this.set(tile.zoom, tile.row, tile.col);
144
+ }
145
+
146
+ /**
147
+ * Return values of tile in string, separated by the separator input.
148
+ * @param separator - string separator
149
+ */
150
+ toString() {
151
+ let separator = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
152
+ return `${this.zoom}${separator}${this.row}${separator}${this.col}`;
153
+ }
154
+ }
155
+ export function tiledCovering(e, tms) {
156
+ if (e.crs == 'EPSG:4326' && tms == 'EPSG:3857') {
157
+ const WMTS_PM = [];
158
+ const extent = _extent.copy(e).as(tms, _extent2);
159
+ const {
160
+ globalExtent,
161
+ globalDimension,
162
+ sTs
163
+ } = getInfoTms(tms);
164
+ extent.clampByExtent(globalExtent);
165
+ extent.planarDimensions(_dimensionTile);
166
+ const zoom = Math.floor(Math.log2(Math.round(globalDimension.x / (_dimensionTile.x * sTs.x))));
167
+ const countTiles = getCountTiles(tms, zoom);
168
+ const center = extent.center(_c);
169
+ _tmsCoord.x = center.x - globalExtent.west;
170
+ _tmsCoord.y = globalExtent.north - extent.north;
171
+ _tmsCoord.divide(globalDimension).multiply(countTiles).floor();
172
+
173
+ // ]N; N+1] => N
174
+ const maxRow = Math.ceil((globalExtent.north - extent.south) / globalDimension.x * countTiles.y) - 1;
175
+ for (let r = maxRow; r >= _tmsCoord.y; r--) {
176
+ WMTS_PM.push(new Tile(tms, zoom, r, _tmsCoord.x));
177
+ }
178
+ return WMTS_PM;
179
+ } else {
180
+ const target = new Tile(tms, 0, 0, 0);
181
+ const {
182
+ globalExtent,
183
+ globalDimension,
184
+ sTs,
185
+ isInverted
186
+ } = getInfoTms(e.crs);
187
+ const center = e.center(_c);
188
+ e.planarDimensions(_dimensionTile);
189
+ // Each level has 2^n * 2^n tiles...
190
+ // ... so we count how many tiles of the same width as tile we can fit
191
+ // in the layer
192
+ // ... 2^zoom = tilecount => zoom = log2(tilecount)
193
+ const zoom = Math.floor(Math.log2(Math.round(globalDimension.x / (_dimensionTile.x * sTs.x))));
194
+ const countTiles = getCountTiles(tms, zoom);
195
+
196
+ // Now that we have computed zoom, we can deduce x and y (or row /
197
+ // column)
198
+ _tmsCoord.x = center.x - globalExtent.west;
199
+ _tmsCoord.y = isInverted ? globalExtent.north - center.y : center.y - globalExtent.south;
200
+ _tmsCoord.divide(globalDimension).multiply(countTiles).floor();
201
+ target.set(zoom, _tmsCoord.y, _tmsCoord.x);
202
+ return [target];
203
+ }
204
+ }
205
+ export default Tile;
@@ -0,0 +1,49 @@
1
+ import * as THREE from 'three';
2
+ import { Extent } from '@itowns/geographic';
3
+ const _countTiles = new THREE.Vector2();
4
+ const _dim = new THREE.Vector2();
5
+ export const globalExtentTMS = new Map();
6
+ export const schemeTiles = new Map();
7
+ const extent4326 = new Extent('EPSG:4326', -180, 180, -90, 90);
8
+ globalExtentTMS.set('EPSG:4326', extent4326);
9
+
10
+ // Compute global extent of TMS in EPSG:3857
11
+ // It's square whose a side is between -180° to 180°.
12
+ // So, west extent, it's 180 convert in EPSG:3857
13
+ const extent3857 = extent4326.as('EPSG:3857');
14
+ extent3857.clampSouthNorth(extent3857.west, extent3857.east);
15
+ globalExtentTMS.set('EPSG:3857', extent3857);
16
+ const defaultScheme = new THREE.Vector2(1, 1);
17
+ schemeTiles.set('EPSG:3857', defaultScheme);
18
+ schemeTiles.set('EPSG:4326', new THREE.Vector2(2, 1));
19
+
20
+ // TODO: For now we can only have a single TMS grid per proj4 identifier.
21
+ // This causes TMS identifier to be proj4 identifier.
22
+ export function getInfoTms(crs) {
23
+ const globalExtent = globalExtentTMS.get(crs);
24
+ if (!globalExtent) {
25
+ throw new Error(`The tile matrix set ${crs} is not defined.`);
26
+ }
27
+ const globalDimension = globalExtent.planarDimensions(_dim);
28
+ const sTs = schemeTiles.get(crs) ?? defaultScheme;
29
+ // The isInverted parameter is to be set to the correct value, true or false
30
+ // (default being false) if the computation of the coordinates needs to be
31
+ // inverted to match the same scheme as OSM, Google Maps or other system.
32
+ // See link below for more information
33
+ // https://alastaira.wordpress.com/2011/07/06/converting-tms-tile-coordinates-to-googlebingosm-tile-coordinates/
34
+ // in crs includes ':NI' => tms isn't inverted (NOT INVERTED)
35
+ const isInverted = !crs.includes(':NI');
36
+ return {
37
+ epsg: crs,
38
+ globalExtent,
39
+ globalDimension,
40
+ sTs,
41
+ isInverted
42
+ };
43
+ }
44
+ export function getCountTiles(crs, zoom) {
45
+ const sTs = schemeTiles.get(crs) || defaultScheme;
46
+ const count = 2 ** zoom;
47
+ _countTiles.set(count, count).multiply(sTs);
48
+ return _countTiles;
49
+ }
@@ -0,0 +1,124 @@
1
+ import * as THREE from 'three';
2
+ import { computeBuffers, getBufferIndexSize } from "./Prefab/computeBufferTileGeometry.js";
3
+ import { Coordinates } from '@itowns/geographic';
4
+ function defaultBuffers(builder, params) {
5
+ const fullParams = {
6
+ disableSkirt: false,
7
+ hideSkirt: false,
8
+ buildIndexAndUv_0: true,
9
+ segments: 16,
10
+ coordinates: new Coordinates(builder.crs),
11
+ center: builder.center(params.extent).clone(),
12
+ ...params
13
+ };
14
+ const buffers = computeBuffers(builder, fullParams);
15
+ const bufferAttributes = {
16
+ index: buffers.index ? new THREE.BufferAttribute(buffers.index, 1) : null,
17
+ uvs: [...(buffers.uvs[0] ? [new THREE.BufferAttribute(buffers.uvs[0], 2)] : []), ...(buffers.uvs[1] ? [new THREE.BufferAttribute(buffers.uvs[1], 1)] : [])],
18
+ position: new THREE.BufferAttribute(buffers.position, 3),
19
+ normal: new THREE.BufferAttribute(buffers.normal, 3)
20
+ };
21
+ return bufferAttributes;
22
+ }
23
+ export class TileGeometry extends THREE.BufferGeometry {
24
+ /** Oriented Bounding Box of the tile geometry. */
25
+
26
+ /** Ground area covered by this tile geometry. */
27
+
28
+ /** Resolution of the tile geometry in segments per side. */
29
+
30
+ /**
31
+ * [TileGeometry] instances are shared between tiles. Since a geometry
32
+ * handles its own GPU resource, it needs a reference counter to dispose of
33
+ * that resource only when it is discarded by every single owner of a
34
+ * reference to the geometry.
35
+ */
36
+ // https://github.com/iTowns/itowns/pull/2440#discussion_r1860743294
37
+ // TODO: Remove nullability by reworking OBB:setFromExtent
38
+
39
+ constructor(builder, params) {
40
+ let bufferAttributes = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : defaultBuffers(builder, params);
41
+ super();
42
+ this.extent = params.extent;
43
+ this.segments = params.segments;
44
+ this.setIndex(bufferAttributes.index);
45
+ this.setAttribute('position', bufferAttributes.position);
46
+ this.setAttribute('normal', bufferAttributes.normal);
47
+ this.setAttribute('uv', bufferAttributes.uvs[0]);
48
+ for (let i = 1; i < bufferAttributes.uvs.length; i++) {
49
+ this.setAttribute(`uv_${i}`, bufferAttributes.uvs[i]);
50
+ }
51
+ this.computeBoundingBox();
52
+ this.OBB = null;
53
+ if (params.hideSkirt) {
54
+ this.hideSkirt = params.hideSkirt;
55
+ }
56
+ this._refCount = null;
57
+ }
58
+
59
+ /**
60
+ * Enables or disables skirt rendering.
61
+ *
62
+ * @param toggle - Whether to hide the skirt; true hides, false shows.
63
+ */
64
+ set hideSkirt(toggle) {
65
+ this.setDrawRange(0, getBufferIndexSize(this.segments, toggle));
66
+ }
67
+
68
+ /**
69
+ * Initialize reference count for this geometry if it is currently null.
70
+ *
71
+ * @param cacheTile - The [Cache] used to store this geometry.
72
+ * @param keys - The [south, level, epsg] key of this geometry.
73
+ */
74
+ initRefCount(cacheTile, key) {
75
+ if (this._refCount !== null) {
76
+ return;
77
+ }
78
+ this._refCount = {
79
+ count: 0,
80
+ fn: () => {
81
+ this._refCount.count--;
82
+ if (this._refCount.count <= 0) {
83
+ // To avoid remove index buffer and attribute buffer uv
84
+ // error un-bound buffer in webgl with VAO rendering.
85
+ // Could be removed if the attribute buffer deleting is
86
+ // taken into account in the buffer binding state
87
+ // (in THREE.WebGLBindingStates code).
88
+ this.index = null;
89
+ delete this.attributes.uv;
90
+ cacheTile.delete(key);
91
+ super.dispose();
92
+ // THREE.BufferGeometry.prototype.dispose.call(this);
93
+ }
94
+ }
95
+ };
96
+ }
97
+
98
+ /**
99
+ * Increase reference count.
100
+ *
101
+ * @throws If reference count has not been initialized.
102
+ */
103
+ increaseRefCount() {
104
+ if (this._refCount === null) {
105
+ throw new Error('[TileGeometry::increaseRefCount] ' + 'Tried to increment an unitialized reference count.');
106
+ }
107
+ this._refCount.count++;
108
+ }
109
+
110
+ /**
111
+ * The current reference count of this [TileGeometry] if it has been
112
+ * initialized.
113
+ */
114
+ get refCount() {
115
+ return this._refCount?.count;
116
+ }
117
+ dispose() {
118
+ if (this._refCount == null) {
119
+ super.dispose();
120
+ } else {
121
+ this._refCount.fn();
122
+ }
123
+ }
124
+ }
@@ -0,0 +1,108 @@
1
+ import * as THREE from 'three';
2
+ import { geoidLayerIsVisible } from "../Layer/GeoidLayer.js";
3
+ import { tiledCovering } from "./Tile/Tile.js";
4
+
5
+ /**
6
+ * A TileMesh is a THREE.Mesh with a geometricError and an OBB
7
+ * The objectId property of the material is the with the id of the TileMesh
8
+ * @param {TileGeometry} geometry - the tile geometry
9
+ * @param {THREE.Material} material - a THREE.Material compatible with THREE.Mesh
10
+ * @param {Layer} layer - the layer the tile is added to
11
+ * @param {Extent} extent - the tile extent
12
+ * @param {?number} level - the tile level (default = 0)
13
+ */
14
+ class TileMesh extends THREE.Mesh {
15
+ #_tms = (() => new Map())();
16
+ #visible = true;
17
+ constructor(geometry, material, layer, extent) {
18
+ let level = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 0;
19
+ super(geometry, material);
20
+ if (!extent) {
21
+ throw new Error('extent is mandatory to build a TileMesh');
22
+ }
23
+ this.layer = layer;
24
+ this.extent = extent;
25
+ this.extent.zoom = level;
26
+ this.level = level;
27
+ this.material.objectId = this.id;
28
+ this.obb = this.geometry.OBB.clone();
29
+ this.boundingSphere = new THREE.Sphere();
30
+ this.obb.box3D.getBoundingSphere(this.boundingSphere);
31
+ for (const tms of layer.tileMatrixSets) {
32
+ this.#_tms.set(tms, tiledCovering(this.extent, tms));
33
+ }
34
+ this.frustumCulled = false;
35
+ this.matrixAutoUpdate = false;
36
+ this.rotationAutoUpdate = false;
37
+ this.layerUpdateState = {};
38
+ this.isTileMesh = true;
39
+ this.geoidHeight = 0;
40
+ this.link = {};
41
+ Object.defineProperty(this, 'visible', {
42
+ get() {
43
+ return this.#visible;
44
+ },
45
+ set(v) {
46
+ if (this.#visible != v) {
47
+ this.#visible = v;
48
+ this.dispatchEvent({
49
+ type: v ? 'shown' : 'hidden'
50
+ });
51
+ }
52
+ }
53
+ });
54
+ }
55
+ /**
56
+ * If specified, update the min and max elevation of the OBB
57
+ * and updates accordingly the bounding sphere and the geometric error
58
+ *
59
+ * @param {Object} elevation
60
+ * @param {number} [elevation.min]
61
+ * @param {number} [elevation.max]
62
+ * @param {number} [elevation.scale]
63
+ */
64
+ setBBoxZ(elevation) {
65
+ elevation.geoidHeight = geoidLayerIsVisible(this.layer) ? this.geoidHeight : 0;
66
+ this.obb.updateZ(elevation);
67
+ if (this.horizonCullingPointElevationScaled) {
68
+ this.horizonCullingPointElevationScaled.setLength(this.obb.z.delta + this.horizonCullingPoint.length());
69
+ }
70
+ this.obb.box3D.getBoundingSphere(this.boundingSphere);
71
+ }
72
+ getExtentsByProjection(crs) {
73
+ return this.#_tms.get(crs);
74
+ }
75
+
76
+ /**
77
+ * Search for a common ancestor between this tile and another one. It goes
78
+ * through parents on each side until one is found.
79
+ *
80
+ * @param {TileMesh} tile
81
+ *
82
+ * @return {TileMesh} the resulting common ancestor
83
+ */
84
+ findCommonAncestor(tile) {
85
+ if (!tile) {
86
+ return undefined;
87
+ }
88
+ if (tile.level == this.level) {
89
+ if (tile.id == this.id) {
90
+ return tile;
91
+ } else if (tile.level != 0) {
92
+ return this.parent.findCommonAncestor(tile.parent);
93
+ } else {
94
+ return undefined;
95
+ }
96
+ } else if (tile.level < this.level) {
97
+ return this.parent.findCommonAncestor(tile);
98
+ } else {
99
+ return this.findCommonAncestor(tile.parent);
100
+ }
101
+ }
102
+ onBeforeRender() {
103
+ if (this.material.layersNeedUpdate) {
104
+ this.material.updateLayersUniforms();
105
+ }
106
+ }
107
+ }
108
+ export default TileMesh;