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.meta;
17 import godot.core;
18 import godot.c;
19 import godot.d.bind;
20 import godot.d.reference;
21 import godot.object;
22 import godot.classdb;
23 import godot.resource;
24 import godot.image;
25 import godot.reference;
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 	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 _classBinding
58 	{
59 		__gshared:
60 		@GodotName("get_seed") GodotMethod!(long) getSeed;
61 		@GodotName("set_seed") GodotMethod!(void, long) setSeed;
62 		@GodotName("set_octaves") GodotMethod!(void, long) setOctaves;
63 		@GodotName("get_octaves") GodotMethod!(long) getOctaves;
64 		@GodotName("set_period") GodotMethod!(void, double) setPeriod;
65 		@GodotName("get_period") GodotMethod!(double) getPeriod;
66 		@GodotName("set_persistence") GodotMethod!(void, double) setPersistence;
67 		@GodotName("get_persistence") GodotMethod!(double) getPersistence;
68 		@GodotName("set_lacunarity") GodotMethod!(void, double) setLacunarity;
69 		@GodotName("get_lacunarity") GodotMethod!(double) getLacunarity;
70 		@GodotName("get_image") GodotMethod!(Image, long, long) getImage;
71 		@GodotName("get_seamless_image") GodotMethod!(Image, long) getSeamlessImage;
72 		@GodotName("get_noise_2d") GodotMethod!(double, double, double) getNoise2d;
73 		@GodotName("get_noise_3d") GodotMethod!(double, double, double, double) getNoise3d;
74 		@GodotName("get_noise_4d") GodotMethod!(double, double, double, double, double) getNoise4d;
75 		@GodotName("get_noise_2dv") GodotMethod!(double, Vector2) getNoise2dv;
76 		@GodotName("get_noise_3dv") GodotMethod!(double, Vector3) getNoise3dv;
77 	}
78 	bool opEquals(in OpenSimplexNoise other) const { return _godot_object.ptr is other._godot_object.ptr; }
79 	OpenSimplexNoise opAssign(T : typeof(null))(T n) { _godot_object.ptr = null; }
80 	bool opEquals(typeof(null) n) const { return _godot_object.ptr is null; }
81 	mixin baseCasts;
82 	static OpenSimplexNoise _new()
83 	{
84 		static godot_class_constructor constructor;
85 		if(constructor is null) constructor = _godot_api.godot_get_class_constructor("OpenSimplexNoise");
86 		if(constructor is null) return typeof(this).init;
87 		return cast(OpenSimplexNoise)(constructor());
88 	}
89 	@disable new(size_t s);
90 	/**
91 	
92 	*/
93 	long getSeed()
94 	{
95 		checkClassBinding!(typeof(this))();
96 		return ptrcall!(long)(_classBinding.getSeed, _godot_object);
97 	}
98 	/**
99 	
100 	*/
101 	void setSeed(in long seed)
102 	{
103 		checkClassBinding!(typeof(this))();
104 		ptrcall!(void)(_classBinding.setSeed, _godot_object, seed);
105 	}
106 	/**
107 	
108 	*/
109 	void setOctaves(in long octave_count)
110 	{
111 		checkClassBinding!(typeof(this))();
112 		ptrcall!(void)(_classBinding.setOctaves, _godot_object, octave_count);
113 	}
114 	/**
115 	
116 	*/
117 	long getOctaves() const
118 	{
119 		checkClassBinding!(typeof(this))();
120 		return ptrcall!(long)(_classBinding.getOctaves, _godot_object);
121 	}
122 	/**
123 	
124 	*/
125 	void setPeriod(in double period)
126 	{
127 		checkClassBinding!(typeof(this))();
128 		ptrcall!(void)(_classBinding.setPeriod, _godot_object, period);
129 	}
130 	/**
131 	
132 	*/
133 	double getPeriod() const
134 	{
135 		checkClassBinding!(typeof(this))();
136 		return ptrcall!(double)(_classBinding.getPeriod, _godot_object);
137 	}
138 	/**
139 	
140 	*/
141 	void setPersistence(in double persistence)
142 	{
143 		checkClassBinding!(typeof(this))();
144 		ptrcall!(void)(_classBinding.setPersistence, _godot_object, persistence);
145 	}
146 	/**
147 	
148 	*/
149 	double getPersistence() const
150 	{
151 		checkClassBinding!(typeof(this))();
152 		return ptrcall!(double)(_classBinding.getPersistence, _godot_object);
153 	}
154 	/**
155 	
156 	*/
157 	void setLacunarity(in double lacunarity)
158 	{
159 		checkClassBinding!(typeof(this))();
160 		ptrcall!(void)(_classBinding.setLacunarity, _godot_object, lacunarity);
161 	}
162 	/**
163 	
164 	*/
165 	double getLacunarity() const
166 	{
167 		checkClassBinding!(typeof(this))();
168 		return ptrcall!(double)(_classBinding.getLacunarity, _godot_object);
169 	}
170 	/**
171 	Generate a noise image with the requested `width` and `height`, based on the current noise parameters.
172 	*/
173 	Ref!Image getImage(in long width, in long height)
174 	{
175 		checkClassBinding!(typeof(this))();
176 		return ptrcall!(Image)(_classBinding.getImage, _godot_object, width, height);
177 	}
178 	/**
179 	Generate a tileable noise image, based on the current noise parameters. Generated seamless images are always square (`size` x `size`).
180 	*/
181 	Ref!Image getSeamlessImage(in long size)
182 	{
183 		checkClassBinding!(typeof(this))();
184 		return ptrcall!(Image)(_classBinding.getSeamlessImage, _godot_object, size);
185 	}
186 	/**
187 	Returns the 2D noise value `$(D -1,1)` at the given position.
188 	*/
189 	double getNoise2d(in double x, in double y)
190 	{
191 		checkClassBinding!(typeof(this))();
192 		return ptrcall!(double)(_classBinding.getNoise2d, _godot_object, x, y);
193 	}
194 	/**
195 	Returns the 3D noise value `$(D -1,1)` at the given position.
196 	*/
197 	double getNoise3d(in double x, in double y, in double z)
198 	{
199 		checkClassBinding!(typeof(this))();
200 		return ptrcall!(double)(_classBinding.getNoise3d, _godot_object, x, y, z);
201 	}
202 	/**
203 	Returns the 4D noise value `$(D -1,1)` at the given position.
204 	*/
205 	double getNoise4d(in double x, in double y, in double z, in double w)
206 	{
207 		checkClassBinding!(typeof(this))();
208 		return ptrcall!(double)(_classBinding.getNoise4d, _godot_object, x, y, z, w);
209 	}
210 	/**
211 	Returns the 2D noise value `$(D -1,1)` at the given position.
212 	*/
213 	double getNoise2dv(in Vector2 pos)
214 	{
215 		checkClassBinding!(typeof(this))();
216 		return ptrcall!(double)(_classBinding.getNoise2dv, _godot_object, pos);
217 	}
218 	/**
219 	Returns the 3D noise value `$(D -1,1)` at the given position.
220 	*/
221 	double getNoise3dv(in Vector3 pos)
222 	{
223 		checkClassBinding!(typeof(this))();
224 		return ptrcall!(double)(_classBinding.getNoise3dv, _godot_object, pos);
225 	}
226 	/**
227 	Seed used to generate random values, different seeds will generate different noise maps.
228 	*/
229 	@property long seed()
230 	{
231 		return getSeed();
232 	}
233 	/// ditto
234 	@property void seed(long v)
235 	{
236 		setSeed(v);
237 	}
238 	/**
239 	Number of OpenSimplex noise layers that are sampled to get the fractal noise.
240 	*/
241 	@property long octaves()
242 	{
243 		return getOctaves();
244 	}
245 	/// ditto
246 	@property void octaves(long v)
247 	{
248 		setOctaves(v);
249 	}
250 	/**
251 	Period of the base octave. A lower period results in a higher-frequency noise (more value changes across the same distance).
252 	*/
253 	@property double period()
254 	{
255 		return getPeriod();
256 	}
257 	/// ditto
258 	@property void period(double v)
259 	{
260 		setPeriod(v);
261 	}
262 	/**
263 	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.
264 	*/
265 	@property double persistence()
266 	{
267 		return getPersistence();
268 	}
269 	/// ditto
270 	@property void persistence(double v)
271 	{
272 		setPersistence(v);
273 	}
274 	/**
275 	Difference in period between $(D octaves).
276 	*/
277 	@property double lacunarity()
278 	{
279 		return getLacunarity();
280 	}
281 	/// ditto
282 	@property void lacunarity(double v)
283 	{
284 		setLacunarity(v);
285 	}
286 }