Fix #27176: Creating a new UV layer in edit mode fails to copy previous one
authorSergey Sharybin <sergey.vfx@gmail.com>
Wed, 27 Apr 2011 08:35:03 +0000 (08:35 +0000)
committerSergey Sharybin <sergey.vfx@gmail.com>
Wed, 27 Apr 2011 08:35:03 +0000 (08:35 +0000)
Implemented copying data from active MTFACE layer to newly created.
Also, fixed the same bug with vertex colors layer.

source/blender/editors/mesh/mesh_data.c

index b6940e8f8f9218af81ce91037c779bca44884cb2..f3e26cfee364a01556c285657b4de91e99174c66 100644 (file)
@@ -163,6 +163,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)
 {
        EditMesh *em;
@@ -176,6 +187,10 @@ int ED_mesh_uv_texture_add(bContext *C, Mesh *me, const char *name, int active_s
                        return 0;
 
                EM_add_data_layer(em, &em->fdata, CD_MTFACE, name);
+
+               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->fdata, CD_MTFACE, layernum);
        }
@@ -234,6 +249,10 @@ int ED_mesh_color_add(bContext *C, Scene *scene, Object *ob, Mesh *me, const cha
                        return 0;
 
                EM_add_data_layer(em, &em->fdata, CD_MCOL, name);
+
+               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->fdata, CD_MCOL, layernum);
        }