Changes
Co-authored-by: Reifonas <211114984+Reifonas@users.noreply.github.com>
This commit is contained in:
@@ -316,3 +316,22 @@ function pointToSegmentDist(px: number, py: number, ax: number, ay: number, bx:
|
|||||||
const closestY = ay + t * dy;
|
const closestY = ay + t * dy;
|
||||||
return Math.sqrt((px - closestX) ** 2 + (py - closestY) ** 2);
|
return Math.sqrt((px - closestX) ** 2 + (py - closestY) ** 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Combined snap resolver: tries vertex first, then edge midpoint,
|
||||||
|
* falling back to the raw hit point. Returns { point, type }.
|
||||||
|
*/
|
||||||
|
export function resolveSnap(
|
||||||
|
mesh: THREE.Mesh,
|
||||||
|
hitPoint: THREE.Vector3,
|
||||||
|
camera: THREE.Camera,
|
||||||
|
canvasSize: { width: number; height: number },
|
||||||
|
vertexThresholdPx: number = 12,
|
||||||
|
edgeThresholdPx: number = 16
|
||||||
|
): { point: THREE.Vector3; type: 'vertex' | 'edge' | 'surface' } {
|
||||||
|
const v = findNearestVertex(mesh, hitPoint, camera, canvasSize, vertexThresholdPx);
|
||||||
|
if (v) return { point: v, type: 'vertex' };
|
||||||
|
const e = findNearestEdgeSegment(mesh, hitPoint, camera, canvasSize, edgeThresholdPx);
|
||||||
|
if (e) return { point: e.midpoint, type: 'edge' };
|
||||||
|
return { point: hitPoint.clone(), type: 'surface' };
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user