itowns 2.44.3-next.3 → 2.44.3-next.30

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 (92) hide show
  1. package/CODING.md +1 -1
  2. package/CONTRIBUTORS.md +1 -0
  3. package/dist/debug.js +1 -1
  4. package/dist/debug.js.map +1 -1
  5. package/dist/itowns.js +1 -1
  6. package/dist/itowns.js.LICENSE.txt +0 -2
  7. package/dist/itowns.js.map +1 -1
  8. package/dist/itowns_widgets.js +1 -1
  9. package/dist/itowns_widgets.js.map +1 -1
  10. package/examples/3dtiles_loader.html +109 -45
  11. package/examples/config.json +2 -10
  12. package/examples/entwine_3d_loader.html +3 -1
  13. package/examples/entwine_simple_loader.html +1 -1
  14. package/examples/images/itowns_logo.svg +123 -0
  15. package/examples/js/plugins/COGParser.js +1 -1
  16. package/examples/jsm/OGC3DTilesHelper.js +1 -1
  17. package/examples/layers/JSONLayers/GeoidMNT.json +3 -1
  18. package/examples/source_file_geojson_3d.html +0 -1
  19. package/examples/source_stream_wfs_raster.html +0 -7
  20. package/lib/Controls/GlobeControls.js +45 -28
  21. package/lib/Controls/StateControl.js +5 -2
  22. package/lib/Converter/Feature2Mesh.js +10 -4
  23. package/lib/Converter/Feature2Texture.js +3 -1
  24. package/lib/Converter/convertToTile.js +3 -8
  25. package/lib/Converter/textureConverter.js +3 -4
  26. package/lib/Core/Deprecated/Undeprecator.js +0 -1
  27. package/lib/Core/Feature.js +1 -2
  28. package/lib/Core/Geographic/Coordinates.js +143 -132
  29. package/lib/Core/Geographic/Crs.js +140 -145
  30. package/lib/Core/Geographic/Extent.js +72 -267
  31. package/lib/Core/Geographic/GeoidGrid.js +1 -1
  32. package/lib/Core/Math/Ellipsoid.js +62 -21
  33. package/lib/Core/Prefab/Globe/Atmosphere.js +4 -8
  34. package/lib/Core/Prefab/Globe/GlobeLayer.js +22 -15
  35. package/lib/Core/Prefab/Globe/GlobeTileBuilder.js +111 -0
  36. package/lib/Core/Prefab/GlobeView.js +2 -7
  37. package/lib/Core/Prefab/Planar/PlanarLayer.js +17 -11
  38. package/lib/Core/Prefab/Planar/PlanarTileBuilder.js +43 -43
  39. package/lib/Core/Prefab/TileBuilder.js +27 -32
  40. package/lib/Core/Prefab/computeBufferTileGeometry.js +189 -130
  41. package/lib/Core/Style.js +3 -3
  42. package/lib/Core/Tile/Tile.js +219 -0
  43. package/lib/Core/Tile/TileGrid.js +43 -0
  44. package/lib/Core/TileGeometry.js +112 -28
  45. package/lib/Core/TileMesh.js +3 -3
  46. package/lib/Core/View.js +15 -8
  47. package/lib/Layer/C3DTilesLayer.js +20 -16
  48. package/lib/Layer/ColorLayer.js +35 -9
  49. package/lib/Layer/CopcLayer.js +5 -0
  50. package/lib/Layer/ElevationLayer.js +39 -7
  51. package/lib/Layer/EntwinePointTileLayer.js +12 -5
  52. package/lib/Layer/FeatureGeometryLayer.js +20 -6
  53. package/lib/Layer/GeometryLayer.js +42 -11
  54. package/lib/Layer/LabelLayer.js +19 -9
  55. package/lib/Layer/Layer.js +83 -57
  56. package/lib/Layer/OGC3DTilesLayer.js +81 -30
  57. package/lib/Layer/OrientedImageLayer.js +11 -5
  58. package/lib/Layer/PointCloudLayer.js +74 -30
  59. package/lib/Layer/Potree2Layer.js +7 -2
  60. package/lib/Layer/PotreeLayer.js +8 -3
  61. package/lib/Layer/RasterLayer.js +12 -2
  62. package/lib/Layer/TiledGeometryLayer.js +69 -13
  63. package/lib/Main.js +2 -2
  64. package/lib/Parser/GeoJsonParser.js +1 -1
  65. package/lib/Parser/VectorTileParser.js +1 -1
  66. package/lib/Parser/XbilParser.js +14 -2
  67. package/lib/Provider/Fetcher.js +5 -1
  68. package/lib/Provider/URLBuilder.js +22 -11
  69. package/lib/Renderer/Camera.js +1 -1
  70. package/lib/Renderer/OBB.js +11 -13
  71. package/lib/Renderer/PointsMaterial.js +1 -1
  72. package/lib/Renderer/RasterTile.js +1 -2
  73. package/lib/Renderer/SphereHelper.js +0 -6
  74. package/lib/Source/CopcSource.js +13 -2
  75. package/lib/Source/EntwinePointTileSource.js +14 -4
  76. package/lib/Source/FileSource.js +1 -4
  77. package/lib/Source/Source.js +1 -4
  78. package/lib/Source/TMSSource.js +10 -9
  79. package/lib/Source/VectorTilesSource.js +3 -5
  80. package/lib/Source/WFSSource.js +15 -10
  81. package/lib/Source/WMSSource.js +56 -18
  82. package/lib/Source/WMTSSource.js +13 -7
  83. package/lib/Utils/CameraUtils.js +1 -1
  84. package/lib/Utils/gui/C3DTilesStyle.js +2 -3
  85. package/lib/Utils/placeObjectOnGround.js +0 -1
  86. package/package.json +13 -6
  87. package/examples/3dtiles_25d.html +0 -120
  88. package/examples/3dtiles_basic.html +0 -94
  89. package/examples/3dtiles_batch_table.html +0 -86
  90. package/examples/3dtiles_ion.html +0 -126
  91. package/examples/3dtiles_pointcloud.html +0 -95
  92. package/lib/Core/Prefab/Globe/BuilderEllipsoidTile.js +0 -110
