svn merge ^/trunk/blender -r42722:42742
authorCampbell Barton <ideasman42@gmail.com>
Tue, 20 Dec 2011 01:33:14 +0000 (01:33 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Tue, 20 Dec 2011 01:33:14 +0000 (01:33 +0000)
1  2 
CMakeLists.txt
source/blender/blenkernel/intern/DerivedMesh.c
source/blender/blenloader/intern/readfile.c
source/blender/modifiers/intern/MOD_weightvgedit.c
source/blender/modifiers/intern/MOD_weightvgmix.c
source/blender/modifiers/intern/MOD_weightvgproximity.c
source/blender/render/intern/source/render_texture.c
source/creator/CMakeLists.txt

diff --cc CMakeLists.txt
Simple merge
index 98465dafecbc01e18acc29e159eaa658a0a80727,c078de87d0026f7739b4fd3edd034d1dd4df5b41..e47c197cfa0d9d452c63c2fd35b2a080dfd3f311
@@@ -958,156 -717,63 +958,167 @@@ void vDM_ColorBand_store(ColorBand *cob
        stored_cb= coba;
  }
  
- static void add_weight_mcol_dm(Object *ob, DerivedMesh *dm, int const draw_flag)
+ /* return an array of vertex weight colors */
+ static unsigned char *calc_weightpaint_vert_array(Object *ob, int const draw_flag, ColorBand *coba)
  {
        Mesh *me = ob->data;
-       MFace *mf = dm->getTessFaceArray(dm);
-       MLoop *mloop = dm->getLoopArray(dm), *ml;
-       MPoly *mp = dm->getPolyArray(dm);
-       ColorBand *coba= stored_cb;     /* warning, not a local var */
-       unsigned char *wtcol;
-       unsigned char(*wlcol)[4] = NULL;
-       BLI_array_declare(wlcol);
-       int i, j, totface=dm->getNumTessFaces(dm), totloop;
-       int *origIndex = dm->getVertDataArray(dm, CD_ORIGINDEX);
-       int defbase_tot = BLI_countlist(&ob->defbase);
-       const int defbase_act = ob->actdef-1;
-       char *dg_flags = MEM_mallocN(defbase_tot * sizeof(char), __func__);
-       int selected = get_selected_defgroups(ob, dg_flags, defbase_tot);
-       wtcol = MEM_callocN (sizeof (unsigned char) * totface*4*4, "weightmap");
+       unsigned char *wtcol_v = MEM_callocN (sizeof(unsigned char) * me->totvert * 4, "weightmap_v");
  
        if (me->dvert) {
-               MDeformVert *dvert= me->dvert;
-               /*first add colors to the tesselation faces*/
-               memset(wtcol, 0x55, sizeof (unsigned char) * totface*4*4);
-               for (i=0; i<totface; i++, mf++) {
-                       /*origindex being NULL means we're operating on original mesh data*/
-                       unsigned int fidx= mf->v4 ? 3:2;
-                       do {
-                               calc_weightpaint_vert_color(&wtcol[(i*4 + fidx)*4],
-                                                           &dvert[*(&mf->v1 + fidx)], coba,
-                                                           defbase_tot, defbase_act,
-                                                           dg_flags, selected, draw_flag);
-                       } while (fidx--);
+               unsigned char *wc = wtcol_v;
+               MDeformVert *dv= me->dvert;
+               unsigned int i;
+               /* varisbles for multipaint */
+               const int defbase_tot = BLI_countlist(&ob->defbase);
+               const int defbase_act = ob->actdef-1;
+               char *dg_flags = MEM_mallocN(defbase_tot * sizeof(char), __func__);
+               const int selected = get_selected_defgroups(ob, dg_flags, defbase_tot);
+               /* const int unselected = defbase_tot - selected; */ /* UNUSED */
+               for (i = me->totvert; i != 0; i--, wc += 4, dv++) {
+                       calc_weightpaint_vert_color(wc, dv, coba, defbase_tot, defbase_act, dg_flags, selected, draw_flag);
                }
+               MEM_freeN(dg_flags);
        }
        else {
-               /* no weights, fill in zero */
                int col_i;
                weightpaint_color((unsigned char *)&col_i, coba, 0.0f);
-               fill_vn_i((int *)wtcol, totface*4, col_i);
+               fill_vn_i((int *)wtcol_v, me->totvert, col_i);
+       }
+       return wtcol_v;
+ }
 -#include "PIL_time.h"
 -
+ static void add_weight_mcol_dm(Object *ob, DerivedMesh *dm, int const draw_flag)
+ {
+       ColorBand *coba= stored_cb;     /* warning, not a local var */
 -
 -      Mesh *me = ob->data;
+       unsigned char *wtcol_v = calc_weightpaint_vert_array(ob, draw_flag, coba);
 -      unsigned char *wtcol_f = MEM_mallocN (sizeof(unsigned char) * me->totface*4*4, "weightmap_f");
 -
 -      MFace *mf = me->mface;
 -      int i;
 -
 -      for (i=0; i<me->totface; i++, mf++) {
++      unsigned char *wtcol_f;
++      unsigned char(*wtcol_l)[4] = NULL;
++      BLI_array_declare(wtcol_l);
++      MFace *mf = dm->getTessFaceArray(dm);
++      MLoop *mloop = dm->getLoopArray(dm), *ml;
++      MPoly *mp = dm->getPolyArray(dm);
++      int i, j, totface=dm->getNumTessFaces(dm), totloop;
++      int *origIndex = dm->getVertDataArray(dm, CD_ORIGINDEX);
++
++      wtcol_f = MEM_mallocN(sizeof (unsigned char) * totface*4*4, "weightmap_f");
++
++      /*first add colors to the tesselation faces*/
++      for (i=0; i<totface; i++, mf++) {
++              /*origindex being NULL means we're operating on original mesh data*/
+               unsigned int fidx= mf->v4 ? 3:2;
+               do {
 -                      copy_v4_v4_char((char *)&wtcol_f[(4 * i + fidx) * 4],
 -                                      (char *)&wtcol_v[4 * (*(&mf->v1 + fidx))]);
++              copy_v4_v4_char((char *)&wtcol_f[(4 * i + fidx) * 4],
++                                              (char *)&wtcol_v[4 * (*(&mf->v1 + fidx))]);
+               } while (fidx--);
        }
-       
-       CustomData_add_layer(&dm->faceData, CD_WEIGHT_MCOL, CD_ASSIGN, wtcol, totface);
++      CustomData_add_layer(&dm->faceData, CD_WEIGHT_MCOL, CD_ASSIGN, wtcol_f, totface);
 +
 +      /*now add to loops, so the data can be passed through the modifier stack*/
 +      totloop = 0;
 +      for (i=0; i<dm->numPolyData; i++, mp++) {
-               MDeformVert *dvert= me->dvert;
 +              ml = mloop + mp->loopstart;
 +
 +              for (j=0; j<mp->totloop; j++, ml++, totloop++) {
-                       BLI_array_growone(wlcol);
-                       calc_weightpaint_vert_color((unsigned char *)&wlcol[totloop],
-                                                   &dvert[origIndex ? origIndex[ml->v] : ml->v], coba,
-                                                   defbase_tot, defbase_act,
-                                                                               dg_flags, selected, draw_flag);
++                      BLI_array_growone(wtcol_l);
++                      copy_v4_v4_char((char *)&wtcol_l[totloop],
++                                      (char *)&wtcol_v[4 * (origIndex ? origIndex[ml->v] : ml->v)]);
 +              }
 +      }
 +
-       MEM_freeN(dg_flags);
+       MEM_freeN(wtcol_v);
  
-       CustomData_add_layer(&dm->loopData, CD_WEIGHT_MLOOPCOL, CD_ASSIGN, wlcol, totloop);
 -      CustomData_add_layer(&dm->faceData, CD_WEIGHT_MCOL, CD_ASSIGN, wtcol_f, dm->numFaceData);
++      CustomData_add_layer(&dm->loopData, CD_WEIGHT_MLOOPCOL, CD_ASSIGN, wtcol_l, totloop);
 +}
 +
 +
 +static void shapekey_layers_to_keyblocks(DerivedMesh *dm, Mesh *me, int actshape_uid)
 +{
 +      KeyBlock *kb;
 +      int i, j, tot;
 +      
 +      if (!me->key)
 +              return; 
 +      
 +      tot = CustomData_number_of_layers(&dm->vertData, CD_SHAPEKEY);
 +      for (i=0; i<tot; i++) {
 +              CustomDataLayer *layer = &dm->vertData.layers[CustomData_get_layer_index_n(&dm->vertData, CD_SHAPEKEY, i)];
 +              float (*cos)[3], (*kbcos)[3];
 +              
 +              for (kb=me->key->block.first; kb; kb=kb->next) {
 +                      if (kb->uid == layer->uid)
 +                              break;
 +              }
 +              
 +              if (!kb) {
 +                      kb = add_keyblock(me->key, layer->name);
 +                      kb->uid = layer->uid;
 +              }
 +              
 +              if (kb->data)
 +                      MEM_freeN(kb->data);
 +              
 +              cos = CustomData_get_layer_n(&dm->vertData, CD_SHAPEKEY, i);
 +              kb->totelem = dm->numVertData;
 +
 +              kb->data = kbcos = MEM_mallocN(sizeof(float)*3*kb->totelem, "kbcos DerivedMesh.c");
 +              if (kb->uid == actshape_uid) {
 +                      MVert *mvert = dm->getVertArray(dm);
 +                      
 +                      for (j=0; j<dm->numVertData; j++, kbcos++, mvert++) {
 +                              copy_v3_v3(*kbcos, mvert->co);
 +                      }
 +              } else {
 +                      for (j=0; j<kb->totelem; j++, cos++, kbcos++) {
 +                              copy_v3_v3(*kbcos, *cos);
 +                      }
 +              }
 +      }
 +      
 +      for (kb=me->key->block.first; kb; kb=kb->next) {
 +              if (kb->totelem != dm->numVertData) {
 +                      if (kb->data)
 +                              MEM_freeN(kb->data);
 +                      
 +                      kb->totelem = dm->numVertData;
 +                      kb->data = MEM_callocN(sizeof(float)*3*kb->totelem, "kb->data derivedmesh.c");
 +                      fprintf(stderr, "%s: lost a shapekey layer! (bmesh internal error)\n", __func__);
 +              }
 +      }
 +}
 +
 +static void add_shapekey_layers(DerivedMesh *dm, Mesh *me, Object *UNUSED(ob))
 +{
 +      KeyBlock *kb;
 +      Key *key = me->key;
 +      int a, b;
 +      
 +      if (!me->key)
 +              return;
 +      
 +      if (dm->numVertData != me->totvert) {
 +              printf("error in add_shapekey_layers: dm isn't the same size as me\n");
 +              return;
 +      }
 +              
 +      for (a=0, kb=key->block.first; kb; kb=kb->next, a++) {
 +              float (*cos)[3] = CustomData_add_layer_named(&dm->vertData, CD_SHAPEKEY, CD_CALLOC, NULL, dm->numVertData, kb->name);
 +              int ci = CustomData_get_layer_index_n(&dm->vertData, CD_SHAPEKEY, a);
 +              
 +              dm->vertData.layers[ci].uid = kb->uid;
 +              if (kb->totelem != dm->numVertData) {
 +                      printf("error in add_shapekey_layers: totelem and totvert don't match");
 +                      continue;
 +              }
 +              
 +              for (b=0; b<kb->totelem; b++, cos++) {
 +                      copy_v3_v3((float *)cos, ((float*)kb->data)+b*3);
 +              }
 +      }
  }
  
  /* new value for useDeform -1  (hack for the gameengine):
Simple merge