| 520 | #include "Engine/Core/Math/Matrix.h" |
| 521 | |
| 522 | void DrawPoly(NavMeshRuntime* navMesh, const Matrix& navMeshToWorld, const dtMeshTile& tile, const dtPoly& poly) |
| 523 | { |
| 524 | const unsigned int ip = (unsigned int)(&poly - tile.polys); |
| 525 | const dtPolyDetail& pd = tile.detailMeshes[ip]; |
| 526 | const Color& areaColor = NavMeshRuntime::NavAreasColors[poly.getArea()]; |
| 527 | const Color color = Color::Lerp(navMesh->Properties.Color, areaColor, areaColor.A); |
| 528 | const float drawOffsetY = 10.0f + ((float)GetHash(color) / (float)MAX_uint32) * 10.0f; // Apply some offset to prevent Z-fighting for different navmeshes |
| 529 | const Color fillColor = color * 0.5f; |
| 530 | const Color edgesColor = Color::FromHSV(color.ToHSV() + Float3(20.0f, 0, -0.1f), color.A); |
| 531 | |
| 532 | for (int i = 0; i < pd.triCount; i++) |
| 533 | { |
| 534 | Float3 v[3]; |
| 535 | const unsigned char* t = &tile.detailTris[(pd.triBase + i) * 4]; |
| 536 | |
| 537 | for (int k = 0; k < 3; k++) |
| 538 | { |
| 539 | if (t[k] < poly.vertCount) |
| 540 | { |
| 541 | v[k] = *(Float3*)&tile.verts[poly.verts[t[k]] * 3]; |
| 542 | } |
| 543 | else |
| 544 | { |
| 545 | v[k] = *(Float3*)&tile.detailVerts[(pd.vertBase + t[k] - poly.vertCount) * 3]; |
| 546 | } |
| 547 | } |
| 548 | |
| 549 | v[0].Y += drawOffsetY; |
| 550 | v[1].Y += drawOffsetY; |
| 551 | v[2].Y += drawOffsetY; |
| 552 | |
| 553 | Float3::Transform(v[0], navMeshToWorld, v[0]); |
| 554 | Float3::Transform(v[1], navMeshToWorld, v[1]); |
| 555 | Float3::Transform(v[2], navMeshToWorld, v[2]); |
| 556 | |
| 557 | DEBUG_DRAW_TRIANGLE(v[0], v[1], v[2], fillColor, 0, true); |
| 558 | } |
| 559 | |
| 560 | for (int k = 0; k < pd.triCount; k++) |
| 561 | { |
| 562 | const unsigned char* t = &tile.detailTris[(pd.triBase + k) * 4]; |
| 563 | Float3 v[3]; |
| 564 | |
| 565 | for (int m = 0; m < 3; m++) |
| 566 | { |
| 567 | if (t[m] < poly.vertCount) |
| 568 | v[m] = *(Float3*)&tile.verts[poly.verts[t[m]] * 3]; |
| 569 | else |
| 570 | v[m] = *(Float3*)&tile.detailVerts[(pd.vertBase + (t[m] - poly.vertCount)) * 3]; |
| 571 | } |
| 572 | |
| 573 | v[0].Y += drawOffsetY; |
| 574 | v[1].Y += drawOffsetY; |
| 575 | v[2].Y += drawOffsetY; |
| 576 | |
| 577 | Float3::Transform(v[0], navMeshToWorld, v[0]); |
| 578 | Float3::Transform(v[1], navMeshToWorld, v[1]); |
| 579 | Float3::Transform(v[2], navMeshToWorld, v[2]); |