cz.cuni.amis.pogamut.ut2004.agent.navigation.navmesh
Class NavMesh

Package class diagram package NavMesh
java.lang.Object
  extended by cz.cuni.amis.pogamut.ut2004.agent.navigation.navmesh.NavMesh
All Implemented Interfaces:
IPathPlanner<ILocated>

public class NavMesh
extends Object
implements IPathPlanner<ILocated>

Class storing NavMesh data structures. Controlled from NavMeshModule.

Author:
Jakub Tomek, Jakub Gemrot aka Jimmy

Constructor Summary
NavMesh(IWorldView worldView, Logger log)
           
 
Method Summary
protected  void clear()
          Reseting NavMesh instance, completely "unloading" the NavMesh.
 IPathFuture<ILocated> computePath(ILocated from, ILocated to)
          Computes and returns a path between two points anywhere on the map.
protected  boolean eliminateUnreachablePolygons()
          Some polygons cannot be reached we find them with the help of navigation graph Definition: 1.
 NavMeshBSPNode getBiggestLeafInTree()
           
 double getDistance(ILocated from, ILocated to)
           
protected  double getDistance(INavMeshAtom atom1, INavMeshAtom atom2)
          Returns distance between two atoms (euclidean distance) If the atom is a polygon, this method takes its middle
 double getDistanceFromEdge(Location location, javax.vecmath.Vector2d vector)
          Returns distance of the location from the navmesh's edge in the given direction.
 double getDistanceFromEdge(Location location, javax.vecmath.Vector2d vector, double rayLength)
          A simple implementation of NavMesh's 2D raycasting.
 NavMeshPolygon getNearestPolygon(Location location)
           
 ArrayList<Integer> getNeighbourIdsToPolygon(int polygonId)
          Gets an array of polygon ids by an polygon id
 int getNeighbourPolygon(int currentPolygonId, int v1, int v2)
          Finds neighbour behind given vertexes.
 int getNumberOfPolygonsInBiggestLeaf()
          Debug method: helps to describe BSP tree by telling the number of polygons in the biggest leaf (this should not bee too big. 5 is a good number.)
 ArrayList<OffMeshPoint> getOffMeshPoints()
          Returns list of OffMeshPoints within the NavMesh.
 List<OffMeshPoint> getOffMeshPointsOnPolygon(int polygonId)
          Returns a List of offmeshpoints that are located on target polygon
 List<ILocated> getPath(ILocated from, ILocated to)
          Computes and returns a path between two points anywhere on the map.
 int[] getPolygon(int polygonId)
          Gets a clone of polygon by its order
 int getPolygonId(Location location)
          Gets the id of a polygon that contains this location
 int getPolygonId(math.geom3d.Point3D point3D)
          Returns PolygonId for a given point3D.
 List<INavMeshAtom> getPolygonPath(INavMeshAtom fromAtom, INavMeshAtom toAtom)
          Gets a List of polygons on which the path should go.
 List<INavMeshAtom> getPolygonPath(Location from, Location to)
          Calls the method with the same name but polygons as arguments and returns result
 ArrayList<Integer> getPolygonsByVertex(int vertexId)
          Gets a list of polygons containing this vertex.
 ArrayList<int[]> getPolys()
          Returns list of all NavMesh polygons.
 double[] getVertex(int vertexId)
          Gets a clone of vertex by its order
 ArrayList<double[]> getVerts()
          Returns list of all NavMesh points.
 boolean isLoaded()
          Tells whether the NavMesh has been successfully initialized and thus can be used.
 boolean load(GameInfo info, boolean shouldReloadNavMesh)
          Load NavMesh according to current map (obtained through GameInfo.getLevel()) from directories specified by NavMeshConstants.
protected  void loadNavMeshFromCoreFile(File processedNavMeshFile)
           
protected  void loadSourceFile(File pureMeshFile)
           
 int polyCount()
          Returns the number of polygons in navmesh
