OpenAssetImporter.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. //
  2. // Copyright (c) 2014-2015, THUNDERBEAST GAMES LLC All rights reserved
  3. // LICENSE: Atomic Game Engine Editor and Tools EULA
  4. // Please see LICENSE_ATOMIC_EDITOR_AND_TOOLS.md in repository root for
  5. // license information: https://github.com/AtomicGameEngine/AtomicGameEngine
  6. //
  7. //
  8. // Copyright (c) 2008-2015 the Urho3D project.
  9. //
  10. // Permission is hereby granted, free of charge, to any person obtaining a copy
  11. // of this software and associated documentation files (the "Software"), to deal
  12. // in the Software without restriction, including without limitation the rights
  13. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  14. // copies of the Software, and to permit persons to whom the Software is
  15. // furnished to do so, subject to the following conditions:
  16. //
  17. // The above copyright notice and this permission notice shall be included in
  18. // all copies or substantial portions of the Software.
  19. //
  20. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  21. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  22. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  23. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  24. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  25. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  26. // THE SOFTWARE.
  27. //
  28. // Copyright (c) 2014-2015, THUNDERBEAST GAMES LLC All rights reserved
  29. // Please see LICENSE.md in repository root for license information
  30. // https://github.com/AtomicGameEngine/AtomicGameEngine
  31. #pragma once
  32. #include "OpenAssetUtils.h"
  33. #include <Atomic/Core/Object.h>
  34. #include <Atomic/Scene/Node.h>
  35. using namespace Atomic;
  36. namespace ToolCore
  37. {
  38. class OpenAssetImporter : public Object
  39. {
  40. OBJECT(OpenAssetImporter);
  41. public:
  42. struct AnimationInfo
  43. {
  44. String name_;
  45. String cacheFilename_;
  46. };
  47. OpenAssetImporter(Context* context);
  48. virtual ~OpenAssetImporter();
  49. bool Load(const String& assetPath);
  50. const String& GetErrorMessage() { return errorMessage_; }
  51. bool ExportModel(const String& outName, const String& animName = String::EMPTY, bool animationOnly = false);
  52. void SetImportNode(Node* node) { importNode_ = node; }
  53. void SetStartTime(float startTime) { startTime_ = startTime; }
  54. void SetEndTime(float endTime) { endTime_ = endTime; }
  55. void SetScale(float scale) { scale_ = scale; }
  56. void SetExportAnimations(bool exportAnimations) { noAnimations_ = !exportAnimations; }
  57. void SetVerboseLog(bool verboseLog) { verboseLog_ = verboseLog; }
  58. const Vector<AnimationInfo>& GetAnimationInfos() { return animationInfos_; }
  59. private:
  60. void ApplyScale();
  61. void ApplyScale(aiNode* node);
  62. bool BuildAndSaveModel(OutModel& model);
  63. bool BuildAndSaveAnimations(OutModel* model = 0, const String& animNameOverride = String::EMPTY);
  64. void ExportMaterials(HashSet<String>& usedTextures);
  65. bool BuildAndSaveMaterial(aiMaterial* material, HashSet<String>& usedTextures);
  66. void CollectSceneModels(OutScene& scene, aiNode* node);
  67. bool CollectBones(OutModel& model, bool animationOnly = false);
  68. void CollectBonesFinal(PODVector<aiNode*>& dest, const HashSet<aiNode*>& necessary, aiNode* node);
  69. void BuildBoneCollisionInfo(OutModel& model);
  70. void CollectAnimations(OutModel* model = 0);
  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 localIDs_;
  87. bool saveBinary_;
  88. bool createZone_;
  89. bool noAnimations_;
  90. bool noHierarchy_;
  91. bool noMaterials_;
  92. bool noTextures_;
  93. bool noMaterialDiffuseColor_;
  94. bool noEmptyNodes_;
  95. bool saveMaterialList_;
  96. bool includeNonSkinningBones_;
  97. bool verboseLog_;
  98. bool emissiveAO_;
  99. bool noOverwriteMaterial_;
  100. bool noOverwriteTexture_;
  101. bool noOverwriteNewerTexture_;
  102. bool checkUniqueModel_;
  103. float scale_;
  104. unsigned maxBones_;
  105. unsigned aiFlagsDefault_;
  106. unsigned aiCurrentFlags_;
  107. Vector<String> nonSkinningBoneIncludes_;
  108. Vector<String> nonSkinningBoneExcludes_;
  109. HashSet<aiAnimation*> allAnimations_;
  110. PODVector<aiAnimation*> sceneAnimations_;
  111. Vector<AnimationInfo> animationInfos_;
  112. SharedPtr<Node> importNode_;
  113. float defaultTicksPerSecond_;
  114. float startTime_;
  115. float endTime_;
  116. };
  117. }