TextureImporter.cpp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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()
  19. {
  20. AssetDatabase* db = GetSubsystem<AssetDatabase>();
  21. ResourceCache* cache = GetSubsystem<ResourceCache>();
  22. SharedPtr<Image> image = cache->GetTempResource<Image>(asset_->GetPath());
  23. if (image.Null())
  24. return false;
  25. // todo, proper proportions
  26. image->Resize(64, 64);
  27. String cachePath = db->GetCachePath();
  28. // not sure entirely what we want to do here, though if the cache file doesn't exist
  29. // will reimport
  30. image->SavePNG(cachePath + asset_->GetGUID());
  31. // save thumbnail
  32. image->SavePNG(cachePath + asset_->GetGUID() + "_thumbnail.png");
  33. return true;
  34. }
  35. bool TextureImporter::LoadSettingsInternal()
  36. {
  37. if (!AssetImporter::LoadSettingsInternal())
  38. return false;
  39. JSONValue import = jsonRoot_.GetChild("TextureImporter", JSON_OBJECT);
  40. return true;
  41. }
  42. bool TextureImporter::SaveSettingsInternal()
  43. {
  44. if (!AssetImporter::SaveSettingsInternal())
  45. return false;
  46. JSONValue import = jsonRoot_.CreateChild("TextureImporter");
  47. return true;
  48. }
  49. }