TextureImporter.cpp 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #include <Atomic/Resource/ResourceCache.h>
  2. #include <Atomic/Resource/Image.h>
  3. #include "Asset.h"
  4. #include "AssetDatabase.h"
  5. #include "TextureImporter.h"
  6. namespace ToolCore
  7. {
  8. TextureImporter::TextureImporter(Context* context, Asset *asset) : AssetImporter(context, asset)
  9. {
  10. }
  11. TextureImporter::~TextureImporter()
  12. {
  13. }
  14. void TextureImporter::SetDefaults()
  15. {
  16. AssetImporter::SetDefaults();
  17. }
  18. bool TextureImporter::Import(const String& guid)
  19. {
  20. AssetDatabase* db = GetSubsystem<AssetDatabase>();
  21. Asset* asset = db->GetAssetByGUID(guid);
  22. if (!asset)
  23. return false;
  24. ResourceCache* cache = GetSubsystem<ResourceCache>();
  25. SharedPtr<Image> image = cache->GetTempResource<Image>(asset->GetPath());
  26. if (image.Null())
  27. return false;
  28. // todo, proper proportions
  29. image->Resize(64, 64);
  30. String cachePath = db->GetCachePath();
  31. // not sure entirely what we want to do here, though if the cache file doesn't exist
  32. // will reimport
  33. image->SavePNG(cachePath + asset->GetGUID());
  34. // save thumbnail
  35. image->SavePNG(cachePath + asset->GetGUID() + "_thumbnail.png");
  36. return true;
  37. }
  38. bool TextureImporter::LoadSettingsInternal()
  39. {
  40. if (!AssetImporter::LoadSettingsInternal())
  41. return false;
  42. JSONValue import = jsonRoot_.GetChild("TextureImporter", JSON_OBJECT);
  43. return true;
  44. }
  45. bool TextureImporter::SaveSettingsInternal()
  46. {
  47. if (!AssetImporter::SaveSettingsInternal())
  48. return false;
  49. JSONValue import = jsonRoot_.CreateChild("TextureImporter");
  50. return true;
  51. }
  52. }