public Mesh ToMesh() { AiNativeList <float3> vertices = new AiNativeList <float3>(2); AiNativeList <int> indices = new AiNativeList <int>(2); GetTileGeometry(vertices, indices); Vector3[] unityVerts = new Vector3[vertices.Length]; for (int i = 0; i < vertices.Length; i++) { unityVerts[i] = new Vector3(vertices[i].x, vertices[i].y, vertices[i].z); } Mesh mesh = new Mesh(); mesh.indexFormat = UnityEngine.Rendering.IndexFormat.UInt32; mesh.vertices = unityVerts; mesh.uv = new Vector2[unityVerts.Length]; mesh.triangles = indices.ToArray(); mesh.RecalculateBounds(); mesh.RecalculateNormals(); vertices.Dispose(); indices.Dispose(); return(mesh); }
public void GetTileGeometry(AiNativeList <float3> vertices, AiNativeList <int> indices) { AiNativeList <float3> tileVerts = new AiNativeList <float3>(2); AiNativeList <int> tileIndices = new AiNativeList <int>(2); foreach (byte[] data in Tiles) { NavMeshTile tile = new NavMeshTile(); tile.Data = data; tile.GetTileVertices(tileVerts, tileIndices); // Copy vertices int vbase = vertices.Length; for (int i = 0; i < tileVerts.Length; i++) { vertices.Add(tileVerts[i]); } // Copy indices with offset applied for (int i = 0; i < tileIndices.Length; i++) { indices.Add(tileIndices[i] + vbase); } tileVerts.Clear(); tileIndices.Clear(); } tileVerts.Dispose(); tileIndices.Dispose(); }
public NavMeshInputBuilder(NavMeshTileBounds tileBounds) { Coord = tileBounds.Coord; BoundingBox = tileBounds.Bounds; Vertices = new AiNativeList <float3>(2); Indices = new AiNativeList <int>(2); Areas = new AiNativeList <byte>(2); }
public unsafe bool GetTileVertices(AiNativeList <float3> vertices, AiNativeList <int> indices) { if (Data == null || Data.Length == 0) return(false); fixed(byte *dataPtr = Data) { DtTileHeader *header = (DtTileHeader *)dataPtr; if (header->VertCount == 0) { return(false); } int headerSize = Navigation.DtAlign4(sizeof(DtTileHeader)); int vertsSize = Navigation.DtAlign4(sizeof(float) * 3 * header->VertCount); byte *ptr = dataPtr; ptr += headerSize; float3 *vertexPtr = (float3 *)ptr; ptr += vertsSize; DtPoly *polyPtr = (DtPoly *)ptr; for (int i = 0; i < header->VertCount; i++) { vertices.Add(vertexPtr[i]); } for (int i = 0; i < header->PolyCount; i++) { // Expand polygons into triangles var poly = polyPtr[i]; for (int j = 0; j <= poly.VertexCount - 3; j++) { indices.Add(poly.Vertices[0]); indices.Add(poly.Vertices[j + 1]); indices.Add(poly.Vertices[j + 2]); } } return(true); } }
public void Append(AiNativeList <float3> vertices, AiNativeList <int> indices, byte area = DtArea.WALKABLE) { // Copy vertices int vbase = Vertices.Length; for (int i = 0; i < vertices.Length; i++) { Vertices.Add(vertices[i]); BoundingBox = DtBoundingBox.Merge(BoundingBox, vertices[i]); } // Copy indices with offset applied for (int i = 0; i < indices.Length; i++) { Indices.Add(indices[i] + vbase); } int triangleCount = indices.Length / 3; for (int i = 0; i < triangleCount; i++) { Areas.Add(area); } }