mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-07 15:42:39 +02:00
untabify the source files
This commit is contained in:
parent
36c3131524
commit
95839dd64e
3 changed files with 180 additions and 179 deletions
|
@ -16,104 +16,105 @@
|
|||
//Read all the meshes from provided FBX file
|
||||
bool vhacd::VHACDUtil::loadFBX(const QString filename, vhacd::LoadFBXResults *results){
|
||||
|
||||
// open the fbx file
|
||||
QFile fbx(filename);
|
||||
if (!fbx.open(QIODevice::ReadOnly)) {
|
||||
return false;
|
||||
}
|
||||
std::cout << "Reading FBX.....\n";
|
||||
// open the fbx file
|
||||
QFile fbx(filename);
|
||||
if (!fbx.open(QIODevice::ReadOnly)) {
|
||||
return false;
|
||||
}
|
||||
std::cout << "Reading FBX.....\n";
|
||||
|
||||
QByteArray fbxContents = fbx.readAll();
|
||||
FBXGeometry geometry = readFBX(fbxContents, QVariantHash());
|
||||
//results->meshCount = geometry.meshes.count();
|
||||
|
||||
int count = 0;
|
||||
foreach(FBXMesh mesh, geometry.meshes) {
|
||||
//get vertices for each mesh
|
||||
QVector<glm::vec3> vertices = mesh.vertices;
|
||||
QByteArray fbxContents = fbx.readAll();
|
||||
FBXGeometry geometry = readFBX(fbxContents, QVariantHash());
|
||||
//results->meshCount = geometry.meshes.count();
|
||||
|
||||
int count = 0;
|
||||
foreach(FBXMesh mesh, geometry.meshes) {
|
||||
//get vertices for each mesh
|
||||
QVector<glm::vec3> vertices = mesh.vertices;
|
||||
|
||||
//get the triangle indices for each mesh
|
||||
QVector<int> triangles;
|
||||
foreach(FBXMeshPart part, mesh.parts) {
|
||||
QVector<int> indices = part.triangleIndices;
|
||||
triangles += indices;
|
||||
}
|
||||
//get the triangle indices for each mesh
|
||||
QVector<int> triangles;
|
||||
foreach(FBXMeshPart part, mesh.parts) {
|
||||
QVector<int> indices = part.triangleIndices;
|
||||
triangles += indices;
|
||||
}
|
||||
|
||||
//only read meshes with triangles
|
||||
if (triangles.count() <= 0)
|
||||
continue;
|
||||
results->perMeshVertices.append(vertices);
|
||||
results->perMeshTriangleIndices.append(triangles);
|
||||
count++;
|
||||
}
|
||||
//only read meshes with triangles
|
||||
if (triangles.count() <= 0)
|
||||
continue;
|
||||
results->perMeshVertices.append(vertices);
|
||||
results->perMeshTriangleIndices.append(triangles);
|
||||
count++;
|
||||
}
|
||||
|
||||
results->meshCount = count;
|
||||
return true;
|
||||
results->meshCount = count;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool vhacd::VHACDUtil::computeVHACD(vhacd::LoadFBXResults *meshes, VHACD::IVHACD::Parameters params, vhacd::ComputeResults *results)const{
|
||||
VHACD::IVHACD * interfaceVHACD = VHACD::CreateVHACD();
|
||||
int meshCount = meshes->meshCount;
|
||||
int count = 0;
|
||||
std::cout << "Performing V-HACD computation on " << meshCount <<" meshes ..... " << std::endl;
|
||||
VHACD::IVHACD * interfaceVHACD = VHACD::CreateVHACD();
|
||||
int meshCount = meshes->meshCount;
|
||||
int count = 0;
|
||||
std::cout << "Performing V-HACD computation on " << meshCount <<" meshes ..... " << std::endl;
|
||||
|
||||
for (int i = 0; i < meshCount; i++){
|
||||
|
||||
std::vector<glm::vec3> vertices = meshes->perMeshVertices.at(i).toStdVector();
|
||||
std::vector<int> triangles = meshes->perMeshTriangleIndices.at(i).toStdVector();
|
||||
int nPoints = (unsigned int)vertices.size();
|
||||
int nTriangles = (unsigned int)triangles.size() / 3;
|
||||
std::cout << "Mesh " << i + 1 << " : ";
|
||||
// compute approximate convex decomposition
|
||||
bool res = interfaceVHACD->Compute(&vertices[0].x, 3, nPoints, &triangles[0], 3, nTriangles, params);
|
||||
if (!res){
|
||||
std::cout << "V-HACD computation failed for Mesh : " << i + 1 << std::endl;
|
||||
continue;
|
||||
}
|
||||
count++; //For counting number of successfull computations
|
||||
for (int i = 0; i < meshCount; i++){
|
||||
|
||||
std::vector<glm::vec3> vertices = meshes->perMeshVertices.at(i).toStdVector();
|
||||
std::vector<int> triangles = meshes->perMeshTriangleIndices.at(i).toStdVector();
|
||||
int nPoints = (unsigned int)vertices.size();
|
||||
int nTriangles = (unsigned int)triangles.size() / 3;
|
||||
std::cout << "Mesh " << i + 1 << " : ";
|
||||
// compute approximate convex decomposition
|
||||
bool res = interfaceVHACD->Compute(&vertices[0].x, 3, nPoints, &triangles[0], 3, nTriangles, params);
|
||||
if (!res){
|
||||
std::cout << "V-HACD computation failed for Mesh : " << i + 1 << std::endl;
|
||||
continue;
|
||||
}
|
||||
count++; //For counting number of successfull computations
|
||||
|
||||
//Number of hulls for the mesh
|
||||
unsigned int nConvexHulls = interfaceVHACD->GetNConvexHulls();
|
||||
results->convexHullsCountList.append(nConvexHulls);
|
||||
//Number of hulls for the mesh
|
||||
unsigned int nConvexHulls = interfaceVHACD->GetNConvexHulls();
|
||||
results->convexHullsCountList.append(nConvexHulls);
|
||||
|
||||
//get all the convex hulls for this mesh
|
||||
QVector<VHACD::IVHACD::ConvexHull> convexHulls;
|
||||
for (unsigned int j = 0; j < nConvexHulls; j++){
|
||||
VHACD::IVHACD::ConvexHull hull;
|
||||
interfaceVHACD->GetConvexHull(j, hull);
|
||||
convexHulls.append(hull);
|
||||
}
|
||||
results->convexHullList.append(convexHulls);
|
||||
} //end of for loop
|
||||
//get all the convex hulls for this mesh
|
||||
QVector<VHACD::IVHACD::ConvexHull> convexHulls;
|
||||
for (unsigned int j = 0; j < nConvexHulls; j++){
|
||||
VHACD::IVHACD::ConvexHull hull;
|
||||
interfaceVHACD->GetConvexHull(j, hull);
|
||||
convexHulls.append(hull);
|
||||
}
|
||||
results->convexHullList.append(convexHulls);
|
||||
} //end of for loop
|
||||
|
||||
results->meshCount = count;
|
||||
results->meshCount = count;
|
||||
|
||||
//release memory
|
||||
interfaceVHACD->Clean();
|
||||
interfaceVHACD->Release();
|
||||
//release memory
|
||||
interfaceVHACD->Clean();
|
||||
interfaceVHACD->Release();
|
||||
|
||||
if (count > 0)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
if (count > 0)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
vhacd::VHACDUtil:: ~VHACDUtil(){
|
||||
//nothing to be cleaned
|
||||
//nothing to be cleaned
|
||||
}
|
||||
|
||||
//ProgressClaback implementation
|
||||
void vhacd::ProgressCallback::Update(const double overallProgress, const double stageProgress, const double operationProgress, const char * const stage, const char * const operation){
|
||||
int progress = (int)(overallProgress + 0.5);
|
||||
void vhacd::ProgressCallback::Update(const double overallProgress, const double stageProgress, const double operationProgress,
|
||||
const char * const stage, const char * const operation){
|
||||
int progress = (int)(overallProgress + 0.5);
|
||||
|
||||
if (progress < 10)
|
||||
std::cout << "\b\b";
|
||||
else
|
||||
std::cout << "\b\b\b";
|
||||
std::cout << progress << "%";
|
||||
if (progress < 10)
|
||||
std::cout << "\b\b";
|
||||
else
|
||||
std::cout << "\b\b\b";
|
||||
std::cout << progress << "%";
|
||||
|
||||
if (progress >= 100)
|
||||
std::cout << std::endl;
|
||||
if (progress >= 100)
|
||||
std::cout << std::endl;
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -23,32 +23,33 @@
|
|||
|
||||
namespace vhacd{
|
||||
|
||||
typedef struct{
|
||||
int meshCount;
|
||||
QVector<int> convexHullsCountList;
|
||||
QVector<QVector<VHACD::IVHACD::ConvexHull>> convexHullList;
|
||||
}ComputeResults;
|
||||
typedef struct{
|
||||
int meshCount;
|
||||
QVector<int> convexHullsCountList;
|
||||
QVector<QVector<VHACD::IVHACD::ConvexHull>> convexHullList;
|
||||
}ComputeResults;
|
||||
|
||||
typedef struct{
|
||||
int meshCount;
|
||||
QVector<QVector<glm::vec3>> perMeshVertices;
|
||||
QVector<QVector<int>> perMeshTriangleIndices;
|
||||
}LoadFBXResults;
|
||||
typedef struct{
|
||||
int meshCount;
|
||||
QVector<QVector<glm::vec3>> perMeshVertices;
|
||||
QVector<QVector<int>> perMeshTriangleIndices;
|
||||
}LoadFBXResults;
|
||||
|
||||
class VHACDUtil{
|
||||
public:
|
||||
bool loadFBX(const QString filename, vhacd::LoadFBXResults *results);
|
||||
bool computeVHACD(vhacd::LoadFBXResults *meshes, VHACD::IVHACD::Parameters params, vhacd::ComputeResults *results)const;
|
||||
~VHACDUtil();
|
||||
};
|
||||
class VHACDUtil{
|
||||
public:
|
||||
bool loadFBX(const QString filename, vhacd::LoadFBXResults *results);
|
||||
bool computeVHACD(vhacd::LoadFBXResults *meshes, VHACD::IVHACD::Parameters params, vhacd::ComputeResults *results)const;
|
||||
~VHACDUtil();
|
||||
};
|
||||
|
||||
class ProgressCallback : public VHACD::IVHACD::IUserCallback{
|
||||
public:
|
||||
ProgressCallback(void);
|
||||
~ProgressCallback();
|
||||
class ProgressCallback : public VHACD::IVHACD::IUserCallback{
|
||||
public:
|
||||
ProgressCallback(void);
|
||||
~ProgressCallback();
|
||||
|
||||
//Couldn't follow coding guideline here due to virtual function declared in IUserCallback
|
||||
void Update(const double overallProgress, const double stageProgress, const double operationProgress, const char * const stage, const char * const operation);
|
||||
};
|
||||
//Couldn't follow coding guideline here due to virtual function declared in IUserCallback
|
||||
void Update(const double overallProgress, const double stageProgress, const double operationProgress,
|
||||
const char * const stage, const char * const operation);
|
||||
};
|
||||
}
|
||||
#endif //hifi_VHACDUtil_h
|
|
@ -20,93 +20,92 @@ using namespace std;
|
|||
using namespace VHACD;
|
||||
|
||||
int main(int argc, char * argv[]){
|
||||
vector<int> triangles; // array of indexes
|
||||
vector<float> points; // array of coordinates
|
||||
vhacd::VHACDUtil vUtil;
|
||||
vhacd::LoadFBXResults fbx; //mesh data from loaded fbx file
|
||||
vhacd::ComputeResults results; // results after computing vhacd
|
||||
VHACD::IVHACD::Parameters params;
|
||||
vhacd::ProgressCallback pCallBack;
|
||||
if (argc < 2){
|
||||
cout << "please provide a FBX file as argument\n ";
|
||||
return 1;
|
||||
}
|
||||
string filename(argv[1]);
|
||||
if (filename.empty()){
|
||||
cout << "please provide a FBX file as argument\n ";
|
||||
return 1;
|
||||
}
|
||||
vector<int> triangles; // array of indexes
|
||||
vector<float> points; // array of coordinates
|
||||
vhacd::VHACDUtil vUtil;
|
||||
vhacd::LoadFBXResults fbx; //mesh data from loaded fbx file
|
||||
vhacd::ComputeResults results; // results after computing vhacd
|
||||
VHACD::IVHACD::Parameters params;
|
||||
vhacd::ProgressCallback pCallBack;
|
||||
if (argc < 2){
|
||||
cout << "please provide a FBX file as argument\n ";
|
||||
return 1;
|
||||
}
|
||||
string filename(argv[1]);
|
||||
if (filename.empty()){
|
||||
cout << "please provide a FBX file as argument\n ";
|
||||
return 1;
|
||||
}
|
||||
|
||||
QString fname = QString::fromStdString(filename);
|
||||
QString fname = QString::fromStdString(filename);
|
||||
|
||||
//set parameters for V-HACD
|
||||
params.m_callback = &pCallBack; //progress callback
|
||||
params.m_resolution = 50000;
|
||||
params.m_depth = 10;
|
||||
params.m_concavity = 0.003;
|
||||
params.m_alpha = 0.05; // controls the bias toward clipping along symmetry planes
|
||||
params.m_pca = 1; // enable/disable normalizing the mesh before applying the convex decomposition
|
||||
params.m_mode = 1; // 0: voxel - based approximate convex decomposition, 1 : tetrahedron - based approximate convex decomposition
|
||||
params.m_maxNumVerticesPerCH = 128;
|
||||
params.m_minVolumePerCH = 0.0001; // controls the adaptive sampling of the generated convex - hulls
|
||||
//set parameters for V-HACD
|
||||
params.m_callback = &pCallBack; //progress callback
|
||||
params.m_resolution = 50000;
|
||||
params.m_depth = 10;
|
||||
params.m_concavity = 0.003;
|
||||
params.m_alpha = 0.05; // controls the bias toward clipping along symmetry planes
|
||||
params.m_pca = 1; // enable/disable normalizing the mesh before applying the convex decomposition
|
||||
params.m_mode = 1; // 0: voxel - based approximate convex decomposition, 1 : tetrahedron - based approximate convex decomposition
|
||||
params.m_maxNumVerticesPerCH = 128;
|
||||
params.m_minVolumePerCH = 0.0001; // controls the adaptive sampling of the generated convex - hulls
|
||||
|
||||
// load the mesh
|
||||
// load the mesh
|
||||
|
||||
auto begin = std::chrono::high_resolution_clock::now();
|
||||
if (!vUtil.loadFBX(fname, &fbx)){
|
||||
cout << "Error in opening FBX file....";
|
||||
return 1;
|
||||
}
|
||||
auto end = std::chrono::high_resolution_clock::now();
|
||||
auto loadDuration = std::chrono::duration_cast<std::chrono::nanoseconds>(end - begin).count();
|
||||
auto begin = std::chrono::high_resolution_clock::now();
|
||||
if (!vUtil.loadFBX(fname, &fbx)){
|
||||
cout << "Error in opening FBX file....";
|
||||
return 1;
|
||||
}
|
||||
auto end = std::chrono::high_resolution_clock::now();
|
||||
auto loadDuration = std::chrono::duration_cast<std::chrono::nanoseconds>(end - begin).count();
|
||||
|
||||
//perform vhacd computation
|
||||
begin = std::chrono::high_resolution_clock::now();
|
||||
if (!vUtil.computeVHACD(&fbx, params, &results)){
|
||||
cout << "Compute Failed...";
|
||||
return 1;
|
||||
}
|
||||
end = std::chrono::high_resolution_clock::now();
|
||||
auto computeDuration = std::chrono::duration_cast<std::chrono::nanoseconds>(end - begin).count();
|
||||
//perform vhacd computation
|
||||
begin = std::chrono::high_resolution_clock::now();
|
||||
if (!vUtil.computeVHACD(&fbx, params, &results)){
|
||||
cout << "Compute Failed...";
|
||||
return 1;
|
||||
}
|
||||
end = std::chrono::high_resolution_clock::now();
|
||||
auto computeDuration = std::chrono::duration_cast<std::chrono::nanoseconds>(end - begin).count();
|
||||
|
||||
int totalVertices = 0;
|
||||
for (int i = 0; i < fbx.meshCount; i++){
|
||||
totalVertices += fbx.perMeshVertices.at(i).count();
|
||||
}
|
||||
int totalVertices = 0;
|
||||
for (int i = 0; i < fbx.meshCount; i++){
|
||||
totalVertices += fbx.perMeshVertices.at(i).count();
|
||||
}
|
||||
|
||||
int totalTriangles = 0;
|
||||
for (int i = 0; i < fbx.meshCount; i++){
|
||||
totalTriangles += fbx.perMeshTriangleIndices.at(i).count();
|
||||
}
|
||||
int totalTriangles = 0;
|
||||
for (int i = 0; i < fbx.meshCount; i++){
|
||||
totalTriangles += fbx.perMeshTriangleIndices.at(i).count();
|
||||
}
|
||||
|
||||
int totalHulls = 0;
|
||||
QVector<int> hullCounts = results.convexHullsCountList;
|
||||
for (int i = 0; i < results.meshCount; i++){
|
||||
totalHulls += hullCounts.at(i);
|
||||
}
|
||||
cout << endl << "Summary of V-HACD Computation..................." << endl;
|
||||
cout << "File Path : " << fname.toStdString() << endl;
|
||||
cout << "Number Of Meshes : " << fbx.meshCount << endl;
|
||||
cout << "Processed Meshes : " << results.meshCount << endl;
|
||||
cout << "Total vertices : " << totalVertices << endl;
|
||||
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;
|
||||
cout << endl << "Summary per convex hull ........................" << endl <<endl;
|
||||
for (int i = 0; i < results.meshCount; i++){
|
||||
cout << "Mesh : " << i + 1 << endl;
|
||||
QVector<VHACD::IVHACD::ConvexHull> chList = results.convexHullList.at(i);
|
||||
cout << "\t" << "Number Of Hulls : " << chList.count() << endl;
|
||||
int totalHulls = 0;
|
||||
QVector<int> hullCounts = results.convexHullsCountList;
|
||||
for (int i = 0; i < results.meshCount; i++){
|
||||
totalHulls += hullCounts.at(i);
|
||||
}
|
||||
cout << endl << "Summary of V-HACD Computation..................." << endl;
|
||||
cout << "File Path : " << fname.toStdString() << endl;
|
||||
cout << "Number Of Meshes : " << fbx.meshCount << endl;
|
||||
cout << "Processed Meshes : " << results.meshCount << endl;
|
||||
cout << "Total vertices : " << totalVertices << endl;
|
||||
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;
|
||||
cout << endl << "Summary per convex hull ........................" << endl <<endl;
|
||||
for (int i = 0; i < results.meshCount; i++){
|
||||
cout << "Mesh : " << i + 1 << endl;
|
||||
QVector<VHACD::IVHACD::ConvexHull> chList = results.convexHullList.at(i);
|
||||
cout << "\t" << "Number Of Hulls : " << chList.count() << endl;
|
||||
|
||||
for (int j = 0; j < results.convexHullList.at(i).count(); j++){
|
||||
for (int j = 0; j < results.convexHullList.at(i).count(); j++){
|
||||
cout << "\tHUll : " << j + 1 << endl;
|
||||
cout << "\t\tNumber Of Points : " << chList.at(j).m_nPoints << endl;
|
||||
cout << "\t\tNumber Of Triangles : " << chList.at(j).m_nTriangles << endl;
|
||||
}
|
||||
}
|
||||
|
||||
cout << "\tHUll : " << j + 1 << endl;
|
||||
cout << "\t\tNumber Of Points : " << chList.at(j).m_nPoints << endl;
|
||||
cout << "\t\tNumber Of Triangles : " << chList.at(j).m_nTriangles << endl;
|
||||
}
|
||||
}
|
||||
|
||||
getchar();
|
||||
return 0;
|
||||
getchar();
|
||||
return 0;
|
||||
}
|
Loading…
Reference in a new issue