本文整理汇总了C#中Pathfinding.TriangleMeshNode.GetVertex方法的典型用法代码示例。如果您正苦于以下问题:C# TriangleMeshNode.GetVertex方法的具体用法?C# TriangleMeshNode.GetVertex怎么用?C# TriangleMeshNode.GetVertex使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Pathfinding.TriangleMeshNode
的用法示例。
在下文中一共展示了TriangleMeshNode.GetVertex方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ReplaceTile
//.........这里部分代码省略.........
//Create a new navmesh tile and assign its settings
NavmeshTile tile = new NavmeshTile();
tile.x = x;
tile.z = z;
tile.w = w;
tile.d = d;
tile.tris = tris;
tile.verts = verts;
tile.bbTree = new BBTree(tile);
if (tile.tris.Length % 3 != 0) throw new System.ArgumentException ("Triangle array's length must be a multiple of 3 (tris)");
if (tile.verts.Length > 0xFFFF) throw new System.ArgumentException ("Too many vertices per tile (more than 65535)");
if (!worldSpace) {
if (!Mathf.Approximately (x*tileSizeX*cellSize*Int3.FloatPrecision, (float)System.Math.Round(x*tileSizeX*cellSize*Int3.FloatPrecision))) Debug.LogWarning ("Possible numerical imprecision. Consider adjusting tileSize and/or cellSize");
if (!Mathf.Approximately (z*tileSizeZ*cellSize*Int3.FloatPrecision, (float)System.Math.Round(z*tileSizeZ*cellSize*Int3.FloatPrecision))) Debug.LogWarning ("Possible numerical imprecision. Consider adjusting tileSize and/or cellSize");
Int3 offset = (Int3)(new Vector3((x * tileSizeX * cellSize),0,(z * tileSizeZ * cellSize)) + forcedBounds.min);
for (int i=0;i<verts.Length;i++) {
verts[i] += offset;
}
}
TriangleMeshNode[] nodes = new TriangleMeshNode[tile.tris.Length/3];
tile.nodes = nodes;
//Here we are faking a new graph
//The tile is not added to any graphs yet, but to get the position querys from the nodes
//to work correctly (not throw exceptions because the tile is not calculated) we fake a new graph
//and direct the position queries directly to the tile
int graphIndex = AstarPath.active.astarData.graphs.Length;
TriangleMeshNode.SetNavmeshHolder (graphIndex, tile);
//This index will be ORed to the triangle indices
int tileIndex = x + z*tileXCount;
tileIndex <<= TileIndexOffset;
//Create nodes and assign triangle indices
for (int i=0;i<nodes.Length;i++) {
TriangleMeshNode node = new TriangleMeshNode(active);
nodes[i] = node;
node.GraphIndex = (uint)graphIndex;
node.v0 = tile.tris[i*3+0] | tileIndex;
node.v1 = tile.tris[i*3+1] | tileIndex;
node.v2 = tile.tris[i*3+2] | tileIndex;
//Degenerate triangles might ocurr, but they will not cause any large troubles anymore
//if (Polygon.IsColinear (node.GetVertex(0), node.GetVertex(1), node.GetVertex(2))) {
// Debug.Log ("COLINEAR!!!!!!");
//}
//Make sure the triangle is clockwise
if (!Polygon.IsClockwise (node.GetVertex(0), node.GetVertex(1), node.GetVertex(2))) {
int tmp = node.v0;
node.v0 = node.v2;
node.v2 = tmp;
}
node.Walkable = true;
node.Penalty = initialPenalty;
node.UpdatePositionFromVertices();
tile.bbTree.Insert (node);
}
CreateNodeConnections (tile.nodes);
//Set tile
for (int cz=z; cz < z+d;cz++) {
for (int cx=x; cx < x+w;cx++) {
tiles[cx + cz*tileXCount] = tile;
}
}
if (batchTileUpdate) {
batchUpdatedTiles.Add (x + z*tileXCount);
} else {
ConnectTileWithNeighbours(tile);
/*if (x > 0) ConnectTiles (tiles[(x-1) + z*tileXCount], tile);
if (z > 0) ConnectTiles (tiles[x + (z-1)*tileXCount], tile);
if (x < tileXCount-1) ConnectTiles (tiles[(x+1) + z*tileXCount], tile);
if (z < tileZCount-1) ConnectTiles (tiles[x + (z+1)*tileXCount], tile);*/
}
//Remove the fake graph
TriangleMeshNode.SetNavmeshHolder (graphIndex, null);
//Real graph index
//TODO, could this step be changed for this function, is a fake index required?
graphIndex = AstarPath.active.astarData.GetGraphIndex (this);
for (int i=0;i<nodes.Length;i++) nodes[i].GraphIndex = (uint)graphIndex;
}
示例2: ReplaceTile
//.........这里部分代码省略.........
{
throw new Exception("This should not happen");
}
if (l < z || l >= z + d || m < x || m >= x + w)
{
this.tiles[m + l * this.tileXCount] = RecastGraph.NewEmptyTile(m, l);
if (this.batchTileUpdate)
{
this.batchUpdatedTiles.Add(m + l * this.tileXCount);
}
}
else
{
this.tiles[m + l * this.tileXCount] = null;
}
}
}
}
}
}
RecastGraph.NavmeshTile navmeshTile3 = new RecastGraph.NavmeshTile();
navmeshTile3.x = x;
navmeshTile3.z = z;
navmeshTile3.w = w;
navmeshTile3.d = d;
navmeshTile3.tris = tris;
navmeshTile3.verts = verts;
navmeshTile3.bbTree = new BBTree();
if (navmeshTile3.tris.Length % 3 != 0)
{
throw new ArgumentException("Triangle array's length must be a multiple of 3 (tris)");
}
if (navmeshTile3.verts.Length > 65535)
{
throw new ArgumentException("Too many vertices per tile (more than 65535)");
}
if (!worldSpace)
{
if (!Mathf.Approximately((float)(x * this.tileSizeX) * this.cellSize * 1000f, (float)Math.Round((double)((float)(x * this.tileSizeX) * this.cellSize * 1000f))))
{
UnityEngine.Debug.LogWarning("Possible numerical imprecision. Consider adjusting tileSize and/or cellSize");
}
if (!Mathf.Approximately((float)(z * this.tileSizeZ) * this.cellSize * 1000f, (float)Math.Round((double)((float)(z * this.tileSizeZ) * this.cellSize * 1000f))))
{
UnityEngine.Debug.LogWarning("Possible numerical imprecision. Consider adjusting tileSize and/or cellSize");
}
Int3 rhs = (Int3)(new Vector3((float)(x * this.tileSizeX) * this.cellSize, 0f, (float)(z * this.tileSizeZ) * this.cellSize) + this.forcedBounds.min);
for (int n = 0; n < verts.Length; n++)
{
verts[n] += rhs;
}
}
TriangleMeshNode[] array = new TriangleMeshNode[navmeshTile3.tris.Length / 3];
navmeshTile3.nodes = array;
int graphIndex = AstarPath.active.astarData.graphs.Length;
TriangleMeshNode.SetNavmeshHolder(graphIndex, navmeshTile3);
int num = x + z * this.tileXCount;
num <<= 12;
for (int num2 = 0; num2 < array.Length; num2++)
{
TriangleMeshNode triangleMeshNode = new TriangleMeshNode(this.active);
array[num2] = triangleMeshNode;
triangleMeshNode.GraphIndex = (uint)graphIndex;
triangleMeshNode.v0 = (navmeshTile3.tris[num2 * 3] | num);
triangleMeshNode.v1 = (navmeshTile3.tris[num2 * 3 + 1] | num);
triangleMeshNode.v2 = (navmeshTile3.tris[num2 * 3 + 2] | num);
if (!Polygon.IsClockwise(triangleMeshNode.GetVertex(0), triangleMeshNode.GetVertex(1), triangleMeshNode.GetVertex(2)))
{
int v = triangleMeshNode.v0;
triangleMeshNode.v0 = triangleMeshNode.v2;
triangleMeshNode.v2 = v;
}
triangleMeshNode.Walkable = true;
triangleMeshNode.Penalty = this.initialPenalty;
triangleMeshNode.UpdatePositionFromVertices();
}
navmeshTile3.bbTree.RebuildFrom(array);
this.CreateNodeConnections(navmeshTile3.nodes);
for (int num3 = z; num3 < z + d; num3++)
{
for (int num4 = x; num4 < x + w; num4++)
{
this.tiles[num4 + num3 * this.tileXCount] = navmeshTile3;
}
}
if (this.batchTileUpdate)
{
this.batchUpdatedTiles.Add(x + z * this.tileXCount);
}
else
{
this.ConnectTileWithNeighbours(navmeshTile3);
}
TriangleMeshNode.SetNavmeshHolder(graphIndex, null);
graphIndex = AstarPath.active.astarData.GetGraphIndex(this);
for (int num5 = 0; num5 < array.Length; num5++)
{
array[num5].GraphIndex = (uint)graphIndex;
}
}
示例3: CreateTile
/** Create a tile at tile index \a x , \a z from the mesh.
* \warning This implementation is not thread safe. It uses cached variables to improve performance
*/
NavmeshTile CreateTile (Voxelize vox, VoxelMesh mesh, int x, int z) {
if (mesh.tris == null) throw new System.ArgumentNullException ("The mesh must be valid. tris is null.");
if (mesh.verts == null) throw new System.ArgumentNullException ("The mesh must be valid. verts is null.");
//Create a new navmesh tile and assign its settings
NavmeshTile tile = new NavmeshTile();
tile.x = x;
tile.z = z;
tile.w = 1;
tile.d = 1;
tile.tris = mesh.tris;
tile.verts = mesh.verts;
tile.bbTree = new BBTree(tile);
if (tile.tris.Length % 3 != 0) throw new System.ArgumentException ("Indices array's length must be a multiple of 3 (mesh.tris)");
if (tile.verts.Length >= VertexIndexMask) throw new System.ArgumentException ("Too many vertices per tile (more than "+VertexIndexMask+")." +
"\nTry enabling ASTAR_RECAST_LARGER_TILES under the 'Optimizations' tab in the A* Inspector");
//Dictionary<Int3, int> firstVerts = new Dictionary<Int3, int> ();
Dictionary<Int3, int> firstVerts = cachedInt3_int_dict;
firstVerts.Clear();
int[] compressedPointers = new int[tile.verts.Length];
int count = 0;
for (int i=0;i<tile.verts.Length;i++) {
try {
firstVerts.Add (tile.verts[i], count);
compressedPointers[i] = count;
tile.verts[count] = tile.verts[i];
count++;
} catch {
//There are some cases, rare but still there, that vertices are identical
compressedPointers[i] = firstVerts[tile.verts[i]];
}
}
for (int i=0;i<tile.tris.Length;i++) {
tile.tris[i] = compressedPointers[tile.tris[i]];
}
Int3[] compressed = new Int3[count];
for (int i=0;i<count;i++) compressed[i] = tile.verts[i];
tile.verts = compressed;
TriangleMeshNode[] nodes = new TriangleMeshNode[tile.tris.Length/3];
tile.nodes = nodes;
//Here we are faking a new graph
//The tile is not added to any graphs yet, but to get the position querys from the nodes
//to work correctly (not throw exceptions because the tile is not calculated) we fake a new graph
//and direct the position queries directly to the tile
int graphIndex = AstarPath.active.astarData.graphs.Length;
TriangleMeshNode.SetNavmeshHolder (graphIndex, tile);
//This index will be ORed to the triangle indices
int tileIndex = x + z*tileXCount;
tileIndex <<= TileIndexOffset;
//Create nodes and assign triangle indices
for (int i=0;i<nodes.Length;i++) {
TriangleMeshNode node = new TriangleMeshNode(active);
nodes[i] = node;
node.GraphIndex = (uint)graphIndex;
node.v0 = tile.tris[i*3+0] | tileIndex;
node.v1 = tile.tris[i*3+1] | tileIndex;
node.v2 = tile.tris[i*3+2] | tileIndex;
//Degenerate triangles might ocurr, but they will not cause any large troubles anymore
//if (Polygon.IsColinear (node.GetVertex(0), node.GetVertex(1), node.GetVertex(2))) {
// Debug.Log ("COLINEAR!!!!!!");
//}
//Make sure the triangle is clockwise
if (!Polygon.IsClockwise (node.GetVertex(0), node.GetVertex(1), node.GetVertex(2))) {
int tmp = node.v0;
node.v0 = node.v2;
node.v2 = tmp;
}
node.Walkable = true;
node.Penalty = initialPenalty;
node.UpdatePositionFromVertices();
tile.bbTree.Insert (node);
}
CreateNodeConnections (tile.nodes);
//Remove the fake graph
TriangleMeshNode.SetNavmeshHolder (graphIndex, null);
return tile;
//.........这里部分代码省略.........
示例4: CreateTile
private RecastGraph.NavmeshTile CreateTile(Voxelize vox, VoxelMesh mesh, int x, int z)
{
if (mesh.tris == null)
{
throw new ArgumentNullException("mesh.tris");
}
if (mesh.verts == null)
{
throw new ArgumentNullException("mesh.verts");
}
RecastGraph.NavmeshTile navmeshTile = new RecastGraph.NavmeshTile();
navmeshTile.x = x;
navmeshTile.z = z;
navmeshTile.w = 1;
navmeshTile.d = 1;
navmeshTile.tris = mesh.tris;
navmeshTile.verts = mesh.verts;
navmeshTile.bbTree = new BBTree();
if (navmeshTile.tris.Length % 3 != 0)
{
throw new ArgumentException("Indices array's length must be a multiple of 3 (mesh.tris)");
}
if (navmeshTile.verts.Length >= 4095)
{
throw new ArgumentException("Too many vertices per tile (more than " + 4095 + ").\nTry enabling ASTAR_RECAST_LARGER_TILES under the 'Optimizations' tab in the A* Inspector");
}
Dictionary<Int3, int> dictionary = this.cachedInt3_int_dict;
dictionary.Clear();
int[] array = new int[navmeshTile.verts.Length];
int num = 0;
for (int i = 0; i < navmeshTile.verts.Length; i++)
{
if (!dictionary.ContainsKey(navmeshTile.verts[i]))
{
dictionary.Add(navmeshTile.verts[i], num);
array[i] = num;
navmeshTile.verts[num] = navmeshTile.verts[i];
num++;
}
else
{
array[i] = dictionary[navmeshTile.verts[i]];
}
}
for (int j = 0; j < navmeshTile.tris.Length; j++)
{
navmeshTile.tris[j] = array[navmeshTile.tris[j]];
}
Int3[] array2 = new Int3[num];
for (int k = 0; k < num; k++)
{
array2[k] = navmeshTile.verts[k];
}
navmeshTile.verts = array2;
TriangleMeshNode[] array3 = new TriangleMeshNode[navmeshTile.tris.Length / 3];
navmeshTile.nodes = array3;
int graphIndex = AstarPath.active.astarData.graphs.Length;
TriangleMeshNode.SetNavmeshHolder(graphIndex, navmeshTile);
int num2 = x + z * this.tileXCount;
num2 <<= 12;
for (int l = 0; l < array3.Length; l++)
{
TriangleMeshNode triangleMeshNode = new TriangleMeshNode(this.active);
array3[l] = triangleMeshNode;
triangleMeshNode.GraphIndex = (uint)graphIndex;
triangleMeshNode.v0 = (navmeshTile.tris[l * 3] | num2);
triangleMeshNode.v1 = (navmeshTile.tris[l * 3 + 1] | num2);
triangleMeshNode.v2 = (navmeshTile.tris[l * 3 + 2] | num2);
if (!Polygon.IsClockwise(triangleMeshNode.GetVertex(0), triangleMeshNode.GetVertex(1), triangleMeshNode.GetVertex(2)))
{
int v = triangleMeshNode.v0;
triangleMeshNode.v0 = triangleMeshNode.v2;
triangleMeshNode.v2 = v;
}
triangleMeshNode.Walkable = true;
triangleMeshNode.Penalty = this.initialPenalty;
triangleMeshNode.UpdatePositionFromVertices();
}
navmeshTile.bbTree.RebuildFrom(array3);
this.CreateNodeConnections(navmeshTile.nodes);
TriangleMeshNode.SetNavmeshHolder(graphIndex, null);
return navmeshTile;
}