1 /** 2 Parent of all visual 3D nodes. 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.visualinstance; 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.spatial; 24 import godot.node; 25 /** 26 Parent of all visual 3D nodes. 27 28 The $(D VisualInstance) is used to connect a resource to a visual representation. All visual 3D nodes inherit from the $(D VisualInstance). In general, you should not access the $(D VisualInstance) properties directly as they are accessed and managed by the nodes that inherit from $(D VisualInstance). $(D VisualInstance) is the node representation of the $(D VisualServer) instance. 29 */ 30 @GodotBaseClass struct VisualInstance 31 { 32 package(godot) enum string _GODOT_internal_name = "VisualInstance"; 33 public: 34 @nogc nothrow: 35 union { /** */ godot_object _godot_object; /** */ Spatial _GODOT_base; } 36 alias _GODOT_base this; 37 alias BaseClasses = AliasSeq!(typeof(_GODOT_base), typeof(_GODOT_base).BaseClasses); 38 package(godot) __gshared bool _classBindingInitialized = false; 39 package(godot) static struct GDNativeClassBinding 40 { 41 __gshared: 42 @GodotName("_get_visual_instance_rid") GodotMethod!(RID) _getVisualInstanceRid; 43 @GodotName("get_aabb") GodotMethod!(AABB) getAabb; 44 @GodotName("get_base") GodotMethod!(RID) getBase; 45 @GodotName("get_instance") GodotMethod!(RID) getInstance; 46 @GodotName("get_layer_mask") GodotMethod!(long) getLayerMask; 47 @GodotName("get_layer_mask_bit") GodotMethod!(bool, long) getLayerMaskBit; 48 @GodotName("get_transformed_aabb") GodotMethod!(AABB) getTransformedAabb; 49 @GodotName("set_base") GodotMethod!(void, RID) setBase; 50 @GodotName("set_layer_mask") GodotMethod!(void, long) setLayerMask; 51 @GodotName("set_layer_mask_bit") GodotMethod!(void, long, bool) setLayerMaskBit; 52 } 53 /// 54 pragma(inline, true) bool opEquals(in VisualInstance other) const 55 { return _godot_object.ptr is other._godot_object.ptr; } 56 /// 57 pragma(inline, true) typeof(null) opAssign(typeof(null) n) 58 { _godot_object.ptr = n; return null; } 59 /// 60 pragma(inline, true) bool opEquals(typeof(null) n) const 61 { return _godot_object.ptr is n; } 62 /// 63 size_t toHash() const @trusted { return cast(size_t)_godot_object.ptr; } 64 mixin baseCasts; 65 /// Construct a new instance of VisualInstance. 66 /// Note: use `memnew!VisualInstance` instead. 67 static VisualInstance _new() 68 { 69 static godot_class_constructor constructor; 70 if(constructor is null) constructor = _godot_api.godot_get_class_constructor("VisualInstance"); 71 if(constructor is null) return typeof(this).init; 72 return cast(VisualInstance)(constructor()); 73 } 74 @disable new(size_t s); 75 /** 76 77 */ 78 RID _getVisualInstanceRid() const 79 { 80 Array _GODOT_args = Array.make(); 81 String _GODOT_method_name = String("_get_visual_instance_rid"); 82 return this.callv(_GODOT_method_name, _GODOT_args).as!(RefOrT!RID); 83 } 84 /** 85 Returns the $(D AABB) (also known as the bounding box) for this $(D VisualInstance). See also $(D getTransformedAabb). 86 */ 87 AABB getAabb() const 88 { 89 checkClassBinding!(typeof(this))(); 90 return ptrcall!(AABB)(GDNativeClassBinding.getAabb, _godot_object); 91 } 92 /** 93 Returns the RID of the resource associated with this $(D VisualInstance). For example, if the Node is a $(D MeshInstance), this will return the RID of the associated $(D Mesh). 94 */ 95 RID getBase() const 96 { 97 checkClassBinding!(typeof(this))(); 98 return ptrcall!(RID)(GDNativeClassBinding.getBase, _godot_object); 99 } 100 /** 101 Returns the RID of this instance. This RID is the same as the RID returned by $(D VisualServer.instanceCreate). This RID is needed if you want to call $(D VisualServer) functions directly on this $(D VisualInstance). 102 */ 103 RID getInstance() const 104 { 105 checkClassBinding!(typeof(this))(); 106 return ptrcall!(RID)(GDNativeClassBinding.getInstance, _godot_object); 107 } 108 /** 109 110 */ 111 long getLayerMask() const 112 { 113 checkClassBinding!(typeof(this))(); 114 return ptrcall!(long)(GDNativeClassBinding.getLayerMask, _godot_object); 115 } 116 /** 117 Returns `true` when the specified layer is enabled in $(D layers) and `false` otherwise. 118 */ 119 bool getLayerMaskBit(in long layer) const 120 { 121 checkClassBinding!(typeof(this))(); 122 return ptrcall!(bool)(GDNativeClassBinding.getLayerMaskBit, _godot_object, layer); 123 } 124 /** 125 Returns the transformed $(D AABB) (also known as the bounding box) for this $(D VisualInstance). 126 Transformed in this case means the $(D AABB) plus the position, rotation, and scale of the $(D Spatial)'s $(D Transform). See also $(D getAabb). 127 */ 128 AABB getTransformedAabb() const 129 { 130 checkClassBinding!(typeof(this))(); 131 return ptrcall!(AABB)(GDNativeClassBinding.getTransformedAabb, _godot_object); 132 } 133 /** 134 Sets the resource that is instantiated by this $(D VisualInstance), which changes how the engine handles the $(D VisualInstance) under the hood. Equivalent to $(D VisualServer.instanceSetBase). 135 */ 136 void setBase(in RID base) 137 { 138 checkClassBinding!(typeof(this))(); 139 ptrcall!(void)(GDNativeClassBinding.setBase, _godot_object, base); 140 } 141 /** 142 143 */ 144 void setLayerMask(in long mask) 145 { 146 checkClassBinding!(typeof(this))(); 147 ptrcall!(void)(GDNativeClassBinding.setLayerMask, _godot_object, mask); 148 } 149 /** 150 Enables a particular layer in $(D layers). 151 */ 152 void setLayerMaskBit(in long layer, in bool enabled) 153 { 154 checkClassBinding!(typeof(this))(); 155 ptrcall!(void)(GDNativeClassBinding.setLayerMaskBit, _godot_object, layer, enabled); 156 } 157 /** 158 The render layer(s) this $(D VisualInstance) is drawn on. 159 This object will only be visible for $(D Camera)s whose cull mask includes the render object this $(D VisualInstance) is set to. 160 */ 161 @property long layers() 162 { 163 return getLayerMask(); 164 } 165 /// ditto 166 @property void layers(long v) 167 { 168 setLayerMask(v); 169 } 170 }