line_builder.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594
  1. /**************************************************************************/
  2. /* line_builder.cpp */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. #include "line_builder.h"
  31. #include "core/math/geometry_2d.h"
  32. // Utility method.
  33. static inline Vector2 interpolate(const Rect2 &r, const Vector2 &v) {
  34. return Vector2(
  35. Math::lerp(r.position.x, r.position.x + r.get_size().x, v.x),
  36. Math::lerp(r.position.y, r.position.y + r.get_size().y, v.y));
  37. }
  38. LineBuilder::LineBuilder() {
  39. }
  40. void LineBuilder::build() {
  41. // Need at least 2 points to draw a line, so clear the output and return.
  42. if (points.size() < 2) {
  43. vertices.clear();
  44. colors.clear();
  45. indices.clear();
  46. uvs.clear();
  47. return;
  48. }
  49. ERR_FAIL_COND(tile_aspect <= 0.f);
  50. const float hw = width / 2.f;
  51. const float hw_sq = hw * hw;
  52. const float sharp_limit_sq = sharp_limit * sharp_limit;
  53. const int point_count = points.size();
  54. const bool wrap_around = closed && point_count > 2;
  55. _interpolate_color = gradient != nullptr;
  56. const bool retrieve_curve = curve != nullptr;
  57. const bool distance_required = _interpolate_color || retrieve_curve ||
  58. texture_mode == Line2D::LINE_TEXTURE_TILE ||
  59. texture_mode == Line2D::LINE_TEXTURE_STRETCH;
  60. // Initial values
  61. Vector2 pos0 = points[0];
  62. Vector2 pos1 = points[1];
  63. Vector2 f0 = (pos1 - pos0).normalized();
  64. Vector2 u0 = f0.orthogonal();
  65. Vector2 pos_up0 = pos0;
  66. Vector2 pos_down0 = pos0;
  67. Color color0;
  68. Color color1;
  69. float current_distance0 = 0.f;
  70. float current_distance1 = 0.f;
  71. float total_distance = 0.f;
  72. float width_factor = 1.f;
  73. float modified_hw = hw;
  74. if (retrieve_curve) {
  75. width_factor = curve->sample_baked(0.f);
  76. modified_hw = hw * width_factor;
  77. }
  78. if (distance_required) {
  79. // Calculate the total distance.
  80. for (int i = 1; i < point_count; ++i) {
  81. total_distance += points[i].distance_to(points[i - 1]);
  82. }
  83. if (wrap_around) {
  84. total_distance += points[point_count - 1].distance_to(pos0);
  85. } else {
  86. // Adjust the total distance.
  87. // The line's outer length may be a little higher due to the end caps.
  88. if (begin_cap_mode == Line2D::LINE_CAP_BOX || begin_cap_mode == Line2D::LINE_CAP_ROUND) {
  89. total_distance += modified_hw;
  90. }
  91. if (end_cap_mode == Line2D::LINE_CAP_BOX || end_cap_mode == Line2D::LINE_CAP_ROUND) {
  92. if (retrieve_curve) {
  93. total_distance += hw * curve->sample_baked(1.f);
  94. } else {
  95. total_distance += hw;
  96. }
  97. }
  98. }
  99. }
  100. if (_interpolate_color) {
  101. color0 = gradient->get_color(0);
  102. } else {
  103. colors.push_back(default_color);
  104. }
  105. float uvx0 = 0.f;
  106. float uvx1 = 0.f;
  107. pos_up0 += u0 * modified_hw;
  108. pos_down0 -= u0 * modified_hw;
  109. // Begin cap
  110. if (!wrap_around) {
  111. if (begin_cap_mode == Line2D::LINE_CAP_BOX) {
  112. // Push back first vertices a little bit.
  113. pos_up0 -= f0 * modified_hw;
  114. pos_down0 -= f0 * modified_hw;
  115. current_distance0 += modified_hw;
  116. current_distance1 = current_distance0;
  117. } else if (begin_cap_mode == Line2D::LINE_CAP_ROUND) {
  118. if (texture_mode == Line2D::LINE_TEXTURE_TILE) {
  119. uvx0 = width_factor * 0.5f / tile_aspect;
  120. } else if (texture_mode == Line2D::LINE_TEXTURE_STRETCH) {
  121. uvx0 = width * width_factor / total_distance;
  122. }
  123. new_arc(pos0, pos_up0 - pos0, -Math_PI, color0, Rect2(0.f, 0.f, uvx0 * 2, 1.f));
  124. current_distance0 += modified_hw;
  125. current_distance1 = current_distance0;
  126. }
  127. strip_begin(pos_up0, pos_down0, color0, uvx0);
  128. }
  129. /*
  130. * pos_up0 ------------- pos_up1 --------------------
  131. * | |
  132. * pos0 - - - - - - - - - pos1 - - - - - - - - - pos2
  133. * | |
  134. * pos_down0 ------------ pos_down1 ------------------
  135. *
  136. * i-1 i i+1
  137. */
  138. // http://labs.hyperandroid.com/tag/opengl-lines
  139. // (not the same implementation but visuals help a lot)
  140. // If the polyline wraps around, then draw two more segments with joints:
  141. // The last one, which should normally end with an end cap, and the one that matches the end and the beginning.
  142. int segments_count = wrap_around ? point_count : (point_count - 2);
  143. // The wraparound case starts with a "fake walk" from the end of the polyline
  144. // to its beginning, so that its first joint is correct, without drawing anything.
  145. int first_point = wrap_around ? -1 : 1;
  146. // If the line wraps around, these variables will be used for the final segment.
  147. Vector2 first_pos_up, first_pos_down;
  148. bool is_first_joint_sharp = false;
  149. // For each additional segment
  150. for (int i = first_point; i <= segments_count; ++i) {
  151. pos1 = points[(i == -1) ? point_count - 1 : i % point_count]; // First point.
  152. Vector2 pos2 = points[(i + 1) % point_count]; // Second point.
  153. Vector2 f1 = (pos2 - pos1).normalized();
  154. Vector2 u1 = f1.orthogonal();
  155. // Determine joint orientation.
  156. float dp = u0.dot(f1);
  157. const Orientation orientation = (dp > 0.f ? UP : DOWN);
  158. if (distance_required && i >= 1) {
  159. current_distance1 += pos0.distance_to(pos1);
  160. }
  161. if (_interpolate_color) {
  162. color1 = gradient->get_color_at_offset(current_distance1 / total_distance);
  163. }
  164. if (retrieve_curve) {
  165. width_factor = curve->sample_baked(current_distance1 / total_distance);
  166. modified_hw = hw * width_factor;
  167. }
  168. Vector2 inner_normal0 = u0 * modified_hw;
  169. Vector2 inner_normal1 = u1 * modified_hw;
  170. if (orientation == DOWN) {
  171. inner_normal0 = -inner_normal0;
  172. inner_normal1 = -inner_normal1;
  173. }
  174. /*
  175. * ---------------------------
  176. * /
  177. * 0 / 1
  178. * / /
  179. * --------------------x------ /
  180. * / / (here shown with orientation == DOWN)
  181. * / /
  182. * / /
  183. * / /
  184. * 2 /
  185. * /
  186. */
  187. // Find inner intersection at the joint.
  188. Vector2 corner_pos_in, corner_pos_out;
  189. bool is_intersecting = Geometry2D::segment_intersects_segment(
  190. pos0 + inner_normal0, pos1 + inner_normal0,
  191. pos1 + inner_normal1, pos2 + inner_normal1,
  192. &corner_pos_in);
  193. if (is_intersecting) {
  194. // Inner parts of the segments intersect.
  195. corner_pos_out = 2.f * pos1 - corner_pos_in;
  196. } else {
  197. // No intersection, segments are too sharp or they overlap.
  198. corner_pos_in = pos1 + inner_normal0;
  199. corner_pos_out = pos1 - inner_normal0;
  200. }
  201. Vector2 corner_pos_up, corner_pos_down;
  202. if (orientation == UP) {
  203. corner_pos_up = corner_pos_in;
  204. corner_pos_down = corner_pos_out;
  205. } else {
  206. corner_pos_up = corner_pos_out;
  207. corner_pos_down = corner_pos_in;
  208. }
  209. Line2D::LineJointMode current_joint_mode = joint_mode;
  210. Vector2 pos_up1, pos_down1;
  211. if (is_intersecting) {
  212. // Fallback on bevel if sharp angle is too high (because it would produce very long miters).
  213. float width_factor_sq = width_factor * width_factor;
  214. if (current_joint_mode == Line2D::LINE_JOINT_SHARP && corner_pos_out.distance_squared_to(pos1) / (hw_sq * width_factor_sq) > sharp_limit_sq) {
  215. current_joint_mode = Line2D::LINE_JOINT_BEVEL;
  216. }
  217. if (current_joint_mode == Line2D::LINE_JOINT_SHARP) {
  218. // In this case, we won't create joint geometry,
  219. // The previous and next line quads will directly share an edge.
  220. pos_up1 = corner_pos_up;
  221. pos_down1 = corner_pos_down;
  222. } else {
  223. // Bevel or round
  224. if (orientation == UP) {
  225. pos_up1 = corner_pos_up;
  226. pos_down1 = pos1 - u0 * modified_hw;
  227. } else {
  228. pos_up1 = pos1 + u0 * modified_hw;
  229. pos_down1 = corner_pos_down;
  230. }
  231. }
  232. } else {
  233. // No intersection: fallback
  234. if (current_joint_mode == Line2D::LINE_JOINT_SHARP) {
  235. // There is no fallback implementation for LINE_JOINT_SHARP so switch to the LINE_JOINT_BEVEL.
  236. current_joint_mode = Line2D::LINE_JOINT_BEVEL;
  237. }
  238. pos_up1 = corner_pos_up;
  239. pos_down1 = corner_pos_down;
  240. }
  241. // Triangles are clockwise.
  242. if (texture_mode == Line2D::LINE_TEXTURE_TILE) {
  243. uvx1 = current_distance1 / (width * tile_aspect);
  244. } else if (texture_mode == Line2D::LINE_TEXTURE_STRETCH) {
  245. uvx1 = current_distance1 / total_distance;
  246. }
  247. // Swap vars for use in the next line.
  248. color0 = color1;
  249. u0 = u1;
  250. f0 = f1;
  251. pos0 = pos1;
  252. if (is_intersecting) {
  253. if (current_joint_mode == Line2D::LINE_JOINT_SHARP) {
  254. pos_up0 = pos_up1;
  255. pos_down0 = pos_down1;
  256. } else {
  257. if (orientation == UP) {
  258. pos_up0 = corner_pos_up;
  259. pos_down0 = pos1 - u1 * modified_hw;
  260. } else {
  261. pos_up0 = pos1 + u1 * modified_hw;
  262. pos_down0 = corner_pos_down;
  263. }
  264. }
  265. } else {
  266. pos_up0 = pos1 + u1 * modified_hw;
  267. pos_down0 = pos1 - u1 * modified_hw;
  268. }
  269. // End the "fake pass" in the closed line case before the drawing subroutine.
  270. if (i == -1) {
  271. continue;
  272. }
  273. // For wrap-around polylines, store some kind of start positions of the first joint for the final connection.
  274. if (wrap_around && i == 0) {
  275. Vector2 first_pos_center = (pos_up1 + pos_down1) / 2;
  276. float lerp_factor = 1.0 / width_factor;
  277. first_pos_up = first_pos_center.lerp(pos_up1, lerp_factor);
  278. first_pos_down = first_pos_center.lerp(pos_down1, lerp_factor);
  279. is_first_joint_sharp = current_joint_mode == Line2D::LINE_JOINT_SHARP;
  280. }
  281. // Add current line body quad.
  282. if (wrap_around && retrieve_curve && !is_first_joint_sharp && i == segments_count) {
  283. // If the width curve is not seamless, we might need to fetch the line's start points to use them for the final connection.
  284. Vector2 first_pos_center = (first_pos_up + first_pos_down) / 2;
  285. strip_add_quad(first_pos_center.lerp(first_pos_up, width_factor), first_pos_center.lerp(first_pos_down, width_factor), color1, uvx1);
  286. return;
  287. } else {
  288. strip_add_quad(pos_up1, pos_down1, color1, uvx1);
  289. }
  290. // From this point, bu0 and bd0 concern the next segment.
  291. // Add joint geometry.
  292. if (current_joint_mode != Line2D::LINE_JOINT_SHARP) {
  293. /* ________________ cbegin
  294. * / \
  295. * / \
  296. * ____________/_ _ _\ cend
  297. * | |
  298. * | |
  299. * | |
  300. */
  301. Vector2 cbegin, cend;
  302. if (orientation == UP) {
  303. cbegin = pos_down1;
  304. cend = pos_down0;
  305. } else {
  306. cbegin = pos_up1;
  307. cend = pos_up0;
  308. }
  309. if (current_joint_mode == Line2D::LINE_JOINT_BEVEL && !(wrap_around && i == segments_count)) {
  310. strip_add_tri(cend, orientation);
  311. } else if (current_joint_mode == Line2D::LINE_JOINT_ROUND && !(wrap_around && i == segments_count)) {
  312. Vector2 vbegin = cbegin - pos1;
  313. Vector2 vend = cend - pos1;
  314. // We want to use vbegin.angle_to(vend) below, which evaluates to
  315. // Math::atan2(vbegin.cross(vend), vbegin.dot(vend)) but we need to
  316. // calculate this ourselves as we need to check if the cross product
  317. // in that calculation ends up being -0.f and flip it if so, effectively
  318. // flipping the resulting angle_delta to not return -PI but +PI instead
  319. float cross_product = vbegin.cross(vend);
  320. float dot_product = vbegin.dot(vend);
  321. // Note that we're comparing against -0.f for clarity but 0.f would
  322. // match as well, therefore we need the explicit signbit check too.
  323. if (cross_product == -0.f && signbit(cross_product)) {
  324. cross_product = 0.f;
  325. }
  326. float angle_delta = Math::atan2(cross_product, dot_product);
  327. strip_add_arc(pos1, angle_delta, orientation);
  328. }
  329. if (!is_intersecting) {
  330. // In this case the joint is too corrupted to be re-used,
  331. // start again the strip with fallback points
  332. strip_begin(pos_up0, pos_down0, color1, uvx1);
  333. }
  334. }
  335. }
  336. // Draw the last (or only) segment, with its end cap logic.
  337. if (!wrap_around) {
  338. pos1 = points[point_count - 1];
  339. if (distance_required) {
  340. current_distance1 += pos0.distance_to(pos1);
  341. }
  342. if (_interpolate_color) {
  343. color1 = gradient->get_color(gradient->get_point_count() - 1);
  344. }
  345. if (retrieve_curve) {
  346. width_factor = curve->sample_baked(1.f);
  347. modified_hw = hw * width_factor;
  348. }
  349. Vector2 pos_up1 = pos1 + u0 * modified_hw;
  350. Vector2 pos_down1 = pos1 - u0 * modified_hw;
  351. // Add extra distance for a box end cap.
  352. if (end_cap_mode == Line2D::LINE_CAP_BOX) {
  353. pos_up1 += f0 * modified_hw;
  354. pos_down1 += f0 * modified_hw;
  355. current_distance1 += modified_hw;
  356. }
  357. if (texture_mode == Line2D::LINE_TEXTURE_TILE) {
  358. uvx1 = current_distance1 / (width * tile_aspect);
  359. } else if (texture_mode == Line2D::LINE_TEXTURE_STRETCH) {
  360. uvx1 = current_distance1 / total_distance;
  361. }
  362. strip_add_quad(pos_up1, pos_down1, color1, uvx1);
  363. // Custom drawing for a round end cap.
  364. if (end_cap_mode == Line2D::LINE_CAP_ROUND) {
  365. // Note: color is not used in case we don't interpolate.
  366. Color color = _interpolate_color ? gradient->get_color(gradient->get_point_count() - 1) : Color(0, 0, 0);
  367. float dist = 0;
  368. if (texture_mode == Line2D::LINE_TEXTURE_TILE) {
  369. dist = width_factor / tile_aspect;
  370. } else if (texture_mode == Line2D::LINE_TEXTURE_STRETCH) {
  371. dist = width * width_factor / total_distance;
  372. }
  373. new_arc(pos1, pos_up1 - pos1, Math_PI, color, Rect2(uvx1 - 0.5f * dist, 0.f, dist, 1.f));
  374. }
  375. }
  376. }
  377. void LineBuilder::strip_begin(Vector2 up, Vector2 down, Color color, float uvx) {
  378. int vi = vertices.size();
  379. vertices.push_back(up);
  380. vertices.push_back(down);
  381. if (_interpolate_color) {
  382. colors.push_back(color);
  383. colors.push_back(color);
  384. }
  385. if (texture_mode != Line2D::LINE_TEXTURE_NONE) {
  386. uvs.push_back(Vector2(uvx, 0.f));
  387. uvs.push_back(Vector2(uvx, 1.f));
  388. }
  389. _last_index[UP] = vi;
  390. _last_index[DOWN] = vi + 1;
  391. }
  392. void LineBuilder::strip_add_quad(Vector2 up, Vector2 down, Color color, float uvx) {
  393. int vi = vertices.size();
  394. vertices.push_back(up);
  395. vertices.push_back(down);
  396. if (_interpolate_color) {
  397. colors.push_back(color);
  398. colors.push_back(color);
  399. }
  400. if (texture_mode != Line2D::LINE_TEXTURE_NONE) {
  401. uvs.push_back(Vector2(uvx, 0.f));
  402. uvs.push_back(Vector2(uvx, 1.f));
  403. }
  404. indices.push_back(_last_index[UP]);
  405. indices.push_back(vi + 1);
  406. indices.push_back(_last_index[DOWN]);
  407. indices.push_back(_last_index[UP]);
  408. indices.push_back(vi);
  409. indices.push_back(vi + 1);
  410. _last_index[UP] = vi;
  411. _last_index[DOWN] = vi + 1;
  412. }
  413. void LineBuilder::strip_add_tri(Vector2 up, Orientation orientation) {
  414. int vi = vertices.size();
  415. vertices.push_back(up);
  416. if (_interpolate_color) {
  417. colors.push_back(colors[colors.size() - 1]);
  418. }
  419. Orientation opposite_orientation = orientation == UP ? DOWN : UP;
  420. if (texture_mode != Line2D::LINE_TEXTURE_NONE) {
  421. // UVs are just one slice of the texture all along
  422. // (otherwise we can't share the bottom vertex)
  423. uvs.push_back(uvs[_last_index[opposite_orientation]]);
  424. }
  425. indices.push_back(_last_index[opposite_orientation]);
  426. indices.push_back(vi);
  427. indices.push_back(_last_index[orientation]);
  428. _last_index[opposite_orientation] = vi;
  429. }
  430. void LineBuilder::strip_add_arc(Vector2 center, float angle_delta, Orientation orientation) {
  431. // Take the two last vertices and extrude an arc made of triangles
  432. // that all share one of the initial vertices
  433. Orientation opposite_orientation = orientation == UP ? DOWN : UP;
  434. Vector2 vbegin = vertices[_last_index[opposite_orientation]] - center;
  435. float radius = vbegin.length();
  436. float angle_step = Math_PI / static_cast<float>(round_precision);
  437. float steps = Math::abs(angle_delta) / angle_step;
  438. if (angle_delta < 0.f) {
  439. angle_step = -angle_step;
  440. }
  441. float t = Vector2(1, 0).angle_to(vbegin);
  442. float end_angle = t + angle_delta;
  443. Vector2 rpos(0, 0);
  444. // Arc vertices
  445. for (int ti = 0; ti < steps; ++ti, t += angle_step) {
  446. rpos = center + Vector2(Math::cos(t), Math::sin(t)) * radius;
  447. strip_add_tri(rpos, orientation);
  448. }
  449. // Last arc vertex
  450. rpos = center + Vector2(Math::cos(end_angle), Math::sin(end_angle)) * radius;
  451. strip_add_tri(rpos, orientation);
  452. }
  453. void LineBuilder::new_arc(Vector2 center, Vector2 vbegin, float angle_delta, Color color, Rect2 uv_rect) {
  454. // Make a standalone arc that doesn't use existing vertices,
  455. // with undistorted UVs from within a square section
  456. float radius = vbegin.length();
  457. float angle_step = Math_PI / static_cast<float>(round_precision);
  458. float steps = Math::abs(angle_delta) / angle_step;
  459. if (angle_delta < 0.f) {
  460. angle_step = -angle_step;
  461. }
  462. float t = Vector2(1, 0).angle_to(vbegin);
  463. float end_angle = t + angle_delta;
  464. Vector2 rpos(0, 0);
  465. float tt_begin = -Math_PI / 2.0f;
  466. float tt = tt_begin;
  467. // Center vertice
  468. int vi = vertices.size();
  469. vertices.push_back(center);
  470. if (_interpolate_color) {
  471. colors.push_back(color);
  472. }
  473. if (texture_mode != Line2D::LINE_TEXTURE_NONE) {
  474. uvs.push_back(interpolate(uv_rect, Vector2(0.5f, 0.5f)));
  475. }
  476. // Arc vertices
  477. for (int ti = 0; ti < steps; ++ti, t += angle_step) {
  478. Vector2 sc = Vector2(Math::cos(t), Math::sin(t));
  479. rpos = center + sc * radius;
  480. vertices.push_back(rpos);
  481. if (_interpolate_color) {
  482. colors.push_back(color);
  483. }
  484. if (texture_mode != Line2D::LINE_TEXTURE_NONE) {
  485. Vector2 tsc = Vector2(Math::cos(tt), Math::sin(tt));
  486. uvs.push_back(interpolate(uv_rect, 0.5f * (tsc + Vector2(1.f, 1.f))));
  487. tt += angle_step;
  488. }
  489. }
  490. // Last arc vertex
  491. Vector2 sc = Vector2(Math::cos(end_angle), Math::sin(end_angle));
  492. rpos = center + sc * radius;
  493. vertices.push_back(rpos);
  494. if (_interpolate_color) {
  495. colors.push_back(color);
  496. }
  497. if (texture_mode != Line2D::LINE_TEXTURE_NONE) {
  498. tt = tt_begin + angle_delta;
  499. Vector2 tsc = Vector2(Math::cos(tt), Math::sin(tt));
  500. uvs.push_back(interpolate(uv_rect, 0.5f * (tsc + Vector2(1.f, 1.f))));
  501. }
  502. // Make up triangles
  503. int vi0 = vi;
  504. for (int ti = 0; ti < steps; ++ti) {
  505. indices.push_back(vi0);
  506. indices.push_back(++vi);
  507. indices.push_back(vi + 1);
  508. }
  509. }