起点的Yuka js库中的函数,用于计算光线与凸包之间的相交情况。
intersectConvexHull( ray, points )
ray - THREE.Ray | THREE.Raycaster,射线对象。points - Array<THREE.Vector3>,表示凸包的点集。返回 null,表示光线与凸包没有任何交点。如果相交了,返回一个具有以下属性的对象:
point - THREE.Vector3,相交点的位置。distance - Number,相交点到光线原点的距离。import { intersectConvexHull } from 'yuka';
const convexHull = new THREE.ConvexGeometry( [
new THREE.Vector3( -50, 50, 0 ),
new THREE.Vector3( -50, -50, -50 ),
new THREE.Vector3( 50, 50, 0 ),
new THREE.Vector3( 50, -50, -50 )
] );
const raycaster = new THREE.Raycaster();
let intersection = intersectConvexHull( raycaster.ray, convexHull.vertices );
if ( intersection ) {
console.log( 'Intersection point:', intersection.point );
console.log( 'Distance to the intersection point:', intersection.distance );
} else {
console.log( 'No intersection.' );
}