[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [46930] branches/meshdata_transfer/source/ blender/editors/object/object_vgroup.c: Changed structure of the entire feature/code.

Ove Murberg Henriksen sorayasilvermoon at hotmail.com
Wed May 23 12:21:58 CEST 2012


Revision: 46930
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=46930
Author:   cyborgmuppet
Date:     2012-05-23 10:21:57 +0000 (Wed, 23 May 2012)
Log Message:
-----------
Changed structure of the entire feature/code.
It should now work in 24 different ways depending on options.
Its not tested in depth yet... 

Modified Paths:
--------------
    branches/meshdata_transfer/source/blender/editors/object/object_vgroup.c

Modified: branches/meshdata_transfer/source/blender/editors/object/object_vgroup.c
===================================================================
--- branches/meshdata_transfer/source/blender/editors/object/object_vgroup.c	2012-05-23 09:55:48 UTC (rev 46929)
+++ branches/meshdata_transfer/source/blender/editors/object/object_vgroup.c	2012-05-23 10:21:57 UTC (rev 46930)
@@ -376,57 +376,9 @@
 	return 1;
 }
 
-/*ideasman42 2012/05/17 09:04:35
-the single vgroup to copy could be an argument -
-allows to be more flexible later even if for now, the arg is "ob_src->actdef-1" for all callers.
-*/
-/*Copy a single vertex group from source to destination with weights by identical meshes*/
-int ED_vgroup_copy_single(Object *ob_dst, const Object *ob_src)
-{
-	MDeformVert **dv_array_src;
-	MDeformVert **dv_array_dst;
-	MDeformWeight *dw_dst, *dw_src;
-	int dv_tot_src, dv_tot_dst;
-	int i, index_src, index_dst;
-	bDeformGroup *dg_src, *dg_dst;
-
-	/*get source deform group*/
-	dg_src = BLI_findlink(&ob_src->defbase, (ob_src->actdef-1));
-
-	/*create new and overwrite vertex group on destination without data*/
-	ED_vgroup_delete(ob_dst, defgroup_find_name(ob_dst, dg_src->name));
-	ED_vgroup_add_name(ob_dst, dg_src->name);
-
-	/*get destination deformgroup*/
-	dg_dst = defgroup_find_name(ob_dst, dg_src->name);
-
-	/*get vertex group arrays*/
-	ED_vgroup_give_parray(ob_src->data, &dv_array_src, &dv_tot_src, FALSE);
-	ED_vgroup_give_parray(ob_dst->data, &dv_array_dst, &dv_tot_dst, FALSE);
-
-	/*get indexes of vertex groups*/
-	index_src = BLI_findindex(&ob_src->defbase, dg_src);
-	index_dst = BLI_findindex(&ob_dst->defbase, dg_dst);
-
-	/*check if indices are matching, delete and return if not*/
-	if (ob_dst == ob_src || dv_tot_dst == 0 || (dv_tot_dst != dv_tot_src) || dv_array_src == NULL || dv_array_dst == NULL) {
-		ED_vgroup_delete(ob_dst, defgroup_find_name(ob_dst, dg_dst->name));
-		return 0;
-	}
-
-	/* loop through the vertices and copy weight*/
-	for(i = 0; i < dv_tot_dst; i++, dv_array_src++, dv_array_dst++) {
-		dw_src = defvert_verify_index(*dv_array_src, index_src);
-		dw_dst = defvert_verify_index(*dv_array_dst, index_dst);
-		dw_dst->weight = dw_src->weight;
-	}
-
-	return 1;
-}
-
 /********************** Start transfer weight functions *********************/
 
