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
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')
-rw-r--r--source/blender/blenkernel/BKE_DerivedMesh.h11
-rw-r--r--source/blender/blenkernel/intern/anim.c2
-rw-r--r--source/blender/blenkernel/intern/cdderivedmesh.c53
-rw-r--r--source/blender/blenkernel/intern/editderivedmesh.c74
-rw-r--r--source/blender/blenkernel/intern/subsurf_ccg.c29
5 files changed, 107 insertions, 62 deletions
diff --git a/source/blender/blenkernel/BKE_DerivedMesh.h b/source/blender/blenkernel/BKE_DerivedMesh.h
index 40fc71e82ca..8396380fd06 100644
--- a/source/blender/blenkernel/BKE_DerivedMesh.h
+++ b/source/blender/blenkernel/BKE_DerivedMesh.h
@@ -152,6 +152,11 @@ typedef enum DMDrawFlag {
DM_DRAW_ALWAYS_SMOOTH = 2
} DMDrawFlag;
+typedef enum DMForeachFlag {
+ DM_FOREACH_NOP = 0,
+ DM_FOREACH_USE_NORMAL = (1 << 0), /* foreachMappedVert, foreachMappedFaceCenter */
+} DMForeachFlag;
+
typedef enum DMDirtyFlag {
/* dm has valid tessellated faces, but tessellated CDDATA need to be updated. */
DM_DIRTY_TESS_CDLAYERS = 1 << 0,
@@ -285,7 +290,8 @@ struct DerivedMesh {
void (*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);
/** Iterate over each mapped edge in the derived mesh, calling the
* given function with the original edge and the mapped edge's new
@@ -303,7 +309,8 @@ struct DerivedMesh {
void (*foreachMappedFaceCenter)(DerivedMesh *dm,
void (*func)(void *userData, int index,
const float cent[3], const float no[3]),
- void *userData);
+ void *userData,
+ DMForeachFlag flag);
/** Iterate over all vertex points, calling DO_MINMAX with given args.
*
diff --git a/source/blender/blenkernel/intern/anim.c b/source/blender/blenkernel/intern/anim.c
index 9fea3d2e13f..ba680147201 100644
--- a/source/blender/blenkernel/intern/anim.c
+++ b/source/blender/blenkernel/intern/anim.c
@@ -1036,7 +1036,7 @@ static void vertex_duplilist(ListBase *lb, ID *id, Scene *scene, Object *par, fl
if (ob->type != OB_MBALL) ob->flag |= OB_DONE; /* doesnt render */
if (me->edit_btmesh) {
- dm->foreachMappedVert(dm, vertex_dupli__mapFunc, (void *) &vdd);
+ dm->foreachMappedVert(dm, vertex_dupli__mapFunc, (void *) &vdd, DM_FOREACH_USE_NORMAL);
}
else {
for (a = 0; a < totvert; a++) {
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);
diff --git a/source/blender/blenkernel/intern/editderivedmesh.c b/source/blender/blenkernel/intern/editderivedmesh.c
index b853d2b87a2..c9fc5f15d8b 100644
--- a/source/blender/blenkernel/intern/editderivedmesh.c
+++ b/source/blender/blenkernel/intern/editderivedmesh.c
@@ -86,7 +86,6 @@ static void emDM_ensurePolyNormals(EditDerivedBMesh *bmdm);
static void emDM_ensureVertNormals(EditDerivedBMesh *bmdm)
{
-
if (bmdm->vertexCos && (bmdm->vertexNos == NULL)) {
BMesh *bm = bmdm->em->bm;
@@ -196,9 +195,11 @@ static void emDM_recalcTessellation(DerivedMesh *UNUSED(dm))
/* do nothing */
}
-static void emDM_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)
+static void emDM_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,
+ DMForeachFlag flag)
{
EditDerivedBMesh *bmdm = (EditDerivedBMesh *)dm;
BMesh *bm = bmdm->em->bm;
@@ -207,14 +208,26 @@ static void emDM_foreachMappedVert(DerivedMesh *dm,
int i;
if (bmdm->vertexCos) {
- emDM_ensureVertNormals(bmdm);
+ const float (*vertexCos)[3] = bmdm->vertexCos;
+ const float (*vertexNos)[3];
+
+ if (flag & DM_FOREACH_USE_NORMAL) {
+ emDM_ensureVertNormals(bmdm);
+ vertexNos = bmdm->vertexNos;
+ }
+ else {
+ vertexNos = NULL;
+ }
+
BM_ITER_MESH_INDEX (eve, &iter, bm, BM_VERTS_OF_MESH, i) {
- func(userData, i, bmdm->vertexCos[i], bmdm->vertexNos[i], NULL);
+ const float *no = (flag & DM_FOREACH_USE_NORMAL) ? vertexNos[i] : NULL;
+ func(userData, i, vertexCos[i], no, NULL);
}
}
else {
BM_ITER_MESH_INDEX (eve, &iter, bm, BM_VERTS_OF_MESH, i) {
- func(userData, i, eve->co, eve->no, NULL);
+ const float *no = (flag & DM_FOREACH_USE_NORMAL) ? eve->no : NULL;
+ func(userData, i, eve->co, no, NULL);
}
}
}
@@ -359,9 +372,11 @@ static void emDM_drawUVEdges(DerivedMesh *dm)
glEnd();
}
-static void emDM_foreachMappedFaceCenter(DerivedMesh *dm,
- void (*func)(void *userData, int index, const float co[3], const float no[3]),
- void *userData)
+static void emDM_foreachMappedFaceCenter(
+ DerivedMesh *dm,
+ void (*func)(void *userData, int index, const float co[3], const float no[3]),
+ void *userData,
+ DMForeachFlag flag)
{
EditDerivedBMesh *bmdm = (EditDerivedBMesh *)dm;
BMesh *bm = bmdm->em->bm;
@@ -371,13 +386,28 @@ static void emDM_foreachMappedFaceCenter(DerivedMesh *dm,
BMIter iter;
int i;
- emDM_ensurePolyNormals(bmdm);
emDM_ensurePolyCenters(bmdm);
- polyNos = bmdm->polyNos; /* maybe NULL */
polyCos = bmdm->polyCos; /* always set */
- BM_ITER_MESH_INDEX (efa, &iter, bm, BM_FACES_OF_MESH, i) {
- func(userData, i, polyCos[i], polyNos ? polyNos[i] : efa->no);
+ if (flag & DM_FOREACH_USE_NORMAL) {
+ emDM_ensurePolyNormals(bmdm);
+ polyNos = bmdm->polyNos; /* maybe NULL */
+ }
+ else {
+ polyNos = NULL;
+ }
+
+ if (polyNos) {
+ BM_ITER_MESH_INDEX (efa, &iter, bm, BM_FACES_OF_MESH, i) {
+ const float *no = polyNos[i];
+ func(userData, i, polyCos[i], no);
+ }
+ }
+ else {
+ BM_ITER_MESH_INDEX (efa, &iter, bm, BM_FACES_OF_MESH, i) {
+ const float *no = (flag & DM_FOREACH_USE_NORMAL) ? efa->no : NULL;
+ func(userData, i, polyCos[i], no);
+ }
}
}
@@ -433,10 +463,16 @@ static void emDM_drawMappedFaces(DerivedMesh *dm,
const float (*vertexNos)[3];
const float (*polyNos)[3];
- emDM_ensureVertNormals(bmdm);
- emDM_ensurePolyNormals(bmdm);
- vertexNos = bmdm->vertexNos;
- polyNos = bmdm->polyNos;
+ if (skip_normals) {
+ vertexNos = NULL;
+ polyNos = NULL;
+ }
+ else {
+ emDM_ensureVertNormals(bmdm);
+ emDM_ensurePolyNormals(bmdm);
+ vertexNos = bmdm->vertexNos;
+ polyNos = bmdm->polyNos;
+ }
BM_mesh_elem_index_ensure(bm, BM_VERT | BM_FACE);
@@ -2186,7 +2222,7 @@ float (*BKE_editmesh_vertexCos_get(BMEditMesh *em, Scene *scene, int *r_numVerts
data.cos_cage = cos_cage;
data.visit_bitmap = visit_bitmap;
- cage->foreachMappedVert(cage, cage_mapped_verts_callback, &data);
+ cage->foreachMappedVert(cage, cage_mapped_verts_callback, &data, DM_FOREACH_NOP);
MEM_freeN(visit_bitmap);
diff --git a/source/blender/blenkernel/intern/subsurf_ccg.c b/source/blender/blenkernel/intern/subsurf_ccg.c
index 26a5dada108..7c5727b0f69 100644
--- a/source/blender/blenkernel/intern/subsurf_ccg.c
+++ b/source/blender/blenkernel/intern/subsurf_ccg.c
@@ -1505,7 +1505,8 @@ static void ccgdm_getVertCos(DerivedMesh *dm, float (*cos)[3])
static void ccgDM_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)
{
CCGDerivedMesh *ccgdm = (CCGDerivedMesh *) dm;
CCGVertIterator *vi;
@@ -1514,11 +1515,13 @@ static void ccgDM_foreachMappedVert(
for (vi = ccgSubSurf_getVertIterator(ccgdm->ss); !ccgVertIterator_isStopped(vi); ccgVertIterator_next(vi)) {
CCGVert *v = ccgVertIterator_getCurrent(vi);
- CCGElem *vd = ccgSubSurf_getVertData(ccgdm->ss, v);
- int index = ccgDM_getVertMapIndex(ccgdm->ss, v);
+ const int index = ccgDM_getVertMapIndex(ccgdm->ss, v);
- if (index != -1)
- func(userData, index, CCG_elem_co(&key, vd), CCG_elem_no(&key, vd), NULL);
+ if (index != -1) {
+ CCGElem *vd = ccgSubSurf_getVertData(ccgdm->ss, v);
+ const float *no = (flag & DM_FOREACH_USE_NORMAL) ? CCG_elem_no(&key, vd) : NULL;
+ func(userData, index, CCG_elem_co(&key, vd), no, NULL);
+ }
}
ccgVertIterator_free(vi);
@@ -1539,12 +1542,13 @@ static void ccgDM_foreachMappedEdge(
for (ei = ccgSubSurf_getEdgeIterator(ss); !ccgEdgeIterator_isStopped(ei); ccgEdgeIterator_next(ei)) {
CCGEdge *e = ccgEdgeIterator_getCurrent(ei);
- CCGElem *edgeData = ccgSubSurf_getEdgeDataArray(ss, e);
- int index = ccgDM_getEdgeMapIndex(ss, e);
+ const int index = ccgDM_getEdgeMapIndex(ss, e);
if (index != -1) {
- for (i = 0; i < edgeSize - 1; i++)
+ CCGElem *edgeData = ccgSubSurf_getEdgeDataArray(ss, e);
+ for (i = 0; i < edgeSize - 1; i++) {
func(userData, index, CCG_elem_offset_co(&key, edgeData, i), CCG_elem_offset_co(&key, edgeData, i + 1));
+ }
}
}
@@ -2530,7 +2534,8 @@ static void ccgDM_drawMappedEdgesInterp(DerivedMesh *dm,
static void ccgDM_foreachMappedFaceCenter(
DerivedMesh *dm,
void (*func)(void *userData, int index, const float co[3], const float no[3]),
- void *userData)
+ void *userData,
+ DMForeachFlag flag)
{
CCGDerivedMesh *ccgdm = (CCGDerivedMesh *) dm;
CCGSubSurf *ss = ccgdm->ss;
@@ -2541,13 +2546,13 @@ static void ccgDM_foreachMappedFaceCenter(
for (fi = ccgSubSurf_getFaceIterator(ss); !ccgFaceIterator_isStopped(fi); ccgFaceIterator_next(fi)) {
CCGFace *f = ccgFaceIterator_getCurrent(fi);
- int index = ccgDM_getFaceMapIndex(ss, f);
+ const int index = ccgDM_getFaceMapIndex(ss, f);
if (index != -1) {
/* Face center data normal isn't updated atm. */
CCGElem *vd = ccgSubSurf_getFaceGridData(ss, f, 0, 0, 0);
-
- func(userData, index, CCG_elem_co(&key, vd), CCG_elem_no(&key, vd));
+ const float *no = (flag & DM_FOREACH_USE_NORMAL) ? CCG_elem_no(&key, vd) : NULL;
+ func(userData, index, CCG_elem_co(&key, vd), no);
}
}