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:
authorBrecht Van Lommel <brechtvanlommel@pandora.be>2011-03-20 16:35:35 +0300
committerBrecht Van Lommel <brechtvanlommel@pandora.be>2011-03-20 16:35:35 +0300
commit549b5e1222fcda5ca9b7d1892ca4d05e2c62c066 (patch)
treef69a4a833a3eb092530bb0d7959e43cf05ca0362 /source/blender/blenkernel/intern/mesh.c
parenta50cdf713a800c07629495f0d5e7124cddbbc2c9 (diff)
Fix/change in normal computation, now the viewport uses the same angle
weighted normals as the render engine, and the render engine will copy normals from the mesh rather than always recalculating them. Subsurf/multires still use regular vertex normals, but they are expected to be sufficiently high resolution to not need this. This means that normal maps displayed in the viewport actually match the render engine exactly and don't have artifacts due to this discrepancy. It of course also avoids unexpected surprises where your render normals look different than your viewport normals. Subversion bumped to 4 for version patch to recalculate normals. Patch by Morten Mikkelsen, with some small changes.
Diffstat (limited to 'source/blender/blenkernel/intern/mesh.c')
-rw-r--r--source/blender/blenkernel/intern/mesh.c45
1 files changed, 30 insertions, 15 deletions
diff --git a/source/blender/blenkernel/intern/mesh.c b/source/blender/blenkernel/intern/mesh.c
index 247e48a5576..1e29f5c9d3f 100644
--- a/source/blender/blenkernel/intern/mesh.c
+++ b/source/blender/blenkernel/intern/mesh.c
@@ -1278,26 +1278,42 @@ void mesh_calc_normals(MVert *mverts, int numVerts, MFace *mfaces, int numFaces,
float *fnors= MEM_callocN(sizeof(*fnors)*3*numFaces, "meshnormals");
int i;
- for (i=0; i<numFaces; i++) {
+ for(i=0; i<numFaces; i++) {
MFace *mf= &mfaces[i];
float *f_no= &fnors[i*3];
- if (mf->v4)
- normal_quad_v3( f_no,mverts[mf->v1].co, mverts[mf->v2].co, mverts[mf->v3].co, mverts[mf->v4].co);
+ if(mf->v4)
+ normal_quad_v3(f_no, mverts[mf->v1].co, mverts[mf->v2].co, mverts[mf->v3].co, mverts[mf->v4].co);
else
- normal_tri_v3( f_no,mverts[mf->v1].co, mverts[mf->v2].co, mverts[mf->v3].co);
-
- add_v3_v3(tnorms[mf->v1], f_no);
- add_v3_v3(tnorms[mf->v2], f_no);
- add_v3_v3(tnorms[mf->v3], f_no);
- if (mf->v4)
- add_v3_v3(tnorms[mf->v4], f_no);
+ normal_tri_v3(f_no, mverts[mf->v1].co, mverts[mf->v2].co, mverts[mf->v3].co);
+
+ if((mf->flag&ME_SMOOTH)!=0) {
+ float *n4 = (mf->v4)? tnorms[mf->v4]: NULL;
+ float *c4 = (mf->v4)? mverts[mf->v4].co: NULL;
+
+ accumulate_vertex_normals(tnorms[mf->v1], tnorms[mf->v2], tnorms[mf->v3], n4,
+ f_no, mverts[mf->v1].co, mverts[mf->v2].co, mverts[mf->v3].co, c4);
+ }
+ }
+
+ for(i=0; i<numFaces; i++) {
+ MFace *mf= &mfaces[i];
+
+ if((mf->flag&ME_SMOOTH)==0) {
+ float *f_no= &fnors[i*3];
+ if(is_zero_v3(tnorms[mf->v1])) copy_v3_v3(tnorms[mf->v1], f_no);
+ if(is_zero_v3(tnorms[mf->v2])) copy_v3_v3(tnorms[mf->v2], f_no);
+ if(is_zero_v3(tnorms[mf->v3])) copy_v3_v3(tnorms[mf->v3], f_no);
+ if(mf->v4 && is_zero_v3(tnorms[mf->v4])) copy_v3_v3(tnorms[mf->v4], f_no);
+ }
}
- for (i=0; i<numVerts; i++) {
+
+ /* 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.0)
+ if(normalize_v3(no) == 0.0f)
normalize_v3_v3(no, mv->co);
normal_float_to_short_v3(mv->no, no);
@@ -1305,11 +1321,10 @@ void mesh_calc_normals(MVert *mverts, int numVerts, MFace *mfaces, int numFaces,
MEM_freeN(tnorms);
- if (faceNors_r) {
+ if(faceNors_r)
*faceNors_r = fnors;
- } else {
+ else
MEM_freeN(fnors);
- }
}
float (*mesh_getVertexCos(Mesh *me, int *numVerts_r))[3]