Skip to content

Commit

Permalink
Add barycoord to the results to match latest thre.js
Browse files Browse the repository at this point in the history
  • Loading branch information
gkjohnson committed Sep 29, 2024
1 parent d753bd9 commit dca4244
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
13 changes: 12 additions & 1 deletion src/utils/ThreeRayIntersectUtilities.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { Vector3, Vector2, Triangle, DoubleSide, BackSide } from 'three';
import { Vector3, Vector2, Triangle, DoubleSide, BackSide, REVISION } from 'three';

const IS_GT_REVISION_169 = parseInt( REVISION ) >= 169;

// Ripped and modified From THREE.js Mesh raycast
// https://github.com/mrdoob/three.js/blob/0aa87c999fe61e216c1133fba7a95772b503eddf/src/objects/Mesh.js#L115
Expand Down Expand Up @@ -53,6 +55,9 @@ function checkBufferGeometryIntersection( ray, position, normal, uv, uv1, a, b,

if ( intersection ) {

const barycoord = new Vector3();
Triangle.getBarycoord( _intersectionPoint, _vA, _vB, _vC, barycoord );

if ( uv ) {

_uvA.fromBufferAttribute( uv, a );
Expand Down Expand Up @@ -101,6 +106,12 @@ function checkBufferGeometryIntersection( ray, position, normal, uv, uv1, a, b,
intersection.face = face;
intersection.faceIndex = a;

if ( IS_GT_REVISION_169 ) {

intersection.barycoord = barycoord;

}

}

return intersection;
Expand Down
8 changes: 7 additions & 1 deletion src/utils/TriangleUtilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ export function getTriangleHitPointInfo( point, geometry, triangleIndex, target

}

// extract barycoord
const barycoord = target && target.barycoord ? target.barycoord : new Vector3();
Triangle.getBarycoord( point, tempV1, tempV2, tempV3, barycoord );

// extract uvs
let uv = null;
if ( uvs ) {
Expand Down Expand Up @@ -98,6 +102,7 @@ export function getTriangleHitPointInfo( point, geometry, triangleIndex, target
Triangle.getNormal( tempV1, tempV2, tempV3, target.face.normal );

if ( uv ) target.uv = uv;
target.barycoord = barycoord;

return target;

Expand All @@ -111,7 +116,8 @@ export function getTriangleHitPointInfo( point, geometry, triangleIndex, target
materialIndex: materialIndex,
normal: Triangle.getNormal( tempV1, tempV2, tempV3, new Vector3() )
},
uv: uv
uv: uv,
barycoord: barycoord,
};

}
Expand Down

0 comments on commit dca4244

Please sign in to comment.