MDCLoader.cpp 18 KB

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