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 BlenderLoader.h |
43 | * @brief Declaration of the Blender 3D (*.blend) importer class. |
44 | */ |
45 | #ifndef INCLUDED_AI_BLEND_LOADER_H |
46 | #define INCLUDED_AI_BLEND_LOADER_H |
47 | |
48 | #include "BaseImporter.h" |
49 | #include "LogAux.h" |
50 | #include <memory> |
51 | |
52 | struct aiNode; |
53 | struct aiMesh; |
54 | struct aiLight; |
55 | struct aiCamera; |
56 | struct aiMaterial; |
57 | |
58 | namespace Assimp { |
59 | |
60 | // TinyFormatter.h |
61 | namespace Formatter { |
62 | template <typename T,typename TR, typename A> class basic_formatter; |
63 | typedef class basic_formatter< char, std::char_traits<char>, std::allocator<char> > format; |
64 | } |
65 | |
66 | // BlenderDNA.h |
67 | namespace Blender { |
68 | class FileDatabase; |
69 | struct ElemBase; |
70 | } |
71 | |
72 | // BlenderScene.h |
73 | namespace Blender { |
74 | struct Scene; |
75 | struct Object; |
76 | struct Mesh; |
77 | struct Camera; |
78 | struct Lamp; |
79 | struct MTex; |
80 | struct Image; |
81 | struct Material; |
82 | } |
83 | |
84 | // BlenderIntermediate.h |
85 | namespace Blender { |
86 | struct ConversionData; |
87 | template <template <typename,typename> class TCLASS, typename T> struct TempArray; |
88 | } |
89 | |
90 | // BlenderModifier.h |
91 | namespace Blender { |
92 | class BlenderModifierShowcase; |
93 | class BlenderModifier; |
94 | } |
95 | |
96 | |
97 | |
98 | // ------------------------------------------------------------------------------------------- |
99 | /** Load blenders official binary format. The actual file structure (the `DNA` how they |
100 | * call it is outsourced to BlenderDNA.cpp/BlenderDNA.h. This class only performs the |
101 | * conversion from intermediate format to aiScene. */ |
102 | // ------------------------------------------------------------------------------------------- |
103 | class BlenderImporter : public BaseImporter, public LogFunctions<BlenderImporter> |
104 | { |
105 | public: |
106 | BlenderImporter(); |
107 | ~BlenderImporter(); |
108 | |
109 | public: |
110 | |
111 | // -------------------- |
112 | bool CanRead( const std::string& pFile, |
113 | IOSystem* pIOHandler, |
114 | bool checkSig |
115 | ) const; |
116 | |
117 | protected: |
118 | |
119 | // -------------------- |
120 | const aiImporterDesc* GetInfo () const; |
121 | |
122 | // -------------------- |
123 | void GetExtensionList(std::set<std::string>& app); |
124 | |
125 | // -------------------- |
126 | void SetupProperties(const Importer* pImp); |
127 | |
128 | // -------------------- |
129 | void InternReadFile( const std::string& pFile, |
130 | aiScene* pScene, |
131 | IOSystem* pIOHandler |
132 | ); |
133 | |
134 | // -------------------- |
135 | void ParseBlendFile(Blender::FileDatabase& out, |
136 | std::shared_ptr<IOStream> stream |
137 | ); |
138 | |
139 | // -------------------- |
140 | void (Blender::Scene& out, |
141 | const Blender::FileDatabase& file |
142 | ); |
143 | |
144 | // -------------------- |
145 | void ConvertBlendFile(aiScene* out, |
146 | const Blender::Scene& in, |
147 | const Blender::FileDatabase& file |
148 | ); |
149 | |
150 | private: |
151 | |
152 | // -------------------- |
153 | aiNode* ConvertNode(const Blender::Scene& in, |
154 | const Blender::Object* obj, |
155 | Blender::ConversionData& conv_info, |
156 | const aiMatrix4x4& parentTransform |
157 | ); |
158 | |
159 | // -------------------- |
160 | void ConvertMesh(const Blender::Scene& in, |
161 | const Blender::Object* obj, |
162 | const Blender::Mesh* mesh, |
163 | Blender::ConversionData& conv_data, |
164 | Blender::TempArray<std::vector,aiMesh>& temp |
165 | ); |
166 | |
167 | // -------------------- |
168 | aiLight* ConvertLight(const Blender::Scene& in, |
169 | const Blender::Object* obj, |
170 | const Blender::Lamp* mesh, |
171 | Blender::ConversionData& conv_data |
172 | ); |
173 | |
174 | // -------------------- |
175 | aiCamera* ConvertCamera(const Blender::Scene& in, |
176 | const Blender::Object* obj, |
177 | const Blender::Camera* mesh, |
178 | Blender::ConversionData& conv_data |
179 | ); |
180 | |
181 | // -------------------- |
182 | void BuildDefaultMaterial( |
183 | Blender::ConversionData& conv_data |
184 | ); |
185 | |
186 | void AddBlendParams( |
187 | aiMaterial* result, |
188 | const Blender::Material* source |
189 | ); |
190 | |
191 | void BuildMaterials( |
192 | Blender::ConversionData& conv_data |
193 | ); |
194 | |
195 | // -------------------- |
196 | void ResolveTexture( |
197 | aiMaterial* out, |
198 | const Blender::Material* mat, |
199 | const Blender::MTex* tex, |
200 | Blender::ConversionData& conv_data |
201 | ); |
202 | |
203 | // -------------------- |
204 | void ResolveImage( |
205 | aiMaterial* out, |
206 | const Blender::Material* mat, |
207 | const Blender::MTex* tex, |
208 | const Blender::Image* img, |
209 | Blender::ConversionData& conv_data |
210 | ); |
211 | |
212 | void AddSentinelTexture( |
213 | aiMaterial* out, |
214 | const Blender::Material* mat, |
215 | const Blender::MTex* tex, |
216 | Blender::ConversionData& conv_data |
217 | ); |
218 | |
219 | private: // static stuff, mostly logging and error reporting. |
220 | |
221 | // -------------------- |
222 | static void CheckActualType(const Blender::ElemBase* dt, |
223 | const char* check |
224 | ); |
225 | |
226 | // -------------------- |
227 | static void NotSupportedObjectType(const Blender::Object* obj, |
228 | const char* type |
229 | ); |
230 | |
231 | |
232 | private: |
233 | |
234 | Blender::BlenderModifierShowcase* modifier_cache; |
235 | |
236 | }; // !class BlenderImporter |
237 | |
238 | } // end of namespace Assimp |
239 | #endif // AI_UNREALIMPORTER_H_INC |
240 | |