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