OpenAssetUtils.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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. #pragma once
  29. #include <ThirdParty/Assimp/include/assimp/cimport.h>
  30. #include <ThirdParty/Assimp/include/assimp/scene.h>
  31. #include <ThirdParty/Assimp/include/assimp/postprocess.h>
  32. #include <ThirdParty/Assimp/include/assimp/DefaultLogger.hpp>
  33. #include <cstring>
  34. #include <Atomic/Container/Str.h>
  35. #include <Atomic/Container/Sort.h>
  36. #include <Atomic/Container/Hash.h>
  37. #include <Atomic/Container/HashSet.h>
  38. #include <Atomic/Core/StringUtils.h>
  39. #include <Atomic/Math/Vector3.h>
  40. #include <Atomic/Math/Quaternion.h>
  41. #include <Atomic/Math/Matrix3x4.h>
  42. #include <Atomic/Math/BoundingBox.h>
  43. using namespace Atomic;
  44. namespace ToolCore
  45. {
  46. struct OutModel
  47. {
  48. OutModel() :
  49. rootBone_(0),
  50. totalVertices_(0),
  51. totalIndices_(0)
  52. {
  53. }
  54. String outName_;
  55. aiNode* rootNode_;
  56. HashSet<unsigned> meshIndices_;
  57. PODVector<aiMesh*> meshes_;
  58. PODVector<aiNode*> meshNodes_;
  59. PODVector<aiNode*> bones_;
  60. PODVector<aiAnimation*> animations_;
  61. PODVector<float> boneRadii_;
  62. PODVector<BoundingBox> boneHitboxes_;
  63. aiNode* rootBone_;
  64. unsigned totalVertices_;
  65. unsigned totalIndices_;
  66. };
  67. struct OutScene
  68. {
  69. String outName_;
  70. aiNode* rootNode_;
  71. Vector<OutModel> models_;
  72. PODVector<aiNode*> nodes_;
  73. PODVector<unsigned> nodeModelIndices_;
  74. };
  75. void WriteShortIndices(unsigned short*& dest, aiMesh* mesh, unsigned index, unsigned offset);
  76. void WriteLargeIndices(unsigned*& dest, aiMesh* mesh, unsigned index, unsigned offset);
  77. void WriteVertex(float*& dest, aiMesh* mesh, unsigned index, unsigned elementMask, BoundingBox& box,
  78. const Matrix3x4& vertexTransform, const Matrix3& normalTransform, Vector<PODVector<unsigned char> >& blendIndices,
  79. Vector<PODVector<float> >& blendWeights);
  80. unsigned GetElementMask(aiMesh* mesh);
  81. aiNode* GetNode(const String& name, aiNode* rootNode, bool caseSensitive = true);
  82. aiMatrix4x4 GetDerivedTransform(aiNode* node, aiNode* rootNode, bool rootInclusive = true);
  83. aiMatrix4x4 GetDerivedTransform(aiMatrix4x4 transform, aiNode* node, aiNode* rootNode, bool rootInclusive = true);
  84. aiMatrix4x4 GetMeshBakingTransform(aiNode* meshNode, aiNode* modelRootNode);
  85. void GetPosRotScale(const aiMatrix4x4& transform, Vector3& pos, Quaternion& rot, Vector3& scale);
  86. String FromAIString(const aiString& str);
  87. Vector3 ToVector3(const aiVector3D& vec);
  88. Vector2 ToVector2(const aiVector2D& vec);
  89. Quaternion ToQuaternion(const aiQuaternion& quat);
  90. Matrix3x4 ToMatrix3x4(const aiMatrix4x4& mat);
  91. String SanitateAssetName(const String& name);
  92. void GetMeshesUnderNode(const aiScene* scene, Vector<Pair<aiNode*, aiMesh*> >& dest, aiNode* node);
  93. unsigned GetMeshIndex(const aiScene* scene, aiMesh* mesh);
  94. unsigned GetBoneIndex(OutModel& model, const String& boneName);
  95. aiBone* GetMeshBone(OutModel& model, const String& boneName);
  96. Matrix3x4 GetOffsetMatrix(OutModel& model, const String& boneName);
  97. unsigned GetNumValidFaces(aiMesh* mesh);
  98. bool GetBlendData(OutModel& model, aiMesh* mesh, PODVector<unsigned>& boneMappings, Vector<PODVector<unsigned char> >&
  99. blendIndices, Vector<PODVector<float> >& blendWeights, String &errorMessage, unsigned maxBones = 64);
  100. void CollectMeshes(const aiScene* scene, OutModel& model, aiNode* node);
  101. void DumpNodes(aiNode* rootNode, unsigned level);
  102. }