added various controls for the convex hull generator

This commit is contained in:
Seth Alves 2015-03-25 15:13:40 -07:00
parent e6ac502fb5
commit c68f5dd1fa
5 changed files with 67 additions and 10 deletions

View file

@ -14,6 +14,7 @@
#define hifi_Extents_h #define hifi_Extents_h
#include <glm/glm.hpp> #include <glm/glm.hpp>
#include <glm/gtx/extented_min_max.hpp>
#include <QDebug> #include <QDebug>
#include "StreamUtils.h" #include "StreamUtils.h"
@ -46,6 +47,9 @@ public:
/// rotate the extents around orign by rotation /// rotate the extents around orign by rotation
void rotate(const glm::quat& rotation); void rotate(const glm::quat& rotation);
glm::vec3 size() const { return maximum - minimum; }
float largestDimension () const {glm::vec3 s = size(); return glm::max(s[0], s[1], s[2]); }
/// \return new Extents which is original rotated around orign by rotation /// \return new Extents which is original rotated around orign by rotation
Extents getRotated(const glm::quat& rotation) const { Extents getRotated(const glm::quat& rotation) const {
Extents temp = { minimum, maximum }; Extents temp = { minimum, maximum };
@ -68,4 +72,4 @@ inline QDebug operator<<(QDebug debug, const Extents& extents) {
} }
#endif // hifi_Extents_h #endif // hifi_Extents_h

View file

@ -8,5 +8,5 @@ set_target_properties(scribe PROPERTIES FOLDER "Tools")
find_package(VHACD) find_package(VHACD)
if(VHACD_FOUND) if(VHACD_FOUND)
add_subdirectory(vhacd) add_subdirectory(vhacd)
set_target_properties(vhacd PROPERTIES FOLDER "Tools") # set_target_properties(vhacd PROPERTIES FOLDER "Tools")
endif() endif()

View file

@ -57,8 +57,15 @@ bool vhacd::VHACDUtil::loadFBX(const QString filename, vhacd::LoadFBXResults *re
if (triangles.count() <= 0){ if (triangles.count() <= 0){
continue; continue;
} }
AABox aaBox;
foreach (glm::vec3 p, vertices) {
aaBox += p;
}
results->perMeshVertices.append(vertices); results->perMeshVertices.append(vertices);
results->perMeshTriangleIndices.append(triangles); results->perMeshTriangleIndices.append(triangles);
results->perMeshLargestDimension.append(aaBox.getLargestDimension());
count++; count++;
} }
@ -66,23 +73,40 @@ bool vhacd::VHACDUtil::loadFBX(const QString filename, vhacd::LoadFBXResults *re
return true; return true;
} }
bool vhacd::VHACDUtil::computeVHACD(vhacd::LoadFBXResults *meshes, VHACD::IVHACD::Parameters params, vhacd::ComputeResults *results)const{ bool vhacd::VHACDUtil::computeVHACD(vhacd::LoadFBXResults *meshes, VHACD::IVHACD::Parameters params,
vhacd::ComputeResults *results,
int startMeshIndex, int endMeshIndex, float minimumMeshSize) const {
VHACD::IVHACD * interfaceVHACD = VHACD::CreateVHACD(); VHACD::IVHACD * interfaceVHACD = VHACD::CreateVHACD();
int meshCount = meshes->meshCount; int meshCount = meshes->meshCount;
int count = 0; int count = 0;
std::cout << "Performing V-HACD computation on " << meshCount << " meshes ..... " << std::endl; std::cout << "Performing V-HACD computation on " << meshCount << " meshes ..... " << std::endl;
for (int i = 0; i < meshCount; i++){ if (startMeshIndex < 0) {
startMeshIndex = 0;
}
if (endMeshIndex < 0) {
endMeshIndex = meshCount;
}
for (int i = startMeshIndex; i < endMeshIndex; i++){
qDebug() << "--------------------";
std::vector<glm::vec3> vertices = meshes->perMeshVertices.at(i).toStdVector(); std::vector<glm::vec3> vertices = meshes->perMeshVertices.at(i).toStdVector();
std::vector<int> triangles = meshes->perMeshTriangleIndices.at(i).toStdVector(); std::vector<int> triangles = meshes->perMeshTriangleIndices.at(i).toStdVector();
int nPoints = (unsigned int)vertices.size(); int nPoints = (unsigned int)vertices.size();
int nTriangles = (unsigned int)triangles.size() / 3; int nTriangles = (unsigned int)triangles.size() / 3;
std::cout << "Mesh " << i + 1 << " : "; const float largestDimension = meshes->perMeshLargestDimension.at(i);
qDebug() << "Mesh " << i << " -- " << nPoints << " points, " << nTriangles << " triangles, "
<< "size =" << largestDimension;
if (largestDimension < minimumMeshSize || largestDimension > 1000) {
qDebug() << " Skipping...";
continue;
}
// compute approximate convex decomposition // compute approximate convex decomposition
bool res = interfaceVHACD->Compute(&vertices[0].x, 3, nPoints, &triangles[0], 3, nTriangles, params); bool res = interfaceVHACD->Compute(&vertices[0].x, 3, nPoints, &triangles[0], 3, nTriangles, params);
if (!res){ if (!res){
std::cout << "V-HACD computation failed for Mesh : " << i + 1 << std::endl; qDebug() << "V-HACD computation failed for Mesh : " << i;
continue; continue;
} }
count++; //For counting number of successfull computations count++; //For counting number of successfull computations

View file

@ -34,12 +34,14 @@ namespace vhacd {
int meshCount; int meshCount;
QVector<QVector<glm::vec3>> perMeshVertices; QVector<QVector<glm::vec3>> perMeshVertices;
QVector<QVector<int>> perMeshTriangleIndices; QVector<QVector<int>> perMeshTriangleIndices;
QVector<float> perMeshLargestDimension;
} LoadFBXResults; } LoadFBXResults;
class VHACDUtil { class VHACDUtil {
public: public:
bool loadFBX(const QString filename, vhacd::LoadFBXResults *results); bool loadFBX(const QString filename, vhacd::LoadFBXResults *results);
bool computeVHACD(vhacd::LoadFBXResults *meshes, VHACD::IVHACD::Parameters params, vhacd::ComputeResults *results)const; bool computeVHACD(vhacd::LoadFBXResults *meshes, VHACD::IVHACD::Parameters params,
vhacd::ComputeResults *results, int startMeshIndex, int endMeshIndex, float minimumMeshSize) const;
~VHACDUtil(); ~VHACDUtil();
}; };

View file

@ -98,6 +98,15 @@ VHACDUtilApp::VHACDUtilApp(int argc, char* argv[]) :
const QCommandLineOption outputFilenameOption("o", "output file", "filename.obj"); const QCommandLineOption outputFilenameOption("o", "output file", "filename.obj");
parser.addOption(outputFilenameOption); parser.addOption(outputFilenameOption);
const QCommandLineOption startMeshIndexOption("s", "start-mesh index", "0");
parser.addOption(startMeshIndexOption);
const QCommandLineOption endMeshIndexOption("e", "end-mesh index", "0");
parser.addOption(endMeshIndexOption);
const QCommandLineOption minimumMeshSizeOption("m", "minimum mesh size to consider", "0");
parser.addOption(minimumMeshSizeOption);
if (!parser.parse(QCoreApplication::arguments())) { if (!parser.parse(QCoreApplication::arguments())) {
qCritical() << parser.errorText() << endl; qCritical() << parser.errorText() << endl;
@ -138,13 +147,31 @@ VHACDUtilApp::VHACDUtilApp(int argc, char* argv[]) :
Q_UNREACHABLE(); Q_UNREACHABLE();
} }
int startMeshIndex = -1;
// check for an assignment pool passed on the command line or in the config
if (parser.isSet(startMeshIndexOption)) {
startMeshIndex = parser.value(startMeshIndexOption).toInt();
}
int endMeshIndex = -1;
// check for an assignment pool passed on the command line or in the config
if (parser.isSet(endMeshIndexOption)) {
endMeshIndex = parser.value(endMeshIndexOption).toInt();
}
float minimumMeshSize = 0.0f;
// check for an assignment pool passed on the command line or in the config
if (parser.isSet(minimumMeshSizeOption)) {
minimumMeshSize = parser.value(minimumMeshSizeOption).toFloat();
}
//set parameters for V-HACD //set parameters for V-HACD
params.m_callback = &pCallBack; //progress callback params.m_callback = &pCallBack; //progress callback
params.m_resolution = 100000; // 100000 params.m_resolution = 100000; // 100000
params.m_depth = 20; // 20 params.m_depth = 20; // 20
params.m_concavity = 0.001; // 0.001 params.m_concavity = 0.001; // 0.001
params.m_delta = 0.01; // 0.05 params.m_delta = 0.05; // 0.05
params.m_planeDownsampling = 4; // 4 params.m_planeDownsampling = 4; // 4
params.m_convexhullDownsampling = 4; // 4 params.m_convexhullDownsampling = 4; // 4
params.m_alpha = 0.05; // 0.05 // controls the bias toward clipping along symmetry planes params.m_alpha = 0.05; // 0.05 // controls the bias toward clipping along symmetry planes
@ -153,7 +180,7 @@ VHACDUtilApp::VHACDUtilApp(int argc, char* argv[]) :
params.m_pca = 0; // 0 enable/disable normalizing the mesh before applying the convex decomposition params.m_pca = 0; // 0 enable/disable normalizing the mesh before applying the convex decomposition
params.m_mode = 0; // 0: voxel-based (recommended), 1: tetrahedron-based params.m_mode = 0; // 0: voxel-based (recommended), 1: tetrahedron-based
params.m_maxNumVerticesPerCH = 64; // 64 params.m_maxNumVerticesPerCH = 64; // 64
params.m_minVolumePerCH = 0.00001; // 0.0001 params.m_minVolumePerCH = 0.0001; // 0.0001
params.m_callback = 0; // 0 params.m_callback = 0; // 0
params.m_logger = 0; // 0 params.m_logger = 0; // 0
params.m_convexhullApproximation = true; // true params.m_convexhullApproximation = true; // true
@ -172,7 +199,7 @@ VHACDUtilApp::VHACDUtilApp(int argc, char* argv[]) :
begin = std::chrono::high_resolution_clock::now(); begin = std::chrono::high_resolution_clock::now();
if (!vUtil.computeVHACD(&fbx, params, &results)){ if (!vUtil.computeVHACD(&fbx, params, &results, startMeshIndex, endMeshIndex, minimumMeshSize)) {
cout << "Compute Failed..."; cout << "Compute Failed...";
} }
end = std::chrono::high_resolution_clock::now(); end = std::chrono::high_resolution_clock::now();