From 6b2490611b183b2e192574c19c65dc8fd1f3eff2 Mon Sep 17 00:00:00 2001 From: Xiao Qi Date: Fri, 3 Mar 2023 21:56:03 +0800 Subject: [PATCH] Fixed bug in setting bit flag for rig node data included Fixed bug in building rig header --- src/Libraries/MeshCompiler.hpp | 24 +++++++++++++----------- src/Libraries/MeshWriter.cpp | 8 ++++---- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/src/Libraries/MeshCompiler.hpp b/src/Libraries/MeshCompiler.hpp index f20b8ea..48a5b28 100644 --- a/src/Libraries/MeshCompiler.hpp +++ b/src/Libraries/MeshCompiler.hpp @@ -101,8 +101,6 @@ namespace SH_COMP { FetchData(primitive.attributes.at(ATT_WEIGHTS.data()), meshIn.weights); FetchData(primitive.attributes.at(ATT_JOINT.data()), meshIn.joints); - - std::cout << "hi\n"; } catch(std::out_of_range e) { @@ -260,7 +258,8 @@ namespace SH_COMP AnimationInterpolation::DEFAULT; } - std::cout << "all anim channels copied\n"; + anim.duration = (anim.nodes[0].positionKeys.end() - 1)->time; + anim.ticksPerSecond = 1.f; } } @@ -268,19 +267,18 @@ namespace SH_COMP { if (asset.anims.empty()) return; + + auto& rig = asset.rig; + auto& header = rig.header; for (auto const& node : data.nodes) { - if ( - node.rotation.empty() && - node.translation.empty() && - node.translation.empty() - ) + if (node.mesh > -1) continue; std::vector intermediate(node.children.begin(), node.children.end()); - asset.rig.nodes.emplace_back( + rig.nodes.emplace_back( node.name, static_cast const&>(intermediate), node.rotation, @@ -288,6 +286,7 @@ namespace SH_COMP node.matrix //node.weights ); + header.charCounts.emplace_back(node.name.size()); } for (auto const& skin : data.skins) @@ -296,13 +295,16 @@ namespace SH_COMP FetchData(skin.inverseBindMatrices, inverseBindMatrices); std::vector joints(skin.joints.begin(), skin.joints.end()); - auto& nodes{ asset.rig.nodes }; + auto& nodes{ rig.nodes }; auto matrix{ inverseBindMatrices.begin() }; for (auto const& joint : joints) { nodes[joint].inverseBindMatrix = *(matrix++); } } - asset.rig.header.startNode = data.skins[0].joints[0]; + + //Build header + header.startNode = data.skins[0].joints[0]; + header.nodeCount = rig.nodes.size(); } } diff --git a/src/Libraries/MeshWriter.cpp b/src/Libraries/MeshWriter.cpp index a48295b..81a6c55 100644 --- a/src/Libraries/MeshWriter.cpp +++ b/src/Libraries/MeshWriter.cpp @@ -174,13 +174,13 @@ namespace SH_COMP NodeDataFlag flag{ 0 }; if (!node.rotation.empty()) - flag &= NODE_DATA_ROTATION; + flag |= NODE_DATA_ROTATION; if (!node.scale.empty()) - flag &= NODE_DATA_SCALE; + flag |= NODE_DATA_SCALE; if (!node.translation.empty()) - flag &= NODE_DATA_TRANSLATION; + flag |= NODE_DATA_TRANSLATION; if (!node.matrix.empty()) - flag &= NODE_DATA_MATRIX; + flag |= NODE_DATA_MATRIX; file.put(flag);