[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [57930] trunk/blender/source/blender/bmesh /tools/bmesh_bevel.c: Fix Bevel bug #34321, making bevel keep UVs contiguous when possible.
Howard Trickey
howard.trickey at gmail.com
Tue Jul 2 15:18:56 CEST 2013
Revision: 57930
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=57930
Author: howardt
Date: 2013-07-02 13:18:56 +0000 (Tue, 02 Jul 2013)
Log Message:
-----------
Fix Bevel bug #34321, making bevel keep UVs contiguous when possible.
Modified Paths:
--------------
trunk/blender/source/blender/bmesh/tools/bmesh_bevel.c
Modified: trunk/blender/source/blender/bmesh/tools/bmesh_bevel.c
===================================================================
--- trunk/blender/source/blender/bmesh/tools/bmesh_bevel.c 2013-07-02 12:52:37 UTC (rev 57929)
+++ trunk/blender/source/blender/bmesh/tools/bmesh_bevel.c 2013-07-02 13:18:56 UTC (rev 57930)
@@ -69,10 +69,11 @@
BMFace *fnext; /* face between this edge and next, if any */
struct BoundVert *leftv; /* left boundary vert (looking along edge to end) */
struct BoundVert *rightv; /* right boundary vert, if beveled */
- short is_bev; /* is this edge beveled? */
- short is_rev; /* is e->v2 the vertex at this end? */
int seg; /* how many segments for the bevel */
float offset; /* offset for this edge */
+ bool is_bev; /* is this edge beveled? */
+ bool is_rev; /* is e->v2 the vertex at this end? */
+ bool is_seam; /* is e a seam for custom loopdata (e.g., UVs)? */
// int _pad;
} EdgeHalf;
@@ -84,6 +85,7 @@
EdgeHalf *elast;
EdgeHalf *ebev; /* beveled edge whose left side is attached here, if any */
int index; /* used for vmesh indexing */
+ bool any_seam; /* are any of the edges attached here seams? */
// int _pad;
} BoundVert;
@@ -110,6 +112,7 @@
int edgecount; /* total number of edges around the vertex */
int selcount; /* number of selected edges around the vertex */
float offset; /* offset for this vertex, if vertex_only bevel */
+ bool any_seam; /* any seams on attached edges? */
EdgeHalf *edges; /* array of size edgecount; CCW order from vertex normal side */
VMesh *vmesh; /* mesh structure for replacing vertex */
} BevVert;
@@ -227,43 +230,29 @@
* created around/near BoundVert v */
static BMFace *boundvert_rep_face(BoundVert *v)
{
- BMFace *fans = NULL;
- BMFace *firstf = NULL;
- BMEdge *e1, *e2;
- BMFace *f1, *f2;
- BMIter iter1, iter2;
-
BLI_assert(v->efirst != NULL && v->elast != NULL);
- e1 = v->efirst->e;
- e2 = v->elast->e;
- BM_ITER_ELEM (f1, &iter1, e1, BM_FACES_OF_EDGE) {
- if (!firstf)
- firstf = f1;
- BM_ITER_ELEM (f2, &iter2, e2, BM_FACES_OF_EDGE) {
- if (f1 == f2) {
- fans = f1;
- break;
- }
- }
- }
- if (!fans)
- fans = firstf;
-
- return fans;
+ if (v->efirst->fnext == v->elast->fprev)
+ return v->efirst->fnext;
+ else if (v->efirst->fnext)
+ return v->efirst->fnext;
+ else
+ return v->elast->fprev;
}
/**
* Make ngon from verts alone.
* Make sure to properly copy face attributes and do custom data interpolation from
- * example face, facerep.
+ * corresponding elements of face_arr, if that is non-NULL, else from facerep.
*
* \note ALL face creation goes through this function, this is important to keep!
*/
-static BMFace *bev_create_ngon(BMesh *bm, BMVert **vert_arr, const int totv, BMFace *facerep)
+static BMFace *bev_create_ngon(BMesh *bm, BMVert **vert_arr, const int totv,
+ BMFace **face_arr, BMFace *facerep, bool do_interp)
{
BMIter iter;
BMLoop *l;
- BMFace *f;
+ BMFace *f, *interp_f;
+ int i;
if (totv == 3) {
f = BM_face_create_quad_tri_v(bm, vert_arr, 3, facerep, FALSE);
@@ -272,25 +261,29 @@
f = BM_face_create_quad_tri_v(bm, vert_arr, 4, facerep, FALSE);
}
else {
- int i;
BMEdge **ee = BLI_array_alloca(ee, totv);
for (i = 0; i < totv; i++) {
ee[i] = BM_edge_create(bm, vert_arr[i], vert_arr[(i + 1) % totv], NULL, BM_CREATE_NO_DOUBLE);
}
-#if 0
- f = BM_face_create_ngon(bm, vert_arr[0], vert_arr[1], ee, totv, 0);
-#else
f = BM_face_create(bm, vert_arr, ee, totv, 0);
-#endif
}
- if (facerep && f) {
- int has_mdisps = CustomData_has_layer(&bm->ldata, CD_MDISPS);
+ if ((facerep || face_arr) && f) {
BM_elem_attrs_copy(bm, bm, facerep, f);
- BM_ITER_ELEM (l, &iter, f, BM_LOOPS_OF_FACE) {
- BM_loop_interp_from_face(bm, l, facerep, TRUE, TRUE);
- if (has_mdisps)
- BM_loop_interp_multires(bm, l, facerep);
+ if (do_interp) {
+ i = 0;
+ BM_ITER_ELEM (l, &iter, f, BM_LOOPS_OF_FACE) {
+ if (face_arr) {
+ /* assume loops of created face are in same order as verts */
+ BLI_assert(l->v == vert_arr[i]);
+ interp_f = face_arr[i];
+ }
+ else {
+ interp_f = facerep;
+ }
+ BM_loop_interp_from_face(bm, l, interp_f, TRUE, TRUE);
+ i++;
+ }
}
}
@@ -304,12 +297,142 @@
}
static BMFace *bev_create_quad_tri(BMesh *bm, BMVert *v1, BMVert *v2, BMVert *v3, BMVert *v4,
- BMFace *facerep)
+ BMFace *facerep, bool do_interp)
{
BMVert *varr[4] = {v1, v2, v3, v4};
- return bev_create_ngon(bm, varr, v4 ? 4 : 3, facerep);
+ return bev_create_ngon(bm, varr, v4 ? 4 : 3, NULL, facerep, do_interp);
}
+static BMFace *bev_create_quad_tri_ex(BMesh *bm, BMVert *v1, BMVert *v2, BMVert *v3, BMVert *v4,
+ BMFace *f1, BMFace *f2, BMFace *f3, BMFace *f4)
+{
+ BMVert *varr[4] = {v1, v2, v3, v4};
+ BMFace *farr[4] = {f1, f2, f3, f4};
+ return bev_create_ngon(bm, varr, v4 ? 4 : 3, farr, f1, true);
+}
+
+
+/* Is Loop layer layer_index contiguous across shared vertex of l1 and l2? */
+static bool contig_ldata_across_loops(BMesh *bm, BMLoop *l1, BMLoop *l2,
+ int layer_index)
+{
+ const int offset = bm->ldata.layers[layer_index].offset;
+ const int type = bm->ldata.layers[layer_index].type;
+
+ return CustomData_data_equals(type,
+ (char *)l1->head.data + offset,
+ (char *)l2->head.data + offset);
+}
+
+/* Are all loop layers with have math (e.g., UVs) contiguous from face f1 to face f2 across edge e? */
+static bool contig_ldata_across_edge(BMesh *bm, BMEdge *e, BMFace* f1, BMFace *f2)
+{
+ BMLoop *lef1, *lef2;
+ BMLoop *lv1f1, *lv1f2, *lv2f1, *lv2f2;
+ BMVert *v1, *v2;
+ int i;
+
+ if (bm->ldata.totlayer == 0)
+ return true;
+
+ v1 = e->v1;
+ v2 = e->v2;
+ if (!BM_edge_loop_pair(e, &lef1, &lef2))
+ return false;
+ if (lef1->f == f2) {
+ SWAP(BMLoop *, lef1, lef2);
+ }
+ if (lef1->v == v1) {
+ lv1f1 = lef1;
+ lv2f1 = BM_face_other_edge_loop(f1, e, v2);
+ } else {
+ lv2f1 = lef1;
+ lv1f1 = BM_face_other_edge_loop(f1, e, v1);
+ }
+ if (lef2->v == v1) {
+ lv1f2 = lef2;
+ lv2f2 = BM_face_other_edge_loop(f2, e, v2);
+ } else {
+ lv2f2 = lef2;
+ lv1f2 = BM_face_other_edge_loop(f2, e, v1);
+ }
+
+ for (i = 0; i < bm->ldata.totlayer; i++) {
+ if (CustomData_layer_has_math(&bm->ldata, i) &&
+ (!contig_ldata_across_loops(bm, lv1f1, lv1f2, i) ||
+ !contig_ldata_across_loops(bm, lv2f1, lv2f2, i))) {
+ return false;
+ }
+ }
+ return true;
+}
+
+/* Like bev_create_quad_tri, but when verts straddle an old edge.
+ * e
+ * |
+ * v1+---|---+v4
+ * | | |
+ * | | |
+ * v2+---|---+v3
+ * |
+ * f1 | f2
+ *
+ * Most CustomData for loops can be interpolated in their respective
+ * faces' loops, but for UVs and other 'has_math_cd' layers, only
+ * do this if the UVs are continuous across the edge e, otherwise pick
+ * one side (f1, arbitrarily), and interpolate them all on that side.
+ * For face data, use f1 (arbitrarily) as face representative. */
+static BMFace *bev_create_quad_straddle(BMesh *bm, BMVert *v1, BMVert *v2, BMVert *v3, BMVert *v4,
+ BMFace *f1, BMFace *f2, bool is_seam)
+{
+ BMFace *f, *facerep;
+ BMLoop *l;
+ BMIter iter;
+
+ f = bev_create_quad_tri(bm, v1, v2, v3, v4, f1, false);
+
+ if (!f)
+ return NULL;
+
+ BM_ITER_ELEM (l, &iter, f, BM_LOOPS_OF_FACE) {
+ if (is_seam || l->v == v1 || l->v == v2)
+ facerep = f1;
+ else
+ facerep = f2;
+ BM_loop_interp_from_face(bm, l, facerep, TRUE, TRUE);
+ }
+ return f;
+}
+
+/* Merge (using average) all the UV values for loops of v's faces.
+ * Caller should ensure that no seams are violated by doing this. */
+static void bev_merge_uvs(BMesh *bm, BMVert *v) {
+ BMIter iter;
+ MLoopUV *luv;
+ BMLoop *l;
+ float uv[2];
+ int n;
+ int cd_loop_uv_offset = CustomData_get_offset(&bm->ldata, CD_MLOOPUV);
+
+ if (cd_loop_uv_offset == -1)
+ return;
+
+ n = 0;
+ zero_v2(uv);
+ BM_ITER_ELEM(l, &iter, v, BM_LOOPS_OF_VERT) {
+ luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset);
+ add_v2_v2(uv, luv->uv);
+ n++;
+ }
+ if (n > 1) {
+ mul_v2_fl(uv, 1.0f/(float)n);
+ BM_ITER_ELEM(l, &iter, v, BM_LOOPS_OF_VERT) {
+ luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset);
+ copy_v2_v2(luv->uv, uv);
+ }
+ }
+}
+
/* Calculate coordinates of a point a distance d from v on e->e and return it in slideco */
static void slide_dist(EdgeHalf *e, BMVert *v, float d, float slideco[3])
{
@@ -641,6 +764,25 @@
}
}
+/* Set the any_seam property for a BevVert and all its BoundVerts */
+static void set_bound_vert_seams(BevVert *bv)
+{
+ BoundVert *v;
+ EdgeHalf *e;
+
+ bv->any_seam = false;
+ v = bv->vmesh->boundstart;
+ do {
+ v->any_seam = false;
+ for (e = v->efirst; e; e = e->next) {
+ v->any_seam |= e->is_seam;
+ if (e == v->elast)
+ break;
+ }
+ bv->any_seam |= v->any_seam;
+ } while ((v = v->next) != bv->vmesh->boundstart);
+}
+
/* Make a circular list of BoundVerts for bv, each of which has the coordinates
* of a vertex on the the boundary of the beveled vertex bv->v.
* Also decide on the mesh pattern that will be used inside the boundary.
@@ -683,6 +825,7 @@
e->next->leftv = e->next->rightv = v;
/* could use M_POLY too, but tri-fan looks nicer)*/
vm->mesh_kind = M_TRI_FAN;
+ set_bound_vert_seams(bv);
return;
}
@@ -754,6 +897,8 @@
}
} while ((e = e->next) != efirst);
+ set_bound_vert_seams(bv);
+
BLI_assert(vm->count >= 2);
if (bp->vertex_only) {
vm->mesh_kind = bp->seg > 1 ? M_ADJ_SUBDIV : M_POLY;
@@ -783,19 +928,20 @@
* then make the BMVerts and the new faces. */
static void bevel_build_rings(BMesh *bm, BevVert *bv)
{
- int k, ring, i, n, ns, ns2, nn;
+ int k, ring, i, n, ns, ns2, nn, odd;
VMesh *vm = bv->vmesh;
BoundVert *v, *vprev, *vnext;
NewVert *nv, *nvprev, *nvnext;
EdgeHalf *e1, *e2, *epipe;
BMVert *bmv, *bmv1, *bmv2, *bmv3, *bmv4;
- BMFace *f;
+ BMFace *f, *f2, *f23;
float co[3], coa[3], cob[3], midco[3];
float va_pipe[3], vb_pipe[3];
n = vm->count;
ns = vm->seg;
ns2 = ns / 2;
+ odd = (ns % 2) != 0;
BLI_assert(n > 2 && ns > 1);
/* special case: two beveled edges are in line and share a face, making a "pipe" */
@@ -884,7 +1030,7 @@
if (vprev->ebev) {
for (ring = 1; ring <= ns2; ring++) {
for (k = 1; k <= ns2; k++) {
- if (ns % 2 == 0 && (k == ns2 || ring == ns2))
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list