public static SetNavmeshHolder ( int graphIndex, INavmeshHolder graph ) : void | ||
graphIndex | int | |
graph | INavmeshHolder | |
return | void |
public override void DeserializeExtraInfo(GraphSerializationContext ctx) { uint graphIndex = (uint)ctx.graphIndex; TriangleMeshNode.SetNavmeshHolder((int)graphIndex, this); int num = ctx.reader.ReadInt32(); int num2 = ctx.reader.ReadInt32(); if (num == -1) { this.nodes = new TriangleMeshNode[0]; this._vertices = new Int3[0]; this.originalVertices = new Vector3[0]; } this.nodes = new TriangleMeshNode[num]; this._vertices = new Int3[num2]; this.originalVertices = new Vector3[num2]; for (int i = 0; i < num2; i++) { this._vertices[i] = new Int3(ctx.reader.ReadInt32(), ctx.reader.ReadInt32(), ctx.reader.ReadInt32()); this.originalVertices[i] = new Vector3(ctx.reader.ReadSingle(), ctx.reader.ReadSingle(), ctx.reader.ReadSingle()); } this.bbTree = new BBTree(); for (int j = 0; j < num; j++) { this.nodes[j] = new TriangleMeshNode(this.active); TriangleMeshNode triangleMeshNode = this.nodes[j]; triangleMeshNode.DeserializeNode(ctx); triangleMeshNode.UpdatePositionFromVertices(); } this.bbTree.RebuildFrom(this.nodes); }
public override void OnDestroy() { base.OnDestroy(); // Cleanup TriangleMeshNode.SetNavmeshHolder(active.astarData.GetGraphIndex(this), null); }
public override void DeserializeExtraInfo(GraphSerializationContext ctx) { uint graphIndex = (uint)ctx.graphIndex; TriangleMeshNode.SetNavmeshHolder((int)graphIndex, this); int c1 = ctx.reader.ReadInt32(); int c2 = ctx.reader.ReadInt32(); if (c1 == -1) { nodes = new TriangleMeshNode[0]; _vertices = new Int3[0]; originalVertices = new Vector3[0]; } nodes = new TriangleMeshNode[c1]; _vertices = new Int3[c2]; originalVertices = new Vector3[c2]; for (int i = 0; i < c2; i++) { _vertices[i] = new Int3(ctx.reader.ReadInt32(), ctx.reader.ReadInt32(), ctx.reader.ReadInt32()); originalVertices[i] = new Vector3(ctx.reader.ReadSingle(), ctx.reader.ReadSingle(), ctx.reader.ReadSingle()); } for (int i = 0; i < c1; i++) { nodes[i] = new TriangleMeshNode(active); TriangleMeshNode node = nodes[i]; node.DeserializeNode(ctx); node.UpdatePositionFromVertices(); } }
public override void DeserializeExtraInfo(GraphSerializationContext ctx) { uint graphIndex = (uint)base.active.astarData.GetGraphIndex(this); TriangleMeshNode.SetNavmeshHolder(0, (int)graphIndex, this); int num2 = ctx.reader.ReadInt32(); int num3 = ctx.reader.ReadInt32(); if (num2 == -1) { this.nodes = new TriangleMeshNode[0]; this._vertices = new VInt3[0]; this.originalVertices = new Vector3[0]; } this.nodes = new TriangleMeshNode[num2]; this._vertices = new VInt3[num3]; this.originalVertices = new Vector3[num3]; for (int i = 0; i < num3; i++) { this._vertices[i] = new VInt3(ctx.reader.ReadInt32(), ctx.reader.ReadInt32(), ctx.reader.ReadInt32()); this.originalVertices[i] = new Vector3(ctx.reader.ReadSingle(), ctx.reader.ReadSingle(), ctx.reader.ReadSingle()); } this.bbTree = new BBTree(this); for (int j = 0; j < num2; j++) { this.nodes[j] = new TriangleMeshNode(base.active); TriangleMeshNode node = this.nodes[j]; node.DeserializeNode(ctx); node.GraphIndex = graphIndex; node.UpdatePositionFromVertices(); this.bbTree.Insert(node); } }
private NavmeshTile CreateTile(Voxelize vox, VoxelMesh mesh, int x, int z, int threadIndex) { if (mesh.tris == null) { throw new ArgumentNullException("mesh.tris"); } if (mesh.verts == null) { throw new ArgumentNullException("mesh.verts"); } if (mesh.tris.Length % 3 != 0) { throw new ArgumentException("Indices array's length must be a multiple of 3 (mesh.tris)"); } if (mesh.verts.Length >= 4095) { if (this.tileXCount * this.tileZCount == 1) { throw new ArgumentException("Too many vertices per tile (more than " + 4095 + ").\n<b>Try enabling tiling in the recast graph settings.</b>\n"); } throw new ArgumentException("Too many vertices per tile (more than " + 4095 + ").\n<b>Try reducing tile size or enabling ASTAR_RECAST_LARGER_TILES under the 'Optimizations' tab in the A* Inspector</b>"); } else { NavmeshTile navmeshTile = new NavmeshTile { x = x, z = z, w = 1, d = 1, tris = mesh.tris, bbTree = new BBTree() }; navmeshTile.vertsInGraphSpace = Utility.RemoveDuplicateVertices(mesh.verts, navmeshTile.tris); navmeshTile.verts = (Int3[])navmeshTile.vertsInGraphSpace.Clone(); this.transform.Transform(navmeshTile.verts); uint num = (uint)(this.active.data.graphs.Length + threadIndex); if (num > 255u) { throw new Exception("Graph limit reached. Multithreaded recast calculations cannot be done because a few scratch graph indices are required."); } int num2 = x + z * this.tileXCount; num2 <<= 12; TriangleMeshNode.SetNavmeshHolder((int)num, navmeshTile); object active = this.active; lock (active) { navmeshTile.nodes = base.CreateNodes(navmeshTile.tris, num2, num); } navmeshTile.bbTree.RebuildFrom(navmeshTile.nodes); NavmeshBase.CreateNodeConnections(navmeshTile.nodes); TriangleMeshNode.SetNavmeshHolder((int)num, null); return(navmeshTile); } }
public override void ScanInternal(OnScanStatus statusCallback) { if (this.sourceMesh == null) { return; } this.GenerateMatrix(); Vector3[] vertices = this.sourceMesh.vertices; this.triangles = this.sourceMesh.triangles; TriangleMeshNode.SetNavmeshHolder(this.active.astarData.GetGraphIndex(this), this); this.GenerateNodes(vertices, this.triangles, out this.originalVertices, out this._vertices); }
protected override IEnumerable <Progress> ScanInternal() { cachedSourceMeshBoundsMin = sourceMesh != null ? sourceMesh.bounds.min : Vector3.zero; transform = CalculateTransform(); tileZCount = tileXCount = 1; tiles = new NavmeshTile[tileZCount * tileXCount]; TriangleMeshNode.SetNavmeshHolder(AstarPath.active.data.GetGraphIndex(this), this); if (sourceMesh == null) { FillWithEmptyTiles(); yield break; } yield return(new Progress(0.0f, "Transforming Vertices")); forcedBoundsSize = sourceMesh.bounds.size * scale; Vector3[] vectorVertices = sourceMesh.vertices; var intVertices = ListPool <Int3> .Claim(vectorVertices.Length); var matrix = Matrix4x4.TRS(-sourceMesh.bounds.min * scale, Quaternion.identity, Vector3.one * scale); // Convert the vertices to integer coordinates and also position them in graph space // so that the minimum of the bounding box of the mesh is at the origin // (the vertices will later be transformed to world space) for (int i = 0; i < vectorVertices.Length; i++) { intVertices.Add((Int3)matrix.MultiplyPoint3x4(vectorVertices[i])); } yield return(new Progress(0.1f, "Compressing Vertices")); // Remove duplicate vertices Int3[] compressedVertices = null; int[] compressedTriangles = null; Polygon.CompressMesh(intVertices, new List <int>(sourceMesh.triangles), out compressedVertices, out compressedTriangles); ListPool <Int3> .Release(ref intVertices); yield return(new Progress(0.2f, "Building Nodes")); ReplaceTile(0, 0, compressedVertices, compressedTriangles); // Signal that tiles have been recalculated to the navmesh cutting system. navmeshUpdateData.OnRecalculatedTiles(tiles); if (OnRecalculatedTiles != null) { OnRecalculatedTiles(tiles.Clone() as NavmeshTile[]); } }
public override IEnumerable <Progress> ScanInternal() { TriangleMeshNode.SetNavmeshHolder(AstarPath.active.data.GetGraphIndex(this), this); if (!Application.isPlaying) { RelevantGraphSurface.FindAllGraphSurfaces(); } RelevantGraphSurface.UpdateAllPositions(); foreach (Progress progress in this.ScanAllTiles()) { yield return(progress); } yield break; }
public override IEnumerable <Progress> ScanInternal() { transform = CalculateTransform(); tileZCount = tileXCount = 1; tiles = new NavmeshTile[tileZCount * tileXCount]; TriangleMeshNode.SetNavmeshHolder(AstarPath.active.data.GetGraphIndex(this), this); if (sourceMesh == null) { FillWithEmptyTiles(); yield break; } yield return(new Progress(0.0f, "Transforming Vertices")); forcedBoundsSize = sourceMesh.bounds.size * scale; Vector3[] vectorVertices = sourceMesh.vertices; var intVertices = ListPool <Int3> .Claim(vectorVertices.Length); var matrix = Matrix4x4.TRS(-sourceMesh.bounds.min * scale, Quaternion.identity, Vector3.one * scale); // Convert the vertices to integer coordinates and also position them in graph space // so that the minimum of the bounding box of the mesh is at the origin // (the vertices will later be transformed to world space) for (int i = 0; i < vectorVertices.Length; i++) { intVertices.Add((Int3)matrix.MultiplyPoint3x4(vectorVertices[i])); } yield return(new Progress(0.1f, "Compressing Vertices")); // Remove duplicate vertices Int3[] compressedVertices = null; int[] compressedTriangles = null; Polygon.CompressMesh(intVertices, new List <int>(sourceMesh.triangles), out compressedVertices, out compressedTriangles); ListPool <Int3> .Release(intVertices); yield return(new Progress(0.2f, "Building Nodes")); ReplaceTile(0, 0, compressedVertices, compressedTriangles); // This may be used by the TileHandlerHelper script to update the tiles // while taking NavmeshCuts into account after the graph has been completely recalculated. if (OnRecalculatedTiles != null) { OnRecalculatedTiles(tiles.Clone() as NavmeshTile[]); } }
public void ScanInternal(OnScanStatus statusCallback) { if (sourceMesh == null) { return; } GenerateMatrix(); Vector3[] vectorVertices = sourceMesh.vertices; triangles = sourceMesh.triangles; TriangleMeshNode.SetNavmeshHolder(active.astarData.GetGraphIndex(this), this); GenerateNodes(vectorVertices, triangles, out originalVertices, out _vertices); }
public override void ScanInternal(OnScanStatus statusCallback) { if (sourceMesh == null) { return; } GenerateMatrix(); //float startTime = 0;//Time.realtimeSinceStartup; var vectorVertices = sourceMesh.vertices; triangles = sourceMesh.triangles; TriangleMeshNode.SetNavmeshHolder(active.astarData.GetGraphIndex(this), this); GenerateNodes(vectorVertices, triangles, out originalVertices, out _vertices); }
public override IEnumerable <Progress> ScanInternal() { this.transform = this.CalculateTransform(); this.tileZCount = (this.tileXCount = 1); this.tiles = new NavmeshTile[this.tileZCount * this.tileXCount]; TriangleMeshNode.SetNavmeshHolder(AstarPath.active.data.GetGraphIndex(this), this); if (this.sourceMesh == null) { base.FillWithEmptyTiles(); yield break; } yield return(new Progress(0f, "Transforming Vertices")); this.forcedBoundsSize = this.sourceMesh.bounds.size * this.scale; Vector3[] vertices = this.sourceMesh.vertices; List <Int3> intVertices = ListPool <Int3> .Claim(vertices.Length); Matrix4x4 matrix4x = Matrix4x4.TRS(-this.sourceMesh.bounds.min * this.scale, Quaternion.identity, Vector3.one * this.scale); for (int i = 0; i < vertices.Length; i++) { intVertices.Add((Int3)matrix4x.MultiplyPoint3x4(vertices[i])); } yield return(new Progress(0.1f, "Compressing Vertices")); Int3[] compressedVertices = null; int[] compressedTriangles = null; Polygon.CompressMesh(intVertices, new List <int>(this.sourceMesh.triangles), out compressedVertices, out compressedTriangles); ListPool <Int3> .Release(intVertices); yield return(new Progress(0.2f, "Building Nodes")); base.ReplaceTile(0, 0, compressedVertices, compressedTriangles); if (this.OnRecalculatedTiles != null) { this.OnRecalculatedTiles(this.tiles.Clone() as NavmeshTile[]); } yield break; yield break; }
protected override IEnumerable <Progress> ScanInternal() { TriangleMeshNode.SetNavmeshHolder(AstarPath.active.data.GetGraphIndex(this), this); if (!Application.isPlaying) { RelevantGraphSurface.FindAllGraphSurfaces(); } RelevantGraphSurface.UpdateAllPositions(); foreach (var progress in ScanAllTiles()) { yield return(progress); } #if DEBUG_REPLAY DebugReplay.WriteToFile(); #endif }
public override void DeserializeExtraInfo(GraphSerializationContext ctx) { uint graphIndex = ctx.graphIndex; TriangleMeshNode.SetNavmeshHolder((int)graphIndex, this); int nodeCount = ctx.reader.ReadInt32(); int vertexCount = ctx.reader.ReadInt32(); if (nodeCount == -1) { nodes = new TriangleMeshNode[0]; _vertices = new Int3[0]; originalVertices = new Vector3[0]; return; } nodes = new TriangleMeshNode[nodeCount]; _vertices = new Int3[vertexCount]; originalVertices = new Vector3[vertexCount]; for (int i = 0; i < vertexCount; i++) { _vertices[i] = ctx.DeserializeInt3(); originalVertices[i] = ctx.DeserializeVector3(); } bbTree = new BBTree(); for (int i = 0; i < nodeCount; i++) { nodes[i] = new TriangleMeshNode(active); TriangleMeshNode node = nodes[i]; node.DeserializeNode(ctx); node.UpdatePositionFromVertices(); } bbTree.RebuildFrom(nodes); }
/** Create a tile at tile index \a x, \a z from the mesh. * \version Since version 3.7.6 the implementation is thread safe */ NavmeshTile CreateTile(Voxelize vox, VoxelMesh mesh, int x, int z, int threadIndex) { if (mesh.tris == null) { throw new System.ArgumentNullException("mesh.tris"); } if (mesh.verts == null) { throw new System.ArgumentNullException("mesh.verts"); } if (mesh.tris.Length % 3 != 0) { throw new System.ArgumentException("Indices array's length must be a multiple of 3 (mesh.tris)"); } if (mesh.verts.Length >= VertexIndexMask) { if (tileXCount * tileZCount == 1) { throw new System.ArgumentException("Too many vertices per tile (more than " + VertexIndexMask + ")." + "\n<b>Try enabling tiling in the recast graph settings.</b>\n"); } else { throw new System.ArgumentException("Too many vertices per tile (more than " + VertexIndexMask + ")." + "\n<b>Try reducing tile size or enabling ASTAR_RECAST_LARGER_TILES under the 'Optimizations' tab in the A* Inspector</b>"); } } // Create a new navmesh tile and assign its settings var tile = new NavmeshTile { x = x, z = z, w = 1, d = 1, tris = mesh.tris, bbTree = new BBTree(), graph = this, }; tile.vertsInGraphSpace = Utility.RemoveDuplicateVertices(mesh.verts, tile.tris); tile.verts = (Int3[])tile.vertsInGraphSpace.Clone(); transform.Transform(tile.verts); // Here we are faking a new graph // The tile is not added to any graphs yet, but to get the position queries 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 // The thread index is added to make sure that if multiple threads are calculating tiles at the same time // they will not use the same temporary graph index uint temporaryGraphIndex = (uint)(active.data.graphs.Length + threadIndex); if (temporaryGraphIndex > GraphNode.MaxGraphIndex) { // Multithreaded tile calculations use fake graph indices, see above. throw new System.Exception("Graph limit reached. Multithreaded recast calculations cannot be done because a few scratch graph indices are required."); } TriangleMeshNode.SetNavmeshHolder((int)temporaryGraphIndex, tile); // We need to lock here because creating nodes is not thread safe // and we may be doing this from multiple threads at the same time tile.nodes = new TriangleMeshNode[tile.tris.Length / 3]; lock (active) { CreateNodes(tile.nodes, tile.tris, x + z * tileXCount, temporaryGraphIndex); } tile.bbTree.RebuildFrom(tile.nodes); CreateNodeConnections(tile.nodes); // Remove the fake graph TriangleMeshNode.SetNavmeshHolder((int)temporaryGraphIndex, null); return(tile); }
protected NavmeshTile CreateTile(int[] tris, Int3[] verts, int x, int z) { #if BNICKSON_UPDATED if (tris == null) { throw new System.ArgumentNullException("The mesh must be valid. tris is null."); } if (verts == null) { throw new System.ArgumentNullException("The mesh must be valid. verts is null."); } //Create a new navmesh tile and assign its settings var tile = new NavmeshTile(); tile.x = x; tile.z = z; tile.w = 1; tile.d = 1; tile.tris = tris; tile.verts = verts; tile.bbTree = new BBTree(); #endif 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(); var 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]]; } var compressed = new Int3[count]; for (int i = 0; i < count; i++) { compressed[i] = tile.verts[i]; } tile.verts = compressed; var 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++) { var 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 occur, 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 (!VectorMath.IsClockwiseXZ(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); }