clone and stencil layer access added, renamed mask to stencil layer internally
[blender.git] / source / blender / makesrna / intern / rna_mesh.c
index bacd7fc2b72744b53c6adf8657cbc9435de0aef5..c298d83850b0a24ad2494b9c97163a6dc5767457 100644 (file)
 #include "WM_api.h"
 #include "WM_types.h"
 
-static void rna_Mesh_update_data(bContext *C, PointerRNA *ptr)
+static void rna_Mesh_update_data(Main *bmain, Scene *scene, PointerRNA *ptr)
 {
        ID *id= ptr->id.data;
 
        DAG_id_flush_update(id, OB_RECALC_DATA);
-       WM_event_add_notifier(C, NC_GEOM|ND_DATA, id);
+       WM_main_add_notifier(NC_GEOM|ND_DATA, id);
 }
 
-static void rna_Mesh_update_select(bContext *C, PointerRNA *ptr)
+static void rna_Mesh_update_select(Main *bmain, Scene *scene, PointerRNA *ptr)
 {
        ID *id= ptr->id.data;
 
-       WM_event_add_notifier(C, NC_GEOM|ND_SELECT, id);
+       WM_main_add_notifier(NC_GEOM|ND_SELECT, id);
 }
 
-void rna_Mesh_update_draw(bContext *C, PointerRNA *ptr)
+void rna_Mesh_update_draw(Main *bmain, Scene *scene, PointerRNA *ptr)
 {
        ID *id= ptr->id.data;
 
-       WM_event_add_notifier(C, NC_GEOM|ND_DATA, id);
+       WM_main_add_notifier(NC_GEOM|ND_DATA, id);
 }
 
 static void rna_MeshVertex_normal_get(PointerRNA *ptr, float *value)
@@ -330,7 +330,7 @@ static PointerRNA rna_Mesh_active_uv_texture_get(PointerRNA *ptr)
        return rna_pointer_inherit_refine(ptr, &RNA_MeshTextureFaceLayer, cdl);
 }
 
-static PointerRNA rna_Mesh_clone_uv_texture_get(PointerRNA *ptr)
+static PointerRNA rna_Mesh_uv_texture_clone_get(PointerRNA *ptr)
 {
        Mesh *me= (Mesh*)ptr->data;
        CustomData *fdata= rna_mesh_fdata(me);
@@ -340,6 +340,16 @@ static PointerRNA rna_Mesh_clone_uv_texture_get(PointerRNA *ptr)
        return rna_pointer_inherit_refine(ptr, &RNA_MeshTextureFaceLayer, cdl);
 }
 
+static PointerRNA rna_Mesh_uv_texture_stencil_get(PointerRNA *ptr)
+{
+       Mesh *me= (Mesh*)ptr->data;
+       CustomData *fdata= rna_mesh_fdata(me);
+       int index= CustomData_get_stencil_layer_index(fdata, CD_MTFACE);
+       CustomDataLayer *cdl= (index == -1)? NULL: &fdata->layers[index];
+
+       return rna_pointer_inherit_refine(ptr, &RNA_MeshTextureFaceLayer, cdl);
+}
+
 static void rna_Mesh_active_uv_texture_set(PointerRNA *ptr, PointerRNA value)
 {
        Mesh *me= (Mesh*)ptr->data;
@@ -356,7 +366,7 @@ static void rna_Mesh_active_uv_texture_set(PointerRNA *ptr, PointerRNA value)
        }
 }
 
