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-23 02:59:47 +0400
committerCampbell Barton <ideasman42@gmail.com>2013-07-23 02:59:47 +0400
commitb7bf20d9504127ec7c3d52bc8a1448d4a2bdc3bf (patch)
treea38041dec1c240652d0e22991489ab1255d35fd4 /source/blender/blenkernel/intern/cdderivedmesh.c
parent33e52d0df4d2d9dfd248144e2aac08af4c1bbeff (diff)
optimization: only calculate the normals for passing into derivedMesh foreachMappedVert/foreachMappedFaceCenter when needed,
this means in editmode with wire draw, face and vertex normals don't have to be calculated at all. in most cases the normals are not used so add a flag that makes calculating them only for functions that need them. also fix face normal calculation for CDDM, was using quad calculation for ngons too.
Diffstat (limited to 'source/blender/blenkernel/intern/cdderivedmesh.c')
-rw-r--r--source/blender/blenkernel/intern/cdderivedmesh.c53
1 files changed, 25 insertions, 28 deletions
diff --git a/source/blender/blenkernel/intern/cdderivedmesh.c b/source/blender/blenkernel/intern/cdderivedmesh.c
index faa4d8d3071..0e294f38838 100644
--- a/source/blender/blenkernel/intern/cdderivedmesh.c
+++ b/source/blender/blenkernel/intern/cdderivedmesh.c
@@ -1548,19 +1548,26 @@ static void cdDM_drawMappedEdges(DerivedMesh *dm, DMSetDrawOptions setDrawOption
static void cdDM_foreachMappedVert(
DerivedMesh *dm,
void (*func)(void *userData, int index, const float co[3], const float no_f[3], const short no_s[3]),
- void *userData)
+ void *userData,
+ DMForeachFlag flag)
{
MVert *mv = CDDM_get_verts(dm);
- int i, orig, *index = DM_get_vert_data_layer(dm, CD_ORIGINDEX);
+ int *index = DM_get_vert_data_layer(dm, CD_ORIGINDEX);
+ int i;
- for (i = 0; i < dm->numVertData; i++, mv++) {
- if (index) {
- orig = *index++;
+ if (index) {
+ for (i = 0; i < dm->numVertData; i++, mv++) {
+ const short *no = (flag & DM_FOREACH_USE_NORMAL) ? mv->no : NULL;
+ const int orig = *index++;
if (orig == ORIGINDEX_NONE) continue;
- func(userData, orig, mv->co, NULL, mv->no);
+ func(userData, orig, mv->co, NULL, no);
+ }
+ }
+ else {
+ for (i = 0; i < dm->numVertData; i++, mv++) {
+ const short *no = (flag & DM_FOREACH_USE_NORMAL) ? mv->no : NULL;
+ func(userData, i, mv->co, NULL, no);
}
- else
- func(userData, i, mv->co, NULL, mv->no);
}
}
@@ -1588,47 +1595,37 @@ static void cdDM_foreachMappedEdge(
static void cdDM_foreachMappedFaceCenter(
DerivedMesh *dm,
void (*func)(void *userData, int index, const float cent[3], const float no[3]),
- void *userData)
+ void *userData,
+ DMForeachFlag flag)
{
CDDerivedMesh *cddm = (CDDerivedMesh *)dm;
MVert *mvert = cddm->mvert;
MPoly *mp;
MLoop *ml;
- int i, j, orig, *index;
+ int i, orig, *index;
index = CustomData_get_layer(&dm->polyData, CD_ORIGINDEX);
mp = cddm->mpoly;
for (i = 0; i < dm->numPolyData; i++, mp++) {
float cent[3];
- float no[3];
+ float *no, _no[3];
if (index) {
orig = *index++;
if (orig == ORIGINDEX_NONE) continue;
}
- else
+ else {
orig = i;
+ }
ml = &cddm->mloop[mp->loopstart];
- cent[0] = cent[1] = cent[2] = 0.0f;
- for (j = 0; j < mp->totloop; j++, ml++) {
- add_v3_v3v3(cent, cent, mvert[ml->v].co);
- }
- mul_v3_fl(cent, 1.0f / (float)j);
+ BKE_mesh_calc_poly_center(mp, ml, mvert, cent);
- ml = &cddm->mloop[mp->loopstart];
- if (j > 3) {
- normal_quad_v3(no,
- mvert[(ml + 0)->v].co,
- mvert[(ml + 1)->v].co,
- mvert[(ml + 2)->v].co,
- mvert[(ml + 3)->v].co);
+ if (flag & DM_FOREACH_USE_NORMAL) {
+ BKE_mesh_calc_poly_normal(mp, ml, mvert, (no = _no));
}
else {
- normal_tri_v3(no,
- mvert[(ml + 0)->v].co,
- mvert[(ml + 1)->v].co,
- mvert[(ml + 2)->v].co);
+ no = NULL;
}
func(userData, orig, cent, no);