Fix for customdata layer copying. Issue was caused by mixing up of destination and...
authorAndrew Hale <TrumanBlending@gmail.com>
Tue, 22 May 2012 12:03:56 +0000 (12:03 +0000)
committerAndrew Hale <TrumanBlending@gmail.com>
Tue, 22 May 2012 12:03:56 +0000 (12:03 +0000)
source/blender/bmesh/intern/bmesh_interp.c
source/blender/editors/mesh/mesh_data.c
source/blender/python/bmesh/bmesh_py_types_customdata.c

index f64b55193c57e2274b9be8232b8a067030bd3d91..c39096d08003b14391f821993908bd08880b088d 100644 (file)
@@ -852,24 +852,24 @@ void BM_data_layer_copy(BMesh *bm, CustomData *data, int type, int src_n, int ds
                BMVert *eve;
 
                BM_ITER_MESH (eve, &iter, bm, BM_VERTS_OF_MESH) {
-                       void *ptr = CustomData_bmesh_get_n(data, eve->head.data, type, dst_n);
-                       CustomData_bmesh_set_n(data, eve->head.data, type, src_n, ptr);
+                       void *ptr = CustomData_bmesh_get_n(data, eve->head.data, type, src_n);
+                       CustomData_bmesh_set_n(data, eve->head.data, type, dst_n, ptr);
                }
        }
        else if (&bm->edata == data) {
                BMEdge *eed;
 
                BM_ITER_MESH (eed, &iter, bm, BM_EDGES_OF_MESH) {
-                       void *ptr = CustomData_bmesh_get_n(data, eed->head.data, type, dst_n);
-                       CustomData_bmesh_set_n(data, eed->head.data, type, src_n, ptr);
+                       void *ptr = CustomData_bmesh_get_n(data, eed->head.data, type, src_n);
+                       CustomData_bmesh_set_n(data, eed->head.data, type, dst_n, ptr);
                }
        }
        else if (&bm->pdata == data) {
                BMFace *efa;
 
                BM_ITER_MESH (efa, &iter, bm, BM_FACES_OF_MESH) {
-                       void *ptr = CustomData_bmesh_get_n(data, efa->head.data, type, dst_n);
-                       CustomData_bmesh_set_n(data, efa->head.data, type, src_n, ptr);
+                       void *ptr = CustomData_bmesh_get_n(data, efa->head.data, type, src_n);
+                       CustomData_bmesh_set_n(data, efa->head.data, type, dst_n, ptr);
                }
        }
        else if (&bm->ldata == data) {
@@ -879,8 +879,8 @@ void BM_data_layer_copy(BMesh *bm, CustomData *data, int type, int src_n, int ds
 
                BM_ITER_MESH (efa, &iter, bm, BM_FACES_OF_MESH) {
                        BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
-                               void *ptr = CustomData_bmesh_get_n(data, l->head.data, type, dst_n);
-                               CustomData_bmesh_set_n(data, l->head.data, type, src_n, ptr);
+                               void *ptr = CustomData_bmesh_get_n(data, l->head.data, type, src_n);
+                               CustomData_bmesh_set_n(data, l->head.data, type, dst_n, ptr);
                        }
                }
        }
