X3DImporter_Geometry2D.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469
  1. /*
  2. Open Asset Import Library (assimp)
  3. ----------------------------------------------------------------------
  4. Copyright (c) 2006-2025, 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_Geometry2D.cpp
  34. /// \brief Parsing data from nodes of "Geometry2D" 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. #include "X3DGeoHelper.h"
  42. namespace Assimp {
  43. // <Arc2D
  44. // DEF="" ID
  45. // USE="" IDREF
  46. // endAngle="1.570796" SFFloat [initializeOnly]
  47. // radius="1" SFFloat [initializeOnly]
  48. // startAngle="0" SFFloat [initializeOnly]
  49. // />
  50. // The Arc2D node specifies a linear circular arc whose center is at (0,0) and whose angles are measured starting at the positive x-axis and sweeping
  51. // towards the positive y-axis. The radius field specifies the radius of the circle of which the arc is a portion. The arc extends from the startAngle
  52. // counterclockwise to the endAngle. The values of startAngle and endAngle shall be in the range [-2pi, 2pi] radians (or the equivalent if a different
  53. // angle base unit has been specified). If startAngle and endAngle have the same value, a circle is specified.
  54. void X3DImporter::readArc2D(XmlNode &node) {
  55. std::string def, use;
  56. float endAngle = AI_MATH_HALF_PI_F;
  57. float radius = 1;
  58. float startAngle = 0;
  59. X3DNodeElementBase *ne(nullptr);
  60. MACRO_ATTRREAD_CHECKUSEDEF_RET(node, def, use);
  61. XmlParser::getFloatAttribute(node, "endAngle", endAngle);
  62. XmlParser::getFloatAttribute(node, "radius", radius);
  63. XmlParser::getFloatAttribute(node, "startAngle", startAngle);
  64. // if "USE" defined then find already defined element.
  65. if (!use.empty()) {
  66. ne = MACRO_USE_CHECKANDAPPLY(node, def, use, ENET_Arc2D, ne);
  67. } else {
  68. // create and if needed - define new geometry object.
  69. ne = new X3DNodeElementGeometry2D(X3DElemType::ENET_Arc2D, mNodeElementCur);
  70. if (!def.empty()) ne->ID = def;
  71. // create point list of geometry object and convert it to line set.
  72. std::list<aiVector3D> tlist;
  73. X3DGeoHelper::make_arc2D(startAngle, endAngle, radius, 10, tlist); ///TODO: IME - AI_CONFIG for NumSeg
  74. X3DGeoHelper::extend_point_to_line(tlist, ((X3DNodeElementGeometry2D *)ne)->Vertices);
  75. ((X3DNodeElementGeometry2D *)ne)->NumIndices = 2;
  76. // check for X3DMetadataObject childs.
  77. if (!isNodeEmpty(node))
  78. childrenReadMetadata(node, ne, "Arc2D");
  79. else
  80. mNodeElementCur->Children.push_back(ne); // add made object as child to current element
  81. NodeElement_List.push_back(ne); // add element to node element list because its a new object in graph
  82. } // if(!use.empty()) else
  83. }
  84. // <ArcClose2D
  85. // DEF="" ID
  86. // USE="" IDREF
  87. // closureType="PIE" SFString [initializeOnly], {"PIE", "CHORD"}
  88. // endAngle="1.570796" SFFloat [initializeOnly]
  89. // radius="1" SFFloat [initializeOnly]
  90. // solid="false" SFBool [initializeOnly]
  91. // startAngle="0" SFFloat [initializeOnly]
  92. // />
  93. // The ArcClose node specifies a portion of a circle whose center is at (0,0) and whose angles are measured starting at the positive x-axis and sweeping
  94. // towards the positive y-axis. The end points of the arc specified are connected as defined by the closureType field. The radius field specifies the radius
  95. // of the circle of which the arc is a portion. The arc extends from the startAngle counterclockwise to the endAngle. The value of radius shall be greater
  96. // than zero. The values of startAngle and endAngle shall be in the range [-2pi, 2pi] radians (or the equivalent if a different default angle base unit has
  97. // been specified). If startAngle and endAngle have the same value, a circle is specified and closureType is ignored. If the absolute difference between
  98. // startAngle and endAngle is greater than or equal to 2pi, a complete circle is produced with no chord or radial line(s) drawn from the center.
  99. // A closureType of "PIE" connects the end point to the start point by defining two straight line segments first from the end point to the center and then
  100. // the center to the start point. A closureType of "CHORD" connects the end point to the start point by defining a straight line segment from the end point
  101. // to the start point. Textures are applied individually to each face of the ArcClose2D. On the front (+Z) and back (-Z) faces of the ArcClose2D, when
  102. // viewed from the +Z-axis, the texture is mapped onto each face with the same orientation as if the image were displayed normally in 2D.
  103. void X3DImporter::readArcClose2D(XmlNode &node) {
  104. std::string def, use;
  105. std::string closureType("PIE");
  106. float endAngle = AI_MATH_HALF_PI_F;
  107. float radius = 1;
  108. bool solid = false;
  109. float startAngle = 0;
  110. X3DNodeElementBase *ne(nullptr);
  111. MACRO_ATTRREAD_CHECKUSEDEF_RET(node, def, use);
  112. XmlParser::getStdStrAttribute(node, "closureType", closureType);
  113. XmlParser::getFloatAttribute(node, "endAngle", endAngle);
  114. XmlParser::getFloatAttribute(node, "endAngle", endAngle);
  115. XmlParser::getFloatAttribute(node, "radius", radius);
  116. XmlParser::getBoolAttribute(node, "solid", solid);
  117. XmlParser::getFloatAttribute(node, "startAngle", startAngle);
  118. // if "USE" defined then find already defined element.
  119. if (!use.empty()) {
  120. ne = MACRO_USE_CHECKANDAPPLY(node, def, use, ENET_ArcClose2D, ne);
  121. } else {
  122. // create and if needed - define new geometry object.
  123. ne = new X3DNodeElementGeometry2D(X3DElemType::ENET_ArcClose2D, mNodeElementCur);
  124. if (!def.empty()) ne->ID = def;
  125. ((X3DNodeElementGeometry2D *)ne)->Solid = solid;
  126. // create point list of geometry object.
  127. X3DGeoHelper::make_arc2D(startAngle, endAngle, radius, 10, ((X3DNodeElementGeometry2D *)ne)->Vertices); ///TODO: IME - AI_CONFIG for NumSeg
  128. // add chord or two radiuses only if not a circle was defined
  129. if (!((std::fabs(endAngle - startAngle) >= AI_MATH_TWO_PI_F) || (endAngle == startAngle))) {
  130. std::list<aiVector3D> &vlist = ((X3DNodeElementGeometry2D *)ne)->Vertices; // just short alias.
  131. if ((closureType == "PIE") || (closureType == "\"PIE\""))
  132. vlist.emplace_back(static_cast<ai_real>(0), static_cast<ai_real>(0), static_cast<ai_real>(0)); // center point - first radial line
  133. else if ((closureType != "CHORD") && (closureType != "\"CHORD\""))
  134. Throw_IncorrectAttrValue("ArcClose2D", "closureType");
  135. vlist.push_back(*vlist.begin()); // arc first point - chord from first to last point of arc(if CHORD) or second radial line(if PIE).
  136. }
  137. ((X3DNodeElementGeometry2D *)ne)->NumIndices = ((X3DNodeElementGeometry2D *)ne)->Vertices.size();
  138. // check for X3DMetadataObject childs.
  139. if (!isNodeEmpty(node))
  140. childrenReadMetadata(node, ne, "ArcClose2D");
  141. else
  142. mNodeElementCur->Children.push_back(ne); // add made object as child to current element
  143. NodeElement_List.push_back(ne); // add element to node element list because its a new object in graph
  144. } // if(!use.empty()) else
  145. }
  146. // <Circle2D
  147. // DEF="" ID
  148. // USE="" IDREF
  149. // radius="1" SFFloat [initializeOnly]
  150. // />
  151. void X3DImporter::readCircle2D(XmlNode &node) {
  152. std::string def, use;
  153. float radius = 1;
  154. X3DNodeElementBase *ne(nullptr);
  155. MACRO_ATTRREAD_CHECKUSEDEF_RET(node, def, use);
  156. XmlParser::getFloatAttribute(node, "radius", radius);
  157. // if "USE" defined then find already defined element.
  158. if (!use.empty()) {
  159. ne = MACRO_USE_CHECKANDAPPLY(node, def, use, ENET_Circle2D, ne);
  160. } else {
  161. // create and if needed - define new geometry object.
  162. ne = new X3DNodeElementGeometry2D(X3DElemType::ENET_Circle2D, mNodeElementCur);
  163. if (!def.empty()) ne->ID = def;
  164. // create point list of geometry object and convert it to line set.
  165. std::list<aiVector3D> tlist;
  166. X3DGeoHelper::make_arc2D(0, 0, radius, 10, tlist); ///TODO: IME - AI_CONFIG for NumSeg
  167. X3DGeoHelper::extend_point_to_line(tlist, ((X3DNodeElementGeometry2D *)ne)->Vertices);
  168. ((X3DNodeElementGeometry2D *)ne)->NumIndices = 2;
  169. // check for X3DMetadataObject childs.
  170. if (!isNodeEmpty(node))
  171. childrenReadMetadata(node, ne, "Circle2D");
  172. else
  173. mNodeElementCur->Children.push_back(ne); // add made object as child to current element
  174. NodeElement_List.push_back(ne); // add element to node element list because its a new object in graph
  175. } // if(!use.empty()) else
  176. }
  177. // <Disk2D
  178. // DEF="" ID
  179. // USE="" IDREF
  180. // innerRadius="0" SFFloat [initializeOnly]
  181. // outerRadius="1" SFFloat [initializeOnly]
  182. // solid="false" SFBool [initializeOnly]
  183. // />
  184. // The Disk2D node specifies a circular disk which is centred at (0, 0) in the local coordinate system. The outerRadius field specifies the radius of the
  185. // outer dimension of the Disk2D. The innerRadius field specifies the inner dimension of the Disk2D. The value of outerRadius shall be greater than zero.
  186. // The value of innerRadius shall be greater than or equal to zero and less than or equal to outerRadius. If innerRadius is zero, the Disk2D is completely
  187. // filled. Otherwise, the area within the innerRadius forms a hole in the Disk2D. If innerRadius is equal to outerRadius, a solid circular line shall
  188. // be drawn using the current line properties. Textures are applied individually to each face of the Disk2D. On the front (+Z) and back (-Z) faces of
  189. // the Disk2D, when viewed from the +Z-axis, the texture is mapped onto each face with the same orientation as if the image were displayed normally in 2D.
  190. void X3DImporter::readDisk2D(XmlNode &node) {
  191. std::string def, use;
  192. float innerRadius = 0;
  193. float outerRadius = 1;
  194. bool solid = false;
  195. X3DNodeElementBase *ne(nullptr);
  196. MACRO_ATTRREAD_CHECKUSEDEF_RET(node, def, use);
  197. XmlParser::getFloatAttribute(node, "innerRadius", innerRadius);
  198. XmlParser::getFloatAttribute(node, "outerRadius", outerRadius);
  199. XmlParser::getBoolAttribute(node, "solid", solid);
  200. // if "USE" defined then find already defined element.
  201. if (!use.empty()) {
  202. ne = MACRO_USE_CHECKANDAPPLY(node, def, use, ENET_Disk2D, ne);
  203. } else {
  204. std::list<aiVector3D> tlist_o, tlist_i;
  205. if (innerRadius > outerRadius) Throw_IncorrectAttrValue("Disk2D", "innerRadius");
  206. // create and if needed - define new geometry object.
  207. ne = new X3DNodeElementGeometry2D(X3DElemType::ENET_Disk2D, mNodeElementCur);
  208. if (!def.empty()) ne->ID = def;
  209. // create point list of geometry object.
  210. ///TODO: IME - AI_CONFIG for NumSeg
  211. X3DGeoHelper::make_arc2D(0, 0, outerRadius, 10, tlist_o); // outer circle
  212. if (innerRadius == 0.0f) { // make filled disk
  213. // in tlist_o we already have points of circle. just copy it and sign as polygon.
  214. ((X3DNodeElementGeometry2D *)ne)->Vertices = tlist_o;
  215. ((X3DNodeElementGeometry2D *)ne)->NumIndices = tlist_o.size();
  216. } else if (innerRadius == outerRadius) { // make circle
  217. // in tlist_o we already have points of circle. convert it to line set.
  218. X3DGeoHelper::extend_point_to_line(tlist_o, ((X3DNodeElementGeometry2D *)ne)->Vertices);
  219. ((X3DNodeElementGeometry2D *)ne)->NumIndices = 2;
  220. } else { // make disk
  221. std::list<aiVector3D> &vlist = ((X3DNodeElementGeometry2D *)ne)->Vertices; // just short alias.
  222. X3DGeoHelper::make_arc2D(0, 0, innerRadius, 10, tlist_i); // inner circle
  223. //
  224. // create quad list from two point lists
  225. //
  226. if (tlist_i.size() < 2) {
  227. // tlist_i and tlist_o has equal size.
  228. throw DeadlyImportError("Disk2D. Not enough points for creating quad list.");
  229. }
  230. // add all quads except last
  231. for (std::list<aiVector3D>::iterator it_i = tlist_i.begin(), it_o = tlist_o.begin(); it_i != tlist_i.end();) {
  232. // do not forget - CCW direction
  233. vlist.emplace_back(*it_i++); // 1st point
  234. vlist.emplace_back(*it_o++); // 2nd point
  235. vlist.emplace_back(*it_o); // 3rd point
  236. vlist.emplace_back(*it_i); // 4th point
  237. }
  238. // add last quad
  239. vlist.emplace_back(tlist_i.back()); // 1st point
  240. vlist.emplace_back(tlist_o.back()); // 2nd point
  241. vlist.emplace_back(tlist_o.front()); // 3rd point
  242. vlist.emplace_back(tlist_i.front()); // 4th point
  243. ((X3DNodeElementGeometry2D *)ne)->NumIndices = 4;
  244. }
  245. ((X3DNodeElementGeometry2D *)ne)->Solid = solid;
  246. // check for X3DMetadataObject childs.
  247. if (!isNodeEmpty(node))
  248. childrenReadMetadata(node, ne, "Disk2D");
  249. else
  250. mNodeElementCur->Children.push_back(ne); // add made object as child to current element
  251. NodeElement_List.push_back(ne); // add element to node element list because its a new object in graph
  252. } // if(!use.empty()) else
  253. }
  254. // <Polyline2D
  255. // DEF="" ID
  256. // USE="" IDREF
  257. // lineSegments="" MFVec2F [intializeOnly]
  258. // />
  259. void X3DImporter::readPolyline2D(XmlNode &node) {
  260. std::string def, use;
  261. std::list<aiVector2D> lineSegments;
  262. X3DNodeElementBase *ne(nullptr);
  263. MACRO_ATTRREAD_CHECKUSEDEF_RET(node, def, use);
  264. X3DXmlHelper::getVector2DListAttribute(node, "lineSegments", lineSegments);
  265. // if "USE" defined then find already defined element.
  266. if (!use.empty()) {
  267. ne = MACRO_USE_CHECKANDAPPLY(node, def, use, ENET_Polyline2D, ne);
  268. } else {
  269. // create and if needed - define new geometry object.
  270. ne = new X3DNodeElementGeometry2D(X3DElemType::ENET_Polyline2D, mNodeElementCur);
  271. if (!def.empty()) ne->ID = def;
  272. //
  273. // convert read point list of geometry object to line set.
  274. //
  275. std::list<aiVector3D> tlist;
  276. // convert vec2 to vec3
  277. for (std::list<aiVector2D>::iterator it2 = lineSegments.begin(); it2 != lineSegments.end(); ++it2)
  278. tlist.emplace_back(it2->x, it2->y, static_cast<ai_real>(0));
  279. // convert point set to line set
  280. X3DGeoHelper::extend_point_to_line(tlist, ((X3DNodeElementGeometry2D *)ne)->Vertices);
  281. ((X3DNodeElementGeometry2D *)ne)->NumIndices = 2;
  282. // check for X3DMetadataObject childs.
  283. if (!isNodeEmpty(node))
  284. childrenReadMetadata(node, ne, "Polyline2D");
  285. else
  286. mNodeElementCur->Children.push_back(ne); // add made object as child to current element
  287. NodeElement_List.push_back(ne); // add element to node element list because its a new object in graph
  288. } // if(!use.empty()) else
  289. }
  290. // <Polypoint2D
  291. // DEF="" ID
  292. // USE="" IDREF
  293. // point="" MFVec2F [inputOutput]
  294. // />
  295. void X3DImporter::readPolypoint2D(XmlNode &node) {
  296. std::string def, use;
  297. std::list<aiVector2D> point;
  298. X3DNodeElementBase *ne(nullptr);
  299. MACRO_ATTRREAD_CHECKUSEDEF_RET(node, def, use);
  300. X3DXmlHelper::getVector2DListAttribute(node, "point", point);
  301. // if "USE" defined then find already defined element.
  302. if (!use.empty()) {
  303. ne = MACRO_USE_CHECKANDAPPLY(node, def, use, ENET_Polypoint2D, ne);
  304. } else {
  305. // create and if needed - define new geometry object.
  306. ne = new X3DNodeElementGeometry2D(X3DElemType::ENET_Polypoint2D, mNodeElementCur);
  307. if (!def.empty()) ne->ID = def;
  308. // convert vec2 to vec3
  309. for (std::list<aiVector2D>::iterator it2 = point.begin(); it2 != point.end(); ++it2) {
  310. ((X3DNodeElementGeometry2D *)ne)->Vertices.emplace_back(it2->x, it2->y, static_cast<ai_real>(0));
  311. }
  312. ((X3DNodeElementGeometry2D *)ne)->NumIndices = 1;
  313. // check for X3DMetadataObject childs.
  314. if (!isNodeEmpty(node))
  315. childrenReadMetadata(node, ne, "Polypoint2D");
  316. else
  317. mNodeElementCur->Children.push_back(ne); // add made object as child to current element
  318. NodeElement_List.push_back(ne); // add element to node element list because its a new object in graph
  319. } // if(!use.empty()) else
  320. }
  321. // <Rectangle2D
  322. // DEF="" ID
  323. // USE="" IDREF
  324. // size="2 2" SFVec2f [initializeOnly]
  325. // solid="false" SFBool [initializeOnly]
  326. // />
  327. void X3DImporter::readRectangle2D(XmlNode &node) {
  328. std::string def, use;
  329. aiVector2D size(2, 2);
  330. bool solid = false;
  331. X3DNodeElementBase *ne(nullptr);
  332. MACRO_ATTRREAD_CHECKUSEDEF_RET(node, def, use);
  333. X3DXmlHelper::getVector2DAttribute(node, "size", size);
  334. XmlParser::getBoolAttribute(node, "solid", solid);
  335. // if "USE" defined then find already defined element.
  336. if (!use.empty()) {
  337. ne = MACRO_USE_CHECKANDAPPLY(node, def, use, ENET_Rectangle2D, ne);
  338. } else {
  339. // create and if needed - define new geometry object.
  340. ne = new X3DNodeElementGeometry2D(X3DElemType::ENET_Rectangle2D, mNodeElementCur);
  341. if (!def.empty()) ne->ID = def;
  342. float x1 = -size.x / 2.0f;
  343. float x2 = size.x / 2.0f;
  344. float y1 = -size.y / 2.0f;
  345. float y2 = size.y / 2.0f;
  346. std::list<aiVector3D> &vlist = ((X3DNodeElementGeometry2D *)ne)->Vertices; // just short alias.
  347. vlist.emplace_back(x2, y1, static_cast<ai_real>(0)); // 1st point
  348. vlist.emplace_back(x2, y2, static_cast<ai_real>(0)); // 2nd point
  349. vlist.emplace_back(x1, y2, static_cast<ai_real>(0)); // 3rd point
  350. vlist.emplace_back(x1, y1, static_cast<ai_real>(0)); // 4th point
  351. ((X3DNodeElementGeometry2D *)ne)->Solid = solid;
  352. ((X3DNodeElementGeometry2D *)ne)->NumIndices = 4;
  353. // check for X3DMetadataObject childs.
  354. if (!isNodeEmpty(node))
  355. childrenReadMetadata(node, ne, "Rectangle2D");
  356. else
  357. mNodeElementCur->Children.push_back(ne); // add made object as child to current element
  358. NodeElement_List.push_back(ne); // add element to node element list because its a new object in graph
  359. } // if(!use.empty()) else
  360. }
  361. // <TriangleSet2D
  362. // DEF="" ID
  363. // USE="" IDREF
  364. // solid="false" SFBool [initializeOnly]
  365. // vertices="" MFVec2F [inputOutput]
  366. // />
  367. void X3DImporter::readTriangleSet2D(XmlNode &node) {
  368. std::string def, use;
  369. bool solid = false;
  370. std::list<aiVector2D> vertices;
  371. X3DNodeElementBase *ne(nullptr);
  372. MACRO_ATTRREAD_CHECKUSEDEF_RET(node, def, use);
  373. X3DXmlHelper::getVector2DListAttribute(node, "vertices", vertices);
  374. XmlParser::getBoolAttribute(node, "solid", solid);
  375. // if "USE" defined then find already defined element.
  376. if (!use.empty()) {
  377. ne = MACRO_USE_CHECKANDAPPLY(node, def, use, ENET_TriangleSet2D, ne);
  378. } else {
  379. if (vertices.size() % 3) throw DeadlyImportError("TriangleSet2D. Not enough points for defining triangle.");
  380. // create and if needed - define new geometry object.
  381. ne = new X3DNodeElementGeometry2D(X3DElemType::ENET_TriangleSet2D, mNodeElementCur);
  382. if (!def.empty()) ne->ID = def;
  383. // convert vec2 to vec3
  384. for (std::list<aiVector2D>::iterator it2 = vertices.begin(); it2 != vertices.end(); ++it2) {
  385. ((X3DNodeElementGeometry2D *)ne)->Vertices.emplace_back(it2->x, it2->y, static_cast<ai_real>(0));
  386. }
  387. ((X3DNodeElementGeometry2D *)ne)->Solid = solid;
  388. ((X3DNodeElementGeometry2D *)ne)->NumIndices = 3;
  389. // check for X3DMetadataObject childs.
  390. if (!isNodeEmpty(node))
  391. childrenReadMetadata(node, ne, "TriangleSet2D");
  392. else
  393. mNodeElementCur->Children.push_back(ne); // add made object as child to current element
  394. NodeElement_List.push_back(ne); // add element to node element list because its a new object in graph
  395. } // if(!use.empty()) else
  396. }
  397. } // namespace Assimp
  398. #endif // !ASSIMP_BUILD_NO_X3D_IMPORTER