Welcome to mirror list, hosted at ThFree Co, Russian Federation.

bmo_fill_holes.c « operators « bmesh « blender « source - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: b717db8c76ff7fe83dc54fa473d7d922d6e7a092 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/* SPDX-License-Identifier: GPL-2.0-or-later */

/** \file
 * \ingroup bmesh
 *
 * Fill boundary edge loop(s) with faces.
 */

#include "BLI_utildefines.h"

#include "bmesh.h"
#include "bmesh_tools.h"

#include "intern/bmesh_operators_private.h" /* own include */

void bmo_holes_fill_exec(BMesh *bm, BMOperator *op)
{
  BMOperator op_attr;
  const uint sides = BMO_slot_int_get(op->slots_in, "sides");

  BM_mesh_elem_hflag_disable_all(bm, BM_EDGE | BM_FACE, BM_ELEM_TAG, false);
  BMO_slot_buffer_hflag_enable(bm, op->slots_in, "edges", BM_EDGE, BM_ELEM_TAG, false);

  BM_mesh_edgenet(bm, true, true);  // TODO: sides

  /* bad - remove faces after as a workaround */
  if (sides != 0) {
    BMOIter siter;
    BMFace *f;

    BMO_slot_buffer_from_enabled_hflag(bm, op, op->slots_out, "faces.out", BM_FACE, BM_ELEM_TAG);
    BMO_ITER (f, &siter, op->slots_out, "faces.out", BM_FACE) {
      if (f->len > sides) {
        BM_face_kill(bm, f);
      }
    }
  }

  BMO_slot_buffer_from_enabled_hflag(bm, op, op->slots_out, "faces.out", BM_FACE, BM_ELEM_TAG);

  /* --- Attribute Fill --- */
  /* may as well since we have the faces already in a buffer */
  BMO_op_initf(bm,
               &op_attr,
               op->flag,
               "face_attribute_fill faces=%S use_normals=%b use_data=%b",
               op,
               "faces.out",
               true,
               true);

  BMO_op_exec(bm, &op_attr);

  /* check if some faces couldn't be touched */
  if (BMO_slot_buffer_len(op_attr.slots_out, "faces_fail.out")) {
    BMOIter siter;
    BMFace *f;

    BMO_ITER (f, &siter, op_attr.slots_out, "faces_fail.out", BM_FACE) {
      BM_face_normal_update(f); /* normals are zero'd */
    }

    BMO_op_callf(bm, op->flag, "recalc_face_normals faces=%S", &op_attr, "faces_fail.out");
  }
  BMO_op_finish(bm, &op_attr);
}