Merge from 2.5 r21160 through r21285
[blender.git] / source / blender / makesrna / intern / rna_mesh.c
index 4b4c9b97871c31e2629382c72777d2ed2a6d2823..2133ff2615773052e9df38f1c070e8c69a92e5ed 100644 (file)
@@ -259,19 +259,25 @@ static int rna_Mesh_uv_layers_length(PointerRNA *ptr)
 
 static PointerRNA rna_Mesh_active_uv_layer_get(PointerRNA *ptr)
 {
-       CustomDataLayer *active_layer;
-       Mesh *me;
-       int layer_index;
+       Mesh *me= (Mesh*)ptr->data;
+       int index= CustomData_get_active_layer_index(&me->fdata, CD_MTFACE);
+       CustomDataLayer *cdl= (index == -1)? NULL: &me->fdata.layers[index];
 
-       active_layer= NULL;
-       me= (Mesh*)ptr->data;
+       return rna_pointer_inherit_refine(ptr, &RNA_MeshTextureFaceLayer, cdl);
+}
 
-       if (CustomData_has_layer(&me->fdata, CD_MTFACE)) {
-               layer_index= CustomData_get_active_layer_index(&me->fdata, CD_MTFACE);
-               active_layer= &me->fdata.layers[layer_index];
-       }
+static void rna_Mesh_active_uv_layer_set(PointerRNA *ptr, PointerRNA value)
+{
+       Mesh *me= (Mesh*)ptr->data;
+       CustomDataLayer *cdl;
+       int a;
 
-       return rna_pointer_inherit_refine(ptr, &RNA_MeshTextureFaceLayer, active_layer);
+       for(cdl=me->fdata.layers, a=0; a<me->fdata.totlayer; cdl++, a++) {
+               if(value.data == cdl) {
+                       CustomData_set_layer_active_index(&me->fdata, CD_MTFACE, a);
+                       return;
+               }
+       }
 }
 
 static void rna_MeshTextureFace_uv1_get(PointerRNA *ptr, float *values)
@@ -388,6 +394,29 @@ static int rna_Mesh_vcol_layers_length(PointerRNA *ptr)
        return rna_CustomDataLayer_length(ptr, CD_MCOL);
 }
 
