ValidateDataStructure.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689
  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 post processing step to validate
  35. * the data structure returned by Assimp
  36. */
  37. #include <vector>
  38. #include <assert.h>
  39. #include "ValidateDataStructure.h"
  40. #include "BaseImporter.h"
  41. #include "StringComparison.h"
  42. #include "fast_atof.h"
  43. #include "../include/DefaultLogger.h"
  44. #include "../include/aiPostProcess.h"
  45. #include "../include/aiMesh.h"
  46. #include "../include/aiScene.h"
  47. #include "../include/aiAssert.h"
  48. #include <stdarg.h>
  49. using namespace Assimp;
  50. // ------------------------------------------------------------------------------------------------
  51. // Constructor to be privately used by Importer
  52. ValidateDSProcess::ValidateDSProcess()
  53. {
  54. // nothing to do here
  55. }
  56. // ------------------------------------------------------------------------------------------------
  57. // Destructor, private as well
  58. ValidateDSProcess::~ValidateDSProcess()
  59. {
  60. // nothing to do here
  61. }
  62. // ------------------------------------------------------------------------------------------------
  63. // Returns whether the processing step is present in the given flag field.
  64. bool ValidateDSProcess::IsActive( unsigned int pFlags) const
  65. {
  66. return (pFlags & aiProcess_ValidateDataStructure) != 0;
  67. }
  68. // ------------------------------------------------------------------------------------------------
  69. void ValidateDSProcess::ReportError(const char* msg,...)
  70. {
  71. ai_assert(NULL != msg);
  72. va_list args;
  73. va_start(args,msg);
  74. char szBuffer[3000];
  75. int iLen;
  76. #if _MSC_VER >= 1400
  77. iLen = vsprintf_s(szBuffer,msg,args);
  78. #else
  79. iLen = vsprintf(szBuffer,msg,args);
  80. #endif
  81. if (0 >= iLen)
  82. {
  83. // :-) should not happen ...
  84. throw new ImportErrorException("Idiot ... learn coding!");
  85. }
  86. va_end(args);
  87. throw new ImportErrorException("Validation failed: " + std::string(szBuffer,iLen));
  88. }
  89. // ------------------------------------------------------------------------------------------------
  90. void ValidateDSProcess::ReportWarning(const char* msg,...)
  91. {
  92. ai_assert(NULL != msg);
  93. va_list args;
  94. va_start(args,msg);
  95. char szBuffer[3000];
  96. int iLen;
  97. #if _MSC_VER >= 1400
  98. iLen = vsprintf_s(szBuffer,msg,args);
  99. #else
  100. iLen = vsprintf(szBuffer,msg,args);
  101. #endif
  102. if (0 >= iLen)
  103. {
  104. // :-) should not happen ...
  105. throw new ImportErrorException("Idiot ... learn coding!");
  106. }
  107. va_end(args);
  108. DefaultLogger::get()->warn("Validation failed: " + std::string(szBuffer,iLen));
  109. }
  110. // ------------------------------------------------------------------------------------------------
  111. // Executes the post processing step on the given imported data.
  112. void ValidateDSProcess::Execute( aiScene* pScene)
  113. {
  114. this->mScene = pScene;
  115. DefaultLogger::get()->debug("ValidateDataStructureProcess begin");
  116. // validate all meshes
  117. if (pScene->mNumMeshes)
  118. {
  119. if (!pScene->mMeshes)
  120. {
  121. this->ReportError("aiScene::mMeshes is NULL (aiScene::mNumMeshes is %i)",
  122. pScene->mNumMeshes);
  123. }
  124. for (unsigned int i = 0; i < pScene->mNumMeshes;++i)
  125. {
  126. if (!pScene->mMeshes[i])
  127. {
  128. this->ReportError("aiScene::mMeshes[%i] is NULL (aiScene::mNumMeshes is %i)",
  129. i,pScene->mNumMeshes);
  130. }
  131. this->Validate(pScene->mMeshes[i]);
  132. }
  133. }
  134. else this->ReportError("aiScene::mNumMeshes is 0. At least one mesh must be there");
  135. // validate all animations
  136. if (pScene->mNumAnimations)
  137. {
  138. if (!pScene->mAnimations)
  139. {
  140. this->ReportError("aiScene::mAnimations is NULL (aiScene::mNumAnimations is %i)",
  141. pScene->mNumAnimations);
  142. }
  143. for (unsigned int i = 0; i < pScene->mNumAnimations;++i)
  144. {
  145. if (!pScene->mAnimations[i])
  146. {
  147. this->ReportError("aiScene::mAnimations[%i] is NULL (aiScene::mNumAnimations is %i)",
  148. i,pScene->mNumAnimations);
  149. }
  150. this->Validate(pScene->mAnimations[i]);
  151. // check whether there are duplicate animation names
  152. for (unsigned int a = i+1; a < pScene->mNumAnimations;++a)
  153. {
  154. if (pScene->mAnimations[i]->mName == pScene->mAnimations[a]->mName)
  155. {
  156. this->ReportError("aiScene::mAnimations[%i] has the same name as "
  157. "aiScene::mAnimations[%i]",i,a);
  158. }
  159. }
  160. }
  161. }
  162. // validate all textures
  163. if (pScene->mNumTextures)
  164. {
  165. if (!pScene->mTextures)
  166. {
  167. this->ReportError("aiScene::mTextures is NULL (aiScene::mNumTextures is %i)",
  168. pScene->mNumTextures);
  169. }
  170. for (unsigned int i = 0; i < pScene->mNumTextures;++i)
  171. {
  172. if (!pScene->mTextures[i])
  173. {
  174. this->ReportError("aiScene::mTextures[%i] is NULL (aiScene::mNumTextures is %i)",
  175. i,pScene->mNumTextures);
  176. }
  177. this->Validate(pScene->mTextures[i]);
  178. }
  179. }
  180. // validate all materials
  181. if (pScene->mNumMaterials)
  182. {
  183. if (!pScene->mMaterials)
  184. {
  185. this->ReportError("aiScene::mMaterials is NULL (aiScene::mNumMaterials is %i)",
  186. pScene->mNumMaterials);
  187. }
  188. for (unsigned int i = 0; i < pScene->mNumMaterials;++i)
  189. {
  190. if (!pScene->mMaterials[i])
  191. {
  192. this->ReportError("aiScene::mMaterials[%i] is NULL (aiScene::mNumMaterials is %i)",
  193. i,pScene->mNumMaterials);
  194. }
  195. this->Validate(pScene->mMaterials[i]);
  196. }
  197. }
  198. else this->ReportError("aiScene::mNumMaterials is 0. At least one material must be there.");
  199. // validate the node graph of the scene
  200. this->Validate(pScene->mRootNode);
  201. DefaultLogger::get()->debug("ValidateDataStructureProcess end");
  202. }
  203. // ------------------------------------------------------------------------------------------------
  204. void ValidateDSProcess::Validate( const aiMesh* pMesh)
  205. {
  206. // validate the material index of the mesh
  207. if (pMesh->mMaterialIndex >= this->mScene->mNumMaterials)
  208. {
  209. this->ReportError("aiMesh::mMaterialIndex is invalid (value: %i maximum: %i)",
  210. pMesh->mMaterialIndex,this->mScene->mNumMaterials-1);
  211. }
  212. // positions must always be there ...
  213. if (!pMesh->mNumVertices || !pMesh->mVertices)
  214. {
  215. this->ReportError("The mesh contains no vertices");
  216. }
  217. // faces, too
  218. if (!pMesh->mNumFaces || !pMesh->mFaces)
  219. {
  220. this->ReportError("The mesh contains no faces");
  221. }
  222. // now check whether the face indexing layout is correct:
  223. // unique vertices, pseudo-indexed.
  224. std::vector<bool> abRefList;
  225. abRefList.resize(pMesh->mNumVertices,false);
  226. for (unsigned int i = 0; i < pMesh->mNumFaces;++i)
  227. {
  228. aiFace& face = pMesh->mFaces[i];
  229. if (!face.mIndices)this->ReportError("aiMesh::mFaces[%i].mIndices is NULL",i);
  230. if (face.mNumIndices < 3)this->ReportError(
  231. "aiMesh::mFaces[%i].mIndices is not a triangle or polygon",i);
  232. for (unsigned int a = 0; a < face.mNumIndices;++a)
  233. {
  234. if (face.mIndices[a] >= pMesh->mNumVertices)
  235. {
  236. this->ReportError("aiMesh::mFaces[%i]::mIndices[%a] is out of range",i,a);
  237. }
  238. if (abRefList[face.mIndices[a]])
  239. {
  240. this->ReportError("aiMesh::mVertices[%i] is referenced twice - second "
  241. "time by aiMesh::mFaces[%i]::mIndices[%i]",face.mIndices[a],i,a);
  242. }
  243. abRefList[face.mIndices[a]] = true;
  244. }
  245. }
  246. abRefList.clear();
  247. // texture channel 2 may not be set if channel 1 is zero ...
  248. {
  249. unsigned int i = 0;
  250. for (;i < AI_MAX_NUMBER_OF_TEXTURECOORDS;++i)
  251. {
  252. if (!pMesh->HasTextureCoords(i))break;
  253. }
  254. for (;i < AI_MAX_NUMBER_OF_TEXTURECOORDS;++i)
  255. if (pMesh->HasTextureCoords(i))
  256. {
  257. this->ReportError("Texture coordinate channel %i is existing, "
  258. "although the previous channel was NULL.",i);
  259. }
  260. }
  261. // the same for the vertex colors
  262. {
  263. unsigned int i = 0;
  264. for (;i < AI_MAX_NUMBER_OF_COLOR_SETS;++i)
  265. {
  266. if (!pMesh->HasVertexColors(i))break;
  267. }
  268. for (;i < AI_MAX_NUMBER_OF_COLOR_SETS;++i)
  269. if (pMesh->HasVertexColors(i))
  270. {
  271. this->ReportError("Vertex color channel %i is existing, "
  272. "although the previous channel was NULL.",i);
  273. }
  274. }
  275. // now validate all bones
  276. if (pMesh->HasBones())
  277. {
  278. if (!pMesh->mBones)
  279. {
  280. this->ReportError("aiMesh::mBones is NULL (aiMesh::mNumBones is %i)",
  281. pMesh->mNumBones);
  282. }
  283. // check whether there are duplicate bone names
  284. for (unsigned int i = 0; i < pMesh->mNumBones;++i)
  285. {
  286. if (!pMesh->mBones[i])
  287. {
  288. this->ReportError("aiMesh::mBones[%i] is NULL (aiMesh::mNumBones is %i)",
  289. i,pMesh->mNumBones);
  290. }
  291. this->Validate(pMesh,pMesh->mBones[i]);
  292. for (unsigned int a = i+1; a < pMesh->mNumBones;++a)
  293. {
  294. if (pMesh->mBones[i]->mName == pMesh->mBones[a]->mName)
  295. {
  296. this->ReportError("aiMesh::mBones[%i] has the same name as "
  297. "aiMesh::mBones[%i]",i,a);
  298. }
  299. }
  300. }
  301. }
  302. }
  303. // ------------------------------------------------------------------------------------------------
  304. void ValidateDSProcess::Validate( const aiMesh* pMesh,
  305. const aiBone* pBone)
  306. {
  307. // check whether all vertices affected by this bone are valid
  308. for (unsigned int i = 0; i < pBone->mNumWeights;++i)
  309. {
  310. if (pBone->mWeights[i].mVertexId > pMesh->mNumVertices)
  311. {
  312. this->ReportError("aiBone::mWeights[%i].mVertexId is out of range",i);
  313. }
  314. else if (!pBone->mWeights[i].mWeight || pBone->mWeights[i].mWeight > 1.0f)
  315. {
  316. this->ReportWarning("aiBone::mWeights[%i].mWeight has an invalid value",i);
  317. }
  318. }
  319. // TODO: check whether all bone weights for a vertex sum to 1.0 ...
  320. }
  321. // ------------------------------------------------------------------------------------------------
  322. void ValidateDSProcess::Validate( const aiAnimation* pAnimation)
  323. {
  324. // validate all materials
  325. if (pAnimation->mNumBones)
  326. {
  327. if (!pAnimation->mBones)
  328. {
  329. this->ReportError("aiAnimation::mBones is NULL (aiAnimation::mNumBones is %i)",
  330. pAnimation->mBones);
  331. }
  332. for (unsigned int i = 0; i < pAnimation->mNumBones;++i)
  333. {
  334. if (!pAnimation->mBones[i])
  335. {
  336. this->ReportError("aiAnimation::mBones[%i] is NULL (aiAnimation::mNumBones is %i)",
  337. i,pAnimation->mNumBones);
  338. }
  339. this->Validate(pAnimation, pAnimation->mBones[i]);
  340. }
  341. }
  342. else this->ReportError("aiAnimation::mNumBones is 0. At least one bone animation channel must be there.");
  343. if (!pAnimation->mDuration)this->ReportError("aiAnimation::mDuration is zero");
  344. }
  345. // ------------------------------------------------------------------------------------------------
  346. void ValidateDSProcess::SearchForInvalidTextures(const aiMaterial* pMaterial,
  347. const char* szType)
  348. {
  349. ai_assert(NULL != szType);
  350. // search all keys of the material ...
  351. // textures must be specified with rising indices (e.g. diffuse #2 may not be
  352. // specified if diffuse #1 is not there ...)
  353. // "$tex.file.<szType>[<index>]"
  354. char szBaseBuf[512];
  355. int iLen;
  356. #if _MSC_VER >= 1400
  357. iLen = ::sprintf_s(szBaseBuf,"$tex.file.%s",szType);
  358. #else
  359. iLen = ::sprintf(szBaseBuf,"$tex.file.%s",szType);
  360. #endif
  361. if (0 >= iLen)return;
  362. int iNumIndices = 0;
  363. int iIndex = -1;
  364. for (unsigned int i = 0; i < pMaterial->mNumProperties;++i)
  365. {
  366. aiMaterialProperty* prop = pMaterial->mProperties[i];
  367. if (0 == ASSIMP_strincmp( prop->mKey->data, szBaseBuf, iLen ))
  368. {
  369. const char* sz = &prop->mKey->data[iLen];
  370. if (*sz)
  371. {
  372. ++sz;
  373. iIndex = std::max(iIndex, (int)strtol10(sz,NULL));
  374. ++iNumIndices;
  375. }
  376. if (aiPTI_String != prop->mType)
  377. this->ReportError("Material property %s is expected to be a string",prop->mKey);
  378. }
  379. }
  380. if (iIndex +1 != iNumIndices)
  381. {
  382. this->ReportError("%s #%i is set, but there are only %i %s textures",
  383. szType,iIndex,iNumIndices,szType);
  384. }
  385. // now check whether all UV indices are valid ...
  386. #if _MSC_VER >= 1400
  387. iLen = ::sprintf_s(szBaseBuf,"$tex.uvw.%s",szType);
  388. #else
  389. iLen = ::sprintf(szBaseBuf,"$tex.uvw.%s",szType);
  390. #endif
  391. if (0 >= iLen)return;
  392. for (unsigned int i = 0; i < pMaterial->mNumProperties;++i)
  393. {
  394. aiMaterialProperty* prop = pMaterial->mProperties[i];
  395. if (0 == ASSIMP_strincmp( prop->mKey->data, szBaseBuf, iLen ))
  396. {
  397. if (aiPTI_Integer != prop->mType || sizeof(int) > prop->mDataLength)
  398. this->ReportError("Material property %s is expected to be an integer",prop->mKey);
  399. const char* sz = &prop->mKey->data[iLen];
  400. if (*sz)
  401. {
  402. ++sz;
  403. iIndex = strtol10(sz,NULL);
  404. // ignore UV indices for texture channel that are not there ...
  405. if (iIndex >= iNumIndices)
  406. {
  407. // get the value
  408. iIndex = *((unsigned int*)prop->mData);
  409. // check whether there is a mesh using this material
  410. // which has not enough UV channels ...
  411. for (unsigned int a = 0; a < this->mScene->mNumMeshes;++a)
  412. {
  413. aiMesh* mesh = this->mScene->mMeshes[a];
  414. if(mesh->mMaterialIndex == iIndex)
  415. {
  416. int iChannels = 0;
  417. while (mesh->HasTextureCoords(iChannels++));
  418. if (iIndex >= iChannels)
  419. {
  420. this->ReportError("Invalid UV index: %i (key %s). Mesh %i has only %i UV channels",
  421. iIndex,prop->mKey,a,iChannels);
  422. }
  423. }
  424. }
  425. }
  426. }
  427. }
  428. }
  429. }
  430. // ------------------------------------------------------------------------------------------------
  431. void ValidateDSProcess::Validate( const aiMaterial* pMaterial)
  432. {
  433. // check whether there are material keys that are obviously not legal
  434. for (unsigned int i = 0; i < pMaterial->mNumProperties;++i)
  435. {
  436. aiMaterialProperty* prop = pMaterial->mProperties[i];
  437. if (!prop)
  438. {
  439. this->ReportError("aiMaterial::mProperties[%i] is NULL (aiMaterial::mNumProperties is %i)",
  440. i,pMaterial->mNumProperties);
  441. }
  442. if (!prop->mDataLength || !prop->mData)
  443. {
  444. this->ReportError("aiMaterial::mProperties[%i].mDataLength or "
  445. "aiMaterial::mProperties[%i].mData is 0",i,i);
  446. }
  447. // TODO: check whether there is a key with an unknown name ...
  448. }
  449. float fTemp;
  450. int iShading;
  451. if (AI_SUCCESS == aiGetMaterialInteger( pMaterial,AI_MATKEY_SHADING_MODEL,&iShading))
  452. {
  453. switch ((aiShadingMode)iShading)
  454. {
  455. case aiShadingMode_Blinn:
  456. case aiShadingMode_CookTorrance:
  457. case aiShadingMode_Phong:
  458. if (AI_SUCCESS != aiGetMaterialFloat(pMaterial,AI_MATKEY_SHININESS,&fTemp))
  459. {
  460. this->ReportWarning("A specular shading model is specified but there is no "
  461. "AI_MATKEY_SHININESS key");
  462. }
  463. if (AI_SUCCESS == aiGetMaterialFloat(pMaterial,AI_MATKEY_SHININESS_STRENGTH,&fTemp) && !fTemp)
  464. {
  465. this->ReportWarning("A specular shading model is specified but the value of the "
  466. "AI_MATKEY_SHININESS_STRENGTH key is 0.0");
  467. }
  468. break;
  469. };
  470. }
  471. // check whether there are invalid texture keys
  472. SearchForInvalidTextures(pMaterial,"diffuse");
  473. SearchForInvalidTextures(pMaterial,"specular");
  474. SearchForInvalidTextures(pMaterial,"ambient");
  475. SearchForInvalidTextures(pMaterial,"emissive");
  476. SearchForInvalidTextures(pMaterial,"opacity");
  477. SearchForInvalidTextures(pMaterial,"shininess");
  478. SearchForInvalidTextures(pMaterial,"normals");
  479. SearchForInvalidTextures(pMaterial,"height");
  480. }
  481. // ------------------------------------------------------------------------------------------------
  482. void ValidateDSProcess::Validate( const aiTexture* pTexture)
  483. {
  484. // the data section may NEVER be NULL
  485. if (!pTexture->pcData)
  486. {
  487. this->ReportError("aiTexture::pcData is NULL");
  488. }
  489. if (pTexture->mHeight)
  490. {
  491. if (!pTexture->mWidth)this->ReportError("aiTexture::mWidth is zero "
  492. "(aiTexture::mHeight is %i, uncompressed texture)",pTexture->mHeight);
  493. }
  494. else
  495. {
  496. if (!pTexture->mWidth)this->ReportError("aiTexture::mWidth is zero (compressed texture)");
  497. if ('.' == pTexture->achFormatHint[0])
  498. {
  499. char szTemp[5];
  500. szTemp[0] = pTexture->achFormatHint[0];
  501. szTemp[1] = pTexture->achFormatHint[1];
  502. szTemp[2] = pTexture->achFormatHint[2];
  503. szTemp[3] = pTexture->achFormatHint[3];
  504. szTemp[4] = '\0';
  505. this->ReportWarning("aiTexture::achFormatHint should contain a file extension "
  506. "without a leading dot (format hint: %s).",szTemp);
  507. }
  508. }
  509. }
  510. // ------------------------------------------------------------------------------------------------
  511. void ValidateDSProcess::Validate( const aiAnimation* pAnimation,
  512. const aiBoneAnim* pBoneAnim)
  513. {
  514. // check whether there is a bone with this name ...
  515. unsigned int i = 0;
  516. for (; i < this->mScene->mNumMeshes;++i)
  517. {
  518. aiMesh* mesh = this->mScene->mMeshes[i];
  519. for (unsigned int a = 0; a < mesh->mNumBones;++a)
  520. {
  521. if (mesh->mBones[a]->mName == pBoneAnim->mBoneName)
  522. break;
  523. }
  524. }
  525. if (i == this->mScene->mNumMeshes)
  526. {
  527. this->ReportWarning("aiBoneAnim::mBoneName is %s. However, no bone with this name was found",
  528. pBoneAnim->mBoneName.data);
  529. }
  530. if (!pBoneAnim->mNumPositionKeys && !pBoneAnim->mNumRotationKeys && !pBoneAnim->mNumScalingKeys)
  531. {
  532. this->ReportWarning("A bone animation channel has no keys");
  533. }
  534. // otherwise check whether one of the keys exceeds the total duration of the animation
  535. if (pBoneAnim->mNumPositionKeys)
  536. {
  537. if (!pBoneAnim->mPositionKeys)
  538. {
  539. this->ReportError("aiBoneAnim::mPositionKeys is NULL (aiBoneAnim::mNumPositionKeys is %i)",
  540. pBoneAnim->mNumPositionKeys);
  541. }
  542. for (unsigned int i = 0; i < pBoneAnim->mNumPositionKeys;++i)
  543. {
  544. if (pBoneAnim->mPositionKeys[i].mTime > pAnimation->mDuration)
  545. {
  546. this->ReportError("aiBoneAnim::mPositionKeys[%i].mTime (%.5f) is larger "
  547. "than aiAnimation::mDuration (which is %.5f)",i,
  548. (float)pBoneAnim->mPositionKeys[i].mTime,
  549. (float)pAnimation->mDuration);
  550. }
  551. }
  552. }
  553. // rotation keys
  554. if (pBoneAnim->mNumRotationKeys)
  555. {
  556. if (!pBoneAnim->mRotationKeys)
  557. {
  558. this->ReportError("aiBoneAnim::mRotationKeys is NULL (aiBoneAnim::mNumRotationKeys is %i)",
  559. pBoneAnim->mNumRotationKeys);
  560. }
  561. for (unsigned int i = 0; i < pBoneAnim->mNumRotationKeys;++i)
  562. {
  563. if (pBoneAnim->mRotationKeys[i].mTime > pAnimation->mDuration)
  564. {
  565. this->ReportError("aiBoneAnim::mRotationKeys[%i].mTime (%.5f) is larger "
  566. "than aiAnimation::mDuration (which is %.5f)",i,
  567. (float)pBoneAnim->mRotationKeys[i].mTime,
  568. (float)pAnimation->mDuration);
  569. }
  570. }
  571. }
  572. // scaling keys
  573. if (pBoneAnim->mNumScalingKeys)
  574. {
  575. if (!pBoneAnim->mScalingKeys)
  576. {
  577. this->ReportError("aiBoneAnim::mScalingKeys is NULL (aiBoneAnim::mNumScalingKeys is %i)",
  578. pBoneAnim->mNumScalingKeys);
  579. }
  580. for (unsigned int i = 0; i < pBoneAnim->mNumScalingKeys;++i)
  581. {
  582. if (pBoneAnim->mScalingKeys[i].mTime > pAnimation->mDuration)
  583. {
  584. this->ReportError("aiBoneAnim::mScalingKeys[%i].mTime (%.5f) is larger "
  585. "than aiAnimation::mDuration (which is %.5f)",i,
  586. (float)pBoneAnim->mScalingKeys[i].mTime,
  587. (float)pAnimation->mDuration);
  588. }
  589. }
  590. }
  591. }
  592. // ------------------------------------------------------------------------------------------------
  593. void ValidateDSProcess::Validate( const aiNode* pNode)
  594. {
  595. if (!pNode)this->ReportError("A node of the scenegraph is NULL");
  596. if (pNode != this->mScene->mRootNode && !pNode->mParent)
  597. this->ReportError("A node has no valid parent (aiNode::mParent is NULL)");
  598. // validate all meshes
  599. if (pNode->mNumMeshes)
  600. {
  601. if (!pNode->mMeshes)
  602. {
  603. this->ReportError("aiNode::mMeshes is NULL (aiNode::mNumMeshes is %i)",
  604. pNode->mNumMeshes);
  605. }
  606. std::vector<bool> abHadMesh;
  607. abHadMesh.resize(this->mScene->mNumMeshes,false);
  608. for (unsigned int i = 0; i < pNode->mNumMeshes;++i)
  609. {
  610. if (pNode->mMeshes[i] >= this->mScene->mNumMeshes)
  611. {
  612. this->ReportError("aiNode::mMeshes[%i] is out of range (maximum is %i)",
  613. pNode->mMeshes[i],this->mScene->mNumMeshes-1);
  614. }
  615. if (abHadMesh[pNode->mMeshes[i]])
  616. {
  617. this->ReportError("aiNode::mMeshes[%i] is already referenced by this node (value: %i)",
  618. i,pNode->mMeshes[i]);
  619. }
  620. abHadMesh[pNode->mMeshes[i]] = true;
  621. }
  622. }
  623. if (pNode->mNumChildren)
  624. {
  625. if (!pNode->mChildren)
  626. {
  627. this->ReportError("aiNode::mChildren is NULL (aiNode::mNumChildren is %i)",
  628. pNode->mNumChildren);
  629. }
  630. for (unsigned int i = 0; i < pNode->mNumChildren;++i)
  631. {
  632. this->Validate(pNode->mChildren[i]);
  633. }
  634. }
  635. }