OpenAssetImporter.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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 ToolCore
  30. {
  31. class OpenAssetImporter : public Object
  32. {
  33. ATOMIC_OBJECT(OpenAssetImporter, Object);
  34. public:
  35. struct AnimationInfo
  36. {
  37. String name_;
  38. String cacheFilename_;
  39. };
  40. OpenAssetImporter(Context* context);
  41. virtual ~OpenAssetImporter();
  42. bool Load(const String& assetPath);
  43. const String& GetErrorMessage() { return errorMessage_; }
  44. bool ExportModel(const String& outName, const String& animName = String::EMPTY, bool animationOnly = false);
  45. void SetImportNode(Node* node) { importNode_ = node; }
  46. void SetStartTime(float startTime) { startTime_ = startTime; }
  47. void SetEndTime(float endTime) { endTime_ = endTime; }
  48. void SetScale(float scale) { scale_ = scale; }
  49. void SetExportAnimations(bool exportAnimations) { noAnimations_ = !exportAnimations; }
  50. void SetImportMaterials(bool importMaterials) { importMaterials_ = importMaterials; }
  51. void SetIncludeNonSkinningBones(bool includeNonSkinningBones) { includeNonSkinningBones_ = includeNonSkinningBones; }
  52. void SetVerboseLog(bool verboseLog) { verboseLog_ = verboseLog; }
  53. bool GetImportMaterialsDefault() { return importMaterialsDefault_; }
  54. bool GetIncludeNonSkinningBones() { return includeNonSkinningBonesDefault_; }
  55. const Vector<AnimationInfo>& GetAnimationInfos() { return animationInfos_; }
  56. private:
  57. void ApplyScale();
  58. void ApplyScale(aiNode* node);
  59. bool BuildAndSaveModel(OutModel& model);
  60. bool BuildAndSaveAnimations(OutModel* model = 0, const String& animNameOverride = String::EMPTY);
  61. void ExportMaterials(HashSet<String>& usedTextures);
  62. bool BuildAndSaveMaterial(aiMaterial* material, HashSet<String>& usedTextures);
  63. void CollectSceneModels(OutScene& scene, aiNode* node);
  64. bool CollectBones(OutModel& model, bool animationOnly = false);
  65. void CollectBonesFinal(PODVector<aiNode*>& dest, const HashSet<aiNode*>& necessary, aiNode* node);
  66. void BuildBoneCollisionInfo(OutModel& model);
  67. void CollectAnimations(OutModel* model = 0);
  68. void ApplyProjectImportConfig();
  69. void SetOveriddenFlags(VariantMap& aiFlagParameters);
  70. void ApplyFlag(int processStep, bool active);
  71. String GetMeshMaterialName(aiMesh* mesh);
  72. String GenerateMaterialName(aiMaterial* material);
  73. String GetMaterialTextureName(const String& nameIn);
  74. String GenerateTextureName(unsigned texIndex);
  75. // TODO: See AssetImporter
  76. // void CombineLods(const PODVector<float>& lodDistances, const Vector<String>& modelNames, const String& outName)
  77. void DumpNodes(aiNode* rootNode, unsigned level);
  78. String errorMessage_;
  79. const aiScene* scene_;
  80. aiNode* rootNode_;
  81. String inputName_;
  82. String sourceAssetPath_;
  83. String resourcePath_;
  84. String outPath_;
  85. bool useSubdirs_;
  86. bool importMaterials_;
  87. bool importMaterialsDefault_;
  88. bool localIDs_;
  89. bool saveBinary_;
  90. bool createZone_;
  91. bool noAnimations_;
  92. bool noHierarchy_;
  93. bool noMaterials_;
  94. bool noTextures_;
  95. bool noMaterialDiffuseColor_;
  96. bool noEmptyNodes_;
  97. bool saveMaterialList_;
  98. bool includeNonSkinningBones_;
  99. bool includeNonSkinningBonesDefault_;
  100. bool verboseLog_;
  101. bool emissiveAO_;
  102. bool noOverwriteMaterial_;
  103. bool noOverwriteTexture_;
  104. bool noOverwriteNewerTexture_;
  105. bool checkUniqueModel_;
  106. bool useVertexColors_;
  107. float scale_;
  108. unsigned maxBones_;
  109. unsigned aiFlagsDefault_;
  110. unsigned aiCurrentFlags_;
  111. Vector<String> nonSkinningBoneIncludes_;
  112. Vector<String> nonSkinningBoneExcludes_;
  113. HashSet<aiAnimation*> allAnimations_;
  114. PODVector<aiAnimation*> sceneAnimations_;
  115. Vector<AnimationInfo> animationInfos_;
  116. SharedPtr<Node> importNode_;
  117. float defaultTicksPerSecond_;
  118. float startTime_;
  119. float endTime_;
  120. };
  121. }