protected  void resetBSPTree()
          Gets a new BSPTree for this mesh
protected  void resetOffMeshConnections()
          Creates off-mesh connections between polygons that does not share an edge, but there is a connection from one to the other in navigation graph.
protected  void resetSafeVerts()
          Resets the array of boolean values saying whether a vertex is at the edge of navmesh
protected  void resetVertsToPolys()
          Builds the resetVertsToPolys mapping array
protected  void saveNavMeshCore(String mapName)
           
 void setBiggestLeafInTree(NavMeshBSPNode node)
          DEBUG ONLY: sets the biggest leaf so it can be easily found.
protected  void setFwMap(FloydWarshallMap fwMap)
           
 int vertCount()
          Returns the number of vertices in navmesh
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NavMesh

public NavMesh(IWorldView worldView,
               Logger log)
Method Detail

isLoaded

public boolean isLoaded()
Tells whether the NavMesh has been successfully initialized and thus can be used. Use load(GameInfo, boolean) to initialize NavMesh.

Returns:

polyCount

public int polyCount()
Returns the number of polygons in navmesh


vertCount

public int vertCount()
Returns the number of vertices in navmesh


getPolys

public ArrayList<int[]> getPolys()
Returns list of all NavMesh polygons. A polygon is formed by triple [vertexId, vertexId, vertexId] pointing into getVerts() array.

Returns:

getVerts

public ArrayList<double[]> getVerts()
Returns list of all NavMesh points. A point is formed by triple [double,double,double] ~ [x,y,z].

Returns:

getPolygon

public int[] getPolygon(int polygonId)
Gets a clone of polygon by its order


getVertex

public double[] getVertex(int vertexId)
Gets a clone of vertex by its order


getPolygonsByVertex

public ArrayList<Integer> getPolygonsByVertex(int vertexId)
Gets a list of polygons containing this vertex.


getNeighbourIdsToPolygon

public ArrayList<Integer> getNeighbourIdsToPolygon(int polygonId)
Gets an array of polygon ids by an polygon id


getOffMeshPoints

public ArrayList<OffMeshPoint> getOffMeshPoints()
Returns list of OffMeshPoints within the NavMesh.

Returns:

getOffMeshPointsOnPolygon

public List<OffMeshPoint> getOffMeshPointsOnPolygon(int polygonId)
Returns a List of offmeshpoints that are located on target polygon

Parameters:
polygonId -
Returns:

getNumberOfPolygonsInBiggestLeaf

public int getNumberOfPolygonsInBiggestLeaf()
Debug method: helps to describe BSP tree by telling the number of polygons in the biggest leaf (this should not bee too big. 5 is a good number.)


setBiggestLeafInTree

public void setBiggestLeafInTree(NavMeshBSPNode node)
DEBUG ONLY: sets the biggest leaf so it can be easily found.


getPolygonId

public int getPolygonId(math.geom3d.Point3D point3D)
Returns PolygonId for a given point3D.

Parameters:
point3D -
Returns:
id of polygon on which is this point

getPolygonId

public int getPolygonId(Location location)
Gets the id of a polygon that contains this location

Parameters:
location -
Returns:
id of polygon or value < 0 if the is no such polygon

load

public boolean load(GameInfo info,
                    boolean shouldReloadNavMesh)
Load NavMesh according to current map (obtained through GameInfo.getLevel()) from directories specified by NavMeshConstants.

Parameters:
info -
shouldReloadNavMesh - whether we should ignore ".navmesh.processed" file and recreate NavMesh again, comes in handy when you are working with NavigationGraphBuilder
Returns:

loadNavMeshFromCoreFile

protected void loadNavMeshFromCoreFile(File processedNavMeshFile)
                                throws FileNotFoundException,
                                       IOException,
                                       ClassNotFoundException
Throws:
FileNotFoundException
IOException
ClassNotFoundException

