itowns 2.42.1-next.1 → 2.42.1-next.3

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.
@@ -51,10 +51,14 @@
51
51
 
52
52
  view.camera3D.far = 2.0 * size.length();
53
53
 
54
- var position = eptLayer.root.bbox.min.clone().add(size.multiply({ x: 0, y: 0, z: size.x / size.z }));
54
+ controls.groundLevel = eptLayer.root.bbox.min.z;
55
+ var position = eptLayer.root.bbox.min.clone().add(
56
+ size.multiply({ x: 0, y: 0, z: size.x / size.z })
57
+ );
55
58
 
56
59
  view.camera3D.position.copy(position);
57
60
  view.camera3D.lookAt(lookAt);
61
+ view.camera3D.updateProjectionMatrix();
58
62
 
59
63
  view.notifyChange(view.camera3D);
60
64
  }
@@ -77,8 +81,10 @@
77
81
  eptSource = new itowns.EntwinePointTileSource({ url });
78
82
 
79
83
  if (eptLayer) {
80
- view.removeLayer('ept');
84
+ debugGUI.removeFolder(eptLayer.debugUI);
85
+ view.removeLayer('Entwine Point Tile');
81
86
  view.notifyChange();
87
+ eptLayer.delete();
82
88
  }
83
89
 
84
90
  eptLayer = new itowns.EntwinePointTileLayer('Entwine Point Tile', {
@@ -7,6 +7,24 @@ exports.default = void 0;
7
7
  var _three = require("three");
8
8
  // eslint-disable-next-line no-unused-vars
9
9
 
10
+ /**
11
+ * Finds the batch table of an object in a 3D Tiles layer. This is
12
+ * for instance needed when picking because we pick the geometric
13
+ * object which is not at the same level in the layer structure as
14
+ * the batch table.
15
+ * @param {THREE.Object3D} object - a 3D geometric object
16
+ * @returns {C3DTBatchTable|null} - the batch table of the object
17
+ */
18
+ function findBatchTable(object) {
19
+ if (object.batchTable) {
20
+ return object.batchTable;
21
+ }
22
+ if (object.parent) {
23
+ return findBatchTable(object.parent);
24
+ }
25
+ return null;
26
+ }
27
+
10
28
  /**
11
29
  * C3DTFeature is a feature of a 3DTiles
12
30
  *
@@ -14,23 +32,17 @@ var _three = require("three");
14
32
  * @param {number} tileId - tileId
15
33
  * @param {number} batchId - batch id
16
34
  * @param {Array<{start:number,count:number}>} groups - groups in geometry.attributes matching batchId
17
- * @param {object} info - info in the batchTable
18
35
  * @param {object} [userData] - some userData
19
36
  * @param {Object3D} object3d - object3d in which feature is present
20
37
  * @property {number} tileId - tile id
21
38
  * @property {Object3D} object3d - object3d in which feature is present
22
39
  * @property {number} batchId - batch id
23
40
  * @property {Array<{start:number,count:number}>} groups - groups in geometry.attributes matching batchId
24
- * @property {object} info - info in the batchTable
25
41
  * @property {object} [userData] - some userData
26
42
  */
27
43
  class C3DTFeature {
28
44
  #info;
29
- constructor(tileId, batchId, groups, info, userData, object3d) {
30
- if (!object3d) {
31
- console.error('BREAKING CHANGE: C3DTFeature constructor changed from (tileId, batchId, groups, info, userData) to (tileId, batchId, groups, info, userData, object3d)');
32
- }
33
-
45
+ constructor(tileId, batchId, groups, userData, object3d) {
34
46
  /** @type {Object3D} */
35
47
  this.object3d = object3d;
36
48
 
@@ -43,11 +55,11 @@ class C3DTFeature {
43
55
  /** @type {object} */
44
56
  this.userData = userData;
45
57
 
46
- /** @type {object} */
47
- this.#info = info;
48
-
49
58
  /** @type {number} */
50
59
  this.tileId = tileId;
60
+
61
+ // Lazy-loaded batch table information for this.batchId.
62
+ this.#info = null;
51
63
  }
52
64
 
53
65
  /**
@@ -85,10 +97,20 @@ class C3DTFeature {
85
97
  }
86
98
 
87
99
  /**
88
- *
100
+ * Gets the information from the tile batch table for this C3DTFeature batch id.
89
101
  * @returns {object} - batchTable info
90
102
  */
91
103
  getInfo() {
104
+ if (this.#info) {
105
+ return this.#info;
106
+ }
107
+ const batchTable = findBatchTable(this.object3d);
108
+ if (!batchTable) {
109
+ console.warn(`[C3DTFeature]: No batch table found for tile ${this.tileId}.`);
110
+ return null; // or return undefined;
111
+ }
112
+
113
+ this.#info = batchTable.getInfoById(this.batchId);
92
114
  return this.#info;
93
115
  }
94
116
  }
@@ -223,25 +223,6 @@ class C3DTilesLayer extends _GeometryLayer.default {
223
223
  }
224
224
  }
225
225
 
226
- /**
227
- * Finds the batch table of an object in a 3D Tiles layer. This is
228
- * for instance needed when picking because we pick the geometric
229
- * object which is not at the same level in the layer structure as
230
- * the batch table. More details here on itowns internal
231
- * organization of 3DTiles:
232
- * https://github.com/MEPP-team/RICT/blob/master/Doc/iTowns/Doc.md#itowns-internal-organisation-of-3d-tiles-data
233
- * @param {THREE.Object3D} object - a 3D geometric object
234
- * @returns {C3DTBatchTable} - the batch table of the object
235
- */
236
- findBatchTable(object) {
237
- if (object.batchTable) {
238
- return object.batchTable;
239
- }
240
- if (object.parent) {
241
- return this.findBatchTable(object.parent);
242
- }
243
- }
244
-
245
226
  /**
246
227
  * Get the closest c3DTileFeature of an intersects array.
247
228
  * @param {Array} intersects - @return An array containing all
@@ -300,12 +281,8 @@ class C3DTilesLayer extends _GeometryLayer.default {
300
281
  this.tilesC3DTileFeatures.set(tileContent.tileId, new Map()); // initialize
301
282
  tileContent.traverse(child => {
302
283
  if (object3DHasFeature(child)) {
303
- const batchTable = this.findBatchTable(child);
304
- if (!batchTable) {
305
- throw new Error('no batchTable');
306
- }
307
- const geometryAttributes = child.geometry.attributes;
308
- let currentBatchId = geometryAttributes._BATCHID.array[0];
284
+ const batchIdAttribute = child.geometry.getAttribute('_BATCHID');
285
+ let currentBatchId = batchIdAttribute.getX(0);
309
286
  let start = 0;
310
287
  let count = 0;
311
288
  const registerBatchIdGroup = () => {
@@ -324,13 +301,18 @@ class C3DTilesLayer extends _GeometryLayer.default {
324
301
  count
325
302
  }],
326
303
  // initialize with current group
327
- batchTable.getInfoById(currentBatchId), {}, child);
304
+ {}, child);
328
305
  this.tilesC3DTileFeatures.get(tileContent.tileId).set(currentBatchId, c3DTileFeature);
329
306
  }
330
307
  };
331
- for (let index = 0; index < geometryAttributes.position.array.length; index += geometryAttributes.position.itemSize) {
332
- const batchIndex = index / geometryAttributes.position.itemSize;
333
- const batchId = geometryAttributes._BATCHID.array[batchIndex];
308
+
309
+ // TODO: Could be simplified by incrementing of 1 and stopping the iteration at positionAttributeSize.count
310
+ // See https://github.com/iTowns/itowns/pull/2266#discussion_r1483285122
311
+ const positionAttribute = child.geometry.getAttribute('position');
312
+ const positionAttributeSize = positionAttribute.count * positionAttribute.itemSize;
313
+ for (let index = 0; index < positionAttributeSize; index += positionAttribute.itemSize) {
314
+ const batchIndex = index / positionAttribute.itemSize;
315
+ const batchId = batchIdAttribute.getX(batchIndex);
334
316
 
335
317
  // check if batchId is currentBatchId
336
318
  if (currentBatchId !== batchId) {
@@ -346,7 +328,7 @@ class C3DTilesLayer extends _GeometryLayer.default {
346
328
  count++;
347
329
 
348
330
  // check if end of the array
349
- if (index + geometryAttributes.position.itemSize >= geometryAttributes.position.array.length) {
331
+ if (index + positionAttribute.itemSize >= positionAttributeSize) {
350
332
  registerBatchIdGroup();
351
333
  }
352
334
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "itowns",
3
- "version": "2.42.1-next.1",
3
+ "version": "2.42.1-next.3",
4
4
  "description": "A JS/WebGL framework for 3D geospatial data visualization",
5
5
  "main": "lib/Main.js",
6
6
  "exports": {