Animation WIP merge #321

Merged
XiaoQiDigipen merged 76 commits from SP3-17-animation-system into main 2023-01-30 17:35:57 +08:00
9 changed files with 35 additions and 13 deletions
Showing only changes of commit 2d1987e14b - Show all commits

View File

@ -58,7 +58,6 @@ namespace SHADE
std::vector<uint32_t> Indices;
std::vector<SHVec4U> VertexBoneIndices;
std::vector<SHVec4> VertexBoneWeights;
uint32_t boneCount;
uint32_t BoneCount;
};
}

View File

@ -221,7 +221,7 @@ namespace SHADE
data.VertexNormals.resize(header.vertexCount);
data.VertexTexCoords.resize(header.vertexCount);
data.Indices.resize(header.indexCount);
data.boneCount = header.boneCount;
data.BoneCount = header.boneCount;
file.read(data.name.data(), header.charCount);
file.read(reinterpret_cast<char*>(data.VertexPositions.data()), vertexVec3Byte);

View File

@ -418,16 +418,31 @@ namespace SHADE
for (auto& subBatch : subBatches)
for (auto rendId : subBatch.Renderables)
{
// Get resources
auto animator = SHComponentManager::GetComponent_s<SHAnimatorComponent>(rendId);
auto renderable = SHComponentManager::GetComponent<SHRenderable>(rendId);
auto mesh = renderable->GetMesh();
// Add matrices
const int BONE_COUNT = static_cast<int>(mesh->BoneCount);
int extraMatricesToAdd = BONE_COUNT;
if (animator)
{
// Add matrices
const auto& MATRICES = animator->GetBoneMatrices();
boneMatrixData.insert(boneMatrixData.end(), MATRICES.cbegin(), MATRICES.cend());
if (MATRICES.size() <= BONE_COUNT)
{
boneMatrixData.insert(boneMatrixData.end(), MATRICES.cbegin(), MATRICES.cend());
extraMatricesToAdd = std::max({0, BONE_COUNT - static_cast<int>(MATRICES.size())});
}
}
else
// If we need to patch up with more matrices, add it
if (extraMatricesToAdd > 0)
{
// TODO: Populate with empty matrices
boneMatrixData.insert(boneMatrixData.end(), extraMatricesToAdd, SHMatrix::Identity);
}
// We don't have to account for missing animators or reset indices as the renderable list are not updated at this point
}

View File

@ -797,9 +797,9 @@ namespace SHADE
/*---------------------------------------------------------------------------------*/
/* Mesh Registration Functions */
/*---------------------------------------------------------------------------------*/
SHADE::Handle<SHADE::SHMesh> SHGraphicsSystem::AddMesh(uint32_t vertexCount, const SHMesh::VertexPosition* const positions, const SHMesh::VertexTexCoord* const texCoords, const SHMesh::VertexTangent* const tangents, const SHMesh::VertexNormal* const normals, uint32_t indexCount, const SHMesh::Index* const indices, const SHMesh::VertexBoneIndices* const boneIndices, const SHMesh::VertexWeights* const boneWeights)
SHADE::Handle<SHADE::SHMesh> SHGraphicsSystem::AddMesh(uint32_t vertexCount, const SHMesh::VertexPosition* const positions, const SHMesh::VertexTexCoord* const texCoords, const SHMesh::VertexTangent* const tangents, const SHMesh::VertexNormal* const normals, uint32_t indexCount, const SHMesh::Index* const indices, const SHMesh::VertexBoneIndices* const boneIndices, const SHMesh::VertexWeights* const boneWeights, uint32_t boneCount)
{
return meshLibrary.AddMesh(vertexCount, positions, texCoords, tangents, normals, boneIndices, boneWeights, indexCount, indices);
return meshLibrary.AddMesh(vertexCount, positions, texCoords, tangents, normals, boneIndices, boneWeights, indexCount, indices, boneCount);
}
void SHGraphicsSystem::RemoveMesh(Handle<SHMesh> mesh)

View File

@ -229,7 +229,7 @@ namespace SHADE
*/
/*******************************************************************************/
Handle<SHMesh> AddMesh(uint32_t vertexCount, const SHMesh::VertexPosition* const positions, const SHMesh::VertexTexCoord* const texCoords, const SHMesh::VertexTangent* const tangents, const SHMesh::VertexNormal* const normals, uint32_t indexCount, const SHMesh::Index* const indices, const SHMesh::VertexBoneIndices* const boneIndices = nullptr, const SHMesh::VertexWeights* const boneWeights = nullptr);
Handle<SHMesh> AddMesh(uint32_t vertexCount, const SHMesh::VertexPosition* const positions, const SHMesh::VertexTexCoord* const texCoords, const SHMesh::VertexTangent* const tangents, const SHMesh::VertexNormal* const normals, uint32_t indexCount, const SHMesh::Index* const indices, const SHMesh::VertexBoneIndices* const boneIndices = nullptr, const SHMesh::VertexWeights* const boneWeights = nullptr, uint32_t boneCount = 0);
/*******************************************************************************/
/*!

View File

@ -28,7 +28,8 @@ namespace SHADE
const SHMesh::VertexNormal* const normals,
const SHMesh::VertexBoneIndices* const boneIndices,
const SHMesh::VertexWeights* const boneWeights,
uint32_t indexCount, const SHMesh::Index* const indices)
uint32_t indexCount, const SHMesh::Index* const indices,
uint32_t boneCount)
{
isDirty = true;
@ -44,6 +45,7 @@ namespace SHADE
boneWeights,
indexCount,
indices,
boneCount,
handle
});
return handle;
@ -140,6 +142,7 @@ namespace SHADE
.VertexCount = static_cast<uint32_t>(addJob.VertexCount),
.FirstIndex = static_cast<uint32_t>(indexStorage.size()),
.IndexCount = static_cast<uint32_t>(addJob.IndexCount),
.BoneCount = addJob.BoneCount
};
// Copy into storage

View File

@ -61,6 +61,7 @@ namespace SHADE
uint32_t VertexCount;
uint32_t FirstIndex;
uint32_t IndexCount;
uint32_t BoneCount;
};
/***********************************************************************************/
/*!
@ -115,7 +116,8 @@ namespace SHADE
const SHMesh::VertexNormal* const normals,
const SHMesh::VertexBoneIndices* const boneIndices,
const SHMesh::VertexWeights* const boneWeights,
uint32_t indexCount, const SHMesh::Index* const indices);
uint32_t indexCount, const SHMesh::Index* const indices,
uint32_t boneCount);
/*******************************************************************************/
/*!
@ -173,6 +175,7 @@ namespace SHADE
const SHMesh::VertexWeights* VertexBoneWeights = nullptr;
uint32_t IndexCount = 0;
const SHMesh::Index* Indices = nullptr;
uint32_t BoneCount = 0;
Handle<SHMesh> Handle;
};
/*-----------------------------------------------------------------------------*/

View File

@ -407,7 +407,8 @@ namespace SHADE
nullptr,
nullptr,
static_cast<uint32_t>(meshData.Indices.size()),
meshData.Indices.data()
meshData.Indices.data(),
0
);
}

View File

@ -218,7 +218,8 @@ namespace SHADE
assetData.Indices.size(),
assetData.Indices.data(),
assetData.VertexBoneIndices.empty() ? nullptr : assetData.VertexBoneIndices.data(),
assetData.VertexBoneWeights.empty() ? nullptr : assetData.VertexBoneWeights.data()
assetData.VertexBoneWeights.empty() ? nullptr : assetData.VertexBoneWeights.data(),
assetData.BoneCount
);
}
// Textures