X3DImporter_Texturing.cpp 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. /*
  2. Open Asset Import Library (assimp)
  3. ----------------------------------------------------------------------
  4. Copyright (c) 2006-2020, 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. namespace Assimp
  41. {
  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::ParseNode_Texturing_ImageTexture()
  51. {
  52. std::string use, def;
  53. bool repeatS = true;
  54. bool repeatT = true;
  55. std::list<std::string> url;
  56. CX3DImporter_NodeElement* ne( nullptr );
  57. MACRO_ATTRREAD_LOOPBEG;
  58. MACRO_ATTRREAD_CHECKUSEDEF_RET(def, use);
  59. MACRO_ATTRREAD_CHECK_RET("repeatS", repeatS, XML_ReadNode_GetAttrVal_AsBool);
  60. MACRO_ATTRREAD_CHECK_RET("repeatT", repeatT, XML_ReadNode_GetAttrVal_AsBool);
  61. MACRO_ATTRREAD_CHECK_REF("url", url, XML_ReadNode_GetAttrVal_AsListS);
  62. MACRO_ATTRREAD_LOOPEND;
  63. // if "USE" defined then find already defined element.
  64. if(!use.empty())
  65. {
  66. MACRO_USE_CHECKANDAPPLY(def, use, ENET_ImageTexture, ne);
  67. }
  68. else
  69. {
  70. // create and if needed - define new geometry object.
  71. ne = new CX3DImporter_NodeElement_ImageTexture(NodeElement_Cur);
  72. if(!def.empty()) ne->ID = def;
  73. ((CX3DImporter_NodeElement_ImageTexture*)ne)->RepeatS = repeatS;
  74. ((CX3DImporter_NodeElement_ImageTexture*)ne)->RepeatT = repeatT;
  75. // Attribute "url" can contain list of strings. But we need only one - first.
  76. if(!url.empty())
  77. ((CX3DImporter_NodeElement_ImageTexture*)ne)->URL = url.front();
  78. else
  79. ((CX3DImporter_NodeElement_ImageTexture*)ne)->URL = "";
  80. // check for X3DMetadataObject childs.
  81. if(!mReader->isEmptyElement())
  82. ParseNode_Metadata(ne, "ImageTexture");
  83. else
  84. NodeElement_Cur->Child.push_back(ne);// add made object as child to current element
  85. NodeElement_List.push_back(ne);// add element to node element list because its a new object in graph
  86. }// if(!use.empty()) else
  87. }
  88. // <TextureCoordinate
  89. // DEF="" ID
  90. // USE="" IDREF
  91. // point="" MFVec3f [inputOutput]
  92. // />
  93. void X3DImporter::ParseNode_Texturing_TextureCoordinate()
  94. {
  95. std::string use, def;
  96. std::list<aiVector2D> point;
  97. CX3DImporter_NodeElement* ne( nullptr );
  98. MACRO_ATTRREAD_LOOPBEG;
  99. MACRO_ATTRREAD_CHECKUSEDEF_RET(def, use);
  100. MACRO_ATTRREAD_CHECK_REF("point", point, XML_ReadNode_GetAttrVal_AsListVec2f);
  101. MACRO_ATTRREAD_LOOPEND;
  102. // if "USE" defined then find already defined element.
  103. if(!use.empty())
  104. {
  105. MACRO_USE_CHECKANDAPPLY(def, use, ENET_TextureCoordinate, ne);
  106. }
  107. else
  108. {
  109. // create and if needed - define new geometry object.
  110. ne = new CX3DImporter_NodeElement_TextureCoordinate(NodeElement_Cur);
  111. if(!def.empty()) ne->ID = def;
  112. ((CX3DImporter_NodeElement_TextureCoordinate*)ne)->Value = point;
  113. // check for X3DMetadataObject childs.
  114. if(!mReader->isEmptyElement())
  115. ParseNode_Metadata(ne, "TextureCoordinate");
  116. else
  117. NodeElement_Cur->Child.push_back(ne);// add made object as child to current element
  118. NodeElement_List.push_back(ne);// add element to node element list because its a new object in graph
  119. }// if(!use.empty()) else
  120. }
  121. // <TextureTransform
  122. // DEF="" ID
  123. // USE="" IDREF
  124. // center="0 0" SFVec2f [inputOutput]
  125. // rotation="0" SFFloat [inputOutput]
  126. // scale="1 1" SFVec2f [inputOutput]
  127. // translation="0 0" SFVec2f [inputOutput]
  128. // />
  129. void X3DImporter::ParseNode_Texturing_TextureTransform()
  130. {
  131. std::string use, def;
  132. aiVector2D center(0, 0);
  133. float rotation = 0;
  134. aiVector2D scale(1, 1);
  135. aiVector2D translation(0, 0);
  136. CX3DImporter_NodeElement* ne( nullptr );
  137. MACRO_ATTRREAD_LOOPBEG;
  138. MACRO_ATTRREAD_CHECKUSEDEF_RET(def, use);
  139. MACRO_ATTRREAD_CHECK_REF("center", center, XML_ReadNode_GetAttrVal_AsVec2f);
  140. MACRO_ATTRREAD_CHECK_RET("rotation", rotation, XML_ReadNode_GetAttrVal_AsFloat);
  141. MACRO_ATTRREAD_CHECK_REF("scale", scale, XML_ReadNode_GetAttrVal_AsVec2f);
  142. MACRO_ATTRREAD_CHECK_REF("translation", translation, XML_ReadNode_GetAttrVal_AsVec2f);
  143. MACRO_ATTRREAD_LOOPEND;
  144. // if "USE" defined then find already defined element.
  145. if(!use.empty())
  146. {
  147. MACRO_USE_CHECKANDAPPLY(def, use, ENET_TextureTransform, ne);
  148. }
  149. else
  150. {
  151. // create and if needed - define new geometry object.
  152. ne = new CX3DImporter_NodeElement_TextureTransform(NodeElement_Cur);
  153. if(!def.empty()) ne->ID = def;
  154. ((CX3DImporter_NodeElement_TextureTransform*)ne)->Center = center;
  155. ((CX3DImporter_NodeElement_TextureTransform*)ne)->Rotation = rotation;
  156. ((CX3DImporter_NodeElement_TextureTransform*)ne)->Scale = scale;
  157. ((CX3DImporter_NodeElement_TextureTransform*)ne)->Translation = translation;
  158. // check for X3DMetadataObject childs.
  159. if(!mReader->isEmptyElement())
  160. ParseNode_Metadata(ne, "TextureTransform");
  161. else
  162. NodeElement_Cur->Child.push_back(ne);// add made object as child to current element
  163. NodeElement_List.push_back(ne);// add element to node element list because its a new object in graph
  164. }// if(!use.empty()) else
  165. }
  166. }// namespace Assimp
  167. #endif // !ASSIMP_BUILD_NO_X3D_IMPORTER