Skip to content

Commit

Permalink
Fix splitting algorithm (#113)
Browse files Browse the repository at this point in the history
  • Loading branch information
shrinktofit authored Oct 13, 2023
1 parent d4e9306 commit 18a8a86
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions Core/Source/bee/Convert/fbxsdk/SplitMeshByMaterial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,31 @@

namespace bee {
namespace {
void collect_meshes(fbxsdk::FbxNode &node_, std::unordered_set<fbxsdk::FbxMesh *> &result_) {
void collect_meshes(fbxsdk::FbxNode &node_, std::vector<fbxsdk::FbxMesh *> &result_) {
for (const auto iNodeAttribute : ranges::iota_view<int, int>(0, node_.GetNodeAttributeCount())) {
const auto nodeAttribute = node_.GetNodeAttributeByIndex(iNodeAttribute);
switch (const auto attributeType = nodeAttribute->GetAttributeType()) {
case fbxsdk::FbxNodeAttribute::EType::eMesh:
result_.emplace(static_cast<fbxsdk::FbxMesh *>(nodeAttribute));
break;
case fbxsdk::FbxNodeAttribute::EType::eMesh: {
const auto mesh = static_cast<fbxsdk::FbxMesh *>(nodeAttribute);
if (ranges::find(result_, mesh) == result_.end()) {
result_.emplace_back(mesh);
}
} break;
default:
break;
}
}
}

void collect_meshes_recurse(fbxsdk::FbxNode &node_, std::unordered_set<fbxsdk::FbxMesh *> &result_) {
void collect_meshes_recurse(fbxsdk::FbxNode &node_, std::vector<fbxsdk::FbxMesh *> &result_) {
collect_meshes(node_, result_);
for (const auto iChild : ranges::iota_view<int, int>(0, node_.GetChildCount())) {
collect_meshes_recurse(*node_.GetChild(iChild), result_);
}
}

std::unordered_set<fbxsdk::FbxMesh *> collect_meshes(fbxsdk::FbxScene &scene_) {
std::unordered_set<fbxsdk::FbxMesh *> result;
std::vector<fbxsdk::FbxMesh *> collect_meshes(fbxsdk::FbxScene &scene_) {
std::vector<fbxsdk::FbxMesh *> result;
collect_meshes_recurse(*scene_.GetRootNode(), result);
return result;
}
Expand All @@ -50,20 +53,20 @@ SplitMeshesResult split_meshes_per_material(fbxsdk::FbxScene &scene_, fbxsdk::Fb
const auto firstNode = mesh->GetNode(0);
assert(firstNode);

std::unordered_set<fbxsdk::FbxMesh *> meshesOnThisNodeBefore;
std::vector<fbxsdk::FbxMesh *> meshesOnThisNodeBefore;
collect_meshes(*firstNode, meshesOnThisNodeBefore);

const auto success = geometry_converter_.SplitMeshPerMaterial(mesh, false);

std::unordered_set<fbxsdk::FbxMesh *> meshesOnThisNodeAfter;
std::vector<fbxsdk::FbxMesh *> meshesOnThisNodeAfter;
collect_meshes(*firstNode, meshesOnThisNodeAfter);

{
std::vector<fbxsdk::FbxMesh *> removed;
ranges::copy_if(
meshesOnThisNodeBefore,
ranges::back_inserter(removed),
[&meshesOnThisNodeAfter](auto mesh_) { return meshesOnThisNodeAfter.find(mesh_) == meshesOnThisNodeAfter.end(); });
[&meshesOnThisNodeAfter](auto mesh_) { return ranges::find(meshesOnThisNodeAfter, mesh_) == meshesOnThisNodeAfter.end(); });
assert(removed.empty() && "fbxsdk did something wrong?");
}

Expand All @@ -78,7 +81,7 @@ SplitMeshesResult split_meshes_per_material(fbxsdk::FbxScene &scene_, fbxsdk::Fb
ranges::copy_if(
meshesOnThisNodeAfter,
ranges::back_inserter(newlyAdded),
[&meshesOnThisNodeBefore](auto mesh_) { return meshesOnThisNodeBefore.find(mesh_) == meshesOnThisNodeBefore.end(); });
[&meshesOnThisNodeBefore](auto mesh_) { return ranges::find(meshesOnThisNodeBefore, mesh_) == meshesOnThisNodeBefore.end(); });
if (newlyAdded.empty()) {
assert(meshesOnThisNodeBefore == meshesOnThisNodeAfter && "fbxsdk did something wrong?");
continue;
Expand Down

0 comments on commit 18a8a86

Please sign in to comment.