Revision: 58839
          
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=58839
Author:   walid
Date:     2013-08-03 01:59:04 +0000 (Sat, 03 Aug 2013)
Log Message:
-----------
Vertex Colors transfer through projection: initial implementation for the 
Vertex Colors transfer in a similar manner to the previous transfer for UVs, 
Shapekeys and Vertex Weights

Modified Paths:
--------------
    
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

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-02 23:41:09 UTC (rev 58838)
+++ 
branches/soc-2013-meshdata_transfer/source/blender/bmesh/tools/bmesh_data_transfer.c
        2013-08-03 01:59:04 UTC (rev 58839)
@@ -1810,10 +1810,10 @@
        return true;
 }
 
-typedef struct co_pool {
-       float (*coord)[3];
+typedef struct coord_pool {
+       float (*coord)[3];              //used as the offset coordinates for 
shapekeys
        int count;      //used to keep track of the coordinate to be filled
-} co_pool;
+} coord_pool;
 
 bool BM_mesh_shapekey_copy3(BMesh *bm_src, BMesh *bm_dst, float 
UNUSED(tolerance), float UNUSED(radius_interp),
                             int UNUSED(dist_pow), int UNUSED(no_pow), bool 
UNUSED(USE_NORMALS),
@@ -1835,7 +1835,7 @@
        int v_dst_count, v_src_count;
        float (*v_co_list_dst)[3], (*v_co_list_src)[3];
        float f_mid_dst[3], f_mid_src[3];
-       co_pool *offsets_grp;                           //stores all the 
gathered offsets/vert to be averaged at the end of interpolation
+       coord_pool *offsets_grp;                                //stores all 
the gathered offsets/vert to be averaged at the end of interpolation
        //====algorithm definitions end
 
        int CD_offset_src, CD_offset_dst;
@@ -2042,8 +2042,6 @@
        int src_lay_start, src_lay_end;
        int dst_lay_start, dst_lay_end; //dst_lay_end currently isn't being used
 
-//     float v_co[3];
-
        //Is that good to support edit mesh mode at the cost of receiving 
me_src too ?
        //if (me_src->edit_btmesh != NULL) em_src = me_src->edit_btmesh;        
//edit mesh mode
        //else
@@ -2177,3 +2175,156 @@
 
        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])
