MDCLoader.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471
  1. /*
  2. ---------------------------------------------------------------------------
  3. Open Asset Import Library (assimp)
  4. ---------------------------------------------------------------------------
  5. Copyright (c) 2006-2025, 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 Implementation of the MDC importer class */
  35. #ifndef ASSIMP_BUILD_NO_MDC_IMPORTER
  36. // internal headers
  37. #include "MDCLoader.h"
  38. #include "AssetLib/MD3/MD3FileData.h"
  39. #include "MDCNormalTable.h" // shouldn't be included by other units
  40. #include <assimp/importerdesc.h>
  41. #include <assimp/scene.h>
  42. #include <assimp/DefaultLogger.hpp>
  43. #include <assimp/IOSystem.hpp>
  44. #include <assimp/Importer.hpp>
  45. #include <assimp/StringUtils.h>
  46. #include <memory>
  47. using namespace Assimp;
  48. using namespace Assimp::MDC;
  49. static constexpr aiImporterDesc desc = {
  50. "Return To Castle Wolfenstein Mesh Importer",
  51. "",
  52. "",
  53. "",
  54. aiImporterFlags_SupportBinaryFlavour,
  55. 0,
  56. 0,
  57. 0,
  58. 0,
  59. "mdc"
  60. };
  61. // ------------------------------------------------------------------------------------------------
  62. void MDC::BuildVertex(const Frame &frame,
  63. const BaseVertex &bvert,
  64. const CompressedVertex &cvert,
  65. aiVector3D &vXYZOut,
  66. aiVector3D &vNorOut) {
  67. // compute the position
  68. const float xd = (cvert.xd - AI_MDC_CVERT_BIAS) * AI_MDC_DELTA_SCALING;
  69. const float yd = (cvert.yd - AI_MDC_CVERT_BIAS) * AI_MDC_DELTA_SCALING;
  70. const float zd = (cvert.zd - AI_MDC_CVERT_BIAS) * AI_MDC_DELTA_SCALING;
  71. vXYZOut.x = frame.localOrigin.x + AI_MDC_BASE_SCALING * (bvert.x + xd);
  72. vXYZOut.y = frame.localOrigin.y + AI_MDC_BASE_SCALING * (bvert.y + yd);
  73. vXYZOut.z = frame.localOrigin.z + AI_MDC_BASE_SCALING * (bvert.z + zd);
  74. // compute the normal vector .. ehm ... lookup it in the table :-)
  75. vNorOut.x = mdcNormals[cvert.nd][0];
  76. vNorOut.y = mdcNormals[cvert.nd][1];
  77. vNorOut.z = mdcNormals[cvert.nd][2];
  78. }
  79. // ------------------------------------------------------------------------------------------------
  80. // Constructor to be privately used by Importer
  81. MDCImporter::MDCImporter() :
  82. configFrameID(),
  83. pcHeader(),
  84. mBuffer(),
  85. fileSize() {
  86. // empty
  87. }
  88. // ------------------------------------------------------------------------------------------------
  89. // Returns whether the class can handle the format of the given file.
  90. bool MDCImporter::CanRead(const std::string &pFile, IOSystem *pIOHandler, bool /*checkSig*/) const {
  91. static constexpr uint32_t tokens[] = { AI_MDC_MAGIC_NUMBER_LE };
  92. return CheckMagicToken(pIOHandler, pFile, tokens, AI_COUNT_OF(tokens));
  93. }
  94. // ------------------------------------------------------------------------------------------------
  95. const aiImporterDesc *MDCImporter::GetInfo() const {
  96. return &desc;
  97. }
  98. // ------------------------------------------------------------------------------------------------
  99. // Validate the header of the given MDC file
  100. void MDCImporter::ValidateHeader() {
  101. AI_SWAP4(this->pcHeader->ulVersion);
  102. AI_SWAP4(this->pcHeader->ulFlags);
  103. AI_SWAP4(this->pcHeader->ulNumFrames);
  104. AI_SWAP4(this->pcHeader->ulNumTags);
  105. AI_SWAP4(this->pcHeader->ulNumSurfaces);
  106. AI_SWAP4(this->pcHeader->ulNumSkins);
  107. AI_SWAP4(this->pcHeader->ulOffsetBorderFrames);
  108. if (pcHeader->ulIdent != AI_MDC_MAGIC_NUMBER_BE &&
  109. pcHeader->ulIdent != AI_MDC_MAGIC_NUMBER_LE) {
  110. throw DeadlyImportError("Invalid MDC magic word: expected IDPC, found ",
  111. ai_str_toprintable((char *)&pcHeader->ulIdent, 4));
  112. }
  113. if (pcHeader->ulVersion != AI_MDC_VERSION) {
  114. ASSIMP_LOG_WARN("Unsupported MDC file version (2 (AI_MDC_VERSION) was expected)");
  115. }
  116. if (pcHeader->ulOffsetBorderFrames + pcHeader->ulNumFrames * sizeof(MDC::Frame) > this->fileSize ||
  117. pcHeader->ulOffsetSurfaces + pcHeader->ulNumSurfaces * sizeof(MDC::Surface) > this->fileSize) {
  118. throw DeadlyImportError("Some of the offset values in the MDC header are invalid "
  119. "and point to something behind the file.");
  120. }
  121. if (this->configFrameID >= this->pcHeader->ulNumFrames) {
  122. throw DeadlyImportError("The requested frame is not available");
  123. }
  124. }
  125. // ------------------------------------------------------------------------------------------------
  126. // Validate the header of a given MDC file surface
  127. void MDCImporter::ValidateSurfaceHeader(BE_NCONST MDC::Surface *pcSurf) {
  128. AI_SWAP4(pcSurf->ulFlags);
  129. AI_SWAP4(pcSurf->ulNumCompFrames);
  130. AI_SWAP4(pcSurf->ulNumBaseFrames);
  131. AI_SWAP4(pcSurf->ulNumShaders);
  132. AI_SWAP4(pcSurf->ulNumVertices);
  133. AI_SWAP4(pcSurf->ulNumTriangles);
  134. AI_SWAP4(pcSurf->ulOffsetTriangles);
  135. AI_SWAP4(pcSurf->ulOffsetTexCoords);
  136. AI_SWAP4(pcSurf->ulOffsetBaseVerts);
  137. AI_SWAP4(pcSurf->ulOffsetCompVerts);
  138. AI_SWAP4(pcSurf->ulOffsetShaders);
  139. AI_SWAP4(pcSurf->ulOffsetFrameBaseFrames);
  140. AI_SWAP4(pcSurf->ulOffsetFrameCompFrames);
  141. AI_SWAP4(pcSurf->ulOffsetEnd);
  142. const unsigned int iMax = this->fileSize - (unsigned int)((int8_t *)pcSurf - (int8_t *)pcHeader);
  143. if (pcSurf->ulOffsetBaseVerts + pcSurf->ulNumVertices * sizeof(MDC::BaseVertex) > iMax ||
  144. (pcSurf->ulNumCompFrames && pcSurf->ulOffsetCompVerts + pcSurf->ulNumVertices * sizeof(MDC::CompressedVertex) > iMax) ||
  145. pcSurf->ulOffsetTriangles + pcSurf->ulNumTriangles * sizeof(MDC::Triangle) > iMax ||
  146. pcSurf->ulOffsetTexCoords + pcSurf->ulNumVertices * sizeof(MDC::TexturCoord) > iMax ||
  147. pcSurf->ulOffsetShaders + pcSurf->ulNumShaders * sizeof(MDC::Shader) > iMax ||
  148. pcSurf->ulOffsetFrameBaseFrames + pcSurf->ulNumBaseFrames * 2 > iMax ||
  149. (pcSurf->ulNumCompFrames && pcSurf->ulOffsetFrameCompFrames + pcSurf->ulNumCompFrames * 2 > iMax) ||
  150. pcSurf->ulOffsetEnd > iMax) {
  151. throw DeadlyImportError("Some of the offset values in the MDC surface header "
  152. "are invalid and point somewhere behind the file.");
  153. }
  154. }
  155. // ------------------------------------------------------------------------------------------------
  156. // Setup configuration properties
  157. void MDCImporter::SetupProperties(const Importer *pImp) {
  158. // The AI_CONFIG_IMPORT_MDC_KEYFRAME option overrides the
  159. // AI_CONFIG_IMPORT_GLOBAL_KEYFRAME option.
  160. if (static_cast<unsigned int>(-1) == (configFrameID = pImp->GetPropertyInteger(AI_CONFIG_IMPORT_MDC_KEYFRAME, -1))) {
  161. configFrameID = pImp->GetPropertyInteger(AI_CONFIG_IMPORT_GLOBAL_KEYFRAME, 0);
  162. }
  163. }
  164. // ------------------------------------------------------------------------------------------------
  165. // Imports the given file into the given scene structure.
  166. void MDCImporter::InternReadFile(
  167. const std::string &pFile, aiScene *pScene, IOSystem *pIOHandler) {
  168. std::unique_ptr<IOStream> file(pIOHandler->Open(pFile));
  169. // Check whether we can read from the file
  170. if (file == nullptr) {
  171. throw DeadlyImportError("Failed to open MDC file ", pFile, ".");
  172. }
  173. // check whether the mdc file is large enough to contain the file header
  174. fileSize = static_cast<unsigned int>(file->FileSize());
  175. if (fileSize < sizeof(MDC::Header)) {
  176. throw DeadlyImportError("MDC File is too small.");
  177. }
  178. std::vector<unsigned char> mBuffer2(fileSize);
  179. file->Read(&mBuffer2[0], 1, fileSize);
  180. mBuffer = &mBuffer2[0];
  181. // validate the file header
  182. this->pcHeader = (BE_NCONST MDC::Header *)this->mBuffer;
  183. this->ValidateHeader();
  184. std::vector<std::string> aszShaders;
  185. // get a pointer to the frame we want to read
  186. BE_NCONST MDC::Frame *pcFrame = (BE_NCONST MDC::Frame *)(this->mBuffer +
  187. this->pcHeader->ulOffsetBorderFrames);
  188. // no need to swap the other members, we won't need them
  189. pcFrame += configFrameID;
  190. AI_SWAP4(pcFrame->localOrigin[0]);
  191. AI_SWAP4(pcFrame->localOrigin[1]);
  192. AI_SWAP4(pcFrame->localOrigin[2]);
  193. // get the number of valid surfaces
  194. BE_NCONST MDC::Surface *pcSurface, *pcSurface2;
  195. pcSurface = pcSurface2 = reinterpret_cast<BE_NCONST MDC::Surface *>(mBuffer + pcHeader->ulOffsetSurfaces);
  196. unsigned int iNumShaders = 0;
  197. for (unsigned int i = 0; i < pcHeader->ulNumSurfaces; ++i) {
  198. // validate the surface header
  199. this->ValidateSurfaceHeader(pcSurface2);
  200. if (pcSurface2->ulNumVertices && pcSurface2->ulNumTriangles) {
  201. ++pScene->mNumMeshes;
  202. }
  203. iNumShaders += pcSurface2->ulNumShaders;
  204. pcSurface2 = reinterpret_cast<BE_NCONST MDC::Surface *>((BE_NCONST int8_t *)pcSurface2 + pcSurface2->ulOffsetEnd);
  205. }
  206. aszShaders.reserve(iNumShaders);
  207. pScene->mMeshes = new aiMesh *[pScene->mNumMeshes];
  208. // necessary that we don't crash if an exception occurs
  209. for (unsigned int i = 0; i < pScene->mNumMeshes; ++i) {
  210. pScene->mMeshes[i] = nullptr;
  211. }
  212. // now read all surfaces
  213. unsigned int iDefaultMatIndex = UINT_MAX;
  214. for (unsigned int i = 0, iNum = 0; i < pcHeader->ulNumSurfaces; ++i) {
  215. if (!pcSurface->ulNumVertices || !pcSurface->ulNumTriangles) continue;
  216. aiMesh *pcMesh = pScene->mMeshes[iNum++] = new aiMesh();
  217. pcMesh->mNumFaces = pcSurface->ulNumTriangles;
  218. pcMesh->mNumVertices = pcMesh->mNumFaces * 3;
  219. // store the name of the surface for use as node name.
  220. pcMesh->mName.Set(std::string(pcSurface->ucName, strnlen(pcSurface->ucName, AI_MDC_MAXQPATH - 1)));
  221. // go to the first shader in the file. ignore the others.
  222. if (pcSurface->ulNumShaders) {
  223. const MDC::Shader *pcShader = (const MDC::Shader *)((int8_t *)pcSurface + pcSurface->ulOffsetShaders);
  224. pcMesh->mMaterialIndex = (unsigned int)aszShaders.size();
  225. // create a new shader
  226. aszShaders.emplace_back(pcShader->ucName,
  227. ::strnlen(pcShader->ucName, sizeof(pcShader->ucName)));
  228. }
  229. // need to create a default material
  230. else if (UINT_MAX == iDefaultMatIndex) {
  231. pcMesh->mMaterialIndex = iDefaultMatIndex = (unsigned int)aszShaders.size();
  232. aszShaders.emplace_back();
  233. }
  234. // otherwise assign a reference to the default material
  235. else
  236. pcMesh->mMaterialIndex = iDefaultMatIndex;
  237. // allocate output storage for the mesh
  238. aiVector3D *pcVertCur = pcMesh->mVertices = new aiVector3D[pcMesh->mNumVertices];
  239. aiVector3D *pcNorCur = pcMesh->mNormals = new aiVector3D[pcMesh->mNumVertices];
  240. aiVector3D *pcUVCur = pcMesh->mTextureCoords[0] = new aiVector3D[pcMesh->mNumVertices];
  241. aiFace *pcFaceCur = pcMesh->mFaces = new aiFace[pcMesh->mNumFaces];
  242. // create all vertices/faces
  243. BE_NCONST MDC::Triangle *pcTriangle = (BE_NCONST MDC::Triangle *)((int8_t *)pcSurface + pcSurface->ulOffsetTriangles);
  244. BE_NCONST MDC::TexturCoord *const pcUVs = (BE_NCONST MDC::TexturCoord *)((int8_t *)pcSurface + pcSurface->ulOffsetTexCoords);
  245. // get a pointer to the uncompressed vertices
  246. int16_t iOfs = *((int16_t *)((int8_t *)pcSurface +
  247. pcSurface->ulOffsetFrameBaseFrames) +
  248. this->configFrameID);
  249. AI_SWAP2(iOfs);
  250. BE_NCONST MDC::BaseVertex *const pcVerts = (BE_NCONST MDC::BaseVertex *)((int8_t *)pcSurface + pcSurface->ulOffsetBaseVerts) +
  251. ((int)iOfs * pcSurface->ulNumVertices * 4);
  252. // do the main swapping stuff ...
  253. #if (defined AI_BUILD_BIG_ENDIAN)
  254. // swap all triangles
  255. for (unsigned int i = 0; i < pcSurface->ulNumTriangles; ++i) {
  256. AI_SWAP4(pcTriangle[i].aiIndices[0]);
  257. AI_SWAP4(pcTriangle[i].aiIndices[1]);
  258. AI_SWAP4(pcTriangle[i].aiIndices[2]);
  259. }
  260. // swap all vertices
  261. for (unsigned int i = 0; i < pcSurface->ulNumVertices * pcSurface->ulNumBaseFrames; ++i) {
  262. AI_SWAP2(pcVerts->normal);
  263. AI_SWAP2(pcVerts->x);
  264. AI_SWAP2(pcVerts->y);
  265. AI_SWAP2(pcVerts->z);
  266. }
  267. // swap all texture coordinates
  268. for (unsigned int i = 0; i < pcSurface->ulNumVertices; ++i) {
  269. AI_SWAP4(pcUVs->u);
  270. AI_SWAP4(pcUVs->v);
  271. }
  272. #endif
  273. // boundary check for pcVerts
  274. auto surfStart = reinterpret_cast<const uint8_t*>(pcSurface);
  275. const uint8_t* surfEnd = surfStart + pcSurface->ulOffsetEnd;
  276. auto vertBufStart = reinterpret_cast<const uint8_t*>(pcVerts);
  277. const size_t needVertBytes = sizeof(MDC::BaseVertex) * pcSurface->ulNumVertices;
  278. if (vertBufStart < surfStart || vertBufStart + needVertBytes > surfEnd) {
  279. throw DeadlyImportError("MDCImporter: pcVerts points outside of surface block.");
  280. }
  281. const MDC::CompressedVertex *pcCVerts = nullptr;
  282. int16_t *mdcCompVert = nullptr;
  283. // access compressed frames for large frame numbers, but never for the first
  284. if (this->configFrameID && pcSurface->ulNumCompFrames > 0) {
  285. mdcCompVert = (int16_t *)((int8_t *)pcSurface + pcSurface->ulOffsetFrameCompFrames) + this->configFrameID;
  286. AI_SWAP2P(mdcCompVert);
  287. if (*mdcCompVert >= 0) {
  288. pcCVerts = (const MDC::CompressedVertex *)((int8_t *)pcSurface +
  289. pcSurface->ulOffsetCompVerts) +
  290. *mdcCompVert * pcSurface->ulNumVertices;
  291. auto cvertBufStart = reinterpret_cast<const uint8_t*>(pcCVerts);
  292. const size_t needCompVertBytes = sizeof(MDC::CompressedVertex) * pcSurface->ulNumVertices;
  293. if (cvertBufStart < surfStart || cvertBufStart > surfEnd ||
  294. needCompVertBytes > static_cast<size_t>(surfEnd - cvertBufStart)) {
  295. throw DeadlyImportError("MDCImporter: pcCVerts points outside of surface block.");
  296. }
  297. } else
  298. mdcCompVert = nullptr;
  299. }
  300. // copy all faces
  301. for (unsigned int iFace = 0; iFace < pcSurface->ulNumTriangles; ++iFace,
  302. ++pcTriangle, ++pcFaceCur) {
  303. const unsigned int iOutIndex = iFace * 3;
  304. pcFaceCur->mNumIndices = 3;
  305. pcFaceCur->mIndices = new unsigned int[3];
  306. for (unsigned int iIndex = 0; iIndex < 3; ++iIndex,
  307. ++pcVertCur, ++pcUVCur, ++pcNorCur) {
  308. uint32_t quak = pcTriangle->aiIndices[iIndex];
  309. if (quak >= pcSurface->ulNumVertices) {
  310. ASSIMP_LOG_ERROR("MDC vertex index is out of range");
  311. quak = pcSurface->ulNumVertices - 1;
  312. }
  313. // compressed vertices?
  314. if (mdcCompVert) {
  315. MDC::BuildVertex(*pcFrame, pcVerts[quak], pcCVerts[quak],
  316. *pcVertCur, *pcNorCur);
  317. } else {
  318. // copy position
  319. pcVertCur->x = pcVerts[quak].x * AI_MDC_BASE_SCALING;
  320. pcVertCur->y = pcVerts[quak].y * AI_MDC_BASE_SCALING;
  321. pcVertCur->z = pcVerts[quak].z * AI_MDC_BASE_SCALING;
  322. // copy normals
  323. MD3::LatLngNormalToVec3(pcVerts[quak].normal, &pcNorCur->x);
  324. // copy texture coordinates
  325. pcUVCur->x = pcUVs[quak].u;
  326. pcUVCur->y = ai_real(1.0) - pcUVs[quak].v; // DX to OGL
  327. }
  328. pcVertCur->x += pcFrame->localOrigin[0];
  329. pcVertCur->y += pcFrame->localOrigin[1];
  330. pcVertCur->z += pcFrame->localOrigin[2];
  331. }
  332. // swap the face order - DX to OGL
  333. pcFaceCur->mIndices[0] = iOutIndex + 2;
  334. pcFaceCur->mIndices[1] = iOutIndex + 1;
  335. pcFaceCur->mIndices[2] = iOutIndex + 0;
  336. }
  337. pcSurface = reinterpret_cast<BE_NCONST MDC::Surface *>((BE_NCONST int8_t *)pcSurface + pcSurface->ulOffsetEnd);
  338. }
  339. // create a flat node graph with a root node and one child for each surface
  340. if (!pScene->mNumMeshes)
  341. throw DeadlyImportError("Invalid MDC file: File contains no valid mesh");
  342. else if (1 == pScene->mNumMeshes) {
  343. pScene->mRootNode = new aiNode();
  344. if (nullptr != pScene->mMeshes[0]) {
  345. pScene->mRootNode->mName = pScene->mMeshes[0]->mName;
  346. pScene->mRootNode->mNumMeshes = 1;
  347. pScene->mRootNode->mMeshes = new unsigned int[1];
  348. pScene->mRootNode->mMeshes[0] = 0;
  349. }
  350. } else {
  351. pScene->mRootNode = new aiNode();
  352. pScene->mRootNode->mNumChildren = pScene->mNumMeshes;
  353. pScene->mRootNode->mChildren = new aiNode *[pScene->mNumMeshes];
  354. pScene->mRootNode->mName.Set("<root>");
  355. for (unsigned int i = 0; i < pScene->mNumMeshes; ++i) {
  356. aiNode *pcNode = pScene->mRootNode->mChildren[i] = new aiNode();
  357. pcNode->mParent = pScene->mRootNode;
  358. pcNode->mName = pScene->mMeshes[i]->mName;
  359. pcNode->mNumMeshes = 1;
  360. pcNode->mMeshes = new unsigned int[1];
  361. pcNode->mMeshes[0] = i;
  362. }
  363. }
  364. // create materials
  365. pScene->mNumMaterials = (unsigned int)aszShaders.size();
  366. pScene->mMaterials = new aiMaterial *[pScene->mNumMaterials];
  367. for (unsigned int i = 0; i < pScene->mNumMaterials; ++i) {
  368. aiMaterial *pcMat = new aiMaterial();
  369. pScene->mMaterials[i] = pcMat;
  370. const std::string &name = aszShaders[i];
  371. int iMode = (int)aiShadingMode_Gouraud;
  372. pcMat->AddProperty<int>(&iMode, 1, AI_MATKEY_SHADING_MODEL);
  373. // add a small ambient color value - RtCW seems to have one
  374. aiColor3D clr;
  375. clr.b = clr.g = clr.r = 0.05f;
  376. pcMat->AddProperty<aiColor3D>(&clr, 1, AI_MATKEY_COLOR_AMBIENT);
  377. if (name.length())
  378. clr.b = clr.g = clr.r = 1.0f;
  379. else
  380. clr.b = clr.g = clr.r = 0.6f;
  381. pcMat->AddProperty<aiColor3D>(&clr, 1, AI_MATKEY_COLOR_DIFFUSE);
  382. pcMat->AddProperty<aiColor3D>(&clr, 1, AI_MATKEY_COLOR_SPECULAR);
  383. if (name.length()) {
  384. aiString path;
  385. path.Set(name);
  386. pcMat->AddProperty(&path, AI_MATKEY_TEXTURE_DIFFUSE(0));
  387. }
  388. }
  389. // Now rotate the whole scene 90 degrees around the x axis to convert to internal coordinate system
  390. pScene->mRootNode->mTransformation = aiMatrix4x4(
  391. 1.f, 0.f, 0.f, 0.f,
  392. 0.f, 0.f, 1.f, 0.f,
  393. 0.f, -1.f, 0.f, 0.f,
  394. 0.f, 0.f, 0.f, 1.f);
  395. }
  396. #endif // !! ASSIMP_BUILD_NO_MDC_IMPORTER