added more options to v-hacd util, messed with fatten-mesh code some more

This commit is contained in:
Seth Alves 2015-04-01 09:19:34 -07:00
parent 0f967f5971
commit 23903570f0
2 changed files with 55 additions and 14 deletions

View file

@ -38,6 +38,15 @@ bool vhacd::VHACDUtil::loadFBX(const QString filename, vhacd::LoadFBXResults *re
}
std::cout << "-------------------\n";
foreach (const FBXMesh& mesh, geometry.meshes) {
foreach (const FBXMeshPart &meshPart, mesh.parts) {
std::cout << meshPart.triangleIndices.size() << " ";
}
}
std::cout << "\n";
//results->meshCount = geometry.meshes.count();
// qDebug() << "read in" << geometry.meshes.count() << "meshes";
@ -52,7 +61,7 @@ bool vhacd::VHACDUtil::loadFBX(const QString filename, vhacd::LoadFBXResults *re
vertices.append(glm::vec3(mesh.modelTransform * glm::vec4(vertex, 1.0f)));
}
//get the triangle indices for each mesh
// get the triangle indices for each mesh
QVector<int> triangles;
foreach(FBXMeshPart meshPart, mesh.parts){
QVector<int> indices = meshPart.triangleIndices;
@ -60,10 +69,10 @@ bool vhacd::VHACDUtil::loadFBX(const QString filename, vhacd::LoadFBXResults *re
unsigned int quadCount = meshPart.quadIndices.size() / 4;
for (unsigned int i = 0; i < quadCount; i++) {
unsigned int p0Index = meshPart.quadIndices[i*4];
unsigned int p1Index = meshPart.quadIndices[i*4+1];
unsigned int p2Index = meshPart.quadIndices[i*4+2];
unsigned int p3Index = meshPart.quadIndices[i*4+3];
unsigned int p0Index = meshPart.quadIndices[i * 4];
unsigned int p1Index = meshPart.quadIndices[i * 4 + 1];
unsigned int p2Index = meshPart.quadIndices[i * 4 + 2];
unsigned int p3Index = meshPart.quadIndices[i * 4 + 3];
// split each quad into two triangles
triangles.append(p0Index);
triangles.append(p1Index);
@ -74,7 +83,7 @@ bool vhacd::VHACDUtil::loadFBX(const QString filename, vhacd::LoadFBXResults *re
}
}
//only read meshes with triangles
// only read meshes with triangles
if (triangles.count() <= 0){
continue;
}
@ -146,15 +155,16 @@ void vhacd::VHACDUtil::fattenMeshes(vhacd::LoadFBXResults *meshes, vhacd::LoadFB
auto d1 = p2 - p0;
auto cp = glm::cross(d0, d1);
cp = 5.0f * glm::normalize(cp);
cp = -2.0f * glm::normalize(cp);
auto p3 = p0 + cp;
auto p4 = p1 + cp;
auto p5 = p2 + cp;
auto n = results->perMeshVertices.size();
results->perMeshVertices[i] << p3 << p4 << p5;
results->perMeshTriangleIndices[i] << n << n+1 << n+2;
results->perMeshVertices[i] << p3;
results->perMeshTriangleIndices[i] << triangles[j] << n << triangles[j + 1];
results->perMeshTriangleIndices[i] << triangles[j + 1] << n << triangles[j + 2];
results->perMeshTriangleIndices[i] << triangles[j + 2] << n << triangles[j];
}
results->meshCount++;
@ -191,6 +201,12 @@ bool vhacd::VHACDUtil::computeVHACD(vhacd::LoadFBXResults *inMeshes, VHACD::IVHA
endMeshIndex = meshCount;
}
for (int i = 0; i < meshCount; i++) {
std::cout << meshes->perMeshTriangleIndices.at(i).size() << " ";
}
std::cout << "\n";
std::cout << "Performing V-HACD computation on " << endMeshIndex - startMeshIndex << " meshes ..... " << std::endl;
for (int i = startMeshIndex; i < endMeshIndex; i++){

View file

@ -110,6 +110,15 @@ VHACDUtilApp::VHACDUtilApp(int argc, char* argv[]) :
const QCommandLineOption minimumMeshSizeOption("m", "minimum mesh size to consider", "0");
parser.addOption(minimumMeshSizeOption);
const QCommandLineOption vHacdResolutionOption("resolution", "v-hacd resolution", "100000");
parser.addOption(vHacdResolutionOption);
const QCommandLineOption vHacdDepthOption("depth", "v-hacd depth", "20");
parser.addOption(vHacdDepthOption);
const QCommandLineOption vHacdDeltaOption("delta", "v-hacd delta", "0.05");
parser.addOption(vHacdDeltaOption);
if (!parser.parse(QCoreApplication::arguments())) {
qCritical() << parser.errorText() << endl;
@ -163,13 +172,29 @@ VHACDUtilApp::VHACDUtilApp(int argc, char* argv[]) :
minimumMeshSize = parser.value(minimumMeshSizeOption).toFloat();
}
int vHacdResolution = 100000;
if (parser.isSet(vHacdResolutionOption)) {
vHacdResolution = parser.value(vHacdResolutionOption).toInt();
}
int vHacdDepth = 20;
if (parser.isSet(vHacdDepthOption)) {
vHacdDepth = parser.value(vHacdDepthOption).toInt();
}
float vHacdDelta = 0.05;
if (parser.isSet(vHacdDeltaOption)) {
vHacdDelta = parser.value(vHacdDeltaOption).toFloat();
}
//set parameters for V-HACD
params.m_callback = &pCallBack; //progress callback
params.m_resolution = 100000; // 100000
params.m_depth = 20; // 20
params.m_resolution = vHacdResolution; // 100000
params.m_depth = vHacdDepth; // 20
params.m_concavity = 0.001; // 0.001
params.m_delta = 0.05; // 0.05
params.m_delta = vHacdDelta; // 0.05
params.m_planeDownsampling = 4; // 4
params.m_convexhullDownsampling = 4; // 4
params.m_alpha = 0.05; // 0.05 // controls the bias toward clipping along symmetry planes