Animation WIP merge #321
|
@ -18,6 +18,13 @@
|
||||||
|
|
||||||
namespace SHADE
|
namespace SHADE
|
||||||
{
|
{
|
||||||
|
constexpr int BONE_INDEX_ALIGHTMENT = 4;
|
||||||
|
|
||||||
|
struct IndexUInt4
|
||||||
|
{
|
||||||
|
std::array<uint32_t,BONE_INDEX_ALIGHTMENT> indices;
|
||||||
|
};
|
||||||
|
|
||||||
struct SHMeshDataHeader
|
struct SHMeshDataHeader
|
||||||
{
|
{
|
||||||
uint32_t vertexCount;
|
uint32_t vertexCount;
|
||||||
|
@ -48,12 +55,12 @@ namespace SHADE
|
||||||
struct SH_API SHMeshAsset : SHAssetData
|
struct SH_API SHMeshAsset : SHAssetData
|
||||||
{
|
{
|
||||||
std::string name;
|
std::string name;
|
||||||
std::vector<SHVec3> VertexPositions;
|
std::vector<SHVec3> VertexPositions;
|
||||||
std::vector<SHVec3> VertexTangents;
|
std::vector<SHVec3> VertexTangents;
|
||||||
std::vector<SHVec3> VertexNormals;
|
std::vector<SHVec3> VertexNormals;
|
||||||
std::vector<SHVec2> VertexTexCoords;
|
std::vector<SHVec2> VertexTexCoords;
|
||||||
std::vector<uint32_t> Indices;
|
std::vector<uint32_t> Indices;
|
||||||
std::vector<int> VertexBoneIndices;
|
std::vector<IndexUInt4> VertexBoneIndices;
|
||||||
std::vector<SHVec4> VertexBoneWeights;
|
std::vector<SHVec4> VertexBoneWeights;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -222,33 +222,50 @@ namespace SHADE
|
||||||
file.read(reinterpret_cast<char*>(data.VertexNormals.data()), vertexVec3Byte);
|
file.read(reinterpret_cast<char*>(data.VertexNormals.data()), vertexVec3Byte);
|
||||||
file.read(reinterpret_cast<char*>(data.VertexTexCoords.data()), vertexVec2Byte);
|
file.read(reinterpret_cast<char*>(data.VertexTexCoords.data()), vertexVec2Byte);
|
||||||
file.read(reinterpret_cast<char*>(data.Indices.data()), sizeof(uint32_t) * header.indexCount);
|
file.read(reinterpret_cast<char*>(data.Indices.data()), sizeof(uint32_t) * header.indexCount);
|
||||||
|
|
||||||
std::vector<MeshBoneInfo> boneInfos(header.boneCount);
|
|
||||||
std::vector<MeshBone> bones(header.boneCount);
|
|
||||||
|
|
||||||
file.read(reinterpret_cast<char*>(boneInfos.data()), sizeof(MeshBoneInfo) * header.boneCount);
|
if (header.boneCount)
|
||||||
|
|
||||||
for (auto i{ 0 }; i < header.boneCount; ++i)
|
|
||||||
{
|
{
|
||||||
auto& bone = bones[i];
|
std::vector<MeshBoneInfo> boneInfos(header.boneCount);
|
||||||
auto const& info = boneInfos[i];
|
std::vector<MeshBone> bones(header.boneCount);
|
||||||
|
|
||||||
bone.name.resize(info.charCount);
|
file.read(reinterpret_cast<char*>(boneInfos.data()), sizeof(MeshBoneInfo) * header.boneCount);
|
||||||
file.read(bone.name.data(), info.charCount);
|
|
||||||
file.read(reinterpret_cast<char*>(&bone.offset), sizeof(SHMatrix));
|
|
||||||
|
|
||||||
uint32_t weightCount;
|
for (auto i{ 0 }; i < header.boneCount; ++i)
|
||||||
file.read(reinterpret_cast<char*>(&weightCount), sizeof(uint32_t));
|
{
|
||||||
bone.weights.resize(weightCount);
|
auto& bone = bones[i];
|
||||||
file.read(reinterpret_cast<char*>(bone.weights.data()), sizeof(BoneWeight) * weightCount);
|
auto const& info = boneInfos[i];
|
||||||
}
|
|
||||||
|
|
||||||
data.VertexBoneIndices.resize(header.vertexCount);
|
bone.name.resize(info.charCount);
|
||||||
data.VertexBoneWeights.resize(header.vertexCount);
|
file.read(bone.name.data(), info.charCount);
|
||||||
|
file.read(reinterpret_cast<char*>(&bone.offset), sizeof(SHMatrix));
|
||||||
|
|
||||||
for (auto const& bone : bones)
|
uint32_t weightCount;
|
||||||
{
|
file.read(reinterpret_cast<char*>(&weightCount), sizeof(uint32_t));
|
||||||
|
bone.weights.resize(weightCount);
|
||||||
|
file.read(reinterpret_cast<char*>(bone.weights.data()), sizeof(BoneWeight) * weightCount);
|
||||||
|
}
|
||||||
|
|
||||||
|
data.VertexBoneIndices.resize(header.vertexCount);
|
||||||
|
data.VertexBoneWeights.resize(header.vertexCount);
|
||||||
|
|
||||||
|
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;
|
meshes[i] = &data;
|
||||||
|
|
Loading…
Reference in New Issue