public bool FindHitEdge(Ray3f sceneRay, MeshEditorOpType.BoundaryType boundaryMode, bool snap_to_center, ref Frame3f hitFrameS, ref int hitEID) { Ray3f objRay = SceneTransforms.SceneToObject(Target, sceneRay); int hit_tri = PreviewSpatial.FindNearestHitTriangle(objRay); if (hit_tri == DMesh3.InvalidID) { return(false); } if (allow_backface_hits == false && is_back_facing(hit_tri)) { return(false); } var intr = MeshQueries.TriangleIntersection(PreviewMesh, hit_tri, objRay); int e_idx = -1; double near_sqr = double.MaxValue; DistRay3Segment3 near_dist = null; for (int j = 0; j < 3; ++j) { Segment3d seg = new Segment3d(intr.Triangle[j], intr.Triangle[(j + 1) % 3]); DistRay3Segment3 dist = new DistRay3Segment3(objRay, seg); if (dist.GetSquared() < near_sqr) { near_sqr = dist.GetSquared(); near_dist = dist; e_idx = j; } } int eid = PreviewMesh.GetTriEdge(hit_tri, e_idx); if (boundaryMode != MeshEditorOpType.BoundaryType.Any) { bool is_boundary = PreviewMesh.IsBoundaryEdge(eid); if ((is_boundary && boundaryMode == MeshEditorOpType.BoundaryType.OnlyInternal) || (is_boundary == false && boundaryMode == MeshEditorOpType.BoundaryType.OnlyBoundary)) { return(false); } } if (snap_to_center) { Frame3f hitFrameL = new Frame3f(PreviewMesh.GetEdgePoint(eid, 0.5), PreviewMesh.GetTriNormal(hit_tri)); hitFrameS = SceneTransforms.ObjectToScene(previewSO, hitFrameL); } else { Frame3f hitFrameL = new Frame3f(near_dist.SegmentClosest, PreviewMesh.GetTriNormal(hit_tri)); hitFrameS = SceneTransforms.ObjectToScene(previewSO, hitFrameL); } hitEID = eid; return(true); }
public Vector3f FindSnapPoint(Ray3f ray) { DistRay3Segment3 dist = new DistRay3Segment3(ray, segmentW); dist.GetSquared(); return((Vector3f)dist.SegmentClosest); }
public bool FindRayIntersection(Ray3f ray, out float fHitDist) { fHitDist = float.PositiveInfinity; float fHitThreshSqr = 2.0f * fLineWidthW; fHitThreshSqr *= fHitThreshSqr; DistRay3Segment3 dist = new DistRay3Segment3(ray, segmentW); float fDistWSqr = (float)dist.GetSquared(); if (fDistWSqr < fHitThreshSqr) { fHitDist = (float)dist.RayParameter; return(true); } return(false); }
public static bool FindClosestRayIntersection(ISampledCurve3d c, double segRadius, Ray3d ray, out double rayT) { rayT = double.MaxValue; int nNearSegment = -1; //double fNearSegT = 0.0; int N = c.VertexCount; int iStop = (c.Closed) ? N : N - 1; for (int i = 0; i < iStop; ++i) { DistRay3Segment3 dist = new DistRay3Segment3(ray, new Segment3d(c.GetVertex(i), c.GetVertex((i + 1) % N))); // raycast to line bounding-sphere first (is this going ot be faster??) double fSphereHitT; bool bHitBoundSphere = RayIntersection.SphereSigned(ray.Origin, ray.Direction, dist.Segment.Center, dist.Segment.Extent + segRadius, out fSphereHitT); if (bHitBoundSphere == false) { continue; } // find ray/seg min-distance and use ray T double dSqr = dist.GetSquared(); if (dSqr < segRadius * segRadius) { if (dist.RayParameter < rayT) { rayT = dist.RayParameter; //fNearSegT = dist.SegmentParameter; nNearSegment = i; } } } return(nNearSegment >= 0); }