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
43/** @file MD5Loader.h
44 * @brief Definition of the .MD5 importer class.
45 * http://www.modwiki.net/wiki/MD5_(file_format)
46*/
47#ifndef AI_MD5LOADER_H_INCLUDED
48#define AI_MD5LOADER_H_INCLUDED
49
50#include "BaseImporter.h"
51#include "MD5Parser.h"
52
53#include <assimp/types.h>
54
55struct aiNode;
56struct aiNodeAnim;
57
58namespace Assimp {
59
60class IOStream;
61using namespace Assimp::MD5;
62
63// ---------------------------------------------------------------------------
64/** Importer class for the MD5 file format
65*/
66class MD5Importer : public BaseImporter
67{
68public:
69 MD5Importer();
70 ~MD5Importer();
71
72
73public:
74
75 // -------------------------------------------------------------------
76 /** Returns whether the class can handle the format of the given file.
77 * See BaseImporter::CanRead() for details.
78 */
79 bool CanRead( const std::string& pFile, IOSystem* pIOHandler,
80 bool checkSig) const;
81
82protected:
83
84 // -------------------------------------------------------------------
85 /** Return importer meta information.
86 * See #BaseImporter::GetInfo for the details
87 */
88 const aiImporterDesc* GetInfo () const;
89
90 // -------------------------------------------------------------------
91 /** Called prior to ReadFile().
92 * The function is a request to the importer to update its configuration
93 * basing on the Importer's configuration property list.
94 */
95 void SetupProperties(const Importer* pImp);
96
97 // -------------------------------------------------------------------
98 /** Imports the given file into the given scene structure.
99 * See BaseImporter::InternReadFile() for details
100 */
101 void InternReadFile( const std::string& pFile, aiScene* pScene,
102 IOSystem* pIOHandler);
103
104protected:
105
106
107 // -------------------------------------------------------------------
108 /** Load a *.MD5MESH file.
109 */
110 void LoadMD5MeshFile ();
111
112 // -------------------------------------------------------------------
113 /** Load a *.MD5ANIM file.
114 */
115 void LoadMD5AnimFile ();
116
117 // -------------------------------------------------------------------
118 /** Load a *.MD5CAMERA file.
119 */
120 void LoadMD5CameraFile ();
121
122 // -------------------------------------------------------------------
123 /** Construct node hierarchy from a given MD5ANIM
124 * @param iParentID Current parent ID
125 * @param piParent Parent node to attach to
126 * @param bones Input bones
127 * @param node_anims Generated node animations
128 */
129 void AttachChilds_Anim(int iParentID,aiNode* piParent,
130 AnimBoneList& bones,const aiNodeAnim** node_anims);
131
132 // -------------------------------------------------------------------
133 /** Construct node hierarchy from a given MD5MESH
134 * @param iParentID Current parent ID
135 * @param piParent Parent node to attach to
136 * @param bones Input bones
137 */
138 void AttachChilds_Mesh(int iParentID,aiNode* piParent,BoneList& bones);
139
140 // -------------------------------------------------------------------
141 /** Build unique vertex buffers from a given MD5ANIM
142 * @param meshSrc Input data
143 */
144 void MakeDataUnique (MD5::MeshDesc& meshSrc);
145
146 // -------------------------------------------------------------------
147 /** Load the contents of a specific file into memory and
148 * alocates a buffer to keep it.
149 *
150 * mBuffer is modified to point to this buffer.
151 * @param pFile File stream to be read
152 */
153 void LoadFileIntoMemory (IOStream* pFile);
154 void UnloadFileFromMemory ();
155
156
157 /** IOSystem to be used to access files */
158 IOSystem* mIOHandler;
159
160 /** Path to the file, excluding the file extension but
161 with the dot */
162 std::string mFile;
163
164 /** Buffer to hold the loaded file */
165 char* mBuffer;
166
167 /** Size of the file */
168 unsigned int fileSize;
169
170 /** Current line number. For debugging purposes */
171 unsigned int iLineNumber;
172
173 /** Scene to be filled */
174 aiScene* pScene;
175
176 /** (Custom) I/O handler implementation */
177 IOSystem* pIOHandler;
178
179 /** true if a MD5MESH file has already been parsed */
180 bool bHadMD5Mesh;
181
182 /** true if a MD5ANIM file has already been parsed */
183 bool bHadMD5Anim;
184
185 /** true if a MD5CAMERA file has already been parsed */
186 bool bHadMD5Camera;
187
188 /** configuration option: prevent anim autoload */
189 bool configNoAutoLoad;
190};
191
192} // end of namespace Assimp
193
194#endif // AI_3DSIMPORTER_H_INC
195