=bmesh= merge from trunk at r36529
[blender.git] / source / blender / editors / mesh / mesh_data.c
index 96512600dda5a45f3065b3372cf9cb2e94fcadb1..b6c6570e27d9b4e0d6425c8dfc41f038407dbfe9 100644 (file)
@@ -176,6 +176,17 @@ static void delete_customdata_layer(bContext *C, Object *ob, CustomDataLayer *la
        }
 }
 
+static void copy_editface_active_customdata(EditMesh *em, int type, int index)
+{
+       EditFace *efa;
+       int n= CustomData_get_active_layer(&em->fdata, type);
+
+       for(efa= em->faces.first; efa; efa= efa->next) {
+               void *data= CustomData_em_get_n(&em->fdata, efa->data, type, n);
+               CustomData_em_set_n(&em->fdata, efa->data, type, index, data);
+       }
+}
+
 int ED_mesh_uv_texture_add(bContext *C, Mesh *me, const char *name, int active_set)
 {
        BMEditMesh *em;
@@ -190,6 +201,10 @@ int ED_mesh_uv_texture_add(bContext *C, Mesh *me, const char *name, int active_s
 
                BM_add_data_layer(em->bm, &em->bm->pdata, CD_MTEXPOLY);
                CustomData_set_layer_active(&em->bm->pdata, CD_MTEXPOLY, layernum);
+
+               if(layernum) /* copy data from active UV */
+                       copy_editface_active_customdata(em, CD_MTFACE, layernum);
+
                if(active_set || layernum==0)
                        CustomData_set_layer_active(&em->bm->pdata, CD_MTEXPOLY, layernum);
 
@@ -265,6 +280,10 @@ int ED_mesh_color_add(bContext *C, Scene *UNUSED(scene), Object *UNUSED(ob), Mes
                BM_add_data_layer(em->bm, &em->bm->pdata, CD_MLOOPCOL);
                CustomData_set_layer_active(&em->bm->ldata, CD_MLOOPCOL, layernum);
 
+
+               if(layernum) /* copy data from active vertex color layer */
+                       copy_editface_active_customdata(em, CD_MCOL, layernum);
+
                if(active_set || layernum==0)
                        CustomData_set_layer_active(&em->bm->ldata, CD_MLOOPCOL, layernum);