Merge branch 'SP3-22-AnimationController' of https://github.com/SHADE-DP/SHADE_Y3 into SP3-22-AnimationController

This commit is contained in:
Kah Wei 2023-03-10 18:57:14 +08:00
commit b443f32388
4 changed files with 37 additions and 18 deletions

View File

@ -31,6 +31,6 @@ namespace SHADE
struct SH_API SHAnimClipContainerAsset final : SHAssetData
{
AssetID animRawDataAssetId;
std::vector<SHAnimClipAsset> clips{};
std::vector<SHAnimClipAsset*> clips{};
};
}

View File

@ -66,19 +66,19 @@ namespace SHADE
for (auto const& clip : anim.clips)
{
uint32_t charCount {static_cast<uint32_t>(clip.name.size())};
uint32_t charCount {static_cast<uint32_t>(clip->name.size())};
file.write(
reinterpret_cast<char const*>(&charCount),
sizeof(uint32_t)
);
file.write(
clip.name.data(),
clip->name.data(),
charCount
);
file.write(
reinterpret_cast<char const*>(&clip.firstIndex),
reinterpret_cast<char const*>(&clip->firstIndex),
sizeof(uint32_t) * 2
);
}
@ -99,28 +99,29 @@ namespace SHADE
reinterpret_cast<char*>(&size),
sizeof(uint32_t)
);
data->clips.resize(size);
for (auto i{0}; i < size; ++i)
for (auto& clip : data->clips)
{
auto& clip {data->clips.emplace_back()};
clip = new SHAnimClipAsset;
uint32_t charCount;
file.read(
reinterpret_cast<char*>(&charCount),
sizeof(uint32_t)
);
clip.name.resize(charCount);
clip->name.resize(charCount);
file.read(
clip.name.data(),
clip->name.data(),
charCount
);
file.read(
reinterpret_cast<char*>(&clip.firstIndex),
reinterpret_cast<char*>(&clip->firstIndex),
sizeof(uint32_t) * 2
);
clip.animRawDataAssetId = data->animRawDataAssetId;
clip->animRawDataAssetId = data->animRawDataAssetId;
}
result = data;

View File

@ -314,10 +314,10 @@ namespace SHADE
.parent = parent
};
auto& newClip {animContainer->clips.emplace_back()};
newClip.name = name;
newClip->name = name;
assetCollection.emplace(id, asset);
assetCollection[parent].subAssets.push_back(&assetCollection[id]);
assetData.emplace(id, &newClip);
assetData.emplace(id, newClip);
return id;
}
@ -639,6 +639,25 @@ namespace SHADE
assetData.emplace(asset.id, data);
}
switch (asset.type)
{
case AssetType::ANIM_CONTAINER:
{
auto container = reinterpret_cast<SHAnimClipContainerAsset*>(data);
for (auto i{0}; i < asset.subAssets.size(); ++i)
{
assetData.emplace(
asset.subAssets[i]->id,
container->clips[i]
);
}
}
break;
default:
break;
}
return data;
}
@ -646,7 +665,6 @@ namespace SHADE
{
auto const& parent = assetCollection[asset.parent];
auto parentData = loaders[static_cast<size_t>(parent.type)]->Load(parent.path);
if (parentData == nullptr)
{
SHLOG_ERROR("[Asset Manager] Unable to load asset into memory: {}\n", parent.path.string());
@ -676,7 +694,7 @@ namespace SHADE
{
assetData.emplace(
parent.subAssets[i]->id,
&parentContainer->clips[i]
parentContainer->clips[i]
);
}
}
@ -859,7 +877,7 @@ namespace SHADE
for(auto& clip : data->clips)
{
SHAsset subAsset{
.name = clip.name,
.name = clip->name,
.id = GenerateAssetID(AssetType::ANIM_CLIP),
.type = AssetType::ANIM_CLIP,
.isSubAsset = true,
@ -869,7 +887,7 @@ namespace SHADE
assetCollection.emplace(subAsset.id, subAsset);
assetCollection[newAsset.id].subAssets.push_back(&assetCollection[subAsset.id]);
assetData.emplace(subAsset.id, &clip);
assetData.emplace(subAsset.id, clip);
}
SHAssetMetaHandler::WriteMetaData(assetCollection[newAsset.id]);

View File

@ -194,10 +194,10 @@ namespace SHADE
auto assetId = SHResourceManager::GetAssetID(animClip);
if (assetId.has_value())
{
auto animAsset = SHAssetManager::GetData<SHAnimClipAsset>(assetId.value());
auto const animAsset = SHAssetManager::GetData<SHAnimClipAsset>(assetId.value());
animAsset->firstIndex = firstIndex;
animAsset->lastIndex = endIndex;
SHAssetManager::SaveAsset(assetId.value());
SHAssetManager::SaveAsset(containerAsset->id);
}
}