+static PointerRNA rna_Mesh_active_vcol_layer_get(PointerRNA *ptr)
+{
+       Mesh *me= (Mesh*)ptr->data;
+       int index= CustomData_get_active_layer_index(&me->fdata, CD_MCOL);
+       CustomDataLayer *cdl= (index == -1)? NULL: &me->fdata.layers[index];
+
+       return rna_pointer_inherit_refine(ptr, &RNA_MeshColorLayer, cdl);
+}
+
+static void rna_Mesh_active_vcol_layer_set(PointerRNA *ptr, PointerRNA value)
+{
+       Mesh *me= (Mesh*)ptr->data;
+       CustomDataLayer *cdl;
+       int a;
+
+       for(cdl=me->fdata.layers, a=0; a<me->fdata.totlayer; cdl++, a++) {
+               if(value.data == cdl) {
+                       CustomData_set_layer_active_index(&me->fdata, CD_MCOL, a);
+                       return;
+               }
+       }
+}
+
 static void rna_MeshColorLayer_data_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
 {
        Mesh *me= (Mesh*)ptr->id.data;
@@ -710,8 +739,8 @@ static void rna_def_medge(BlenderRNA *brna)
        prop= RNA_def_property(srna, "verts", PROP_INT, PROP_UNSIGNED);
        RNA_def_property_int_sdna(prop, NULL, "v1");
        RNA_def_property_array(prop, 2);
-       RNA_def_property_clear_flag(prop, PROP_EDITABLE);
        RNA_def_property_ui_text(prop, "Vertices", "Vertex indices");
+       // XXX allows creating invalid meshes
 
        prop= RNA_def_property(srna, "crease", PROP_FLOAT, PROP_NONE);
        RNA_def_property_float_funcs(prop, "rna_MEdge_crease_get", "rna_MEdge_crease_set", NULL);
@@ -757,8 +786,8 @@ static void rna_def_mface(BlenderRNA *brna)
        prop= RNA_def_property(srna, "verts", PROP_INT, PROP_UNSIGNED);
        RNA_def_property_int_sdna(prop, NULL, "v1");
        RNA_def_property_array(prop, 4);
-       RNA_def_property_clear_flag(prop, PROP_EDITABLE);
        RNA_def_property_ui_text(prop, "Vertices", "Vertex indices");
+       // XXX allows creating invalid meshes
 
        prop= RNA_def_property(srna, "material_index", PROP_INT, PROP_UNSIGNED);
        RNA_def_property_int_sdna(prop, NULL, "mat_nr");
@@ -1109,7 +1138,6 @@ static void rna_def_mesh(BlenderRNA *brna)
        RNA_def_property_collection_sdna(prop, NULL, "mvert", "totvert");
        RNA_def_property_struct_type(prop, "MeshVertex");
        RNA_def_property_ui_text(prop, "Vertices", "Vertices of the mesh.");
-       // XXX RNA_def_property_collection_funcs(prop, "rna_Mesh_verts_begin", 0, 0, 0, 0, 0, 0, "add_verts", "remove_verts");
 
        prop= RNA_def_property(srna, "edges", PROP_COLLECTION, PROP_NONE);
        RNA_def_property_collection_sdna(prop, NULL, "medge", "totedge");
@@ -1126,16 +1154,21 @@ static void rna_def_mesh(BlenderRNA *brna)
        RNA_def_property_struct_type(prop, "MeshSticky");
        RNA_def_property_ui_text(prop, "Sticky", "Sticky texture coordinates.");
 
+       /* UV layers */
+
        prop= RNA_def_property(srna, "uv_layers", PROP_COLLECTION, PROP_NONE);
        RNA_def_property_collection_sdna(prop, NULL, "fdata.layers", "fdata.totlayer");
        RNA_def_property_collection_funcs(prop, "rna_Mesh_uv_layers_begin", 0, 0, 0, "rna_Mesh_uv_layers_length", 0, 0, 0, 0);
        RNA_def_property_struct_type(prop, "MeshTextureFaceLayer");
        RNA_def_property_ui_text(prop, "UV Layers", "");
 
-       prop= RNA_def_property(srna, "active_uv_layer", PROP_POINTER, PROP_NONE);
+       prop= RNA_def_property(srna, "active_uv_layer", PROP_POINTER, PROP_UNSIGNED);
        RNA_def_property_struct_type(prop, "MeshTextureFaceLayer");
-       RNA_def_property_pointer_funcs(prop, "rna_Mesh_active_uv_layer_get", NULL, NULL);
-       RNA_def_property_ui_text(prop, "Active UV layer", "Active UV layer.");
+       RNA_def_property_pointer_funcs(prop, "rna_Mesh_active_uv_layer_get", "rna_Mesh_active_uv_layer_set", NULL);
+       RNA_def_property_flag(prop, PROP_EDITABLE);
+       RNA_def_property_ui_text(prop, "Active UV Layer", "Active UV layer.");
+
+       /* VCol layers */
 
        prop= RNA_def_property(srna, "vcol_layers", PROP_COLLECTION, PROP_NONE);
        RNA_def_property_collection_sdna(prop, NULL, "fdata.layers", "fdata.totlayer");
@@ -1143,6 +1176,12 @@ static void rna_def_mesh(BlenderRNA *brna)
        RNA_def_property_struct_type(prop, "MeshColorLayer");
        RNA_def_property_ui_text(prop, "Vertex Color Layers", "");
 
+       prop= RNA_def_property(srna, "active_vcol_layer", PROP_POINTER, PROP_UNSIGNED);
+       RNA_def_property_struct_type(prop, "MeshColorLayer");
+       RNA_def_property_pointer_funcs(prop, "rna_Mesh_active_vcol_layer_get", "rna_Mesh_active_vcol_layer_set", NULL);
+       RNA_def_property_flag(prop, PROP_EDITABLE);
+       RNA_def_property_ui_text(prop, "Active Vertex Color Layer", "Active vertex color layer.");
+
        prop= RNA_def_property(srna, "float_layers", PROP_COLLECTION, PROP_NONE);
        RNA_def_property_collection_sdna(prop, NULL, "fdata.layers", "fdata.totlayer");
        RNA_def_property_collection_funcs(prop, "rna_Mesh_float_layers_begin", 0, 0, 0, "rna_Mesh_float_layers_length", 0, 0, 0, 0);