2
0

MaterialSystem.cpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589
  1. /*
  2. Open Asset Import Library (ASSIMP)
  3. ----------------------------------------------------------------------
  4. Copyright (c) 2006-2008, ASSIMP Development Team
  5. All rights reserved.
  6. Redistribution and use of this software in source and binary forms,
  7. with or without modification, are permitted provided that the
  8. following conditions are met:
  9. * Redistributions of source code must retain the above
  10. copyright notice, this list of conditions and the
  11. following disclaimer.
  12. * Redistributions in binary form must reproduce the above
  13. copyright notice, this list of conditions and the
  14. following disclaimer in the documentation and/or other
  15. materials provided with the distribution.
  16. * Neither the name of the ASSIMP team, nor the names of its
  17. contributors may be used to endorse or promote products
  18. derived from this software without specific prior
  19. written permission of the ASSIMP Development Team.
  20. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  21. "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  22. LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  23. A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  24. OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  25. SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  26. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  27. DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  28. THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  29. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  30. OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31. ----------------------------------------------------------------------
  32. */
  33. #include "MaterialSystem.h"
  34. #include "StringComparison.h"
  35. #include "Hash.h"
  36. #include "../include/aiMaterial.h"
  37. #include "../include/aiAssert.h"
  38. using namespace Assimp;
  39. // we are using sprintf only on fixed-size buffers, so the
  40. // compiler should automatically expand the template sprintf_s<>
  41. #if _MSC_VER >= 1400
  42. # define sprintf sprintf_s
  43. #endif
  44. // ------------------------------------------------------------------------------------------------
  45. aiReturn aiGetMaterialProperty(const aiMaterial* pMat,
  46. const char* pKey,
  47. const aiMaterialProperty** pPropOut)
  48. {
  49. ai_assert (pMat != NULL);
  50. ai_assert (pKey != NULL);
  51. ai_assert (pPropOut != NULL);
  52. for (unsigned int i = 0; i < pMat->mNumProperties;++i)
  53. {
  54. if (NULL != pMat->mProperties[i])
  55. {
  56. if (0 == ASSIMP_stricmp( pMat->mProperties[i]->mKey.data, pKey ))
  57. {
  58. *pPropOut = pMat->mProperties[i];
  59. return AI_SUCCESS;
  60. }
  61. }
  62. }
  63. *pPropOut = NULL;
  64. return AI_FAILURE;
  65. }
  66. // ------------------------------------------------------------------------------------------------
  67. aiReturn aiGetMaterialFloatArray(const aiMaterial* pMat,
  68. const char* pKey,
  69. float* pOut,
  70. unsigned int* pMax)
  71. {
  72. ai_assert (pMat != NULL);
  73. ai_assert (pKey != NULL);
  74. ai_assert (pOut != NULL);
  75. for (unsigned int i = 0; i < pMat->mNumProperties;++i)
  76. {
  77. if (NULL != pMat->mProperties[i])
  78. {
  79. if (0 == ASSIMP_stricmp( pMat->mProperties[i]->mKey.data, pKey ))
  80. {
  81. // data is given in floats, simply copy it
  82. if( aiPTI_Float == pMat->mProperties[i]->mType ||
  83. aiPTI_Buffer == pMat->mProperties[i]->mType)
  84. {
  85. unsigned int iWrite = pMat->mProperties[i]->mDataLength / sizeof(float);
  86. if (NULL != pMax)
  87. iWrite = *pMax < iWrite ? *pMax : iWrite;
  88. memcpy (pOut, pMat->mProperties[i]->mData, iWrite * sizeof (float));
  89. if (NULL != pMax)
  90. *pMax = iWrite;
  91. }
  92. // data is given in ints, convert to float
  93. else if( aiPTI_Integer == pMat->mProperties[i]->mType)
  94. {
  95. unsigned int iWrite = pMat->mProperties[i]->
  96. mDataLength / sizeof(int);
  97. if (NULL != pMax)
  98. iWrite = *pMax < iWrite ? *pMax : iWrite;
  99. for (unsigned int a = 0; a < iWrite;++a)
  100. {
  101. pOut[a] = (float) ((int*)pMat->mProperties[i]->mData)[a];
  102. }
  103. if (NULL != pMax)
  104. *pMax = iWrite;
  105. }
  106. // it is a string ... no way to read something out of this
  107. else
  108. {
  109. if (NULL != pMax)
  110. *pMax = 0;
  111. return AI_FAILURE;
  112. }
  113. return AI_SUCCESS;
  114. }
  115. }
  116. }
  117. return AI_FAILURE;
  118. }
  119. // ------------------------------------------------------------------------------------------------
  120. aiReturn aiGetMaterialIntegerArray(const aiMaterial* pMat,
  121. const char* pKey,
  122. int* pOut,
  123. unsigned int* pMax)
  124. {
  125. ai_assert (pMat != NULL);
  126. ai_assert (pKey != NULL);
  127. ai_assert (pOut != NULL);
  128. for (unsigned int i = 0; i < pMat->mNumProperties;++i)
  129. {
  130. if (NULL != pMat->mProperties[i])
  131. {
  132. if (0 == ASSIMP_stricmp( pMat->mProperties[i]->mKey.data, pKey ))
  133. {
  134. // data is given in ints, simply copy it
  135. if( aiPTI_Integer == pMat->mProperties[i]->mType ||
  136. aiPTI_Buffer == pMat->mProperties[i]->mType)
  137. {
  138. unsigned int iWrite = pMat->mProperties[i]->
  139. mDataLength / sizeof(int);
  140. if (NULL != pMax)
  141. iWrite = *pMax < iWrite ? *pMax : iWrite;
  142. memcpy (pOut, pMat->mProperties[i]->mData, iWrite * sizeof (int));
  143. if (NULL != pMax)
  144. *pMax = iWrite;
  145. }
  146. // data is given in floats convert to int (lossy!)
  147. else if( aiPTI_Float == pMat->mProperties[i]->mType)
  148. {
  149. unsigned int iWrite = pMat->mProperties[i]->
  150. mDataLength / sizeof(float);
  151. if (NULL != pMax)
  152. iWrite = *pMax < iWrite ? *pMax : iWrite;
  153. for (unsigned int a = 0; a < iWrite;++a)
  154. {
  155. pOut[a] = (int) ((float*)pMat->mProperties[i]->mData)[a];
  156. }
  157. if (NULL != pMax)
  158. *pMax = iWrite;
  159. }
  160. // it is a string ... no way to read something out of this
  161. else
  162. {
  163. if (NULL != pMax)
  164. *pMax = 0;
  165. return AI_FAILURE;
  166. }
  167. return AI_SUCCESS;
  168. }
  169. }
  170. }
  171. return AI_FAILURE;
  172. }
  173. // ------------------------------------------------------------------------------------------------
  174. aiReturn aiGetMaterialColor(const aiMaterial* pMat,
  175. const char* pKey,
  176. aiColor4D* pOut)
  177. {
  178. unsigned int iMax = 4;
  179. aiReturn eRet = aiGetMaterialFloatArray(pMat,pKey,(float*)pOut,&iMax);
  180. // if no alpha channel is provided set it to 1.0 by default
  181. if (3 == iMax)pOut->a = 1.0f;
  182. return eRet;
  183. }
  184. // ------------------------------------------------------------------------------------------------
  185. aiReturn aiGetMaterialString(const aiMaterial* pMat,
  186. const char* pKey,
  187. aiString* pOut)
  188. {
  189. ai_assert (pMat != NULL);
  190. ai_assert (pKey != NULL);
  191. ai_assert (pOut != NULL);
  192. for (unsigned int i = 0; i < pMat->mNumProperties;++i)
  193. {
  194. if (NULL != pMat->mProperties[i])
  195. {
  196. if (0 == ASSIMP_stricmp( pMat->mProperties[i]->mKey.data, pKey ))
  197. {
  198. if( aiPTI_String == pMat->mProperties[i]->mType)
  199. {
  200. const aiString* pcSrc = (const aiString*)pMat->mProperties[i]->mData;
  201. ::memcpy (pOut->data, pcSrc->data, (pOut->length = pcSrc->length)+1);
  202. }
  203. // wrong type
  204. else return AI_FAILURE;
  205. return AI_SUCCESS;
  206. }
  207. }
  208. }
  209. return AI_FAILURE;
  210. }
  211. // ------------------------------------------------------------------------------------------------
  212. MaterialHelper::MaterialHelper()
  213. {
  214. // allocate 5 entries by default
  215. this->mNumProperties = 0;
  216. this->mNumAllocated = 5;
  217. this->mProperties = new aiMaterialProperty*[5];
  218. return;
  219. }
  220. // ------------------------------------------------------------------------------------------------
  221. MaterialHelper::~MaterialHelper()
  222. {
  223. for (unsigned int i = 0; i < this->mNumProperties;++i)
  224. {
  225. // be careful ...
  226. if(NULL != this->mProperties[i])
  227. {
  228. delete[] this->mProperties[i]->mData;
  229. delete this->mProperties[i];
  230. }
  231. }
  232. return;
  233. }
  234. // ------------------------------------------------------------------------------------------------
  235. uint32_t MaterialHelper::ComputeHash()
  236. {
  237. uint32_t hash = 1503; // magic start value, choosen to be my birthday :-)
  238. for (unsigned int i = 0; i < this->mNumProperties;++i)
  239. {
  240. aiMaterialProperty* prop;
  241. // NOTE: We need to exclude the material name from the hash
  242. if ((prop = this->mProperties[i]) && 0 != ::strcmp(prop->mKey.data,AI_MATKEY_NAME))
  243. {
  244. hash = SuperFastHash(prop->mKey.data,(unsigned int)prop->mKey.length,hash);
  245. hash = SuperFastHash(prop->mData,prop->mDataLength,hash);
  246. }
  247. }
  248. return hash;
  249. }
  250. // ------------------------------------------------------------------------------------------------
  251. aiReturn MaterialHelper::RemoveProperty (const char* pKey)
  252. {
  253. ai_assert(NULL != pKey);
  254. for (unsigned int i = 0; i < this->mNumProperties;++i)
  255. {
  256. if (this->mProperties[i]) // just for safety
  257. {
  258. if (0 == ASSIMP_stricmp( this->mProperties[i]->mKey.data, pKey ))
  259. {
  260. // delete this entry
  261. delete[] this->mProperties[i]->mData;
  262. delete this->mProperties[i];
  263. // collapse the array behind --.
  264. --this->mNumProperties;
  265. for (unsigned int a = i; a < this->mNumProperties;++a)
  266. {
  267. this->mProperties[a] = this->mProperties[a+1];
  268. }
  269. return AI_SUCCESS;
  270. }
  271. }
  272. }
  273. return AI_FAILURE;
  274. }
  275. // ------------------------------------------------------------------------------------------------
  276. aiReturn MaterialHelper::AddBinaryProperty (const void* pInput,
  277. const unsigned int pSizeInBytes,
  278. const char* pKey,
  279. aiPropertyTypeInfo pType)
  280. {
  281. ai_assert (pInput != NULL);
  282. ai_assert (pKey != NULL);
  283. ai_assert (0 != pSizeInBytes);
  284. // first search the list whether there is already an entry
  285. // with this name.
  286. unsigned int iOutIndex = 0xFFFFFFFF;
  287. for (unsigned int i = 0; i < this->mNumProperties;++i)
  288. {
  289. if (this->mProperties[i])
  290. {
  291. if (0 == ASSIMP_stricmp( this->mProperties[i]->mKey.data, pKey ))
  292. {
  293. // delete this entry
  294. delete[] this->mProperties[i]->mData;
  295. delete this->mProperties[i];
  296. iOutIndex = i;
  297. }
  298. }
  299. }
  300. aiMaterialProperty* pcNew = new aiMaterialProperty();
  301. // fill this
  302. pcNew->mType = pType;
  303. pcNew->mDataLength = pSizeInBytes;
  304. pcNew->mData = new char[pSizeInBytes];
  305. memcpy (pcNew->mData,pInput,pSizeInBytes);
  306. pcNew->mKey.length = ::strlen(pKey);
  307. ai_assert ( MAXLEN > pcNew->mKey.length);
  308. ::strcpy( pcNew->mKey.data, pKey );
  309. if (0xFFFFFFFF != iOutIndex)
  310. {
  311. this->mProperties[iOutIndex] = pcNew;
  312. return AI_SUCCESS;
  313. }
  314. // resize the array ... allocate storage for 5 other properties
  315. if (this->mNumProperties == this->mNumAllocated)
  316. {
  317. unsigned int iOld = this->mNumAllocated;
  318. this->mNumAllocated += 5;
  319. aiMaterialProperty** ppTemp = new aiMaterialProperty*[this->mNumAllocated];
  320. if (NULL == ppTemp)return AI_OUTOFMEMORY;
  321. ::memcpy (ppTemp,this->mProperties,iOld * sizeof(void*));
  322. delete[] this->mProperties;
  323. this->mProperties = ppTemp;
  324. }
  325. // push back ...
  326. this->mProperties[this->mNumProperties++] = pcNew;
  327. return AI_SUCCESS;
  328. }
  329. // ------------------------------------------------------------------------------------------------
  330. aiReturn MaterialHelper::AddProperty (const aiString* pInput,
  331. const char* pKey)
  332. {
  333. // fix ... don't keep the whole string buffer
  334. return this->AddBinaryProperty(pInput,(unsigned int)pInput->length+1+
  335. (unsigned int)(((uint8_t*)&pInput->data - (uint8_t*)&pInput->length)),
  336. pKey,aiPTI_String);
  337. }
  338. // ------------------------------------------------------------------------------------------------
  339. void MaterialHelper::CopyPropertyList(MaterialHelper* pcDest,
  340. const MaterialHelper* pcSrc)
  341. {
  342. ai_assert(NULL != pcDest);
  343. ai_assert(NULL != pcSrc);
  344. unsigned int iOldNum = pcDest->mNumProperties;
  345. pcDest->mNumAllocated += pcSrc->mNumAllocated;
  346. pcDest->mNumProperties += pcSrc->mNumProperties;
  347. aiMaterialProperty** pcOld = pcDest->mProperties;
  348. pcDest->mProperties = new aiMaterialProperty*[pcDest->mNumAllocated];
  349. if (iOldNum && pcOld)
  350. {
  351. for (unsigned int i = 0; i < iOldNum;++i)
  352. pcDest->mProperties[i] = pcOld[i];
  353. delete[] pcOld;
  354. }
  355. for (unsigned int i = iOldNum; i< pcDest->mNumProperties;++i)
  356. {
  357. aiMaterialProperty* propSrc = pcSrc->mProperties[i];
  358. // search whether we have already a property with this name
  359. // (if yes we overwrite the old one)
  360. aiMaterialProperty* prop;
  361. for (unsigned int q = 0; q < iOldNum;++q)
  362. {
  363. prop = pcDest->mProperties[q];
  364. if (propSrc->mKey.length == prop->mKey.length &&
  365. !ASSIMP_stricmp(propSrc->mKey.data,prop->mKey.data))
  366. {
  367. delete prop;
  368. // collapse the whole array ...
  369. ::memmove(&pcDest->mProperties[q],&pcDest->mProperties[q+1],i-q);
  370. i--;
  371. pcDest->mNumProperties--;
  372. }
  373. }
  374. prop = pcDest->mProperties[i] = new aiMaterialProperty();
  375. prop->mKey = propSrc->mKey;
  376. prop->mDataLength = propSrc->mDataLength;
  377. prop->mType = propSrc->mType;
  378. prop->mData = new char[propSrc->mDataLength];
  379. ::memcpy(prop->mData,propSrc->mData,prop->mDataLength);
  380. }
  381. return;
  382. }
  383. // ------------------------------------------------------------------------------------------------
  384. // we need this dummy because the compiler would otherwise complain about
  385. // empty, but controlled statements ...
  386. void DummyAssertFunction()
  387. {
  388. ai_assert(false);
  389. }
  390. // ------------------------------------------------------------------------------------------------
  391. aiReturn aiGetMaterialTexture(const aiMaterial* pcMat,
  392. unsigned int iIndex,
  393. unsigned int iTexType,
  394. aiString* szOut,
  395. unsigned int* piUVIndex,
  396. float* pfBlendFactor,
  397. aiTextureOp* peTextureOp,
  398. aiTextureMapMode* peMapMode)
  399. {
  400. ai_assert(NULL != pcMat);
  401. ai_assert(NULL != szOut);
  402. const char* szPathBase;
  403. const char* szUVBase;
  404. const char* szBlendBase;
  405. const char* szOpBase;
  406. const char* aszMapModeBase[3];
  407. switch (iTexType)
  408. {
  409. case AI_TEXTYPE_DIFFUSE:
  410. szPathBase = AI_MATKEY_TEXTURE_DIFFUSE_;
  411. szUVBase = AI_MATKEY_UVWSRC_DIFFUSE_;
  412. szBlendBase = AI_MATKEY_TEXBLEND_DIFFUSE_;
  413. szOpBase = AI_MATKEY_TEXOP_DIFFUSE_;
  414. aszMapModeBase[0] = AI_MATKEY_MAPPINGMODE_U_DIFFUSE_;
  415. aszMapModeBase[1] = AI_MATKEY_MAPPINGMODE_V_DIFFUSE_;
  416. aszMapModeBase[2] = AI_MATKEY_MAPPINGMODE_W_DIFFUSE_;
  417. break;
  418. case AI_TEXTYPE_SPECULAR:
  419. szPathBase = AI_MATKEY_TEXTURE_SPECULAR_;
  420. szUVBase = AI_MATKEY_UVWSRC_SPECULAR_;
  421. szBlendBase = AI_MATKEY_TEXBLEND_SPECULAR_;
  422. szOpBase = AI_MATKEY_TEXOP_SPECULAR_;
  423. aszMapModeBase[0] = AI_MATKEY_MAPPINGMODE_U_SPECULAR_;
  424. aszMapModeBase[1] = AI_MATKEY_MAPPINGMODE_V_SPECULAR_;
  425. aszMapModeBase[2] = AI_MATKEY_MAPPINGMODE_W_SPECULAR_;
  426. break;
  427. case AI_TEXTYPE_AMBIENT:
  428. szPathBase = AI_MATKEY_TEXTURE_AMBIENT_;
  429. szUVBase = AI_MATKEY_UVWSRC_AMBIENT_;
  430. szBlendBase = AI_MATKEY_TEXBLEND_AMBIENT_;
  431. szOpBase = AI_MATKEY_TEXOP_AMBIENT_;
  432. aszMapModeBase[0] = AI_MATKEY_MAPPINGMODE_U_AMBIENT_;
  433. aszMapModeBase[1] = AI_MATKEY_MAPPINGMODE_V_AMBIENT_;
  434. aszMapModeBase[2] = AI_MATKEY_MAPPINGMODE_W_AMBIENT_;
  435. break;
  436. case AI_TEXTYPE_EMISSIVE:
  437. szPathBase = AI_MATKEY_TEXTURE_EMISSIVE_;
  438. szUVBase = AI_MATKEY_UVWSRC_EMISSIVE_;
  439. szBlendBase = AI_MATKEY_TEXBLEND_EMISSIVE_;
  440. szOpBase = AI_MATKEY_TEXOP_EMISSIVE_;
  441. aszMapModeBase[0] = AI_MATKEY_MAPPINGMODE_U_EMISSIVE_;
  442. aszMapModeBase[1] = AI_MATKEY_MAPPINGMODE_V_EMISSIVE_;
  443. aszMapModeBase[2] = AI_MATKEY_MAPPINGMODE_W_EMISSIVE_;
  444. break;
  445. case AI_TEXTYPE_HEIGHT:
  446. szPathBase = AI_MATKEY_TEXTURE_HEIGHT_;
  447. szUVBase = AI_MATKEY_UVWSRC_HEIGHT_;
  448. szBlendBase = AI_MATKEY_TEXBLEND_HEIGHT_;
  449. szOpBase = AI_MATKEY_TEXOP_HEIGHT_;
  450. aszMapModeBase[0] = AI_MATKEY_MAPPINGMODE_U_HEIGHT_;
  451. aszMapModeBase[1] = AI_MATKEY_MAPPINGMODE_V_HEIGHT_;
  452. aszMapModeBase[2] = AI_MATKEY_MAPPINGMODE_W_HEIGHT_;
  453. break;
  454. case AI_TEXTYPE_NORMALS:
  455. szPathBase = AI_MATKEY_TEXTURE_NORMALS_;
  456. szUVBase = AI_MATKEY_UVWSRC_NORMALS_;
  457. szBlendBase = AI_MATKEY_TEXBLEND_NORMALS_;
  458. szOpBase = AI_MATKEY_TEXOP_NORMALS_;
  459. aszMapModeBase[0] = AI_MATKEY_MAPPINGMODE_U_NORMALS_;
  460. aszMapModeBase[1] = AI_MATKEY_MAPPINGMODE_V_NORMALS_;
  461. aszMapModeBase[2] = AI_MATKEY_MAPPINGMODE_W_NORMALS_;
  462. break;
  463. case AI_TEXTYPE_SHININESS:
  464. szPathBase = AI_MATKEY_TEXTURE_SHININESS_;
  465. szUVBase = AI_MATKEY_UVWSRC_SHININESS_;
  466. szBlendBase = AI_MATKEY_TEXBLEND_SHININESS_;
  467. szOpBase = AI_MATKEY_TEXOP_SHININESS_;
  468. aszMapModeBase[0] = AI_MATKEY_MAPPINGMODE_U_SHININESS_;
  469. aszMapModeBase[1] = AI_MATKEY_MAPPINGMODE_V_SHININESS_;
  470. aszMapModeBase[2] = AI_MATKEY_MAPPINGMODE_W_SHININESS_;
  471. break;
  472. case AI_TEXTYPE_OPACITY:
  473. szPathBase = AI_MATKEY_TEXTURE_OPACITY_;
  474. szUVBase = AI_MATKEY_UVWSRC_OPACITY_;
  475. szBlendBase = AI_MATKEY_TEXBLEND_OPACITY_;
  476. szOpBase = AI_MATKEY_TEXOP_OPACITY_;
  477. aszMapModeBase[0] = AI_MATKEY_MAPPINGMODE_U_OPACITY_;
  478. aszMapModeBase[1] = AI_MATKEY_MAPPINGMODE_V_OPACITY_;
  479. aszMapModeBase[2] = AI_MATKEY_MAPPINGMODE_W_OPACITY_;
  480. break;
  481. default: return AI_FAILURE;
  482. };
  483. char szKey[256];
  484. if (iIndex > 100)return AI_FAILURE;
  485. // get the path to the texture
  486. if(0 >= sprintf(szKey,"%s[%i]",szPathBase,iIndex))DummyAssertFunction();
  487. if (AI_SUCCESS != aiGetMaterialString(pcMat,szKey,szOut))
  488. {
  489. return AI_FAILURE;
  490. }
  491. // get the UV index of the texture
  492. if (piUVIndex)
  493. {
  494. int iUV;
  495. if(0 >= sprintf(szKey,"%s[%i]",szUVBase,iIndex))DummyAssertFunction();
  496. if (AI_SUCCESS != aiGetMaterialInteger(pcMat,szKey,&iUV))
  497. iUV = 0;
  498. *piUVIndex = iUV;
  499. }
  500. // get the blend factor of the texture
  501. if (pfBlendFactor)
  502. {
  503. float fBlend;
  504. if(0 >= sprintf(szKey,"%s[%i]",szBlendBase,iIndex))DummyAssertFunction();
  505. if (AI_SUCCESS != aiGetMaterialFloat(pcMat,szKey,&fBlend))
  506. fBlend = 1.0f;
  507. *pfBlendFactor = fBlend;
  508. }
  509. // get the texture operation of the texture
  510. if (peTextureOp)
  511. {
  512. aiTextureOp op;
  513. if(0 >= sprintf(szKey,"%s[%i]",szOpBase,iIndex))DummyAssertFunction();
  514. if (AI_SUCCESS != aiGetMaterialInteger(pcMat,szKey,(int*)&op))
  515. op = aiTextureOp_Multiply;
  516. *peTextureOp = op;
  517. }
  518. // get the texture mapping modes for the texture
  519. if (peMapMode)
  520. {
  521. aiTextureMapMode eMode;
  522. for (unsigned int q = 0; q < 3;++q)
  523. {
  524. if(0 >= sprintf(szKey,"%s[%i]",aszMapModeBase[q],iIndex))DummyAssertFunction();
  525. if (AI_SUCCESS != aiGetMaterialInteger(pcMat,szKey,(int*)&eMode))
  526. {
  527. eMode = aiTextureMapMode_Wrap;
  528. }
  529. peMapMode[q] = eMode;
  530. }
  531. }
  532. return AI_SUCCESS;
  533. }