Cleanup: Use simpler iterator for mesh polygons
Avoid incrementing a pointer, use only indices as a source of truth. This should ease refactors to change the way polys are stored.
This commit is contained in:
parent
e1a0c09f06
commit
45cff837bc
|
@ -1895,27 +1895,25 @@ static void mesh_init_origspace(Mesh *mesh)
|
|||
|
||||
OrigSpaceLoop *lof_array = (OrigSpaceLoop *)CustomData_get_layer_for_write(
|
||||
&mesh->ldata, CD_ORIGSPACE_MLOOP, mesh->totloop);
|
||||
const int numpoly = mesh->totpoly;
|
||||
// const int numloop = mesh->totloop;
|
||||
const Span<float3> positions = mesh->vert_positions();
|
||||
const Span<MPoly> polys = mesh->polys();
|
||||
const Span<MLoop> loops = mesh->loops();
|
||||
|
||||
const MPoly *poly = polys.data();
|
||||
int i, j, k;
|
||||
int j, k;
|
||||
|
||||
blender::Vector<blender::float2, 64> vcos_2d;
|
||||
|
||||
for (i = 0; i < numpoly; i++, poly++) {
|
||||
OrigSpaceLoop *lof = lof_array + poly->loopstart;
|
||||
for (const int i : polys.index_range()) {
|
||||
const MPoly &poly = polys[i];
|
||||
OrigSpaceLoop *lof = lof_array + poly.loopstart;
|
||||
|
||||
if (ELEM(poly->totloop, 3, 4)) {
|
||||
for (j = 0; j < poly->totloop; j++, lof++) {
|
||||
if (ELEM(poly.totloop, 3, 4)) {
|
||||
for (j = 0; j < poly.totloop; j++, lof++) {
|
||||
copy_v2_v2(lof->uv, default_osf[j]);
|
||||
}
|
||||
}
|
||||
else {
|
||||
const MLoop *l = &loops[poly->loopstart];
|
||||
const MLoop *l = &loops[poly.loopstart];
|
||||
float p_nor[3], co[3];
|
||||
float mat[3][3];
|
||||
|
||||
|
@ -1923,11 +1921,11 @@ static void mesh_init_origspace(Mesh *mesh)
|
|||
float translate[2], scale[2];
|
||||
|
||||
BKE_mesh_calc_poly_normal(
|
||||
poly, l, reinterpret_cast<const float(*)[3]>(positions.data()), p_nor);
|
||||
&poly, l, reinterpret_cast<const float(*)[3]>(positions.data()), p_nor);
|
||||
axis_dominant_v3_to_m3(mat, p_nor);
|
||||
|
||||
vcos_2d.resize(poly->totloop);
|
||||
for (j = 0; j < poly->totloop; j++, l++) {
|
||||
vcos_2d.resize(poly.totloop);
|
||||
for (j = 0; j < poly.totloop; j++, l++) {
|
||||
mul_v3_m3v3(co, mat, positions[l->v]);
|
||||
copy_v2_v2(vcos_2d[j], co);
|
||||
|
||||
|
@ -1956,7 +1954,7 @@ static void mesh_init_origspace(Mesh *mesh)
|
|||
|
||||
/* Finally, transform all vcos_2d into ((0, 0), (1, 1))
|
||||
* square and assign them as origspace. */
|
||||
for (j = 0; j < poly->totloop; j++, lof++) {
|
||||
for (j = 0; j < poly.totloop; j++, lof++) {
|
||||
add_v2_v2v2(lof->uv, vcos_2d[j], translate);
|
||||
mul_v2_v2(lof->uv, scale);
|
||||
}
|
||||
|
|
|
@ -82,8 +82,6 @@ static CLG_LogRef LOG = {"bke.mesh_convert"};
|
|||
static void make_edges_mdata_extend(Mesh &mesh)
|
||||
{
|
||||
int totedge = mesh.totedge;
|
||||
const MPoly *poly;
|
||||
int i;
|
||||
|
||||
const Span<MPoly> polys = mesh.polys();
|
||||
MutableSpan<MLoop> loops = mesh.loops_for_write();
|
||||
|
@ -123,11 +121,12 @@ static void make_edges_mdata_extend(Mesh &mesh)
|
|||
}
|
||||
BLI_edgehashIterator_free(ehi);
|
||||
|
||||
for (i = 0, poly = polys.data(); i < mesh.totpoly; i++, poly++) {
|
||||
MLoop *l = &loops[poly->loopstart];
|
||||
MLoop *l_prev = (l + (poly->totloop - 1));
|
||||
for (const int i : polys.index_range()) {
|
||||
const MPoly &poly = polys[i];
|
||||
MLoop *l = &loops[poly.loopstart];
|
||||
MLoop *l_prev = (l + (poly.totloop - 1));
|
||||
int j;
|
||||
for (j = 0; j < poly->totloop; j++, l++) {
|
||||
for (j = 0; j < poly.totloop; j++, l++) {
|
||||
/* lookup hashed edge index */
|
||||
l_prev->e = POINTER_AS_UINT(BLI_edgehash_lookup(eh, l_prev->v, l->v));
|
||||
l_prev = l;
|
||||
|
@ -457,13 +456,7 @@ void BKE_mesh_to_curve_nurblist(const Mesh *me, ListBase *nurblist, const int ed
|
|||
const Span<MPoly> polys = me->polys();
|
||||
const Span<MLoop> loops = me->loops();
|
||||
|
||||
const MEdge *edge;
|
||||
const MPoly *poly;
|
||||
|
||||
int edges_len = me->totedge;
|
||||
int polys_len = me->totpoly;
|
||||
int totedges = 0;
|
||||
int i;
|
||||
|
||||
/* only to detect edge polylines */
|
||||
int *edge_users;
|
||||
|
@ -471,21 +464,21 @@ void BKE_mesh_to_curve_nurblist(const Mesh *me, ListBase *nurblist, const int ed
|
|||
ListBase edges = {nullptr, nullptr};
|
||||
|
||||
/* get boundary edges */
|
||||
edge_users = (int *)MEM_calloc_arrayN(edges_len, sizeof(int), __func__);
|
||||
for (i = 0, poly = polys.data(); i < polys_len; i++, poly++) {
|
||||
const MLoop *ml = &loops[poly->loopstart];
|
||||
edge_users = (int *)MEM_calloc_arrayN(mesh_edges.size(), sizeof(int), __func__);
|
||||
for (const int i : polys.index_range()) {
|
||||
const MPoly &poly = polys[i];
|
||||
const MLoop *ml = &loops[poly.loopstart];
|
||||
int j;
|
||||
for (j = 0; j < poly->totloop; j++, ml++) {
|
||||
for (j = 0; j < poly.totloop; j++, ml++) {
|
||||
edge_users[ml->e]++;
|
||||
}
|
||||
}
|
||||
|
||||
/* create edges from all faces (so as to find edges not in any faces) */
|
||||
edge = mesh_edges.data();
|
||||
for (i = 0; i < edges_len; i++, edge++) {
|
||||
for (const int i : mesh_edges.index_range()) {
|
||||
if (edge_users[i] == edge_users_test) {
|
||||
EdgeLink *edl = MEM_cnew<EdgeLink>("EdgeLink");
|
||||
edl->edge = edge;
|
||||
edl->edge = &mesh_edges[i];
|
||||
|
||||
BLI_addtail(&edges, edl);
|
||||
totedges++;
|
||||
|
@ -518,7 +511,7 @@ void BKE_mesh_to_curve_nurblist(const Mesh *me, ListBase *nurblist, const int ed
|
|||
while (edl) {
|
||||
EdgeLink *edl_prev = edl->prev;
|
||||
|
||||
edge = (MEdge *)edl->edge;
|
||||
const MEdge *edge = (MEdge *)edl->edge;
|
||||
|
||||
if (edge->v1 == endVert) {
|
||||
endVert = edge->v2;
|
||||
|
@ -573,17 +566,18 @@ void BKE_mesh_to_curve_nurblist(const Mesh *me, ListBase *nurblist, const int ed
|
|||
/* create new 'nurb' within the curve */
|
||||
nu = MEM_new<Nurb>("MeshNurb", blender::dna::shallow_zero_initialize());
|
||||
|
||||
nu->pntsu = totpoly;
|
||||
nu->pntsu = polys.size();
|
||||
nu->pntsv = 1;
|
||||
nu->orderu = 4;
|
||||
nu->flagu = CU_NURB_ENDPOINT | (closed ? CU_NURB_CYCLIC : 0); /* endpoint */
|
||||
nu->resolu = 12;
|
||||
|
||||
nu->bp = (BPoint *)MEM_calloc_arrayN(totpoly, sizeof(BPoint), "bpoints");
|
||||
nu->bp = (BPoint *)MEM_calloc_arrayN(polys.size(), sizeof(BPoint), "bpoints");
|
||||
|
||||
/* add points */
|
||||
vl = (VertLink *)polyline.first;
|
||||
for (i = 0, bp = nu->bp; i < totpoly; i++, bp++, vl = (VertLink *)vl->next) {
|
||||
int i;
|
||||
for (i = 0, bp = nu->bp; i < polys.size(); i++, bp++, vl = (VertLink *)vl->next) {
|
||||
copy_v3_v3(bp->vec, positions[vl->index]);
|
||||
bp->f1 = SELECT;
|
||||
bp->radius = bp->weight = 1.0;
|
||||
|
|
|
@ -796,20 +796,18 @@ void BKE_mesh_calc_relative_deform(const MPoly *polys,
|
|||
const float (*vert_cos_org)[3],
|
||||
float (*vert_cos_new)[3])
|
||||
{
|
||||
const MPoly *poly;
|
||||
int i;
|
||||
|
||||
int *vert_accum = (int *)MEM_calloc_arrayN(size_t(totvert), sizeof(*vert_accum), __func__);
|
||||
|
||||
memset(vert_cos_new, '\0', sizeof(*vert_cos_new) * size_t(totvert));
|
||||
|
||||
for (i = 0, poly = polys; i < totpoly; i++, poly++) {
|
||||
const MLoop *loopstart = mloop + poly->loopstart;
|
||||
for (const int i : blender::IndexRange(totpoly)) {
|
||||
const MPoly &poly = polys[i];
|
||||
const MLoop *loopstart = mloop + poly.loopstart;
|
||||
|
||||
for (int j = 0; j < poly->totloop; j++) {
|
||||
uint v_prev = loopstart[(poly->totloop + (j - 1)) % poly->totloop].v;
|
||||
for (int j = 0; j < poly.totloop; j++) {
|
||||
uint v_prev = loopstart[(poly.totloop + (j - 1)) % poly.totloop].v;
|
||||
uint v_curr = loopstart[j].v;
|
||||
uint v_next = loopstart[(j + 1) % poly->totloop].v;
|
||||
uint v_next = loopstart[(j + 1) % poly.totloop].v;
|
||||
|
||||
float tvec[3];
|
||||
|
||||
|
@ -827,7 +825,7 @@ void BKE_mesh_calc_relative_deform(const MPoly *polys,
|
|||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < totvert; i++) {
|
||||
for (int i = 0; i < totvert; i++) {
|
||||
if (vert_accum[i]) {
|
||||
mul_v3_fl(vert_cos_new[i], 1.0f / float(vert_accum[i]));
|
||||
}
|
||||
|
|
|
@ -45,8 +45,6 @@ UvVertMap *BKE_mesh_uv_vert_map_create(const MPoly *polys,
|
|||
|
||||
UvVertMap *vmap;
|
||||
UvMapVert *buf;
|
||||
const MPoly *poly;
|
||||
uint a;
|
||||
int i, totuv, nverts;
|
||||
|
||||
BLI_buffer_declare_static(vec2f, tf_uv_buf, BLI_BUFFER_NOP, 32);
|
||||
|
@ -54,10 +52,10 @@ UvVertMap *BKE_mesh_uv_vert_map_create(const MPoly *polys,
|
|||
totuv = 0;
|
||||
|
||||
/* generate UvMapVert array */
|
||||
poly = polys;
|
||||
for (a = 0; a < totpoly; a++, poly++) {
|
||||
for (const int64_t a : blender::IndexRange(totpoly)) {
|
||||
const MPoly &poly = polys[a];
|
||||
if (!selected || (!(hide_poly && hide_poly[a]) && (select_poly && select_poly[a]))) {
|
||||
totuv += poly->totloop;
|
||||
totuv += poly.totloop;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -79,26 +77,26 @@ UvVertMap *BKE_mesh_uv_vert_map_create(const MPoly *polys,
|
|||
winding = static_cast<bool *>(MEM_callocN(sizeof(*winding) * totpoly, "winding"));
|
||||
}
|
||||
|
||||
poly = polys;
|
||||
for (a = 0; a < totpoly; a++, poly++) {
|
||||
for (const int64_t a : blender::IndexRange(totpoly)) {
|
||||
const MPoly &poly = polys[a];
|
||||
if (!selected || (!(hide_poly && hide_poly[a]) && (select_poly && select_poly[a]))) {
|
||||
float(*tf_uv)[2] = nullptr;
|
||||
|
||||
if (use_winding) {
|
||||
tf_uv = (float(*)[2])BLI_buffer_reinit_data(&tf_uv_buf, vec2f, size_t(poly->totloop));
|
||||
tf_uv = (float(*)[2])BLI_buffer_reinit_data(&tf_uv_buf, vec2f, size_t(poly.totloop));
|
||||
}
|
||||
|
||||
nverts = poly->totloop;
|
||||
nverts = poly.totloop;
|
||||
|
||||
for (i = 0; i < nverts; i++) {
|
||||
buf->loop_of_poly_index = ushort(i);
|
||||
buf->poly_index = a;
|
||||
buf->poly_index = uint(a);
|
||||
buf->separate = false;
|
||||
buf->next = vmap->vert[mloop[poly->loopstart + i].v];
|
||||
vmap->vert[mloop[poly->loopstart + i].v] = buf;
|
||||
buf->next = vmap->vert[mloop[poly.loopstart + i].v];
|
||||
vmap->vert[mloop[poly.loopstart + i].v] = buf;
|
||||
|
||||
if (use_winding) {
|
||||
copy_v2_v2(tf_uv[i], mloopuv[polys[a].loopstart + i]);
|
||||
copy_v2_v2(tf_uv[i], mloopuv[poly.loopstart + i]);
|
||||
}
|
||||
|
||||
buf++;
|
||||
|
@ -111,7 +109,7 @@ UvVertMap *BKE_mesh_uv_vert_map_create(const MPoly *polys,
|
|||
}
|
||||
|
||||
/* sort individual uvs for each vert */
|
||||
for (a = 0; a < totvert; a++) {
|
||||
for (uint a = 0; a < totvert; a++) {
|
||||
UvMapVert *newvlist = nullptr, *vlist = vmap->vert[a];
|
||||
UvMapVert *iterv, *v, *lastv, *next;
|
||||
const float *uv, *uv2;
|
||||
|
@ -395,21 +393,20 @@ void BKE_mesh_edge_loop_map_create(MeshElemMap **r_map,
|
|||
MeshElemMap *map = MEM_cnew_array<MeshElemMap>(size_t(totedge), __func__);
|
||||
int *indices = static_cast<int *>(MEM_mallocN(sizeof(int) * size_t(totloop) * 2, __func__));
|
||||
int *index_step;
|
||||
const MPoly *poly;
|
||||
int i;
|
||||
|
||||
/* count face users */
|
||||
for (i = 0, poly = polys; i < totpoly; poly++, i++) {
|
||||
for (const int64_t i : blender::IndexRange(totpoly)) {
|
||||
const MPoly &poly = polys[i];
|
||||
const MLoop *ml;
|
||||
int j = poly->totloop;
|
||||
for (ml = &mloop[poly->loopstart]; j--; ml++) {
|
||||
int j = poly.totloop;
|
||||
for (ml = &mloop[poly.loopstart]; j--; ml++) {
|
||||
map[ml->e].count += 2;
|
||||
}
|
||||
}
|
||||
|
||||
/* create offsets */
|
||||
index_step = indices;
|
||||
for (i = 0; i < totedge; i++) {
|
||||
for (int i = 0; i < totedge; i++) {
|
||||
map[i].indices = index_step;
|
||||
index_step += map[i].count;
|
||||
|
||||
|
@ -418,18 +415,19 @@ void BKE_mesh_edge_loop_map_create(MeshElemMap **r_map,
|
|||
}
|
||||
|
||||
/* assign loop-edge users */
|
||||
for (i = 0, poly = polys; i < totpoly; poly++, i++) {
|
||||
for (const int64_t i : blender::IndexRange(totpoly)) {
|
||||
const MPoly &poly = polys[i];
|
||||
const MLoop *ml;
|
||||
MeshElemMap *map_ele;
|
||||
const int max_loop = poly->loopstart + poly->totloop;
|
||||
int j = poly->loopstart;
|
||||
const int max_loop = poly.loopstart + poly.totloop;
|
||||
int j = poly.loopstart;
|
||||
for (ml = &mloop[j]; j < max_loop; j++, ml++) {
|
||||
map_ele = &map[ml->e];
|
||||
map_ele->indices[map_ele->count++] = j;
|
||||
map_ele->indices[map_ele->count++] = j + 1;
|
||||
}
|
||||
/* last edge/loop of poly, must point back to first loop! */
|
||||
map_ele->indices[map_ele->count - 1] = poly->loopstart;
|
||||
map_ele->indices[map_ele->count - 1] = poly.loopstart;
|
||||
}
|
||||
|
||||
*r_map = map;
|
||||
|
@ -447,21 +445,20 @@ void BKE_mesh_edge_poly_map_create(MeshElemMap **r_map,
|
|||
MeshElemMap *map = MEM_cnew_array<MeshElemMap>(size_t(totedge), __func__);
|
||||
int *indices = static_cast<int *>(MEM_mallocN(sizeof(int) * size_t(totloop), __func__));
|
||||
int *index_step;
|
||||
const MPoly *poly;
|
||||
int i;
|
||||
|
||||
/* count face users */
|
||||
for (i = 0, poly = polys; i < totpoly; poly++, i++) {
|
||||
for (const int64_t i : blender::IndexRange(totpoly)) {
|
||||
const MPoly &poly = polys[i];
|
||||
const MLoop *ml;
|
||||
int j = poly->totloop;
|
||||
for (ml = &mloop[poly->loopstart]; j--; ml++) {
|
||||
int j = poly.totloop;
|
||||
for (ml = &mloop[poly.loopstart]; j--; ml++) {
|
||||
map[ml->e].count++;
|
||||
}
|
||||
}
|
||||
|
||||
/* create offsets */
|
||||
index_step = indices;
|
||||
for (i = 0; i < totedge; i++) {
|
||||
for (int i = 0; i < totedge; i++) {
|
||||
map[i].indices = index_step;
|
||||
index_step += map[i].count;
|
||||
|
||||
|
@ -470,12 +467,13 @@ void BKE_mesh_edge_poly_map_create(MeshElemMap **r_map,
|
|||
}
|
||||
|
||||
/* assign poly-edge users */
|
||||
for (i = 0, poly = polys; i < totpoly; poly++, i++) {
|
||||
for (const int64_t i : blender::IndexRange(totpoly)) {
|
||||
const MPoly &poly = polys[i];
|
||||
const MLoop *ml;
|
||||
int j = poly->totloop;
|
||||
for (ml = &mloop[poly->loopstart]; j--; ml++) {
|
||||
int j = poly.totloop;
|
||||
for (ml = &mloop[poly.loopstart]; j--; ml++) {
|
||||
MeshElemMap *map_ele = &map[ml->e];
|
||||
map_ele->indices[map_ele->count++] = i;
|
||||
map_ele->indices[map_ele->count++] = int(i);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -252,7 +252,6 @@ bool BKE_mesh_validate_arrays(Mesh *mesh,
|
|||
|
||||
MEdge *edge;
|
||||
MLoop *ml;
|
||||
MPoly *poly;
|
||||
uint i, j;
|
||||
int *v;
|
||||
|
||||
|
@ -563,7 +562,9 @@ bool BKE_mesh_validate_arrays(Mesh *mesh,
|
|||
SortPoly *prev_sp, *sp = sort_polys;
|
||||
int prev_end;
|
||||
|
||||
for (i = 0, poly = polys; i < totpoly; i++, poly++, sp++) {
|
||||
for (const int64_t i : blender::IndexRange(totpoly)) {
|
||||
const MPoly &poly = polys[i];
|
||||
|
||||
sp->index = i;
|
||||
|
||||
/* Material index, isolated from other tests here. While large indices are clamped,
|
||||
|
@ -576,22 +577,22 @@ bool BKE_mesh_validate_arrays(Mesh *mesh,
|
|||
}
|
||||
}
|
||||
|
||||
if (poly->loopstart < 0 || poly->totloop < 3) {
|
||||
if (poly.loopstart < 0 || poly.totloop < 3) {
|
||||
/* Invalid loop data. */
|
||||
PRINT_ERR("\tPoly %u is invalid (loopstart: %d, totloop: %d)",
|
||||
sp->index,
|
||||
poly->loopstart,
|
||||
poly->totloop);
|
||||
poly.loopstart,
|
||||
poly.totloop);
|
||||
sp->invalid = true;
|
||||
}
|
||||
else if (poly->loopstart + poly->totloop > totloop) {
|
||||
else if (poly.loopstart + poly.totloop > totloop) {
|
||||
/* Invalid loop data. */
|
||||
PRINT_ERR(
|
||||
"\tPoly %u uses loops out of range "
|
||||
"(loopstart: %d, loopend: %d, max number of loops: %u)",
|
||||
sp->index,
|
||||
poly->loopstart,
|
||||
poly->loopstart + poly->totloop - 1,
|
||||
poly.loopstart,
|
||||
poly.loopstart + poly.totloop - 1,
|
||||
totloop - 1);
|
||||
sp->invalid = true;
|
||||
}
|
||||
|
@ -599,28 +600,28 @@ bool BKE_mesh_validate_arrays(Mesh *mesh,
|
|||
/* Poly itself is valid, for now. */
|
||||
int v1, v2; /* v1 is prev loop vert idx, v2 is current loop one. */
|
||||
sp->invalid = false;
|
||||
sp->verts = v = (int *)MEM_mallocN(sizeof(int) * poly->totloop, "Vert idx of SortPoly");
|
||||
sp->numverts = poly->totloop;
|
||||
sp->loopstart = poly->loopstart;
|
||||
sp->verts = v = (int *)MEM_mallocN(sizeof(int) * poly.totloop, "Vert idx of SortPoly");
|
||||
sp->numverts = poly.totloop;
|
||||
sp->loopstart = poly.loopstart;
|
||||
|
||||
/* Ideally we would only have to do that once on all vertices
|
||||
* before we start checking each poly, but several polys can use same vert,
|
||||
* so we have to ensure here all verts of current poly are cleared. */
|
||||
for (j = 0, ml = &mloops[sp->loopstart]; j < poly->totloop; j++, ml++) {
|
||||
for (j = 0, ml = &mloops[sp->loopstart]; j < poly.totloop; j++, ml++) {
|
||||
if (ml->v < totvert) {
|
||||
BLI_BITMAP_DISABLE(vert_tag, ml->v);
|
||||
}
|
||||
}
|
||||
|
||||
/* Test all poly's loops' vert idx. */
|
||||
for (j = 0, ml = &mloops[sp->loopstart]; j < poly->totloop; j++, ml++, v++) {
|
||||
for (j = 0, ml = &mloops[sp->loopstart]; j < poly.totloop; j++, ml++, v++) {
|
||||
if (ml->v >= totvert) {
|
||||
/* Invalid vert idx. */
|
||||
PRINT_ERR("\tLoop %u has invalid vert reference (%u)", sp->loopstart + j, ml->v);
|
||||
sp->invalid = true;
|
||||
}
|
||||
else if (BLI_BITMAP_TEST(vert_tag, ml->v)) {
|
||||
PRINT_ERR("\tPoly %u has duplicated vert reference at corner (%u)", i, j);
|
||||
PRINT_ERR("\tPoly %u has duplicated vert reference at corner (%u)", uint(i), j);
|
||||
sp->invalid = true;
|
||||
}
|
||||
else {
|
||||
|
@ -630,13 +631,14 @@ bool BKE_mesh_validate_arrays(Mesh *mesh,
|
|||
}
|
||||
|
||||
if (sp->invalid) {
|
||||
sp++;
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Test all poly's loops. */
|
||||
for (j = 0, ml = &mloops[sp->loopstart]; j < poly->totloop; j++, ml++) {
|
||||
for (j = 0, ml = &mloops[sp->loopstart]; j < poly.totloop; j++, ml++) {
|
||||
v1 = ml->v;
|
||||
v2 = mloops[sp->loopstart + (j + 1) % poly->totloop].v;
|
||||
v2 = mloops[sp->loopstart + (j + 1) % poly.totloop].v;
|
||||
if (!BLI_edgehash_haskey(edge_hash, v1, v2)) {
|
||||
/* Edge not existing. */
|
||||
PRINT_ERR("\tPoly %u needs missing edge (%d, %d)", sp->index, v1, v2);
|
||||
|
@ -696,6 +698,7 @@ bool BKE_mesh_validate_arrays(Mesh *mesh,
|
|||
qsort(sp->verts, sp->numverts, sizeof(int), int_cmp);
|
||||
}
|
||||
}
|
||||
sp++;
|
||||
}
|
||||
|
||||
MEM_freeN(vert_tag);
|
||||
|
@ -1213,18 +1216,18 @@ void mesh_strip_polysloops(Mesh *me)
|
|||
MutableSpan<MPoly> polys = me->polys_for_write();
|
||||
MutableSpan<MLoop> loops = me->loops_for_write();
|
||||
|
||||
MPoly *poly;
|
||||
MLoop *l;
|
||||
int a, b;
|
||||
/* New loops idx! */
|
||||
int *new_idx = (int *)MEM_mallocN(sizeof(int) * me->totloop, __func__);
|
||||
|
||||
for (a = b = 0, poly = polys.data(); a < me->totpoly; a++, poly++) {
|
||||
for (a = b = 0; a < me->totpoly; a++) {
|
||||
const MPoly &poly = polys[a];
|
||||
bool invalid = false;
|
||||
int i = poly->loopstart;
|
||||
int stop = i + poly->totloop;
|
||||
int i = poly.loopstart;
|
||||
int stop = i + poly.totloop;
|
||||
|
||||
if (stop > me->totloop || stop < i || poly->loopstart < 0) {
|
||||
if (stop > me->totloop || stop < i || poly.loopstart < 0) {
|
||||
invalid = true;
|
||||
}
|
||||
else {
|
||||
|
@ -1239,9 +1242,9 @@ void mesh_strip_polysloops(Mesh *me)
|
|||
}
|
||||
}
|
||||
|
||||
if (poly->totloop >= 3 && !invalid) {
|
||||
if (poly.totloop >= 3 && !invalid) {
|
||||
if (a != b) {
|
||||
memcpy(&polys[b], poly, sizeof(polys[b]));
|
||||
memcpy(&polys[b], &poly, sizeof(polys[b]));
|
||||
CustomData_copy_data(&me->pdata, &me->pdata, a, b, 1);
|
||||
}
|
||||
b++;
|
||||
|
|
|
@ -1155,11 +1155,11 @@ static DupliObject *face_dupli_from_mesh(const DupliContext *ctx,
|
|||
const float scale_fac,
|
||||
|
||||
/* Mesh variables. */
|
||||
const MPoly *polys,
|
||||
const MPoly &poly,
|
||||
const MLoop *mloopstart,
|
||||
const Span<float3> vert_positions)
|
||||
{
|
||||
const int coords_len = polys->totloop;
|
||||
const int coords_len = poly.totloop;
|
||||
Array<float3, 64> coords(coords_len);
|
||||
|
||||
const MLoop *ml = mloopstart;
|
||||
|
@ -1206,13 +1206,12 @@ static void make_child_duplis_faces_from_mesh(const DupliContext *ctx,
|
|||
Object *inst_ob)
|
||||
{
|
||||
FaceDupliData_Mesh *fdd = (FaceDupliData_Mesh *)userdata;
|
||||
const MPoly *polys = fdd->polys, *poly;
|
||||
const MPoly *polys = fdd->polys;
|
||||
const MLoop *mloop = fdd->mloop;
|
||||
const float(*orco)[3] = fdd->orco;
|
||||
const float2 *mloopuv = fdd->mloopuv;
|
||||
const int totface = fdd->totface;
|
||||
const bool use_scale = fdd->params.use_scale;
|
||||
int a;
|
||||
|
||||
float child_imat[4][4];
|
||||
|
||||
|
@ -1221,8 +1220,9 @@ static void make_child_duplis_faces_from_mesh(const DupliContext *ctx,
|
|||
mul_m4_m4m4(child_imat, inst_ob->world_to_object, ctx->object->object_to_world);
|
||||
const float scale_fac = ctx->object->instance_faces_scale;
|
||||
|
||||
for (a = 0, poly = polys; a < totface; a++, poly++) {
|
||||
const MLoop *loopstart = mloop + poly->loopstart;
|
||||
for (const int a : blender::IndexRange(totface)) {
|
||||
const MPoly &poly = polys[a];
|
||||
const MLoop *loopstart = mloop + poly.loopstart;
|
||||
DupliObject *dob = face_dupli_from_mesh(fdd->params.ctx,
|
||||
inst_ob,
|
||||
child_imat,
|
||||
|
@ -1233,15 +1233,15 @@ static void make_child_duplis_faces_from_mesh(const DupliContext *ctx,
|
|||
loopstart,
|
||||
fdd->vert_positions);
|
||||
|
||||
const float w = 1.0f / float(poly->totloop);
|
||||
const float w = 1.0f / float(poly.totloop);
|
||||
if (orco) {
|
||||
for (int j = 0; j < poly->totloop; j++) {
|
||||
for (int j = 0; j < poly.totloop; j++) {
|
||||
madd_v3_v3fl(dob->orco, orco[loopstart[j].v], w);
|
||||
}
|
||||
}
|
||||
if (mloopuv) {
|
||||
for (int j = 0; j < poly->totloop; j++) {
|
||||
madd_v2_v2fl(dob->uv, mloopuv[poly->loopstart + j], w);
|
||||
for (int j = 0; j < poly.totloop; j++) {
|
||||
madd_v2_v2fl(dob->uv, mloopuv[poly.loopstart + j], w);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -567,11 +567,10 @@ static void ccd_update_deflector_hash(Depsgraph *depsgraph,
|
|||
static int count_mesh_quads(Mesh *me)
|
||||
{
|
||||
int a, result = 0;
|
||||
const MPoly *poly = BKE_mesh_polys(me);
|
||||
|
||||
if (poly) {
|
||||
for (a = me->totpoly; a > 0; a--, poly++) {
|
||||
if (poly->totloop == 4) {
|
||||
const MPoly *polys = BKE_mesh_polys(me);
|
||||
if (polys) {
|
||||
for (a = me->totpoly; a > 0; a--) {
|
||||
if (polys[a].totloop == 4) {
|
||||
result++;
|
||||
}
|
||||
}
|
||||
|
@ -583,8 +582,6 @@ static void add_mesh_quad_diag_springs(Object *ob)
|
|||
{
|
||||
Mesh *me = ob->data;
|
||||
// BodyPoint *bp; /* UNUSED */
|
||||
int a;
|
||||
|
||||
if (ob->soft) {
|
||||
int nofquads;
|
||||
// float s_shear = ob->soft->shearstiff*ob->soft->shearstiff;
|
||||
|
@ -592,7 +589,7 @@ static void add_mesh_quad_diag_springs(Object *ob)
|
|||
nofquads = count_mesh_quads(me);
|
||||
if (nofquads) {
|
||||
const MLoop *mloop = BKE_mesh_loops(me);
|
||||
const MPoly *poly = BKE_mesh_polys(me);
|
||||
const MPoly *polys = BKE_mesh_polys(me);
|
||||
BodySpring *bs;
|
||||
|
||||
/* resize spring-array to hold additional quad springs */
|
||||
|
@ -600,10 +597,10 @@ static void add_mesh_quad_diag_springs(Object *ob)
|
|||
sizeof(BodySpring) * (ob->soft->totspring + nofquads * 2));
|
||||
|
||||
/* fill the tail */
|
||||
a = 0;
|
||||
bs = &ob->soft->bspring[ob->soft->totspring];
|
||||
// bp = ob->soft->bpoint; /* UNUSED */
|
||||
for (a = me->totpoly; a > 0; a--, poly++) {
|
||||
for (int a = 0; a < me->totpoly; a++) {
|
||||
const MPoly *poly = &polys[a];
|
||||
if (poly->totloop == 4) {
|
||||
bs->v1 = mloop[poly->loopstart + 0].v;
|
||||
bs->v2 = mloop[poly->loopstart + 2].v;
|
||||
|
|
|
@ -540,7 +540,7 @@ static void ss_sync_ccg_from_derivedmesh(CCGSubSurf *ss,
|
|||
MEdge *edges = dm->getEdgeArray(dm);
|
||||
MEdge *edge;
|
||||
MLoop *mloop = dm->getLoopArray(dm), *ml;
|
||||
MPoly *polys = dm->getPolyArray(dm), *poly;
|
||||
MPoly *polys = dm->getPolyArray(dm);
|
||||
int totvert = dm->getNumVerts(dm);
|
||||
int totedge = dm->getNumEdges(dm);
|
||||
int i, j;
|
||||
|
@ -581,15 +581,15 @@ static void ss_sync_ccg_from_derivedmesh(CCGSubSurf *ss,
|
|||
((int *)ccgSubSurf_getEdgeUserData(ss, e))[1] = (index) ? *index++ : i;
|
||||
}
|
||||
|
||||
poly = polys;
|
||||
index = (int *)dm->getPolyDataArray(dm, CD_ORIGINDEX);
|
||||
for (i = 0; i < dm->numPolyData; i++, poly++) {
|
||||
for (i = 0; i < dm->numPolyData; i++) {
|
||||
const MPoly &poly = polys[i];
|
||||
CCGFace *f;
|
||||
|
||||
fverts.reinitialize(poly->totloop);
|
||||
fverts.reinitialize(poly.totloop);
|
||||
|
||||
ml = mloop + poly->loopstart;
|
||||
for (j = 0; j < poly->totloop; j++, ml++) {
|
||||
ml = mloop + poly.loopstart;
|
||||
for (j = 0; j < poly.totloop; j++, ml++) {
|
||||
fverts[j] = POINTER_FROM_UINT(ml->v);
|
||||
}
|
||||
|
||||
|
@ -597,7 +597,7 @@ static void ss_sync_ccg_from_derivedmesh(CCGSubSurf *ss,
|
|||
* it is not really possible to continue without modifying
|
||||
* other parts of code significantly to handle missing faces.
|
||||
* since this really shouldn't even be possible we just bail. */
|
||||
if (ccgSubSurf_syncFace(ss, POINTER_FROM_INT(i), poly->totloop, fverts.data(), &f) ==
|
||||
if (ccgSubSurf_syncFace(ss, POINTER_FROM_INT(i), poly.totloop, fverts.data(), &f) ==
|
||||
eCCGError_InvalidValue) {
|
||||
static int hasGivenError = 0;
|
||||
|
||||
|
|
|
@ -117,10 +117,10 @@ static void extract_edituv_stretch_area_finish(const MeshRenderData *mr,
|
|||
}
|
||||
else {
|
||||
BLI_assert(mr->extract_type == MR_EXTRACT_MESH);
|
||||
const MPoly *poly = mr->polys.data();
|
||||
for (int poly_index = 0, l_index = 0; poly_index < mr->poly_len; poly_index++, poly++) {
|
||||
for (int i = 0; i < poly->totloop; i++, l_index++) {
|
||||
loop_stretch[l_index] = area_ratio[poly_index];
|
||||
for (const int poly_i : mr->polys.index_range()) {
|
||||
const MPoly &poly = mr->polys[poly_i];
|
||||
for (const int loop_i : IndexRange(poly.loopstart, poly.totloop)) {
|
||||
loop_stretch[loop_i] = area_ratio[poly_i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -96,12 +96,12 @@ static void statvis_calc_overhang(const MeshRenderData *mr, float *r_overhang)
|
|||
}
|
||||
}
|
||||
else {
|
||||
const MPoly *poly = mr->polys.data();
|
||||
for (int poly_index = 0, l_index = 0; poly_index < mr->poly_len; poly_index++, poly++) {
|
||||
float fac = angle_normalized_v3v3(mr->poly_normals[poly_index], dir) / float(M_PI);
|
||||
for (const int poly_i : mr->polys.index_range()) {
|
||||
const MPoly &poly = mr->polys[poly_i];
|
||||
float fac = angle_normalized_v3v3(mr->poly_normals[poly_i], dir) / float(M_PI);
|
||||
fac = overhang_remap(fac, min, max, minmax_irange);
|
||||
for (int i = 0; i < poly->totloop; i++, l_index++) {
|
||||
r_overhang[l_index] = fac;
|
||||
for (const int loop_i : IndexRange(poly.loopstart, poly.totloop)) {
|
||||
r_overhang[loop_i] = fac;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -247,12 +247,12 @@ static void statvis_calc_thickness(const MeshRenderData *mr, float *r_thickness)
|
|||
}
|
||||
}
|
||||
|
||||
const MPoly *poly = mr->polys.data();
|
||||
for (int poly_index = 0, l_index = 0; poly_index < mr->poly_len; poly_index++, poly++) {
|
||||
float fac = face_dists[poly_index];
|
||||
for (const int poly_i : mr->polys.index_range()) {
|
||||
const MPoly &poly = mr->polys[poly_i];
|
||||
float fac = face_dists[poly_i];
|
||||
fac = thickness_remap(fac, min, max, minmax_irange);
|
||||
for (int i = 0; i < poly->totloop; i++, l_index++) {
|
||||
r_thickness[l_index] = fac;
|
||||
for (const int loop_i : IndexRange(poly.loopstart, poly.totloop)) {
|
||||
r_thickness[loop_i] = fac;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -440,18 +440,19 @@ static void statvis_calc_distort(const MeshRenderData *mr, float *r_distort)
|
|||
}
|
||||
}
|
||||
else {
|
||||
const MPoly *poly = mr->polys.data();
|
||||
for (int poly_index = 0, l_index = 0; poly_index < mr->poly_len; poly_index++, poly++) {
|
||||
int l_index = 0;
|
||||
for (const int poly_index : mr->polys.index_range()) {
|
||||
const MPoly &poly = mr->polys[poly_index];
|
||||
float fac = -1.0f;
|
||||
|
||||
if (poly->totloop > 3) {
|
||||
if (poly.totloop > 3) {
|
||||
const float *f_no = mr->poly_normals[poly_index];
|
||||
fac = 0.0f;
|
||||
|
||||
for (int i = 1; i <= poly->totloop; i++) {
|
||||
const MLoop *l_prev = &mr->loops[poly->loopstart + (i - 1) % poly->totloop];
|
||||
const MLoop *l_curr = &mr->loops[poly->loopstart + (i + 0) % poly->totloop];
|
||||
const MLoop *l_next = &mr->loops[poly->loopstart + (i + 1) % poly->totloop];
|
||||
for (int i = 1; i <= poly.totloop; i++) {
|
||||
const MLoop *l_prev = &mr->loops[poly.loopstart + (i - 1) % poly.totloop];
|
||||
const MLoop *l_curr = &mr->loops[poly.loopstart + (i + 0) % poly.totloop];
|
||||
const MLoop *l_next = &mr->loops[poly.loopstart + (i + 1) % poly.totloop];
|
||||
float no_corner[3];
|
||||
normal_tri_v3(no_corner,
|
||||
mr->vert_positions[l_prev->v],
|
||||
|
@ -467,7 +468,7 @@ static void statvis_calc_distort(const MeshRenderData *mr, float *r_distort)
|
|||
}
|
||||
|
||||
fac = distort_remap(fac, min, max, minmax_irange);
|
||||
for (int i = 0; i < poly->totloop; i++, l_index++) {
|
||||
for (int i = 0; i < poly.totloop; i++, l_index++) {
|
||||
r_distort[l_index] = fac;
|
||||
}
|
||||
}
|
||||
|
@ -526,14 +527,14 @@ static void statvis_calc_sharp(const MeshRenderData *mr, float *r_sharp)
|
|||
}
|
||||
else {
|
||||
/* first assign float values to verts */
|
||||
const MPoly *poly = mr->polys.data();
|
||||
|
||||
EdgeHash *eh = BLI_edgehash_new_ex(__func__, mr->edge_len);
|
||||
|
||||
for (int poly_index = 0; poly_index < mr->poly_len; poly_index++, poly++) {
|
||||
for (int i = 0; i < poly->totloop; i++) {
|
||||
const MLoop *l_curr = &mr->loops[poly->loopstart + (i + 0) % poly->totloop];
|
||||
const MLoop *l_next = &mr->loops[poly->loopstart + (i + 1) % poly->totloop];
|
||||
for (const int poly_index : mr->polys.index_range()) {
|
||||
const MPoly &poly = mr->polys[poly_index];
|
||||
for (int i = 0; i < poly.totloop; i++) {
|
||||
const MLoop *l_curr = &mr->loops[poly.loopstart + (i + 0) % poly.totloop];
|
||||
const MLoop *l_next = &mr->loops[poly.loopstart + (i + 1) % poly.totloop];
|
||||
float angle;
|
||||
void **pval;
|
||||
bool value_is_init = BLI_edgehash_ensure_p(eh, l_curr->v, l_next->v, &pval);
|
||||
|
|
|
@ -100,7 +100,6 @@ static void join_mesh_single(Depsgraph *depsgraph,
|
|||
float3 *vert_positions = *vert_positions_pp;
|
||||
MEdge *edge = *medge_pp;
|
||||
MLoop *mloop = *mloop_pp;
|
||||
MPoly *poly = *mpoly_pp;
|
||||
|
||||
if (me->totvert) {
|
||||
/* standard data */
|
||||
|
@ -266,8 +265,8 @@ static void join_mesh_single(Depsgraph *depsgraph,
|
|||
}
|
||||
}
|
||||
|
||||
for (a = 0; a < me->totpoly; a++, poly++) {
|
||||
poly->loopstart += *loopofs;
|
||||
for (const int i : blender::IndexRange(me->totpoly)) {
|
||||
(*mpoly_pp)[i].loopstart += *loopofs;
|
||||
}
|
||||
|
||||
/* Face maps. */
|
||||
|
|
|
@ -166,8 +166,8 @@ static void weld_assert_poly_and_loop_kill_len(WeldMesh *weld_mesh,
|
|||
{
|
||||
int poly_kills = 0;
|
||||
int loop_kills = mloop.size();
|
||||
const MPoly *poly = &polys[0];
|
||||
for (int i = 0; i < polys.size(); i++, poly++) {
|
||||
for (const int i : polys.index_range()) {
|
||||
const MPoly &poly = polys[i];
|
||||
int poly_ctx = weld_mesh->poly_map[i];
|
||||
if (poly_ctx != OUT_OF_CONTEXT) {
|
||||
const WeldPoly *wp = &weld_mesh->wpoly[poly_ctx];
|
||||
|
@ -206,7 +206,7 @@ static void weld_assert_poly_and_loop_kill_len(WeldMesh *weld_mesh,
|
|||
}
|
||||
}
|
||||
else {
|
||||
loop_kills -= poly->totloop;
|
||||
loop_kills -= poly.totloop;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1606,7 +1606,6 @@ static Mesh *create_merged_mesh(const Mesh &mesh,
|
|||
|
||||
/* Polys/Loops. */
|
||||
|
||||
MPoly *r_mp = dst_polys.data();
|
||||
MLoop *r_ml = dst_loops.data();
|
||||
int r_i = 0;
|
||||
int loop_cur = 0;
|
||||
|
@ -1648,9 +1647,8 @@ static Mesh *create_merged_mesh(const Mesh &mesh,
|
|||
}
|
||||
|
||||
CustomData_copy_data(&mesh.pdata, &result->pdata, i, r_i, 1);
|
||||
r_mp->loopstart = loop_start;
|
||||
r_mp->totloop = loop_cur - loop_start;
|
||||
r_mp++;
|
||||
dst_polys[r_i].loopstart = loop_start;
|
||||
dst_polys[r_i].totloop = loop_cur - loop_start;
|
||||
r_i++;
|
||||
}
|
||||
|
||||
|
@ -1677,9 +1675,8 @@ static Mesh *create_merged_mesh(const Mesh &mesh,
|
|||
loop_cur++;
|
||||
}
|
||||
|
||||
r_mp->loopstart = loop_start;
|
||||
r_mp->totloop = loop_cur - loop_start;
|
||||
r_mp++;
|
||||
dst_polys[r_i].loopstart = loop_start;
|
||||
dst_polys[r_i].totloop = loop_cur - loop_start;
|
||||
r_i++;
|
||||
}
|
||||
|
||||
|
|
|
@ -270,13 +270,14 @@ static void process_loop_normals(CDStreamConfig &config, const N3fArraySamplePtr
|
|||
float(*lnors)[3] = static_cast<float(*)[3]>(
|
||||
MEM_malloc_arrayN(loop_count, sizeof(float[3]), "ABC::FaceNormals"));
|
||||
|
||||
MPoly *poly = mesh->polys_for_write().data();
|
||||
const Span<MPoly> polys = mesh->polys();
|
||||
const N3fArraySample &loop_normals = *loop_normals_ptr;
|
||||
int abc_index = 0;
|
||||
for (int i = 0, e = mesh->totpoly; i < e; i++, poly++) {
|
||||
for (const int i : polys.index_range()) {
|
||||
const MPoly &poly = polys[i];
|
||||
/* As usual, ABC orders the loops in reverse. */
|
||||
for (int j = poly->totloop - 1; j >= 0; j--, abc_index++) {
|
||||
int blender_index = poly->loopstart + j;
|
||||
for (int j = poly.totloop - 1; j >= 0; j--, abc_index++) {
|
||||
int blender_index = poly.loopstart + j;
|
||||
copy_zup_from_yup(lnors[blender_index], loop_normals[abc_index].getValue());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -610,8 +610,8 @@ void MeshImporter::read_polys(COLLADAFW::Mesh *collada_mesh,
|
|||
|
||||
MutableSpan<MPoly> polys = me->polys_for_write();
|
||||
MutableSpan<MLoop> loops = me->loops_for_write();
|
||||
MPoly *poly = polys.data();
|
||||
MLoop *mloop = loops.data();
|
||||
int poly_index = 0;
|
||||
int loop_index = 0;
|
||||
|
||||
MaterialIdPrimitiveArrayMap mat_prim_map;
|
||||
|
@ -636,7 +636,7 @@ void MeshImporter::read_polys(COLLADAFW::Mesh *collada_mesh,
|
|||
int collada_meshtype = mp->getPrimitiveType();
|
||||
|
||||
/* since we cannot set poly->mat_nr here, we store a portion of me->mpoly in Primitive */
|
||||
Primitive prim = {poly, material_indices, 0};
|
||||
Primitive prim = {poly_index, &material_indices[poly_index], 0};
|
||||
|
||||
/* If MeshPrimitive is TRIANGLE_FANS we split it into triangles
|
||||
* The first triangle-fan vertex will be the first vertex in every triangle
|
||||
|
@ -654,22 +654,19 @@ void MeshImporter::read_polys(COLLADAFW::Mesh *collada_mesh,
|
|||
/* For each triangle store indices of its 3 vertices */
|
||||
uint triangle_vertex_indices[3] = {
|
||||
first_vertex, position_indices[1], position_indices[2]};
|
||||
set_poly_indices(poly, mloop, loop_index, triangle_vertex_indices, 3);
|
||||
set_poly_indices(&polys[poly_index], mloop, loop_index, triangle_vertex_indices, 3);
|
||||
|
||||
if (mp_has_normals) { /* vertex normals, same implementation as for the triangles */
|
||||
/* The same for vertices normals. */
|
||||
uint vertex_normal_indices[3] = {first_normal, normal_indices[1], normal_indices[2]};
|
||||
if (!is_flat_face(vertex_normal_indices, nor, 3)) {
|
||||
poly->flag |= ME_SMOOTH;
|
||||
polys[poly_index].flag |= ME_SMOOTH;
|
||||
}
|
||||
normal_indices++;
|
||||
}
|
||||
|
||||
poly++;
|
||||
if (material_indices) {
|
||||
material_indices++;
|
||||
}
|
||||
mloop += 3;
|
||||
poly_index++;
|
||||
loop_index += 3;
|
||||
prim.totpoly++;
|
||||
}
|
||||
|
@ -702,7 +699,8 @@ void MeshImporter::read_polys(COLLADAFW::Mesh *collada_mesh,
|
|||
continue; /* TODO: add support for holes */
|
||||
}
|
||||
|
||||
bool broken_loop = set_poly_indices(poly, mloop, loop_index, position_indices, vcount);
|
||||
bool broken_loop = set_poly_indices(
|
||||
&polys[poly_index], mloop, loop_index, position_indices, vcount);
|
||||
if (broken_loop) {
|
||||
invalid_loop_holes += 1;
|
||||
}
|
||||
|
@ -732,7 +730,7 @@ void MeshImporter::read_polys(COLLADAFW::Mesh *collada_mesh,
|
|||
/* If it turns out that we have complete custom normals for each MPoly
|
||||
* and we want to use custom normals, this will be overridden. */
|
||||
if (!is_flat_face(normal_indices, nor, vcount)) {
|
||||
poly->flag |= ME_SMOOTH;
|
||||
polys[poly_index].flag |= ME_SMOOTH;
|
||||
}
|
||||
|
||||
if (use_custom_normals) {
|
||||
|
@ -768,10 +766,7 @@ void MeshImporter::read_polys(COLLADAFW::Mesh *collada_mesh,
|
|||
}
|
||||
}
|
||||
|
||||
poly++;
|
||||
if (material_indices) {
|
||||
material_indices++;
|
||||
}
|
||||
poly_index++;
|
||||
mloop += vcount;
|
||||
loop_index += vcount;
|
||||
start_index += vcount;
|
||||
|
|
|
@ -81,7 +81,7 @@ class MeshImporter : public MeshImporterBase {
|
|||
* it holds a portion of Mesh faces and corresponds to a DAE primitive list
|
||||
* (<triangles>, <polylist>, etc.) */
|
||||
struct Primitive {
|
||||
MPoly *poly;
|
||||
int poly_index;
|
||||
int *material_indices;
|
||||
unsigned int totpoly;
|
||||
};
|
||||
|
|
|
@ -285,7 +285,6 @@ static void mesh_merge_transform(Mesh *result,
|
|||
int i;
|
||||
MEdge *edge;
|
||||
MLoop *ml;
|
||||
MPoly *poly;
|
||||
float(*result_positions)[3] = BKE_mesh_vert_positions_for_write(result);
|
||||
blender::MutableSpan<MEdge> result_edges = result->edges_for_write();
|
||||
blender::MutableSpan<MPoly> result_polys = result->polys_for_write();
|
||||
|
@ -323,9 +322,8 @@ static void mesh_merge_transform(Mesh *result,
|
|||
}
|
||||
|
||||
/* adjust cap poly loopstart indices */
|
||||
poly = &result_polys[cap_polys_index];
|
||||
for (i = 0; i < cap_npolys; i++, poly++) {
|
||||
poly->loopstart += cap_loops_index;
|
||||
for (const int i : blender::IndexRange(cap_polys_index, cap_npolys)) {
|
||||
result_polys[i].loopstart += cap_loops_index;
|
||||
}
|
||||
|
||||
/* adjust cap loop vertex and edge indices */
|
||||
|
@ -378,7 +376,6 @@ static Mesh *arrayModifier_doArray(ArrayModifierData *amd,
|
|||
{
|
||||
MEdge *edge;
|
||||
MLoop *ml;
|
||||
MPoly *poly;
|
||||
int i, j, c, count;
|
||||
float length = amd->length;
|
||||
/* offset matrix */
|
||||
|
@ -615,9 +612,8 @@ static Mesh *arrayModifier_doArray(ArrayModifierData *amd,
|
|||
edge->v2 += c * chunk_nverts;
|
||||
}
|
||||
|
||||
poly = &result_polys[c * chunk_npolys];
|
||||
for (i = 0; i < chunk_npolys; i++, poly++) {
|
||||
poly->loopstart += c * chunk_nloops;
|
||||
for (const int i : blender::IndexRange(c * chunk_npolys, chunk_npolys)) {
|
||||
result_polys[i].loopstart += c * chunk_nloops;
|
||||
}
|
||||
|
||||
/* adjust loop vertex and edge indices */
|
||||
|
|
|
@ -413,42 +413,41 @@ Mesh *MOD_solidify_extrude_modifyMesh(ModifierData *md, const ModifierEvalContex
|
|||
/* flip normals */
|
||||
|
||||
if (do_shell) {
|
||||
uint i;
|
||||
|
||||
MPoly *poly = &polys[polys_num];
|
||||
for (i = 0; i < mesh->totpoly; i++, poly++) {
|
||||
const int loop_end = poly->totloop - 1;
|
||||
for (const int64_t i : blender::IndexRange(mesh->totpoly)) {
|
||||
const int64_t poly_i = polys_num + i;
|
||||
MPoly &poly = polys[poly_i];
|
||||
const int loop_end = poly.totloop - 1;
|
||||
MLoop *ml2;
|
||||
uint e;
|
||||
int j;
|
||||
|
||||
/* reverses the loop direction (MLoop.v as well as custom-data)
|
||||
* MLoop.e also needs to be corrected too, done in a separate loop below. */
|
||||
ml2 = &loops[poly->loopstart + mesh->totloop];
|
||||
ml2 = &loops[poly.loopstart + mesh->totloop];
|
||||
#if 0
|
||||
for (j = 0; j < poly->totloop; j++) {
|
||||
for (j = 0; j < poly.totloop; j++) {
|
||||
CustomData_copy_data(&mesh->ldata,
|
||||
&result->ldata,
|
||||
poly->loopstart + j,
|
||||
poly->loopstart + (loop_end - j) + mesh->totloop,
|
||||
poly.loopstart + j,
|
||||
poly.loopstart + (loop_end - j) + mesh->totloop,
|
||||
1);
|
||||
}
|
||||
#else
|
||||
/* slightly more involved, keep the first vertex the same for the copy,
|
||||
* ensures the diagonals in the new face match the original. */
|
||||
j = 0;
|
||||
for (int j_prev = loop_end; j < poly->totloop; j_prev = j++) {
|
||||
for (int j_prev = loop_end; j < poly.totloop; j_prev = j++) {
|
||||
CustomData_copy_data(&mesh->ldata,
|
||||
&result->ldata,
|
||||
poly->loopstart + j,
|
||||
poly->loopstart + (loop_end - j_prev) + mesh->totloop,
|
||||
poly.loopstart + j,
|
||||
poly.loopstart + (loop_end - j_prev) + mesh->totloop,
|
||||
1);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (mat_ofs) {
|
||||
dst_material_index[poly - polys.data()] += mat_ofs;
|
||||
CLAMP(dst_material_index[poly - polys.data()], 0, mat_nr_max);
|
||||
dst_material_index[i] += mat_ofs;
|
||||
CLAMP(dst_material_index[i], 0, mat_nr_max);
|
||||
}
|
||||
|
||||
e = ml2[0].e;
|
||||
|
@ -457,9 +456,9 @@ Mesh *MOD_solidify_extrude_modifyMesh(ModifierData *md, const ModifierEvalContex
|
|||
}
|
||||
ml2[loop_end].e = e;
|
||||
|
||||
poly->loopstart += mesh->totloop;
|
||||
poly.loopstart += mesh->totloop;
|
||||
|
||||
for (j = 0; j < poly->totloop; j++) {
|
||||
for (j = 0; j < poly.totloop; j++) {
|
||||
ml2[j].e += edges_num;
|
||||
ml2[j].v += verts_num;
|
||||
}
|
||||
|
@ -715,21 +714,20 @@ Mesh *MOD_solidify_extrude_modifyMesh(ModifierData *md, const ModifierEvalContex
|
|||
}
|
||||
}
|
||||
|
||||
const MPoly *poly;
|
||||
for (i = 0, poly = polys.data(); i < polys_num; i++, poly++) {
|
||||
for (const int64_t i : blender::IndexRange(polys_num)) {
|
||||
/* #BKE_mesh_calc_poly_angles logic is inlined here */
|
||||
float nor_prev[3];
|
||||
float nor_next[3];
|
||||
|
||||
int i_curr = poly->totloop - 1;
|
||||
int i_curr = polys[i].totloop - 1;
|
||||
int i_next = 0;
|
||||
|
||||
const MLoop *ml = &loops[poly->loopstart];
|
||||
const MLoop *ml = &loops[polys[i].loopstart];
|
||||
|
||||
sub_v3_v3v3(nor_prev, vert_positions[ml[i_curr - 1].v], vert_positions[ml[i_curr].v]);
|
||||
normalize_v3(nor_prev);
|
||||
|
||||
while (i_next < poly->totloop) {
|
||||
while (i_next < polys[i].totloop) {
|
||||
float angle;
|
||||
sub_v3_v3v3(nor_next, vert_positions[ml[i_curr].v], vert_positions[ml[i_next].v]);
|
||||
normalize_v3(nor_next);
|
||||
|
|
|
@ -288,11 +288,9 @@ static void freeAdjacencyMap(SDefAdjacencyArray *const vert_edges,
|
|||
MEM_freeN(vert_edges);
|
||||
}
|
||||
|
||||
static int buildAdjacencyMap(const MPoly *poly,
|
||||
const MEdge *edge,
|
||||
const MLoop *const loops,
|
||||
const uint polys_num,
|
||||
const uint edges_num,
|
||||
static int buildAdjacencyMap(const blender::Span<MPoly> polys,
|
||||
const blender::Span<MEdge> edges,
|
||||
const blender::Span<MLoop> loops,
|
||||
SDefAdjacencyArray *const vert_edges,
|
||||
SDefAdjacency *adj,
|
||||
SDefEdgePolys *const edge_polys)
|
||||
|
@ -300,10 +298,11 @@ static int buildAdjacencyMap(const MPoly *poly,
|
|||
const MLoop *loop;
|
||||
|
||||
/* Find polygons adjacent to edges. */
|
||||
for (int i = 0; i < polys_num; i++, poly++) {
|
||||
loop = &loops[poly->loopstart];
|
||||
for (const int i : polys.index_range()) {
|
||||
const MPoly &poly = polys[i];
|
||||
loop = &loops[poly.loopstart];
|
||||
|
||||
for (int j = 0; j < poly->totloop; j++, loop++) {
|
||||
for (int j = 0; j < poly.totloop; j++, loop++) {
|
||||
if (edge_polys[loop->e].num == 0) {
|
||||
edge_polys[loop->e].polys[0] = i;
|
||||
edge_polys[loop->e].polys[1] = -1;
|
||||
|
@ -320,17 +319,18 @@ static int buildAdjacencyMap(const MPoly *poly,
|
|||
}
|
||||
|
||||
/* Find edges adjacent to vertices */
|
||||
for (int i = 0; i < edges_num; i++, edge++) {
|
||||
adj->next = vert_edges[edge->v1].first;
|
||||
for (const int i : edges.index_range()) {
|
||||
const MEdge &edge = edges[i];
|
||||
adj->next = vert_edges[edge.v1].first;
|
||||
adj->index = i;
|
||||
vert_edges[edge->v1].first = adj;
|
||||
vert_edges[edge->v1].num += edge_polys[i].num;
|
||||
vert_edges[edge.v1].first = adj;
|
||||
vert_edges[edge.v1].num += edge_polys[i].num;
|
||||
adj++;
|
||||
|
||||
adj->next = vert_edges[edge->v2].first;
|
||||
adj->next = vert_edges[edge.v2].first;
|
||||
adj->index = i;
|
||||
vert_edges[edge->v2].first = adj;
|
||||
vert_edges[edge->v2].num += edge_polys[i].num;
|
||||
vert_edges[edge.v2].first = adj;
|
||||
vert_edges[edge.v2].num += edge_polys[i].num;
|
||||
adj++;
|
||||
}
|
||||
|
||||
|
@ -1230,14 +1230,7 @@ static bool surfacedeformBind(Object *ob,
|
|||
return false;
|
||||
}
|
||||
|
||||
adj_result = buildAdjacencyMap(polys.data(),
|
||||
edges.data(),
|
||||
loops.data(),
|
||||
target_polys_num,
|
||||
tedges_num,
|
||||
vert_edges,
|
||||
adj_array,
|
||||
edge_polys);
|
||||
adj_result = buildAdjacencyMap(polys, edges, loops, vert_edges, adj_array, edge_polys);
|
||||
|
||||
if (adj_result == MOD_SDEF_BIND_RESULT_NONMANY_ERR) {
|
||||
BKE_modifier_set_error(
|
||||
|
|
Loading…
Reference in New Issue