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>2012-01-06 04:08:37 +0400
committerCampbell Barton <ideasman42@gmail.com>2012-01-06 04:08:37 +0400
commit2b2c1007f6a960274f3ddbcfa0ac2849e65894c9 (patch)
treec98b9422fc4df7d2090dbe6d5e75d0077993fd52
parent2c9f08302c13ace22befb0603ec5f5ee2c7f31b1 (diff)
rename normal calc functions.
comparing bmesh to trunk, mesh_calc_normals() in bmesh is a much more comprehensive function, calculating mpoly,mface normals, where trunk only calculated vertex normals. renamed: * mesh_calc_normals() --> mesh_calc_normals_mapping_ex * mesh_calc_tessface_normals --> mesh_calc_normals_tessface() - only calculates normals from tessface * added mesh_calc_normals() - only calculates normals from poltys this way we can have mesh_calc_normals() remain fast for parts of the code which only need vertex normals to be updated. only refactor, no func changes- didnt replace mesh_calc_normals_mapping_ex() with mesh_calc_normals() anywhere yet.
-rw-r--r--source/blender/blenkernel/BKE_mesh.h22
-rw-r--r--source/blender/blenkernel/intern/cdderivedmesh.c2
-rw-r--r--source/blender/blenkernel/intern/mesh.c142
-rw-r--r--source/blender/blenlib/intern/pbvh.c2
-rw-r--r--source/blender/blenloader/intern/readfile.c2
-rw-r--r--source/blender/collada/MeshImporter.cpp2
-rw-r--r--source/blender/editors/mesh/mesh_data.c6
-rw-r--r--source/blender/editors/object/object_transform.c2
-rw-r--r--source/blender/editors/sculpt_paint/sculpt.c4
-rw-r--r--source/blender/editors/sculpt_paint/sculpt_undo.c2
10 files changed, 104 insertions, 82 deletions
diff --git a/source/blender/blenkernel/BKE_mesh.h b/source/blender/blenkernel/BKE_mesh.h
index 9172ad86fee..6fcbb6d9f18 100644
--- a/source/blender/blenkernel/BKE_mesh.h
+++ b/source/blender/blenkernel/BKE_mesh.h
@@ -123,7 +123,7 @@ void copy_dverts(struct MDeformVert *dst, struct MDeformVert *src, int totvert);
void mesh_delete_material_index(struct Mesh *me, short index);
void mesh_set_smooth_flag(struct Object *meshOb, int enableSmooth);
void convert_mfaces_to_mpolys(struct Mesh *mesh);
-void mesh_calc_tessface_normals(struct MVert *mverts, int numVerts,struct MFace *mfaces, int numFaces, float (*faceNors_r)[3]);
+void mesh_calc_normals_tessface(struct MVert *mverts, int numVerts,struct MFace *mfaces, int numFaces, float (*faceNors_r)[3]);
/*used for unit testing; compares two meshes, checking only
differences we care about. should be usable with leaf's
@@ -143,14 +143,20 @@ void mesh_strip_loose_edges(struct Mesh *me);
/* Calculate vertex and face normals, face normals are returned in *faceNors_r if non-NULL
* and vertex normals are stored in actual mverts.
*/
-void mesh_calc_normals(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]);
+void 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 'mesh_calc_normals' with option not to calc vertex normals */
-void mesh_calc_normals_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 short only_face_normals);
+void 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 short only_face_normals);
+
+void mesh_calc_normals(
+ struct MVert *mverts, int numVerts, struct MLoop *mloop,
+ struct MPoly *mpolys, int UNUSED(numLoops), int numPolys, float (*polyNors_r)[3]);
/* Return a newly MEM_malloc'd array of all the mesh vertex locations
* (_numVerts_r_ may be NULL) */
diff --git a/source/blender/blenkernel/intern/cdderivedmesh.c b/source/blender/blenkernel/intern/cdderivedmesh.c
index 164299d4462..7aee5d4b5aa 100644
--- a/source/blender/blenkernel/intern/cdderivedmesh.c
+++ b/source/blender/blenkernel/intern/cdderivedmesh.c
@@ -2258,7 +2258,7 @@ void CDDM_calc_normals(DerivedMesh *dm)
face_nors = MEM_mallocN(sizeof(float)*3*dm->numTessFaceData, "face_nors");
/* calculate face normals */
- mesh_calc_normals_ex(cddm->mvert, dm->numVertData, CDDM_get_loops(dm), CDDM_get_polys(dm),
+ mesh_calc_normals_mapping_ex(cddm->mvert, dm->numVertData, CDDM_get_loops(dm), CDDM_get_polys(dm),
dm->numLoopData, dm->numPolyData, NULL, cddm->mface, dm->numTessFaceData,
CustomData_get_layer(&dm->faceData, CD_POLYINDEX), face_nors,
only_face_normals);
diff --git a/source/blender/blenkernel/intern/mesh.c b/source/blender/blenkernel/intern/mesh.c
index f07bd7903e9..414763fc964 100644
--- a/source/blender/blenkernel/intern/mesh.c
+++ b/source/blender/blenkernel/intern/mesh.c
@@ -1392,7 +1392,7 @@ void nurbs_to_mesh(Object *ob)
me->mloop= CustomData_add_layer(&me->ldata, CD_MLOOP, CD_ASSIGN, allloop, me->totloop);
me->mpoly= CustomData_add_layer(&me->pdata, CD_MPOLY, CD_ASSIGN, allpoly, me->totpoly);
- mesh_calc_normals(me->mvert, me->totvert, me->mloop, me->mpoly, me->totloop, me->totpoly, NULL, NULL, 0, NULL, NULL);
+ mesh_calc_normals_mapping(me->mvert, me->totvert, me->mloop, me->mpoly, me->totloop, me->totpoly, NULL, NULL, 0, NULL, NULL);
} else {
me= add_mesh("Mesh");
DM_to_mesh(dm, me, ob);
@@ -1663,24 +1663,25 @@ void mesh_set_smooth_flag(Object *meshOb, int enableSmooth)
}
}
-void mesh_calc_normals(MVert *mverts, int numVerts, MLoop *mloop, MPoly *mpolys,
- int numLoops, int numPolys, float (*polyNors_r)[3], MFace *mfaces, int numFaces,
- int *origIndexFace, float (*faceNors_r)[3])
+void mesh_calc_normals_mapping(MVert *mverts, int numVerts,
+ MLoop *mloop, MPoly *mpolys, int numLoops, int numPolys, float (*polyNors_r)[3],
+ MFace *mfaces, int numFaces, int *origIndexFace, float (*faceNors_r)[3])
{
- mesh_calc_normals_ex(mverts, numVerts, mloop, mpolys,
- numLoops, numPolys, polyNors_r, mfaces, numFaces,
- origIndexFace, faceNors_r, TRUE);
+ mesh_calc_normals_mapping_ex(mverts, numVerts, mloop, mpolys,
+ numLoops, numPolys, polyNors_r, mfaces, numFaces,
+ origIndexFace, faceNors_r, TRUE);
}
-void mesh_calc_normals_ex(MVert *mverts, int numVerts, MLoop *mloop, MPoly *mpolys,
- int UNUSED(numLoops), int numPolys, float (*polyNors_r)[3], MFace *mfaces, int numFaces,
- int *origIndexFace, float (*faceNors_r)[3],
- const short only_face_normals)
+
+void mesh_calc_normals_mapping_ex(MVert *mverts, int numVerts,
+ MLoop *mloop, MPoly *mpolys,
+ int numLoops, int numPolys, float (*polyNors_r)[3],
+ MFace *mfaces, int numFaces, int *origIndexFace, float (*faceNors_r)[3],
+ const short only_face_normals)
{
float (*pnors)[3] = polyNors_r, (*fnors)[3] = faceNors_r;
- int i, j;
+ int i;
MFace *mf;
MPoly *mp;
- MLoop *ml;
if (numPolys == 0) {
return;
@@ -1699,51 +1700,7 @@ void mesh_calc_normals_ex(MVert *mverts, int numVerts, MLoop *mloop, MPoly *mpol
if (only_face_normals == FALSE) {
/* vertex normals are optional, they require some extra calculations,
* so make them optional */
-
- float (*tnorms)[3], (*edgevecbuf)[3]= NULL;
- float **vertcos = NULL, **vertnos = NULL;
- BLI_array_declare(vertcos);
- BLI_array_declare(vertnos);
- BLI_array_declare(edgevecbuf);
-
- /*first go through and calculate normals for all the polys*/
- tnorms = MEM_callocN(sizeof(float)*3*numVerts, "tnorms mesh.c");
-
- mp = mpolys;
- for (i=0; i<numPolys; i++, mp++) {
- mesh_calc_poly_normal(mp, mloop+mp->loopstart, mverts, pnors[i]);
- ml = mloop + mp->loopstart;
-
- BLI_array_empty(vertcos);
- BLI_array_empty(vertnos);
- for (j=0; j<mp->totloop; j++) {
- int vindex = ml[j].v;
- BLI_array_append(vertcos, mverts[vindex].co);
- BLI_array_append(vertnos, tnorms[vindex]);
- }
-
- BLI_array_empty(edgevecbuf);
- BLI_array_growitems(edgevecbuf, mp->totloop);
-
- accumulate_vertex_normals_poly(vertnos, pnors[i], vertcos, edgevecbuf, mp->totloop);
- }
-
- BLI_array_free(vertcos);
- BLI_array_free(vertnos);
- BLI_array_free(edgevecbuf);
-
- /* following Mesh convention; we use vertex coordinate itself for normal in this case */
- for(i=0; i<numVerts; i++) {
- MVert *mv= &mverts[i];
- float *no= tnorms[i];
-
- if(normalize_v3(no) == 0.0f)
- normalize_v3_v3(no, mv->co);
-
- normal_float_to_short_v3(mv->no, no);
- }
-
- MEM_freeN(tnorms);
+ mesh_calc_normals(mverts, numVerts, mloop, mpolys, numLoops, numPolys, polyNors_r);
}
else {
/* only calc poly normals */
@@ -1776,7 +1733,66 @@ void mesh_calc_normals_ex(MVert *mverts, int numVerts, MLoop *mloop, MPoly *mpol
}
-void mesh_calc_tessface_normals(MVert *mverts, int numVerts, MFace *mfaces, int numFaces, float (*faceNors_r)[3])
+void mesh_calc_normals(MVert *mverts, int numVerts, MLoop *mloop, MPoly *mpolys,
+ int UNUSED(numLoops), int numPolys, float (*polyNors_r)[3])
+{
+ float (*pnors)[3] = polyNors_r;
+
+ float (*tnorms)[3], (*edgevecbuf)[3]= NULL;
+ float **vertcos = NULL, **vertnos = NULL;
+ BLI_array_declare(vertcos);
+ BLI_array_declare(vertnos);
+ BLI_array_declare(edgevecbuf);
+
+ int i, j;
+ MPoly *mp;
+ MLoop *ml;
+
+ if (!pnors) pnors = MEM_callocN(sizeof(float) * 3 * numPolys, "poly_nors mesh.c");
+
+ /*first go through and calculate normals for all the polys*/
+ tnorms = MEM_callocN(sizeof(float)*3*numVerts, "tnorms mesh.c");
+
+ mp = mpolys;
+ for (i=0; i<numPolys; i++, mp++) {
+ mesh_calc_poly_normal(mp, mloop+mp->loopstart, mverts, pnors[i]);
+ ml = mloop + mp->loopstart;
+
+ BLI_array_empty(vertcos);
+ BLI_array_empty(vertnos);
+ for (j=0; j<mp->totloop; j++) {
+ int vindex = ml[j].v;
+ BLI_array_append(vertcos, mverts[vindex].co);
+ BLI_array_append(vertnos, tnorms[vindex]);
+ }
+
+ BLI_array_empty(edgevecbuf);
+ BLI_array_growitems(edgevecbuf, mp->totloop);
+
+ accumulate_vertex_normals_poly(vertnos, pnors[i], vertcos, edgevecbuf, mp->totloop);
+ }
+
+ BLI_array_free(vertcos);
+ BLI_array_free(vertnos);
+ BLI_array_free(edgevecbuf);
+
+ /* following Mesh convention; we use vertex coordinate itself for normal in this case */
+ for(i=0; i<numVerts; i++) {
+ MVert *mv= &mverts[i];
+ float *no= tnorms[i];
+
+ if(normalize_v3(no) == 0.0f)
+ normalize_v3_v3(no, mv->co);
+
+ normal_float_to_short_v3(mv->no, no);
+ }
+
+ MEM_freeN(tnorms);
+
+ if (pnors != polyNors_r) MEM_freeN(pnors);
+}
+
+void 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");
float (*fnors)[3]= (faceNors_r)? faceNors_r: MEM_callocN(sizeof(*fnors)*numFaces, "meshnormals");
@@ -2602,15 +2618,15 @@ static void mesh_calc_ngon_normal_coords(MPoly *mpoly, MLoop *loopstart,
const float (*vertex_coords)[3], float normal[3])
{
- float *v1, *v2, *v3;
+ const float *v1, *v2, *v3;
double u[3], v[3], w[3];
double n[3] = {0.0, 0.0, 0.0}, l;
int i;
for(i = 0; i < mpoly->totloop; i++){
- v1 = vertex_coords + loopstart[i].v;
- v2 = vertex_coords + loopstart[(i+1)%mpoly->totloop].v;
- v3 = vertex_coords + loopstart[(i+2)%mpoly->totloop].v;
+ v1 = (const float *)(vertex_coords + loopstart[i].v);
+ v2 = (const float *)(vertex_coords + loopstart[(i+1)%mpoly->totloop].v);
+ v3 = (const float *)(vertex_coords + loopstart[(i+2)%mpoly->totloop].v);
VECCOPY(u, v1);
VECCOPY(v, v2);
diff --git a/source/blender/blenlib/intern/pbvh.c b/source/blender/blenlib/intern/pbvh.c
index ae0becc840b..b7175db4ca3 100644
--- a/source/blender/blenlib/intern/pbvh.c
+++ b/source/blender/blenlib/intern/pbvh.c
@@ -1585,7 +1585,7 @@ void BLI_pbvh_apply_vertCos(PBVH *pbvh, float (*vertCos)[3])
}
/* coordinates are new -- normals should also be updated */
- mesh_calc_tessface_normals(pbvh->verts, pbvh->totvert, pbvh->faces, pbvh->totprim, NULL);
+ mesh_calc_normals_tessface(pbvh->verts, pbvh->totvert, pbvh->faces, pbvh->totprim, NULL);
for (a= 0; a < pbvh->totnode; ++a)
BLI_pbvh_node_mark_update(&pbvh->nodes[a]);
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index 162d3102cb6..c44b95fb353 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -12327,7 +12327,7 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
Mesh *me;
for(me= main->mesh.first; me; me= me->id.next)
- mesh_calc_tessface_normals(me->mvert, me->totvert, me->mface, me->totface, NULL);
+ mesh_calc_normals_tessface(me->mvert, me->totvert, me->mface, me->totface, NULL);
}
if (main->versionfile < 256 || (main->versionfile == 256 && main->subversionfile < 2)){
diff --git a/source/blender/collada/MeshImporter.cpp b/source/blender/collada/MeshImporter.cpp
index 90671ddc162..26ec7be1002 100644
--- a/source/blender/collada/MeshImporter.cpp
+++ b/source/blender/collada/MeshImporter.cpp
@@ -959,7 +959,7 @@ bool MeshImporter::write_geometry(const COLLADAFW::Geometry* geom)
make_edges(me, 0);
- mesh_calc_normals(me->mvert, me->totvert, me->mloop, me->mpoly, me->totloop, me->totpoly, NULL, NULL, 0, NULL, NULL);
+ mesh_calc_normals_mapping(me->mvert, me->totvert, me->mloop, me->mpoly, me->totloop, me->totpoly, NULL, NULL, 0, NULL, NULL);
return true;
}
diff --git a/source/blender/editors/mesh/mesh_data.c b/source/blender/editors/mesh/mesh_data.c
index 48aa69eff46..93ea76db569 100644
--- a/source/blender/editors/mesh/mesh_data.c
+++ b/source/blender/editors/mesh/mesh_data.c
@@ -774,7 +774,7 @@ void ED_mesh_update(Mesh *mesh, bContext *C, int calc_edges)
contain the normal of the poly the face was tesselated from. */
face_nors = CustomData_add_layer(&mesh->fdata, CD_NORMAL, CD_CALLOC, NULL, mesh->totface);
- mesh_calc_normals(
+ mesh_calc_normals_mapping(
mesh->mvert,
mesh->totvert,
mesh->mloop,
@@ -829,7 +829,7 @@ void ED_mesh_transform(Mesh *mesh, float *mat)
for(i= 0; i < mesh->totvert; i++, mvert++)
mul_m4_v3((float (*)[4])mat, mvert->co);
- mesh_calc_normals(mesh->mvert, mesh->totvert, mesh->mloop, mesh->mpoly, mesh->totloop, mesh->totpoly, NULL, NULL, 0, NULL, NULL);
+ mesh_calc_normals_mapping(mesh->mvert, mesh->totvert, mesh->mloop, mesh->mpoly, mesh->totloop, mesh->totpoly, NULL, NULL, 0, NULL, NULL);
}
static void mesh_add_edges(Mesh *mesh, int len)
@@ -1015,5 +1015,5 @@ void ED_mesh_polys_add(Mesh *mesh, ReportList *reports, int count)
void ED_mesh_calc_normals(Mesh *mesh)
{
- mesh_calc_normals(mesh->mvert, mesh->totvert, mesh->mloop, mesh->mpoly, mesh->totloop, mesh->totpoly, NULL, NULL, 0, NULL, NULL);
+ mesh_calc_normals_mapping(mesh->mvert, mesh->totvert, mesh->mloop, mesh->mpoly, mesh->totloop, mesh->totpoly, NULL, NULL, 0, NULL, NULL);
}
diff --git a/source/blender/editors/object/object_transform.c b/source/blender/editors/object/object_transform.c
index d1e4568b1cc..24061defa7c 100644
--- a/source/blender/editors/object/object_transform.c
+++ b/source/blender/editors/object/object_transform.c
@@ -480,7 +480,7 @@ static int apply_objects_internal(bContext *C, ReportList *reports, int apply_lo
}
/* update normals */
- mesh_calc_normals(me->mvert, me->totvert, me->mloop, me->mpoly, me->totloop, me->totpoly, NULL, NULL, 0, NULL, NULL);
+ mesh_calc_normals_mapping(me->mvert, me->totvert, me->mloop, me->mpoly, me->totloop, me->totpoly, NULL, NULL, 0, NULL, NULL);
}
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 ab12bd40622..e14ba9b8c4f 100644
--- a/source/blender/editors/sculpt_paint/sculpt.c
+++ b/source/blender/editors/sculpt_paint/sculpt.c
@@ -2299,7 +2299,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]);
- mesh_calc_normals(me->mvert, me->totvert, me->mloop, me->mpoly, me->totloop, me->totpoly, NULL, NULL, 0, NULL, NULL);
+ mesh_calc_normals_mapping(me->mvert, me->totvert, me->mloop, me->mpoly, me->totloop, me->totpoly, NULL, NULL, 0, NULL, NULL);
}
/* apply new coords on active key block */
@@ -2532,7 +2532,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 */
- mesh_calc_normals(me->mvert, me->totvert, me->mloop, me->mpoly, me->totloop, me->totpoly, NULL, NULL, 0, NULL, NULL);
+ mesh_calc_normals_mapping(me->mvert, me->totvert, me->mloop, me->mpoly, me->totloop, me->totpoly, NULL, NULL, 0, NULL, NULL);
} else if (ss->kb)
sculpt_update_keyblock(ob);
}
diff --git a/source/blender/editors/sculpt_paint/sculpt_undo.c b/source/blender/editors/sculpt_paint/sculpt_undo.c
index 014cbff3e22..b1f009522fa 100644
--- a/source/blender/editors/sculpt_paint/sculpt_undo.c
+++ b/source/blender/editors/sculpt_paint/sculpt_undo.c
@@ -197,7 +197,7 @@ static void sculpt_undo_restore(bContext *C, ListBase *lb)
if(ss->modifiers_active) {
Mesh *mesh= ob->data;
- mesh_calc_normals(mesh->mvert, mesh->totvert, mesh->mloop, mesh->mpoly, mesh->totloop, mesh->totpoly, NULL, NULL, 0, NULL, NULL);
+ mesh_calc_normals_mapping(mesh->mvert, mesh->totvert, mesh->mloop, mesh->mpoly, mesh->totloop, mesh->totpoly, NULL, NULL, 0, NULL, NULL);
free_sculptsession_deformMats(ss);
tag_update|= 1;