RemoveVCProcess.cpp 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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 remove
  35. * any parts of the mesh structure from the imported data.
  36. */
  37. #include "RemoveVCProcess.h"
  38. #include "../include/DefaultLogger.h"
  39. #include "../include/aiPostProcess.h"
  40. #include "../include/aiScene.h"
  41. #include "../include/aiConfig.h"
  42. using namespace Assimp;
  43. // ------------------------------------------------------------------------------------------------
  44. // Constructor to be privately used by Importer
  45. RemoveVCProcess::RemoveVCProcess()
  46. {
  47. }
  48. // ------------------------------------------------------------------------------------------------
  49. // Destructor, private as well
  50. RemoveVCProcess::~RemoveVCProcess()
  51. {
  52. // nothing to do here
  53. }
  54. // ------------------------------------------------------------------------------------------------
  55. // Returns whether the processing step is present in the given flag field.
  56. bool RemoveVCProcess::IsActive( unsigned int pFlags) const
  57. {
  58. return (pFlags & aiProcess_RemVertexComponentXYZ) != 0;
  59. }
  60. // ------------------------------------------------------------------------------------------------
  61. // Executes the post processing step on the given imported data.
  62. void RemoveVCProcess::Execute( aiScene* pScene)
  63. {
  64. DefaultLogger::get()->debug("RemoveVCProcess begin");
  65. bool bHas = false;
  66. for( unsigned int a = 0; a < pScene->mNumMeshes; a++)
  67. {
  68. if( this->ProcessMesh( pScene->mMeshes[a]))
  69. bHas = true;
  70. }
  71. if (bHas)DefaultLogger::get()->info("RemoveVCProcess finished. The specified vertex components have been removed");
  72. else DefaultLogger::get()->debug("RemoveVCProcess finished. There was nothing to do ..");
  73. }
  74. // ------------------------------------------------------------------------------------------------
  75. // Setup configuration properties for the step
  76. void RemoveVCProcess::SetupProperties(const Importer* pImp)
  77. {
  78. configDeleteFlags = pImp->GetPropertyInteger(AI_CONFIG_PP_RVC_FLAGS,0x0);
  79. if (!configDeleteFlags)
  80. {
  81. DefaultLogger::get()->warn("RemoveVCProcess: AI_CONFIG_PP_RVC_FLAGS is zero, no streams selected");
  82. }
  83. }
  84. // ------------------------------------------------------------------------------------------------
  85. // Executes the post processing step on the given imported data.
  86. bool RemoveVCProcess::ProcessMesh(aiMesh* pMesh)
  87. {
  88. // handle normals
  89. if (configDeleteFlags & aiVertexComponent_NORMALS && pMesh->mNormals)
  90. {
  91. delete[] pMesh->mNormals;
  92. pMesh->mNormals = NULL;
  93. }
  94. // handle tangents and bitangents
  95. if (configDeleteFlags & aiVertexComponent_TANGENTS_AND_BITANGENTS && pMesh->mTangents)
  96. {
  97. delete[] pMesh->mTangents;
  98. pMesh->mTangents = NULL;
  99. delete[] pMesh->mBitangents;
  100. pMesh->mBitangents = NULL;
  101. }
  102. // handle texture coordinates
  103. register bool b = (0 != (configDeleteFlags & aiVertexComponent_TEXCOORDS));
  104. for (unsigned int i = 0; i < AI_MAX_NUMBER_OF_TEXTURECOORDS; ++i)
  105. {
  106. if (!pMesh->mTextureCoords[i])break;
  107. if (configDeleteFlags & aiVertexComponent_TEXCOORDSn(i) || b)
  108. {
  109. delete pMesh->mTextureCoords[i];
  110. pMesh->mTextureCoords[i] = NULL;
  111. if (!b)
  112. {
  113. // collapse the rest of the array
  114. unsigned int a;
  115. for (a = i+1; a < AI_MAX_NUMBER_OF_TEXTURECOORDS;++a)
  116. {
  117. pMesh->mTextureCoords[a-1] = pMesh->mTextureCoords[a];
  118. }
  119. pMesh->mTextureCoords[AI_MAX_NUMBER_OF_TEXTURECOORDS-1] = NULL;
  120. }
  121. }
  122. }
  123. // handle vertex colors
  124. b = (0 != (configDeleteFlags & aiVertexComponent_COLORS));
  125. for (unsigned int i = 0; i < AI_MAX_NUMBER_OF_COLOR_SETS; ++i)
  126. {
  127. if (!pMesh->mColors[i])break;
  128. if (configDeleteFlags & aiVertexComponent_COLORSn(i) || b)
  129. {
  130. delete pMesh->mColors[i];
  131. pMesh->mColors[i] = NULL;
  132. if (!b)
  133. {
  134. // collapse the rest of the array
  135. unsigned int a;
  136. for (a = i+1; a < AI_MAX_NUMBER_OF_COLOR_SETS;++a)
  137. {
  138. pMesh->mColors[a-1] = pMesh->mColors[a];
  139. }
  140. pMesh->mColors[AI_MAX_NUMBER_OF_COLOR_SETS-1] = NULL;
  141. }
  142. }
  143. }
  144. return true;
  145. }