Fixed bug when processing nodes in scene

Rewrote bone writing because i discarded like a moron
This commit is contained in:
Xiao Qi 2023-01-17 15:40:35 +08:00
parent b99c9e6ebf
commit d590a3894f
3 changed files with 35 additions and 10 deletions

View File

@ -42,21 +42,20 @@ namespace SH_COMP
{ {
if (node->mNumMeshes > 0) if (node->mNumMeshes > 0)
{ {
aiMesh* mesh = scene.mMeshes[node->mMeshes[0]]; aiMesh* mesh = scene.mMeshes[node->mMeshes[0]];
meshes.emplace_back(); meshes.emplace_back();
GetMesh(*mesh, meshes.back()); GetMesh(*mesh, meshes.back());
meshes.back().name = node->mName.C_Str(); meshes.back().name = node->mName.C_Str();
} }
else if (node->mParent != nullptr) else if (node->mParent != nullptr)
{ {
BuildArmature(node, rig); BuildArmature(node, rig);
return;
} }
else
for (auto i{ 0 }; i < node->mNumChildren; ++i)
{ {
for (auto i{ 0 }; i < node->mNumChildren; ++i) ProcessNode(node->mChildren[i], scene, meshes, rig);
{
ProcessNode(node->mChildren[i], scene, meshes, rig);
}
} }
} }

View File

@ -55,6 +55,32 @@ namespace SH_COMP
reinterpret_cast<char const*>(asset.indices.data()), reinterpret_cast<char const*>(asset.indices.data()),
sizeof(uint32_t) * header.indexCount sizeof(uint32_t) * header.indexCount
); );
if (header.boneCount)
{
file.write(
reinterpret_cast<char const*>(asset.bonesInfo.data()),
sizeof(MeshBoneInfo) * header.boneCount
);
for (auto const& bone : asset.bones)
{
file.write(
bone.name.data(),
bone.name.size()
);
file.write(
reinterpret_cast<char const*>(&bone.offset),
sizeof(SHMat4)
);
file.write(
reinterpret_cast<char const*>(bone.weights.data()),
sizeof(BoneWeight) * bone.weights.size()
);
}
}
} }
} }

View File

@ -18,7 +18,7 @@ namespace SH_COMP
struct MeshBoneInfo struct MeshBoneInfo
{ {
uint32_t charCount; uint32_t charCount;
uint32_t weightCount; // Size should be same as boneCount uint32_t weightCount;
}; };
struct BoneWeight struct BoneWeight