OpenAssetImporter.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. //
  2. // Copyright (c) 2008-2015 the Urho3D project.
  3. //
  4. // Copyright (c) 2014-2016 THUNDERBEAST GAMES LLC
  5. //
  6. // Permission is hereby granted, free of charge, to any person obtaining a copy
  7. // of this software and associated documentation files (the "Software"), to deal
  8. // in the Software without restriction, including without limitation the rights
  9. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  10. // copies of the Software, and to permit persons to whom the Software is
  11. // furnished to do so, subject to the following conditions:
  12. //
  13. // The above copyright notice and this permission notice shall be included in
  14. // all copies or substantial portions of the Software.
  15. //
  16. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  19. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  20. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  21. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  22. // THE SOFTWARE.
  23. //
  24. #pragma once
  25. #include "OpenAssetUtils.h"
  26. #include <Atomic/Core/Object.h>
  27. #include <Atomic/Scene/Node.h>
  28. using namespace Atomic;
  29. namespace Atomic
  30. {
  31. class Model;
  32. }
  33. namespace ToolCore
  34. {
  35. class OpenAssetImporter : public Object
  36. {
  37. ATOMIC_OBJECT(OpenAssetImporter, Object)
  38. public:
  39. struct AnimationInfo
  40. {
  41. String name_;
  42. String cacheFilename_;
  43. };
  44. OpenAssetImporter(Context* context);
  45. virtual ~OpenAssetImporter();
  46. bool Load(const String& assetPath);
  47. const String& GetErrorMessage() { return errorMessage_; }
  48. bool ExportModel(const String& outName, const String& animName = String::EMPTY, bool animationOnly = false);
  49. void SetImportNode(Node* node) { importNode_ = node; }
  50. void SetStartTime(float startTime) { startTime_ = startTime; }
  51. void SetEndTime(float endTime) { endTime_ = endTime; }
  52. void SetScale(float scale) { scale_ = scale; }
  53. void SetExportAnimations(bool exportAnimations) { noAnimations_ = !exportAnimations; }
  54. void SetImportMaterials(bool importMaterials) { importMaterials_ = importMaterials; }
  55. void SetIncludeNonSkinningBones(bool includeNonSkinningBones) { includeNonSkinningBones_ = includeNonSkinningBones; }
  56. void SetVerboseLog(bool verboseLog) { verboseLog_ = verboseLog; }
  57. bool GetImportMaterialsDefault() { return importMaterialsDefault_; }
  58. bool GetIncludeNonSkinningBones() { return includeNonSkinningBonesDefault_; }
  59. const Vector<AnimationInfo>& GetAnimationInfos() { return animationInfos_; }
  60. bool GetGenerateLightmapUV() const { return genLightmapUV_; }
  61. void SetGenerateLightmapUV(bool value) { genLightmapUV_ = value; }
  62. static bool GenerateLightmapUV(Model* model);
  63. private:
  64. void ApplyScale();
  65. void ApplyScale(aiNode* node);
  66. bool BuildAndSaveModel(OutModel& model);
  67. bool BuildAndSaveAnimations(OutModel* model = 0, const String& animNameOverride = String::EMPTY);
  68. void ExportMaterials(HashSet<String>& usedTextures);
  69. bool BuildAndSaveMaterial(aiMaterial* material, HashSet<String>& usedTextures);
  70. void CollectSceneModels(OutScene& scene, aiNode* node);
  71. bool CollectBones(OutModel& model, bool animationOnly = false);
  72. void CollectBonesFinal(PODVector<aiNode*>& dest, const HashSet<aiNode*>& necessary, aiNode* node);
  73. void BuildBoneCollisionInfo(OutModel& model);
  74. void CollectAnimations(OutModel* model = 0);
  75. void ApplyProjectImportConfig();
  76. void SetOveriddenFlags(VariantMap& aiFlagParameters);
  77. void ApplyFlag(int processStep, bool active);
  78. String GetMeshMaterialName(aiMesh* mesh);
  79. String GenerateMaterialName(aiMaterial* material);
  80. String GetMaterialTextureName(const String& nameIn);
  81. String GenerateTextureName(unsigned texIndex);
  82. // TODO: See AssetImporter
  83. // void CombineLods(const PODVector<float>& lodDistances, const Vector<String>& modelNames, const String& outName)
  84. void DumpNodes(aiNode* rootNode, unsigned level);
  85. String errorMessage_;
  86. const aiScene* scene_;
  87. aiNode* rootNode_;
  88. String inputName_;
  89. String sourceAssetPath_;
  90. String sourceAssetFilename_;
  91. String resourcePath_;
  92. String outPath_;
  93. bool useSubdirs_;
  94. bool importMaterials_;
  95. bool importMaterialsDefault_;
  96. bool localIDs_;
  97. bool saveBinary_;
  98. bool createZone_;
  99. bool noAnimations_;
  100. bool noHierarchy_;
  101. bool noMaterials_;
  102. bool noTextures_;
  103. bool noMaterialDiffuseColor_;
  104. bool noEmptyNodes_;
  105. bool saveMaterialList_;
  106. bool includeNonSkinningBones_;
  107. bool includeNonSkinningBonesDefault_;
  108. bool verboseLog_;
  109. bool emissiveAO_;
  110. bool noOverwriteMaterial_;
  111. bool noOverwriteTexture_;
  112. bool noOverwriteNewerTexture_;
  113. bool checkUniqueModel_;
  114. bool useVertexColors_;
  115. float scale_;
  116. unsigned maxBones_;
  117. unsigned aiFlagsDefault_;
  118. unsigned aiCurrentFlags_;
  119. Vector<String> nonSkinningBoneIncludes_;
  120. Vector<String> nonSkinningBoneExcludes_;
  121. HashSet<aiAnimation*> allAnimations_;
  122. PODVector<aiAnimation*> sceneAnimations_;
  123. Vector<AnimationInfo> animationInfos_;
  124. SharedPtr<Node> importNode_;
  125. float defaultTicksPerSecond_;
  126. float startTime_;
  127. float endTime_;
  128. bool genLightmapUV_;
  129. };
  130. }