index bc11a627be69cbecf22d6579417fd684c2311171..19ca30b9c45e1883f5782bef5293c54fa5d28778 100644 (file)
@@ -309,44 +309,44 @@ int ED_mesh_uv_loop_reset(struct bContext *C, struct Mesh *me)
 int ED_mesh_uv_texture_add(bContext *C, Mesh *me, const char *name, int active_set)
 {
        BMEditMesh *em;
-       int layernum;
+       int layernum_dst;
 
        short is_init = FALSE;
 
        if (me->edit_btmesh) {
                em = me->edit_btmesh;
 
-               layernum = CustomData_number_of_layers(&em->bm->pdata, CD_MTEXPOLY);
-               if (layernum >= MAX_MTFACE)
+               layernum_dst = CustomData_number_of_layers(&em->bm->pdata, CD_MTEXPOLY);
+               if (layernum_dst >= MAX_MTFACE)
                        return -1;
 
                /* CD_MTEXPOLY */
                BM_data_layer_add_named(em->bm, &em->bm->pdata, CD_MTEXPOLY, name);
                /* copy data from active UV */
-               if (layernum) {
-                       const int layernum_dst = CustomData_get_active_layer(&em->bm->pdata, CD_MTEXPOLY);
-                       BM_data_layer_copy(em->bm, &em->bm->pdata, CD_MTEXPOLY, layernum, layernum_dst);
+               if (layernum_dst) {
+                       const int layernum_src = CustomData_get_active_layer(&em->bm->pdata, CD_MTEXPOLY);
+                       BM_data_layer_copy(em->bm, &em->bm->pdata, CD_MTEXPOLY, layernum_src, layernum_dst);
                }
-               if (active_set || layernum == 0) {
-                       CustomData_set_layer_active(&em->bm->pdata, CD_MTEXPOLY, layernum);
+               if (active_set || layernum_dst == 0) {
+                       CustomData_set_layer_active(&em->bm->pdata, CD_MTEXPOLY, layernum_dst);
                }
 
                /* CD_MLOOPUV */
                BM_data_layer_add_named(em->bm, &em->bm->ldata, CD_MLOOPUV, name);
                /* copy data from active UV */
-               if (layernum) {
-                       const int layernum_dst = CustomData_get_active_layer(&em->bm->ldata, CD_MLOOPUV);
-                       BM_data_layer_copy(em->bm, &em->bm->ldata, CD_MLOOPUV, layernum, layernum_dst);
+               if (layernum_dst) {
+                       const int layernum_src = CustomData_get_active_layer(&em->bm->ldata, CD_MLOOPUV);
+                       BM_data_layer_copy(em->bm, &em->bm->ldata, CD_MLOOPUV, layernum_src, layernum_dst);
 
                        is_init = TRUE;
                }
-               if (active_set || layernum == 0) {
-                       CustomData_set_layer_active(&em->bm->ldata, CD_MLOOPUV, layernum);
+               if (active_set || layernum_dst == 0) {
+                       CustomData_set_layer_active(&em->bm->ldata, CD_MLOOPUV, layernum_dst);
                }
        }
        else {
-               layernum = CustomData_number_of_layers(&me->pdata, CD_MTEXPOLY);
-               if (layernum >= MAX_MTFACE)
+               layernum_dst = CustomData_number_of_layers(&me->pdata, CD_MTEXPOLY);
+               if (layernum_dst >= MAX_MTFACE)
                        return -1;
 
                if (me->mtpoly) {
@@ -361,11 +361,11 @@ int ED_mesh_uv_texture_add(bContext *C, Mesh *me, const char *name, int active_s
                        CustomData_add_layer_named(&me->fdata, CD_MTFACE, CD_DEFAULT, NULL, me->totface, name);
                }
                
-               if (active_set || layernum == 0) {
-                       CustomData_set_layer_active(&me->pdata, CD_MTEXPOLY, layernum);
-                       CustomData_set_layer_active(&me->ldata, CD_MLOOPUV, layernum);
+               if (active_set || layernum_dst == 0) {
+                       CustomData_set_layer_active(&me->pdata, CD_MTEXPOLY, layernum_dst);
+                       CustomData_set_layer_active(&me->ldata, CD_MLOOPUV, layernum_dst);
 
-                       CustomData_set_layer_active(&me->fdata, CD_MTFACE, layernum);
+                       CustomData_set_layer_active(&me->fdata, CD_MTFACE, layernum_dst);
                }
 
                mesh_update_customdata_pointers(me, TRUE);
@@ -373,13 +373,13 @@ int ED_mesh_uv_texture_add(bContext *C, Mesh *me, const char *name, int active_s
 
        /* don't overwrite our copied coords */
        if (is_init == FALSE) {
-               ED_mesh_uv_loop_reset_ex(C, me, layernum);
+               ED_mesh_uv_loop_reset_ex(C, me, layernum_dst);
        }
 
        DAG_id_tag_update(&me->id, 0);
        WM_event_add_notifier(C, NC_GEOM | ND_DATA, me);
 
-       return layernum;
+       return layernum_dst;
 }
 
 int ED_mesh_uv_texture_remove(bContext *C, Object *ob, Mesh *me)
index f25222c89dae19fc146b706cc605b4da04794cf8..d484ad5c87e930223bc1daf88a568de8a713c8fe 100644 (file)
@@ -271,13 +271,16 @@ static PyObject *bpy_bmlayeritem_copy_from(BPy_BMLayerItem *self, BPy_BMLayerIte
        }
 
        else if ((self->htype != value->htype) ||
-                (self->type  != value->type) ||
-                (self->index != value->index))
+                (self->type  != value->type))
        {
                PyErr_SetString(PyExc_ValueError,
                                "layer.copy_from(other): layer type mismatch");
        }
 
+       else if (self->index == value->index) {
+               Py_RETURN_NONE;
+       }
+
        data = bpy_bm_customdata_get(self->bm, self->htype);
 
        if ((bpy_bmlayeritem_get(self) == NULL) ||