Commit: ec4786d00b357458dd11d5d3ee28e00da4cbf859 Author: Joseph Eagar Date: Wed May 12 16:22:39 2021 -0700 Branches: temp_bmesh_multires https://developer.blender.org/rBec4786d00b357458dd11d5d3ee28e00da4cbf859
Dyntopo branch * Sculpt expand now works with dyntopo in more cases * Fixed various dyntopo face set bugs Stuff from several commits ago: * There is now an API to get face sets using SculptFaceRef's. + SCULPT_face_set_get + SCULPT_face_set_set * Prototyped a faster geodesic propagation function, but it currently doesn't work. * Dyntopo triangulation now preserves face flags (took some work as BM_triangulate_face explicitly prevents selection flags from being preserved). * Also face smooth flags are no longer being overriden. * Most of the faceset create operators work (I'm not sure I've tested all of them though). * SCULPT_face_set.c now has helper functions that checks if a pbvh is *not* PBVH_BMESH, in which case it builds a temporary bmesh, otherwise ss->bm is used (sculpt_faceset_bm_begin and sculpt_faceset_bm_end). + Note that some functions were able to use SCULPT_face_set_XXX instead and avoid bmesh entirely. =================================================================== M source/blender/bmesh/intern/bmesh_log.c M source/blender/editors/sculpt_paint/paint_mask.c M source/blender/editors/sculpt_paint/sculpt.c M source/blender/editors/sculpt_paint/sculpt_dyntopo.c M source/blender/editors/sculpt_paint/sculpt_expand.c M source/blender/editors/sculpt_paint/sculpt_face_set.c M source/blender/editors/sculpt_paint/sculpt_geodesic.c M source/blender/editors/sculpt_paint/sculpt_intern.h M source/blender/editors/sculpt_paint/sculpt_undo.c =================================================================== diff --git a/source/blender/bmesh/intern/bmesh_log.c b/source/blender/bmesh/intern/bmesh_log.c index a5ce2d67e0c..94f0187df4c 100644 --- a/source/blender/bmesh/intern/bmesh_log.c +++ b/source/blender/bmesh/intern/bmesh_log.c @@ -882,7 +882,7 @@ BMLog *BM_log_from_existing_entries_create(BMesh *bm, BMLogEntry *entry) return log; } -ATTR_NO_OPT BMLog *BM_log_unfreeze(BMesh *bm, BMLogEntry *entry) +BMLog *BM_log_unfreeze(BMesh *bm, BMLogEntry *entry) { if (!entry || !entry->log) { return NULL; diff --git a/source/blender/editors/sculpt_paint/paint_mask.c b/source/blender/editors/sculpt_paint/paint_mask.c index da3dbe03e3f..d1d0bf6a138 100644 --- a/source/blender/editors/sculpt_paint/paint_mask.c +++ b/source/blender/editors/sculpt_paint/paint_mask.c @@ -1366,7 +1366,7 @@ static void sculpt_gesture_trim_end(bContext *UNUSED(C), SculptGestureContext *s sculpt_gesture_trim_geometry_free(sgcontext); if (sgcontext->ss && sgcontext->ss->bm) { - SCULPT_dynamic_topology_triangulate(sgcontext->ss->bm); + SCULPT_dynamic_topology_triangulate(sgcontext->ss, sgcontext->ss->bm); } SCULPT_undo_push_node(sgcontext->vc.obact, NULL, SCULPT_UNDO_GEOMETRY); diff --git a/source/blender/editors/sculpt_paint/sculpt.c b/source/blender/editors/sculpt_paint/sculpt.c index 84f655be0c6..795b0b2e215 100644 --- a/source/blender/editors/sculpt_paint/sculpt.c +++ b/source/blender/editors/sculpt_paint/sculpt.c @@ -112,6 +112,9 @@ void SCULPT_vertex_random_access_ensure(SculptSession *ss) { if (ss->bm) { + ss->totfaces = ss->totpoly = ss->bm->totface; + ss->totvert = ss->bm->totvert; + BM_mesh_elem_index_ensure(ss->bm, BM_VERT); BM_mesh_elem_table_ensure(ss->bm, BM_VERT); } @@ -129,10 +132,14 @@ void SCULPT_vertex_random_access_ensure(SculptSession *ss) void SCULPT_face_random_access_ensure(SculptSession *ss) { if (ss->bm) { + ss->totfaces = ss->totpoly = ss->bm->totface; + ss->totvert = ss->bm->totvert; + BM_mesh_elem_index_ensure(ss->bm, BM_FACE); BM_mesh_elem_table_ensure(ss->bm, BM_FACE); } } + int SCULPT_vertex_count_get(SculptSession *ss) { switch (BKE_pbvh_type(ss->pbvh)) { @@ -986,7 +993,7 @@ bool SCULPT_vertex_has_unique_face_set(SculptSession *ss, SculptVertRef index) face_set = face_set2; } - return !first; + return true; } case PBVH_GRIDS: { const CCGKey *key = BKE_pbvh_get_grid_key(ss->pbvh); @@ -1468,15 +1475,15 @@ void SCULPT_floodfill_init(SculptSession *ss, SculptFloodFill *flood) flood->visited_vertices = BLI_BITMAP_NEW(vertex_count, "visited vertices"); } -void SCULPT_floodfill_add_initial(SculptFloodFill *flood, SculptVertRef index) +void SCULPT_floodfill_add_initial(SculptFloodFill *flood, SculptVertRef vertex) { - BLI_gsqueue_push(flood->queue, &index); + BLI_gsqueue_push(flood->queue, &vertex); } -void SCULPT_floodfill_add_and_skip_initial(SculptFloodFill *flood, int index) +void SCULPT_floodfill_add_and_skip_initial(SculptSession *ss, SculptFloodFill *flood, SculptVertRef vertex) { - BLI_gsqueue_push(flood->queue, &index); - BLI_BITMAP_ENABLE(flood->visited_vertices, index); + BLI_gsqueue_push(flood->queue, &vertex); + BLI_BITMAP_ENABLE(flood->visited_vertices, BKE_pbvh_vertex_index_to_table(ss->pbvh, vertex)); } void SCULPT_floodfill_add_initial_with_symmetry(Sculpt *sd, @@ -6467,6 +6474,9 @@ static void sculpt_topology_update(Sculpt *sd, /* Update average stroke position. */ copy_v3_v3(location, ss->cache->true_location); mul_m4_v3(ob->obmat, location); + + ss->totfaces = ss->totpoly = ss->bm->totface; + ss->totvert = ss->bm->totvert; } static void do_brush_action_task_cb(void *__restrict userdata, @@ -9093,7 +9103,7 @@ static int sculpt_symmetrize_exec(bContext *C, wmOperator *op) sd->symmetrize_direction, dist, true); - SCULPT_dynamic_topology_triangulate(ss->bm); + SCULPT_dynamic_topology_triangulate(ss, ss->bm); /* Bisect operator flags edges (keep tags clean for edge queue). */ BM_mesh_elem_hflag_disable_all(ss->bm, BM_EDGE, BM_ELEM_TAG, false); diff --git a/source/blender/editors/sculpt_paint/sculpt_dyntopo.c b/source/blender/editors/sculpt_paint/sculpt_dyntopo.c index 4b746757997..d531f0ffa0e 100644 --- a/source/blender/editors/sculpt_paint/sculpt_dyntopo.c +++ b/source/blender/editors/sculpt_paint/sculpt_dyntopo.c @@ -82,9 +82,12 @@ #include <math.h> #include <stdlib.h> -void SCULPT_dynamic_topology_triangulate(BMesh *bm) +void SCULPT_dynamic_topology_triangulate(SculptSession *ss, BMesh *bm) { if (bm->totloop == bm->totface * 3) { + ss->totfaces = ss->totpoly = ss->bm->totface; + ss->totvert = ss->bm->totvert; + return; } @@ -152,6 +155,9 @@ void SCULPT_dynamic_topology_triangulate(BMesh *bm) BLI_memarena_free(pf_arena); + ss->totfaces = ss->totpoly = ss->bm->totface; + ss->totvert = ss->bm->totvert; + // BM_mesh_triangulate( // bm, MOD_TRIANGULATE_QUAD_BEAUTY, MOD_TRIANGULATE_NGON_EARCLIP, 4, false, NULL, NULL, // NULL); @@ -445,7 +451,8 @@ void SCULPT_dynamic_topology_enable_ex(Main *bmain, Depsgraph *depsgraph, Scene .use_shapekey = true, .active_shapekey = ob->shapenr, })); - SCULPT_dynamic_topology_triangulate(ss->bm); + SCULPT_dynamic_topology_triangulate(ss, ss->bm); + BM_data_layer_add(ss->bm, &ss->bm->vdata, CD_PAINT_MASK); SCULPT_dyntopo_node_layers_add(ss); diff --git a/source/blender/editors/sculpt_paint/sculpt_expand.c b/source/blender/editors/sculpt_paint/sculpt_expand.c index a26f5622e71..1ccfb19400d 100644 --- a/source/blender/editors/sculpt_paint/sculpt_expand.c +++ b/source/blender/editors/sculpt_paint/sculpt_expand.c @@ -176,14 +176,16 @@ static bool sculpt_expand_is_face_in_active_component(SculptSession *ss, const SculptFaceRef f) { if (ss->bm) { - BMFace *bf = (BMFace*)f.i; + BMFace *bf = (BMFace *)f.i; BMLoop *l = bf->l_first; SculptVertRef v = {(intptr_t)l->v}; return sculpt_expand_is_vert_in_active_component(ss, expand_cache, v); - } else { + } + else { const MLoop *loop = &ss->mloop[ss->mpoly[f.i].loopstart]; - return sculpt_expand_is_vert_in_active_component(ss, expand_cache, BKE_pbvh_table_index_to_vertex(ss->pbvh, loop->v)); + return sculpt_expand_is_vert_in_active_component( + ss, expand_cache, BKE_pbvh_table_index_to_vertex(ss->pbvh, loop->v)); } } @@ -237,7 +239,9 @@ static float sculpt_expand_max_vertex_falloff_get(ExpandCache *expand_cache) * Main function to get the state of a vertex for the current state and settings of a #ExpandCache. * Returns true when the target data should be modified by expand. */ -static bool sculpt_expand_state_get(SculptSession *ss, ExpandCache *expand_cache, const SculptVertRef v) +static bool sculpt_expand_state_get(SculptSession *ss, + ExpandCache *expand_cache, + const SculptVertRef v) { if (!SCULPT_vertex_visible_get(ss, v)) { return false; @@ -283,11 +287,14 @@ static bool sculpt_expand_state_get(SculptSession *ss, ExpandCache *expand_cache * Main function to get the state of a face for the current state and settings of a #ExpandCache. * Returns true when the target data should be modified by expand. */ -static bool sculpt_expand_face_state_get(SculptSession *ss, ExpandCache *expand_cache, const SculptFaceRef f) +static bool sculpt_expand_face_state_get(SculptSession *ss, + ExpandCache *expand_cache, + const SculptFaceRef f) { const int f_i = BKE_pbvh_face_index_to_table(ss->pbvh, f); + const int fset = SCULPT_face_set_get(ss, f); - if (ss->face_sets[f_i] <= 0) { + if (fset <= 0) { return false; } @@ -315,7 +322,7 @@ static bool sculpt_expand_face_state_get(SculptSession *ss, ExpandCache *expand_ } if (expand_cache->falloff_type == SCULPT_EXPAND_FALLOFF_ACTIVE_FACE_SET) { - if (ss->face_sets[f_i] == expand_cache->initial_active_face_set) { + if (fset == expand_cache->initial_active_face_set) { enabled = false; } } @@ -377,7 +384,8 @@ static BLI_bitmap *sculpt_expand_bitmap_from_enabled(SculptSession *ss, ExpandCa const int totvert = SCULPT_vertex_count_get(ss); BLI_bitmap *enabled_vertices = BLI_BITMAP_NEW(totvert, "enabled vertices"); for (int i = 0; i < totvert; i++) { - const bool enabled = sculpt_expand_state_get(ss, expand_cache, BKE_pbvh_table_index_to_vertex(ss->pbvh, i)); + const bool enabled = sculpt_expand_state_get( + ss, expand_cache, BKE_pbvh_table_index_to_vertex(ss->pbvh, i)); BLI_BITMAP_SET(enabled_vertices, i, enabled); } return enabled_vertices; @@ -639,7 +647,8 @@ static float *sculpt_expand_boundary_topology_falloff_create(Object *ob, const S for (int i = 0; i < boundary->num_vertices; i++) { BLI_gsqueue_push(queue, &boundary->vertices[i]); - BLI_BITMAP_ENABLE(visited_vertices, BKE_pbvh_vertex_index_to_table(ss->pbvh, boundary->vertices[i])); + BLI_BITMAP_ENABLE(visited_vertices, + BKE_pbvh_vertex_index_to_table(ss->pbvh, boundary->vertices[i])); } SCULPT_boundary_data_free(boundary); } @@ -686,12 +695,17 @@ static float *sculpt_expand_diagonals_falloff_create(Object *ob, const SculptVer float *dists = MEM_calloc_arrayN(sizeof(float), totvert, "spherical dist"); /* This algorithm uses mesh data (polys and loops), so this falloff type can't be initialized for - * Multires. It also does not make sense to implement it for dyntopo as the result will be the - * same as Topology falloff. */ - if (BKE_pbvh_type(ss->pbvh) != PBVH_FACES) { + * Multires. Also supports non-tri PBVH_BMESH, though untested until we implement that properly*/ + if (BKE_pbvh_type(ss->pbvh) != PBVH_FACES || + (ss->bm && ss->bm->totloop != ss->bm->totvert * 3)) { return dists; } + if (ss->bm) { + BM_mesh_elem_index_ensure(ss->bm, BM_VERT); + BM_mesh_elem_ta @@ Diff output truncated at 10240 characters. @@ _______________________________________________ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org https://lists.blender.org/mailman/listinfo/bf-blender-cvs