Added handling for rendering objects using an animated shader but without an animator component or an attached rig

This commit is contained in:
Kah Wei 2023-01-29 19:27:58 +08:00
parent 741489b0ae
commit 2d1987e14b
9 changed files with 35 additions and 13 deletions

View File

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

View File

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

View File

@ -418,16 +418,31 @@ namespace SHADE
for (auto& subBatch : subBatches) for (auto& subBatch : subBatches)
for (auto rendId : subBatch.Renderables) for (auto rendId : subBatch.Renderables)
{ {
// Get resources
auto animator = SHComponentManager::GetComponent_s<SHAnimatorComponent>(rendId); 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) if (animator)
{ {
// Add matrices
const auto& MATRICES = animator->GetBoneMatrices(); 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 // 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 */ /* 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) 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::VertexNormal* const normals,
const SHMesh::VertexBoneIndices* const boneIndices, const SHMesh::VertexBoneIndices* const boneIndices,
const SHMesh::VertexWeights* const boneWeights, 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; isDirty = true;
@ -44,6 +45,7 @@ namespace SHADE
boneWeights, boneWeights,
indexCount, indexCount,
indices, indices,
boneCount,
handle handle
}); });
return handle; return handle;
@ -140,6 +142,7 @@ namespace SHADE
.VertexCount = static_cast<uint32_t>(addJob.VertexCount), .VertexCount = static_cast<uint32_t>(addJob.VertexCount),
.FirstIndex = static_cast<uint32_t>(indexStorage.size()), .FirstIndex = static_cast<uint32_t>(indexStorage.size()),
.IndexCount = static_cast<uint32_t>(addJob.IndexCount), .IndexCount = static_cast<uint32_t>(addJob.IndexCount),
.BoneCount = addJob.BoneCount
}; };
// Copy into storage // Copy into storage

View File

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

View File

@ -407,7 +407,8 @@ namespace SHADE
nullptr, nullptr,
nullptr, nullptr,
static_cast<uint32_t>(meshData.Indices.size()), 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.size(),
assetData.Indices.data(), assetData.Indices.data(),
assetData.VertexBoneIndices.empty() ? nullptr : assetData.VertexBoneIndices.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 // Textures