Animation WIP merge #321
|
@ -18,6 +18,13 @@
|
|||
|
||||
namespace SHADE
|
||||
{
|
||||
constexpr int BONE_INDEX_ALIGHTMENT = 4;
|
||||
|
||||
struct IndexUInt4
|
||||
{
|
||||
std::array<uint32_t,BONE_INDEX_ALIGHTMENT> indices;
|
||||
};
|
||||
|
||||
struct SHMeshDataHeader
|
||||
{
|
||||
uint32_t vertexCount;
|
||||
|
@ -53,7 +60,7 @@ namespace SHADE
|
|||
std::vector<SHVec3> VertexNormals;
|
||||
std::vector<SHVec2> VertexTexCoords;
|
||||
std::vector<uint32_t> Indices;
|
||||
std::vector<int> VertexBoneIndices;
|
||||
std::vector<IndexUInt4> VertexBoneIndices;
|
||||
std::vector<SHVec4> VertexBoneWeights;
|
||||
};
|
||||
}
|
||||
|
|
|
@ -223,6 +223,8 @@ namespace SHADE
|
|||
file.read(reinterpret_cast<char*>(data.VertexTexCoords.data()), vertexVec2Byte);
|
||||
file.read(reinterpret_cast<char*>(data.Indices.data()), sizeof(uint32_t) * header.indexCount);
|
||||
|
||||
if (header.boneCount)
|
||||
{
|
||||
std::vector<MeshBoneInfo> boneInfos(header.boneCount);
|
||||
std::vector<MeshBone> bones(header.boneCount);
|
||||
|
||||
|
@ -246,9 +248,24 @@ namespace SHADE
|
|||
data.VertexBoneIndices.resize(header.vertexCount);
|
||||
data.VertexBoneWeights.resize(header.vertexCount);
|
||||
|
||||
for (auto const& bone : bones)
|
||||
for (uint32_t boneIndex{0}; boneIndex < bones.size(); ++boneIndex)
|
||||
{
|
||||
auto const& bone = bones[boneIndex];
|
||||
for (auto const& weight : bone.weights)
|
||||
{
|
||||
auto& boneIndices = data.VertexBoneIndices[weight.index];
|
||||
auto& boneWeight = data.VertexBoneWeights[weight.index];
|
||||
|
||||
for (auto j{0}; j < BONE_INDEX_ALIGHTMENT; ++j)
|
||||
{
|
||||
if (boneWeight[j] == 0.f)
|
||||
{
|
||||
boneIndices.indices[j] = boneIndex;
|
||||
boneWeight[j] = weight.weight;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
meshes[i] = &data;
|
||||
|
|
Loading…
Reference in New Issue