From ef4db04da848a9790e502300285ccd17d71b4646 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 28 May 2013 14:23:07 +0000 Subject: [PATCH] code cleanup: lots of calls to BKE_mesh_calc_normals_mapping were not using the mapping functionality. replace ED_mesh_calc_normals with BKE_mesh_calc_normals(). --- source/blender/blenkernel/BKE_mesh.h | 6 ++- .../blender/blenkernel/intern/cdderivedmesh.c | 4 +- source/blender/blenkernel/intern/mesh.c | 21 ++++++---- source/blender/blenkernel/intern/multires.c | 2 +- source/blender/collada/MeshImporter.cpp | 7 +--- source/blender/editors/include/ED_mesh.h | 1 - source/blender/editors/mesh/mesh_data.c | 38 +------------------ source/blender/editors/mesh/meshtools.c | 2 +- .../blender/editors/object/object_transform.c | 2 +- source/blender/editors/sculpt_paint/sculpt.c | 6 +-- source/blender/makesdna/DNA_mesh_types.h | 3 -- source/blender/makesrna/intern/rna_mesh_api.c | 2 +- .../bad_level_call_stubs/stubs.c | 1 - 13 files changed, 29 insertions(+), 66 deletions(-) diff --git a/source/blender/blenkernel/BKE_mesh.h b/source/blender/blenkernel/BKE_mesh.h index 4f8823ec46c..7bb188d5ff6 100644 --- a/source/blender/blenkernel/BKE_mesh.h +++ b/source/blender/blenkernel/BKE_mesh.h @@ -211,18 +211,20 @@ void BKE_mesh_calc_normals_mapping( struct MVert *mverts, int numVerts, struct MLoop *mloop, struct MPoly *mpolys, int numLoops, int numPolys, float (*polyNors_r)[3], struct MFace *mfaces, int numFaces, int *origIndexFace, float (*faceNors_r)[3]); -/* extended version of 'BKE_mesh_calc_normals' with option not to calc vertex normals */ +/* extended version of 'BKE_mesh_calc_normals_poly' with option not to calc vertex normals */ void BKE_mesh_calc_normals_mapping_ex( struct MVert *mverts, int numVerts, struct MLoop *mloop, struct MPoly *mpolys, int numLoops, int numPolys, float (*polyNors_r)[3], struct MFace *mfaces, int numFaces, int *origIndexFace, float (*faceNors_r)[3], const bool only_face_normals); -void BKE_mesh_calc_normals( +void BKE_mesh_calc_normals_poly( struct MVert *mverts, int numVerts, struct MLoop *mloop, struct MPoly *mpolys, int numLoops, int numPolys, float (*polyNors_r)[3]); +void BKE_mesh_calc_normals(struct Mesh *me); + /* Return a newly MEM_malloc'd array of all the mesh vertex locations * (_numVerts_r_ may be NULL) */ float (*BKE_mesh_vertexCos_get(struct Mesh *me, int *r_numVerts))[3]; diff --git a/source/blender/blenkernel/intern/cdderivedmesh.c b/source/blender/blenkernel/intern/cdderivedmesh.c index 45dbf4cebc9..743b4a33bc2 100644 --- a/source/blender/blenkernel/intern/cdderivedmesh.c +++ b/source/blender/blenkernel/intern/cdderivedmesh.c @@ -2283,8 +2283,8 @@ void CDDM_calc_normals(DerivedMesh *dm) poly_nors = CustomData_add_layer(&dm->polyData, CD_NORMAL, CD_CALLOC, NULL, dm->numPolyData); } - BKE_mesh_calc_normals(cddm->mvert, dm->numVertData, CDDM_get_loops(dm), CDDM_get_polys(dm), - dm->numLoopData, dm->numPolyData, poly_nors); + BKE_mesh_calc_normals_poly(cddm->mvert, dm->numVertData, CDDM_get_loops(dm), CDDM_get_polys(dm), + dm->numLoopData, dm->numPolyData, poly_nors); } void CDDM_calc_normals_tessface(DerivedMesh *dm) diff --git a/source/blender/blenkernel/intern/mesh.c b/source/blender/blenkernel/intern/mesh.c index 6feb39bd836..7db724aa11d 100644 --- a/source/blender/blenkernel/intern/mesh.c +++ b/source/blender/blenkernel/intern/mesh.c @@ -1197,7 +1197,7 @@ void BKE_mesh_from_metaball(ListBase *lb, Mesh *me) BKE_mesh_update_customdata_pointers(me, true); - BKE_mesh_calc_normals(me->mvert, me->totvert, me->mloop, me->mpoly, me->totloop, me->totpoly, NULL); + BKE_mesh_calc_normals(me); BKE_mesh_calc_edges(me, true, false); } @@ -1591,7 +1591,7 @@ void BKE_mesh_from_nurbs_displist(Object *ob, ListBase *dispbase, const bool use me->mloopuv = CustomData_add_layer_named(&me->ldata, CD_MLOOPUV, CD_ASSIGN, alluv, me->totloop, uvname); } - BKE_mesh_calc_normals(me->mvert, me->totvert, me->mloop, me->mpoly, me->totloop, me->totpoly, NULL); + BKE_mesh_calc_normals(me); } else { me = BKE_mesh_add(G.main, "Mesh"); @@ -1907,7 +1907,7 @@ void BKE_mesh_calc_normals_mapping_ex(MVert *mverts, int numVerts, if (only_face_normals == FALSE) { /* vertex normals are optional, they require some extra calculations, * so make them optional */ - BKE_mesh_calc_normals(mverts, numVerts, mloop, mpolys, numLoops, numPolys, pnors); + BKE_mesh_calc_normals_poly(mverts, numVerts, mloop, mpolys, numLoops, numPolys, pnors); } else { /* only calc poly normals */ @@ -1929,7 +1929,7 @@ void BKE_mesh_calc_normals_mapping_ex(MVert *mverts, int numVerts, } else { /* eek, we're not corresponding to polys */ - printf("error in BKE_mesh_calc_normals; tessellation face indices are incorrect. normals may look bad.\n"); + printf("error in %s: tessellation face indices are incorrect. normals may look bad.\n", __func__); } } } @@ -1993,10 +1993,10 @@ static void mesh_calc_normals_poly_accum(MPoly *mp, MLoop *ml, } -void BKE_mesh_calc_normals(MVert *mverts, int numVerts, MLoop *mloop, MPoly *mpolys, - int UNUSED(numLoops), int numPolys, float (*polyNors_r)[3]) +void BKE_mesh_calc_normals_poly(MVert *mverts, int numVerts, MLoop *mloop, MPoly *mpolys, + int UNUSED(numLoops), int numPolys, float (*r_polynors)[3]) { - float (*pnors)[3] = polyNors_r; + float (*pnors)[3] = r_polynors; float (*tnorms)[3]; float tpnor[3]; /* temp poly normal */ int i; @@ -2025,6 +2025,13 @@ void BKE_mesh_calc_normals(MVert *mverts, int numVerts, MLoop *mloop, MPoly *mpo MEM_freeN(tnorms); } +void BKE_mesh_calc_normals(Mesh *mesh) +{ + BKE_mesh_calc_normals_poly(mesh->mvert, mesh->totvert, + mesh->mloop, mesh->mpoly, mesh->totloop, mesh->totpoly, + NULL); +} + void BKE_mesh_calc_normals_tessface(MVert *mverts, int numVerts, MFace *mfaces, int numFaces, float (*faceNors_r)[3]) { float (*tnorms)[3] = MEM_callocN(numVerts * sizeof(*tnorms), "tnorms"); diff --git a/source/blender/blenkernel/intern/multires.c b/source/blender/blenkernel/intern/multires.c index c9f3314c573..cba4c9206c9 100644 --- a/source/blender/blenkernel/intern/multires.c +++ b/source/blender/blenkernel/intern/multires.c @@ -861,7 +861,7 @@ void multiresModifier_base_apply(MultiresModifierData *mmd, Object *ob) * Probably this is possible to do in the loop above, but this is rather tricky because * we don't know all needed vertices' coordinates there yet. */ - BKE_mesh_calc_normals(me->mvert, me->totvert, me->mloop, me->mpoly, me->totloop, me->totpoly, NULL); + BKE_mesh_calc_normals(me); /* subdivide the mesh to highest level without displacements */ cddm = CDDM_from_mesh(me, NULL); diff --git a/source/blender/collada/MeshImporter.cpp b/source/blender/collada/MeshImporter.cpp index cb1b55d2ac0..b4b37f7d0bd 100644 --- a/source/blender/collada/MeshImporter.cpp +++ b/source/blender/collada/MeshImporter.cpp @@ -710,7 +710,7 @@ void MeshImporter::bmeshConversion() if ((*m).second) { Mesh *me = (*m).second; BKE_mesh_tessface_clear(me); - BKE_mesh_calc_normals_mapping(me->mvert, me->totvert, me->mloop, me->mpoly, me->totloop, me->totpoly, NULL, NULL, 0, NULL, NULL); + BKE_mesh_calc_normals(me); //BKE_mesh_validate(me, 1); } } @@ -1033,10 +1033,7 @@ Object *MeshImporter::create_mesh_object(COLLADAFW::Node *node, COLLADAFW::Insta Mesh *new_mesh = uid_mesh_map[*geom_uid]; BKE_mesh_assign_object(ob, new_mesh); - BKE_mesh_calc_normals_mapping(new_mesh->mvert, new_mesh->totvert, - new_mesh->mloop, new_mesh->mpoly, - new_mesh->totloop, new_mesh->totpoly, - NULL, NULL, 0, NULL, NULL); + BKE_mesh_calc_normals(new_mesh); if (old_mesh->id.us == 0) BKE_libblock_free(&G.main->mesh, old_mesh); diff --git a/source/blender/editors/include/ED_mesh.h b/source/blender/editors/include/ED_mesh.h index 65217e09259..9aa405eda1d 100644 --- a/source/blender/editors/include/ED_mesh.h +++ b/source/blender/editors/include/ED_mesh.h @@ -259,7 +259,6 @@ void ED_mesh_edges_remove(struct Mesh *mesh, struct ReportList *reports, int cou void ED_mesh_vertices_remove(struct Mesh *mesh, struct ReportList *reports, int count); void ED_mesh_transform(struct Mesh *me, float *mat); -void ED_mesh_calc_normals(struct Mesh *me); void ED_mesh_calc_tessface(struct Mesh *mesh); void ED_mesh_update(struct Mesh *mesh, struct bContext *C, int calc_edges, int calc_tessface); diff --git a/source/blender/editors/mesh/mesh_data.c b/source/blender/editors/mesh/mesh_data.c index ed652a7b812..869b2fb8f2d 100644 --- a/source/blender/editors/mesh/mesh_data.c +++ b/source/blender/editors/mesh/mesh_data.c @@ -896,8 +896,6 @@ void MESH_OT_customdata_clear_skin(wmOperatorType *ot) void ED_mesh_update(Mesh *mesh, bContext *C, int calc_edges, int calc_tessface) { - int *polyindex = NULL; - float (*face_nors)[3]; bool tessface_input = false; if (mesh->totface > 0 && mesh->totpoly == 0) { @@ -920,28 +918,7 @@ void ED_mesh_update(Mesh *mesh, bContext *C, int calc_edges, int calc_tessface) BKE_mesh_tessface_clear(mesh); } - /* note on this if/else - looks like these layers are not needed - * so rather then add poly-index layer and calculate normals for it - * calculate normals only for the mvert's. - campbell */ -#ifdef USE_BMESH_MPOLY_NORMALS - polyindex = CustomData_get_layer(&mesh->fdata, CD_ORIGINDEX); - /* add a normals layer for tessellated faces, a tessface normal will - * contain the normal of the poly the face was tessellated from. */ - face_nors = CustomData_add_layer(&mesh->fdata, CD_NORMAL, CD_CALLOC, NULL, mesh->totface); - - BKE_mesh_calc_normals_mapping_ex(mesh->mvert, mesh->totvert, - mesh->mloop, mesh->mpoly, - mesh->totloop, mesh->totpoly, - NULL /* polyNors_r */, - mesh->mface, mesh->totface, - polyindex, face_nors, false); -#else - BKE_mesh_calc_normals(mesh->mvert, mesh->totvert, - mesh->mloop, mesh->mpoly, mesh->totloop, mesh->totpoly, - NULL); - (void)polyindex; - (void)face_nors; -#endif + BKE_mesh_calc_normals(mesh); DAG_id_tag_update(&mesh->id, 0); WM_event_add_notifier(C, NC_GEOM | ND_DATA, mesh); @@ -1257,19 +1234,6 @@ void ED_mesh_polys_add(Mesh *mesh, ReportList *reports, int count) mesh_add_polys(mesh, count); } -void ED_mesh_calc_normals(Mesh *mesh) -{ -#ifdef USE_BMESH_MPOLY_NORMALS - BKE_mesh_calc_normals_mapping_ex(mesh->mvert, mesh->totvert, - mesh->mloop, mesh->mpoly, mesh->totloop, mesh->totpoly, - NULL, NULL, 0, NULL, NULL, false); -#else - BKE_mesh_calc_normals(mesh->mvert, mesh->totvert, - mesh->mloop, mesh->mpoly, mesh->totloop, mesh->totpoly, - NULL); -#endif -} - void ED_mesh_calc_tessface(Mesh *mesh) { if (mesh->edit_btmesh) { diff --git a/source/blender/editors/mesh/meshtools.c b/source/blender/editors/mesh/meshtools.c index 48bd96251a6..8b07cc51721 100644 --- a/source/blender/editors/mesh/meshtools.c +++ b/source/blender/editors/mesh/meshtools.c @@ -507,7 +507,7 @@ int join_mesh_exec(bContext *C, wmOperator *op) BKE_mesh_update_customdata_pointers(me, false); /* update normals in case objects with non-uniform scale are joined */ - ED_mesh_calc_normals(me); + BKE_mesh_calc_normals(me); /* old material array */ for (a = 1; a <= ob->totcol; a++) { diff --git a/source/blender/editors/object/object_transform.c b/source/blender/editors/object/object_transform.c index 7eb5c36a3fc..424333810a8 100644 --- a/source/blender/editors/object/object_transform.c +++ b/source/blender/editors/object/object_transform.c @@ -503,7 +503,7 @@ static int apply_objects_internal(bContext *C, ReportList *reports, int apply_lo } /* update normals */ - BKE_mesh_calc_normals_mapping(me->mvert, me->totvert, me->mloop, me->mpoly, me->totloop, me->totpoly, NULL, NULL, 0, NULL, NULL); + BKE_mesh_calc_normals(me); } else if (ob->type == OB_ARMATURE) { ED_armature_apply_transform(ob, mat); diff --git a/source/blender/editors/sculpt_paint/sculpt.c b/source/blender/editors/sculpt_paint/sculpt.c index 889b8b7c79c..053ace4e59d 100644 --- a/source/blender/editors/sculpt_paint/sculpt.c +++ b/source/blender/editors/sculpt_paint/sculpt.c @@ -2942,9 +2942,7 @@ void sculpt_vertcos_to_key(Object *ob, KeyBlock *kb, float (*vertCos)[3]) for (a = 0; a < me->totvert; a++, mvert++) copy_v3_v3(mvert->co, vertCos[a]); - BKE_mesh_calc_normals_mapping(me->mvert, me->totvert, me->mloop, - me->mpoly, me->totloop, me->totpoly, - NULL, NULL, 0, NULL, NULL); + BKE_mesh_calc_normals(me); } /* apply new coords on active key block */ @@ -3278,7 +3276,7 @@ static void sculpt_flush_stroke_deform(Sculpt *sd, Object *ob) /* Modifiers could depend on mesh normals, so we should update them/ * Note, then if sculpting happens on locked key, normals should be re-calculated * after applying coords from keyblock on base mesh */ - BKE_mesh_calc_normals(me->mvert, me->totvert, me->mloop, me->mpoly, me->totloop, me->totpoly, NULL); + BKE_mesh_calc_normals(me); } else if (ss->kb) { sculpt_update_keyblock(ob); diff --git a/source/blender/makesdna/DNA_mesh_types.h b/source/blender/makesdna/DNA_mesh_types.h index 499b8176e1d..947bf593310 100644 --- a/source/blender/makesdna/DNA_mesh_types.h +++ b/source/blender/makesdna/DNA_mesh_types.h @@ -221,9 +221,6 @@ typedef struct TFace { #define USE_BMESH_SAVE_AS_COMPAT #define USE_BMESH_SAVE_WITHOUT_MFACE -/* enable this to calculate mpoly normal layer and face origindex mapping */ -// #define USE_BMESH_MPOLY_NORMALS - /* enable this so meshes get tessfaces calculated by default */ // #define USE_TESSFACE_DEFAULT diff --git a/source/blender/makesrna/intern/rna_mesh_api.c b/source/blender/makesrna/intern/rna_mesh_api.c index 1e75569c841..3b0936a3830 100644 --- a/source/blender/makesrna/intern/rna_mesh_api.c +++ b/source/blender/makesrna/intern/rna_mesh_api.c @@ -66,7 +66,7 @@ void RNA_api_mesh(StructRNA *srna) parm = RNA_def_float_matrix(func, "matrix", 4, 4, NULL, 0.0f, 0.0f, "", "Matrix", 0.0f, 0.0f); RNA_def_property_flag(parm, PROP_REQUIRED); - func = RNA_def_function(srna, "calc_normals", "ED_mesh_calc_normals"); + func = RNA_def_function(srna, "calc_normals", "BKE_mesh_calc_normals"); RNA_def_function_ui_description(func, "Calculate vertex normals"); func = RNA_def_function(srna, "calc_tessface", "ED_mesh_calc_tessface"); diff --git a/source/blenderplayer/bad_level_call_stubs/stubs.c b/source/blenderplayer/bad_level_call_stubs/stubs.c index d0445236740..10d2934a0d2 100644 --- a/source/blenderplayer/bad_level_call_stubs/stubs.c +++ b/source/blenderplayer/bad_level_call_stubs/stubs.c @@ -356,7 +356,6 @@ void uiLayoutSetScaleX(struct uiLayout *layout, float scale) {STUB_ASSERT(0);} void uiLayoutSetScaleY(struct uiLayout *layout, float scale) {STUB_ASSERT(0);} void uiTemplateIconView(struct uiLayout *layout, struct PointerRNA *ptr, const char *propname) {STUB_ASSERT(0);} void ED_base_object_free_and_unlink(struct Scene *scene, struct Base *base) {STUB_ASSERT(0);} -void ED_mesh_calc_normals(struct Mesh *me) {STUB_ASSERT(0);} void ED_mesh_geometry_add(struct Mesh *mesh, struct ReportList *reports, int verts, int edges, int faces) {STUB_ASSERT(0);} void ED_mesh_material_add(struct Mesh *me, struct Material *ma) {STUB_ASSERT(0);} void ED_mesh_transform(struct Mesh *me, float *mat) {STUB_ASSERT(0);}