Recommit fix that I seem to have uncommitted accidentally, had the fix
authorBrecht Van Lommel <brechtvanlommel@pandora.be>
Mon, 10 May 2010 15:02:37 +0000 (15:02 +0000)
committerBrecht Van Lommel <brechtvanlommel@pandora.be>
Mon, 10 May 2010 15:02:37 +0000 (15:02 +0000)
still in my source tree but svn wasn't showing any diffs.. weird.

source/blender/blenkernel/intern/multires.c

index 9e95581..52c6f93 100644 (file)
@@ -264,6 +264,38 @@ int multiresModifier_reshapeFromDeformMod(MultiresModifierData *mmd, Object *ob,
        return result;
 }
 
+static void multires_set_tot_mdisps(Mesh *me, int lvl)
+{
+       MDisps *mdisps= CustomData_get_layer(&me->fdata, CD_MDISPS);
+       int i;
+
+       if(mdisps) {
+               for(i = 0; i < me->totface; i++) {
+                       if(mdisps[i].totdisp == 0) {
+                               int nvert = (me->mface[i].v4)? 4: 3;
+                               mdisps[i].totdisp = multires_grid_tot[lvl]*nvert;
+                       }
+               }
+       }
+}
+
+static void multires_reallocate_mdisps(Mesh *me, MDisps *mdisps, int lvl)
+{
+       int i;
+
+       /* reallocate displacements to be filled in */
+       for(i = 0; i < me->totface; ++i) {
+               int nvert = (me->mface[i].v4)? 4: 3;
+               int totdisp = multires_grid_tot[lvl]*nvert;
+               float (*disps)[3] = MEM_callocN(sizeof(float) * 3 * totdisp, "multires disps");
+
+               if(mdisps[i].disps)
+                       MEM_freeN(mdisps[i].disps);
+
+               mdisps[i].disps = disps;
+               mdisps[i].totdisp = totdisp;
+       }
+}
 
 static void column_vectors_to_mat3(float mat[][3], float v1[3], float v2[3], float v3[3])
 {
@@ -320,6 +352,7 @@ void multiresModifier_del_levels(MultiresModifierData *mmd, Object *ob, int dire
        int levels = mmd->totlvl - lvl;
        MDisps *mdisps;
 
+       multires_set_tot_mdisps(me, mmd->totlvl);
        CustomData_external_read(&me->fdata, &me->id, CD_MASK_MDISPS, me->totface);
        mdisps= CustomData_get_layer(&me->fdata, CD_MDISPS);
 
@@ -393,24 +426,6 @@ static DerivedMesh *subsurf_dm_create_local(Object *ob, DerivedMesh *dm, int lvl
        return subsurf_make_derived_from_derived(dm, &smd, 0, NULL, 0, 0);
 }
 
-static void multires_reallocate_mdisps(Mesh *me, MDisps *mdisps, int lvl)
-{
-       int i;
-
-       /* reallocate displacements to be filled in */
-       for(i = 0; i < me->totface; ++i) {
-               int nvert = (me->mface[i].v4)? 4: 3;
-               int totdisp = multires_grid_tot[lvl]*nvert;
-               float (*disps)[3] = MEM_callocN(sizeof(float) * 3 * totdisp, "multires disps");
-
-               if(mdisps[i].disps)
-                       MEM_freeN(mdisps[i].disps);
-
-               mdisps[i].disps = disps;
-               mdisps[i].totdisp = totdisp;
-       }
-}
-
 void multiresModifier_subdivide(MultiresModifierData *mmd, Object *ob, int updateblock, int simple)
 {
        Mesh *me = ob->data;
@@ -615,6 +630,7 @@ static void multiresModifier_update(DerivedMesh *dm)
        ob = ccgdm->multires.ob;
        me = ccgdm->multires.ob->data;
        mmd = ccgdm->multires.mmd;
+       multires_set_tot_mdisps(me, mmd->totlvl);
        CustomData_external_read(&me->fdata, &me->id, CD_MASK_MDISPS, me->totface);
        mdisps = CustomData_get_layer(&me->fdata, CD_MDISPS);
 
@@ -750,6 +766,7 @@ DerivedMesh *multires_dm_create_from_derived(MultiresModifierData *mmd, int loca
                memcpy(subGridData[i], gridData[i], sizeof(DMGridData)*gridSize*gridSize);
        }
 
+       multires_set_tot_mdisps(me, mmd->totlvl);
        CustomData_external_read(&me->fdata, &me->id, CD_MASK_MDISPS, me->totface);
        multiresModifier_disp_run(result, ob->data, 0, 0, subGridData, mmd->totlvl);