mirror of
https://github.com/Armored-Dragon/overte.git
synced 2025-03-11 16:13:16 +01:00
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:
parent
05cb0b830c
commit
5cc12b8b47
3 changed files with 36 additions and 17 deletions
|
@ -54,9 +54,24 @@ bool vhacd::VHACDUtil::loadFBX(const QString filename, vhacd::LoadFBXResults *re
|
|||
|
||||
//get the triangle indices for each mesh
|
||||
QVector<int> triangles;
|
||||
foreach(FBXMeshPart part, mesh.parts){
|
||||
QVector<int> indices = part.triangleIndices;
|
||||
foreach(FBXMeshPart meshPart, mesh.parts){
|
||||
QVector<int> indices = meshPart.triangleIndices;
|
||||
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
|
||||
|
@ -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,
|
||||
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);
|
||||
|
||||
// vhacd::LoadFBXResults *meshes = new vhacd::LoadFBXResults;
|
||||
// fattenMeshes(inMeshes, meshes);
|
||||
|
||||
if (fattenFaces) {
|
||||
fattenMeshes(inMeshes, meshes);
|
||||
} else {
|
||||
meshes = inMeshes;
|
||||
}
|
||||
|
||||
|
||||
VHACD::IVHACD * interfaceVHACD = VHACD::CreateVHACD();
|
||||
int meshCount = meshes->meshCount;
|
||||
int count = 0;
|
||||
std::cout << "Performing V-HACD computation on " << meshCount << " meshes ..... " << std::endl;
|
||||
|
||||
if (startMeshIndex < 0) {
|
||||
startMeshIndex = 0;
|
||||
|
@ -171,6 +191,8 @@ bool vhacd::VHACDUtil::computeVHACD(vhacd::LoadFBXResults *meshes, VHACD::IVHACD
|
|||
endMeshIndex = meshCount;
|
||||
}
|
||||
|
||||
std::cout << "Performing V-HACD computation on " << endMeshIndex - startMeshIndex << " meshes ..... " << std::endl;
|
||||
|
||||
for (int i = startMeshIndex; i < endMeshIndex; i++){
|
||||
qDebug() << "--------------------";
|
||||
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;
|
||||
|
||||
|
||||
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));
|
||||
for (unsigned int i=0; i<hull.m_nTriangles * 3; i++) {
|
||||
|
|
|
@ -43,7 +43,8 @@ namespace vhacd {
|
|||
void combineMeshes(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,
|
||||
vhacd::ComputeResults *results, int startMeshIndex, int endMeshIndex, float minimumMeshSize) const;
|
||||
vhacd::ComputeResults *results, int startMeshIndex, int endMeshIndex, float minimumMeshSize,
|
||||
bool fattenFaces) const;
|
||||
~VHACDUtil();
|
||||
};
|
||||
|
||||
|
|
|
@ -92,6 +92,9 @@ VHACDUtilApp::VHACDUtilApp(int argc, char* argv[]) :
|
|||
const QCommandLineOption outputOneMeshOption("1", "output hulls as single mesh");
|
||||
parser.addOption(outputOneMeshOption);
|
||||
|
||||
const QCommandLineOption fattenFacesOption("f", "fatten faces");
|
||||
parser.addOption(fattenFacesOption);
|
||||
|
||||
const QCommandLineOption inputFilenameOption("i", "input file", "filename.fbx");
|
||||
parser.addOption(inputFilenameOption);
|
||||
|
||||
|
@ -119,17 +122,15 @@ VHACDUtilApp::VHACDUtilApp(int argc, char* argv[]) :
|
|||
Q_UNREACHABLE();
|
||||
}
|
||||
|
||||
|
||||
bool fattenFaces = parser.isSet(fattenFacesOption);
|
||||
bool outputOneMesh = parser.isSet(outputOneMeshOption);
|
||||
|
||||
QString inputFilename;
|
||||
// check for an assignment pool passed on the command line or in the config
|
||||
if (parser.isSet(inputFilenameOption)) {
|
||||
inputFilename = parser.value(inputFilenameOption);
|
||||
}
|
||||
|
||||
QString outputFilename;
|
||||
// check for an assignment pool passed on the command line or in the config
|
||||
if (parser.isSet(outputFilenameOption)) {
|
||||
outputFilename = parser.value(outputFilenameOption);
|
||||
}
|
||||
|
@ -148,19 +149,16 @@ VHACDUtilApp::VHACDUtilApp(int argc, char* argv[]) :
|
|||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
@ -198,8 +196,7 @@ VHACDUtilApp::VHACDUtilApp(int argc, char* argv[]) :
|
|||
//perform vhacd computation
|
||||
begin = std::chrono::high_resolution_clock::now();
|
||||
|
||||
|
||||
if (!vUtil.computeVHACD(&fbx, params, &results, startMeshIndex, endMeshIndex, minimumMeshSize)) {
|
||||
if (!vUtil.computeVHACD(&fbx, params, &results, startMeshIndex, endMeshIndex, minimumMeshSize, fattenFaces)) {
|
||||
cout << "Compute Failed...";
|
||||
}
|
||||
end = std::chrono::high_resolution_clock::now();
|
||||
|
|
Loading…
Reference in a new issue