+{
+       //-----uv dependent variables
+       BMLoop *l, *l2;                                         //used for 
iterating the destination's loops
+//     MLoopUV *luv, *luv_src;
+       BMIter liter, liter2;
+       float weight_accu[4];
+
+       //-----algorithm definitions start
+       BMEditMesh *em_src;                                             //tree 
variable
+       struct BMBVHTree *bmtree_src = NULL;    //tree variable
+       float *tmp_weight = NULL;
+       float tmp_co[3];
+       float f_mid_src[3], f_mid_dst[3];
+
+       BMFace *f_src, *f_dst;
+       BMIter fiter;
+       BMVert *v2;
+       float (*v_co_list_src)[3];
+       float (*v_co_list_dst)[3];
+       int v_src_count;
+       int v_dst_count;
+
+       int a, b;//, c, d, g, h, i;
+       //====algorithm definitions end
+
+       int CD_src, CD_dst;
+
+       //used for iterating the destination's verts
+       BMVert *v;                                              //iterated vert
+       BMIter iter, iter2;                                     //vertex 
iterator
+       int tot_layer_src,tot_layer_dst;
+       int src_lay_iter, dst_lay_iter;
+
+       //replace mode variables
+       int src_lay_start, src_lay_end;
+       int dst_lay_start, dst_lay_end; //dst_lay_end currently isn't being used
+
+
+       //Is that good to support edit mesh mode at the cost of receiving 
me_src too ?
+       //if (me_src->edit_btmesh != NULL) em_src = me_src->edit_btmesh;        
//edit mesh mode
+       //else
+       em_src = BKE_editmesh_create(bm_src, true);     //create editmesh data 
from bm WITH tess.
+                                                                               
                        //if it was false ... data other than
+                                                                               
                        //em->bm won't be copied
+
+       //get the faces tree
+       bmtree_src = BKE_bmbvh_new(em_src, 0, NULL, false);
+
+
+       v_co_list_dst = MEM_mallocN(sizeof(*v_co_list_dst), "v_co_list_dst 
bmesh_data_transfer.c");
+       v_co_list_src = MEM_mallocN(sizeof(*v_co_list_src), "v_co_list 
bmesh_data_transfer.c");
+
+       tot_layer_src = CustomData_number_of_layers(&bm_src->ldata, 
CD_MLOOPCOL);//to change the last one
+       tot_layer_dst = CustomData_number_of_layers(&bm_dst->ldata, 
CD_MLOOPCOL);       //get the number of Shapekey layers
+                                                                               
                                                                                
//within the target
+
+       if (replace_mode == ST_APPEND_SHAPEKEY_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;
+               dst_lay_end = tot_layer_dst;
+       }
+
+       else if ((replace_mode == ST_REPLACE_ENOUGH_SHAPEKEY_GROUPS) || 
(replace_mode == ST_REPLACE_ALL_SHAPEKEY_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];
+       }
+
+       for (src_lay_iter = src_lay_start, dst_lay_iter = dst_lay_start; 
src_lay_iter < src_lay_end;
+               src_lay_iter++, dst_lay_iter++) {
+
+               //fix the layer index of the source & dest
+               CD_src = CustomData_get_n_offset(&bm_src->ldata, CD_MLOOPCOL, 
src_lay_iter);    //get the offset of the
+               CD_dst = CustomData_get_n_offset(&bm_dst->ldata, CD_MLOOPCOL, 
dst_lay_iter);    //lay_iter(th)CD_SHAPEKEY layer
+
+               //the way we do it is by looping over each face!!
+               BM_ITER_MESH (f_dst, &fiter, bm_dst, BM_FACES_OF_MESH) {
+
+                       //get a coordinate list of the f_dst verts
+                       //used to get the the f_mid_dst for mid_poly_v3
+                       BM_ITER_ELEM_INDEX (v, &iter, f_dst, BM_VERTS_OF_FACE, 
v_dst_count) {
+                               v_co_list_dst = MEM_reallocN(v_co_list_dst, 
sizeof(*v_co_list_dst) * (v_dst_count + 1));
+                               copy_v3_v3(v_co_list_dst[v_dst_count], v->co);
+                       }
+
+                       zero_v3(f_mid_dst);
+                       mid_poly_v3(f_mid_dst, v_co_list_dst, v_dst_count);
+
+                       // Transform into target space.
+                       mul_v3_m4v3(tmp_co, tmp_mat, f_mid_dst);        //to 
start searching for a match
+
+                       // Node tree accelerated search for closest face.
+                       f_src = BKE_bmbvh_find_face_closest(bmtree_src, tmp_co, 
FLT_MAX);       //would return null if the source didn't
+                                                                               
                                                                                
//have faces within the radius range!!
+                       ///fork from here to map each vertex into the projection
+
+
+                       //get a coordinate list of the f verts
+                       BM_ITER_ELEM_INDEX (v2, &iter2, f_src, 
BM_VERTS_OF_FACE, v_src_count) {
+                               v_co_list_src = MEM_reallocN(v_co_list_src, 
sizeof(*v_co_list_src) * (v_src_count + 1));
+                               copy_v3_v3(v_co_list_src[v_src_count], v2->co);
+                       }
+                       zero_v3(f_mid_src);
+                       mid_poly_v3(f_mid_src, v_co_list_src, v_src_count);     
//get the mid point of the source face
+
+                       BM_ITER_ELEM_INDEX (l, &liter, f_dst, BM_LOOPS_OF_FACE, 
b) {
+
+                               zero_v3(tmp_co);
+                               // Transform into target space.
+                               mul_v3_m4v3(tmp_co, tmp_mat, l->v->co);
+
+                               // Project each vertex onto face.
+                               project_v3_plane(tmp_co, f_src->no, f_mid_src);
+
+                               // Interpolate weights over face.
+                               //check that v_count will equal to n not n-1!!
+                               tmp_weight = MEM_mallocN(sizeof(*tmp_weight) * 
v_src_count, "tmp_weight bmesh_data_transfer.c");
+
+                               //spatially finding the weights from the face's 
vertices
+                               interp_weights_poly_v3(tmp_weight, 
v_co_list_src, v_src_count, tmp_co);
+
+                               // Interpolating according to the spatially 
found weights
+                               zero_v4(weight_accu);
+                               BM_ITER_ELEM_INDEX (l2, &liter2, f_src, 
BM_LOOPS_OF_FACE, a) {
+                                       madd_v4_v4fl(weight_accu, 
BM_ELEM_CD_GET_VOID_P(l2, CD_src), tmp_weight[a]);
+                               }
+
+                               //shall we verify the indices!?
+                               // copy for each loop directly
+                               copy_v4_v4(BM_ELEM_CD_GET_VOID_P(l, CD_dst), 
weight_accu);
+
+                               //end of interpolation
+                       }
+               }
+
+       }
+
+       return true;
+}

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-02 23:41:09 UTC (rev 58838)
+++ 
branches/soc-2013-meshdata_transfer/source/blender/bmesh/tools/bmesh_data_transfer.h
        2013-08-03 01:59:04 UTC (rev 58839)
@@ -63,5 +63,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]);
 #endif /* __BMESH_DATA_TRANSFER_H__ */
 

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

Reply via email to