1 /* 2 Open Asset Import Library (assimp) 3 ---------------------------------------------------------------------- 4 5 Copyright (c) 2006-2015, assimp team 6 All rights reserved. 7 8 Redistribution and use of this software in source and binary forms, 9 with or without modification, are permitted provided that the 10 following conditions are met: 11 12 * Redistributions of source code must retain the above 13 copyright notice, this list of conditions and the 14 following disclaimer. 15 16 * Redistributions in binary form must reproduce the above 17 copyright notice, this list of conditions and the 18 following disclaimer in the documentation and/or other 19 materials provided with the distribution. 20 21 * Neither the name of the assimp team, nor the names of its 22 contributors may be used to endorse or promote products 23 derived from this software without specific prior 24 written permission of the assimp team. 25 26 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 27 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 28 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 29 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 30 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 31 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 32 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 33 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 34 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 35 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 36 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 37 38 ---------------------------------------------------------------------- 39 */ 40 41 /** @file COBLoader.h 42 * @brief Declaration of the TrueSpace (*.cob,*.scn) importer class. 43 */ 44 #ifndef INCLUDED_AI_COB_LOADER_H 45 #define INCLUDED_AI_COB_LOADER_H 46 47 #include "BaseImporter.h" 48 #include "StreamReader.h" 49 50 struct aiNode; 51 52 namespace Assimp { 53 class LineSplitter; 54 55 // TinyFormatter.h 56 namespace Formatter { 57 template <typename T,typename TR, typename A> class basic_formatter; 58 typedef class basic_formatter< char, std::char_traits<char>, std::allocator<char> > format; 59 } 60 61 // COBScene.h 62 namespace COB { 63 struct ChunkInfo; 64 struct Node; 65 struct Scene; 66 } 67 68 // ------------------------------------------------------------------------------------------- 69 /** Importer class to load TrueSpace files (cob,scn) up to v6. 70 * 71 * Currently relatively limited, loads only ASCII files and needs more test coverage. */ 72 // ------------------------------------------------------------------------------------------- 73 class COBImporter : public BaseImporter 74 { 75 public: 76 COBImporter(); 77 ~COBImporter(); 78 79 80 public: 81 82 // -------------------- 83 bool CanRead( const std::string& pFile, IOSystem* pIOHandler, 84 bool checkSig) const; 85 86 protected: 87 88 // -------------------- 89 const aiImporterDesc* GetInfo () const; 90 91 // -------------------- 92 void SetupProperties(const Importer* pImp); 93 94 // -------------------- 95 void InternReadFile( const std::string& pFile, aiScene* pScene, 96 IOSystem* pIOHandler); 97 98 private: 99 100 // ------------------------------------------------------------------- 101 /** Prepend 'COB: ' and throw msg.*/ 102 AI_WONT_RETURN static void ThrowException(const std::string& msg) AI_WONT_RETURN_SUFFIX; 103 104 // ------------------------------------------------------------------- 105 /** @brief Read from an ascii scene/object file 106 * @param out Receives output data. 107 * @param stream Stream to read from. */ 108 void ReadAsciiFile(COB::Scene& out, StreamReaderLE* stream); 109 110 // ------------------------------------------------------------------- 111 /** @brief Read from a binary scene/object file 112 * @param out Receives output data. 113 * @param stream Stream to read from. */ 114 void ReadBinaryFile(COB::Scene& out, StreamReaderLE* stream); 115 116 117 private: 118 119 // Conversion to Assimp output format 120 121 aiNode* BuildNodes(const COB::Node& root,const COB::Scene& scin,aiScene* fill); 122 123 private: 124 125 // ASCII file support 126 127 void UnsupportedChunk_Ascii(LineSplitter& splitter, const COB::ChunkInfo& nfo, const char* name); 128 void ReadChunkInfo_Ascii(COB::ChunkInfo& out, const LineSplitter& splitter); 129 void ReadBasicNodeInfo_Ascii(COB::Node& msh, LineSplitter& splitter, const COB::ChunkInfo& nfo); 130 template <typename T> void ReadFloat3Tuple_Ascii(T& fill, const char** in); 131 132 void ReadPolH_Ascii(COB::Scene& out, LineSplitter& splitter, const COB::ChunkInfo& nfo); 133 void ReadBitM_Ascii(COB::Scene& out, LineSplitter& splitter, const COB::ChunkInfo& nfo); 134 void ReadMat1_Ascii(COB::Scene& out, LineSplitter& splitter, const COB::ChunkInfo& nfo); 135 void ReadGrou_Ascii(COB::Scene& out, LineSplitter& splitter, const COB::ChunkInfo& nfo); 136 void ReadBone_Ascii(COB::Scene& out, LineSplitter& splitter, const COB::ChunkInfo& nfo); 137 void ReadCame_Ascii(COB::Scene& out, LineSplitter& splitter, const COB::ChunkInfo& nfo); 138 void ReadLght_Ascii(COB::Scene& out, LineSplitter& splitter, const COB::ChunkInfo& nfo); 139 void ReadUnit_Ascii(COB::Scene& out, LineSplitter& splitter, const COB::ChunkInfo& nfo); 140 void ReadChan_Ascii(COB::Scene& out, LineSplitter& splitter, const COB::ChunkInfo& nfo); 141 142 143 // ASCII file logging stuff to add proper line numbers to messages 144 145 static void LogWarn_Ascii (const LineSplitter& splitter, const Formatter::format& message); 146 static void LogError_Ascii(const LineSplitter& splitter, const Formatter::format& message); 147 static void LogInfo_Ascii (const LineSplitter& splitter, const Formatter::format& message); 148 static void LogDebug_Ascii(const LineSplitter& splitter, const Formatter::format& message); 149 150 static void LogWarn_Ascii (const Formatter::format& message); 151 static void LogError_Ascii (const Formatter::format& message); 152 static void LogInfo_Ascii (const Formatter::format& message); 153 static void LogDebug_Ascii (const Formatter::format& message); 154 155 156 // Binary file support 157 158 void UnsupportedChunk_Binary(StreamReaderLE& reader, const COB::ChunkInfo& nfo, const char* name); 159 void ReadString_Binary(std::string& out, StreamReaderLE& reader); 160 void ReadBasicNodeInfo_Binary(COB::Node& msh, StreamReaderLE& reader, const COB::ChunkInfo& nfo); 161 162 void ReadPolH_Binary(COB::Scene& out, StreamReaderLE& reader, const COB::ChunkInfo& nfo); 163 void ReadBitM_Binary(COB::Scene& out, StreamReaderLE& reader, const COB::ChunkInfo& nfo); 164 void ReadMat1_Binary(COB::Scene& out, StreamReaderLE& reader, const COB::ChunkInfo& nfo); 165 void ReadCame_Binary(COB::Scene& out, StreamReaderLE& reader, const COB::ChunkInfo& nfo); 166 void ReadLght_Binary(COB::Scene& out, StreamReaderLE& reader, const COB::ChunkInfo& nfo); 167 void ReadGrou_Binary(COB::Scene& out, StreamReaderLE& reader, const COB::ChunkInfo& nfo); 168 void ReadUnit_Binary(COB::Scene& out, StreamReaderLE& reader, const COB::ChunkInfo& nfo); 169 170 171 }; // !class COBImporter 172 173 } // end of namespace Assimp 174 #endif // AI_UNREALIMPORTER_H_INC 175