XFileImporter.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. /*
  2. Open Asset Import Library (assimp)
  3. ----------------------------------------------------------------------
  4. Copyright (c) 2006-2020, assimp team
  5. All rights reserved.
  6. Redistribution and use of this software in source and binary forms,
  7. with or without modification, are permitted provided that the
  8. following conditions are met:
  9. * Redistributions of source code must retain the above
  10. copyright notice, this list of conditions and the
  11. following disclaimer.
  12. * Redistributions in binary form must reproduce the above
  13. copyright notice, this list of conditions and the
  14. following disclaimer in the documentation and/or other
  15. materials provided with the distribution.
  16. * Neither the name of the assimp team, nor the names of its
  17. contributors may be used to endorse or promote products
  18. derived from this software without specific prior
  19. written permission of the assimp team.
  20. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  21. "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  22. LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  23. A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  24. OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  25. SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  26. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  27. DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  28. THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  29. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  30. OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31. ----------------------------------------------------------------------
  32. */
  33. /** @file XFileImporter.h
  34. * @brief Definition of the XFile importer class.
  35. */
  36. #ifndef AI_XFILEIMPORTER_H_INC
  37. #define AI_XFILEIMPORTER_H_INC
  38. #include <map>
  39. #include "XFileHelper.h"
  40. #include <assimp/BaseImporter.h>
  41. #include <assimp/types.h>
  42. struct aiNode;
  43. namespace Assimp {
  44. namespace XFile {
  45. struct Scene;
  46. struct Node;
  47. }
  48. // ---------------------------------------------------------------------------
  49. /** The XFileImporter is a worker class capable of importing a scene from a
  50. * DirectX file .x
  51. */
  52. class XFileImporter : public BaseImporter {
  53. public:
  54. XFileImporter();
  55. ~XFileImporter();
  56. // -------------------------------------------------------------------
  57. /** Returns whether the class can handle the format of the given file.
  58. * See BaseImporter::CanRead() for details. */
  59. bool CanRead( const std::string& pFile, IOSystem* pIOHandler,
  60. bool CheckSig) const;
  61. protected:
  62. // -------------------------------------------------------------------
  63. /** Return importer meta information.
  64. * See #BaseImporter::GetInfo for the details
  65. */
  66. const aiImporterDesc* GetInfo () const;
  67. // -------------------------------------------------------------------
  68. /** Imports the given file into the given scene structure.
  69. * See BaseImporter::InternReadFile() for details
  70. */
  71. void InternReadFile( const std::string& pFile, aiScene* pScene,
  72. IOSystem* pIOHandler);
  73. // -------------------------------------------------------------------
  74. /** Constructs the return data structure out of the imported data.
  75. * @param pScene The scene to construct the return data in.
  76. * @param pData The imported data in the internal temporary
  77. * representation.
  78. */
  79. void CreateDataRepresentationFromImport( aiScene* pScene, XFile::Scene* pData);
  80. // -------------------------------------------------------------------
  81. /** Recursively creates scene nodes from the imported hierarchy.
  82. * The meshes and materials of the nodes will be extracted on the way.
  83. * @param pScene The scene to construct the return data in.
  84. * @param pParent The parent node where to create new child nodes
  85. * @param pNode The temporary node to copy.
  86. * @return The created node
  87. */
  88. aiNode* CreateNodes( aiScene* pScene, aiNode* pParent,
  89. const XFile::Node* pNode);
  90. // -------------------------------------------------------------------
  91. /** Converts all meshes in the given mesh array. Each mesh is split
  92. * up per material, the indices of the generated meshes are stored in
  93. * the node structure.
  94. * @param pScene The scene to construct the return data in.
  95. * @param pNode The target node structure that references the
  96. * constructed meshes.
  97. * @param pMeshes The array of meshes to convert
  98. */
  99. void CreateMeshes( aiScene* pScene, aiNode* pNode,
  100. const std::vector<XFile::Mesh*>& pMeshes);
  101. // -------------------------------------------------------------------
  102. /** Converts the animations from the given imported data and creates
  103. * them in the scene.
  104. * @param pScene The scene to hold to converted animations
  105. * @param pData The data to read the animations from
  106. */
  107. void CreateAnimations( aiScene* pScene, const XFile::Scene* pData);
  108. // -------------------------------------------------------------------
  109. /** Converts all materials in the given array and stores them in the
  110. * scene's material list.
  111. * @param pScene The scene to hold the converted materials.
  112. * @param pMaterials The material array to convert.
  113. */
  114. void ConvertMaterials( aiScene* pScene, std::vector<XFile::Material>& pMaterials);
  115. protected:
  116. /** Buffer to hold the loaded file */
  117. std::vector<char> mBuffer;
  118. };
  119. } // end of namespace Assimp
  120. #endif // AI_BASEIMPORTER_H_INC