Cleanup: Use references for mesh poly variables

Similar to the previous commit, this simplifies future refactoring
to change the way edges are stored, and further differentiates
single poly variables from array pointers.
This commit is contained in:
2023-03-03 11:40:34 -05:00
parent 45cff837bc
commit 915ff8d152
56 changed files with 455 additions and 468 deletions

View File

@@ -153,7 +153,8 @@ void old_mdisps_bilinear(float out[3], float (*disps)[3], int st, float u, float
/**
* Find per-corner coordinate with given per-face UV coord.
*/
int mdisp_rot_face_to_crn(struct MPoly *poly, int face_side, float u, float v, float *x, float *y);
int mdisp_rot_face_to_crn(
const struct MPoly *poly, int face_side, float u, float v, float *x, float *y);
/* Reshaping, define in multires_reshape.cc */

View File

@@ -193,12 +193,12 @@ void BKE_crazyspace_set_quats_mesh(Mesh *me,
const Span<MLoop> loops = me->loops();
for (int i = 0; i < me->totpoly; i++) {
const MPoly *poly = &polys[i];
const MLoop *ml_next = &loops[poly->loopstart];
const MLoop *ml_curr = &ml_next[poly->totloop - 1];
const MLoop *ml_prev = &ml_next[poly->totloop - 2];
const MPoly &poly = polys[i];
const MLoop *ml_next = &loops[poly.loopstart];
const MLoop *ml_curr = &ml_next[poly.totloop - 1];
const MLoop *ml_prev = &ml_next[poly.totloop - 2];
for (int j = 0; j < poly->totloop; j++) {
for (int j = 0; j < poly.totloop; j++) {
if (!BLI_BITMAP_TEST(vert_tag, ml_curr->v)) {
const float *co_prev, *co_curr, *co_next; /* orig */
const float *vd_prev, *vd_curr, *vd_next; /* deform */

View File

@@ -1119,15 +1119,15 @@ void BKE_defvert_extract_vgroup_to_polyweights(const MDeformVert *dvert,
dvert, defgroup, verts_num, invert_vgroup, tmp_weights);
while (i--) {
const MPoly *poly = &polys[i];
const MLoop *ml = &loops[poly->loopstart];
int j = poly->totloop;
const MPoly &poly = polys[i];
const MLoop *ml = &loops[poly.loopstart];
int j = poly.totloop;
float w = 0.0f;
for (; j--; ml++) {
w += tmp_weights[ml->v];
}
r_weights[i] = w / float(poly->totloop);
r_weights[i] = w / float(poly.totloop);
}
MEM_freeN(tmp_weights);

View File

@@ -2754,7 +2754,7 @@ bool BKE_gpencil_convert_mesh(Main *bmain,
const VArray<int> mesh_material_indices = me_eval->attributes().lookup_or_default<int>(
"material_index", ATTR_DOMAIN_FACE, 0);
for (i = 0; i < polys_len; i++) {
const MPoly *poly = &polys[i];
const MPoly &poly = polys[i];
/* Find material. */
int mat_idx = 0;
@@ -2774,19 +2774,19 @@ bool BKE_gpencil_convert_mesh(Main *bmain,
gpencil_add_material(bmain, ob_gp, element_name, color, false, true, &mat_idx);
}
bGPDstroke *gps_fill = BKE_gpencil_stroke_add(gpf_fill, mat_idx, poly->totloop, 10, false);
bGPDstroke *gps_fill = BKE_gpencil_stroke_add(gpf_fill, mat_idx, poly.totloop, 10, false);
gps_fill->flag |= GP_STROKE_CYCLIC;
/* Create dvert data. */
const Span<MDeformVert> dverts = me_eval->deform_verts();
if (use_vgroups && !dverts.is_empty()) {
gps_fill->dvert = (MDeformVert *)MEM_callocN(sizeof(MDeformVert) * poly->totloop,
gps_fill->dvert = (MDeformVert *)MEM_callocN(sizeof(MDeformVert) * poly.totloop,
"gp_fill_dverts");
}
/* Add points to strokes. */
for (int j = 0; j < poly->totloop; j++) {
const MLoop *ml = &loops[poly->loopstart + j];
for (int j = 0; j < poly.totloop; j++) {
const MLoop *ml = &loops[poly.loopstart + j];
bGPDspoint *pt = &gps_fill->points[j];
copy_v3_v3(&pt->x, positions[ml->v]);
@@ -2808,7 +2808,7 @@ bool BKE_gpencil_convert_mesh(Main *bmain,
}
}
/* If has only 3 points subdivide. */
if (poly->totloop == 3) {
if (poly.totloop == 3) {
BKE_gpencil_stroke_subdivide(gpd, gps_fill, 1, GP_SUBDIV_SIMPLE);
}

View File

@@ -773,13 +773,13 @@ static Mesh *imesh_to_mesh(IMesh *im, MeshesToIMeshInfo &mim)
*/
for (int fi : im->face_index_range()) {
const Face *f = im->face(fi);
const MPoly *poly = &dst_polys[fi];
const MPoly &poly = dst_polys[fi];
for (int j : f->index_range()) {
if (f->edge_orig[j] != NO_INDEX) {
const Mesh *orig_me;
int index_in_orig_me;
mim.input_medge_for_orig_index(f->edge_orig[j], &orig_me, &index_in_orig_me);
int e_index = dst_loops[poly->loopstart + j].e;
int e_index = dst_loops[poly.loopstart + j].e;
copy_edge_attributes(result, orig_me, e_index, index_in_orig_me);
}
}

View File

@@ -236,10 +236,10 @@ class MeshFairingContext : public FairingContext {
float r_adj_prev[3]) override
{
const int vert = mloop_[loop].v;
const MPoly *poly = &polys[loop_to_poly_map_[loop]];
const int corner = poly_find_loop_from_vert(poly, &mloop_[poly->loopstart], vert);
copy_v3_v3(r_adj_next, co_[ME_POLY_LOOP_NEXT(mloop_, poly, corner)->v]);
copy_v3_v3(r_adj_prev, co_[ME_POLY_LOOP_PREV(mloop_, poly, corner)->v]);
const MPoly &poly = polys[loop_to_poly_map_[loop]];
const int corner = poly_find_loop_from_vert(&poly, &mloop_[poly.loopstart], vert);
copy_v3_v3(r_adj_next, co_[ME_POLY_LOOP_NEXT(mloop_, &poly, corner)->v]);
copy_v3_v3(r_adj_prev, co_[ME_POLY_LOOP_PREV(mloop_, &poly, corner)->v]);
}
int other_vertex_index_from_loop(const int loop, const uint v) override

View File

@@ -207,10 +207,10 @@ static void mesh_vert_poly_or_loop_map_create(MeshElemMap **r_map,
/* Count number of polys for each vertex */
for (i = 0; i < totpoly; i++) {
const MPoly *poly = &polys[i];
const MPoly &poly = polys[i];
for (j = 0; j < poly->totloop; j++) {
map[mloop[poly->loopstart + j].v].count++;
for (j = 0; j < poly.totloop; j++) {
map[mloop[poly.loopstart + j].v].count++;
}
}
@@ -225,12 +225,12 @@ static void mesh_vert_poly_or_loop_map_create(MeshElemMap **r_map,
/* Find the users */
for (i = 0; i < totpoly; i++) {
const MPoly *poly = &polys[i];
const MPoly &poly = polys[i];
for (j = 0; j < poly->totloop; j++) {
uint v = mloop[poly->loopstart + j].v;
for (j = 0; j < poly.totloop; j++) {
uint v = mloop[poly.loopstart + j].v;
map[v].indices[map[v].count] = do_loops ? poly->loopstart + j : i;
map[v].indices[map[v].count] = do_loops ? poly.loopstart + j : i;
map[v].count++;
}
}
@@ -1132,9 +1132,9 @@ static bool mesh_calc_islands_loop_poly_uv(const int totedge,
if (poly_groups[p_idx] != grp_idx) {
continue;
}
const MPoly *poly = &polys[p_idx];
const MPoly &poly = polys[p_idx];
poly_indices[num_pidx++] = p_idx;
for (l_idx = poly->loopstart, pl_idx = 0; pl_idx < poly->totloop; l_idx++, pl_idx++) {
for (l_idx = poly.loopstart, pl_idx = 0; pl_idx < poly.totloop; l_idx++, pl_idx++) {
const MLoop *ml = &loops[l_idx];
loop_indices[num_lidx++] = l_idx;
if (num_edge_borders && BLI_BITMAP_TEST(edge_borders, ml->e) &&

View File

@@ -1470,10 +1470,10 @@ void BKE_mesh_normals_loop_split(const float (*vert_positions)[3],
int poly_index;
for (poly_index = 0; poly_index < numPolys; poly_index++) {
const MPoly *poly = &polys[poly_index];
int ml_index = poly->loopstart;
const int ml_index_end = ml_index + poly->totloop;
const bool is_poly_flat = ((poly->flag & ME_SMOOTH) == 0);
const MPoly &poly = polys[poly_index];
int ml_index = poly.loopstart;
const int ml_index_end = ml_index + poly.totloop;
const bool is_poly_flat = ((poly.flag & ME_SMOOTH) == 0);
for (; ml_index < ml_index_end; ml_index++) {
if (is_poly_flat) {
@@ -1733,9 +1733,9 @@ static void mesh_normals_loop_custom_set(const float (*positions)[3],
* previous loop's face and current's one as sharp.
* We know those two loops do not point to the same edge,
* since we do not allow reversed winding in a same smooth fan. */
const MPoly *poly = &polys[loop_to_poly[lidx]];
const MPoly &poly = polys[loop_to_poly[lidx]];
const MLoop *mlp =
&mloops[(lidx == poly->loopstart) ? poly->loopstart + poly->totloop - 1 : lidx - 1];
&mloops[(lidx == poly.loopstart) ? poly.loopstart + poly.totloop - 1 : lidx - 1];
sharp_edges[(prev_ml->e == mlp->e) ? prev_ml->e : ml->e] = true;
org_nor = nor;
@@ -1758,9 +1758,9 @@ static void mesh_normals_loop_custom_set(const float (*positions)[3],
float *nor = r_custom_loop_normals[nidx];
if (dot_v3v3(org_nor, nor) < LNOR_SPACE_TRIGO_THRESHOLD) {
const MPoly *poly = &polys[loop_to_poly[lidx]];
const MPoly &poly = polys[loop_to_poly[lidx]];
const MLoop *mlp =
&mloops[(lidx == poly->loopstart) ? poly->loopstart + poly->totloop - 1 : lidx - 1];
&mloops[(lidx == poly.loopstart) ? poly.loopstart + poly.totloop - 1 : lidx - 1];
sharp_edges[(prev_ml->e == mlp->e) ? prev_ml->e : ml->e] = true;
}
}

View File

@@ -892,9 +892,9 @@ void BKE_mesh_remap_calc_edges_from_mesh(const int mode,
if (mesh_remap_bvhtree_query_nearest(
&treedata, &nearest, tmp_co, max_dist_sq, &hit_dist)) {
const MLoopTri *lt = &treedata.looptri[nearest.index];
const MPoly *mp_src = &polys_src[lt->poly];
const MLoop *ml_src = &loops_src[mp_src->loopstart];
int nloops = mp_src->totloop;
const MPoly &poly_src = polys_src[lt->poly];
const MLoop *ml_src = &loops_src[poly_src.loopstart];
int nloops = poly_src.totloop;
float best_dist_sq = FLT_MAX;
int best_eidx_src = -1;
@@ -1059,11 +1059,11 @@ static void mesh_island_to_astar_graph_edge_process(MeshIslandStore *islands,
for (i = 0; i < edge_to_poly_map[edge_idx].count; i++) {
const int pidx = edge_to_poly_map[edge_idx].indices[i];
const MPoly *poly = &polys[pidx];
const MPoly &poly = polys[pidx];
const int pidx_isld = islands ? poly_island_index_map[pidx] : pidx;
void *custom_data = is_edge_innercut ? POINTER_FROM_INT(edge_idx) : POINTER_FROM_INT(-1);
if (UNLIKELY(islands && (islands->items_to_islands[poly->loopstart] != island_index))) {
if (UNLIKELY(islands && (islands->items_to_islands[poly.loopstart] != island_index))) {
/* poly not in current island, happens with border edges... */
poly_island_indices[i] = -1;
continue;
@@ -1075,7 +1075,7 @@ static void mesh_island_to_astar_graph_edge_process(MeshIslandStore *islands,
}
if (poly_status[pidx_isld] == POLY_UNSET) {
BKE_mesh_calc_poly_center(poly, &loops[poly->loopstart], positions, poly_centers[pidx_isld]);
BKE_mesh_calc_poly_center(&poly, &loops[poly.loopstart], positions, poly_centers[pidx_isld]);
BLI_astar_node_init(as_graph, pidx_isld, poly_centers[pidx_isld]);
poly_status[pidx_isld] = POLY_CENTER_INIT;
}
@@ -1156,14 +1156,14 @@ static void mesh_island_to_astar_graph(MeshIslandStore *islands,
for (pidx_isld = node_num; pidx_isld--;) {
const int pidx = islands ? island_poly_map->indices[pidx_isld] : pidx_isld;
const MPoly *poly = &polys[pidx];
const MPoly &poly = polys[pidx];
int pl_idx, l_idx;
if (poly_status[pidx_isld] == POLY_COMPLETE) {
continue;
}
for (pl_idx = 0, l_idx = poly->loopstart; pl_idx < poly->totloop; pl_idx++, l_idx++) {
for (pl_idx = 0, l_idx = poly.loopstart; pl_idx < poly.totloop; pl_idx++, l_idx++) {
const MLoop *ml = &loops[l_idx];
if (BLI_BITMAP_TEST(done_edges, ml->e)) {
@@ -2195,9 +2195,9 @@ void BKE_mesh_remap_calc_polys_from_mesh(const int mode,
nearest.index = -1;
for (i = 0; i < numpolys_dst; i++) {
const MPoly *poly = &polys_dst[i];
const MPoly &poly = polys_dst[i];
BKE_mesh_calc_poly_center(poly, &loops_dst[poly->loopstart], vert_positions_dst, tmp_co);
BKE_mesh_calc_poly_center(&poly, &loops_dst[poly.loopstart], vert_positions_dst, tmp_co);
/* Convert the vertex to tree coordinates, if needed. */
if (space_transform) {
@@ -2220,9 +2220,9 @@ void BKE_mesh_remap_calc_polys_from_mesh(const int mode,
BLI_assert(poly_nors_dst);
for (i = 0; i < numpolys_dst; i++) {
const MPoly *poly = &polys_dst[i];
const MPoly &poly = polys_dst[i];
BKE_mesh_calc_poly_center(poly, &loops_dst[poly->loopstart], vert_positions_dst, tmp_co);
BKE_mesh_calc_poly_center(&poly, &loops_dst[poly.loopstart], vert_positions_dst, tmp_co);
copy_v3_v3(tmp_no, poly_nors_dst[i]);
/* Convert the vertex to tree coordinates, if needed. */
@@ -2269,7 +2269,7 @@ void BKE_mesh_remap_calc_polys_from_mesh(const int mode,
/* For each dst poly, we sample some rays from it (2D grid in pnor space)
* and use their hits to interpolate from source polys. */
/* NOTE: dst poly is early-converted into src space! */
const MPoly *poly = &polys_dst[i];
const MPoly &poly = polys_dst[i];
int tot_rays, done_rays = 0;
float poly_area_2d_inv, done_area = 0.0f;
@@ -2282,11 +2282,11 @@ void BKE_mesh_remap_calc_polys_from_mesh(const int mode,
float totweights = 0.0f;
float hit_dist_accum = 0.0f;
int sources_num = 0;
const int tris_num = poly->totloop - 2;
const int tris_num = poly.totloop - 2;
int j;
BKE_mesh_calc_poly_center(
poly, &loops_dst[poly->loopstart], vert_positions_dst, pcent_dst);
&poly, &loops_dst[poly.loopstart], vert_positions_dst, pcent_dst);
copy_v3_v3(tmp_no, poly_nors_dst[i]);
/* We do our transform here, else it'd be redone by raycast helper for each ray, ugh! */
@@ -2297,8 +2297,8 @@ void BKE_mesh_remap_calc_polys_from_mesh(const int mode,
copy_vn_fl(weights, int(numpolys_src), 0.0f);
if (UNLIKELY(size_t(poly->totloop) > tmp_poly_size)) {
tmp_poly_size = size_t(poly->totloop);
if (UNLIKELY(size_t(poly.totloop) > tmp_poly_size)) {
tmp_poly_size = size_t(poly.totloop);
poly_vcos_2d = static_cast<float(*)[2]>(
MEM_reallocN(poly_vcos_2d, sizeof(*poly_vcos_2d) * tmp_poly_size));
tri_vidx_2d = static_cast<int(*)[3]>(
@@ -2314,8 +2314,8 @@ void BKE_mesh_remap_calc_polys_from_mesh(const int mode,
/* Get (2D) bounding square of our poly. */
INIT_MINMAX2(poly_dst_2d_min, poly_dst_2d_max);
for (j = 0; j < poly->totloop; j++) {
const MLoop *ml = &loops_dst[j + poly->loopstart];
for (j = 0; j < poly.totloop; j++) {
const MLoop *ml = &loops_dst[j + poly.loopstart];
copy_v3_v3(tmp_co, vert_positions_dst[ml->v]);
if (space_transform) {
BLI_space_transform_apply(space_transform, tmp_co);
@@ -2338,17 +2338,17 @@ void BKE_mesh_remap_calc_polys_from_mesh(const int mode,
}
tot_rays *= tot_rays;
poly_area_2d_inv = area_poly_v2(poly_vcos_2d, uint(poly->totloop));
poly_area_2d_inv = area_poly_v2(poly_vcos_2d, uint(poly.totloop));
/* In case we have a null-area degenerated poly... */
poly_area_2d_inv = 1.0f / max_ff(poly_area_2d_inv, 1e-9f);
/* Tessellate our poly. */
if (poly->totloop == 3) {
if (poly.totloop == 3) {
tri_vidx_2d[0][0] = 0;
tri_vidx_2d[0][1] = 1;
tri_vidx_2d[0][2] = 2;
}
if (poly->totloop == 4) {
if (poly.totloop == 4) {
tri_vidx_2d[0][0] = 0;
tri_vidx_2d[0][1] = 1;
tri_vidx_2d[0][2] = 2;
@@ -2357,7 +2357,7 @@ void BKE_mesh_remap_calc_polys_from_mesh(const int mode,
tri_vidx_2d[1][2] = 3;
}
else {
BLI_polyfill_calc(poly_vcos_2d, uint(poly->totloop), -1, (uint(*)[3])tri_vidx_2d);
BLI_polyfill_calc(poly_vcos_2d, uint(poly.totloop), -1, (uint(*)[3])tri_vidx_2d);
}
for (j = 0; j < tris_num; j++) {

View File

@@ -342,9 +342,9 @@ void BKE_remesh_reproject_sculpt_face_sets(Mesh *target, const Mesh *source)
BVHTreeNearest nearest;
nearest.index = -1;
nearest.dist_sq = FLT_MAX;
const MPoly *poly = &target_polys[i];
BKE_mesh_calc_poly_center(poly,
&target_loops[poly->loopstart],
const MPoly &poly = target_polys[i];
BKE_mesh_calc_poly_center(&poly,
&target_loops[poly.loopstart],
reinterpret_cast<const float(*)[3]>(target_positions.data()),
from_co);
BLI_bvhtree_find_nearest(

View File

@@ -180,8 +180,8 @@ struct SGLSLMeshToTangent {
#ifdef USE_LOOPTRI_DETECT_QUADS
if (face_as_quad_map) {
const MLoopTri *lt = &looptri[face_as_quad_map[face_num]];
const MPoly *poly = &polys[lt->poly];
if (poly->totloop == 4) {
const MPoly &poly = polys[lt->poly];
if (poly.totloop == 4) {
return 4;
}
}
@@ -197,9 +197,9 @@ struct SGLSLMeshToTangent {
#ifdef USE_LOOPTRI_DETECT_QUADS
if (face_as_quad_map) {
lt = &looptri[face_as_quad_map[face_num]];
const MPoly *poly = &polys[lt->poly];
if (poly->totloop == 4) {
return (uint(poly->loopstart) + vert_num);
const MPoly &poly = polys[lt->poly];
if (poly.totloop == 4) {
return (uint(poly.loopstart) + vert_num);
}
/* fall through to regular triangle */
}
@@ -245,14 +245,14 @@ struct SGLSLMeshToTangent {
return mikk::float3(precomputedFaceNormals[lt->poly]);
}
#ifdef USE_LOOPTRI_DETECT_QUADS
const MPoly *poly = &polys[lt->poly];
const MPoly &poly = polys[lt->poly];
float normal[3];
if (poly->totloop == 4) {
if (poly.totloop == 4) {
normal_quad_v3(normal,
positions[mloop[poly->loopstart + 0].v],
positions[mloop[poly->loopstart + 1].v],
positions[mloop[poly->loopstart + 2].v],
positions[mloop[poly->loopstart + 3].v]);
positions[mloop[poly.loopstart + 0].v],
positions[mloop[poly.loopstart + 1].v],
positions[mloop[poly.loopstart + 2].v],
positions[mloop[poly.loopstart + 3].v]);
}
else
#endif

View File

@@ -1556,7 +1556,7 @@ void multiresModifier_ensure_external_read(struct Mesh *mesh, const MultiresModi
/***************** Multires interpolation stuff *****************/
int mdisp_rot_face_to_crn(
MPoly *poly, const int face_side, const float u, const float v, float *x, float *y)
const MPoly *poly, const int face_side, const float u, const float v, float *x, float *y)
{
const float offset = face_side * 0.5f - 0.5f;
int S = 0;

View File

@@ -98,11 +98,11 @@ void multires_reshape_apply_base_refit_base_mesh(MultiresReshapeContext *reshape
/* Find center. */
int tot = 0;
for (int j = 0; j < pmap[i].count; j++) {
const MPoly *poly = &reshape_context->base_polys[pmap[i].indices[j]];
const MPoly &poly = reshape_context->base_polys[pmap[i].indices[j]];
/* This double counts, not sure if that's bad or good. */
for (int k = 0; k < poly->totloop; k++) {
const int vndx = reshape_context->base_loops[poly->loopstart + k].v;
for (int k = 0; k < poly.totloop; k++) {
const int vndx = reshape_context->base_loops[poly.loopstart + k].v;
if (vndx != i) {
add_v3_v3(center, origco[vndx]);
tot++;
@@ -113,20 +113,20 @@ void multires_reshape_apply_base_refit_base_mesh(MultiresReshapeContext *reshape
/* Find normal. */
for (int j = 0; j < pmap[i].count; j++) {
const MPoly *poly = &reshape_context->base_polys[pmap[i].indices[j]];
const MPoly &poly = reshape_context->base_polys[pmap[i].indices[j]];
MPoly fake_poly;
float no[3];
/* Set up poly, loops, and coords in order to call BKE_mesh_calc_poly_normal(). */
fake_poly.totloop = poly->totloop;
fake_poly.totloop = poly.totloop;
fake_poly.loopstart = 0;
MLoop *fake_loops = static_cast<MLoop *>(
MEM_malloc_arrayN(poly->totloop, sizeof(MLoop), __func__));
MEM_malloc_arrayN(poly.totloop, sizeof(MLoop), __func__));
float(*fake_co)[3] = static_cast<float(*)[3]>(
MEM_malloc_arrayN(poly->totloop, sizeof(float[3]), __func__));
MEM_malloc_arrayN(poly.totloop, sizeof(float[3]), __func__));
for (int k = 0; k < poly->totloop; k++) {
const int vndx = reshape_context->base_loops[poly->loopstart + k].v;
for (int k = 0; k < poly.totloop; k++) {
const int vndx = reshape_context->base_loops[poly.loopstart + k].v;
fake_loops[k].v = k;

View File

@@ -648,8 +648,8 @@ static void foreach_vertex(const SubdivForeachContext *foreach_context,
const int face_index = multires_reshape_grid_to_face_index(reshape_context,
grid_coord.grid_index);
const MPoly *base_poly = &reshape_context->base_polys[face_index];
const int num_corners = base_poly->totloop;
const MPoly &base_poly = reshape_context->base_polys[face_index];
const int num_corners = base_poly.totloop;
const int start_grid_index = reshape_context->face_start_grid_index[face_index];
const int corner = grid_coord.grid_index - start_grid_index;
@@ -857,9 +857,9 @@ static void geometry_init_loose_information(MultiresReshapeSmoothContext *reshap
int num_used_edges = 0;
for (const int poly_index : base_polys.index_range()) {
const MPoly *base_poly = &base_polys[poly_index];
for (int corner = 0; corner < base_poly->totloop; corner++) {
const MLoop *loop = &base_loops[base_poly->loopstart + corner];
const MPoly &base_poly = base_polys[poly_index];
for (int corner = 0; corner < base_poly.totloop; corner++) {
const MLoop *loop = &base_loops[base_poly.loopstart + corner];
if (!BLI_BITMAP_TEST_BOOL(reshape_smooth_context->non_loose_base_edge_map, loop->e)) {
BLI_BITMAP_ENABLE(reshape_smooth_context->non_loose_base_edge_map, loop->e);

View File

@@ -35,18 +35,18 @@ static void multires_subdivide_create_object_space_linear_grids(Mesh *mesh)
MDisps *mdisps = static_cast<MDisps *>(
CustomData_get_layer_for_write(&mesh->ldata, CD_MDISPS, mesh->totloop));
for (const int p : polys.index_range()) {
const MPoly *poly = &polys[p];
const MPoly &poly = polys[p];
float poly_center[3];
BKE_mesh_calc_poly_center(poly, &loops[poly->loopstart], positions, poly_center);
for (int l = 0; l < poly->totloop; l++) {
const int loop_index = poly->loopstart + l;
BKE_mesh_calc_poly_center(&poly, &loops[poly.loopstart], positions, poly_center);
for (int l = 0; l < poly.totloop; l++) {
const int loop_index = poly.loopstart + l;
float(*disps)[3] = mdisps[loop_index].disps;
mdisps[loop_index].totdisp = 4;
mdisps[loop_index].level = 1;
int prev_loop_index = l - 1 >= 0 ? loop_index - 1 : loop_index + poly->totloop - 1;
int next_loop_index = l + 1 < poly->totloop ? loop_index + 1 : poly->loopstart;
int prev_loop_index = l - 1 >= 0 ? loop_index - 1 : loop_index + poly.totloop - 1;
int next_loop_index = l + 1 < poly.totloop ? loop_index + 1 : poly.loopstart;
const MLoop *loop = &loops[loop_index];
const MLoop *loop_next = &loops[next_loop_index];

View File

@@ -368,8 +368,8 @@ int multires_reshape_grid_to_corner(const MultiresReshapeContext *reshape_contex
bool multires_reshape_is_quad_face(const MultiresReshapeContext *reshape_context, int face_index)
{
const MPoly *base_poly = &reshape_context->base_polys[face_index];
return (base_poly->totloop == 4);
const MPoly &base_poly = reshape_context->base_polys[face_index];
return (base_poly.totloop == 4);
}
int multires_reshape_grid_to_ptex_index(const MultiresReshapeContext *reshape_context,

View File

@@ -54,8 +54,8 @@ static void multires_reshape_vertcos_foreach_vertex(const SubdivForeachContext *
const int face_index = multires_reshape_grid_to_face_index(reshape_context,
grid_coord.grid_index);
const MPoly *base_poly = &reshape_context->base_polys[face_index];
const int num_corners = base_poly->totloop;
const MPoly &base_poly = reshape_context->base_polys[face_index];
const int num_corners = base_poly.totloop;
const int start_grid_index = reshape_context->face_start_grid_index[face_index];
const int corner = grid_coord.grid_index - start_grid_index;

View File

@@ -644,15 +644,15 @@ static void store_grid_data(MultiresUnsubdivideContext *context,
Mesh *original_mesh = context->original_mesh;
const blender::Span<MPoly> polys = original_mesh->polys();
const blender::Span<MLoop> loops = original_mesh->loops();
const MPoly *poly = &polys[BM_elem_index_get(f)];
const MPoly &poly = polys[BM_elem_index_get(f)];
const int corner_vertex_index = BM_elem_index_get(v);
/* Calculates an offset to write the grids correctly oriented in the main
* #MultiresUnsubdivideGrid. */
int loop_offset = 0;
for (int i = 0; i < poly->totloop; i++) {
const int loop_index = poly->loopstart + i;
for (int i = 0; i < poly.totloop; i++) {
const int loop_index = poly.loopstart + i;
const MLoop *l = &loops[loop_index];
if (l->v == corner_vertex_index) {
loop_offset = i;
@@ -667,8 +667,8 @@ static void store_grid_data(MultiresUnsubdivideContext *context,
float(*face_grid)[3] = static_cast<float(*)[3]>(
MEM_calloc_arrayN(face_grid_area, sizeof(float[3]), "face_grid"));
for (int i = 0; i < poly->totloop; i++) {
const int loop_index = poly->loopstart + i;
for (int i = 0; i < poly.totloop; i++) {
const int loop_index = poly.loopstart + i;
MDisps *mdisp = &context->original_mdisp[loop_index];
int quad_loop = i - loop_offset;
if (quad_loop < 0) {
@@ -954,9 +954,9 @@ static void multires_unsubdivide_prepare_original_bmesh_for_extract(
MEM_calloc_arrayN(original_mesh->totloop, sizeof(int), "loop map"));
for (int i = 0; i < original_mesh->totpoly; i++) {
const MPoly *poly = &original_polys[i];
for (int l = 0; l < poly->totloop; l++) {
int original_loop_index = l + poly->loopstart;
const MPoly &poly = original_polys[i];
for (int l = 0; l < poly.totloop; l++) {
int original_loop_index = l + poly.loopstart;
context->loop_to_face_map[original_loop_index] = i;
}
}
@@ -972,15 +972,15 @@ static bool multires_unsubdivide_flip_grid_x_axis(const blender::Span<MPoly> pol
int loop,
int v_x)
{
const MPoly *poly = &polys[poly_index];
const MPoly &poly = polys[poly_index];
const MLoop *l_first = &loops[poly->loopstart];
if ((loop == (poly->loopstart + (poly->totloop - 1))) && l_first->v == v_x) {
const MLoop *l_first = &loops[poly.loopstart];
if ((loop == (poly.loopstart + (poly.totloop - 1))) && l_first->v == v_x) {
return true;
}
int next_l_index = loop + 1;
if (next_l_index < poly->loopstart + poly->totloop) {
if (next_l_index < poly.loopstart + poly.totloop) {
const MLoop *l_next = &loops[next_l_index];
if (l_next->v == v_x) {
return true;

View File

@@ -2015,22 +2015,22 @@ 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++) {
const MPoly *poly = &polys[i];
const MPoly &poly = polys[i];
float avg = 0;
/* mask center */
for (j = 0; j < poly->totloop; j++) {
const MLoop *l = &loops[poly->loopstart + j];
for (j = 0; j < poly.totloop; j++) {
const MLoop *l = &loops[poly.loopstart + j];
avg += paint_mask[l->v];
}
avg /= float(poly->totloop);
avg /= float(poly.totloop);
/* fill in multires mask corner */
for (j = 0; j < poly->totloop; j++) {
GridPaintMask *gpm = &gmask[poly->loopstart + j];
const MLoop *l = &loops[poly->loopstart + j];
const MLoop *prev = ME_POLY_LOOP_PREV(loops, poly, j);
const MLoop *next = ME_POLY_LOOP_NEXT(loops, poly, j);
for (j = 0; j < poly.totloop; j++) {
GridPaintMask *gpm = &gmask[poly.loopstart + j];
const MLoop *l = &loops[poly.loopstart + j];
const MLoop *prev = ME_POLY_LOOP_PREV(loops, &poly, j);
const MLoop *next = ME_POLY_LOOP_NEXT(loops, &poly, j);
gpm->data[0] = avg;
gpm->data[1] = (paint_mask[l->v] + paint_mask[next->v]) * 0.5f;

View File

@@ -1410,8 +1410,8 @@ static void pbvh_update_normals_accum_task_cb(void *__restrict userdata,
/* Face normal and mask */
if (lt->poly != mpoly_prev) {
const MPoly *poly = &pbvh->polys[lt->poly];
BKE_mesh_calc_poly_normal(poly, &pbvh->mloop[poly->loopstart], pbvh->vert_positions, fn);
const MPoly &poly = pbvh->polys[lt->poly];
BKE_mesh_calc_poly_normal(&poly, &pbvh->mloop[poly.loopstart], pbvh->vert_positions, fn);
mpoly_prev = lt->poly;
}
@@ -3713,7 +3713,7 @@ static void pbvh_face_iter_step(PBVHFaceIter *fd, bool do_step)
}
fd->last_face_index_ = face_index;
const MPoly *poly = fd->polys_ + face_index;
const MPoly &poly = fd->polys_[face_index];
fd->face.i = fd->index = face_index;
@@ -3724,15 +3724,15 @@ static void pbvh_face_iter_step(PBVHFaceIter *fd, bool do_step)
fd->hide = fd->hide_poly_ + face_index;
}
pbvh_face_iter_verts_reserve(fd, poly->totloop);
pbvh_face_iter_verts_reserve(fd, poly.totloop);
const MLoop *ml = fd->mloop_ + poly->loopstart;
const MLoop *ml = fd->mloop_ + poly.loopstart;
const int grid_area = fd->subdiv_key_.grid_area;
for (int i = 0; i < poly->totloop; i++, ml++) {
for (int i = 0; i < poly.totloop; i++, ml++) {
if (fd->pbvh_type_ == PBVH_GRIDS) {
/* Grid corners. */
fd->verts[i].i = (poly->loopstart + i) * grid_area + grid_area - 1;
fd->verts[i].i = (poly.loopstart + i) * grid_area + grid_area - 1;
}
else {
fd->verts[i].i = ml->v;

View File

@@ -1993,16 +1993,16 @@ static void adjacet_vertices_index_from_adjacent_edge(const SubdivCCG *subdiv_cc
{
const int grid_size_1 = subdiv_ccg->grid_size - 1;
const int poly_index = BKE_subdiv_ccg_grid_to_face_index(subdiv_ccg, coord->grid_index);
const MPoly *poly = &polys[poly_index];
const MPoly &poly = polys[poly_index];
*r_v1 = mloop[coord->grid_index].v;
const int corner = poly_find_loop_from_vert(poly, &mloop[poly->loopstart], *r_v1);
const int corner = poly_find_loop_from_vert(&poly, &mloop[poly.loopstart], *r_v1);
if (coord->x == grid_size_1) {
const MLoop *next = ME_POLY_LOOP_NEXT(mloop, poly, corner);
const MLoop *next = ME_POLY_LOOP_NEXT(mloop, &poly, corner);
*r_v2 = next->v;
}
if (coord->y == grid_size_1) {
const MLoop *prev = ME_POLY_LOOP_PREV(mloop, poly, corner);
const MLoop *prev = ME_POLY_LOOP_PREV(mloop, &poly, corner);
*r_v2 = prev->v;
}
}

View File

@@ -50,10 +50,10 @@ static int mask_get_grid_and_coord(SubdivCCGMaskEvaluator *mask_evaluator,
{
GridPaintMaskData *data = static_cast<GridPaintMaskData *>(mask_evaluator->user_data);
const PolyCornerIndex *poly_corner = &data->ptex_poly_corner[ptex_face_index];
const MPoly *poly = &data->polys[poly_corner->poly_index];
const int start_grid_index = poly->loopstart + poly_corner->corner;
const MPoly &poly = data->polys[poly_corner->poly_index];
const int start_grid_index = poly.loopstart + poly_corner->corner;
int corner = 0;
if (poly->totloop == 4) {
if (poly.totloop == 4) {
float corner_u, corner_v;
corner = BKE_subdiv_rotate_quad_to_corner(u, v, &corner_u, &corner_v);
*r_mask_grid = &data->grid_paint_mask[start_grid_index + corner];
@@ -105,8 +105,8 @@ static int count_num_ptex_faces(const Mesh *mesh)
int num_ptex_faces = 0;
const blender::Span<MPoly> polys = mesh->polys();
for (int poly_index = 0; poly_index < mesh->totpoly; poly_index++) {
const MPoly *poly = &polys[poly_index];
num_ptex_faces += (poly->totloop == 4) ? 1 : poly->totloop;
const MPoly &poly = polys[poly_index];
num_ptex_faces += (poly.totloop == 4) ? 1 : poly.totloop;
}
return num_ptex_faces;
}
@@ -123,14 +123,14 @@ static void mask_data_init_mapping(SubdivCCGMaskEvaluator *mask_evaluator, const
int ptex_face_index = 0;
PolyCornerIndex *ptex_poly_corner = data->ptex_poly_corner;
for (int poly_index = 0; poly_index < mesh->totpoly; poly_index++) {
const MPoly *poly = &polys[poly_index];
if (poly->totloop == 4) {
const MPoly &poly = polys[poly_index];
if (poly.totloop == 4) {
ptex_poly_corner[ptex_face_index].poly_index = poly_index;
ptex_poly_corner[ptex_face_index].corner = 0;
ptex_face_index++;
}
else {
for (int corner = 0; corner < poly->totloop; corner++) {
for (int corner = 0; corner < poly.totloop; corner++) {
ptex_poly_corner[ptex_face_index].poly_index = poly_index;
ptex_poly_corner[ptex_face_index].corner = corner;
ptex_face_index++;

View File

@@ -24,9 +24,9 @@ static DMFlagMat subdiv_ccg_material_flags_eval(
{
CCGMaterialFromMeshData *data = (CCGMaterialFromMeshData *)material_flags_evaluator->user_data;
BLI_assert(coarse_face_index < data->mesh->totpoly);
const MPoly *poly = &data->polys[coarse_face_index];
const MPoly &poly = data->polys[coarse_face_index];
DMFlagMat material_flags;
material_flags.flag = poly->flag;
material_flags.flag = poly.flag;
material_flags.mat_nr = data->material_indices ? data->material_indices[coarse_face_index] : 0;
return material_flags;
}

View File

@@ -134,11 +134,11 @@ static void get_face_vertices(const OpenSubdiv_Converter *converter,
int *manifold_face_vertices)
{
ConverterStorage *storage = static_cast<ConverterStorage *>(converter->user_data);
const MPoly *poly = &storage->polys[manifold_face_index];
const MPoly &poly = storage->polys[manifold_face_index];
const blender::Span<MLoop> loops = storage->loops;
for (int corner = 0; corner < poly->totloop; corner++) {
for (int corner = 0; corner < poly.totloop; corner++) {
manifold_face_vertices[corner] =
storage->manifold_vertex_index[loops[poly->loopstart + corner].v];
storage->manifold_vertex_index[loops[poly.loopstart + corner].v];
}
}
@@ -231,8 +231,8 @@ static void precalc_uv_layer(const OpenSubdiv_Converter *converter, const int la
if (uv_vert->separate) {
storage->num_uv_coordinates++;
}
const MPoly *poly = &storage->polys[uv_vert->poly_index];
const int global_loop_index = poly->loopstart + uv_vert->loop_of_poly_index;
const MPoly &poly = storage->polys[uv_vert->poly_index];
const int global_loop_index = poly.loopstart + uv_vert->loop_of_poly_index;
storage->loop_uv_indices[global_loop_index] = storage->num_uv_coordinates;
uv_vert = uv_vert->next;
}
@@ -259,8 +259,8 @@ static int get_face_corner_uv_index(const OpenSubdiv_Converter *converter,
const int corner)
{
ConverterStorage *storage = static_cast<ConverterStorage *>(converter->user_data);
const MPoly *poly = &storage->polys[face_index];
return storage->loop_uv_indices[poly->loopstart + corner];
const MPoly &poly = storage->polys[face_index];
return storage->loop_uv_indices[poly.loopstart + corner];
}
static void free_user_data(const OpenSubdiv_Converter *converter)
@@ -361,9 +361,9 @@ static void initialize_manifold_indices(ConverterStorage *storage)
BLI_bitmap *vert_used_map = BLI_BITMAP_NEW(mesh->totvert, "vert used map");
BLI_bitmap *edge_used_map = BLI_BITMAP_NEW(mesh->totedge, "edge used map");
for (int poly_index = 0; poly_index < mesh->totpoly; poly_index++) {
const MPoly *poly = &polys[poly_index];
for (int corner = 0; corner < poly->totloop; corner++) {
const MLoop *loop = &loops[poly->loopstart + corner];
const MPoly &poly = polys[poly_index];
for (int corner = 0; corner < poly.totloop; corner++) {
const MLoop *loop = &loops[poly.loopstart + corner];
BLI_BITMAP_ENABLE(vert_used_map, loop->v);
BLI_BITMAP_ENABLE(edge_used_map, loop->e);
}

View File

@@ -71,10 +71,10 @@ static int displacement_get_grid_and_coord(SubdivDisplacement *displacement,
MultiresDisplacementData *data = static_cast<MultiresDisplacementData *>(
displacement->user_data);
const PolyCornerIndex *poly_corner = &data->ptex_poly_corner[ptex_face_index];
const MPoly *poly = &data->polys[poly_corner->poly_index];
const int start_grid_index = poly->loopstart + poly_corner->corner;
const MPoly &poly = data->polys[poly_corner->poly_index];
const int start_grid_index = poly.loopstart + poly_corner->corner;
int corner = 0;
if (poly->totloop == 4) {
if (poly.totloop == 4) {
float corner_u, corner_v;
corner = BKE_subdiv_rotate_quad_to_corner(u, v, &corner_u, &corner_v);
*r_displacement_grid = &data->mdisps[start_grid_index + corner];
@@ -95,10 +95,10 @@ static const MDisps *displacement_get_other_grid(SubdivDisplacement *displacemen
MultiresDisplacementData *data = static_cast<MultiresDisplacementData *>(
displacement->user_data);
const PolyCornerIndex *poly_corner = &data->ptex_poly_corner[ptex_face_index];
const MPoly *poly = &data->polys[poly_corner->poly_index];
const int effective_corner = (poly->totloop == 4) ? corner : poly_corner->corner;
const int next_corner = (effective_corner + corner_delta + poly->totloop) % poly->totloop;
return &data->mdisps[poly->loopstart + next_corner];
const MPoly &poly = data->polys[poly_corner->poly_index];
const int effective_corner = (poly.totloop == 4) ? corner : poly_corner->corner;
const int next_corner = (effective_corner + corner_delta + poly.totloop) % poly.totloop;
return &data->mdisps[poly.loopstart + next_corner];
}
BLI_INLINE eAverageWith read_displacement_grid(const MDisps *displacement_grid,
@@ -126,14 +126,14 @@ BLI_INLINE eAverageWith read_displacement_grid(const MDisps *displacement_grid,
return AVERAGE_WITH_NONE;
}
static void average_convert_grid_coord_to_ptex(const MPoly *poly,
static void average_convert_grid_coord_to_ptex(const MPoly &poly,
const int corner,
const float grid_u,
const float grid_v,
float *r_ptex_face_u,
float *r_ptex_face_v)
{
if (poly->totloop == 4) {
if (poly.totloop == 4) {
BKE_subdiv_rotate_grid_to_quad(corner, grid_u, grid_v, r_ptex_face_u, r_ptex_face_v);
}
else {
@@ -142,14 +142,14 @@ static void average_convert_grid_coord_to_ptex(const MPoly *poly,
}
static void average_construct_tangent_matrix(Subdiv *subdiv,
const MPoly *poly,
const MPoly &poly,
const int ptex_face_index,
const int corner,
const float u,
const float v,
float r_tangent_matrix[3][3])
{
const bool is_quad = (poly->totloop == 4);
const bool is_quad = (poly.totloop == 4);
const int quad_corner = is_quad ? corner : 0;
float dummy_P[3], dPdu[3], dPdv[3];
BKE_subdiv_eval_limit_point_and_derivatives(subdiv, ptex_face_index, u, v, dummy_P, dPdu, dPdv);
@@ -174,7 +174,7 @@ static void average_read_displacement_object(MultiresDisplacementData *data,
float r_D[3])
{
const PolyCornerIndex *poly_corner = &data->ptex_poly_corner[ptex_face_index];
const MPoly *poly = &data->polys[poly_corner->poly_index];
const MPoly &poly = data->polys[poly_corner->poly_index];
/* Get (u, v) coordinate within the other ptex face which corresponds to
* the grid coordinates. */
float u, v;
@@ -199,11 +199,10 @@ static void average_get_other_ptex_and_corner(MultiresDisplacementData *data,
int *r_other_corner_index)
{
const PolyCornerIndex *poly_corner = &data->ptex_poly_corner[ptex_face_index];
const MPoly *poly = &data->polys[poly_corner->poly_index];
const int num_corners = poly->totloop;
const MPoly &poly = data->polys[poly_corner->poly_index];
const int num_corners = poly.totloop;
const bool is_quad = (num_corners == 4);
const int poly_index = poly - data->polys.data();
const int start_ptex_face_index = data->face_ptex_offset[poly_index];
const int start_ptex_face_index = data->face_ptex_offset[poly_corner->poly_index];
*r_other_corner_index = (corner + corner_delta + num_corners) % num_corners;
*r_other_ptex_face_index = is_quad ? start_ptex_face_index :
start_ptex_face_index + *r_other_corner_index;
@@ -249,8 +248,8 @@ static void average_with_all(SubdivDisplacement *displacement,
MultiresDisplacementData *data = static_cast<MultiresDisplacementData *>(
displacement->user_data);
const PolyCornerIndex *poly_corner = &data->ptex_poly_corner[ptex_face_index];
const MPoly *poly = &data->polys[poly_corner->poly_index];
const int num_corners = poly->totloop;
const MPoly &poly = data->polys[poly_corner->poly_index];
const int num_corners = poly.totloop;
for (int corner_delta = 1; corner_delta < num_corners; corner_delta++) {
average_with_other(displacement, ptex_face_index, corner, 0.0f, 0.0f, corner_delta, r_D);
}
@@ -305,8 +304,8 @@ static int displacement_get_face_corner(MultiresDisplacementData *data,
const float v)
{
const PolyCornerIndex *poly_corner = &data->ptex_poly_corner[ptex_face_index];
const MPoly *poly = &data->polys[poly_corner->poly_index];
const int num_corners = poly->totloop;
const MPoly &poly = data->polys[poly_corner->poly_index];
const int num_corners = poly.totloop;
const bool is_quad = (num_corners == 4);
if (is_quad) {
float dummy_corner_u, dummy_corner_v;
@@ -370,8 +369,8 @@ static int count_num_ptex_faces(const Mesh *mesh)
int num_ptex_faces = 0;
const blender::Span<MPoly> polys = mesh->polys();
for (int poly_index = 0; poly_index < mesh->totpoly; poly_index++) {
const MPoly *poly = &polys[poly_index];
num_ptex_faces += (poly->totloop == 4) ? 1 : poly->totloop;
const MPoly &poly = polys[poly_index];
num_ptex_faces += (poly.totloop == 4) ? 1 : poly.totloop;
}
return num_ptex_faces;
}
@@ -389,14 +388,14 @@ static void displacement_data_init_mapping(SubdivDisplacement *displacement, con
int ptex_face_index = 0;
PolyCornerIndex *ptex_poly_corner = data->ptex_poly_corner;
for (int poly_index = 0; poly_index < mesh->totpoly; poly_index++) {
const MPoly *poly = &polys[poly_index];
if (poly->totloop == 4) {
const MPoly &poly = polys[poly_index];
if (poly.totloop == 4) {
ptex_poly_corner[ptex_face_index].poly_index = poly_index;
ptex_poly_corner[ptex_face_index].corner = 0;
ptex_face_index++;
}
else {
for (int corner = 0; corner < poly->totloop; corner++) {
for (int corner = 0; corner < poly.totloop; corner++) {
ptex_poly_corner[ptex_face_index].poly_index = poly_index;
ptex_poly_corner[ptex_face_index].corner = corner;
ptex_face_index++;

View File

@@ -90,9 +90,9 @@ static void set_coarse_positions(Subdiv *subdiv,
* OpenSubdiv's vertices match mesh ones? */
BLI_bitmap *vertex_used_map = BLI_BITMAP_NEW(mesh->totvert, "vert used map");
for (int poly_index = 0; poly_index < mesh->totpoly; poly_index++) {
const MPoly *poly = &polys[poly_index];
for (int corner = 0; corner < poly->totloop; corner++) {
const MLoop *loop = &loops[poly->loopstart + corner];
const MPoly &poly = polys[poly_index];
for (int corner = 0; corner < poly.totloop; corner++) {
const MLoop *loop = &loops[poly.loopstart + corner];
BLI_BITMAP_ENABLE(vertex_used_map, loop->v);
}
}
@@ -139,8 +139,8 @@ static void set_face_varying_data_from_uv_task(void *__restrict userdata,
FaceVaryingDataFromUVContext *ctx = static_cast<FaceVaryingDataFromUVContext *>(userdata);
OpenSubdiv_TopologyRefiner *topology_refiner = ctx->topology_refiner;
const int layer_index = ctx->layer_index;
const MPoly *poly = &ctx->polys[face_index];
const float(*mluv)[2] = &ctx->mloopuv[poly->loopstart];
const MPoly &poly = ctx->polys[face_index];
const float(*mluv)[2] = &ctx->mloopuv[poly.loopstart];
/* TODO(sergey): OpenSubdiv's C-API converter can change winding of
* loops of a face, need to watch for that, to prevent wrong UVs assigned.

View File

@@ -29,9 +29,9 @@
* \{ */
/* Number of ptex faces for a given polygon. */
BLI_INLINE int num_ptex_faces_per_poly_get(const MPoly *poly)
BLI_INLINE int num_ptex_faces_per_poly_get(const MPoly &poly)
{
return (poly->totloop == 4) ? 1 : poly->totloop;
return (poly.totloop == 4) ? 1 : poly.totloop;
}
BLI_INLINE int num_edges_per_ptex_face_get(const int resolution)
@@ -54,9 +54,9 @@ BLI_INLINE int num_polys_per_ptex_get(const int resolution)
}
/* Subdivision resolution per given polygon's ptex faces. */
BLI_INLINE int ptex_face_resolution_get(const MPoly *poly, int resolution)
BLI_INLINE int ptex_face_resolution_get(const MPoly &poly, int resolution)
{
return (poly->totloop == 4) ? (resolution) : ((resolution >> 1) + 1);
return (poly.totloop == 4) ? (resolution) : ((resolution >> 1) + 1);
}
/** \} */
@@ -165,7 +165,7 @@ static void subdiv_foreach_ctx_count(SubdivForeachTaskContext *ctx)
ctx->num_subdiv_edges = coarse_mesh->totedge * (num_subdiv_vertices_per_coarse_edge + 1);
/* Calculate extra vertices and edges created by non-loose geometry. */
for (int poly_index = 0; poly_index < coarse_mesh->totpoly; poly_index++) {
const MPoly *coarse_poly = &ctx->coarse_polys[poly_index];
const MPoly &coarse_poly = ctx->coarse_polys[poly_index];
const int num_ptex_faces_per_poly = num_ptex_faces_per_poly_get(coarse_poly);
/* Inner vertices of polygon. */
if (num_ptex_faces_per_poly == 1) {
@@ -182,7 +182,7 @@ static void subdiv_foreach_ctx_count(SubdivForeachTaskContext *ctx)
(no_quad_patch_resolution - 2) +
num_subdiv_vertices_per_coarse_edge);
if (no_quad_patch_resolution >= 3) {
ctx->num_subdiv_edges += coarse_poly->totloop;
ctx->num_subdiv_edges += coarse_poly.totloop;
}
ctx->num_subdiv_polygons += num_ptex_faces_per_poly *
num_polys_per_ptex_get(no_quad_patch_resolution);
@@ -219,7 +219,7 @@ static void subdiv_foreach_ctx_init_offsets(SubdivForeachTaskContext *ctx)
int edge_offset = 0;
int polygon_offset = 0;
for (int poly_index = 0; poly_index < coarse_mesh->totpoly; poly_index++) {
const MPoly *coarse_poly = &ctx->coarse_polys[poly_index];
const MPoly &coarse_poly = ctx->coarse_polys[poly_index];
const int num_ptex_faces_per_poly = num_ptex_faces_per_poly_get(coarse_poly);
ctx->subdiv_vertex_offset[poly_index] = vertex_offset;
ctx->subdiv_edge_offset[poly_index] = edge_offset;
@@ -236,7 +236,7 @@ static void subdiv_foreach_ctx_init_offsets(SubdivForeachTaskContext *ctx)
(num_inner_edges_per_ptex_face_get(no_quad_patch_resolution - 1) +
(no_quad_patch_resolution - 2) + num_subdiv_vertices_per_coarse_edge);
if (no_quad_patch_resolution >= 3) {
edge_offset += coarse_poly->totloop;
edge_offset += coarse_poly.totloop;
}
polygon_offset += num_ptex_faces_per_poly * num_polys_per_ptex_get(no_quad_patch_resolution);
}
@@ -391,12 +391,12 @@ static void subdiv_foreach_every_corner_vertices(SubdivForeachTaskContext *ctx,
}
const Mesh *coarse_mesh = ctx->coarse_mesh;
for (int poly_index = 0; poly_index < coarse_mesh->totpoly; poly_index++) {
const MPoly *coarse_poly = &ctx->coarse_polys[poly_index];
if (coarse_poly->totloop == 4) {
subdiv_foreach_every_corner_vertices_regular(ctx, tls, coarse_poly);
const MPoly &coarse_poly = ctx->coarse_polys[poly_index];
if (coarse_poly.totloop == 4) {
subdiv_foreach_every_corner_vertices_regular(ctx, tls, &coarse_poly);
}
else {
subdiv_foreach_every_corner_vertices_special(ctx, tls, coarse_poly);
subdiv_foreach_every_corner_vertices_special(ctx, tls, &coarse_poly);
}
}
}
@@ -568,12 +568,12 @@ static void subdiv_foreach_every_edge_vertices(SubdivForeachTaskContext *ctx, vo
}
const Mesh *coarse_mesh = ctx->coarse_mesh;
for (int poly_index = 0; poly_index < coarse_mesh->totpoly; poly_index++) {
const MPoly *coarse_poly = &ctx->coarse_polys[poly_index];
if (coarse_poly->totloop == 4) {
subdiv_foreach_every_edge_vertices_regular(ctx, tls, coarse_poly);
const MPoly &coarse_poly = ctx->coarse_polys[poly_index];
if (coarse_poly.totloop == 4) {
subdiv_foreach_every_edge_vertices_regular(ctx, tls, &coarse_poly);
}
else {
subdiv_foreach_every_edge_vertices_special(ctx, tls, coarse_poly);
subdiv_foreach_every_edge_vertices_special(ctx, tls, &coarse_poly);
}
}
}
@@ -611,7 +611,7 @@ static void subdiv_foreach_inner_vertices_special(SubdivForeachTaskContext *ctx,
const MPoly *coarse_poly)
{
const int resolution = ctx->settings->resolution;
const int ptex_face_resolution = ptex_face_resolution_get(coarse_poly, resolution);
const int ptex_face_resolution = ptex_face_resolution_get(*coarse_poly, resolution);
const float inv_ptex_face_resolution_1 = 1.0f / float(ptex_face_resolution - 1);
const int coarse_poly_index = coarse_poly - ctx->coarse_polys.data();
int ptex_face_index = ctx->face_ptex_offset[coarse_poly_index];
@@ -819,7 +819,7 @@ static void subdiv_foreach_edges_all_patches_special(SubdivForeachTaskContext *c
{
const int poly_index = coarse_poly - ctx->coarse_polys.data();
const int resolution = ctx->settings->resolution;
const int ptex_face_resolution = ptex_face_resolution_get(coarse_poly, resolution);
const int ptex_face_resolution = ptex_face_resolution_get(*coarse_poly, resolution);
const int ptex_face_inner_resolution = ptex_face_resolution - 2;
const int num_inner_vertices_per_ptex = (ptex_face_resolution - 1) * (ptex_face_resolution - 2);
const int num_subdiv_vertices_per_coarse_edge = resolution - 2;
@@ -1079,7 +1079,7 @@ static void subdiv_foreach_loops_regular(SubdivForeachTaskContext *ctx,
const int resolution = ctx->settings->resolution;
/* Base/coarse mesh information. */
const int coarse_poly_index = coarse_poly - ctx->coarse_polys.data();
const int ptex_resolution = ptex_face_resolution_get(coarse_poly, resolution);
const int ptex_resolution = ptex_face_resolution_get(*coarse_poly, resolution);
const int ptex_inner_resolution = ptex_resolution - 2;
const int num_subdiv_edges_per_coarse_edge = resolution - 1;
const int num_subdiv_vertices_per_coarse_edge = resolution - 2;
@@ -1270,7 +1270,7 @@ static void subdiv_foreach_loops_special(SubdivForeachTaskContext *ctx,
const int resolution = ctx->settings->resolution;
/* Base/coarse mesh information. */
const int coarse_poly_index = coarse_poly - ctx->coarse_polys.data();
const int ptex_face_resolution = ptex_face_resolution_get(coarse_poly, resolution);
const int ptex_face_resolution = ptex_face_resolution_get(*coarse_poly, resolution);
const int ptex_face_inner_resolution = ptex_face_resolution - 2;
const float inv_ptex_resolution_1 = 1.0f / float(ptex_face_resolution - 1);
const int num_inner_vertices_per_ptex = (ptex_face_resolution - 1) * (ptex_face_resolution - 2);
@@ -1601,12 +1601,12 @@ static void subdiv_foreach_loops_special(SubdivForeachTaskContext *ctx,
static void subdiv_foreach_loops(SubdivForeachTaskContext *ctx, void *tls, int poly_index)
{
const MPoly *coarse_poly = &ctx->coarse_polys[poly_index];
if (coarse_poly->totloop == 4) {
subdiv_foreach_loops_regular(ctx, tls, coarse_poly);
const MPoly &coarse_poly = ctx->coarse_polys[poly_index];
if (coarse_poly.totloop == 4) {
subdiv_foreach_loops_regular(ctx, tls, &coarse_poly);
}
else {
subdiv_foreach_loops_special(ctx, tls, coarse_poly);
subdiv_foreach_loops_special(ctx, tls, &coarse_poly);
}
}
@@ -1621,7 +1621,7 @@ static void subdiv_foreach_polys(SubdivForeachTaskContext *ctx, void *tls, int p
const int resolution = ctx->settings->resolution;
const int start_poly_index = ctx->subdiv_polygon_offset[poly_index];
/* Base/coarse mesh information. */
const MPoly *coarse_poly = &ctx->coarse_polys[poly_index];
const MPoly &coarse_poly = ctx->coarse_polys[poly_index];
const int num_ptex_faces_per_poly = num_ptex_faces_per_poly_get(coarse_poly);
const int ptex_resolution = ptex_face_resolution_get(coarse_poly, resolution);
const int num_polys_per_ptex = num_polys_per_ptex_get(ptex_resolution);
@@ -1712,9 +1712,9 @@ static void subdiv_foreach_single_geometry_vertices(SubdivForeachTaskContext *ct
}
const Mesh *coarse_mesh = ctx->coarse_mesh;
for (int poly_index = 0; poly_index < coarse_mesh->totpoly; poly_index++) {
const MPoly *coarse_poly = &ctx->coarse_polys[poly_index];
subdiv_foreach_corner_vertices(ctx, tls, coarse_poly);
subdiv_foreach_edge_vertices(ctx, tls, coarse_poly);
const MPoly &coarse_poly = ctx->coarse_polys[poly_index];
subdiv_foreach_corner_vertices(ctx, tls, &coarse_poly);
subdiv_foreach_edge_vertices(ctx, tls, &coarse_poly);
}
}
@@ -1722,9 +1722,9 @@ static void subdiv_foreach_mark_non_loose_geometry(SubdivForeachTaskContext *ctx
{
const Mesh *coarse_mesh = ctx->coarse_mesh;
for (int poly_index = 0; poly_index < coarse_mesh->totpoly; poly_index++) {
const MPoly *coarse_poly = &ctx->coarse_polys[poly_index];
for (int corner = 0; corner < coarse_poly->totloop; corner++) {
const MLoop *loop = &ctx->coarse_loops[coarse_poly->loopstart + corner];
const MPoly &coarse_poly = ctx->coarse_polys[poly_index];
for (int corner = 0; corner < coarse_poly.totloop; corner++) {
const MLoop *loop = &ctx->coarse_loops[coarse_poly.loopstart + corner];
BLI_BITMAP_ENABLE(ctx->coarse_edges_used_map, loop->e);
BLI_BITMAP_ENABLE(ctx->coarse_vertices_used_map, loop->v);
}

View File

@@ -203,16 +203,16 @@ struct VerticesForInterpolation {
static void vertex_interpolation_init(const SubdivMeshContext *ctx,
VerticesForInterpolation *vertex_interpolation,
const MPoly *coarse_poly)
const MPoly &coarse_poly)
{
const Mesh *coarse_mesh = ctx->coarse_mesh;
const blender::Span<MLoop> coarse_loops = ctx->coarse_loops;
if (coarse_poly->totloop == 4) {
if (coarse_poly.totloop == 4) {
vertex_interpolation->vertex_data = &coarse_mesh->vdata;
vertex_interpolation->vertex_indices[0] = coarse_loops[coarse_poly->loopstart + 0].v;
vertex_interpolation->vertex_indices[1] = coarse_loops[coarse_poly->loopstart + 1].v;
vertex_interpolation->vertex_indices[2] = coarse_loops[coarse_poly->loopstart + 2].v;
vertex_interpolation->vertex_indices[3] = coarse_loops[coarse_poly->loopstart + 3].v;
vertex_interpolation->vertex_indices[0] = coarse_loops[coarse_poly.loopstart + 0].v;
vertex_interpolation->vertex_indices[1] = coarse_loops[coarse_poly.loopstart + 1].v;
vertex_interpolation->vertex_indices[2] = coarse_loops[coarse_poly.loopstart + 2].v;
vertex_interpolation->vertex_indices[3] = coarse_loops[coarse_poly.loopstart + 3].v;
vertex_interpolation->vertex_data_storage_allocated = false;
}
else {
@@ -231,19 +231,19 @@ static void vertex_interpolation_init(const SubdivMeshContext *ctx,
vertex_interpolation->vertex_data_storage_allocated = true;
/* Interpolate center of poly right away, it stays unchanged for all
* ptex faces. */
const float weight = 1.0f / float(coarse_poly->totloop);
blender::Array<float, 32> weights(coarse_poly->totloop);
blender::Array<int, 32> indices(coarse_poly->totloop);
for (int i = 0; i < coarse_poly->totloop; i++) {
const float weight = 1.0f / float(coarse_poly.totloop);
blender::Array<float, 32> weights(coarse_poly.totloop);
blender::Array<int, 32> indices(coarse_poly.totloop);
for (int i = 0; i < coarse_poly.totloop; i++) {
weights[i] = weight;
indices[i] = coarse_loops[coarse_poly->loopstart + i].v;
indices[i] = coarse_loops[coarse_poly.loopstart + i].v;
}
CustomData_interp(&coarse_mesh->vdata,
&vertex_interpolation->vertex_data_storage,
indices.data(),
weights.data(),
nullptr,
coarse_poly->totloop,
coarse_poly.totloop,
2);
}
}
@@ -705,7 +705,7 @@ static void subdiv_mesh_ensure_vertex_interpolation(SubdivMeshContext *ctx,
}
/* Initialize the interpolation. */
if (!tls->vertex_interpolation_initialized) {
vertex_interpolation_init(ctx, &tls->vertex_interpolation, coarse_poly);
vertex_interpolation_init(ctx, &tls->vertex_interpolation, *coarse_poly);
}
/* Update it for a new corner if needed. */
if (!tls->vertex_interpolation_initialized ||
@@ -730,15 +730,15 @@ static void subdiv_mesh_vertex_edge(const SubdivForeachContext *foreach_context,
{
SubdivMeshContext *ctx = static_cast<SubdivMeshContext *>(foreach_context->user_data);
SubdivMeshTLS *tls = static_cast<SubdivMeshTLS *>(tls_v);
const MPoly *coarse_poly = &ctx->coarse_polys[coarse_poly_index];
subdiv_mesh_ensure_vertex_interpolation(ctx, tls, coarse_poly, coarse_corner);
const MPoly &coarse_poly = ctx->coarse_polys[coarse_poly_index];
subdiv_mesh_ensure_vertex_interpolation(ctx, tls, &coarse_poly, coarse_corner);
evaluate_vertex_and_apply_displacement_interpolate(
ctx, ptex_face_index, u, v, &tls->vertex_interpolation, subdiv_vertex_index);
}
static bool subdiv_mesh_is_center_vertex(const MPoly *coarse_poly, const float u, const float v)
static bool subdiv_mesh_is_center_vertex(const MPoly &coarse_poly, const float u, const float v)
{
if (coarse_poly->totloop == 4) {
if (coarse_poly.totloop == 4) {
if (u == 0.5f && v == 0.5f) {
return true;
}
@@ -751,7 +751,7 @@ static bool subdiv_mesh_is_center_vertex(const MPoly *coarse_poly, const float u
return false;
}
static void subdiv_mesh_tag_center_vertex(const MPoly *coarse_poly,
static void subdiv_mesh_tag_center_vertex(const MPoly &coarse_poly,
const int subdiv_vertex_index,
const float u,
const float v,
@@ -774,10 +774,10 @@ static void subdiv_mesh_vertex_inner(const SubdivForeachContext *foreach_context
SubdivMeshContext *ctx = static_cast<SubdivMeshContext *>(foreach_context->user_data);
SubdivMeshTLS *tls = static_cast<SubdivMeshTLS *>(tls_v);
Subdiv *subdiv = ctx->subdiv;
const MPoly *coarse_poly = &ctx->coarse_polys[coarse_poly_index];
const MPoly &coarse_poly = ctx->coarse_polys[coarse_poly_index];
Mesh *subdiv_mesh = ctx->subdiv_mesh;
float3 &subdiv_position = ctx->subdiv_positions[subdiv_vertex_index];
subdiv_mesh_ensure_vertex_interpolation(ctx, tls, coarse_poly, coarse_corner);
subdiv_mesh_ensure_vertex_interpolation(ctx, tls, &coarse_poly, coarse_corner);
subdiv_vertex_data_interpolate(ctx, subdiv_vertex_index, &tls->vertex_interpolation, u, v);
BKE_subdiv_eval_final_point(subdiv, ptex_face_index, u, v, subdiv_position);
subdiv_mesh_tag_center_vertex(coarse_poly, subdiv_vertex_index, u, v, subdiv_mesh);
@@ -904,9 +904,9 @@ static void subdiv_mesh_loop(const SubdivForeachContext *foreach_context,
{
SubdivMeshContext *ctx = static_cast<SubdivMeshContext *>(foreach_context->user_data);
SubdivMeshTLS *tls = static_cast<SubdivMeshTLS *>(tls_v);
const MPoly *coarse_poly = &ctx->coarse_polys[coarse_poly_index];
const MPoly &coarse_poly = ctx->coarse_polys[coarse_poly_index];
MLoop *subdiv_loop = &ctx->subdiv_loops[subdiv_loop_index];
subdiv_mesh_ensure_loop_interpolation(ctx, tls, coarse_poly, coarse_corner);
subdiv_mesh_ensure_loop_interpolation(ctx, tls, &coarse_poly, coarse_corner);
subdiv_interpolate_loop_data(ctx, subdiv_loop, &tls->loop_interpolation, u, v);
subdiv_eval_uv_layer(ctx, subdiv_loop, ptex_face_index, u, v);
subdiv_loop->v = subdiv_vertex_index;
@@ -920,13 +920,11 @@ static void subdiv_mesh_loop(const SubdivForeachContext *foreach_context,
* \{ */
static void subdiv_copy_poly_data(const SubdivMeshContext *ctx,
MPoly *subdiv_poly,
const MPoly *coarse_poly)
const int subdiv_poly,
const int coarse_poly)
{
const int coarse_poly_index = coarse_poly - ctx->coarse_polys.data();
const int subdiv_poly_index = subdiv_poly - ctx->subdiv_polys.data();
CustomData_copy_data(
&ctx->coarse_mesh->pdata, &ctx->subdiv_mesh->pdata, coarse_poly_index, subdiv_poly_index, 1);
&ctx->coarse_mesh->pdata, &ctx->subdiv_mesh->pdata, coarse_poly, subdiv_poly, 1);
}
static void subdiv_mesh_poly(const SubdivForeachContext *foreach_context,
@@ -938,11 +936,9 @@ static void subdiv_mesh_poly(const SubdivForeachContext *foreach_context,
{
BLI_assert(coarse_poly_index != ORIGINDEX_NONE);
SubdivMeshContext *ctx = static_cast<SubdivMeshContext *>(foreach_context->user_data);
const MPoly *coarse_poly = &ctx->coarse_polys[coarse_poly_index];
MPoly *subdiv_poly = &ctx->subdiv_polys[subdiv_poly_index];
subdiv_copy_poly_data(ctx, subdiv_poly, coarse_poly);
subdiv_poly->loopstart = start_loop_index;
subdiv_poly->totloop = num_loops;
subdiv_copy_poly_data(ctx, subdiv_poly_index, coarse_poly_index);
ctx->subdiv_polys[subdiv_poly_index].loopstart = start_loop_index;
ctx->subdiv_polys[subdiv_poly_index].totloop = num_loops;
}
/** \} */

View File

@@ -228,7 +228,7 @@ static int getFaceIndex(
}
static void get_face_uv_map_vert(
UvVertMap *vmap, MPoly *polys, MLoop *ml, int fi, CCGVertHDL *fverts)
UvVertMap *vmap, const MPoly *polys, MLoop *ml, int fi, CCGVertHDL *fverts)
{
UvMapVert *v, *nv;
int j, nverts = polys[fi].totloop;
@@ -308,12 +308,12 @@ static int ss_sync_from_uv(CCGSubSurf *ss,
eset = BLI_edgeset_new_ex(__func__, BLI_EDGEHASH_SIZE_GUESS_FROM_POLYS(totface));
for (i = 0; i < totface; i++) {
MPoly *poly = &polys[i];
int nverts = poly->totloop;
const MPoly &poly = polys[i];
int nverts = poly.totloop;
int j, j_next;
CCGFace *origf = ccgSubSurf_getFace(origss, POINTER_FROM_INT(i));
// uint *fv = &poly->v1;
MLoop *ml = mloop + poly->loopstart;
// uint *fv = &poly.v1;
MLoop *ml = mloop + poly.loopstart;
fverts.reinitialize(nverts);
@@ -325,7 +325,7 @@ static int ss_sync_from_uv(CCGSubSurf *ss,
if (BLI_edgeset_add(eset, v0, v1)) {
CCGEdge *e, *orige = ccgSubSurf_getFaceEdge(origf, j_next);
CCGEdgeHDL ehdl = POINTER_FROM_INT(poly->loopstart + j_next);
CCGEdgeHDL ehdl = POINTER_FROM_INT(poly.loopstart + j_next);
float crease = ccgSubSurf_getEdgeCrease(orige);
ccgSubSurf_syncEdge(ss, ehdl, fverts[j_next], fverts[j], crease, &e);
@@ -337,9 +337,9 @@ static int ss_sync_from_uv(CCGSubSurf *ss,
/* create faces */
for (i = 0; i < totface; i++) {
MPoly *poly = &polys[i];
MLoop *ml = &mloop[poly->loopstart];
int nverts = poly->totloop;
const MPoly &poly = polys[i];
MLoop *ml = &mloop[poly.loopstart];
int nverts = poly.totloop;
CCGFace *f;
fverts.reinitialize(nverts);
@@ -1079,11 +1079,9 @@ static void ccgDM_copyFinalPolyArray(DerivedMesh *dm, MPoly *polys)
for (S = 0; S < numVerts; S++) {
for (y = 0; y < gridSize - 1; y++) {
for (x = 0; x < gridSize - 1; x++) {
MPoly *poly = &polys[i];
poly->flag = flag;
poly->loopstart = k;
poly->totloop = 4;
polys[i].loopstart = k;
polys[i].totloop = 4;
polys[i].flag = flag;
k += 4;
i++;

View File

@@ -885,8 +885,8 @@ void mesh_buffer_cache_create_requested_subdiv(MeshBatchCache *cache,
/* Multiply by 4 to have the start index of the quad's loop, as subdiv_loop_poly_index is
* based on the subdivision loops. */
const int poly_origindex = subdiv_loop_poly_index[i * 4];
const MPoly *poly = &mr->polys[poly_origindex];
extractor->iter_subdiv_mesh(subdiv_cache, mr, data, i, poly);
const MPoly &poly = mr->polys[poly_origindex];
extractor->iter_subdiv_mesh(subdiv_cache, mr, data, i, &poly);
}
}
}

View File

@@ -237,10 +237,10 @@ static void mesh_render_data_polys_sorted_build(MeshRenderData *mr, MeshBufferCa
else {
for (int i = 0; i < mr->poly_len; i++) {
if (!(mr->use_hide && mr->hide_poly && mr->hide_poly[i])) {
const MPoly *poly = &mr->polys[i];
const MPoly &poly = mr->polys[i];
const int mat = min_ii(mr->material_indices ? mr->material_indices[i] : 0, mat_last);
tri_first_index[i] = mat_tri_offs[mat];
mat_tri_offs[mat] += poly->totloop - 2;
mat_tri_offs[mat] += poly.totloop - 2;
}
else {
tri_first_index[i] = -1;
@@ -275,10 +275,10 @@ static void mesh_render_data_mat_tri_len_mesh_range_fn(void *__restrict userdata
MeshRenderData *mr = static_cast<MeshRenderData *>(userdata);
int *mat_tri_len = static_cast<int *>(tls->userdata_chunk);
const MPoly *poly = &mr->polys[iter];
const MPoly &poly = mr->polys[iter];
if (!(mr->use_hide && mr->hide_poly && mr->hide_poly[iter])) {
int mat = min_ii(mr->material_indices ? mr->material_indices[iter] : 0, mr->mat_len - 1);
mat_tri_len[mat] += poly->totloop - 2;
mat_tri_len[mat] += poly.totloop - 2;
}
}

View File

@@ -339,15 +339,14 @@ struct PBVHBatches {
bool smooth = false;
foreach_faces([&](int /*buffer_i*/, int /*tri_i*/, int vertex_i, const MLoopTri *tri) {
const MPoly *poly = args->polys + tri->poly;
if (tri->poly != last_poly) {
last_poly = tri->poly;
if (!(poly->flag & ME_SMOOTH)) {
const MPoly &poly = args->polys[tri->poly];
if (!(poly.flag & ME_SMOOTH)) {
smooth = true;
BKE_mesh_calc_poly_normal(
poly, args->mloop + poly->loopstart, args->vert_positions, fno);
&poly, args->mloop + poly.loopstart, args->vert_positions, fno);
normal_float_to_short_v3(no, fno);
}
else {

View File

@@ -88,8 +88,8 @@ static void extract_sculpt_data_init(const MeshRenderData *mr,
else {
int mp_loop = 0;
for (int poly_index = 0; poly_index < mr->poly_len; poly_index++) {
const MPoly *poly = &mr->polys[poly_index];
for (int l = 0; l < poly->totloop; l++) {
const MPoly &poly = mr->polys[poly_index];
for (int l = 0; l < poly.totloop; l++) {
float v_mask = 0.0f;
if (cd_mask) {
v_mask = cd_mask[loops[mp_loop].v];
@@ -143,9 +143,9 @@ static void extract_sculpt_data_init_subdiv(const DRWSubdivCache *subdiv_cache,
float *v_mask = static_cast<float *>(GPU_vertbuf_get_data(mask_vbo));
for (int i = 0; i < coarse_mesh->totpoly; i++) {
const MPoly *poly = &coarse_polys[i];
const MPoly &poly = coarse_polys[i];
for (int loop_index = poly->loopstart; loop_index < poly->loopstart + poly->totloop;
for (int loop_index = poly.loopstart; loop_index < poly.loopstart + poly.totloop;
loop_index++) {
const MLoop *ml = &coarse_loops[loop_index];
*v_mask++ = cd_mask[ml->v];

View File

@@ -173,8 +173,8 @@ static void extract_weights_init_subdiv(const DRWSubdivCache *subdiv_cache,
if (mr->extract_type != MR_EXTRACT_BMESH) {
const Span<MPoly> coarse_polys = coarse_mesh->polys();
for (const int i : coarse_polys.index_range()) {
const MPoly *poly = &coarse_polys[i];
extract_weights_iter_poly_mesh(mr, poly, i, _data);
const MPoly &poly = coarse_polys[i];
extract_weights_iter_poly_mesh(mr, &poly, i, _data);
}
}
else {

View File

@@ -1034,16 +1034,16 @@ static MDefBoundIsect *meshdeform_ray_tree_intersect(MeshDeformBind *mdb,
BVH_RAYCAST_WATERTIGHT) != -1) {
const blender::Span<MLoop> loops = mdb->cagemesh_cache.loops;
const MLoopTri *lt = &mdb->cagemesh_cache.looptris[hit.index];
const MPoly *poly = &mdb->cagemesh_cache.polys[lt->poly];
const MPoly &poly = mdb->cagemesh_cache.polys[lt->poly];
const float(*cagecos)[3] = mdb->cagecos;
const float len = isect_mdef.lambda;
MDefBoundIsect *isect;
blender::Array<blender::float3, 64> mp_cagecos(poly->totloop);
blender::Array<blender::float3, 64> mp_cagecos(poly.totloop);
/* create MDefBoundIsect, and extra for 'poly_weights[]' */
isect = static_cast<MDefBoundIsect *>(
BLI_memarena_alloc(mdb->memarena, sizeof(*isect) + (sizeof(float) * poly->totloop)));
BLI_memarena_alloc(mdb->memarena, sizeof(*isect) + (sizeof(float) * poly.totloop)));
/* compute intersection coordinate */
madd_v3_v3v3fl(isect->co, co1, isect_mdef.vec, len);
@@ -1055,13 +1055,13 @@ static MDefBoundIsect *meshdeform_ray_tree_intersect(MeshDeformBind *mdb,
isect->len = max_ff(len_v3v3(co1, isect->co), MESHDEFORM_LEN_THRESHOLD);
/* compute mean value coordinates for interpolation */
for (int i = 0; i < poly->totloop; i++) {
copy_v3_v3(mp_cagecos[i], cagecos[loops[poly->loopstart + i].v]);
for (int i = 0; i < poly.totloop; i++) {
copy_v3_v3(mp_cagecos[i], cagecos[loops[poly.loopstart + i].v]);
}
interp_weights_poly_v3(isect->poly_weights,
reinterpret_cast<float(*)[3]>(mp_cagecos.data()),
poly->totloop,
poly.totloop,
isect->co);
return isect;
@@ -1226,10 +1226,10 @@ static float meshdeform_boundary_phi(const MeshDeformBind *mdb,
int cagevert)
{
const blender::Span<MLoop> loops = mdb->cagemesh_cache.loops;
const MPoly *poly = &mdb->cagemesh_cache.polys[isect->poly_index];
const MPoly &poly = mdb->cagemesh_cache.polys[isect->poly_index];
for (int i = 0; i < poly->totloop; i++) {
if (loops[poly->loopstart + i].v == cagevert) {
for (int i = 0; i < poly.totloop; i++) {
if (loops[poly.loopstart + i].v == cagevert) {
return isect->poly_weights[i];
}
}

View File

@@ -988,18 +988,18 @@ static int find_original_loop(const blender::Span<MPoly> orig_polys,
/* Get original vertex and polygon index. There is currently no loop mapping
* in modifier stack evaluation. */
const int vert_orig = vert_origindex[vert_eval];
const int poly_orig = poly_origindex[poly_eval];
const int poly_orig_i = poly_origindex[poly_eval];
if (vert_orig == ORIGINDEX_NONE || poly_orig == ORIGINDEX_NONE) {
if (vert_orig == ORIGINDEX_NONE || poly_orig_i == ORIGINDEX_NONE) {
return ORIGINDEX_NONE;
}
/* Find matching loop with original vertex in original polygon. */
const MPoly *mpoly_orig = &orig_polys[poly_orig];
const MLoop *mloop_orig = &orig_loops[mpoly_orig->loopstart];
for (int j = 0; j < mpoly_orig->totloop; ++j, ++mloop_orig) {
const MPoly &poly_orig = orig_polys[poly_orig_i];
const MLoop *mloop_orig = &orig_loops[poly_orig.loopstart];
for (int j = 0; j < poly_orig.totloop; ++j, ++mloop_orig) {
if (mloop_orig->v == vert_orig) {
return mpoly_orig->loopstart + j;
return poly_orig.loopstart + j;
}
}

View File

@@ -1721,10 +1721,10 @@ static float project_paint_uvpixel_mask(const ProjPaintState *ps,
if (ps->do_mask_normal) {
const MLoopTri *lt = &ps->looptris_eval[tri_index];
const int lt_vtri[3] = {PS_LOOPTRI_AS_VERT_INDEX_3(ps, lt)};
const MPoly *poly = &ps->polys_eval[lt->poly];
const MPoly &poly = ps->polys_eval[lt->poly];
float no[3], angle_cos;
if (poly->flag & ME_SMOOTH) {
if (poly.flag & ME_SMOOTH) {
const float *no1, *no2, *no3;
no1 = ps->vert_normals[lt_vtri[0]];
no2 = ps->vert_normals[lt_vtri[1]];
@@ -4388,11 +4388,11 @@ static void project_paint_prepare_all_faces(ProjPaintState *ps,
if (prev_poly != looptris[tri_index].poly) {
int iloop;
bool culled = true;
const MPoly *poly = &ps->polys_eval[looptris[tri_index].poly];
int poly_loops = poly->totloop;
const MPoly &poly = ps->polys_eval[looptris[tri_index].poly];
int poly_loops = poly.totloop;
prev_poly = looptris[tri_index].poly;
for (iloop = 0; iloop < poly_loops; iloop++) {
if (!(ps->vertFlags[ps->loops_eval[poly->loopstart + iloop].v] & PROJ_VERT_CULL)) {
if (!(ps->vertFlags[ps->loops_eval[poly.loopstart + iloop].v] & PROJ_VERT_CULL)) {
culled = false;
break;
}

View File

@@ -1981,11 +1981,11 @@ static void do_wpaint_brush_blur_task_cb_ex(void *__restrict userdata,
float weight_final = 0.0f;
for (int j = 0; j < gmap->vert_to_poly[v_index].count; j++) {
const int p_index = gmap->vert_to_poly[v_index].indices[j];
const MPoly *poly = &ss->polys[p_index];
const MPoly &poly = ss->polys[p_index];
total_hit_loops += poly->totloop;
for (int k = 0; k < poly->totloop; k++) {
const int l_index = poly->loopstart + k;
total_hit_loops += poly.totloop;
for (int k = 0; k < poly.totloop; k++) {
const int l_index = poly.loopstart + k;
const MLoop *ml = &ss->mloop[l_index];
weight_final += data->wpd->precomputed_weight[ml->v];
}
@@ -2094,9 +2094,9 @@ static void do_wpaint_brush_smear_task_cb_ex(void *__restrict userdata,
float weight_final = 0.0;
for (int j = 0; j < gmap->vert_to_poly[v_index].count; j++) {
const int p_index = gmap->vert_to_poly[v_index].indices[j];
const MPoly *poly = &ss->polys[p_index];
const MLoop *ml_other = &ss->mloop[poly->loopstart];
for (int k = 0; k < poly->totloop; k++, ml_other++) {
const MPoly &poly = ss->polys[p_index];
const MLoop *ml_other = &ss->mloop[poly.loopstart];
for (int k = 0; k < poly.totloop; k++, ml_other++) {
const uint v_other_index = ml_other->v;
if (v_other_index != v_index) {
const float3 &mv_other = ss->vert_positions[v_other_index];
@@ -3030,11 +3030,11 @@ static void do_vpaint_brush_blur_loops(bContext *C,
for (int j = 0; j < gmap->vert_to_poly[v_index].count; j++) {
int p_index = gmap->vert_to_poly[v_index].indices[j];
const MPoly *poly = &ss->polys[p_index];
const MPoly &poly = ss->polys[p_index];
if (!use_face_sel || select_poly[p_index]) {
total_hit_loops += poly->totloop;
for (int k = 0; k < poly->totloop; k++) {
const uint l_index = poly->loopstart + k;
total_hit_loops += poly.totloop;
for (int k = 0; k < poly.totloop; k++) {
const uint l_index = poly.loopstart + k;
Color *col = lcol + l_index;
/* Color is squared to compensate the sqrt color encoding. */
@@ -3175,11 +3175,11 @@ static void do_vpaint_brush_blur_verts(bContext *C,
for (int j = 0; j < gmap->vert_to_poly[v_index].count; j++) {
int p_index = gmap->vert_to_poly[v_index].indices[j];
const MPoly *poly = &ss->polys[p_index];
const MPoly &poly = ss->polys[p_index];
if (!use_face_sel || select_poly[p_index]) {
total_hit_loops += poly->totloop;
for (int k = 0; k < poly->totloop; k++) {
const uint l_index = poly->loopstart + k;
total_hit_loops += poly.totloop;
for (int k = 0; k < poly.totloop; k++) {
const uint l_index = poly.loopstart + k;
const uint v_index = ss->mloop[l_index].v;
Color *col = lcol + v_index;
@@ -3338,10 +3338,10 @@ static void do_vpaint_brush_smear(bContext *C,
const int l_index = gmap->vert_to_loop[v_index].indices[j];
BLI_assert(ss->mloop[l_index].v == v_index);
UNUSED_VARS_NDEBUG(l_index);
const MPoly *poly = &ss->polys[p_index];
const MPoly &poly = ss->polys[p_index];
if (!use_face_sel || select_poly[p_index]) {
const MLoop *ml_other = &ss->mloop[poly->loopstart];
for (int k = 0; k < poly->totloop; k++, ml_other++) {
const MLoop *ml_other = &ss->mloop[poly.loopstart];
for (int k = 0; k < poly.totloop; k++, ml_other++) {
const uint v_other_index = ml_other->v;
if (v_other_index != v_index) {
const float3 &mv_other = &ss->vert_positions[v_other_index];
@@ -3361,7 +3361,7 @@ static void do_vpaint_brush_smear(bContext *C,
elem_index = ml_other->v;
}
else {
elem_index = poly->loopstart + k;
elem_index = poly.loopstart + k;
}
if (stroke_dot > stroke_dot_max) {

View File

@@ -344,11 +344,11 @@ static const EnumPropertyItem *weight_paint_sample_enum_itemf(bContext *C,
}
else {
if (ED_mesh_pick_face(C, vc.obact, mval, ED_MESH_PICK_DEFAULT_FACE_DIST, &index)) {
const MPoly *poly = &polys[index];
uint fidx = poly->totloop - 1;
const MPoly &poly = polys[index];
uint fidx = poly.totloop - 1;
do {
const MDeformVert *dvert = &dverts[loops[poly->loopstart + fidx].v];
const MDeformVert *dvert = &dverts[loops[poly.loopstart + fidx].v];
found |= weight_paint_sample_enum_itemf__helper(dvert, defbase_tot, groups);
} while (fidx--);
}

View File

@@ -725,9 +725,9 @@ static bool sculpt_check_unique_face_set_for_edge_in_base_mesh(SculptSession *ss
const MeshElemMap *vert_map = &ss->pmap[v1];
int p1 = -1, p2 = -1;
for (int i = 0; i < vert_map->count; i++) {
const MPoly *poly = &ss->polys[vert_map->indices[i]];
for (int l = 0; l < poly->totloop; l++) {
const MLoop *loop = &ss->mloop[poly->loopstart + l];
const MPoly &poly = ss->polys[vert_map->indices[i]];
for (int l = 0; l < poly.totloop; l++) {
const MLoop *loop = &ss->mloop[poly.loopstart + l];
if (loop->v == v2) {
if (p1 == -1) {
p1 = vert_map->indices[i];
@@ -888,9 +888,9 @@ static void sculpt_vertex_neighbors_get_faces(SculptSession *ss,
/* Skip connectivity from hidden faces. */
continue;
}
const MPoly *poly = &ss->polys[vert_map->indices[i]];
const MPoly &poly = ss->polys[vert_map->indices[i]];
int f_adj_v[2];
if (poly_get_adj_loops_from_vert(poly, ss->mloop, vertex.i, f_adj_v) != -1) {
if (poly_get_adj_loops_from_vert(&poly, ss->mloop, vertex.i, f_adj_v) != -1) {
for (int j = 0; j < ARRAY_SIZE(f_adj_v); j += 1) {
if (f_adj_v[j] != vertex.i) {
sculpt_vertex_neighbor_add(iter, BKE_pbvh_make_vref(f_adj_v[j]), f_adj_v[j]);
@@ -6211,9 +6211,9 @@ void SCULPT_boundary_info_ensure(Object *object)
MEM_calloc_arrayN(base_mesh->totedge, sizeof(int), "Adjacent face edge count"));
for (const int p : polys.index_range()) {
const MPoly *poly = &polys[p];
for (int l = 0; l < poly->totloop; l++) {
const MLoop *loop = &loops[l + poly->loopstart];
const MPoly &poly = polys[p];
for (int l = 0; l < poly.totloop; l++) {
const MLoop *loop = &loops[l + poly.loopstart];
adjacent_faces_edge_count[loop->e]++;
}
}

View File

@@ -712,9 +712,9 @@ static float *sculpt_expand_diagonals_falloff_create(Object *ob, const PBVHVertR
int v_next_i = BKE_pbvh_vertex_to_index(ss->pbvh, v_next);
for (int j = 0; j < ss->pmap[v_next_i].count; j++) {
const MPoly *poly = &ss->polys[ss->pmap[v_next_i].indices[j]];
for (int l = 0; l < poly->totloop; l++) {
const PBVHVertRef neighbor_v = BKE_pbvh_make_vref(ss->mloop[poly->loopstart + l].v);
const MPoly &poly = ss->polys[ss->pmap[v_next_i].indices[j]];
for (int l = 0; l < poly.totloop; l++) {
const PBVHVertRef neighbor_v = BKE_pbvh_make_vref(ss->mloop[poly.loopstart + l].v);
if (BLI_BITMAP_TEST(visited_verts, neighbor_v.i)) {
continue;
}
@@ -795,15 +795,15 @@ static void sculpt_expand_grids_to_faces_falloff(SculptSession *ss,
const CCGKey *key = BKE_pbvh_get_grid_key(ss->pbvh);
for (const int p : polys.index_range()) {
const MPoly *poly = &polys[p];
const MPoly &poly = polys[p];
float accum = 0.0f;
for (int l = 0; l < poly->totloop; l++) {
const int grid_loop_index = (poly->loopstart + l) * key->grid_area;
for (int l = 0; l < poly.totloop; l++) {
const int grid_loop_index = (poly.loopstart + l) * key->grid_area;
for (int g = 0; g < key->grid_area; g++) {
accum += expand_cache->vert_falloff[grid_loop_index + g];
}
}
expand_cache->face_falloff[p] = accum / (poly->totloop * key->grid_area);
expand_cache->face_falloff[p] = accum / (poly.totloop * key->grid_area);
}
}
@@ -813,13 +813,13 @@ static void sculpt_expand_vertex_to_faces_falloff(Mesh *mesh, ExpandCache *expan
const blender::Span<MLoop> loops = mesh->loops();
for (const int p : polys.index_range()) {
const MPoly *poly = &polys[p];
const MPoly &poly = polys[p];
float accum = 0.0f;
for (int l = 0; l < poly->totloop; l++) {
const MLoop *loop = &loops[l + poly->loopstart];
for (int l = 0; l < poly.totloop; l++) {
const MLoop *loop = &loops[l + poly.loopstart];
accum += expand_cache->vert_falloff[loop->v];
}
expand_cache->face_falloff[p] = accum / poly->totloop;
expand_cache->face_falloff[p] = accum / poly.totloop;
}
}
@@ -1116,10 +1116,10 @@ static void sculpt_expand_snap_initialize_from_enabled(SculptSession *ss,
}
for (int p = 0; p < totface; p++) {
const MPoly *poly = &ss->polys[p];
const MPoly &poly = ss->polys[p];
bool any_disabled = false;
for (int l = 0; l < poly->totloop; l++) {
const MLoop *loop = &ss->mloop[l + poly->loopstart];
for (int l = 0; l < poly.totloop; l++) {
const MLoop *loop = &ss->mloop[l + poly.loopstart];
if (!BLI_BITMAP_TEST(enabled_verts, loop->v)) {
any_disabled = true;
break;
@@ -2023,9 +2023,9 @@ static void sculpt_expand_delete_face_set_id(int *r_face_sets,
while (BLI_LINKSTACK_SIZE(queue)) {
const int f_index = POINTER_AS_INT(BLI_LINKSTACK_POP(queue));
int other_id = delete_id;
const MPoly *c_poly = &polys[f_index];
for (int l = 0; l < c_poly->totloop; l++) {
const MLoop *c_loop = &loops[c_poly->loopstart + l];
const MPoly &c_poly = polys[f_index];
for (int l = 0; l < c_poly.totloop; l++) {
const MLoop *c_loop = &loops[c_poly.loopstart + l];
const MeshElemMap *vert_map = &pmap[c_loop->v];
for (int i = 0; i < vert_map->count; i++) {

View File

@@ -132,10 +132,10 @@ static void do_draw_face_sets_brush_task_cb_ex(void *__restrict userdata,
if (BKE_pbvh_type(ss->pbvh) == PBVH_FACES) {
MeshElemMap *vert_map = &ss->pmap[vd.index];
for (int j = 0; j < ss->pmap[vd.index].count; j++) {
const MPoly *poly = &ss->polys[vert_map->indices[j]];
const MPoly &poly = ss->polys[vert_map->indices[j]];
float poly_center[3];
BKE_mesh_calc_poly_center(poly, &ss->mloop[poly->loopstart], positions, poly_center);
BKE_mesh_calc_poly_center(&poly, &ss->mloop[poly.loopstart], positions, poly_center);
if (!sculpt_brush_test_sq_fn(&test, poly_center)) {
continue;
@@ -1110,9 +1110,9 @@ static void sculpt_face_set_grow(Object *ob,
if (!modify_hidden && prev_face_sets[p] <= 0) {
continue;
}
const MPoly *c_poly = &polys[p];
for (int l = 0; l < c_poly->totloop; l++) {
const MLoop *c_loop = &loops[c_poly->loopstart + l];
const MPoly &c_poly = polys[p];
for (int l = 0; l < c_poly.totloop; l++) {
const MLoop *c_loop = &loops[c_poly.loopstart + l];
const MeshElemMap *vert_map = &ss->pmap[c_loop->v];
for (int i = 0; i < vert_map->count; i++) {
const int neighbor_face_index = vert_map->indices[i];
@@ -1141,9 +1141,9 @@ static void sculpt_face_set_shrink(Object *ob,
continue;
}
if (abs(prev_face_sets[p]) == active_face_set_id) {
const MPoly *c_poly = &polys[p];
for (int l = 0; l < c_poly->totloop; l++) {
const MLoop *c_loop = &loops[c_poly->loopstart + l];
const MPoly &c_poly = polys[p];
for (int l = 0; l < c_poly.totloop; l++) {
const MLoop *c_loop = &loops[c_poly.loopstart + l];
const MeshElemMap *vert_map = &ss->pmap[c_loop->v];
for (int i = 0; i < vert_map->count; i++) {
const int neighbor_face_index = vert_map->indices[i];

View File

@@ -1782,12 +1782,12 @@ static eSnapMode snap_mesh_polygon(SnapObjectContext *sctx,
params->use_backface_culling,
&nearest2d);
const MPoly *poly = &mesh->polys()[sctx->ret.index];
const MLoop *ml = &nearest2d.loop[poly->loopstart];
const MPoly &poly = mesh->polys()[sctx->ret.index];
const MLoop *ml = &nearest2d.loop[poly.loopstart];
if (sctx->runtime.snap_to_flag & SCE_SNAP_MODE_EDGE) {
elem = SCE_SNAP_MODE_EDGE;
BLI_assert(nearest2d.edges != nullptr);
for (int i = poly->totloop; i--; ml++) {
for (int i = poly.totloop; i--; ml++) {
cb_snap_edge(&nearest2d,
int(ml->e),
&neasrest_precalc,
@@ -1798,7 +1798,7 @@ static eSnapMode snap_mesh_polygon(SnapObjectContext *sctx,
}
else {
elem = SCE_SNAP_MODE_VERTEX;
for (int i = poly->totloop; i--; ml++) {
for (int i = poly.totloop; i--; ml++) {
cb_snap_vert(&nearest2d,
int(ml->v),
&neasrest_precalc,

View File

@@ -671,7 +671,7 @@ static ParamHandle *construct_param_handle_subsurfed(const Scene *scene,
/* Prepare and feed faces to the solver */
for (const int i : subsurf_polys.index_range()) {
const MPoly *poly = &subsurf_polys[i];
const MPoly &poly = subsurf_polys[i];
ParamKey key, vkeys[4];
bool pin[4], select[4];
const float *co[4];
@@ -690,10 +690,10 @@ static ParamHandle *construct_param_handle_subsurfed(const Scene *scene,
}
}
const MLoop *mloop = &subsurf_loops[poly->loopstart];
const MLoop *mloop = &subsurf_loops[poly.loopstart];
/* We will not check for v4 here. Sub-surface faces always have 4 vertices. */
BLI_assert(poly->totloop == 4);
BLI_assert(poly.totloop == 4);
key = (ParamKey)i;
vkeys[0] = (ParamKey)mloop[0].v;
vkeys[1] = (ParamKey)mloop[1].v;

View File

@@ -548,9 +548,9 @@ static void get_loop_normals(struct Mesh *mesh,
const Span<MPoly> polys = mesh->polys();
for (const int i : polys.index_range()) {
const MPoly *poly = &polys[i];
for (int j = poly->totloop - 1; j >= 0; j--, abc_index++) {
int blender_index = poly->loopstart + j;
const MPoly &poly = polys[i];
for (int j = poly.totloop - 1; j >= 0; j--, abc_index++) {
int blender_index = poly.loopstart + j;
copy_yup_from_zup(normals[abc_index].getValue(), lnors[blender_index]);
}
}

View File

@@ -181,10 +181,10 @@ static void get_cols(const CDStreamConfig &config,
Imath::C4f col;
for (int i = 0; i < config.totpoly; i++) {
const MPoly *poly = &polys[i];
const MCol *cface = &cfaces[poly->loopstart + poly->totloop];
const MPoly &poly = polys[i];
const MCol *cface = &cfaces[poly.loopstart + poly.totloop];
for (int j = 0; j < poly->totloop; j++) {
for (int j = 0; j < poly.totloop; j++) {
cface--;
col[0] = cface->a * cscale;
@@ -411,7 +411,7 @@ static void read_custom_data_mcols(const std::string &iobject_full_name,
void *cd_data = config.add_customdata_cb(
config.mesh, prop_header.getName().c_str(), CD_PROP_BYTE_COLOR);
MCol *cfaces = static_cast<MCol *>(cd_data);
MPoly *polys = config.polys;
const MPoly *polys = config.polys;
MLoop *mloops = config.mloop;
size_t face_index = 0;
@@ -425,11 +425,11 @@ static void read_custom_data_mcols(const std::string &iobject_full_name,
bool use_dual_indexing = is_facevarying && indices->size() > 0;
for (int i = 0; i < config.totpoly; i++) {
MPoly *poly = &polys[i];
MCol *cface = &cfaces[poly->loopstart + poly->totloop];
MLoop *mloop = &mloops[poly->loopstart + poly->totloop];
const MPoly &poly = polys[i];
MCol *cface = &cfaces[poly.loopstart + poly.totloop];
MLoop *mloop = &mloops[poly.loopstart + poly.totloop];
for (int j = 0; j < poly->totloop; j++, face_index++) {
for (int j = 0; j < poly.totloop; j++, face_index++) {
cface--;
mloop--;

View File

@@ -442,9 +442,9 @@ static void calc_tangent_spaces(const Mesh *mesh,
}
for (const int64_t i : polys.index_range()) {
const MPoly *poly = &polys[i];
const MLoop *l_next = &loops[poly->loopstart];
const MLoop *l_term = l_next + poly->totloop;
const MPoly &poly = polys[i];
const MLoop *l_next = &loops[poly.loopstart];
const MLoop *l_term = l_next + poly.totloop;
const MLoop *l_prev = l_term - 2;
const MLoop *l_curr = l_term - 1;

View File

@@ -118,11 +118,11 @@ static float compute_volume(const float center[3],
float vol = 0.0f;
for (const int i : polys.index_range()) {
const MPoly *poly = &polys[i];
const MLoop *l_first = &loops[poly->loopstart];
const MPoly &poly = polys[i];
const MLoop *l_first = &loops[poly.loopstart];
const MLoop *l_prev = l_first + 1;
const MLoop *l_curr = l_first + 2;
const MLoop *l_term = l_first + poly->totloop;
const MLoop *l_term = l_first + poly.totloop;
for (; l_curr != l_term; l_prev = l_curr, l_curr++) {
vol += volume_tetrahedron_signed_v3(
@@ -187,9 +187,9 @@ static void init_laplacian_matrix(LaplacianSystem *sys)
}
for (const int i : sys->polys.index_range()) {
const MPoly *poly = &sys->polys[i];
const MLoop *l_next = &sys->loops[poly->loopstart];
const MLoop *l_term = l_next + poly->totloop;
const MPoly &poly = sys->polys[i];
const MLoop *l_next = &sys->loops[poly.loopstart];
const MLoop *l_term = l_next + poly.totloop;
const MLoop *l_prev = l_term - 2;
const MLoop *l_curr = l_term - 1;
@@ -242,9 +242,9 @@ static void fill_laplacian_matrix(LaplacianSystem *sys)
uint idv1, idv2;
for (const int i : sys->polys.index_range()) {
const MPoly *poly = &sys->polys[i];
const MLoop *l_next = &sys->loops[poly->loopstart];
const MLoop *l_term = l_next + poly->totloop;
const MPoly &poly = sys->polys[i];
const MLoop *l_next = &sys->loops[poly.loopstart];
const MLoop *l_term = l_next + poly.totloop;
const MLoop *l_prev = l_term - 2;
const MLoop *l_curr = l_term - 1;

View File

@@ -191,7 +191,6 @@ static void generate_ocean_geometry_polys(void *__restrict userdata,
for (x = 0; x < gogd->res_x; x++) {
const int fi = y * gogd->res_x + x;
const int vi = y * (gogd->res_x + 1) + x;
MPoly *poly = &gogd->polys[fi];
MLoop *ml = &gogd->loops[fi * 4];
ml->v = vi;
@@ -203,10 +202,9 @@ static void generate_ocean_geometry_polys(void *__restrict userdata,
ml->v = vi + gogd->res_x + 1;
ml++;
poly->loopstart = fi * 4;
poly->totloop = 4;
poly->flag |= ME_SMOOTH;
gogd->polys[fi].loopstart = fi * 4;
gogd->polys[fi].totloop = 4;
gogd->polys[fi].flag |= ME_SMOOTH;
}
}

View File

@@ -477,19 +477,19 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh *
/* create polys and loops */
for (k = 0; k < totpoly; k++) {
const MPoly *inMP = &orig_polys[k];
MPoly *poly = &polys[p_skip * totpoly + k];
const MPoly &in_poly = orig_polys[k];
MPoly &poly = polys[p_skip * totpoly + k];
CustomData_copy_data(&mesh->pdata, &result->pdata, k, p_skip * totpoly + k, 1);
*poly = *inMP;
poly->loopstart += p_skip * totloop;
poly = in_poly;
poly.loopstart += p_skip * totloop;
{
const MLoop *inML = &orig_loops[inMP->loopstart];
MLoop *ml = &loops[poly->loopstart];
int j = poly->totloop;
const MLoop *inML = &orig_loops[in_poly.loopstart];
MLoop *ml = &loops[poly.loopstart];
int j = poly.totloop;
CustomData_copy_data(&mesh->ldata, &result->ldata, inMP->loopstart, poly->loopstart, j);
CustomData_copy_data(&mesh->ldata, &result->ldata, in_poly.loopstart, poly.loopstart, j);
for (; j; j--, ml++, inML++) {
ml->v = inML->v + (p_skip * totvert);
ml->e = inML->e + (p_skip * totedge);

View File

@@ -120,11 +120,10 @@ static void dualcon_add_quad(void *output_v, const int vert_indices[4])
BLI_assert(output->curface < mesh->totpoly);
UNUSED_VARS_NDEBUG(mesh);
MLoop *mloop = output->loops;
MPoly *cur_poly = &output->polys[output->curface];
output->polys[output->curface].loopstart = output->curface * 4;
output->polys[output->curface].totloop = 4;
cur_poly->loopstart = output->curface * 4;
cur_poly->totloop = 4;
MLoop *mloop = output->loops;
for (i = 0; i < 4; i++) {
mloop[output->curface * 4 + i].v = vert_indices[i];
}

View File

@@ -397,12 +397,12 @@ Mesh *MOD_solidify_nonmanifold_modifyMesh(ModifierData *md,
if (k != i && edge_adj_faces_len[k] > 0 &&
(ELEM(vm[orig_edges[k].v1], v1, v2) != ELEM(vm[orig_edges[k].v2], v1, v2))) {
for (uint j = 0; j < edge_adj_faces[k]->faces_len && can_merge; j++) {
const MPoly *poly = &orig_polys[edge_adj_faces[k]->faces[j]];
const MPoly &poly = orig_polys[edge_adj_faces[k]->faces[j]];
uint changes = 0;
int cur = poly->totloop - 1;
for (int next = 0; next < poly->totloop && changes <= 2; next++) {
uint cur_v = vm[orig_loops[poly->loopstart + cur].v];
uint next_v = vm[orig_loops[poly->loopstart + next].v];
int cur = poly.totloop - 1;
for (int next = 0; next < poly.totloop && changes <= 2; next++) {
uint cur_v = vm[orig_loops[poly.loopstart + cur].v];
uint next_v = vm[orig_loops[poly.loopstart + next].v];
changes += (ELEM(cur_v, v1, v2) != ELEM(next_v, v1, v2));
cur = next;
}

View File

@@ -383,7 +383,6 @@ BLI_INLINE uint nearestVert(SDefBindCalcData *const data, const float point_co[3
nearest.dist_sq = FLT_MAX;
nearest.index = -1;
const MPoly *poly;
const MEdge *edge;
const MLoop *loop;
float t_point[3];
@@ -396,10 +395,10 @@ BLI_INLINE uint nearestVert(SDefBindCalcData *const data, const float point_co[3
BLI_bvhtree_find_nearest(
data->treeData->tree, t_point, &nearest, data->treeData->nearest_callback, data->treeData);
poly = &data->polys[data->looptris[nearest.index].poly];
loop = &data->loops[poly->loopstart];
const MPoly &poly = data->polys[data->looptris[nearest.index].poly];
loop = &data->loops[poly.loopstart];
for (int i = 0; i < poly->totloop; i++, loop++) {
for (int i = 0; i < poly.totloop; i++, loop++) {
edge = &data->edges[loop->e];
dist = dist_squared_to_line_segment_v3(
point_co, data->targetCos[edge->v1], data->targetCos[edge->v2]);
@@ -489,7 +488,6 @@ BLI_INLINE SDefBindWeightData *computeBindWeights(SDefBindCalcData *const data,
const SDefEdgePolys *const edge_polys = data->edge_polys;
const SDefAdjacency *vedge;
const MPoly *poly;
const MLoop *loop;
SDefBindWeightData *bwdata;
@@ -547,14 +545,14 @@ BLI_INLINE SDefBindWeightData *computeBindWeights(SDefBindCalcData *const data,
bpoly->coords_v2 = nullptr;
/* Copy poly data */
poly = &data->polys[bpoly->index];
loop = &data->loops[poly->loopstart];
const MPoly &poly = data->polys[bpoly->index];
loop = &data->loops[poly.loopstart];
bpoly->verts_num = poly->totloop;
bpoly->loopstart = poly->loopstart;
bpoly->verts_num = poly.totloop;
bpoly->loopstart = poly.loopstart;
bpoly->coords = static_cast<float(*)[3]>(
MEM_malloc_arrayN(poly->totloop, sizeof(*bpoly->coords), "SDefBindPolyCoords"));
MEM_malloc_arrayN(poly.totloop, sizeof(*bpoly->coords), "SDefBindPolyCoords"));
if (bpoly->coords == nullptr) {
freeBindData(bwdata);
data->success = MOD_SDEF_BIND_RESULT_MEM_ERR;
@@ -562,30 +560,30 @@ BLI_INLINE SDefBindWeightData *computeBindWeights(SDefBindCalcData *const data,
}
bpoly->coords_v2 = static_cast<float(*)[2]>(
MEM_malloc_arrayN(poly->totloop, sizeof(*bpoly->coords_v2), "SDefBindPolyCoords_v2"));
MEM_malloc_arrayN(poly.totloop, sizeof(*bpoly->coords_v2), "SDefBindPolyCoords_v2"));
if (bpoly->coords_v2 == nullptr) {
freeBindData(bwdata);
data->success = MOD_SDEF_BIND_RESULT_MEM_ERR;
return nullptr;
}
for (int j = 0; j < poly->totloop; j++, loop++) {
for (int j = 0; j < poly.totloop; j++, loop++) {
copy_v3_v3(bpoly->coords[j], data->targetCos[loop->v]);
/* Find corner and edge indices within poly loop array */
if (loop->v == nearest) {
bpoly->corner_ind = j;
bpoly->edge_vert_inds[0] = (j == 0) ? (poly->totloop - 1) : (j - 1);
bpoly->edge_vert_inds[1] = (j == poly->totloop - 1) ? (0) : (j + 1);
bpoly->edge_vert_inds[0] = (j == 0) ? (poly.totloop - 1) : (j - 1);
bpoly->edge_vert_inds[1] = (j == poly.totloop - 1) ? (0) : (j + 1);
bpoly->edge_inds[0] = data->loops[poly->loopstart + bpoly->edge_vert_inds[0]].e;
bpoly->edge_inds[0] = data->loops[poly.loopstart + bpoly->edge_vert_inds[0]].e;
bpoly->edge_inds[1] = loop->e;
}
}
/* Compute polygons parametric data. */
mid_v3_v3_array(bpoly->centroid, bpoly->coords, poly->totloop);
normal_poly_v3(bpoly->normal, bpoly->coords, poly->totloop);
mid_v3_v3_array(bpoly->centroid, bpoly->coords, poly.totloop);
normal_poly_v3(bpoly->normal, bpoly->coords, poly.totloop);
/* Compute poly skew angle and axis */
angle = angle_normalized_v3v3(bpoly->normal, world);
@@ -597,12 +595,12 @@ BLI_INLINE SDefBindWeightData *computeBindWeights(SDefBindCalcData *const data,
map_to_plane_axis_angle_v2_v3v3fl(bpoly->point_v2, point_co, axis, angle);
zero_v2(bpoly->centroid_v2);
for (int j = 0; j < poly->totloop; j++) {
for (int j = 0; j < poly.totloop; j++) {
map_to_plane_axis_angle_v2_v3v3fl(bpoly->coords_v2[j], bpoly->coords[j], axis, angle);
madd_v2_v2fl(bpoly->centroid_v2, bpoly->coords_v2[j], 1.0f / poly->totloop);
madd_v2_v2fl(bpoly->centroid_v2, bpoly->coords_v2[j], 1.0f / poly.totloop);
}
is_poly_valid = isPolyValid(bpoly->coords_v2, poly->totloop);
is_poly_valid = isPolyValid(bpoly->coords_v2, poly.totloop);
if (is_poly_valid != MOD_SDEF_BIND_RESULT_SUCCESS) {
freeBindData(bwdata);
@@ -611,7 +609,7 @@ BLI_INLINE SDefBindWeightData *computeBindWeights(SDefBindCalcData *const data,
}
bpoly->inside = isect_point_poly_v2(
bpoly->point_v2, bpoly->coords_v2, poly->totloop, false);
bpoly->point_v2, bpoly->coords_v2, poly.totloop, false);
/* Initialize weight components */
bpoly->weight_angular = 1.0f;

View File

@@ -97,9 +97,9 @@ static void uv_warp_compute(void *__restrict userdata,
{
const UVWarpData *data = static_cast<const UVWarpData *>(userdata);
const MPoly *poly = &data->polys[i];
const MLoop *ml = &data->loops[poly->loopstart];
float(*mluv)[2] = &data->mloopuv[poly->loopstart];
const MPoly &poly = data->polys[i];
const MLoop *ml = &data->loops[poly.loopstart];
float(*mluv)[2] = &data->mloopuv[poly.loopstart];
const MDeformVert *dvert = data->dvert;
const int defgrp_index = data->defgrp_index;
@@ -109,7 +109,7 @@ static void uv_warp_compute(void *__restrict userdata,
int l;
if (dvert) {
for (l = 0; l < poly->totloop; l++, ml++, mluv++) {
for (l = 0; l < poly.totloop; l++, ml++, mluv++) {
float uv[2];
const float weight = data->invert_vgroup ?
1.0f - BKE_defvert_find_weight(&dvert[ml->v], defgrp_index) :
@@ -120,7 +120,7 @@ static void uv_warp_compute(void *__restrict userdata,
}
}
else {
for (l = 0; l < poly->totloop; l++, mluv++) {
for (l = 0; l < poly.totloop; l++, mluv++) {
uv_warp_from_mat4_pair(*mluv, *mluv, warp_mat);
}
}

View File

@@ -503,7 +503,7 @@ static TriTessFace *mesh_calc_tri_tessface(Mesh *me, bool tangent, Mesh *me_eval
const float(*vert_normals)[3] = BKE_mesh_vert_normals_ensure(me);
for (i = 0; i < tottri; i++) {
const MLoopTri *lt = &looptri[i];
const MPoly *poly = &polys[lt->poly];
const MPoly &poly = polys[lt->poly];
triangles[i].positions[0] = positions[loops[lt->tri[0]].v];
triangles[i].positions[1] = positions[loops[lt->tri[1]].v];
@@ -511,7 +511,7 @@ static TriTessFace *mesh_calc_tri_tessface(Mesh *me, bool tangent, Mesh *me_eval
triangles[i].vert_normals[0] = vert_normals[loops[lt->tri[0]].v];
triangles[i].vert_normals[1] = vert_normals[loops[lt->tri[1]].v];
triangles[i].vert_normals[2] = vert_normals[loops[lt->tri[2]].v];
triangles[i].is_smooth = (poly->flag & ME_SMOOTH) != 0;
triangles[i].is_smooth = (poly.flag & ME_SMOOTH) != 0;
if (tangent) {
triangles[i].tspace[0] = &tspace[lt->tri[0]];
@@ -527,7 +527,7 @@ static TriTessFace *mesh_calc_tri_tessface(Mesh *me, bool tangent, Mesh *me_eval
if (calculate_normal) {
if (lt->poly != mpoly_prev) {
BKE_mesh_calc_poly_normal(poly, &loops[poly->loopstart], positions, no);
BKE_mesh_calc_poly_normal(&poly, &loops[poly.loopstart], positions, no);
mpoly_prev = lt->poly;
}
copy_v3_v3(triangles[i].normal, no);

View File

@@ -62,7 +62,7 @@ struct MultiresBakeResult {
struct MResolvePixelData {
const float (*vert_positions)[3];
const float (*vert_normals)[3];
MPoly *polys;
const MPoly *polys;
const int *material_indices;
MLoop *mloop;
float (*mloopuv)[2];
@@ -113,8 +113,8 @@ static void multiresbake_get_normal(const MResolvePixelData *data,
float r_normal[3])
{
const int poly_index = data->mlooptri[tri_num].poly;
const MPoly *poly = &data->polys[poly_index];
const bool smoothnormal = (poly->flag & ME_SMOOTH) != 0;
const MPoly &poly = data->polys[poly_index];
const bool smoothnormal = (poly.flag & ME_SMOOTH) != 0;
if (smoothnormal) {
const int vi = data->mloop[data->mlooptri[tri_num].tri[vert_index]].v;
@@ -126,7 +126,7 @@ static void multiresbake_get_normal(const MResolvePixelData *data,
}
else {
BKE_mesh_calc_poly_normal(
poly, &data->mloop[poly->loopstart], data->vert_positions, r_normal);
&poly, &data->mloop[poly.loopstart], data->vert_positions, r_normal);
}
}
}
@@ -474,7 +474,7 @@ static void do_multires_bake(MultiresBakeRender *bkr,
MultiresBakeQueue queue;
const float(*positions)[3] = (float(*)[3])dm->getVertArray(dm);
MPoly *polys = dm->getPolyArray(dm);
const MPoly *polys = dm->getPolyArray(dm);
MLoop *mloop = dm->getLoopArray(dm);
float(*mloopuv)[2] = static_cast<float(*)[2]>(dm->getLoopDataArray(dm, CD_PROP_FLOAT2));
float *pvtangent = nullptr;
@@ -664,13 +664,12 @@ static void get_ccgdm_data(DerivedMesh *lodm,
hidm->getGridKey(hidm, &key);
if (lvl == 0) {
MPoly *poly;
face_side = (grid_size << 1) - 1;
poly = lodm->getPolyArray(lodm) + poly_index;
const MPoly &poly = lodm->getPolyArray(lodm)[poly_index];
g_index = grid_offset[poly_index];
S = mdisp_rot_face_to_crn(
poly, face_side, u * (face_side - 1), v * (face_side - 1), &crn_x, &crn_y);
&poly, face_side, u * (face_side - 1), v * (face_side - 1), &crn_x, &crn_y);
}
else {
/* number of faces per grid side */
@@ -713,7 +712,7 @@ static void get_ccgdm_data(DerivedMesh *lodm,
static void interp_bilinear_mpoly(DerivedMesh *dm,
MLoop *mloop,
MPoly *poly,
const MPoly &poly,
const float u,
const float v,
const int mode,
@@ -722,16 +721,16 @@ static void interp_bilinear_mpoly(DerivedMesh *dm,
float data[4][3];
if (mode == 0) {
dm->getVertNo(dm, mloop[poly->loopstart].v, data[0]);
dm->getVertNo(dm, mloop[poly->loopstart + 1].v, data[1]);
dm->getVertNo(dm, mloop[poly->loopstart + 2].v, data[2]);
dm->getVertNo(dm, mloop[poly->loopstart + 3].v, data[3]);
dm->getVertNo(dm, mloop[poly.loopstart].v, data[0]);
dm->getVertNo(dm, mloop[poly.loopstart + 1].v, data[1]);
dm->getVertNo(dm, mloop[poly.loopstart + 2].v, data[2]);
dm->getVertNo(dm, mloop[poly.loopstart + 3].v, data[3]);
}
else {
dm->getVertCo(dm, mloop[poly->loopstart].v, data[0]);
dm->getVertCo(dm, mloop[poly->loopstart + 1].v, data[1]);
dm->getVertCo(dm, mloop[poly->loopstart + 2].v, data[2]);
dm->getVertCo(dm, mloop[poly->loopstart + 3].v, data[3]);
dm->getVertCo(dm, mloop[poly.loopstart].v, data[0]);
dm->getVertCo(dm, mloop[poly.loopstart + 1].v, data[1]);
dm->getVertCo(dm, mloop[poly.loopstart + 2].v, data[2]);
dm->getVertCo(dm, mloop[poly.loopstart + 3].v, data[3]);
}
interp_bilinear_quad_v3(data, u, v, res);
@@ -832,7 +831,7 @@ static void apply_heights_callback(DerivedMesh *lores_dm,
{
const MLoopTri *lt = lores_dm->getLoopTriArray(lores_dm) + tri_index;
MLoop *mloop = lores_dm->getLoopArray(lores_dm);
MPoly *poly = lores_dm->getPolyArray(lores_dm) + lt->poly;
const MPoly &poly = lores_dm->getPolyArray(lores_dm)[lt->poly];
float(*mloopuv)[2] = static_cast<float(*)[2]>(
lores_dm->getLoopDataArray(lores_dm, CD_PROP_FLOAT2));
MHeightBakeData *height_data = (MHeightBakeData *)bake_data;
@@ -843,11 +842,11 @@ static void apply_heights_callback(DerivedMesh *lores_dm,
/* ideally we would work on triangles only, however, we rely on quads to get orthogonal
* coordinates for use in grid space (triangle barycentric is not orthogonal) */
if (poly->totloop == 4) {
st0 = mloopuv[poly->loopstart];
st1 = mloopuv[poly->loopstart + 1];
st2 = mloopuv[poly->loopstart + 2];
st3 = mloopuv[poly->loopstart + 3];
if (poly.totloop == 4) {
st0 = mloopuv[poly.loopstart];
st1 = mloopuv[poly.loopstart + 1];
st2 = mloopuv[poly.loopstart + 2];
st3 = mloopuv[poly.loopstart + 3];
resolve_quad_uv_v2(uv, st, st0, st1, st2, st3);
}
else {
@@ -874,7 +873,7 @@ static void apply_heights_callback(DerivedMesh *lores_dm,
n);
}
else {
if (poly->totloop == 4) {
if (poly.totloop == 4) {
interp_bilinear_mpoly(lores_dm, mloop, poly, uv[0], uv[1], 1, p0);
interp_bilinear_mpoly(lores_dm, mloop, poly, uv[0], uv[1], 0, n);
}
@@ -947,7 +946,7 @@ static void apply_tangmat_callback(DerivedMesh *lores_dm,
const int y)
{
const MLoopTri *lt = lores_dm->getLoopTriArray(lores_dm) + tri_index;
MPoly *poly = lores_dm->getPolyArray(lores_dm) + lt->poly;
const MPoly &poly = lores_dm->getPolyArray(lores_dm)[lt->poly];
float(*mloopuv)[2] = static_cast<float(*)[2]>(
lores_dm->getLoopDataArray(lores_dm, CD_PROP_FLOAT2));
MNormalBakeData *normal_data = (MNormalBakeData *)bake_data;
@@ -957,11 +956,11 @@ static void apply_tangmat_callback(DerivedMesh *lores_dm,
/* ideally we would work on triangles only, however, we rely on quads to get orthogonal
* coordinates for use in grid space (triangle barycentric is not orthogonal) */
if (poly->totloop == 4) {
st0 = mloopuv[poly->loopstart];
st1 = mloopuv[poly->loopstart + 1];
st2 = mloopuv[poly->loopstart + 2];
st3 = mloopuv[poly->loopstart + 3];
if (poly.totloop == 4) {
st0 = mloopuv[poly.loopstart];
st1 = mloopuv[poly.loopstart + 1];
st2 = mloopuv[poly.loopstart + 2];
st3 = mloopuv[poly.loopstart + 3];
resolve_quad_uv_v2(uv, st, st0, st1, st2, st3);
}
else {
@@ -1209,7 +1208,7 @@ static void apply_ao_callback(DerivedMesh *lores_dm,
const int y)
{
const MLoopTri *lt = lores_dm->getLoopTriArray(lores_dm) + tri_index;
MPoly *poly = lores_dm->getPolyArray(lores_dm) + lt->poly;
const MPoly &poly = lores_dm->getPolyArray(lores_dm) [lt->poly];
float (*mloopuv)[2] = lores_dm->getLoopDataArray(lores_dm, CD_PROP_FLOAT2);
MAOBakeData *ao_data = (MAOBakeData *)bake_data;
@@ -1224,11 +1223,11 @@ static void apply_ao_callback(DerivedMesh *lores_dm,
/* ideally we would work on triangles only, however, we rely on quads to get orthogonal
* coordinates for use in grid space (triangle barycentric is not orthogonal) */
if (poly->totloop == 4) {
st0 = mloopuv[poly->loopstart];
st1 = mloopuv[poly->loopstart + 1];
st2 = mloopuv[poly->loopstart + 2];
st3 = mloopuv[poly->loopstart + 3];
if (poly.totloop == 4) {
st0 = mloopuv[poly.loopstart];
st1 = mloopuv[poly.loopstart + 1];
st2 = mloopuv[poly.loopstart + 2];
st3 = mloopuv[poly.loopstart + 3];
resolve_quad_uv_v2(uv, st, st0, st1, st2, st3);
}
else {