Revision: 44893
          
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=44893
Author:   campbellbarton
Date:     2012-03-15 05:40:33 +0000 (Thu, 15 Mar 2012)
Log Message:
-----------
fixes for vertex color (found when brining X3D import back)
- tessface vertex color had the wrong sized array passing to 
rna_iterator_array_begin
- re-calculating tessface's would clear them if they were already created (own 
mistake)
- ED_mesh_color_add initialized tessface vertex colors from the loop color array

also made rna's mesh.tessface_vertex_colors.new() work like 
tessface_uv_textures.new()
where layers can be added as long as polygons are not present.

Modified Paths:
--------------
    trunk/blender/source/blender/editors/mesh/mesh_data.c
    trunk/blender/source/blender/makesrna/intern/rna_mesh.c

Modified: trunk/blender/source/blender/editors/mesh/mesh_data.c
===================================================================
--- trunk/blender/source/blender/editors/mesh/mesh_data.c       2012-03-15 
04:08:57 UTC (rev 44892)
+++ trunk/blender/source/blender/editors/mesh/mesh_data.c       2012-03-15 
05:40:33 UTC (rev 44893)
@@ -421,7 +421,7 @@
 
                if(me->mloopcol) {
                        CustomData_add_layer_named(&me->ldata, CD_MLOOPCOL, 
CD_DUPLICATE, me->mloopcol, me->totloop, name);
-                       CustomData_add_layer_named(&me->fdata, CD_MCOL, 
CD_DUPLICATE, me->mloopcol, me->totface, name);
+                       CustomData_add_layer_named(&me->fdata, CD_MCOL, 
CD_DUPLICATE, me->mcol, me->totface, name);
                }
                else {
                        CustomData_add_layer_named(&me->ldata, CD_MLOOPCOL, 
CD_DEFAULT, NULL, me->totloop, name);
@@ -757,12 +757,13 @@
 {
        int *polyindex = NULL;
        float (*face_nors)[3];
+       int tessface_input = FALSE;
 
        if(mesh->totface > 0 && mesh->totpoly == 0) {
                convert_mfaces_to_mpolys(mesh);
 
                /* would only be converting back again, dont bother */
-               calc_tessface = FALSE;
+               tessface_input = TRUE;
 
                /* it also happens that converting the faces calculates edges, 
skip this */
                calc_edges = FALSE;
@@ -772,7 +773,9 @@
                BKE_mesh_calc_edges(mesh, calc_edges);
 
        if (calc_tessface) {
-               BKE_mesh_tessface_calc(mesh);
+               if (tessface_input == FALSE) {
+                       BKE_mesh_tessface_calc(mesh);
+               }
        }
        else {
                /* default state is not to have tessface's so make sure this is 
the case */

Modified: trunk/blender/source/blender/makesrna/intern/rna_mesh.c
===================================================================
--- trunk/blender/source/blender/makesrna/intern/rna_mesh.c     2012-03-15 
04:08:57 UTC (rev 44892)
+++ trunk/blender/source/blender/makesrna/intern/rna_mesh.c     2012-03-15 
05:40:33 UTC (rev 44893)
@@ -666,7 +666,7 @@
 {
        Mesh *me = rna_mesh(ptr);
        CustomDataLayer *layer = (CustomDataLayer *)ptr->data;
-       rna_iterator_array_begin(iter, layer->data, sizeof(CD_MCOL), 
me->totface, 0, NULL);
+       rna_iterator_array_begin(iter, layer->data, sizeof(MCol) * 4, 
me->totface, 0, NULL);
 }
 
 static int rna_MeshColorLayer_data_length(PointerRNA *ptr)
@@ -703,7 +703,7 @@
 {
        Mesh *me = rna_mesh(ptr);
        CustomDataLayer *layer = (CustomDataLayer*)ptr->data;
-       rna_iterator_array_begin(iter, layer->data, sizeof(CD_MLOOPCOL), 
me->totloop, 0, NULL);
+       rna_iterator_array_begin(iter, layer->data, sizeof(MLoopCol), 
me->totloop, 0, NULL);
 }
 
 static int rna_MeshLoopColorLayer_data_length(PointerRNA *ptr)
@@ -1178,6 +1178,35 @@
        return ptr;
 }
 
+static PointerRNA rna_Mesh_tessface_vertex_color_new(struct Mesh *me, struct 
bContext *C, ReportList *reports,
+                                                     const char *name)
+{
+       PointerRNA ptr;
+       CustomData *fdata;
+       CustomDataLayer *cdl= NULL;
+       int index;
+
+       if (me->edit_btmesh) {
+               BKE_report(reports, RPT_ERROR, "Can't add tessface colors's in 
editmode");
+               return PointerRNA_NULL;
+       }
+
+       if (me->mpoly) {
+               BKE_report(reports, RPT_ERROR, "Can't add tessface colors's 
when MPoly's exist");
+               return PointerRNA_NULL;
+       }
+
+       index = ED_mesh_color_add(C, NULL, NULL, me, name, FALSE);
+
+       if(index != -1) {
+               fdata = rna_mesh_fdata_helper(me);
+               cdl = &fdata->layers[CustomData_get_layer_index_n(fdata, 
CD_MCOL, index)];
+       }
+
+       RNA_pointer_create(&me->id, &RNA_MeshColorLayer, cdl, &ptr);
+       return ptr;
+}
+
 static PointerRNA rna_Mesh_int_property_new(struct Mesh *me, struct bContext 
*C, const char *name)
 {
        PointerRNA ptr;
@@ -1242,7 +1271,7 @@
 /* while this is supposed to be readonly,
  * keep it to support importers that only make tessfaces */
 
-static PointerRNA rna_Mesh_uv_tessface_texture_new(struct Mesh *me, struct 
bContext *C, ReportList *reports,
+static PointerRNA rna_Mesh_tessface_uv_texture_new(struct Mesh *me, struct 
bContext *C, ReportList *reports,
                                                    const char *name)
 {
        PointerRNA ptr;
@@ -1263,8 +1292,8 @@
        index = ED_mesh_uv_texture_add(C, me, name, FALSE);
 
        if(index != -1) {
-               fdata= rna_mesh_fdata_helper(me);
-               cdl= &fdata->layers[CustomData_get_layer_index_n(fdata, 
CD_MTFACE, index)];
+               fdata = rna_mesh_fdata_helper(me);
+               cdl = &fdata->layers[CustomData_get_layer_index_n(fdata, 
CD_MTFACE, index)];
        }
 
        RNA_pointer_create(&me->id, &RNA_MeshTextureFaceLayer, cdl, &ptr);
@@ -2192,14 +2221,23 @@
        StructRNA *srna;
        PropertyRNA *prop;
 
-       /* FunctionRNA *func; */
-       /* PropertyRNA *parm; */
+       FunctionRNA *func;
+       PropertyRNA *parm;
 
        RNA_def_property_srna(cprop, "VertexColors");
        srna = RNA_def_struct(brna, "VertexColors", NULL);
        RNA_def_struct_sdna(srna, "Mesh");
        RNA_def_struct_ui_text(srna, "Vertex Colors", "Collection of vertex 
colors");
 
+       /* eventually deprecate this */
+       func = RNA_def_function(srna, "new", 
"rna_Mesh_tessface_vertex_color_new");
+       RNA_def_function_flag(func, FUNC_USE_CONTEXT | FUNC_USE_REPORTS);
+       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);
+
        prop = RNA_def_property(srna, "active", PROP_POINTER, PROP_UNSIGNED);
        RNA_def_property_struct_type(prop, "MeshColorLayer");
        RNA_def_property_pointer_funcs(prop, 
"rna_Mesh_tessface_vertex_color_active_get",
@@ -2366,7 +2404,7 @@
        RNA_def_struct_ui_text(srna, "UV Maps", "Collection of UV maps for 
tessellated faces");
 
        /* eventually deprecate this */
-       func= RNA_def_function(srna, "new", "rna_Mesh_uv_tessface_texture_new");
+       func= RNA_def_function(srna, "new", "rna_Mesh_tessface_uv_texture_new");
        RNA_def_function_flag(func, FUNC_USE_CONTEXT | FUNC_USE_REPORTS);
        RNA_def_function_ui_description(func, "Add a UV tessface-texture layer 
to Mesh (only for meshes with no polygons)");
        RNA_def_string(func, "name", "UVMap", 0, "", "UV map name");

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to