Revision: 42476
          
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=42476
Author:   campbellbarton
Date:     2011-12-07 01:12:53 +0000 (Wed, 07 Dec 2011)
Log Message:
-----------
alternative fix for [#29338], now dont duplicate the vertex layer when 
calculating normals, instead only calculate face normals.

Modified Paths:
--------------
    branches/bmesh/blender/source/blender/blenkernel/intern/DerivedMesh.c
    branches/bmesh/blender/source/blender/blenkernel/intern/cdderivedmesh.c

Modified: branches/bmesh/blender/source/blender/blenkernel/intern/DerivedMesh.c
===================================================================
--- branches/bmesh/blender/source/blender/blenkernel/intern/DerivedMesh.c       
2011-12-07 00:36:57 UTC (rev 42475)
+++ branches/bmesh/blender/source/blender/blenkernel/intern/DerivedMesh.c       
2011-12-07 01:12:53 UTC (rev 42476)
@@ -1109,8 +1109,6 @@
        int draw_flag= ((scene->toolsettings->multipaint ? CALC_WP_MULTIPAINT : 
0) |
                        (scene->toolsettings->auto_normalize ? 
CALC_WP_AUTO_NORMALIZE : 0));
 
-       short do_re_tessellate;
-
        if(mmd && !mmd->sculptlvl)
                has_multires = 0;
 
@@ -1412,19 +1410,13 @@
 
                CDDM_apply_vert_coords(finaldm, deformedVerts);
 
-               /* BMESH_TODO, do_re_tesselate recalculates normals anyway, 
this seems redundant! - campbell */
                CDDM_calc_normals(finaldm);
 
                if((dataMask & CD_MASK_WEIGHT_MCOL) && (ob->mode & 
OB_MODE_WEIGHT_PAINT))
                        add_weight_mcol_dm(ob, finaldm, draw_flag);
 
-               do_re_tessellate= TRUE;
-
        } else if(dm) {
                finaldm = dm;
-
-               do_re_tessellate= TRUE;
-
        } else {
                int recalc_normals= 0;
 
@@ -1445,8 +1437,6 @@
                
                if((dataMask & CD_MASK_WEIGHT_MCOL) && (ob->mode & 
OB_MODE_WEIGHT_PAINT))
                        add_weight_mcol_dm(ob, finaldm, draw_flag);
-
-               do_re_tessellate= FALSE;
        }
 
        /* add an orco layer if needed */
@@ -1470,23 +1460,22 @@
 #endif /* WITH_GAMEENGINE */
 
 
-       /* need to check when this isnt needed.
-        * - when the mesh has no modifiers (shouldnt be needed)
-        * - deform only? (unside, can try skip) but need to double check
-        * - rebuild mesh with constructive modifier (ofcourse)
-        *
-        * Need to watch this, it can cause issues, see bug [#29338]
-        */
-       if (do_re_tessellate) {
-               /* Re-tesselation is necessary to push render data (uvs, 
textures, colors)
-                * from loops and polys onto the tessfaces. This may be 
currently be redundant
-                * in cases where the render mode doesn't use these inputs, but 
ideally
-                * eventually tesselation would happen on-demand, and this is 
one of the primary
-                * places it would be needed. */
-               finaldm->recalcTesselation(finaldm);
-               finaldm->calcNormals(finaldm);
-       }
+       /* 
--------------------------------------------------------------------- */
+       /* Re-tesselation is necessary to push render data (uvs, textures, 
colors)
+        * from loops and polys onto the tessfaces. This may be currently be
+        * redundantin cases where the render mode doesn't use these inputs, but
+        * ideally eventually tesselation would happen on-demand, and this is 
one
+        * of the primary places it would be needed. */
+       finaldm->recalcTesselation(finaldm);
+       /* if we have no modifiers applied we'lll still want the tessface 
normals
+        * to be calculated from the polygon noramals,
+        * 'CDDM_calc_normals' checks for this case - campbell */
+       finaldm->calcNormals(finaldm);
+       /* Need to watch this, it can cause issues, see bug [#29338]            
 */
+       /* take care with this block, we really need testing frameworks         
 */
+       /* 
--------------------------------------------------------------------- */
 
+
        *final_r = finaldm;
 
        if(orcodm)

Modified: 
branches/bmesh/blender/source/blender/blenkernel/intern/cdderivedmesh.c
===================================================================
--- branches/bmesh/blender/source/blender/blenkernel/intern/cdderivedmesh.c     
2011-12-07 00:36:57 UTC (rev 42475)
+++ branches/bmesh/blender/source/blender/blenkernel/intern/cdderivedmesh.c     
2011-12-07 01:12:53 UTC (rev 42476)
@@ -2232,11 +2232,20 @@
 {
        CDDerivedMesh *cddm = (CDDerivedMesh*)dm;
        float (*face_nors)[3] = NULL;
+
+       /* use this to skip calculating normals on original vert's, this may 
need to be changed */
+       const short only_face_normals = 
CustomData_is_referenced_layer(&dm->vertData, CD_MVERT);
        
        if(dm->numVertData == 0) return;
 
+       /* now we skip calculating vertex normals for referenced layer,
+        * no need to duplicate verts.
+        * WATCH THIS, bmesh only change!,
+        * need to take care of the side effects here - campbell */
+#if 0
        /* we don't want to overwrite any referenced layers */
        cddm->mvert = CustomData_duplicate_referenced_layer(&dm->vertData, 
CD_MVERT);
+#endif
 
        if (dm->numTessFaceData == 0) {
                /* No tesselation on this mesh yet, need to calculate one */
@@ -2251,9 +2260,10 @@
        face_nors = MEM_mallocN(sizeof(float)*3*dm->numTessFaceData, 
"face_nors");
        
        /* calculate face normals */
-       mesh_calc_normals(cddm->mvert, dm->numVertData, CDDM_get_loops(dm), 
CDDM_get_polys(dm), 
-                                         dm->numLoopData, dm->numPolyData, 
NULL, cddm->mface, dm->numTessFaceData, 
-                                         CustomData_get_layer(&dm->faceData, 
CD_POLYINDEX), face_nors);
+       mesh_calc_normals_ex(cddm->mvert, dm->numVertData, CDDM_get_loops(dm), 
CDDM_get_polys(dm),
+                            dm->numLoopData, dm->numPolyData, NULL, 
cddm->mface, dm->numTessFaceData,
+                            CustomData_get_layer(&dm->faceData, CD_POLYINDEX), 
face_nors,
+                            only_face_normals);
        
        CustomData_add_layer(&dm->faceData, CD_NORMAL, CD_ASSIGN, 
                face_nors, dm->numTessFaceData);

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

Reply via email to