OpenAssetImporter.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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. OBJECT(OpenAssetImporter);
  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 SetVerboseLog(bool verboseLog) { verboseLog_ = verboseLog; }
  51. const Vector<AnimationInfo>& GetAnimationInfos() { return animationInfos_; }
  52. private:
  53. void ApplyScale();
  54. void ApplyScale(aiNode* node);
  55. bool BuildAndSaveModel(OutModel& model);
  56. bool BuildAndSaveAnimations(OutModel* model = 0, const String& animNameOverride = String::EMPTY);
  57. void ExportMaterials(HashSet<String>& usedTextures);
  58. bool BuildAndSaveMaterial(aiMaterial* material, HashSet<String>& usedTextures);
  59. void CollectSceneModels(OutScene& scene, aiNode* node);
  60. bool CollectBones(OutModel& model, bool animationOnly = false);
  61. void CollectBonesFinal(PODVector<aiNode*>& dest, const HashSet<aiNode*>& necessary, aiNode* node);
  62. void BuildBoneCollisionInfo(OutModel& model);
  63. void CollectAnimations(OutModel* model = 0);
  64. void ApplyProjectImportConfig();
  65. void SetOveriddenFlags(VariantMap& aiFlagParameters);
  66. void ApplyFlag(int processStep, bool active);
  67. String GetMeshMaterialName(aiMesh* mesh);
  68. String GenerateMaterialName(aiMaterial* material);
  69. String GetMaterialTextureName(const String& nameIn);
  70. String GenerateTextureName(unsigned texIndex);
  71. // TODO: See AssetImporter
  72. // void CombineLods(const PODVector<float>& lodDistances, const Vector<String>& modelNames, const String& outName)
  73. void DumpNodes(aiNode* rootNode, unsigned level);
  74. String errorMessage_;
  75. const aiScene* scene_;
  76. aiNode* rootNode_;
  77. String inputName_;
  78. String sourceAssetPath_;
  79. String resourcePath_;
  80. String outPath_;
  81. bool useSubdirs_;
  82. bool localIDs_;
  83. bool saveBinary_;
  84. bool createZone_;
  85. bool noAnimations_;
  86. bool noHierarchy_;
  87. bool noMaterials_;
  88. bool noTextures_;
  89. bool noMaterialDiffuseColor_;
  90. bool noEmptyNodes_;
  91. bool saveMaterialList_;
  92. bool includeNonSkinningBones_;
  93. bool verboseLog_;
  94. bool emissiveAO_;
  95. bool noOverwriteMaterial_;
  96. bool noOverwriteTexture_;
  97. bool noOverwriteNewerTexture_;
  98. bool checkUniqueModel_;
  99. float scale_;
  100. unsigned maxBones_;
  101. unsigned aiFlagsDefault_;
  102. unsigned aiCurrentFlags_;
  103. Vector<String> nonSkinningBoneIncludes_;
  104. Vector<String> nonSkinningBoneExcludes_;
  105. HashSet<aiAnimation*> allAnimations_;
  106. PODVector<aiAnimation*> sceneAnimations_;
  107. Vector<AnimationInfo> animationInfos_;
  108. SharedPtr<Node> importNode_;
  109. float defaultTicksPerSecond_;
  110. float startTime_;
  111. float endTime_;
  112. };
  113. }