curve.cpp 50 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743
  1. /*************************************************************************/
  2. /* curve.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
  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 "curve.h"
  31. #include "core/core_string_names.h"
  32. template <class T>
  33. static _FORCE_INLINE_ T _bezier_interp(real_t p_t, T p_start, T p_control_1, T p_control_2, T p_end) {
  34. /* Formula from Wikipedia article on Bezier curves. */
  35. real_t omt = (1.0 - p_t);
  36. real_t omt2 = omt * omt;
  37. real_t omt3 = omt2 * omt;
  38. real_t t2 = p_t * p_t;
  39. real_t t3 = t2 * p_t;
  40. return p_start * omt3 + p_control_1 * omt2 * p_t * 3.0 + p_control_2 * omt * t2 * 3.0 + p_end * t3;
  41. }
  42. const char *Curve::SIGNAL_RANGE_CHANGED = "range_changed";
  43. Curve::Curve() {
  44. }
  45. int Curve::add_point(Vector2 p_position, real_t p_left_tangent, real_t p_right_tangent, TangentMode p_left_mode, TangentMode p_right_mode) {
  46. // Add a point and preserve order
  47. // Curve bounds is in 0..1
  48. if (p_position.x > MAX_X) {
  49. p_position.x = MAX_X;
  50. } else if (p_position.x < MIN_X) {
  51. p_position.x = MIN_X;
  52. }
  53. int ret = -1;
  54. if (_points.size() == 0) {
  55. _points.push_back(Point(p_position, p_left_tangent, p_right_tangent, p_left_mode, p_right_mode));
  56. ret = 0;
  57. } else if (_points.size() == 1) {
  58. // TODO Is the `else` able to handle this block already?
  59. real_t diff = p_position.x - _points[0].position.x;
  60. if (diff > 0) {
  61. _points.push_back(Point(p_position, p_left_tangent, p_right_tangent, p_left_mode, p_right_mode));
  62. ret = 1;
  63. } else {
  64. _points.insert(0, Point(p_position, p_left_tangent, p_right_tangent, p_left_mode, p_right_mode));
  65. ret = 0;
  66. }
  67. } else {
  68. int i = get_index(p_position.x);
  69. if (i == 0 && p_position.x < _points[0].position.x) {
  70. // Insert before anything else
  71. _points.insert(0, Point(p_position, p_left_tangent, p_right_tangent, p_left_mode, p_right_mode));
  72. ret = 0;
  73. } else {
  74. // Insert between i and i+1
  75. ++i;
  76. _points.insert(i, Point(p_position, p_left_tangent, p_right_tangent, p_left_mode, p_right_mode));
  77. ret = i;
  78. }
  79. }
  80. update_auto_tangents(ret);
  81. mark_dirty();
  82. return ret;
  83. }
  84. int Curve::get_index(real_t p_offset) const {
  85. // Lower-bound float binary search
  86. int imin = 0;
  87. int imax = _points.size() - 1;
  88. while (imax - imin > 1) {
  89. int m = (imin + imax) / 2;
  90. real_t a = _points[m].position.x;
  91. real_t b = _points[m + 1].position.x;
  92. if (a < p_offset && b < p_offset) {
  93. imin = m;
  94. } else if (a > p_offset) {
  95. imax = m;
  96. } else {
  97. return m;
  98. }
  99. }
  100. // Will happen if the offset is out of bounds
  101. if (p_offset > _points[imax].position.x) {
  102. return imax;
  103. }
  104. return imin;
  105. }
  106. void Curve::clean_dupes() {
  107. bool dirty = false;
  108. for (int i = 1; i < _points.size(); ++i) {
  109. real_t diff = _points[i - 1].position.x - _points[i].position.x;
  110. if (diff <= CMP_EPSILON) {
  111. _points.remove_at(i);
  112. --i;
  113. dirty = true;
  114. }
  115. }
  116. if (dirty) {
  117. mark_dirty();
  118. }
  119. }
  120. void Curve::set_point_left_tangent(int p_index, real_t p_tangent) {
  121. ERR_FAIL_INDEX(p_index, _points.size());
  122. _points.write[p_index].left_tangent = p_tangent;
  123. _points.write[p_index].left_mode = TANGENT_FREE;
  124. mark_dirty();
  125. }
  126. void Curve::set_point_right_tangent(int p_index, real_t p_tangent) {
  127. ERR_FAIL_INDEX(p_index, _points.size());
  128. _points.write[p_index].right_tangent = p_tangent;
  129. _points.write[p_index].right_mode = TANGENT_FREE;
  130. mark_dirty();
  131. }
  132. void Curve::set_point_left_mode(int p_index, TangentMode p_mode) {
  133. ERR_FAIL_INDEX(p_index, _points.size());
  134. _points.write[p_index].left_mode = p_mode;
  135. if (p_index > 0) {
  136. if (p_mode == TANGENT_LINEAR) {
  137. Vector2 v = (_points[p_index - 1].position - _points[p_index].position).normalized();
  138. _points.write[p_index].left_tangent = v.y / v.x;
  139. }
  140. }
  141. mark_dirty();
  142. }
  143. void Curve::set_point_right_mode(int p_index, TangentMode p_mode) {
  144. ERR_FAIL_INDEX(p_index, _points.size());
  145. _points.write[p_index].right_mode = p_mode;
  146. if (p_index + 1 < _points.size()) {
  147. if (p_mode == TANGENT_LINEAR) {
  148. Vector2 v = (_points[p_index + 1].position - _points[p_index].position).normalized();
  149. _points.write[p_index].right_tangent = v.y / v.x;
  150. }
  151. }
  152. mark_dirty();
  153. }
  154. real_t Curve::get_point_left_tangent(int p_index) const {
  155. ERR_FAIL_INDEX_V(p_index, _points.size(), 0);
  156. return _points[p_index].left_tangent;
  157. }
  158. real_t Curve::get_point_right_tangent(int p_index) const {
  159. ERR_FAIL_INDEX_V(p_index, _points.size(), 0);
  160. return _points[p_index].right_tangent;
  161. }
  162. Curve::TangentMode Curve::get_point_left_mode(int p_index) const {
  163. ERR_FAIL_INDEX_V(p_index, _points.size(), TANGENT_FREE);
  164. return _points[p_index].left_mode;
  165. }
  166. Curve::TangentMode Curve::get_point_right_mode(int p_index) const {
  167. ERR_FAIL_INDEX_V(p_index, _points.size(), TANGENT_FREE);
  168. return _points[p_index].right_mode;
  169. }
  170. void Curve::remove_point(int p_index) {
  171. ERR_FAIL_INDEX(p_index, _points.size());
  172. _points.remove_at(p_index);
  173. mark_dirty();
  174. }
  175. void Curve::clear_points() {
  176. _points.clear();
  177. mark_dirty();
  178. }
  179. void Curve::set_point_value(int p_index, real_t p_position) {
  180. ERR_FAIL_INDEX(p_index, _points.size());
  181. _points.write[p_index].position.y = p_position;
  182. update_auto_tangents(p_index);
  183. mark_dirty();
  184. }
  185. int Curve::set_point_offset(int p_index, real_t p_offset) {
  186. ERR_FAIL_INDEX_V(p_index, _points.size(), -1);
  187. Point p = _points[p_index];
  188. remove_point(p_index);
  189. int i = add_point(Vector2(p_offset, p.position.y));
  190. _points.write[i].left_tangent = p.left_tangent;
  191. _points.write[i].right_tangent = p.right_tangent;
  192. _points.write[i].left_mode = p.left_mode;
  193. _points.write[i].right_mode = p.right_mode;
  194. if (p_index != i) {
  195. update_auto_tangents(p_index);
  196. }
  197. update_auto_tangents(i);
  198. return i;
  199. }
  200. Vector2 Curve::get_point_position(int p_index) const {
  201. ERR_FAIL_INDEX_V(p_index, _points.size(), Vector2(0, 0));
  202. return _points[p_index].position;
  203. }
  204. Curve::Point Curve::get_point(int p_index) const {
  205. ERR_FAIL_INDEX_V(p_index, _points.size(), Point());
  206. return _points[p_index];
  207. }
  208. void Curve::update_auto_tangents(int p_index) {
  209. Point &p = _points.write[p_index];
  210. if (p_index > 0) {
  211. if (p.left_mode == TANGENT_LINEAR) {
  212. Vector2 v = (_points[p_index - 1].position - p.position).normalized();
  213. p.left_tangent = v.y / v.x;
  214. }
  215. if (_points[p_index - 1].right_mode == TANGENT_LINEAR) {
  216. Vector2 v = (_points[p_index - 1].position - p.position).normalized();
  217. _points.write[p_index - 1].right_tangent = v.y / v.x;
  218. }
  219. }
  220. if (p_index + 1 < _points.size()) {
  221. if (p.right_mode == TANGENT_LINEAR) {
  222. Vector2 v = (_points[p_index + 1].position - p.position).normalized();
  223. p.right_tangent = v.y / v.x;
  224. }
  225. if (_points[p_index + 1].left_mode == TANGENT_LINEAR) {
  226. Vector2 v = (_points[p_index + 1].position - p.position).normalized();
  227. _points.write[p_index + 1].left_tangent = v.y / v.x;
  228. }
  229. }
  230. }
  231. #define MIN_Y_RANGE 0.01
  232. void Curve::set_min_value(real_t p_min) {
  233. if (_minmax_set_once & 0b11 && p_min > _max_value - MIN_Y_RANGE) {
  234. _min_value = _max_value - MIN_Y_RANGE;
  235. } else {
  236. _minmax_set_once |= 0b10; // first bit is "min set"
  237. _min_value = p_min;
  238. }
  239. // Note: min and max are indicative values,
  240. // it's still possible that existing points are out of range at this point.
  241. emit_signal(SNAME(SIGNAL_RANGE_CHANGED));
  242. }
  243. void Curve::set_max_value(real_t p_max) {
  244. if (_minmax_set_once & 0b11 && p_max < _min_value + MIN_Y_RANGE) {
  245. _max_value = _min_value + MIN_Y_RANGE;
  246. } else {
  247. _minmax_set_once |= 0b01; // second bit is "max set"
  248. _max_value = p_max;
  249. }
  250. emit_signal(SNAME(SIGNAL_RANGE_CHANGED));
  251. }
  252. real_t Curve::interpolate(real_t p_offset) const {
  253. if (_points.size() == 0) {
  254. return 0;
  255. }
  256. if (_points.size() == 1) {
  257. return _points[0].position.y;
  258. }
  259. int i = get_index(p_offset);
  260. if (i == _points.size() - 1) {
  261. return _points[i].position.y;
  262. }
  263. real_t local = p_offset - _points[i].position.x;
  264. if (i == 0 && local <= 0) {
  265. return _points[0].position.y;
  266. }
  267. return interpolate_local_nocheck(i, local);
  268. }
  269. real_t Curve::interpolate_local_nocheck(int p_index, real_t p_local_offset) const {
  270. const Point a = _points[p_index];
  271. const Point b = _points[p_index + 1];
  272. /* Cubic bezier
  273. *
  274. * ac-----bc
  275. * / \
  276. * / \ Here with a.right_tangent > 0
  277. * / \ and b.left_tangent < 0
  278. * / \
  279. * a b
  280. *
  281. * |-d1--|-d2--|-d3--|
  282. *
  283. * d1 == d2 == d3 == d / 3
  284. */
  285. // Control points are chosen at equal distances
  286. real_t d = b.position.x - a.position.x;
  287. if (Math::is_zero_approx(d)) {
  288. return b.position.y;
  289. }
  290. p_local_offset /= d;
  291. d /= 3.0;
  292. real_t yac = a.position.y + d * a.right_tangent;
  293. real_t ybc = b.position.y - d * b.left_tangent;
  294. real_t y = _bezier_interp(p_local_offset, a.position.y, yac, ybc, b.position.y);
  295. return y;
  296. }
  297. void Curve::mark_dirty() {
  298. _baked_cache_dirty = true;
  299. emit_signal(CoreStringNames::get_singleton()->changed);
  300. }
  301. Array Curve::get_data() const {
  302. Array output;
  303. const unsigned int ELEMS = 5;
  304. output.resize(_points.size() * ELEMS);
  305. for (int j = 0; j < _points.size(); ++j) {
  306. const Point p = _points[j];
  307. int i = j * ELEMS;
  308. output[i] = p.position;
  309. output[i + 1] = p.left_tangent;
  310. output[i + 2] = p.right_tangent;
  311. output[i + 3] = p.left_mode;
  312. output[i + 4] = p.right_mode;
  313. }
  314. return output;
  315. }
  316. void Curve::set_data(const Array p_input) {
  317. const unsigned int ELEMS = 5;
  318. ERR_FAIL_COND(p_input.size() % ELEMS != 0);
  319. _points.clear();
  320. // Validate input
  321. for (int i = 0; i < p_input.size(); i += ELEMS) {
  322. ERR_FAIL_COND(p_input[i].get_type() != Variant::VECTOR2);
  323. ERR_FAIL_COND(!p_input[i + 1].is_num());
  324. ERR_FAIL_COND(p_input[i + 2].get_type() != Variant::FLOAT);
  325. ERR_FAIL_COND(p_input[i + 3].get_type() != Variant::INT);
  326. int left_mode = p_input[i + 3];
  327. ERR_FAIL_COND(left_mode < 0 || left_mode >= TANGENT_MODE_COUNT);
  328. ERR_FAIL_COND(p_input[i + 4].get_type() != Variant::INT);
  329. int right_mode = p_input[i + 4];
  330. ERR_FAIL_COND(right_mode < 0 || right_mode >= TANGENT_MODE_COUNT);
  331. }
  332. _points.resize(p_input.size() / ELEMS);
  333. for (int j = 0; j < _points.size(); ++j) {
  334. Point &p = _points.write[j];
  335. int i = j * ELEMS;
  336. p.position = p_input[i];
  337. p.left_tangent = p_input[i + 1];
  338. p.right_tangent = p_input[i + 2];
  339. // TODO For some reason the compiler won't convert from Variant to enum
  340. int left_mode = p_input[i + 3];
  341. int right_mode = p_input[i + 4];
  342. p.left_mode = (TangentMode)left_mode;
  343. p.right_mode = (TangentMode)right_mode;
  344. }
  345. mark_dirty();
  346. }
  347. void Curve::bake() {
  348. _baked_cache.clear();
  349. _baked_cache.resize(_bake_resolution);
  350. for (int i = 1; i < _bake_resolution - 1; ++i) {
  351. real_t x = i / static_cast<real_t>(_bake_resolution);
  352. real_t y = interpolate(x);
  353. _baked_cache.write[i] = y;
  354. }
  355. if (_points.size() != 0) {
  356. _baked_cache.write[0] = _points[0].position.y;
  357. _baked_cache.write[_baked_cache.size() - 1] = _points[_points.size() - 1].position.y;
  358. }
  359. _baked_cache_dirty = false;
  360. }
  361. void Curve::set_bake_resolution(int p_resolution) {
  362. ERR_FAIL_COND(p_resolution < 1);
  363. ERR_FAIL_COND(p_resolution > 1000);
  364. _bake_resolution = p_resolution;
  365. _baked_cache_dirty = true;
  366. }
  367. real_t Curve::interpolate_baked(real_t p_offset) const {
  368. if (_baked_cache_dirty) {
  369. // Last-second bake if not done already
  370. const_cast<Curve *>(this)->bake();
  371. }
  372. // Special cases if the cache is too small
  373. if (_baked_cache.size() == 0) {
  374. if (_points.size() == 0) {
  375. return 0;
  376. }
  377. return _points[0].position.y;
  378. } else if (_baked_cache.size() == 1) {
  379. return _baked_cache[0];
  380. }
  381. // Get interpolation index
  382. real_t fi = p_offset * _baked_cache.size();
  383. int i = Math::floor(fi);
  384. if (i < 0) {
  385. i = 0;
  386. fi = 0;
  387. } else if (i >= _baked_cache.size()) {
  388. i = _baked_cache.size() - 1;
  389. fi = 0;
  390. }
  391. // Interpolate
  392. if (i + 1 < _baked_cache.size()) {
  393. real_t t = fi - i;
  394. return Math::lerp(_baked_cache[i], _baked_cache[i + 1], t);
  395. } else {
  396. return _baked_cache[_baked_cache.size() - 1];
  397. }
  398. }
  399. void Curve::ensure_default_setup(real_t p_min, real_t p_max) {
  400. if (_points.size() == 0 && _min_value == 0 && _max_value == 1) {
  401. add_point(Vector2(0, 1));
  402. add_point(Vector2(1, 1));
  403. set_min_value(p_min);
  404. set_max_value(p_max);
  405. }
  406. }
  407. void Curve::_bind_methods() {
  408. ClassDB::bind_method(D_METHOD("get_point_count"), &Curve::get_point_count);
  409. ClassDB::bind_method(D_METHOD("add_point", "position", "left_tangent", "right_tangent", "left_mode", "right_mode"), &Curve::add_point, DEFVAL(0), DEFVAL(0), DEFVAL(TANGENT_FREE), DEFVAL(TANGENT_FREE));
  410. ClassDB::bind_method(D_METHOD("remove_point", "index"), &Curve::remove_point);
  411. ClassDB::bind_method(D_METHOD("clear_points"), &Curve::clear_points);
  412. ClassDB::bind_method(D_METHOD("get_point_position", "index"), &Curve::get_point_position);
  413. ClassDB::bind_method(D_METHOD("set_point_value", "index", "y"), &Curve::set_point_value);
  414. ClassDB::bind_method(D_METHOD("set_point_offset", "index", "offset"), &Curve::set_point_offset);
  415. ClassDB::bind_method(D_METHOD("interpolate", "offset"), &Curve::interpolate);
  416. ClassDB::bind_method(D_METHOD("interpolate_baked", "offset"), &Curve::interpolate_baked);
  417. ClassDB::bind_method(D_METHOD("get_point_left_tangent", "index"), &Curve::get_point_left_tangent);
  418. ClassDB::bind_method(D_METHOD("get_point_right_tangent", "index"), &Curve::get_point_right_tangent);
  419. ClassDB::bind_method(D_METHOD("get_point_left_mode", "index"), &Curve::get_point_left_mode);
  420. ClassDB::bind_method(D_METHOD("get_point_right_mode", "index"), &Curve::get_point_right_mode);
  421. ClassDB::bind_method(D_METHOD("set_point_left_tangent", "index", "tangent"), &Curve::set_point_left_tangent);
  422. ClassDB::bind_method(D_METHOD("set_point_right_tangent", "index", "tangent"), &Curve::set_point_right_tangent);
  423. ClassDB::bind_method(D_METHOD("set_point_left_mode", "index", "mode"), &Curve::set_point_left_mode);
  424. ClassDB::bind_method(D_METHOD("set_point_right_mode", "index", "mode"), &Curve::set_point_right_mode);
  425. ClassDB::bind_method(D_METHOD("get_min_value"), &Curve::get_min_value);
  426. ClassDB::bind_method(D_METHOD("set_min_value", "min"), &Curve::set_min_value);
  427. ClassDB::bind_method(D_METHOD("get_max_value"), &Curve::get_max_value);
  428. ClassDB::bind_method(D_METHOD("set_max_value", "max"), &Curve::set_max_value);
  429. ClassDB::bind_method(D_METHOD("clean_dupes"), &Curve::clean_dupes);
  430. ClassDB::bind_method(D_METHOD("bake"), &Curve::bake);
  431. ClassDB::bind_method(D_METHOD("get_bake_resolution"), &Curve::get_bake_resolution);
  432. ClassDB::bind_method(D_METHOD("set_bake_resolution", "resolution"), &Curve::set_bake_resolution);
  433. ClassDB::bind_method(D_METHOD("_get_data"), &Curve::get_data);
  434. ClassDB::bind_method(D_METHOD("_set_data", "data"), &Curve::set_data);
  435. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "min_value", PROPERTY_HINT_RANGE, "-1024,1024,0.01"), "set_min_value", "get_min_value");
  436. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "max_value", PROPERTY_HINT_RANGE, "-1024,1024,0.01"), "set_max_value", "get_max_value");
  437. ADD_PROPERTY(PropertyInfo(Variant::INT, "bake_resolution", PROPERTY_HINT_RANGE, "1,1000,1"), "set_bake_resolution", "get_bake_resolution");
  438. ADD_PROPERTY(PropertyInfo(Variant::INT, "_data", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR | PROPERTY_USAGE_INTERNAL), "_set_data", "_get_data");
  439. ADD_SIGNAL(MethodInfo(SIGNAL_RANGE_CHANGED));
  440. BIND_ENUM_CONSTANT(TANGENT_FREE);
  441. BIND_ENUM_CONSTANT(TANGENT_LINEAR);
  442. BIND_ENUM_CONSTANT(TANGENT_MODE_COUNT);
  443. }
  444. int Curve2D::get_point_count() const {
  445. return points.size();
  446. }
  447. void Curve2D::add_point(const Vector2 &p_position, const Vector2 &p_in, const Vector2 &p_out, int p_atpos) {
  448. Point n;
  449. n.position = p_position;
  450. n.in = p_in;
  451. n.out = p_out;
  452. if (p_atpos >= 0 && p_atpos < points.size()) {
  453. points.insert(p_atpos, n);
  454. } else {
  455. points.push_back(n);
  456. }
  457. baked_cache_dirty = true;
  458. emit_signal(CoreStringNames::get_singleton()->changed);
  459. }
  460. void Curve2D::set_point_position(int p_index, const Vector2 &p_position) {
  461. ERR_FAIL_INDEX(p_index, points.size());
  462. points.write[p_index].position = p_position;
  463. baked_cache_dirty = true;
  464. emit_signal(CoreStringNames::get_singleton()->changed);
  465. }
  466. Vector2 Curve2D::get_point_position(int p_index) const {
  467. ERR_FAIL_INDEX_V(p_index, points.size(), Vector2());
  468. return points[p_index].position;
  469. }
  470. void Curve2D::set_point_in(int p_index, const Vector2 &p_in) {
  471. ERR_FAIL_INDEX(p_index, points.size());
  472. points.write[p_index].in = p_in;
  473. baked_cache_dirty = true;
  474. emit_signal(CoreStringNames::get_singleton()->changed);
  475. }
  476. Vector2 Curve2D::get_point_in(int p_index) const {
  477. ERR_FAIL_INDEX_V(p_index, points.size(), Vector2());
  478. return points[p_index].in;
  479. }
  480. void Curve2D::set_point_out(int p_index, const Vector2 &p_out) {
  481. ERR_FAIL_INDEX(p_index, points.size());
  482. points.write[p_index].out = p_out;
  483. baked_cache_dirty = true;
  484. emit_signal(CoreStringNames::get_singleton()->changed);
  485. }
  486. Vector2 Curve2D::get_point_out(int p_index) const {
  487. ERR_FAIL_INDEX_V(p_index, points.size(), Vector2());
  488. return points[p_index].out;
  489. }
  490. void Curve2D::remove_point(int p_index) {
  491. ERR_FAIL_INDEX(p_index, points.size());
  492. points.remove_at(p_index);
  493. baked_cache_dirty = true;
  494. emit_signal(CoreStringNames::get_singleton()->changed);
  495. }
  496. void Curve2D::clear_points() {
  497. if (!points.is_empty()) {
  498. points.clear();
  499. baked_cache_dirty = true;
  500. emit_signal(CoreStringNames::get_singleton()->changed);
  501. }
  502. }
  503. Vector2 Curve2D::interpolate(int p_index, const real_t p_offset) const {
  504. int pc = points.size();
  505. ERR_FAIL_COND_V(pc == 0, Vector2());
  506. if (p_index >= pc - 1) {
  507. return points[pc - 1].position;
  508. } else if (p_index < 0) {
  509. return points[0].position;
  510. }
  511. Vector2 p0 = points[p_index].position;
  512. Vector2 p1 = p0 + points[p_index].out;
  513. Vector2 p3 = points[p_index + 1].position;
  514. Vector2 p2 = p3 + points[p_index + 1].in;
  515. return _bezier_interp(p_offset, p0, p1, p2, p3);
  516. }
  517. Vector2 Curve2D::interpolatef(real_t p_findex) const {
  518. if (p_findex < 0) {
  519. p_findex = 0;
  520. } else if (p_findex >= points.size()) {
  521. p_findex = points.size();
  522. }
  523. return interpolate((int)p_findex, Math::fmod(p_findex, (real_t)1.0));
  524. }
  525. void Curve2D::_bake_segment2d(RBMap<real_t, Vector2> &r_bake, real_t p_begin, real_t p_end, const Vector2 &p_a, const Vector2 &p_out, const Vector2 &p_b, const Vector2 &p_in, int p_depth, int p_max_depth, real_t p_tol) const {
  526. real_t mp = p_begin + (p_end - p_begin) * 0.5;
  527. Vector2 beg = _bezier_interp(p_begin, p_a, p_a + p_out, p_b + p_in, p_b);
  528. Vector2 mid = _bezier_interp(mp, p_a, p_a + p_out, p_b + p_in, p_b);
  529. Vector2 end = _bezier_interp(p_end, p_a, p_a + p_out, p_b + p_in, p_b);
  530. Vector2 na = (mid - beg).normalized();
  531. Vector2 nb = (end - mid).normalized();
  532. real_t dp = na.dot(nb);
  533. if (dp < Math::cos(Math::deg2rad(p_tol))) {
  534. r_bake[mp] = mid;
  535. }
  536. if (p_depth < p_max_depth) {
  537. _bake_segment2d(r_bake, p_begin, mp, p_a, p_out, p_b, p_in, p_depth + 1, p_max_depth, p_tol);
  538. _bake_segment2d(r_bake, mp, p_end, p_a, p_out, p_b, p_in, p_depth + 1, p_max_depth, p_tol);
  539. }
  540. }
  541. void Curve2D::_bake() const {
  542. if (!baked_cache_dirty) {
  543. return;
  544. }
  545. baked_max_ofs = 0;
  546. baked_cache_dirty = false;
  547. if (points.size() == 0) {
  548. baked_point_cache.clear();
  549. baked_dist_cache.clear();
  550. return;
  551. }
  552. if (points.size() == 1) {
  553. baked_point_cache.resize(1);
  554. baked_point_cache.set(0, points[0].position);
  555. baked_dist_cache.resize(1);
  556. baked_dist_cache.set(0, 0.0);
  557. return;
  558. }
  559. Vector2 position = points[0].position;
  560. real_t dist = 0.0;
  561. List<Vector2> pointlist;
  562. List<real_t> distlist;
  563. // Start always from origin.
  564. pointlist.push_back(position);
  565. distlist.push_back(0.0);
  566. for (int i = 0; i < points.size() - 1; i++) {
  567. real_t step = 0.1; // at least 10 substeps ought to be enough?
  568. real_t p = 0.0;
  569. while (p < 1.0) {
  570. real_t np = p + step;
  571. if (np > 1.0) {
  572. np = 1.0;
  573. }
  574. Vector2 npp = _bezier_interp(np, points[i].position, points[i].position + points[i].out, points[i + 1].position + points[i + 1].in, points[i + 1].position);
  575. real_t d = position.distance_to(npp);
  576. if (d > bake_interval) {
  577. // OK! between P and NP there _has_ to be Something, let's go searching!
  578. int iterations = 10; //lots of detail!
  579. real_t low = p;
  580. real_t hi = np;
  581. real_t mid = low + (hi - low) * 0.5;
  582. for (int j = 0; j < iterations; j++) {
  583. npp = _bezier_interp(mid, points[i].position, points[i].position + points[i].out, points[i + 1].position + points[i + 1].in, points[i + 1].position);
  584. d = position.distance_to(npp);
  585. if (bake_interval < d) {
  586. hi = mid;
  587. } else {
  588. low = mid;
  589. }
  590. mid = low + (hi - low) * 0.5;
  591. }
  592. position = npp;
  593. p = mid;
  594. dist += d;
  595. pointlist.push_back(position);
  596. distlist.push_back(dist);
  597. } else {
  598. p = np;
  599. }
  600. }
  601. Vector2 npp = points[i + 1].position;
  602. real_t d = position.distance_to(npp);
  603. position = npp;
  604. dist += d;
  605. pointlist.push_back(position);
  606. distlist.push_back(dist);
  607. }
  608. baked_max_ofs = dist;
  609. baked_point_cache.resize(pointlist.size());
  610. baked_dist_cache.resize(distlist.size());
  611. Vector2 *w = baked_point_cache.ptrw();
  612. real_t *wd = baked_dist_cache.ptrw();
  613. for (int i = 0; i < pointlist.size(); i++) {
  614. w[i] = pointlist[i];
  615. wd[i] = distlist[i];
  616. }
  617. }
  618. real_t Curve2D::get_baked_length() const {
  619. if (baked_cache_dirty) {
  620. _bake();
  621. }
  622. return baked_max_ofs;
  623. }
  624. Vector2 Curve2D::interpolate_baked(real_t p_offset, bool p_cubic) const {
  625. if (baked_cache_dirty) {
  626. _bake();
  627. }
  628. // Validate: Curve may not have baked points.
  629. int pc = baked_point_cache.size();
  630. ERR_FAIL_COND_V_MSG(pc == 0, Vector2(), "No points in Curve2D.");
  631. if (pc == 1) {
  632. return baked_point_cache.get(0);
  633. }
  634. const Vector2 *r = baked_point_cache.ptr();
  635. if (p_offset < 0) {
  636. return r[0];
  637. }
  638. if (p_offset >= baked_max_ofs) {
  639. return r[pc - 1];
  640. }
  641. int start = 0;
  642. int end = pc;
  643. int idx = (end + start) / 2;
  644. // Binary search to find baked points.
  645. while (start < idx) {
  646. real_t offset = baked_dist_cache[idx];
  647. if (p_offset <= offset) {
  648. end = idx;
  649. } else {
  650. start = idx;
  651. }
  652. idx = (end + start) / 2;
  653. }
  654. real_t offset_begin = baked_dist_cache[idx];
  655. real_t offset_end = baked_dist_cache[idx + 1];
  656. real_t idx_interval = offset_end - offset_begin;
  657. ERR_FAIL_COND_V_MSG(p_offset < offset_begin || p_offset > offset_end, Vector2(), "failed to find baked segment");
  658. real_t frac = (p_offset - offset_begin) / idx_interval;
  659. if (p_cubic) {
  660. Vector2 pre = idx > 0 ? r[idx - 1] : r[idx];
  661. Vector2 post = (idx < (pc - 2)) ? r[idx + 2] : r[idx + 1];
  662. return r[idx].cubic_interpolate(r[idx + 1], pre, post, frac);
  663. } else {
  664. return r[idx].lerp(r[idx + 1], frac);
  665. }
  666. }
  667. PackedVector2Array Curve2D::get_baked_points() const {
  668. if (baked_cache_dirty) {
  669. _bake();
  670. }
  671. return baked_point_cache;
  672. }
  673. void Curve2D::set_bake_interval(real_t p_tolerance) {
  674. bake_interval = p_tolerance;
  675. baked_cache_dirty = true;
  676. emit_signal(CoreStringNames::get_singleton()->changed);
  677. }
  678. real_t Curve2D::get_bake_interval() const {
  679. return bake_interval;
  680. }
  681. Vector2 Curve2D::get_closest_point(const Vector2 &p_to_point) const {
  682. // Brute force method.
  683. if (baked_cache_dirty) {
  684. _bake();
  685. }
  686. // Validate: Curve may not have baked points.
  687. int pc = baked_point_cache.size();
  688. ERR_FAIL_COND_V_MSG(pc == 0, Vector2(), "No points in Curve2D.");
  689. if (pc == 1) {
  690. return baked_point_cache.get(0);
  691. }
  692. const Vector2 *r = baked_point_cache.ptr();
  693. Vector2 nearest;
  694. real_t nearest_dist = -1.0f;
  695. for (int i = 0; i < pc - 1; i++) {
  696. Vector2 origin = r[i];
  697. Vector2 direction = (r[i + 1] - origin) / bake_interval;
  698. real_t d = CLAMP((p_to_point - origin).dot(direction), 0.0f, bake_interval);
  699. Vector2 proj = origin + direction * d;
  700. real_t dist = proj.distance_squared_to(p_to_point);
  701. if (nearest_dist < 0.0f || dist < nearest_dist) {
  702. nearest = proj;
  703. nearest_dist = dist;
  704. }
  705. }
  706. return nearest;
  707. }
  708. real_t Curve2D::get_closest_offset(const Vector2 &p_to_point) const {
  709. // Brute force method.
  710. if (baked_cache_dirty) {
  711. _bake();
  712. }
  713. // Validate: Curve may not have baked points.
  714. int pc = baked_point_cache.size();
  715. ERR_FAIL_COND_V_MSG(pc == 0, 0.0f, "No points in Curve2D.");
  716. if (pc == 1) {
  717. return 0.0f;
  718. }
  719. const Vector2 *r = baked_point_cache.ptr();
  720. real_t nearest = 0.0f;
  721. real_t nearest_dist = -1.0f;
  722. real_t offset = 0.0f;
  723. for (int i = 0; i < pc - 1; i++) {
  724. Vector2 origin = r[i];
  725. Vector2 direction = (r[i + 1] - origin) / bake_interval;
  726. real_t d = CLAMP((p_to_point - origin).dot(direction), 0.0f, bake_interval);
  727. Vector2 proj = origin + direction * d;
  728. real_t dist = proj.distance_squared_to(p_to_point);
  729. if (nearest_dist < 0.0f || dist < nearest_dist) {
  730. nearest = offset + d;
  731. nearest_dist = dist;
  732. }
  733. offset += bake_interval;
  734. }
  735. return nearest;
  736. }
  737. Dictionary Curve2D::_get_data() const {
  738. Dictionary dc;
  739. PackedVector2Array d;
  740. d.resize(points.size() * 3);
  741. Vector2 *w = d.ptrw();
  742. for (int i = 0; i < points.size(); i++) {
  743. w[i * 3 + 0] = points[i].in;
  744. w[i * 3 + 1] = points[i].out;
  745. w[i * 3 + 2] = points[i].position;
  746. }
  747. dc["points"] = d;
  748. return dc;
  749. }
  750. void Curve2D::_set_data(const Dictionary &p_data) {
  751. ERR_FAIL_COND(!p_data.has("points"));
  752. PackedVector2Array rp = p_data["points"];
  753. int pc = rp.size();
  754. ERR_FAIL_COND(pc % 3 != 0);
  755. points.resize(pc / 3);
  756. const Vector2 *r = rp.ptr();
  757. for (int i = 0; i < points.size(); i++) {
  758. points.write[i].in = r[i * 3 + 0];
  759. points.write[i].out = r[i * 3 + 1];
  760. points.write[i].position = r[i * 3 + 2];
  761. }
  762. baked_cache_dirty = true;
  763. }
  764. PackedVector2Array Curve2D::tessellate(int p_max_stages, real_t p_tolerance) const {
  765. PackedVector2Array tess;
  766. if (points.size() == 0) {
  767. return tess;
  768. }
  769. // The current implementation requires a sorted map.
  770. Vector<RBMap<real_t, Vector2>> midpoints;
  771. midpoints.resize(points.size() - 1);
  772. int pc = 1;
  773. for (int i = 0; i < points.size() - 1; i++) {
  774. _bake_segment2d(midpoints.write[i], 0, 1, points[i].position, points[i].out, points[i + 1].position, points[i + 1].in, 0, p_max_stages, p_tolerance);
  775. pc++;
  776. pc += midpoints[i].size();
  777. }
  778. tess.resize(pc);
  779. Vector2 *bpw = tess.ptrw();
  780. bpw[0] = points[0].position;
  781. int pidx = 0;
  782. for (int i = 0; i < points.size() - 1; i++) {
  783. for (const KeyValue<real_t, Vector2> &E : midpoints[i]) {
  784. pidx++;
  785. bpw[pidx] = E.value;
  786. }
  787. pidx++;
  788. bpw[pidx] = points[i + 1].position;
  789. }
  790. return tess;
  791. }
  792. void Curve2D::_bind_methods() {
  793. ClassDB::bind_method(D_METHOD("get_point_count"), &Curve2D::get_point_count);
  794. ClassDB::bind_method(D_METHOD("add_point", "position", "in", "out", "at_position"), &Curve2D::add_point, DEFVAL(Vector2()), DEFVAL(Vector2()), DEFVAL(-1));
  795. ClassDB::bind_method(D_METHOD("set_point_position", "idx", "position"), &Curve2D::set_point_position);
  796. ClassDB::bind_method(D_METHOD("get_point_position", "idx"), &Curve2D::get_point_position);
  797. ClassDB::bind_method(D_METHOD("set_point_in", "idx", "position"), &Curve2D::set_point_in);
  798. ClassDB::bind_method(D_METHOD("get_point_in", "idx"), &Curve2D::get_point_in);
  799. ClassDB::bind_method(D_METHOD("set_point_out", "idx", "position"), &Curve2D::set_point_out);
  800. ClassDB::bind_method(D_METHOD("get_point_out", "idx"), &Curve2D::get_point_out);
  801. ClassDB::bind_method(D_METHOD("remove_point", "idx"), &Curve2D::remove_point);
  802. ClassDB::bind_method(D_METHOD("clear_points"), &Curve2D::clear_points);
  803. ClassDB::bind_method(D_METHOD("interpolate", "idx", "t"), &Curve2D::interpolate);
  804. ClassDB::bind_method(D_METHOD("interpolatef", "fofs"), &Curve2D::interpolatef);
  805. //ClassDB::bind_method(D_METHOD("bake","subdivs"),&Curve2D::bake,DEFVAL(10));
  806. ClassDB::bind_method(D_METHOD("set_bake_interval", "distance"), &Curve2D::set_bake_interval);
  807. ClassDB::bind_method(D_METHOD("get_bake_interval"), &Curve2D::get_bake_interval);
  808. ClassDB::bind_method(D_METHOD("get_baked_length"), &Curve2D::get_baked_length);
  809. ClassDB::bind_method(D_METHOD("interpolate_baked", "offset", "cubic"), &Curve2D::interpolate_baked, DEFVAL(false));
  810. ClassDB::bind_method(D_METHOD("get_baked_points"), &Curve2D::get_baked_points);
  811. ClassDB::bind_method(D_METHOD("get_closest_point", "to_point"), &Curve2D::get_closest_point);
  812. ClassDB::bind_method(D_METHOD("get_closest_offset", "to_point"), &Curve2D::get_closest_offset);
  813. ClassDB::bind_method(D_METHOD("tessellate", "max_stages", "tolerance_degrees"), &Curve2D::tessellate, DEFVAL(5), DEFVAL(4));
  814. ClassDB::bind_method(D_METHOD("_get_data"), &Curve2D::_get_data);
  815. ClassDB::bind_method(D_METHOD("_set_data"), &Curve2D::_set_data);
  816. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "bake_interval", PROPERTY_HINT_RANGE, "0.01,512,0.01"), "set_bake_interval", "get_bake_interval");
  817. ADD_PROPERTY(PropertyInfo(Variant::INT, "_data", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR | PROPERTY_USAGE_INTERNAL), "_set_data", "_get_data");
  818. }
  819. Curve2D::Curve2D() {}
  820. /***********************************************************************************/
  821. /***********************************************************************************/
  822. /***********************************************************************************/
  823. /***********************************************************************************/
  824. /***********************************************************************************/
  825. /***********************************************************************************/
  826. int Curve3D::get_point_count() const {
  827. return points.size();
  828. }
  829. void Curve3D::add_point(const Vector3 &p_position, const Vector3 &p_in, const Vector3 &p_out, int p_atpos) {
  830. Point n;
  831. n.position = p_position;
  832. n.in = p_in;
  833. n.out = p_out;
  834. if (p_atpos >= 0 && p_atpos < points.size()) {
  835. points.insert(p_atpos, n);
  836. } else {
  837. points.push_back(n);
  838. }
  839. baked_cache_dirty = true;
  840. emit_signal(CoreStringNames::get_singleton()->changed);
  841. }
  842. void Curve3D::set_point_position(int p_index, const Vector3 &p_position) {
  843. ERR_FAIL_INDEX(p_index, points.size());
  844. points.write[p_index].position = p_position;
  845. baked_cache_dirty = true;
  846. emit_signal(CoreStringNames::get_singleton()->changed);
  847. }
  848. Vector3 Curve3D::get_point_position(int p_index) const {
  849. ERR_FAIL_INDEX_V(p_index, points.size(), Vector3());
  850. return points[p_index].position;
  851. }
  852. void Curve3D::set_point_tilt(int p_index, real_t p_tilt) {
  853. ERR_FAIL_INDEX(p_index, points.size());
  854. points.write[p_index].tilt = p_tilt;
  855. baked_cache_dirty = true;
  856. emit_signal(CoreStringNames::get_singleton()->changed);
  857. }
  858. real_t Curve3D::get_point_tilt(int p_index) const {
  859. ERR_FAIL_INDEX_V(p_index, points.size(), 0);
  860. return points[p_index].tilt;
  861. }
  862. void Curve3D::set_point_in(int p_index, const Vector3 &p_in) {
  863. ERR_FAIL_INDEX(p_index, points.size());
  864. points.write[p_index].in = p_in;
  865. baked_cache_dirty = true;
  866. emit_signal(CoreStringNames::get_singleton()->changed);
  867. }
  868. Vector3 Curve3D::get_point_in(int p_index) const {
  869. ERR_FAIL_INDEX_V(p_index, points.size(), Vector3());
  870. return points[p_index].in;
  871. }
  872. void Curve3D::set_point_out(int p_index, const Vector3 &p_out) {
  873. ERR_FAIL_INDEX(p_index, points.size());
  874. points.write[p_index].out = p_out;
  875. baked_cache_dirty = true;
  876. emit_signal(CoreStringNames::get_singleton()->changed);
  877. }
  878. Vector3 Curve3D::get_point_out(int p_index) const {
  879. ERR_FAIL_INDEX_V(p_index, points.size(), Vector3());
  880. return points[p_index].out;
  881. }
  882. void Curve3D::remove_point(int p_index) {
  883. ERR_FAIL_INDEX(p_index, points.size());
  884. points.remove_at(p_index);
  885. baked_cache_dirty = true;
  886. emit_signal(CoreStringNames::get_singleton()->changed);
  887. }
  888. void Curve3D::clear_points() {
  889. if (!points.is_empty()) {
  890. points.clear();
  891. baked_cache_dirty = true;
  892. emit_signal(CoreStringNames::get_singleton()->changed);
  893. }
  894. }
  895. Vector3 Curve3D::interpolate(int p_index, real_t p_offset) const {
  896. int pc = points.size();
  897. ERR_FAIL_COND_V(pc == 0, Vector3());
  898. if (p_index >= pc - 1) {
  899. return points[pc - 1].position;
  900. } else if (p_index < 0) {
  901. return points[0].position;
  902. }
  903. Vector3 p0 = points[p_index].position;
  904. Vector3 p1 = p0 + points[p_index].out;
  905. Vector3 p3 = points[p_index + 1].position;
  906. Vector3 p2 = p3 + points[p_index + 1].in;
  907. return _bezier_interp(p_offset, p0, p1, p2, p3);
  908. }
  909. Vector3 Curve3D::interpolatef(real_t p_findex) const {
  910. if (p_findex < 0) {
  911. p_findex = 0;
  912. } else if (p_findex >= points.size()) {
  913. p_findex = points.size();
  914. }
  915. return interpolate((int)p_findex, Math::fmod(p_findex, (real_t)1.0));
  916. }
  917. void Curve3D::_bake_segment3d(RBMap<real_t, Vector3> &r_bake, real_t p_begin, real_t p_end, const Vector3 &p_a, const Vector3 &p_out, const Vector3 &p_b, const Vector3 &p_in, int p_depth, int p_max_depth, real_t p_tol) const {
  918. real_t mp = p_begin + (p_end - p_begin) * 0.5;
  919. Vector3 beg = _bezier_interp(p_begin, p_a, p_a + p_out, p_b + p_in, p_b);
  920. Vector3 mid = _bezier_interp(mp, p_a, p_a + p_out, p_b + p_in, p_b);
  921. Vector3 end = _bezier_interp(p_end, p_a, p_a + p_out, p_b + p_in, p_b);
  922. Vector3 na = (mid - beg).normalized();
  923. Vector3 nb = (end - mid).normalized();
  924. real_t dp = na.dot(nb);
  925. if (dp < Math::cos(Math::deg2rad(p_tol))) {
  926. r_bake[mp] = mid;
  927. }
  928. if (p_depth < p_max_depth) {
  929. _bake_segment3d(r_bake, p_begin, mp, p_a, p_out, p_b, p_in, p_depth + 1, p_max_depth, p_tol);
  930. _bake_segment3d(r_bake, mp, p_end, p_a, p_out, p_b, p_in, p_depth + 1, p_max_depth, p_tol);
  931. }
  932. }
  933. void Curve3D::_bake() const {
  934. if (!baked_cache_dirty) {
  935. return;
  936. }
  937. baked_max_ofs = 0;
  938. baked_cache_dirty = false;
  939. if (points.size() == 0) {
  940. baked_point_cache.clear();
  941. baked_tilt_cache.clear();
  942. baked_up_vector_cache.clear();
  943. baked_dist_cache.clear();
  944. return;
  945. }
  946. if (points.size() == 1) {
  947. baked_point_cache.resize(1);
  948. baked_point_cache.set(0, points[0].position);
  949. baked_tilt_cache.resize(1);
  950. baked_tilt_cache.set(0, points[0].tilt);
  951. baked_dist_cache.resize(1);
  952. baked_dist_cache.set(0, 0.0);
  953. if (up_vector_enabled) {
  954. baked_up_vector_cache.resize(1);
  955. baked_up_vector_cache.set(0, Vector3(0, 1, 0));
  956. } else {
  957. baked_up_vector_cache.clear();
  958. }
  959. return;
  960. }
  961. Vector3 position = points[0].position;
  962. real_t dist = 0.0;
  963. List<Plane> pointlist;
  964. List<real_t> distlist;
  965. // Start always from origin.
  966. pointlist.push_back(Plane(position, points[0].tilt));
  967. distlist.push_back(0.0);
  968. for (int i = 0; i < points.size() - 1; i++) {
  969. real_t step = 0.1; // at least 10 substeps ought to be enough?
  970. real_t p = 0.0;
  971. while (p < 1.0) {
  972. real_t np = p + step;
  973. if (np > 1.0) {
  974. np = 1.0;
  975. }
  976. Vector3 npp = _bezier_interp(np, points[i].position, points[i].position + points[i].out, points[i + 1].position + points[i + 1].in, points[i + 1].position);
  977. real_t d = position.distance_to(npp);
  978. if (d > bake_interval) {
  979. // OK! between P and NP there _has_ to be Something, let's go searching!
  980. int iterations = 10; //lots of detail!
  981. real_t low = p;
  982. real_t hi = np;
  983. real_t mid = low + (hi - low) * 0.5;
  984. for (int j = 0; j < iterations; j++) {
  985. npp = _bezier_interp(mid, points[i].position, points[i].position + points[i].out, points[i + 1].position + points[i + 1].in, points[i + 1].position);
  986. d = position.distance_to(npp);
  987. if (bake_interval < d) {
  988. hi = mid;
  989. } else {
  990. low = mid;
  991. }
  992. mid = low + (hi - low) * 0.5;
  993. }
  994. position = npp;
  995. p = mid;
  996. Plane post;
  997. post.normal = position;
  998. post.d = Math::lerp(points[i].tilt, points[i + 1].tilt, mid);
  999. dist += d;
  1000. pointlist.push_back(post);
  1001. distlist.push_back(dist);
  1002. } else {
  1003. p = np;
  1004. }
  1005. }
  1006. Vector3 npp = points[i + 1].position;
  1007. real_t d = position.distance_to(npp);
  1008. position = npp;
  1009. Plane post;
  1010. post.normal = position;
  1011. post.d = points[i + 1].tilt;
  1012. dist += d;
  1013. pointlist.push_back(post);
  1014. distlist.push_back(dist);
  1015. }
  1016. baked_max_ofs = dist;
  1017. baked_point_cache.resize(pointlist.size());
  1018. Vector3 *w = baked_point_cache.ptrw();
  1019. int idx = 0;
  1020. baked_tilt_cache.resize(pointlist.size());
  1021. real_t *wt = baked_tilt_cache.ptrw();
  1022. baked_up_vector_cache.resize(up_vector_enabled ? pointlist.size() : 0);
  1023. Vector3 *up_write = baked_up_vector_cache.ptrw();
  1024. baked_dist_cache.resize(pointlist.size());
  1025. real_t *wd = baked_dist_cache.ptrw();
  1026. Vector3 sideways;
  1027. Vector3 up;
  1028. Vector3 forward;
  1029. Vector3 prev_sideways = Vector3(1, 0, 0);
  1030. Vector3 prev_up = Vector3(0, 1, 0);
  1031. Vector3 prev_forward = Vector3(0, 0, 1);
  1032. for (const Plane &E : pointlist) {
  1033. w[idx] = E.normal;
  1034. wt[idx] = E.d;
  1035. wd[idx] = distlist[idx];
  1036. if (!up_vector_enabled) {
  1037. idx++;
  1038. continue;
  1039. }
  1040. forward = idx > 0 ? (w[idx] - w[idx - 1]).normalized() : prev_forward;
  1041. real_t y_dot = prev_up.dot(forward);
  1042. if (y_dot > (1.0f - CMP_EPSILON)) {
  1043. sideways = prev_sideways;
  1044. up = -prev_forward;
  1045. } else if (y_dot < -(1.0f - CMP_EPSILON)) {
  1046. sideways = prev_sideways;
  1047. up = prev_forward;
  1048. } else {
  1049. sideways = prev_up.cross(forward).normalized();
  1050. up = forward.cross(sideways).normalized();
  1051. }
  1052. if (idx == 1) {
  1053. up_write[0] = up;
  1054. }
  1055. up_write[idx] = up;
  1056. prev_sideways = sideways;
  1057. prev_up = up;
  1058. prev_forward = forward;
  1059. idx++;
  1060. }
  1061. }
  1062. real_t Curve3D::get_baked_length() const {
  1063. if (baked_cache_dirty) {
  1064. _bake();
  1065. }
  1066. return baked_max_ofs;
  1067. }
  1068. Vector3 Curve3D::interpolate_baked(real_t p_offset, bool p_cubic) const {
  1069. if (baked_cache_dirty) {
  1070. _bake();
  1071. }
  1072. // Validate: Curve may not have baked points.
  1073. int pc = baked_point_cache.size();
  1074. ERR_FAIL_COND_V_MSG(pc == 0, Vector3(), "No points in Curve3D.");
  1075. if (pc == 1) {
  1076. return baked_point_cache.get(0);
  1077. }
  1078. const Vector3 *r = baked_point_cache.ptr();
  1079. if (p_offset < 0) {
  1080. return r[0];
  1081. }
  1082. if (p_offset >= baked_max_ofs) {
  1083. return r[pc - 1];
  1084. }
  1085. int start = 0;
  1086. int end = pc;
  1087. int idx = (end + start) / 2;
  1088. // Binary search to find baked points.
  1089. while (start < idx) {
  1090. real_t offset = baked_dist_cache[idx];
  1091. if (p_offset <= offset) {
  1092. end = idx;
  1093. } else {
  1094. start = idx;
  1095. }
  1096. idx = (end + start) / 2;
  1097. }
  1098. real_t offset_begin = baked_dist_cache[idx];
  1099. real_t offset_end = baked_dist_cache[idx + 1];
  1100. real_t idx_interval = offset_end - offset_begin;
  1101. ERR_FAIL_COND_V_MSG(p_offset < offset_begin || p_offset > offset_end, Vector3(), "failed to find baked segment");
  1102. real_t frac = (p_offset - offset_begin) / idx_interval;
  1103. if (p_cubic) {
  1104. Vector3 pre = idx > 0 ? r[idx - 1] : r[idx];
  1105. Vector3 post = (idx < (pc - 2)) ? r[idx + 2] : r[idx + 1];
  1106. return r[idx].cubic_interpolate(r[idx + 1], pre, post, frac);
  1107. } else {
  1108. return r[idx].lerp(r[idx + 1], frac);
  1109. }
  1110. }
  1111. real_t Curve3D::interpolate_baked_tilt(real_t p_offset) const {
  1112. if (baked_cache_dirty) {
  1113. _bake();
  1114. }
  1115. // Validate: Curve may not have baked tilts.
  1116. int pc = baked_tilt_cache.size();
  1117. ERR_FAIL_COND_V_MSG(pc == 0, 0, "No tilts in Curve3D.");
  1118. if (pc == 1) {
  1119. return baked_tilt_cache.get(0);
  1120. }
  1121. const real_t *r = baked_tilt_cache.ptr();
  1122. if (p_offset < 0) {
  1123. return r[0];
  1124. }
  1125. if (p_offset >= baked_max_ofs) {
  1126. return r[pc - 1];
  1127. }
  1128. int start = 0;
  1129. int end = pc;
  1130. int idx = (end + start) / 2;
  1131. // Binary search to find baked points.
  1132. while (start < idx) {
  1133. real_t offset = baked_dist_cache[idx];
  1134. if (p_offset <= offset) {
  1135. end = idx;
  1136. } else {
  1137. start = idx;
  1138. }
  1139. idx = (end + start) / 2;
  1140. }
  1141. real_t offset_begin = baked_dist_cache[idx];
  1142. real_t offset_end = baked_dist_cache[idx + 1];
  1143. real_t idx_interval = offset_end - offset_begin;
  1144. ERR_FAIL_COND_V_MSG(p_offset < offset_begin || p_offset > offset_end, 0, "failed to find baked segment");
  1145. real_t frac = (p_offset - offset_begin) / idx_interval;
  1146. return Math::lerp(r[idx], r[idx + 1], (real_t)frac);
  1147. }
  1148. Vector3 Curve3D::interpolate_baked_up_vector(real_t p_offset, bool p_apply_tilt) const {
  1149. if (baked_cache_dirty) {
  1150. _bake();
  1151. }
  1152. // Validate: Curve may not have baked up vectors.
  1153. int count = baked_up_vector_cache.size();
  1154. ERR_FAIL_COND_V_MSG(count == 0, Vector3(0, 1, 0), "No up vectors in Curve3D.");
  1155. if (count == 1) {
  1156. return baked_up_vector_cache.get(0);
  1157. }
  1158. const Vector3 *r = baked_up_vector_cache.ptr();
  1159. const Vector3 *rp = baked_point_cache.ptr();
  1160. const real_t *rt = baked_tilt_cache.ptr();
  1161. int start = 0;
  1162. int end = count;
  1163. int idx = (end + start) / 2;
  1164. // Binary search to find baked points.
  1165. while (start < idx) {
  1166. real_t offset = baked_dist_cache[idx];
  1167. if (p_offset <= offset) {
  1168. end = idx;
  1169. } else {
  1170. start = idx;
  1171. }
  1172. idx = (end + start) / 2;
  1173. }
  1174. real_t offset_begin = baked_dist_cache[idx];
  1175. real_t offset_end = baked_dist_cache[idx + 1];
  1176. real_t idx_interval = offset_end - offset_begin;
  1177. ERR_FAIL_COND_V_MSG(p_offset < offset_begin || p_offset > offset_end, Vector3(0, 1, 0), "failed to find baked segment");
  1178. real_t frac = (p_offset - offset_begin) / idx_interval;
  1179. if (idx == count - 1) {
  1180. return p_apply_tilt ? r[idx].rotated((rp[idx] - rp[idx - 1]).normalized(), rt[idx]) : r[idx];
  1181. }
  1182. Vector3 forward = (rp[idx + 1] - rp[idx]).normalized();
  1183. Vector3 up = r[idx];
  1184. Vector3 up1 = r[idx + 1];
  1185. if (p_apply_tilt) {
  1186. up.rotate(forward, rt[idx]);
  1187. up1.rotate(idx + 2 >= count ? forward : (rp[idx + 2] - rp[idx + 1]).normalized(), rt[idx + 1]);
  1188. }
  1189. Vector3 axis = up.cross(up1);
  1190. if (axis.length_squared() < CMP_EPSILON2) {
  1191. axis = forward;
  1192. } else {
  1193. axis.normalize();
  1194. }
  1195. return up.rotated(axis, up.angle_to(up1) * frac);
  1196. }
  1197. PackedVector3Array Curve3D::get_baked_points() const {
  1198. if (baked_cache_dirty) {
  1199. _bake();
  1200. }
  1201. return baked_point_cache;
  1202. }
  1203. Vector<real_t> Curve3D::get_baked_tilts() const {
  1204. if (baked_cache_dirty) {
  1205. _bake();
  1206. }
  1207. return baked_tilt_cache;
  1208. }
  1209. PackedVector3Array Curve3D::get_baked_up_vectors() const {
  1210. if (baked_cache_dirty) {
  1211. _bake();
  1212. }
  1213. return baked_up_vector_cache;
  1214. }
  1215. Vector3 Curve3D::get_closest_point(const Vector3 &p_to_point) const {
  1216. // Brute force method.
  1217. if (baked_cache_dirty) {
  1218. _bake();
  1219. }
  1220. // Validate: Curve may not have baked points.
  1221. int pc = baked_point_cache.size();
  1222. ERR_FAIL_COND_V_MSG(pc == 0, Vector3(), "No points in Curve3D.");
  1223. if (pc == 1) {
  1224. return baked_point_cache.get(0);
  1225. }
  1226. const Vector3 *r = baked_point_cache.ptr();
  1227. Vector3 nearest;
  1228. real_t nearest_dist = -1.0f;
  1229. for (int i = 0; i < pc - 1; i++) {
  1230. Vector3 origin = r[i];
  1231. Vector3 direction = (r[i + 1] - origin) / bake_interval;
  1232. real_t d = CLAMP((p_to_point - origin).dot(direction), 0.0f, bake_interval);
  1233. Vector3 proj = origin + direction * d;
  1234. real_t dist = proj.distance_squared_to(p_to_point);
  1235. if (nearest_dist < 0.0f || dist < nearest_dist) {
  1236. nearest = proj;
  1237. nearest_dist = dist;
  1238. }
  1239. }
  1240. return nearest;
  1241. }
  1242. real_t Curve3D::get_closest_offset(const Vector3 &p_to_point) const {
  1243. // Brute force method.
  1244. if (baked_cache_dirty) {
  1245. _bake();
  1246. }
  1247. // Validate: Curve may not have baked points.
  1248. int pc = baked_point_cache.size();
  1249. ERR_FAIL_COND_V_MSG(pc == 0, 0.0f, "No points in Curve3D.");
  1250. if (pc == 1) {
  1251. return 0.0f;
  1252. }
  1253. const Vector3 *r = baked_point_cache.ptr();
  1254. real_t nearest = 0.0f;
  1255. real_t nearest_dist = -1.0f;
  1256. real_t offset = 0.0f;
  1257. for (int i = 0; i < pc - 1; i++) {
  1258. Vector3 origin = r[i];
  1259. Vector3 direction = (r[i + 1] - origin) / bake_interval;
  1260. real_t d = CLAMP((p_to_point - origin).dot(direction), 0.0f, bake_interval);
  1261. Vector3 proj = origin + direction * d;
  1262. real_t dist = proj.distance_squared_to(p_to_point);
  1263. if (nearest_dist < 0.0f || dist < nearest_dist) {
  1264. nearest = offset + d;
  1265. nearest_dist = dist;
  1266. }
  1267. offset += bake_interval;
  1268. }
  1269. return nearest;
  1270. }
  1271. void Curve3D::set_bake_interval(real_t p_tolerance) {
  1272. bake_interval = p_tolerance;
  1273. baked_cache_dirty = true;
  1274. emit_signal(CoreStringNames::get_singleton()->changed);
  1275. }
  1276. real_t Curve3D::get_bake_interval() const {
  1277. return bake_interval;
  1278. }
  1279. void Curve3D::set_up_vector_enabled(bool p_enable) {
  1280. up_vector_enabled = p_enable;
  1281. baked_cache_dirty = true;
  1282. emit_signal(CoreStringNames::get_singleton()->changed);
  1283. }
  1284. bool Curve3D::is_up_vector_enabled() const {
  1285. return up_vector_enabled;
  1286. }
  1287. Dictionary Curve3D::_get_data() const {
  1288. Dictionary dc;
  1289. PackedVector3Array d;
  1290. d.resize(points.size() * 3);
  1291. Vector3 *w = d.ptrw();
  1292. Vector<real_t> t;
  1293. t.resize(points.size());
  1294. real_t *wt = t.ptrw();
  1295. for (int i = 0; i < points.size(); i++) {
  1296. w[i * 3 + 0] = points[i].in;
  1297. w[i * 3 + 1] = points[i].out;
  1298. w[i * 3 + 2] = points[i].position;
  1299. wt[i] = points[i].tilt;
  1300. }
  1301. dc["points"] = d;
  1302. dc["tilts"] = t;
  1303. return dc;
  1304. }
  1305. void Curve3D::_set_data(const Dictionary &p_data) {
  1306. ERR_FAIL_COND(!p_data.has("points"));
  1307. ERR_FAIL_COND(!p_data.has("tilts"));
  1308. PackedVector3Array rp = p_data["points"];
  1309. int pc = rp.size();
  1310. ERR_FAIL_COND(pc % 3 != 0);
  1311. points.resize(pc / 3);
  1312. const Vector3 *r = rp.ptr();
  1313. Vector<real_t> rtl = p_data["tilts"];
  1314. const real_t *rt = rtl.ptr();
  1315. for (int i = 0; i < points.size(); i++) {
  1316. points.write[i].in = r[i * 3 + 0];
  1317. points.write[i].out = r[i * 3 + 1];
  1318. points.write[i].position = r[i * 3 + 2];
  1319. points.write[i].tilt = rt[i];
  1320. }
  1321. baked_cache_dirty = true;
  1322. }
  1323. PackedVector3Array Curve3D::tessellate(int p_max_stages, real_t p_tolerance) const {
  1324. PackedVector3Array tess;
  1325. if (points.size() == 0) {
  1326. return tess;
  1327. }
  1328. Vector<RBMap<real_t, Vector3>> midpoints;
  1329. midpoints.resize(points.size() - 1);
  1330. int pc = 1;
  1331. for (int i = 0; i < points.size() - 1; i++) {
  1332. _bake_segment3d(midpoints.write[i], 0, 1, points[i].position, points[i].out, points[i + 1].position, points[i + 1].in, 0, p_max_stages, p_tolerance);
  1333. pc++;
  1334. pc += midpoints[i].size();
  1335. }
  1336. tess.resize(pc);
  1337. Vector3 *bpw = tess.ptrw();
  1338. bpw[0] = points[0].position;
  1339. int pidx = 0;
  1340. for (int i = 0; i < points.size() - 1; i++) {
  1341. for (const KeyValue<real_t, Vector3> &E : midpoints[i]) {
  1342. pidx++;
  1343. bpw[pidx] = E.value;
  1344. }
  1345. pidx++;
  1346. bpw[pidx] = points[i + 1].position;
  1347. }
  1348. return tess;
  1349. }
  1350. void Curve3D::_bind_methods() {
  1351. ClassDB::bind_method(D_METHOD("get_point_count"), &Curve3D::get_point_count);
  1352. ClassDB::bind_method(D_METHOD("add_point", "position", "in", "out", "at_position"), &Curve3D::add_point, DEFVAL(Vector3()), DEFVAL(Vector3()), DEFVAL(-1));
  1353. ClassDB::bind_method(D_METHOD("set_point_position", "idx", "position"), &Curve3D::set_point_position);
  1354. ClassDB::bind_method(D_METHOD("get_point_position", "idx"), &Curve3D::get_point_position);
  1355. ClassDB::bind_method(D_METHOD("set_point_tilt", "idx", "tilt"), &Curve3D::set_point_tilt);
  1356. ClassDB::bind_method(D_METHOD("get_point_tilt", "idx"), &Curve3D::get_point_tilt);
  1357. ClassDB::bind_method(D_METHOD("set_point_in", "idx", "position"), &Curve3D::set_point_in);
  1358. ClassDB::bind_method(D_METHOD("get_point_in", "idx"), &Curve3D::get_point_in);
  1359. ClassDB::bind_method(D_METHOD("set_point_out", "idx", "position"), &Curve3D::set_point_out);
  1360. ClassDB::bind_method(D_METHOD("get_point_out", "idx"), &Curve3D::get_point_out);
  1361. ClassDB::bind_method(D_METHOD("remove_point", "idx"), &Curve3D::remove_point);
  1362. ClassDB::bind_method(D_METHOD("clear_points"), &Curve3D::clear_points);
  1363. ClassDB::bind_method(D_METHOD("interpolate", "idx", "t"), &Curve3D::interpolate);
  1364. ClassDB::bind_method(D_METHOD("interpolatef", "fofs"), &Curve3D::interpolatef);
  1365. //ClassDB::bind_method(D_METHOD("bake","subdivs"),&Curve3D::bake,DEFVAL(10));
  1366. ClassDB::bind_method(D_METHOD("set_bake_interval", "distance"), &Curve3D::set_bake_interval);
  1367. ClassDB::bind_method(D_METHOD("get_bake_interval"), &Curve3D::get_bake_interval);
  1368. ClassDB::bind_method(D_METHOD("set_up_vector_enabled", "enable"), &Curve3D::set_up_vector_enabled);
  1369. ClassDB::bind_method(D_METHOD("is_up_vector_enabled"), &Curve3D::is_up_vector_enabled);
  1370. ClassDB::bind_method(D_METHOD("get_baked_length"), &Curve3D::get_baked_length);
  1371. ClassDB::bind_method(D_METHOD("interpolate_baked", "offset", "cubic"), &Curve3D::interpolate_baked, DEFVAL(false));
  1372. ClassDB::bind_method(D_METHOD("interpolate_baked_up_vector", "offset", "apply_tilt"), &Curve3D::interpolate_baked_up_vector, DEFVAL(false));
  1373. ClassDB::bind_method(D_METHOD("get_baked_points"), &Curve3D::get_baked_points);
  1374. ClassDB::bind_method(D_METHOD("get_baked_tilts"), &Curve3D::get_baked_tilts);
  1375. ClassDB::bind_method(D_METHOD("get_baked_up_vectors"), &Curve3D::get_baked_up_vectors);
  1376. ClassDB::bind_method(D_METHOD("get_closest_point", "to_point"), &Curve3D::get_closest_point);
  1377. ClassDB::bind_method(D_METHOD("get_closest_offset", "to_point"), &Curve3D::get_closest_offset);
  1378. ClassDB::bind_method(D_METHOD("tessellate", "max_stages", "tolerance_degrees"), &Curve3D::tessellate, DEFVAL(5), DEFVAL(4));
  1379. ClassDB::bind_method(D_METHOD("_get_data"), &Curve3D::_get_data);
  1380. ClassDB::bind_method(D_METHOD("_set_data"), &Curve3D::_set_data);
  1381. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "bake_interval", PROPERTY_HINT_RANGE, "0.01,512,0.01"), "set_bake_interval", "get_bake_interval");
  1382. ADD_PROPERTY(PropertyInfo(Variant::INT, "_data", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR | PROPERTY_USAGE_INTERNAL), "_set_data", "_get_data");
  1383. ADD_GROUP("Up Vector", "up_vector_");
  1384. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "up_vector_enabled"), "set_up_vector_enabled", "is_up_vector_enabled");
  1385. }
  1386. Curve3D::Curve3D() {}