Fixed bug in setting bit flag for rig node data included

Fixed bug in building rig header
This commit is contained in:
Xiao Qi 2023-03-03 21:56:03 +08:00
parent 5839a2b80d
commit 6b2490611b
2 changed files with 17 additions and 15 deletions

View File

@ -101,8 +101,6 @@ namespace SH_COMP
{ {
FetchData(primitive.attributes.at(ATT_WEIGHTS.data()), meshIn.weights); FetchData(primitive.attributes.at(ATT_WEIGHTS.data()), meshIn.weights);
FetchData(primitive.attributes.at(ATT_JOINT.data()), meshIn.joints); FetchData(primitive.attributes.at(ATT_JOINT.data()), meshIn.joints);
std::cout << "hi\n";
} }
catch(std::out_of_range e) catch(std::out_of_range e)
{ {
@ -260,7 +258,8 @@ namespace SH_COMP
AnimationInterpolation::DEFAULT; AnimationInterpolation::DEFAULT;
} }
std::cout << "all anim channels copied\n"; anim.duration = (anim.nodes[0].positionKeys.end() - 1)->time;
anim.ticksPerSecond = 1.f;
} }
} }
@ -269,18 +268,17 @@ namespace SH_COMP
if (asset.anims.empty()) if (asset.anims.empty())
return; return;
auto& rig = asset.rig;
auto& header = rig.header;
for (auto const& node : data.nodes) for (auto const& node : data.nodes)
{ {
if ( if (node.mesh > -1)
node.rotation.empty() &&
node.translation.empty() &&
node.translation.empty()
)
continue; continue;
std::vector<IndexType> intermediate(node.children.begin(), node.children.end()); std::vector<IndexType> intermediate(node.children.begin(), node.children.end());
asset.rig.nodes.emplace_back( rig.nodes.emplace_back(
node.name, node.name,
static_cast<std::vector<IndexType> const&>(intermediate), static_cast<std::vector<IndexType> const&>(intermediate),
node.rotation, node.rotation,
@ -288,6 +286,7 @@ namespace SH_COMP
node.matrix node.matrix
//node.weights //node.weights
); );
header.charCounts.emplace_back(node.name.size());
} }
for (auto const& skin : data.skins) for (auto const& skin : data.skins)
@ -296,13 +295,16 @@ namespace SH_COMP
FetchData(skin.inverseBindMatrices, inverseBindMatrices); FetchData(skin.inverseBindMatrices, inverseBindMatrices);
std::vector<IndexType> joints(skin.joints.begin(), skin.joints.end()); std::vector<IndexType> joints(skin.joints.begin(), skin.joints.end());
auto& nodes{ asset.rig.nodes }; auto& nodes{ rig.nodes };
auto matrix{ inverseBindMatrices.begin() }; auto matrix{ inverseBindMatrices.begin() };
for (auto const& joint : joints) for (auto const& joint : joints)
{ {
nodes[joint].inverseBindMatrix = *(matrix++); 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();
} }
} }

View File

@ -174,13 +174,13 @@ namespace SH_COMP
NodeDataFlag flag{ 0 }; NodeDataFlag flag{ 0 };
if (!node.rotation.empty()) if (!node.rotation.empty())
flag &= NODE_DATA_ROTATION; flag |= NODE_DATA_ROTATION;
if (!node.scale.empty()) if (!node.scale.empty())
flag &= NODE_DATA_SCALE; flag |= NODE_DATA_SCALE;
if (!node.translation.empty()) if (!node.translation.empty())
flag &= NODE_DATA_TRANSLATION; flag |= NODE_DATA_TRANSLATION;
if (!node.matrix.empty()) if (!node.matrix.empty())
flag &= NODE_DATA_MATRIX; flag |= NODE_DATA_MATRIX;
file.put(flag); file.put(flag);