Skip to content

Commit

Permalink
utility functions
Browse files Browse the repository at this point in the history
  • Loading branch information
rms80 committed May 30, 2017
1 parent 0a8bfc2 commit 2c8eb44
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
18 changes: 18 additions & 0 deletions core/Util.cs
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,24 @@ public static void WriteDebugMesh(IMesh mesh, string sPath)
StandardMeshWriter.WriteFile(sPath, new List<WriteMesh>() { new WriteMesh(mesh) }, options);
}

public static void WriteDebugMeshAndMarkers(IMesh mesh, List<Vector3d> Markers, string sPath)
{
WriteOptions options = WriteOptions.Defaults;
options.bWriteGroups = true;
List<WriteMesh> meshes = new List<WriteMesh>() { new WriteMesh(mesh) };
double size = BoundsUtil.Bounds(mesh).Diagonal.Length * 0.01f;
foreach ( Vector3d v in Markers ) {
TrivialBox3Generator boxgen = new TrivialBox3Generator();
boxgen.Box = new Box3d(v, size * Vector3d.One);
boxgen.Generate();
DMesh3 m = new DMesh3();
boxgen.MakeMesh(m);
meshes.Add(new WriteMesh(m));
}

StandardMeshWriter.WriteFile(sPath, meshes, options);
}


}

Expand Down
18 changes: 17 additions & 1 deletion queries/MeshQueries.cs
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,23 @@ public static double TriDistanceSqr(DMesh3 mesh, int ti, Vector3d point)



// brute force search for nearest triangle to point
public static int FindNearestVertex_LinearSearch(DMesh3 mesh, Vector3d p)
{
int vNearest = DMesh3.InvalidID;
double fNearestSqr = double.MaxValue;
foreach ( int vid in mesh.VertexIndices() ) {
double distSqr = mesh.GetVertex(vid).DistanceSquared(p);
if (distSqr < fNearestSqr) {
fNearestSqr = distSqr;
vNearest = vid;
}
}
return vNearest;
}



// brute force search for nearest triangle to point
public static int FindNearestTriangle_LinearSearch(DMesh3 mesh, Vector3d p)
{
Expand All @@ -219,7 +236,6 @@ public static int FindNearestTriangle_LinearSearch(DMesh3 mesh, Vector3d p)
return tNearest;
}


public static int FindHitTriangle_LinearSearch(DMesh3 mesh, Ray3d ray)
{
int tNearestID = DMesh3.InvalidID;
Expand Down

0 comments on commit 2c8eb44

Please sign in to comment.