1 /** 2 $(D OpenSimplexNoise) filled texture. 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.noisetexture; 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.texture; 25 import godot.image; 26 import godot.opensimplexnoise; 27 /** 28 $(D OpenSimplexNoise) filled texture. 29 30 Uses an $(D OpenSimplexNoise) to fill the texture data. You can specify the texture size but keep in mind that larger textures will take longer to generate and seamless noise only works with square sized textures. 31 NoiseTexture can also generate normalmap textures. 32 The class uses $(D Thread)s to generate the texture data internally, so $(D Texture.getData) may return `null` if the generation process has not completed yet. In that case, you need to wait for the texture to be generated before accessing the data: 33 34 35 var texture = preload("res://noise.tres") 36 yield(texture, "changed") 37 var image = texture.get_data() 38 39 40 */ 41 @GodotBaseClass struct NoiseTexture 42 { 43 package(godot) enum string _GODOT_internal_name = "NoiseTexture"; 44 public: 45 @nogc nothrow: 46 union { /** */ godot_object _godot_object; /** */ Texture _GODOT_base; } 47 alias _GODOT_base this; 48 alias BaseClasses = AliasSeq!(typeof(_GODOT_base), typeof(_GODOT_base).BaseClasses); 49 package(godot) __gshared bool _classBindingInitialized = false; 50 package(godot) static struct GDNativeClassBinding 51 { 52 __gshared: 53 @GodotName("_generate_texture") GodotMethod!(Image) _generateTexture; 54 @GodotName("_queue_update") GodotMethod!(void) _queueUpdate; 55 @GodotName("_thread_done") GodotMethod!(void, Image) _threadDone; 56 @GodotName("_update_texture") GodotMethod!(void) _updateTexture; 57 @GodotName("get_bump_strength") GodotMethod!(double) getBumpStrength; 58 @GodotName("get_noise") GodotMethod!(OpenSimplexNoise) getNoise; 59 @GodotName("get_seamless") GodotMethod!(bool) getSeamless; 60 @GodotName("is_normalmap") GodotMethod!(bool) isNormalmap; 61 @GodotName("set_as_normalmap") GodotMethod!(void, bool) setAsNormalmap; 62 @GodotName("set_bump_strength") GodotMethod!(void, double) setBumpStrength; 63 @GodotName("set_height") GodotMethod!(void, long) setHeight; 64 @GodotName("set_noise") GodotMethod!(void, OpenSimplexNoise) setNoise; 65 @GodotName("set_seamless") GodotMethod!(void, bool) setSeamless; 66 @GodotName("set_width") GodotMethod!(void, long) setWidth; 67 } 68 /// 69 pragma(inline, true) bool opEquals(in NoiseTexture other) const 70 { return _godot_object.ptr is other._godot_object.ptr; } 71 /// 72 pragma(inline, true) typeof(null) opAssign(typeof(null) n) 73 { _godot_object.ptr = n; return null; } 74 /// 75 pragma(inline, true) bool opEquals(typeof(null) n) const 76 { return _godot_object.ptr is n; } 77 /// 78 size_t toHash() const @trusted { return cast(size_t)_godot_object.ptr; } 79 mixin baseCasts; 80 /// Construct a new instance of NoiseTexture. 81 /// Note: use `memnew!NoiseTexture` instead. 82 static NoiseTexture _new() 83 { 84 static godot_class_constructor constructor; 85 if(constructor is null) constructor = _godot_api.godot_get_class_constructor("NoiseTexture"); 86 if(constructor is null) return typeof(this).init; 87 return cast(NoiseTexture)(constructor()); 88 } 89 @disable new(size_t s); 90 /** 91 92 */ 93 Ref!Image _generateTexture() 94 { 95 Array _GODOT_args = Array.make(); 96 String _GODOT_method_name = String("_generate_texture"); 97 return this.callv(_GODOT_method_name, _GODOT_args).as!(RefOrT!Image); 98 } 99 /** 100 101 */ 102 void _queueUpdate() 103 { 104 Array _GODOT_args = Array.make(); 105 String _GODOT_method_name = String("_queue_update"); 106 this.callv(_GODOT_method_name, _GODOT_args); 107 } 108 /** 109 110 */ 111 void _threadDone(Image image) 112 { 113 Array _GODOT_args = Array.make(); 114 _GODOT_args.append(image); 115 String _GODOT_method_name = String("_thread_done"); 116 this.callv(_GODOT_method_name, _GODOT_args); 117 } 118 /** 119 120 */ 121 void _updateTexture() 122 { 123 Array _GODOT_args = Array.make(); 124 String _GODOT_method_name = String("_update_texture"); 125 this.callv(_GODOT_method_name, _GODOT_args); 126 } 127 /** 128 129 */ 130 double getBumpStrength() 131 { 132 checkClassBinding!(typeof(this))(); 133 return ptrcall!(double)(GDNativeClassBinding.getBumpStrength, _godot_object); 134 } 135 /** 136 137 */ 138 Ref!OpenSimplexNoise getNoise() 139 { 140 checkClassBinding!(typeof(this))(); 141 return ptrcall!(OpenSimplexNoise)(GDNativeClassBinding.getNoise, _godot_object); 142 } 143 /** 144 145 */ 146 bool getSeamless() 147 { 148 checkClassBinding!(typeof(this))(); 149 return ptrcall!(bool)(GDNativeClassBinding.getSeamless, _godot_object); 150 } 151 /** 152 153 */ 154 bool isNormalmap() 155 { 156 checkClassBinding!(typeof(this))(); 157 return ptrcall!(bool)(GDNativeClassBinding.isNormalmap, _godot_object); 158 } 159 /** 160 161 */ 162 void setAsNormalmap(in bool as_normalmap) 163 { 164 checkClassBinding!(typeof(this))(); 165 ptrcall!(void)(GDNativeClassBinding.setAsNormalmap, _godot_object, as_normalmap); 166 } 167 /** 168 169 */ 170 void setBumpStrength(in double bump_strength) 171 { 172 checkClassBinding!(typeof(this))(); 173 ptrcall!(void)(GDNativeClassBinding.setBumpStrength, _godot_object, bump_strength); 174 } 175 /** 176 177 */ 178 void setHeight(in long height) 179 { 180 checkClassBinding!(typeof(this))(); 181 ptrcall!(void)(GDNativeClassBinding.setHeight, _godot_object, height); 182 } 183 /** 184 185 */ 186 void setNoise(OpenSimplexNoise noise) 187 { 188 checkClassBinding!(typeof(this))(); 189 ptrcall!(void)(GDNativeClassBinding.setNoise, _godot_object, noise); 190 } 191 /** 192 193 */ 194 void setSeamless(in bool seamless) 195 { 196 checkClassBinding!(typeof(this))(); 197 ptrcall!(void)(GDNativeClassBinding.setSeamless, _godot_object, seamless); 198 } 199 /** 200 201 */ 202 void setWidth(in long width) 203 { 204 checkClassBinding!(typeof(this))(); 205 ptrcall!(void)(GDNativeClassBinding.setWidth, _godot_object, width); 206 } 207 /** 208 If `true`, the resulting texture contains a normal map created from the original noise interpreted as a bump map. 209 */ 210 @property bool asNormalmap() 211 { 212 return isNormalmap(); 213 } 214 /// ditto 215 @property void asNormalmap(bool v) 216 { 217 setAsNormalmap(v); 218 } 219 /** 220 Strength of the bump maps used in this texture. A higher value will make the bump maps appear larger while a lower value will make them appear softer. 221 */ 222 @property double bumpStrength() 223 { 224 return getBumpStrength(); 225 } 226 /// ditto 227 @property void bumpStrength(double v) 228 { 229 setBumpStrength(v); 230 } 231 /** 232 Height of the generated texture. 233 */ 234 @property long height() 235 { 236 return getHeight(); 237 } 238 /// ditto 239 @property void height(long v) 240 { 241 setHeight(v); 242 } 243 /** 244 The $(D OpenSimplexNoise) instance used to generate the noise. 245 */ 246 @property OpenSimplexNoise noise() 247 { 248 return getNoise(); 249 } 250 /// ditto 251 @property void noise(OpenSimplexNoise v) 252 { 253 setNoise(v); 254 } 255 /** 256 Whether the texture can be tiled without visible seams or not. Seamless textures take longer to generate. 257 $(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. 258 */ 259 @property bool seamless() 260 { 261 return getSeamless(); 262 } 263 /// ditto 264 @property void seamless(bool v) 265 { 266 setSeamless(v); 267 } 268 /** 269 Width of the generated texture. 270 */ 271 @property long width() 272 { 273 return getWidth(); 274 } 275 /// ditto 276 @property void width(long v) 277 { 278 setWidth(v); 279 } 280 }