Asset.cpp 1.7 KB

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