Cleanup: Remove mesh poly macros, simplify loops
These `ME_POLY_LOOP_PREV` are redundant, since they're similar to the `poly_corner_prev` inline functions. They were also confusing, since they took an index into the poly and returned an index into the entire corner range. Instead structure code to use the function version, and simplify some loops in the process.
This commit is contained in:
@@ -310,6 +310,7 @@ typedef enum SubdivCCGAdjacencyType {
|
||||
SubdivCCGAdjacencyType BKE_subdiv_ccg_coarse_mesh_adjacency_info_get(const SubdivCCG *subdiv_ccg,
|
||||
const SubdivCCGCoord *coord,
|
||||
const int *corner_verts,
|
||||
int corners_num,
|
||||
const struct MPoly *mpoly,
|
||||
int *r_v1,
|
||||
int *r_v2);
|
||||
|
||||
@@ -1999,12 +1999,11 @@ int BKE_sculpt_mask_layers_ensure(Depsgraph *depsgraph,
|
||||
int level = max_ii(1, mmd->sculptlvl);
|
||||
int gridsize = BKE_ccg_gridsize(level);
|
||||
int gridarea = gridsize * gridsize;
|
||||
int i, j;
|
||||
|
||||
gmask = static_cast<GridPaintMask *>(
|
||||
CustomData_add_layer(&me->ldata, CD_GRID_PAINT_MASK, CD_SET_DEFAULT, me->totloop));
|
||||
|
||||
for (i = 0; i < me->totloop; i++) {
|
||||
for (int i = 0; i < me->totloop; i++) {
|
||||
GridPaintMask *gpm = &gmask[i];
|
||||
|
||||
gpm->level = level;
|
||||
@@ -2014,27 +2013,26 @@ int BKE_sculpt_mask_layers_ensure(Depsgraph *depsgraph,
|
||||
|
||||
/* if vertices already have mask, copy into multires data */
|
||||
if (paint_mask) {
|
||||
for (i = 0; i < me->totpoly; i++) {
|
||||
for (const int i : polys.index_range()) {
|
||||
const MPoly &poly = polys[i];
|
||||
float avg = 0;
|
||||
|
||||
/* mask center */
|
||||
for (j = 0; j < poly.totloop; j++) {
|
||||
const int vert = corner_verts[poly.loopstart + j];
|
||||
float avg = 0.0f;
|
||||
for (const int vert : corner_verts.slice(poly.loopstart, poly.totloop)) {
|
||||
avg += paint_mask[vert];
|
||||
}
|
||||
avg /= float(poly.totloop);
|
||||
|
||||
/* fill in multires mask corner */
|
||||
for (j = 0; j < poly.totloop; j++) {
|
||||
GridPaintMask *gpm = &gmask[poly.loopstart + j];
|
||||
const int vert = corner_verts[poly.loopstart + j];
|
||||
const int prev = ME_POLY_LOOP_PREV(&poly, j);
|
||||
const int next = ME_POLY_LOOP_NEXT(&poly, j);
|
||||
for (const int corner : blender::IndexRange(poly.loopstart, poly.totloop)) {
|
||||
GridPaintMask *gpm = &gmask[corner];
|
||||
const int vert = corner_verts[corner];
|
||||
const int prev = corner_verts[blender::bke::mesh::poly_corner_prev(poly, vert)];
|
||||
const int next = corner_verts[blender::bke::mesh::poly_corner_next(poly, vert)];
|
||||
|
||||
gpm->data[0] = avg;
|
||||
gpm->data[1] = (paint_mask[vert] + paint_mask[corner_verts[next]]) * 0.5f;
|
||||
gpm->data[2] = (paint_mask[vert] + paint_mask[corner_verts[prev]]) * 0.5f;
|
||||
gpm->data[1] = (paint_mask[vert] + paint_mask[vert]) * 0.5f;
|
||||
gpm->data[2] = (paint_mask[vert] + paint_mask[vert]) * 0.5f;
|
||||
gpm->data[3] = paint_mask[vert];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1986,7 +1986,7 @@ const int *BKE_subdiv_ccg_start_face_grid_index_get(const SubdivCCG *subdiv_ccg)
|
||||
|
||||
static void adjacet_vertices_index_from_adjacent_edge(const SubdivCCG *subdiv_ccg,
|
||||
const SubdivCCGCoord *coord,
|
||||
const int *corner_verts,
|
||||
const blender::Span<int> corner_verts,
|
||||
const MPoly *polys,
|
||||
int *r_v1,
|
||||
int *r_v2)
|
||||
@@ -1996,14 +1996,13 @@ static void adjacet_vertices_index_from_adjacent_edge(const SubdivCCG *subdiv_cc
|
||||
const MPoly &poly = polys[poly_index];
|
||||
*r_v1 = corner_verts[coord->grid_index];
|
||||
|
||||
const blender::Span poly_verts(&corner_verts[poly.loopstart], poly.totloop);
|
||||
const int i = poly_verts.first_index(*r_v1);
|
||||
const int corner = blender::bke::mesh::poly_find_corner_from_vert(poly, corner_verts, *r_v1);
|
||||
if (coord->x == grid_size_1) {
|
||||
const int next = ME_POLY_LOOP_NEXT(&poly, i);
|
||||
const int next = blender::bke::mesh::poly_corner_next(poly, corner);
|
||||
*r_v2 = corner_verts[next];
|
||||
}
|
||||
if (coord->y == grid_size_1) {
|
||||
const int prev = ME_POLY_LOOP_PREV(&poly, i);
|
||||
const int prev = blender::bke::mesh::poly_corner_prev(poly, corner);
|
||||
*r_v2 = corner_verts[prev];
|
||||
}
|
||||
}
|
||||
@@ -2011,6 +2010,7 @@ static void adjacet_vertices_index_from_adjacent_edge(const SubdivCCG *subdiv_cc
|
||||
SubdivCCGAdjacencyType BKE_subdiv_ccg_coarse_mesh_adjacency_info_get(const SubdivCCG *subdiv_ccg,
|
||||
const SubdivCCGCoord *coord,
|
||||
const int *corner_verts,
|
||||
const int corners_num,
|
||||
const MPoly *polys,
|
||||
int *r_v1,
|
||||
int *r_v2)
|
||||
@@ -2028,7 +2028,8 @@ SubdivCCGAdjacencyType BKE_subdiv_ccg_coarse_mesh_adjacency_info_get(const Subdi
|
||||
return SUBDIV_CCG_ADJACENT_VERTEX;
|
||||
}
|
||||
/* Grid corner adjacent to the middle of a coarse mesh edge. */
|
||||
adjacet_vertices_index_from_adjacent_edge(subdiv_ccg, coord, corner_verts, polys, r_v1, r_v2);
|
||||
adjacet_vertices_index_from_adjacent_edge(
|
||||
subdiv_ccg, coord, {corner_verts, corners_num}, polys, r_v1, r_v2);
|
||||
return SUBDIV_CCG_ADJACENT_EDGE;
|
||||
}
|
||||
|
||||
@@ -2036,7 +2037,7 @@ SubdivCCGAdjacencyType BKE_subdiv_ccg_coarse_mesh_adjacency_info_get(const Subdi
|
||||
if (!is_inner_edge_grid_coordinate(subdiv_ccg, coord)) {
|
||||
/* Grid boundary adjacent to a coarse mesh edge. */
|
||||
adjacet_vertices_index_from_adjacent_edge(
|
||||
subdiv_ccg, coord, corner_verts, polys, r_v1, r_v2);
|
||||
subdiv_ccg, coord, {corner_verts, corners_num}, polys, r_v1, r_v2);
|
||||
return SUBDIV_CCG_ADJACENT_EDGE;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -768,7 +768,13 @@ bool SCULPT_vertex_has_unique_face_set(SculptSession *ss, PBVHVertRef vertex)
|
||||
coord.y = vertex_index / key->grid_size;
|
||||
int v1, v2;
|
||||
const SubdivCCGAdjacencyType adjacency = BKE_subdiv_ccg_coarse_mesh_adjacency_info_get(
|
||||
ss->subdiv_ccg, &coord, ss->corner_verts.data(), ss->polys.data(), &v1, &v2);
|
||||
ss->subdiv_ccg,
|
||||
&coord,
|
||||
ss->corner_verts.data(),
|
||||
ss->corner_verts.size(),
|
||||
ss->polys.data(),
|
||||
&v1,
|
||||
&v2);
|
||||
switch (adjacency) {
|
||||
case SUBDIV_CCG_ADJACENT_VERTEX:
|
||||
return sculpt_check_unique_face_set_in_base_mesh(ss, v1);
|
||||
@@ -1002,7 +1008,13 @@ bool SCULPT_vertex_is_boundary(const SculptSession *ss, const PBVHVertRef vertex
|
||||
coord.y = vertex_index / key->grid_size;
|
||||
int v1, v2;
|
||||
const SubdivCCGAdjacencyType adjacency = BKE_subdiv_ccg_coarse_mesh_adjacency_info_get(
|
||||
ss->subdiv_ccg, &coord, ss->corner_verts.data(), ss->polys.data(), &v1, &v2);
|
||||
ss->subdiv_ccg,
|
||||
&coord,
|
||||
ss->corner_verts.data(),
|
||||
ss->corner_verts.size(),
|
||||
ss->polys.data(),
|
||||
&v1,
|
||||
&v2);
|
||||
switch (adjacency) {
|
||||
case SUBDIV_CCG_ADJACENT_VERTEX:
|
||||
return sculpt_check_boundary_vertex_in_base_mesh(ss, v1);
|
||||
|
||||
@@ -398,10 +398,6 @@ enum {
|
||||
/** \name Utility Macros
|
||||
* \{ */
|
||||
|
||||
#define ME_POLY_LOOP_PREV(poly, i) \
|
||||
((poly)->loopstart + (((i) + (poly)->totloop - 1) % (poly)->totloop))
|
||||
#define ME_POLY_LOOP_NEXT(poly, i) ((poly)->loopstart + (((i) + 1) % (poly)->totloop))
|
||||
|
||||
/** Number of tri's that make up this polygon once tessellated. */
|
||||
#define ME_POLY_TRI_TOT(poly) ((poly)->totloop - 2)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user