-static void rna_Mesh_clone_uv_texture_set(PointerRNA *ptr, PointerRNA value)
+static void rna_Mesh_uv_texture_clone_set(PointerRNA *ptr, PointerRNA value)
 {
        Mesh *me= (Mesh*)ptr->data;
        CustomData *fdata= rna_mesh_fdata(me);
@@ -366,7 +376,21 @@ static void rna_Mesh_clone_uv_texture_set(PointerRNA *ptr, PointerRNA value)
        for(cdl=fdata->layers, a=0; a<fdata->totlayer; cdl++, a++) {
                if(value.data == cdl) {
                        CustomData_set_layer_clone_index(fdata, CD_MTFACE, a);
-                       mesh_update_customdata_pointers(me);
+                       return;
+               }
+       }
+}
+
+static void rna_Mesh_uv_texture_stencil_set(PointerRNA *ptr, PointerRNA value)
+{
+       Mesh *me= (Mesh*)ptr->data;
+       CustomData *fdata= rna_mesh_fdata(me);
+       CustomDataLayer *cdl;
+       int a;
+
+       for(cdl=fdata->layers, a=0; a<fdata->totlayer; cdl++, a++) {
+               if(value.data == cdl) {
+                       CustomData_set_layer_stencil_index(fdata, CD_MTFACE, a);
                        return;
                }
        }
@@ -379,13 +403,20 @@ static int rna_Mesh_active_uv_texture_index_get(PointerRNA *ptr)
        return CustomData_get_active_layer(fdata, CD_MTFACE);
 }
 
-static int rna_Mesh_clone_uv_texture_index_get(PointerRNA *ptr)
+static int rna_Mesh_uv_texture_clone_index_get(PointerRNA *ptr)
 {
        Mesh *me= (Mesh*)ptr->data;
        CustomData *fdata= rna_mesh_fdata(me);
        return CustomData_get_clone_layer(fdata, CD_MTFACE);
 }
 
+static int rna_Mesh_uv_texture_stencil_index_get(PointerRNA *ptr)
+{
+       Mesh *me= (Mesh*)ptr->data;
+       CustomData *fdata= rna_mesh_fdata(me);
+       return CustomData_get_stencil_layer(fdata, CD_MTFACE);
+}
+
 static void rna_Mesh_active_uv_texture_index_set(PointerRNA *ptr, int value)
 {
        Mesh *me= (Mesh*)ptr->data;
@@ -395,13 +426,20 @@ static void rna_Mesh_active_uv_texture_index_set(PointerRNA *ptr, int value)
        mesh_update_customdata_pointers(me);
 }
 
-static void rna_Mesh_clone_uv_texture_index_set(PointerRNA *ptr, int value)
+static void rna_Mesh_uv_texture_clone_index_set(PointerRNA *ptr, int value)
 {
        Mesh *me= (Mesh*)ptr->data;
        CustomData *fdata= rna_mesh_fdata(me);
 
        CustomData_set_layer_clone(fdata, CD_MTFACE, value);
-       mesh_update_customdata_pointers(me);
+}
+
+static void rna_Mesh_uv_texture_stencil_index_set(PointerRNA *ptr, int value)
+{
+       Mesh *me= (Mesh*)ptr->data;
+       CustomData *fdata= rna_mesh_fdata(me);
+
+       CustomData_set_layer_stencil(fdata, CD_MTFACE, value);
 }
 
 static void rna_Mesh_active_uv_texture_index_range(PointerRNA *ptr, int *min, int *max)
@@ -1517,6 +1555,27 @@ void rna_def_texmat_common(StructRNA *srna, const char *texspace_editable)
        RNA_def_property_ui_text(prop, "Materials", "");
 }
 
