itowns 2.44.3-next.39 → 2.44.3-next.40
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.
- package/dist/itowns.js +1 -1
- package/dist/itowns.js.map +1 -1
- package/examples/jsm/OGC3DTilesHelper.js +5 -0
- package/lib/Layer/OGC3DTilesLayer.js +106 -4
- package/package.json +1 -1
|
@@ -33,6 +33,11 @@ export function fillHTMLWithPickingInfo(event, pickingArg) {
|
|
|
33
33
|
// eslint-disable-next-line
|
|
34
34
|
htmlDiv.appendChild(createHTMLListFromObject(closestC3DTileFeature));
|
|
35
35
|
}
|
|
36
|
+
|
|
37
|
+
layer.getMetadataFromIntersections(intersects).then((metadata) => {
|
|
38
|
+
// eslint-disable-next-line
|
|
39
|
+
metadata?.forEach(m => htmlDiv.appendChild(createHTMLListFromObject(m)));
|
|
40
|
+
});
|
|
36
41
|
}
|
|
37
42
|
|
|
38
43
|
function zoomToSphere(view, tile, sphere) {
|
|
@@ -129,6 +129,82 @@ export function enableMeshoptDecoder(MeshOptDecoder) {
|
|
|
129
129
|
}
|
|
130
130
|
itownsGLTFLoader.setMeshoptDecoder(MeshOptDecoder);
|
|
131
131
|
}
|
|
132
|
+
async function getMeshFeatures(meshFeatures, options) {
|
|
133
|
+
const {
|
|
134
|
+
faceIndex,
|
|
135
|
+
barycoord
|
|
136
|
+
} = options;
|
|
137
|
+
const features = await meshFeatures.getFeaturesAsync(faceIndex, barycoord);
|
|
138
|
+
return {
|
|
139
|
+
features,
|
|
140
|
+
featureIds: meshFeatures.getFeatureInfo()
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
function getStructuralMetadata(structuralMetadata, options) {
|
|
144
|
+
const {
|
|
145
|
+
index,
|
|
146
|
+
faceIndex,
|
|
147
|
+
barycoord,
|
|
148
|
+
tableIndices,
|
|
149
|
+
features
|
|
150
|
+
} = options;
|
|
151
|
+
const tableData = [];
|
|
152
|
+
if (tableIndices !== undefined && features !== undefined) {
|
|
153
|
+
structuralMetadata.getPropertyTableData(tableIndices, features, tableData);
|
|
154
|
+
}
|
|
155
|
+
const attributeData = [];
|
|
156
|
+
if (index !== undefined) {
|
|
157
|
+
structuralMetadata.getPropertyAttributeData(index, attributeData);
|
|
158
|
+
}
|
|
159
|
+
const textureData = [];
|
|
160
|
+
if (faceIndex !== undefined) {
|
|
161
|
+
structuralMetadata.getPropertyTextureData(faceIndex, barycoord, textureData);
|
|
162
|
+
}
|
|
163
|
+
const metadata = [...tableData, ...textureData, ...attributeData];
|
|
164
|
+
return metadata;
|
|
165
|
+
}
|
|
166
|
+
async function getMetadataFromIntersection(intersection) {
|
|
167
|
+
const {
|
|
168
|
+
point,
|
|
169
|
+
object,
|
|
170
|
+
face,
|
|
171
|
+
faceIndex
|
|
172
|
+
} = intersection;
|
|
173
|
+
const {
|
|
174
|
+
meshFeatures,
|
|
175
|
+
structuralMetadata
|
|
176
|
+
} = object.userData;
|
|
177
|
+
const barycoord = new THREE.Vector3();
|
|
178
|
+
if (face) {
|
|
179
|
+
const position = object.geometry.getAttribute('position');
|
|
180
|
+
const triangle = new THREE.Triangle().setFromAttributeAndIndices(position, face.a, face.b, face.c);
|
|
181
|
+
triangle.a.applyMatrix4(object.matrixWorld);
|
|
182
|
+
triangle.b.applyMatrix4(object.matrixWorld);
|
|
183
|
+
triangle.c.applyMatrix4(object.matrixWorld);
|
|
184
|
+
triangle.getBarycoord(point, barycoord);
|
|
185
|
+
} else {
|
|
186
|
+
barycoord.set(0, 0, 0);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
// EXT_mesh_features
|
|
190
|
+
const {
|
|
191
|
+
features,
|
|
192
|
+
featureIds
|
|
193
|
+
} = meshFeatures ? await getMeshFeatures(meshFeatures, {
|
|
194
|
+
faceIndex,
|
|
195
|
+
barycoord
|
|
196
|
+
}) : {};
|
|
197
|
+
const tableIndices = featureIds?.map(p => p.propertyTable);
|
|
198
|
+
|
|
199
|
+
// EXT_structural_metadata
|
|
200
|
+
const metadata = structuralMetadata ? getStructuralMetadata(structuralMetadata, {
|
|
201
|
+
...intersection,
|
|
202
|
+
barycoord,
|
|
203
|
+
tableIndices,
|
|
204
|
+
features
|
|
205
|
+
}) : [];
|
|
206
|
+
return metadata;
|
|
207
|
+
}
|
|
132
208
|
class OGC3DTilesLayer extends GeometryLayer {
|
|
133
209
|
/**
|
|
134
210
|
* Layer for [3D Tiles](https://www.ogc.org/standard/3dtiles/) datasets.
|
|
@@ -269,10 +345,10 @@ class OGC3DTilesLayer extends GeometryLayer {
|
|
|
269
345
|
this._res();
|
|
270
346
|
}
|
|
271
347
|
});
|
|
272
|
-
this.tilesRenderer.addEventListener('load-model',
|
|
273
|
-
|
|
348
|
+
this.tilesRenderer.addEventListener('load-model', e => {
|
|
349
|
+
const {
|
|
274
350
|
scene
|
|
275
|
-
} =
|
|
351
|
+
} = e;
|
|
276
352
|
scene.traverse(obj => {
|
|
277
353
|
this._assignFinalMaterial(obj);
|
|
278
354
|
this._assignFinalAttributes(obj);
|
|
@@ -345,10 +421,36 @@ class OGC3DTilesLayer extends GeometryLayer {
|
|
|
345
421
|
this.tilesRenderer.dispose();
|
|
346
422
|
}
|
|
347
423
|
|
|
424
|
+
/**
|
|
425
|
+
* Get the [metadata](https://github.com/CesiumGS/3d-tiles/tree/main/specification/Metadata)
|
|
426
|
+
* of the closest intersected object from a list of intersections.
|
|
427
|
+
*
|
|
428
|
+
* This method retrieves structured metadata stored in GLTF 2.0 assets using
|
|
429
|
+
* the [`EXT_structural_metadata`](https://github.com/CesiumGS/glTF/tree/3d-tiles-next/extensions/2.0/Vendor/EXT_structural_metadata)
|
|
430
|
+
* extension.
|
|
431
|
+
*
|
|
432
|
+
* Internally, it uses the closest intersected point to index metadata
|
|
433
|
+
* stored in property attributes and textures.
|
|
434
|
+
*
|
|
435
|
+
* If present in GLTF 2.0 assets, this method leverages the
|
|
436
|
+
* [`EXT_mesh_features`](`https://github.com/CesiumGS/glTF/tree/3d-tiles-next/extensions/2.0/Vendor/EXT_mesh_features)
|
|
437
|
+
* extension and the returned featured to index metadata stored in property tables.
|
|
438
|
+
*
|
|
439
|
+
* @param {Array<THREE.Intersection>} intersections
|
|
440
|
+
* @returns {Promise<Object | null>} - the intersected object's metadata
|
|
441
|
+
*/
|
|
442
|
+
async getMetadataFromIntersections(intersections) {
|
|
443
|
+
if (!intersections.length) {
|
|
444
|
+
return null;
|
|
445
|
+
}
|
|
446
|
+
const metadata = await getMetadataFromIntersection(intersections[0]);
|
|
447
|
+
return metadata;
|
|
448
|
+
}
|
|
449
|
+
|
|
348
450
|
/**
|
|
349
451
|
* Get the attributes for the closest intersection from a list of
|
|
350
452
|
* intersects.
|
|
351
|
-
* @param {Array} intersects - An array containing all
|
|
453
|
+
* @param {Array<THREE.Intersection>} intersects - An array containing all
|
|
352
454
|
* objects picked under mouse coordinates computed with view.pickObjectsAt(..).
|
|
353
455
|
* @returns {Object | null} - An object containing
|
|
354
456
|
*/
|