bmo_fill_holes.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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_fill_holes.c
  23. * \ingroup bmesh
  24. *
  25. * Fill boundary edge loop(s) with faces.
  26. */
  27. #include "BLI_utildefines.h"
  28. #include "bmesh.h"
  29. #include "bmesh_tools.h"
  30. #include "intern/bmesh_operators_private.h" /* own include */
  31. void bmo_holes_fill_exec(BMesh *bm, BMOperator *op)
  32. {
  33. BMOperator op_attr;
  34. const uint sides = BMO_slot_int_get(op->slots_in, "sides");
  35. BM_mesh_elem_hflag_disable_all(bm, BM_EDGE | BM_FACE, BM_ELEM_TAG, false);
  36. BMO_slot_buffer_hflag_enable(bm, op->slots_in, "edges", BM_EDGE, BM_ELEM_TAG, false);
  37. BM_mesh_edgenet(bm, true, true); // TODO, sides
  38. /* bad - remove faces after as a workaround */
  39. if (sides != 0) {
  40. BMOIter siter;
  41. BMFace *f;
  42. BMO_slot_buffer_from_enabled_hflag(bm, op, op->slots_out, "faces.out", BM_FACE, BM_ELEM_TAG);
  43. BMO_ITER (f, &siter, op->slots_out, "faces.out", BM_FACE) {
  44. if (f->len > sides) {
  45. BM_face_kill(bm, f);
  46. }
  47. }
  48. }
  49. BMO_slot_buffer_from_enabled_hflag(bm, op, op->slots_out, "faces.out", BM_FACE, BM_ELEM_TAG);
  50. /* --- Attribute Fill --- */
  51. /* may as well since we have the faces already in a buffer */
  52. BMO_op_initf(bm, &op_attr, op->flag,
  53. "face_attribute_fill faces=%S use_normals=%b use_data=%b",
  54. op, "faces.out", true, true);
  55. BMO_op_exec(bm, &op_attr);
  56. /* check if some faces couldn't be touched */
  57. if (BMO_slot_buffer_count(op_attr.slots_out, "faces_fail.out")) {
  58. BMOIter siter;
  59. BMFace *f;
  60. BMO_ITER (f, &siter, op_attr.slots_out, "faces_fail.out", BM_FACE) {
  61. BM_face_normal_update(f); /* normals are zero'd */
  62. }
  63. BMO_op_callf(bm, op->flag, "recalc_face_normals faces=%S", &op_attr, "faces_fail.out");
  64. }
  65. BMO_op_finish(bm, &op_attr);
  66. }