Fixed certain crashes when assigning rig and clip

This commit is contained in:
Kah Wei 2023-01-12 20:04:49 +08:00
parent 406759f856
commit d1ab595126
3 changed files with 26 additions and 19 deletions

View File

@ -85,7 +85,11 @@ namespace SHADE
currClip = newClip; currClip = newClip;
secsPerTick = 1.0f / currClip->GetTicksPerSecond(); secsPerTick = 1.0f / currClip->GetTicksPerSecond();
updatePoseWithClip(0.0f);
if (!rig)
{
updatePoseWithClip(0.0f);
}
} }
/*-----------------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------------*/
@ -94,7 +98,7 @@ namespace SHADE
void SHAnimatorComponent::Update(float dt) void SHAnimatorComponent::Update(float dt)
{ {
// Nothing to animate // Nothing to animate
if (!currClip || !isPlaying) if (!currClip || !isPlaying || !rig)
return; return;
// Update time on the playback // Update time on the playback

View File

@ -597,7 +597,7 @@ namespace SHADE
}, },
[component](AssetID const& id) [component](AssetID const& id)
{ {
if (SHAssetManager::GetType(id) != AssetType::MESH) if (SHAssetManager::GetType(id) != AssetType::MODEL)
{ {
SHLOG_WARNING("Attempted to assign non mesh asset to Renderable Mesh property!") SHLOG_WARNING("Attempted to assign non mesh asset to Renderable Mesh property!")
return; return;
@ -608,7 +608,7 @@ namespace SHADE
Handle<SHAnimationClip> const& clip = component->GetCurrentClip(); Handle<SHAnimationClip> const& clip = component->GetCurrentClip();
const auto CLIP_NAME = rig ? SHResourceManager::GetAssetName<SHAnimationClip>(clip).value_or("") : ""; const auto CLIP_NAME = rig ? SHResourceManager::GetAssetName<SHAnimationClip>(clip).value_or("") : "";
SHEditorWidgets::DragDropReadOnlyField<AssetID>("Material", CLIP_NAME, SHEditorWidgets::DragDropReadOnlyField<AssetID>("Clip", CLIP_NAME,
[component]() [component]()
{ {
Handle<SHAnimationClip> const& clip = component->GetCurrentClip(); Handle<SHAnimationClip> const& clip = component->GetCurrentClip();
@ -616,7 +616,7 @@ namespace SHADE
}, },
[component](AssetID const& id) [component](AssetID const& id)
{ {
if (SHAssetManager::GetType(id) != AssetType::MESH) if (SHAssetManager::GetType(id) != AssetType::MODEL)
{ {
SHLOG_WARNING("Attempted to assign non mesh asset to Renderable Mesh property!") SHLOG_WARNING("Attempted to assign non mesh asset to Renderable Mesh property!")
return; return;

View File

@ -648,15 +648,19 @@ namespace SHADE
using PreDefDescLayoutType = SHGraphicsPredefinedData::PredefinedDescSetLayoutTypes; using PreDefDescLayoutType = SHGraphicsPredefinedData::PredefinedDescSetLayoutTypes;
static constexpr uint32_t MATERIAL_DESC_SET_INDEX = 0; static constexpr uint32_t MATERIAL_DESC_SET_INDEX = 0;
// Flags
bool descSetUpdateRequired = false;
/* Create Descriptor Sets if Needed */ /* Create Descriptor Sets if Needed */
std::vector<uint32_t> varDescCounts;
PreDefDescLayoutType layoutTypes = {}; PreDefDescLayoutType layoutTypes = {};
if (matPropsData) if (matPropsData)
{
layoutTypes |= PreDefDescLayoutType::MATERIALS; layoutTypes |= PreDefDescLayoutType::MATERIALS;
varDescCounts.push_back(0);
}
if (!boneMatrixData.empty()) if (!boneMatrixData.empty())
{
layoutTypes |= PreDefDescLayoutType::BONES; layoutTypes |= PreDefDescLayoutType::BONES;
varDescCounts.push_back(0);
}
if (matPropsData || !boneMatrixData.empty()) if (matPropsData || !boneMatrixData.empty())
{ {
@ -666,7 +670,7 @@ namespace SHADE
instanceDataDescSet[frameIndex] = descPool->Allocate instanceDataDescSet[frameIndex] = descPool->Allocate
( (
SHGraphicsPredefinedData::GetPredefinedDescSetLayouts(layoutTypes), SHGraphicsPredefinedData::GetPredefinedDescSetLayouts(layoutTypes),
{ 0 } varDescCounts
); );
#ifdef _DEBUG #ifdef _DEBUG
const auto& DESC_SETS = instanceDataDescSet[frameIndex]->GetVkHandle(); const auto& DESC_SETS = instanceDataDescSet[frameIndex]->GetVkHandle();
@ -699,7 +703,12 @@ namespace SHADE
0, static_cast<uint32_t>(matPropsDataSize) 0, static_cast<uint32_t>(matPropsDataSize)
); );
descSetUpdateRequired = true; // Update the descriptor set buffer
instanceDataDescSet[frameIndex]->UpdateDescriptorSetBuffer
(
MATERIAL_DESC_SET_INDEX,
SHGraphicsConstants::DescriptorSetBindings::PER_INST_MATERIAL_DATA
);
} }
/* Animation Bone Data */ /* Animation Bone Data */
@ -713,7 +722,7 @@ namespace SHADE
BuffUsage::eVertexBuffer, BuffUsage::eVertexBuffer,
"Batch Bone Indices Buffer" "Batch Bone Indices Buffer"
); );
const uint32_t BONE_MTX_DATA_BYTES = static_cast<uint32_t>(boneMatrixData.size() * sizeof(uint32_t)); const uint32_t BONE_MTX_DATA_BYTES = static_cast<uint32_t>(boneMatrixData.size() * sizeof(SHMatrix));
SHVkUtil::EnsureBufferAndCopyHostVisibleData SHVkUtil::EnsureBufferAndCopyHostVisibleData
( (
device, boneMatrixBuffer[frameIndex], boneMatrixData.data(), BONE_MTX_DATA_BYTES, device, boneMatrixBuffer[frameIndex], boneMatrixData.data(), BONE_MTX_DATA_BYTES,
@ -728,21 +737,15 @@ namespace SHADE
MATERIAL_DESC_SET_INDEX, MATERIAL_DESC_SET_INDEX,
SHGraphicsConstants::DescriptorSetBindings::PER_INST_BONE_DATA, SHGraphicsConstants::DescriptorSetBindings::PER_INST_BONE_DATA,
bufferList, bufferList,
static_cast<uint32_t>(matPropsDataSize), 0,
static_cast<uint32_t>(boneMatrixData.size() * sizeof(SHMatrix)) static_cast<uint32_t>(boneMatrixData.size() * sizeof(SHMatrix))
); );
descSetUpdateRequired = true;
}
// Build and prepare the descriptor set if necessary
if (descSetUpdateRequired)
{
// Update the descriptor set buffer // Update the descriptor set buffer
instanceDataDescSet[frameIndex]->UpdateDescriptorSetBuffer instanceDataDescSet[frameIndex]->UpdateDescriptorSetBuffer
( (
MATERIAL_DESC_SET_INDEX, MATERIAL_DESC_SET_INDEX,
SHGraphicsConstants::DescriptorSetBindings::PER_INST_MATERIAL_DATA SHGraphicsConstants::DescriptorSetBindings::PER_INST_BONE_DATA
); );
} }
} }