+
+/* scene.objects */
+static void rna_def_mesh_faces(BlenderRNA *brna, PropertyRNA *cprop)
+{
+       StructRNA *srna;
+       PropertyRNA *prop;
+
+//     FunctionRNA *func;
+//     PropertyRNA *parm;
+
+       RNA_def_property_srna(cprop, "MeshFaces");
+       srna= RNA_def_struct(brna, "MeshFaces", NULL);
+       RNA_def_struct_sdna(srna, "Mesh");
+       RNA_def_struct_ui_text(srna, "Mesh Faces", "Collection of mesh faces.");
+
+       prop= RNA_def_property(srna, "active", PROP_INT, PROP_NONE);
+       RNA_def_property_int_sdna(prop, NULL, "act_face");
+       RNA_def_property_ui_text(prop, "Active Face", "The active face for this mesh");
+}
+
+
 static void rna_def_mesh(BlenderRNA *brna)
 {
        StructRNA *srna;
@@ -1540,6 +1599,7 @@ static void rna_def_mesh(BlenderRNA *brna)
        RNA_def_property_collection_sdna(prop, NULL, "mface", "totface");
        RNA_def_property_struct_type(prop, "MeshFace");
        RNA_def_property_ui_text(prop, "Faces", "Faces of the mesh.");
+       rna_def_mesh_faces(brna, prop);
 
        prop= RNA_def_property(srna, "sticky", PROP_COLLECTION, PROP_NONE);
        RNA_def_property_collection_sdna(prop, NULL, "msticky", "totvert");
@@ -1571,17 +1631,25 @@ static void rna_def_mesh(BlenderRNA *brna)
        RNA_def_property_ui_text(prop, "Active UV Texture Index", "Active UV texture index.");
        RNA_def_property_update(prop, 0, "rna_Mesh_update_data");
 
-       prop= RNA_def_property(srna, "clone_uv_texture", PROP_POINTER, PROP_UNSIGNED);
+       prop= RNA_def_property(srna, "uv_texture_clone", PROP_POINTER, PROP_UNSIGNED);
        RNA_def_property_struct_type(prop, "MeshTextureFaceLayer");
-       RNA_def_property_pointer_funcs(prop, "rna_Mesh_clone_uv_texture_get", "rna_Mesh_clone_uv_texture_set", NULL);
+       RNA_def_property_pointer_funcs(prop, "rna_Mesh_uv_texture_clone_get", "rna_Mesh_uv_texture_clone_set", NULL);
        RNA_def_property_flag(prop, PROP_EDITABLE);
        RNA_def_property_ui_text(prop, "Clone UV Texture", "UV texture to be used as cloning source.");
-       RNA_def_property_update(prop, 0, "rna_Mesh_update_data");
 
-       prop= RNA_def_property(srna, "clone_uv_texture_index", PROP_INT, PROP_UNSIGNED);
-       RNA_def_property_int_funcs(prop, "rna_Mesh_clone_uv_texture_index_get", "rna_Mesh_clone_uv_texture_index_set", "rna_Mesh_active_uv_texture_index_range");
+       prop= RNA_def_property(srna, "uv_texture_clone_index", PROP_INT, PROP_UNSIGNED);
+       RNA_def_property_int_funcs(prop, "rna_Mesh_uv_texture_clone_index_get", "rna_Mesh_uv_texture_clone_index_set", "rna_Mesh_active_uv_texture_index_range");
        RNA_def_property_ui_text(prop, "Clone UV Texture Index", "Clone UV texture index.");
-       RNA_def_property_update(prop, 0, "rna_Mesh_update_data");
+
+       prop= RNA_def_property(srna, "uv_texture_stencil", PROP_POINTER, PROP_UNSIGNED);
+       RNA_def_property_struct_type(prop, "MeshTextureFaceLayer");
+       RNA_def_property_pointer_funcs(prop, "rna_Mesh_uv_texture_stencil_get", "rna_Mesh_uv_texture_stencil_set", NULL);
+       RNA_def_property_flag(prop, PROP_EDITABLE);
+       RNA_def_property_ui_text(prop, "Mask UV Texture", "UV texture to mask the painted area.");
+
+       prop= RNA_def_property(srna, "uv_texture_stencil_index", PROP_INT, PROP_UNSIGNED);
+       RNA_def_property_int_funcs(prop, "rna_Mesh_uv_texture_stencil_index_get", "rna_Mesh_uv_texture_stencil_index_set", "rna_Mesh_active_uv_texture_index_range");
+       RNA_def_property_ui_text(prop, "Mask UV Texture Index", "Mask UV texture index.");
 
        /* Vertex colors */