COBLoader.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. /*
  2. Open Asset Import Library (assimp)
  3. ----------------------------------------------------------------------
  4. Copyright (c) 2006-2025, 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 COBLoader.h
  34. * @brief Declaration of the TrueSpace (*.cob,*.scn) importer class.
  35. */
  36. #ifndef INCLUDED_AI_COB_LOADER_H
  37. #define INCLUDED_AI_COB_LOADER_H
  38. #include <assimp/BaseImporter.h>
  39. #include <assimp/StreamReader.h>
  40. struct aiNode;
  41. namespace Assimp {
  42. class LineSplitter;
  43. // TinyFormatter.h
  44. namespace Formatter {
  45. template <typename T, typename TR, typename A>
  46. class basic_formatter;
  47. typedef class basic_formatter<char, std::char_traits<char>, std::allocator<char>> format;
  48. } // namespace Formatter
  49. // COBScene.h
  50. namespace COB {
  51. struct ChunkInfo;
  52. struct Node;
  53. struct Scene;
  54. } // namespace COB
  55. // -------------------------------------------------------------------------------------------
  56. /** Importer class to load TrueSpace files (cob,scn) up to v6.
  57. *
  58. * Currently relatively limited, loads only ASCII files and needs more test coverage. */
  59. // -------------------------------------------------------------------------------------------
  60. class COBImporter : public BaseImporter {
  61. public:
  62. COBImporter() = default;
  63. ~COBImporter() override = default;
  64. // --------------------
  65. bool CanRead(const std::string &pFile, IOSystem *pIOHandler,
  66. bool checkSig) const override;
  67. protected:
  68. // --------------------
  69. const aiImporterDesc *GetInfo() const override;
  70. // --------------------
  71. void SetupProperties(const Importer *pImp) override;
  72. // --------------------
  73. void InternReadFile(const std::string &pFile, aiScene *pScene,
  74. IOSystem *pIOHandler) override;
  75. private:
  76. // -------------------------------------------------------------------
  77. /** Prepend 'COB: ' and throw msg.*/
  78. AI_WONT_RETURN static void ThrowException(const std::string &msg) AI_WONT_RETURN_SUFFIX;
  79. // -------------------------------------------------------------------
  80. /** @brief Read from an ascii scene/object file
  81. * @param out Receives output data.
  82. * @param stream Stream to read from. */
  83. void ReadAsciiFile(COB::Scene &out, StreamReaderLE *stream);
  84. // -------------------------------------------------------------------
  85. /** @brief Read from a binary scene/object file
  86. * @param out Receives output data.
  87. * @param stream Stream to read from. */
  88. void ReadBinaryFile(COB::Scene &out, StreamReaderLE *stream);
  89. // Conversion to Assimp output format
  90. aiNode *BuildNodes(const COB::Node &root, const COB::Scene &scin, aiScene *fill);
  91. private:
  92. // ASCII file support
  93. void UnsupportedChunk_Ascii(LineSplitter &splitter, const COB::ChunkInfo &nfo, const char *name);
  94. void ReadChunkInfo_Ascii(COB::ChunkInfo &out, const LineSplitter &splitter);
  95. void ReadBasicNodeInfo_Ascii(COB::Node &msh, LineSplitter &splitter, const COB::ChunkInfo &nfo);
  96. template <typename T>
  97. void ReadFloat3Tuple_Ascii(T &fill, const char **in, const char *end);
  98. void ReadPolH_Ascii(COB::Scene &out, LineSplitter &splitter, const COB::ChunkInfo &nfo);
  99. void ReadBitM_Ascii(COB::Scene &out, LineSplitter &splitter, const COB::ChunkInfo &nfo);
  100. void ReadMat1_Ascii(COB::Scene &out, LineSplitter &splitter, const COB::ChunkInfo &nfo);
  101. void ReadGrou_Ascii(COB::Scene &out, LineSplitter &splitter, const COB::ChunkInfo &nfo);
  102. void ReadBone_Ascii(COB::Scene &out, LineSplitter &splitter, const COB::ChunkInfo &nfo);
  103. void ReadCame_Ascii(COB::Scene &out, LineSplitter &splitter, const COB::ChunkInfo &nfo);
  104. void ReadLght_Ascii(COB::Scene &out, LineSplitter &splitter, const COB::ChunkInfo &nfo);
  105. void ReadUnit_Ascii(COB::Scene &out, LineSplitter &splitter, const COB::ChunkInfo &nfo);
  106. void ReadChan_Ascii(COB::Scene &out, LineSplitter &splitter, const COB::ChunkInfo &nfo);
  107. // Binary file support
  108. void UnsupportedChunk_Binary(StreamReaderLE &reader, const COB::ChunkInfo &nfo, const char *name);
  109. void ReadString_Binary(std::string &out, StreamReaderLE &reader);
  110. void ReadBasicNodeInfo_Binary(COB::Node &msh, StreamReaderLE &reader, const COB::ChunkInfo &nfo);
  111. void ReadPolH_Binary(COB::Scene &out, StreamReaderLE &reader, const COB::ChunkInfo &nfo);
  112. void ReadBitM_Binary(COB::Scene &out, StreamReaderLE &reader, const COB::ChunkInfo &nfo);
  113. void ReadMat1_Binary(COB::Scene &out, StreamReaderLE &reader, const COB::ChunkInfo &nfo);
  114. void ReadCame_Binary(COB::Scene &out, StreamReaderLE &reader, const COB::ChunkInfo &nfo);
  115. void ReadLght_Binary(COB::Scene &out, StreamReaderLE &reader, const COB::ChunkInfo &nfo);
  116. void ReadGrou_Binary(COB::Scene &out, StreamReaderLE &reader, const COB::ChunkInfo &nfo);
  117. void ReadUnit_Binary(COB::Scene &out, StreamReaderLE &reader, const COB::ChunkInfo &nfo);
  118. }; // !class COBImporter
  119. } // end of namespace Assimp
  120. #endif // AI_UNREALIMPORTER_H_INC