OpenAssetImporter.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. //
  2. // Copyright (c) 2008-2015 the Urho3D project.
  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. // Copyright (c) 2014-2015, THUNDERBEAST GAMES LLC All rights reserved
  23. // Please see LICENSE.md in repository root for license information
  24. // https://github.com/AtomicGameEngine/AtomicGameEngine
  25. #pragma once
  26. #include "OpenAssetUtils.h"
  27. #include <Atomic/Core/Object.h>
  28. #include <Atomic/Scene/Node.h>
  29. using namespace Atomic;
  30. namespace ToolCore
  31. {
  32. class OpenAssetImporter : public Object
  33. {
  34. OBJECT(OpenAssetImporter);
  35. public:
  36. struct AnimationInfo
  37. {
  38. String name_;
  39. String cacheFilename_;
  40. };
  41. OpenAssetImporter(Context* context);
  42. virtual ~OpenAssetImporter();
  43. bool Load(const String& assetPath);
  44. const String& GetErrorMessage() { return errorMessage_; }
  45. bool ExportModel(const String& outName, const String& animName = String::EMPTY, bool animationOnly = false);
  46. void SetImportNode(Node* node) { importNode_ = node; }
  47. void SetStartTime(float startTime) { startTime_ = startTime; }
  48. void SetEndTime(float endTime) { endTime_ = endTime; }
  49. void SetScale(float scale) { scale_ = scale; }
  50. void SetExportAnimations(bool exportAnimations) { noAnimations_ = !exportAnimations; }
  51. void SetVerboseLog(bool verboseLog) { verboseLog_ = verboseLog; }
  52. const Vector<AnimationInfo>& GetAnimationInfos() { return animationInfos_; }
  53. private:
  54. void ApplyScale();
  55. void ApplyScale(aiNode* node);
  56. bool BuildAndSaveModel(OutModel& model);
  57. bool BuildAndSaveAnimations(OutModel* model = 0, const String& animNameOverride = String::EMPTY);
  58. void ExportMaterials(HashSet<String>& usedTextures);
  59. bool BuildAndSaveMaterial(aiMaterial* material, HashSet<String>& usedTextures);
  60. void CollectSceneModels(OutScene& scene, aiNode* node);
  61. bool CollectBones(OutModel& model, bool animationOnly = false);
  62. void CollectBonesFinal(PODVector<aiNode*>& dest, const HashSet<aiNode*>& necessary, aiNode* node);
  63. void BuildBoneCollisionInfo(OutModel& model);
  64. void CollectAnimations(OutModel* model = 0);
  65. String GetMeshMaterialName(aiMesh* mesh);
  66. String GenerateMaterialName(aiMaterial* material);
  67. String GetMaterialTextureName(const String& nameIn);
  68. String GenerateTextureName(unsigned texIndex);
  69. // TODO: See AssetImporter
  70. // void CombineLods(const PODVector<float>& lodDistances, const Vector<String>& modelNames, const String& outName)
  71. void DumpNodes(aiNode* rootNode, unsigned level);
  72. String errorMessage_;
  73. const aiScene* scene_;
  74. aiNode* rootNode_;
  75. String inputName_;
  76. String sourceAssetPath_;
  77. String resourcePath_;
  78. String outPath_;
  79. bool useSubdirs_;
  80. bool localIDs_;
  81. bool saveBinary_;
  82. bool createZone_;
  83. bool noAnimations_;
  84. bool noHierarchy_;
  85. bool noMaterials_;
  86. bool noTextures_;
  87. bool noMaterialDiffuseColor_;
  88. bool noEmptyNodes_;
  89. bool saveMaterialList_;
  90. bool includeNonSkinningBones_;
  91. bool verboseLog_;
  92. bool emissiveAO_;
  93. bool noOverwriteMaterial_;
  94. bool noOverwriteTexture_;
  95. bool noOverwriteNewerTexture_;
  96. bool checkUniqueModel_;
  97. float scale_;
  98. unsigned maxBones_;
  99. unsigned aiFlagsDefault_;
  100. unsigned aiCurrentFlags_;
  101. Vector<String> nonSkinningBoneIncludes_;
  102. Vector<String> nonSkinningBoneExcludes_;
  103. HashSet<aiAnimation*> allAnimations_;
  104. PODVector<aiAnimation*> sceneAnimations_;
  105. Vector<AnimationInfo> animationInfos_;
  106. SharedPtr<Node> importNode_;
  107. float defaultTicksPerSecond_;
  108. float startTime_;
  109. float endTime_;
  110. };
  111. }