Skip to content

Commit

Permalink
Finished implementing the raycast projection code
Browse files Browse the repository at this point in the history
  • Loading branch information
jratcliff committed Aug 9, 2017
1 parent 9b6e5a6 commit dd20bd4
Show file tree
Hide file tree
Showing 15 changed files with 104 additions and 580 deletions.
Binary file modified DebugView/ConvexDecomposition.exe
Binary file not shown.
4 changes: 2 additions & 2 deletions DebugView/TestRaycast.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "TestRaycast.h"
#include "NvRenderDebug.h"
#include "RaycastMesh.h"
#include "vhacdRaycastMesh.h"
#include <float.h>
#include <math.h>

Expand Down Expand Up @@ -90,7 +90,7 @@ class TestRaycastImpl : public TestRaycast
renderDebug->removeFromCurrentState(RENDER_DEBUG::DebugRenderState::SolidWireShaded);
renderDebug->setCurrentArrowSize(float(distance*0.01));

RaycastMesh *rm = RaycastMesh::createRaycastMesh(vcount,3, vertices, tcount, 3, indices);
VHACD::RaycastMesh *rm = VHACD::RaycastMesh::createRaycastMesh(vcount,3, vertices, tcount, 3, indices);

float bmn[3];
float bmx[3];
Expand Down
8 changes: 2 additions & 6 deletions DebugView/compiler/vc14win32/ConvexDecomposition.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,6 @@
</ClInclude>
<ClInclude Include="..\..\..\src\VHACD_Lib\inc\btVector3.h">
</ClInclude>
<ClInclude Include="..\..\..\src\VHACD_Lib\inc\RaycastMesh.h">
</ClInclude>
<ClInclude Include="..\..\..\src\VHACD_Lib\inc\vhacdCircularList.h">
</ClInclude>
<ClInclude Include="..\..\..\src\VHACD_Lib\inc\vhacdICHull.h">
Expand All @@ -157,7 +155,7 @@
</ClInclude>
<ClInclude Include="..\..\..\src\VHACD_Lib\inc\vhacdMutex.h">
</ClInclude>
<ClInclude Include="..\..\..\src\VHACD_Lib\inc\vhacdNearestPoint.h">
<ClInclude Include="..\..\..\src\VHACD_Lib\inc\vhacdRaycastMesh.h">
</ClInclude>
<ClInclude Include="..\..\..\src\VHACD_Lib\inc\vhacdSArray.h">
</ClInclude>
Expand All @@ -179,8 +177,6 @@
</ClCompile>
<ClCompile Include="..\..\..\src\VHACD_Lib\src\btConvexHullComputer.cpp">
</ClCompile>
<ClCompile Include="..\..\..\src\VHACD_Lib\src\RaycastMesh.cpp">
</ClCompile>
<ClCompile Include="..\..\..\src\VHACD_Lib\src\VHACD-ASYNC.cpp">
</ClCompile>
<ClCompile Include="..\..\..\src\VHACD_Lib\src\VHACD.cpp">
Expand All @@ -191,7 +187,7 @@
</ClCompile>
<ClCompile Include="..\..\..\src\VHACD_Lib\src\vhacdMesh.cpp">
</ClCompile>
<ClCompile Include="..\..\..\src\VHACD_Lib\src\vhacdNearestPoint.cpp">
<ClCompile Include="..\..\..\src\VHACD_Lib\src\vhacdRaycastMesh.cpp">
</ClCompile>
<ClCompile Include="..\..\..\src\VHACD_Lib\src\vhacdVolume.cpp">
</ClCompile>
Expand Down
10 changes: 2 additions & 8 deletions DebugView/compiler/vc14win32/ConvexDecomposition.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,6 @@
<ClInclude Include="..\..\..\src\VHACD_Lib\inc\btVector3.h">
<Filter>VHADC_lib\inc</Filter>
</ClInclude>
<ClInclude Include="..\..\..\src\VHACD_Lib\inc\RaycastMesh.h">
<Filter>VHADC_lib\inc</Filter>
</ClInclude>
<ClInclude Include="..\..\..\src\VHACD_Lib\inc\vhacdCircularList.h">
<Filter>VHADC_lib\inc</Filter>
</ClInclude>
Expand All @@ -87,7 +84,7 @@
<ClInclude Include="..\..\..\src\VHACD_Lib\inc\vhacdMutex.h">
<Filter>VHADC_lib\inc</Filter>
</ClInclude>
<ClInclude Include="..\..\..\src\VHACD_Lib\inc\vhacdNearestPoint.h">
<ClInclude Include="..\..\..\src\VHACD_Lib\inc\vhacdRaycastMesh.h">
<Filter>VHADC_lib\inc</Filter>
</ClInclude>
<ClInclude Include="..\..\..\src\VHACD_Lib\inc\vhacdSArray.h">
Expand Down Expand Up @@ -126,9 +123,6 @@
<ClCompile Include="..\..\..\src\VHACD_Lib\src\btConvexHullComputer.cpp">
<Filter>VHADC_lib\src</Filter>
</ClCompile>
<ClCompile Include="..\..\..\src\VHACD_Lib\src\RaycastMesh.cpp">
<Filter>VHADC_lib\src</Filter>
</ClCompile>
<ClCompile Include="..\..\..\src\VHACD_Lib\src\VHACD-ASYNC.cpp">
<Filter>VHADC_lib\src</Filter>
</ClCompile>
Expand All @@ -144,7 +138,7 @@
<ClCompile Include="..\..\..\src\VHACD_Lib\src\vhacdMesh.cpp">
<Filter>VHADC_lib\src</Filter>
</ClCompile>
<ClCompile Include="..\..\..\src\VHACD_Lib\src\vhacdNearestPoint.cpp">
<ClCompile Include="..\..\..\src\VHACD_Lib\src\vhacdRaycastMesh.cpp">
<Filter>VHADC_lib\src</Filter>
</ClCompile>
<ClCompile Include="..\..\..\src\VHACD_Lib\src\vhacdVolume.cpp">
Expand Down
8 changes: 2 additions & 6 deletions DebugView/compiler/vc14win64/ConvexDecomposition.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,6 @@
</ClInclude>
<ClInclude Include="..\..\..\src\VHACD_Lib\inc\btVector3.h">
</ClInclude>
<ClInclude Include="..\..\..\src\VHACD_Lib\inc\RaycastMesh.h">
</ClInclude>
<ClInclude Include="..\..\..\src\VHACD_Lib\inc\vhacdCircularList.h">
</ClInclude>
<ClInclude Include="..\..\..\src\VHACD_Lib\inc\vhacdICHull.h">
Expand All @@ -157,7 +155,7 @@
</ClInclude>
<ClInclude Include="..\..\..\src\VHACD_Lib\inc\vhacdMutex.h">
</ClInclude>
<ClInclude Include="..\..\..\src\VHACD_Lib\inc\vhacdNearestPoint.h">
<ClInclude Include="..\..\..\src\VHACD_Lib\inc\vhacdRaycastMesh.h">
</ClInclude>
<ClInclude Include="..\..\..\src\VHACD_Lib\inc\vhacdSArray.h">
</ClInclude>
Expand All @@ -179,8 +177,6 @@
</ClCompile>
<ClCompile Include="..\..\..\src\VHACD_Lib\src\btConvexHullComputer.cpp">
</ClCompile>
<ClCompile Include="..\..\..\src\VHACD_Lib\src\RaycastMesh.cpp">
</ClCompile>
<ClCompile Include="..\..\..\src\VHACD_Lib\src\VHACD-ASYNC.cpp">
</ClCompile>
<ClCompile Include="..\..\..\src\VHACD_Lib\src\VHACD.cpp">
Expand All @@ -191,7 +187,7 @@
</ClCompile>
<ClCompile Include="..\..\..\src\VHACD_Lib\src\vhacdMesh.cpp">
</ClCompile>
<ClCompile Include="..\..\..\src\VHACD_Lib\src\vhacdNearestPoint.cpp">
<ClCompile Include="..\..\..\src\VHACD_Lib\src\vhacdRaycastMesh.cpp">
</ClCompile>
<ClCompile Include="..\..\..\src\VHACD_Lib\src\vhacdVolume.cpp">
</ClCompile>
Expand Down
10 changes: 2 additions & 8 deletions DebugView/compiler/vc14win64/ConvexDecomposition.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,6 @@
<ClInclude Include="..\..\..\src\VHACD_Lib\inc\btVector3.h">
<Filter>VHADC_lib\inc</Filter>
</ClInclude>
<ClInclude Include="..\..\..\src\VHACD_Lib\inc\RaycastMesh.h">
<Filter>VHADC_lib\inc</Filter>
</ClInclude>
<ClInclude Include="..\..\..\src\VHACD_Lib\inc\vhacdCircularList.h">
<Filter>VHADC_lib\inc</Filter>
</ClInclude>
Expand All @@ -87,7 +84,7 @@
<ClInclude Include="..\..\..\src\VHACD_Lib\inc\vhacdMutex.h">
<Filter>VHADC_lib\inc</Filter>
</ClInclude>
<ClInclude Include="..\..\..\src\VHACD_Lib\inc\vhacdNearestPoint.h">
<ClInclude Include="..\..\..\src\VHACD_Lib\inc\vhacdRaycastMesh.h">
<Filter>VHADC_lib\inc</Filter>
</ClInclude>
<ClInclude Include="..\..\..\src\VHACD_Lib\inc\vhacdSArray.h">
Expand Down Expand Up @@ -126,9 +123,6 @@
<ClCompile Include="..\..\..\src\VHACD_Lib\src\btConvexHullComputer.cpp">
<Filter>VHADC_lib\src</Filter>
</ClCompile>
<ClCompile Include="..\..\..\src\VHACD_Lib\src\RaycastMesh.cpp">
<Filter>VHADC_lib\src</Filter>
</ClCompile>
<ClCompile Include="..\..\..\src\VHACD_Lib\src\VHACD-ASYNC.cpp">
<Filter>VHADC_lib\src</Filter>
</ClCompile>
Expand All @@ -144,7 +138,7 @@
<ClCompile Include="..\..\..\src\VHACD_Lib\src\vhacdMesh.cpp">
<Filter>VHADC_lib\src</Filter>
</ClCompile>
<ClCompile Include="..\..\..\src\VHACD_Lib\src\vhacdNearestPoint.cpp">
<ClCompile Include="..\..\..\src\VHACD_Lib\src\vhacdRaycastMesh.cpp">
<Filter>VHADC_lib\src</Filter>
</ClCompile>
<ClCompile Include="..\..\..\src\VHACD_Lib\src\vhacdVolume.cpp">
Expand Down
10 changes: 8 additions & 2 deletions DebugView/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,8 @@ void createMenus(void)
gRenderDebug->sendRemoteCommand("BeginGroup \"V-HACD Settings2\""); // Mark the beginning of a group of controls.
gRenderDebug->sendRemoteCommand("Slider Alpha 0.0005 0 0.1 Alpha");
gRenderDebug->sendRemoteCommand("Slider Beta 0.05 0 0.1 Beta");
//gRenderDebug->sendRemoteCommand("SliderInt Resolution 100000 10000 1000000 Resolution");
gRenderDebug->sendRemoteCommand("SliderInt Resolution 100000 10000 64000000 Resolution");
gRenderDebug->sendRemoteCommand("CheckBox ProjectHullVertices true ProjectHullVertices");
gRenderDebug->sendRemoteCommand("SliderInt Resolution 100000 10000 1000000 Resolution");
gRenderDebug->sendRemoteCommand("EndGroup"); // End the group called 'HACD settings'


