選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 
 
 
 
 

329 行
9.5 KiB

  1. /*
  2. ---------------------------------------------------------------------------
  3. Open Asset Import Library (assimp)
  4. ---------------------------------------------------------------------------
  5. Copyright (c) 2006-2012, 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 post processing step to remove
  35. * any parts of the mesh structure from the imported data.
  36. */
  37. #include "AssimpPCH.h"
  38. #include "RemoveVCProcess.h"
  39. using namespace Assimp;
  40. // ------------------------------------------------------------------------------------------------
  41. // Constructor to be privately used by Importer
  42. RemoveVCProcess::RemoveVCProcess()
  43. {}
  44. // ------------------------------------------------------------------------------------------------
  45. // Destructor, private as well
  46. RemoveVCProcess::~RemoveVCProcess()
  47. {}
  48. // ------------------------------------------------------------------------------------------------
  49. // Returns whether the processing step is present in the given flag field.
  50. bool RemoveVCProcess::IsActive( unsigned int pFlags) const
  51. {
  52. return (pFlags & aiProcess_RemoveComponent) != 0;
  53. }
  54. // ------------------------------------------------------------------------------------------------
  55. // Small helper function to delete all elements in a T** aray using delete
  56. template <typename T>
  57. inline void ArrayDelete(T**& in, unsigned int& num)
  58. {
  59. for (unsigned int i = 0; i < num; ++i)
  60. delete in[i];
  61. delete[] in;
  62. in = NULL;
  63. num = 0;
  64. }
  65. #if 0
  66. // ------------------------------------------------------------------------------------------------
  67. // Updates the node graph - removes all nodes which have the "remove" flag set and the
  68. // "don't remove" flag not set. Nodes with meshes are never deleted.
  69. bool UpdateNodeGraph(aiNode* node,std::list<aiNode*>& childsOfParent,bool root)
  70. {
  71. register bool b = false;
  72. std::list<aiNode*> mine;
  73. for (unsigned int i = 0; i < node->mNumChildren;++i)
  74. {
  75. if(UpdateNodeGraph(node->mChildren[i],mine,false))
  76. b = true;
  77. }
  78. // somewhat tricky ... mNumMeshes must be originally 0 and MSB2 may not be set,
  79. // so we can do a simple comparison against MSB here
  80. if (!root && AI_RC_UINT_MSB == node->mNumMeshes )
  81. {
  82. // this node needs to be removed
  83. if(node->mNumChildren)
  84. {
  85. childsOfParent.insert(childsOfParent.end(),mine.begin(),mine.end());
  86. // set all children to NULL to make sure they are not deleted when we delete ourself
  87. for (unsigned int i = 0; i < node->mNumChildren;++i)
  88. node->mChildren[i] = NULL;
  89. }
  90. b = true;
  91. delete node;
  92. }
  93. else
  94. {
  95. AI_RC_UNMASK(node->mNumMeshes);
  96. childsOfParent.push_back(node);
  97. if (b)
  98. {
  99. // reallocate the array of our children here
  100. node->mNumChildren = (unsigned int)mine.size();
  101. aiNode** const children = new aiNode*[mine.size()];
  102. aiNode** ptr = children;
  103. for (std::list<aiNode*>::iterator it = mine.begin(), end = mine.end();
  104. it != end; ++it)
  105. {
  106. *ptr++ = *it;
  107. }
  108. delete[] node->mChildren;
  109. node->mChildren = children;
  110. return false;
  111. }
  112. }
  113. return b;
  114. }
  115. #endif
  116. // ------------------------------------------------------------------------------------------------
  117. // Executes the post processing step on the given imported data.
  118. void RemoveVCProcess::Execute( aiScene* pScene)
  119. {
  120. DefaultLogger::get()->debug("RemoveVCProcess begin");
  121. bool bHas = false; //,bMasked = false;
  122. mScene = pScene;
  123. // handle animations
  124. if ( configDeleteFlags & aiComponent_ANIMATIONS)
  125. {
  126. bHas = true;
  127. ArrayDelete(pScene->mAnimations,pScene->mNumAnimations);
  128. }
  129. // handle textures
  130. if ( configDeleteFlags & aiComponent_TEXTURES)
  131. {
  132. bHas = true;
  133. ArrayDelete(pScene->mTextures,pScene->mNumTextures);
  134. }
  135. // handle materials
  136. if ( configDeleteFlags & aiComponent_MATERIALS && pScene->mNumMaterials)
  137. {
  138. bHas = true;
  139. for (unsigned int i = 1;i < pScene->mNumMaterials;++i)
  140. delete pScene->mMaterials[i];
  141. pScene->mNumMaterials = 1;
  142. aiMaterial* helper = (aiMaterial*) pScene->mMaterials[0];
  143. ai_assert(NULL != helper);
  144. helper->Clear();
  145. // gray
  146. aiColor3D clr(0.6f,0.6f,0.6f);
  147. helper->AddProperty(&clr,1,AI_MATKEY_COLOR_DIFFUSE);
  148. // add a small ambient color value
  149. clr = aiColor3D(0.05f,0.05f,0.05f);
  150. helper->AddProperty(&clr,1,AI_MATKEY_COLOR_AMBIENT);
  151. aiString s;
  152. s.Set("Dummy_MaterialsRemoved");
  153. helper->AddProperty(&s,AI_MATKEY_NAME);
  154. }
  155. // handle light sources
  156. if ( configDeleteFlags & aiComponent_LIGHTS)
  157. {
  158. bHas = true;
  159. ArrayDelete(pScene->mLights,pScene->mNumLights);
  160. }
  161. // handle camneras
  162. if ( configDeleteFlags & aiComponent_CAMERAS)
  163. {
  164. bHas = true;
  165. ArrayDelete(pScene->mCameras,pScene->mNumCameras);
  166. }
  167. // handle meshes
  168. if (configDeleteFlags & aiComponent_MESHES)
  169. {
  170. bHas = true;
  171. ArrayDelete(pScene->mMeshes,pScene->mNumMeshes);
  172. }
  173. else
  174. {
  175. for( unsigned int a = 0; a < pScene->mNumMeshes; a++)
  176. {
  177. if( ProcessMesh( pScene->mMeshes[a]))
  178. bHas = true;
  179. }
  180. }
  181. // now check whether the result is still a full scene
  182. if (!pScene->mNumMeshes || !pScene->mNumMaterials)
  183. {
  184. pScene->mFlags |= AI_SCENE_FLAGS_INCOMPLETE;
  185. DefaultLogger::get()->debug("Setting AI_SCENE_FLAGS_INCOMPLETE flag");
  186. // If we have no meshes anymore we should also clear another flag ...
  187. if (!pScene->mNumMeshes)
  188. pScene->mFlags &= ~AI_SCENE_FLAGS_NON_VERBOSE_FORMAT;
  189. }
  190. if (bHas)DefaultLogger::get()->info("RemoveVCProcess finished. Data structure cleanup has been done.");
  191. else DefaultLogger::get()->debug("RemoveVCProcess finished. Nothing to be done ...");
  192. }
  193. // ------------------------------------------------------------------------------------------------
  194. // Setup configuration properties for the step
  195. void RemoveVCProcess::SetupProperties(const Importer* pImp)
  196. {
  197. configDeleteFlags = pImp->GetPropertyInteger(AI_CONFIG_PP_RVC_FLAGS,0x0);
  198. if (!configDeleteFlags)
  199. {
  200. DefaultLogger::get()->warn("RemoveVCProcess: AI_CONFIG_PP_RVC_FLAGS is zero.");
  201. }
  202. }
  203. // ------------------------------------------------------------------------------------------------
  204. // Executes the post processing step on the given imported data.
  205. bool RemoveVCProcess::ProcessMesh(aiMesh* pMesh)
  206. {
  207. bool ret = false;
  208. // if all materials have been deleted let the material
  209. // index of the mesh point to the created default material
  210. if ( configDeleteFlags & aiComponent_MATERIALS)
  211. pMesh->mMaterialIndex = 0;
  212. // handle normals
  213. if (configDeleteFlags & aiComponent_NORMALS && pMesh->mNormals)
  214. {
  215. delete[] pMesh->mNormals;
  216. pMesh->mNormals = NULL;
  217. ret = true;
  218. }
  219. // handle tangents and bitangents
  220. if (configDeleteFlags & aiComponent_TANGENTS_AND_BITANGENTS && pMesh->mTangents)
  221. {
  222. delete[] pMesh->mTangents;
  223. pMesh->mTangents = NULL;
  224. delete[] pMesh->mBitangents;
  225. pMesh->mBitangents = NULL;
  226. ret = true;
  227. }
  228. // handle texture coordinates
  229. register bool b = (0 != (configDeleteFlags & aiComponent_TEXCOORDS));
  230. for (unsigned int i = 0, real = 0; real < AI_MAX_NUMBER_OF_TEXTURECOORDS; ++real)
  231. {
  232. if (!pMesh->mTextureCoords[i])break;
  233. if (configDeleteFlags & aiComponent_TEXCOORDSn(real) || b)
  234. {
  235. delete pMesh->mTextureCoords[i];
  236. pMesh->mTextureCoords[i] = NULL;
  237. ret = true;
  238. if (!b)
  239. {
  240. // collapse the rest of the array
  241. for (unsigned int a = i+1; a < AI_MAX_NUMBER_OF_TEXTURECOORDS;++a)
  242. pMesh->mTextureCoords[a-1] = pMesh->mTextureCoords[a];
  243. pMesh->mTextureCoords[AI_MAX_NUMBER_OF_TEXTURECOORDS-1] = NULL;
  244. continue;
  245. }
  246. }
  247. ++i;
  248. }
  249. // handle vertex colors
  250. b = (0 != (configDeleteFlags & aiComponent_COLORS));
  251. for (unsigned int i = 0, real = 0; real < AI_MAX_NUMBER_OF_COLOR_SETS; ++real)
  252. {
  253. if (!pMesh->mColors[i])break;
  254. if (configDeleteFlags & aiComponent_COLORSn(i) || b)
  255. {
  256. delete pMesh->mColors[i];
  257. pMesh->mColors[i] = NULL;
  258. ret = true;
  259. if (!b)
  260. {
  261. // collapse the rest of the array
  262. for (unsigned int a = i+1; a < AI_MAX_NUMBER_OF_COLOR_SETS;++a)
  263. pMesh->mColors[a-1] = pMesh->mColors[a];
  264. pMesh->mColors[AI_MAX_NUMBER_OF_COLOR_SETS-1] = NULL;
  265. continue;
  266. }
  267. }
  268. ++i;
  269. }
  270. // handle bones
  271. if (configDeleteFlags & aiComponent_BONEWEIGHTS && pMesh->mBones)
  272. {
  273. ArrayDelete(pMesh->mBones,pMesh->mNumBones);
  274. ret = true;
  275. }
  276. return ret;
  277. }