1 /*
2 Open Asset Import Library (assimp)
3 ----------------------------------------------------------------------
4 
5 Copyright (c) 2006-2017, 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  XFileImporter.h
43  *  @brief Definition of the XFile importer class.
44  */
45 #ifndef AI_XFILEIMPORTER_H_INC
46 #define AI_XFILEIMPORTER_H_INC
47 
48 #include <map>
49 
50 #include "XFileHelper.h"
51 #include "BaseImporter.h"
52 
53 #include <assimp/types.h>
54 
55 struct aiNode;
56 
57 namespace Assimp    {
58 
59 namespace XFile {
60 struct Scene;
61 struct Node;
62 }
63 
64 // ---------------------------------------------------------------------------
65 /** The XFileImporter is a worker class capable of importing a scene from a
66  * DirectX file .x
67  */
68 class XFileImporter : public BaseImporter {
69 public:
70     XFileImporter();
71     ~XFileImporter();
72 
73     // -------------------------------------------------------------------
74     /** Returns whether the class can handle the format of the given file.
75      * See BaseImporter::CanRead() for details. */
76     bool CanRead( const std::string& pFile, IOSystem* pIOHandler,
77         bool CheckSig) const;
78 
79 protected:
80 
81     // -------------------------------------------------------------------
82     /** Return importer meta information.
83      * See #BaseImporter::GetInfo for the details
84      */
85     const aiImporterDesc* GetInfo () const;
86 
87     // -------------------------------------------------------------------
88     /** Imports the given file into the given scene structure.
89      * See BaseImporter::InternReadFile() for details
90      */
91     void InternReadFile( const std::string& pFile, aiScene* pScene,
92         IOSystem* pIOHandler);
93 
94     // -------------------------------------------------------------------
95     /** Constructs the return data structure out of the imported data.
96      * @param pScene The scene to construct the return data in.
97      * @param pData The imported data in the internal temporary
98      *   representation.
99      */
100     void CreateDataRepresentationFromImport( aiScene* pScene, XFile::Scene* pData);
101 
102     // -------------------------------------------------------------------
103     /** Recursively creates scene nodes from the imported hierarchy.
104      * The meshes and materials of the nodes will be extracted on the way.
105      * @param pScene The scene to construct the return data in.
106      * @param pParent The parent node where to create new child nodes
107      * @param pNode The temporary node to copy.
108      * @return The created node
109      */
110     aiNode* CreateNodes( aiScene* pScene, aiNode* pParent,
111         const XFile::Node* pNode);
112 
113     // -------------------------------------------------------------------
114     /** Converts all meshes in the given mesh array. Each mesh is split
115      * up per material, the indices of the generated meshes are stored in
116      * the node structure.
117      * @param pScene The scene to construct the return data in.
118      * @param pNode The target node structure that references the
119      *   constructed meshes.
120      * @param pMeshes The array of meshes to convert
121      */
122     void CreateMeshes( aiScene* pScene, aiNode* pNode,
123         const std::vector<XFile::Mesh*>& pMeshes);
124 
125     // -------------------------------------------------------------------
126     /** Converts the animations from the given imported data and creates
127     *  them in the scene.
128      * @param pScene The scene to hold to converted animations
129      * @param pData The data to read the animations from
130      */
131     void CreateAnimations( aiScene* pScene, const XFile::Scene* pData);
132 
133     // -------------------------------------------------------------------
134     /** Converts all materials in the given array and stores them in the
135      *  scene's material list.
136      * @param pScene The scene to hold the converted materials.
137      * @param pMaterials The material array to convert.
138      */
139     void ConvertMaterials( aiScene* pScene, std::vector<XFile::Material>& pMaterials);
140 
141 protected:
142     /** Buffer to hold the loaded file */
143     std::vector<char> mBuffer;
144 };
145 
146 } // end of namespace Assimp
147 
148 #endif // AI_BASEIMPORTER_H_INC
149