Skip to content

Commit

Permalink
feature(View): instancing pickGeometryAt
Browse files Browse the repository at this point in the history
  • Loading branch information
a-dutremble authored and Aymeric DUTREMBLE committed Nov 20, 2023
1 parent 2428d56 commit 549d6b3
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Core/View.js
Original file line number Diff line number Diff line change
Expand Up @@ -774,6 +774,11 @@ class View extends THREE.EventDispatcher {
return results;
}

pickGeometryAt(mouseOrEvt, radius = 0, where) {
const layer = this.getLayerById(where);
return layer.selectGeometry(mouseOrEvt, radius, this);
}

/**
* Return the current zoom scale at the central point of the view. This
* function compute the scale of a map.
Expand Down
7 changes: 7 additions & 0 deletions src/Layer/ColorLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,13 @@ class ColorLayer extends RasterLayer {
update(context, layer, node, parent) {
return updateLayeredMaterialNodeImagery(context, this, node, parent);
}

selectGeometry(mouseOrEvt, radius, view) {
const results = view.pickFeaturesAt(mouseOrEvt, radius, this.id);
if (results[this.id].length) {
return results[this.id][0].geometry;
}
}
}

export default ColorLayer;
17 changes: 17 additions & 0 deletions src/Layer/FeatureGeometryLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,23 @@ class FeatureGeometryLayer extends GeometryLayer {
this.object3d.clear();
}
}

selectGeometry(mouseOrEvt, radius, view) {
const results = view.pickObjectsAt(mouseOrEvt, radius, this.id);
if (results.length) {
if (results[0].object.isLine) {
const batchId = results[0].object.geometry.attributes.batchId.array[results[0].object.geometry.index.array[results[0].index]];
return { geometry: results[0].object.feature.geometries[batchId], mesh: results[0].object };
} else if (results[0].object.isPoints) {
const batchId = results[0].object.geometry.attributes.batchId.array[results[0].index];
return { geometry: results[0].object.feature.geometries[batchId], mesh: results[0].object };
} else if (results[0].object.isMesh) {
const batchId = results[0].object.geometry.attributes.batchId.array[results[0].face.a];
return { geometry: results[0].object.feature.geometries[batchId], mesh: results[0].object };
}
}
return undefined;
}
}

export default FeatureGeometryLayer;
4 changes: 4 additions & 0 deletions src/Layer/Layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,10 @@ class Layer extends THREE.EventDispatcher {
delete(clearCache) {
console.warn('Function delete doesn\'t exist for this layer');
}

selectGeometry() {
throw new Error('selectGeometry is not supported yet in this type of layer');
}
}

export default Layer;
Expand Down

0 comments on commit 549d6b3

Please sign in to comment.