XFileExporter.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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. @author: Richard Steffen, 2014
  32. ----------------------------------------------------------------------
  33. */
  34. /** @file XFileExporter.h
  35. * Declares the exporter class to write a scene to a Collada file
  36. */
  37. #ifndef AI_XFILEEXPORTER_H_INC
  38. #define AI_XFILEEXPORTER_H_INC
  39. #include <assimp/ai_assert.h>
  40. #include <assimp/matrix4x4.h>
  41. #include <assimp/Exporter.hpp>
  42. #include <sstream>
  43. struct aiScene;
  44. struct aiNode;
  45. struct aiMesh;
  46. struct aiString;
  47. namespace Assimp {
  48. class IOSystem;
  49. /// Helper class to export a given scene to a X-file.
  50. /// Note: an xFile uses a left hand system. Assimp used a right hand system (OpenGL), therefore we have to transform everything
  51. class XFileExporter
  52. {
  53. public:
  54. /// Constructor for a specific scene to export
  55. XFileExporter(const aiScene* pScene, IOSystem* pIOSystem, const std::string& path, const std::string& file, const ExportProperties* pProperties);
  56. /// Destructor
  57. virtual ~XFileExporter();
  58. protected:
  59. /// Starts writing the contents
  60. void WriteFile();
  61. /// Writes the asset header
  62. void WriteHeader();
  63. /// write a frame transform
  64. void WriteFrameTransform(aiMatrix4x4& m);
  65. /// Recursively writes the given node
  66. void WriteNode( aiNode* pNode );
  67. /// write a mesh entry of the scene
  68. void WriteMesh( aiMesh* mesh);
  69. /// Enters a new xml element, which increases the indentation
  70. void PushTag() { startstr.append( " "); }
  71. /// Leaves an element, decreasing the indentation
  72. void PopTag() {
  73. ai_assert( startstr.length() > 1);
  74. startstr.erase( startstr.length() - 2);
  75. }
  76. public:
  77. /// Stringstream to write all output into
  78. std::stringstream mOutput;
  79. protected:
  80. /// normalize the name to be accepted by xfile readers
  81. std::string toXFileString(aiString &name);
  82. /// hold the properties pointer
  83. const ExportProperties* mProperties;
  84. /// write a path
  85. void writePath(const aiString &path);
  86. /// The IOSystem for output
  87. IOSystem* mIOSystem;
  88. /// Path of the directory where the scene will be exported
  89. const std::string mPath;
  90. /// Name of the file (without extension) where the scene will be exported
  91. const std::string mFile;
  92. /// The scene to be written
  93. const aiScene* mScene;
  94. bool mSceneOwned;
  95. /// current line start string, contains the current indentation for simple stream insertion
  96. std::string startstr;
  97. /// current line end string for simple stream insertion
  98. std::string endstr;
  99. };
  100. }
  101. #endif // !! AI_XFILEEXPORTER_H_INC