mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-07-23 15:14:33 +02:00
cleanup vhacd-util logging and variable names
This commit is contained in:
parent
485c8aceac
commit
f8e2cf8064
3 changed files with 60 additions and 66 deletions
|
@ -33,7 +33,7 @@ bool vhacd::VHACDUtil::loadFBX(const QString filename, FBXGeometry& result) {
|
||||||
if (!fbx.open(QIODevice::ReadOnly)) {
|
if (!fbx.open(QIODevice::ReadOnly)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
std::cout << "Reading FBX.....\n";
|
qDebug() << "reading FBX file =" << filename << "...";
|
||||||
try {
|
try {
|
||||||
QByteArray fbxContents = fbx.readAll();
|
QByteArray fbxContents = fbx.readAll();
|
||||||
FBXGeometry* geom;
|
FBXGeometry* geom;
|
||||||
|
@ -182,31 +182,34 @@ AABox getAABoxForMeshPart(const FBXMesh& mesh, const FBXMeshPart &meshPart) {
|
||||||
bool vhacd::VHACDUtil::computeVHACD(FBXGeometry& geometry,
|
bool vhacd::VHACDUtil::computeVHACD(FBXGeometry& geometry,
|
||||||
VHACD::IVHACD::Parameters params,
|
VHACD::IVHACD::Parameters params,
|
||||||
FBXGeometry& result,
|
FBXGeometry& result,
|
||||||
int startMeshIndex,
|
int startPartIndex,
|
||||||
int endMeshIndex,
|
int endPartIndex,
|
||||||
float minimumMeshSize, float maximumMeshSize) {
|
float minimumMeshSize, float maximumMeshSize) {
|
||||||
|
qDebug() << "num meshes =" << geometry.meshes.size();
|
||||||
|
|
||||||
// count the mesh-parts
|
// count the mesh-parts
|
||||||
int meshCount = 0;
|
int numParts = 0;
|
||||||
foreach (const FBXMesh& mesh, geometry.meshes) {
|
foreach (const FBXMesh& mesh, geometry.meshes) {
|
||||||
meshCount += mesh.parts.size();
|
numParts += mesh.parts.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
VHACD::IVHACD * interfaceVHACD = VHACD::CreateVHACD();
|
VHACD::IVHACD * interfaceVHACD = VHACD::CreateVHACD();
|
||||||
|
|
||||||
if (startMeshIndex < 0) {
|
if (startPartIndex < 0) {
|
||||||
startMeshIndex = 0;
|
startPartIndex = 0;
|
||||||
}
|
}
|
||||||
if (endMeshIndex < 0) {
|
if (endPartIndex < 0) {
|
||||||
endMeshIndex = meshCount;
|
endPartIndex = numParts;
|
||||||
}
|
}
|
||||||
|
qDebug() << "num parts of interest =" << (endPartIndex - startPartIndex);
|
||||||
std::cout << "Performing V-HACD computation on " << endMeshIndex - startMeshIndex << " meshes ..... " << std::endl;
|
|
||||||
|
|
||||||
result.meshExtents.reset();
|
result.meshExtents.reset();
|
||||||
result.meshes.append(FBXMesh());
|
result.meshes.append(FBXMesh());
|
||||||
FBXMesh &resultMesh = result.meshes.last();
|
FBXMesh &resultMesh = result.meshes.last();
|
||||||
|
|
||||||
int count = 0;
|
int meshIndex = 0;
|
||||||
|
int partIndex = 0;
|
||||||
|
int validPartsFound = 0;
|
||||||
foreach (const FBXMesh& mesh, geometry.meshes) {
|
foreach (const FBXMesh& mesh, geometry.meshes) {
|
||||||
|
|
||||||
// each mesh has its own transform to move it to model-space
|
// each mesh has its own transform to move it to model-space
|
||||||
|
@ -214,51 +217,55 @@ bool vhacd::VHACDUtil::computeVHACD(FBXGeometry& geometry,
|
||||||
foreach (glm::vec3 vertex, mesh.vertices) {
|
foreach (glm::vec3 vertex, mesh.vertices) {
|
||||||
vertices.push_back(glm::vec3(mesh.modelTransform * glm::vec4(vertex, 1.0f)));
|
vertices.push_back(glm::vec3(mesh.modelTransform * glm::vec4(vertex, 1.0f)));
|
||||||
}
|
}
|
||||||
|
auto numVertices = vertices.size();
|
||||||
|
|
||||||
|
qDebug() << "mesh" << meshIndex << ": "
|
||||||
|
<< " parts =" << mesh.parts.size() << " clusters =" << mesh.clusters.size()
|
||||||
|
<< " vertices =" << numVertices;
|
||||||
|
++meshIndex;
|
||||||
|
|
||||||
foreach (const FBXMeshPart &meshPart, mesh.parts) {
|
foreach (const FBXMeshPart &meshPart, mesh.parts) {
|
||||||
|
if (partIndex < startPartIndex || partIndex >= endPartIndex) {
|
||||||
if (count < startMeshIndex || count >= endMeshIndex) {
|
++partIndex;
|
||||||
count ++;
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
qDebug() << "--------------------";
|
|
||||||
|
|
||||||
std::vector<int> triangles;
|
std::vector<int> triangles;
|
||||||
unsigned int triangleCount = getTrianglesInMeshPart(meshPart, triangles);
|
unsigned int triangleCount = getTrianglesInMeshPart(meshPart, triangles);
|
||||||
|
|
||||||
// only process meshes with triangles
|
// only process meshes with triangles
|
||||||
if (triangles.size() <= 0) {
|
if (triangles.size() <= 0) {
|
||||||
qDebug() << " Skipping (no triangles)...";
|
qDebug() << " part" << partIndex << ":";
|
||||||
count++;
|
qDebug() << " skip (zero triangles)";
|
||||||
|
++partIndex;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto nPoints = vertices.size();
|
|
||||||
AABox aaBox = getAABoxForMeshPart(mesh, meshPart);
|
AABox aaBox = getAABoxForMeshPart(mesh, meshPart);
|
||||||
const float largestDimension = aaBox.getLargestDimension();
|
const float largestDimension = aaBox.getLargestDimension();
|
||||||
|
|
||||||
qDebug() << "Mesh " << count << " -- " << nPoints << " points, " << triangleCount << " triangles, "
|
qDebug() << " part" << partIndex << ": "
|
||||||
<< "size =" << largestDimension;
|
<< " triangles =" << triangleCount
|
||||||
|
<< " largestDimension =" << largestDimension;
|
||||||
|
|
||||||
if (largestDimension < minimumMeshSize) {
|
if (largestDimension < minimumMeshSize) {
|
||||||
qDebug() << " Skipping (too small)...";
|
qDebug() << " skip (too small)";
|
||||||
count++;
|
++partIndex;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (maximumMeshSize > 0.0f && largestDimension > maximumMeshSize) {
|
if (maximumMeshSize > 0.0f && largestDimension > maximumMeshSize) {
|
||||||
qDebug() << " Skipping (too large)...";
|
qDebug() << " skip (too large)";
|
||||||
count++;
|
++partIndex;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// compute approximate convex decomposition
|
// compute approximate convex decomposition
|
||||||
bool res = interfaceVHACD->Compute(&vertices[0].x, 3, (uint)nPoints, &triangles[0], 3, triangleCount, params);
|
bool success = interfaceVHACD->Compute(&vertices[0].x, 3, (uint)numVertices, &triangles[0], 3, triangleCount, params);
|
||||||
if (!res){
|
if (!success){
|
||||||
qDebug() << "V-HACD computation failed for Mesh : " << count;
|
qDebug() << " failed to convexify";
|
||||||
count++;
|
++partIndex;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -290,8 +297,8 @@ bool vhacd::VHACDUtil::computeVHACD(FBXGeometry& geometry,
|
||||||
resultMeshPart.triangleIndices.append(index2);
|
resultMeshPart.triangleIndices.append(index2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
++partIndex;
|
||||||
count++;
|
++validPartsFound;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -299,12 +306,7 @@ bool vhacd::VHACDUtil::computeVHACD(FBXGeometry& geometry,
|
||||||
interfaceVHACD->Clean();
|
interfaceVHACD->Clean();
|
||||||
interfaceVHACD->Release();
|
interfaceVHACD->Release();
|
||||||
|
|
||||||
if (count > 0){
|
return validPartsFound > 0;
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
vhacd::VHACDUtil:: ~VHACDUtil(){
|
vhacd::VHACDUtil:: ~VHACDUtil(){
|
||||||
|
@ -319,16 +321,9 @@ void vhacd::ProgressCallback::Update(const double overallProgress,
|
||||||
const char* const operation) {
|
const char* const operation) {
|
||||||
int progress = (int)(overallProgress + 0.5);
|
int progress = (int)(overallProgress + 0.5);
|
||||||
|
|
||||||
if (progress < 10){
|
std::cout << "\b\b\b";
|
||||||
std::cout << "\b\b";
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
std::cout << "\b\b\b";
|
|
||||||
}
|
|
||||||
|
|
||||||
std::cout << progress << "%";
|
std::cout << progress << "%";
|
||||||
|
if (progress >= 100) {
|
||||||
if (progress >= 100){
|
|
||||||
std::cout << std::endl;
|
std::cout << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,7 +34,7 @@ namespace vhacd {
|
||||||
bool computeVHACD(FBXGeometry& geometry,
|
bool computeVHACD(FBXGeometry& geometry,
|
||||||
VHACD::IVHACD::Parameters params,
|
VHACD::IVHACD::Parameters params,
|
||||||
FBXGeometry& result,
|
FBXGeometry& result,
|
||||||
int startMeshIndex, int endMeshIndex,
|
int startPartIndex, int endPartIndex,
|
||||||
float minimumMeshSize, float maximumMeshSize);
|
float minimumMeshSize, float maximumMeshSize);
|
||||||
~VHACDUtil();
|
~VHACDUtil();
|
||||||
};
|
};
|
||||||
|
|
|
@ -301,17 +301,17 @@ VHACDUtilApp::VHACDUtilApp(int argc, char* argv[]) :
|
||||||
Q_UNREACHABLE();
|
Q_UNREACHABLE();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// load the mesh
|
// load the mesh
|
||||||
|
|
||||||
FBXGeometry fbx;
|
FBXGeometry fbx;
|
||||||
auto begin = std::chrono::high_resolution_clock::now();
|
auto begin = std::chrono::high_resolution_clock::now();
|
||||||
if (!vUtil.loadFBX(inputFilename, fbx)){
|
if (!vUtil.loadFBX(inputFilename, fbx)){
|
||||||
cout << "Error in opening FBX file....";
|
qDebug() << "error reading input file" << inputFilename;
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
auto end = std::chrono::high_resolution_clock::now();
|
auto end = std::chrono::high_resolution_clock::now();
|
||||||
auto loadDuration = std::chrono::duration_cast<std::chrono::nanoseconds>(end - begin).count();
|
auto loadDuration = std::chrono::duration_cast<std::chrono::nanoseconds>(end - begin).count();
|
||||||
|
|
||||||
|
qDebug() << "load time =" << (double)loadDuration / 1000000000.00 << "seconds";
|
||||||
|
|
||||||
if (splitModel) {
|
if (splitModel) {
|
||||||
QVector<QString> infileExtensions = {"fbx", "obj"};
|
QVector<QString> infileExtensions = {"fbx", "obj"};
|
||||||
|
@ -352,38 +352,37 @@ VHACDUtilApp::VHACDUtilApp(int argc, char* argv[]) :
|
||||||
params.m_oclAcceleration = true; // true
|
params.m_oclAcceleration = true; // true
|
||||||
|
|
||||||
//perform vhacd computation
|
//perform vhacd computation
|
||||||
|
qDebug() << "running V-HACD algorithm ...";
|
||||||
begin = std::chrono::high_resolution_clock::now();
|
begin = std::chrono::high_resolution_clock::now();
|
||||||
|
|
||||||
FBXGeometry result;
|
FBXGeometry result;
|
||||||
if (!vUtil.computeVHACD(fbx, params, result, startMeshIndex, endMeshIndex,
|
bool success = vUtil.computeVHACD(fbx, params, result, startMeshIndex, endMeshIndex, minimumMeshSize, maximumMeshSize);
|
||||||
minimumMeshSize, maximumMeshSize)) {
|
|
||||||
cout << "Compute Failed...";
|
|
||||||
}
|
|
||||||
end = std::chrono::high_resolution_clock::now();
|
end = std::chrono::high_resolution_clock::now();
|
||||||
auto computeDuration = std::chrono::duration_cast<std::chrono::nanoseconds>(end - begin).count();
|
auto computeDuration = std::chrono::duration_cast<std::chrono::nanoseconds>(end - begin).count();
|
||||||
|
qDebug() << "run time =" << (double)computeDuration / 1000000000.00 << " seconds";
|
||||||
|
|
||||||
|
if (!success) {
|
||||||
|
qDebug() << "failed to convexify model";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
int totalVertices = 0;
|
int totalVertices = 0;
|
||||||
int totalTriangles = 0;
|
int totalTriangles = 0;
|
||||||
int totalMeshParts = 0;
|
|
||||||
foreach (const FBXMesh& mesh, result.meshes) {
|
foreach (const FBXMesh& mesh, result.meshes) {
|
||||||
totalVertices += mesh.vertices.size();
|
totalVertices += mesh.vertices.size();
|
||||||
foreach (const FBXMeshPart &meshPart, mesh.parts) {
|
foreach (const FBXMeshPart &meshPart, mesh.parts) {
|
||||||
totalTriangles += meshPart.triangleIndices.size() / 3;
|
totalTriangles += meshPart.triangleIndices.size() / 3;
|
||||||
// each quad was made into two triangles
|
// each quad was made into two triangles
|
||||||
totalTriangles += 2 * meshPart.quadIndices.size() / 4;
|
totalTriangles += 2 * meshPart.quadIndices.size() / 4;
|
||||||
totalMeshParts++;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int totalHulls = result.meshes[0].parts.size();
|
int totalHulls = result.meshes[0].parts.size();
|
||||||
cout << endl << "Summary of V-HACD Computation..................." << endl;
|
qDebug() << "output file =" << outputFilename;
|
||||||
cout << "File Path : " << inputFilename.toStdString() << endl;
|
qDebug() << "vertices =" << totalVertices;
|
||||||
cout << "Number Of Meshes : " << totalMeshParts << endl;
|
qDebug() << "triangles =" << totalTriangles;
|
||||||
cout << "Total vertices : " << totalVertices << endl;
|
qDebug() << "hulls =" << totalHulls;
|
||||||
cout << "Total Triangles : " << totalTriangles << endl;
|
|
||||||
cout << "Total Convex Hulls : " << totalHulls << endl;
|
|
||||||
cout << "Total FBX load time: " << (double)loadDuration / 1000000000.00 << " seconds" << endl;
|
|
||||||
cout << "V-HACD Compute time: " << (double)computeDuration / 1000000000.00 << " seconds" << endl;
|
|
||||||
|
|
||||||
writeOBJ(outputFilename, result, outputCentimeters);
|
writeOBJ(outputFilename, result, outputCentimeters);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue