diff options
author | Ove Murberg Henriksen <sorayasilvermoon@hotmail.com> | 2012-05-17 16:15:39 +0400 |
---|---|---|
committer | Ove Murberg Henriksen <sorayasilvermoon@hotmail.com> | 2012-05-17 16:15:39 +0400 |
commit | 044fd86a15b358a5e250896b88d493c17c3d5e21 (patch) | |
tree | 0a47e85c382bd15f6951744719ff53da8e008c20 /source/blender/editors/object | |
parent | f4f5254100c16f7e9906dffcdc9695295e27c7e2 (diff) |
Some changes to structure as a response to review.
(I still havent adressed all issues.)
Diffstat (limited to 'source/blender/editors/object')
-rw-r--r-- | source/blender/editors/object/object_vgroup.c | 585 |
1 files changed, 154 insertions, 431 deletions
diff --git a/source/blender/editors/object/object_vgroup.c b/source/blender/editors/object/object_vgroup.c index fd98f7aaa3c..d1622e507d0 100644 --- a/source/blender/editors/object/object_vgroup.c +++ b/source/blender/editors/object/object_vgroup.c @@ -20,7 +20,7 @@ * * The Original Code is: all of this file. * - * Contributor(s): none yet. + * Contributor(s): Ove M Henriksen. * * ***** END GPL LICENSE BLOCK ***** */ @@ -376,6 +376,10 @@ int ED_vgroup_copy_array(Object *ob, Object *ob_from) 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) { @@ -422,26 +426,7 @@ int ED_vgroup_copy_single(Object *ob_dst, const Object *ob_src) /********************** Start transfer weight functions *********************/ -int ED_vgroup_transfer_weight_by_index_all(Object *ob_dst, Object *ob_src, short mode) -{ - - if(mode == 1){ - return ED_vgroup_copy_array(ob_dst, ob_src); - } - - - else if(mode == 2){ - return 0; - } - - - else if(mode == 3){ - return 0; - } - else return 0; -} - -int ED_vgroup_transfer_weight_by_index_single(Object *ob_dst, Object *ob_src, short mode) +int ED_vgroup_transfer_weight_by_index(Object *ob_dst, Object *ob_src, short mode, short option) { MDeformVert **dv_array_src; MDeformVert **dv_array_dst; @@ -450,6 +435,9 @@ int ED_vgroup_transfer_weight_by_index_single(Object *ob_dst, Object *ob_src, sh int i, index_src, index_dst; bDeformGroup *dg_src, *dg_dst; + /*remove this:*/ + option=option; + /*get source deform group*/ dg_src = BLI_findlink(&ob_src->defbase, (ob_src->actdef-1)); @@ -476,51 +464,19 @@ int ED_vgroup_transfer_weight_by_index_single(Object *ob_dst, Object *ob_src, sh return 0; } - /* mode 1 == replace all weights*/ - if(mode == 1){ - /* 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; - } - - /* mode 2 == replace null weights*/ - else if(mode == 2){ - /* 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); - /*check if destination weight is null or zero*/ - if(!dw_dst->weight || dw_dst->weight == 0) dw_dst->weight = dw_src->weight; - } - return 1; - } - - /* mode 3 == replace selected weights*/ - else if(mode == 3){ - /* 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); - /*check if source vertex is selected*/ - if((*dv_array_src)->flag == 1) dw_dst->weight = dw_src->weight; /*This does not work*/ - } - return 1; + /* 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); + 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((*dv_array_src)->flag == 1) dw_dst->weight = dw_src->weight;}/*This does not work*/ + else return 0; } - else return 0; -} - -int ED_vgroup_transfer_weight_by_nearest_vertex_all(Object *ob_dst, Object *ob_src, short mode) -{ - ob_dst = ob_dst; - ob_src = ob_src; - return mode; + return 1; } -int ED_vgroup_transfer_weight_by_nearest_vertex_single(Object *ob_dst, Object *ob_src, short mode) +int ED_vgroup_transfer_weight_by_nearest_vertex(Object *ob_dst, Object *ob_src, short mode, short option) { bDeformGroup *dg_src, *dg_dst; MDeformVert **dv_array_src, **dv_array_dst; @@ -533,6 +489,9 @@ int ED_vgroup_transfer_weight_by_nearest_vertex_single(Object *ob_dst, Object *o int dv_tot_src, dv_tot_dst, i, index_dst, index_src; float tmp_co[3], tmp_mat[4][4]; + /*remove this:*/ + option=option; + /*get source deform group*/ dg_src = BLI_findlink(&ob_src->defbase, (ob_src->actdef-1)); @@ -568,78 +527,28 @@ int ED_vgroup_transfer_weight_by_nearest_vertex_single(Object *ob_dst, Object *o invert_m4_m4(ob_src->imat, ob_src->obmat); mult_m4_m4m4(tmp_mat, ob_src->imat, ob_dst->obmat); - /* mode 1 == replace all weights*/ - if(mode == 1){ - /* loop through the vertices and copy weight*/ - 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); - dw_dst->weight = dw_src->weight; - } - /*free memory and return*/ - free_bvhtree_from_mesh(&tree_mesh_src); - return 1; - } - - /* mode 2 == replace null weights*/ - else if(mode == 2){ - /* loop through the vertices and copy weight weight*/ - 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); - /*check if destination weight is null or zero*/ - if(!dw_dst->weight || dw_dst->weight == 0) dw_dst->weight = dw_src->weight; - } - /*free memory and return*/ - free_bvhtree_from_mesh(&tree_mesh_src); - return 1; - } - - /* mode 3 == replace selected weights*/ - else if(mode == 3){ - /* loop through the vertices and copy weight*/ - 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); - /*dw_dst->weight= dw_src->weight;*//*TODO fix this*/ - } - - /*free memory and return*/ - free_bvhtree_from_mesh(&tree_mesh_src); - return 1; - } - else return 0; -} - -int ED_vgroup_transfer_weight_by_nearest_vertex_in_face_all(Object *ob_dst, Object *ob_src, short mode) -{ - ob_dst = ob_dst; - ob_src = ob_src; - return mode; -} - -int ED_vgroup_transfer_weight_by_nearest_vertex_in_face_single(Object *ob_dst, Object *ob_src, short mode) + /* loop through the vertices and copy weight*/ + 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) {dw_dst->weight= dw_src->weight;}/*TODO fix this*/ + 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) { bDeformGroup *dg_src, *dg_dst; Mesh *me_dst; @@ -653,6 +562,9 @@ int ED_vgroup_transfer_weight_by_nearest_vertex_in_face_single(Object *ob_dst, O int dv_tot_src, dv_tot_dst, i, index_dst, index_src; float dist_v1, dist_v2, dist_v3, dist_v4, tmp_co[3], tmp_mat[4][4]; + /*remove this:*/ + option=option; + /*get source deform group*/ dg_src = BLI_findlink(&ob_src->defbase, (ob_src->actdef-1)); @@ -692,140 +604,54 @@ int ED_vgroup_transfer_weight_by_nearest_vertex_in_face_single(Object *ob_dst, O invert_m4_m4(ob_src->imat, ob_src->obmat); mult_m4_m4m4(tmp_mat, ob_src->imat, ob_dst->obmat); - /* mode 1 == replace all weights*/ - if(mode == 1){ - /* loop through the vertices and copy weight from nearest weight*/ - 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 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 weight from triangle*/ - if(dist_v1 < dist_v2 && dist_v1 < dist_v3){ - dw_src = defvert_verify_index(dv_array_src[mface_src[nearest.index].v1], index_src); - } - else if(dist_v2 < dist_v3){ - dw_src = defvert_verify_index(dv_array_src[mface_src[nearest.index].v2], index_src); - } - else{ - dw_src = defvert_verify_index(dv_array_src[mface_src[nearest.index].v3], index_src); - } - /*check for and get weight from quad*/ - if(mface_src[nearest.index].v4){ - dist_v4 = len_squared_v3v3(tmp_co, mv_src[mface_src[nearest.index].v4].co); - if(dist_v4 < dist_v1 && dist_v4 < dist_v2 && dist_v4 < dist_v3){ - dw_src = defvert_verify_index(dv_array_src[mface_src[nearest.index].v4], index_src); - } - } - /*copy weight*/ - dw_dst = defvert_verify_index(*dv_array_dst, index_dst); - dw_dst->weight = dw_src->weight; - } - /*free memory and return*/ - free_bvhtree_from_mesh(&tree_mesh_faces_src); - return 1; - } - - /* mode 2 == replace null weights*/ - else if(mode == 2){ - /* loop through the vertices and copy weight from nearest weight*/ - 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 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 weight from triangle*/ - if(dist_v1 < dist_v2 && dist_v1 < dist_v3){ - dw_src= defvert_verify_index(dv_array_src[mface_src[nearest.index].v1], index_src); - } - else if(dist_v2 < dist_v3){ - dw_src = defvert_verify_index(dv_array_src[mface_src[nearest.index].v2], index_src); - } - else{ - dw_src = defvert_verify_index(dv_array_src[mface_src[nearest.index].v3], index_src); - } - /*check for and get weight from quad*/ - if(mface_src[nearest.index].v4){ - dist_v4 = len_squared_v3v3(tmp_co, mv_src[mface_src[nearest.index].v4].co); - if(dist_v4 < dist_v1 && dist_v4 < dist_v2 && dist_v4 < dist_v3){ - dw_src = defvert_verify_index(dv_array_src[mface_src[nearest.index].v4], index_src); - } - } - /*copy weight*/ - dw_dst = defvert_verify_index(*dv_array_dst, index_dst); - /*check if destination weight is null or zero*/ - if(!dw_dst->weight || dw_dst->weight == 0) dw_dst->weight = dw_src->weight; - } - /*free memory and return*/ - free_bvhtree_from_mesh(&tree_mesh_faces_src); - return 1; - } - - /* mode 3 == replace selected weights*/ - else if(mode == 3){ - /* loop through the vertices and copy weight from nearest weight*/ - 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 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 weight from triangle*/ - if(dist_v1 < dist_v2 && dist_v1 < dist_v3){ - dw_src = defvert_verify_index(dv_array_src[mface_src[nearest.index].v1], index_src); - } - else if(dist_v2 < dist_v3){ - dw_src = defvert_verify_index(dv_array_src[mface_src[nearest.index].v2], index_src); - } - else{ - dw_src = defvert_verify_index(dv_array_src[mface_src[nearest.index].v3], index_src); - } - /*check for and get weight from quad*/ - if(mface_src[nearest.index].v4){ - dist_v4 = len_squared_v3v3(tmp_co, mv_src[mface_src[nearest.index].v4].co); - if(dist_v4 < dist_v1 && dist_v4 < dist_v2 && dist_v4 < dist_v3){ - dw_src = defvert_verify_index(dv_array_src[mface_src[nearest.index].v4], index_src); - } - } - /*copy weight*/ - dw_dst = defvert_verify_index(*dv_array_dst, index_dst); - /*dw_dst->weight= dw_src->weight;*/ /*TODO: fix this!*/ - } - /*free memory and return*/ - free_bvhtree_from_mesh(&tree_mesh_faces_src); - return 1; + /* +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++){ + /*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 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 weight from triangle*/ + if(dist_v1 < dist_v2 && dist_v1 < dist_v3){ + dw_src = defvert_verify_index(dv_array_src[mface_src[nearest.index].v1], index_src); + } + else if(dist_v2 < dist_v3){ + dw_src = defvert_verify_index(dv_array_src[mface_src[nearest.index].v2], index_src); + } + else{ + dw_src = defvert_verify_index(dv_array_src[mface_src[nearest.index].v3], index_src); + } + /*check for and get weight from quad*/ + if(mface_src[nearest.index].v4){ + dist_v4 = len_squared_v3v3(tmp_co, mv_src[mface_src[nearest.index].v4].co); + if(dist_v4 < dist_v1 && dist_v4 < dist_v2 && dist_v4 < dist_v3){ + dw_src = defvert_verify_index(dv_array_src[mface_src[nearest.index].v4], index_src); + } + } + /*copy weight*/ + 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) {dw_dst->weight= dw_src->weight;}/*TODO: fix this!*/ + else return 0; } - else return 0; -} - -int ED_vgroup_transfer_weight_by_nearest_face_all(Object *ob_dst, Object *ob_src, short mode) -{ - ob_dst = ob_dst; - ob_src = ob_src; - return mode; + /*free memory and return*/ + free_bvhtree_from_mesh(&tree_mesh_faces_src); + return 1; } -int ED_vgroup_transfer_weight_by_nearest_face_single(Object *ob_dst, Object *ob_src, short mode) +int ED_vgroup_transfer_weight_by_nearest_face(Object *ob_dst, Object *ob_src, short mode, short option) { bDeformGroup *dg_src, *dg_dst; Mesh *me_dst; @@ -839,6 +665,9 @@ int ED_vgroup_transfer_weight_by_nearest_face_single(Object *ob_dst, Object *ob_ 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; + /*get source deform group*/ dg_src = BLI_findlink(&ob_src->defbase, (ob_src->actdef-1)); @@ -878,106 +707,38 @@ int ED_vgroup_transfer_weight_by_nearest_face_single(Object *ob_dst, Object *ob_ invert_m4_m4(ob_src->imat, ob_src->obmat); mult_m4_m4m4(tmp_mat, ob_src->imat, ob_dst->obmat); - /* mode 1 == replace all weights*/ - if(mode == 1){ - /* loop through the vertices and copy weight from nearest weight*/ - 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); - /*project onto face*/ - project_v3_plane(tmp_co, normal, mv_src[mface_src[nearest.index].v1].co); - /*interpolate weights*/ - interp_weights_face_v3(tmp_weight, mv_src[mface_src[nearest.index].v1].co, - mv_src[mface_src[nearest.index].v2].co, - mv_src[mface_src[nearest.index].v3].co, - mv_src[mface_src[nearest.index].v4].co, tmp_co); - /*get weights*/ - weight = tmp_weight[0] * defvert_verify_index(dv_array_src[mface_src[nearest.index].v1], index_src)->weight; - weight += tmp_weight[1] * defvert_verify_index(dv_array_src[mface_src[nearest.index].v2], index_src)->weight; - weight += tmp_weight[2] * defvert_verify_index(dv_array_src[mface_src[nearest.index].v3], index_src)->weight; - weight += tmp_weight[3] * defvert_verify_index(dv_array_src[mface_src[nearest.index].v4], index_src)->weight; - /*copy weight*/ - dw_dst = defvert_verify_index(*dv_array_dst, index_dst); - dw_dst->weight = weight; - } - /*free memory and return*/ - free_bvhtree_from_mesh(&tree_mesh_faces_src); - return 1; - } - - /* mode 2 == replace null weights*/ - else if(mode == 2){ - /* loop through the vertices and copy weight from nearest weight*/ - 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); - /*project onto face*/ - project_v3_plane(tmp_co, normal, mv_src[mface_src[nearest.index].v1].co); - /*interpolate weights*/ - interp_weights_face_v3(tmp_weight, mv_src[mface_src[nearest.index].v1].co, - mv_src[mface_src[nearest.index].v2].co, - mv_src[mface_src[nearest.index].v3].co, - mv_src[mface_src[nearest.index].v4].co, tmp_co); - /*get weights*/ - weight = tmp_weight[0] * defvert_verify_index(dv_array_src[mface_src[nearest.index].v1], index_src)->weight; - weight += tmp_weight[1] * defvert_verify_index(dv_array_src[mface_src[nearest.index].v2], index_src)->weight; - weight += tmp_weight[2] * defvert_verify_index(dv_array_src[mface_src[nearest.index].v3], index_src)->weight; - weight += tmp_weight[3] * defvert_verify_index(dv_array_src[mface_src[nearest.index].v4], index_src)->weight; - /*copy weight*/ - dw_dst = defvert_verify_index(*dv_array_dst, index_dst); - /*check if destination weight is null or zero and copy weight*/ - if(!dw_dst->weight || dw_dst->weight == 0) dw_dst->weight = weight; - } - /*free memory and return*/ - free_bvhtree_from_mesh(&tree_mesh_faces_src); - return 1; - } - - /* mode 3 == replace selected weights*/ - else if(mode == 3){ - /* loop through the vertices and copy weight from nearest weight*/ - 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); - /*project onto face*/ - project_v3_plane(tmp_co, normal, mv_src[mface_src[nearest.index].v1].co); - /*interpolate weights*/ - interp_weights_face_v3(tmp_weight, mv_src[mface_src[nearest.index].v1].co, - mv_src[mface_src[nearest.index].v2].co, - mv_src[mface_src[nearest.index].v3].co, - mv_src[mface_src[nearest.index].v4].co, tmp_co); - /*get weights*/ - weight = tmp_weight[0] * defvert_verify_index(dv_array_src[mface_src[nearest.index].v1], index_src)->weight; - weight += tmp_weight[1] * defvert_verify_index(dv_array_src[mface_src[nearest.index].v2], index_src)->weight; - weight += tmp_weight[2] * defvert_verify_index(dv_array_src[mface_src[nearest.index].v3], index_src)->weight; - weight += tmp_weight[3] * defvert_verify_index(dv_array_src[mface_src[nearest.index].v4], index_src)->weight; - /*copy weight*/ - dw_dst = defvert_verify_index(*dv_array_dst, index_dst); - /*dw_dst->weight= weight;*//*TODO: fix this!*/ - } - /*free memory and return*/ - free_bvhtree_from_mesh(&tree_mesh_faces_src); - return 1; - } - else return 0; + /* loop through the vertices and copy weight from nearest weight*/ + 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); + /*project onto face*/ + project_v3_plane(tmp_co, normal, mv_src[mface_src[nearest.index].v1].co); + /*interpolate weights*/ + interp_weights_face_v3(tmp_weight, mv_src[mface_src[nearest.index].v1].co, + mv_src[mface_src[nearest.index].v2].co, + mv_src[mface_src[nearest.index].v3].co, + mv_src[mface_src[nearest.index].v4].co, tmp_co); + /*get weights*/ + weight = tmp_weight[0] * defvert_verify_index(dv_array_src[mface_src[nearest.index].v1], index_src)->weight; + weight += tmp_weight[1] * defvert_verify_index(dv_array_src[mface_src[nearest.index].v2], index_src)->weight; + weight += tmp_weight[2] * defvert_verify_index(dv_array_src[mface_src[nearest.index].v3], index_src)->weight; + weight += tmp_weight[3] * defvert_verify_index(dv_array_src[mface_src[nearest.index].v4], index_src)->weight; + /*copy weight*/ + dw_dst = defvert_verify_index(*dv_array_dst, index_dst); + if(mode == 1) dw_dst->weight = weight; + else if(mode == 2) {if(!dw_dst->weight || dw_dst->weight == 0) dw_dst->weight = weight;} + else if(mode == 3) {dw_dst->weight= weight;}/*TODO: fix this!*/ + else return 0; + } + /*free memory and return*/ + free_bvhtree_from_mesh(&tree_mesh_faces_src); + return 1; } /********************** End transfer weight functions *********************/ @@ -3396,6 +3157,16 @@ static int vertex_group_copy_to_selected_single_exec(bContext *C, wmOperator *op return OPERATOR_FINISHED; } +/* +ideasman42 2012/05/17 09:04:35 +suggest to have one operator with single vgroup as an option, if this is a hassle, it can be done later. + +example properties?: + * properties * + prop = RNA_def_enum(ot->srna, "group", vgroup_items, 0, "Group", "Vertex group to set as active"); + RNA_def_enum_funcs(prop, vgroup_itemf); + ot->prop = prop; +*/ /*Transfer vertex group with weight to selected*/ void OBJECT_OT_vertex_group_copy_to_selected_single(wmOperatorType *ot) { @@ -3418,87 +3189,39 @@ static int vertex_group_transfer_weight_exec(bContext *C, wmOperator *op) int change = 0; int fail = 0; - /*TODO: get this parameter*/ - enum option {single =1, all =2} option= 1; - - /*TODO: get this parameter*/ - enum method {by_index = 1, by_nearest_vertex = 2, by_nearest_face = 3, by_nearest_vertex_in_face = 4} method = 4; - - /*TODO: get this parameter*/ - /* mode is passed on to lower funtions*/ - short mode = 2; - - /* mode 1 == replace all weights*/ - /* mode 2 == replace null weights*/ - /* mode 3 == replace selected weights*/ - - /*Truth table for testing:----*/ - /*1,1,1 Tested and working.*/ - /*1,1,2 Tested and working.*/ - /*1,1,3 Tested and NOT working.*/ - /*1,2,1 Tested and working.*/ - /*1,2,2 Tested and working.*/ - /*1,2,3 Tested and NOT working.*/ - /*1,3,1 Tested and working.*/ - /*1,3,2 Tested and working.*/ - /*1,3,3 Tested and NOT working.*/ - /*1,4,1 Tested and working.*/ - /*1,4,2 Tested and working.*/ - /*1,4,3 Tested and NOT working.*/ - - /*Macro to loop through selected objects and perform operation depending on option and method*/ + /*TODO: get these parameters*/ + enum Function {by_index = 1, by_nearest_vertex = 2, by_nearest_face = 3, by_nearest_vertex_in_face = 4} function = 4; + /*TODO: pass these on to functions*/ + enum Mode {replace_all_weights = 1, replace_empty_weights = 2, replace_selected_weights = 3} mode= 1; + enum Option {single = 1, all = 2} option = 1; + + /*Macro to loop through selected objects and perform operation depending on function, option and method*/ CTX_DATA_BEGIN(C, Object*, obslc, selected_editable_objects) { - if(obact != obslc) { - switch(option){ - - /*single*/ - case(single): - switch(method){ + if(obact != obslc){ + switch(function){ case(by_index): - if(ED_vgroup_transfer_weight_by_index_single(obslc, obact, mode)) change++; + if(ED_vgroup_transfer_weight_by_index(obslc, obact, mode, option)) change++; else fail++; break; case(by_nearest_vertex): - if(ED_vgroup_transfer_weight_by_nearest_vertex_single(obslc, obact, mode)) change++; + if(ED_vgroup_transfer_weight_by_nearest_vertex(obslc, obact, mode, option)) change++; else fail++; break; case(by_nearest_face): - if(ED_vgroup_transfer_weight_by_nearest_vertex_in_face_single(obslc, obact, mode)) change++; + if(ED_vgroup_transfer_weight_by_nearest_face(obslc, obact, mode, option)) change++; else fail++; break; case(by_nearest_vertex_in_face): - if(ED_vgroup_transfer_weight_by_nearest_face_single(obslc, obact, mode)) change++; + if(ED_vgroup_transfer_weight_by_nearest_vertex_in_face(obslc, obact, mode, option)) change++; else fail++; break; - } - - /*all*/ - case(all): - switch(method){ - case(by_index): - /*if(ED_vgroup_transfer_weight_by_index_all(obslc, obact, mode)) change++; - else fail++;*/ break; - - case(by_nearest_vertex): - /*if(ED_vgroup_transfer_weight_by_nearest_vertex_all(obslc, obact, mode)) change++; - else fail++;*/ break; - - case(by_nearest_vertex_in_face): - /*if(ED_vgroup_transfer_weight_by_nearest_vertex_in_face_all(obslc, obact, mode)) change++; - else fail++;*/ break; - - case(by_nearest_face): - /*if(ED_vgroup_transfer_weight_by_nearest_face_all(obslc, obact, mode)) change++; - else fail++;*/ break; - } } - - /*Event notifiers for correct display of data*/ - DAG_id_tag_update(&obslc->id, OB_RECALC_DATA); - WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, obslc); - WM_event_add_notifier(C, NC_GEOM|ND_DATA, obslc->data); } + /*Event notifiers for correct display of data*/ + DAG_id_tag_update(&obslc->id, OB_RECALC_DATA); + WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, obslc); + WM_event_add_notifier(C, NC_GEOM|ND_DATA, obslc->data); } CTX_DATA_END; |