forked from bartvdbraak/blender
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.
This commit is contained in:
parent
265cdf29fb
commit
709e4b309e
@ -44,7 +44,7 @@ extern "C" {
|
||||
* and keep comment above the defines.
|
||||
* Use STRINGIFY() rather then defining with quotes */
|
||||
#define BLENDER_VERSION 256
|
||||
#define BLENDER_SUBVERSION 5
|
||||
#define BLENDER_SUBVERSION 6
|
||||
|
||||
#define BLENDER_MINVERSION 250
|
||||
#define BLENDER_MINSUBVERSION 0
|
||||
|
@ -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; i<numFaces; i++) {
|
||||
MFace *mf= &mfaces[i];
|
||||
float *f_no= fnors[i];
|
||||
float *n4 = (mf->v4)? 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; i<numFaces; i++) {
|
||||
MFace *mf= &mfaces[i];
|
||||
|
||||
if(!(mf->flag & 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; i<numFaces; i++) {
|
||||
MFace *mf= &mfaces[i];
|
||||
float *f_no= fnors[i];
|
||||
|
||||
if(bit_array[mf->v1/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 */
|
||||
|
@ -11545,7 +11545,7 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
|
||||
}
|
||||
}
|
||||
|
||||
if (main->versionfile < 256 || (main->versionfile == 256 && main->subversionfile < 5)){
|
||||
if (main->versionfile < 256 || (main->versionfile == 256 && main->subversionfile < 6)){
|
||||
Mesh *me;
|
||||
|
||||
for(me= main->mesh.first; me; me= me->id.next)
|
||||
|
@ -2001,12 +2001,14 @@ void recalc_editnormals(EditMesh *em)
|
||||
{
|
||||
EditFace *efa;
|
||||
EditVert *eve;
|
||||
int found_flat= 0;
|
||||
|
||||
for(eve= em->verts.first; eve; eve=eve->next)
|
||||
zero_v3(eve->no);
|
||||
|
||||
for(efa= em->faces.first; efa; efa=efa->next) {
|
||||
float *n4= (efa->v4)? efa->v4->no: NULL;
|
||||
float *c4= (efa->v4)? efa->v4->co: NULL;
|
||||
|
||||
if(efa->v4) {
|
||||
normal_quad_v3(efa->n, efa->v1->co, efa->v2->co, efa->v3->co, efa->v4->co);
|
||||
cent_quad_v3(efa->cent, efa->v1->co, efa->v2->co, efa->v3->co, efa->v4->co);
|
||||
@ -2015,42 +2017,6 @@ void recalc_editnormals(EditMesh *em)
|
||||
normal_tri_v3(efa->n, efa->v1->co, efa->v2->co, efa->v3->co);
|
||||
cent_tri_v3(efa->cent, efa->v1->co, efa->v2->co, efa->v3->co);
|
||||
}
|
||||
|
||||
if(efa->flag & ME_SMOOTH) {
|
||||
float *n4= (efa->v4)? efa->v4->no: NULL;
|
||||
float *c4= (efa->v4)? efa->v4->co: NULL;
|
||||
|
||||
accumulate_vertex_normals(efa->v1->no, efa->v2->no, efa->v3->no, n4,
|
||||
efa->n, efa->v1->co, efa->v2->co, efa->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) {
|
||||
for(efa= em->faces.first; efa; efa=efa->next) {
|
||||
efa->v1->tmp.t= 0;
|
||||
efa->v2->tmp.t= 0;
|
||||
efa->v3->tmp.t= 0;
|
||||
if(efa->v4) efa->v4->tmp.t= 0;
|
||||
|
||||
if(!(efa->flag & ME_SMOOTH)) {
|
||||
if(is_zero_v3(efa->v1->no)) efa->v1->tmp.t= 1;
|
||||
if(is_zero_v3(efa->v2->no)) efa->v2->tmp.t= 1;
|
||||
if(is_zero_v3(efa->v3->no)) efa->v3->tmp.t= 1;
|
||||
if(efa->v4 && is_zero_v3(efa->v4->no)) efa->v4->tmp.t= 1;
|
||||
}
|
||||
}
|
||||
|
||||
for(efa= em->faces.first; efa; efa=efa->next) {
|
||||
if(efa->v1->tmp.t) add_v3_v3(efa->v1->no, efa->n);
|
||||
if(efa->v2->tmp.t) add_v3_v3(efa->v2->no, efa->n);
|
||||
if(efa->v3->tmp.t) add_v3_v3(efa->v3->no, efa->n);
|
||||
if(efa->v4 && efa->v4->tmp.t) add_v3_v3(efa->v4->no, efa->n);
|
||||
}
|
||||
}
|
||||
|
||||
/* following Mesh convention; we use vertex coordinate itself for normal in this case */
|
||||
|
Loading…
Reference in New Issue
Block a user