@@ -1,9 +1,8 @@
1
1
  import * as THREE from 'three';
2
2
  import TiledGeometryLayer from "../../../Layer/TiledGeometryLayer.js";
3
3
  import { ellipsoidSizes } from "../../Math/Ellipsoid.js";
4
- import { globalExtentTMS, schemeTiles } from "../../Geographic/Extent.js";
5
- import BuilderEllipsoidTile from "./BuilderEllipsoidTile.js";
6
- import CRS from "../../Geographic/Crs.js";
4
+ import { globalExtentTMS, schemeTiles } from "../../Tile/TileGrid.js";
5
+ import { GlobeTileBuilder } from "./GlobeTileBuilder.js";
7
6
 
8
7
  // matrix to convert sphere to ellipsoid
9
8
  const worldToScaledEllipsoid = new THREE.Matrix4();
@@ -18,18 +17,18 @@ const scaledHorizonCullingPoint = new THREE.Vector3();
18
17
  * @property {boolean} isGlobeLayer - Used to checkout whether this layer is a
19
18
  * GlobeLayer. Default is true. You should not change this, as it is used
20
19
  * internally for optimisation.
20
+ *
21
+ * @extends TiledGeometryLayer
21
22
  */
22
23
  class GlobeLayer extends TiledGeometryLayer {
23
24
  /**
24
25
  * A {@link TiledGeometryLayer} to use with a {@link GlobeView}. It has
25
26
  * specific method for updating and subdivising its grid.
26
27
  *
27
- * @extends TiledGeometryLayer
28
- *
29
28
  * @param {string} id - The id of the layer, that should be unique. It is
30
29
  * not mandatory, but an error will be emitted if this layer is added a
31
30
  * {@link View} that already has a layer going by that id.
32
- * @param {THREE.Object3d} [object3d=THREE.Group] - The object3d used to
31
+ * @param {THREE.Object3D} [object3d=THREE.Group] - The object3d used to
33
32
  * contain the geometry of the TiledGeometryLayer. It is usually a
34
33
  * `THREE.Group`, but it can be anything inheriting from a `THREE.Object3d`.
35
34
  * @param {Object} [config] - Optional configuration, all elements in it
@@ -48,22 +47,30 @@ class GlobeLayer extends TiledGeometryLayer {
48
47
  */
49
48
  constructor(id, object3d) {
50
49
  let config = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
50
+ const {
51
+ minSubdivisionLevel = 2,
52
+ maxSubdivisionLevel = 19,
53
+ ...tiledConfig
54
+ } = config;
55
+
51
56
  // Configure tiles
52
- const scheme = schemeTiles.get(CRS.tms_4326);
57
+ const scheme = schemeTiles.get('EPSG:4326');
53
58
  const schemeTile = globalExtentTMS.get('EPSG:4326').subdivisionByScheme(scheme);
54
59
 
55
60
  // Supported tile matrix set for color/elevation layer
56
- config.tileMatrixSets = [CRS.tms_4326, CRS.tms_3857];
57
- const uvCount = config.tileMatrixSets.length;
58
- const builder = new BuilderEllipsoidTile({
59
- crs: 'EPSG:4978',
61
+ const tileMatrixSets = ['EPSG:4326', 'EPSG:3857'];
62
+ const uvCount = tileMatrixSets.length;
63
+ const builder = new GlobeTileBuilder({
60
64
  uvCount
61
65
  });
62
- super(id, object3d || new THREE.Group(), schemeTile, builder, config);
66
+ super(id, object3d || new THREE.Group(), schemeTile, builder, {
67
+ tileMatrixSets,
68
+ ...tiledConfig
69
+ });
63
70
  this.isGlobeLayer = true;
64
71
  this.options.defaultPickingRadius = 5;
65
- this.minSubdivisionLevel = this.minSubdivisionLevel == undefined ? 2 : this.minSubdivisionLevel;
66
- this.maxSubdivisionLevel = this.maxSubdivisionLevel == undefined ? 19 : this.maxSubdivisionLevel;
72
+ this.minSubdivisionLevel = minSubdivisionLevel;
73
+ this.maxSubdivisionLevel = maxSubdivisionLevel;
67
74
  this.extent = this.schemeTile[0].clone();
68
75
  for (let i = 1; i < this.schemeTile.length; i++) {
69
76
  this.extent.union(this.schemeTile[i]);
@@ -97,7 +104,7 @@ class GlobeLayer extends TiledGeometryLayer {
97
104
  }
98
105
  subdivision(context, layer, node) {
99
106
  if (node.level == 5) {
100
- const row = node.getExtentsByProjection(CRS.tms_4326)[0].row;
107
+ const row = node.getExtentsByProjection('EPSG:4326')[0].row;
101
108
  if (row == 31 || row == 0) {
102
109
  // doesn't subdivise the pole
103
110
  return false;
@@ -0,0 +1,111 @@
1
+ import * as THREE from 'three';
2
+ import Coordinates from "../../Geographic/Coordinates.js";
3
+ import Extent from "../../Geographic/Extent.js";
4
+ const PI_OV_FOUR = Math.PI / 4;
5
+ const INV_TWO_PI = 1.0 / (Math.PI * 2);
6
+ const axisZ = new THREE.Vector3(0, 0, 1);
7
+ const axisY = new THREE.Vector3(0, 1, 0);
8
+ const quatToAlignLongitude = new THREE.Quaternion();
9
+ const quatToAlignLatitude = new THREE.Quaternion();
10
+ const quatNormalToZ = new THREE.Quaternion();
11
+
12
+ /** Transforms a WGS84 latitude into a usable texture offset. */
13
+ function WGS84ToOneSubY(latitude) {
14
+ return 1.0 - (0.5 - Math.log(Math.tan(PI_OV_FOUR + THREE.MathUtils.degToRad(latitude) * 0.5)) * INV_TWO_PI);
15
+ }
16
+
17
+ /** Specialized parameters for the [GlobeTileBuilder]. */
18
+
19
+ /**
20
+ * TileBuilder implementation for the purpose of generating globe (or more
21
+ * precisely ellipsoidal) tile arrangements.
22
+ */
23
+ export class GlobeTileBuilder {
24
+ static _crs = 'EPSG:4978';
25
+ static _computeExtraOffset(params) {
26
+ const t = WGS84ToOneSubY(params.coordinates.latitude) * params.nbRow;
27
+ return (!isFinite(t) ? 0 : t) - params.deltaUV1;
28
+ }
29
+
30
+ /**
31
+ * Buffer holding information about the tile/vertex currently being
32
+ * processed.
33
+ */
34
+
35
+ get crs() {
36
+ return GlobeTileBuilder._crs;
37
+ }
38
+ constructor(options) {
39
+ this._transform = {
40
+ coords: [new Coordinates('EPSG:4326', 0, 0), new Coordinates('EPSG:4326', 0, 0)],
41
+ position: new THREE.Vector3(),
42
+ dimension: new THREE.Vector2()
43
+ };
44
+
45
+ // UV: Normalized coordinates (from degree) on the entire tile
46
+ // EPSG:4326
47
+ // Offset: Float row coordinate from Pseudo mercator coordinates
48
+ // EPSG:3857
49
+ if (options.uvCount > 1) {
50
+ this.computeExtraOffset = GlobeTileBuilder._computeExtraOffset;
51
+ }
52
+ }
53
+ prepare(params) {
54
+ const nbRow = 2 ** (params.level + 1.0);
55
+ let st1 = WGS84ToOneSubY(params.extent.south);
56
+ if (!isFinite(st1)) {
57
+ st1 = 0;
58
+ }
59
+ const start = st1 % (1.0 / nbRow);
60
+ const newParams = {
61
+ nbRow,
62
+ deltaUV1: (st1 - start) * nbRow,
63
+ // transformation to align tile's normal to z axis
64
+ quatNormalToZ: quatNormalToZ.setFromAxisAngle(axisY, -(Math.PI * 0.5 - THREE.MathUtils.degToRad(params.extent.center().latitude))),
65
+ // let's avoid building too much temp objects
66
+ coordinates: new Coordinates(this.crs)
67
+ };
68
+ params.extent.planarDimensions(this._transform.dimension);
69
+ return {
70
+ ...params,
71
+ ...newParams
72
+ };
73
+ }
74
+ center(extent) {
75
+ return extent.center(this._transform.coords[0]).as(this.crs, this._transform.coords[1]).toVector3();
76
+ }
77
+ vertexPosition(coordinates) {
78
+ return this._transform.coords[0].setFromValues(coordinates.x, coordinates.y).as(this.crs, this._transform.coords[1]).toVector3(this._transform.position);
79
+ }
80
+ vertexNormal() {
81
+ return this._transform.coords[1].geodesicNormal;
82
+ }
83
+ uProject(u, extent) {
84
+ return extent.west + u * this._transform.dimension.x;
85
+ }
86
+ vProject(v, extent) {
87
+ return extent.south + v * this._transform.dimension.y;
88
+ }
89
+ computeShareableExtent(extent) {
90
+ // NOTE: It should be possible to take advantage of equatorial plane
91
+ // symmetry, for which we'd have to reverse the tile's UVs.
92
+ // This would halve the memory requirement when viewing a full globe,
93
+ // but that case is not that relevant for iTowns' usual use cases and
94
+ // the globe mesh memory usage is already inconsequential.
95
+ const sizeLongitude = Math.abs(extent.west - extent.east) / 2;
96
+ const shareableExtent = new Extent(extent.crs, -sizeLongitude, sizeLongitude, extent.south, extent.north);
97
+
98
+ // Compute rotation to transform the tile to position on the ellispoid.
99
+ // This transformation takes the parents' transformation into account.
100
+ const rotLon = THREE.MathUtils.degToRad(extent.west - shareableExtent.west);
101
+ const rotLat = THREE.MathUtils.degToRad(90 - extent.center(this._transform.coords[0]).latitude);
102
+ quatToAlignLongitude.setFromAxisAngle(axisZ, rotLon);
103
+ quatToAlignLatitude.setFromAxisAngle(axisY, rotLat);
104
+ quatToAlignLongitude.multiply(quatToAlignLatitude);
105
+ return {
106
+ shareableExtent,
107
+ quaternion: quatToAlignLongitude.clone(),
108
+ position: this.center(extent)
109
+ };
110
+ }
111
+ }
@@ -5,7 +5,6 @@ import Coordinates from "../Geographic/Coordinates.js";
5
5
  import GlobeLayer from "./Globe/GlobeLayer.js";
6
6
  import Atmosphere from "./Globe/Atmosphere.js";
7
7
  import CameraUtils from "../../Utils/CameraUtils.js";
8
- import CRS from "../Geographic/Crs.js";
9
8
  import { ellipsoidSizes } from "../Math/Ellipsoid.js";
10
9
 
11
10
  /**
@@ -90,10 +89,6 @@ class GlobeView extends View {
90
89
  this.camera3D.far = ellipsoidSizes.x * 10;
91
90
  const tileLayer = new GlobeLayer('globe', options.object3d, options);
92
91
  this.mainLoop.gfxEngine.label2dRenderer.infoTileLayer = tileLayer.info;
93
- const sun = new THREE.DirectionalLight();
94
- sun.position.set(-0.5, 0, 1);
95
- sun.updateMatrixWorld(true);
96
- this.scene.add(sun);
97
92
  this.addLayer(tileLayer);
98
93
  this.tileLayer = tileLayer;
99
94
  if (!placement.isExtent) {
@@ -133,11 +128,11 @@ class GlobeView extends View {
133
128
  return Promise.reject(new Error('Add Layer type object'));
134
129
  }
135
130
  if (layer.isColorLayer) {
136
- if (!this.tileLayer.tileMatrixSets.includes(CRS.formatToTms(layer.source.crs))) {
131
+ if (!this.tileLayer.tileMatrixSets.includes(layer.source.crs)) {
137
132
  return layer._reject(`Only ${this.tileLayer.tileMatrixSets} tileMatrixSet are currently supported for color layers`);
138
133
  }
139
134
  } else if (layer.isElevationLayer) {
140
- if (CRS.formatToTms(layer.source.crs) !== this.tileLayer.tileMatrixSets[0]) {
135
+ if (layer.source.crs !== this.tileLayer.tileMatrixSets[0]) {
141
136
  return layer._reject(`Only ${this.tileLayer.tileMatrixSets[0]} tileMatrixSet is currently supported for elevation layers`);
142
137
  }
143
138
  }
@@ -1,21 +1,19 @@
1
1
  import * as THREE from 'three';
2
2
  import TiledGeometryLayer from "../../../Layer/TiledGeometryLayer.js";
3
- import { globalExtentTMS } from "../../Geographic/Extent.js";
4
- import CRS from "../../Geographic/Crs.js";
5
- import PlanarTileBuilder from "./PlanarTileBuilder.js";
3
+ import { globalExtentTMS } from "../../Tile/TileGrid.js";
4
+ import { PlanarTileBuilder } from "./PlanarTileBuilder.js";
6
5
 
7
6
  /**
8
7
  * @property {boolean} isPlanarLayer - Used to checkout whether this layer is a
9
8
  * PlanarLayer. Default is true. You should not change this, as it is used
10
9
  * internally for optimisation.
10
+ * @extends TiledGeometryLayer
11
11
  */
12
12
  class PlanarLayer extends TiledGeometryLayer {
13
13
  /**
14
14
  * A {@link TiledGeometryLayer} to use with a {@link PlanarView}. It has
15
15
  * specific method for updating and subdivising its grid.
16
16
  *
17
- * @extends TiledGeometryLayer
18
- *
19
17
  * @param {string} id - The id of the layer, that should be unique. It is
20
18
  * not mandatory, but an error will be emitted if this layer is added a
21
19
  * {@link View} that already has a layer going by that id.
@@ -35,19 +33,27 @@ class PlanarLayer extends TiledGeometryLayer {
35
33
  */
36
34
  constructor(id, extent, object3d) {
37
35
  let config = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
38
- const tms = CRS.formatToTms(extent.crs);
36
+ const {
37
+ minSubdivisionLevel = 0,
38
+ maxSubdivisionLevel = 5,
39
+ ...tiledConfig
40
+ } = config;
41
+ const tileMatrixSets = [extent.crs];
39
42
  if (!globalExtentTMS.get(extent.crs)) {
40
43
  // Add new global extent for this new crs projection.
41
44
  globalExtentTMS.set(extent.crs, extent);
42
45
  }
43
- config.tileMatrixSets = [tms];
44
- super(id, object3d || new THREE.Group(), [extent], new PlanarTileBuilder({
46
+ const builder = new PlanarTileBuilder({
45
47
  crs: extent.crs
46
- }), config);
48
+ });
49
+ super(id, object3d || new THREE.Group(), [extent], builder, {
50
+ tileMatrixSets,
51
+ ...tiledConfig
52
+ });
47
53
  this.isPlanarLayer = true;
48
54
  this.extent = extent;
49
- this.minSubdivisionLevel = this.minSubdivisionLevel == undefined ? 0 : this.minSubdivisionLevel;
50
- this.maxSubdivisionLevel = this.maxSubdivisionLevel == undefined ? 5 : this.maxSubdivisionLevel;
55
+ this.minSubdivisionLevel = minSubdivisionLevel;
56
+ this.maxSubdivisionLevel = maxSubdivisionLevel;
51
57
  }
52
58
  }
53
59
  export default PlanarLayer;
@@ -3,70 +3,70 @@ import Coordinates from "../../Geographic/Coordinates.js";
3
3
  import Extent from "../../Geographic/Extent.js";
4
4
  const quaternion = new THREE.Quaternion();
5
5
  const center = new THREE.Vector3();
6
- class PlanarTileBuilder {
7
- constructor() {
8
- let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
9
- /* istanbul ignore next */
6
+
7
+ /** Specialized parameters for the [PlanarTileBuilder]. */
8
+
9
+ /**
10
+ * TileBuilder implementation for the purpose of generating planar
11
+ * tile arrangements.
12
+ */
13
+ export class PlanarTileBuilder {
14
+ constructor(options) {
10
15
  if (options.projection) {
11
- console.warn('PlanarTileBuilder projection parameter is deprecated, use crs instead.');
12
- options.crs = options.crs || options.projection;
13
- }
14
- if (options.crs) {
15
- this.crs = options.crs;
16
- } else {
17
- throw new Error('options.crs is mandatory for PlanarTileBuilder');
16
+ console.warn('PlanarTileBuilder projection parameter is deprecated,' + ' use crs instead.');
17
+ options.crs ??= options.projection;
18
18
  }
19
- this.tmp = {
19
+ this._crs = options.crs;
20
+ this._transform = {
20
21
  coords: new Coordinates('EPSG:4326', 0, 0),
21
22
  position: new THREE.Vector3(),
22
23
  normal: new THREE.Vector3(0, 0, 1)
23
24
  };
24
- this.uvCount = options.uvCount || 1;
25
+ this._uvCount = options.uvCount ?? 1;
26
+ }
27
+ get uvCount() {
28
+ return this._uvCount;
29
+ }
30
+ get crs() {
31
+ return this._crs;
25
32
  }
26
- // prepare params
27
- // init projected object -> params.projected
28
33
  prepare(params) {
29
- params.nbRow = 2 ** (params.zoom + 1.0);
30
- params.projected = new THREE.Vector3();
34
+ const newParams = params;
35
+ newParams.nbRow = 2 ** (params.level + 1.0);
36
+ newParams.coordinates = new Coordinates(this.crs);
37
+ return newParams;
31
38
  }
32
-
33
- // get center tile in cartesian 3D
34
39
  center(extent) {
35
- extent.center(this.tmp.coords);
36
- center.set(this.tmp.coords.x, this.tmp.coords.y, 0);
40
+ extent.center(this._transform.coords);
41
+ center.set(this._transform.coords.x, this._transform.coords.y, 0);
37
42
  return center;
38
43
  }
39
-
40
- // get position 3D cartesian
41
- vertexPosition(params) {
42
- this.tmp.position.set(params.projected.x, params.projected.y, 0);
43
- return this.tmp.position;
44
+ vertexPosition(coordinates) {
45
+ this._transform.position.set(coordinates.x, coordinates.y, 0);
46
+ return this._transform.position;
44
47
  }
45
-
46
- // get normal for last vertex
47
48
  vertexNormal() {
48
- return this.tmp.normal;
49
+ return this._transform.normal;
49
50
  }
50
-
51
- // coord u tile to projected
52
- uProjecte(u, params) {
53
- params.projected.x = params.extent.west + u * (params.extent.east - params.extent.west);
51
+ uProject(u, extent) {
52
+ return extent.west + u * (extent.east - extent.west);
54
53
  }
55
-
56
- // coord v tile to projected
57
- vProjecte(v, params) {
58
- params.projected.y = params.extent.south + v * (params.extent.north - params.extent.south);
54
+ vProject(v, extent) {
55
+ return extent.south + v * (extent.north - extent.south);
59
56
  }
60
- computeSharableExtent(extent) {
61
- // compute sharable extent to pool the geometries
57
+ computeShareableExtent(extent) {
58
+ // compute shareable extent to pool the geometries
62
59
  // the geometry in common extent is identical to the existing input
63
60
  // with a translation
64
- const sharableExtent = new Extent(extent.crs, 0, Math.abs(extent.west - extent.east), 0, Math.abs(extent.north - extent.south));
65
61
  return {
66
- sharableExtent,
62
+ shareableExtent: new Extent(extent.crs, {
63
+ west: 0,
64
+ east: Math.abs(extent.west - extent.east),
65
+ south: 0,
66
+ north: Math.abs(extent.north - extent.south)
67
+ }),
67
68
  quaternion,
68
69
  position: this.center(extent).clone()
69
70
  };
70
71
  }
71
- }
72
- export default PlanarTileBuilder;
72
+ }
@@ -1,17 +1,23 @@
1
1
  import * as THREE from 'three';
2
- import TileGeometry from "../TileGeometry.js";
2
+ import { TileGeometry } from "../TileGeometry.js";
3
3
  import Cache from "../Scheduler/Cache.js";
4
- import computeBuffers from "./computeBufferTileGeometry.js";
4
+ import { computeBuffers } from "./computeBufferTileGeometry.js";
5
5
  import OBB from "../../Renderer/OBB.js";
6
6
  const cacheBuffer = new Map();
7
7
  const cacheTile = new Cache();
8
- export default function newTileGeometry(builder, params) {
8
+
9
+ /**
10
+ * Reference to a tile's extent with rigid transformations.
11
+ * Enables reuse of geometry, saving a bit of memory.
12
+ */
13
+
14
+ export function newTileGeometry(builder, params) {
9
15
  const {
10
- sharableExtent,
16
+ shareableExtent,
11
17
  quaternion,
12
18
  position
13
- } = builder.computeSharableExtent(params.extent);
14
- const south = sharableExtent.south.toFixed(6);
19
+ } = builder.computeShareableExtent(params.extent);
20
+ const south = shareableExtent.south.toFixed(6);
15
21
  const bufferKey = `${builder.crs}_${params.disableSkirt ? 0 : 1}_${params.segments}`;
16
22
  let promiseGeometry = cacheTile.get(south, params.level, bufferKey);
17
23
 
@@ -22,49 +28,38 @@ export default function newTileGeometry(builder, params) {
22
28
  resolve = r;
23
29
  });
24
30
  cacheTile.set(promiseGeometry, south, params.level, bufferKey);
25
- params.extent = sharableExtent;
31
+ params.extent = shareableExtent;
26
32
  params.center = builder.center(params.extent).clone();
27
- // Read previously cached values (index and uv.wgs84 only depend on the # of triangles)
33
+ // Read previously cached values (index and uv.wgs84 only
34
+ // depend on the # of triangles)
28
35
  let cachedBuffers = cacheBuffer.get(bufferKey);
29
36
  params.buildIndexAndUv_0 = !cachedBuffers;
30
- params.builder = builder;
31
37
  let buffers;
32
38
  try {
33
- buffers = computeBuffers(params);
39
+ buffers = computeBuffers(builder, params);
34
40
  } catch (e) {
35
41
  return Promise.reject(e);
36
42
  }
37
43
  if (!cachedBuffers) {
38
44
  cachedBuffers = {};
45
+ // We know the fields will exist due to the condition
46
+ // matching with the one for buildIndexAndUv_0.
47
+ // TODO: Make this brain-based check compiler-based.
39
48
  cachedBuffers.index = new THREE.BufferAttribute(buffers.index, 1);
40
49
  cachedBuffers.uv = new THREE.BufferAttribute(buffers.uvs[0], 2);
41
50
 
42
51
  // Update cacheBuffer
43
52
  cacheBuffer.set(bufferKey, cachedBuffers);
44
53
  }
45
- buffers.index = cachedBuffers.index;
46
- buffers.uvs[0] = cachedBuffers.uv;
47
- buffers.position = new THREE.BufferAttribute(buffers.position, 3);
48
- buffers.normal = new THREE.BufferAttribute(buffers.normal, 3);
49
- if (params.builder.uvCount > 1) {
50
- buffers.uvs[1] = new THREE.BufferAttribute(buffers.uvs[1], 1);
51
- }
52
- const geometry = new TileGeometry(params, buffers);
53
- geometry.OBB = new OBB(geometry.boundingBox.min, geometry.boundingBox.max);
54
- geometry._count = 0;
55
- geometry.dispose = () => {
56
- geometry._count--;
57
- if (geometry._count <= 0) {
58
- // To avoid remove index buffer and attribute buffer uv
59
- // error un-bound buffer in webgl with VAO rendering.
60
- // Could be removed if the attribute buffer deleting is
61
- // taken into account in the buffer binding state (in THREE.WebGLBindingStates code).
62
- geometry.index = null;
63
- delete geometry.attributes.uv;
64
- THREE.BufferGeometry.prototype.dispose.call(geometry);
65
- cacheTile.delete(south, params.level, bufferKey);
66
- }
54
+ const gpuBuffers = {
55
+ index: cachedBuffers.index,
56
+ uvs: [cachedBuffers.uv, ...(buffers.uvs[1] !== undefined ? [new THREE.BufferAttribute(buffers.uvs[1], 1)] : [])],
57
+ position: new THREE.BufferAttribute(buffers.position, 3),
58
+ normal: new THREE.BufferAttribute(buffers.normal, 3)
67
59
  };
60
+ const geometry = new TileGeometry(builder, params, gpuBuffers);
61
+ geometry.OBB = new OBB(geometry.boundingBox.min, geometry.boundingBox.max);
62
+ geometry.initRefCount(cacheTile, [south, params.level, bufferKey]);
68
63
  resolve(geometry);
69
64
  return Promise.resolve({
70
65
  geometry,