- change mesh_calc_normals to set vertices with len(no)==0

to normalised coordinate (convention in blender, helps with
   halo)
 - removed vertexnormals(), vertexnormals_mesh()
 - removed CTX_NO_NOR_RECALC (always assume already calculated)
 - change NMesh.c to call mesh_calc_normals
 - chance load_editMesh to call mesh_calc_normals after done
   converting instead of using editmesh normals
 - update recalc_editnormals to also calc vertex normals (whats
   4 more adds and a sqrt among friends)

Its hard to believe, but it just might be the case that there
are only two places mesh normals are calculated now (renderer
and kernel)
This commit is contained in:
2005-07-23 19:03:43 +00:00
parent 948f27c0d8
commit fb651ddb4a
10 changed files with 25 additions and 326 deletions

View File

@@ -39,7 +39,6 @@ void join_mesh(void);
void fasterdraw(void);
void slowerdraw(void);
void vertexnormals_mesh(Mesh *me);
void sort_faces(void);
*/
@@ -533,163 +532,6 @@ void slowerdraw(void) /* reset fasterdraw */
allqueue(REDRAWVIEW3D, 0);
}
/* ***************** */
/* this one for NOT in editmode
(only used by external modules, that is, until now by the
python NMesh module)
TODO: Probably it's better to convert the mesh into a EditMesh, call
vertexnormals() and convert it back to a Mesh again.
*/
static int contrpuntnorm(float *n, float *puno) /* dutch: check vertex normal */
{
float inp;
inp= n[0]*puno[0]+n[1]*puno[1]+n[2]*puno[2];
/* angles 90 degrees: dont flip */
if(inp> -0.000001) return 0;
return 1;
}
void vertexnormals_mesh(Mesh *me)
{
MVert *mvert;
MFace *mface;
float n1[3], n2[3], n3[3], n4[3], co[4], *temp;
float xn, yn, zn, *normals;
float *v1, *v2, *v3, *v4, len, vnor[3];
int a, testflip;
if(me->totvert==0) return;
testflip= (me->flag & ME_NOPUNOFLIP)==0;
if((me->flag & ME_TWOSIDED)==0) testflip= 0; /* large angles */
if(me->totface==0) {
/* fake vertex normals for 'halopuno' (render option) */
mvert= me->mvert;
for(a=0; a<me->totvert; a++, mvert++) {
VECCOPY(n1, mvert->co);
Normalise(n1);
mvert->no[0]= 32767.0*n1[0];
mvert->no[1]= 32767.0*n1[1];
mvert->no[2]= 32767.0*n1[2];
}
return;
}
normals= MEM_callocN(me->totvert*3*sizeof(float), "normals");
/* calculate cosine angles, and add to vertex normal */
mface= me->mface;
mvert= me->mvert;
for(a=0; a<me->totface; a++, mface++) {
if(mface->v3==0) continue;
v1= (mvert+mface->v1)->co;
v2= (mvert+mface->v2)->co;
v3= (mvert+mface->v3)->co;
v4= (mvert+mface->v4)->co;
VecSubf(n1, v2, v1);
VecSubf(n2, v3, v2);
Normalise(n1);
Normalise(n2);
if(mface->v4==0) {
VecSubf(n3, v1, v3);
Normalise(n3);
co[0]= saacos(-n3[0]*n1[0]-n3[1]*n1[1]-n3[2]*n1[2]);
co[1]= saacos(-n1[0]*n2[0]-n1[1]*n2[1]-n1[2]*n2[2]);
co[2]= saacos(-n2[0]*n3[0]-n2[1]*n3[1]-n2[2]*n3[2]);
}
else {
VecSubf(n3, v4, v3);
VecSubf(n4, v1, v4);
Normalise(n3);
Normalise(n4);
co[0]= saacos(-n4[0]*n1[0]-n4[1]*n1[1]-n4[2]*n1[2]);
co[1]= saacos(-n1[0]*n2[0]-n1[1]*n2[1]-n1[2]*n2[2]);
co[2]= saacos(-n2[0]*n3[0]-n2[1]*n3[1]-n2[2]*n3[2]);
co[3]= saacos(-n3[0]*n4[0]-n3[1]*n4[1]-n3[2]*n4[2]);
}
CalcNormFloat(v1, v2, v3, vnor);
temp= normals+3*mface->v1;
if(testflip && contrpuntnorm(vnor, temp) ) co[0]= -co[0];
temp[0]+= co[0]*vnor[0];
temp[1]+= co[0]*vnor[1];
temp[2]+= co[0]*vnor[2];
temp= normals+3*mface->v2;
if(testflip && contrpuntnorm(vnor, temp) ) co[1]= -co[1];
temp[0]+= co[1]*vnor[0];
temp[1]+= co[1]*vnor[1];
temp[2]+= co[1]*vnor[2];
temp= normals+3*mface->v3;
if(testflip && contrpuntnorm(vnor, temp) ) co[2]= -co[2];
temp[0]+= co[2]*vnor[0];
temp[1]+= co[2]*vnor[1];
temp[2]+= co[2]*vnor[2];
if(mface->v4) {
temp= normals+3*mface->v4;
if(testflip && contrpuntnorm(vnor, temp) ) co[3]= -co[3];
temp[0]+= co[3]*vnor[0];
temp[1]+= co[3]*vnor[1];
temp[2]+= co[3]*vnor[2];
}
}
/* normalize vertex normals */
mvert= me->mvert;
for(a=0; a<me->totvert; a++, mvert++) {
len= Normalise(normals+3*a);
if(len!=0.0) {
VECCOPY(n1, normals+3*a);
Normalise(n1);
mvert->no[0]= 32767.0*n1[0];
mvert->no[1]= 32767.0*n1[1];
mvert->no[2]= 32767.0*n1[2];
}
}
/* vertex normal flipping flags, for during render */
mface= me->mface;
mvert= me->mvert;
for(a=0; a<me->totface; a++, mface++) {
if(mface->v3==0) continue;
v1= (mvert+mface->v1)->co;
v2= (mvert+mface->v2)->co;
v3= (mvert+mface->v3)->co;
CalcNormFloat(v1, v2, v3, vnor);
/* proj for cubemap! */
xn= fabs(vnor[0]);
yn= fabs(vnor[1]);
zn= fabs(vnor[2]);
}
MEM_freeN(normals);
}
/* ********************** SORT FACES ******************* */
static void permutate(void *list, int num, int size, int *index)