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 */
1621class 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