COBLoader.h 7.0 KB

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