Revision: 58942
          
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=58942
Author:   walid
Date:     2013-08-05 19:06:37 +0000 (Mon, 05 Aug 2013)
Log Message:
-----------
Vertex Groups transfer through projection: using the MVertWeight to access the 
vertex weights -as they aren't directly accessible through the CD_MDefomrVert-

Modified Paths:
--------------
    
branches/soc-2013-meshdata_transfer/source/blender/bmesh/tools/bmesh_data_transfer.c
    
branches/soc-2013-meshdata_transfer/source/blender/editors/object/object_vgroup.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-05 18:58:19 UTC (rev 58941)
+++ 
branches/soc-2013-meshdata_transfer/source/blender/bmesh/tools/bmesh_data_transfer.c
        2013-08-05 19:06:37 UTC (rev 58942)
@@ -19,6 +19,7 @@
 
 #include "DNA_object_types.h"                  //using the bDeformGroup
 #include "BKE_bvhutils.h"                              //using the bvhutils.h
+#include "BKE_deform.h"
 
 //should be replaced by the min_float and its inverse
 #ifndef MY_MIN_FLOAT
@@ -2509,7 +2510,7 @@
 }
 
 
-bool BM_mesh_vertex_group_copy2(BMesh *bm_src, BMesh* bm_dst, const struct 
ReplaceLayerInfo replace_info, float tmp_mat[4][4])
+bool BM_mesh_vertex_group_copy2(BMesh *bm_src, BMesh* bm_dst, const struct 
ReplaceLayerInfo replace_info,float tmp_mat[4][4])
 {
        //-----algorithm definitions start
        struct BMBVHTree *bmtree_src = NULL;
@@ -2533,7 +2534,7 @@
        int v_src_max_count, v_dst_max_count;
        //====algorithm definitions end
 
-       int CD_src, CD_dst;
+       int src_grp_ind, dst_grp_ind;
 
        //used for iterating the destination's verts
        BMVert *v;
@@ -2548,6 +2549,12 @@
        int src_lay_start, src_lay_end;
        int dst_lay_start;
 
+       MDeformVert *dv_dst, *dv_src;
+       MDeformWeight *dw_dst, *dw_src;
+
+       const int cd_dvert_dst_offset = CustomData_get_offset(&bm_dst->vdata, 
CD_MDEFORMVERT);
+       const int cd_dvert_src_offset = CustomData_get_offset(&bm_src->vdata, 
CD_MDEFORMVERT);
+
        //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
@@ -2579,9 +2586,8 @@
        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->vdata, 
CD_MDEFORMVERT, src_lay_iter); //get the offset of the
-               CD_dst = CustomData_get_n_offset(&bm_dst->vdata, 
CD_MDEFORMVERT, dst_lay_iter); //lay_iter(th)CD_SHAPEKEY layer
+               src_grp_ind = src_lay_iter;
+               dst_grp_ind = dst_lay_start + dst_lay_iter;
 
                //the way we do it is by looping over each face!!
                BM_ITER_MESH (f_dst, &iter, bm_dst, BM_FACES_OF_MESH) {
@@ -2647,9 +2653,28 @@
 
                                // Interpolating according to the spatially 
found weights
                                // Get weights from face.
+
+                               //getting the weight holder (MDeformWeight)
+                               dv_dst = BM_ELEM_CD_GET_VOID_P(v, 
cd_dvert_dst_offset);
+                               dw_dst = defvert_verify_index(dv_dst, 
dst_grp_ind);     //use this to have a weight for the group assuming
+                                                                               
                                                        //the vert may haven't 
been assigned in advance
+
+                               ///use those to support/unsupport copying to 
vertices with NULL value (unassigned vertices!)
+                               ///note we must take into consideration that 
some layers are new and by default have got no vertices
+                               ///assigned
+/*
+                               dw_dst = defvert_verify_index(dv_dst, 
dst_grp_ind);
+                               if (dw_dst != NULL) {
+                                       //do nothing for now :)
+
+                               }
+*/
+
                                weight_accu = 0;
                                BM_ITER_ELEM_INDEX (v2, &fiter2, f_src, 
BM_VERTS_OF_FACE, a) {
-                                       weight_accu = BM_ELEM_CD_GET_FLOAT(v2, 
CD_src) * tmp_weight[a];
+                                       dv_src = BM_ELEM_CD_GET_VOID_P(v2, 
cd_dvert_src_offset);
+                                       dw_src = defvert_verify_index(dv_src, 
src_grp_ind);
+                                       weight_accu += dw_src->weight * 
tmp_weight[a];
                                }
 
                                
weights_grp[v->head.index].fl[weights_grp[v->head.index].count] = weight_accu;
@@ -2668,7 +2693,12 @@
                                weight_accu += 
(weights_grp[v->head.index].fl[i]) / (float)(weights_grp[v->head.index].count);
                        }
 
-                       ((float*)BM_ELEM_CD_GET_VOID_P(v, CD_dst))[0] = 
weight_accu;
+                       dv_dst = BM_ELEM_CD_GET_VOID_P(v, cd_dvert_dst_offset);
+                       dw_dst = defvert_verify_index(dv_dst, dst_grp_ind);
+
+                       if (dw_dst != NULL) {   //this check isnt useful till 
we support/unsupport copying vertices to unassigned v
+                               dw_dst->weight = weight_accu;
+                       }
                        weights_grp[v->head.index].count = 0;
                }
 

Modified: 
branches/soc-2013-meshdata_transfer/source/blender/editors/object/object_vgroup.c
===================================================================
--- 
branches/soc-2013-meshdata_transfer/source/blender/editors/object/object_vgroup.c
   2013-08-05 18:58:19 UTC (rev 58941)
+++ 
branches/soc-2013-meshdata_transfer/source/blender/editors/object/object_vgroup.c
   2013-08-05 19:06:37 UTC (rev 58942)
@@ -265,6 +265,9 @@
        me_dst = ob_dst->data;
        me_src = ob_src->data;
 
+       CustomData_add_layer(&me_dst->vdata, CD_MDEFORMVERT, 1, NULL, 
me_dst->totvert);
+       CustomData_add_layer(&me_src->vdata, CD_MDEFORMVERT, 1, NULL, 
me_src->totvert);
+
        num_src_lay = BLI_countlist(&ob_src->defbase);
        num_dst_lay = BLI_countlist(&ob_dst->defbase);
 

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

Reply via email to