Revision: 58836
          
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=58836
Author:   walid
Date:     2013-08-02 21:55:33 +0000 (Fri, 02 Aug 2013)
Log Message:
-----------
Shapekey transfer through projection: fully implementing shapekey transfer 
-fixing the interpolation to mimic the way of the UVs-

Modified Paths:
--------------
    
branches/soc-2013-meshdata_transfer/source/blender/bmesh/tools/bmesh_data_transfer.c

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 19:57:14 UTC (rev 58835)
+++ 
branches/soc-2013-meshdata_transfer/source/blender/bmesh/tools/bmesh_data_transfer.c
        2013-08-02 21:55:33 UTC (rev 58836)
@@ -1810,6 +1810,11 @@
        return true;
 }
 
+typedef struct co_pool {
+       float (*coord)[3];
+       int count;      //used to keep track of the coordinate to be filled
+} co_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),
                             ST_ShapekeyGroupMode replace_mode, int 
*act_shapekey_lay, float tmp_mat[4][4])
@@ -1818,15 +1823,19 @@
        struct BMBVHTree *bmtree_src = NULL;
        float *tmp_weight = NULL;
        float tmp_co[3];
-       BMFace *f;
-       BMIter fiter;
+       BMIter fiter, fiter2;
        BMVert *v2;
-       float (*v_co_list)[3];
-       int v_count;
 
        int a;
        float v_src_offset[3] = {0, 0, 0};
        float v_dst_offset[3] = {0, 0, 0};
+
+       BMIter viter;
+       BMFace *f_dst, *f_src;
+       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
        //====algorithm definitions end
 
        int CD_offset_src, CD_offset_dst;
@@ -1846,7 +1855,7 @@
        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];
+//     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
@@ -1864,6 +1873,19 @@
        //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");
