mirror of
https://github.com/lubosz/overte.git
synced 2025-04-16 09:46:29 +02:00
added various controls for the convex hull generator
This commit is contained in:
parent
e6ac502fb5
commit
c68f5dd1fa
5 changed files with 67 additions and 10 deletions
|
@ -14,6 +14,7 @@
|
|||
#define hifi_Extents_h
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
#include <glm/gtx/extented_min_max.hpp>
|
||||
|
||||
#include <QDebug>
|
||||
#include "StreamUtils.h"
|
||||
|
@ -46,6 +47,9 @@ public:
|
|||
/// rotate the extents around orign by rotation
|
||||
void rotate(const glm::quat& rotation);
|
||||
|
||||
glm::vec3 size() const { return maximum - minimum; }
|
||||
float largestDimension () const {glm::vec3 s = size(); return glm::max(s[0], s[1], s[2]); }
|
||||
|
||||
/// \return new Extents which is original rotated around orign by rotation
|
||||
Extents getRotated(const glm::quat& rotation) const {
|
||||
Extents temp = { minimum, maximum };
|
||||
|
@ -68,4 +72,4 @@ inline QDebug operator<<(QDebug debug, const Extents& extents) {
|
|||
}
|
||||
|
||||
|
||||
#endif // hifi_Extents_h
|
||||
#endif // hifi_Extents_h
|
||||
|
|
|
@ -8,5 +8,5 @@ set_target_properties(scribe PROPERTIES FOLDER "Tools")
|
|||
find_package(VHACD)
|
||||
if(VHACD_FOUND)
|
||||
add_subdirectory(vhacd)
|
||||
set_target_properties(vhacd PROPERTIES FOLDER "Tools")
|
||||
# set_target_properties(vhacd PROPERTIES FOLDER "Tools")
|
||||
endif()
|
||||
|
|
|
@ -57,8 +57,15 @@ bool vhacd::VHACDUtil::loadFBX(const QString filename, vhacd::LoadFBXResults *re
|
|||
if (triangles.count() <= 0){
|
||||
continue;
|
||||
}
|
||||
|
||||
AABox aaBox;
|
||||
foreach (glm::vec3 p, vertices) {
|
||||
aaBox += p;
|
||||
}
|
||||
|
||||
results->perMeshVertices.append(vertices);
|
||||
results->perMeshTriangleIndices.append(triangles);
|
||||
results->perMeshLargestDimension.append(aaBox.getLargestDimension());
|
||||
count++;
|
||||
}
|
||||
|
||||
|
@ -66,23 +73,40 @@ 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,
|
||||
int startMeshIndex, int endMeshIndex, float minimumMeshSize) 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++){
|
||||
if (startMeshIndex < 0) {
|
||||
startMeshIndex = 0;
|
||||
}
|
||||
if (endMeshIndex < 0) {
|
||||
endMeshIndex = meshCount;
|
||||
}
|
||||
|
||||
for (int i = startMeshIndex; i < endMeshIndex; i++){
|
||||
qDebug() << "--------------------";
|
||||
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 << " : ";
|
||||
const float largestDimension = meshes->perMeshLargestDimension.at(i);
|
||||
|
||||
qDebug() << "Mesh " << i << " -- " << nPoints << " points, " << nTriangles << " triangles, "
|
||||
<< "size =" << largestDimension;
|
||||
|
||||
if (largestDimension < minimumMeshSize || largestDimension > 1000) {
|
||||
qDebug() << " Skipping...";
|
||||
continue;
|
||||
}
|
||||
// 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;
|
||||
qDebug() << "V-HACD computation failed for Mesh : " << i;
|
||||
continue;
|
||||
}
|
||||
count++; //For counting number of successfull computations
|
||||
|
|
|
@ -34,12 +34,14 @@ namespace vhacd {
|
|||
int meshCount;
|
||||
QVector<QVector<glm::vec3>> perMeshVertices;
|
||||
QVector<QVector<int>> perMeshTriangleIndices;
|
||||
QVector<float> perMeshLargestDimension;
|
||||
} 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;
|
||||
bool computeVHACD(vhacd::LoadFBXResults *meshes, VHACD::IVHACD::Parameters params,
|
||||
vhacd::ComputeResults *results, int startMeshIndex, int endMeshIndex, float minimumMeshSize) const;
|
||||
~VHACDUtil();
|
||||
};
|
||||
|
||||
|
|
|
@ -98,6 +98,15 @@ VHACDUtilApp::VHACDUtilApp(int argc, char* argv[]) :
|
|||
const QCommandLineOption outputFilenameOption("o", "output file", "filename.obj");
|
||||
parser.addOption(outputFilenameOption);
|
||||
|
||||
const QCommandLineOption startMeshIndexOption("s", "start-mesh index", "0");
|
||||
parser.addOption(startMeshIndexOption);
|
||||
|
||||
const QCommandLineOption endMeshIndexOption("e", "end-mesh index", "0");
|
||||
parser.addOption(endMeshIndexOption);
|
||||
|
||||
const QCommandLineOption minimumMeshSizeOption("m", "minimum mesh size to consider", "0");
|
||||
parser.addOption(minimumMeshSizeOption);
|
||||
|
||||
|
||||
if (!parser.parse(QCoreApplication::arguments())) {
|
||||
qCritical() << parser.errorText() << endl;
|
||||
|
@ -138,13 +147,31 @@ VHACDUtilApp::VHACDUtilApp(int argc, char* argv[]) :
|
|||
Q_UNREACHABLE();
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
|
||||
//set parameters for V-HACD
|
||||
params.m_callback = &pCallBack; //progress callback
|
||||
params.m_resolution = 100000; // 100000
|
||||
params.m_depth = 20; // 20
|
||||
params.m_concavity = 0.001; // 0.001
|
||||
params.m_delta = 0.01; // 0.05
|
||||
params.m_delta = 0.05; // 0.05
|
||||
params.m_planeDownsampling = 4; // 4
|
||||
params.m_convexhullDownsampling = 4; // 4
|
||||
params.m_alpha = 0.05; // 0.05 // controls the bias toward clipping along symmetry planes
|
||||
|
@ -153,7 +180,7 @@ VHACDUtilApp::VHACDUtilApp(int argc, char* argv[]) :
|
|||
params.m_pca = 0; // 0 enable/disable normalizing the mesh before applying the convex decomposition
|
||||
params.m_mode = 0; // 0: voxel-based (recommended), 1: tetrahedron-based
|
||||
params.m_maxNumVerticesPerCH = 64; // 64
|
||||
params.m_minVolumePerCH = 0.00001; // 0.0001
|
||||
params.m_minVolumePerCH = 0.0001; // 0.0001
|
||||
params.m_callback = 0; // 0
|
||||
params.m_logger = 0; // 0
|
||||
params.m_convexhullApproximation = true; // true
|
||||
|
@ -172,7 +199,7 @@ VHACDUtilApp::VHACDUtilApp(int argc, char* argv[]) :
|
|||
begin = std::chrono::high_resolution_clock::now();
|
||||
|
||||
|
||||
if (!vUtil.computeVHACD(&fbx, params, &results)){
|
||||
if (!vUtil.computeVHACD(&fbx, params, &results, startMeshIndex, endMeshIndex, minimumMeshSize)) {
|
||||
cout << "Compute Failed...";
|
||||
}
|
||||
end = std::chrono::high_resolution_clock::now();
|
||||
|
|
Loading…
Reference in a new issue