Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Sharybin <sergey.vfx@gmail.com>2019-10-04 19:49:39 +0300
committerBrecht Van Lommel <brechtvanlommel@gmail.com>2019-10-04 20:00:57 +0300
commit8f1f756b839942531c69a7608c25ea85de1beb8a (patch)
tree9c9cb3d03598521ae1f8ef753b3cd1dcb0b4dadd /source/blender/editors
parentbebdb6c8249939623f80cc72433aa7d7418444bf (diff)
Subdiv CCG: add utility functions for accessing multires vertex neighbors
This is to be used by the new sculpting tools.
Diffstat (limited to 'source/blender/editors')
-rw-r--r--source/blender/editors/sculpt_paint/sculpt.c32
1 files changed, 27 insertions, 5 deletions
diff --git a/source/blender/editors/sculpt_paint/sculpt.c b/source/blender/editors/sculpt_paint/sculpt.c
index 64674ecd0a1..9bd788f7960 100644
--- a/source/blender/editors/sculpt_paint/sculpt.c
+++ b/source/blender/editors/sculpt_paint/sculpt.c
@@ -64,6 +64,7 @@
#include "BKE_report.h"
#include "BKE_scene.h"
#include "BKE_screen.h"
+#include "BKE_subdiv_ccg.h"
#include "BKE_subsurf.h"
#include "DEG_depsgraph.h"
@@ -293,16 +294,37 @@ static void sculpt_vertex_neighbors_get_faces(SculptSession *ss,
}
}
-static void sculpt_vertex_neighbors_get_grids(SculptSession *UNUSED(ss),
- int UNUSED(index),
+static void sculpt_vertex_neighbors_get_grids(SculptSession *ss,
+ int index,
SculptVertexNeighborIter *iter)
{
- /* TODO: implement this for multires. It might also be worth changing this
- * iterator to provide a coordinate and mask pointer directly for effiency,
- * rather than converting back and forth between CCGElem and global index. */
+ /* TODO: optimize this. We could fill SculptVertexNeighborIter directly,
+ * maybe provide coordinate and mask pointers directly rather than converting
+ * back and forth between CCGElem and global index. */
+ const CCGKey *key = BKE_pbvh_get_grid_key(ss->pbvh);
+ const int grid_index = index / key->grid_area;
+ const int vertex_index = index - grid_index * key->grid_area;
+
+ SubdivCCGCoord coord = {.grid_index = grid_index,
+ .x = vertex_index % key->grid_size,
+ .y = vertex_index / key->grid_size};
+
+ SubdivCCGNeighbors neighbors;
+ BKE_subdiv_ccg_neighbor_coords_get(ss->subdiv_ccg, &coord, &neighbors);
+
iter->size = 0;
iter->capacity = SCULPT_VERTEX_NEIGHBOR_FIXED_CAPACITY;
iter->neighbors = iter->neighbors_fixed;
+
+ for (int i = 0; i < neighbors.size; i++) {
+ sculpt_vertex_neighbor_add(iter,
+ neighbors.coords[i].grid_index * key->grid_area +
+ neighbors.coords[i].y * key->grid_size + neighbors.coords[i].x);
+ }
+
+ if (neighbors.coords != neighbors.coords_fixed) {
+ MEM_freeN(neighbors.coords);
+ }
}
static void sculpt_vertex_neighbors_get(SculptSession *ss,