X3DImporter_Texturing.cpp 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. /// \file X3DImporter_Texturing.cpp
  2. /// \brief Parsing data from nodes of "Texturing" set of X3D.
  3. /// \date 2015-2016
  4. /// \author [email protected]
  5. #ifndef ASSIMP_BUILD_NO_X3D_IMPORTER
  6. #include "X3DImporter.hpp"
  7. #include "X3DImporter_Macro.hpp"
  8. namespace Assimp
  9. {
  10. // <ImageTexture
  11. // DEF="" ID
  12. // USE="" IDREF
  13. // repeatS="true" SFBool
  14. // repeatT="true" SFBool
  15. // url="" MFString
  16. // />
  17. // When the url field contains no values ([]), texturing is disabled.
  18. void X3DImporter::ParseNode_Texturing_ImageTexture()
  19. {
  20. std::string use, def;
  21. bool repeatS = true;
  22. bool repeatT = true;
  23. std::list<std::string> url;
  24. CX3DImporter_NodeElement* ne;
  25. MACRO_ATTRREAD_LOOPBEG;
  26. MACRO_ATTRREAD_CHECKUSEDEF_RET(def, use);
  27. MACRO_ATTRREAD_CHECK_RET("repeatS", repeatS, XML_ReadNode_GetAttrVal_AsBool);
  28. MACRO_ATTRREAD_CHECK_RET("repeatT", repeatT, XML_ReadNode_GetAttrVal_AsBool);
  29. MACRO_ATTRREAD_CHECK_REF("url", url, XML_ReadNode_GetAttrVal_AsListS);
  30. MACRO_ATTRREAD_LOOPEND;
  31. // if "USE" defined then find already defined element.
  32. if(!use.empty())
  33. {
  34. MACRO_USE_CHECKANDAPPLY(def, use, ENET_ImageTexture, ne);
  35. }
  36. else
  37. {
  38. // create and if needed - define new geometry object.
  39. ne = new CX3DImporter_NodeElement_ImageTexture(NodeElement_Cur);
  40. if(!def.empty()) ne->ID = def;
  41. ((CX3DImporter_NodeElement_ImageTexture*)ne)->RepeatS = repeatS;
  42. ((CX3DImporter_NodeElement_ImageTexture*)ne)->RepeatT = repeatT;
  43. // Attribute "url" can contain list of strings. But we need only one - first.
  44. if(url.size() > 0)
  45. ((CX3DImporter_NodeElement_ImageTexture*)ne)->URL = url.front();
  46. else
  47. ((CX3DImporter_NodeElement_ImageTexture*)ne)->URL = "";
  48. // check for X3DMetadataObject childs.
  49. if(!mReader->isEmptyElement())
  50. ParseNode_Metadata(ne, "ImageTexture");
  51. else
  52. NodeElement_Cur->Child.push_back(ne);// add made object as child to current element
  53. NodeElement_List.push_back(ne);// add element to node element list because its a new object in graph
  54. }// if(!use.empty()) else
  55. }
  56. // <TextureCoordinate
  57. // DEF="" ID
  58. // USE="" IDREF
  59. // point="" MFVec3f [inputOutput]
  60. // />
  61. void X3DImporter::ParseNode_Texturing_TextureCoordinate()
  62. {
  63. std::string use, def;
  64. std::list<aiVector2D> point;
  65. CX3DImporter_NodeElement* ne;
  66. MACRO_ATTRREAD_LOOPBEG;
  67. MACRO_ATTRREAD_CHECKUSEDEF_RET(def, use);
  68. MACRO_ATTRREAD_CHECK_REF("point", point, XML_ReadNode_GetAttrVal_AsListVec2f);
  69. MACRO_ATTRREAD_LOOPEND;
  70. // if "USE" defined then find already defined element.
  71. if(!use.empty())
  72. {
  73. MACRO_USE_CHECKANDAPPLY(def, use, ENET_TextureCoordinate, ne);
  74. }
  75. else
  76. {
  77. // create and if needed - define new geometry object.
  78. ne = new CX3DImporter_NodeElement_TextureCoordinate(NodeElement_Cur);
  79. if(!def.empty()) ne->ID = def;
  80. ((CX3DImporter_NodeElement_TextureCoordinate*)ne)->Value = point;
  81. // check for X3DMetadataObject childs.
  82. if(!mReader->isEmptyElement())
  83. ParseNode_Metadata(ne, "TextureCoordinate");
  84. else
  85. NodeElement_Cur->Child.push_back(ne);// add made object as child to current element
  86. NodeElement_List.push_back(ne);// add element to node element list because its a new object in graph
  87. }// if(!use.empty()) else
  88. }
  89. // <TextureTransform
  90. // DEF="" ID
  91. // USE="" IDREF
  92. // center="0 0" SFVec2f [inputOutput]
  93. // rotation="0" SFFloat [inputOutput]
  94. // scale="1 1" SFVec2f [inputOutput]
  95. // translation="0 0" SFVec2f [inputOutput]
  96. // />
  97. void X3DImporter::ParseNode_Texturing_TextureTransform()
  98. {
  99. std::string use, def;
  100. aiVector2D center(0, 0);
  101. float rotation = 0;
  102. aiVector2D scale(1, 1);
  103. aiVector2D translation(0, 0);
  104. CX3DImporter_NodeElement* ne;
  105. MACRO_ATTRREAD_LOOPBEG;
  106. MACRO_ATTRREAD_CHECKUSEDEF_RET(def, use);
  107. MACRO_ATTRREAD_CHECK_REF("center", center, XML_ReadNode_GetAttrVal_AsVec2f);
  108. MACRO_ATTRREAD_CHECK_RET("rotation", rotation, XML_ReadNode_GetAttrVal_AsFloat);
  109. MACRO_ATTRREAD_CHECK_REF("scale", scale, XML_ReadNode_GetAttrVal_AsVec2f);
  110. MACRO_ATTRREAD_CHECK_REF("translation", translation, XML_ReadNode_GetAttrVal_AsVec2f);
  111. MACRO_ATTRREAD_LOOPEND;
  112. // if "USE" defined then find already defined element.
  113. if(!use.empty())
  114. {
  115. MACRO_USE_CHECKANDAPPLY(def, use, ENET_TextureTransform, ne);
  116. }
  117. else
  118. {
  119. // create and if needed - define new geometry object.
  120. ne = new CX3DImporter_NodeElement_TextureTransform(NodeElement_Cur);
  121. if(!def.empty()) ne->ID = def;
  122. ((CX3DImporter_NodeElement_TextureTransform*)ne)->Center = center;
  123. ((CX3DImporter_NodeElement_TextureTransform*)ne)->Rotation = rotation;
  124. ((CX3DImporter_NodeElement_TextureTransform*)ne)->Scale = scale;
  125. ((CX3DImporter_NodeElement_TextureTransform*)ne)->Translation = translation;
  126. // check for X3DMetadataObject childs.
  127. if(!mReader->isEmptyElement())
  128. ParseNode_Metadata(ne, "TextureTransform");
  129. else
  130. NodeElement_Cur->Child.push_back(ne);// add made object as child to current element
  131. NodeElement_List.push_back(ne);// add element to node element list because its a new object in graph
  132. }// if(!use.empty()) else
  133. }
  134. }// namespace Assimp
  135. #endif // !ASSIMP_BUILD_NO_X3D_IMPORTER