mirror of
https://thingvellir.net/git/overte
synced 2025-03-27 23:52:03 +01:00
Merge branch '20305' of https://github.com/virneo/hifi into 20305
This commit is contained in:
commit
a0a1564720
3 changed files with 36 additions and 39 deletions
|
@ -14,8 +14,7 @@
|
|||
|
||||
|
||||
//Read all the meshes from provided FBX file
|
||||
bool vhacd::VHACDUtil::loadFBX(const QString filename, vhacd::LoadFBXResults *results)
|
||||
{
|
||||
bool vhacd::VHACDUtil::loadFBX(const QString filename, vhacd::LoadFBXResults *results){
|
||||
|
||||
// open the fbx file
|
||||
QFile fbx(filename);
|
||||
|
@ -29,15 +28,13 @@ bool vhacd::VHACDUtil::loadFBX(const QString filename, vhacd::LoadFBXResults *re
|
|||
//results->meshCount = geometry.meshes.count();
|
||||
|
||||
int count = 0;
|
||||
foreach(FBXMesh mesh, geometry.meshes)
|
||||
{
|
||||
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)
|
||||
{
|
||||
foreach(FBXMeshPart part, mesh.parts) {
|
||||
QVector<int> indices = part.triangleIndices;
|
||||
triangles += indices;
|
||||
}
|
||||
|
@ -54,15 +51,13 @@ bool vhacd::VHACDUtil::loadFBX(const QString filename, vhacd::LoadFBXResults *re
|
|||
return true;
|
||||
}
|
||||
|
||||
bool vhacd::VHACDUtil::computeVHACD(vhacd::LoadFBXResults *meshes, VHACD::IVHACD::Parameters params, vhacd::ComputeResults *results)const
|
||||
{
|
||||
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;
|
||||
|
||||
for (int i = 0; i < meshCount; i++)
|
||||
{
|
||||
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();
|
||||
|
@ -71,8 +66,7 @@ bool vhacd::VHACDUtil::computeVHACD(vhacd::LoadFBXResults *meshes, VHACD::IVHACD
|
|||
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)
|
||||
{
|
||||
if (!res){
|
||||
std::cout << "V-HACD computation failed for Mesh : " << i + 1 << std::endl;
|
||||
continue;
|
||||
}
|
||||
|
@ -84,8 +78,7 @@ bool vhacd::VHACDUtil::computeVHACD(vhacd::LoadFBXResults *meshes, VHACD::IVHACD
|
|||
|
||||
//get all the convex hulls for this mesh
|
||||
QVector<VHACD::IVHACD::ConvexHull> convexHulls;
|
||||
for (unsigned int j = 0; j < nConvexHulls; j++)
|
||||
{
|
||||
for (unsigned int j = 0; j < nConvexHulls; j++){
|
||||
VHACD::IVHACD::ConvexHull hull;
|
||||
interfaceVHACD->GetConvexHull(j, hull);
|
||||
convexHulls.append(hull);
|
||||
|
@ -105,14 +98,12 @@ bool vhacd::VHACDUtil::computeVHACD(vhacd::LoadFBXResults *meshes, VHACD::IVHACD
|
|||
return false;
|
||||
}
|
||||
|
||||
vhacd::VHACDUtil:: ~VHACDUtil()
|
||||
{
|
||||
vhacd::VHACDUtil:: ~VHACDUtil(){
|
||||
//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)
|
||||
{
|
||||
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)
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
#include <iomanip>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <chrono> //c++11 feature
|
||||
#include <QFile>
|
||||
#include <FBXReader.h>
|
||||
#include <VHACD.h>
|
||||
|
@ -42,8 +42,7 @@ namespace vhacd{
|
|||
~VHACDUtil();
|
||||
};
|
||||
|
||||
class ProgressCallback : public VHACD::IVHACD::IUserCallback
|
||||
{
|
||||
class ProgressCallback : public VHACD::IVHACD::IUserCallback{
|
||||
public:
|
||||
ProgressCallback(void);
|
||||
~ProgressCallback();
|
||||
|
|
|
@ -19,8 +19,7 @@
|
|||
using namespace std;
|
||||
using namespace VHACD;
|
||||
|
||||
int main(int argc, char * argv[])
|
||||
{
|
||||
int main(int argc, char * argv[]){
|
||||
vector<int> triangles; // array of indexes
|
||||
vector<float> points; // array of coordinates
|
||||
vhacd::VHACDUtil vUtil;
|
||||
|
@ -28,9 +27,14 @@ int main(int argc, char * argv[])
|
|||
vhacd::ComputeResults results; // results after computing vhacd
|
||||
VHACD::IVHACD::Parameters params;
|
||||
vhacd::ProgressCallback pCallBack;
|
||||
|
||||
|
||||
QString fname = "F:/models/ship/Sample_Ship.fbx";
|
||||
string filename(argv[1]);
|
||||
if (filename.empty()){
|
||||
cout << "please provide a FBX file as argument\n ";
|
||||
return 1;
|
||||
}
|
||||
|
||||
QString fname = QString::fromStdString(filename);
|
||||
|
||||
//set parameters for V-HACD
|
||||
params.m_callback = &pCallBack; //progress callback
|
||||
|
@ -44,34 +48,37 @@ int main(int argc, char * argv[])
|
|||
params.m_minVolumePerCH = 0.0001; // controls the adaptive sampling of the generated convex - hulls
|
||||
|
||||
// load the mesh
|
||||
if (!vUtil.loadFBX(fname, &fbx))
|
||||
{
|
||||
|
||||
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();
|
||||
|
||||
if (!vUtil.computeVHACD(&fbx, params, &results))
|
||||
{
|
||||
//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++)
|
||||
{
|
||||
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++)
|
||||
{
|
||||
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++)
|
||||
{
|
||||
for (int i = 0; i < results.meshCount; i++){
|
||||
totalHulls += hullCounts.at(i);
|
||||
}
|
||||
cout << endl << "Summary of V-HACD Computation..................." << endl;
|
||||
|
@ -81,15 +88,15 @@ int main(int argc, char * argv[])
|
|||
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++)
|
||||
{
|
||||
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;
|
||||
|
|
Loading…
Reference in a new issue