MD3Loader.cpp 36 KB

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