rev |
line source |
nuclear@0
|
1 /*
|
nuclear@0
|
2 ---------------------------------------------------------------------------
|
nuclear@0
|
3 Open Asset Import Library (assimp)
|
nuclear@0
|
4 ---------------------------------------------------------------------------
|
nuclear@0
|
5
|
nuclear@0
|
6 Copyright (c) 2006-2012, assimp team
|
nuclear@0
|
7
|
nuclear@0
|
8 All rights reserved.
|
nuclear@0
|
9
|
nuclear@0
|
10 Redistribution and use of this software in source and binary forms,
|
nuclear@0
|
11 with or without modification, are permitted provided that the following
|
nuclear@0
|
12 conditions are met:
|
nuclear@0
|
13
|
nuclear@0
|
14 * Redistributions of source code must retain the above
|
nuclear@0
|
15 copyright notice, this list of conditions and the
|
nuclear@0
|
16 following disclaimer.
|
nuclear@0
|
17
|
nuclear@0
|
18 * Redistributions in binary form must reproduce the above
|
nuclear@0
|
19 copyright notice, this list of conditions and the
|
nuclear@0
|
20 following disclaimer in the documentation and/or other
|
nuclear@0
|
21 materials provided with the distribution.
|
nuclear@0
|
22
|
nuclear@0
|
23 * Neither the name of the assimp team, nor the names of its
|
nuclear@0
|
24 contributors may be used to endorse or promote products
|
nuclear@0
|
25 derived from this software without specific prior
|
nuclear@0
|
26 written permission of the assimp team.
|
nuclear@0
|
27
|
nuclear@0
|
28 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
nuclear@0
|
29 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
nuclear@0
|
30 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
nuclear@0
|
31 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
nuclear@0
|
32 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
nuclear@0
|
33 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
nuclear@0
|
34 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
nuclear@0
|
35 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
nuclear@0
|
36 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
nuclear@0
|
37 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
nuclear@0
|
38 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
nuclear@0
|
39 ---------------------------------------------------------------------------
|
nuclear@0
|
40 */
|
nuclear@0
|
41
|
nuclear@0
|
42 /** @file UnrealLoader.cpp
|
nuclear@0
|
43 * @brief Implementation of the UNREAL (*.3D) importer class
|
nuclear@0
|
44 *
|
nuclear@0
|
45 * Sources:
|
nuclear@0
|
46 * http://local.wasp.uwa.edu.au/~pbourke/dataformats/unreal/
|
nuclear@0
|
47 */
|
nuclear@0
|
48
|
nuclear@0
|
49 #include "AssimpPCH.h"
|
nuclear@0
|
50
|
nuclear@0
|
51 #ifndef ASSIMP_BUILD_NO_3D_IMPORTER
|
nuclear@0
|
52
|
nuclear@0
|
53 #include "UnrealLoader.h"
|
nuclear@0
|
54 #include "StreamReader.h"
|
nuclear@0
|
55 #include "ParsingUtils.h"
|
nuclear@0
|
56 #include "fast_atof.h"
|
nuclear@0
|
57 #include "ConvertToLHProcess.h"
|
nuclear@0
|
58
|
nuclear@0
|
59 using namespace Assimp;
|
nuclear@0
|
60
|
nuclear@0
|
61 static const aiImporterDesc desc = {
|
nuclear@0
|
62 "Unreal Mesh Importer",
|
nuclear@0
|
63 "",
|
nuclear@0
|
64 "",
|
nuclear@0
|
65 "",
|
nuclear@0
|
66 aiImporterFlags_SupportTextFlavour,
|
nuclear@0
|
67 0,
|
nuclear@0
|
68 0,
|
nuclear@0
|
69 0,
|
nuclear@0
|
70 0,
|
nuclear@0
|
71 "3d uc"
|
nuclear@0
|
72 };
|
nuclear@0
|
73
|
nuclear@0
|
74
|
nuclear@0
|
75 // ------------------------------------------------------------------------------------------------
|
nuclear@0
|
76 // Constructor to be privately used by Importer
|
nuclear@0
|
77 UnrealImporter::UnrealImporter()
|
nuclear@0
|
78 : configFrameID (0)
|
nuclear@0
|
79 , configHandleFlags (true)
|
nuclear@0
|
80 {}
|
nuclear@0
|
81
|
nuclear@0
|
82 // ------------------------------------------------------------------------------------------------
|
nuclear@0
|
83 // Destructor, private as well
|
nuclear@0
|
84 UnrealImporter::~UnrealImporter()
|
nuclear@0
|
85 {}
|
nuclear@0
|
86
|
nuclear@0
|
87 // ------------------------------------------------------------------------------------------------
|
nuclear@0
|
88 // Returns whether the class can handle the format of the given file.
|
nuclear@0
|
89 bool UnrealImporter::CanRead( const std::string& pFile, IOSystem* /*pIOHandler*/, bool /*checkSig*/) const
|
nuclear@0
|
90 {
|
nuclear@0
|
91 return SimpleExtensionCheck(pFile,"3d","uc");
|
nuclear@0
|
92 }
|
nuclear@0
|
93
|
nuclear@0
|
94 // ------------------------------------------------------------------------------------------------
|
nuclear@0
|
95 // Build a string of all file extensions supported
|
nuclear@0
|
96 const aiImporterDesc* UnrealImporter::GetInfo () const
|
nuclear@0
|
97 {
|
nuclear@0
|
98 return &desc;
|
nuclear@0
|
99 }
|
nuclear@0
|
100
|
nuclear@0
|
101 // ------------------------------------------------------------------------------------------------
|
nuclear@0
|
102 // Setup configuration properties for the loader
|
nuclear@0
|
103 void UnrealImporter::SetupProperties(const Importer* pImp)
|
nuclear@0
|
104 {
|
nuclear@0
|
105 // The
|
nuclear@0
|
106 // AI_CONFIG_IMPORT_UNREAL_KEYFRAME option overrides the
|
nuclear@0
|
107 // AI_CONFIG_IMPORT_GLOBAL_KEYFRAME option.
|
nuclear@0
|
108 configFrameID = pImp->GetPropertyInteger(AI_CONFIG_IMPORT_UNREAL_KEYFRAME,-1);
|
nuclear@0
|
109 if(static_cast<unsigned int>(-1) == configFrameID) {
|
nuclear@0
|
110 configFrameID = pImp->GetPropertyInteger(AI_CONFIG_IMPORT_GLOBAL_KEYFRAME,0);
|
nuclear@0
|
111 }
|
nuclear@0
|
112
|
nuclear@0
|
113 // AI_CONFIG_IMPORT_UNREAL_HANDLE_FLAGS, default is true
|
nuclear@0
|
114 configHandleFlags = (0 != pImp->GetPropertyInteger(AI_CONFIG_IMPORT_UNREAL_HANDLE_FLAGS,1));
|
nuclear@0
|
115 }
|
nuclear@0
|
116
|
nuclear@0
|
117 // ------------------------------------------------------------------------------------------------
|
nuclear@0
|
118 // Imports the given file into the given scene structure.
|
nuclear@0
|
119 void UnrealImporter::InternReadFile( const std::string& pFile,
|
nuclear@0
|
120 aiScene* pScene, IOSystem* pIOHandler)
|
nuclear@0
|
121 {
|
nuclear@0
|
122 // For any of the 3 files being passed get the three correct paths
|
nuclear@0
|
123 // First of all, determine file extension
|
nuclear@0
|
124 std::string::size_type pos = pFile.find_last_of('.');
|
nuclear@0
|
125 std::string extension = GetExtension(pFile);
|
nuclear@0
|
126
|
nuclear@0
|
127 std::string d_path,a_path,uc_path;
|
nuclear@0
|
128 if (extension == "3d") {
|
nuclear@0
|
129 // jjjj_d.3d
|
nuclear@0
|
130 // jjjj_a.3d
|
nuclear@0
|
131 pos = pFile.find_last_of('_');
|
nuclear@0
|
132 if (std::string::npos == pos) {
|
nuclear@0
|
133 throw DeadlyImportError("UNREAL: Unexpected naming scheme");
|
nuclear@0
|
134 }
|
nuclear@0
|
135 extension = pFile.substr(0,pos);
|
nuclear@0
|
136 }
|
nuclear@0
|
137 else {
|
nuclear@0
|
138 extension = pFile.substr(0,pos);
|
nuclear@0
|
139 }
|
nuclear@0
|
140
|
nuclear@0
|
141 // build proper paths
|
nuclear@0
|
142 d_path = extension+"_d.3d";
|
nuclear@0
|
143 a_path = extension+"_a.3d";
|
nuclear@0
|
144 uc_path = extension+".uc";
|
nuclear@0
|
145
|
nuclear@0
|
146 DefaultLogger::get()->debug("UNREAL: data file is " + d_path);
|
nuclear@0
|
147 DefaultLogger::get()->debug("UNREAL: aniv file is " + a_path);
|
nuclear@0
|
148 DefaultLogger::get()->debug("UNREAL: uc file is " + uc_path);
|
nuclear@0
|
149
|
nuclear@0
|
150 // and open the files ... we can't live without them
|
nuclear@0
|
151 IOStream* p = pIOHandler->Open(d_path);
|
nuclear@0
|
152 if (!p)
|
nuclear@0
|
153 throw DeadlyImportError("UNREAL: Unable to open _d file");
|
nuclear@0
|
154 StreamReaderLE d_reader(pIOHandler->Open(d_path));
|
nuclear@0
|
155
|
nuclear@0
|
156 const uint16_t numTris = d_reader.GetI2();
|
nuclear@0
|
157 const uint16_t numVert = d_reader.GetI2();
|
nuclear@0
|
158 d_reader.IncPtr(44);
|
nuclear@0
|
159 if (!numTris || numVert < 3)
|
nuclear@0
|
160 throw DeadlyImportError("UNREAL: Invalid number of vertices/triangles");
|
nuclear@0
|
161
|
nuclear@0
|
162 // maximum texture index
|
nuclear@0
|
163 unsigned int maxTexIdx = 0;
|
nuclear@0
|
164
|
nuclear@0
|
165 // collect triangles
|
nuclear@0
|
166 std::vector<Unreal::Triangle> triangles(numTris);
|
nuclear@0
|
167 for (std::vector<Unreal::Triangle>::iterator it = triangles.begin(), end = triangles.end();it != end; ++it) {
|
nuclear@0
|
168 Unreal::Triangle& tri = *it;
|
nuclear@0
|
169
|
nuclear@0
|
170 for (unsigned int i = 0; i < 3;++i) {
|
nuclear@0
|
171
|
nuclear@0
|
172 tri.mVertex[i] = d_reader.GetI2();
|
nuclear@0
|
173 if (tri.mVertex[i] >= numTris) {
|
nuclear@0
|
174 DefaultLogger::get()->warn("UNREAL: vertex index out of range");
|
nuclear@0
|
175 tri.mVertex[i] = 0;
|
nuclear@0
|
176 }
|
nuclear@0
|
177 }
|
nuclear@0
|
178 tri.mType = d_reader.GetI1();
|
nuclear@0
|
179
|
nuclear@0
|
180 // handle mesh flagss?
|
nuclear@0
|
181 if (configHandleFlags)
|
nuclear@0
|
182 tri.mType = Unreal::MF_NORMAL_OS;
|
nuclear@0
|
183 else {
|
nuclear@0
|
184 // ignore MOD and MASKED for the moment, treat them as two-sided
|
nuclear@0
|
185 if (tri.mType == Unreal::MF_NORMAL_MOD_TS || tri.mType == Unreal::MF_NORMAL_MASKED_TS)
|
nuclear@0
|
186 tri.mType = Unreal::MF_NORMAL_TS;
|
nuclear@0
|
187 }
|
nuclear@0
|
188 d_reader.IncPtr(1);
|
nuclear@0
|
189
|
nuclear@0
|
190 for (unsigned int i = 0; i < 3;++i)
|
nuclear@0
|
191 for (unsigned int i2 = 0; i2 < 2;++i2)
|
nuclear@0
|
192 tri.mTex[i][i2] = d_reader.GetI1();
|
nuclear@0
|
193
|
nuclear@0
|
194 tri.mTextureNum = d_reader.GetI1();
|
nuclear@0
|
195 maxTexIdx = std::max(maxTexIdx,(unsigned int)tri.mTextureNum);
|
nuclear@0
|
196 d_reader.IncPtr(1);
|
nuclear@0
|
197 }
|
nuclear@0
|
198
|
nuclear@0
|
199 p = pIOHandler->Open(a_path);
|
nuclear@0
|
200 if (!p)
|
nuclear@0
|
201 throw DeadlyImportError("UNREAL: Unable to open _a file");
|
nuclear@0
|
202 StreamReaderLE a_reader(pIOHandler->Open(a_path));
|
nuclear@0
|
203
|
nuclear@0
|
204 // read number of frames
|
nuclear@0
|
205 const uint32_t numFrames = a_reader.GetI2();
|
nuclear@0
|
206 if (configFrameID >= numFrames)
|
nuclear@0
|
207 throw DeadlyImportError("UNREAL: The requested frame does not exist");
|
nuclear@0
|
208
|
nuclear@0
|
209 uint32_t st = a_reader.GetI2();
|
nuclear@0
|
210 if (st != numVert*4)
|
nuclear@0
|
211 throw DeadlyImportError("UNREAL: Unexpected aniv file length");
|
nuclear@0
|
212
|
nuclear@0
|
213 // skip to our frame
|
nuclear@0
|
214 a_reader.IncPtr(configFrameID *numVert*4);
|
nuclear@0
|
215
|
nuclear@0
|
216 // collect vertices
|
nuclear@0
|
217 std::vector<aiVector3D> vertices(numVert);
|
nuclear@0
|
218 for (std::vector<aiVector3D>::iterator it = vertices.begin(), end = vertices.end(); it != end; ++it) {
|
nuclear@0
|
219 int32_t val = a_reader.GetI4();
|
nuclear@0
|
220 Unreal::DecompressVertex(*it,val);
|
nuclear@0
|
221 }
|
nuclear@0
|
222
|
nuclear@0
|
223 // list of textures.
|
nuclear@0
|
224 std::vector< std::pair<unsigned int, std::string> > textures;
|
nuclear@0
|
225
|
nuclear@0
|
226 // allocate the output scene
|
nuclear@0
|
227 aiNode* nd = pScene->mRootNode = new aiNode();
|
nuclear@0
|
228 nd->mName.Set("<UnrealRoot>");
|
nuclear@0
|
229
|
nuclear@0
|
230 // we can live without the uc file if necessary
|
nuclear@0
|
231 boost::scoped_ptr<IOStream> pb (pIOHandler->Open(uc_path));
|
nuclear@0
|
232 if (pb.get()) {
|
nuclear@0
|
233
|
nuclear@0
|
234 std::vector<char> _data;
|
nuclear@0
|
235 TextFileToBuffer(pb.get(),_data);
|
nuclear@0
|
236 const char* data = &_data[0];
|
nuclear@0
|
237
|
nuclear@0
|
238 std::vector< std::pair< std::string,std::string > > tempTextures;
|
nuclear@0
|
239
|
nuclear@0
|
240 // do a quick search in the UC file for some known, usually texture-related, tags
|
nuclear@0
|
241 for (;*data;++data) {
|
nuclear@0
|
242 if (TokenMatchI(data,"#exec",5)) {
|
nuclear@0
|
243 SkipSpacesAndLineEnd(&data);
|
nuclear@0
|
244
|
nuclear@0
|
245 // #exec TEXTURE IMPORT [...] NAME=jjjjj [...] FILE=jjjj.pcx [...]
|
nuclear@0
|
246 if (TokenMatchI(data,"TEXTURE",7)) {
|
nuclear@0
|
247 SkipSpacesAndLineEnd(&data);
|
nuclear@0
|
248
|
nuclear@0
|
249 if (TokenMatchI(data,"IMPORT",6)) {
|
nuclear@0
|
250 tempTextures.push_back(std::pair< std::string,std::string >());
|
nuclear@0
|
251 std::pair< std::string,std::string >& me = tempTextures.back();
|
nuclear@0
|
252 for (;!IsLineEnd(*data);++data) {
|
nuclear@0
|
253 if (!::ASSIMP_strincmp(data,"NAME=",5)) {
|
nuclear@0
|
254 const char *d = data+=5;
|
nuclear@0
|
255 for (;!IsSpaceOrNewLine(*data);++data);
|
nuclear@0
|
256 me.first = std::string(d,(size_t)(data-d));
|
nuclear@0
|
257 }
|
nuclear@0
|
258 else if (!::ASSIMP_strincmp(data,"FILE=",5)) {
|
nuclear@0
|
259 const char *d = data+=5;
|
nuclear@0
|
260 for (;!IsSpaceOrNewLine(*data);++data);
|
nuclear@0
|
261 me.second = std::string(d,(size_t)(data-d));
|
nuclear@0
|
262 }
|
nuclear@0
|
263 }
|
nuclear@0
|
264 if (!me.first.length() || !me.second.length())
|
nuclear@0
|
265 tempTextures.pop_back();
|
nuclear@0
|
266 }
|
nuclear@0
|
267 }
|
nuclear@0
|
268 // #exec MESHMAP SETTEXTURE MESHMAP=box NUM=1 TEXTURE=Jtex1
|
nuclear@0
|
269 // #exec MESHMAP SCALE MESHMAP=box X=0.1 Y=0.1 Z=0.2
|
nuclear@0
|
270 else if (TokenMatchI(data,"MESHMAP",7)) {
|
nuclear@0
|
271 SkipSpacesAndLineEnd(&data);
|
nuclear@0
|
272
|
nuclear@0
|
273 if (TokenMatchI(data,"SETTEXTURE",10)) {
|
nuclear@0
|
274
|
nuclear@0
|
275 textures.push_back(std::pair<unsigned int, std::string>());
|
nuclear@0
|
276 std::pair<unsigned int, std::string>& me = textures.back();
|
nuclear@0
|
277
|
nuclear@0
|
278 for (;!IsLineEnd(*data);++data) {
|
nuclear@0
|
279 if (!::ASSIMP_strincmp(data,"NUM=",4)) {
|
nuclear@0
|
280 data += 4;
|
nuclear@0
|
281 me.first = strtoul10(data,&data);
|
nuclear@0
|
282 }
|
nuclear@0
|
283 else if (!::ASSIMP_strincmp(data,"TEXTURE=",8)) {
|
nuclear@0
|
284 data += 8;
|
nuclear@0
|
285 const char *d = data;
|
nuclear@0
|
286 for (;!IsSpaceOrNewLine(*data);++data);
|
nuclear@0
|
287 me.second = std::string(d,(size_t)(data-d));
|
nuclear@0
|
288
|
nuclear@0
|
289 // try to find matching path names, doesn't care if we don't find them
|
nuclear@0
|
290 for (std::vector< std::pair< std::string,std::string > >::const_iterator it = tempTextures.begin();
|
nuclear@0
|
291 it != tempTextures.end(); ++it) {
|
nuclear@0
|
292 if ((*it).first == me.second) {
|
nuclear@0
|
293 me.second = (*it).second;
|
nuclear@0
|
294 break;
|
nuclear@0
|
295 }
|
nuclear@0
|
296 }
|
nuclear@0
|
297 }
|
nuclear@0
|
298 }
|
nuclear@0
|
299 }
|
nuclear@0
|
300 else if (TokenMatchI(data,"SCALE",5)) {
|
nuclear@0
|
301
|
nuclear@0
|
302 for (;!IsLineEnd(*data);++data) {
|
nuclear@0
|
303 if (data[0] == 'X' && data[1] == '=') {
|
nuclear@0
|
304 data = fast_atoreal_move<float>(data+2,(float&)nd->mTransformation.a1);
|
nuclear@0
|
305 }
|
nuclear@0
|
306 else if (data[0] == 'Y' && data[1] == '=') {
|
nuclear@0
|
307 data = fast_atoreal_move<float>(data+2,(float&)nd->mTransformation.b2);
|
nuclear@0
|
308 }
|
nuclear@0
|
309 else if (data[0] == 'Z' && data[1] == '=') {
|
nuclear@0
|
310 data = fast_atoreal_move<float>(data+2,(float&)nd->mTransformation.c3);
|
nuclear@0
|
311 }
|
nuclear@0
|
312 }
|
nuclear@0
|
313 }
|
nuclear@0
|
314 }
|
nuclear@0
|
315 }
|
nuclear@0
|
316 }
|
nuclear@0
|
317 }
|
nuclear@0
|
318 else {
|
nuclear@0
|
319 DefaultLogger::get()->error("Unable to open .uc file");
|
nuclear@0
|
320 }
|
nuclear@0
|
321
|
nuclear@0
|
322 std::vector<Unreal::TempMat> materials;
|
nuclear@0
|
323 materials.reserve(textures.size()*2+5);
|
nuclear@0
|
324
|
nuclear@0
|
325 // find out how many output meshes and materials we'll have and build material indices
|
nuclear@0
|
326 for (std::vector<Unreal::Triangle>::iterator it = triangles.begin(), end = triangles.end();it != end; ++it) {
|
nuclear@0
|
327 Unreal::Triangle& tri = *it;
|
nuclear@0
|
328 Unreal::TempMat mat(tri);
|
nuclear@0
|
329 std::vector<Unreal::TempMat>::iterator nt = std::find(materials.begin(),materials.end(),mat);
|
nuclear@0
|
330 if (nt == materials.end()) {
|
nuclear@0
|
331 // add material
|
nuclear@0
|
332 tri.matIndex = materials.size();
|
nuclear@0
|
333 mat.numFaces = 1;
|
nuclear@0
|
334 materials.push_back(mat);
|
nuclear@0
|
335
|
nuclear@0
|
336 ++pScene->mNumMeshes;
|
nuclear@0
|
337 }
|
nuclear@0
|
338 else {
|
nuclear@0
|
339 tri.matIndex = static_cast<unsigned int>(nt-materials.begin());
|
nuclear@0
|
340 ++nt->numFaces;
|
nuclear@0
|
341 }
|
nuclear@0
|
342 }
|
nuclear@0
|
343
|
nuclear@0
|
344 if (!pScene->mNumMeshes) {
|
nuclear@0
|
345 throw DeadlyImportError("UNREAL: Unable to find valid mesh data");
|
nuclear@0
|
346 }
|
nuclear@0
|
347
|
nuclear@0
|
348 // allocate meshes and bind them to the node graph
|
nuclear@0
|
349 pScene->mMeshes = new aiMesh*[pScene->mNumMeshes];
|
nuclear@0
|
350 pScene->mMaterials = new aiMaterial*[pScene->mNumMaterials = pScene->mNumMeshes];
|
nuclear@0
|
351
|
nuclear@0
|
352 nd->mNumMeshes = pScene->mNumMeshes;
|
nuclear@0
|
353 nd->mMeshes = new unsigned int[nd->mNumMeshes];
|
nuclear@0
|
354 for (unsigned int i = 0; i < pScene->mNumMeshes;++i) {
|
nuclear@0
|
355 aiMesh* m = pScene->mMeshes[i] = new aiMesh();
|
nuclear@0
|
356 m->mPrimitiveTypes = aiPrimitiveType_TRIANGLE;
|
nuclear@0
|
357
|
nuclear@0
|
358 const unsigned int num = materials[i].numFaces;
|
nuclear@0
|
359 m->mFaces = new aiFace [num];
|
nuclear@0
|
360 m->mVertices = new aiVector3D [num*3];
|
nuclear@0
|
361 m->mTextureCoords[0] = new aiVector3D [num*3];
|
nuclear@0
|
362
|
nuclear@0
|
363 nd->mMeshes[i] = i;
|
nuclear@0
|
364
|
nuclear@0
|
365 // create materials, too
|
nuclear@0
|
366 aiMaterial* mat = new aiMaterial();
|
nuclear@0
|
367 pScene->mMaterials[i] = mat;
|
nuclear@0
|
368
|
nuclear@0
|
369 // all white by default - texture rulez
|
nuclear@0
|
370 aiColor3D color(1.f,1.f,1.f);
|
nuclear@0
|
371
|
nuclear@0
|
372 aiString s;
|
nuclear@0
|
373 ::sprintf(s.data,"mat%i_tx%i_",i,materials[i].tex);
|
nuclear@0
|
374
|
nuclear@0
|
375 // set the two-sided flag
|
nuclear@0
|
376 if (materials[i].type == Unreal::MF_NORMAL_TS) {
|
nuclear@0
|
377 const int twosided = 1;
|
nuclear@0
|
378 mat->AddProperty(&twosided,1,AI_MATKEY_TWOSIDED);
|
nuclear@0
|
379 ::strcat(s.data,"ts_");
|
nuclear@0
|
380 }
|
nuclear@0
|
381 else ::strcat(s.data,"os_");
|
nuclear@0
|
382
|
nuclear@0
|
383 // make TRANS faces 90% opaque that RemRedundantMaterials won't catch us
|
nuclear@0
|
384 if (materials[i].type == Unreal::MF_NORMAL_TRANS_TS) {
|
nuclear@0
|
385 const float opac = 0.9f;
|
nuclear@0
|
386 mat->AddProperty(&opac,1,AI_MATKEY_OPACITY);
|
nuclear@0
|
387 ::strcat(s.data,"tran_");
|
nuclear@0
|
388 }
|
nuclear@0
|
389 else ::strcat(s.data,"opaq_");
|
nuclear@0
|
390
|
nuclear@0
|
391 // a special name for the weapon attachment point
|
nuclear@0
|
392 if (materials[i].type == Unreal::MF_WEAPON_PLACEHOLDER) {
|
nuclear@0
|
393 s.length = ::sprintf(s.data,"$WeaponTag$");
|
nuclear@0
|
394 color = aiColor3D(0.f,0.f,0.f);
|
nuclear@0
|
395 }
|
nuclear@0
|
396
|
nuclear@0
|
397 // set color and name
|
nuclear@0
|
398 mat->AddProperty(&color,1,AI_MATKEY_COLOR_DIFFUSE);
|
nuclear@0
|
399 s.length = ::strlen(s.data);
|
nuclear@0
|
400 mat->AddProperty(&s,AI_MATKEY_NAME);
|
nuclear@0
|
401
|
nuclear@0
|
402 // set texture, if any
|
nuclear@0
|
403 const unsigned int tex = materials[i].tex;
|
nuclear@0
|
404 for (std::vector< std::pair< unsigned int, std::string > >::const_iterator it = textures.begin();it != textures.end();++it) {
|
nuclear@0
|
405 if ((*it).first == tex) {
|
nuclear@0
|
406 s.Set((*it).second);
|
nuclear@0
|
407 mat->AddProperty(&s,AI_MATKEY_TEXTURE_DIFFUSE(0));
|
nuclear@0
|
408 break;
|
nuclear@0
|
409 }
|
nuclear@0
|
410 }
|
nuclear@0
|
411 }
|
nuclear@0
|
412
|
nuclear@0
|
413 // fill them.
|
nuclear@0
|
414 for (std::vector<Unreal::Triangle>::iterator it = triangles.begin(), end = triangles.end();it != end; ++it) {
|
nuclear@0
|
415 Unreal::Triangle& tri = *it;
|
nuclear@0
|
416 Unreal::TempMat mat(tri);
|
nuclear@0
|
417 std::vector<Unreal::TempMat>::iterator nt = std::find(materials.begin(),materials.end(),mat);
|
nuclear@0
|
418
|
nuclear@0
|
419 aiMesh* mesh = pScene->mMeshes[nt-materials.begin()];
|
nuclear@0
|
420 aiFace& f = mesh->mFaces[mesh->mNumFaces++];
|
nuclear@0
|
421 f.mIndices = new unsigned int[f.mNumIndices = 3];
|
nuclear@0
|
422
|
nuclear@0
|
423 for (unsigned int i = 0; i < 3;++i,mesh->mNumVertices++) {
|
nuclear@0
|
424 f.mIndices[i] = mesh->mNumVertices;
|
nuclear@0
|
425
|
nuclear@0
|
426 mesh->mVertices[mesh->mNumVertices] = vertices[ tri.mVertex[i] ];
|
nuclear@0
|
427 mesh->mTextureCoords[0][mesh->mNumVertices] = aiVector3D( tri.mTex[i][0] / 255.f, 1.f - tri.mTex[i][1] / 255.f, 0.f);
|
nuclear@0
|
428 }
|
nuclear@0
|
429 }
|
nuclear@0
|
430
|
nuclear@0
|
431 // convert to RH
|
nuclear@0
|
432 MakeLeftHandedProcess hero;
|
nuclear@0
|
433 hero.Execute(pScene);
|
nuclear@0
|
434
|
nuclear@0
|
435 FlipWindingOrderProcess flipper;
|
nuclear@0
|
436 flipper.Execute(pScene);
|
nuclear@0
|
437 }
|
nuclear@0
|
438
|
nuclear@0
|
439 #endif // !! ASSIMP_BUILD_NO_3D_IMPORTER
|