Skip to content

Commit

Permalink
optional flag to force return face normal
Browse files Browse the repository at this point in the history
  • Loading branch information
rms80 committed Apr 24, 2018
1 parent 89dcd9f commit 307dfe4
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions queries/MeshQueries.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ public static DistPoint3Triangle3 TriangleDistance(DMesh3 mesh, int ti, Vector3d
/// Find point-normal(Z) frame at closest point to queryPoint on mesh.
/// Returns interpolated vertex-normal frame if available, otherwise tri-normal frame.
/// </summary>
public static Frame3f NearestPointFrame(DMesh3 mesh, ISpatial spatial, Vector3d queryPoint)
public static Frame3f NearestPointFrame(DMesh3 mesh, ISpatial spatial, Vector3d queryPoint, bool bForceFaceNormal = false)
{
int tid = spatial.FindNearestTriangle(queryPoint);
Vector3d surfPt = TriangleDistance(mesh, tid, queryPoint).TriangleClosest;
if (mesh.HasVertexNormals)
if (mesh.HasVertexNormals && bForceFaceNormal == false)
return SurfaceFrame(mesh, tid, surfPt);
else
return new Frame3f(surfPt, mesh.GetTriNormal(tid));
Expand Down Expand Up @@ -113,7 +113,7 @@ public static DistTriangle3Triangle3 TrianglesDistance(DMesh3 mesh1, int ti, DMe
/// Find point-normal frame at ray-intersection point on mesh, or return false if no hit.
/// Returns interpolated vertex-normal frame if available, otherwise tri-normal frame.
/// </summary>
public static bool RayHitPointFrame(DMesh3 mesh, ISpatial spatial, Ray3d ray, out Frame3f hitPosFrame)
public static bool RayHitPointFrame(DMesh3 mesh, ISpatial spatial, Ray3d ray, out Frame3f hitPosFrame, bool bForceFaceNormal = false)
{
hitPosFrame = new Frame3f();
int tid = spatial.FindNearestHitTriangle(ray);
Expand All @@ -123,7 +123,7 @@ public static bool RayHitPointFrame(DMesh3 mesh, ISpatial spatial, Ray3d ray, ou
if (isect.Result != IntersectionResult.Intersects)
return false;
Vector3d surfPt = ray.PointAt(isect.RayParameter);
if (mesh.HasVertexNormals)
if (mesh.HasVertexNormals && bForceFaceNormal == false)
hitPosFrame = SurfaceFrame(mesh, tid, surfPt); // TODO isect has bary-coords already!!
else
hitPosFrame = new Frame3f(surfPt, mesh.GetTriNormal(tid));
Expand All @@ -135,15 +135,15 @@ public static bool RayHitPointFrame(DMesh3 mesh, ISpatial spatial, Ray3d ray, ou
/// Get point-normal frame on surface of mesh. Assumption is that point lies in tID.
/// returns interpolated vertex-normal frame if available, otherwise tri-normal frame.
/// </summary>
public static Frame3f SurfaceFrame(DMesh3 mesh, int tID, Vector3d point)
public static Frame3f SurfaceFrame(DMesh3 mesh, int tID, Vector3d point, bool bForceFaceNormal = false)
{
if (!mesh.IsTriangle(tID))
throw new Exception("MeshQueries.SurfaceFrame: triangle " + tID + " does not exist!");
Triangle3d tri = new Triangle3d();
mesh.GetTriVertices(tID, ref tri.V0, ref tri.V1, ref tri.V2);
Vector3d bary = tri.BarycentricCoords(point);
point = tri.PointAt(bary);
if (mesh.HasVertexNormals) {
if (mesh.HasVertexNormals && bForceFaceNormal == false) {
Vector3d normal = mesh.GetTriBaryNormal(tID, bary.x, bary.y, bary.z);
return new Frame3f(point, normal);
} else
Expand Down

0 comments on commit 307dfe4

Please sign in to comment.