Copy Bone offsets into rig bone node data
This commit is contained in:
parent
5670f06046
commit
393ae91333
|
@ -179,6 +179,34 @@ namespace SH_COMP
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MeshCompiler::BoneOffsetCopy(ModelRef asset) noexcept
|
||||||
|
{
|
||||||
|
auto const& boneVec {asset.meshes[0].bones};
|
||||||
|
|
||||||
|
std::stack<RigNodeData*> nodeStack;
|
||||||
|
nodeStack.push(asset.rig.root);
|
||||||
|
|
||||||
|
while(!nodeStack.empty())
|
||||||
|
{
|
||||||
|
auto& node = *nodeStack.top();
|
||||||
|
nodeStack.pop();
|
||||||
|
|
||||||
|
for (auto const& bone : boneVec)
|
||||||
|
{
|
||||||
|
if (node.name == bone.name)
|
||||||
|
{
|
||||||
|
node.offset = bone.offset;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (auto const& child : node.children)
|
||||||
|
{
|
||||||
|
nodeStack.push(child);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void MeshCompiler::ParseAnimations(aiScene const& scene, std::vector<AnimData>& anims) noexcept
|
void MeshCompiler::ParseAnimations(aiScene const& scene, std::vector<AnimData>& anims) noexcept
|
||||||
{
|
{
|
||||||
// Size and read for number of animation clips
|
// Size and read for number of animation clips
|
||||||
|
@ -317,6 +345,7 @@ namespace SH_COMP
|
||||||
|
|
||||||
LoadFromFile(path, *asset);
|
LoadFromFile(path, *asset);
|
||||||
BuildHeaders(*asset);
|
BuildHeaders(*asset);
|
||||||
|
BoneOffsetCopy(*asset);
|
||||||
MeshWriter::CompileMeshBinary(path, *asset);
|
MeshWriter::CompileMeshBinary(path, *asset);
|
||||||
|
|
||||||
delete asset;
|
delete asset;
|
||||||
|
|
|
@ -39,6 +39,8 @@ namespace SH_COMP
|
||||||
static void GetMesh(aiMesh const& mesh, MeshData& meshData) noexcept;
|
static void GetMesh(aiMesh const& mesh, MeshData& meshData) noexcept;
|
||||||
static void BuildHeaders(ModelRef asset) noexcept;
|
static void BuildHeaders(ModelRef asset) noexcept;
|
||||||
|
|
||||||
|
static void BoneOffsetCopy(ModelRef asset) noexcept;
|
||||||
|
|
||||||
static void BuildArmature(AiNodeConstPtr node, RigData& rig) noexcept;
|
static void BuildArmature(AiNodeConstPtr node, RigData& rig) noexcept;
|
||||||
static void ParseAnimations(aiScene const& scene, std::vector<AnimData>& anims) noexcept;
|
static void ParseAnimations(aiScene const& scene, std::vector<AnimData>& anims) noexcept;
|
||||||
|
|
||||||
|
|
|
@ -198,7 +198,7 @@ namespace SH_COMP
|
||||||
auto currWriteNode = currPair.first;
|
auto currWriteNode = currPair.first;
|
||||||
auto currDataNode = currPair.second;
|
auto currDataNode = currPair.second;
|
||||||
|
|
||||||
dataToWrite.emplace_back(currDataNode->name, currDataNode->transform);
|
dataToWrite.emplace_back(currDataNode->name, currDataNode->transform, currDataNode->offset);
|
||||||
uint32_t idCounter = dataToWrite.size() + currDataNode->children.size() - 1;
|
uint32_t idCounter = dataToWrite.size() + currDataNode->children.size() - 1;
|
||||||
|
|
||||||
for (auto i{0}; i < currDataNode->children.size(); ++i)
|
for (auto i{0}; i < currDataNode->children.size(); ++i)
|
||||||
|
@ -221,6 +221,10 @@ namespace SH_COMP
|
||||||
reinterpret_cast<char const*>(&data.transform),
|
reinterpret_cast<char const*>(&data.transform),
|
||||||
sizeof(SHMat4)
|
sizeof(SHMat4)
|
||||||
);
|
);
|
||||||
|
file.write(
|
||||||
|
reinterpret_cast<char const*>(&data.offset),
|
||||||
|
sizeof(SHMat4)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -248,8 +252,6 @@ namespace SH_COMP
|
||||||
sizeof(uint32_t)
|
sizeof(uint32_t)
|
||||||
);
|
);
|
||||||
|
|
||||||
std::cout << "Write Node: " << node->id << ", " << node->children.size() << std::endl;;
|
|
||||||
|
|
||||||
for (auto child : node->children)
|
for (auto child : node->children)
|
||||||
{
|
{
|
||||||
nodeQueue.push(child);
|
nodeQueue.push(child);
|
||||||
|
|
|
@ -21,5 +21,18 @@ namespace SH_COMP
|
||||||
struct SHMat4
|
struct SHMat4
|
||||||
{
|
{
|
||||||
float data[16];
|
float data[16];
|
||||||
|
|
||||||
|
bool operator==(SHMat4 const& rhs) const
|
||||||
|
{
|
||||||
|
for (auto i {0}; i < 16; ++i)
|
||||||
|
{
|
||||||
|
if (data[i] != rhs.data[i])
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
|
@ -21,6 +21,7 @@ namespace SH_COMP
|
||||||
|
|
||||||
std::string name;
|
std::string name;
|
||||||
SHMat4 transform;
|
SHMat4 transform;
|
||||||
|
SHMat4 offset;
|
||||||
std::vector<RigNodeData*> children;
|
std::vector<RigNodeData*> children;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -28,6 +29,7 @@ namespace SH_COMP
|
||||||
{
|
{
|
||||||
std::string name;
|
std::string name;
|
||||||
SHMat4 transform;
|
SHMat4 transform;
|
||||||
|
SHMat4 offset;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct RigWriteNode
|
struct RigWriteNode
|
||||||
|
|
Loading…
Reference in New Issue