Closed Tirzono closed 1 year ago
If you look at the documentation for shapecast you'll see that the triangle index is already being passed into the intersectsTriangle
function:
intersectsTriangle : (
triangle : ExtendedTriangle,
triangleIndex : Number,
contained : Boolean,
depth : Number
) => Boolean = null,
Apologies, that's something I should've known.
For anyone else with the same question who then wants to translate triangleIndex
to the indices of the points of the triangle:
const indices = mesh.geometry.getIndex().array;
mesh.geometry.boundsTree.shapecast({
intersectsTriangle: (triangle, triangleIndex) => {
const a = indices[triangleIndex * 3]; // Matches triangle.a
const b = indices[triangleIndex * 3 + 1]; // Matches triangle.b
const c = indices[triangleIndex * 3 + 2]; // Matches triangle.c
It's best to do the following to account for different buffer attribute types:
const index = mesh.geometry.getIndex();
// ...
const a = index.getX( triangleIndex * 3 ); // Matches triangle.a
const b = index.getX( triangleIndex * 3 + 1 ); // Matches triangle.b
const c = index.getX( triangleIndex * 3 + 2 ); // Matches triangle.c
Is your feature request related to a problem? Please describe.
I would like to intersect a geometry with a plane and would like to get an outline of that intersection, but I would also like to get the color from the material of the geometry along that line. I am using this example:
https://github.com/gkjohnson/three-mesh-bvh/blob/master/example/clippedEdges.js
And am able to get the outline. However, in order to get the color from the material of the geometry, I need to know the indices of points in the ExtendedTriangle.
Describe the solution you'd like
Pass the indices of the intersection to the user in the
intersectsTriangle
function. Maybe this can be done insetTriangle
by adding a propertyindices
?And in
setTriangle
:Describe alternatives you've considered
N/A
Additional context
N/A