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 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(NavMeshInputBuilder other) { // Copy vertices int vbase = Vertices.Length; for (int i = 0; i < other.Vertices.Length; i++) { float3 point = other.Vertices[i]; Vertices.Add(point); BoundingBox = DtBoundingBox.Merge(BoundingBox, point); } // Copy indices with offset applied for (int i = 0; i < other.Indices.Length; i++) { Indices.Add(other.Indices[i] + vbase); } }
public unsafe void Append(float3 *vertices, int verticesLength, int *indices, int indicesLength, byte area = DtArea.WALKABLE) { // Copy vertices int vbase = Vertices.Length; for (int i = 0; i < verticesLength; i++) { Vertices.Add(vertices[i]); BoundingBox = DtBoundingBox.Merge(BoundingBox, vertices[i]); } // Copy indices with offset applied for (int i = 0; i < indicesLength; i++) { Indices.Add(indices[i] + vbase); } int triangleCount = indicesLength / 3; for (int i = 0; i < triangleCount; i++) { Areas.Add(area); } }