Revision: 15281
          
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=15281
Author:   nicholasbishop
Date:     2008-06-19 17:35:44 +0200 (Thu, 19 Jun 2008)

Log Message:
-----------
Fixed updating of normals during sculpting for non-smooth multires meshes.

Modified Paths:
--------------
    branches/soc-2008-nicholasbishop/source/blender/blenkernel/BKE_sculpt.h
    branches/soc-2008-nicholasbishop/source/blender/src/sculptmode.c

Modified: 
branches/soc-2008-nicholasbishop/source/blender/blenkernel/BKE_sculpt.h
===================================================================
--- branches/soc-2008-nicholasbishop/source/blender/blenkernel/BKE_sculpt.h     
2008-06-19 14:40:46 UTC (rev 15280)
+++ branches/soc-2008-nicholasbishop/source/blender/blenkernel/BKE_sculpt.h     
2008-06-19 15:35:44 UTC (rev 15281)
@@ -48,6 +48,7 @@
        int totface;
        struct MVert *mvert;
        struct MFace *mface;
+       float *face_normals;
        
        /* An array of lists; array is sized as
           large as the number of verts in the mesh,

Modified: branches/soc-2008-nicholasbishop/source/blender/src/sculptmode.c
===================================================================
--- branches/soc-2008-nicholasbishop/source/blender/src/sculptmode.c    
2008-06-19 14:40:46 UTC (rev 15280)
+++ branches/soc-2008-nicholasbishop/source/blender/src/sculptmode.c    
2008-06-19 15:35:44 UTC (rev 15281)
@@ -1087,19 +1087,27 @@
        a->symm = orig;
 }
 
-void add_face_normal(vec3f *norm, MVert *mvert, const MFace* face)
+void add_face_normal(vec3f *norm, MVert *mvert, const MFace* face, float *fn)
 {
        vec3f c= 
{mvert[face->v1].co[0],mvert[face->v1].co[1],mvert[face->v1].co[2]};
        vec3f b= 
{mvert[face->v2].co[0],mvert[face->v2].co[1],mvert[face->v2].co[2]};
        vec3f a= 
{mvert[face->v3].co[0],mvert[face->v3].co[1],mvert[face->v3].co[2]};
        vec3f s1, s2;
+       float final[3];
 
        VecSubf(&s1.x,&a.x,&b.x);
        VecSubf(&s2.x,&c.x,&b.x);
 
-       norm->x+= s1.y * s2.z - s1.z * s2.y;
-       norm->y+= s1.z * s2.x - s1.x * s2.z;
-       norm->z+= s1.x * s2.y - s1.y * s2.x;
+       final[0] = s1.y * s2.z - s1.z * s2.y;
+       final[1] = s1.z * s2.x - s1.x * s2.z;
+       final[2] = s1.x * s2.y - s1.y * s2.x;
+
+       if(fn)
+               VecCopyf(fn, final);
+
+       norm->x+= final[0];
+       norm->y+= final[1];
+       norm->z+= final[2];
 }
 
 void update_damaged_vert(ListBase *lb, BrushAction *a)
@@ -1112,7 +1120,10 @@
                IndexNode *face= 
sculpt_session()->vertex_users[vert->Index].first;
 
                while(face){
-                       add_face_normal(&norm, ss->mvert, 
&ss->mface[face->Index]);
+                       float *fn = NULL;
+                       if(ss->face_normals)
+                               fn = &ss->face_normals[face->Index*3];
+                       add_face_normal(&norm, ss->mvert, 
&ss->mface[face->Index], fn);
                        face= face->next;
                }
                Normalize(&norm.x);
@@ -1643,6 +1654,7 @@
                ss->totface = dm->getNumFaces(dm);
                ss->mvert = dm->getVertDataArray(dm, CD_MVERT);
                ss->mface = dm->getFaceDataArray(dm, CD_MFACE);
+               ss->face_normals = dm->getFaceDataArray(dm, CD_NORMAL);
        }
        else {
                Mesh *me = get_mesh(ob);
@@ -1651,6 +1663,7 @@
                ss->totface = me->totface;
                ss->mvert = me->mvert;
                ss->mface = me->mface;
+               ss->face_normals = NULL;
        }
 
        /* Check that vertex users are up-to-date */


_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to