X3DImporter_Texturing.cpp 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. /*
  2. Open Asset Import Library (assimp)
  3. ----------------------------------------------------------------------
  4. Copyright (c) 2006-2019, assimp 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 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 X3DImporter_Texturing.cpp
  34. /// \brief Parsing data from nodes of "Texturing" set of X3D.
  35. /// \date 2015-2016
  36. /// \author [email protected]
  37. #ifndef ASSIMP_BUILD_NO_X3D_IMPORTER
  38. #include "X3DImporter.hpp"
  39. #include "X3DImporter_Macro.hpp"
  40. #include "X3DXmlHelper.h"
  41. namespace Assimp {
  42. // <ImageTexture
  43. // DEF="" ID
  44. // USE="" IDREF
  45. // repeatS="true" SFBool
  46. // repeatT="true" SFBool
  47. // url="" MFString
  48. // />
  49. // When the url field contains no values ([]), texturing is disabled.
  50. void X3DImporter::readImageTexture(XmlNode &node) {
  51. std::string use, def;
  52. bool repeatS = true;
  53. bool repeatT = true;
  54. std::list<std::string> url;
  55. X3DNodeElementBase *ne(nullptr);
  56. MACRO_ATTRREAD_CHECKUSEDEF_RET(node, def, use);
  57. XmlParser::getBoolAttribute(node, "repeatS", repeatS);
  58. XmlParser::getBoolAttribute(node, "repeatT", repeatT);
  59. X3DXmlHelper::getStringListAttribute(node, "url", url);
  60. // if "USE" defined then find already defined element.
  61. if (!use.empty()) {
  62. ne = MACRO_USE_CHECKANDAPPLY(node, def, use, ENET_ImageTexture, ne);
  63. } else {
  64. // create and if needed - define new geometry object.
  65. ne = new X3DNodeElementImageTexture(mNodeElementCur);
  66. if (!def.empty()) ne->ID = def;
  67. ((X3DNodeElementImageTexture *)ne)->RepeatS = repeatS;
  68. ((X3DNodeElementImageTexture *)ne)->RepeatT = repeatT;
  69. // Attribute "url" can contain list of strings. But we need only one - first.
  70. if (!url.empty())
  71. ((X3DNodeElementImageTexture *)ne)->URL = url.front();
  72. else
  73. ((X3DNodeElementImageTexture *)ne)->URL = "";
  74. // check for X3DMetadataObject childs.
  75. if (!isNodeEmpty(node))
  76. childrenReadMetadata(node, ne, "ImageTexture");
  77. else
  78. mNodeElementCur->Children.push_back(ne); // add made object as child to current element
  79. NodeElement_List.push_back(ne); // add element to node element list because its a new object in graph
  80. } // if(!use.empty()) else
  81. }
  82. // <TextureCoordinate
  83. // DEF="" ID
  84. // USE="" IDREF
  85. // point="" MFVec3f [inputOutput]
  86. // />
  87. void X3DImporter::readTextureCoordinate(XmlNode &node) {
  88. std::string use, def;
  89. std::list<aiVector2D> point;
  90. X3DNodeElementBase *ne(nullptr);
  91. MACRO_ATTRREAD_CHECKUSEDEF_RET(node, def, use);
  92. X3DXmlHelper::getVector2DListAttribute(node, "point", point);
  93. // if "USE" defined then find already defined element.
  94. if (!use.empty()) {
  95. ne = MACRO_USE_CHECKANDAPPLY(node, def, use, ENET_TextureCoordinate, ne);
  96. } else {
  97. // create and if needed - define new geometry object.
  98. ne = new X3DNodeElementTextureCoordinate(mNodeElementCur);
  99. if (!def.empty()) ne->ID = def;
  100. ((X3DNodeElementTextureCoordinate *)ne)->Value = point;
  101. // check for X3DMetadataObject childs.
  102. if (!isNodeEmpty(node))
  103. childrenReadMetadata(node, ne, "TextureCoordinate");
  104. else
  105. mNodeElementCur->Children.push_back(ne); // add made object as child to current element
  106. NodeElement_List.push_back(ne); // add element to node element list because its a new object in graph
  107. } // if(!use.empty()) else
  108. }
  109. // <TextureTransform
  110. // DEF="" ID
  111. // USE="" IDREF
  112. // center="0 0" SFVec2f [inputOutput]
  113. // rotation="0" SFFloat [inputOutput]
  114. // scale="1 1" SFVec2f [inputOutput]
  115. // translation="0 0" SFVec2f [inputOutput]
  116. // />
  117. void X3DImporter::readTextureTransform(XmlNode &node) {
  118. std::string use, def;
  119. aiVector2D center(0, 0);
  120. float rotation = 0;
  121. aiVector2D scale(1, 1);
  122. aiVector2D translation(0, 0);
  123. X3DNodeElementBase *ne(nullptr);
  124. MACRO_ATTRREAD_CHECKUSEDEF_RET(node, def, use);
  125. X3DXmlHelper::getVector2DAttribute(node, "center", center);
  126. XmlParser::getFloatAttribute(node, "rotation", rotation);
  127. X3DXmlHelper::getVector2DAttribute(node, "scale", scale);
  128. X3DXmlHelper::getVector2DAttribute(node, "translation", translation);
  129. // if "USE" defined then find already defined element.
  130. if (!use.empty()) {
  131. ne = MACRO_USE_CHECKANDAPPLY(node, def, use, ENET_TextureTransform, ne);
  132. } else {
  133. // create and if needed - define new geometry object.
  134. ne = new X3DNodeElementTextureTransform(mNodeElementCur);
  135. if (!def.empty()) ne->ID = def;
  136. ((X3DNodeElementTextureTransform *)ne)->Center = center;
  137. ((X3DNodeElementTextureTransform *)ne)->Rotation = rotation;
  138. ((X3DNodeElementTextureTransform *)ne)->Scale = scale;
  139. ((X3DNodeElementTextureTransform *)ne)->Translation = translation;
  140. // check for X3DMetadataObject childs.
  141. if (!isNodeEmpty(node))
  142. childrenReadMetadata(node, ne, "TextureTransform");
  143. else
  144. mNodeElementCur->Children.push_back(ne); // add made object as child to current element
  145. NodeElement_List.push_back(ne); // add element to node element list because its a new object in graph
  146. } // if(!use.empty()) else
  147. }
  148. } // namespace Assimp
  149. #endif // !ASSIMP_BUILD_NO_X3D_IMPORTER