Fix #27176: Creating a new UV layer in edit mode fails to copy previous one
Implemented copying data from active MTFACE layer to newly created. Also, fixed the same bug with vertex colors layer.
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
Reference in New Issue
Block a user