[Bf-blender-cvs] [b8fb46ab20c] sculpt-dev: Sculpt: BMLog stuff
Joseph Eagar
noreply at git.blender.org
Wed Oct 13 11:50:51 CEST 2021
Commit: b8fb46ab20ca705427f78acf9844a952012fe5a2
Author: Joseph Eagar
Date: Wed Oct 13 02:12:30 2021 -0700
Branches: sculpt-dev
https://developer.blender.org/rBb8fb46ab20ca705427f78acf9844a952012fe5a2
Sculpt: BMLog stuff
* BMLog now has a more fine-grained logging
facility to track the call chains
that produce specific log elements.
* Wrote a new function in bmesh_core.c to
dump local geometry around an element to
stdout in .obj format.
* Edge collapse now properly handles the
fact that bmesh handles sharp flags
inversely, i.e. edges *not* marked
with BM_ELEM_SMOOTH are sharp.
* Wrote a new BMLog API that handles elements
undergoing topological changes a bit better.
- BM_log_[edge/face]_[pre/post]
- Idea is to call the _pre before calling
collapse or split edge, then _post afterwards.
- No longer need to assign new IDs
in certain cases to avoid confusing BMLog.
- Other parts of BMLog may now be redundant;
need to check.
* Deleted some #if 0'd code
* Fixed a bug in BLI_smallhash_ensure_p, it didn't properly
set up state for when smallhash is used as a very simple
set.
===================================================================
M source/blender/blenkernel/intern/dyntopo.c
M source/blender/blenlib/intern/smallhash.c
M source/blender/bmesh/intern/bmesh_core.c
M source/blender/bmesh/intern/bmesh_log.c
M source/blender/bmesh/intern/bmesh_log.h
===================================================================
diff --git a/source/blender/blenkernel/intern/dyntopo.c b/source/blender/blenkernel/intern/dyntopo.c
index 19caee327e1..1f9bcd87216 100644
--- a/source/blender/blenkernel/intern/dyntopo.c
+++ b/source/blender/blenkernel/intern/dyntopo.c
@@ -39,7 +39,6 @@
#define SCULPTVERT_VALENCE_TEMP SCULPTVERT_SPLIT_TEMP
-#define USE_NEW_SPLIT
#define SCULPTVERT_SMOOTH_BOUNDARY \
(SCULPTVERT_BOUNDARY | SCULPTVERT_FSET_BOUNDARY | SCULPTVERT_SHARP_BOUNDARY | \
SCULPTVERT_SEAM_BOUNDARY)
@@ -289,7 +288,7 @@ static void fix_mesh(PBVH *pbvh, BMesh *bm)
printf("done fixing mesh.\n");
}
-#define CHECKMESH
+//#define CHECKMESH
//#define TEST_INVALID_NORMALS
#ifndef CHECKMESH
@@ -677,6 +676,7 @@ BLI_INLINE void surface_smooth_v_safe(PBVH *pbvh, BMVert *v, float fac)
static void pbvh_kill_vert(PBVH *pbvh, BMVert *v)
{
BMEdge *e = v->e;
+ bm_logstack_push();
if (e) {
do {
@@ -685,11 +685,13 @@ static void pbvh_kill_vert(PBVH *pbvh, BMVert *v)
}
BM_vert_kill(pbvh->bm, v);
+ bm_logstack_pop();
}
static void pbvh_log_vert_edges_kill(PBVH *pbvh, BMVert *v)
{
BMEdge *e = v->e;
+ bm_logstack_push();
if (e) {
do {
@@ -697,6 +699,8 @@ static void pbvh_log_vert_edges_kill(PBVH *pbvh, BMVert *v)
e = BM_DISK_EDGE_NEXT(e, v);
} while (e != v->e);
}
+
+ bm_logstack_pop();
}
static void bm_edges_from_tri(PBVH *pbvh, BMVert *v_tri[3], BMEdge *e_tri[3])
@@ -1267,7 +1271,9 @@ void BKE_pbvh_bmesh_remove_face(PBVH *pbvh, BMFace *f, bool log_face)
void BKE_pbvh_bmesh_remove_edge(PBVH *pbvh, BMEdge *e, bool log_edge)
{
if (log_edge) {
+ bm_logstack_push();
BM_log_edge_removed(pbvh->bm_log, e);
+ bm_logstack_pop();
}
}
@@ -2452,7 +2458,7 @@ static bool check_face_is_tri(PBVH *pbvh, BMFace *f)
static bool destroy_nonmanifold_fins(PBVH *pbvh, BMEdge *e_root)
{
- // return false;
+ bm_logstack_push();
static int max_faces = 64;
BMFace **stack = NULL;
@@ -2466,6 +2472,7 @@ static bool destroy_nonmanifold_fins(PBVH *pbvh, BMEdge *e_root)
int minfs = INT_MAX;
if (!l) {
+ bm_logstack_pop();
return false;
}
@@ -2540,6 +2547,7 @@ static bool destroy_nonmanifold_fins(PBVH *pbvh, BMEdge *e_root)
if (!fs) {
BLI_array_free(stack);
+ bm_logstack_pop();
return false;
}
@@ -2626,6 +2634,7 @@ static bool destroy_nonmanifold_fins(PBVH *pbvh, BMEdge *e_root)
BLI_array_free(fs);
BLI_array_free(stack);
+ bm_logstack_pop();
return true;
}
@@ -2636,6 +2645,8 @@ static bool check_for_fins(PBVH *pbvh, BMVert *v)
return false;
}
+ bm_logstack_push();
+
do {
if (!e) {
printf("%s: e was NULL\n", __func__);
@@ -2647,6 +2658,7 @@ static bool check_for_fins(PBVH *pbvh, BMVert *v)
do {
if (l != l->radial_next && l != l->radial_next->radial_next) {
if (destroy_nonmanifold_fins(pbvh, e)) {
+ bm_logstack_pop();
return true;
}
}
@@ -2654,6 +2666,7 @@ static bool check_for_fins(PBVH *pbvh, BMVert *v)
}
} while ((e = BM_DISK_EDGE_NEXT(e, v)) != v->e);
+ bm_logstack_pop();
return false;
}
@@ -3254,230 +3267,6 @@ static void short_edge_queue_create(EdgeQueueContext *eq_ctx,
/*************************** Topology update **************************/
-static void pbvh_bmesh_split_edge(EdgeQueueContext *eq_ctx,
- PBVH *pbvh,
- BMEdge *e,
- BLI_Buffer *edge_loops)
-{
- BMesh *bm = pbvh->bm;
-
- bm_log_message(" == split edge == ");
-
- // pbvh_bmesh_check_nodes(pbvh);
-
- // pbvh_bmesh_check_nodes(pbvh);
-
- float co_mid[3], no_mid[3];
- MSculptVert *mv1 = BKE_PBVH_SCULPTVERT(pbvh->cd_sculpt_vert, e->v1);
- MSculptVert *mv2 = BKE_PBVH_SCULPTVERT(pbvh->cd_sculpt_vert, e->v2);
-
- pbvh_check_vert_boundary(pbvh, e->v1);
- pbvh_check_vert_boundary(pbvh, e->v2);
-
- MV_ADD_FLAG(mv1, SCULPTVERT_NEED_VALENCE | SCULPTVERT_NEED_BOUNDARY | SCULPTVERT_NEED_DISK_SORT);
- MV_ADD_FLAG(mv2, SCULPTVERT_NEED_VALENCE | SCULPTVERT_NEED_BOUNDARY | SCULPTVERT_NEED_DISK_SORT);
-
- // bool boundary = (mv1->flag & SCULPTVERT_ALL_BOUNDARY) && (mv2->flag &
- // SCULPTVERT_ALL_BOUNDARY);
-
- /* Get all faces adjacent to the edge */
- pbvh_bmesh_edge_loops(edge_loops, e);
-
- /* Create a new vertex in current node at the edge's midpoint */
- mid_v3_v3v3(co_mid, e->v1->co, e->v2->co);
- mid_v3_v3v3(no_mid, e->v1->no, e->v2->no);
- normalize_v3(no_mid);
-
- int node_index = BM_ELEM_CD_GET_INT(e->v1, eq_ctx->cd_vert_node_offset);
- BMVert *v_new = pbvh_bmesh_vert_create(
- pbvh, node_index, co_mid, no_mid, NULL, eq_ctx->cd_vert_mask_offset);
- // transfer edge flags
-
- BMEdge *e1 = bmesh_edge_create_log(pbvh, e->v1, v_new, e);
- BMEdge *e2 = bmesh_edge_create_log(pbvh, v_new, e->v2, e);
-
- BM_log_edge_added(pbvh->bm_log, e1);
- BM_log_edge_added(pbvh->bm_log, e2);
-
- int eflag = e->head.hflag & ~BM_ELEM_HIDDEN;
- int vflag = (e->v1->head.hflag | e->v2->head.hflag) & ~BM_ELEM_HIDDEN;
-
- e1->head.hflag = e2->head.hflag = eflag;
- v_new->head.hflag = vflag;
-
- MSculptVert *mv_new = BKE_PBVH_SCULPTVERT(pbvh->cd_sculpt_vert, v_new);
-
- /*TODO: is it worth interpolating edge customdata?*/
-
- int ni_new = BM_ELEM_CD_GET_INT(v_new, pbvh->cd_vert_node_offset);
-
- void *vsrcs[2] = {e->v1->head.data, e->v2->head.data};
- float vws[2] = {0.5f, 0.5f};
- CustomData_bmesh_interp(
- &pbvh->bm->vdata, (const void **)vsrcs, (float *)vws, NULL, 2, v_new->head.data);
-
- // bke_pbvh_update_vert_boundary(pbvh->cd_sculpt_vert, pbvh->cd_faceset_offset, v_new);
- MV_ADD_FLAG(mv_new,
- SCULPTVERT_NEED_DISK_SORT | SCULPTVERT_NEED_VALENCE | SCULPTVERT_NEED_BOUNDARY);
- mv_new->flag &= ~SCULPTVERT_VALENCE_TEMP;
-
- int ni_new2 = BM_ELEM_CD_GET_INT(v_new, pbvh->cd_vert_node_offset);
- if (ni_new2 != ni_new) {
- // printf("error!\n");
- BM_ELEM_CD_SET_INT(v_new, pbvh->cd_vert_node_offset, ni_new);
- }
-
- /* For each face, add two new triangles and delete the original */
- for (int i = 0; i < (int)edge_loops->count; i++) {
- BMLoop *l_adj = BLI_buffer_at(edge_loops, BMLoop *, i);
- BMFace *f_adj = l_adj->f;
- BMFace *f_new;
- BMVert *v_opp, *v1, *v2;
- BMVert *v_tri[3];
- BMEdge *e_tri[3];
-
- BLI_assert(f_adj->len == 3);
- int ni = BM_ELEM_CD_GET_INT(f_adj, eq_ctx->cd_face_node_offset);
-
- /* Find the vertex not in the edge */
- v_opp = l_adj->prev->v;
-
- /* Get e->v1 and e->v2 in the order they appear in the
- * existing face so that the new faces' winding orders
- * match */
- v1 = l_adj->v;
- v2 = l_adj->next->v;
-
- MSculptVert *mv1b = BKE_PBVH_SCULPTVERT(pbvh->cd_sculpt_vert, v1);
- MSculptVert *mv2b = BKE_PBVH_SCULPTVERT(pbvh->cd_sculpt_vert, v2);
- MSculptVert *mv_opp = BKE_PBVH_SCULPTVERT(pbvh->cd_sculpt_vert, v_opp);
-
- MV_ADD_FLAG(mv1b,
- SCULPTVERT_NEED_VALENCE | SCULPTVERT_NEED_BOUNDARY | SCULPTVERT_NEED_DISK_SORT);
- MV_ADD_FLAG(mv2b,
- SCULPTVERT_NEED_VALENCE | SCULPTVERT_NEED_BOUNDARY | SCULPTVERT_NEED_DISK_SORT);
- MV_ADD_FLAG(mv_opp,
- SCULPTVERT_NEED_VALENCE | SCULPTVERT_NEED_BOUNDARY | SCULPTVERT_NEED_DISK_SORT);
-
- if (ni != node_index && i == 0) {
- pbvh_bmesh_vert_ownership_transfer(pbvh, &pbvh->nodes[ni], v_new);
- }
-
- /**
- * The 2 new faces created and assigned to `f_new` have their
- * verts & edges shuffled around.
- *
- * - faces wind anticlockwise in this example.
- * - original edge is `(v1, v2)`
- * - original face is `(v1, v2, v3)`
- *
- * <pre>
- * + v3(v_opp)
- * /|\
- * / | \
- * / | \
- * e4/ | \ e3
- * / |e5 \
- * / | \
- * / e1 | e2 \
- * +-------+-------+
- * v1 v4(v_new) v2
- * (first) (second)
- * </pre>
- *
- * - f_new (first): `v_tri=(v1, v4, v3), e_tri=(e1, e5, e4)`
- * - f_new (second): `v_tri=(v4, v2, v3), e_tri=(e2, e3, e5)`
- */
-
- /* Create two new faces */
-
- v_tri[0] = v1;
- v_tri[1] = v_new;
- v_tri[2] = v_opp;
- bm_edges_from_tri(pbvh, v_tri, e_tri);
- f_new = pbvh_bmesh_face_create(pbvh, ni, v_tri, e_tri, f_adj, false, true);
- long_edge_queue_face_add(eq_ctx, f_new, true);
-
- pbvh_bmesh_copy_facedata(pbvh, bm, f_new, f_adj);
-
- // customdata interpolation
- BMLoop *lfirst = f_adj->l_first;
- while (lfirst->v != v1) {
- lfirst = lfirst->next;
-
- // paranoia check
- if (lfirst == f_adj->l_first) {
- break;
- }
- }
-
- BMLoop *l1 = lfirst;
- BMLoop *l2 = lfirst->next;
- BMLoop *l3 = lfirst->next->next;
-
- void *lsrcs[2] = {l1->head.data, l2->head.data};
- float lws[2] = {0.5f, 0.5f};
-
- CustomData_bmesh_interp(
- &pbvh->bm->ldata, (const void **)lsrcs, lws, lws, 2, f_new->l_first->next->head.data);
-
- lsrcs[0] = l1->head.data;
- lws[0] = 1.0f;
-
- CustomData_bmesh_interp(
- &pbvh->bm->ldata, (const void **)lsrcs, lws, lws, 1, f_new->l_first->head.data);
-
- lsrcs[0] = l3->head.data;
- lws[0] = 1.0f;
-
- CustomData_bmesh_interp(
- &pbvh->bm->ldata, (const void **)lsrcs, lws, lws, 1, f_new->l_first->prev->head.data);
-
- v_tri[0] = v_new;
- v_tri[1] = v2;
- /* v_tri[2] = v_opp; */ /* unchanged */
- e_tri[0] = bmesh_edge_create_log(pbvh, v_tri[0], v_tri[1], NULL);
- e_tri[2] = e_tri[1]; /* switched */
- e_tri[1] = bmesh_edge_create_log(pbvh, v_tri[1], v_tri[2], NULL);
-
- f_new = pbvh_bmesh_face_create(pbvh, ni, v_tri, e_tri, f_adj, false, true);
-
- long_edge_queue_face_add(eq_ctx, f_new, true);
-
- pbvh_bmesh_copy_facedata(pbvh, bm, f_new, f_adj);
-
- // customdata interpolation
- lsrcs[0] = lfirst->head.data;
- lsrcs[1] = lfirst->next->head.data;
- lws[0] = lws[1] = 0.5f;
-
- CustomData_bmesh_interp(
- &pbvh->bm->ldata, (const void **)lsrcs, lws, lws, 2, f_new->l_first->head.data);
-
- lsrcs[0] = lfirst->next->head.data;
- ;
- lws[0] = 1.0f;
-
- CustomData_bmesh_interp(
- &pbvh->bm->ldata, (const
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list