1 //
2 // Copyright (c) 2008-2017 the Urho3D project.
3 //
4 // Permission is hereby granted, free of charge, to any person obtaining a copy
5 // of this software and associated documentation files (the "Software"), to deal
6 // in the Software without restriction, including without limitation the rights
7 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 // copies of the Software, and to permit persons to whom the Software is
9 // furnished to do so, subject to the following conditions:
10 //
11 // The above copyright notice and this permission notice shall be included in
12 // all copies or substantial portions of the Software.
13 //
14 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 // THE SOFTWARE.
21 //
22
23 #ifdef URHO3D_NAVIGATION
24
25 #include "../Precompiled.h"
26
27 #include "../AngelScript/APITemplates.h"
28 #include "../Navigation/Navigable.h"
29 #include "../Navigation/CrowdAgent.h"
30 #include "../Navigation/DynamicNavigationMesh.h"
31 #include "../Navigation/NavArea.h"
32 #include "../Navigation/Obstacle.h"
33 #include "../Navigation/OffMeshConnection.h"
34
35 namespace Urho3D
36 {
37
RegisterNavigable(asIScriptEngine * engine)38 void RegisterNavigable(asIScriptEngine* engine)
39 {
40 RegisterComponent<Navigable>(engine, "Navigable");
41 engine->RegisterObjectMethod("Navigable", "void set_recursive(bool)", asMETHOD(Navigable, SetRecursive), asCALL_THISCALL);
42 engine->RegisterObjectMethod("Navigable", "bool get_recursive() const", asMETHOD(Navigable, IsRecursive), asCALL_THISCALL);
43 }
44
NavigationMeshFindPath(const Vector3 & start,const Vector3 & end,const Vector3 & extents,NavigationMesh * ptr)45 static CScriptArray* NavigationMeshFindPath(const Vector3& start, const Vector3& end, const Vector3& extents, NavigationMesh* ptr)
46 {
47 PODVector<Vector3> dest;
48 ptr->FindPath(dest, start, end, extents);
49 return VectorToArray<Vector3>(dest, "Array<Vector3>");
50 }
51
DynamicNavigationMeshFindPath(const Vector3 & start,const Vector3 & end,const Vector3 & extents,DynamicNavigationMesh * ptr)52 static CScriptArray* DynamicNavigationMeshFindPath(const Vector3& start, const Vector3& end, const Vector3& extents, DynamicNavigationMesh* ptr)
53 {
54 PODVector<Vector3> dest;
55 ptr->FindPath(dest, start, end, extents);
56 return VectorToArray<Vector3>(dest, "Array<Vector3>");
57 }
58
CrowdManagerGetAgents(Node * node,bool inCrowdFilter,CrowdManager * crowd)59 static CScriptArray* CrowdManagerGetAgents(Node* node, bool inCrowdFilter, CrowdManager* crowd)
60 {
61 PODVector<CrowdAgent*> agents = crowd->GetAgents(node, inCrowdFilter);
62 return VectorToHandleArray<CrowdAgent>(agents, "Array<CrowdAgent@>");
63 }
64
NavigationMeshFindNearestPoint(const Vector3 & point,const Vector3 & extents,NavigationMesh * ptr)65 static Vector3 NavigationMeshFindNearestPoint(const Vector3& point, const Vector3& extents, NavigationMesh* ptr)
66 {
67 return ptr->FindNearestPoint(point, extents);
68 }
69
NavigationMeshMoveAlongSurface(const Vector3 & start,const Vector3 & end,const Vector3 & extents,int maxVisited,NavigationMesh * ptr)70 static Vector3 NavigationMeshMoveAlongSurface(const Vector3& start, const Vector3& end, const Vector3& extents, int maxVisited, NavigationMesh* ptr)
71 {
72 return ptr->MoveAlongSurface(start, end, extents, maxVisited);
73 }
74
NavigationMeshGetTileData(const IntVector2 & tile,const NavigationMesh * ptr)75 static VectorBuffer NavigationMeshGetTileData(const IntVector2& tile, const NavigationMesh* ptr)
76 {
77 VectorBuffer buffer;
78 buffer.SetData(ptr->GetTileData(tile));
79 return buffer;
80 }
81
NavigationMeshAddTile(const VectorBuffer & tileData,NavigationMesh * ptr)82 static bool NavigationMeshAddTile(const VectorBuffer& tileData, NavigationMesh* ptr)
83 {
84 return ptr->AddTile(tileData.GetBuffer());
85 }
86
NavigationMeshGetRandomPoint(NavigationMesh * ptr)87 static Vector3 NavigationMeshGetRandomPoint(NavigationMesh* ptr)
88 {
89 return ptr->GetRandomPoint();
90 }
91
NavigationMeshGetRandomPointInCircle(const Vector3 & center,float radius,const Vector3 & extents,NavigationMesh * ptr)92 static Vector3 NavigationMeshGetRandomPointInCircle(const Vector3& center, float radius, const Vector3& extents, NavigationMesh* ptr)
93 {
94 return ptr->GetRandomPointInCircle(center, radius, extents);
95 }
96
NavigationMeshGetDistanceToWall(const Vector3 & point,float radius,const Vector3 & extents,NavigationMesh * ptr)97 static float NavigationMeshGetDistanceToWall(const Vector3& point, float radius, const Vector3& extents, NavigationMesh* ptr)
98 {
99 return ptr->GetDistanceToWall(point, radius, extents);
100 }
101
NavigationMeshRaycast(const Vector3 & start,const Vector3 & end,const Vector3 & extents,NavigationMesh * ptr)102 static Vector3 NavigationMeshRaycast(const Vector3& start, const Vector3& end, const Vector3& extents, NavigationMesh* ptr)
103 {
104 return ptr->Raycast(start, end, extents);
105 }
106
CrowdManagerGetRandomPoint(int queryFilterType,CrowdManager * crowdManager)107 static Vector3 CrowdManagerGetRandomPoint(int queryFilterType, CrowdManager* crowdManager)
108 {
109 return crowdManager->GetRandomPoint(queryFilterType);
110 }
111
CrowdManagerRandomPointInCircle(const Vector3 & center,float radius,int queryFilterType,CrowdManager * manager)112 static Vector3 CrowdManagerRandomPointInCircle(const Vector3& center, float radius, int queryFilterType, CrowdManager* manager)
113 {
114 return manager->GetRandomPointInCircle(center, radius, queryFilterType);
115 }
116
RegisterNavMeshBase(asIScriptEngine * engine,const char * name)117 template<class T> static void RegisterNavMeshBase(asIScriptEngine* engine, const char* name)
118 {
119 engine->RegisterObjectMethod(name, "bool Allocate(const BoundingBox&in, uint)", asMETHOD(T, Allocate), asCALL_THISCALL);
120 engine->RegisterObjectMethod(name, "bool Build()", asMETHODPR(T, Build, (), bool), asCALL_THISCALL);
121 engine->RegisterObjectMethod(name, "bool Build(const BoundingBox&in)", asMETHODPR(T, Build, (const BoundingBox&), bool), asCALL_THISCALL);
122 engine->RegisterObjectMethod(name, "bool Build(const IntVector2&, const IntVector2&)", asMETHODPR(T, Build, (const IntVector2&, const IntVector2&), bool), asCALL_THISCALL);
123 engine->RegisterObjectMethod(name, "VectorBuffer GetTileData(const IntVector2&) const", asFUNCTION(NavigationMeshGetTileData), asCALL_CDECL_OBJLAST);
124 engine->RegisterObjectMethod(name, "bool AddTile(const VectorBuffer&in) const", asFUNCTION(NavigationMeshAddTile), asCALL_CDECL_OBJLAST);
125 engine->RegisterObjectMethod(name, "void RemoveTile(const IntVector2&)", asMETHOD(T, RemoveTile), asCALL_THISCALL);
126 engine->RegisterObjectMethod(name, "void RemoveAllTiles()", asMETHOD(T, RemoveAllTiles), asCALL_THISCALL);
127 engine->RegisterObjectMethod(name, "bool HasTile(const IntVector2&) const", asMETHOD(T, HasTile), asCALL_THISCALL);
128 engine->RegisterObjectMethod(name, "BoundingBox GetTileBoudningBox(const IntVector2&) const", asMETHOD(T, GetTileBoudningBox), asCALL_THISCALL);
129 engine->RegisterObjectMethod(name, "IntVector2 GetTileIndex(const Vector3&) const", asMETHOD(T, GetTileIndex), asCALL_THISCALL);
130 engine->RegisterObjectMethod(name, "void SetAreaCost(uint, float)", asMETHOD(T, SetAreaCost), asCALL_THISCALL);
131 engine->RegisterObjectMethod(name, "float GetAreaCost(uint) const", asMETHOD(T, GetAreaCost), asCALL_THISCALL);
132 engine->RegisterObjectMethod(name, "Vector3 FindNearestPoint(const Vector3&in, const Vector3&in extents = Vector3(1.0, 1.0, 1.0))", asFUNCTION(NavigationMeshFindNearestPoint), asCALL_CDECL_OBJLAST);
133 engine->RegisterObjectMethod(name, "Vector3 MoveAlongSurface(const Vector3&in, const Vector3&in, const Vector3&in extents = Vector3(1.0, 1.0, 1.0), int maxVisited = 3)", asFUNCTION(NavigationMeshMoveAlongSurface), asCALL_CDECL_OBJLAST);
134 engine->RegisterObjectMethod(name, "Vector3 GetRandomPoint()", asFUNCTION(NavigationMeshGetRandomPoint), asCALL_CDECL_OBJLAST);
135 engine->RegisterObjectMethod(name, "Vector3 GetRandomPointInCircle(const Vector3&in, float, const Vector3&in extents = Vector3(1.0, 1.0, 1.0))", asFUNCTION(NavigationMeshGetRandomPointInCircle), asCALL_CDECL_OBJLAST);
136 engine->RegisterObjectMethod(name, "float GetDistanceToWall(const Vector3&in, float, const Vector3&in extents = Vector3(1.0, 1.0, 1.0))", asFUNCTION(NavigationMeshGetDistanceToWall), asCALL_CDECL_OBJLAST);
137 engine->RegisterObjectMethod(name, "Vector3 Raycast(const Vector3&in, const Vector3&in, const Vector3&in extents = Vector3(1.0, 1.0, 1.0))", asFUNCTION(NavigationMeshRaycast), asCALL_CDECL_OBJLAST);
138 engine->RegisterObjectMethod(name, "void DrawDebugGeometry(bool)", asMETHODPR(NavigationMesh, DrawDebugGeometry, (bool), void), asCALL_THISCALL);
139 engine->RegisterObjectMethod(name, "void set_tileSize(int)", asMETHOD(T, SetTileSize), asCALL_THISCALL);
140 engine->RegisterObjectMethod(name, "int get_tileSize() const", asMETHOD(T, GetTileSize), asCALL_THISCALL);
141 engine->RegisterObjectMethod(name, "void set_cellSize(float)", asMETHOD(T, SetCellSize), asCALL_THISCALL);
142 engine->RegisterObjectMethod(name, "float get_cellSize() const", asMETHOD(T, GetCellSize), asCALL_THISCALL);
143 engine->RegisterObjectMethod(name, "void set_cellHeight(float)", asMETHOD(T, SetCellHeight), asCALL_THISCALL);
144 engine->RegisterObjectMethod(name, "float get_cellHeight() const", asMETHOD(T, GetCellHeight), asCALL_THISCALL);
145 engine->RegisterObjectMethod(name, "void set_agentHeight(float)", asMETHOD(T, SetAgentHeight), asCALL_THISCALL);
146 engine->RegisterObjectMethod(name, "float get_agentHeight() const", asMETHOD(T, GetAgentHeight), asCALL_THISCALL);
147 engine->RegisterObjectMethod(name, "void set_agentRadius(float)", asMETHOD(T, SetAgentRadius), asCALL_THISCALL);
148 engine->RegisterObjectMethod(name, "float get_agentRadius() const", asMETHOD(T, GetAgentRadius), asCALL_THISCALL);
149 engine->RegisterObjectMethod(name, "void set_agentMaxClimb(float)", asMETHOD(T, SetAgentMaxClimb), asCALL_THISCALL);
150 engine->RegisterObjectMethod(name, "float get_agentMaxClimb() const", asMETHOD(T, GetAgentMaxClimb), asCALL_THISCALL);
151 engine->RegisterObjectMethod(name, "void set_agentMaxSlope(float)", asMETHOD(T, SetAgentMaxSlope), asCALL_THISCALL);
152 engine->RegisterObjectMethod(name, "float get_agentMaxSlope() const", asMETHOD(T, GetAgentMaxSlope), asCALL_THISCALL);
153 engine->RegisterObjectMethod(name, "void set_regionMinSize(float)", asMETHOD(T, SetRegionMinSize), asCALL_THISCALL);
154 engine->RegisterObjectMethod(name, "float get_regionMinSize() const", asMETHOD(T, GetRegionMinSize), asCALL_THISCALL);
155 engine->RegisterObjectMethod(name, "void set_regionMergeSize(float)", asMETHOD(T, SetRegionMergeSize), asCALL_THISCALL);
156 engine->RegisterObjectMethod(name, "float get_regionMergeSize() const", asMETHOD(T, GetRegionMergeSize), asCALL_THISCALL);
157 engine->RegisterObjectMethod(name, "void set_edgeMaxLength(float)", asMETHOD(T, SetEdgeMaxLength), asCALL_THISCALL);
158 engine->RegisterObjectMethod(name, "float get_edgeMaxLength() const", asMETHOD(T, GetEdgeMaxLength), asCALL_THISCALL);
159 engine->RegisterObjectMethod(name, "void set_edgeMaxError(float)", asMETHOD(T, SetEdgeMaxError), asCALL_THISCALL);
160 engine->RegisterObjectMethod(name, "float get_edgeMaxError() const", asMETHOD(T, GetEdgeMaxError), asCALL_THISCALL);
161 engine->RegisterObjectMethod(name, "void set_detailSampleDistance(float)", asMETHOD(T, SetDetailSampleDistance), asCALL_THISCALL);
162 engine->RegisterObjectMethod(name, "float get_detailSampleDistance() const", asMETHOD(T, GetDetailSampleDistance), asCALL_THISCALL);
163 engine->RegisterObjectMethod(name, "void set_detailSampleMaxError(float)", asMETHOD(T, SetDetailSampleMaxError), asCALL_THISCALL);
164 engine->RegisterObjectMethod(name, "float get_detailSampleMaxError() const", asMETHOD(T, GetDetailSampleMaxError), asCALL_THISCALL);
165 engine->RegisterObjectMethod(name, "void set_padding(const Vector3&in)", asMETHOD(T, SetPadding), asCALL_THISCALL);
166 engine->RegisterObjectMethod(name, "const Vector3& get_padding() const", asMETHOD(T, GetPadding), asCALL_THISCALL);
167 engine->RegisterObjectMethod(name, "bool get_initialized() const", asMETHOD(T, IsInitialized), asCALL_THISCALL);
168 engine->RegisterObjectMethod(name, "const BoundingBox& get_boundingBox() const", asMETHOD(T, GetBoundingBox), asCALL_THISCALL);
169 engine->RegisterObjectMethod(name, "BoundingBox get_worldBoundingBox() const", asMETHOD(T, GetWorldBoundingBox), asCALL_THISCALL);
170 engine->RegisterObjectMethod(name, "IntVector2 get_numTiles() const", asMETHOD(T, GetNumTiles), asCALL_THISCALL);
171 engine->RegisterObjectMethod(name, "void set_partitionType()", asMETHOD(T, SetPartitionType), asCALL_THISCALL);
172 engine->RegisterObjectMethod(name, "NavmeshPartitionType get_partitionType()", asMETHOD(T, GetPartitionType), asCALL_THISCALL);
173 engine->RegisterObjectMethod(name, "void set_drawOffMeshConnections(bool)", asMETHOD(T, SetDrawOffMeshConnections), asCALL_THISCALL);
174 engine->RegisterObjectMethod(name, "bool get_drawOffMeshConnections() const", asMETHOD(T, GetDrawOffMeshConnections), asCALL_THISCALL);
175 engine->RegisterObjectMethod(name, "void set_drawNavAreas(bool)", asMETHOD(T, SetDrawNavAreas), asCALL_THISCALL);
176 engine->RegisterObjectMethod(name, "bool get_drawNavAreas() const", asMETHOD(T, GetDrawNavAreas), asCALL_THISCALL);
177 }
178
RegisterNavigationMesh(asIScriptEngine * engine)179 void RegisterNavigationMesh(asIScriptEngine* engine)
180 {
181 engine->RegisterEnum("NavmeshPartitionType");
182 engine->RegisterEnumValue("NavmeshPartitionType", "NAVMESH_PARTITION_WATERSHED", NAVMESH_PARTITION_WATERSHED);
183 engine->RegisterEnumValue("NavmeshPartitionType", "NAVMESH_PARTITION_MONOTONE", NAVMESH_PARTITION_MONOTONE);
184
185 RegisterComponent<NavigationMesh>(engine, "NavigationMesh");
186 RegisterNavMeshBase<NavigationMesh>(engine, "NavigationMesh");
187 engine->RegisterObjectMethod("NavigationMesh", "Array<Vector3>@ FindPath(const Vector3&in, const Vector3&in, const Vector3&in extents = Vector3(1.0, 1.0, 1.0))", asFUNCTION(NavigationMeshFindPath), asCALL_CDECL_OBJLAST);
188 }
189
RegisterDynamicNavigationMesh(asIScriptEngine * engine)190 void RegisterDynamicNavigationMesh(asIScriptEngine* engine)
191 {
192 RegisterComponent<DynamicNavigationMesh>(engine, "DynamicNavigationMesh");
193 RegisterSubclass<NavigationMesh, DynamicNavigationMesh>(engine, "NavigationMesh", "DynamicNavigationMesh");
194 RegisterNavMeshBase<DynamicNavigationMesh>(engine, "DynamicNavigationMesh");
195 engine->RegisterObjectMethod("DynamicNavigationMesh", "Array<Vector3>@ FindPath(const Vector3&in, const Vector3&in, const Vector3&in extents = Vector3(1.0, 1.0, 1.0))", asFUNCTION(DynamicNavigationMeshFindPath), asCALL_CDECL_OBJLAST);
196 engine->RegisterObjectMethod("DynamicNavigationMesh", "void set_drawObstacles(bool)", asMETHOD(DynamicNavigationMesh, SetDrawObstacles), asCALL_THISCALL);
197 engine->RegisterObjectMethod("DynamicNavigationMesh", "bool get_drawObstacles() const", asMETHOD(DynamicNavigationMesh, GetDrawObstacles), asCALL_THISCALL);
198 engine->RegisterObjectMethod("DynamicNavigationMesh", "void set_maxLayers(uint)", asMETHOD(DynamicNavigationMesh, SetMaxLayers), asCALL_THISCALL);
199 engine->RegisterObjectMethod("DynamicNavigationMesh", "bool get_maxLayers() const", asMETHOD(DynamicNavigationMesh, GetMaxLayers), asCALL_THISCALL);
200 engine->RegisterObjectMethod("DynamicNavigationMesh", "void set_maxObstacles(uint)", asMETHOD(DynamicNavigationMesh, SetMaxObstacles), asCALL_THISCALL);
201 engine->RegisterObjectMethod("DynamicNavigationMesh", "uint get_maxObstacles() const", asMETHOD(DynamicNavigationMesh, GetMaxObstacles), asCALL_THISCALL);
202 }
203
RegisterOffMeshConnection(asIScriptEngine * engine)204 void RegisterOffMeshConnection(asIScriptEngine* engine)
205 {
206 RegisterComponent<OffMeshConnection>(engine, "OffMeshConnection");
207 engine->RegisterObjectMethod("OffMeshConnection", "void set_endPoint(Node@+)", asMETHOD(OffMeshConnection, SetEndPoint), asCALL_THISCALL);
208 engine->RegisterObjectMethod("OffMeshConnection", "Node@+ get_endPoint() const", asMETHOD(OffMeshConnection, GetEndPoint), asCALL_THISCALL);
209 engine->RegisterObjectMethod("OffMeshConnection", "void set_radius(float)", asMETHOD(OffMeshConnection, SetRadius), asCALL_THISCALL);
210 engine->RegisterObjectMethod("OffMeshConnection", "float get_radius() const", asMETHOD(OffMeshConnection, GetRadius), asCALL_THISCALL);
211 engine->RegisterObjectMethod("OffMeshConnection", "void set_bidirectional(bool)", asMETHOD(OffMeshConnection, SetBidirectional), asCALL_THISCALL);
212 engine->RegisterObjectMethod("OffMeshConnection", "bool get_bidirectional() const", asMETHOD(OffMeshConnection, IsBidirectional), asCALL_THISCALL);
213 engine->RegisterObjectMethod("OffMeshConnection", "void set_mask(uint)", asMETHOD(OffMeshConnection, SetMask), asCALL_THISCALL);
214 engine->RegisterObjectMethod("OffMeshConnection", "uint get_mask() const", asMETHOD(OffMeshConnection, GetMask), asCALL_THISCALL);
215 engine->RegisterObjectMethod("OffMeshConnection", "void set_areaID(uint)", asMETHOD(OffMeshConnection, SetAreaID), asCALL_THISCALL);
216 engine->RegisterObjectMethod("OffMeshConnection", "uint get_areaID() const", asMETHOD(OffMeshConnection, GetAreaID), asCALL_THISCALL);
217 }
218
RegisterObstacle(asIScriptEngine * engine)219 void RegisterObstacle(asIScriptEngine* engine)
220 {
221 RegisterComponent<Obstacle>(engine, "Obstacle");
222 engine->RegisterObjectMethod("Obstacle", "float get_radius() const", asMETHOD(Obstacle, GetRadius), asCALL_THISCALL);
223 engine->RegisterObjectMethod("Obstacle", "void set_radius(float)", asMETHOD(Obstacle, SetRadius), asCALL_THISCALL);
224 engine->RegisterObjectMethod("Obstacle", "float get_height() const", asMETHOD(Obstacle, GetHeight), asCALL_THISCALL);
225 engine->RegisterObjectMethod("Obstacle", "void set_height(float)", asMETHOD(Obstacle, SetHeight), asCALL_THISCALL);
226 engine->RegisterObjectMethod("Obstacle", "uint get_obstacleId() const", asMETHOD(Obstacle, GetObstacleID), asCALL_THISCALL);
227 engine->RegisterObjectMethod("Obstacle", "void DrawDebugGeometry(bool)", asMETHODPR(Obstacle, DrawDebugGeometry, (bool), void), asCALL_THISCALL);
228 }
229
RegisterNavArea(asIScriptEngine * engine)230 void RegisterNavArea(asIScriptEngine* engine)
231 {
232 RegisterComponent<NavArea>(engine, "NavArea");
233 engine->RegisterObjectMethod("NavArea", "BoundingBox get_boundingBox() const", asMETHOD(NavArea, GetBoundingBox), asCALL_THISCALL);
234 engine->RegisterObjectMethod("NavArea", "void set_boundingBox(const BoundingBox&in)", asMETHOD(NavArea, SetBoundingBox), asCALL_THISCALL);
235 engine->RegisterObjectMethod("NavArea", "uint get_areaID() const", asMETHOD(NavArea, GetAreaID), asCALL_THISCALL);
236 engine->RegisterObjectMethod("NavArea", "void set_areaID(uint)", asMETHOD(NavArea, SetAreaID), asCALL_THISCALL);
237 engine->RegisterObjectMethod("NavArea", "BoundingBox get_worldBoundingBox() const", asMETHOD(NavArea, GetWorldBoundingBox), asCALL_THISCALL);
238 }
239
RegisterCrowdManager(asIScriptEngine * engine)240 void RegisterCrowdManager(asIScriptEngine* engine)
241 {
242 engine->RegisterObjectType("CrowdObstacleAvoidanceParams", sizeof(CrowdObstacleAvoidanceParams), asOBJ_VALUE | asOBJ_POD);
243 engine->RegisterObjectProperty("CrowdObstacleAvoidanceParams", "float velBias", offsetof(CrowdObstacleAvoidanceParams, velBias));
244 engine->RegisterObjectProperty("CrowdObstacleAvoidanceParams", "float weightDesVel", offsetof(CrowdObstacleAvoidanceParams, weightDesVel));
245 engine->RegisterObjectProperty("CrowdObstacleAvoidanceParams", "float weightCurVel", offsetof(CrowdObstacleAvoidanceParams, weightCurVel));
246 engine->RegisterObjectProperty("CrowdObstacleAvoidanceParams", "float weightSide", offsetof(CrowdObstacleAvoidanceParams, weightSide));
247 engine->RegisterObjectProperty("CrowdObstacleAvoidanceParams", "float weightToi", offsetof(CrowdObstacleAvoidanceParams, weightToi));
248 engine->RegisterObjectProperty("CrowdObstacleAvoidanceParams", "float horizTime", offsetof(CrowdObstacleAvoidanceParams, horizTime));
249 engine->RegisterObjectProperty("CrowdObstacleAvoidanceParams", "uint8 gridSize", offsetof(CrowdObstacleAvoidanceParams, gridSize));
250 engine->RegisterObjectProperty("CrowdObstacleAvoidanceParams", "uint8 adaptiveDivs", offsetof(CrowdObstacleAvoidanceParams, adaptiveDivs));
251 engine->RegisterObjectProperty("CrowdObstacleAvoidanceParams", "uint8 adaptiveRings", offsetof(CrowdObstacleAvoidanceParams, adaptiveRings));
252 engine->RegisterObjectProperty("CrowdObstacleAvoidanceParams", "uint8 adaptiveDepth", offsetof(CrowdObstacleAvoidanceParams, adaptiveDepth));
253
254 RegisterComponent<CrowdManager>(engine, "CrowdManager");
255 engine->RegisterObjectMethod("CrowdManager", "void DrawDebugGeometry(bool)", asMETHODPR(CrowdManager, DrawDebugGeometry, (bool), void), asCALL_THISCALL);
256 engine->RegisterObjectMethod("CrowdManager", "void SetCrowdTarget(const Vector3&in, Node@+ node = null)", asMETHOD(CrowdManager, SetCrowdTarget), asCALL_THISCALL);
257 engine->RegisterObjectMethod("CrowdManager", "void SetCrowdVelocity(const Vector3&in, Node@+ node = null)", asMETHOD(CrowdManager, SetCrowdVelocity), asCALL_THISCALL);
258 engine->RegisterObjectMethod("CrowdManager", "void ResetCrowdTarget(Node@+ node = null)", asMETHOD(CrowdManager, ResetCrowdTarget), asCALL_THISCALL);
259 engine->RegisterObjectMethod("CrowdManager", "void SetIncludeFlags(uint, uint16)", asMETHOD(CrowdManager, SetIncludeFlags), asCALL_THISCALL);
260 engine->RegisterObjectMethod("CrowdManager", "void SetExcludeFlags(uint, uint16)", asMETHOD(CrowdManager, SetExcludeFlags), asCALL_THISCALL);
261 engine->RegisterObjectMethod("CrowdManager", "void SetAreaCost(uint, uint, float)", asMETHOD(CrowdManager, SetAreaCost), asCALL_THISCALL);
262 engine->RegisterObjectMethod("CrowdManager", "void SetObstacleAvoidanceParams(uint, const CrowdObstacleAvoidanceParams&in)", asMETHOD(CrowdManager, SetObstacleAvoidanceParams), asCALL_THISCALL);
263 engine->RegisterObjectMethod("CrowdManager", "Array<CrowdAgent@>@ GetAgents(Node@+ node = null, bool inCrowdFilter = true)", asFUNCTION(CrowdManagerGetAgents), asCALL_CDECL_OBJLAST);
264 engine->RegisterObjectMethod("CrowdManager", "Vector3 FindNearestPoint(const Vector3&in, int)", asMETHOD(CrowdManager, FindNearestPoint), asCALL_THISCALL);
265 engine->RegisterObjectMethod("CrowdManager", "Vector3 MoveAlongSurface(const Vector3&in, const Vector3&in, int, uint maxVisited = 3)", asMETHOD(CrowdManager, MoveAlongSurface), asCALL_THISCALL);
266 engine->RegisterObjectMethod("CrowdManager", "Vector3 GetRandomPoint(int)", asFUNCTION(CrowdManagerGetRandomPoint), asCALL_CDECL_OBJLAST);
267 engine->RegisterObjectMethod("CrowdManager", "Vector3 GetRandomPointInCircle(const Vector3&in, float, int)", asFUNCTION(CrowdManagerRandomPointInCircle), asCALL_CDECL_OBJLAST);
268 engine->RegisterObjectMethod("CrowdManager", "float GetDistanceToWall(const Vector3&in, float, int)", asMETHOD(CrowdManager, GetDistanceToWall), asCALL_THISCALL);
269 engine->RegisterObjectMethod("CrowdManager", "Vector3 Raycast(const Vector3&in, const Vector3&in, int)", asMETHOD(CrowdManager, Raycast), asCALL_THISCALL);
270 engine->RegisterObjectMethod("CrowdManager", "uint16 GetIncludeFlags(uint)", asMETHOD(CrowdManager, GetIncludeFlags), asCALL_THISCALL);
271 engine->RegisterObjectMethod("CrowdManager", "uint16 GetExcludeFlags(uint)", asMETHOD(CrowdManager, GetExcludeFlags), asCALL_THISCALL);
272 engine->RegisterObjectMethod("CrowdManager", "float GetAreaCost(uint, uint)", asMETHOD(CrowdManager, GetAreaCost), asCALL_THISCALL);
273 engine->RegisterObjectMethod("CrowdManager", "const CrowdObstacleAvoidanceParams& GetObstacleAvoidanceParams(uint)", asMETHOD(CrowdManager, GetObstacleAvoidanceParams), asCALL_THISCALL);
274 engine->RegisterObjectMethod("CrowdManager", "int get_maxAgents() const", asMETHOD(CrowdManager, GetMaxAgents), asCALL_THISCALL);
275 engine->RegisterObjectMethod("CrowdManager", "void set_maxAgents(int)", asMETHOD(CrowdManager, SetMaxAgents), asCALL_THISCALL);
276 engine->RegisterObjectMethod("CrowdManager", "float get_maxAgentRadius() const", asMETHOD(CrowdManager, GetMaxAgentRadius), asCALL_THISCALL);
277 engine->RegisterObjectMethod("CrowdManager", "void set_maxAgentRadius(float)", asMETHOD(CrowdManager, SetMaxAgentRadius), asCALL_THISCALL);
278 engine->RegisterObjectMethod("CrowdManager", "void set_navMesh(NavigationMesh@+)", asMETHOD(CrowdManager, SetNavigationMesh), asCALL_THISCALL);
279 engine->RegisterObjectMethod("CrowdManager", "NavigationMesh@+ get_navMesh() const", asMETHOD(CrowdManager, GetNavigationMesh), asCALL_THISCALL);
280 engine->RegisterObjectMethod("CrowdManager", "uint get_numQueryFilterTypes() const", asMETHOD(CrowdManager, GetNumQueryFilterTypes), asCALL_THISCALL);
281 engine->RegisterObjectMethod("CrowdManager", "uint get_numAreas(uint) const", asMETHOD(CrowdManager, GetNumAreas), asCALL_THISCALL);
282 engine->RegisterObjectMethod("CrowdManager", "uint get_numObstacleAvoidanceTypes() const", asMETHOD(CrowdManager, GetNumObstacleAvoidanceTypes), asCALL_THISCALL);
283 }
284
RegisterCrowdAgent(asIScriptEngine * engine)285 void RegisterCrowdAgent(asIScriptEngine* engine)
286 {
287 engine->RegisterEnum("CrowdAgentRequestedTarget");
288 engine->RegisterEnumValue("CrowdAgentRequestedTarget", "CA_REQUESTEDTARGET_NONE", CA_REQUESTEDTARGET_NONE);
289 engine->RegisterEnumValue("CrowdAgentRequestedTarget", "CA_REQUESTEDTARGET_POSITION", CA_REQUESTEDTARGET_POSITION);
290 engine->RegisterEnumValue("CrowdAgentRequestedTarget", "CA_REQUESTEDTARGET_VELOCITY", CA_REQUESTEDTARGET_VELOCITY);
291
292 engine->RegisterEnum("CrowdAgentTargetState");
293 engine->RegisterEnumValue("CrowdAgentTargetState", "CA_TARGET_NONE", CA_TARGET_NONE);
294 engine->RegisterEnumValue("CrowdAgentTargetState", "CA_TARGET_FAILED", CA_TARGET_FAILED);
295 engine->RegisterEnumValue("CrowdAgentTargetState", "CA_TARGET_VALID", CA_TARGET_VALID);
296 engine->RegisterEnumValue("CrowdAgentTargetState", "CA_TARGET_REQUESTING", CA_TARGET_REQUESTING);
297 engine->RegisterEnumValue("CrowdAgentTargetState", "CA_TARGET_WAITINGFORQUEUE", CA_TARGET_WAITINGFORQUEUE);
298 engine->RegisterEnumValue("CrowdAgentTargetState", "CA_TARGET_WAITINGFORPATH", CA_TARGET_WAITINGFORPATH);
299 engine->RegisterEnumValue("CrowdAgentTargetState", "CA_TARGET_VELOCITY", CA_TARGET_VELOCITY);
300
301 engine->RegisterEnum("CrowdAgentState");
302 engine->RegisterEnumValue("CrowdAgentState", "CA_STATE_INVALID", CA_STATE_INVALID);
303 engine->RegisterEnumValue("CrowdAgentState", "CA_STATE_WALKING", CA_STATE_WALKING);
304 engine->RegisterEnumValue("CrowdAgentState", "CA_STATE_OFFMESH", CA_STATE_OFFMESH);
305
306 engine->RegisterEnum("NavigationQuality");
307 engine->RegisterEnumValue("NavigationQuality", "NAVIGATIONQUALITY_LOW", NAVIGATIONQUALITY_LOW);
308 engine->RegisterEnumValue("NavigationQuality", "NAVIGATIONQUALITY_MEDIUM", NAVIGATIONQUALITY_MEDIUM);
309 engine->RegisterEnumValue("NavigationQuality", "NAVIGATIONQUALITY_HIGH", NAVIGATIONQUALITY_HIGH);
310
311 engine->RegisterEnum("NavigationPushiness");
312 engine->RegisterEnumValue("NavigationPushiness", "NAVIGATIONPUSHINESS_LOW", NAVIGATIONPUSHINESS_LOW);
313 engine->RegisterEnumValue("NavigationPushiness", "NAVIGATIONPUSHINESS_MEDIUM", NAVIGATIONPUSHINESS_MEDIUM);
314 engine->RegisterEnumValue("NavigationPushiness", "NAVIGATIONPUSHINESS_HIGH", NAVIGATIONPUSHINESS_HIGH);
315 engine->RegisterEnumValue("NavigationPushiness", "NAVIGATIONPUSHINESS_NONE", NAVIGATIONPUSHINESS_NONE);
316
317 RegisterComponent<CrowdAgent>(engine, "CrowdAgent");
318 engine->RegisterObjectMethod("CrowdAgent", "void DrawDebugGeometry(bool)", asMETHODPR(CrowdAgent, DrawDebugGeometry, (bool), void), asCALL_THISCALL);
319 engine->RegisterObjectMethod("CrowdAgent", "void ResetTarget()", asMETHOD(CrowdAgent, ResetTarget), asCALL_THISCALL);
320 engine->RegisterObjectMethod("CrowdAgent", "void set_updateNodePosition(bool)", asMETHOD(CrowdAgent, SetUpdateNodePosition), asCALL_THISCALL);
321 engine->RegisterObjectMethod("CrowdAgent", "bool get_updateNodePosition() const", asMETHOD(CrowdAgent, GetUpdateNodePosition), asCALL_THISCALL);
322 engine->RegisterObjectMethod("CrowdAgent", "void set_targetPosition(const Vector3&in)", asMETHOD(CrowdAgent, SetTargetPosition), asCALL_THISCALL);
323 engine->RegisterObjectMethod("CrowdAgent", "const Vector3& get_targetPosition()", asMETHOD(CrowdAgent, GetTargetPosition), asCALL_THISCALL);
324 engine->RegisterObjectMethod("CrowdAgent", "void set_targetVelocity(const Vector3&in)", asMETHOD(CrowdAgent, SetTargetVelocity), asCALL_THISCALL);
325 engine->RegisterObjectMethod("CrowdAgent", "const Vector3& get_targetVelocity()", asMETHOD(CrowdAgent, GetTargetVelocity), asCALL_THISCALL);
326 engine->RegisterObjectMethod("CrowdAgent", "void set_maxAccel(float)", asMETHOD(CrowdAgent, SetMaxAccel), asCALL_THISCALL);
327 engine->RegisterObjectMethod("CrowdAgent", "float get_maxAccel()", asMETHOD(CrowdAgent, GetMaxAccel), asCALL_THISCALL);
328 engine->RegisterObjectMethod("CrowdAgent", "void set_maxSpeed(float)", asMETHOD(CrowdAgent, SetMaxSpeed), asCALL_THISCALL);
329 engine->RegisterObjectMethod("CrowdAgent", "float get_maxSpeed()", asMETHOD(CrowdAgent, GetMaxSpeed), asCALL_THISCALL);
330 engine->RegisterObjectMethod("CrowdAgent", "void set_radius(float)", asMETHOD(CrowdAgent, SetRadius), asCALL_THISCALL);
331 engine->RegisterObjectMethod("CrowdAgent", "float get_radius()", asMETHOD(CrowdAgent, GetRadius), asCALL_THISCALL);
332 engine->RegisterObjectMethod("CrowdAgent", "void set_height(float)", asMETHOD(CrowdAgent, SetHeight), asCALL_THISCALL);
333 engine->RegisterObjectMethod("CrowdAgent", "float get_height()", asMETHOD(CrowdAgent, GetHeight), asCALL_THISCALL);
334 engine->RegisterObjectMethod("CrowdAgent", "uint get_queryFilterType()", asMETHOD(CrowdAgent, GetQueryFilterType), asCALL_THISCALL);
335 engine->RegisterObjectMethod("CrowdAgent", "void set_queryFilterType(uint)", asMETHOD(CrowdAgent, SetQueryFilterType), asCALL_THISCALL);
336 engine->RegisterObjectMethod("CrowdAgent", "uint get_obstacleAvoidanceType()", asMETHOD(CrowdAgent, GetObstacleAvoidanceType), asCALL_THISCALL);
337 engine->RegisterObjectMethod("CrowdAgent", "void set_obstacleAvoidanceType(uint)", asMETHOD(CrowdAgent, SetObstacleAvoidanceType), asCALL_THISCALL);
338 engine->RegisterObjectMethod("CrowdAgent", "void set_navigationQuality(NavigationQuality)", asMETHOD(CrowdAgent, SetNavigationQuality), asCALL_THISCALL);
339 engine->RegisterObjectMethod("CrowdAgent", "NavigationQuality get_navigationQuality()", asMETHOD(CrowdAgent, GetNavigationQuality), asCALL_THISCALL);
340 engine->RegisterObjectMethod("CrowdAgent", "void set_navigationPushiness(NavigationPushiness)", asMETHOD(CrowdAgent, SetNavigationPushiness), asCALL_THISCALL);
341 engine->RegisterObjectMethod("CrowdAgent", "NavigationPushiness get_navigationPushiness()", asMETHOD(CrowdAgent, GetNavigationPushiness), asCALL_THISCALL);
342 engine->RegisterObjectMethod("CrowdAgent", "CrowdAgentRequestedTarget get_requestedTargetType() const", asMETHOD(CrowdAgent, GetRequestedTargetType), asCALL_THISCALL);
343 engine->RegisterObjectMethod("CrowdAgent", "Vector3 get_position() const", asMETHOD(CrowdAgent, GetPosition), asCALL_THISCALL);
344 engine->RegisterObjectMethod("CrowdAgent", "Vector3 get_desiredVelocity() const", asMETHOD(CrowdAgent, GetDesiredVelocity), asCALL_THISCALL);
345 engine->RegisterObjectMethod("CrowdAgent", "Vector3 get_actualVelocity() const", asMETHOD(CrowdAgent, GetActualVelocity), asCALL_THISCALL);
346 engine->RegisterObjectMethod("CrowdAgent", "CrowdAgentState get_agentState() const", asMETHOD(CrowdAgent, GetAgentState), asCALL_THISCALL);
347 engine->RegisterObjectMethod("CrowdAgent", "CrowdAgentTargetState get_targetState() const", asMETHOD(CrowdAgent, GetTargetState), asCALL_THISCALL);
348 engine->RegisterObjectMethod("CrowdAgent", "bool get_requestedTarget() const", asMETHOD(CrowdAgent, HasRequestedTarget), asCALL_THISCALL);
349 engine->RegisterObjectMethod("CrowdAgent", "bool get_arrived() const", asMETHOD(CrowdAgent, HasArrived), asCALL_THISCALL);
350 engine->RegisterObjectMethod("CrowdAgent", "bool get_inCrowd() const", asMETHOD(CrowdAgent, IsInCrowd), asCALL_THISCALL);
351 }
352
RegisterNavigationAPI(asIScriptEngine * engine)353 void RegisterNavigationAPI(asIScriptEngine* engine)
354 {
355 RegisterNavigationMesh(engine);
356 RegisterCrowdAgent(engine);
357 RegisterCrowdManager(engine);
358 RegisterDynamicNavigationMesh(engine);
359 RegisterNavArea(engine);
360 RegisterNavigable(engine);
361 RegisterObstacle(engine);
362 RegisterOffMeshConnection(engine);
363 }
364
365 }
366
367 #endif
368