allow for quads in the model which is being used as the template for generating the collision shape. added a flag to run the fatten-face code

This commit is contained in:
Seth Alves 2015-03-31 17:00:36 -07:00
parent 05cb0b830c
commit 5cc12b8b47
3 changed files with 36 additions and 17 deletions

View file

@ -54,9 +54,24 @@ bool vhacd::VHACDUtil::loadFBX(const QString filename, vhacd::LoadFBXResults *re
//get the triangle indices for each mesh //get the triangle indices for each mesh
QVector<int> triangles; QVector<int> triangles;
foreach(FBXMeshPart part, mesh.parts){ foreach(FBXMeshPart meshPart, mesh.parts){
QVector<int> indices = part.triangleIndices; QVector<int> indices = meshPart.triangleIndices;
triangles += indices; triangles += indices;
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];
// split each quad into two triangles
triangles.append(p0Index);
triangles.append(p1Index);
triangles.append(p2Index);
triangles.append(p0Index);
triangles.append(p2Index);
triangles.append(p3Index);
}
} }
//only read meshes with triangles //only read meshes with triangles
@ -148,21 +163,26 @@ void vhacd::VHACDUtil::fattenMeshes(vhacd::LoadFBXResults *meshes, vhacd::LoadFB
bool vhacd::VHACDUtil::computeVHACD(vhacd::LoadFBXResults *meshes, VHACD::IVHACD::Parameters params, bool vhacd::VHACDUtil::computeVHACD(vhacd::LoadFBXResults *inMeshes, VHACD::IVHACD::Parameters params,
vhacd::ComputeResults *results, vhacd::ComputeResults *results,
int startMeshIndex, int endMeshIndex, float minimumMeshSize) const { int startMeshIndex, int endMeshIndex, float minimumMeshSize,
bool fattenFaces) const {
// vhacd::LoadFBXResults *meshes = new vhacd::LoadFBXResults; vhacd::LoadFBXResults *meshes = new vhacd::LoadFBXResults;
// combineMeshes(inMeshes, meshes); // combineMeshes(inMeshes, meshes);
// vhacd::LoadFBXResults *meshes = new vhacd::LoadFBXResults; // vhacd::LoadFBXResults *meshes = new vhacd::LoadFBXResults;
// fattenMeshes(inMeshes, meshes);
if (fattenFaces) {
fattenMeshes(inMeshes, meshes);
} else {
meshes = inMeshes;
}
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;
if (startMeshIndex < 0) { if (startMeshIndex < 0) {
startMeshIndex = 0; startMeshIndex = 0;
@ -171,6 +191,8 @@ bool vhacd::VHACDUtil::computeVHACD(vhacd::LoadFBXResults *meshes, VHACD::IVHACD
endMeshIndex = meshCount; endMeshIndex = meshCount;
} }
std::cout << "Performing V-HACD computation on " << endMeshIndex - startMeshIndex << " meshes ..... " << std::endl;
for (int i = startMeshIndex; i < endMeshIndex; i++){ for (int i = startMeshIndex; i < endMeshIndex; i++){
qDebug() << "--------------------"; qDebug() << "--------------------";
std::vector<glm::vec3> vertices = meshes->perMeshVertices.at(i).toStdVector(); std::vector<glm::vec3> vertices = meshes->perMeshVertices.at(i).toStdVector();
@ -211,7 +233,6 @@ bool vhacd::VHACDUtil::computeVHACD(vhacd::LoadFBXResults *meshes, VHACD::IVHACD
} }
hull.m_points = m_points_copy; hull.m_points = m_points_copy;
int *m_triangles_copy = new int[hull.m_nTriangles * 3]; int *m_triangles_copy = new int[hull.m_nTriangles * 3];
// std::copy(std::begin(hull.m_triangles), std::end(hull.m_triangles), std::begin(m_triangles_copy)); // std::copy(std::begin(hull.m_triangles), std::end(hull.m_triangles), std::begin(m_triangles_copy));
for (unsigned int i=0; i<hull.m_nTriangles * 3; i++) { for (unsigned int i=0; i<hull.m_nTriangles * 3; i++) {

View file

@ -43,7 +43,8 @@ namespace vhacd {
void combineMeshes(vhacd::LoadFBXResults *meshes, vhacd::LoadFBXResults *results) const; void combineMeshes(vhacd::LoadFBXResults *meshes, vhacd::LoadFBXResults *results) const;
void fattenMeshes(vhacd::LoadFBXResults *meshes, vhacd::LoadFBXResults *results) const; void fattenMeshes(vhacd::LoadFBXResults *meshes, vhacd::LoadFBXResults *results) const;
bool computeVHACD(vhacd::LoadFBXResults *meshes, VHACD::IVHACD::Parameters params, bool computeVHACD(vhacd::LoadFBXResults *meshes, VHACD::IVHACD::Parameters params,
vhacd::ComputeResults *results, int startMeshIndex, int endMeshIndex, float minimumMeshSize) const; vhacd::ComputeResults *results, int startMeshIndex, int endMeshIndex, float minimumMeshSize,
bool fattenFaces) const;
~VHACDUtil(); ~VHACDUtil();
}; };

View file

@ -92,6 +92,9 @@ VHACDUtilApp::VHACDUtilApp(int argc, char* argv[]) :
const QCommandLineOption outputOneMeshOption("1", "output hulls as single mesh"); const QCommandLineOption outputOneMeshOption("1", "output hulls as single mesh");
parser.addOption(outputOneMeshOption); parser.addOption(outputOneMeshOption);
const QCommandLineOption fattenFacesOption("f", "fatten faces");
parser.addOption(fattenFacesOption);
const QCommandLineOption inputFilenameOption("i", "input file", "filename.fbx"); const QCommandLineOption inputFilenameOption("i", "input file", "filename.fbx");
parser.addOption(inputFilenameOption); parser.addOption(inputFilenameOption);
@ -119,17 +122,15 @@ VHACDUtilApp::VHACDUtilApp(int argc, char* argv[]) :
Q_UNREACHABLE(); Q_UNREACHABLE();
} }
bool fattenFaces = parser.isSet(fattenFacesOption);
bool outputOneMesh = parser.isSet(outputOneMeshOption); bool outputOneMesh = parser.isSet(outputOneMeshOption);
QString inputFilename; QString inputFilename;
// check for an assignment pool passed on the command line or in the config
if (parser.isSet(inputFilenameOption)) { if (parser.isSet(inputFilenameOption)) {
inputFilename = parser.value(inputFilenameOption); inputFilename = parser.value(inputFilenameOption);
} }
QString outputFilename; QString outputFilename;
// check for an assignment pool passed on the command line or in the config
if (parser.isSet(outputFilenameOption)) { if (parser.isSet(outputFilenameOption)) {
outputFilename = parser.value(outputFilenameOption); outputFilename = parser.value(outputFilenameOption);
} }
@ -148,19 +149,16 @@ VHACDUtilApp::VHACDUtilApp(int argc, char* argv[]) :
} }
int startMeshIndex = -1; int startMeshIndex = -1;
// check for an assignment pool passed on the command line or in the config
if (parser.isSet(startMeshIndexOption)) { if (parser.isSet(startMeshIndexOption)) {
startMeshIndex = parser.value(startMeshIndexOption).toInt(); startMeshIndex = parser.value(startMeshIndexOption).toInt();
} }
int endMeshIndex = -1; int endMeshIndex = -1;
// check for an assignment pool passed on the command line or in the config
if (parser.isSet(endMeshIndexOption)) { if (parser.isSet(endMeshIndexOption)) {
endMeshIndex = parser.value(endMeshIndexOption).toInt(); endMeshIndex = parser.value(endMeshIndexOption).toInt();
} }
float minimumMeshSize = 0.0f; float minimumMeshSize = 0.0f;
// check for an assignment pool passed on the command line or in the config
if (parser.isSet(minimumMeshSizeOption)) { if (parser.isSet(minimumMeshSizeOption)) {
minimumMeshSize = parser.value(minimumMeshSizeOption).toFloat(); minimumMeshSize = parser.value(minimumMeshSizeOption).toFloat();
} }
@ -198,8 +196,7 @@ VHACDUtilApp::VHACDUtilApp(int argc, char* argv[]) :
//perform vhacd computation //perform vhacd computation
begin = std::chrono::high_resolution_clock::now(); begin = std::chrono::high_resolution_clock::now();
if (!vUtil.computeVHACD(&fbx, params, &results, startMeshIndex, endMeshIndex, minimumMeshSize, fattenFaces)) {
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();