MDCLoader.cpp 19 KB

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