loadSourceFile

protected void loadSourceFile(File pureMeshFile)
                       throws NumberFormatException,
                              IOException
Throws:
NumberFormatException
IOException

resetVertsToPolys

protected void resetVertsToPolys()
Builds the resetVertsToPolys mapping array


resetSafeVerts

protected void resetSafeVerts()
Resets the array of boolean values saying whether a vertex is at the edge of navmesh


resetBSPTree

protected void resetBSPTree()
Gets a new BSPTree for this mesh


eliminateUnreachablePolygons

protected boolean eliminateUnreachablePolygons()
Some polygons cannot be reached we find them with the help of navigation graph Definition: 1. Any polygon with navigation point is reachable 2. Any polygon sharing edge with a reachable polygon is also reachable.


resetOffMeshConnections

protected void resetOffMeshConnections()
Creates off-mesh connections between polygons that does not share an edge, but there is a connection from one to the other in navigation graph. The endpoints are not necessarily polygons. Thay also may be off-mesh navpoints. This method also creates list of off-mesh points and also creates mappings between polygons and these points


saveNavMeshCore

protected void saveNavMeshCore(String mapName)

computePath

public IPathFuture<ILocated> computePath(ILocated from,
                                         ILocated to)
Computes and returns a path between two points anywhere on the map. If no such path is found, returns path of zero length;

Specified by:
computePath in interface IPathPlanner<ILocated>
Parameters:
from -
to -
Returns:

getDistance

public double getDistance(ILocated from,
                          ILocated to)
Specified by:
getDistance in interface IPathPlanner<ILocated>

getPolygonPath

public List<INavMeshAtom> getPolygonPath(INavMeshAtom fromAtom,
                                         INavMeshAtom toAtom)
Gets a List of polygons on which the path should go.

Parameters:
fromAtom -
toAtom -
Returns:

getPolygonPath

public List<INavMeshAtom> getPolygonPath(Location from,
                                         Location to)
Calls the method with the same name but polygons as arguments and returns result

Parameters:
from -
to -
Returns:

getPath

public List<ILocated> getPath(ILocated from,
                              ILocated to)
Computes and returns a path between two points anywhere on the map. If no such path is found, returns null;

Parameters:
from -
to -
Returns:

getNearestPolygon

public NavMeshPolygon getNearestPolygon(Location location)

getDistance

protected double getDistance(INavMeshAtom atom1,
                             INavMeshAtom atom2)
Returns distance between two atoms (euclidean distance) If the atom is a polygon, this method takes its middle

Parameters:
atom1 -
atom2 -
Returns:

getDistanceFromEdge

public double getDistanceFromEdge(Location location,
                                  javax.vecmath.Vector2d vector,
                                  double rayLength)
A simple implementation of NavMesh's 2D raycasting. Returns distance from the edge of navmesh in a direction from a location if the entrire ray is inside navmesh of there is no navmesh it returns 0;

Parameters:
location -
vector -
Returns:

getDistanceFromEdge

public double getDistanceFromEdge(Location location,
                                  javax.vecmath.Vector2d vector)
Returns distance of the location from the navmesh's edge in the given direction. If location is not not on navmesh, 0 is returned

Parameters:
location -
vector -
Returns:

getNeighbourPolygon

public int getNeighbourPolygon(int currentPolygonId,
                               int v1,
                               int v2)
Finds neighbour behind given vertexes. Returns polygon id or -1 there is none

Parameters:
currentPolygonId -
v1 -
v2 -
Returns:

getBiggestLeafInTree

public NavMeshBSPNode getBiggestLeafInTree()

setFwMap

protected void setFwMap(FloydWarshallMap fwMap)

clear

protected void clear()
Reseting NavMesh instance, completely "unloading" the NavMesh.



Copyright © 2015 AMIS research group, Faculty of Mathematics and Physics, Charles University in Prague, Czech Republic. All Rights Reserved.