ImportCmd.cpp 2.1 KB

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