2
0

ComputeUVMappingProcess.cpp 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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. /** @file GenUVCoords step */
  34. #include "AssimpPCH.h"
  35. #include "ComputeUVMappingProcess.h"
  36. #include "ProcessHelper.h"
  37. using namespace Assimp;
  38. // ------------------------------------------------------------------------------------------------
  39. // Constructor to be privately used by Importer
  40. ComputeUVMappingProcess::ComputeUVMappingProcess()
  41. {
  42. // nothing to do here
  43. }
  44. // ------------------------------------------------------------------------------------------------
  45. // Destructor, private as well
  46. ComputeUVMappingProcess::~ComputeUVMappingProcess()
  47. {
  48. // nothing to do here
  49. }
  50. // ------------------------------------------------------------------------------------------------
  51. // Returns whether the processing step is present in the given flag field.
  52. bool ComputeUVMappingProcess::IsActive( unsigned int pFlags) const
  53. {
  54. return (pFlags & aiProcess_GenUVCoords) != 0;
  55. }
  56. // ------------------------------------------------------------------------------------------------
  57. unsigned int ComputeUVMappingProcess::ComputeSphereMapping(aiMesh* mesh,aiAxis axis)
  58. {
  59. DefaultLogger::get()->error("Mapping type currently not implemented");
  60. return 0;
  61. }
  62. // ------------------------------------------------------------------------------------------------
  63. unsigned int ComputeUVMappingProcess::ComputeCylinderMapping(aiMesh* mesh,aiAxis axis)
  64. {
  65. DefaultLogger::get()->error("Mapping type currently not implemented");
  66. return 0;
  67. }
  68. // ------------------------------------------------------------------------------------------------
  69. unsigned int ComputeUVMappingProcess::ComputePlaneMapping(aiMesh* mesh,aiAxis axis)
  70. {
  71. DefaultLogger::get()->error("Mapping type currently not implemented");
  72. return 0;
  73. }
  74. // ------------------------------------------------------------------------------------------------
  75. unsigned int ComputeUVMappingProcess::ComputeBoxMapping(aiMesh* mesh)
  76. {
  77. DefaultLogger::get()->error("Mapping type currently not implemented");
  78. return 0;
  79. }
  80. // ------------------------------------------------------------------------------------------------
  81. void ComputeUVMappingProcess::Execute( aiScene* pScene)
  82. {
  83. DefaultLogger::get()->debug("GenUVCoordsProcess begin");
  84. char buffer[1024];
  85. /* Iterate through all materials and search for non-UV mapped textures
  86. */
  87. for (unsigned int i = 0; i < pScene->mNumMaterials;++i)
  88. {
  89. aiMaterial* mat = pScene->mMaterials[i];
  90. for (unsigned int a = 0; a < mat->mNumProperties;++a)
  91. {
  92. aiMaterialProperty* prop = mat->mProperties[a];
  93. if (!::strcmp( prop->mKey.data, "$tex.mapping"))
  94. {
  95. aiTextureMapping mapping = *((aiTextureMapping*)prop->mData);
  96. if (aiTextureMapping_UV != mapping)
  97. {
  98. if (!DefaultLogger::isNullLogger())
  99. {
  100. sprintf(buffer, "Found non-UV mapped texture (%s,%i). Mapping type: %s",
  101. TextureTypeToString((aiTextureType)prop->mSemantic),prop->mIndex,
  102. MappingTypeToString(mapping));
  103. DefaultLogger::get()->info(buffer);
  104. }
  105. aiAxis axis;
  106. // Get further properties - currently only the major axis
  107. for (unsigned int a2 = 0; a2 < mat->mNumProperties;++a2)
  108. {
  109. aiMaterialProperty* prop2 = mat->mProperties[a2];
  110. if (prop2->mSemantic != prop->mSemantic || prop2->mIndex != prop->mIndex)
  111. continue;
  112. if ( !::strcmp( prop2->mKey.data, "$tex.mapaxis"))
  113. {
  114. axis = *((aiAxis*)prop2->mData);
  115. break;
  116. }
  117. }
  118. /* We have found a non-UV mapped texture. Now
  119. * we need to find all meshes using this material
  120. * that we can compute UV channels for them.
  121. */
  122. for (unsigned int m = 0; m < pScene->mNumMeshes;++m)
  123. {
  124. aiMesh* mesh = pScene->mMeshes[m];
  125. if (mesh->mMaterialIndex != i) continue;
  126. switch (mapping)
  127. {
  128. case aiTextureMapping_SPHERE:
  129. ComputeSphereMapping(mesh,axis);
  130. break;
  131. case aiTextureMapping_CYLINDER:
  132. ComputeCylinderMapping(mesh,axis);
  133. break;
  134. case aiTextureMapping_PLANE:
  135. ComputePlaneMapping(mesh,axis);
  136. break;
  137. case aiTextureMapping_BOX:
  138. ComputeBoxMapping(mesh);
  139. break;
  140. }
  141. }
  142. }
  143. }
  144. }
  145. }
  146. DefaultLogger::get()->debug("GenUVCoordsProcess finished");
  147. }