From 709e4b309e21a0e2b7569924446b0295382e8b82 Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Mon, 4 Apr 2011 13:02:12 +0000 Subject: Revert mesh recalculation change that gives different vertex normals based on smooth/flat flag on faces. This does give better results for low poly game models, but there's just too much functionality that depends on this (modifiers, displacey, editmode tools, extrude, ...), that there's not enough time to fix these before the release. --- source/blender/blenkernel/intern/mesh.c | 47 +++------------------------------ 1 file changed, 4 insertions(+), 43 deletions(-) (limited to 'source/blender/blenkernel/intern/mesh.c') diff --git a/source/blender/blenkernel/intern/mesh.c b/source/blender/blenkernel/intern/mesh.c index 7302abe8968..f1e1b24b891 100644 --- a/source/blender/blenkernel/intern/mesh.c +++ b/source/blender/blenkernel/intern/mesh.c @@ -1277,59 +1277,20 @@ void mesh_calc_normals(MVert *mverts, int numVerts, MFace *mfaces, int numFaces, float (*tnorms)[3]= MEM_callocN(numVerts*sizeof(*tnorms), "tnorms"); float (*fnors)[3]= (faceNors_r)? faceNors_r: MEM_callocN(sizeof(*fnors)*numFaces, "meshnormals"); int i; - int found_flat=0; for(i=0; iv4)? tnorms[mf->v4]: NULL; + float *c4 = (mf->v4)? mverts[mf->v4].co: NULL; 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); - if(mf->flag & ME_SMOOTH) { - 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); - } - else { - found_flat=1; - } - } - - /* build smooth normals for uninitialized normals at faces set to flat */ - /* For such faces the renderer/3Dview and exporters will be using the face normal */ - /* The vertex normals built inside this if-statement are entirely to support the needs of the modeler */ - if(found_flat!=0) { - const int nr_bits= sizeof(int)*8; - const int nr_words= (numVerts+(nr_bits-1))/nr_bits; - int *bit_array= (int*)MEM_callocN(sizeof(int)*MAX2(nr_words, 1), "temp buffer"); - - for(i=0; iflag & ME_SMOOTH)) { - if(is_zero_v3(tnorms[mf->v1])) bit_array[mf->v1/nr_bits]|=(1<<(mf->v1&(nr_bits-1))); - if(is_zero_v3(tnorms[mf->v2])) bit_array[mf->v2/nr_bits]|=(1<<(mf->v2&(nr_bits-1))); - if(is_zero_v3(tnorms[mf->v3])) bit_array[mf->v3/nr_bits]|=(1<<(mf->v3&(nr_bits-1))); - if(mf->v4 && is_zero_v3(tnorms[mf->v4])) bit_array[mf->v4/nr_bits]|=(1<<(mf->v4&(nr_bits-1))); - } - } - - for(i=0; iv1/nr_bits]&(1<<(mf->v1&(nr_bits-1)))) add_v3_v3(tnorms[mf->v1], f_no); - if(bit_array[mf->v2/nr_bits]&(1<<(mf->v2&(nr_bits-1)))) add_v3_v3(tnorms[mf->v2], f_no); - if(bit_array[mf->v3/nr_bits]&(1<<(mf->v3&(nr_bits-1)))) add_v3_v3(tnorms[mf->v3], f_no); - if(mf->v4 && bit_array[mf->v4/nr_bits]&(1<<(mf->v4&(nr_bits-1)))) add_v3_v3(tnorms[mf->v4], f_no); - } - - MEM_freeN(bit_array); + 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); } /* following Mesh convention; we use vertex coordinate itself for normal in this case */ -- cgit v1.2.3