diff options
author | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2012-02-01 22:25:13 +0400 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2012-02-01 22:25:13 +0400 |
commit | 5adcf774ba50c3561728e3e9b24448aed798c248 (patch) | |
tree | 2390f1a7f9c81f2663248acad032e86c40b62c80 | |
parent | d7ce201e6a78658c04ebcc29bad710863f587d52 (diff) |
Fix #30045: mesh.uv_textures.new() not returning correct layer when a layer with
the requested name already exists.
-rw-r--r-- | source/blender/editors/mesh/mesh_data.c | 16 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_mesh.c | 52 |
2 files changed, 42 insertions, 26 deletions
diff --git a/source/blender/editors/mesh/mesh_data.c b/source/blender/editors/mesh/mesh_data.c index d752d90ffdd..b10fbaf69b7 100644 --- a/source/blender/editors/mesh/mesh_data.c +++ b/source/blender/editors/mesh/mesh_data.c @@ -183,7 +183,7 @@ int ED_mesh_uv_texture_add(bContext *C, Mesh *me, const char *name, int active_s layernum= CustomData_number_of_layers(&em->fdata, CD_MTFACE); if(layernum >= MAX_MTFACE) - return 0; + return -1; EM_add_data_layer(em, &em->fdata, CD_MTFACE, name); @@ -196,7 +196,7 @@ int ED_mesh_uv_texture_add(bContext *C, Mesh *me, const char *name, int active_s else { layernum= CustomData_number_of_layers(&me->fdata, CD_MTFACE); if(layernum >= MAX_MTFACE) - return 0; + return -1; if(me->mtface) CustomData_add_layer_named(&me->fdata, CD_MTFACE, CD_DUPLICATE, me->mtface, me->totface, name); @@ -212,7 +212,7 @@ int ED_mesh_uv_texture_add(bContext *C, Mesh *me, const char *name, int active_s DAG_id_tag_update(&me->id, 0); WM_event_add_notifier(C, NC_GEOM|ND_DATA, me); - return 1; + return layernum; } int ED_mesh_uv_texture_remove(bContext *C, Object *ob, Mesh *me) @@ -244,7 +244,7 @@ int ED_mesh_color_add(bContext *C, Scene *UNUSED(scene), Object *UNUSED(ob), Mes layernum= CustomData_number_of_layers(&em->fdata, CD_MCOL); if(layernum >= MAX_MCOL) - return 0; + return -1; EM_add_data_layer(em, &em->fdata, CD_MCOL, name); @@ -257,7 +257,7 @@ int ED_mesh_color_add(bContext *C, Scene *UNUSED(scene), Object *UNUSED(ob), Mes else { layernum= CustomData_number_of_layers(&me->fdata, CD_MCOL); if(layernum >= MAX_MCOL) - return 0; + return -1; if(me->mcol) CustomData_add_layer_named(&me->fdata, CD_MCOL, CD_DUPLICATE, me->mcol, me->totface, name); @@ -273,7 +273,7 @@ int ED_mesh_color_add(bContext *C, Scene *UNUSED(scene), Object *UNUSED(ob), Mes DAG_id_tag_update(&me->id, 0); WM_event_add_notifier(C, NC_GEOM|ND_DATA, me); - return 1; + return layernum; } int ED_mesh_color_remove(bContext *C, Object *ob, Mesh *me) @@ -328,7 +328,7 @@ static int uv_texture_add_exec(bContext *C, wmOperator *UNUSED(op)) Object *ob= ED_object_context(C); Mesh *me= ob->data; - if(!ED_mesh_uv_texture_add(C, me, NULL, TRUE)) + if(ED_mesh_uv_texture_add(C, me, NULL, TRUE) == -1) return OPERATOR_CANCELLED; return OPERATOR_FINISHED; @@ -467,7 +467,7 @@ static int vertex_color_add_exec(bContext *C, wmOperator *UNUSED(op)) Object *ob= ED_object_context(C); Mesh *me= ob->data; - if(!ED_mesh_color_add(C, scene, ob, me, NULL, TRUE)) + if(ED_mesh_color_add(C, scene, ob, me, NULL, TRUE) == -1) return OPERATOR_CANCELLED; return OPERATOR_FINISHED; diff --git a/source/blender/makesrna/intern/rna_mesh.c b/source/blender/makesrna/intern/rna_mesh.c index 2ada09f2df1..c2faf20749d 100644 --- a/source/blender/makesrna/intern/rna_mesh.c +++ b/source/blender/makesrna/intern/rna_mesh.c @@ -27,6 +27,7 @@ #include <stdlib.h> +#include "RNA_access.h" #include "RNA_define.h" #include "rna_internal.h" @@ -1132,22 +1133,25 @@ static int rna_Mesh_tot_face_get(PointerRNA *ptr) return me->edit_mesh ? me->edit_mesh->totfacesel : 0; } -static CustomDataLayer *rna_Mesh_vertex_color_new(struct Mesh *me, struct bContext *C, const char *name) +static PointerRNA rna_Mesh_vertex_color_new(struct Mesh *me, struct bContext *C, const char *name) { + PointerRNA ptr; CustomData *fdata; CustomDataLayer *cdl= NULL; - int index; + int index= ED_mesh_color_add(C, NULL, NULL, me, name, FALSE); - if(ED_mesh_color_add(C, NULL, NULL, me, name, FALSE)) { + if(index != -1) { fdata= rna_mesh_fdata(me); - index= CustomData_get_named_layer_index(fdata, CD_MCOL, name); - cdl= (index == -1)? NULL: &fdata->layers[index]; + cdl= &fdata->layers[CustomData_get_layer_index_n(fdata, CD_MCOL, index)]; } - return cdl; + + RNA_pointer_create(&me->id, &RNA_MeshColorLayer, cdl, &ptr); + return ptr; } -static CustomDataLayer *rna_Mesh_int_property_new(struct Mesh *me, struct bContext *C, const char *name) +static PointerRNA rna_Mesh_int_property_new(struct Mesh *me, struct bContext *C, const char *name) { + PointerRNA ptr; CustomDataLayer *cdl = NULL; int index; @@ -1156,11 +1160,13 @@ static CustomDataLayer *rna_Mesh_int_property_new(struct Mesh *me, struct bConte cdl = (index == -1) ? NULL : &(me->fdata.layers[index]); - return cdl; + RNA_pointer_create(&me->id, &RNA_MeshIntPropertyLayer, cdl, &ptr); + return ptr; } -static CustomDataLayer *rna_Mesh_float_property_new(struct Mesh *me, struct bContext *C, const char *name) +static PointerRNA rna_Mesh_float_property_new(struct Mesh *me, struct bContext *C, const char *name) { + PointerRNA ptr; CustomDataLayer *cdl = NULL; int index; @@ -1169,11 +1175,13 @@ static CustomDataLayer *rna_Mesh_float_property_new(struct Mesh *me, struct bCon cdl = (index == -1) ? NULL : &(me->fdata.layers[index]); - return cdl; + RNA_pointer_create(&me->id, &RNA_MeshFloatPropertyLayer, cdl, &ptr); + return ptr; } -static CustomDataLayer *rna_Mesh_string_property_new(struct Mesh *me, struct bContext *C, const char *name) +static PointerRNA rna_Mesh_string_property_new(struct Mesh *me, struct bContext *C, const char *name) { + PointerRNA ptr; CustomDataLayer *cdl = NULL; int index; @@ -1182,21 +1190,24 @@ static CustomDataLayer *rna_Mesh_string_property_new(struct Mesh *me, struct bCo cdl = (index == -1) ? NULL : &(me->fdata.layers[index]); - return cdl; + RNA_pointer_create(&me->id, &RNA_MeshStringPropertyLayer, cdl, &ptr); + return ptr; } -static CustomDataLayer *rna_Mesh_uv_texture_new(struct Mesh *me, struct bContext *C, const char *name) +static PointerRNA rna_Mesh_uv_texture_new(struct Mesh *me, struct bContext *C, const char *name) { + PointerRNA ptr; CustomData *fdata; CustomDataLayer *cdl= NULL; - int index; + int index= ED_mesh_uv_texture_add(C, me, name, FALSE); - if(ED_mesh_uv_texture_add(C, me, name, FALSE)) { + if(index != -1) { fdata= rna_mesh_fdata(me); - index= CustomData_get_named_layer_index(fdata, CD_MTFACE, name); - cdl= (index == -1)? NULL: &fdata->layers[index]; + cdl= &fdata->layers[CustomData_get_layer_index_n(fdata, CD_MTFACE, index)]; } - return cdl; + + RNA_pointer_create(&me->id, &RNA_MeshTextureFaceLayer, cdl, &ptr); + return ptr; } #else @@ -1783,6 +1794,7 @@ static void rna_def_vertex_colors(BlenderRNA *brna, PropertyRNA *cprop) RNA_def_function_ui_description(func, "Add a vertex color layer to Mesh"); RNA_def_string(func, "name", "Col", 0, "", "Vertex color name"); parm= RNA_def_pointer(func, "layer", "MeshColorLayer", "", "The newly created layer"); + RNA_def_property_flag(parm, PROP_RNAPTR); RNA_def_function_return(func, parm); /* @@ -1823,6 +1835,7 @@ static void rna_def_int_layers(BlenderRNA *brna, PropertyRNA *cprop) RNA_def_function_ui_description(func, "Add a integer property layer to Mesh"); RNA_def_string(func, "name", "Int Prop", 0, "", "Int property name"); parm= RNA_def_pointer(func, "layer", "MeshIntPropertyLayer", "", "The newly created layer"); + RNA_def_property_flag(parm, PROP_RNAPTR); RNA_def_function_return(func, parm); } @@ -1844,6 +1857,7 @@ static void rna_def_float_layers(BlenderRNA *brna, PropertyRNA *cprop) RNA_def_function_ui_description(func, "Add a float property layer to Mesh"); RNA_def_string(func, "name", "Float Prop", 0, "", "Float property name"); parm= RNA_def_pointer(func, "layer", "MeshFloatPropertyLayer", "", "The newly created layer"); + RNA_def_property_flag(parm, PROP_RNAPTR); RNA_def_function_return(func, parm); } @@ -1865,6 +1879,7 @@ static void rna_def_string_layers(BlenderRNA *brna, PropertyRNA *cprop) RNA_def_function_ui_description(func, "Add a string property layer to Mesh"); RNA_def_string(func, "name", "String Prop", 0, "", "String property name"); parm= RNA_def_pointer(func, "layer", "MeshStringPropertyLayer", "", "The newly created layer"); + RNA_def_property_flag(parm, PROP_RNAPTR); RNA_def_function_return(func, parm); } @@ -1887,6 +1902,7 @@ static void rna_def_uv_textures(BlenderRNA *brna, PropertyRNA *cprop) RNA_def_function_ui_description(func, "Add a UV texture layer to Mesh"); RNA_def_string(func, "name", "UVMap", 0, "", "UV map name"); parm= RNA_def_pointer(func, "layer", "MeshTextureFaceLayer", "", "The newly created layer"); + RNA_def_property_flag(parm, PROP_RNAPTR); RNA_def_function_return(func, parm); /* |