+
+       offsets_grp = MEM_mallocN(sizeof(*offsets_grp) * bm_dst->totvert, 
"offsets_grp bmesh_data_transfer.c");
+       BM_ITER_MESH (v, &iter, bm_dst, BM_VERTS_OF_MESH) {
+
+               BM_ITER_ELEM_INDEX (f_dst, &viter, v, BM_FACES_OF_VERT, a) {}
+               offsets_grp[v->head.index].coord = 
MEM_mallocN(sizeof(*(offsets_grp[v->head.index].coord)) * a,
+                       "offsets_grp[v->head.index].coord  
bmesh_data_transfer.c");
+
+               offsets_grp[v->head.index].count = 0;   //if that wasn't fast 
enf we may use calloc for the offsets_grp
+       }
+
        if (replace_mode == ST_APPEND_SHAPEKEY_GROUPS) {
                //add 1 to skip the basis
                src_lay_start = 1;
@@ -1894,46 +1916,83 @@
                CD_offset_src = CustomData_get_n_offset(&bm_src->vdata, 
CD_SHAPEKEY,src_lay_iter);      //get the offset of the
                CD_offset_dst = CustomData_get_n_offset(&bm_dst->vdata, 
CD_SHAPEKEY,dst_lay_iter);      //lay_iter(th)CD_SHAPEKEY layer
 
-               //the way we do it is by looping over each vertex!!
-               for (v = BM_iter_new(&iter, bm_dst, BM_VERTS_OF_MESH, NULL); v; 
v = BM_iter_step(&iter)) {
+               //the way we do it is by looping over each face!!
+               BM_ITER_MESH (f_dst, &iter, 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, &fiter, 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, v->co);
+                       mul_v3_m4v3(tmp_co, tmp_mat, f_mid_dst);        //to 
start searching for a match
 
                        // Node tree accelerated search for closest face.
-                       f = BKE_bmbvh_find_face_closest(bmtree_src, tmp_co, 
FLT_MAX);
+                       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!!
+                       //deprecated comment
+                       ///fork from here to map each vertex into the projection
 
                        //get a coordinate list of the f verts
-                       BM_ITER_ELEM_INDEX (v2, &fiter, f, BM_VERTS_OF_FACE, 
v_count) {
-                               v_co_list = MEM_reallocN(v_co_list, 
sizeof(*v_co_list) * (v_count + 1));
-                               copy_v3_v3(v_co_list[v_count], v2->co);
+                       BM_ITER_ELEM_INDEX (v2, &fiter, 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
 
-                       // Project onto face.
-                       zero_v3(v_co);
-                       mid_poly_v3(v_co, v_co_list, v_count);  //v_co <= face 
center of the basis!
-                       project_v3_plane(tmp_co, f->no, v_co);
-                       //project_v3_plane(tmp_co, f->no, 
f->l_first->v->co);//not sure, do we really have to use an actual vertex ?
+                       BM_ITER_ELEM (v, &fiter, f_dst, BM_VERTS_OF_FACE) {
+                               float tmp[3] = {0, 0, 0};
+                               zero_v3(tmp_co);
+                               // Transform into target space.
+                               mul_v3_m4v3(tmp_co, tmp_mat, v->co);
 
-                       // Interpolate weights over face.
-                       //check that v_count will equal to n not n-1!!
-                       tmp_weight = MEM_mallocN(sizeof(*tmp_weight) * v_count, 
"tmp_weight bmesh_data_transfer.c");
+                               // Project each vertex onto face.
+                               project_v3_plane(tmp_co, f_src->no, f_mid_src);
+                               //project_v3_plane(tmp_co, f->no, 
f->l_first->v->co);//not sure, do we really have to use an actual vertex ?
 
-                       interp_weights_poly_v3(tmp_weight, v_co_list, v_count, 
v_co);
+                               // 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");
 
-                       // Get weights from face.
-                       zero_v3(v_dst_offset);
-                       BM_ITER_ELEM_INDEX (v2, &fiter, f, BM_VERTS_OF_FACE, a) 
{
-                               sub_v3_v3v3(v_src_offset, 
BM_ELEM_CD_GET_VOID_P(v2, CD_offset_src),
-                                       BM_ELEM_CD_GET_VOID_P(v2, 
CD_basis_src));
-                               madd_v3_v3fl(v_dst_offset, v_src_offset, 
tmp_weight[a]);
+                               //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
+                               // Get weights from face.
+                               zero_v3(v_dst_offset);
+                               BM_ITER_ELEM_INDEX (v2, &fiter2, f_src, 
BM_VERTS_OF_FACE, a) {
+                                       sub_v3_v3v3(v_src_offset, 
BM_ELEM_CD_GET_VOID_P(v2, CD_offset_src),
+                                               BM_ELEM_CD_GET_VOID_P(v2, 
CD_basis_src));
+                                       madd_v3_v3fl(v_dst_offset, 
v_src_offset, tmp_weight[a]);
+                               }
+
+                               
copy_v3_v3(offsets_grp[v->head.index].coord[offsets_grp[v->head.index].count], 
v_dst_offset);
+                               copy_v3_v3(tmp, v_dst_offset);
+                               copy_v3_v3(tmp, 
offsets_grp[v->head.index].coord[offsets_grp[v->head.index].count]);
+                               (offsets_grp[v->head.index].count)++;
+
+                               //shall we verify the indices!?
+                               //we interpolate vertix weights instead
                        }
 
-                       //shall we verify the indices!?
-                       //we interpolate vertix weights instead
+               }
+
+               BM_ITER_MESH (v, &iter, bm_dst, BM_VERTS_OF_MESH) {
+                       ///should be prepended with a copy_v3_v3
+                       zero_v3(v_dst_offset);
+                       mid_poly_v3(v_dst_offset, 
offsets_grp[v->head.index].coord, offsets_grp[v->head.index].count);
+
                        add_v3_v3v3(BM_ELEM_CD_GET_VOID_P(v, CD_offset_dst), 
BM_ELEM_CD_GET_VOID_P(v, CD_basis_dst),
                                    v_dst_offset);
+                       offsets_grp[v->head.index].count = 0; //reset for the 
upcoming layer
                }
+
        }
 
        return true;

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

Reply via email to