fix [#30657] New UV layers created with Mesh.uv_textures.new reset previous ones.

adding UV's from python was resetting the active UV layer but not setting the new layer to active, resetting existing UV's.
This commit is contained in:
Campbell Barton 2012-03-26 02:39:05 +00:00
parent 94b8b8913e
commit 44010fb659
3 changed files with 16 additions and 7 deletions

@ -346,7 +346,7 @@ def xml_file_run(context, filepath, rna_map):
value = _get_context_val(context, rna_path) value = _get_context_val(context, rna_path)
if value is not Ellipsis and value is not None: if value is not Ellipsis and value is not None:
print(" loading XML: %r" % rna_path) print(" loading XML: %r -> %r" % (filepath, rna_path))
xml2rna(xml_node, root_rna=value) xml2rna(xml_node, root_rna=value)

@ -287,6 +287,7 @@ void ED_mesh_update(struct Mesh *mesh, struct bContext *C, int calc_edges, int c
int ED_mesh_uv_texture_add(struct bContext *C, struct Mesh *me, const char *name, int active_set); int ED_mesh_uv_texture_add(struct bContext *C, struct Mesh *me, const char *name, int active_set);
int ED_mesh_uv_texture_remove(struct bContext *C, struct Object *ob, struct Mesh *me); int ED_mesh_uv_texture_remove(struct bContext *C, struct Object *ob, struct Mesh *me);
int ED_mesh_uv_loop_reset(struct bContext *C, struct Mesh *me); int ED_mesh_uv_loop_reset(struct bContext *C, struct Mesh *me);
int ED_mesh_uv_loop_reset_ex(struct bContext *C, struct Mesh *me, const int layernum);
int ED_mesh_color_add(struct bContext *C, struct Scene *scene, struct Object *ob, struct Mesh *me, const char *name, int active_set); int ED_mesh_color_add(struct bContext *C, struct Scene *scene, struct Object *ob, struct Mesh *me, const char *name, int active_set);
int ED_mesh_color_remove(struct bContext *C, struct Object *ob, struct Mesh *me); int ED_mesh_color_remove(struct bContext *C, struct Object *ob, struct Mesh *me);
int ED_mesh_color_remove_named(struct bContext *C, struct Object *ob, struct Mesh *me, const char *name); int ED_mesh_color_remove_named(struct bContext *C, struct Object *ob, struct Mesh *me, const char *name);

@ -206,7 +206,7 @@ static void copy_editface_active_customdata(BMEditMesh *em, int type, int index)
#endif #endif
} }
int ED_mesh_uv_loop_reset(struct bContext *C, struct Mesh *me) int ED_mesh_uv_loop_reset_ex(struct bContext *C, struct Mesh *me, const int layernum)
{ {
BMEditMesh *em= me->edit_btmesh; BMEditMesh *em= me->edit_btmesh;
MLoopUV *luv; MLoopUV *luv;
@ -232,7 +232,7 @@ int ED_mesh_uv_loop_reset(struct bContext *C, struct Mesh *me)
i = 0; i = 0;
BM_ITER(l, &liter, em->bm, BM_LOOPS_OF_FACE, efa) { BM_ITER(l, &liter, em->bm, BM_LOOPS_OF_FACE, efa) {
luv = CustomData_bmesh_get(&em->bm->ldata, l->head.data, CD_MLOOPUV); luv = CustomData_bmesh_get_n(&em->bm->ldata, l->head.data, CD_MLOOPUV, layernum);
BLI_array_append(uvs, luv->uv); BLI_array_append(uvs, luv->uv);
i++; i++;
} }
@ -244,14 +244,16 @@ int ED_mesh_uv_loop_reset(struct bContext *C, struct Mesh *me)
/* Collect Mesh UVs */ /* Collect Mesh UVs */
MPoly *mp; MPoly *mp;
MLoopUV *mloouv;
BLI_assert(CustomData_has_layer(&me->ldata, CD_MLOOPUV)); BLI_assert(CustomData_has_layer(&me->ldata, CD_MLOOPUV));
mloouv = CustomData_get_layer_n(&me->ldata, CD_MLOOPUV, layernum);
for (j = 0; j < me->totpoly; j++) { for (j = 0; j < me->totpoly; j++) {
mp = &me->mpoly[j]; mp = &me->mpoly[j];
for (i = 0; i < mp->totloop; i++) { for (i = 0; i < mp->totloop; i++) {
luv = &me->mloopuv[mp->loopstart + i]; luv = &mloouv[mp->loopstart + i];
BLI_array_append(uvs, luv->uv); BLI_array_append(uvs, luv->uv);
} }
@ -303,8 +305,6 @@ int ED_mesh_uv_loop_reset(struct bContext *C, struct Mesh *me)
fuvs += len; fuvs += len;
} }
/* BMESH_TODO: Copy poly UVs onto CD_MTFACE layer for tessellated faces */
BLI_array_free(uvs); BLI_array_free(uvs);
BLI_array_free(polylengths); BLI_array_free(polylengths);
@ -314,6 +314,14 @@ int ED_mesh_uv_loop_reset(struct bContext *C, struct Mesh *me)
return 1; return 1;
} }
int ED_mesh_uv_loop_reset(struct bContext *C, struct Mesh *me)
{
/* could be ldata or pdata */
CustomData *pdata = GET_CD_DATA(me, pdata);
const int layernum = CustomData_get_active_layer_index(pdata, CD_MTEXPOLY);
return ED_mesh_uv_loop_reset_ex(C, me, layernum);
}
int ED_mesh_uv_texture_add(bContext *C, Mesh *me, const char *name, int active_set) int ED_mesh_uv_texture_add(bContext *C, Mesh *me, const char *name, int active_set)
{ {
BMEditMesh *em; BMEditMesh *em;
@ -372,7 +380,7 @@ int ED_mesh_uv_texture_add(bContext *C, Mesh *me, const char *name, int active_s
mesh_update_customdata_pointers(me, TRUE); mesh_update_customdata_pointers(me, TRUE);
} }
ED_mesh_uv_loop_reset(C, me); ED_mesh_uv_loop_reset_ex(C, me, layernum);
DAG_id_tag_update(&me->id, 0); DAG_id_tag_update(&me->id, 0);
WM_event_add_notifier(C, NC_GEOM|ND_DATA, me); WM_event_add_notifier(C, NC_GEOM|ND_DATA, me);