1 /** 2 Mesh-based navigation and pathfinding node. 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.navigation; 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.spatial; 25 import godot.navigationmesh; 26 /** 27 Mesh-based navigation and pathfinding node. 28 29 Provides navigation and pathfinding within a collection of $(D NavigationMesh)es. By default, these will be automatically collected from child $(D NavigationMeshInstance) nodes, but they can also be added on the fly with $(D navmeshAdd). In addition to basic pathfinding, this class also assists with aligning navigation agents with the meshes they are navigating on. 30 $(B Note:) The current navigation system has many known issues and will not always return optimal paths as expected. These issues will be fixed in Godot 4.0. 31 */ 32 @GodotBaseClass struct Navigation 33 { 34 package(godot) enum string _GODOT_internal_name = "Navigation"; 35 public: 36 @nogc nothrow: 37 union { /** */ godot_object _godot_object; /** */ Spatial _GODOT_base; } 38 alias _GODOT_base this; 39 alias BaseClasses = AliasSeq!(typeof(_GODOT_base), typeof(_GODOT_base).BaseClasses); 40 package(godot) __gshared bool _classBindingInitialized = false; 41 package(godot) static struct GDNativeClassBinding 42 { 43 __gshared: 44 @GodotName("get_closest_point") GodotMethod!(Vector3, Vector3) getClosestPoint; 45 @GodotName("get_closest_point_normal") GodotMethod!(Vector3, Vector3) getClosestPointNormal; 46 @GodotName("get_closest_point_owner") GodotMethod!(GodotObject, Vector3) getClosestPointOwner; 47 @GodotName("get_closest_point_to_segment") GodotMethod!(Vector3, Vector3, Vector3, bool) getClosestPointToSegment; 48 @GodotName("get_simple_path") GodotMethod!(PoolVector3Array, Vector3, Vector3, bool) getSimplePath; 49 @GodotName("get_up_vector") GodotMethod!(Vector3) getUpVector; 50 @GodotName("navmesh_add") GodotMethod!(long, NavigationMesh, Transform, GodotObject) navmeshAdd; 51 @GodotName("navmesh_remove") GodotMethod!(void, long) navmeshRemove; 52 @GodotName("navmesh_set_transform") GodotMethod!(void, long, Transform) navmeshSetTransform; 53 @GodotName("set_up_vector") GodotMethod!(void, Vector3) setUpVector; 54 } 55 /// 56 pragma(inline, true) bool opEquals(in Navigation other) const 57 { return _godot_object.ptr is other._godot_object.ptr; } 58 /// 59 pragma(inline, true) typeof(null) opAssign(typeof(null) n) 60 { _godot_object.ptr = n; return null; } 61 /// 62 pragma(inline, true) bool opEquals(typeof(null) n) const 63 { return _godot_object.ptr is n; } 64 /// 65 size_t toHash() const @trusted { return cast(size_t)_godot_object.ptr; } 66 mixin baseCasts; 67 /// Construct a new instance of Navigation. 68 /// Note: use `memnew!Navigation` instead. 69 static Navigation _new() 70 { 71 static godot_class_constructor constructor; 72 if(constructor is null) constructor = _godot_api.godot_get_class_constructor("Navigation"); 73 if(constructor is null) return typeof(this).init; 74 return cast(Navigation)(constructor()); 75 } 76 @disable new(size_t s); 77 /** 78 Returns the navigation point closest to the point given. Points are in local coordinate space. 79 */ 80 Vector3 getClosestPoint(in Vector3 to_point) 81 { 82 checkClassBinding!(typeof(this))(); 83 return ptrcall!(Vector3)(GDNativeClassBinding.getClosestPoint, _godot_object, to_point); 84 } 85 /** 86 Returns the surface normal at the navigation point closest to the point given. Useful for rotating a navigation agent according to the navigation mesh it moves on. 87 */ 88 Vector3 getClosestPointNormal(in Vector3 to_point) 89 { 90 checkClassBinding!(typeof(this))(); 91 return ptrcall!(Vector3)(GDNativeClassBinding.getClosestPointNormal, _godot_object, to_point); 92 } 93 /** 94 Returns the owner of the $(D NavigationMesh) which contains the navigation point closest to the point given. This is usually a $(D NavigationMeshInstance). For meshes added via $(D navmeshAdd), returns the owner that was given (or `null` if the `owner` parameter was omitted). 95 */ 96 GodotObject getClosestPointOwner(in Vector3 to_point) 97 { 98 checkClassBinding!(typeof(this))(); 99 return ptrcall!(GodotObject)(GDNativeClassBinding.getClosestPointOwner, _godot_object, to_point); 100 } 101 /** 102 Returns the navigation point closest to the given line segment. When enabling `use_collision`, only considers intersection points between segment and navigation meshes. If multiple intersection points are found, the one closest to the segment start point is returned. 103 */ 104 Vector3 getClosestPointToSegment(in Vector3 start, in Vector3 end, in bool use_collision = false) 105 { 106 checkClassBinding!(typeof(this))(); 107 return ptrcall!(Vector3)(GDNativeClassBinding.getClosestPointToSegment, _godot_object, start, end, use_collision); 108 } 109 /** 110 Returns the path between two given points. Points are in local coordinate space. If `optimize` is `true` (the default), the agent properties associated with each $(D NavigationMesh) (radius, height, etc.) are considered in the path calculation, otherwise they are ignored. 111 $(B Note:) This method has known issues and will often return non-optimal paths. These issues will be fixed in Godot 4.0. 112 */ 113 PoolVector3Array getSimplePath(in Vector3 start, in Vector3 end, in bool optimize = true) 114 { 115 checkClassBinding!(typeof(this))(); 116 return ptrcall!(PoolVector3Array)(GDNativeClassBinding.getSimplePath, _godot_object, start, end, optimize); 117 } 118 /** 119 120 */ 121 Vector3 getUpVector() const 122 { 123 checkClassBinding!(typeof(this))(); 124 return ptrcall!(Vector3)(GDNativeClassBinding.getUpVector, _godot_object); 125 } 126 /** 127 Adds a $(D NavigationMesh). Returns an ID for use with $(D navmeshRemove) or $(D navmeshSetTransform). If given, a $(D Transform2D) is applied to the polygon. The optional `owner` is used as return value for $(D getClosestPointOwner). 128 */ 129 long navmeshAdd(NavigationMesh mesh, in Transform xform, GodotObject owner = GodotObject.init) 130 { 131 checkClassBinding!(typeof(this))(); 132 return ptrcall!(long)(GDNativeClassBinding.navmeshAdd, _godot_object, mesh, xform, owner); 133 } 134 /** 135 Removes the $(D NavigationMesh) with the given ID. 136 */ 137 void navmeshRemove(in long id) 138 { 139 checkClassBinding!(typeof(this))(); 140 ptrcall!(void)(GDNativeClassBinding.navmeshRemove, _godot_object, id); 141 } 142 /** 143 Sets the transform applied to the $(D NavigationMesh) with the given ID. 144 */ 145 void navmeshSetTransform(in long id, in Transform xform) 146 { 147 checkClassBinding!(typeof(this))(); 148 ptrcall!(void)(GDNativeClassBinding.navmeshSetTransform, _godot_object, id, xform); 149 } 150 /** 151 152 */ 153 void setUpVector(in Vector3 up) 154 { 155 checkClassBinding!(typeof(this))(); 156 ptrcall!(void)(GDNativeClassBinding.setUpVector, _godot_object, up); 157 } 158 /** 159 Defines which direction is up. By default, this is `(0, 1, 0)`, which is the world's "up" direction. 160 */ 161 @property Vector3 upVector() 162 { 163 return getUpVector(); 164 } 165 /// ditto 166 @property void upVector(Vector3 v) 167 { 168 setUpVector(v); 169 } 170 }