
org.recast4j.detour.extras.unity.astar.LinkBuilder Maven / Gradle / Ivy
The newest version!
/*
recast4j copyright (c) 2015-2019 Piotr Piastucki [email protected]
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
package org.recast4j.detour.extras.unity.astar;
import java.util.List;
import org.recast4j.detour.MeshData;
import org.recast4j.detour.NavMesh;
import org.recast4j.detour.Poly;
import org.recast4j.detour.extras.PolyUtils;
class LinkBuilder {
// Process connections and transform them into recast neighbour flags
void build(int nodeOffset, GraphMeshData graphData, List connections) {
for (int n = 0; n < connections.size(); n++) {
int[] nodeConnections = connections.get(n);
MeshData tile = graphData.getTile(n);
Poly node = graphData.getNode(n);
for (int connection : nodeConnections) {
MeshData neighbourTile = graphData.getTile(connection - nodeOffset);
if (neighbourTile != tile) {
buildExternalLink(tile, node, neighbourTile);
} else {
Poly neighbour = graphData.getNode(connection - nodeOffset);
buildInternalLink(tile, node, neighbourTile, neighbour);
}
}
}
}
private void buildInternalLink(MeshData tile, Poly node, MeshData neighbourTile, Poly neighbour) {
int edge = PolyUtils.findEdge(node, neighbour, tile, neighbourTile);
if (edge >= 0) {
node.neis[edge] = neighbour.index + 1;
} else {
throw new IllegalArgumentException();
}
}
// In case of external link to other tiles we must find the direction
private void buildExternalLink(MeshData tile, Poly node, MeshData neighbourTile) {
if (neighbourTile.header.bmin[0] > tile.header.bmin[0]) {
node.neis[PolyUtils.findEdge(node, tile, neighbourTile.header.bmin[0], 0)] = NavMesh.DT_EXT_LINK;
} else if (neighbourTile.header.bmin[0] < tile.header.bmin[0]) {
node.neis[PolyUtils.findEdge(node, tile, tile.header.bmin[0], 0)] = NavMesh.DT_EXT_LINK | 4;
} else if (neighbourTile.header.bmin[2] > tile.header.bmin[2]) {
node.neis[PolyUtils.findEdge(node, tile, neighbourTile.header.bmin[2], 2)] = NavMesh.DT_EXT_LINK | 2;
} else {
node.neis[PolyUtils.findEdge(node, tile, tile.header.bmin[2], 2)] = NavMesh.DT_EXT_LINK | 6;
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy