Asset.cpp 1.5 KB

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