diff --git a/SHADE_Engine/src/Assets/Asset Types/SHAnimClipContainerAsset.h b/SHADE_Engine/src/Assets/Asset Types/SHAnimClipContainerAsset.h index 733119c0..28d3b697 100644 --- a/SHADE_Engine/src/Assets/Asset Types/SHAnimClipContainerAsset.h +++ b/SHADE_Engine/src/Assets/Asset Types/SHAnimClipContainerAsset.h @@ -31,6 +31,6 @@ namespace SHADE struct SH_API SHAnimClipContainerAsset final : SHAssetData { AssetID animRawDataAssetId; - std::vector clips{}; + std::vector clips{}; }; } diff --git a/SHADE_Engine/src/Assets/Libraries/Loaders/SHBinaryLoader.cpp b/SHADE_Engine/src/Assets/Libraries/Loaders/SHBinaryLoader.cpp index b59f6807..119bd9aa 100644 --- a/SHADE_Engine/src/Assets/Libraries/Loaders/SHBinaryLoader.cpp +++ b/SHADE_Engine/src/Assets/Libraries/Loaders/SHBinaryLoader.cpp @@ -66,19 +66,19 @@ namespace SHADE for (auto const& clip : anim.clips) { - uint32_t charCount {static_cast(clip.name.size())}; + uint32_t charCount {static_cast(clip->name.size())}; file.write( reinterpret_cast(&charCount), sizeof(uint32_t) ); file.write( - clip.name.data(), + clip->name.data(), charCount ); file.write( - reinterpret_cast(&clip.firstIndex), + reinterpret_cast(&clip->firstIndex), sizeof(uint32_t) * 2 ); } @@ -99,28 +99,29 @@ namespace SHADE reinterpret_cast(&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(&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(&clip.firstIndex), + reinterpret_cast(&clip->firstIndex), sizeof(uint32_t) * 2 ); - clip.animRawDataAssetId = data->animRawDataAssetId; + clip->animRawDataAssetId = data->animRawDataAssetId; } result = data; diff --git a/SHADE_Engine/src/Assets/SHAssetManager.cpp b/SHADE_Engine/src/Assets/SHAssetManager.cpp index fcd9c5b1..8cddaf2c 100644 --- a/SHADE_Engine/src/Assets/SHAssetManager.cpp +++ b/SHADE_Engine/src/Assets/SHAssetManager.cpp @@ -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(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(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]); diff --git a/SHADE_Engine/src/Editor/EditorWindow/RawAnimationInspector/SHRawAnimInspector.cpp b/SHADE_Engine/src/Editor/EditorWindow/RawAnimationInspector/SHRawAnimInspector.cpp index 6fb53eb5..332bf6e9 100644 --- a/SHADE_Engine/src/Editor/EditorWindow/RawAnimationInspector/SHRawAnimInspector.cpp +++ b/SHADE_Engine/src/Editor/EditorWindow/RawAnimationInspector/SHRawAnimInspector.cpp @@ -194,10 +194,10 @@ namespace SHADE auto assetId = SHResourceManager::GetAssetID(animClip); if (assetId.has_value()) { - auto animAsset = SHAssetManager::GetData(assetId.value()); + auto const animAsset = SHAssetManager::GetData(assetId.value()); animAsset->firstIndex = firstIndex; animAsset->lastIndex = endIndex; - SHAssetManager::SaveAsset(assetId.value()); + SHAssetManager::SaveAsset(containerAsset->id); } }