fastnoise_lite.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500
  1. /**************************************************************************/
  2. /* fastnoise_lite.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 "fastnoise_lite.h"
  31. _FastNoiseLite::FractalType FastNoiseLite::_convert_domain_warp_fractal_type_enum(DomainWarpFractalType p_domain_warp_fractal_type) {
  32. _FastNoiseLite::FractalType type;
  33. switch (p_domain_warp_fractal_type) {
  34. case DOMAIN_WARP_FRACTAL_NONE:
  35. type = _FastNoiseLite::FractalType_None;
  36. break;
  37. case DOMAIN_WARP_FRACTAL_PROGRESSIVE:
  38. type = _FastNoiseLite::FractalType_DomainWarpProgressive;
  39. break;
  40. case DOMAIN_WARP_FRACTAL_INDEPENDENT:
  41. type = _FastNoiseLite::FractalType_DomainWarpIndependent;
  42. break;
  43. default:
  44. type = _FastNoiseLite::FractalType_None;
  45. }
  46. return type;
  47. }
  48. FastNoiseLite::FastNoiseLite() {
  49. _noise.SetNoiseType((_FastNoiseLite::NoiseType)noise_type);
  50. _noise.SetSeed(seed);
  51. _noise.SetFrequency(frequency);
  52. _noise.SetFractalType((_FastNoiseLite::FractalType)fractal_type);
  53. _noise.SetFractalOctaves(fractal_octaves);
  54. _noise.SetFractalLacunarity(fractal_lacunarity);
  55. _noise.SetFractalGain(fractal_gain);
  56. _noise.SetFractalWeightedStrength(fractal_weighted_strength);
  57. _noise.SetFractalPingPongStrength(fractal_ping_pong_strength);
  58. _noise.SetCellularDistanceFunction((_FastNoiseLite::CellularDistanceFunction)cellular_distance_function);
  59. _noise.SetCellularReturnType((_FastNoiseLite::CellularReturnType)cellular_return_type);
  60. _noise.SetCellularJitter(cellular_jitter);
  61. _domain_warp_noise.SetDomainWarpType((_FastNoiseLite::DomainWarpType)domain_warp_type);
  62. _domain_warp_noise.SetSeed(seed);
  63. _domain_warp_noise.SetDomainWarpAmp(domain_warp_amplitude);
  64. _domain_warp_noise.SetFrequency(domain_warp_frequency);
  65. _domain_warp_noise.SetFractalType(_convert_domain_warp_fractal_type_enum(domain_warp_fractal_type));
  66. _domain_warp_noise.SetFractalOctaves(domain_warp_fractal_octaves);
  67. _domain_warp_noise.SetFractalLacunarity(domain_warp_fractal_lacunarity);
  68. _domain_warp_noise.SetFractalGain(domain_warp_fractal_gain);
  69. }
  70. FastNoiseLite::~FastNoiseLite() {
  71. }
  72. // General settings.
  73. void FastNoiseLite::set_noise_type(NoiseType p_noise_type) {
  74. noise_type = p_noise_type;
  75. _noise.SetNoiseType((_FastNoiseLite::NoiseType)p_noise_type);
  76. emit_changed();
  77. notify_property_list_changed();
  78. }
  79. FastNoiseLite::NoiseType FastNoiseLite::get_noise_type() const {
  80. return noise_type;
  81. }
  82. void FastNoiseLite::set_seed(int p_seed) {
  83. seed = p_seed;
  84. _noise.SetSeed(p_seed);
  85. _domain_warp_noise.SetSeed(p_seed);
  86. emit_changed();
  87. }
  88. int FastNoiseLite::get_seed() const {
  89. return seed;
  90. }
  91. void FastNoiseLite::set_frequency(real_t p_freq) {
  92. frequency = p_freq;
  93. _noise.SetFrequency(p_freq);
  94. emit_changed();
  95. }
  96. real_t FastNoiseLite::get_frequency() const {
  97. return frequency;
  98. }
  99. void FastNoiseLite::set_offset(Vector3 p_offset) {
  100. offset = p_offset;
  101. emit_changed();
  102. }
  103. Vector3 FastNoiseLite::get_offset() const {
  104. return offset;
  105. }
  106. // Fractal.
  107. void FastNoiseLite::set_fractal_type(FractalType p_type) {
  108. fractal_type = p_type;
  109. _noise.SetFractalType((_FastNoiseLite::FractalType)p_type);
  110. emit_changed();
  111. notify_property_list_changed();
  112. }
  113. FastNoiseLite::FractalType FastNoiseLite::get_fractal_type() const {
  114. return fractal_type;
  115. }
  116. void FastNoiseLite::set_fractal_octaves(int p_octaves) {
  117. fractal_octaves = p_octaves;
  118. _noise.SetFractalOctaves(p_octaves);
  119. emit_changed();
  120. }
  121. int FastNoiseLite::get_fractal_octaves() const {
  122. return fractal_octaves;
  123. }
  124. void FastNoiseLite::set_fractal_lacunarity(real_t p_lacunarity) {
  125. fractal_lacunarity = p_lacunarity;
  126. _noise.SetFractalLacunarity(p_lacunarity);
  127. emit_changed();
  128. }
  129. real_t FastNoiseLite::get_fractal_lacunarity() const {
  130. return fractal_lacunarity;
  131. }
  132. void FastNoiseLite::set_fractal_gain(real_t p_gain) {
  133. fractal_gain = p_gain;
  134. _noise.SetFractalGain(p_gain);
  135. emit_changed();
  136. }
  137. real_t FastNoiseLite::get_fractal_gain() const {
  138. return fractal_gain;
  139. }
  140. void FastNoiseLite::set_fractal_weighted_strength(real_t p_weighted_strength) {
  141. fractal_weighted_strength = p_weighted_strength;
  142. _noise.SetFractalWeightedStrength(p_weighted_strength);
  143. emit_changed();
  144. }
  145. real_t FastNoiseLite::get_fractal_weighted_strength() const {
  146. return fractal_weighted_strength;
  147. }
  148. void FastNoiseLite::set_fractal_ping_pong_strength(real_t p_ping_pong_strength) {
  149. fractal_ping_pong_strength = p_ping_pong_strength;
  150. _noise.SetFractalPingPongStrength(p_ping_pong_strength);
  151. emit_changed();
  152. }
  153. real_t FastNoiseLite::get_fractal_ping_pong_strength() const {
  154. return fractal_ping_pong_strength;
  155. }
  156. // Cellular.
  157. void FastNoiseLite::set_cellular_distance_function(CellularDistanceFunction p_func) {
  158. cellular_distance_function = p_func;
  159. _noise.SetCellularDistanceFunction((_FastNoiseLite::CellularDistanceFunction)p_func);
  160. emit_changed();
  161. }
  162. FastNoiseLite::CellularDistanceFunction FastNoiseLite::get_cellular_distance_function() const {
  163. return cellular_distance_function;
  164. }
  165. void FastNoiseLite::set_cellular_jitter(real_t p_jitter) {
  166. cellular_jitter = p_jitter;
  167. _noise.SetCellularJitter(p_jitter);
  168. emit_changed();
  169. }
  170. real_t FastNoiseLite::get_cellular_jitter() const {
  171. return cellular_jitter;
  172. }
  173. void FastNoiseLite::set_cellular_return_type(CellularReturnType p_ret) {
  174. cellular_return_type = p_ret;
  175. _noise.SetCellularReturnType((_FastNoiseLite::CellularReturnType)p_ret);
  176. emit_changed();
  177. }
  178. FastNoiseLite::CellularReturnType FastNoiseLite::get_cellular_return_type() const {
  179. return cellular_return_type;
  180. }
  181. // Domain warp specific.
  182. void FastNoiseLite::set_domain_warp_enabled(bool p_enabled) {
  183. if (domain_warp_enabled != p_enabled) {
  184. domain_warp_enabled = p_enabled;
  185. emit_changed();
  186. notify_property_list_changed();
  187. }
  188. }
  189. bool FastNoiseLite::is_domain_warp_enabled() const {
  190. return domain_warp_enabled;
  191. }
  192. void FastNoiseLite::set_domain_warp_type(DomainWarpType p_domain_warp_type) {
  193. domain_warp_type = p_domain_warp_type;
  194. _domain_warp_noise.SetDomainWarpType((_FastNoiseLite::DomainWarpType)p_domain_warp_type);
  195. emit_changed();
  196. }
  197. FastNoiseLite::DomainWarpType FastNoiseLite::get_domain_warp_type() const {
  198. return domain_warp_type;
  199. }
  200. void FastNoiseLite::set_domain_warp_amplitude(real_t p_amplitude) {
  201. domain_warp_amplitude = p_amplitude;
  202. _domain_warp_noise.SetDomainWarpAmp(p_amplitude);
  203. emit_changed();
  204. }
  205. real_t FastNoiseLite::get_domain_warp_amplitude() const {
  206. return domain_warp_amplitude;
  207. }
  208. void FastNoiseLite::set_domain_warp_frequency(real_t p_frequency) {
  209. domain_warp_frequency = p_frequency;
  210. _domain_warp_noise.SetFrequency(p_frequency);
  211. emit_changed();
  212. }
  213. real_t FastNoiseLite::get_domain_warp_frequency() const {
  214. return domain_warp_frequency;
  215. }
  216. void FastNoiseLite::set_domain_warp_fractal_type(DomainWarpFractalType p_domain_warp_fractal_type) {
  217. domain_warp_fractal_type = p_domain_warp_fractal_type;
  218. _domain_warp_noise.SetFractalType(_convert_domain_warp_fractal_type_enum(p_domain_warp_fractal_type));
  219. emit_changed();
  220. }
  221. FastNoiseLite::DomainWarpFractalType FastNoiseLite::get_domain_warp_fractal_type() const {
  222. return domain_warp_fractal_type;
  223. }
  224. void FastNoiseLite::set_domain_warp_fractal_octaves(int p_octaves) {
  225. domain_warp_fractal_octaves = p_octaves;
  226. _domain_warp_noise.SetFractalOctaves(p_octaves);
  227. emit_changed();
  228. }
  229. int FastNoiseLite::get_domain_warp_fractal_octaves() const {
  230. return domain_warp_fractal_octaves;
  231. }
  232. void FastNoiseLite::set_domain_warp_fractal_lacunarity(real_t p_lacunarity) {
  233. domain_warp_fractal_lacunarity = p_lacunarity;
  234. _domain_warp_noise.SetFractalLacunarity(p_lacunarity);
  235. emit_changed();
  236. }
  237. real_t FastNoiseLite::get_domain_warp_fractal_lacunarity() const {
  238. return domain_warp_fractal_lacunarity;
  239. }
  240. void FastNoiseLite::set_domain_warp_fractal_gain(real_t p_gain) {
  241. domain_warp_fractal_gain = p_gain;
  242. _domain_warp_noise.SetFractalGain(p_gain);
  243. emit_changed();
  244. }
  245. real_t FastNoiseLite::get_domain_warp_fractal_gain() const {
  246. return domain_warp_fractal_gain;
  247. }
  248. // Noise interface functions.
  249. real_t FastNoiseLite::get_noise_1d(real_t p_x) const {
  250. p_x += offset.x;
  251. if (domain_warp_enabled) {
  252. // Needed since DomainWarp expects a reference.
  253. real_t y_dummy = 0;
  254. _domain_warp_noise.DomainWarp(p_x, y_dummy);
  255. }
  256. return get_noise_2d(p_x, 0.0);
  257. }
  258. real_t FastNoiseLite::get_noise_2dv(Vector2 p_v) const {
  259. return get_noise_2d(p_v.x, p_v.y);
  260. }
  261. real_t FastNoiseLite::get_noise_2d(real_t p_x, real_t p_y) const {
  262. p_x += offset.x;
  263. p_y += offset.y;
  264. if (domain_warp_enabled) {
  265. _domain_warp_noise.DomainWarp(p_x, p_y);
  266. }
  267. return _noise.GetNoise(p_x, p_y);
  268. }
  269. real_t FastNoiseLite::get_noise_3dv(Vector3 p_v) const {
  270. return get_noise_3d(p_v.x, p_v.y, p_v.z);
  271. }
  272. real_t FastNoiseLite::get_noise_3d(real_t p_x, real_t p_y, real_t p_z) const {
  273. p_x += offset.x;
  274. p_y += offset.y;
  275. p_z += offset.z;
  276. if (domain_warp_enabled) {
  277. _domain_warp_noise.DomainWarp(p_x, p_y, p_z);
  278. }
  279. return _noise.GetNoise(p_x, p_y, p_z);
  280. }
  281. void FastNoiseLite::_changed() {
  282. emit_changed();
  283. }
  284. void FastNoiseLite::_bind_methods() {
  285. // General settings.
  286. ClassDB::bind_method(D_METHOD("set_noise_type", "type"), &FastNoiseLite::set_noise_type);
  287. ClassDB::bind_method(D_METHOD("get_noise_type"), &FastNoiseLite::get_noise_type);
  288. ClassDB::bind_method(D_METHOD("set_seed", "seed"), &FastNoiseLite::set_seed);
  289. ClassDB::bind_method(D_METHOD("get_seed"), &FastNoiseLite::get_seed);
  290. ClassDB::bind_method(D_METHOD("set_frequency", "freq"), &FastNoiseLite::set_frequency);
  291. ClassDB::bind_method(D_METHOD("get_frequency"), &FastNoiseLite::get_frequency);
  292. ClassDB::bind_method(D_METHOD("set_offset", "offset"), &FastNoiseLite::set_offset);
  293. ClassDB::bind_method(D_METHOD("get_offset"), &FastNoiseLite::get_offset);
  294. // Fractal.
  295. ClassDB::bind_method(D_METHOD("set_fractal_type", "type"), &FastNoiseLite::set_fractal_type);
  296. ClassDB::bind_method(D_METHOD("get_fractal_type"), &FastNoiseLite::get_fractal_type);
  297. ClassDB::bind_method(D_METHOD("set_fractal_octaves", "octave_count"), &FastNoiseLite::set_fractal_octaves);
  298. ClassDB::bind_method(D_METHOD("get_fractal_octaves"), &FastNoiseLite::get_fractal_octaves);
  299. ClassDB::bind_method(D_METHOD("set_fractal_lacunarity", "lacunarity"), &FastNoiseLite::set_fractal_lacunarity);
  300. ClassDB::bind_method(D_METHOD("get_fractal_lacunarity"), &FastNoiseLite::get_fractal_lacunarity);
  301. ClassDB::bind_method(D_METHOD("set_fractal_gain", "gain"), &FastNoiseLite::set_fractal_gain);
  302. ClassDB::bind_method(D_METHOD("get_fractal_gain"), &FastNoiseLite::get_fractal_gain);
  303. ClassDB::bind_method(D_METHOD("set_fractal_weighted_strength", "weighted_strength"), &FastNoiseLite::set_fractal_weighted_strength);
  304. ClassDB::bind_method(D_METHOD("get_fractal_weighted_strength"), &FastNoiseLite::get_fractal_weighted_strength);
  305. ClassDB::bind_method(D_METHOD("set_fractal_ping_pong_strength", "ping_pong_strength"), &FastNoiseLite::set_fractal_ping_pong_strength);
  306. ClassDB::bind_method(D_METHOD("get_fractal_ping_pong_strength"), &FastNoiseLite::get_fractal_ping_pong_strength);
  307. // Cellular.
  308. ClassDB::bind_method(D_METHOD("set_cellular_distance_function", "func"), &FastNoiseLite::set_cellular_distance_function);
  309. ClassDB::bind_method(D_METHOD("get_cellular_distance_function"), &FastNoiseLite::get_cellular_distance_function);
  310. ClassDB::bind_method(D_METHOD("set_cellular_jitter", "jitter"), &FastNoiseLite::set_cellular_jitter);
  311. ClassDB::bind_method(D_METHOD("get_cellular_jitter"), &FastNoiseLite::get_cellular_jitter);
  312. ClassDB::bind_method(D_METHOD("set_cellular_return_type", "ret"), &FastNoiseLite::set_cellular_return_type);
  313. ClassDB::bind_method(D_METHOD("get_cellular_return_type"), &FastNoiseLite::get_cellular_return_type);
  314. // Domain warp.
  315. ClassDB::bind_method(D_METHOD("set_domain_warp_enabled", "domain_warp_enabled"), &FastNoiseLite::set_domain_warp_enabled);
  316. ClassDB::bind_method(D_METHOD("is_domain_warp_enabled"), &FastNoiseLite::is_domain_warp_enabled);
  317. ClassDB::bind_method(D_METHOD("set_domain_warp_type", "domain_warp_type"), &FastNoiseLite::set_domain_warp_type);
  318. ClassDB::bind_method(D_METHOD("get_domain_warp_type"), &FastNoiseLite::get_domain_warp_type);
  319. ClassDB::bind_method(D_METHOD("set_domain_warp_amplitude", "domain_warp_amplitude"), &FastNoiseLite::set_domain_warp_amplitude);
  320. ClassDB::bind_method(D_METHOD("get_domain_warp_amplitude"), &FastNoiseLite::get_domain_warp_amplitude);
  321. ClassDB::bind_method(D_METHOD("set_domain_warp_frequency", "domain_warp_frequency"), &FastNoiseLite::set_domain_warp_frequency);
  322. ClassDB::bind_method(D_METHOD("get_domain_warp_frequency"), &FastNoiseLite::get_domain_warp_frequency);
  323. ClassDB::bind_method(D_METHOD("set_domain_warp_fractal_type", "domain_warp_fractal_type"), &FastNoiseLite::set_domain_warp_fractal_type);
  324. ClassDB::bind_method(D_METHOD("get_domain_warp_fractal_type"), &FastNoiseLite::get_domain_warp_fractal_type);
  325. ClassDB::bind_method(D_METHOD("set_domain_warp_fractal_octaves", "domain_warp_octave_count"), &FastNoiseLite::set_domain_warp_fractal_octaves);
  326. ClassDB::bind_method(D_METHOD("get_domain_warp_fractal_octaves"), &FastNoiseLite::get_domain_warp_fractal_octaves);
  327. ClassDB::bind_method(D_METHOD("set_domain_warp_fractal_lacunarity", "domain_warp_lacunarity"), &FastNoiseLite::set_domain_warp_fractal_lacunarity);
  328. ClassDB::bind_method(D_METHOD("get_domain_warp_fractal_lacunarity"), &FastNoiseLite::get_domain_warp_fractal_lacunarity);
  329. ClassDB::bind_method(D_METHOD("set_domain_warp_fractal_gain", "domain_warp_gain"), &FastNoiseLite::set_domain_warp_fractal_gain);
  330. ClassDB::bind_method(D_METHOD("get_domain_warp_fractal_gain"), &FastNoiseLite::get_domain_warp_fractal_gain);
  331. ClassDB::bind_method(D_METHOD("_changed"), &FastNoiseLite::_changed);
  332. ADD_PROPERTY(PropertyInfo(Variant::INT, "noise_type", PROPERTY_HINT_ENUM, "Simplex,Simplex Smooth,Cellular,Perlin,Value Cubic,Value"), "set_noise_type", "get_noise_type");
  333. ADD_PROPERTY(PropertyInfo(Variant::INT, "seed"), "set_seed", "get_seed");
  334. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "frequency", PROPERTY_HINT_RANGE, ".0001,1,.0001,exp"), "set_frequency", "get_frequency");
  335. ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "offset", PROPERTY_HINT_RANGE, "-1000,1000,0.01,or_less,or_greater"), "set_offset", "get_offset");
  336. ADD_GROUP("Fractal", "fractal_");
  337. ADD_PROPERTY(PropertyInfo(Variant::INT, "fractal_type", PROPERTY_HINT_ENUM, "None,FBM,Ridged,Ping-Pong"), "set_fractal_type", "get_fractal_type");
  338. ADD_PROPERTY(PropertyInfo(Variant::INT, "fractal_octaves", PROPERTY_HINT_RANGE, "1,10,1"), "set_fractal_octaves", "get_fractal_octaves");
  339. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "fractal_lacunarity"), "set_fractal_lacunarity", "get_fractal_lacunarity");
  340. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "fractal_gain"), "set_fractal_gain", "get_fractal_gain");
  341. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "fractal_weighted_strength", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_fractal_weighted_strength", "get_fractal_weighted_strength");
  342. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "fractal_ping_pong_strength"), "set_fractal_ping_pong_strength", "get_fractal_ping_pong_strength");
  343. ADD_GROUP("Cellular", "cellular_");
  344. ADD_PROPERTY(PropertyInfo(Variant::INT, "cellular_distance_function", PROPERTY_HINT_ENUM, "Euclidean,Euclidean Squared,Manhattan,Hybrid"), "set_cellular_distance_function", "get_cellular_distance_function");
  345. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "cellular_jitter"), "set_cellular_jitter", "get_cellular_jitter");
  346. ADD_PROPERTY(PropertyInfo(Variant::INT, "cellular_return_type", PROPERTY_HINT_ENUM, "Cell Value,Distance,Distance2,Distance2Add,Distance2Sub,Distance2Mul,Distance2Div"), "set_cellular_return_type", "get_cellular_return_type");
  347. ADD_GROUP("Domain Warp", "domain_warp_");
  348. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "domain_warp_enabled"), "set_domain_warp_enabled", "is_domain_warp_enabled");
  349. ADD_PROPERTY(PropertyInfo(Variant::INT, "domain_warp_type", PROPERTY_HINT_ENUM, "Simplex,Simplex Reduced,Basic Grid"), "set_domain_warp_type", "get_domain_warp_type");
  350. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "domain_warp_amplitude"), "set_domain_warp_amplitude", "get_domain_warp_amplitude");
  351. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "domain_warp_frequency"), "set_domain_warp_frequency", "get_domain_warp_frequency");
  352. ADD_PROPERTY(PropertyInfo(Variant::INT, "domain_warp_fractal_type", PROPERTY_HINT_ENUM, "None,Progressive,Independent"), "set_domain_warp_fractal_type", "get_domain_warp_fractal_type");
  353. ADD_PROPERTY(PropertyInfo(Variant::INT, "domain_warp_fractal_octaves", PROPERTY_HINT_RANGE, "1,10,1"), "set_domain_warp_fractal_octaves", "get_domain_warp_fractal_octaves");
  354. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "domain_warp_fractal_lacunarity"), "set_domain_warp_fractal_lacunarity", "get_domain_warp_fractal_lacunarity");
  355. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "domain_warp_fractal_gain"), "set_domain_warp_fractal_gain", "get_domain_warp_fractal_gain");
  356. BIND_ENUM_CONSTANT(TYPE_VALUE);
  357. BIND_ENUM_CONSTANT(TYPE_VALUE_CUBIC);
  358. BIND_ENUM_CONSTANT(TYPE_PERLIN);
  359. BIND_ENUM_CONSTANT(TYPE_CELLULAR);
  360. BIND_ENUM_CONSTANT(TYPE_SIMPLEX);
  361. BIND_ENUM_CONSTANT(TYPE_SIMPLEX_SMOOTH);
  362. BIND_ENUM_CONSTANT(FRACTAL_NONE);
  363. BIND_ENUM_CONSTANT(FRACTAL_FBM);
  364. BIND_ENUM_CONSTANT(FRACTAL_RIDGED);
  365. BIND_ENUM_CONSTANT(FRACTAL_PING_PONG);
  366. BIND_ENUM_CONSTANT(DISTANCE_EUCLIDEAN);
  367. BIND_ENUM_CONSTANT(DISTANCE_EUCLIDEAN_SQUARED);
  368. BIND_ENUM_CONSTANT(DISTANCE_MANHATTAN);
  369. BIND_ENUM_CONSTANT(DISTANCE_HYBRID);
  370. BIND_ENUM_CONSTANT(RETURN_CELL_VALUE);
  371. BIND_ENUM_CONSTANT(RETURN_DISTANCE);
  372. BIND_ENUM_CONSTANT(RETURN_DISTANCE2);
  373. BIND_ENUM_CONSTANT(RETURN_DISTANCE2_ADD);
  374. BIND_ENUM_CONSTANT(RETURN_DISTANCE2_SUB);
  375. BIND_ENUM_CONSTANT(RETURN_DISTANCE2_MUL);
  376. BIND_ENUM_CONSTANT(RETURN_DISTANCE2_DIV);
  377. BIND_ENUM_CONSTANT(DOMAIN_WARP_SIMPLEX);
  378. BIND_ENUM_CONSTANT(DOMAIN_WARP_SIMPLEX_REDUCED);
  379. BIND_ENUM_CONSTANT(DOMAIN_WARP_BASIC_GRID);
  380. BIND_ENUM_CONSTANT(DOMAIN_WARP_FRACTAL_NONE);
  381. BIND_ENUM_CONSTANT(DOMAIN_WARP_FRACTAL_PROGRESSIVE);
  382. BIND_ENUM_CONSTANT(DOMAIN_WARP_FRACTAL_INDEPENDENT);
  383. }
  384. void FastNoiseLite::_validate_property(PropertyInfo &p_property) const {
  385. if (p_property.name.begins_with("cellular") && get_noise_type() != TYPE_CELLULAR) {
  386. p_property.usage = PROPERTY_USAGE_NO_EDITOR;
  387. return;
  388. }
  389. if (p_property.name != "fractal_type" && p_property.name.begins_with("fractal") && get_fractal_type() == FRACTAL_NONE) {
  390. p_property.usage = PROPERTY_USAGE_NO_EDITOR;
  391. return;
  392. }
  393. if (p_property.name == "fractal_ping_pong_strength" && get_fractal_type() != FRACTAL_PING_PONG) {
  394. p_property.usage = PROPERTY_USAGE_NO_EDITOR;
  395. return;
  396. }
  397. if (p_property.name != "domain_warp_enabled" && p_property.name.begins_with("domain_warp") && !domain_warp_enabled) {
  398. p_property.usage = PROPERTY_USAGE_NO_EDITOR;
  399. return;
  400. }
  401. }