Coverage Report

Created: 2025-08-28 06:38

/src/assimp/code/AssetLib/COB/COBLoader.h
Line
Count
Source
1
/*
2
Open Asset Import Library (assimp)
3
----------------------------------------------------------------------
4
5
Copyright (c) 2006-2025, assimp team
6
7
All rights reserved.
8
9
Redistribution and use of this software in source and binary forms,
10
with or without modification, are permitted provided that the
11
following 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
27
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
28
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
29
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
30
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
31
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
32
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
33
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
34
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
35
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
36
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
37
OF 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 <assimp/BaseImporter.h>
49
#include <assimp/StreamReader.h>
50
51
struct aiNode;
52
53
namespace Assimp {
54
class LineSplitter;
55
56
// TinyFormatter.h
57
namespace Formatter {
58
    template <typename T, typename TR, typename A>
59
    class basic_formatter;
60
    typedef class basic_formatter<char, std::char_traits<char>, std::allocator<char>> format;
61
} // namespace Formatter
62
63
// COBScene.h
64
namespace COB {
65
    struct ChunkInfo;
66
    struct Node;
67
    struct Scene;
68
} // namespace COB
69
70
// -------------------------------------------------------------------------------------------
71
/** Importer class to load TrueSpace files (cob,scn) up to v6.
72
 *
73
 *  Currently relatively limited, loads only ASCII files and needs more test coverage. */
74
// -------------------------------------------------------------------------------------------
75
class COBImporter : public BaseImporter {
76
public:
77
379
    COBImporter() = default;
78
    ~COBImporter() override = default;
79
80
    // --------------------
81
    bool CanRead(const std::string &pFile, IOSystem *pIOHandler,
82
            bool checkSig) const override;
83
84
protected:
85
    // --------------------
86
    const aiImporterDesc *GetInfo() const override;
87
88
    // --------------------
89
    void SetupProperties(const Importer *pImp) override;
90
91
    // --------------------
92
    void InternReadFile(const std::string &pFile, aiScene *pScene,
93
            IOSystem *pIOHandler) override;
94
95
private:
96
    // -------------------------------------------------------------------
97
    /** Prepend 'COB: ' and throw msg.*/
98
    AI_WONT_RETURN static void ThrowException(const std::string &msg) AI_WONT_RETURN_SUFFIX;
99
100
    // -------------------------------------------------------------------
101
    /** @brief Read from an ascii scene/object file
102
     *  @param out Receives output data.
103
     *  @param stream Stream to read from. */
104
    void ReadAsciiFile(COB::Scene &out, StreamReaderLE *stream);
105
106
    // -------------------------------------------------------------------
107
    /** @brief Read from a binary scene/object file
108
     *  @param out Receives output data.
109
     *  @param stream Stream to read from.  */
110
    void ReadBinaryFile(COB::Scene &out, StreamReaderLE *stream);
111
112
    // Conversion to Assimp output format
113
    aiNode *BuildNodes(const COB::Node &root, const COB::Scene &scin, aiScene *fill);
114
115
private:
116
    // ASCII file support
117
118
    void UnsupportedChunk_Ascii(LineSplitter &splitter, const COB::ChunkInfo &nfo, const char *name);
119
    void ReadChunkInfo_Ascii(COB::ChunkInfo &out, const LineSplitter &splitter);
120
    void ReadBasicNodeInfo_Ascii(COB::Node &msh, LineSplitter &splitter, const COB::ChunkInfo &nfo);
121
    template <typename T>
122
    void ReadFloat3Tuple_Ascii(T &fill, const char **in, const char *end);
123
124
    void ReadPolH_Ascii(COB::Scene &out, LineSplitter &splitter, const COB::ChunkInfo &nfo);
125
    void ReadBitM_Ascii(COB::Scene &out, LineSplitter &splitter, const COB::ChunkInfo &nfo);
126
    void ReadMat1_Ascii(COB::Scene &out, LineSplitter &splitter, const COB::ChunkInfo &nfo);
127
    void ReadGrou_Ascii(COB::Scene &out, LineSplitter &splitter, const COB::ChunkInfo &nfo);
128
    void ReadBone_Ascii(COB::Scene &out, LineSplitter &splitter, const COB::ChunkInfo &nfo);
129
    void ReadCame_Ascii(COB::Scene &out, LineSplitter &splitter, const COB::ChunkInfo &nfo);
130
    void ReadLght_Ascii(COB::Scene &out, LineSplitter &splitter, const COB::ChunkInfo &nfo);
131
    void ReadUnit_Ascii(COB::Scene &out, LineSplitter &splitter, const COB::ChunkInfo &nfo);
132
    void ReadChan_Ascii(COB::Scene &out, LineSplitter &splitter, const COB::ChunkInfo &nfo);
133
134
    // Binary file support
135
136
    void UnsupportedChunk_Binary(StreamReaderLE &reader, const COB::ChunkInfo &nfo, const char *name);
137
    void ReadString_Binary(std::string &out, StreamReaderLE &reader);
138
    void ReadBasicNodeInfo_Binary(COB::Node &msh, StreamReaderLE &reader, const COB::ChunkInfo &nfo);
139
140
    void ReadPolH_Binary(COB::Scene &out, StreamReaderLE &reader, const COB::ChunkInfo &nfo);
141
    void ReadBitM_Binary(COB::Scene &out, StreamReaderLE &reader, const COB::ChunkInfo &nfo);
142
    void ReadMat1_Binary(COB::Scene &out, StreamReaderLE &reader, const COB::ChunkInfo &nfo);
143
    void ReadCame_Binary(COB::Scene &out, StreamReaderLE &reader, const COB::ChunkInfo &nfo);
144
    void ReadLght_Binary(COB::Scene &out, StreamReaderLE &reader, const COB::ChunkInfo &nfo);
145
    void ReadGrou_Binary(COB::Scene &out, StreamReaderLE &reader, const COB::ChunkInfo &nfo);
146
    void ReadUnit_Binary(COB::Scene &out, StreamReaderLE &reader, const COB::ChunkInfo &nfo);
147
148
}; // !class COBImporter
149
150
} // end of namespace Assimp
151
#endif // AI_UNREALIMPORTER_H_INC