Revision: 58834
          
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=58834
Author:   walid
Date:     2013-08-02 19:54:32 +0000 (Fri, 02 Aug 2013)
Log Message:
-----------
Shapekey transfer through projection: duplicating the shapekey transfer and 
rewiring the transfer into it (BM_mesh_shapekey_copy3) to mimic the UV 
transfer's face to face mapping into it

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
    
branches/soc-2013-meshdata_transfer/source/blender/editors/object/object_shapekey.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 18:19:08 UTC (rev 58833)
+++ 
branches/soc-2013-meshdata_transfer/source/blender/bmesh/tools/bmesh_data_transfer.c
        2013-08-02 19:54:32 UTC (rev 58834)
@@ -1810,3 +1810,131 @@
        return true;
 }
 
+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])
+{
+       //-----algorithm definitions start
+       struct BMBVHTree *bmtree_src = NULL;
+       float *tmp_weight = NULL;
+       float tmp_co[3];
+       BMFace *f;
+       BMIter fiter;
+       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};
+       //====algorithm definitions end
+
+       int CD_offset_src, CD_offset_dst;
+       int CD_basis_src, CD_basis_dst;
+
+       //used for iterating the destination's verts
+       BMVert *v;
+       //iter => vertex iterator
+       BMIter iter;
+       int tot_layer_src,tot_layer_dst;
+       int src_lay_iter, dst_lay_iter;
+
+       //tree variables
+       BMEditMesh *em_src;
+
+       //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
+
+       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
+       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
+
+       tot_layer_src = CustomData_number_of_layers(&bm_src->vdata, 
CD_SHAPEKEY);//to change the last one
+       tot_layer_dst = CustomData_number_of_layers(&bm_dst->vdata, 
CD_SHAPEKEY);       //get the number of Shapekey layers
+                                                                               
                                                                                
//within the target
+       CD_basis_src = CustomData_get_n_offset(&bm_src->vdata, CD_SHAPEKEY, 0); 
//get the offset of the basis
+       CD_basis_dst = CustomData_get_n_offset(&bm_dst->vdata, CD_SHAPEKEY, 0);
+
+       //get the faces tree
+       bmtree_src = BKE_bmbvh_new(em_src, 0, NULL, false);
+
+       if (replace_mode == ST_APPEND_SHAPEKEY_GROUPS) {
+               //add 1 to skip the basis
+               src_lay_start = 1;
+               src_lay_end = tot_layer_src;
+               dst_lay_start = tot_layer_dst - tot_layer_src + 1;
+               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 = 1;
+               src_lay_end = tot_layer_src;
+               dst_lay_start = 1;
+               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_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)) {
+
+                       // Transform into target space.
+                       mul_v3_m4v3(tmp_co, tmp_mat, v->co);
+
+                       // Node tree accelerated search for closest face.
+                       f = BKE_bmbvh_find_face_closest(bmtree_src, tmp_co, 
FLT_MAX);
+
+                       //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);
+                       }
+
+                       // 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 ?
+
+                       // 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");
+
+                       interp_weights_poly_v3(tmp_weight, v_co_list, v_count, 
v_co);
+
+                       // 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]);
+                       }
+
+                       //shall we verify the indices!?
+                       //we interpolate vertix weights instead
+                       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);
+               }
+       }
+
+       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 18:19:08 UTC (rev 58833)
+++ 
branches/soc-2013-meshdata_transfer/source/blender/bmesh/tools/bmesh_data_transfer.h
        2013-08-02 19:54:32 UTC (rev 58834)
@@ -57,6 +57,9 @@
 bool BM_mesh_shapekey_copy2(BMesh *bm_src, BMesh *bm_dst, float 
UNUSED_tolerance, float UNUSED_radius_interp,
                            int UNUSED_interp_pow, int UNUSED_no_pow, bool 
UNUSED_USE_NORMALS, ST_ShapekeyGroupMode replace_mode,
                             int *act_shapekey_lay, float tmp_mat[4][4]);
+bool BM_mesh_shapekey_copy3(BMesh *bm_src, BMesh *bm_dst, float 
UNUSED_tolerance, float UNUSED_radius_interp,
+                           int UNUSED_interp_pow, int UNUSED_no_pow, bool 
UNUSED_USE_NORMALS, ST_ShapekeyGroupMode replace_mode,
+                            int *act_shapekey_lay, float tmp_mat[4][4]);
 void BM_mesh_shapekey_copy_index(BMesh *bm_src, BMesh *bm_dst);
 
 #endif /* __BMESH_DATA_TRANSFER_H__ */

Modified: 
branches/soc-2013-meshdata_transfer/source/blender/editors/object/object_shapekey.c
===================================================================
--- 
branches/soc-2013-meshdata_transfer/source/blender/editors/object/object_shapekey.c
 2013-08-02 18:19:08 UTC (rev 58833)
+++ 
branches/soc-2013-meshdata_transfer/source/blender/editors/object/object_shapekey.c
 2013-08-02 19:54:32 UTC (rev 58834)
@@ -495,7 +495,7 @@
 
        //*******copy based on ray casting
        if (transfer_mode == ST_USE_NEAREST_FACE) {
-               if (!BM_mesh_shapekey_copy2(bm_src, bm_dst, tolerance, 
radius_interp, interp_pow, no_pow, interp_normals,
+               if (!BM_mesh_shapekey_copy3(bm_src, bm_dst, tolerance, 
radius_interp, interp_pow, no_pow, interp_normals,
                                                                        
replace_mode, act_shapekey_lay, tmp_mat)) {
                        return false;
                }

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

Reply via email to