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