From d7cfb6ac71e4225a654487ab134c89051dad03ed Mon Sep 17 00:00:00 2001 From: Joseph Eagar Date: Fri, 29 Jul 2022 19:01:32 -0700 Subject: Sculpt: Opaque vertex type for sculpt This is a port of sculpt-dev's `SculptVertRef` refactor (note that `SculptVertRef was renamed to PBVHVertRef`) to master. `PBVHVertRef` is a structure that abstracts the concept of a vertex in the sculpt code; it's simply an `intptr_t` wrapped in a struct. For `PBVH_FACES` and `PBVH_GRIDS` this struct stores a vertex index, but for `BMesh` it stores a direct pointer to a BMVert. The intptr_t is wrapped in a struct to prevent the accidental usage of it as an index. There are many reasons to do this: * Right now `BMesh` verts are not logical sculpt verts; to use the sculpt API they must first be converted to indices. This requires a lot of indirect lookups into tables, leading to performance loss. It has also led to greater code complexity and duplication. * Having an abstract vertex type makes it feasible to have one unified temporary attribute API for all three PBVH modes, which in turn made it rather trivial to port sculpt brushes to DynTopo in sculpt-dev (e.g. the layer brush, draw sharp, the smooth brushes, the paint brushes, etc). This attribute API will be in a future patch. * We need to do this anyway for the eventual move to C++. Differential Revision: https://developer.blender.org/D14272 Reviewed By: Brecht Van Lommel Ref D14272 --- source/blender/editors/sculpt_paint/sculpt_detail.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'source/blender/editors/sculpt_paint/sculpt_detail.c') diff --git a/source/blender/editors/sculpt_paint/sculpt_detail.c b/source/blender/editors/sculpt_paint/sculpt_detail.c index 00503087e39..ebbb0fa429e 100644 --- a/source/blender/editors/sculpt_paint/sculpt_detail.c +++ b/source/blender/editors/sculpt_paint/sculpt_detail.c @@ -174,13 +174,13 @@ static void sample_detail_voxel(bContext *C, ViewContext *vc, const int mval[2]) BKE_sculpt_update_object_for_edit(depsgraph, ob, true, false, false); /* Average the edge length of the connected edges to the active vertex. */ - int active_vertex = SCULPT_active_vertex_get(ss); + PBVHVertRef active_vertex = SCULPT_active_vertex_get(ss); const float *active_vertex_co = SCULPT_active_vertex_co_get(ss); float edge_length = 0.0f; int tot = 0; SculptVertexNeighborIter ni; SCULPT_VERTEX_NEIGHBORS_ITER_BEGIN (ss, active_vertex, ni) { - edge_length += len_v3v3(active_vertex_co, SCULPT_vertex_co_get(ss, ni.index)); + edge_length += len_v3v3(active_vertex_co, SCULPT_vertex_co_get(ss, ni.vertex)); tot += 1; } SCULPT_VERTEX_NEIGHBORS_ITER_END(ni); @@ -578,14 +578,14 @@ static void dyntopo_detail_size_sample_from_surface(Object *ob, DyntopoDetailSizeEditCustomData *cd) { SculptSession *ss = ob->sculpt; - const int active_vertex = SCULPT_active_vertex_get(ss); + const PBVHVertRef active_vertex = SCULPT_active_vertex_get(ss); float len_accum = 0; int num_neighbors = 0; SculptVertexNeighborIter ni; SCULPT_VERTEX_NEIGHBORS_ITER_BEGIN (ss, active_vertex, ni) { len_accum += len_v3v3(SCULPT_vertex_co_get(ss, active_vertex), - SCULPT_vertex_co_get(ss, ni.index)); + SCULPT_vertex_co_get(ss, ni.vertex)); num_neighbors++; } SCULPT_VERTEX_NEIGHBORS_ITER_END(ni); -- cgit v1.2.3