[Bf-blender-cvs] [e5394e962a0] sculpt-dev: Sculpt-dev: dyntopo now detects uv island boundaries, independently of edge seams.
Joseph Eagar
noreply at git.blender.org
Thu Nov 18 01:43:40 CET 2021
Commit: e5394e962a0c55dbe4ab522dd29b286cb90f6df5
Author: Joseph Eagar
Date: Wed Nov 17 16:42:56 2021 -0800
Branches: sculpt-dev
https://developer.blender.org/rBe5394e962a0c55dbe4ab522dd29b286cb90f6df5
Sculpt-dev: dyntopo now detects uv island
boundaries, independently of
edge seams.
===================================================================
M source/blender/blenkernel/BKE_paint.h
M source/blender/blenkernel/BKE_pbvh.h
M source/blender/blenkernel/intern/dyntopo.c
M source/blender/blenkernel/intern/paint.c
M source/blender/blenkernel/intern/pbvh_bmesh.c
M source/blender/blenkernel/intern/pbvh_intern.h
M source/blender/editors/sculpt_paint/sculpt.c
M source/blender/editors/sculpt_paint/sculpt_intern.h
M source/blender/editors/sculpt_paint/sculpt_smooth.c
M source/blender/makesdna/DNA_meshdata_types.h
===================================================================
diff --git a/source/blender/blenkernel/BKE_paint.h b/source/blender/blenkernel/BKE_paint.h
index 6c06ebfb8fd..23437876e64 100644
--- a/source/blender/blenkernel/BKE_paint.h
+++ b/source/blender/blenkernel/BKE_paint.h
@@ -719,6 +719,8 @@ typedef struct SculptSession {
int cd_faceset_offset;
int cd_face_areas;
+ int totuv;
+
bool bm_smooth_shading;
/* Undo/redo log for dynamic topology sculpting */
struct BMLog *bm_log;
diff --git a/source/blender/blenkernel/BKE_pbvh.h b/source/blender/blenkernel/BKE_pbvh.h
index 3ae8743de95..6b221da3ad4 100644
--- a/source/blender/blenkernel/BKE_pbvh.h
+++ b/source/blender/blenkernel/BKE_pbvh.h
@@ -121,6 +121,7 @@ struct BMesh;
struct BMVert;
struct BMEdge;
struct BMFace;
+struct Scene;
struct CCGElem;
struct MeshElemMap;
struct CCGKey;
@@ -429,10 +430,13 @@ void BKE_pbvh_draw_cb(PBVH *pbvh,
void (*draw_fn)(void *user_data, struct GPU_PBVH_Buffers *buffers),
void *user_data);
-void BKE_pbvh_draw_debug_cb(
- PBVH *pbvh,
- void (*draw_fn)(void *user_data, const float bmin[3], const float bmax[3], PBVHNodeFlags flag, int depth),
- void *user_data);
+void BKE_pbvh_draw_debug_cb(PBVH *pbvh,
+ void (*draw_fn)(void *user_data,
+ const float bmin[3],
+ const float bmax[3],
+ PBVHNodeFlags flag,
+ int depth),
+ void *user_data);
/* PBVH Access */
typedef enum {
@@ -854,7 +858,9 @@ void BKE_pbvh_update_vert_boundary(int cd_sculpt_vert,
int cd_face_node_offset,
int cd_vcol,
struct BMVert *v,
- int symmetry);
+ int bound_symmetry,
+ const CustomData *ldata,
+ const int totuv);
#define DYNTOPO_DYNAMIC_TESS
diff --git a/source/blender/blenkernel/intern/dyntopo.c b/source/blender/blenkernel/intern/dyntopo.c
index e6a25abe410..bc813d617e7 100644
--- a/source/blender/blenkernel/intern/dyntopo.c
+++ b/source/blender/blenkernel/intern/dyntopo.c
@@ -41,14 +41,16 @@
#define SCULPTVERT_SMOOTH_BOUNDARY \
(SCULPTVERT_BOUNDARY | SCULPTVERT_FSET_BOUNDARY | SCULPTVERT_SHARP_BOUNDARY | \
- SCULPTVERT_SEAM_BOUNDARY)
+ SCULPTVERT_SEAM_BOUNDARY | SCULPTVERT_UV_BOUNDARY)
#define SCULPTVERT_ALL_BOUNDARY \
(SCULPTVERT_BOUNDARY | SCULPTVERT_FSET_BOUNDARY | SCULPTVERT_SHARP_BOUNDARY | \
- SCULPTVERT_SEAM_BOUNDARY)
+ SCULPTVERT_SEAM_BOUNDARY | SCULPTVERT_UV_BOUNDARY)
#define SCULPTVERT_SMOOTH_CORNER \
- (SCULPTVERT_CORNER | SCULPTVERT_FSET_CORNER | SCULPTVERT_SHARP_CORNER | SCULPTVERT_SEAM_CORNER)
+ (SCULPTVERT_CORNER | SCULPTVERT_FSET_CORNER | SCULPTVERT_SHARP_CORNER | \
+ SCULPTVERT_SEAM_CORNER | SCULPTVERT_UV_CORNER)
#define SCULPTVERT_ALL_CORNER \
- (SCULPTVERT_CORNER | SCULPTVERT_FSET_CORNER | SCULPTVERT_SHARP_CORNER | SCULPTVERT_SEAM_CORNER)
+ (SCULPTVERT_CORNER | SCULPTVERT_FSET_CORNER | SCULPTVERT_SHARP_CORNER | \
+ SCULPTVERT_SEAM_CORNER | SCULPTVERT_UV_CORNER)
#define DYNTOPO_MAX_ITER 4096
@@ -3637,7 +3639,7 @@ static BMVert *pbvh_bmesh_collapse_edge(PBVH *pbvh,
} while ((e2 = BM_DISK_EDGE_NEXT(e2, v)) != v->e);
}
- float (*uv)[2] = BLI_array_alloca(uv, 4*totuv);
+ float(*uv)[2] = BLI_array_alloca(uv, 4 * totuv);
do {
const void *ls2[2] = {l->head.data, l->next->head.data};
diff --git a/source/blender/blenkernel/intern/paint.c b/source/blender/blenkernel/intern/paint.c
index 44cad73fdd5..ce8dc3fa566 100644
--- a/source/blender/blenkernel/intern/paint.c
+++ b/source/blender/blenkernel/intern/paint.c
@@ -3317,4 +3317,11 @@ void BKE_sculptsession_update_attr_refs(Object *ob)
ss->vcol = layer->data;
}
}
+
+ if (ss->bm) {
+ ss->totuv = CustomData_number_of_layers(&ss->bm->ldata, CD_MLOOPUV);
+ }
+ else {
+ ss->totuv = ss->ldata ? CustomData_number_of_layers(ss->ldata, CD_MLOOPUV) : 0;
+ }
}
diff --git a/source/blender/blenkernel/intern/pbvh_bmesh.c b/source/blender/blenkernel/intern/pbvh_bmesh.c
index 37d0a7b42ac..9eefc043fdd 100644
--- a/source/blender/blenkernel/intern/pbvh_bmesh.c
+++ b/source/blender/blenkernel/intern/pbvh_bmesh.c
@@ -1717,7 +1717,9 @@ void bke_pbvh_update_vert_boundary(int cd_sculpt_vert,
int cd_face_node_offset,
int cd_vcol,
BMVert *v,
- int bound_symmetry)
+ int bound_symmetry,
+ const CustomData *ldata,
+ const int totuv)
{
MSculptVert *mv = BKE_PBVH_SCULPTVERT(cd_sculpt_vert, v);
@@ -1727,7 +1729,8 @@ void bke_pbvh_update_vert_boundary(int cd_sculpt_vert,
mv->flag &= ~(SCULPTVERT_BOUNDARY | SCULPTVERT_FSET_BOUNDARY | SCULPTVERT_NEED_BOUNDARY |
SCULPTVERT_NEED_TRIANGULATE | SCULPTVERT_FSET_CORNER | SCULPTVERT_CORNER |
SCULPTVERT_NEED_VALENCE | SCULPTVERT_SEAM_BOUNDARY | SCULPTVERT_SHARP_BOUNDARY |
- SCULPTVERT_SEAM_CORNER | SCULPTVERT_SHARP_CORNER | SCULPTVERT_PBVH_BOUNDARY);
+ SCULPTVERT_SEAM_CORNER | SCULPTVERT_SHARP_CORNER | SCULPTVERT_PBVH_BOUNDARY |
+ SCULPTVERT_UV_BOUNDARY | SCULPTVERT_UV_CORNER);
if (!e) {
mv->flag |= SCULPTVERT_BOUNDARY;
@@ -1757,6 +1760,20 @@ void bke_pbvh_update_vert_boundary(int cd_sculpt_vert,
int *fsets = NULL;
BLI_array_staticdeclare(fsets, 16);
+ float(*lastuv)[2] = BLI_array_alloca(lastuv, totuv);
+ float(*lastuv2)[2] = BLI_array_alloca(lastuv2, totuv);
+
+ int *disjount_uv_count = BLI_array_alloca(disjount_uv_count, totuv);
+ int *cd_uvs = BLI_array_alloca(cd_uvs, totuv);
+ int base_uv_idx = ldata->typemap[CD_MLOOPUV];
+ bool uv_first = true;
+
+ for (int i = 0; i < totuv; i++) {
+ CustomDataLayer *layer = ldata->layers + base_uv_idx + i;
+ cd_uvs[i] = layer->offset;
+ disjount_uv_count[i] = 0;
+ }
+
do {
BMVert *v2 = v == e->v1 ? e->v2 : e->v1;
@@ -1812,6 +1829,49 @@ void bke_pbvh_update_vert_boundary(int cd_sculpt_vert,
}
if (e->l) {
+ /* deal with uv island boundaries */
+ if (totuv) {
+ BMLoop *l_iter = e->l;
+ do {
+ BMLoop *l = l_iter->v != v ? l_iter->next : l_iter;
+
+ for (int i = 0; i < totuv; i++) {
+ MLoopUV *luv = BM_ELEM_CD_GET_VOID_P(l, cd_uvs[i]);
+
+ if (uv_first) {
+ copy_v2_v2(lastuv[i], luv->uv);
+ copy_v2_v2(lastuv2[i], luv->uv);
+
+ continue;
+ }
+
+ const float uv_snap_limit = 0.01f * 0.01f;
+
+ float dist = len_squared_v2v2(luv->uv, lastuv[i]);
+ bool same = dist <= uv_snap_limit;
+
+ bool corner = len_squared_v2v2(lastuv[i], lastuv2[i]) > uv_snap_limit &&
+ len_squared_v2v2(lastuv[i], luv->uv) > uv_snap_limit &&
+ len_squared_v2v2(lastuv2[i], luv->uv) > uv_snap_limit;
+
+ if (!same) {
+ mv->flag |= SCULPTVERT_UV_BOUNDARY;
+ }
+
+ if (corner) {
+ mv->flag |= SCULPTVERT_UV_CORNER;
+ }
+
+ if (!same) {
+ copy_v2_v2(lastuv2[i], lastuv[i]);
+ copy_v2_v2(lastuv[i], luv->uv);
+ }
+ }
+
+ uv_first = false;
+ } while ((l_iter = l_iter->next) != e->l);
+ }
+
if (BM_ELEM_CD_GET_INT(e->l->f, cd_face_node_offset) != ni) {
mv->flag |= SCULPTVERT_PBVH_BOUNDARY;
}
@@ -1942,7 +2002,9 @@ void BKE_pbvh_update_vert_boundary(int cd_sculpt_vert,
int cd_face_node_offset,
int cd_vcol,
BMVert *v,
- int bound_symmetry)
+ int bound_symmetry,
+ const CustomData *ldata,
+ const int totuv)
{
bke_pbvh_update_vert_boundary(cd_sculpt_vert,
cd_faceset_offset,
@@ -1950,7 +2012,9 @@ void BKE_pbvh_update_vert_boundary(int cd_sculpt_vert,
cd_face_node_offset,
cd_vcol,
v,
- bound_symmetry);
+ bound_symmetry,
+ ldata,
+ totuv);
}
/*Used by symmetrize to update boundary flags*/
@@ -1966,7 +2030,9 @@ void BKE_pbvh_recalc_bmesh_boundary(PBVH *pbvh)
pbvh->cd_face_node_offset,
pbvh->cd_vcol_offset,
v,
- pbvh->boundary_symmetry);
+ pbvh->boundary_symmetry,
+ &pbvh->bm->ldata,
+ pbvh->totuv);
}
}
@@ -2198,6 +2264,8 @@ void BKE_pbvh_update_sculpt_verts(BMesh *bm,
BMVert *v;
BMIter iter;
+ int totuv = CustomData_number_of_layers(&bm->ldata, CD_MLOOPUV);
+
BM_ITER_MESH (v, &iter, bm, BM_VERTS_OF_MESH) {
MSculptVert *mv = BKE_PBVH_SCULPTVERT(cd_sculpt_vert, v);
@@ -2209,7 +2277,9 @@ void BKE_pbvh_update_sculpt_verts(BMesh *bm,
cd_face_node_offset,
-1,
v,
- boundary_symmetry);
+ boundary_symmetry,
+ &bm->ldata,
+ totuv);
BKE_pbvh_bmesh_update_valence(cd_sculpt_vert, (SculptVertRef){(intptr_t)v});
@@ -3938,6 +4008,8 @@ void BKE_pbvh_update_offsets(PBVH *pbvh,
pbvh->cd_vert_mask_offset = CustomData_get_offset(&pbvh->bm->v
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list