From 06b38615d5b7d6123c9e787ec850b029526efeba Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Wed, 1 Apr 2015 17:53:33 -0700 Subject: [PATCH] sort meshes into the order they appeared in the model file so that start and end arguments mean something usefil --- tools/vhacd/src/VHACDUtil.cpp | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/tools/vhacd/src/VHACDUtil.cpp b/tools/vhacd/src/VHACDUtil.cpp index eab9a25b2c..9f20e5e706 100644 --- a/tools/vhacd/src/VHACDUtil.cpp +++ b/tools/vhacd/src/VHACDUtil.cpp @@ -13,6 +13,16 @@ #include "VHACDUtil.h" +// FBXReader jumbles the order of the meshes by reading them back out of a hashtable. This will put +// them back in the order in which they appeared in the file. +bool FBXGeometryLessThan(const FBXMesh& e1, const FBXMesh& e2) { + return e1.meshIndex < e2.meshIndex; +} +void reSortFBXGeometryMeshes(FBXGeometry& geometry) { + qSort(geometry.meshes.begin(), geometry.meshes.end(), FBXGeometryLessThan); +} + + // Read all the meshes from provided FBX file bool vhacd::VHACDUtil::loadFBX(const QString filename, FBXGeometry& result) { @@ -34,10 +44,13 @@ bool vhacd::VHACDUtil::loadFBX(const QString filename, FBXGeometry& result) { return false; } + reSortFBXGeometryMeshes(result); + return true; } + // void vhacd::VHACDUtil::fattenMeshes(vhacd::LoadFBXResults *meshes, vhacd::LoadFBXResults *results) const { // for (int i = 0; i < meshes->meshCount; i++) { @@ -85,9 +98,6 @@ bool vhacd::VHACDUtil::computeVHACD(FBXGeometry& geometry, // count the mesh-parts QVector meshParts; int meshCount = 0; - foreach (FBXMesh mesh, geometry.meshes) { - meshCount += mesh.parts.size(); - } VHACD::IVHACD * interfaceVHACD = VHACD::CreateVHACD(); @@ -106,9 +116,22 @@ bool vhacd::VHACDUtil::computeVHACD(FBXGeometry& geometry, int count = 0; foreach (const FBXMesh& mesh, geometry.meshes) { + + // each mesh has its own transform to move it to model-space + std::vector vertices; + foreach (glm::vec3 vertex, mesh.vertices) { + vertices.push_back(glm::vec3(mesh.modelTransform * glm::vec4(vertex, 1.0f))); + } + foreach (const FBXMeshPart &meshPart, mesh.parts) { + + if (count < startMeshIndex || count >= endMeshIndex) { + count ++; + continue; + } + qDebug() << "--------------------"; - std::vector vertices = mesh.vertices.toStdVector(); + std::vector triangles = meshPart.triangleIndices.toStdVector(); AABox aaBox;