ImportConfig.cpp 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. //
  2. // Copyright (c) 2014-2015, THUNDERBEAST GAMES LLC All rights reserved
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to deal
  6. // in the Software without restriction, including without limitation the rights
  7. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. // copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. // THE SOFTWARE.
  21. //
  22. #include "../../Atomic/Core/Context.h"
  23. #include "../../Atomic/IO/Log.h"
  24. #include "../../Atomic/IO/File.h"
  25. #include "../../Atomic/IO/FileSystem.h"
  26. #include "../Atomic/Resource/JSONFile.h"
  27. #include "../../Atomic/Graphics/GraphicsDefs.h"
  28. #include "ImportConfig.h"
  29. namespace Atomic
  30. {
  31. ImportConfig ImportConfig::importConfig_;
  32. bool ImportConfig::LoadModelImporterConfig(const JSONValue& jModelImporterConfig)
  33. {
  34. const JSONValue& jflags = jModelImporterConfig["aiFlagsDefault"];
  35. if (!jflags.IsObject())
  36. return false;
  37. for (JSONObject::ConstIterator i = jflags.Begin(); i != jflags.End(); ++i)
  38. {
  39. String key = i->first_;
  40. const JSONValue& jvalue = i->second_;
  41. if (key == "convertToLeftHanded")
  42. valueMap_["aiProcess_ConvertToLeftHanded"] = GetBoolValue(jvalue, true);
  43. else if (key == "joinIdenticalVertices")
  44. valueMap_["aiProcess_JoinIdenticalVertices"] = GetBoolValue(jvalue, true);
  45. else if (key == "triangulate")
  46. valueMap_["aiProcess_Triangulate"] = GetBoolValue(jvalue, true);
  47. else if (key == "genSmoothNormals")
  48. valueMap_["aiProcess_GenSmoothNormals"] = GetBoolValue(jvalue, true);
  49. else if (key == "limitBoneWeights")
  50. valueMap_["aiProcess_LimitBoneWeights"] = GetBoolValue(jvalue, true);
  51. else if (key == "improveCacheLocality")
  52. valueMap_["aiProcess_ImproveCacheLocality"] = GetBoolValue(jvalue, true);
  53. else if (key == "fixInFacingNormals")
  54. valueMap_["aiProcess_FixInfacingNormals"] = GetBoolValue(jvalue, true);
  55. else if (key == "findInvalidData")
  56. valueMap_["aiProcess_FindInvalidData"] = GetBoolValue(jvalue, true);
  57. else if (key == "genUVCoords")
  58. valueMap_["aiProcess_GenUVCoords"] = GetBoolValue(jvalue, true);
  59. else if (key == "findInstances")
  60. valueMap_["aiProcess_FindInstances"] = GetBoolValue(jvalue, true);
  61. else if (key == "optimizeMeshes")
  62. valueMap_["aiProcess_OptimizeMeshes"] = GetBoolValue(jvalue, true);
  63. else if (key == "importMaterials")
  64. valueMap_["ImportMaterials"] = GetBoolValue(jvalue, true);
  65. else if (key == "includeNonSkinningBones")
  66. valueMap_["IncludeNonSkinningBones"] = GetBoolValue(jvalue, true);
  67. else if (key == "useVertexColors")
  68. valueMap_["useVertexColors"] = GetBoolValue(jvalue, false);
  69. }
  70. return true;
  71. }
  72. bool ImportConfig::LoadTextureImporterConfig(const JSONValue& jTextureImporterConfig)
  73. {
  74. for (JSONObject::ConstIterator i = jTextureImporterConfig.Begin(); i != jTextureImporterConfig.End(); ++i)
  75. {
  76. String key = i->first_;
  77. const JSONValue& jvalue = i->second_;
  78. if (key == "compressTextures")
  79. valueMap_["tiProcess_CompressTextures"] = GetBoolValue(jvalue, false);
  80. }
  81. return true;
  82. }
  83. bool ImportConfig::LoadDesktopConfig(JSONValue root)
  84. {
  85. const JSONValue& jdesktop = root["desktop"];
  86. if (!jdesktop.IsObject())
  87. return false;
  88. const JSONValue& jModelImporterConfig = jdesktop["ModelImporter"];
  89. if (jModelImporterConfig.IsObject())
  90. LoadModelImporterConfig(jModelImporterConfig);
  91. const JSONValue& jTextureImporterConfig = jdesktop["TextureImporter"];
  92. if (jTextureImporterConfig.IsObject())
  93. LoadTextureImporterConfig(jTextureImporterConfig);
  94. return true;
  95. }
  96. }