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:
authorDaniel Dunbar <daniel@zuster.org>2005-07-23 23:03:43 +0400
committerDaniel Dunbar <daniel@zuster.org>2005-07-23 23:03:43 +0400
commitfb651ddb4a47d86312a4afafaa48e1bf4e48447f (patch)
treed6e2e742f5aa1b8a4997705536e6fef828509ec0
parent948f27c0d888bbfe0f10c4350b4269166568b40d (diff)
- 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)
-rw-r--r--source/blender/blenkernel/intern/mesh.c6
-rw-r--r--source/blender/include/BIF_editmesh.h1
-rw-r--r--source/blender/include/BIF_meshtools.h1
-rwxr-xr-xsource/blender/include/BIF_transform.h1
-rw-r--r--source/blender/python/api2_2x/NMesh.c5
-rw-r--r--source/blender/src/editmesh.c6
-rw-r--r--source/blender/src/editmesh_lib.c160
-rw-r--r--source/blender/src/editmesh_tools.c11
-rw-r--r--source/blender/src/meshtools.c158
-rwxr-xr-xsource/blender/src/transform_conversions.c2
10 files changed, 25 insertions, 326 deletions
diff --git a/source/blender/blenkernel/intern/mesh.c b/source/blender/blenkernel/intern/mesh.c
index 0dbb9f0d64e..65ac43739da 100644
--- a/source/blender/blenkernel/intern/mesh.c
+++ b/source/blender/blenkernel/intern/mesh.c
@@ -1193,7 +1193,11 @@ void mesh_calc_normals(MVert *mverts, int numVerts, MFace *mfaces, int numFaces,
MVert *mv= &mverts[i];
float *no= tnorms[i];
- Normalise(no);
+ if (Normalise(no)==0.0) {
+ VECCOPY(no, mv->co);
+ Normalise(no);
+ }
+
mv->no[0]= (short)(no[0]*32767.0);
mv->no[1]= (short)(no[1]*32767.0);
mv->no[2]= (short)(no[2]*32767.0);
diff --git a/source/blender/include/BIF_editmesh.h b/source/blender/include/BIF_editmesh.h
index aa322ef5169..cd57f9eb4fe 100644
--- a/source/blender/include/BIF_editmesh.h
+++ b/source/blender/include/BIF_editmesh.h
@@ -88,7 +88,6 @@ extern int EM_nvertices_selected(void);
extern int faceselectedAND(struct EditFace *efa, int flag);
extern void recalc_editnormals(void);
extern void flip_editnormals(void);
-extern void vertexnormals(int testflip);
/* ******************* editmesh_mods.c */
diff --git a/source/blender/include/BIF_meshtools.h b/source/blender/include/BIF_meshtools.h
index 24c56629a30..d12087bc309 100644
--- a/source/blender/include/BIF_meshtools.h
+++ b/source/blender/include/BIF_meshtools.h
@@ -38,7 +38,6 @@ extern void join_mesh(void);
extern void fasterdraw(void);
extern void slowerdraw(void);
-extern void vertexnormals_mesh(Mesh *me);
extern void sort_faces(void);
diff --git a/source/blender/include/BIF_transform.h b/source/blender/include/BIF_transform.h
index 57aaf37a65d..78f2bb38c48 100755
--- a/source/blender/include/BIF_transform.h
+++ b/source/blender/include/BIF_transform.h
@@ -57,7 +57,6 @@
#define CTX_TEXTURE 1
#define CTX_EDGE 2
#define CTX_NO_PET 4
-#define CTX_NO_NOR_RECALC 8
void initTransform(int mode, int context);
void Transform(void);
diff --git a/source/blender/python/api2_2x/NMesh.c b/source/blender/python/api2_2x/NMesh.c
index d5e04b00f32..c80702dc641 100644
--- a/source/blender/python/api2_2x/NMesh.c
+++ b/source/blender/python/api2_2x/NMesh.c
@@ -47,7 +47,6 @@
#include "BIF_editdeform.h"
#include "BIF_editkey.h" /* insert_meshkey */
-#include "BIF_meshtools.h" /* current loc of vertexnormals_mesh() */
#include "BIF_editview.h"
#include "BKE_deform.h"
@@ -1325,7 +1324,7 @@ static PyObject *NMesh_update( PyObject *self, PyObject *a, PyObject *kwd )
}
if( recalc_normals )
- vertexnormals_mesh( mesh );
+ mesh_calc_normals(mesh->mvert, mesh->totvert, mesh->mface, mesh->totface, NULL);
mesh_update( mesh, nmesh->object );
@@ -2875,7 +2874,7 @@ static PyObject *M_NMesh_PutRaw( PyObject * self, PyObject * args )
if (mesh->dvert) check_dverts(mesh, old_totvert);
if( recalc_normals )
- vertexnormals_mesh( mesh );
+ mesh_calc_normals(mesh->mvert, mesh->totvert, mesh->mface, mesh->totface, NULL);
mesh_update( mesh, nmesh->object );
diff --git a/source/blender/src/editmesh.c b/source/blender/src/editmesh.c
index 12b931d7431..e9837a1dd21 100644
--- a/source/blender/src/editmesh.c
+++ b/source/blender/src/editmesh.c
@@ -915,9 +915,6 @@ void load_editMesh(void)
/* eve->f2 : being used in vertexnormals */
edge_drawflags();
- /* this sets efa->puno, punoflag (for vertex normal & projection) */
- vertexnormals( (me->flag & ME_NOPUNOFLIP)==0 );
-
eed= em->edges.first;
while(eed) {
totedge++;
@@ -1235,6 +1232,9 @@ void load_editMesh(void)
error("Sticky was too small");
}
}
+
+ mesh_calc_normals(me->mvert, me->totvert, me->mface, me->totface, NULL);
+
waitcursor(0);
}
diff --git a/source/blender/src/editmesh_lib.c b/source/blender/src/editmesh_lib.c
index 58879a39fbd..677aa070788 100644
--- a/source/blender/src/editmesh_lib.c
+++ b/source/blender/src/editmesh_lib.c
@@ -1306,149 +1306,6 @@ static int check_vnormal_flip(float *n, float *vnorm)
}
-void vertexnormals(int testflip)
-{
- EditMesh *em = G.editMesh;
- Mesh *me;
- EditVert *eve;
- EditFace *efa;
- float n1[3], n2[3], n3[3], n4[3], co[4], *temp;
- float xn, yn, zn;
- float len, area;
-
- if(G.obedit && G.obedit->type==OB_MESH) {
- me= G.obedit->data;
- if((me->flag & ME_TWOSIDED)==0) testflip= 0;
- }
-
- if(G.totvert==0) return;
-
- if(G.totface==0) {
- /* fake vertex normals for 'halo puno'! */
- eve= em->verts.first;
- while(eve) {
- VECCOPY(eve->no, eve->co);
- Normalise( (float *)eve->no);
- eve= eve->next;
- }
- return;
- }
-
- /* clear normals, clear flag */
- eve= em->verts.first;
- while(eve) {
- eve->no[0]= eve->no[1]= eve->no[2]= 0.0;
- eve->f2= 0;
- eve= eve->next;
- }
-
- /* check for vertices being shared by both solid and smooth face,
- these get vertexnormal of smooth face normal only */
- for(efa= em->faces.first; efa; efa= efa->next) {
- if(efa->flag & ME_SMOOTH) {
- efa->v1->f2 |= 1; efa->v2->f2 |= 1; efa->v3->f2 |= 1;
- if(efa->v4) efa->v4->f2 |= 1;
- }
- else {
- efa->v1->f2 |= 2; efa->v2->f2 |= 2; efa->v3->f2 |= 2;
- if(efa->v4) efa->v4->f2 |= 2;
- }
- }
-
- /* calculate cosine angles and add to vertex normal */
- for(efa= em->faces.first; efa; efa= efa->next) {
- VecSubf(n1, efa->v2->co, efa->v1->co);
- VecSubf(n2, efa->v3->co, efa->v2->co);
- Normalise(n1);
- Normalise(n2);
-
- if(efa->v4==0) {
- VecSubf(n3, efa->v1->co, efa->v3->co);
- Normalise(n3);
-
- //area= AreaT3Dfl(efa->v1->co, efa->v2->co, efa->v3->co);
- //if(area!=0.0) area=1.0/area;
- //area= sqrt(area);
- area= 1.0;
-
- co[0]= area*saacos(-n3[0]*n1[0]-n3[1]*n1[1]-n3[2]*n1[2]);
- co[1]= area*saacos(-n1[0]*n2[0]-n1[1]*n2[1]-n1[2]*n2[2]);
- co[2]= area*saacos(-n2[0]*n3[0]-n2[1]*n3[1]-n2[2]*n3[2]);
-
- }
- else {
- VecSubf(n3, efa->v4->co, efa->v3->co);
- VecSubf(n4, efa->v1->co, efa->v4->co);
- Normalise(n3);
- Normalise(n4);
-
- //area= AreaQ3Dfl(efa->v1->co, efa->v2->co, efa->v3->co, efa->v4->co);
- //if(area!=0.0) area=1.0/area;
- //area= sqrt(area);
- area= 1.0;
-
- co[0]= area*saacos(-n4[0]*n1[0]-n4[1]*n1[1]-n4[2]*n1[2]);
- co[1]= area*saacos(-n1[0]*n2[0]-n1[1]*n2[1]-n1[2]*n2[2]);
- co[2]= area*saacos(-n2[0]*n3[0]-n2[1]*n3[1]-n2[2]*n3[2]);
- co[3]= area*saacos(-n3[0]*n4[0]-n3[1]*n4[1]-n3[2]*n4[2]);
- }
-
- if(efa->v1->f2!=3 || (efa->flag & ME_SMOOTH)) {
- temp= efa->v1->no;
- if(testflip && check_vnormal_flip(efa->n, temp) ) co[0]= -co[0];
- temp[0]+= co[0]*efa->n[0];
- temp[1]+= co[0]*efa->n[1];
- temp[2]+= co[0]*efa->n[2];
- }
-
- if(efa->v2->f2!=3 || (efa->flag & ME_SMOOTH)) {
- temp= efa->v2->no;
- if(testflip && check_vnormal_flip(efa->n, temp) ) co[1]= -co[1];
- temp[0]+= co[1]*efa->n[0];
- temp[1]+= co[1]*efa->n[1];
- temp[2]+= co[1]*efa->n[2];
- }
-
- if(efa->v3->f2!=3 || (efa->flag & ME_SMOOTH)) {
- temp= efa->v3->no;
- if(testflip && check_vnormal_flip(efa->n, temp) ) co[2]= -co[2];
- temp[0]+= co[2]*efa->n[0];
- temp[1]+= co[2]*efa->n[1];
- temp[2]+= co[2]*efa->n[2];
- }
-
- if(efa->v4 && (efa->v4->f2!=3 || (efa->flag & ME_SMOOTH))) {
- temp= efa->v4->no;
- if(testflip && check_vnormal_flip(efa->n, temp) ) co[3]= -co[3];
- temp[0]+= co[3]*efa->n[0];
- temp[1]+= co[3]*efa->n[1];
- temp[2]+= co[3]*efa->n[2];
- }
- }
-
- /* normalise vertex normals */
- eve= em->verts.first;
- while(eve) {
- len= Normalise(eve->no);
- if(len==0.0) {
- VECCOPY(eve->no, eve->co);
- Normalise( eve->no);
- }
- eve= eve->next;
- }
-
- /* vertex normal flip-flags for shade (render) */
- efa= em->faces.first;
- while(efa) {
- /* projection for cubemap! */
- xn= fabs(efa->n[0]);
- yn= fabs(efa->n[1]);
- zn= fabs(efa->n[2]);
-
- efa= efa->next;
- }
-}
-
void flipface(EditFace *efa)
{
if(efa->v4) {
@@ -1491,18 +1348,29 @@ void recalc_editnormals(void)
{
EditMesh *em = G.editMesh;
EditFace *efa;
+ EditVert *eve;
- efa= em->faces.first;
- while(efa) {
+ for(eve= em->verts.first; eve; eve=eve->next) {
+ eve->no[0] = eve->no[1] = eve->no[2] = 0.0;
+ }
+
+ for(efa= em->faces.first; efa; efa=efa->next) {
if(efa->v4) {
CalcNormFloat4(efa->v1->co, efa->v2->co, efa->v3->co, efa->v4->co, efa->n);
CalcCent4f(efa->cent, efa->v1->co, efa->v2->co, efa->v3->co, efa->v4->co);
+ VecAddf(efa->v4->no, efa->v4->no, efa->n);
}
else {
CalcNormFloat(efa->v1->co, efa->v2->co, efa->v3->co, efa->n);
CalcCent3f(efa->cent, efa->v1->co, efa->v2->co, efa->v3->co);
}
- efa= efa->next;
+ VecAddf(efa->v1->no, efa->v1->no, efa->n);
+ VecAddf(efa->v2->no, efa->v2->no, efa->n);
+ VecAddf(efa->v3->no, efa->v3->no, efa->n);
+ }
+
+ for(eve= em->verts.first; eve; eve=eve->next) {
+ Normalise(eve->no);
}
}
diff --git a/source/blender/src/editmesh_tools.c b/source/blender/src/editmesh_tools.c
index 750942d3da9..68729accf4f 100644
--- a/source/blender/src/editmesh_tools.c
+++ b/source/blender/src/editmesh_tools.c
@@ -587,7 +587,7 @@ void extrude_mesh(void)
/* individual faces? */
BIF_TransformSetUndo("Extrude");
if(nr==2) {
- initTransform(TFM_SHRINKFATTEN, CTX_NO_PET|CTX_NO_NOR_RECALC);
+ initTransform(TFM_SHRINKFATTEN, CTX_NO_PET);
Transform();
}
else {
@@ -2188,9 +2188,6 @@ void esubdivideflag(int flag, float rad, int beauty, int numcuts, int seltype)
BLI_ghash_insert(gh, eed, templist);
}
}
- vertexnormals(0);
-
-
// Now for each face in the mesh we need to figure out How many edges were cut
@@ -5117,12 +5114,6 @@ void subdivideflag(int flag, float rad, int beauty)
}
}
- if(beauty & B_SMOOTH) {
-
- vertexnormals(0); /* no1*/
-
- }
-
/* make new normal and put in edge, clear flag! needed for face creation part below */
eed= em->edges.first;
while(eed) {
diff --git a/source/blender/src/meshtools.c b/source/blender/src/meshtools.c
index a2622982fae..bff61fa7f75 100644
--- a/source/blender/src/meshtools.c
+++ b/source/blender/src/meshtools.c
@@ -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)
diff --git a/source/blender/src/transform_conversions.c b/source/blender/src/transform_conversions.c
index 30b715a57a5..dd74f39e41a 100755
--- a/source/blender/src/transform_conversions.c
+++ b/source/blender/src/transform_conversions.c
@@ -1590,8 +1590,6 @@ void createTransData(TransInfo *t)
else if (G.obedit) {
t->ext = NULL;
if (G.obedit->type == OB_MESH) {
- if(t->mode==TFM_SHRINKFATTEN && (t->context & CTX_NO_NOR_RECALC)==0)
- vertexnormals(0);
createTransEditVerts(t);
}
else if ELEM(G.obedit->type, OB_CURVE, OB_SURF) {