bmo_unsubdivide.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*
  2. * ***** BEGIN GPL LICENSE BLOCK *****
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License
  6. * as published by the Free Software Foundation; either version 2
  7. * of the License, or (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software Foundation,
  16. * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  17. *
  18. * Contributor(s): Campbell Barton
  19. *
  20. * ***** END GPL LICENSE BLOCK *****
  21. */
  22. /** \file blender/bmesh/operators/bmo_unsubdivide.c
  23. * \ingroup bmesh
  24. *
  25. * Pattern based geometry reduction which has the result similar to undoing
  26. * a subdivide operation.
  27. */
  28. #include "BLI_math.h"
  29. #include "BLI_utildefines.h"
  30. #include "bmesh.h"
  31. #include "bmesh_tools.h"
  32. #include "intern/bmesh_operators_private.h" /* own include */
  33. /* - BMVert.flag & BM_ELEM_TAG: shows we touched this vert
  34. * - BMVert.index == -1: shows we will remove this vert
  35. */
  36. void bmo_unsubdivide_exec(BMesh *bm, BMOperator *op)
  37. {
  38. BMVert *v;
  39. BMIter iter;
  40. const int iterations = max_ii(1, BMO_slot_int_get(op->slots_in, "iterations"));
  41. BMOpSlot *vinput = BMO_slot_get(op->slots_in, "verts");
  42. BMVert **vinput_arr = (BMVert **)vinput->data.buf;
  43. int v_index;
  44. /* tag verts */
  45. BM_ITER_MESH (v, &iter, bm, BM_VERTS_OF_MESH) {
  46. BM_elem_flag_disable(v, BM_ELEM_TAG);
  47. }
  48. for (v_index = 0; v_index < vinput->len; v_index++) {
  49. v = vinput_arr[v_index];
  50. BM_elem_flag_enable(v, BM_ELEM_TAG);
  51. }
  52. /* do all the real work here */
  53. BM_mesh_decimate_unsubdivide_ex(bm, iterations, true);
  54. }