Revision: 58897
          
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=58897
Author:   walid
Date:     2013-08-04 05:37:25 +0000 (Sun, 04 Aug 2013)
Log Message:
-----------
Vertex Color transfer Operator: registering the operator with all the options 
found in the UV transfer operator

Modified Paths:
--------------
    
branches/soc-2013-meshdata_transfer/release/scripts/startup/bl_ui/space_view3d_toolbar.py
    
branches/soc-2013-meshdata_transfer/source/blender/bmesh/tools/bmesh_data_transfer.c
    
branches/soc-2013-meshdata_transfer/source/blender/bmesh/tools/bmesh_data_transfer.h
    branches/soc-2013-meshdata_transfer/source/blender/editors/mesh/mesh_data.c
    
branches/soc-2013-meshdata_transfer/source/blender/editors/mesh/mesh_intern.h
    branches/soc-2013-meshdata_transfer/source/blender/editors/mesh/mesh_ops.c

Modified: 
branches/soc-2013-meshdata_transfer/release/scripts/startup/bl_ui/space_view3d_toolbar.py
===================================================================
--- 
branches/soc-2013-meshdata_transfer/release/scripts/startup/bl_ui/space_view3d_toolbar.py
   2013-08-04 04:59:09 UTC (rev 58896)
+++ 
branches/soc-2013-meshdata_transfer/release/scripts/startup/bl_ui/space_view3d_toolbar.py
   2013-08-04 05:37:25 UTC (rev 58897)
