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.meta;
17 import godot.core;
18 import godot.c;
19 import godot.d.bind;
20 import godot.d.reference;
21 import godot.object;
22 import godot.classdb;
23 import godot.spatial;
24 import godot.navigationmesh;
25 import godot.node;
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 */
31 @GodotBaseClass struct Navigation
32 {
33 	enum string _GODOT_internal_name = "Navigation";
34 public:
35 @nogc nothrow:
36 	union { godot_object _godot_object; Spatial _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 _classBinding
41 	{
42 		__gshared:
43 		@GodotName("navmesh_add") GodotMethod!(long, NavigationMesh, Transform, GodotObject) navmeshAdd;
44 		@GodotName("navmesh_set_transform") GodotMethod!(void, long, Transform) navmeshSetTransform;
45 		@GodotName("navmesh_remove") GodotMethod!(void, long) navmeshRemove;
46 		@GodotName("get_simple_path") GodotMethod!(PoolVector3Array, Vector3, Vector3, bool) getSimplePath;
47 		@GodotName("get_closest_point_to_segment") GodotMethod!(Vector3, Vector3, Vector3, bool) getClosestPointToSegment;
48 		@GodotName("get_closest_point") GodotMethod!(Vector3, Vector3) getClosestPoint;
49 		@GodotName("get_closest_point_normal") GodotMethod!(Vector3, Vector3) getClosestPointNormal;
50 		@GodotName("get_closest_point_owner") GodotMethod!(GodotObject, Vector3) getClosestPointOwner;
51 		@GodotName("set_up_vector") GodotMethod!(void, Vector3) setUpVector;
52 		@GodotName("get_up_vector") GodotMethod!(Vector3) getUpVector;
53 	}
54 	bool opEquals(in Navigation other) const { return _godot_object.ptr is other._godot_object.ptr; }
55 	Navigation opAssign(T : typeof(null))(T n) { _godot_object.ptr = null; }
56 	bool opEquals(typeof(null) n) const { return _godot_object.ptr is null; }
57 	mixin baseCasts;
58 	static Navigation _new()
59 	{
60 		static godot_class_constructor constructor;
61 		if(constructor is null) constructor = _godot_api.godot_get_class_constructor("Navigation");
62 		if(constructor is null) return typeof(this).init;
63 		return cast(Navigation)(constructor());
64 	}
65 	@disable new(size_t s);
66 	/**
67 	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).
68 	*/
69 	long navmeshAdd(NavigationMesh mesh, in Transform xform, GodotObject owner = GodotObject.init)
70 	{
71 		checkClassBinding!(typeof(this))();
72 		return ptrcall!(long)(_classBinding.navmeshAdd, _godot_object, mesh, xform, owner);
73 	}
74 	/**
75 	Sets the transform applied to the $(D NavigationMesh) with the given ID.
76 	*/
77 	void navmeshSetTransform(in long id, in Transform xform)
78 	{
79 		checkClassBinding!(typeof(this))();
80 		ptrcall!(void)(_classBinding.navmeshSetTransform, _godot_object, id, xform);
81 	}
82 	/**
83 	Removes the $(D NavigationMesh) with the given ID.
84 	*/
85 	void navmeshRemove(in long id)
86 	{
87 		checkClassBinding!(typeof(this))();
88 		ptrcall!(void)(_classBinding.navmeshRemove, _godot_object, id);
89 	}
90 	/**
91 	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) (raidus, height, etc.) are considered in the path calculation, otherwise they are ignored.
92 	*/
93 	PoolVector3Array getSimplePath(in Vector3 start, in Vector3 end, in bool optimize = true)
94 	{
95 		checkClassBinding!(typeof(this))();
96 		return ptrcall!(PoolVector3Array)(_classBinding.getSimplePath, _godot_object, start, end, optimize);
97 	}
98 	/**
99 	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.
100 	*/
101 	Vector3 getClosestPointToSegment(in Vector3 start, in Vector3 end, in bool use_collision = false)
102 	{
103 		checkClassBinding!(typeof(this))();
104 		return ptrcall!(Vector3)(_classBinding.getClosestPointToSegment, _godot_object, start, end, use_collision);
105 	}
106 	/**
107 	Returns the navigation point closest to the point given. Points are in local coordinate space.
108 	*/
109 	Vector3 getClosestPoint(in Vector3 to_point)
110 	{
111 		checkClassBinding!(typeof(this))();
112 		return ptrcall!(Vector3)(_classBinding.getClosestPoint, _godot_object, to_point);
113 	}
114 	/**
115 	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.
116 	*/
117 	Vector3 getClosestPointNormal(in Vector3 to_point)
118 	{
119 		checkClassBinding!(typeof(this))();
120 		return ptrcall!(Vector3)(_classBinding.getClosestPointNormal, _godot_object, to_point);
121 	}
122 	/**
123 	Returns the owner of the $(D NavigationMesh) which contains the navigation point closest to the point given. This is usually a $(D NavigtionMeshInstance). For meshes added via $(D navmeshAdd), returns the owner that was given (or `null` if the `owner` parameter was omitted).
124 	*/
125 	GodotObject getClosestPointOwner(in Vector3 to_point)
126 	{
127 		checkClassBinding!(typeof(this))();
128 		return ptrcall!(GodotObject)(_classBinding.getClosestPointOwner, _godot_object, to_point);
129 	}
130 	/**
131 	
132 	*/
133 	void setUpVector(in Vector3 up)
134 	{
135 		checkClassBinding!(typeof(this))();
136 		ptrcall!(void)(_classBinding.setUpVector, _godot_object, up);
137 	}
138 	/**
139 	
140 	*/
141 	Vector3 getUpVector() const
142 	{
143 		checkClassBinding!(typeof(this))();
144 		return ptrcall!(Vector3)(_classBinding.getUpVector, _godot_object);
145 	}
146 	/**
147 	Defines which direction is up. By default this is `(0, 1, 0)`, which is the world up direction.
148 	*/
149 	@property Vector3 upVector()
150 	{
151 		return getUpVector();
152 	}
153 	/// ditto
154 	@property void upVector(Vector3 v)
155 	{
156 		setUpVector(v);
157 	}
158 }