TextureImporter.cpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. Resource* TextureImporter::GetResource(const String& typeName)
  50. {
  51. if (!typeName.Length())
  52. return 0;
  53. ResourceCache* cache = GetSubsystem<ResourceCache>();
  54. return cache->GetResource(typeName, asset_->GetPath());
  55. }
  56. }