[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [59402] branches/ soc-2013-meshdata_transfer/source/blender: supporting partial layer transfer, working when using replace enough groups and only for the multi layers transfer not single ones -as their support may be dropped soon-

Walid Shouman eng.walidshouman at gmail.com
Fri Aug 23 10:32:57 CEST 2013


Revision: 59402
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=59402
Author:   walid
Date:     2013-08-23 08:32:57 +0000 (Fri, 23 Aug 2013)
Log Message:
-----------
supporting partial layer transfer, working when using replace enough groups and only for the multi layers transfer not single ones -as their support may be dropped soon-

Modified Paths:
--------------
    branches/soc-2013-meshdata_transfer/source/blender/blenkernel/intern/editmesh_bvh.c
    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/object/object_shapekey.c
    branches/soc-2013-meshdata_transfer/source/blender/editors/object/object_vgroup.c

Modified: branches/soc-2013-meshdata_transfer/source/blender/blenkernel/intern/editmesh_bvh.c
===================================================================
--- branches/soc-2013-meshdata_transfer/source/blender/blenkernel/intern/editmesh_bvh.c	2013-08-23 08:27:01 UTC (rev 59401)
+++ branches/soc-2013-meshdata_transfer/source/blender/blenkernel/intern/editmesh_bvh.c	2013-08-23 08:32:57 UTC (rev 59402)
@@ -461,7 +461,7 @@
 	float maxdist_sq = maxdist * maxdist;
 
 	//avoid overlap
-	if ((maxdist > 0) && (maxdist_sq < maxdist))
+	if ((maxdist > 1) && (maxdist_sq < maxdist))
 		maxdist_sq = FLT_MAX;
 
 	else if ((maxdist < 0) && (maxdist_sq < (-1 * maxdist)))

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-23 08:27:01 UTC (rev 59401)
+++ branches/soc-2013-meshdata_transfer/source/blender/bmesh/tools/bmesh_data_transfer.c	2013-08-23 08:32:57 UTC (rev 59402)
@@ -2085,8 +2085,9 @@
 } loop_weight;
 
 typedef struct weighed_loop_pool {
-	loop_weight *l_w;
-	int count;
+	loop_weight *l_w;	//the loops and their weights that are associated to \l
+	int count;			//number of loop_weight* for the loop
+	BMLoop *l;			//loop to inherit
 } weighed_loop_pool;
 
 typedef struct vert_weight {
@@ -2139,35 +2140,48 @@
 				BM_ITER_MESH (f_dst, &fiter, bm_dst, BM_FACES_OF_MESH) {
 
 					BM_ITER_ELEM (l, &liter, f_dst, BM_LOOPS_OF_FACE) {
-						MLoopCol *lcol = BM_ELEM_CD_GET_VOID_P(l, CD_dst);
-						MLoopCol lcol_out;
 
-						// Interpolating according to the spatially found weights
-						lcol_out.a = 0;
-						lcol_out.b = 0;
-						lcol_out.g = 0;
-						lcol_out.r = 0;
+						if (l_weights[b].count != 0) {
+							//enter only if the loop got a weight successfully ... ie, the src_f was fnd in search_tol
+							MLoopCol *lcol = BM_ELEM_CD_GET_VOID_P(l, CD_dst);
+							MLoopCol lcol_out;
 
-						for (a = 0; a < l_weights[b].count; a++) {
-							MLoopCol *lcol2 = BM_ELEM_CD_GET_VOID_P(l_weights[b].l_w->l, CD_src);
-							float weight = l_weights[b].l_w[a].weight;
+							if (l_weights[b].l != l)	//inconsistant loop than the one we're gonna copy to!
+								return false;
 
-							//there's no madd_v4_v4fl for char!
-							lcol_out.a += (lcol2->a * weight);
-							lcol_out.b += (lcol2->b * weight);
-							lcol_out.g += (lcol2->g * weight);
-							lcol_out.r += (lcol2->r * weight);
+							// Interpolating according to the spatially found weights
+							lcol_out.a = 0;
+							lcol_out.b = 0;
+							lcol_out.g = 0;
+							lcol_out.r = 0;
+
+							for (a = 0; a < l_weights[b].count; a++) {
+								MLoopCol *lcol2 = BM_ELEM_CD_GET_VOID_P(l_weights[b].l_w->l, CD_src);
+								float weight = l_weights[b].l_w[a].weight;
+
+								//there's no madd_v4_v4fl for char!
+								lcol_out.a += (lcol2->a * weight);
+								lcol_out.b += (lcol2->b * weight);
+								lcol_out.g += (lcol2->g * weight);
+								lcol_out.r += (lcol2->r * weight);
+							}
+
+							//shall we verify the indices!?
+							//there's no copy_v4_v4 for char!
+							lcol->a = lcol_out.a;
+							lcol->b = lcol_out.b;
+							lcol->g = lcol_out.g;
+							lcol->r = lcol_out.r;
+
+							//end of interpolation
+
 						}
 
-						//shall we verify the indices!?
-						//there's no copy_v4_v4 for char!
-						lcol->a = lcol_out.a;
-						lcol->b = lcol_out.b;
-						lcol->g = lcol_out.g;
-						lcol->r = lcol_out.r;
+						else {
+							//in case the loop didn't have src_loops to inherit from
+							//we don't do anything for now, just skip it
+						}
 
-						//end of interpolation
-
 						b++;
 					}
 				}
@@ -2185,6 +2199,8 @@
 			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);
 
+			bool *changed_v_table = MEM_callocN(sizeof(*changed_v_table) * bm_dst->totvert, "changed_v_table bmesh_data_transfer.c");
+\
 			//weight_grp init
 			weights_grp = MEM_mallocN(sizeof(*weights_grp) * bm_dst->totvert, "weights_grp bmesh_data_transfer.c");
 			BM_ITER_MESH (v, &iter, bm_dst, BM_VERTS_OF_MESH) {
@@ -2205,22 +2221,35 @@
 				BM_ITER_MESH (f_dst, &fiter, bm_dst, BM_FACES_OF_MESH) {
 
 					BM_ITER_ELEM (l, &liter, f_dst, BM_LOOPS_OF_FACE) {
-						float weight_accu;
-						//getting the weight holder (MDeformWeight)
-						dv_dst = BM_ELEM_CD_GET_VOID_P(l->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
-						weight_accu = 0;
-						for (a = 0; a < l_weights[b].count; a++) {
-							float weight = l_weights[b].l_w[a].weight;
 
-							dv_src = BM_ELEM_CD_GET_VOID_P(l_weights[b].l_w[a].l->v, cd_dvert_src_offset);
-							dw_src = defvert_verify_index(dv_src, src_grp_ind);
-							weight_accu += dw_src->weight * weight;
+						if (l_weights[b].count != 0) {
+							float weight_accu;
+
+							if (l_weights[b].l != l)	//inconsistant loop than the one we're gonna copy to!
+								return false;
+
+							//getting the weight holder (MDeformWeight)
+							dv_dst = BM_ELEM_CD_GET_VOID_P(l->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
+							weight_accu = 0;
+							for (a = 0; a < l_weights[b].count; a++) {
+								float weight = l_weights[b].l_w[a].weight;
+
+								dv_src = BM_ELEM_CD_GET_VOID_P(l_weights[b].l_w[a].l->v, cd_dvert_src_offset);
+								dw_src = defvert_verify_index(dv_src, src_grp_ind);
+								weight_accu += dw_src->weight * weight;
+							}
+
+							weights_grp[l->v->head.index].fl[weights_grp[l->v->head.index].count] = weight_accu;
+							(weights_grp[l->v->head.index].count)++;
+
+							changed_v_table[l->v->head.index] = true;
 						}
 
-						weights_grp[l->v->head.index].fl[weights_grp[l->v->head.index].count] = weight_accu;
-						(weights_grp[l->v->head.index].count)++;
+						else {
+							//loop doesn't have any other loops to inherit from
+						}
 
 						b++;
 					}
@@ -2228,20 +2257,24 @@
 
 				//normalising weights loop
 				BM_ITER_MESH (v, &iter, bm_dst, BM_VERTS_OF_MESH) {
-					int i;
-					weight_accu = 0;
 
-					for (i = 0; i < weights_grp[v->head.index].count; i++) {
-						weight_accu += (weights_grp[v->head.index].fl[i]) / (float)(weights_grp[v->head.index].count);
-					}
+					//normalize only for the vertices that inherited at least from a single loop
+					if (changed_v_table[v->head.index] == true) {
+						int i;
+						weight_accu = 0;
 
-					dv_dst = BM_ELEM_CD_GET_VOID_P(v, cd_dvert_dst_offset);
-					dw_dst = defvert_verify_index(dv_dst, dst_grp_ind);
+						for (i = 0; i < weights_grp[v->head.index].count; i++) {
+							weight_accu += (weights_grp[v->head.index].fl[i]) / (float)(weights_grp[v->head.index].count);
+						}
 
-					if (dw_dst != NULL) {	//this check isnt useful till we support/unsupport copying vertices to unassigned v
-						dw_dst->weight = 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;
 					}
-					weights_grp[v->head.index].count = 0;
 				}
 			}
 
@@ -2265,6 +2298,8 @@
 
 			coord_pool *offsets_grp;
 
+			bool *changed_v_table = MEM_callocN(sizeof(*changed_v_table) * bm_dst->totvert, "changed_v_table bmesh_data_transfer.c");
+
 			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);
 
@@ -2292,19 +2327,31 @@
 				BM_ITER_MESH (f_dst, &fiter, bm_dst, BM_FACES_OF_MESH) {
 					BM_ITER_ELEM (v, &iter, f_dst, BM_VERTS_OF_FACE) {
 
-						// Interpolating according to the spatially found weights
-						// Get weights from face.
 						zero_v3(v_dst_offset);
-						for (a = 0; a < l_weights[b].count; a++) {
-							float weight = l_weights[b].l_w[a].weight;
+						if (l_weights[b].count != 0) {
 
-							sub_v3_v3v3(v_src_offset, BM_ELEM_CD_GET_VOID_P(l_weights[b].l_w[a].l->v, CD_offset_src),
-							        BM_ELEM_CD_GET_VOID_P(l_weights[b].l_w[a].l->v, CD_basis_src));
-							madd_v3_v3fl(v_dst_offset, v_src_offset, weight);
+							if (l_weights[b].l->v != v)	//inconsistant loop->vert than the one we're gonna copy to!
+								return false;
+
+							// Interpolating according to the spatially found weights
+							// Get weights from face.
+							for (a = 0; a < l_weights[b].count; a++) {
+								float weight = l_weights[b].l_w[a].weight;
+
+								sub_v3_v3v3(v_src_offset, BM_ELEM_CD_GET_VOID_P(l_weights[b].l_w[a].l->v, CD_offset_src),
+										BM_ELEM_CD_GET_VOID_P(l_weights[b].l_w[a].l->v, CD_basis_src));
+								madd_v3_v3fl(v_dst_offset, v_src_offset, weight);
+							}
+
+							copy_v3_v3(offsets_grp[v->head.index].coord[offsets_grp[v->head.index].count], v_dst_offset);
+							(offsets_grp[v->head.index].count)++;
+
+							changed_v_table[v->head.index] = true;
 						}
 
-						copy_v3_v3(offsets_grp[v->head.index].coord[offsets_grp[v->head.index].count], v_dst_offset);
-						(offsets_grp[v->head.index].count)++;
+						else {
+							//loop doesn't have any other loops to inherit from
+						}
 
 						b++;
 					}
@@ -2313,13 +2360,17 @@
 				//Normalising loop
 				//Normalising coords for each vertex
 				BM_ITER_MESH (v, &iter, bm_dst, BM_VERTS_OF_MESH) {
-					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);
-					//reset for the upcoming layer
-					offsets_grp[v->head.index].count = 0;
+					//normalize only for the vertices that inherited at least from a single loop
+					if (changed_v_table[v->head.index] == true) {
+						zero_v3(v_dst_offset);
+						mid_poly_v3(v_dst_offset, offsets_grp[v->head.index].coord, offsets_grp[v->head.index].count);
+

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list