@@ -58,6 +58,9 @@ namespace sh::editor
5858
5959 uuids.insert_or_assign (relativePath, matPtr->GetUUID ());
6060 paths.insert_or_assign (matPtr->GetUUID (), AssetInfo{ relativePath, relativePath });
61+
62+ Meta meta{};
63+ meta.Save (*matPtr, GetMetaDirectory (projectPath / relativePath));
6164 return matPtr;
6265 }
6366 void AssetDatabase::SaveMaterial (render::Material* mat, const std::filesystem::path& dir)
@@ -144,7 +147,7 @@ namespace sh::editor
144147 {
145148 render::Texture* texture = reinterpret_cast <render::Texture*>(obj);
146149 Meta meta{};
147- meta.Save (*texture, GetMetaDirectory (projectPath / originalPath), false );
150+ meta.SaveWithObj (*texture, GetMetaDirectory (projectPath / originalPath), false );
148151 }
149152 }
150153 dirtyObjs.clear ();
@@ -231,7 +234,7 @@ namespace sh::editor
231234 uuids.insert_or_assign (relativePath, objPtr->GetUUID ());
232235 paths.insert_or_assign (objPtr->GetUUID (), AssetInfo{ relativePath, std::filesystem::relative (cachePath, projectPath) });
233236
234- meta.Save (*objPtr, metaDir);
237+ meta.SaveWithObj (*objPtr, metaDir);
235238 return objPtr;
236239 }
237240 AssetDatabase::AssetDatabase ()
@@ -336,7 +339,25 @@ namespace sh::editor
336339 return true ;
337340 }
338341
339- SH_EDITOR_API auto AssetDatabase::GetAssetUUID (const std::filesystem::path& assetPath) -> std::optional<core::UUID>
342+ SH_EDITOR_API auto AssetDatabase::GetAsset (const core::UUID& uuid) -> std::unique_ptr<core::Asset>
343+ {
344+ auto it = paths.find (uuid);
345+ if (it == paths.end ())
346+ return nullptr ;
347+
348+ return core::AssetImporter::Load (projectPath / it->second .cachePath );
349+ }
350+
351+ auto AssetDatabase::GetAssetOriginalPath (const core::UUID& uuid) const -> std::optional<std::filesystem::path>
352+ {
353+ auto it = paths.find (uuid);
354+ if (it == paths.end ())
355+ return std::nullopt ;
356+
357+ return it->second .originalPath ;
358+ }
359+
360+ auto AssetDatabase::GetAssetUUID (const std::filesystem::path& assetPath) -> std::optional<core::UUID>
340361 {
341362 std::filesystem::path relativePath = std::filesystem::relative (assetPath, projectPath);
342363 auto it = uuids.find (relativePath);
0 commit comments