| 661 | } |
| 662 | |
| 663 | static bool removeVertex(rcContext* ctx, rcPolyMesh& mesh, const unsigned short rem, const int maxTris) |
| 664 | { |
| 665 | const int nvp = mesh.nvp; |
| 666 | |
| 667 | // Count number of polygons to remove. |
| 668 | int numRemovedVerts = 0; |
| 669 | for (int i = 0; i < mesh.npolys; ++i) |
| 670 | { |
| 671 | unsigned short* p = &mesh.polys[i*nvp*2]; |
| 672 | const int nv = countPolyVerts(p, nvp); |
| 673 | for (int j = 0; j < nv; ++j) |
| 674 | { |
| 675 | if (p[j] == rem) |
| 676 | numRemovedVerts++; |
| 677 | } |
| 678 | } |
| 679 | |
| 680 | int nedges = 0; |
| 681 | rcScopedDelete<int> edges((int*)rcAlloc(sizeof(int)*numRemovedVerts*nvp*4, RC_ALLOC_TEMP)); |
| 682 | if (!edges) |
| 683 | { |
| 684 | ctx->log(RC_LOG_WARNING, "removeVertex: Out of memory 'edges' (%d).", numRemovedVerts*nvp*4); |
| 685 | return false; |
| 686 | } |
| 687 | |
| 688 | int nhole = 0; |
| 689 | rcScopedDelete<int> hole((int*)rcAlloc(sizeof(int)*numRemovedVerts*nvp, RC_ALLOC_TEMP)); |
| 690 | if (!hole) |
| 691 | { |
| 692 | ctx->log(RC_LOG_WARNING, "removeVertex: Out of memory 'hole' (%d).", numRemovedVerts*nvp); |
| 693 | return false; |
| 694 | } |
| 695 | |
| 696 | int nhreg = 0; |
| 697 | rcScopedDelete<int> hreg((int*)rcAlloc(sizeof(int)*numRemovedVerts*nvp, RC_ALLOC_TEMP)); |
| 698 | if (!hreg) |
| 699 | { |
| 700 | ctx->log(RC_LOG_WARNING, "removeVertex: Out of memory 'hreg' (%d).", numRemovedVerts*nvp); |
| 701 | return false; |
| 702 | } |
| 703 | |
| 704 | int nharea = 0; |
| 705 | rcScopedDelete<int> harea((int*)rcAlloc(sizeof(int)*numRemovedVerts*nvp, RC_ALLOC_TEMP)); |
| 706 | if (!harea) |
| 707 | { |
| 708 | ctx->log(RC_LOG_WARNING, "removeVertex: Out of memory 'harea' (%d).", numRemovedVerts*nvp); |
| 709 | return false; |
| 710 | } |
| 711 | |
| 712 | for (int i = 0; i < mesh.npolys; ++i) |
| 713 | { |
| 714 | unsigned short* p = &mesh.polys[i*nvp*2]; |
| 715 | const int nv = countPolyVerts(p, nvp); |
| 716 | bool hasRem = false; |
| 717 | for (int j = 0; j < nv; ++j) |
| 718 | if (p[j] == rem) hasRem = true; |
| 719 | if (hasRem) |
| 720 | { |
no test coverage detected