-int ED_vgroup_transfer_weight_by_index(Object *ob_dst, Object *ob_src, short mode, short option)
+int ED_vgroup_transfer_weight_by_index(Object *ob_dst, Object *ob_src, short dw_replace_options, bDeformGroup *dg_src)
 {
 	MDeformVert **dv_array_src;
 	MDeformVert **dv_array_dst;
@@ -435,17 +387,12 @@
 	Mesh *me_dst;
 	int dv_tot_src, dv_tot_dst;
 	int i, index_src, index_dst;
-	bDeformGroup *dg_src, *dg_dst;
+	bDeformGroup *dg_dst;
 
-	/*remove this:*/
-	option=option;
-	/*TODO: for option all, loop through all vertex groups*/
+	enum dw_options {REPLACE_ALL_WEIGHTS = 1, REPLACE_EMPTY_WEIGHTS = 2, REPLACE_SELECTED_WEIGHTS = 3} dw_options = dw_replace_options;
 
-	/*get source deform group*/
-	dg_src = BLI_findlink(&ob_src->defbase, (ob_src->actdef-1));
-
 	/*create new and overwrite vertex group on destination without data*/
-	if(!defgroup_find_name(ob_dst, dg_src->name) || mode == 1){
+	if (!defgroup_find_name(ob_dst, dg_src->name) || dw_options == 1){
 		ED_vgroup_delete(ob_dst, defgroup_find_name(ob_dst, dg_src->name));
 		ED_vgroup_add_name(ob_dst, dg_src->name);
 	}
@@ -468,26 +415,26 @@
 	index_dst = BLI_findindex(&ob_dst->defbase, dg_dst);
 
 	/*check if indices are matching, delete and return if not*/
-	if(ob_dst == ob_src || dv_tot_dst == 0 || (dv_tot_dst != dv_tot_src) || dv_array_src == NULL || dv_array_dst == NULL) {
+	if (ob_dst == ob_src || dv_tot_dst == 0 || (dv_tot_dst != dv_tot_src) || dv_array_src == NULL || dv_array_dst == NULL) {
 		ED_vgroup_delete(ob_dst, defgroup_find_name(ob_dst, dg_dst->name));
 		return 0;
 	}
 
 	/* loop through the vertices and copy weight*/
-	for(i = 0; i < dv_tot_dst; i++, dv_array_src++, dv_array_dst++, mv_dst++){
+	for (i = 0; i < dv_tot_dst; i++, dv_array_src++, dv_array_dst++, mv_dst++){
 		dw_src = defvert_verify_index(*dv_array_src, index_src);
 		dw_dst = defvert_verify_index(*dv_array_dst, index_dst);
-		if(mode == 1) dw_dst->weight = dw_src->weight;
-		else if(mode == 2) {if(!dw_dst->weight || dw_dst->weight == 0) dw_dst->weight = dw_src->weight;}
-		else if(mode == 3) {if(mv_dst->flag & SELECT) dw_dst->weight = dw_src->weight;}
+		if (dw_options == REPLACE_ALL_WEIGHTS) dw_dst->weight = dw_src->weight;
+		else if (dw_options == REPLACE_EMPTY_WEIGHTS) {if (!dw_dst->weight || dw_dst->weight == 0) dw_dst->weight = dw_src->weight;}
+		else if (dw_options == REPLACE_SELECTED_WEIGHTS) {if (mv_dst->flag & SELECT) dw_dst->weight = dw_src->weight;}
 		else return 0;
 	}
 	return 1;
 }
 
-int ED_vgroup_transfer_weight_by_nearest_vertex(Object *ob_dst, Object *ob_src, short mode, short option)
+int ED_vgroup_transfer_weight_by_nearest_vertex(Object *ob_dst, Object *ob_src, short dw_replace_options, bDeformGroup *dg_src)
 {
-	bDeformGroup *dg_src, *dg_dst;
+	bDeformGroup *dg_dst;
 	MDeformVert **dv_array_src, **dv_array_dst;
 	MDeformWeight *dw_dst, *dw_src;
 	MVert *mv_dst;
@@ -498,14 +445,10 @@
 	int dv_tot_src, dv_tot_dst, i, index_dst, index_src;
 	float tmp_co[3], tmp_mat[4][4];
 
-	/*remove this:*/
-	option=option;
+	enum dw_options {REPLACE_ALL_WEIGHTS = 1, REPLACE_EMPTY_WEIGHTS = 2, REPLACE_SELECTED_WEIGHTS = 3} dw_options = dw_replace_options;
 
-	/*get source deform group*/
-	dg_src = BLI_findlink(&ob_src->defbase, (ob_src->actdef-1));
-
 	/*create new and overwrite vertex group on destination without data*/
-	if(!defgroup_find_name(ob_dst, dg_src->name) || mode == 1){
+	if (!defgroup_find_name(ob_dst, dg_src->name) || dw_replace_options == 1){
 		ED_vgroup_delete(ob_dst, defgroup_find_name(ob_dst, dg_src->name));
 		ED_vgroup_add_name(ob_dst, dg_src->name);
 	}
@@ -532,34 +475,37 @@
 	mv_dst = me_dst->mvert;
 
 	/*prepare transformation matrix*/
-	/*this can be excluded to make a lazy feature that works better when object centers relative to mesh is the same*/
 	invert_m4_m4(ob_src->imat, ob_src->obmat);
 	mult_m4_m4m4(tmp_mat, ob_src->imat, ob_dst->obmat);
 
 	/* loop through the vertices and copy weight*/
-	for(i = 0; i < me_dst->totvert; i++, mv_dst++, dv_array_dst++){
+	for (i = 0; i < me_dst->totvert; i++, mv_dst++, dv_array_dst++){
+
 		/*reset nearest*/
 		nearest.index = -1;
 		nearest.dist = FLT_MAX;
+
 		/*transform into target space*/
 		mul_v3_m4v3(tmp_co, tmp_mat, mv_dst->co);
+
 		/*node tree accelerated search for closest vetex*/
 		BLI_bvhtree_find_nearest(tree_mesh_src.tree, tmp_co, &nearest, tree_mesh_src.nearest_callback, &tree_mesh_src);
 		dw_src = defvert_verify_index(dv_array_src[nearest.index], index_src);
 		dw_dst = defvert_verify_index(*dv_array_dst, index_dst);
-		if(mode == 1) dw_dst->weight = dw_src->weight;
-		else if(mode == 2) {if(!dw_dst->weight || dw_dst->weight == 0) dw_dst->weight = dw_src->weight;}
-		else if(mode == 3) {if(mv_dst->flag & SELECT) dw_dst->weight = dw_src->weight;}
+		if (dw_options == REPLACE_ALL_WEIGHTS) dw_dst->weight = dw_src->weight;
+		else if (dw_options == REPLACE_EMPTY_WEIGHTS) {if (!dw_dst->weight || dw_dst->weight == 0) dw_dst->weight = dw_src->weight;}
+		else if(dw_options ==  REPLACE_SELECTED_WEIGHTS) {if (mv_dst->flag & SELECT) dw_dst->weight = dw_src->weight;}
 		else return 0;
 	}
+
 	/*free memory and return*/
 	free_bvhtree_from_mesh(&tree_mesh_src);
 	return 1;
 }
 
-int ED_vgroup_transfer_weight_by_nearest_vertex_in_face(Object *ob_dst, Object *ob_src, short mode, short option)
+int ED_vgroup_transfer_weight_by_nearest_face(Object *ob_dst, Object *ob_src, short dw_replace_options, bDeformGroup *dg_src)
 {
-	bDeformGroup *dg_src, *dg_dst;
+	bDeformGroup *dg_dst;
 	Mesh *me_dst;
 	DerivedMesh *dmesh_src;
 	BVHTreeFromMesh tree_mesh_faces_src = {NULL};
@@ -567,18 +513,14 @@
 	MVert *mv_dst, *mv_src;
 	MFace *mface_src;
 	BVHTreeNearest nearest;
-	MDeformWeight *dw_dst, *dw_src;
-	int dv_tot_src, dv_tot_dst, i, index_dst, index_src, index_nearest_vertex;
-	float dist_v1, dist_v2, dist_v3, dist_v4, tmp_co[3], tmp_mat[4][4];
+	MDeformWeight *dw_dst;
+	int dv_tot_src, dv_tot_dst, i, index_dst, index_src;
+	float weight, tmp_weight[4], tmp_co[3], normal[3], tmp_mat[4][4];
 
-	/*remove this:*/
-	option=option;
+	enum dw_options {REPLACE_ALL_WEIGHTS = 1, REPLACE_EMPTY_WEIGHTS = 2, REPLACE_SELECTED_WEIGHTS = 3} dw_options = dw_replace_options;
 
-	/*get source deform group*/
-	dg_src = BLI_findlink(&ob_src->defbase, (ob_src->actdef-1));
-
 	/*create new and overwrite vertex group on destination without data*/
-	if(!defgroup_find_name(ob_dst, dg_src->name) || mode == 1){
+	if (!defgroup_find_name(ob_dst, dg_src->name) || dw_options == 1){
 		ED_vgroup_delete(ob_dst, defgroup_find_name(ob_dst, dg_src->name));
 		ED_vgroup_add_name(ob_dst, dg_src->name);
 	}
@@ -613,48 +555,51 @@
 	invert_m4_m4(ob_src->imat, ob_src->obmat);
 	mult_m4_m4m4(tmp_mat, ob_src->imat, ob_dst->obmat);
 
-	/*
-ideasman42 2012/05/17 09:04:35
-also mode == 1 isnt so readable, better define an enum.
-*/
-
 	/* loop through the vertices and copy weight from nearest weight*/
-	for(i = 0; i < me_dst->totvert; i++, mv_dst++, dv_array_dst++){
+	for (i = 0; i < me_dst->totvert; i++, mv_dst++, dv_array_dst++){
+
 		/*reset nearest*/
 		nearest.index = -1;
 		nearest.dist = FLT_MAX;
+
 		/*transform into target space*/
 		mul_v3_m4v3(tmp_co, tmp_mat, mv_dst->co);
+		normal_tri_v3(normal, mv_src[mface_src[nearest.index].v1].co, mv_src[mface_src[nearest.index].v2].co, mv_src[mface_src[nearest.index].v3].co);
+
 		/*node tree accelerated search for closest face*/
 		BLI_bvhtree_find_nearest(tree_mesh_faces_src.tree, tmp_co, &nearest, tree_mesh_faces_src.nearest_callback, &tree_mesh_faces_src);
-		/*get distances*/
-		dist_v1 = len_squared_v3v3(tmp_co, mv_src[mface_src[nearest.index].v1].co);
-		dist_v2 = len_squared_v3v3(tmp_co, mv_src[mface_src[nearest.index].v2].co);
-		dist_v3 = len_squared_v3v3(tmp_co, mv_src[mface_src[nearest.index].v3].co);
-		/*get closest vertex*/
-		if(dist_v1 < dist_v2 && dist_v1 < dist_v3) index_nearest_vertex = mface_src[nearest.index].v1;
-		else if(dist_v2 < dist_v3) index_nearest_vertex = mface_src[nearest.index].v2;
-		else index_nearest_vertex = mface_src[nearest.index].v3;
-		if(mface_src[nearest.index].v4){
-			dist_v4 = len_squared_v3v3(tmp_co, mv_src[mface_src[nearest.index].v4].co);

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list