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

bmo_edgesplit.c « operators « bmesh « blender « source - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 20dd6321a4fa0ea793c46b3a8d4bdd92c9a7fc8f (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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/*
 * ***** BEGIN GPL LICENSE BLOCK *****
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 * Contributor(s): Campbell Barton
 *
 * ***** END GPL LICENSE BLOCK *****
 */

#include "MEM_guardedalloc.h"

#include "bmesh.h"

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

enum {
	EDGE_SEAM  = 1
};

/**
 * Remove the EDGE_SEAM flag for edges we cant split
 *
 * un-tag edges not connected to other tagged edges,
 * unless they are on a boundary
 */
static void bm_edgesplit_validate_seams(BMesh *bm, BMOperator *op)
{
	BMOIter siter;
	BMIter iter;
	BMEdge *e;

	unsigned char *vtouch;
	unsigned char *vt;

	BM_mesh_elem_index_ensure(bm, BM_VERT);

	vtouch = MEM_callocN(sizeof(char) * bm->totvert, __func__);

	/* tag all boundary verts so as not to untag an edge which is inbetween only 2 faces [] */
	BM_ITER(e, &iter, bm, BM_EDGES_OF_MESH, NULL) {

		/* unrelated to flag assignment in this function - since this is the
		 * only place we loop over all edges, disable tag */
		BM_elem_flag_disable(e, BM_ELEM_INTERNAL_TAG);

		if (BM_edge_is_boundary(e)) {
			vt = &vtouch[BM_elem_index_get(e->v1)]; if (*vt < 2) (*vt)++;
			vt = &vtouch[BM_elem_index_get(e->v2)]; if (*vt < 2) (*vt)++;

			/* while the boundary verts need to be tagged,
			 * the edge its self can't be split */
			BMO_elem_flag_disable(bm, e, EDGE_SEAM);
		}
	}

	/* single marked edges unconnected to any other marked edges
	 * are illegal, go through and unmark them */
	BMO_ITER(e, &siter, bm, op, "edges", BM_EDGE) {
		/* lame, but we don't want the count to exceed 255,
		 * so just count to 2, its all we need */
		unsigned char *vt;
		vt = &vtouch[BM_elem_index_get(e->v1)]; if (*vt < 2) (*vt)++;
		vt = &vtouch[BM_elem_index_get(e->v2)]; if (*vt < 2) (*vt)++;
	}
	BMO_ITER(e, &siter, bm, op, "edges", BM_EDGE) {
		if (vtouch[BM_elem_index_get(e->v1)] == 1 &&
		    vtouch[BM_elem_index_get(e->v2)] == 1)
		{
			BMO_elem_flag_disable(bm, e, EDGE_SEAM);
		}
	}

	MEM_freeN(vtouch);
}

void bmo_edgesplit_exec(BMesh *bm, BMOperator *op)
{
	BMOIter siter;
	BMEdge *e;

	BMO_slot_buffer_flag_enable(bm, op, "edges", EDGE_SEAM, BM_EDGE);

	bm_edgesplit_validate_seams(bm, op);

	BMO_ITER(e, &siter, bm, op, "edges", BM_EDGE) {
		if (BMO_elem_flag_test(bm, e, EDGE_SEAM)) {
			/* this flag gets copied so we can be sure duplicate edges get it too (important) */
			BM_elem_flag_enable(e, BM_ELEM_INTERNAL_TAG);

			bmesh_edge_separate(bm, e, e->l);
			BM_elem_flag_enable(e->v1, BM_ELEM_TAG);
			BM_elem_flag_enable(e->v2, BM_ELEM_TAG);
		}
	}

	BMO_ITER(e, &siter, bm, op, "edges", BM_EDGE) {
		if (BMO_elem_flag_test(bm, e, EDGE_SEAM)) {
			if (BM_elem_flag_test(e->v1, BM_ELEM_TAG)) {
				BM_elem_flag_disable(e->v1, BM_ELEM_TAG);
				bmesh_vert_separate(bm, e->v1, NULL, NULL);
			}
			if (BM_elem_flag_test(e->v2, BM_ELEM_TAG)) {
				BM_elem_flag_disable(e->v2, BM_ELEM_TAG);
				bmesh_vert_separate(bm, e->v2, NULL, NULL);
			}
		}
	}

	BMO_slot_buffer_from_hflag(bm, op, "edgeout", BM_ELEM_INTERNAL_TAG, BM_EDGE);
}