@@ -116,6 +116,7 @@
 
         col.operator("object.shape_key_transfer_new", text="Transfer Shapekeys 
(new)")
         col.operator("mesh.uv_transfer_new", text="Transfer UVs (new)")
+        col.operator("mesh.vertex_color_transfer_new", text="Transfer Colors 
(new)")
 
 
 class VIEW3D_PT_tools_rigidbody(View3DPanel, Panel):

Modified: 
branches/soc-2013-meshdata_transfer/source/blender/bmesh/tools/bmesh_data_transfer.c
===================================================================
--- 
branches/soc-2013-meshdata_transfer/source/blender/bmesh/tools/bmesh_data_transfer.c
        2013-08-04 04:59:09 UTC (rev 58896)
+++ 
branches/soc-2013-meshdata_transfer/source/blender/bmesh/tools/bmesh_data_transfer.c
        2013-08-04 05:37:25 UTC (rev 58897)
@@ -1607,7 +1607,6 @@
 
        tmp_weight = MEM_mallocN(sizeof(*tmp_weight) * exp_vert_per_face, 
"tmp_weight bmesh_data_transfer.c");
        if (replace_mode == APPEND_GROUPS) {
-               //add 1 to skip the basis
                src_lay_start = 0;
                src_lay_end = tot_layer_src;
                dst_lay_start = tot_layer_dst - tot_layer_src;
@@ -2319,8 +2318,7 @@
        return true;
 }
 
-bool BM_mesh_vertex_color_copy(BMesh *bm_src, BMesh* 
bm_dst,ST_ShapekeyGroupMode replace_mode, int *act_shapekey_lay,
-                               float tmp_mat[4][4])
+bool BM_mesh_vertex_color_copy(BMesh *bm_src, BMesh* bm_dst, ReplaceGroupMode 
replace_mode, float tmp_mat[4][4])
 {
        //-----uv dependent variables
        BMLoop *l, *l2;                                         //used for 
iterating the destination's loops
@@ -2382,27 +2380,25 @@
        //its unlikely to have faces with more than a certain number of 
vertices ...
        //we'll later reallocate only if this threshold got exceeded
        tmp_weight = MEM_mallocN(sizeof(*tmp_weight) * exp_vert_per_face, 
"tmp_weight bmesh_data_transfer.c");
-       if (replace_mode == ST_APPEND_SHAPEKEY_GROUPS) {
-               //add 1 to skip the basis
+       if (replace_mode == APPEND_GROUPS) {
                src_lay_start = 0;
                src_lay_end = tot_layer_src;
                dst_lay_start = tot_layer_dst - tot_layer_src;
                dst_lay_end = tot_layer_dst;
        }
 
-       else if ((replace_mode == ST_REPLACE_ENOUGH_SHAPEKEY_GROUPS) || 
(replace_mode == ST_REPLACE_ALL_SHAPEKEY_GROUPS)) {
+       else if ((replace_mode == REPLACE_ENOUGH_GROUPS) || (replace_mode == 
REPLACE_ALL_GROUPS)) {
                src_lay_start = 0;
                src_lay_end = tot_layer_src;
                dst_lay_start = 0;
                dst_lay_end = tot_layer_src;
        }
 
-       else if (replace_mode == ST_REPLACE_ACTIVE_SHAPEKEY_GROUP) {
-               //passed shapekey reperesents the # of shapekeys (starts from 
one), however lay_start uses it as an index
-               src_lay_start = act_shapekey_lay[0] - 1;
-               src_lay_end = act_shapekey_lay[0];
-               dst_lay_start = act_shapekey_lay[1] - 1;
-               dst_lay_end = act_shapekey_lay[1];
+       else if (replace_mode == REPLACE_ACTIVE_GROUP) {
+               src_lay_start = 
CustomData_get_active_layer_index(&bm_src->ldata, CD_MLOOPCOL);
+               src_lay_end = src_lay_start + 1;        //stopping condition
+               dst_lay_start = 
CustomData_get_active_layer_index(&bm_dst->ldata, CD_MLOOPCOL);
+               dst_lay_end = dst_lay_start + 1;
        }
 
        for (src_lay_iter = src_lay_start, dst_lay_iter = dst_lay_start; 
src_lay_iter < src_lay_end;

Modified: 
branches/soc-2013-meshdata_transfer/source/blender/bmesh/tools/bmesh_data_transfer.h
===================================================================
--- 
branches/soc-2013-meshdata_transfer/source/blender/bmesh/tools/bmesh_data_transfer.h
        2013-08-04 04:59:09 UTC (rev 58896)
+++ 
branches/soc-2013-meshdata_transfer/source/blender/bmesh/tools/bmesh_data_transfer.h
        2013-08-04 05:37:25 UTC (rev 58897)
@@ -70,7 +70,7 @@
 void BM_mesh_shapekey_copy_index(BMesh *bm_src, BMesh *bm_dst);
 bool BM_mesh_vertex_group_copy(BMesh *bm_src, BMesh* 
bm_dst,ST_ShapekeyGroupMode replace_mode, int *act_shapekey_lay,
                                float tmp_mat[4][4]);
-bool BM_mesh_vertex_color_copy(BMesh *bm_src, BMesh* 
bm_dst,ST_ShapekeyGroupMode replace_mode, int *act_shapekey_lay,
-                               float tmp_mat[4][4]);
+bool BM_mesh_vertex_color_copy(BMesh *bm_src, BMesh* bm_dst, ReplaceGroupMode 
replace_mode, float tmp_mat[4][4]);
+
 #endif /* __BMESH_DATA_TRANSFER_H__ */
 

Modified: 
branches/soc-2013-meshdata_transfer/source/blender/editors/mesh/mesh_data.c
===================================================================
--- branches/soc-2013-meshdata_transfer/source/blender/editors/mesh/mesh_data.c 
2013-08-04 04:59:09 UTC (rev 58896)
+++ branches/soc-2013-meshdata_transfer/source/blender/editors/mesh/mesh_data.c 
2013-08-04 05:37:25 UTC (rev 58897)
@@ -747,7 +747,154 @@
                return false;
        }
 }
+static bool ED_mesh_vertex_color_transfer(Object *ob_dst, Object *ob_src, 
bContext *UNUSED(C), Scene *UNUSED(scene), wmOperator * op)
+{
+       Mesh *me_dst, *me_src;
+       BMesh *bm_dst, *bm_src;
 
+       float UNUSED(tolerance) = RNA_float_get(op->ptr, "tolerance");
+       float UNUSED(radius_interp) = RNA_float_get(op->ptr, "interp_radius");
+       int UNUSED(interp_pow) = RNA_int_get(op->ptr, "interp_power");
+       bool UNUSED(interp_normals) = RNA_boolean_get(op->ptr, 
"interp_normals");
+       int UNUSED(no_pow) = RNA_int_get(op->ptr, "normals_power");
+       ReplaceGroupMode replace_mode = RNA_enum_get(op->ptr, "replace_mode");
+       TransferMode transfer_mode = RNA_enum_get(op->ptr, "transfer_mode");
+
+       int num_src_lay, num_dst_lay;
+
+       int i;
+
+       float tmp_mat[4][4];
+
+       int CD_src;
+       int active_dst, active_src;
+       char *src_name;
+
+       invert_m4_m4(ob_src->imat, ob_src->obmat);
+       mul_m4_m4m4(tmp_mat, ob_src->imat, ob_dst->obmat);
+
+       me_dst = ob_dst->data;
+       me_src = ob_src->data;
+
+       //manipulating the layers first as its interface uses the Mesh 
structure not the BMesh
+       num_src_lay = CustomData_number_of_layers(&me_src->ldata, CD_MLOOPCOL);
+       num_dst_lay = CustomData_number_of_layers(&me_dst->ldata, CD_MLOOPCOL);
+
+       if (num_src_lay < 1) {
+               //the source should have UV layers
+               BKE_report(op->reports, RPT_ERROR,
+                          "Transfer failed no color groups were found (source 
mesh should have -at least- UV group)");
+
+               return false;
+       }
+
+       if (replace_mode == REPLACE_ENOUGH_GROUPS) {
+
+               //add layers as needed
+               i = num_src_lay - num_dst_lay;
+               while (i > 0) {
+                       ED_mesh_uv_texture_add(me_dst, NULL, true);
+                       i--;
+               }
+               CD_src = CustomData_get_layer_index(&me_src->ldata, 
CD_MLOOPCOL);
+               //copy the names
+               for (i = 0; i < num_src_lay; ++i) {
+
+                       src_name = me_src->ldata.layers[CD_src + i].name;
+                       CustomData_set_layer_name(&me_dst->ldata, CD_MLOOPCOL, 
i, src_name);
+               }
+       }
+
+       //we'll tell the copy function to start copying from # of source layers 
from the end of the dst layers
+       else if (replace_mode == APPEND_GROUPS)
+       {
+               CD_src = CustomData_get_layer_index(&me_src->ldata, 
CD_MLOOPCOL);
+               for (i = 0; i < num_src_lay; ++i) {
+
+                       src_name = me_src->ldata.layers[CD_src + i].name;
+                       //append uv layer with the src names
+                       ED_mesh_uv_texture_add(me_dst, src_name, true);
+               }
+       }
+
+       else if (replace_mode == REPLACE_ALL_GROUPS)
+       {
+               i = num_dst_lay;
+               while (i > 0) {
+                       i--;
+                       ED_mesh_uv_texture_remove_index(me_dst, i);
+               }
+
+               CD_src = CustomData_get_layer_index(&me_src->ldata, 
CD_MLOOPCOL);
+               for (i = 0; i < num_src_lay; ++i) {
+                       src_name = me_src->ldata.layers[CD_src + i].name;
+                       //add uv layer with the src name
+                       ED_mesh_uv_texture_add(me_dst, src_name, true);
+               }
+       }
+
+       else if (replace_mode == REPLACE_ACTIVE_GROUP) {
+
+               //find the source active layer
+               active_src = CustomData_get_active_layer_index(&me_src->ldata, 
CD_MLOOPCOL);
+               active_dst = CustomData_get_active_layer_index(&me_dst->ldata, 
CD_MLOOPCOL);
+
+               CD_src = CustomData_get_layer_index(&me_src->ldata, 
CD_MLOOPCOL);
+
+               if (num_src_lay == 0) { //empty destination
+                       src_name = me_src->ldata.layers[CD_src + 
active_src].name;
+
+                       //add uv layer with the src name
+                       ED_mesh_uv_texture_add(me_dst, src_name, true);
+
+                       //make the added layer the active one
+                       ///what about the MTEXPOLY
+                       CustomData_set_layer_active(&me_dst->ldata, 
CD_MLOOPCOL, 0);
+               }
+
+               else {  //destination has layers (accordingly there's a 
selected layer)
+
+                       src_name = me_src->ldata.layers[CD_src + 
active_src].name;
+
+                       CustomData_set_layer_name(&me_dst->ldata, CD_MLOOPCOL, 
active_dst, src_name);
+               }
+       }
+
+       //allocate space
+       bm_src = BM_mesh_create(&bm_mesh_allocsize_default);
+       bm_dst = BM_mesh_create(&bm_mesh_allocsize_default);
+
+       BM_mesh_bm_from_me(bm_src, me_src, TRUE, true, 0);      //TRUE -> 
should transfer shapekeys too!!
+       BM_mesh_bm_from_me(bm_dst, me_dst, TRUE, true, 0);
+
+       if (transfer_mode == PROJECTION_TRANSFER) {
+               if (!BM_mesh_vertex_color_copy(bm_src, bm_dst, replace_mode, 
tmp_mat)) {
+                       return false;
+               }
+       }
+       //*******copy based on nearest vertex
+       else if (transfer_mode == SPATIAL_TRANSFER) {
+                   BKE_report(op->reports, RPT_ERROR,
+                                  "Spatial transfer is not supported yet, the 
projection transfer would be a better choice :D");
+
+/*             if (!BM_mesh_vertex_color_copy2(bm_src, bm_dst, tolerance, 
radius_interp, interp_pow, no_pow, interp_normals)) {
+                       return false;
+               }
+*/     }
+
+
+       //transfer the BMesh back to Mesh
+       BM_mesh_bm_to_me(bm_src, me_src, FALSE);
+       BM_mesh_bm_to_me(bm_dst, me_dst, TRUE);
+
+       //free the BMesh
+       BM_mesh_free(bm_src);
+       BM_mesh_free(bm_dst);
+
+       return true;
+
+}
+
 /*********************** UV texture operators ************************/
 
 static int layers_poll(bContext *C)
@@ -1043,6 +1190,92 @@
        ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
 }
 
+static int vertex_color_transfer_exec(bContext *C, wmOperator * op)
+{
+       Scene *scene = CTX_data_scene(C);
+       Object *ob_act = CTX_data_active_object(C);
+       int fail = 0;
+
+       bool transfer_first_to_act = true;
+
+       FromToActive from_active = RNA_enum_get(op->ptr, "from_to_active");
+
+       /* Macro to loop through selected objects.*/
+       CTX_DATA_BEGIN (C, Object *, ob_slc, selected_editable_objects)
+       {
+               //if the selected isn't the active object
+               if (ob_act != ob_slc) {
+
+                       if (from_active == TO_ACTIVE) {
+
+                               //if many objects were selected within this 
mode ... we should copy only from the first
+                               //notice that ob_slc priority isn't set by 
order of selection!
+                               if (transfer_first_to_act == true) {

@@ Diff output truncated at 10240 characters. @@
_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to