Reorder nodes to follow skin node order to eliminate one layer of indirection in indices
This commit is contained in:
parent
13fab61332
commit
810c1e4c08
|
@ -268,43 +268,60 @@ namespace SH_COMP
|
||||||
if (asset.anims.empty())
|
if (asset.anims.empty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
if (data.skins.size() == 0)
|
||||||
|
{
|
||||||
|
std::cout << "[Model Compiler] Unable to load rigs without skin, aborting";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
auto& rig = asset.rig;
|
auto& rig = asset.rig;
|
||||||
auto& header = rig.header;
|
auto& header = rig.header;
|
||||||
|
auto const& skin = data.skins[0];
|
||||||
|
auto const jointsCount {skin.joints.size()};
|
||||||
|
auto const& joints = skin.joints;
|
||||||
|
|
||||||
for (auto const& node : data.nodes)
|
std::vector<SHMat4> inverseBindMatrices;
|
||||||
|
FetchData(skin.inverseBindMatrices, inverseBindMatrices);
|
||||||
|
|
||||||
|
std::vector<NodeAsset> nodesOrdered;
|
||||||
|
nodesOrdered.reserve(jointsCount);
|
||||||
|
auto& nodes{ data.nodes };
|
||||||
|
|
||||||
|
for (auto i{0}; i < jointsCount; ++i)
|
||||||
{
|
{
|
||||||
if (node.mesh > -1)
|
auto const& node{nodes[joints[i]]};
|
||||||
continue;
|
std::vector<IndexType> intermediate(node.children.size());
|
||||||
|
|
||||||
std::vector<IndexType> intermediate(node.children.begin(), node.children.end());
|
std::ranges::transform(
|
||||||
|
node.children,
|
||||||
|
intermediate.begin(),
|
||||||
|
[joints, jointsCount](auto const& index)->IndexType
|
||||||
|
{
|
||||||
|
for (IndexType i{0}; i < jointsCount; ++i)
|
||||||
|
{
|
||||||
|
if (joints[i] == index)
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
rig.nodes.emplace_back(
|
nodesOrdered.emplace_back(
|
||||||
node.name,
|
node.name,
|
||||||
static_cast<std::vector<IndexType> const&>(intermediate),
|
static_cast<std::vector<IndexType> const&>(intermediate),
|
||||||
node.rotation,
|
node.rotation,
|
||||||
|
node.scale,
|
||||||
node.translation,
|
node.translation,
|
||||||
node.matrix
|
node.matrix,
|
||||||
//node.weights
|
inverseBindMatrices[i]
|
||||||
);
|
);
|
||||||
|
nodesOrdered[i].inverseBindMatrix = inverseBindMatrices[i];
|
||||||
header.charCounts.emplace_back(node.name.size());
|
header.charCounts.emplace_back(node.name.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto const& skin : data.skins)
|
rig.nodes = std::move(nodesOrdered);
|
||||||
{
|
|
||||||
std::vector<SHMat4> inverseBindMatrices;
|
|
||||||
FetchData(skin.inverseBindMatrices, inverseBindMatrices);
|
|
||||||
|
|
||||||
std::vector<IndexType> joints(skin.joints.begin(), skin.joints.end());
|
|
||||||
auto& nodes{ rig.nodes };
|
|
||||||
auto matrix{ inverseBindMatrices.begin() };
|
|
||||||
for (auto const& joint : joints)
|
|
||||||
{
|
|
||||||
nodes[joint].inverseBindMatrix = *(matrix++);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//Build header
|
//Build header
|
||||||
header.startNode = data.skins[0].joints[0];
|
header.startNode = 0;
|
||||||
header.nodeCount = rig.nodes.size();
|
header.nodeCount = rig.nodes.size();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue