1 /** 2 Noise generator based on Open Simplex. 3 4 Copyright: 5 Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur. 6 Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md) 7 Copyright (c) 2017-2018 Godot-D contributors 8 9 License: $(LINK2 https://opensource.org/licenses/MIT, MIT License) 10 11 12 */ 13 module godot.opensimplexnoise; 14 import std.meta : AliasSeq, staticIndexOf; 15 import std.traits : Unqual; 16 import godot.d.traits; 17 import godot.core; 18 import godot.c; 19 import godot.d.bind; 20 import godot.d.reference; 21 import godot.globalenums; 22 import godot.object; 23 import godot.classdb; 24 import godot.resource; 25 import godot.image; 26 /** 27 Noise generator based on Open Simplex. 28 29 This resource allows you to configure and sample a fractal noise space. Here is a brief usage example that configures an OpenSimplexNoise and gets samples at various positions and dimensions: 30 31 32 var noise = OpenSimplexNoise.new() 33 34 # Configure 35 noise.seed = randi() 36 noise.octaves = 4 37 noise.period = 20.0 38 noise.persistence = 0.8 39 40 # Sample 41 print("Values:") 42 print(noise.get_noise_2d(1.0, 1.0)) 43 print(noise.get_noise_3d(0.5, 3.0, 15.0)) 44 print(noise.get_noise_4d(0.5, 1.9, 4.7, 0.0)) 45 46 47 */ 48 @GodotBaseClass struct OpenSimplexNoise 49 { 50 package(godot) enum string _GODOT_internal_name = "OpenSimplexNoise"; 51 public: 52 @nogc nothrow: 53 union { /** */ godot_object _godot_object; /** */ Resource _GODOT_base; } 54 alias _GODOT_base this; 55 alias BaseClasses = AliasSeq!(typeof(_GODOT_base), typeof(_GODOT_base).BaseClasses); 56 package(godot) __gshared bool _classBindingInitialized = false; 57 package(godot) static struct GDNativeClassBinding 58 { 59 __gshared: 60 @GodotName("get_image") GodotMethod!(Image, long, long) getImage; 61 @GodotName("get_lacunarity") GodotMethod!(double) getLacunarity; 62 @GodotName("get_noise_1d") GodotMethod!(double, double) getNoise1d; 63 @GodotName("get_noise_2d") GodotMethod!(double, double, double) getNoise2d; 64 @GodotName("get_noise_2dv") GodotMethod!(double, Vector2) getNoise2dv; 65 @GodotName("get_noise_3d") GodotMethod!(double, double, double, double) getNoise3d; 66 @GodotName("get_noise_3dv") GodotMethod!(double, Vector3) getNoise3dv; 67 @GodotName("get_noise_4d") GodotMethod!(double, double, double, double, double) getNoise4d; 68 @GodotName("get_octaves") GodotMethod!(long) getOctaves; 69 @GodotName("get_period") GodotMethod!(double) getPeriod; 70 @GodotName("get_persistence") GodotMethod!(double) getPersistence; 71 @GodotName("get_seamless_image") GodotMethod!(Image, long) getSeamlessImage; 72 @GodotName("get_seed") GodotMethod!(long) getSeed; 73 @GodotName("set_lacunarity") GodotMethod!(void, double) setLacunarity; 74 @GodotName("set_octaves") GodotMethod!(void, long) setOctaves; 75 @GodotName("set_period") GodotMethod!(void, double) setPeriod; 76 @GodotName("set_persistence") GodotMethod!(void, double) setPersistence; 77 @GodotName("set_seed") GodotMethod!(void, long) setSeed; 78 } 79 /// 80 pragma(inline, true) bool opEquals(in OpenSimplexNoise other) const 81 { return _godot_object.ptr is other._godot_object.ptr; } 82 /// 83 pragma(inline, true) typeof(null) opAssign(typeof(null) n) 84 { _godot_object.ptr = n; return null; } 85 /// 86 pragma(inline, true) bool opEquals(typeof(null) n) const 87 { return _godot_object.ptr is n; } 88 /// 89 size_t toHash() const @trusted { return cast(size_t)_godot_object.ptr; } 90 mixin baseCasts; 91 /// Construct a new instance of OpenSimplexNoise. 92 /// Note: use `memnew!OpenSimplexNoise` instead. 93 static OpenSimplexNoise _new() 94 { 95 static godot_class_constructor constructor; 96 if(constructor is null) constructor = _godot_api.godot_get_class_constructor("OpenSimplexNoise"); 97 if(constructor is null) return typeof(this).init; 98 return cast(OpenSimplexNoise)(constructor()); 99 } 100 @disable new(size_t s); 101 /** 102 Generate a noise image in $(D constant Image.FORMAT_L8) format with the requested `width` and `height`, based on the current noise parameters. 103 */ 104 Ref!Image getImage(in long width, in long height) const 105 { 106 checkClassBinding!(typeof(this))(); 107 return ptrcall!(Image)(GDNativeClassBinding.getImage, _godot_object, width, height); 108 } 109 /** 110 111 */ 112 double getLacunarity() const 113 { 114 checkClassBinding!(typeof(this))(); 115 return ptrcall!(double)(GDNativeClassBinding.getLacunarity, _godot_object); 116 } 117 /** 118 Returns the 1D noise value `$(D -1,1)` at the given x-coordinate. 119 $(B Note:) This method actually returns the 2D noise value `$(D -1,1)` with fixed y-coordinate value 0.0. 120 */ 121 double getNoise1d(in double x) const 122 { 123 checkClassBinding!(typeof(this))(); 124 return ptrcall!(double)(GDNativeClassBinding.getNoise1d, _godot_object, x); 125 } 126 /** 127 Returns the 2D noise value `$(D -1,1)` at the given position. 128 */ 129 double getNoise2d(in double x, in double y) const 130 { 131 checkClassBinding!(typeof(this))(); 132 return ptrcall!(double)(GDNativeClassBinding.getNoise2d, _godot_object, x, y); 133 } 134 /** 135 Returns the 2D noise value `$(D -1,1)` at the given position. 136 */ 137 double getNoise2dv(in Vector2 pos) const 138 { 139 checkClassBinding!(typeof(this))(); 140 return ptrcall!(double)(GDNativeClassBinding.getNoise2dv, _godot_object, pos); 141 } 142 /** 143 Returns the 3D noise value `$(D -1,1)` at the given position. 144 */ 145 double getNoise3d(in double x, in double y, in double z) const 146 { 147 checkClassBinding!(typeof(this))(); 148 return ptrcall!(double)(GDNativeClassBinding.getNoise3d, _godot_object, x, y, z); 149 } 150 /** 151 Returns the 3D noise value `$(D -1,1)` at the given position. 152 */ 153 double getNoise3dv(in Vector3 pos) const 154 { 155 checkClassBinding!(typeof(this))(); 156 return ptrcall!(double)(GDNativeClassBinding.getNoise3dv, _godot_object, pos); 157 } 158 /** 159 Returns the 4D noise value `$(D -1,1)` at the given position. 160 */ 161 double getNoise4d(in double x, in double y, in double z, in double w) const 162 { 163 checkClassBinding!(typeof(this))(); 164 return ptrcall!(double)(GDNativeClassBinding.getNoise4d, _godot_object, x, y, z, w); 165 } 166 /** 167 168 */ 169 long getOctaves() const 170 { 171 checkClassBinding!(typeof(this))(); 172 return ptrcall!(long)(GDNativeClassBinding.getOctaves, _godot_object); 173 } 174 /** 175 176 */ 177 double getPeriod() const 178 { 179 checkClassBinding!(typeof(this))(); 180 return ptrcall!(double)(GDNativeClassBinding.getPeriod, _godot_object); 181 } 182 /** 183 184 */ 185 double getPersistence() const 186 { 187 checkClassBinding!(typeof(this))(); 188 return ptrcall!(double)(GDNativeClassBinding.getPersistence, _godot_object); 189 } 190 /** 191 Generate a tileable noise image in $(D constant Image.FORMAT_L8) format, based on the current noise parameters. Generated seamless images are always square (`size` × `size`). 192 $(B Note:) Seamless noise has a lower contrast compared to non-seamless noise. This is due to the way noise uses higher dimensions for generating seamless noise. 193 */ 194 Ref!Image getSeamlessImage(in long size) const 195 { 196 checkClassBinding!(typeof(this))(); 197 return ptrcall!(Image)(GDNativeClassBinding.getSeamlessImage, _godot_object, size); 198 } 199 /** 200 201 */ 202 long getSeed() const 203 { 204 checkClassBinding!(typeof(this))(); 205 return ptrcall!(long)(GDNativeClassBinding.getSeed, _godot_object); 206 } 207 /** 208 209 */ 210 void setLacunarity(in double lacunarity) 211 { 212 checkClassBinding!(typeof(this))(); 213 ptrcall!(void)(GDNativeClassBinding.setLacunarity, _godot_object, lacunarity); 214 } 215 /** 216 217 */ 218 void setOctaves(in long octave_count) 219 { 220 checkClassBinding!(typeof(this))(); 221 ptrcall!(void)(GDNativeClassBinding.setOctaves, _godot_object, octave_count); 222 } 223 /** 224 225 */ 226 void setPeriod(in double period) 227 { 228 checkClassBinding!(typeof(this))(); 229 ptrcall!(void)(GDNativeClassBinding.setPeriod, _godot_object, period); 230 } 231 /** 232 233 */ 234 void setPersistence(in double persistence) 235 { 236 checkClassBinding!(typeof(this))(); 237 ptrcall!(void)(GDNativeClassBinding.setPersistence, _godot_object, persistence); 238 } 239 /** 240 241 */ 242 void setSeed(in long seed) 243 { 244 checkClassBinding!(typeof(this))(); 245 ptrcall!(void)(GDNativeClassBinding.setSeed, _godot_object, seed); 246 } 247 /** 248 Difference in period between $(D octaves). 249 */ 250 @property double lacunarity() 251 { 252 return getLacunarity(); 253 } 254 /// ditto 255 @property void lacunarity(double v) 256 { 257 setLacunarity(v); 258 } 259 /** 260 Number of OpenSimplex noise layers that are sampled to get the fractal noise. Higher values result in more detailed noise but take more time to generate. 261 $(B Note:) The maximum allowed value is 9. 262 */ 263 @property long octaves() 264 { 265 return getOctaves(); 266 } 267 /// ditto 268 @property void octaves(long v) 269 { 270 setOctaves(v); 271 } 272 /** 273 Period of the base octave. A lower period results in a higher-frequency noise (more value changes across the same distance). 274 */ 275 @property double period() 276 { 277 return getPeriod(); 278 } 279 /// ditto 280 @property void period(double v) 281 { 282 setPeriod(v); 283 } 284 /** 285 Contribution factor of the different octaves. A `persistence` value of 1 means all the octaves have the same contribution, a value of 0.5 means each octave contributes half as much as the previous one. 286 */ 287 @property double persistence() 288 { 289 return getPersistence(); 290 } 291 /// ditto 292 @property void persistence(double v) 293 { 294 setPersistence(v); 295 } 296 /** 297 Seed used to generate random values, different seeds will generate different noise maps. 298 */ 299 @property long seed() 300 { 301 return getSeed(); 302 } 303 /// ditto 304 @property void seed(long v) 305 { 306 setSeed(v); 307 } 308 }