X3DImporter_Networking.cpp 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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_Networking.cpp
  34. /// \brief Parsing data from nodes of "Networking" 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. // Header files, Assimp.
  41. #include <assimp/DefaultIOSystem.h>
  42. //#include <regex>
  43. namespace Assimp
  44. {
  45. //static std::regex pattern_parentDir(R"((^|/)[^/]+/../)");
  46. static std::string parentDir("/../");
  47. // <Inline
  48. // DEF="" ID
  49. // USE="" IDREF
  50. // bboxCenter="0 0 0" SFVec3f [initializeOnly]
  51. // bboxSize="-1 -1 -1" SFVec3f [initializeOnly]
  52. // load="true" SFBool [inputOutput]
  53. // url="" MFString [inputOutput]
  54. // />
  55. void X3DImporter::ParseNode_Networking_Inline()
  56. {
  57. std::string def, use;
  58. bool load = true;
  59. std::list<std::string> url;
  60. MACRO_ATTRREAD_LOOPBEG;
  61. MACRO_ATTRREAD_CHECKUSEDEF_RET(def, use);
  62. MACRO_ATTRREAD_CHECK_RET("load", load, XML_ReadNode_GetAttrVal_AsBool);
  63. MACRO_ATTRREAD_CHECK_REF("url", url, XML_ReadNode_GetAttrVal_AsListS);
  64. MACRO_ATTRREAD_LOOPEND;
  65. // if "USE" defined then find already defined element.
  66. if(!use.empty())
  67. {
  68. CX3DImporter_NodeElement* ne;
  69. MACRO_USE_CHECKANDAPPLY(def, use, ENET_Group, ne);
  70. }
  71. else
  72. {
  73. ParseHelper_Group_Begin(true);// create new grouping element and go deeper if node has children.
  74. // at this place new group mode created and made current, so we can name it.
  75. if(!def.empty()) NodeElement_Cur->ID = def;
  76. if(load && !url.empty())
  77. {
  78. std::string full_path = mpIOHandler->CurrentDirectory() + url.front();
  79. //full_path = std::regex_replace(full_path, pattern_parentDir, "$1");
  80. for (std::string::size_type pos = full_path.find(parentDir); pos != std::string::npos; pos = full_path.find(parentDir, pos)) {
  81. if (pos > 0) {
  82. std::string::size_type pos2 = full_path.rfind('/', pos - 1);
  83. if (pos2 != std::string::npos) {
  84. full_path.erase(pos2, pos - pos2 + 3);
  85. pos = pos2;
  86. }
  87. else {
  88. full_path.erase(0, pos + 4);
  89. pos = 0;
  90. }
  91. }
  92. else {
  93. pos += 3;
  94. }
  95. }
  96. // Attribute "url" can contain list of strings. But we need only one - first.
  97. std::string::size_type slashPos = full_path.find_last_of("\\/");
  98. mpIOHandler->PushDirectory(slashPos == std::string::npos ? std::string() : full_path.substr(0, slashPos + 1));
  99. ParseFile(full_path, mpIOHandler);
  100. mpIOHandler->PopDirectory();
  101. }
  102. // check for X3DMetadataObject childs.
  103. if(!mReader->isEmptyElement()) ParseNode_Metadata(NodeElement_Cur, "Inline");
  104. // exit from node in that place
  105. ParseHelper_Node_Exit();
  106. }// if(!use.empty()) else
  107. }
  108. }// namespace Assimp
  109. #endif // !ASSIMP_BUILD_NO_X3D_IMPORTER