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:
authorCampbell Barton <ideasman42@gmail.com>2013-07-22 20:49:37 +0400
committerCampbell Barton <ideasman42@gmail.com>2013-07-22 20:49:37 +0400
commit90fdaa82195c2eb9b6412ffa8b4f4f70e16a35dc (patch)
tree189bcebbbd82c301f2a1ee4be9f6406fc9bf54f1 /source/blender/bmesh/intern/bmesh_polygon.c
parentbe7004237c2143ddf1811c2e4ba20e6f2eb1c7f8 (diff)
optimization: lazy initialize EditDerivedBMesh members vertexNos, polyNos.
also add polyCos array which cache's face centers, gives overall ~20% speedup to drawing on a high-poly mesh in face-editmode.
Diffstat (limited to 'source/blender/bmesh/intern/bmesh_polygon.c')
-rw-r--r--source/blender/bmesh/intern/bmesh_polygon.c60
1 files changed, 43 insertions, 17 deletions
diff --git a/source/blender/bmesh/intern/bmesh_polygon.c b/source/blender/bmesh/intern/bmesh_polygon.c
index 88186df89fb..1ecb3c2b9ac 100644
--- a/source/blender/bmesh/intern/bmesh_polygon.c
+++ b/source/blender/bmesh/intern/bmesh_polygon.c
@@ -125,7 +125,7 @@ static void bm_face_calc_poly_normal(BMFace *f, float n[3])
* Same as #calc_poly_normal and #bm_face_calc_poly_normal
* but takes an array of vertex locations.
*/
-static void bm_face_calc_poly_normal_vertex_cos(BMFace *f, float n[3],
+static void bm_face_calc_poly_normal_vertex_cos(BMFace *f, float r_no[3],
float const (*vertexCos)[3])
{
BMLoop *l_first = BM_FACE_FIRST_LOOP(f);
@@ -133,23 +133,41 @@ static void bm_face_calc_poly_normal_vertex_cos(BMFace *f, float n[3],
float const *v_prev = vertexCos[BM_elem_index_get(l_first->prev->v)];
float const *v_curr = vertexCos[BM_elem_index_get(l_first->v)];
- zero_v3(n);
+ zero_v3(r_no);
/* Newell's Method */
do {
- add_newell_cross_v3_v3v3(n, v_prev, v_curr);
+ add_newell_cross_v3_v3v3(r_no, v_prev, v_curr);
l_iter = l_iter->next;
v_prev = v_curr;
v_curr = vertexCos[BM_elem_index_get(l_iter->v)];
} while (l_iter != l_first);
- if (UNLIKELY(normalize_v3(n) == 0.0f)) {
- n[2] = 1.0f; /* other axis set to 0.0 */
+ if (UNLIKELY(normalize_v3(r_no) == 0.0f)) {
+ r_no[2] = 1.0f; /* other axis set to 0.0 */
}
}
/**
+ * \brief COMPUTE POLY CENTER (BMFace)
+ */
+static void bm_face_calc_poly_center_mean_vertex_cos(BMFace *f, float r_cent[3],
+ float const (*vertexCos)[3])
+{
+ BMLoop *l_first = BM_FACE_FIRST_LOOP(f);
+ BMLoop *l_iter = l_first;
+
+ zero_v3(r_cent);
+
+ /* Newell's Method */
+ do {
+ add_v3_v3(r_cent, vertexCos[BM_elem_index_get(l_iter->v)]);
+ } while ((l_iter = l_iter->next) != l_first);
+ mul_v3_fl(r_cent, 1.0f / f->len);
+}
+
+/**
* For tools that insist on using triangles, ideally we would cache this data.
*
* \param r_loops Store face loop pointers, (f->len)
@@ -370,8 +388,7 @@ void BM_face_calc_center_bounds(BMFace *f, float r_cent[3])
*/
void BM_face_calc_center_mean(BMFace *f, float r_cent[3])
{
- BMLoop *l_iter;
- BMLoop *l_first;
+ BMLoop *l_iter, *l_first;
zero_v3(r_cent);
@@ -379,9 +396,7 @@ void BM_face_calc_center_mean(BMFace *f, float r_cent[3])
do {
add_v3_v3(r_cent, l_iter->v->co);
} while ((l_iter = l_iter->next) != l_first);
-
- if (f->len)
- mul_v3_fl(r_cent, 1.0f / (float) f->len);
+ mul_v3_fl(r_cent, 1.0f / (float) f->len);
}
/**
@@ -601,9 +616,9 @@ void BM_face_normal_update(BMFace *f)
BM_face_calc_normal(f, f->no);
}
-/* exact same as 'bmesh_face_normal_update' but accepts vertex coords */
-void BM_face_normal_update_vcos(BMesh *bm, BMFace *f, float no[3],
- float const (*vertexCos)[3])
+/* exact same as 'BM_face_calc_normal' but accepts vertex coords */
+void BM_face_calc_normal_vcos(BMesh *bm, BMFace *f, float r_no[3],
+ float const (*vertexCos)[3])
{
BMLoop *l;
@@ -620,7 +635,7 @@ void BM_face_normal_update_vcos(BMesh *bm, BMFace *f, float no[3],
const float *co3 = vertexCos[BM_elem_index_get((l = l->next)->v)];
const float *co4 = vertexCos[BM_elem_index_get((l->next)->v)];
- normal_quad_v3(no, co1, co2, co3, co4);
+ normal_quad_v3(r_no, co1, co2, co3, co4);
break;
}
case 3:
@@ -629,22 +644,33 @@ void BM_face_normal_update_vcos(BMesh *bm, BMFace *f, float no[3],
const float *co2 = vertexCos[BM_elem_index_get((l = l->next)->v)];
const float *co3 = vertexCos[BM_elem_index_get((l->next)->v)];
- normal_tri_v3(no, co1, co2, co3);
+ normal_tri_v3(r_no, co1, co2, co3);
break;
}
case 0:
{
- zero_v3(no);
+ zero_v3(r_no);
break;
}
default:
{
- bm_face_calc_poly_normal_vertex_cos(f, no, vertexCos);
+ bm_face_calc_poly_normal_vertex_cos(f, r_no, vertexCos);
break;
}
}
}
+/* exact same as 'BM_face_calc_normal' but accepts vertex coords */
+void BM_face_calc_center_mean_vcos(BMesh *bm, BMFace *f, float r_cent[3],
+ float const (*vertexCos)[3])
+{
+ /* must have valid index data */
+ BLI_assert((bm->elem_index_dirty & BM_VERT) == 0);
+ (void)bm;
+
+ bm_face_calc_poly_center_mean_vertex_cos(f, r_cent, vertexCos);
+}
+
/**
* \brief Face Flip Normal
*