ImportCmd.cpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. //
  2. // Copyright (c) 2014-2015, THUNDERBEAST GAMES LLC All rights reserved
  3. // LICENSE: Atomic Game Engine Editor and Tools EULA
  4. // Please see LICENSE_ATOMIC_EDITOR_AND_TOOLS.md in repository root for
  5. // license information: https://github.com/AtomicGameEngine/AtomicGameEngine
  6. //
  7. #include <Atomic/Core/StringUtils.h>
  8. #include <Atomic/IO/Log.h>
  9. #include <Atomic/IO/File.h>
  10. #include "../ToolSystem.h"
  11. #include "../Project/Project.h"
  12. #include "../Import/JSONSceneImporter.h"
  13. #include "../Import/JSONSceneProcess.h"
  14. #include "../Import/OpenAssetImporter.h"
  15. #include "ImportCmd.h"
  16. #include <Poco/File.h>
  17. namespace ToolCore
  18. {
  19. ImportCmd::ImportCmd(Context* context) : Command(context)
  20. {
  21. }
  22. ImportCmd::~ImportCmd()
  23. {
  24. }
  25. bool ImportCmd::Parse(const Vector<String>& arguments, unsigned startIndex, String& errorMsg)
  26. {
  27. String argument = arguments[startIndex].ToLower();
  28. String value = startIndex + 1 < arguments.Size() ? arguments[startIndex + 1] : String::EMPTY;
  29. if (argument != "import")
  30. {
  31. errorMsg = "Unable to parse import command";
  32. return false;
  33. }
  34. if (!value.Length())
  35. {
  36. errorMsg = "Unable to parse source JSON filename";
  37. return false;
  38. }
  39. assetFilename_ = value;
  40. return true;
  41. }
  42. void ImportCmd::Run()
  43. {
  44. ToolSystem* tsystem = GetSubsystem<ToolSystem>();
  45. Project* project = tsystem->GetProject();
  46. String resourcePath = project->GetResourcePath();
  47. String ext = GetExtension(assetFilename_);
  48. if (ext == ".json")
  49. {
  50. Poco::File file(assetFilename_.CString());
  51. if (!file.exists())
  52. {
  53. Error(ToString("JSON source scene does not exist: %s", assetFilename_.CString()));
  54. return;
  55. }
  56. LOGRAWF("Importing JSON: %s", assetFilename_.CString());
  57. SharedPtr<JSONSceneImporter> jimporter;
  58. jimporter = new JSONSceneImporter(context_);
  59. jimporter->Import(assetFilename_);
  60. SharedPtr<JSONSceneProcess> sceneProcess;
  61. sceneProcess = new JSONSceneProcess(context_, jimporter);
  62. sceneProcess->Process(resourcePath);
  63. sceneProcess->Write();
  64. }
  65. else
  66. {
  67. SharedPtr<OpenAssetImporter> importer(new OpenAssetImporter(context_));
  68. if (importer->Load(assetFilename_))
  69. {
  70. importer->ExportModel("/Users/josh/Desktop/ExportedModel.mdl");
  71. }
  72. }
  73. Finished();
  74. }
  75. }