Asset.cpp 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #include <Atomic/IO/FileSystem.h>
  2. #include "ModelImporter.h"
  3. #include "FolderImporter.h"
  4. #include "Asset.h"
  5. namespace ToolCore
  6. {
  7. Asset::Asset(Context* context, const String& guid, unsigned timestamp) :
  8. Object(context),
  9. guid_(guid),
  10. dirty_(false),
  11. isFolder_(false)
  12. {
  13. }
  14. Asset::~Asset()
  15. {
  16. }
  17. bool Asset::Import()
  18. {
  19. if (importer_.Null())
  20. return true;
  21. return importer_->Import(guid_);
  22. }
  23. void Asset::SetPath(const String& path)
  24. {
  25. FileSystem* fs = GetSubsystem<FileSystem>();
  26. path_ = path;
  27. if (importer_.Null())
  28. {
  29. if (fs->DirExists(path))
  30. {
  31. name_ = GetFileName(RemoveTrailingSlash(path));
  32. isFolder_ = true;
  33. importer_ = new FolderImporter(context_);
  34. }
  35. else
  36. {
  37. String ext = GetExtension(path);
  38. // todo, externalize recognizers
  39. if (ext == ".fbx")
  40. {
  41. name_ = GetFileName(path);
  42. importer_ = new ModelImporter(context_);
  43. }
  44. }
  45. String assetPath = path + ".asset";
  46. if (fs->FileExists(assetPath))
  47. {
  48. importer_->Load(guid_);
  49. }
  50. else
  51. {
  52. importer_->Save(guid_);
  53. }
  54. SetDirty(importer_->IsDirty());
  55. }
  56. }
  57. }