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

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/blenkernel/intern/mesh.c')
-rw-r--r--source/blender/blenkernel/intern/mesh.c107
1 files changed, 66 insertions, 41 deletions
diff --git a/source/blender/blenkernel/intern/mesh.c b/source/blender/blenkernel/intern/mesh.c
index 944f06cf740..7a5c43b28f8 100644
--- a/source/blender/blenkernel/intern/mesh.c
+++ b/source/blender/blenkernel/intern/mesh.c
@@ -2092,8 +2092,9 @@ void BKE_mesh_convert_mfaces_to_mpolys(Mesh *mesh)
mp->mat_nr = mf->mat_nr;
mp->flag = mf->flag;
-# define ML(v1, v2) {ml->v = mf->v1; ml->e = GET_INT_FROM_POINTER(BLI_edgehash_lookup(eh, mf->v1, mf->v2)); ml++; j++; \
-}
+# define ML(v1, v2) { \
+ ml->v = mf->v1; ml->e = GET_INT_FROM_POINTER(BLI_edgehash_lookup(eh, mf->v1, mf->v2)); ml++; j++; \
+ } (void)0
ML(v1, v2);
ML(v2, v3);
@@ -2287,21 +2288,39 @@ void create_vert_poly_map(MeshElemMap **map, int **mem,
/* Generates a map where the key is the vertex and the value is a list
* of edges that use that vertex as an endpoint. The lists are allocated
* from one memory pool. */
-void create_vert_edge_map(ListBase **map, IndexNode **mem, const MEdge *medge, const int totvert, const int totedge)
+void create_vert_edge_map(MeshElemMap **map, int **mem,
+ const MEdge *medge, int totvert, int totedge)
{
- int i, j;
- IndexNode *node = NULL;
-
- (*map) = MEM_callocN(sizeof(ListBase) * totvert, "vert edge map");
- (*mem) = MEM_callocN(sizeof(IndexNode) * totedge * 2, "vert edge map mem");
- node = *mem;
+ int i, *indices;
+
+ (*map) = MEM_callocN(sizeof(MeshElemMap) * totvert, "vert-edge map");
+ (*mem) = MEM_mallocN(sizeof(int) * totedge * 2, "vert-edge map mem");
+
+ /* Count number of edges for each vertex */
+ for (i = 0; i < totedge; i++) {
+ (*map)[medge[i].v1].count++;
+ (*map)[medge[i].v2].count++;
+ }
+
+ /* Assign indices mem */
+ indices = (*mem);
+ for (i = 0; i < totvert; i++) {
+ (*map)[i].indices = indices;
+ indices += (*map)[i].count;
+ /* Reset 'count' for use as index in last loop */
+ (*map)[i].count = 0;
+ }
+
/* Find the users */
- for (i = 0; i < totedge; ++i) {
- for (j = 0; j < 2; ++j, ++node) {
- node->index = i;
- BLI_addtail(&(*map)[((unsigned int *)(&medge[i].v1))[j]], node);
- }
+ for (i = 0; i < totedge; i++) {
+ const int v[2] = {medge[i].v1, medge[i].v2};
+
+ (*map)[v[0]].indices[(*map)[v[0]].count] = i;
+ (*map)[v[1]].indices[(*map)[v[1]].count] = i;
+
+ (*map)[v[0]].count++;
+ (*map)[v[1]].count++;
}
}
@@ -2391,8 +2410,8 @@ int BKE_mesh_recalc_tessellation(CustomData *fdata,
MFace *mface = NULL, *mf;
BLI_array_declare(mface);
ScanFillContext sf_ctx;
- ScanFillVert *v, *lastv, *firstv;
- ScanFillFace *f;
+ ScanFillVert *sf_vert, *sf_vert_last, *sf_vert_first;
+ ScanFillFace *sf_tri;
int *mface_orig_index = NULL;
BLI_array_declare(mface_orig_index);
int *mface_to_poly_map = NULL;
@@ -2485,21 +2504,21 @@ int BKE_mesh_recalc_tessellation(CustomData *fdata,
ml = mloop + mp->loopstart;
BLI_scanfill_begin(&sf_ctx);
- firstv = NULL;
- lastv = NULL;
+ sf_vert_first = NULL;
+ sf_vert_last = NULL;
for (j = 0; j < mp->totloop; j++, ml++) {
- v = BLI_scanfill_vert_add(&sf_ctx, mvert[ml->v].co);
+ sf_vert = BLI_scanfill_vert_add(&sf_ctx, mvert[ml->v].co);
- v->keyindex = mp->loopstart + j;
+ sf_vert->keyindex = mp->loopstart + j;
- if (lastv)
- BLI_scanfill_edge_add(&sf_ctx, lastv, v);
+ if (sf_vert_last)
+ BLI_scanfill_edge_add(&sf_ctx, sf_vert_last, sf_vert);
- if (!firstv)
- firstv = v;
- lastv = v;
+ if (!sf_vert_first)
+ sf_vert_first = sf_vert;
+ sf_vert_last = sf_vert;
}
- BLI_scanfill_edge_add(&sf_ctx, lastv, firstv);
+ BLI_scanfill_edge_add(&sf_ctx, sf_vert_last, sf_vert_first);
totfilltri = BLI_scanfill_calc(&sf_ctx, FALSE);
if (totfilltri) {
@@ -2509,14 +2528,14 @@ int BKE_mesh_recalc_tessellation(CustomData *fdata,
BLI_array_grow_items(mface_orig_index, totfilltri);
}
- for (f = sf_ctx.fillfacebase.first; f; f = f->next, mf++) {
+ for (sf_tri = sf_ctx.fillfacebase.first; sf_tri; sf_tri = sf_tri->next, mf++) {
mface_to_poly_map[mface_index] = poly_index;
mf = &mface[mface_index];
/* set loop indices, transformed to vert indices later */
- mf->v1 = f->v1->keyindex;
- mf->v2 = f->v2->keyindex;
- mf->v3 = f->v3->keyindex;
+ mf->v1 = sf_tri->v1->keyindex;
+ mf->v2 = sf_tri->v2->keyindex;
+ mf->v3 = sf_tri->v3->keyindex;
mf->v4 = 0;
mf->mat_nr = mp->mat_nr;
@@ -2771,16 +2790,19 @@ static void mesh_calc_ngon_normal(MPoly *mpoly, MLoop *loopstart,
{
const int nverts = mpoly->totloop;
float const *v_prev = mvert[loopstart[nverts - 1].v].co;
- float const *v_curr = mvert[loopstart->v].co;
- float n[3] = {0.0f};
+ float const *v_curr;
int i;
+ zero_v3(normal);
+
/* Newell's Method */
- for (i = 0; i < nverts; v_prev = v_curr, v_curr = mvert[loopstart[++i].v].co) {
- add_newell_cross_v3_v3v3(n, v_prev, v_curr);
+ for (i = 0; i < nverts; i++) {
+ v_curr = mvert[loopstart[i].v].co;
+ add_newell_cross_v3_v3v3(normal, v_prev, v_curr);
+ v_prev = v_curr;
}
- if (UNLIKELY(normalize_v3_v3(normal, n) == 0.0f)) {
+ if (UNLIKELY(normalize_v3(normal) == 0.0f)) {
normal[2] = 1.0f; /* other axis set to 0.0 */
}
}
@@ -2818,16 +2840,19 @@ static void mesh_calc_ngon_normal_coords(MPoly *mpoly, MLoop *loopstart,
{
const int nverts = mpoly->totloop;
float const *v_prev = vertex_coords[loopstart[nverts - 1].v];
- float const *v_curr = vertex_coords[loopstart->v];
- float n[3] = {0.0f};
+ float const *v_curr;
int i;
+ zero_v3(normal);
+
/* Newell's Method */
- for (i = 0; i < nverts; v_prev = v_curr, v_curr = vertex_coords[loopstart[++i].v]) {
- add_newell_cross_v3_v3v3(n, v_prev, v_curr);
+ for (i = 0; i < nverts; i++) {
+ v_curr = vertex_coords[loopstart[i].v];
+ add_newell_cross_v3_v3v3(normal, v_prev, v_curr);
+ v_prev = v_curr;
}
- if (UNLIKELY(normalize_v3_v3(normal, n) == 0.0f)) {
+ if (UNLIKELY(normalize_v3(normal) == 0.0f)) {
normal[2] = 1.0f; /* other axis set to 0.0 */
}
}
@@ -3011,7 +3036,7 @@ int BKE_mesh_minmax(Mesh *me, float r_min[3], float r_max[3])
int i = me->totvert;
MVert *mvert;
for (mvert = me->mvert; i--; mvert++) {
- DO_MINMAX(mvert->co, r_min, r_max);
+ minmax_v3v3_v3(r_min, r_max, mvert->co);
}
return (me->totvert != 0);