fastnoise_lite.cpp 20 KB

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