1 /** 2 2D sprite node in a 3D world. 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.sprite3d; 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.spritebase3d; 25 import godot.texture; 26 /** 27 2D sprite node in a 3D world. 28 29 A node that displays a 2D texture in a 3D environment. The texture displayed can be a region from a larger atlas texture, or a frame from a sprite sheet animation. 30 */ 31 @GodotBaseClass struct Sprite3D 32 { 33 package(godot) enum string _GODOT_internal_name = "Sprite3D"; 34 public: 35 @nogc nothrow: 36 union { /** */ godot_object _godot_object; /** */ SpriteBase3D _GODOT_base; } 37 alias _GODOT_base this; 38 alias BaseClasses = AliasSeq!(typeof(_GODOT_base), typeof(_GODOT_base).BaseClasses); 39 package(godot) __gshared bool _classBindingInitialized = false; 40 package(godot) static struct GDNativeClassBinding 41 { 42 __gshared: 43 @GodotName("get_frame") GodotMethod!(long) getFrame; 44 @GodotName("get_frame_coords") GodotMethod!(Vector2) getFrameCoords; 45 @GodotName("get_hframes") GodotMethod!(long) getHframes; 46 @GodotName("get_region_rect") GodotMethod!(Rect2) getRegionRect; 47 @GodotName("get_texture") GodotMethod!(Texture) getTexture; 48 @GodotName("get_vframes") GodotMethod!(long) getVframes; 49 @GodotName("is_region") GodotMethod!(bool) isRegion; 50 @GodotName("set_frame") GodotMethod!(void, long) setFrame; 51 @GodotName("set_frame_coords") GodotMethod!(void, Vector2) setFrameCoords; 52 @GodotName("set_hframes") GodotMethod!(void, long) setHframes; 53 @GodotName("set_region") GodotMethod!(void, bool) setRegion; 54 @GodotName("set_region_rect") GodotMethod!(void, Rect2) setRegionRect; 55 @GodotName("set_texture") GodotMethod!(void, Texture) setTexture; 56 @GodotName("set_vframes") GodotMethod!(void, long) setVframes; 57 } 58 /// 59 pragma(inline, true) bool opEquals(in Sprite3D other) const 60 { return _godot_object.ptr is other._godot_object.ptr; } 61 /// 62 pragma(inline, true) typeof(null) opAssign(typeof(null) n) 63 { _godot_object.ptr = n; return null; } 64 /// 65 pragma(inline, true) bool opEquals(typeof(null) n) const 66 { return _godot_object.ptr is n; } 67 /// 68 size_t toHash() const @trusted { return cast(size_t)_godot_object.ptr; } 69 mixin baseCasts; 70 /// Construct a new instance of Sprite3D. 71 /// Note: use `memnew!Sprite3D` instead. 72 static Sprite3D _new() 73 { 74 static godot_class_constructor constructor; 75 if(constructor is null) constructor = _godot_api.godot_get_class_constructor("Sprite3D"); 76 if(constructor is null) return typeof(this).init; 77 return cast(Sprite3D)(constructor()); 78 } 79 @disable new(size_t s); 80 /** 81 82 */ 83 long getFrame() const 84 { 85 checkClassBinding!(typeof(this))(); 86 return ptrcall!(long)(GDNativeClassBinding.getFrame, _godot_object); 87 } 88 /** 89 90 */ 91 Vector2 getFrameCoords() const 92 { 93 checkClassBinding!(typeof(this))(); 94 return ptrcall!(Vector2)(GDNativeClassBinding.getFrameCoords, _godot_object); 95 } 96 /** 97 98 */ 99 long getHframes() const 100 { 101 checkClassBinding!(typeof(this))(); 102 return ptrcall!(long)(GDNativeClassBinding.getHframes, _godot_object); 103 } 104 /** 105 106 */ 107 Rect2 getRegionRect() const 108 { 109 checkClassBinding!(typeof(this))(); 110 return ptrcall!(Rect2)(GDNativeClassBinding.getRegionRect, _godot_object); 111 } 112 /** 113 114 */ 115 Ref!Texture getTexture() const 116 { 117 checkClassBinding!(typeof(this))(); 118 return ptrcall!(Texture)(GDNativeClassBinding.getTexture, _godot_object); 119 } 120 /** 121 122 */ 123 long getVframes() const 124 { 125 checkClassBinding!(typeof(this))(); 126 return ptrcall!(long)(GDNativeClassBinding.getVframes, _godot_object); 127 } 128 /** 129 130 */ 131 bool isRegion() const 132 { 133 checkClassBinding!(typeof(this))(); 134 return ptrcall!(bool)(GDNativeClassBinding.isRegion, _godot_object); 135 } 136 /** 137 138 */ 139 void setFrame(in long frame) 140 { 141 checkClassBinding!(typeof(this))(); 142 ptrcall!(void)(GDNativeClassBinding.setFrame, _godot_object, frame); 143 } 144 /** 145 146 */ 147 void setFrameCoords(in Vector2 coords) 148 { 149 checkClassBinding!(typeof(this))(); 150 ptrcall!(void)(GDNativeClassBinding.setFrameCoords, _godot_object, coords); 151 } 152 /** 153 154 */ 155 void setHframes(in long hframes) 156 { 157 checkClassBinding!(typeof(this))(); 158 ptrcall!(void)(GDNativeClassBinding.setHframes, _godot_object, hframes); 159 } 160 /** 161 162 */ 163 void setRegion(in bool enabled) 164 { 165 checkClassBinding!(typeof(this))(); 166 ptrcall!(void)(GDNativeClassBinding.setRegion, _godot_object, enabled); 167 } 168 /** 169 170 */ 171 void setRegionRect(in Rect2 rect) 172 { 173 checkClassBinding!(typeof(this))(); 174 ptrcall!(void)(GDNativeClassBinding.setRegionRect, _godot_object, rect); 175 } 176 /** 177 178 */ 179 void setTexture(Texture texture) 180 { 181 checkClassBinding!(typeof(this))(); 182 ptrcall!(void)(GDNativeClassBinding.setTexture, _godot_object, texture); 183 } 184 /** 185 186 */ 187 void setVframes(in long vframes) 188 { 189 checkClassBinding!(typeof(this))(); 190 ptrcall!(void)(GDNativeClassBinding.setVframes, _godot_object, vframes); 191 } 192 /** 193 Current frame to display from sprite sheet. $(D hframes) or $(D vframes) must be greater than 1. 194 */ 195 @property long frame() 196 { 197 return getFrame(); 198 } 199 /// ditto 200 @property void frame(long v) 201 { 202 setFrame(v); 203 } 204 /** 205 Coordinates of the frame to display from sprite sheet. This is as an alias for the $(D frame) property. $(D hframes) or $(D vframes) must be greater than 1. 206 */ 207 @property Vector2 frameCoords() 208 { 209 return getFrameCoords(); 210 } 211 /// ditto 212 @property void frameCoords(Vector2 v) 213 { 214 setFrameCoords(v); 215 } 216 /** 217 The number of columns in the sprite sheet. 218 */ 219 @property long hframes() 220 { 221 return getHframes(); 222 } 223 /// ditto 224 @property void hframes(long v) 225 { 226 setHframes(v); 227 } 228 /** 229 If `true`, texture will be cut from a larger atlas texture. See $(D regionRect). 230 */ 231 @property bool regionEnabled() 232 { 233 return isRegion(); 234 } 235 /// ditto 236 @property void regionEnabled(bool v) 237 { 238 setRegion(v); 239 } 240 /** 241 The region of the atlas texture to display. $(D regionEnabled) must be `true`. 242 */ 243 @property Rect2 regionRect() 244 { 245 return getRegionRect(); 246 } 247 /// ditto 248 @property void regionRect(Rect2 v) 249 { 250 setRegionRect(v); 251 } 252 /** 253 $(D Texture) object to draw. If $(D GeometryInstance.materialOverride) is used, this will be overridden. 254 */ 255 @property Texture texture() 256 { 257 return getTexture(); 258 } 259 /// ditto 260 @property void texture(Texture v) 261 { 262 setTexture(v); 263 } 264 /** 265 The number of rows in the sprite sheet. 266 */ 267 @property long vframes() 268 { 269 return getVframes(); 270 } 271 /// ditto 272 @property void vframes(long v) 273 { 274 setVframes(v); 275 } 276 }