1 /** 2 Custom gizmo for editing Spatial objects. 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.editorspatialgizmo; 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.spatialgizmo; 24 import godot.trianglemesh; 25 import godot.material; 26 import godot.arraymesh; 27 import godot.skinreference; 28 import godot.editorspatialgizmoplugin; 29 import godot.spatial; 30 import godot.camera; 31 import godot.node; 32 /** 33 Custom gizmo for editing Spatial objects. 34 35 Custom gizmo that is used for providing custom visualization and editing (handles) for 3D Spatial objects. See $(D EditorSpatialGizmoPlugin) for more information. 36 */ 37 @GodotBaseClass struct EditorSpatialGizmo 38 { 39 package(godot) enum string _GODOT_internal_name = "EditorSpatialGizmo"; 40 public: 41 @nogc nothrow: 42 union { /** */ godot_object _godot_object; /** */ SpatialGizmo _GODOT_base; } 43 alias _GODOT_base this; 44 alias BaseClasses = AliasSeq!(typeof(_GODOT_base), typeof(_GODOT_base).BaseClasses); 45 package(godot) __gshared bool _classBindingInitialized = false; 46 package(godot) static struct GDNativeClassBinding 47 { 48 __gshared: 49 @GodotName("add_collision_segments") GodotMethod!(void, PoolVector3Array) addCollisionSegments; 50 @GodotName("add_collision_triangles") GodotMethod!(void, TriangleMesh) addCollisionTriangles; 51 @GodotName("add_handles") GodotMethod!(void, PoolVector3Array, Material, bool, bool) addHandles; 52 @GodotName("add_lines") GodotMethod!(void, PoolVector3Array, Material, bool, Color) addLines; 53 @GodotName("add_mesh") GodotMethod!(void, ArrayMesh, bool, SkinReference, Material) addMesh; 54 @GodotName("add_unscaled_billboard") GodotMethod!(void, Material, double, Color) addUnscaledBillboard; 55 @GodotName("clear") GodotMethod!(void) clear; 56 @GodotName("commit_handle") GodotMethod!(void, long, Variant, bool) commitHandle; 57 @GodotName("get_handle_name") GodotMethod!(String, long) getHandleName; 58 @GodotName("get_handle_value") GodotMethod!(Variant, long) getHandleValue; 59 @GodotName("get_plugin") GodotMethod!(EditorSpatialGizmoPlugin) getPlugin; 60 @GodotName("get_spatial_node") GodotMethod!(Spatial) getSpatialNode; 61 @GodotName("is_handle_highlighted") GodotMethod!(bool, long) isHandleHighlighted; 62 @GodotName("redraw") GodotMethod!(void) redraw; 63 @GodotName("set_handle") GodotMethod!(void, long, Camera, Vector2) setHandle; 64 @GodotName("set_hidden") GodotMethod!(void, bool) setHidden; 65 @GodotName("set_spatial_node") GodotMethod!(void, Node) setSpatialNode; 66 } 67 /// 68 pragma(inline, true) bool opEquals(in EditorSpatialGizmo other) const 69 { return _godot_object.ptr is other._godot_object.ptr; } 70 /// 71 pragma(inline, true) typeof(null) opAssign(typeof(null) n) 72 { _godot_object.ptr = n; return null; } 73 /// 74 pragma(inline, true) bool opEquals(typeof(null) n) const 75 { return _godot_object.ptr is n; } 76 /// 77 size_t toHash() const @trusted { return cast(size_t)_godot_object.ptr; } 78 mixin baseCasts; 79 /// Construct a new instance of EditorSpatialGizmo. 80 /// Note: use `memnew!EditorSpatialGizmo` instead. 81 static EditorSpatialGizmo _new() 82 { 83 static godot_class_constructor constructor; 84 if(constructor is null) constructor = _godot_api.godot_get_class_constructor("EditorSpatialGizmo"); 85 if(constructor is null) return typeof(this).init; 86 return cast(EditorSpatialGizmo)(constructor()); 87 } 88 @disable new(size_t s); 89 /** 90 Adds the specified `segments` to the gizmo's collision shape for picking. Call this function during $(D redraw). 91 */ 92 void addCollisionSegments(in PoolVector3Array segments) 93 { 94 checkClassBinding!(typeof(this))(); 95 ptrcall!(void)(GDNativeClassBinding.addCollisionSegments, _godot_object, segments); 96 } 97 /** 98 Adds collision triangles to the gizmo for picking. A $(D TriangleMesh) can be generated from a regular $(D Mesh) too. Call this function during $(D redraw). 99 */ 100 void addCollisionTriangles(TriangleMesh triangles) 101 { 102 checkClassBinding!(typeof(this))(); 103 ptrcall!(void)(GDNativeClassBinding.addCollisionTriangles, _godot_object, triangles); 104 } 105 /** 106 Adds a list of handles (points) which can be used to deform the object being edited. 107 There are virtual functions which will be called upon editing of these handles. Call this function during $(D redraw). 108 */ 109 void addHandles(in PoolVector3Array handles, Material material, in bool billboard = false, in bool secondary = false) 110 { 111 checkClassBinding!(typeof(this))(); 112 ptrcall!(void)(GDNativeClassBinding.addHandles, _godot_object, handles, material, billboard, secondary); 113 } 114 /** 115 Adds lines to the gizmo (as sets of 2 points), with a given material. The lines are used for visualizing the gizmo. Call this function during $(D redraw). 116 */ 117 void addLines(in PoolVector3Array lines, Material material, in bool billboard = false, in Color modulate = Color(1,1,1,1)) 118 { 119 checkClassBinding!(typeof(this))(); 120 ptrcall!(void)(GDNativeClassBinding.addLines, _godot_object, lines, material, billboard, modulate); 121 } 122 /** 123 Adds a mesh to the gizmo with the specified `billboard` state, `skeleton` and `material`. If `billboard` is `true`, the mesh will rotate to always face the camera. Call this function during $(D redraw). 124 */ 125 void addMesh(ArrayMesh mesh, in bool billboard = false, SkinReference skeleton = SkinReference.init, Material material = Material.init) 126 { 127 checkClassBinding!(typeof(this))(); 128 ptrcall!(void)(GDNativeClassBinding.addMesh, _godot_object, mesh, billboard, skeleton, material); 129 } 130 /** 131 Adds an unscaled billboard for visualization. Call this function during $(D redraw). 132 */ 133 void addUnscaledBillboard(Material material, in double default_scale = 1, in Color modulate = Color(1,1,1,1)) 134 { 135 checkClassBinding!(typeof(this))(); 136 ptrcall!(void)(GDNativeClassBinding.addUnscaledBillboard, _godot_object, material, default_scale, modulate); 137 } 138 /** 139 Removes everything in the gizmo including meshes, collisions and handles. 140 */ 141 void clear() 142 { 143 checkClassBinding!(typeof(this))(); 144 ptrcall!(void)(GDNativeClassBinding.clear, _godot_object); 145 } 146 /** 147 Commit a handle being edited (handles must have been previously added by $(D addHandles)). 148 If the `cancel` parameter is `true`, an option to restore the edited value to the original is provided. 149 */ 150 void commitHandle(VariantArg1)(in long index, in VariantArg1 restore, in bool cancel) 151 { 152 Array _GODOT_args = Array.make(); 153 _GODOT_args.append(index); 154 _GODOT_args.append(restore); 155 _GODOT_args.append(cancel); 156 String _GODOT_method_name = String("commit_handle"); 157 this.callv(_GODOT_method_name, _GODOT_args); 158 } 159 /** 160 Gets the name of an edited handle (handles must have been previously added by $(D addHandles)). 161 Handles can be named for reference to the user when editing. 162 */ 163 String getHandleName(in long index) 164 { 165 Array _GODOT_args = Array.make(); 166 _GODOT_args.append(index); 167 String _GODOT_method_name = String("get_handle_name"); 168 return this.callv(_GODOT_method_name, _GODOT_args).as!(RefOrT!String); 169 } 170 /** 171 Gets actual value of a handle. This value can be anything and used for eventually undoing the motion when calling $(D commitHandle). 172 */ 173 Variant getHandleValue(in long index) 174 { 175 Array _GODOT_args = Array.make(); 176 _GODOT_args.append(index); 177 String _GODOT_method_name = String("get_handle_value"); 178 return this.callv(_GODOT_method_name, _GODOT_args); 179 } 180 /** 181 Returns the $(D EditorSpatialGizmoPlugin) that owns this gizmo. It's useful to retrieve materials using $(D EditorSpatialGizmoPlugin.getMaterial). 182 */ 183 Ref!EditorSpatialGizmoPlugin getPlugin() const 184 { 185 checkClassBinding!(typeof(this))(); 186 return ptrcall!(EditorSpatialGizmoPlugin)(GDNativeClassBinding.getPlugin, _godot_object); 187 } 188 /** 189 Returns the Spatial node associated with this gizmo. 190 */ 191 Spatial getSpatialNode() const 192 { 193 checkClassBinding!(typeof(this))(); 194 return ptrcall!(Spatial)(GDNativeClassBinding.getSpatialNode, _godot_object); 195 } 196 /** 197 Returns `true` if the handle at index `index` is highlighted by being hovered with the mouse. 198 */ 199 bool isHandleHighlighted(in long index) 200 { 201 Array _GODOT_args = Array.make(); 202 _GODOT_args.append(index); 203 String _GODOT_method_name = String("is_handle_highlighted"); 204 return this.callv(_GODOT_method_name, _GODOT_args).as!(RefOrT!bool); 205 } 206 /** 207 This function is called when the $(D Spatial) this gizmo refers to changes (the $(D Spatial.updateGizmo) is called). 208 */ 209 void redraw() 210 { 211 Array _GODOT_args = Array.make(); 212 String _GODOT_method_name = String("redraw"); 213 this.callv(_GODOT_method_name, _GODOT_args); 214 } 215 /** 216 This function is used when the user drags a gizmo handle (previously added with $(D addHandles)) in screen coordinates. 217 The $(D Camera) is also provided so screen coordinates can be converted to raycasts. 218 */ 219 void setHandle(in long index, Camera camera, in Vector2 point) 220 { 221 Array _GODOT_args = Array.make(); 222 _GODOT_args.append(index); 223 _GODOT_args.append(camera); 224 _GODOT_args.append(point); 225 String _GODOT_method_name = String("set_handle"); 226 this.callv(_GODOT_method_name, _GODOT_args); 227 } 228 /** 229 Sets the gizmo's hidden state. If `true`, the gizmo will be hidden. If `false`, it will be shown. 230 */ 231 void setHidden(in bool hidden) 232 { 233 checkClassBinding!(typeof(this))(); 234 ptrcall!(void)(GDNativeClassBinding.setHidden, _godot_object, hidden); 235 } 236 /** 237 Sets the reference $(D Spatial) node for the gizmo. `node` must inherit from $(D Spatial). 238 */ 239 void setSpatialNode(Node node) 240 { 241 checkClassBinding!(typeof(this))(); 242 ptrcall!(void)(GDNativeClassBinding.setSpatialNode, _godot_object, node); 243 } 244 }