MD3Loader.cpp 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044
  1. /*
  2. ---------------------------------------------------------------------------
  3. Open Asset Import Library (ASSIMP)
  4. ---------------------------------------------------------------------------
  5. Copyright (c) 2006-2010, ASSIMP Development Team
  6. All rights reserved.
  7. Redistribution and use of this software in source and binary forms,
  8. with or without modification, are permitted provided that the following
  9. conditions are met:
  10. * Redistributions of source code must retain the above
  11. copyright notice, this list of conditions and the
  12. following disclaimer.
  13. * Redistributions in binary form must reproduce the above
  14. copyright notice, this list of conditions and the
  15. following disclaimer in the documentation and/or other
  16. materials provided with the distribution.
  17. * Neither the name of the ASSIMP team, nor the names of its
  18. contributors may be used to endorse or promote products
  19. derived from this software without specific prior
  20. written permission of the ASSIMP Development Team.
  21. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  22. "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  23. LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  24. A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  25. OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  26. SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  27. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  28. DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  29. THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  30. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  31. OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  32. ---------------------------------------------------------------------------
  33. */
  34. /** @file MD3Loader.cpp
  35. * @brief Implementation of the MD3 importer class
  36. *
  37. * Sources:
  38. * http://www.gamers.org/dEngine/quake3/UQ3S
  39. * http://linux.ucla.edu/~phaethon/q3/formats/md3format.html
  40. * http://www.heppler.com/shader/shader/
  41. */
  42. #include "AssimpPCH.h"
  43. #ifndef ASSIMP_BUILD_NO_MD3_IMPORTER
  44. #include "MD3Loader.h"
  45. #include "ByteSwap.h"
  46. #include "SceneCombiner.h"
  47. #include "GenericProperty.h"
  48. #include "RemoveComments.h"
  49. #include "ParsingUtils.h"
  50. #include "Importer.h"
  51. using namespace Assimp;
  52. // ------------------------------------------------------------------------------------------------
  53. // Convert a Q3 shader blend function to the appropriate enum value
  54. Q3Shader::BlendFunc StringToBlendFunc(const std::string& m)
  55. {
  56. if (m == "GL_ONE") {
  57. return Q3Shader::BLEND_GL_ONE;
  58. }
  59. if (m == "GL_ZERO") {
  60. return Q3Shader::BLEND_GL_ZERO;
  61. }
  62. if (m == "GL_SRC_ALPHA") {
  63. return Q3Shader::BLEND_GL_SRC_ALPHA;
  64. }
  65. if (m == "GL_ONE_MINUS_SRC_ALPHA") {
  66. return Q3Shader::BLEND_GL_ONE_MINUS_SRC_ALPHA;
  67. }
  68. if (m == "GL_ONE_MINUS_DST_COLOR") {
  69. return Q3Shader::BLEND_GL_ONE_MINUS_DST_COLOR;
  70. }
  71. DefaultLogger::get()->error("Q3Shader: Unknown blend function: " + m);
  72. return Q3Shader::BLEND_NONE;
  73. }
  74. // ------------------------------------------------------------------------------------------------
  75. // Load a Quake 3 shader
  76. bool Q3Shader::LoadShader(ShaderData& fill, const std::string& pFile,IOSystem* io)
  77. {
  78. boost::scoped_ptr<IOStream> file( io->Open( pFile, "rt"));
  79. if (!file.get())
  80. return false; // if we can't access the file, don't worry and return
  81. DefaultLogger::get()->info("Loading Quake3 shader file " + pFile);
  82. // read file in memory
  83. const size_t s = file->FileSize();
  84. std::vector<char> _buff(s+1);
  85. file->Read(&_buff[0],s,1);
  86. _buff[s] = 0;
  87. // remove comments from it (C++ style)
  88. CommentRemover::RemoveLineComments("//",&_buff[0]);
  89. const char* buff = &_buff[0];
  90. Q3Shader::ShaderDataBlock* curData = NULL;
  91. Q3Shader::ShaderMapBlock* curMap = NULL;
  92. // read line per line
  93. for (;SkipSpacesAndLineEnd(&buff);SkipLine(&buff)) {
  94. if (*buff == '{') {
  95. ++buff;
  96. // append to last section, if any
  97. if (!curData) {
  98. DefaultLogger::get()->error("Q3Shader: Unexpected shader section token \'{\'");
  99. return true; // still no failure, the file is there
  100. }
  101. // read this data section
  102. for (;SkipSpacesAndLineEnd(&buff);SkipLine(&buff)) {
  103. if (*buff == '{') {
  104. ++buff;
  105. // add new map section
  106. curData->maps.push_back(Q3Shader::ShaderMapBlock());
  107. curMap = &curData->maps.back();
  108. for (;SkipSpacesAndLineEnd(&buff);SkipLine(&buff)) {
  109. // 'map' - Specifies texture file name
  110. if (TokenMatchI(buff,"map",3) || TokenMatchI(buff,"clampmap",8)) {
  111. curMap->name = GetNextToken(buff);
  112. }
  113. // 'blendfunc' - Alpha blending mode
  114. else if (TokenMatchI(buff,"blendfunc",9)) {
  115. const std::string blend_src = GetNextToken(buff);
  116. if (blend_src == "add") {
  117. curMap->blend_src = Q3Shader::BLEND_GL_ONE;
  118. curMap->blend_dest = Q3Shader::BLEND_GL_ONE;
  119. }
  120. else if (blend_src == "filter") {
  121. curMap->blend_src = Q3Shader::BLEND_GL_DST_COLOR;
  122. curMap->blend_dest = Q3Shader::BLEND_GL_ZERO;
  123. }
  124. else if (blend_src == "blend") {
  125. curMap->blend_src = Q3Shader::BLEND_GL_SRC_ALPHA;
  126. curMap->blend_dest = Q3Shader::BLEND_GL_ONE_MINUS_SRC_ALPHA;
  127. }
  128. else {
  129. curMap->blend_src = StringToBlendFunc(blend_src);
  130. curMap->blend_dest = StringToBlendFunc(GetNextToken(buff));
  131. }
  132. }
  133. // 'alphafunc' - Alpha testing mode
  134. else if (TokenMatchI(buff,"alphafunc",9)) {
  135. const std::string at = GetNextToken(buff);
  136. if (at == "GT0") {
  137. curMap->alpha_test = Q3Shader::AT_GT0;
  138. }
  139. else if (at == "LT128") {
  140. curMap->alpha_test = Q3Shader::AT_LT128;
  141. }
  142. else if (at == "GE128") {
  143. curMap->alpha_test = Q3Shader::AT_GE128;
  144. }
  145. }
  146. else if (*buff == '}') {
  147. ++buff;
  148. // close this map section
  149. curMap = NULL;
  150. break;
  151. }
  152. }
  153. }
  154. else if (*buff == '}') {
  155. ++buff;
  156. curData = NULL;
  157. break;
  158. }
  159. // 'cull' specifies culling behaviour for the model
  160. else if (TokenMatchI(buff,"cull",4)) {
  161. SkipSpaces(&buff);
  162. if (!ASSIMP_strincmp(buff,"back",4)) {
  163. curData->cull = Q3Shader::CULL_CCW;
  164. }
  165. else if (!ASSIMP_strincmp(buff,"front",5)) {
  166. curData->cull = Q3Shader::CULL_CW;
  167. }
  168. else if (!ASSIMP_strincmp(buff,"none",4) || !ASSIMP_strincmp(buff,"disable",7)) {
  169. curData->cull = Q3Shader::CULL_NONE;
  170. }
  171. else DefaultLogger::get()->error("Q3Shader: Unrecognized cull mode");
  172. }
  173. }
  174. }
  175. else {
  176. // add new section
  177. fill.blocks.push_back(Q3Shader::ShaderDataBlock());
  178. curData = &fill.blocks.back();
  179. // get the name of this section
  180. curData->name = GetNextToken(buff);
  181. }
  182. }
  183. return true;
  184. }
  185. // ------------------------------------------------------------------------------------------------
  186. // Load a Quake 3 skin
  187. bool Q3Shader::LoadSkin(SkinData& fill, const std::string& pFile,IOSystem* io)
  188. {
  189. boost::scoped_ptr<IOStream> file( io->Open( pFile, "rt"));
  190. if (!file.get())
  191. return false; // if we can't access the file, don't worry and return
  192. DefaultLogger::get()->info("Loading Quake3 skin file " + pFile);
  193. // read file in memory
  194. const size_t s = file->FileSize();
  195. std::vector<char> _buff(s+1);const char* buff = &_buff[0];
  196. file->Read(&_buff[0],s,1);
  197. _buff[s] = 0;
  198. // remove commas
  199. std::replace(_buff.begin(),_buff.end(),',',' ');
  200. // read token by token and fill output table
  201. for (;*buff;) {
  202. SkipSpacesAndLineEnd(&buff);
  203. // get first identifier
  204. std::string ss = GetNextToken(buff);
  205. // ignore tokens starting with tag_
  206. if (!::strncmp(&ss[0],"tag_",std::min((size_t)4, ss.length())))
  207. continue;
  208. fill.textures.push_back(SkinData::TextureEntry());
  209. SkinData::TextureEntry& s = fill.textures.back();
  210. s.first = ss;
  211. s.second = GetNextToken(buff);
  212. }
  213. return true;
  214. }
  215. // ------------------------------------------------------------------------------------------------
  216. // Convert Q3Shader to material
  217. void Q3Shader::ConvertShaderToMaterial(aiMaterial* out, const ShaderDataBlock& shader)
  218. {
  219. ai_assert(NULL != out);
  220. /* IMPORTANT: This is not a real conversion. Actually we're just guessing and
  221. * hacking around to build an aiMaterial that looks nearly equal to the
  222. * original Quake 3 shader. We're missing some important features like
  223. * animatable material properties in our material system, but at least
  224. * multiple textures should be handled correctly.
  225. */
  226. // Two-sided material?
  227. if (shader.cull == Q3Shader::CULL_NONE) {
  228. const int twosided = 1;
  229. out->AddProperty(&twosided,1,AI_MATKEY_TWOSIDED);
  230. }
  231. unsigned int cur_emissive = 0, cur_diffuse = 0, cur_lm =0;
  232. // Iterate through all textures
  233. for (std::list< Q3Shader::ShaderMapBlock >::const_iterator it = shader.maps.begin(); it != shader.maps.end();++it) {
  234. // CONVERSION BEHAVIOUR:
  235. //
  236. //
  237. // If the texture is additive
  238. // - if it is the first texture, assume additive blending for the whole material
  239. // - otherwise register it as emissive texture.
  240. //
  241. // If the texture is using standard blend (or if the blend mode is unknown)
  242. // - if first texture: assume default blending for material
  243. // - in any case: set it as diffuse texture
  244. //
  245. // If the texture is using 'filter' blending
  246. // - take as lightmap
  247. //
  248. // Textures with alpha funcs
  249. // - aiTextureFlags_UseAlpha is set (otherwise aiTextureFlags_NoAlpha is explicitly set)
  250. aiString s((*it).name);
  251. aiTextureType type; unsigned int index;
  252. if ((*it).blend_src == Q3Shader::BLEND_GL_ONE && (*it).blend_dest == Q3Shader::BLEND_GL_ONE) {
  253. if (it == shader.maps.begin()) {
  254. const int additive = aiBlendMode_Additive;
  255. out->AddProperty(&additive,1,AI_MATKEY_BLEND_FUNC);
  256. index = cur_diffuse++;
  257. type = aiTextureType_DIFFUSE;
  258. }
  259. else {
  260. index = cur_emissive++;
  261. type = aiTextureType_EMISSIVE;
  262. }
  263. }
  264. else if ((*it).blend_src == Q3Shader::BLEND_GL_DST_COLOR && (*it).blend_dest == Q3Shader::BLEND_GL_ZERO) {
  265. index = cur_lm++;
  266. type = aiTextureType_LIGHTMAP;
  267. }
  268. else {
  269. const int blend = aiBlendMode_Default;
  270. out->AddProperty(&blend,1,AI_MATKEY_BLEND_FUNC);
  271. index = cur_diffuse++;
  272. type = aiTextureType_DIFFUSE;
  273. }
  274. // setup texture
  275. out->AddProperty(&s,AI_MATKEY_TEXTURE(type,index));
  276. // setup texture flags
  277. const int use_alpha = ((*it).alpha_test != Q3Shader::AT_NONE ? aiTextureFlags_UseAlpha : aiTextureFlags_IgnoreAlpha);
  278. out->AddProperty(&use_alpha,1,AI_MATKEY_TEXFLAGS(type,index));
  279. }
  280. // If at least one emissive texture was set, set the emissive base color to 1 to ensure
  281. // the texture is actually displayed.
  282. if (0 != cur_emissive) {
  283. aiColor3D one(1.f,1.f,1.f);
  284. out->AddProperty(&one,1,AI_MATKEY_COLOR_EMISSIVE);
  285. }
  286. }
  287. // ------------------------------------------------------------------------------------------------
  288. // Constructor to be privately used by Importer
  289. MD3Importer::MD3Importer()
  290. : configFrameID (0)
  291. , configHandleMP (true)
  292. {}
  293. // ------------------------------------------------------------------------------------------------
  294. // Destructor, private as well
  295. MD3Importer::~MD3Importer()
  296. {}
  297. // ------------------------------------------------------------------------------------------------
  298. // Returns whether the class can handle the format of the given file.
  299. bool MD3Importer::CanRead( const std::string& pFile, IOSystem* pIOHandler, bool checkSig) const
  300. {
  301. const std::string extension = GetExtension(pFile);
  302. if (extension == "md3")
  303. return true;
  304. // if check for extension is not enough, check for the magic tokens
  305. if (!extension.length() || checkSig) {
  306. uint32_t tokens[1];
  307. tokens[0] = AI_MD3_MAGIC_NUMBER_LE;
  308. return CheckMagicToken(pIOHandler,pFile,tokens,1);
  309. }
  310. return false;
  311. }
  312. // ------------------------------------------------------------------------------------------------
  313. void MD3Importer::ValidateHeaderOffsets()
  314. {
  315. // Check magic number
  316. if (pcHeader->IDENT != AI_MD3_MAGIC_NUMBER_BE &&
  317. pcHeader->IDENT != AI_MD3_MAGIC_NUMBER_LE)
  318. throw DeadlyImportError( "Invalid MD3 file: Magic bytes not found");
  319. // Check file format version
  320. if (pcHeader->VERSION > 15)
  321. DefaultLogger::get()->warn( "Unsupported MD3 file version. Continuing happily ...");
  322. // Check some offset values whether they are valid
  323. if (!pcHeader->NUM_SURFACES)
  324. throw DeadlyImportError( "Invalid md3 file: NUM_SURFACES is 0");
  325. if (pcHeader->OFS_FRAMES >= fileSize || pcHeader->OFS_SURFACES >= fileSize ||
  326. pcHeader->OFS_EOF > fileSize) {
  327. throw DeadlyImportError("Invalid MD3 header: some offsets are outside the file");
  328. }
  329. if (pcHeader->NUM_FRAMES <= configFrameID )
  330. throw DeadlyImportError("The requested frame is not existing the file");
  331. }
  332. // ------------------------------------------------------------------------------------------------
  333. void MD3Importer::ValidateSurfaceHeaderOffsets(const MD3::Surface* pcSurf)
  334. {
  335. // Calculate the relative offset of the surface
  336. const int32_t ofs = int32_t((const unsigned char*)pcSurf-this->mBuffer);
  337. // Check whether all data chunks are inside the valid range
  338. if (pcSurf->OFS_TRIANGLES + ofs + pcSurf->NUM_TRIANGLES * sizeof(MD3::Triangle) > fileSize ||
  339. pcSurf->OFS_SHADERS + ofs + pcSurf->NUM_SHADER * sizeof(MD3::Shader) > fileSize ||
  340. pcSurf->OFS_ST + ofs + pcSurf->NUM_VERTICES * sizeof(MD3::TexCoord) > fileSize ||
  341. pcSurf->OFS_XYZNORMAL + ofs + pcSurf->NUM_VERTICES * sizeof(MD3::Vertex) > fileSize) {
  342. throw DeadlyImportError("Invalid MD3 surface header: some offsets are outside the file");
  343. }
  344. // Check whether all requirements for Q3 files are met. We don't
  345. // care, but probably someone does.
  346. if (pcSurf->NUM_TRIANGLES > AI_MD3_MAX_TRIANGLES) {
  347. DefaultLogger::get()->warn("MD3: Quake III triangle limit exceeded");
  348. }
  349. if (pcSurf->NUM_SHADER > AI_MD3_MAX_SHADERS) {
  350. DefaultLogger::get()->warn("MD3: Quake III shader limit exceeded");
  351. }
  352. if (pcSurf->NUM_VERTICES > AI_MD3_MAX_VERTS) {
  353. DefaultLogger::get()->warn("MD3: Quake III vertex limit exceeded");
  354. }
  355. if (pcSurf->NUM_FRAMES > AI_MD3_MAX_FRAMES) {
  356. DefaultLogger::get()->warn("MD3: Quake III frame limit exceeded");
  357. }
  358. }
  359. // ------------------------------------------------------------------------------------------------
  360. void MD3Importer::GetExtensionList(std::set<std::string>& extensions)
  361. {
  362. extensions.insert("md3");
  363. }
  364. // ------------------------------------------------------------------------------------------------
  365. // Setup configuration properties
  366. void MD3Importer::SetupProperties(const Importer* pImp)
  367. {
  368. // The
  369. // AI_CONFIG_IMPORT_MD3_KEYFRAME option overrides the
  370. // AI_CONFIG_IMPORT_GLOBAL_KEYFRAME option.
  371. configFrameID = pImp->GetPropertyInteger(AI_CONFIG_IMPORT_MD3_KEYFRAME,-1);
  372. if(static_cast<unsigned int>(-1) == configFrameID) {
  373. configFrameID = pImp->GetPropertyInteger(AI_CONFIG_IMPORT_GLOBAL_KEYFRAME,0);
  374. }
  375. // AI_CONFIG_IMPORT_MD3_HANDLE_MULTIPART
  376. configHandleMP = (0 != pImp->GetPropertyInteger(AI_CONFIG_IMPORT_MD3_HANDLE_MULTIPART,1));
  377. // AI_CONFIG_IMPORT_MD3_SKIN_NAME
  378. configSkinFile = (pImp->GetPropertyString(AI_CONFIG_IMPORT_MD3_SKIN_NAME,"default"));
  379. // AI_CONFIG_IMPORT_MD3_SHADER_SRC
  380. configShaderFile = (pImp->GetPropertyString(AI_CONFIG_IMPORT_MD3_SHADER_SRC,""));
  381. // AI_CONFIG_FAVOUR_SPEED
  382. configSpeedFlag = (0 != pImp->GetPropertyInteger(AI_CONFIG_FAVOUR_SPEED,0));
  383. }
  384. // ------------------------------------------------------------------------------------------------
  385. // Try to read the skin for a MD3 file
  386. void MD3Importer::ReadSkin(Q3Shader::SkinData& fill) const
  387. {
  388. // skip any postfixes (e.g. lower_1.md3)
  389. std::string::size_type s = filename.find_last_of('_');
  390. if (s == std::string::npos) {
  391. s = filename.find_last_of('.');
  392. }
  393. ai_assert(s != std::string::npos);
  394. const std::string skin_file = path + filename.substr(0,s) + "_" + configSkinFile + ".skin";
  395. Q3Shader::LoadSkin(fill,skin_file,mIOHandler);
  396. }
  397. // ------------------------------------------------------------------------------------------------
  398. // Try to read the shader for a MD3 file
  399. void MD3Importer::ReadShader(Q3Shader::ShaderData& fill) const
  400. {
  401. // Determine Q3 model name from given path
  402. const std::string::size_type s = path.find_last_of("\\/",path.length()-2);
  403. const std::string model_file = path.substr(s+1,path.length()-(s+2));
  404. // If no specific dir or file is given, use our default search behaviour
  405. if (!configShaderFile.length()) {
  406. if(!Q3Shader::LoadShader(fill,path + "..\\..\\..\\scripts\\" + model_file + ".shader",mIOHandler)) {
  407. Q3Shader::LoadShader(fill,path + "..\\..\\..\\scripts\\" + filename + ".shader",mIOHandler);
  408. }
  409. }
  410. else {
  411. // If the given string specifies a file, load this file.
  412. // Otherwise it's a directory.
  413. const std::string::size_type st = configShaderFile.find_last_of('.');
  414. if (st == std::string::npos) {
  415. if(!Q3Shader::LoadShader(fill,configShaderFile + model_file + ".shader",mIOHandler)) {
  416. Q3Shader::LoadShader(fill,configShaderFile + filename + ".shader",mIOHandler);
  417. }
  418. }
  419. else {
  420. Q3Shader::LoadShader(fill,configShaderFile,mIOHandler);
  421. }
  422. }
  423. }
  424. // ------------------------------------------------------------------------------------------------
  425. // Tiny helper to remove a single node from its parent' list
  426. void RemoveSingleNodeFromList(aiNode* nd)
  427. {
  428. if (!nd || nd->mNumChildren || !nd->mParent)return;
  429. aiNode* par = nd->mParent;
  430. for (unsigned int i = 0; i < par->mNumChildren;++i) {
  431. if (par->mChildren[i] == nd) {
  432. --par->mNumChildren;
  433. for (;i < par->mNumChildren;++i) {
  434. par->mChildren[i] = par->mChildren[i+1];
  435. }
  436. delete nd;
  437. break;
  438. }
  439. }
  440. }
  441. // ------------------------------------------------------------------------------------------------
  442. // Read a multi-part Q3 player model
  443. bool MD3Importer::ReadMultipartFile()
  444. {
  445. // check whether the file name contains a common postfix, e.g lower_2.md3
  446. std::string::size_type s = filename.find_last_of('_'), t = filename.find_last_of('.');
  447. ai_assert(t != std::string::npos);
  448. if (s == std::string::npos)
  449. s = t;
  450. const std::string mod_filename = filename.substr(0,s);
  451. const std::string suffix = filename.substr(s,t-s);
  452. if (mod_filename == "lower" || mod_filename == "upper" || mod_filename == "head"){
  453. const std::string lower = path + "lower" + suffix + ".md3";
  454. const std::string upper = path + "upper" + suffix + ".md3";
  455. const std::string head = path + "head" + suffix + ".md3";
  456. aiScene* scene_upper = NULL;
  457. aiScene* scene_lower = NULL;
  458. aiScene* scene_head = NULL;
  459. std::string failure;
  460. aiNode* tag_torso, *tag_head;
  461. std::vector<AttachmentInfo> attach;
  462. DefaultLogger::get()->info("Multi part MD3 player model: lower, upper and head parts are joined");
  463. // ensure we won't try to load ourselves recursively
  464. BatchLoader::PropertyMap props;
  465. SetGenericProperty( props.ints, AI_CONFIG_IMPORT_MD3_HANDLE_MULTIPART, 0, NULL);
  466. // now read these three files
  467. BatchLoader batch(mIOHandler);
  468. const unsigned int _lower = batch.AddLoadRequest(lower,0,&props);
  469. const unsigned int _upper = batch.AddLoadRequest(upper,0,&props);
  470. const unsigned int _head = batch.AddLoadRequest(head,0,&props);
  471. batch.LoadAll();
  472. // now construct a dummy scene to place these three parts in
  473. aiScene* master = new aiScene();
  474. aiNode* nd = master->mRootNode = new aiNode();
  475. nd->mName.Set("<MD3_Player>");
  476. // ... and get them. We need all of them.
  477. scene_lower = batch.GetImport(_lower);
  478. if (!scene_lower) {
  479. DefaultLogger::get()->error("M3D: Failed to read multi part model, lower.md3 fails to load");
  480. failure = "lower";
  481. goto error_cleanup;
  482. }
  483. scene_upper = batch.GetImport(_upper);
  484. if (!scene_upper) {
  485. DefaultLogger::get()->error("M3D: Failed to read multi part model, upper.md3 fails to load");
  486. failure = "upper";
  487. goto error_cleanup;
  488. }
  489. scene_head = batch.GetImport(_head);
  490. if (!scene_head) {
  491. DefaultLogger::get()->error("M3D: Failed to read multi part model, head.md3 fails to load");
  492. failure = "head";
  493. goto error_cleanup;
  494. }
  495. // build attachment infos. search for typical Q3 tags
  496. // original root
  497. scene_lower->mRootNode->mName.Set("lower");
  498. attach.push_back(AttachmentInfo(scene_lower, nd));
  499. // tag_torso
  500. tag_torso = scene_lower->mRootNode->FindNode("tag_torso");
  501. if (!tag_torso) {
  502. DefaultLogger::get()->error("M3D: Failed to find attachment tag for multi part model: tag_torso expected");
  503. goto error_cleanup;
  504. }
  505. scene_upper->mRootNode->mName.Set("upper");
  506. attach.push_back(AttachmentInfo(scene_upper,tag_torso));
  507. // tag_head
  508. tag_head = scene_upper->mRootNode->FindNode("tag_head");
  509. if (!tag_head) {
  510. DefaultLogger::get()->error("M3D: Failed to find attachment tag for multi part model: tag_head expected");
  511. goto error_cleanup;
  512. }
  513. scene_head->mRootNode->mName.Set("head");
  514. attach.push_back(AttachmentInfo(scene_head,tag_head));
  515. // Remove tag_head and tag_torso from all other model parts ...
  516. // this ensures (together with AI_INT_MERGE_SCENE_GEN_UNIQUE_NAMES_IF_NECESSARY)
  517. // that tag_torso/tag_head is also the name of the (unique) output node
  518. RemoveSingleNodeFromList (scene_upper->mRootNode->FindNode("tag_torso"));
  519. RemoveSingleNodeFromList (scene_head-> mRootNode->FindNode("tag_head" ));
  520. // Undo the rotations which we applied to the coordinate systems. We're
  521. // working in global Quake space here
  522. scene_head->mRootNode->mTransformation = aiMatrix4x4();
  523. scene_lower->mRootNode->mTransformation = aiMatrix4x4();
  524. scene_upper->mRootNode->mTransformation = aiMatrix4x4();
  525. // and merge the scenes
  526. SceneCombiner::MergeScenes(&mScene,master, attach,
  527. AI_INT_MERGE_SCENE_GEN_UNIQUE_NAMES |
  528. AI_INT_MERGE_SCENE_GEN_UNIQUE_MATNAMES |
  529. AI_INT_MERGE_SCENE_RESOLVE_CROSS_ATTACHMENTS |
  530. (!configSpeedFlag ? AI_INT_MERGE_SCENE_GEN_UNIQUE_NAMES_IF_NECESSARY : 0));
  531. // Now rotate the whole scene 90 degrees around the x axis to convert to internal coordinate system
  532. mScene->mRootNode->mTransformation = aiMatrix4x4(1.f,0.f,0.f,0.f,
  533. 0.f,0.f,1.f,0.f,0.f,-1.f,0.f,0.f,0.f,0.f,0.f,1.f);
  534. return true;
  535. error_cleanup:
  536. delete scene_upper;
  537. delete scene_lower;
  538. delete scene_head;
  539. delete master;
  540. if (failure == mod_filename) {
  541. throw DeadlyImportError("MD3: failure to read multipart host file");
  542. }
  543. }
  544. return false;
  545. }
  546. // ------------------------------------------------------------------------------------------------
  547. // Convert a MD3 path to a proper value
  548. void MD3Importer::ConvertPath(const char* texture_name, const char* header_name, std::string& out) const
  549. {
  550. // If the MD3's internal path itself and the given path are using
  551. // the same directory, remove it completely to get right output paths.
  552. const char* end1 = ::strrchr(header_name,'\\');
  553. if (!end1)end1 = ::strrchr(header_name,'/');
  554. const char* end2 = ::strrchr(texture_name,'\\');
  555. if (!end2)end2 = ::strrchr(texture_name,'/');
  556. // HACK: If the paths starts with "models", ignore the
  557. // next two hierarchy levels, it specifies just the model name.
  558. // Ignored by Q3, it might be not equal to the real model location.
  559. if (end2) {
  560. size_t len2;
  561. const size_t len1 = (size_t)(end1 - header_name);
  562. if (!ASSIMP_strincmp(texture_name,"models",6) && (texture_name[6] == '/' || texture_name[6] == '\\')) {
  563. len2 = 6; // ignore the seventh - could be slash or backslash
  564. if (!header_name[0]) {
  565. // Use the file name only
  566. out = end2+1;
  567. return;
  568. }
  569. }
  570. else len2 = std::min (len1, (size_t)(end2 - texture_name ));
  571. if (!ASSIMP_strincmp(texture_name,header_name,len2)) {
  572. // Use the file name only
  573. out = end2+1;
  574. return;
  575. }
  576. }
  577. // Use the full path
  578. out = texture_name;
  579. }
  580. // ------------------------------------------------------------------------------------------------
  581. // Imports the given file into the given scene structure.
  582. void MD3Importer::InternReadFile( const std::string& pFile,
  583. aiScene* pScene, IOSystem* pIOHandler)
  584. {
  585. mFile = pFile;
  586. mScene = pScene;
  587. mIOHandler = pIOHandler;
  588. // get base path and file name
  589. // todo ... move to PathConverter
  590. std::string::size_type s = mFile.find_last_of("/\\");
  591. if (s == std::string::npos) {
  592. s = 0;
  593. }
  594. else ++s;
  595. filename = mFile.substr(s), path = mFile.substr(0,s);
  596. for( std::string::iterator it = filename .begin(); it != filename.end(); ++it)
  597. *it = tolower( *it);
  598. // Load multi-part model file, if necessary
  599. if (configHandleMP) {
  600. if (ReadMultipartFile())
  601. return;
  602. }
  603. boost::scoped_ptr<IOStream> file( pIOHandler->Open( pFile));
  604. // Check whether we can read from the file
  605. if( file.get() == NULL)
  606. throw DeadlyImportError( "Failed to open MD3 file " + pFile + ".");
  607. // Check whether the md3 file is large enough to contain the header
  608. fileSize = (unsigned int)file->FileSize();
  609. if( fileSize < sizeof(MD3::Header))
  610. throw DeadlyImportError( "MD3 File is too small.");
  611. // Allocate storage and copy the contents of the file to a memory buffer
  612. std::vector<unsigned char> mBuffer2 (fileSize);
  613. file->Read( &mBuffer2[0], 1, fileSize);
  614. mBuffer = &mBuffer2[0];
  615. pcHeader = (BE_NCONST MD3::Header*)mBuffer;
  616. // Ensure correct endianess
  617. #ifdef AI_BUILD_BIG_ENDIAN
  618. AI_SWAP4(pcHeader->VERSION);
  619. AI_SWAP4(pcHeader->FLAGS);
  620. AI_SWAP4(pcHeader->IDENT);
  621. AI_SWAP4(pcHeader->NUM_FRAMES);
  622. AI_SWAP4(pcHeader->NUM_SKINS);
  623. AI_SWAP4(pcHeader->NUM_SURFACES);
  624. AI_SWAP4(pcHeader->NUM_TAGS);
  625. AI_SWAP4(pcHeader->OFS_EOF);
  626. AI_SWAP4(pcHeader->OFS_FRAMES);
  627. AI_SWAP4(pcHeader->OFS_SURFACES);
  628. AI_SWAP4(pcHeader->OFS_TAGS);
  629. #endif
  630. // Validate the file header
  631. ValidateHeaderOffsets();
  632. // Navigate to the list of surfaces
  633. BE_NCONST MD3::Surface* pcSurfaces = (BE_NCONST MD3::Surface*)(mBuffer + pcHeader->OFS_SURFACES);
  634. // Navigate to the list of tags
  635. BE_NCONST MD3::Tag* pcTags = (BE_NCONST MD3::Tag*)(mBuffer + pcHeader->OFS_TAGS);
  636. // Allocate output storage
  637. pScene->mNumMeshes = pcHeader->NUM_SURFACES;
  638. pScene->mMeshes = new aiMesh*[pScene->mNumMeshes];
  639. pScene->mNumMaterials = pcHeader->NUM_SURFACES;
  640. pScene->mMaterials = new aiMaterial*[pScene->mNumMeshes];
  641. // Set arrays to zero to ensue proper destruction if an exception is raised
  642. ::memset(pScene->mMeshes,0,pScene->mNumMeshes*sizeof(aiMesh*));
  643. ::memset(pScene->mMaterials,0,pScene->mNumMaterials*sizeof(aiMaterial*));
  644. // Now read possible skins from .skin file
  645. Q3Shader::SkinData skins;
  646. ReadSkin(skins);
  647. // And check whether we can locate a shader file for this model
  648. Q3Shader::ShaderData shaders;
  649. ReadShader(shaders);
  650. // Adjust all texture paths in the shader
  651. const char* header_name = pcHeader->NAME;
  652. if (shaders.blocks.size()) {
  653. for (std::list< Q3Shader::ShaderDataBlock >::iterator dit = shaders.blocks.begin(); dit != shaders.blocks.end(); ++dit) {
  654. ConvertPath((*dit).name.c_str(),header_name,(*dit).name);
  655. for (std::list< Q3Shader::ShaderMapBlock >::iterator mit = (*dit).maps.begin(); mit != (*dit).maps.end(); ++mit) {
  656. ConvertPath((*mit).name.c_str(),header_name,(*mit).name);
  657. }
  658. }
  659. }
  660. // Read all surfaces from the file
  661. unsigned int iNum = pcHeader->NUM_SURFACES;
  662. unsigned int iNumMaterials = 0;
  663. while (iNum-- > 0) {
  664. // Ensure correct endianess
  665. #ifdef AI_BUILD_BIG_ENDIAN
  666. AI_SWAP4(pcSurfaces->FLAGS);
  667. AI_SWAP4(pcSurfaces->IDENT);
  668. AI_SWAP4(pcSurfaces->NUM_FRAMES);
  669. AI_SWAP4(pcSurfaces->NUM_SHADER);
  670. AI_SWAP4(pcSurfaces->NUM_TRIANGLES);
  671. AI_SWAP4(pcSurfaces->NUM_VERTICES);
  672. AI_SWAP4(pcSurfaces->OFS_END);
  673. AI_SWAP4(pcSurfaces->OFS_SHADERS);
  674. AI_SWAP4(pcSurfaces->OFS_ST);
  675. AI_SWAP4(pcSurfaces->OFS_TRIANGLES);
  676. AI_SWAP4(pcSurfaces->OFS_XYZNORMAL);
  677. #endif
  678. // Validate the surface header
  679. ValidateSurfaceHeaderOffsets(pcSurfaces);
  680. // Navigate to the vertex list of the surface
  681. BE_NCONST MD3::Vertex* pcVertices = (BE_NCONST MD3::Vertex*)
  682. (((uint8_t*)pcSurfaces) + pcSurfaces->OFS_XYZNORMAL);
  683. // Navigate to the triangle list of the surface
  684. BE_NCONST MD3::Triangle* pcTriangles = (BE_NCONST MD3::Triangle*)
  685. (((uint8_t*)pcSurfaces) + pcSurfaces->OFS_TRIANGLES);
  686. // Navigate to the texture coordinate list of the surface
  687. BE_NCONST MD3::TexCoord* pcUVs = (BE_NCONST MD3::TexCoord*)
  688. (((uint8_t*)pcSurfaces) + pcSurfaces->OFS_ST);
  689. // Navigate to the shader list of the surface
  690. BE_NCONST MD3::Shader* pcShaders = (BE_NCONST MD3::Shader*)
  691. (((uint8_t*)pcSurfaces) + pcSurfaces->OFS_SHADERS);
  692. // If the submesh is empty ignore it
  693. if (0 == pcSurfaces->NUM_VERTICES || 0 == pcSurfaces->NUM_TRIANGLES)
  694. {
  695. pcSurfaces = (BE_NCONST MD3::Surface*)(((uint8_t*)pcSurfaces) + pcSurfaces->OFS_END);
  696. pScene->mNumMeshes--;
  697. continue;
  698. }
  699. // Allocate output mesh
  700. pScene->mMeshes[iNum] = new aiMesh();
  701. aiMesh* pcMesh = pScene->mMeshes[iNum];
  702. std::string _texture_name;
  703. const char* texture_name = NULL;
  704. // Check whether we have a texture record for this surface in the .skin file
  705. std::list< Q3Shader::SkinData::TextureEntry >::iterator it = std::find(
  706. skins.textures.begin(), skins.textures.end(), pcSurfaces->NAME );
  707. if (it != skins.textures.end()) {
  708. texture_name = &*( _texture_name = (*it).second).begin();
  709. DefaultLogger::get()->debug("MD3: Assigning skin texture " + (*it).second + " to surface " + pcSurfaces->NAME);
  710. (*it).resolved = true; // mark entry as resolved
  711. }
  712. // Get the first shader (= texture?) assigned to the surface
  713. if (!texture_name && pcSurfaces->NUM_SHADER) {
  714. texture_name = pcShaders->NAME;
  715. }
  716. std::string convertedPath;
  717. if (texture_name) {
  718. ConvertPath(texture_name,header_name,convertedPath);
  719. }
  720. const Q3Shader::ShaderDataBlock* shader = NULL;
  721. // Now search the current shader for a record with this name (
  722. // excluding texture file extension)
  723. if (shaders.blocks.size()) {
  724. std::string::size_type s = convertedPath.find_last_of('.');
  725. if (s == std::string::npos)
  726. s = convertedPath.length();
  727. const std::string without_ext = convertedPath.substr(0,s);
  728. std::list< Q3Shader::ShaderDataBlock >::const_iterator dit = std::find(shaders.blocks.begin(),shaders.blocks.end(),without_ext);
  729. if (dit != shaders.blocks.end()) {
  730. // Hurra, wir haben einen. Tolle Sache.
  731. shader = &*dit;
  732. DefaultLogger::get()->info("Found shader record for " +without_ext );
  733. }
  734. else DefaultLogger::get()->warn("Unable to find shader record for " +without_ext );
  735. }
  736. aiMaterial* pcHelper = new aiMaterial();
  737. const int iMode = (int)aiShadingMode_Gouraud;
  738. pcHelper->AddProperty<int>(&iMode, 1, AI_MATKEY_SHADING_MODEL);
  739. // Add a small ambient color value - Quake 3 seems to have one
  740. aiColor3D clr;
  741. clr.b = clr.g = clr.r = 0.05f;
  742. pcHelper->AddProperty<aiColor3D>(&clr, 1,AI_MATKEY_COLOR_AMBIENT);
  743. clr.b = clr.g = clr.r = 1.0f;
  744. pcHelper->AddProperty<aiColor3D>(&clr, 1,AI_MATKEY_COLOR_DIFFUSE);
  745. pcHelper->AddProperty<aiColor3D>(&clr, 1,AI_MATKEY_COLOR_SPECULAR);
  746. // use surface name + skin_name as material name
  747. aiString name;
  748. name.Set("MD3_[" + configSkinFile + "][" + pcSurfaces->NAME + "]");
  749. pcHelper->AddProperty(&name,AI_MATKEY_NAME);
  750. if (!shader) {
  751. // Setup dummy texture file name to ensure UV coordinates are kept during postprocessing
  752. aiString szString;
  753. if (convertedPath.length()) {
  754. szString.Set(convertedPath);
  755. }
  756. else {
  757. DefaultLogger::get()->warn("Texture file name has zero length. Using default name");
  758. szString.Set("dummy_texture.bmp");
  759. }
  760. pcHelper->AddProperty(&szString,AI_MATKEY_TEXTURE_DIFFUSE(0));
  761. // prevent transparency by default
  762. int no_alpha = aiTextureFlags_IgnoreAlpha;
  763. pcHelper->AddProperty(&no_alpha,1,AI_MATKEY_TEXFLAGS_DIFFUSE(0));
  764. }
  765. else {
  766. Q3Shader::ConvertShaderToMaterial(pcHelper,*shader);
  767. }
  768. pScene->mMaterials[iNumMaterials] = (aiMaterial*)pcHelper;
  769. pcMesh->mMaterialIndex = iNumMaterials++;
  770. // Ensure correct endianess
  771. #ifdef AI_BUILD_BIG_ENDIAN
  772. for (uint32_t i = 0; i < pcSurfaces->NUM_VERTICES;++i) {
  773. AI_SWAP2( pcVertices[i].NORMAL );
  774. AI_SWAP2( pcVertices[i].X );
  775. AI_SWAP2( pcVertices[i].Y );
  776. AI_SWAP2( pcVertices[i].Z );
  777. AI_SWAP4( pcUVs[i].U );
  778. AI_SWAP4( pcUVs[i].U );
  779. }
  780. for (uint32_t i = 0; i < pcSurfaces->NUM_TRIANGLES;++i) {
  781. AI_SWAP4(pcTriangles[i].INDEXES[0]);
  782. AI_SWAP4(pcTriangles[i].INDEXES[1]);
  783. AI_SWAP4(pcTriangles[i].INDEXES[2]);
  784. }
  785. #endif
  786. // Fill mesh information
  787. pcMesh->mPrimitiveTypes = aiPrimitiveType_TRIANGLE;
  788. pcMesh->mNumVertices = pcSurfaces->NUM_TRIANGLES*3;
  789. pcMesh->mNumFaces = pcSurfaces->NUM_TRIANGLES;
  790. pcMesh->mFaces = new aiFace[pcSurfaces->NUM_TRIANGLES];
  791. pcMesh->mNormals = new aiVector3D[pcMesh->mNumVertices];
  792. pcMesh->mVertices = new aiVector3D[pcMesh->mNumVertices];
  793. pcMesh->mTextureCoords[0] = new aiVector3D[pcMesh->mNumVertices];
  794. pcMesh->mNumUVComponents[0] = 2;
  795. // Fill in all triangles
  796. unsigned int iCurrent = 0;
  797. for (unsigned int i = 0; i < (unsigned int)pcSurfaces->NUM_TRIANGLES;++i) {
  798. pcMesh->mFaces[i].mIndices = new unsigned int[3];
  799. pcMesh->mFaces[i].mNumIndices = 3;
  800. //unsigned int iTemp = iCurrent;
  801. for (unsigned int c = 0; c < 3;++c,++iCurrent) {
  802. pcMesh->mFaces[i].mIndices[c] = iCurrent;
  803. // Read vertices
  804. aiVector3D& vec = pcMesh->mVertices[iCurrent];
  805. vec.x = pcVertices[ pcTriangles->INDEXES[c]].X*AI_MD3_XYZ_SCALE;
  806. vec.y = pcVertices[ pcTriangles->INDEXES[c]].Y*AI_MD3_XYZ_SCALE;
  807. vec.z = pcVertices[ pcTriangles->INDEXES[c]].Z*AI_MD3_XYZ_SCALE;
  808. // Convert the normal vector to uncompressed float3 format
  809. aiVector3D& nor = pcMesh->mNormals[iCurrent];
  810. LatLngNormalToVec3(pcVertices[pcTriangles->INDEXES[c]].NORMAL,(float*)&nor);
  811. // Read texture coordinates
  812. pcMesh->mTextureCoords[0][iCurrent].x = pcUVs[ pcTriangles->INDEXES[c]].U;
  813. pcMesh->mTextureCoords[0][iCurrent].y = 1.0f-pcUVs[ pcTriangles->INDEXES[c]].V;
  814. }
  815. // Flip face order if necessary
  816. if (!shader || shader->cull == Q3Shader::CULL_CW) {
  817. std::swap(pcMesh->mFaces[i].mIndices[2],pcMesh->mFaces[i].mIndices[1]);
  818. }
  819. pcTriangles++;
  820. }
  821. // Go to the next surface
  822. pcSurfaces = (BE_NCONST MD3::Surface*)(((unsigned char*)pcSurfaces) + pcSurfaces->OFS_END);
  823. }
  824. // For debugging purposes: check whether we found matches for all entries in the skins file
  825. if (!DefaultLogger::isNullLogger()) {
  826. for (std::list< Q3Shader::SkinData::TextureEntry>::const_iterator it = skins.textures.begin();it != skins.textures.end(); ++it) {
  827. if (!(*it).resolved) {
  828. DefaultLogger::get()->error("MD3: Failed to match skin " + (*it).first + " to surface " + (*it).second);
  829. }
  830. }
  831. }
  832. if (!pScene->mNumMeshes)
  833. throw DeadlyImportError( "MD3: File contains no valid mesh");
  834. pScene->mNumMaterials = iNumMaterials;
  835. // Now we need to generate an empty node graph
  836. pScene->mRootNode = new aiNode("<MD3Root>");
  837. pScene->mRootNode->mNumMeshes = pScene->mNumMeshes;
  838. pScene->mRootNode->mMeshes = new unsigned int[pScene->mNumMeshes];
  839. // Attach tiny children for all tags
  840. if (pcHeader->NUM_TAGS) {
  841. pScene->mRootNode->mNumChildren = pcHeader->NUM_TAGS;
  842. pScene->mRootNode->mChildren = new aiNode*[pcHeader->NUM_TAGS];
  843. for (unsigned int i = 0; i < pcHeader->NUM_TAGS; ++i, ++pcTags) {
  844. aiNode* nd = pScene->mRootNode->mChildren[i] = new aiNode();
  845. nd->mName.Set((const char*)pcTags->NAME);
  846. nd->mParent = pScene->mRootNode;
  847. AI_SWAP4(pcTags->origin.x);
  848. AI_SWAP4(pcTags->origin.y);
  849. AI_SWAP4(pcTags->origin.z);
  850. // Copy local origin, again flip z,y
  851. nd->mTransformation.a4 = pcTags->origin.x;
  852. nd->mTransformation.b4 = pcTags->origin.y;
  853. nd->mTransformation.c4 = pcTags->origin.z;
  854. // Copy rest of transformation (need to transpose to match row-order matrix)
  855. for (unsigned int a = 0; a < 3;++a) {
  856. for (unsigned int m = 0; m < 3;++m) {
  857. nd->mTransformation[m][a] = pcTags->orientation[a][m];
  858. AI_SWAP4(nd->mTransformation[m][a]);
  859. }
  860. }
  861. }
  862. }
  863. for (unsigned int i = 0; i < pScene->mNumMeshes;++i)
  864. pScene->mRootNode->mMeshes[i] = i;
  865. // Now rotate the whole scene 90 degrees around the x axis to convert to internal coordinate system
  866. pScene->mRootNode->mTransformation = aiMatrix4x4(1.f,0.f,0.f,0.f,
  867. 0.f,0.f,1.f,0.f,0.f,-1.f,0.f,0.f,0.f,0.f,0.f,1.f);
  868. }
  869. #endif // !! ASSIMP_BUILD_NO_MD3_IMPORTER