Expand Down Expand Up @@ -425,6 +425,12 @@ int main(int argc,const char **argv)
gDesc.m_beta = (float)atof(value);
printf("Beta=%0.5f\n", gDesc.m_beta);
}
else if (strcmp(cmd, "ProjectHullVertices") == 0 && argc == 2)
{
const char *value = argv[1];
gDesc.m_projectHullVertices = strcmp(value, "true") == 0;
printf("ProjectHullVertices=%s\n", gDesc.m_projectHullVertices ? "true" : "false");
}
else if (strcmp(cmd, "Resolution") == 0 && argc == 2)
{
const char *value = argv[1];
Expand Down
40 changes: 0 additions & 40 deletions src/VHACD_Lib/inc/RaycastMesh.h

This file was deleted.

35 changes: 0 additions & 35 deletions src/VHACD_Lib/inc/vhacdNearestPoint.h

This file was deleted.

43 changes: 43 additions & 0 deletions src/VHACD_Lib/inc/vhacdRaycastMesh.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#ifndef RAYCAST_MESH_H

#define RAYCAST_MESH_H

#include <stdint.h>

namespace VHACD
{

// Very simple brute force raycast against a triangle mesh. Tests every triangle; no hierachy.
// Does a deep copy, always does calculations with full double float precision
class RaycastMesh
{
public:
static RaycastMesh * createRaycastMesh(uint32_t vcount, // The number of vertices in the source triangle mesh
uint32_t vertexStride,
const double *vertices, // The array of vertex positions in the format x1,y1,z1..x2,y2,z2.. etc.
uint32_t tcount, // The number of triangles in the source triangle mesh
uint32_t triangleStride,
const uint32_t *indices); // The triangle indices in the format of i1,i2,i3 ... i4,i5,i6, ...

static RaycastMesh * createRaycastMesh(uint32_t vcount, // The number of vertices in the source triangle mesh
uint32_t vertexStride,
const float *vertices, // The array of vertex positions in the format x1,y1,z1..x2,y2,z2.. etc.
uint32_t tcount, // The number of triangles in the source triangle mesh
uint32_t triangleStride,
const uint32_t *indices); // The triangle indices in the format of i1,i2,i3 ... i4,i5,i6, ...


virtual bool raycast(const double *from, // The starting point of the raycast
const double *to, // The ending point of the raycast
const double *closestToPoint, // The point to match the nearest hit location (can just be the 'from' location of no specific point)
double *hitLocation, // The point where the ray hit nearest to the 'closestToPoint' location
double *hitDistance) = 0; // The distance the ray traveled to the hit location

virtual void release(void) = 0;
protected:
virtual ~RaycastMesh(void) { };
};

} // end of VHACD namespace

#endif
2 changes: 1 addition & 1 deletion src/VHACD_Lib/inc/vhacdVHACD.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND

#include "vhacdMutex.h"
#include "vhacdVolume.h"
#include "RaycastMesh.h"
#include "vhacdRaycastMesh.h"

#define USE_THREAD 1
#define OCL_MIN_NUM_PRIMITIVES 4096
Expand Down
5 changes: 5 additions & 0 deletions src/VHACD_Lib/inc/vhacdVector.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,11 @@ class Vec3 {
return dx*dx + dy*dy + dz*dz;
}

T GetDistance(const Vec3 &p) const
{
return sqrt(GetDistanceSquared(p));
}

// Returns the raw vector data as a pointer
T* GetData(void)
{
Expand Down
13 changes: 9 additions & 4 deletions src/VHACD_Lib/src/VHACD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1402,6 +1402,8 @@ void VHACD::SimplifyConvexHull(Mesh* const ch, const size_t nvertices, const dou
// We project these points onto the original source mesh to increase precision
// The voxelization process drops floating point precision so returned data points are not exactly lying on the
// surface of the original source mesh.
// The first step is we need to compute the bounding box of the mesh we are trying to build a convex hull for.
// From this bounding box, we compute the length of the diagonal to get a relative size and center for point projection
uint32_t nPoints = ch->GetNPoints();
Vec3<double> *inputPoints = ch->GetPointsBuffer();
Vec3<double> bmin(inputPoints[0]);
Expand All @@ -1412,12 +1414,14 @@ void VHACD::SimplifyConvexHull(Mesh* const ch, const size_t nvertices, const dou
p.UpdateMinMax(bmin, bmax);
}
Vec3<double> center;
double diagonalLength = center.GetCenter(bmin, bmax);
// We do *not* want to produce convex hulls with thin slivers
// The threshold distance for combining two points is 1/100th the diagonal length of the bounding box
double diagonalLength = center.GetCenter(bmin, bmax); // Get the center of the bounding box
// This is the error threshold for determining if we should use the raycast result data point vs. the voxelized result.
double pointDistanceThreshold = diagonalLength * 0.01;
double snapDistanceThreshold = diagonalLength * 0.05;
// If a new point is within 1/100th the diagonal length of the bounding volume we do not add it. To do so would create a
// thin sliver in the resulting convex hull
double snapDistanceThreshold = diagonalLength * 0.01;
double snapDistanceThresholdSquared = snapDistanceThreshold*snapDistanceThreshold;

// Allocate buffer for projected vertices
Vec3<double> *outputPoints = new Vec3<double>[nPoints];
uint32_t outCount = 0;
Expand Down Expand Up @@ -1464,6 +1468,7 @@ void VHACD::SimplifyConvexHull(Mesh* const ch, const size_t nvertices, const dou
}
}
icHull.AddPoints(outputPoints, outCount);
delete[]outputPoints;
}
else
{
Expand Down
Loading

0 comments on commit dd20bd4

Please sign in to comment.