Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 219e015

Browse files
valentinMachadojailln
authored andcommitted
fix(C3DTilesLayer): handle tileContent with several child containing C3DTFeature.
BREAKING CHANGE: C3DTFeature constructor changed from (tileId, batchId, groups, info, userData) to (tileId, batchId, groups, info, userData, object3d)
1 parent de88737 commit 219e015

File tree

5 files changed

+186
-156
lines changed

5 files changed

+186
-156
lines changed

examples/widgets_3dtiles_style.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,11 @@
108108
const material = new itowns.THREE.MeshBasicMaterial( {color: 0x00ff00, opacity: 0.5, transparent: true} );
109109
const cube = new itowns.THREE.Mesh( geometry, material );
110110
view.domElement.onclick = (event) => {
111-
const intersects = view.pickObjectsAt(event, 0, [$3dTilesLayer]);
111+
const intersects = view.pickObjectsAt(event, 5, [$3dTilesLayer]);
112112
const c3DTileFeatureClicked = $3dTilesLayer.getC3DTileFeatureFromIntersectsArray(intersects);
113113

114114
if (c3DTileFeatureClicked) {
115-
const worldBox3 = $3dTilesLayer.computeWorldBox3(c3DTileFeatureClicked);
115+
const worldBox3 = c3DTileFeatureClicked.computeWorldBox3();
116116
cube.scale.copy(worldBox3.max.clone().sub(worldBox3.min));
117117
worldBox3.getCenter(cube.position);
118118
cube.updateMatrixWorld();

src/Core/3DTiles/C3DTFeature.js

Lines changed: 57 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,32 @@
1+
// eslint-disable-next-line no-unused-vars
2+
import { Object3D, Box3 } from 'three';
3+
14
/**
25
* C3DTFeature is a feature of a 3DTiles
36
*
47
* @class C3DTFeature
5-
* @param {number} tileId - tile id
8+
* @param {number} tileId - tileId
69
* @param {number} batchId - batch id
710
* @param {Array<{start:number,count:number}>} groups - groups in geometry.attributes matching batchId
811
* @param {object} info - info in the batchTable
9-
* @param {object} [userData={}] - some userData
12+
* @param {object} [userData] - some userData
13+
* @param {Object3D} object3d - object3d in which feature is present
1014
* @property {number} tileId - tile id
15+
* @property {Object3D} object3d - object3d in which feature is present
1116
* @property {number} batchId - batch id
1217
* @property {Array<{start:number,count:number}>} groups - groups in geometry.attributes matching batchId
1318
* @property {object} info - info in the batchTable
14-
* @property {object} [userData={}] - some userData
19+
* @property {object} [userData] - some userData
1520
*/
1621
class C3DTFeature {
1722
#info;
18-
constructor(tileId, batchId, groups, info, userData = {}) {
19-
/** @type {number} */
20-
this.tileId = tileId;
23+
constructor(tileId, batchId, groups, info, userData, object3d) {
24+
if (!object3d) {
25+
console.error('BREAKING CHANGE: C3DTFeature constructor changed from (tileId, batchId, groups, info, userData) to (tileId, batchId, groups, info, userData, object3d)');
26+
}
27+
28+
/** @type {Object3D} */
29+
this.object3d = object3d;
2130

2231
/** @type {number} */
2332
this.batchId = batchId;
@@ -30,6 +39,48 @@ class C3DTFeature {
3039

3140
/** @type {object} */
3241
this.#info = info;
42+
43+
/** @type {number} */
44+
this.tileId = tileId;
45+
}
46+
47+
/**
48+
* Compute world box3 of this
49+
*
50+
* @param {Box3} target - target of the result
51+
* @returns {Box3}
52+
*/
53+
computeWorldBox3(target = new Box3()) {
54+
// reset
55+
target.max.x = -Infinity;
56+
target.max.y = -Infinity;
57+
target.max.z = -Infinity;
58+
target.min.x = Infinity;
59+
target.min.y = Infinity;
60+
target.min.z = Infinity;
61+
62+
this.groups.forEach((group) => {
63+
const positionIndexStart = group.start * 3;
64+
const positionIndexCount = (group.start + group.count) * 3;
65+
66+
for (let index = positionIndexStart; index < positionIndexCount; index += 3) {
67+
const x = this.object3d.geometry.attributes.position.array[index];
68+
const y = this.object3d.geometry.attributes.position.array[index + 1];
69+
const z = this.object3d.geometry.attributes.position.array[index + 2];
70+
71+
target.max.x = Math.max(x, target.max.x);
72+
target.max.y = Math.max(y, target.max.y);
73+
target.max.z = Math.max(z, target.max.z);
74+
75+
target.min.x = Math.min(x, target.min.x);
76+
target.min.y = Math.min(y, target.min.y);
77+
target.min.z = Math.min(z, target.min.z);
78+
}
79+
});
80+
81+
target.applyMatrix4(this.object3d.matrixWorld);
82+
83+
return target;
3384
}
3485

3586
/**

0 commit comments

Comments
 (0)