Two bugfixes.
authorBen Batt <benbatt@gmail.com>
Thu, 7 Sep 2006 06:44:25 +0000 (06:44 +0000)
committerBen Batt <benbatt@gmail.com>
Thu, 7 Sep 2006 06:44:25 +0000 (06:44 +0000)
My commit to fix weightpaint display (revision 1.125 of DerivedMesh.c) broke
normal recalculation for meshes which have only deform modifiers applied.
This commit fixes that by adding calls to CDDM_calc_normals in the appropriate
places.

The DM_from_template and DM_init functions checked for numVerts > 0 before
initialising the DerivedMesh's custom data layers. This was something of a
hack intended to allow DerivedMesh creation functions to initialise default
function pointers without initialising custom data layers (by passing a 0 for
the numVerts parameter). It is unneeded now that DM_init_funcs is present, and
causes memory deallocation warnings later on when the number of vertices
really is 0, so it has been removed.

source/blender/blenkernel/intern/DerivedMesh.c

index 622a7511b5f9b5a351dc5c63aca6e84f1f4e7372..79cac1b4657a5811913797f8355c327debc60c37 100644 (file)
@@ -135,18 +135,16 @@ void DM_init_funcs(DerivedMesh *dm)
 void DM_init(DerivedMesh *dm,
              int numVerts, int numEdges, int numFaces)
 {
-       if(numVerts > 0) {
-               CustomData_init(&dm->vertData, DERIVEDMESH_INITIAL_LAYERS, numVerts,
-                               SUB_ELEMS_VERT);
-               CustomData_init(&dm->edgeData, DERIVEDMESH_INITIAL_LAYERS, numEdges,
-                               SUB_ELEMS_EDGE);
-               CustomData_init(&dm->faceData, DERIVEDMESH_INITIAL_LAYERS, numFaces,
-                               SUB_ELEMS_FACE);
+       CustomData_init(&dm->vertData, DERIVEDMESH_INITIAL_LAYERS, numVerts,
+                       SUB_ELEMS_VERT);
+       CustomData_init(&dm->edgeData, DERIVEDMESH_INITIAL_LAYERS, numEdges,
+                       SUB_ELEMS_EDGE);
+       CustomData_init(&dm->faceData, DERIVEDMESH_INITIAL_LAYERS, numFaces,
+                       SUB_ELEMS_FACE);
 
-               CustomData_add_layer(&dm->vertData, LAYERTYPE_ORIGINDEX, 0, NULL);
-               CustomData_add_layer(&dm->edgeData, LAYERTYPE_ORIGINDEX, 0, NULL);
-               CustomData_add_layer(&dm->faceData, LAYERTYPE_ORIGINDEX, 0, NULL);
-       }
+       CustomData_add_layer(&dm->vertData, LAYERTYPE_ORIGINDEX, 0, NULL);
+       CustomData_add_layer(&dm->edgeData, LAYERTYPE_ORIGINDEX, 0, NULL);
+       CustomData_add_layer(&dm->faceData, LAYERTYPE_ORIGINDEX, 0, NULL);
 
        DM_init_funcs(dm);
 }
@@ -154,11 +152,9 @@ void DM_init(DerivedMesh *dm,
 void DM_from_template(DerivedMesh *dm, DerivedMesh *source,
                       int numVerts, int numEdges, int numFaces)
 {
-       if(numVerts > 0) {
-               CustomData_from_template(&source->vertData, &dm->vertData, numVerts);
-               CustomData_from_template(&source->edgeData, &dm->edgeData, numEdges);
-               CustomData_from_template(&source->faceData, &dm->faceData, numFaces);
-       }
+       CustomData_from_template(&source->vertData, &dm->vertData, numVerts);
+       CustomData_from_template(&source->edgeData, &dm->edgeData, numEdges);
+       CustomData_from_template(&source->faceData, &dm->faceData, numFaces);
 
        DM_init_funcs(dm);
 }
@@ -2834,13 +2830,17 @@ static void mesh_calc_modifiers(Object *ob, float (*inputVertexCos)[3],
                        if(me->vnode) *deform_r = derivedmesh_from_versemesh(me->vnode, deformedVerts);
                        else {
                                *deform_r = CDDM_from_mesh(me);
-                               if(deformedVerts)
+                               if(deformedVerts) {
                                        CDDM_apply_vert_coords(*deform_r, deformedVerts);
+                                       CDDM_calc_normals(*deform_r);
+                               }
                        }
 #else
                        *deform_r = CDDM_from_mesh(me);
-                       if(deformedVerts)
+                       if(deformedVerts) {
                                CDDM_apply_vert_coords(*deform_r, deformedVerts);
+                               CDDM_calc_normals(*deform_r);
+                       }
 #endif
                }
        } else {
@@ -2960,16 +2960,21 @@ static void mesh_calc_modifiers(Object *ob, float (*inputVertexCos)[3],
                *final_r = dm;
        } else {
 #ifdef WITH_VERSE
-               if(me->vnode) *final_r = derivedmesh_from_versemesh(me->vnode, deformedVerts);
+               if(me->vnode)
+                       *final_r = derivedmesh_from_versemesh(me->vnode, deformedVerts);
                else {
                        *final_r = CDDM_from_mesh(me);
-                       if(deformedVerts)
+                       if(deformedVerts) {
                                CDDM_apply_vert_coords(*final_r, deformedVerts);
+                               CDDM_calc_normals(*final_r);
+                       }
                }
 #else
                *final_r = CDDM_from_mesh(me);
-               if(deformedVerts)
+               if(deformedVerts) {
                        CDDM_apply_vert_coords(*final_r, deformedVerts);
+                       CDDM_calc_normals(*final_r);
+               }
 #endif
        }