From 94a2775a14865ef699901afd41294b688e7211a5 Mon Sep 17 00:00:00 2001 From: Ove Murberg Henriksen Date: Wed, 29 Feb 2012 19:46:31 +0000 Subject: M source/blender/editors/object/object_vgroup.c M source/blender/editors/object/object_ops.c M source/blender/editors/object/object_intern.h --- source/blender/editors/object/object_intern.h | 1 + source/blender/editors/object/object_ops.c | 1 + source/blender/editors/object/object_vgroup.c | 29 +++++++++++++++++++++++++++ 3 files changed, 31 insertions(+) diff --git a/source/blender/editors/object/object_intern.h b/source/blender/editors/object/object_intern.h index 526706b566d..b1c071ea2a0 100644 --- a/source/blender/editors/object/object_intern.h +++ b/source/blender/editors/object/object_intern.h @@ -200,6 +200,7 @@ void OBJECT_OT_vertex_group_copy_to_selected(struct wmOperatorType *ot); void OBJECT_OT_vertex_group_copy(struct wmOperatorType *ot); void OBJECT_OT_vertex_group_normalize(struct wmOperatorType *ot); void OBJECT_OT_vertex_group_normalize_all(struct wmOperatorType *ot); +void OBJECT_OT_vertex_group_transfer_weight(struct wmOperatorType *ot); /*cyborgmuppets experimental test */ void OBJECT_OT_vertex_group_levels(struct wmOperatorType *ot); void OBJECT_OT_vertex_group_lock(struct wmOperatorType *ot); void OBJECT_OT_vertex_group_fix(struct wmOperatorType *ot); diff --git a/source/blender/editors/object/object_ops.c b/source/blender/editors/object/object_ops.c index 542b75e1f19..550082d7554 100644 --- a/source/blender/editors/object/object_ops.c +++ b/source/blender/editors/object/object_ops.c @@ -173,6 +173,7 @@ void ED_operatortypes_object(void) WM_operatortype_append(OBJECT_OT_vertex_group_copy); WM_operatortype_append(OBJECT_OT_vertex_group_normalize); WM_operatortype_append(OBJECT_OT_vertex_group_normalize_all); + WM_operatortype_append(OBJECT_OT_vertex_group_transfer_weight); /*cyborgmuppets experimental test*/ WM_operatortype_append(OBJECT_OT_vertex_group_lock); WM_operatortype_append(OBJECT_OT_vertex_group_fix); WM_operatortype_append(OBJECT_OT_vertex_group_invert); diff --git a/source/blender/editors/object/object_vgroup.c b/source/blender/editors/object/object_vgroup.c index c60041fe67b..f14177ae3a3 100644 --- a/source/blender/editors/object/object_vgroup.c +++ b/source/blender/editors/object/object_vgroup.c @@ -1176,6 +1176,8 @@ static void vgroup_normalize_all(Object *ob, int lock_active) } } +static void vgroup_transfer_weight() +{} static void vgroup_lock_all(Object *ob, int action) { @@ -2367,6 +2369,33 @@ void OBJECT_OT_vertex_group_normalize_all(wmOperatorType *ot) "Keep the values of the active group while normalizing others"); } +static int vertex_group_transfer_weight_exec(bContext *C, wmOperator *op) +{ + Object *ob= ED_object_context(C); + + vgroup_transfer_weight(); + + DAG_id_tag_update(&ob->id, OB_RECALC_DATA); + WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, ob); + WM_event_add_notifier(C, NC_GEOM|ND_DATA, ob->data); + + return OPERATOR_FINISHED; +} + +void OBJECT_OT_vertex_group_transfer_weight(wmOperatorType *ot) +{ + /* identifiers */ + ot->name= "Transfer Weight"; + ot->idname= "OBJECT_OT_vertex_group_transfer_weight"; + + /* api callbacks */ + ot->poll= vertex_group_poll; + ot->exec= vertex_group_transfer_weight_exec; + + /* flags */ + ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; +} + static int vertex_group_fix_exec(bContext *C, wmOperator *op) { Object *ob= CTX_data_active_object(C); -- cgit v1.2.3 From 42dfd8292821bdf079eb4cde97dc396aca59fb32 Mon Sep 17 00:00:00 2001 From: Ove Murberg Henriksen Date: Wed, 29 Feb 2012 19:55:54 +0000 Subject: M source/blender/editors/object/object_ops.c M source/blender/editors/object/object_intern.h --- source/blender/editors/object/object_intern.h | 2 +- source/blender/editors/object/object_ops.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/source/blender/editors/object/object_intern.h b/source/blender/editors/object/object_intern.h index b1c071ea2a0..29f46f93315 100644 --- a/source/blender/editors/object/object_intern.h +++ b/source/blender/editors/object/object_intern.h @@ -200,7 +200,7 @@ void OBJECT_OT_vertex_group_copy_to_selected(struct wmOperatorType *ot); void OBJECT_OT_vertex_group_copy(struct wmOperatorType *ot); void OBJECT_OT_vertex_group_normalize(struct wmOperatorType *ot); void OBJECT_OT_vertex_group_normalize_all(struct wmOperatorType *ot); -void OBJECT_OT_vertex_group_transfer_weight(struct wmOperatorType *ot); /*cyborgmuppets experimental test */ +void OBJECT_OT_vertex_group_transfer_weight(struct wmOperatorType *ot); void OBJECT_OT_vertex_group_levels(struct wmOperatorType *ot); void OBJECT_OT_vertex_group_lock(struct wmOperatorType *ot); void OBJECT_OT_vertex_group_fix(struct wmOperatorType *ot); diff --git a/source/blender/editors/object/object_ops.c b/source/blender/editors/object/object_ops.c index 550082d7554..d6b5861fa66 100644 --- a/source/blender/editors/object/object_ops.c +++ b/source/blender/editors/object/object_ops.c @@ -173,7 +173,7 @@ void ED_operatortypes_object(void) WM_operatortype_append(OBJECT_OT_vertex_group_copy); WM_operatortype_append(OBJECT_OT_vertex_group_normalize); WM_operatortype_append(OBJECT_OT_vertex_group_normalize_all); - WM_operatortype_append(OBJECT_OT_vertex_group_transfer_weight); /*cyborgmuppets experimental test*/ + WM_operatortype_append(OBJECT_OT_vertex_group_transfer_weight); WM_operatortype_append(OBJECT_OT_vertex_group_lock); WM_operatortype_append(OBJECT_OT_vertex_group_fix); WM_operatortype_append(OBJECT_OT_vertex_group_invert); -- cgit v1.2.3 From 5b29a7bd2f9e3503c06e0e97a1fc75bca106dc6c Mon Sep 17 00:00:00 2001 From: Ove Murberg Henriksen Date: Fri, 2 Mar 2012 13:33:14 +0000 Subject: from first change up until including this: added two buttons to gui, transfer weight and trtransfer weight all, made the basic structure, redy to implement the contents of the functions in object_vgroup.c --- source/blender/editors/object/object_intern.h | 1 + source/blender/editors/object/object_ops.c | 1 + source/blender/editors/object/object_vgroup.c | 42 +++++++++++++++++++++++++-- 3 files changed, 41 insertions(+), 3 deletions(-) diff --git a/source/blender/editors/object/object_intern.h b/source/blender/editors/object/object_intern.h index 29f46f93315..bb87bd5de2e 100644 --- a/source/blender/editors/object/object_intern.h +++ b/source/blender/editors/object/object_intern.h @@ -200,6 +200,7 @@ void OBJECT_OT_vertex_group_copy_to_selected(struct wmOperatorType *ot); void OBJECT_OT_vertex_group_copy(struct wmOperatorType *ot); void OBJECT_OT_vertex_group_normalize(struct wmOperatorType *ot); void OBJECT_OT_vertex_group_normalize_all(struct wmOperatorType *ot); +void OBJECT_OT_vertex_group_transfer_weight_all(struct wmOperatorType *ot); void OBJECT_OT_vertex_group_transfer_weight(struct wmOperatorType *ot); void OBJECT_OT_vertex_group_levels(struct wmOperatorType *ot); void OBJECT_OT_vertex_group_lock(struct wmOperatorType *ot); diff --git a/source/blender/editors/object/object_ops.c b/source/blender/editors/object/object_ops.c index d6b5861fa66..08df069fbf1 100644 --- a/source/blender/editors/object/object_ops.c +++ b/source/blender/editors/object/object_ops.c @@ -173,6 +173,7 @@ void ED_operatortypes_object(void) WM_operatortype_append(OBJECT_OT_vertex_group_copy); WM_operatortype_append(OBJECT_OT_vertex_group_normalize); WM_operatortype_append(OBJECT_OT_vertex_group_normalize_all); + WM_operatortype_append(OBJECT_OT_vertex_group_transfer_weight_all); WM_operatortype_append(OBJECT_OT_vertex_group_transfer_weight); WM_operatortype_append(OBJECT_OT_vertex_group_lock); WM_operatortype_append(OBJECT_OT_vertex_group_fix); diff --git a/source/blender/editors/object/object_vgroup.c b/source/blender/editors/object/object_vgroup.c index f14177ae3a3..d8aead9fdc9 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 ***** */ @@ -75,6 +75,7 @@ #include "UI_resources.h" #include "object_intern.h" +#include /************************ Exported Functions **********************/ static void vgroup_remap_update_users(Object *ob, int *map); @@ -1176,8 +1177,16 @@ static void vgroup_normalize_all(Object *ob, int lock_active) } } -static void vgroup_transfer_weight() -{} +static void vgroup_transfer_weight_all(Object *ob_act, Object *ob_other) +{ + /* for each vertex group {vgroup_transfer_weight()} */ + printf("Not implemented yet!"); +} + +static void vgroup_transfer_weight(Object *ob_act, Object *ob_other) +{ + printf("not implemented yet!"); +} static void vgroup_lock_all(Object *ob, int action) { @@ -2369,6 +2378,33 @@ void OBJECT_OT_vertex_group_normalize_all(wmOperatorType *ot) "Keep the values of the active group while normalizing others"); } +static int vertex_group_transfer_weight_all_exec(bContext *C, wmOperator *op) +{ + Object *ob= ED_object_context(C); + + vgroup_transfer_weight_all(); + + DAG_id_tag_update(&ob->id, OB_RECALC_DATA); + WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, ob); + WM_event_add_notifier(C, NC_GEOM|ND_DATA, ob->data); + + return OPERATOR_FINISHED; +} + +void OBJECT_OT_vertex_group_transfer_weight_all(wmOperatorType *ot) +{ + /* identifiers */ + ot->name= "Transfer Weight"; + ot->idname= "OBJECT_OT_vertex_group_transfer_weight"; + + /* api callbacks */ + ot->poll= vertex_group_poll; + ot->exec= vertex_group_transfer_weight_all_exec; + + /* flags */ + ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; +} + static int vertex_group_transfer_weight_exec(bContext *C, wmOperator *op) { Object *ob= ED_object_context(C); -- cgit v1.2.3 From fd9ea43c47cf11f05bdcb25053b4d3a5f0586dc0 Mon Sep 17 00:00:00 2001 From: Ove Murberg Henriksen Date: Sun, 4 Mar 2012 15:03:59 +0000 Subject: Requested commit. two wight paint buttons added, code calling functions and empty functions in place. --- source/blender/editors/object/object_vgroup.c | 29 +++++++++++++++------------ 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/source/blender/editors/object/object_vgroup.c b/source/blender/editors/object/object_vgroup.c index d8aead9fdc9..53b2bd96e87 100644 --- a/source/blender/editors/object/object_vgroup.c +++ b/source/blender/editors/object/object_vgroup.c @@ -1177,15 +1177,18 @@ static void vgroup_normalize_all(Object *ob, int lock_active) } } -static void vgroup_transfer_weight_all(Object *ob_act, Object *ob_other) +static void vgroup_transfer_weight_all(bContext *C) { /* for each vertex group {vgroup_transfer_weight()} */ printf("Not implemented yet!"); } -static void vgroup_transfer_weight(Object *ob_act, Object *ob_other) +static void vgroup_transfer_weight(bContext *C) { - printf("not implemented yet!"); + printf("Not implemented yet!"); + + + } static void vgroup_lock_all(Object *ob, int action) @@ -2378,11 +2381,10 @@ void OBJECT_OT_vertex_group_normalize_all(wmOperatorType *ot) "Keep the values of the active group while normalizing others"); } -static int vertex_group_transfer_weight_all_exec(bContext *C, wmOperator *op) +static int vertex_group_transfer_weight_all_exec(const bContext *C, wmOperator *op) { - Object *ob= ED_object_context(C); - - vgroup_transfer_weight_all(); + Object *ob= CTX_data_active_object(C); + vgroup_transfer_weight_all(C); DAG_id_tag_update(&ob->id, OB_RECALC_DATA); WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, ob); @@ -2391,11 +2393,12 @@ static int vertex_group_transfer_weight_all_exec(bContext *C, wmOperator *op) return OPERATOR_FINISHED; } +/* Transfers all vertex groups and weight from active object to targets*/ void OBJECT_OT_vertex_group_transfer_weight_all(wmOperatorType *ot) { /* identifiers */ - ot->name= "Transfer Weight"; - ot->idname= "OBJECT_OT_vertex_group_transfer_weight"; + ot->name= "Transfer Weight All"; + ot->idname= "OBJECT_OT_vertex_group_transfer_weight_all"; /* api callbacks */ ot->poll= vertex_group_poll; @@ -2405,11 +2408,10 @@ void OBJECT_OT_vertex_group_transfer_weight_all(wmOperatorType *ot) ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; } -static int vertex_group_transfer_weight_exec(bContext *C, wmOperator *op) +static int vertex_group_transfer_weight_exec(const bContext *C, wmOperator *op) { - Object *ob= ED_object_context(C); - - vgroup_transfer_weight(); + Object *ob= CTX_data_active_object(C); + vgroup_transfer_weight(C); DAG_id_tag_update(&ob->id, OB_RECALC_DATA); WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, ob); @@ -2418,6 +2420,7 @@ static int vertex_group_transfer_weight_exec(bContext *C, wmOperator *op) return OPERATOR_FINISHED; } +/* Transfers one vertex group with weight from active object to target*/ void OBJECT_OT_vertex_group_transfer_weight(wmOperatorType *ot) { /* identifiers */ -- cgit v1.2.3 From 5087c5a6184522f6f25848a367b29374e471c7d9 Mon Sep 17 00:00:00 2001 From: Ove Murberg Henriksen Date: Sat, 10 Mar 2012 00:09:57 +0000 Subject: Adjusted line number of funtions and implemented vertex group copy into them. --- source/blender/editors/object/object_vgroup.c | 137 +++++++++++++------------- 1 file changed, 68 insertions(+), 69 deletions(-) diff --git a/source/blender/editors/object/object_vgroup.c b/source/blender/editors/object/object_vgroup.c index 53b2bd96e87..8855b7c08c1 100644 --- a/source/blender/editors/object/object_vgroup.c +++ b/source/blender/editors/object/object_vgroup.c @@ -1177,20 +1177,6 @@ static void vgroup_normalize_all(Object *ob, int lock_active) } } -static void vgroup_transfer_weight_all(bContext *C) -{ - /* for each vertex group {vgroup_transfer_weight()} */ - printf("Not implemented yet!"); -} - -static void vgroup_transfer_weight(bContext *C) -{ - printf("Not implemented yet!"); - - - -} - static void vgroup_lock_all(Object *ob, int action) { bDeformGroup *dg; @@ -2264,6 +2250,7 @@ void OBJECT_OT_vertex_group_deselect(wmOperatorType *ot) ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; } +/*Adds a copy of selected vertex group on source object to source object*/ static int vertex_group_copy_exec(bContext *C, wmOperator *UNUSED(op)) { Object *ob= ED_object_context(C); @@ -2381,60 +2368,6 @@ void OBJECT_OT_vertex_group_normalize_all(wmOperatorType *ot) "Keep the values of the active group while normalizing others"); } -static int vertex_group_transfer_weight_all_exec(const bContext *C, wmOperator *op) -{ - Object *ob= CTX_data_active_object(C); - vgroup_transfer_weight_all(C); - - DAG_id_tag_update(&ob->id, OB_RECALC_DATA); - WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, ob); - WM_event_add_notifier(C, NC_GEOM|ND_DATA, ob->data); - - return OPERATOR_FINISHED; -} - -/* Transfers all vertex groups and weight from active object to targets*/ -void OBJECT_OT_vertex_group_transfer_weight_all(wmOperatorType *ot) -{ - /* identifiers */ - ot->name= "Transfer Weight All"; - ot->idname= "OBJECT_OT_vertex_group_transfer_weight_all"; - - /* api callbacks */ - ot->poll= vertex_group_poll; - ot->exec= vertex_group_transfer_weight_all_exec; - - /* flags */ - ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; -} - -static int vertex_group_transfer_weight_exec(const bContext *C, wmOperator *op) -{ - Object *ob= CTX_data_active_object(C); - vgroup_transfer_weight(C); - - DAG_id_tag_update(&ob->id, OB_RECALC_DATA); - WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, ob); - WM_event_add_notifier(C, NC_GEOM|ND_DATA, ob->data); - - return OPERATOR_FINISHED; -} - -/* Transfers one vertex group with weight from active object to target*/ -void OBJECT_OT_vertex_group_transfer_weight(wmOperatorType *ot) -{ - /* identifiers */ - ot->name= "Transfer Weight"; - ot->idname= "OBJECT_OT_vertex_group_transfer_weight"; - - /* api callbacks */ - ot->poll= vertex_group_poll; - ot->exec= vertex_group_transfer_weight_exec; - - /* flags */ - ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; -} - static int vertex_group_fix_exec(bContext *C, wmOperator *op) { Object *ob= CTX_data_active_object(C); @@ -2719,7 +2652,6 @@ static int vertex_group_copy_to_selected_exec(bContext *C, wmOperator *op) return OPERATOR_FINISHED; } - void OBJECT_OT_vertex_group_copy_to_selected(wmOperatorType *ot) { /* identifiers */ @@ -2735,6 +2667,73 @@ void OBJECT_OT_vertex_group_copy_to_selected(wmOperatorType *ot) ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; } +/* Transfers all vertex groups and weight from active object to targets*/ +static void vgroup_copy_weight_all(const bContext *C, wmOperator *op) +{ + /* for each vertex group {vgroup_copy_weight(sourceGroup, targetGroup)} */ + printf("Not implemented yet! \n"); +} + +static int vertex_group_transfer_weight_all_exec(const bContext *C, wmOperator *op) +{ + Object *ob= CTX_data_active_object(C); + vertex_group_copy_to_selected_exec(C, op); + vgroup_copy_weight_all(C, op); + + DAG_id_tag_update(&ob->id, OB_RECALC_DATA); + WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, ob); + WM_event_add_notifier(C, NC_GEOM|ND_DATA, ob->data); + + return OPERATOR_FINISHED; +} + +void OBJECT_OT_vertex_group_transfer_weight_all(wmOperatorType *ot) +{ + /* identifiers */ + ot->name= "Transfer Weight All"; + ot->idname= "OBJECT_OT_vertex_group_transfer_weight_all"; + + /* api callbacks */ + ot->poll= vertex_group_poll; + ot->exec= vertex_group_transfer_weight_all_exec; + + /* flags */ + ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; +} + +/* Transfers one vertex group with weight from active object to target*/ +static void vgroup_copy_weight(/*source vertex group*/ /*target vertex group*/) +{ + printf("Not implemented yet! \n"); +} + +static int vertex_group_transfer_weight_exec(const bContext *C, wmOperator *op) +{ + Object *ob= CTX_data_active_object(C); + /*vertex_group_copy_to_selected_exec(C,op); ----- must be implemented!*/ + vgroup_copy_weight(); + + DAG_id_tag_update(&ob->id, OB_RECALC_DATA); + WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, ob); + WM_event_add_notifier(C, NC_GEOM|ND_DATA, ob->data); + + return OPERATOR_FINISHED; +} + +void OBJECT_OT_vertex_group_transfer_weight(wmOperatorType *ot) +{ + /* identifiers */ + ot->name= "Transfer Weight"; + ot->idname= "OBJECT_OT_vertex_group_transfer_weight"; + + /* api callbacks */ + ot->poll= vertex_group_poll; + ot->exec= vertex_group_transfer_weight_exec; + + /* flags */ + ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; +} + static EnumPropertyItem vgroup_items[]= { {0, NULL, 0, NULL, NULL}}; -- cgit v1.2.3 From 0b8ae86e591955214bb78b684be57430d119f9ab Mon Sep 17 00:00:00 2001 From: Ove Murberg Henriksen Date: Thu, 15 Mar 2012 21:49:40 +0000 Subject: Added functionality: copy vertex group from source to targets. Changed some comments to represent the code more accuratly. --- source/blender/editors/object/object_intern.h | 1 + source/blender/editors/object/object_ops.c | 1 + source/blender/editors/object/object_vgroup.c | 77 ++++++++++++++++++++++----- 3 files changed, 66 insertions(+), 13 deletions(-) diff --git a/source/blender/editors/object/object_intern.h b/source/blender/editors/object/object_intern.h index bb87bd5de2e..8f24a9638ab 100644 --- a/source/blender/editors/object/object_intern.h +++ b/source/blender/editors/object/object_intern.h @@ -197,6 +197,7 @@ void OBJECT_OT_vertex_group_select(struct wmOperatorType *ot); void OBJECT_OT_vertex_group_deselect(struct wmOperatorType *ot); void OBJECT_OT_vertex_group_copy_to_linked(struct wmOperatorType *ot); void OBJECT_OT_vertex_group_copy_to_selected(struct wmOperatorType *ot); +void OBJECT_OT_vertex_group_copy_to_selected_single(struct wmOperatorType *ot); void OBJECT_OT_vertex_group_copy(struct wmOperatorType *ot); void OBJECT_OT_vertex_group_normalize(struct wmOperatorType *ot); void OBJECT_OT_vertex_group_normalize_all(struct wmOperatorType *ot); diff --git a/source/blender/editors/object/object_ops.c b/source/blender/editors/object/object_ops.c index 08df069fbf1..c704e165ca2 100644 --- a/source/blender/editors/object/object_ops.c +++ b/source/blender/editors/object/object_ops.c @@ -170,6 +170,7 @@ void ED_operatortypes_object(void) WM_operatortype_append(OBJECT_OT_vertex_group_deselect); WM_operatortype_append(OBJECT_OT_vertex_group_copy_to_linked); WM_operatortype_append(OBJECT_OT_vertex_group_copy_to_selected); + WM_operatortype_append(OBJECT_OT_vertex_group_copy_to_selected_single); WM_operatortype_append(OBJECT_OT_vertex_group_copy); WM_operatortype_append(OBJECT_OT_vertex_group_normalize); WM_operatortype_append(OBJECT_OT_vertex_group_normalize_all); diff --git a/source/blender/editors/object/object_vgroup.c b/source/blender/editors/object/object_vgroup.c index 8855b7c08c1..2983ea6c65f 100644 --- a/source/blender/editors/object/object_vgroup.c +++ b/source/blender/editors/object/object_vgroup.c @@ -75,7 +75,7 @@ #include "UI_resources.h" #include "object_intern.h" -#include +#include /*only for development purposes, remove*/ /************************ Exported Functions **********************/ static void vgroup_remap_update_users(Object *ob, int *map); @@ -2250,7 +2250,7 @@ void OBJECT_OT_vertex_group_deselect(wmOperatorType *ot) ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; } -/*Adds a copy of selected vertex group on source object to source object*/ +/*Adds a copy of selected vertex group from source object to source object*/ static int vertex_group_copy_exec(bContext *C, wmOperator *UNUSED(op)) { Object *ob= ED_object_context(C); @@ -2628,6 +2628,7 @@ void OBJECT_OT_vertex_group_copy_to_linked(wmOperatorType *ot) ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; } +/*Copy vertex groups from source to target*/ /*warning! overwrites list*/ static int vertex_group_copy_to_selected_exec(bContext *C, wmOperator *op) { Object *obact= ED_object_context(C); @@ -2652,6 +2653,7 @@ static int vertex_group_copy_to_selected_exec(bContext *C, wmOperator *op) return OPERATOR_FINISHED; } +/*Copy vertex groups from source to target*/ /*warning! overwrites list*/ void OBJECT_OT_vertex_group_copy_to_selected(wmOperatorType *ot) { /* identifiers */ @@ -2667,31 +2669,77 @@ void OBJECT_OT_vertex_group_copy_to_selected(wmOperatorType *ot) ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; } -/* Transfers all vertex groups and weight from active object to targets*/ +static int vertex_group_copy_to_selected_single_exec(bContext *C, wmOperator *op) +{ + Object *obact= CTX_data_active_object(C); + int change= 0; + int fail= 0; + + bDeformGroup *dg; + dg = BLI_findlink(&obact->defbase, (obact->actdef-1)); + + CTX_DATA_BEGIN(C, Object*, obslc, selected_editable_objects) + { + if(obact != obslc) { + if(ED_vgroup_add_name(obslc, dg->name)) change++; + else fail++; + } + } + CTX_DATA_END; + + if((change == 0 && fail == 0) || fail) { + BKE_reportf(op->reports, RPT_ERROR, + "Copy to VGroups to Selected warning done %d, failed %d, object data must have matching indicies", + change, fail); + } + + return OPERATOR_FINISHED; +} + +/*Copy a vertex group from source to targets*/ +void OBJECT_OT_vertex_group_copy_to_selected_single(wmOperatorType *ot) /*Todo: add gui in python*/ +{ + /* identifiers */ + ot->name= "Copy a Vertex Group to Selected"; + ot->idname= "OBJECT_OT_vertex_group_copy_to_selected_single"; + ot->description= "Copy a vertex group to other selected objects with matching indices"; + + /* api callbacks */ + ot->poll= vertex_group_poll; + ot->exec= vertex_group_copy_to_selected_exec; + + /* flags */ + ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; +} + static void vgroup_copy_weight_all(const bContext *C, wmOperator *op) { - /* for each vertex group {vgroup_copy_weight(sourceGroup, targetGroup)} */ + /* for each vertex group {defvert_copy(sourceGroup, targetGroup)} */ printf("Not implemented yet! \n"); } static int vertex_group_transfer_weight_all_exec(const bContext *C, wmOperator *op) { - Object *ob= CTX_data_active_object(C); - vertex_group_copy_to_selected_exec(C, op); + Object *ob = CTX_data_active_object(C); + + vertex_group_copy_to_selected_exec(C, op); /*!!!This causes all vertex groups to be copied, weight or not.*/ vgroup_copy_weight_all(C, op); + /*is the right stuff being updated?*/ DAG_id_tag_update(&ob->id, OB_RECALC_DATA); - WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, ob); WM_event_add_notifier(C, NC_GEOM|ND_DATA, ob->data); + WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, ob); return OPERATOR_FINISHED; } +/* Transfers all vertex groups with weight from source to targets*/ void OBJECT_OT_vertex_group_transfer_weight_all(wmOperatorType *ot) { /* identifiers */ ot->name= "Transfer Weight All"; ot->idname= "OBJECT_OT_vertex_group_transfer_weight_all"; + ot->description= "Copy all vertex groups including weights to targets"; /* api callbacks */ ot->poll= vertex_group_poll; @@ -2701,30 +2749,33 @@ void OBJECT_OT_vertex_group_transfer_weight_all(wmOperatorType *ot) ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; } -/* Transfers one vertex group with weight from active object to target*/ -static void vgroup_copy_weight(/*source vertex group*/ /*target vertex group*/) +static void vgroup_copy_weight(const bContext *C, wmOperator *op) { printf("Not implemented yet! \n"); } static int vertex_group_transfer_weight_exec(const bContext *C, wmOperator *op) { - Object *ob= CTX_data_active_object(C); - /*vertex_group_copy_to_selected_exec(C,op); ----- must be implemented!*/ - vgroup_copy_weight(); + Object *ob = CTX_data_active_object(C); + + vertex_group_copy_to_selected_single_exec(C,op); /*!!!This will copy vertex grop, weight or not.*/ + vgroup_copy_weight(C, op); + /*is the right stuff being updated?*/ DAG_id_tag_update(&ob->id, OB_RECALC_DATA); - WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, ob); WM_event_add_notifier(C, NC_GEOM|ND_DATA, ob->data); + WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, ob); return OPERATOR_FINISHED; } +/* Transfers one vertex group with weight from source to targets*/ void OBJECT_OT_vertex_group_transfer_weight(wmOperatorType *ot) { /* identifiers */ ot->name= "Transfer Weight"; ot->idname= "OBJECT_OT_vertex_group_transfer_weight"; + ot->description= "Copy a vertex group including weights to targets"; /* api callbacks */ ot->poll= vertex_group_poll; -- cgit v1.2.3 From 4fb535070ecaae57dc3f6521e447d42c6cc57193 Mon Sep 17 00:00:00 2001 From: Ove Murberg Henriksen Date: Tue, 3 Apr 2012 08:23:00 +0000 Subject: Removed: The uneccecary previously added code and added functions for "copy_to_selected_single. Reason: less code and consistensy with existing code. Added fuction "ED_vgroup_copy_single" that forms the basis for the above. --- source/blender/editors/object/object_intern.h | 2 - source/blender/editors/object/object_ops.c | 2 - source/blender/editors/object/object_vgroup.c | 131 ++++++++++---------------- 3 files changed, 48 insertions(+), 87 deletions(-) diff --git a/source/blender/editors/object/object_intern.h b/source/blender/editors/object/object_intern.h index 8f24a9638ab..651272323f3 100644 --- a/source/blender/editors/object/object_intern.h +++ b/source/blender/editors/object/object_intern.h @@ -201,8 +201,6 @@ void OBJECT_OT_vertex_group_copy_to_selected_single(struct wmOperatorType *ot); void OBJECT_OT_vertex_group_copy(struct wmOperatorType *ot); void OBJECT_OT_vertex_group_normalize(struct wmOperatorType *ot); void OBJECT_OT_vertex_group_normalize_all(struct wmOperatorType *ot); -void OBJECT_OT_vertex_group_transfer_weight_all(struct wmOperatorType *ot); -void OBJECT_OT_vertex_group_transfer_weight(struct wmOperatorType *ot); void OBJECT_OT_vertex_group_levels(struct wmOperatorType *ot); void OBJECT_OT_vertex_group_lock(struct wmOperatorType *ot); void OBJECT_OT_vertex_group_fix(struct wmOperatorType *ot); diff --git a/source/blender/editors/object/object_ops.c b/source/blender/editors/object/object_ops.c index c704e165ca2..4307bd71c1b 100644 --- a/source/blender/editors/object/object_ops.c +++ b/source/blender/editors/object/object_ops.c @@ -174,8 +174,6 @@ void ED_operatortypes_object(void) WM_operatortype_append(OBJECT_OT_vertex_group_copy); WM_operatortype_append(OBJECT_OT_vertex_group_normalize); WM_operatortype_append(OBJECT_OT_vertex_group_normalize_all); - WM_operatortype_append(OBJECT_OT_vertex_group_transfer_weight_all); - WM_operatortype_append(OBJECT_OT_vertex_group_transfer_weight); WM_operatortype_append(OBJECT_OT_vertex_group_lock); WM_operatortype_append(OBJECT_OT_vertex_group_fix); WM_operatortype_append(OBJECT_OT_vertex_group_invert); diff --git a/source/blender/editors/object/object_vgroup.c b/source/blender/editors/object/object_vgroup.c index 2983ea6c65f..dcf3a400470 100644 --- a/source/blender/editors/object/object_vgroup.c +++ b/source/blender/editors/object/object_vgroup.c @@ -312,7 +312,7 @@ int ED_vgroup_give_array(ID *id, MDeformVert **dvert_arr, int *dvert_tot) return FALSE; } -/* matching index only */ +/*Copy all vertex groups to target, overwriting existing. matching index only*/ int ED_vgroup_copy_array(Object *ob, Object *ob_from) { MDeformVert **dvert_array_from, **dvf; @@ -377,6 +377,43 @@ int ED_vgroup_copy_array(Object *ob, Object *ob_from) return 1; } +/*Copy a single vertex group from source to destination with weights*/ +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); + + /* Loop through the vertices and copy weight*/ + for(i=0; iweight = dw_src->weight; + } + + return 1; +} /* for Mesh in Object mode */ /* allows editmode for Lattice */ @@ -2653,7 +2690,7 @@ static int vertex_group_copy_to_selected_exec(bContext *C, wmOperator *op) return OPERATOR_FINISHED; } -/*Copy vertex groups from source to target*/ /*warning! overwrites list*/ +/* Transfer all vertex groups with weight to selected*/ void OBJECT_OT_vertex_group_copy_to_selected(wmOperatorType *ot) { /* identifiers */ @@ -2675,18 +2712,19 @@ static int vertex_group_copy_to_selected_single_exec(bContext *C, wmOperator *op int change= 0; int fail= 0; - bDeformGroup *dg; - dg = BLI_findlink(&obact->defbase, (obact->actdef-1)); - + /*Macro to loop through selected objects and perform operation*/ CTX_DATA_BEGIN(C, Object*, obslc, selected_editable_objects) { if(obact != obslc) { - if(ED_vgroup_add_name(obslc, dg->name)) change++; + if(ED_vgroup_copy_single(obslc, obact)) change++; else fail++; + /*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; - if((change == 0 && fail == 0) || fail) { BKE_reportf(op->reports, RPT_ERROR, "Copy to VGroups to Selected warning done %d, failed %d, object data must have matching indicies", @@ -2696,8 +2734,8 @@ static int vertex_group_copy_to_selected_single_exec(bContext *C, wmOperator *op return OPERATOR_FINISHED; } -/*Copy a vertex group from source to targets*/ -void OBJECT_OT_vertex_group_copy_to_selected_single(wmOperatorType *ot) /*Todo: add gui in python*/ +/*Transfer vertex group with weight to selected*/ +void OBJECT_OT_vertex_group_copy_to_selected_single(wmOperatorType *ot) { /* identifiers */ ot->name= "Copy a Vertex Group to Selected"; @@ -2706,80 +2744,7 @@ void OBJECT_OT_vertex_group_copy_to_selected_single(wmOperatorType *ot) /*Todo: /* api callbacks */ ot->poll= vertex_group_poll; - ot->exec= vertex_group_copy_to_selected_exec; - - /* flags */ - ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; -} - -static void vgroup_copy_weight_all(const bContext *C, wmOperator *op) -{ - /* for each vertex group {defvert_copy(sourceGroup, targetGroup)} */ - printf("Not implemented yet! \n"); -} - -static int vertex_group_transfer_weight_all_exec(const bContext *C, wmOperator *op) -{ - Object *ob = CTX_data_active_object(C); - - vertex_group_copy_to_selected_exec(C, op); /*!!!This causes all vertex groups to be copied, weight or not.*/ - vgroup_copy_weight_all(C, op); - - /*is the right stuff being updated?*/ - DAG_id_tag_update(&ob->id, OB_RECALC_DATA); - WM_event_add_notifier(C, NC_GEOM|ND_DATA, ob->data); - WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, ob); - - return OPERATOR_FINISHED; -} - -/* Transfers all vertex groups with weight from source to targets*/ -void OBJECT_OT_vertex_group_transfer_weight_all(wmOperatorType *ot) -{ - /* identifiers */ - ot->name= "Transfer Weight All"; - ot->idname= "OBJECT_OT_vertex_group_transfer_weight_all"; - ot->description= "Copy all vertex groups including weights to targets"; - - /* api callbacks */ - ot->poll= vertex_group_poll; - ot->exec= vertex_group_transfer_weight_all_exec; - - /* flags */ - ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; -} - -static void vgroup_copy_weight(const bContext *C, wmOperator *op) -{ - printf("Not implemented yet! \n"); -} - -static int vertex_group_transfer_weight_exec(const bContext *C, wmOperator *op) -{ - Object *ob = CTX_data_active_object(C); - - vertex_group_copy_to_selected_single_exec(C,op); /*!!!This will copy vertex grop, weight or not.*/ - vgroup_copy_weight(C, op); - - /*is the right stuff being updated?*/ - DAG_id_tag_update(&ob->id, OB_RECALC_DATA); - WM_event_add_notifier(C, NC_GEOM|ND_DATA, ob->data); - WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, ob); - - return OPERATOR_FINISHED; -} - -/* Transfers one vertex group with weight from source to targets*/ -void OBJECT_OT_vertex_group_transfer_weight(wmOperatorType *ot) -{ - /* identifiers */ - ot->name= "Transfer Weight"; - ot->idname= "OBJECT_OT_vertex_group_transfer_weight"; - ot->description= "Copy a vertex group including weights to targets"; - - /* api callbacks */ - ot->poll= vertex_group_poll; - ot->exec= vertex_group_transfer_weight_exec; + ot->exec= vertex_group_copy_to_selected_single_exec; /* flags */ ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; -- cgit v1.2.3 From 0563ec03f53d81132359e3dd4da86c43d40320fa Mon Sep 17 00:00:00 2001 From: Ove Murberg Henriksen Date: Tue, 17 Apr 2012 19:10:57 +0000 Subject: Added mechanics for detecting and reacting on uneven indices. --- source/blender/editors/object/object_vgroup.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/source/blender/editors/object/object_vgroup.c b/source/blender/editors/object/object_vgroup.c index aab05e022c0..31b314b374b 100644 --- a/source/blender/editors/object/object_vgroup.c +++ b/source/blender/editors/object/object_vgroup.c @@ -405,6 +405,12 @@ int ED_vgroup_copy_single(Object *ob_dst, const Object *ob_src) 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; ireports, RPT_ERROR, + "Copy to VGroups to Selected warning done %d, failed %d, object data must have matching indices", + change, fail); + } + return OPERATOR_FINISHED; } -- cgit v1.2.3 From c88c6886aad117c62a7786f135cf0cb313605a5d Mon Sep 17 00:00:00 2001 From: Ove Murberg Henriksen Date: Thu, 19 Apr 2012 00:09:20 +0000 Subject: added function for copying weight to target vertex from closest source vertex --- source/blender/editors/object/object_vgroup.c | 97 ++++++++++++++++++++++++--- 1 file changed, 89 insertions(+), 8 deletions(-) diff --git a/source/blender/editors/object/object_vgroup.c b/source/blender/editors/object/object_vgroup.c index 31b314b374b..edaa1158db0 100644 --- a/source/blender/editors/object/object_vgroup.c +++ b/source/blender/editors/object/object_vgroup.c @@ -421,6 +421,87 @@ int ED_vgroup_copy_single(Object *ob_dst, const Object *ob_src) return 1; } +/*return distance between coordinates that are comparable to other instances but not right*/ +float comparable_distance_between_coordinates(const float co_1[3], const float co_2[3]){ + float x_dist, y_dist, z_dist, dist_XY_square, distance; + x_dist= co_1[0] - co_2[0]; + y_dist= co_1[1] - co_2[1]; + z_dist= co_1[2] - co_2[2]; + dist_XY_square= x_dist * x_dist + y_dist * y_dist; + distance= dist_XY_square + z_dist * z_dist; + return distance; +} + +/*return the closest weight*/ +MDeformWeight *dweight_get_nearest(MVert *mv_dst, MDeformVert **dv_array_src, MVert *mv_src, int mv_tot_src, int index) +{ + MDeformWeight *dw; + float min_dist, dist; + int i; + /*initiate*/ + dw= (*dv_array_src)->dw; + min_dist= comparable_distance_between_coordinates(mv_dst->co, mv_src->co); + /*get closest*/ + for(i=0; ico, mv_src->co); + if(min_dist > dist){ + min_dist= dist; + dw= defvert_verify_index((*dv_array_src), index); + } + } + return dw; +} + +/*Copy a single vertex group from source to destination with weights, get the closest weight on source*/ +int ED_vgroup_copy_by_closest_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_dst, index_src; + bDeformGroup *dg_src, *dg_dst; + Mesh *me_src, *me_dst; + MVert *mv_src, *mv_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 meshes*/ + me_dst= ob_dst->data; + me_src= ob_src->data; + + /*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); + + /*get vertices*/ + mv_dst= me_dst->mvert; + mv_src= me_src->mvert; + + /*TODO: Check if it should be used and return 0 if not*/ + + /* Loop through the vertices and copy weight from closest to destination*/ + for(i=0; i < me_dst->totvert; i++, mv_dst++, dv_array_dst++) { + dw_dst= defvert_verify_index(*dv_array_dst, index_dst); + dw_src= dweight_get_nearest(mv_dst, dv_array_src, mv_src, me_src->totvert, index_src); + dw_dst->weight = dw_src->weight; + } + + return 1; +} + /* for Mesh in Object mode */ /* allows editmode for Lattice */ static void ED_vgroup_nr_vert_add(Object *ob, @@ -2800,8 +2881,12 @@ static int vertex_group_copy_to_selected_single_exec(bContext *C, wmOperator *op CTX_DATA_BEGIN(C, Object*, obslc, selected_editable_objects) { if(obact != obslc) { + /*Trying function for matching number of vertices*/ if(ED_vgroup_copy_single(obslc, obact)) change++; - else fail++; + /*Trying function for get weight from closest vertex*/ + else if(ED_vgroup_copy_by_closest_single(obslc, obact)) change++; + /*Triggers error message*/ + else fail++; /*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); @@ -2809,15 +2894,11 @@ static int vertex_group_copy_to_selected_single_exec(bContext *C, wmOperator *op } } CTX_DATA_END; - if((change == 0 && fail == 0) || fail) { - BKE_reportf(op->reports, RPT_ERROR, - "Copy to VGroups to Selected warning done %d, failed %d, object data must have matching indicies", - change, fail); - } - if ((change == 0 && fail == 0) || fail) { + /*reports error when: 1: indices are not matching. 2: smart functions fails.*/ + if((change == 0 && fail == 0) || fail) { BKE_reportf(op->reports, RPT_ERROR, - "Copy to VGroups to Selected warning done %d, failed %d, object data must have matching indices", + "Copy to VGroups to Selected warning done %d, failed %d, Noob coder is noob!", change, fail); } -- cgit v1.2.3 From 12ce42e76f5e3a33b0bf148762513dc94d296616 Mon Sep 17 00:00:00 2001 From: Ove Murberg Henriksen Date: Tue, 24 Apr 2012 15:00:38 +0000 Subject: BVHTree accellerated: ED_vgroup_copy_by_closest_single --- source/blender/editors/object/object_vgroup.c | 82 ++++++++++++++------------- 1 file changed, 44 insertions(+), 38 deletions(-) diff --git a/source/blender/editors/object/object_vgroup.c b/source/blender/editors/object/object_vgroup.c index edaa1158db0..4ac948792a2 100644 --- a/source/blender/editors/object/object_vgroup.c +++ b/source/blender/editors/object/object_vgroup.c @@ -432,37 +432,31 @@ float comparable_distance_between_coordinates(const float co_1[3], const float c return distance; } -/*return the closest weight*/ -MDeformWeight *dweight_get_nearest(MVert *mv_dst, MDeformVert **dv_array_src, MVert *mv_src, int mv_tot_src, int index) -{ - MDeformWeight *dw; - float min_dist, dist; - int i; - /*initiate*/ - dw= (*dv_array_src)->dw; - min_dist= comparable_distance_between_coordinates(mv_dst->co, mv_src->co); - /*get closest*/ - for(i=0; ico, mv_src->co); - if(min_dist > dist){ - min_dist= dist; - dw= defvert_verify_index((*dv_array_src), index); - } - } - return dw; -} - /*Copy a single vertex group from source to destination with weights, get the closest weight on source*/ int ED_vgroup_copy_by_closest_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_dst, index_src; bDeformGroup *dg_src, *dg_dst; - Mesh *me_src, *me_dst; - MVert *mv_src, *mv_dst; + MDeformVert **dv_array_src, **dv_array_dst; + MDeformWeight *dw_dst, *dw_src; + MVert *mv_dst; + Mesh *me_dst; + BVHTreeFromMesh tree_mesh_src; + BVHTreeNearest nearest; + DerivedMesh *dmesh_src; + int dv_tot_src, dv_tot_dst, i, index_dst, index_src; + + /*TODO: Check if it should be used and return 0 if not*/ + /*TODO: Bugfix, if position of object center is not similar, the copy will fail*/ + /*suggested sollution: temporarily set object center to geometry center on both source and target*/ + /*suggested sollution: temporarily manipulate destination object center to align with source*/ + /*suggested solution: user choise*/ + /*TODO: take scale into account*/ + /*memory safety TODO make this work. + if (tree_mesh_src.tree == NULL) + { + OUT_OF_MEMORY(); + return; + }*/ /*get source deform group*/ dg_src = BLI_findlink(&ob_src->defbase, (ob_src->actdef-1)); @@ -476,7 +470,12 @@ int ED_vgroup_copy_by_closest_single(Object *ob_dst, const Object *ob_src) /*get meshes*/ me_dst= ob_dst->data; - me_src= ob_src->data; + + /*get derived mesh*/ + dmesh_src= ob_src->derivedDeform; + + /*make node tree*/ + bvhtree_from_mesh_verts(&tree_mesh_src, dmesh_src, 0.0, 2, 6); /*get vertex group arrays*/ ED_vgroup_give_parray(ob_src->data, &dv_array_src, &dv_tot_src, FALSE); @@ -488,17 +487,24 @@ int ED_vgroup_copy_by_closest_single(Object *ob_dst, const Object *ob_src) /*get vertices*/ mv_dst= me_dst->mvert; - mv_src= me_src->mvert; - - /*TODO: Check if it should be used and return 0 if not*/ /* Loop through the vertices and copy weight from closest to destination*/ for(i=0; i < me_dst->totvert; i++, mv_dst++, dv_array_dst++) { + /*Reset nearest*/ + nearest.index= -1; + nearest.dist= FLT_MAX; + + /*Node tree accelerated search for closest vetex*/ + BLI_bvhtree_find_nearest(tree_mesh_src.tree, mv_dst->co, &nearest, tree_mesh_src.nearest_callback, &tree_mesh_src); + + /*copy weight*/ + dw_src= defvert_verify_index(dv_array_src[nearest.index], index_src); dw_dst= defvert_verify_index(*dv_array_dst, index_dst); - dw_src= dweight_get_nearest(mv_dst, dv_array_src, mv_src, me_src->totvert, index_src); dw_dst->weight = dw_src->weight; } + free_bvhtree_from_mesh(&tree_mesh_src); + return 1; } @@ -2881,13 +2887,13 @@ static int vertex_group_copy_to_selected_single_exec(bContext *C, wmOperator *op CTX_DATA_BEGIN(C, Object*, obslc, selected_editable_objects) { if(obact != obslc) { - /*Trying function for matching number of vertices*/ + /*Try function for matching number of vertices*/ if(ED_vgroup_copy_single(obslc, obact)) change++; - /*Trying function for get weight from closest vertex*/ + /*Try function for get weight from closest vertex*/ else if(ED_vgroup_copy_by_closest_single(obslc, obact)) change++; - /*Triggers error message*/ + /*Trigger error message*/ else fail++; - /*event notifiers for correct display of 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); @@ -2895,10 +2901,10 @@ static int vertex_group_copy_to_selected_single_exec(bContext *C, wmOperator *op } CTX_DATA_END; - /*reports error when: 1: indices are not matching. 2: smart functions fails.*/ + /*Report error when task could not be completed.*/ if((change == 0 && fail == 0) || fail) { BKE_reportf(op->reports, RPT_ERROR, - "Copy to VGroups to Selected warning done %d, failed %d, Noob coder is noob!", + "Copy to VGroups to Selected warning done %d, failed %d, All functions failed!", change, fail); } -- cgit v1.2.3 From 01a62964d9a95af2067b2c9ed9c645f104b5de21 Mon Sep 17 00:00:00 2001 From: Ove Murberg Henriksen Date: Tue, 24 Apr 2012 16:31:40 +0000 Subject: Cleanup only: Comments clarified, whitespaces adjusted for consistency, unneccesary code removed. --- source/blender/editors/object/object_vgroup.c | 61 +++++++++++---------------- 1 file changed, 24 insertions(+), 37 deletions(-) diff --git a/source/blender/editors/object/object_vgroup.c b/source/blender/editors/object/object_vgroup.c index cdec2e96b82..673345961e9 100644 --- a/source/blender/editors/object/object_vgroup.c +++ b/source/blender/editors/object/object_vgroup.c @@ -317,13 +317,12 @@ int ED_vgroup_copy_array(Object *ob, Object *ob_from) { MDeformVert **dvert_array_from, **dvf; MDeformVert **dvert_array, **dv; - int dvert_tot_from; - int dvert_tot; - int i; + int dvert_tot_from, dvert_tot, i; int defbase_tot_from= BLI_countlist(&ob_from->defbase); int defbase_tot= BLI_countlist(&ob->defbase); short new_vgroup= FALSE; + /*get vertex groups arrays*/ ED_vgroup_give_parray(ob_from->data, &dvert_array_from, &dvert_tot_from, FALSE); ED_vgroup_give_parray(ob->data, &dvert_array, &dvert_tot, FALSE); @@ -351,8 +350,8 @@ int ED_vgroup_copy_array(Object *ob, Object *ob_from) if (defbase_tot_from < defbase_tot) { /* correct vgroup indices because the number of vgroups is being reduced. */ int *remap= MEM_mallocN(sizeof(int) * (defbase_tot + 1), __func__); - for (i=0; i<=defbase_tot_from; i++) remap[i]= i; - for (; i<=defbase_tot; i++) remap[i]= 0; /* can't use these, so disable */ + for (i=0; i <= defbase_tot_from; i++) remap[i]= i; + for (; i <= defbase_tot; i++) remap[i]= 0; /* can't use these, so disable */ vgroup_remap_update_users(ob, remap); MEM_freeN(remap); @@ -388,7 +387,7 @@ int ED_vgroup_copy_single(Object *ob_dst, const Object *ob_src) bDeformGroup *dg_src, *dg_dst; /*get source deform group*/ - dg_src = BLI_findlink(&ob_src->defbase, (ob_src->actdef-1)); + 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)); @@ -406,34 +405,23 @@ int ED_vgroup_copy_single(Object *ob_dst, const Object *ob_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) { + 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; iweight = dw_src->weight; + 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; } -/*return distance between coordinates that are comparable to other instances but not right*/ -float comparable_distance_between_coordinates(const float co_1[3], const float co_2[3]){ - float x_dist, y_dist, z_dist, dist_XY_square, distance; - x_dist= co_1[0] - co_2[0]; - y_dist= co_1[1] - co_2[1]; - z_dist= co_1[2] - co_2[2]; - dist_XY_square= x_dist * x_dist + y_dist * y_dist; - distance= dist_XY_square + z_dist * z_dist; - return distance; -} - -/*Copy a single vertex group from source to destination with weights, get the closest weight on source*/ -int ED_vgroup_copy_by_closest_single(Object *ob_dst, const Object *ob_src) +/*Copy a single vertex group from source to destination with weights by nearest weight*/ +int ED_vgroup_copy_by_nearest_single(Object *ob_dst, const Object *ob_src) { bDeformGroup *dg_src, *dg_dst; MDeformVert **dv_array_src, **dv_array_dst; @@ -459,7 +447,7 @@ int ED_vgroup_copy_by_closest_single(Object *ob_dst, const Object *ob_src) }*/ /*get source deform group*/ - dg_src = BLI_findlink(&ob_src->defbase, (ob_src->actdef-1)); + 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)); @@ -470,8 +458,6 @@ int ED_vgroup_copy_by_closest_single(Object *ob_dst, const Object *ob_src) /*get meshes*/ me_dst= ob_dst->data; - - /*get derived mesh*/ dmesh_src= ob_src->derivedDeform; /*make node tree*/ @@ -488,8 +474,9 @@ int ED_vgroup_copy_by_closest_single(Object *ob_dst, const Object *ob_src) /*get vertices*/ mv_dst= me_dst->mvert; - /* Loop through the vertices and copy weight from closest to destination*/ + /* 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; @@ -500,11 +487,11 @@ int ED_vgroup_copy_by_closest_single(Object *ob_dst, const Object *ob_src) /*copy weight*/ 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; + dw_dst->weight= dw_src->weight; } + /*free memory and return*/ free_bvhtree_from_mesh(&tree_mesh_src); - return 1; } @@ -2866,16 +2853,16 @@ static int vertex_group_copy_to_selected_exec(bContext *C, wmOperator *op) void OBJECT_OT_vertex_group_copy_to_selected(wmOperatorType *ot) { /* identifiers */ - ot->name = "Copy Vertex Group to Selected"; - ot->idname = "OBJECT_OT_vertex_group_copy_to_selected"; - ot->description = "Copy Vertex Groups to other selected objects with matching indices"; + ot->name= "Copy Vertex Group to Selected"; + ot->idname= "OBJECT_OT_vertex_group_copy_to_selected"; + ot->description= "Copy Vertex Groups to other selected objects with matching indices"; /* api callbacks */ - ot->poll = vertex_group_poll; - ot->exec = vertex_group_copy_to_selected_exec; + ot->poll= vertex_group_poll; + ot->exec= vertex_group_copy_to_selected_exec; /* flags */ - ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; } static int vertex_group_copy_to_selected_single_exec(bContext *C, wmOperator *op) @@ -2891,7 +2878,7 @@ static int vertex_group_copy_to_selected_single_exec(bContext *C, wmOperator *op /*Try function for matching number of vertices*/ if(ED_vgroup_copy_single(obslc, obact)) change++; /*Try function for get weight from closest vertex*/ - else if(ED_vgroup_copy_by_closest_single(obslc, obact)) change++; + else if(ED_vgroup_copy_by_nearest_single(obslc, obact)) change++; /*Trigger error message*/ else fail++; /*Event notifiers for correct display of data*/ @@ -2902,7 +2889,7 @@ static int vertex_group_copy_to_selected_single_exec(bContext *C, wmOperator *op } CTX_DATA_END; - /*Report error when task could not be completed.*/ + /*Report error when task can not be completed with available functions.*/ if((change == 0 && fail == 0) || fail) { BKE_reportf(op->reports, RPT_ERROR, "Copy to VGroups to Selected warning done %d, failed %d, All functions failed!", -- cgit v1.2.3 From 0e9c52047be538fbf95759fa8b73bf0536d73de7 Mon Sep 17 00:00:00 2001 From: Ove Murberg Henriksen Date: Fri, 4 May 2012 21:28:21 +0000 Subject: Added incomplete function ED_vgroup_copy_by_nearest_face_single It does not work but is a starting point. --- source/blender/editors/object/object_vgroup.c | 91 ++++++++++++++++++++++----- 1 file changed, 75 insertions(+), 16 deletions(-) diff --git a/source/blender/editors/object/object_vgroup.c b/source/blender/editors/object/object_vgroup.c index 673345961e9..93eef06f402 100644 --- a/source/blender/editors/object/object_vgroup.c +++ b/source/blender/editors/object/object_vgroup.c @@ -421,7 +421,7 @@ int ED_vgroup_copy_single(Object *ob_dst, const Object *ob_src) } /*Copy a single vertex group from source to destination with weights by nearest weight*/ -int ED_vgroup_copy_by_nearest_single(Object *ob_dst, const Object *ob_src) +int ED_vgroup_copy_by_nearest_vertex_single(Object *ob_dst, const Object *ob_src) { bDeformGroup *dg_src, *dg_dst; MDeformVert **dv_array_src, **dv_array_dst; @@ -433,19 +433,6 @@ int ED_vgroup_copy_by_nearest_single(Object *ob_dst, const Object *ob_src) DerivedMesh *dmesh_src; int dv_tot_src, dv_tot_dst, i, index_dst, index_src; - /*TODO: Check if it should be used and return 0 if not*/ - /*TODO: Bugfix, if position of object center is not similar, the copy will fail*/ - /*suggested sollution: temporarily set object center to geometry center on both source and target*/ - /*suggested sollution: temporarily manipulate destination object center to align with source*/ - /*suggested solution: user choise*/ - /*TODO: take scale into account*/ - /*memory safety TODO make this work. - if (tree_mesh_src.tree == NULL) - { - OUT_OF_MEMORY(); - return; - }*/ - /*get source deform group*/ dg_src= BLI_findlink(&ob_src->defbase, (ob_src->actdef-1)); @@ -475,7 +462,7 @@ int ED_vgroup_copy_by_nearest_single(Object *ob_dst, const Object *ob_src) mv_dst= me_dst->mvert; /* 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; @@ -495,6 +482,76 @@ int ED_vgroup_copy_by_nearest_single(Object *ob_dst, const Object *ob_src) return 1; } +/*Copy a single vertex group from source to destination with weights by nearest weight*/ +int ED_vgroup_copy_by_nearest_face_single(Object *ob_dst, Object *ob_src) +{ + bDeformGroup *dg_src, *dg_dst; + MDeformVert **dv_array_src, **dv_array_dst; + MDeformWeight *dw_dst, *dw_src; + MVert *mv_dst; + MFace *mface_src; + Mesh *me_dst, *me_src; + BVHTreeFromMesh tree_mesh_faces_src; + BVHTreeNearest nearest; + DerivedMesh *dmesh_src; + int dv_tot_src, dv_tot_dst, i, index_dst, index_src; + float weight; + + /*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 meshes*/ + me_dst= ob_dst->data; + me_src= ob_src->data; + dmesh_src= ob_src->derivedDeform; + + /*make node tree*/ + DM_ensure_tessface(dmesh_src); + bvhtree_from_mesh_faces(&tree_mesh_faces_src, dmesh_src, 0.0, 2, 6); + + /*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); + + /*get vertices*/ + mv_dst= me_dst->mvert; + + /* 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; + + /*Node tree accelerated search for closest face*/ + BLI_bvhtree_find_nearest(tree_mesh_faces_src.tree, mv_dst->co, &nearest, tree_mesh_faces_src.nearest_callback, &tree_mesh_faces_src); + + /*get*/ + mface_src= me_src->mface + nearest.index; + dw_src= defvert_verify_index(dv_array_src[mface_src->v1], index_src); + weight= dw_src->weight; + weight= 0; + + /*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; +} + /* for Mesh in Object mode */ /* allows editmode for Lattice */ static void ED_vgroup_nr_vert_add(Object *ob, @@ -2878,7 +2935,9 @@ static int vertex_group_copy_to_selected_single_exec(bContext *C, wmOperator *op /*Try function for matching number of vertices*/ if(ED_vgroup_copy_single(obslc, obact)) change++; /*Try function for get weight from closest vertex*/ - else if(ED_vgroup_copy_by_nearest_single(obslc, obact)) change++; + /*TODO: try this function*/ + /*Try function for get weight from closest face*/ + else if(ED_vgroup_copy_by_nearest_face_single(obslc, obact)) change++; /*Trigger error message*/ else fail++; /*Event notifiers for correct display of data*/ -- cgit v1.2.3 From 2624c871bdb12ea08891d20b64b10524f66c0382 Mon Sep 17 00:00:00 2001 From: Ove Murberg Henriksen Date: Sun, 6 May 2012 17:19:16 +0000 Subject: ED_vgroup_copy_by_nearest_vertex_single: Added transformation into target space ED_vgroup_copy_by_nearest_face_single: Is incomplete. BVHTree fails. --- source/blender/editors/object/object_vgroup.c | 40 +++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 6 deletions(-) diff --git a/source/blender/editors/object/object_vgroup.c b/source/blender/editors/object/object_vgroup.c index 93eef06f402..ea0b7542886 100644 --- a/source/blender/editors/object/object_vgroup.c +++ b/source/blender/editors/object/object_vgroup.c @@ -421,7 +421,7 @@ int ED_vgroup_copy_single(Object *ob_dst, const Object *ob_src) } /*Copy a single vertex group from source to destination with weights by nearest weight*/ -int ED_vgroup_copy_by_nearest_vertex_single(Object *ob_dst, const Object *ob_src) +int ED_vgroup_copy_by_nearest_vertex_single(Object *ob_dst, Object *ob_src) { bDeformGroup *dg_src, *dg_dst; MDeformVert **dv_array_src, **dv_array_dst; @@ -432,6 +432,7 @@ int ED_vgroup_copy_by_nearest_vertex_single(Object *ob_dst, const Object *ob_src BVHTreeNearest nearest; DerivedMesh *dmesh_src; int dv_tot_src, dv_tot_dst, i, index_dst, index_src; + float tmp_co[3], tmp_mat[4][4]; /*get source deform group*/ dg_src= BLI_findlink(&ob_src->defbase, (ob_src->actdef-1)); @@ -461,6 +462,11 @@ int ED_vgroup_copy_by_nearest_vertex_single(Object *ob_dst, const Object *ob_src /*get vertices*/ mv_dst= me_dst->mvert; + /*Prepearing 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 from nearest weight*/ for(i=0; i < me_dst->totvert; i++, mv_dst++, dv_array_dst++){ @@ -468,8 +474,11 @@ int ED_vgroup_copy_by_nearest_vertex_single(Object *ob_dst, const Object *ob_src nearest.index= -1; nearest.dist= FLT_MAX; + /*Transforming 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, mv_dst->co, &nearest, tree_mesh_src.nearest_callback, &tree_mesh_src); + BLI_bvhtree_find_nearest(tree_mesh_src.tree, tmp_co, &nearest, tree_mesh_src.nearest_callback, &tree_mesh_src); /*copy weight*/ dw_src= defvert_verify_index(dv_array_src[nearest.index], index_src); @@ -483,6 +492,7 @@ int ED_vgroup_copy_by_nearest_vertex_single(Object *ob_dst, const Object *ob_src } /*Copy a single vertex group from source to destination with weights by nearest weight*/ +/*TODO: transform into target space as in by_vertex function. postphoned due to easier testing during development*/ int ED_vgroup_copy_by_nearest_face_single(Object *ob_dst, Object *ob_src) { bDeformGroup *dg_src, *dg_dst; @@ -495,7 +505,7 @@ int ED_vgroup_copy_by_nearest_face_single(Object *ob_dst, Object *ob_src) BVHTreeNearest nearest; DerivedMesh *dmesh_src; int dv_tot_src, dv_tot_dst, i, index_dst, index_src; - float weight; + float weight/*, tot_dist*/; /*get source deform group*/ dg_src= BLI_findlink(&ob_src->defbase, (ob_src->actdef-1)); @@ -510,12 +520,13 @@ int ED_vgroup_copy_by_nearest_face_single(Object *ob_dst, Object *ob_src) /*get meshes*/ me_dst= ob_dst->data; me_src= ob_src->data; - dmesh_src= ob_src->derivedDeform; + dmesh_src= ob_src->derivedDeform; /*sergey- : this might easily be null?? (using ob_src.deriveddeform*/ /*make node tree*/ DM_ensure_tessface(dmesh_src); bvhtree_from_mesh_faces(&tree_mesh_faces_src, dmesh_src, 0.0, 2, 6); + /*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); @@ -529,6 +540,7 @@ int ED_vgroup_copy_by_nearest_face_single(Object *ob_dst, Object *ob_src) /* 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; @@ -536,11 +548,27 @@ int ED_vgroup_copy_by_nearest_face_single(Object *ob_dst, Object *ob_src) /*Node tree accelerated search for closest face*/ BLI_bvhtree_find_nearest(tree_mesh_faces_src.tree, mv_dst->co, &nearest, tree_mesh_faces_src.nearest_callback, &tree_mesh_faces_src); - /*get*/ + /*get weight*/ mface_src= me_src->mface + nearest.index; + /*tot_dist= ()+()+(); use a comparable distance + if(mface_src->v4){ + tot_dist+= (); + }*/ dw_src= defvert_verify_index(dv_array_src[mface_src->v1], index_src); weight= dw_src->weight; - weight= 0; + dw_src= defvert_verify_index(dv_array_src[mface_src->v2], index_src); + weight+= dw_src->weight; + dw_src= defvert_verify_index(dv_array_src[mface_src->v3], index_src); + weight+= dw_src->weight; + if(mface_src->v4){ + dw_src= defvert_verify_index(dv_array_src[mface_src->v4], index_src); + weight+= dw_src->weight; + weight/=4; + } + else{ + weight/=3; + } + /*copy weight*/ dw_dst= defvert_verify_index(*dv_array_dst, index_dst); -- cgit v1.2.3 From f61e50aa4ea462b3e369764843e868c4692143bd Mon Sep 17 00:00:00 2001 From: Ove Murberg Henriksen Date: Wed, 9 May 2012 16:24:46 +0000 Subject: it works! Even it compiles some code might still not be implemented. (I know the gui lacks). --- source/blender/editors/object/object_vgroup.c | 256 ++++++++++++++++++++++++++ 1 file changed, 256 insertions(+) diff --git a/source/blender/editors/object/object_vgroup.c b/source/blender/editors/object/object_vgroup.c index 0c0611d3d33..5e575c890b4 100644 --- a/source/blender/editors/object/object_vgroup.c +++ b/source/blender/editors/object/object_vgroup.c @@ -376,6 +376,210 @@ int ED_vgroup_copy_array(Object *ob, Object *ob_from) return 1; } +/*Copy a single vertex group from source to destination with weights*/ +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; iweight= dw_src->weight; + } + + return 1; +} + +/*Copy a single vertex group from source to destination with weights by nearest weight*/ +int ED_vgroup_copy_by_nearest_vertex_single(Object *ob_dst, Object *ob_src) +{ + bDeformGroup *dg_src, *dg_dst; + MDeformVert **dv_array_src, **dv_array_dst; + MDeformWeight *dw_dst, *dw_src; + MVert *mv_dst; + Mesh *me_dst; + BVHTreeFromMesh tree_mesh_src; + BVHTreeNearest nearest; + DerivedMesh *dmesh_src; + int dv_tot_src, dv_tot_dst, i, index_dst, index_src; + float tmp_co[3], tmp_mat[4][4]; + + /*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 meshes*/ + me_dst= ob_dst->data; + dmesh_src= ob_src->derivedDeform; + + /*make node tree*/ + bvhtree_from_mesh_verts(&tree_mesh_src, dmesh_src, 0.0, 2, 6); + + /*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); + + /*get vertices*/ + mv_dst= me_dst->mvert; + + /*Prepearing 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 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; + + /*Transforming 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); + + /*copy weight*/ + 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; +} + +/*Copy a single vertex group from source to destination with weights by nearest weight*/ +/*TODO: transform into target space as in by_vertex function. postphoned due to easier testing during development*/ +int ED_vgroup_copy_by_nearest_face_single(Object *ob_dst, Object *ob_src) +{ + bDeformGroup *dg_src, *dg_dst; + MDeformVert **dv_array_src, **dv_array_dst; + MDeformWeight *dw_dst, *dw_src; + MVert *mv_dst; + MFace *mface_src; + Mesh *me_dst, *me_src; + BVHTreeFromMesh tree_mesh_faces_src; + BVHTreeNearest nearest; + DerivedMesh *dmesh_src; + int dv_tot_src, dv_tot_dst, i, index_dst, index_src; + float weight/*, tot_dist*/; + + /*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 meshes*/ + me_dst= ob_dst->data; + me_src= ob_src->data; + dmesh_src= ob_src->derivedDeform; /*sergey- : this might easily be null?? (using ob_src.deriveddeform*/ + + /*make node tree*/ + DM_ensure_tessface(dmesh_src); + bvhtree_from_mesh_faces(&tree_mesh_faces_src, dmesh_src, 0.0, 2, 6); + + + /*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); + + /*get vertices*/ + mv_dst= me_dst->mvert; + + /* 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; + + /*Node tree accelerated search for closest face*/ + BLI_bvhtree_find_nearest(tree_mesh_faces_src.tree, mv_dst->co, &nearest, tree_mesh_faces_src.nearest_callback, &tree_mesh_faces_src); + + /*get weight*/ + mface_src= me_src->mface + nearest.index; + /*tot_dist= ()+()+(); use a comparable distance + if(mface_src->v4){ + tot_dist+= (); + }*/ + dw_src= defvert_verify_index(dv_array_src[mface_src->v1], index_src); + weight= dw_src->weight; + dw_src= defvert_verify_index(dv_array_src[mface_src->v2], index_src); + weight+= dw_src->weight; + dw_src= defvert_verify_index(dv_array_src[mface_src->v3], index_src); + weight+= dw_src->weight; + if(mface_src->v4){ + dw_src= defvert_verify_index(dv_array_src[mface_src->v4], index_src); + weight+= dw_src->weight; + weight/=4; + } + else{ + weight/=3; + } + + + /*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; +} + /* for Mesh in Object mode */ /* allows editmode for Lattice */ @@ -2760,6 +2964,58 @@ void OBJECT_OT_vertex_group_copy_to_selected(wmOperatorType *ot) ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; } +static int vertex_group_copy_to_selected_single_exec(bContext *C, wmOperator *op) +{ + Object *obact= CTX_data_active_object(C); + int change= 0; + int fail= 0; + + /*Macro to loop through selected objects and perform operation*/ + CTX_DATA_BEGIN(C, Object*, obslc, selected_editable_objects) + { + if(obact != obslc) { + /*Try function for matching number of vertices*/ + if(ED_vgroup_copy_single(obslc, obact)) change++; + /*Try function for get weight from closest vertex*/ + /*TODO: try this function*/ + /*Try function for get weight from closest face*/ + else if(ED_vgroup_copy_by_nearest_face_single(obslc, obact)) change++; + /*Trigger error message*/ + else fail++; + /*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; + + /*Report error when task can not be completed with available functions.*/ + if((change == 0 && fail == 0) || fail) { + BKE_reportf(op->reports, RPT_ERROR, + "Copy to VGroups to Selected warning done %d, failed %d, All functions failed!", + change, fail); + } + + return OPERATOR_FINISHED; +} + +/*Transfer vertex group with weight to selected*/ +void OBJECT_OT_vertex_group_copy_to_selected_single(wmOperatorType *ot) +{ + /* identifiers */ + ot->name= "Copy a Vertex Group to Selected"; + ot->idname= "OBJECT_OT_vertex_group_copy_to_selected_single"; + ot->description= "Copy a vertex group to other selected objects with matching indices"; + + /* api callbacks */ + ot->poll= vertex_group_poll; + ot->exec= vertex_group_copy_to_selected_single_exec; + + /* flags */ + ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; +} + static EnumPropertyItem vgroup_items[] = { {0, NULL, 0, NULL, NULL} }; -- cgit v1.2.3 From 8776458e74f329e61977f4539be00bed9e2f0d10 Mon Sep 17 00:00:00 2001 From: Ove Murberg Henriksen Date: Wed, 9 May 2012 16:38:49 +0000 Subject: gui fixed --- release/scripts/startup/bl_ui/space_view3d_toolbar.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/release/scripts/startup/bl_ui/space_view3d_toolbar.py b/release/scripts/startup/bl_ui/space_view3d_toolbar.py index f220ec19bfe..f33c9051989 100644 --- a/release/scripts/startup/bl_ui/space_view3d_toolbar.py +++ b/release/scripts/startup/bl_ui/space_view3d_toolbar.py @@ -983,6 +983,8 @@ class VIEW3D_PT_tools_weightpaint(View3DPanel, Panel): col = layout.column() col.active = ob.vertex_groups.active is not None + col.operator("object.vertex_group_copy_to_selected", text="Transfer weight All") + col.operator("object.vertex_group_copy_to_selected_single", text="Transfer weight") col.operator("object.vertex_group_normalize_all", text="Normalize All") col.operator("object.vertex_group_normalize", text="Normalize") col.operator("object.vertex_group_mirror", text="Mirror") -- cgit v1.2.3 From f95f3d96976e24f7fbf8e268e853ef1d0106e624 Mon Sep 17 00:00:00 2001 From: Ove Murberg Henriksen Date: Fri, 11 May 2012 21:33:24 +0000 Subject: Incomplete ED_vgroup_copy_by_nearest_face_single() compiles. --- source/blender/editors/object/object_vgroup.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/source/blender/editors/object/object_vgroup.c b/source/blender/editors/object/object_vgroup.c index 33a9d9b00f0..ee690b16229 100644 --- a/source/blender/editors/object/object_vgroup.c +++ b/source/blender/editors/object/object_vgroup.c @@ -538,6 +538,11 @@ int ED_vgroup_copy_by_nearest_face_single(Object *ob_dst, Object *ob_src) /*get vertices*/ mv_dst= me_dst->mvert; + /*get faces*/ + mface_src= dmesh_src->getTessFaceArray(dmesh_src); + + /*printf("test % \n", *mface_src);*/ + /* Loop through the vertices and copy weight from nearest weight*/ for(i=0; i < me_dst->totvert; i++, mv_dst++, dv_array_dst++){ @@ -549,15 +554,11 @@ int ED_vgroup_copy_by_nearest_face_single(Object *ob_dst, Object *ob_src) BLI_bvhtree_find_nearest(tree_mesh_faces_src.tree, mv_dst->co, &nearest, tree_mesh_faces_src.nearest_callback, &tree_mesh_faces_src); /*get weight*/ - printf("test %d %d \n", me_src->mface->v1, (*me_src->mface).v1); - mface_src= me_src->mface + nearest.index; /*tot_dist= ()+()+(); use a comparable distance if(mface_src->v4){ tot_dist+= (); }*/ - printf("test %d \n", (*mface_src).v1); - dv_array_src+= mface_src->v1; - dw_src= defvert_verify_index(*dv_array_src, index_src); + dw_src= defvert_verify_index(dv_array_src[mface_src[nearest.index].v1], index_src); weight= dw_src->weight; dw_src= defvert_verify_index(dv_array_src[mface_src->v2], index_src); weight+= dw_src->weight; -- cgit v1.2.3 From c40d445ef7fe462b26ac5303215c23495f2c77c5 Mon Sep 17 00:00:00 2001 From: Ove Murberg Henriksen Date: Sat, 12 May 2012 00:37:45 +0000 Subject: ED_vgroup_copy_by_nearest_face_single() Is supposed to work, but something funny is going on. (logick error) Function also needs optimization. --- source/blender/editors/object/object_vgroup.c | 93 +++++++++++++++++++-------- 1 file changed, 65 insertions(+), 28 deletions(-) diff --git a/source/blender/editors/object/object_vgroup.c b/source/blender/editors/object/object_vgroup.c index ee690b16229..dff7dc6636c 100644 --- a/source/blender/editors/object/object_vgroup.c +++ b/source/blender/editors/object/object_vgroup.c @@ -491,21 +491,30 @@ int ED_vgroup_copy_by_nearest_vertex_single(Object *ob_dst, Object *ob_src) return 1; } +float sqr_dist_v3v3(float v1[3], float v2[3]) +{ + float d[3]; + d[0]= v2[0]-v1[0]; + d[1]= v2[1]-v1[1]; + d[2]= v2[2]-v1[2]; + return dot_v3v3(d, d); +} + /*Copy a single vertex group from source to destination with weights by nearest weight*/ /*TODO: transform into target space as in by_vertex function. postphoned due to easier testing during development*/ int ED_vgroup_copy_by_nearest_face_single(Object *ob_dst, Object *ob_src) { bDeformGroup *dg_src, *dg_dst; + Mesh *me_dst; + DerivedMesh *dmesh_src; + BVHTreeFromMesh tree_mesh_faces_src = {NULL}; MDeformVert **dv_array_src, **dv_array_dst; - MDeformWeight *dw_dst, *dw_src; - MVert *mv_dst; + MVert *mv_dst, *mv_src; MFace *mface_src; - Mesh *me_dst, *me_src; - BVHTreeFromMesh tree_mesh_faces_src = {NULL}; BVHTreeNearest nearest; - DerivedMesh *dmesh_src; + MDeformWeight *dw_dst, *dw_src; int dv_tot_src, dv_tot_dst, i, index_dst, index_src; - float weight/*, tot_dist*/; + float weight, tot_dist, dist_v1, dist_v2, dist_v3, dist_v4; /*get source deform group*/ dg_src= BLI_findlink(&ob_src->defbase, (ob_src->actdef-1)); @@ -519,14 +528,12 @@ int ED_vgroup_copy_by_nearest_face_single(Object *ob_dst, Object *ob_src) /*get meshes*/ me_dst= ob_dst->data; - me_src= ob_src->data; /*mfaces does not exist*/ dmesh_src= ob_src->derivedDeform; /*sergey- : this might easily be null?? (using ob_src.deriveddeform*/ /*make node tree*/ DM_ensure_tessface(dmesh_src); bvhtree_from_mesh_faces(&tree_mesh_faces_src, dmesh_src, 0.0, 2, 6); - /*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); @@ -537,16 +544,15 @@ int ED_vgroup_copy_by_nearest_face_single(Object *ob_dst, Object *ob_src) /*get vertices*/ mv_dst= me_dst->mvert; + mv_src= dmesh_src->getVertArray(dmesh_src); /*get faces*/ mface_src= dmesh_src->getTessFaceArray(dmesh_src); - /*printf("test % \n", *mface_src);*/ - /* 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*/ + /*Reset nearest*//*can I accellerate further with tweaking this=*/ nearest.index= -1; nearest.dist= FLT_MAX; @@ -554,25 +560,56 @@ int ED_vgroup_copy_by_nearest_face_single(Object *ob_dst, Object *ob_src) BLI_bvhtree_find_nearest(tree_mesh_faces_src.tree, mv_dst->co, &nearest, tree_mesh_faces_src.nearest_callback, &tree_mesh_faces_src); /*get weight*/ - /*tot_dist= ()+()+(); use a comparable distance - if(mface_src->v4){ - tot_dist+= (); - }*/ - dw_src= defvert_verify_index(dv_array_src[mface_src[nearest.index].v1], index_src); - weight= dw_src->weight; - dw_src= defvert_verify_index(dv_array_src[mface_src->v2], index_src); - weight+= dw_src->weight; - dw_src= defvert_verify_index(dv_array_src[mface_src->v3], index_src); - weight+= dw_src->weight; - if(mface_src->v4){ - dw_src= defvert_verify_index(dv_array_src[mface_src->v4], index_src); - weight+= dw_src->weight; - weight/=4; - } + dist_v1= sqr_dist_v3v3(mv_dst->co, mv_src[mface_src[nearest.index].v1].co); + dist_v2= sqr_dist_v3v3(mv_dst->co, mv_src[mface_src[nearest.index].v2].co); + dist_v3= sqr_dist_v3v3(mv_dst->co, mv_src[mface_src[nearest.index].v3].co); + + /*get weight from overlapping vert if any*/ + if(dist_v1 == 0)weight= defvert_verify_index(dv_array_src[mface_src[nearest.index].v1], index_src)->weight; + if(dist_v2 == 0)weight= defvert_verify_index(dv_array_src[mface_src[nearest.index].v2], index_src)->weight; + if(dist_v3 == 0)weight= defvert_verify_index(dv_array_src[mface_src[nearest.index].v3], index_src)->weight; + + /*interpolate weight*/ else{ - weight/=3; - } + /*check for quad*/ + if(mface_src[nearest.index].v4){ + dist_v4= sqr_dist_v3v3(mv_dst->co, mv_src[mface_src->v4].co); + + /*check if vert 4 is overlapping*/ + if(dist_v4 == 0)weight= defvert_verify_index(dv_array_src[mface_src[nearest.index].v4], index_src)->weight; + + /*get weight from quad*/ + else{ + tot_dist= dist_v1 + dist_v2 + dist_v3 + dist_v4; + + dw_src= defvert_verify_index(dv_array_src[mface_src[nearest.index].v1], index_src); + weight= dw_src->weight * dist_v1; + dw_src= defvert_verify_index(dv_array_src[mface_src[nearest.index].v2], index_src); + weight+= dw_src->weight * dist_v2; + dw_src= defvert_verify_index(dv_array_src[mface_src[nearest.index].v3], index_src); + weight+= dw_src->weight * dist_v3; + dw_src= defvert_verify_index(dv_array_src[mface_src[nearest.index].v4], index_src); + weight+= dw_src->weight * dist_v4; + + weight/=tot_dist; + } + } + + /*get weight from triangle*/ + else{ + tot_dist= dist_v1 + dist_v2 + dist_v3; + + dw_src= defvert_verify_index(dv_array_src[mface_src[nearest.index].v1], index_src); + weight= dw_src->weight * dist_v1; + dw_src= defvert_verify_index(dv_array_src[mface_src[nearest.index].v2], index_src); + weight+= dw_src->weight * dist_v2; + dw_src= defvert_verify_index(dv_array_src[mface_src[nearest.index].v3], index_src); + weight+= dw_src->weight * dist_v3; + + weight/=tot_dist; + } + } /*copy weight*/ dw_dst= defvert_verify_index(*dv_array_dst, index_dst); -- cgit v1.2.3 From 8d7de250f3b990ecfb507615aac32acf9a332259 Mon Sep 17 00:00:00 2001 From: Ove Murberg Henriksen Date: Sat, 12 May 2012 01:04:12 +0000 Subject: Tiny bit of cleaning. --- source/blender/editors/object/object_vgroup.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/source/blender/editors/object/object_vgroup.c b/source/blender/editors/object/object_vgroup.c index dff7dc6636c..7d0adaa587e 100644 --- a/source/blender/editors/object/object_vgroup.c +++ b/source/blender/editors/object/object_vgroup.c @@ -528,7 +528,7 @@ int ED_vgroup_copy_by_nearest_face_single(Object *ob_dst, Object *ob_src) /*get meshes*/ me_dst= ob_dst->data; - dmesh_src= ob_src->derivedDeform; /*sergey- : this might easily be null?? (using ob_src.deriveddeform*/ + dmesh_src= ob_src->derivedDeform; /*make node tree*/ DM_ensure_tessface(dmesh_src); @@ -552,7 +552,7 @@ int ED_vgroup_copy_by_nearest_face_single(Object *ob_dst, Object *ob_src) /* 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*//*can I accellerate further with tweaking this=*/ + /*Reset nearest*/ nearest.index= -1; nearest.dist= FLT_MAX; @@ -560,14 +560,18 @@ int ED_vgroup_copy_by_nearest_face_single(Object *ob_dst, Object *ob_src) BLI_bvhtree_find_nearest(tree_mesh_faces_src.tree, mv_dst->co, &nearest, tree_mesh_faces_src.nearest_callback, &tree_mesh_faces_src); /*get weight*/ + + /*TODO: Have to project onto face to get a decent result*/ + + /*get distances*/ dist_v1= sqr_dist_v3v3(mv_dst->co, mv_src[mface_src[nearest.index].v1].co); dist_v2= sqr_dist_v3v3(mv_dst->co, mv_src[mface_src[nearest.index].v2].co); dist_v3= sqr_dist_v3v3(mv_dst->co, mv_src[mface_src[nearest.index].v3].co); /*get weight from overlapping vert if any*/ - if(dist_v1 == 0)weight= defvert_verify_index(dv_array_src[mface_src[nearest.index].v1], index_src)->weight; - if(dist_v2 == 0)weight= defvert_verify_index(dv_array_src[mface_src[nearest.index].v2], index_src)->weight; - if(dist_v3 == 0)weight= defvert_verify_index(dv_array_src[mface_src[nearest.index].v3], index_src)->weight; + if(dist_v1 == 0) weight= defvert_verify_index(dv_array_src[mface_src[nearest.index].v1], index_src)->weight; + if(dist_v2 == 0) weight= defvert_verify_index(dv_array_src[mface_src[nearest.index].v2], index_src)->weight; + if(dist_v3 == 0) weight= defvert_verify_index(dv_array_src[mface_src[nearest.index].v3], index_src)->weight; /*interpolate weight*/ else{ @@ -577,7 +581,7 @@ int ED_vgroup_copy_by_nearest_face_single(Object *ob_dst, Object *ob_src) dist_v4= sqr_dist_v3v3(mv_dst->co, mv_src[mface_src->v4].co); /*check if vert 4 is overlapping*/ - if(dist_v4 == 0)weight= defvert_verify_index(dv_array_src[mface_src[nearest.index].v4], index_src)->weight; + if(dist_v4 == 0) weight= defvert_verify_index(dv_array_src[mface_src[nearest.index].v4], index_src)->weight; /*get weight from quad*/ else{ @@ -592,7 +596,7 @@ int ED_vgroup_copy_by_nearest_face_single(Object *ob_dst, Object *ob_src) dw_src= defvert_verify_index(dv_array_src[mface_src[nearest.index].v4], index_src); weight+= dw_src->weight * dist_v4; - weight/=tot_dist; + weight/= tot_dist; } } @@ -607,7 +611,7 @@ int ED_vgroup_copy_by_nearest_face_single(Object *ob_dst, Object *ob_src) dw_src= defvert_verify_index(dv_array_src[mface_src[nearest.index].v3], index_src); weight+= dw_src->weight * dist_v3; - weight/=tot_dist; + weight/= tot_dist; } } -- cgit v1.2.3 From 097ebb0a6366741d6addbd81e0f6953dfa878067 Mon Sep 17 00:00:00 2001 From: Ove Murberg Henriksen Date: Sat, 12 May 2012 02:13:26 +0000 Subject: ED_vgroup_copy_by_nearest_face_single() excluded 4th vertex in faces for better result. --- source/blender/editors/object/object_vgroup.c | 80 +++++++++++++++++++-------- 1 file changed, 57 insertions(+), 23 deletions(-) diff --git a/source/blender/editors/object/object_vgroup.c b/source/blender/editors/object/object_vgroup.c index 7d0adaa587e..1b67fe146ab 100644 --- a/source/blender/editors/object/object_vgroup.c +++ b/source/blender/editors/object/object_vgroup.c @@ -514,7 +514,7 @@ int ED_vgroup_copy_by_nearest_face_single(Object *ob_dst, Object *ob_src) BVHTreeNearest nearest; MDeformWeight *dw_dst, *dw_src; int dv_tot_src, dv_tot_dst, i, index_dst, index_src; - float weight, tot_dist, dist_v1, dist_v2, dist_v3, dist_v4; + float weight, tot_dist, dist_v1, dist_v2, dist_v3, dist_v4, tmp_co[3]; /*get source deform group*/ dg_src= BLI_findlink(&ob_src->defbase, (ob_src->actdef-1)); @@ -556,17 +556,21 @@ int ED_vgroup_copy_by_nearest_face_single(Object *ob_dst, Object *ob_src) nearest.index= -1; nearest.dist= FLT_MAX; + /*set destination coordinate*/ + copy_v3_v3(tmp_co, mv_dst->co); + /*Node tree accelerated search for closest face*/ - BLI_bvhtree_find_nearest(tree_mesh_faces_src.tree, mv_dst->co, &nearest, tree_mesh_faces_src.nearest_callback, &tree_mesh_faces_src); + BLI_bvhtree_find_nearest(tree_mesh_faces_src.tree, tmp_co, &nearest, tree_mesh_faces_src.nearest_callback, &tree_mesh_faces_src); /*get weight*/ /*TODO: Have to project onto face to get a decent result*/ + /*Smart solution might be to just substract the distance difference to plane instead.*/ /*get distances*/ - dist_v1= sqr_dist_v3v3(mv_dst->co, mv_src[mface_src[nearest.index].v1].co); - dist_v2= sqr_dist_v3v3(mv_dst->co, mv_src[mface_src[nearest.index].v2].co); - dist_v3= sqr_dist_v3v3(mv_dst->co, mv_src[mface_src[nearest.index].v3].co); + dist_v1= sqr_dist_v3v3(tmp_co, mv_src[mface_src[nearest.index].v1].co); + dist_v2= sqr_dist_v3v3(tmp_co, mv_src[mface_src[nearest.index].v2].co); + dist_v3= sqr_dist_v3v3(tmp_co, mv_src[mface_src[nearest.index].v3].co); /*get weight from overlapping vert if any*/ if(dist_v1 == 0) weight= defvert_verify_index(dv_array_src[mface_src[nearest.index].v1], index_src)->weight; @@ -578,25 +582,57 @@ int ED_vgroup_copy_by_nearest_face_single(Object *ob_dst, Object *ob_src) /*check for quad*/ if(mface_src[nearest.index].v4){ - dist_v4= sqr_dist_v3v3(mv_dst->co, mv_src[mface_src->v4].co); + dist_v4= sqr_dist_v3v3(tmp_co, mv_src[mface_src->v4].co); /*check if vert 4 is overlapping*/ if(dist_v4 == 0) weight= defvert_verify_index(dv_array_src[mface_src[nearest.index].v4], index_src)->weight; /*get weight from quad*/ else{ - tot_dist= dist_v1 + dist_v2 + dist_v3 + dist_v4; - - dw_src= defvert_verify_index(dv_array_src[mface_src[nearest.index].v1], index_src); - weight= dw_src->weight * dist_v1; - dw_src= defvert_verify_index(dv_array_src[mface_src[nearest.index].v2], index_src); - weight+= dw_src->weight * dist_v2; - dw_src= defvert_verify_index(dv_array_src[mface_src[nearest.index].v3], index_src); - weight+= dw_src->weight * dist_v3; - dw_src= defvert_verify_index(dv_array_src[mface_src[nearest.index].v4], index_src); - weight+= dw_src->weight * dist_v4; - - weight/= tot_dist; + if(dist_v1 > dist_v2||dist_v1 > dist_v3||dist_v1 > dist_v4){ + /*exclude v1 and get weight from the 3 closest*/ + tot_dist= dist_v4 + dist_v2 + dist_v3; + + dw_src= defvert_verify_index(dv_array_src[mface_src[nearest.index].v4], index_src); + weight= dw_src->weight * (1-dist_v4/tot_dist); + dw_src= defvert_verify_index(dv_array_src[mface_src[nearest.index].v2], index_src); + weight+= dw_src->weight * (1-dist_v2/tot_dist); + dw_src= defvert_verify_index(dv_array_src[mface_src[nearest.index].v3], index_src); + weight+= dw_src->weight * (1-dist_v3/tot_dist); + } + else if(dist_v2 > dist_v3||dist_v2 > dist_v4){ + /*exclude v2 and get weight from the 3 closest*/ + tot_dist= dist_v1 + dist_v4 + dist_v3; + + dw_src= defvert_verify_index(dv_array_src[mface_src[nearest.index].v1], index_src); + weight= dw_src->weight * (1-dist_v1/tot_dist); + dw_src= defvert_verify_index(dv_array_src[mface_src[nearest.index].v4], index_src); + weight+= dw_src->weight * (1-dist_v4/tot_dist); + dw_src= defvert_verify_index(dv_array_src[mface_src[nearest.index].v3], index_src); + weight+= dw_src->weight * (1-dist_v3/tot_dist); + } + else if(dist_v3 > dist_v4){ + /*exclude v3 and get weight from the 3 closest*/ + tot_dist= dist_v1 + dist_v2 + dist_v4; + + dw_src= defvert_verify_index(dv_array_src[mface_src[nearest.index].v1], index_src); + weight= dw_src->weight * (1-dist_v1/tot_dist); + dw_src= defvert_verify_index(dv_array_src[mface_src[nearest.index].v2], index_src); + weight+= dw_src->weight * (1-dist_v2/tot_dist); + dw_src= defvert_verify_index(dv_array_src[mface_src[nearest.index].v4], index_src); + weight+= dw_src->weight * (1-dist_v4/tot_dist); + } + else{ + /*exclude v4 and get weight from the 3 closest*/ + tot_dist= dist_v1 + dist_v2 + dist_v3; + + dw_src= defvert_verify_index(dv_array_src[mface_src[nearest.index].v1], index_src); + weight= dw_src->weight * (1-dist_v1/tot_dist); + dw_src= defvert_verify_index(dv_array_src[mface_src[nearest.index].v2], index_src); + weight+= dw_src->weight * (1-dist_v2/tot_dist); + dw_src= defvert_verify_index(dv_array_src[mface_src[nearest.index].v3], index_src); + weight+= dw_src->weight * (1-dist_v3/tot_dist); + } } } @@ -605,13 +641,11 @@ int ED_vgroup_copy_by_nearest_face_single(Object *ob_dst, Object *ob_src) tot_dist= dist_v1 + dist_v2 + dist_v3; dw_src= defvert_verify_index(dv_array_src[mface_src[nearest.index].v1], index_src); - weight= dw_src->weight * dist_v1; + weight= dw_src->weight * (1-dist_v1/tot_dist); dw_src= defvert_verify_index(dv_array_src[mface_src[nearest.index].v2], index_src); - weight+= dw_src->weight * dist_v2; + weight+= dw_src->weight * (1-dist_v2/tot_dist); dw_src= defvert_verify_index(dv_array_src[mface_src[nearest.index].v3], index_src); - weight+= dw_src->weight * dist_v3; - - weight/= tot_dist; + weight+= dw_src->weight * (1-dist_v3/tot_dist); } } -- cgit v1.2.3 From 66f4f3a9f5bacbb661b87a0463b0875fad00d8be Mon Sep 17 00:00:00 2001 From: Ove Murberg Henriksen Date: Sat, 12 May 2012 03:32:13 +0000 Subject: some more cleanup --- source/blender/editors/object/object_vgroup.c | 52 +++++++++++++-------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/source/blender/editors/object/object_vgroup.c b/source/blender/editors/object/object_vgroup.c index 1b67fe146ab..580124d480d 100644 --- a/source/blender/editors/object/object_vgroup.c +++ b/source/blender/editors/object/object_vgroup.c @@ -589,49 +589,49 @@ int ED_vgroup_copy_by_nearest_face_single(Object *ob_dst, Object *ob_src) /*get weight from quad*/ else{ - if(dist_v1 > dist_v2||dist_v1 > dist_v3||dist_v1 > dist_v4){ - /*exclude v1 and get weight from the 3 closest*/ - tot_dist= dist_v4 + dist_v2 + dist_v3; + /*exclude v1 and get weight from the 3 closest*/ + if(dist_v1 >= dist_v2 && dist_v1 >= dist_v3 && dist_v1 >= dist_v4){ + tot_dist= dist_v4 + dist_v2 + dist_v3; dw_src= defvert_verify_index(dv_array_src[mface_src[nearest.index].v4], index_src); - weight= dw_src->weight * (1-dist_v4/tot_dist); + weight= dw_src->weight / tot_dist * dist_v4; dw_src= defvert_verify_index(dv_array_src[mface_src[nearest.index].v2], index_src); - weight+= dw_src->weight * (1-dist_v2/tot_dist); + weight+= dw_src->weight / tot_dist * dist_v2; dw_src= defvert_verify_index(dv_array_src[mface_src[nearest.index].v3], index_src); - weight+= dw_src->weight * (1-dist_v3/tot_dist); + weight+= dw_src->weight / tot_dist * dist_v3; } - else if(dist_v2 > dist_v3||dist_v2 > dist_v4){ - /*exclude v2 and get weight from the 3 closest*/ - tot_dist= dist_v1 + dist_v4 + dist_v3; + /*exclude v2 and get weight from the 3 closest*/ + else if(dist_v2 >= dist_v3 && dist_v2 >= dist_v4){ + tot_dist= dist_v1 + dist_v4 + dist_v3; dw_src= defvert_verify_index(dv_array_src[mface_src[nearest.index].v1], index_src); - weight= dw_src->weight * (1-dist_v1/tot_dist); + weight= dw_src->weight / tot_dist * dist_v1; dw_src= defvert_verify_index(dv_array_src[mface_src[nearest.index].v4], index_src); - weight+= dw_src->weight * (1-dist_v4/tot_dist); + weight+= dw_src->weight / tot_dist * dist_v4; dw_src= defvert_verify_index(dv_array_src[mface_src[nearest.index].v3], index_src); - weight+= dw_src->weight * (1-dist_v3/tot_dist); + weight+= dw_src->weight / tot_dist * dist_v3; } - else if(dist_v3 > dist_v4){ - /*exclude v3 and get weight from the 3 closest*/ - tot_dist= dist_v1 + dist_v2 + dist_v4; + /*exclude v3 and get weight from the 3 closest*/ + else if(dist_v3 >= dist_v4){ + tot_dist= dist_v1 + dist_v2 + dist_v4; dw_src= defvert_verify_index(dv_array_src[mface_src[nearest.index].v1], index_src); - weight= dw_src->weight * (1-dist_v1/tot_dist); + weight= dw_src->weight / tot_dist * dist_v1; dw_src= defvert_verify_index(dv_array_src[mface_src[nearest.index].v2], index_src); - weight+= dw_src->weight * (1-dist_v2/tot_dist); + weight+= dw_src->weight / tot_dist * dist_v2; dw_src= defvert_verify_index(dv_array_src[mface_src[nearest.index].v4], index_src); - weight+= dw_src->weight * (1-dist_v4/tot_dist); + weight+= dw_src->weight / tot_dist * dist_v4; } + + /*exclude v4 and get weight from the 3 closest*/ else{ - /*exclude v4 and get weight from the 3 closest*/ tot_dist= dist_v1 + dist_v2 + dist_v3; - dw_src= defvert_verify_index(dv_array_src[mface_src[nearest.index].v1], index_src); - weight= dw_src->weight * (1-dist_v1/tot_dist); + weight= dw_src->weight / tot_dist * dist_v1; dw_src= defvert_verify_index(dv_array_src[mface_src[nearest.index].v2], index_src); - weight+= dw_src->weight * (1-dist_v2/tot_dist); + weight+= dw_src->weight / tot_dist * dist_v2; dw_src= defvert_verify_index(dv_array_src[mface_src[nearest.index].v3], index_src); - weight+= dw_src->weight * (1-dist_v3/tot_dist); + weight+= dw_src->weight / tot_dist * dist_v3; } } } @@ -641,11 +641,11 @@ int ED_vgroup_copy_by_nearest_face_single(Object *ob_dst, Object *ob_src) tot_dist= dist_v1 + dist_v2 + dist_v3; dw_src= defvert_verify_index(dv_array_src[mface_src[nearest.index].v1], index_src); - weight= dw_src->weight * (1-dist_v1/tot_dist); + weight= dw_src->weight / tot_dist * dist_v1; dw_src= defvert_verify_index(dv_array_src[mface_src[nearest.index].v2], index_src); - weight+= dw_src->weight * (1-dist_v2/tot_dist); + weight+= dw_src->weight / tot_dist * dist_v2; dw_src= defvert_verify_index(dv_array_src[mface_src[nearest.index].v3], index_src); - weight+= dw_src->weight * (1-dist_v3/tot_dist); + weight+= dw_src->weight / tot_dist * dist_v3; } } -- cgit v1.2.3 From b7f4ea118c4daad48283362bc454d62a9cfea832 Mon Sep 17 00:00:00 2001 From: Ove Murberg Henriksen Date: Sat, 12 May 2012 03:50:44 +0000 Subject: obs! not thinking straight. Reverting bug from cleanup. --- source/blender/editors/object/object_vgroup.c | 30 +++++++++++++-------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/source/blender/editors/object/object_vgroup.c b/source/blender/editors/object/object_vgroup.c index 580124d480d..256d8f3f3d9 100644 --- a/source/blender/editors/object/object_vgroup.c +++ b/source/blender/editors/object/object_vgroup.c @@ -594,44 +594,44 @@ int ED_vgroup_copy_by_nearest_face_single(Object *ob_dst, Object *ob_src) if(dist_v1 >= dist_v2 && dist_v1 >= dist_v3 && dist_v1 >= dist_v4){ tot_dist= dist_v4 + dist_v2 + dist_v3; dw_src= defvert_verify_index(dv_array_src[mface_src[nearest.index].v4], index_src); - weight= dw_src->weight / tot_dist * dist_v4; + weight= dw_src->weight * (1-dist_v4/tot_dist); dw_src= defvert_verify_index(dv_array_src[mface_src[nearest.index].v2], index_src); - weight+= dw_src->weight / tot_dist * dist_v2; + weight+= dw_src->weight * (1-dist_v2/tot_dist); dw_src= defvert_verify_index(dv_array_src[mface_src[nearest.index].v3], index_src); - weight+= dw_src->weight / tot_dist * dist_v3; + weight+= dw_src->weight * (1-dist_v3/tot_dist); } /*exclude v2 and get weight from the 3 closest*/ else if(dist_v2 >= dist_v3 && dist_v2 >= dist_v4){ tot_dist= dist_v1 + dist_v4 + dist_v3; dw_src= defvert_verify_index(dv_array_src[mface_src[nearest.index].v1], index_src); - weight= dw_src->weight / tot_dist * dist_v1; + weight= dw_src->weight * (1-dist_v1/tot_dist); dw_src= defvert_verify_index(dv_array_src[mface_src[nearest.index].v4], index_src); - weight+= dw_src->weight / tot_dist * dist_v4; + weight+= dw_src->weight * (1-dist_v4/tot_dist); dw_src= defvert_verify_index(dv_array_src[mface_src[nearest.index].v3], index_src); - weight+= dw_src->weight / tot_dist * dist_v3; + weight+= dw_src->weight * (1-dist_v3/tot_dist); } /*exclude v3 and get weight from the 3 closest*/ else if(dist_v3 >= dist_v4){ tot_dist= dist_v1 + dist_v2 + dist_v4; dw_src= defvert_verify_index(dv_array_src[mface_src[nearest.index].v1], index_src); - weight= dw_src->weight / tot_dist * dist_v1; + weight= dw_src->weight * (1-dist_v1/tot_dist); dw_src= defvert_verify_index(dv_array_src[mface_src[nearest.index].v2], index_src); - weight+= dw_src->weight / tot_dist * dist_v2; + weight+= dw_src->weight * (1-dist_v2/tot_dist); dw_src= defvert_verify_index(dv_array_src[mface_src[nearest.index].v4], index_src); - weight+= dw_src->weight / tot_dist * dist_v4; + weight+= dw_src->weight * (1-dist_v4/tot_dist); } /*exclude v4 and get weight from the 3 closest*/ else{ tot_dist= dist_v1 + dist_v2 + dist_v3; dw_src= defvert_verify_index(dv_array_src[mface_src[nearest.index].v1], index_src); - weight= dw_src->weight / tot_dist * dist_v1; + weight= dw_src->weight * (1-dist_v1/tot_dist); dw_src= defvert_verify_index(dv_array_src[mface_src[nearest.index].v2], index_src); - weight+= dw_src->weight / tot_dist * dist_v2; + weight+= dw_src->weight * (1-dist_v2/tot_dist); dw_src= defvert_verify_index(dv_array_src[mface_src[nearest.index].v3], index_src); - weight+= dw_src->weight / tot_dist * dist_v3; + weight+= dw_src->weight * (1-dist_v3/tot_dist); } } } @@ -641,11 +641,11 @@ int ED_vgroup_copy_by_nearest_face_single(Object *ob_dst, Object *ob_src) tot_dist= dist_v1 + dist_v2 + dist_v3; dw_src= defvert_verify_index(dv_array_src[mface_src[nearest.index].v1], index_src); - weight= dw_src->weight / tot_dist * dist_v1; + weight= dw_src->weight * (1-dist_v1/tot_dist); dw_src= defvert_verify_index(dv_array_src[mface_src[nearest.index].v2], index_src); - weight+= dw_src->weight / tot_dist * dist_v2; + weight+= dw_src->weight * (1-dist_v2/tot_dist); dw_src= defvert_verify_index(dv_array_src[mface_src[nearest.index].v3], index_src); - weight+= dw_src->weight / tot_dist * dist_v3; + weight+= dw_src->weight * (1-dist_v3/tot_dist); } } -- cgit v1.2.3 From 7adeedfecc19d5acc94463bdffa0e6e4524259ee Mon Sep 17 00:00:00 2001 From: Ove Murberg Henriksen Date: Sat, 12 May 2012 17:43:56 +0000 Subject: ED_vgroup_copy_by_nearest_face_single() Math for interpolation of weights fixed to be consistent with reality... Still there is probably some indexing errors. Some vertices that should have blue weight, gets red. (on border faces) --- source/blender/editors/object/object_vgroup.c | 83 ++++++++++++++++----------- 1 file changed, 50 insertions(+), 33 deletions(-) diff --git a/source/blender/editors/object/object_vgroup.c b/source/blender/editors/object/object_vgroup.c index 256d8f3f3d9..b96130716a5 100644 --- a/source/blender/editors/object/object_vgroup.c +++ b/source/blender/editors/object/object_vgroup.c @@ -514,7 +514,7 @@ int ED_vgroup_copy_by_nearest_face_single(Object *ob_dst, Object *ob_src) BVHTreeNearest nearest; MDeformWeight *dw_dst, *dw_src; int dv_tot_src, dv_tot_dst, i, index_dst, index_src; - float weight, tot_dist, dist_v1, dist_v2, dist_v3, dist_v4, tmp_co[3]; + float weight, tot_distribution, distribution_v1, distribution_v2, distribution_v3, distribution_v4, tmp_co[3]; /*get source deform group*/ dg_src= BLI_findlink(&ob_src->defbase, (ob_src->actdef-1)); @@ -544,6 +544,7 @@ int ED_vgroup_copy_by_nearest_face_single(Object *ob_dst, Object *ob_src) /*get vertices*/ mv_dst= me_dst->mvert; + mv_src= dmesh_src->getVertArray(dmesh_src); /*get faces*/ @@ -568,84 +569,100 @@ int ED_vgroup_copy_by_nearest_face_single(Object *ob_dst, Object *ob_src) /*Smart solution might be to just substract the distance difference to plane instead.*/ /*get distances*/ - dist_v1= sqr_dist_v3v3(tmp_co, mv_src[mface_src[nearest.index].v1].co); - dist_v2= sqr_dist_v3v3(tmp_co, mv_src[mface_src[nearest.index].v2].co); - dist_v3= sqr_dist_v3v3(tmp_co, mv_src[mface_src[nearest.index].v3].co); + distribution_v1= sqr_dist_v3v3(tmp_co, mv_src[mface_src[nearest.index].v1].co); + distribution_v2= sqr_dist_v3v3(tmp_co, mv_src[mface_src[nearest.index].v2].co); + distribution_v3= sqr_dist_v3v3(tmp_co, mv_src[mface_src[nearest.index].v3].co); + + /*test + printf("dist_v1 %f index v1%d \n", dist_v1, mface_src[nearest.index].v1); + printf("dist_v2 %f index v2%d \n", dist_v2, mface_src[nearest.index].v2); + printf("dist_v3 %f index v3%d \n", dist_v3, mface_src[nearest.index].v3);*/ /*get weight from overlapping vert if any*/ - if(dist_v1 == 0) weight= defvert_verify_index(dv_array_src[mface_src[nearest.index].v1], index_src)->weight; - if(dist_v2 == 0) weight= defvert_verify_index(dv_array_src[mface_src[nearest.index].v2], index_src)->weight; - if(dist_v3 == 0) weight= defvert_verify_index(dv_array_src[mface_src[nearest.index].v3], index_src)->weight; + if(distribution_v1 == 0) weight= defvert_verify_index(dv_array_src[mface_src[nearest.index].v1], index_src)->weight; + if(distribution_v2 == 0) weight= defvert_verify_index(dv_array_src[mface_src[nearest.index].v2], index_src)->weight; + if(distribution_v3 == 0) weight= defvert_verify_index(dv_array_src[mface_src[nearest.index].v3], index_src)->weight; /*interpolate weight*/ else{ /*check for quad*/ if(mface_src[nearest.index].v4){ - dist_v4= sqr_dist_v3v3(tmp_co, mv_src[mface_src->v4].co); + distribution_v4= sqr_dist_v3v3(tmp_co, mv_src[mface_src->v4].co); /*check if vert 4 is overlapping*/ - if(dist_v4 == 0) weight= defvert_verify_index(dv_array_src[mface_src[nearest.index].v4], index_src)->weight; + if(distribution_v4 == 0) weight= defvert_verify_index(dv_array_src[mface_src[nearest.index].v4], index_src)->weight; /*get weight from quad*/ else{ + /*invert distribution*/ + distribution_v1= 1 / distribution_v1; + distribution_v2= 1 / distribution_v2; + distribution_v3= 1 / distribution_v3; + distribution_v4= 1 / distribution_v4; + /*exclude v1 and get weight from the 3 closest*/ - if(dist_v1 >= dist_v2 && dist_v1 >= dist_v3 && dist_v1 >= dist_v4){ - tot_dist= dist_v4 + dist_v2 + dist_v3; + if(distribution_v1 > distribution_v2 && distribution_v1 > distribution_v3 && distribution_v1 > distribution_v4){ + tot_distribution= distribution_v4 + distribution_v2 + distribution_v3; dw_src= defvert_verify_index(dv_array_src[mface_src[nearest.index].v4], index_src); - weight= dw_src->weight * (1-dist_v4/tot_dist); + weight= dw_src->weight * distribution_v4 / tot_distribution; dw_src= defvert_verify_index(dv_array_src[mface_src[nearest.index].v2], index_src); - weight+= dw_src->weight * (1-dist_v2/tot_dist); + weight+= dw_src->weight * distribution_v2 / tot_distribution; dw_src= defvert_verify_index(dv_array_src[mface_src[nearest.index].v3], index_src); - weight+= dw_src->weight * (1-dist_v3/tot_dist); + weight+= dw_src->weight * distribution_v3 / tot_distribution; } /*exclude v2 and get weight from the 3 closest*/ - else if(dist_v2 >= dist_v3 && dist_v2 >= dist_v4){ - tot_dist= dist_v1 + dist_v4 + dist_v3; + else if(distribution_v2 > distribution_v3 && distribution_v2 > distribution_v4){ + tot_distribution= distribution_v1 + distribution_v4 + distribution_v3; dw_src= defvert_verify_index(dv_array_src[mface_src[nearest.index].v1], index_src); - weight= dw_src->weight * (1-dist_v1/tot_dist); + weight= dw_src->weight * distribution_v1 / tot_distribution; dw_src= defvert_verify_index(dv_array_src[mface_src[nearest.index].v4], index_src); - weight+= dw_src->weight * (1-dist_v4/tot_dist); + weight+= dw_src->weight * distribution_v4 / tot_distribution; dw_src= defvert_verify_index(dv_array_src[mface_src[nearest.index].v3], index_src); - weight+= dw_src->weight * (1-dist_v3/tot_dist); + weight+= dw_src->weight * distribution_v3 / tot_distribution; } /*exclude v3 and get weight from the 3 closest*/ - else if(dist_v3 >= dist_v4){ - tot_dist= dist_v1 + dist_v2 + dist_v4; + else if(distribution_v3 > distribution_v4){ + tot_distribution= distribution_v1 + distribution_v2 + distribution_v4; dw_src= defvert_verify_index(dv_array_src[mface_src[nearest.index].v1], index_src); - weight= dw_src->weight * (1-dist_v1/tot_dist); + weight= dw_src->weight * distribution_v1 / tot_distribution; dw_src= defvert_verify_index(dv_array_src[mface_src[nearest.index].v2], index_src); - weight+= dw_src->weight * (1-dist_v2/tot_dist); + weight+= dw_src->weight * distribution_v2 / tot_distribution; dw_src= defvert_verify_index(dv_array_src[mface_src[nearest.index].v4], index_src); - weight+= dw_src->weight * (1-dist_v4/tot_dist); + weight+= dw_src->weight * distribution_v4 / tot_distribution; } - /*exclude v4 and get weight from the 3 closest*/ + /*exclude v4 and get weight from the 3 closest. Also when some distances are the same*/ else{ - tot_dist= dist_v1 + dist_v2 + dist_v3; + tot_distribution= distribution_v1 + distribution_v2 + distribution_v3; dw_src= defvert_verify_index(dv_array_src[mface_src[nearest.index].v1], index_src); - weight= dw_src->weight * (1-dist_v1/tot_dist); + weight= dw_src->weight * distribution_v1 / tot_distribution; dw_src= defvert_verify_index(dv_array_src[mface_src[nearest.index].v2], index_src); - weight+= dw_src->weight * (1-dist_v2/tot_dist); + weight+= dw_src->weight * distribution_v2 / tot_distribution; dw_src= defvert_verify_index(dv_array_src[mface_src[nearest.index].v3], index_src); - weight+= dw_src->weight * (1-dist_v3/tot_dist); + weight+= dw_src->weight * distribution_v3 / tot_distribution; } } } /*get weight from triangle*/ else{ - tot_dist= dist_v1 + dist_v2 + dist_v3; + /*invert distribution*/ + distribution_v1= 1 / distribution_v1; + distribution_v2= 1 / distribution_v2; + distribution_v3= 1 / distribution_v3; + + tot_distribution= distribution_v1 + distribution_v2 + distribution_v3; dw_src= defvert_verify_index(dv_array_src[mface_src[nearest.index].v1], index_src); - weight= dw_src->weight * (1-dist_v1/tot_dist); + weight= dw_src->weight * distribution_v1 / tot_distribution; dw_src= defvert_verify_index(dv_array_src[mface_src[nearest.index].v2], index_src); - weight+= dw_src->weight * (1-dist_v2/tot_dist); + weight+= dw_src->weight * distribution_v2 / tot_distribution; dw_src= defvert_verify_index(dv_array_src[mface_src[nearest.index].v3], index_src); - weight+= dw_src->weight * (1-dist_v3/tot_dist); + weight+= dw_src->weight * distribution_v3 / tot_distribution; } } -- cgit v1.2.3 From 4215071ace4e6d9ea7a3e8aa2719e382761b5427 Mon Sep 17 00:00:00 2001 From: Ove Murberg Henriksen Date: Sun, 13 May 2012 03:46:46 +0000 Subject: Complete working function added: ED_vgroup_copy_by_nearest_vertex_in_face_single() --- source/blender/editors/object/object_vgroup.c | 101 +++++++++++++++++++++++++- 1 file changed, 100 insertions(+), 1 deletion(-) diff --git a/source/blender/editors/object/object_vgroup.c b/source/blender/editors/object/object_vgroup.c index b96130716a5..b1824e90dde 100644 --- a/source/blender/editors/object/object_vgroup.c +++ b/source/blender/editors/object/object_vgroup.c @@ -500,6 +500,105 @@ float sqr_dist_v3v3(float v1[3], float v2[3]) return dot_v3v3(d, d); } +/*Copy a single vertex group from source to destination with weights by nearest weight in face*/ +int ED_vgroup_copy_by_nearest_vertex_in_face_single(Object *ob_dst, Object *ob_src) +{ + bDeformGroup *dg_src, *dg_dst; + Mesh *me_dst; + DerivedMesh *dmesh_src; + BVHTreeFromMesh tree_mesh_faces_src = {NULL}; + MDeformVert **dv_array_src, **dv_array_dst; + 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; + float dist_v1, dist_v2, dist_v3, dist_v4, tmp_co[3], tmp_mat[4][4]; + + /*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 meshes*/ + me_dst= ob_dst->data; + dmesh_src= ob_src->derivedDeform; + + /*make node tree*/ + DM_ensure_tessface(dmesh_src); + bvhtree_from_mesh_faces(&tree_mesh_faces_src, dmesh_src, 0.0, 2, 6); + + /*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); + + /*get vertices*/ + mv_dst= me_dst->mvert; + + mv_src= dmesh_src->getVertArray(dmesh_src); + + /*get faces*/ + mface_src= dmesh_src->getTessFaceArray(dmesh_src); + + /*Prepearing transformation matrix*/ + 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 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; + + /*Transforming 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= sqr_dist_v3v3(tmp_co, mv_src[mface_src[nearest.index].v1].co); + dist_v2= sqr_dist_v3v3(tmp_co, mv_src[mface_src[nearest.index].v2].co); + dist_v3= sqr_dist_v3v3(tmp_co, mv_src[mface_src[nearest.index].v3].co); + + /*get weight from triangle*/ + if(dist_v1weight= dw_src->weight; + } + + /*free memory and return*/ + free_bvhtree_from_mesh(&tree_mesh_faces_src); + return 1; +} + /*Copy a single vertex group from source to destination with weights by nearest weight*/ /*TODO: transform into target space as in by_vertex function. postphoned due to easier testing during development*/ int ED_vgroup_copy_by_nearest_face_single(Object *ob_dst, Object *ob_src) @@ -3075,7 +3174,7 @@ static int vertex_group_copy_to_selected_single_exec(bContext *C, wmOperator *op /*Try function for get weight from closest vertex*/ /*TODO: try this function*/ /*Try function for get weight from closest face*/ - else if(ED_vgroup_copy_by_nearest_face_single(obslc, obact)) change++; + else if(ED_vgroup_copy_by_nearest_vertex_in_face_single(obslc, obact)) change++; /*Trigger error message*/ else fail++; /*Event notifiers for correct display of data*/ -- cgit v1.2.3 From 4bee0a42dd8f41abf6d9bcf72b484f05cba8f955 Mon Sep 17 00:00:00 2001 From: Ove Murberg Henriksen Date: Sun, 13 May 2012 05:33:25 +0000 Subject: Cleanup. Basis changed/added for: ED_vgroup_copy_by_nearest_face_single() Interpolation is still not working 100% --- source/blender/editors/object/object_vgroup.c | 150 +++++++++----------------- 1 file changed, 52 insertions(+), 98 deletions(-) diff --git a/source/blender/editors/object/object_vgroup.c b/source/blender/editors/object/object_vgroup.c index b1824e90dde..f40bdde8aa2 100644 --- a/source/blender/editors/object/object_vgroup.c +++ b/source/blender/editors/object/object_vgroup.c @@ -376,7 +376,7 @@ int ED_vgroup_copy_array(Object *ob, Object *ob_from) return 1; } -/*Copy a single vertex group from source to destination with weights*/ +/*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; @@ -389,7 +389,7 @@ int ED_vgroup_copy_single(Object *ob_dst, const Object *ob_src) /*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*/ + /*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); @@ -404,13 +404,13 @@ int ED_vgroup_copy_single(Object *ob_dst, const Object *ob_src) 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*/ + /*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*/ + /* loop through the vertices and copy weight*/ for(i=0; idefbase, (ob_src->actdef-1)); - /*Create new and overwrite vertex group on destination without data*/ + /*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); @@ -462,22 +462,22 @@ int ED_vgroup_copy_by_nearest_vertex_single(Object *ob_dst, Object *ob_src) /*get vertices*/ mv_dst= me_dst->mvert; - /*Prepearing transformation matrix*/ - /*This can be excluded to make a lazy feature that works better when object centers relative to mesh is the same*/ + /*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 from nearest weight*/ + /* 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*/ + /*reset nearest*/ nearest.index= -1; nearest.dist= FLT_MAX; - /*Transforming into target space*/ + /*transform into target space*/ mul_v3_m4v3(tmp_co, tmp_mat, mv_dst->co); - /*Node tree accelerated search for closest vetex*/ + /*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); /*copy weight*/ @@ -491,6 +491,7 @@ int ED_vgroup_copy_by_nearest_vertex_single(Object *ob_dst, Object *ob_src) return 1; } +/*Return the squared distance between two points in 3d space*/ float sqr_dist_v3v3(float v1[3], float v2[3]) { float d[3]; @@ -518,7 +519,7 @@ int ED_vgroup_copy_by_nearest_vertex_in_face_single(Object *ob_dst, Object *ob_s /*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*/ + /*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); @@ -543,27 +544,26 @@ int ED_vgroup_copy_by_nearest_vertex_in_face_single(Object *ob_dst, Object *ob_s /*get vertices*/ mv_dst= me_dst->mvert; - mv_src= dmesh_src->getVertArray(dmesh_src); /*get faces*/ mface_src= dmesh_src->getTessFaceArray(dmesh_src); - /*Prepearing transformation matrix*/ + /*prepare transformation matrix*/ 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 from nearest weight*/ + /* 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*/ + /*reset nearest*/ nearest.index= -1; nearest.dist= FLT_MAX; - /*Transforming into target space*/ + /*transform into target space*/ mul_v3_m4v3(tmp_co, tmp_mat, mv_dst->co); - /*Node tree accelerated search for closest face*/ + /*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*/ @@ -581,7 +581,7 @@ int ED_vgroup_copy_by_nearest_vertex_in_face_single(Object *ob_dst, Object *ob_s else{ dw_src= defvert_verify_index(dv_array_src[mface_src[nearest.index].v3], index_src); } - /*Check for and get weight from quad*/ + /*check for and get weight from quad*/ if(mface_src[nearest.index].v4){ dist_v4= sqr_dist_v3v3(tmp_co, mv_src[mface_src[nearest.index].v4].co); if(dist_v4defbase, (ob_src->actdef-1)); - /*Create new and overwrite vertex group on destination without data*/ + /*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); @@ -643,27 +643,24 @@ int ED_vgroup_copy_by_nearest_face_single(Object *ob_dst, Object *ob_src) /*get vertices*/ mv_dst= me_dst->mvert; - mv_src= dmesh_src->getVertArray(dmesh_src); /*get faces*/ mface_src= dmesh_src->getTessFaceArray(dmesh_src); - /* Loop through the vertices and copy weight from nearest weight*/ + /* 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*/ + /*reset nearest*/ nearest.index= -1; nearest.dist= FLT_MAX; /*set destination coordinate*/ copy_v3_v3(tmp_co, mv_dst->co); - /*Node tree accelerated search for closest face*/ + /*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 weight*/ - /*TODO: Have to project onto face to get a decent result*/ /*Smart solution might be to just substract the distance difference to plane instead.*/ @@ -672,90 +669,40 @@ int ED_vgroup_copy_by_nearest_face_single(Object *ob_dst, Object *ob_src) distribution_v2= sqr_dist_v3v3(tmp_co, mv_src[mface_src[nearest.index].v2].co); distribution_v3= sqr_dist_v3v3(tmp_co, mv_src[mface_src[nearest.index].v3].co); - /*test - printf("dist_v1 %f index v1%d \n", dist_v1, mface_src[nearest.index].v1); - printf("dist_v2 %f index v2%d \n", dist_v2, mface_src[nearest.index].v2); - printf("dist_v3 %f index v3%d \n", dist_v3, mface_src[nearest.index].v3);*/ - /*get weight from overlapping vert if any*/ if(distribution_v1 == 0) weight= defvert_verify_index(dv_array_src[mface_src[nearest.index].v1], index_src)->weight; if(distribution_v2 == 0) weight= defvert_verify_index(dv_array_src[mface_src[nearest.index].v2], index_src)->weight; if(distribution_v3 == 0) weight= defvert_verify_index(dv_array_src[mface_src[nearest.index].v3], index_src)->weight; - - /*interpolate weight*/ else{ + /*invert distribution*/ + distribution_v1= 1/distribution_v1; + distribution_v2= 1/distribution_v2; + distribution_v3= 1/distribution_v3; + + /*set total distribution*/ + tot_distribution= distribution_v1 + distribution_v2 + distribution_v3; /*check for quad*/ if(mface_src[nearest.index].v4){ distribution_v4= sqr_dist_v3v3(tmp_co, mv_src[mface_src->v4].co); - - /*check if vert 4 is overlapping*/ if(distribution_v4 == 0) weight= defvert_verify_index(dv_array_src[mface_src[nearest.index].v4], index_src)->weight; - - /*get weight from quad*/ else{ - - /*invert distribution*/ - distribution_v1= 1 / distribution_v1; - distribution_v2= 1 / distribution_v2; - distribution_v3= 1 / distribution_v3; - distribution_v4= 1 / distribution_v4; - - /*exclude v1 and get weight from the 3 closest*/ - if(distribution_v1 > distribution_v2 && distribution_v1 > distribution_v3 && distribution_v1 > distribution_v4){ - tot_distribution= distribution_v4 + distribution_v2 + distribution_v3; - dw_src= defvert_verify_index(dv_array_src[mface_src[nearest.index].v4], index_src); - weight= dw_src->weight * distribution_v4 / tot_distribution; - dw_src= defvert_verify_index(dv_array_src[mface_src[nearest.index].v2], index_src); - weight+= dw_src->weight * distribution_v2 / tot_distribution; - dw_src= defvert_verify_index(dv_array_src[mface_src[nearest.index].v3], index_src); - weight+= dw_src->weight * distribution_v3 / tot_distribution; - } - - /*exclude v2 and get weight from the 3 closest*/ - else if(distribution_v2 > distribution_v3 && distribution_v2 > distribution_v4){ - tot_distribution= distribution_v1 + distribution_v4 + distribution_v3; - dw_src= defvert_verify_index(dv_array_src[mface_src[nearest.index].v1], index_src); - weight= dw_src->weight * distribution_v1 / tot_distribution; - dw_src= defvert_verify_index(dv_array_src[mface_src[nearest.index].v4], index_src); - weight+= dw_src->weight * distribution_v4 / tot_distribution; - dw_src= defvert_verify_index(dv_array_src[mface_src[nearest.index].v3], index_src); - weight+= dw_src->weight * distribution_v3 / tot_distribution; - } - - /*exclude v3 and get weight from the 3 closest*/ - else if(distribution_v3 > distribution_v4){ - tot_distribution= distribution_v1 + distribution_v2 + distribution_v4; - dw_src= defvert_verify_index(dv_array_src[mface_src[nearest.index].v1], index_src); - weight= dw_src->weight * distribution_v1 / tot_distribution; - dw_src= defvert_verify_index(dv_array_src[mface_src[nearest.index].v2], index_src); - weight+= dw_src->weight * distribution_v2 / tot_distribution; - dw_src= defvert_verify_index(dv_array_src[mface_src[nearest.index].v4], index_src); - weight+= dw_src->weight * distribution_v4 / tot_distribution; - } - - /*exclude v4 and get weight from the 3 closest. Also when some distances are the same*/ - else{ - tot_distribution= distribution_v1 + distribution_v2 + distribution_v3; - dw_src= defvert_verify_index(dv_array_src[mface_src[nearest.index].v1], index_src); - weight= dw_src->weight * distribution_v1 / tot_distribution; - dw_src= defvert_verify_index(dv_array_src[mface_src[nearest.index].v2], index_src); - weight+= dw_src->weight * distribution_v2 / tot_distribution; - dw_src= defvert_verify_index(dv_array_src[mface_src[nearest.index].v3], index_src); - weight+= dw_src->weight * distribution_v3 / tot_distribution; - } + distribution_v4= 1/distribution_v4; + tot_distribution+= distribution_v4; + + /*get weight from quad*/ + dw_src= defvert_verify_index(dv_array_src[mface_src[nearest.index].v1], index_src); + weight= dw_src->weight * distribution_v1 / tot_distribution; + dw_src= defvert_verify_index(dv_array_src[mface_src[nearest.index].v2], index_src); + weight+= dw_src->weight * distribution_v2 / tot_distribution; + dw_src= defvert_verify_index(dv_array_src[mface_src[nearest.index].v3], index_src); + weight+= dw_src->weight * distribution_v3 / tot_distribution; + dw_src= defvert_verify_index(dv_array_src[mface_src[nearest.index].v4], index_src); + weight+= dw_src->weight * distribution_v4 / tot_distribution; } } - - /*get weight from triangle*/ else{ - - /*invert distribution*/ - distribution_v1= 1 / distribution_v1; - distribution_v2= 1 / distribution_v2; - distribution_v3= 1 / distribution_v3; - - tot_distribution= distribution_v1 + distribution_v2 + distribution_v3; + /*get weight from triangle*/ dw_src= defvert_verify_index(dv_array_src[mface_src[nearest.index].v1], index_src); weight= dw_src->weight * distribution_v1 / tot_distribution; dw_src= defvert_verify_index(dv_array_src[mface_src[nearest.index].v2], index_src); @@ -765,6 +712,13 @@ int ED_vgroup_copy_by_nearest_face_single(Object *ob_dst, Object *ob_src) } } + /*snap to valid number*/ + weight*= 1000; + weight+= 0.5; + weight= (int)weight; + weight/=1000; + if(weight>1)weight= 1; + /*copy weight*/ dw_dst= defvert_verify_index(*dv_array_dst, index_dst); dw_dst->weight= weight; @@ -3174,7 +3128,7 @@ static int vertex_group_copy_to_selected_single_exec(bContext *C, wmOperator *op /*Try function for get weight from closest vertex*/ /*TODO: try this function*/ /*Try function for get weight from closest face*/ - else if(ED_vgroup_copy_by_nearest_vertex_in_face_single(obslc, obact)) change++; + else if(ED_vgroup_copy_by_nearest_face_single(obslc, obact)) change++; /*Trigger error message*/ else fail++; /*Event notifiers for correct display of data*/ -- cgit v1.2.3 From 55e627d01eb8f2eeea190f53ce4a014052ed0cf2 Mon Sep 17 00:00:00 2001 From: Ove Murberg Henriksen Date: Sun, 13 May 2012 05:57:32 +0000 Subject: Removed sqr_dist_v3v3() Now using existing: len_squared_v3v3() --- source/blender/editors/object/object_vgroup.c | 26 ++++++++------------------ 1 file changed, 8 insertions(+), 18 deletions(-) diff --git a/source/blender/editors/object/object_vgroup.c b/source/blender/editors/object/object_vgroup.c index f40bdde8aa2..a81fb87e9b1 100644 --- a/source/blender/editors/object/object_vgroup.c +++ b/source/blender/editors/object/object_vgroup.c @@ -491,16 +491,6 @@ int ED_vgroup_copy_by_nearest_vertex_single(Object *ob_dst, Object *ob_src) return 1; } -/*Return the squared distance between two points in 3d space*/ -float sqr_dist_v3v3(float v1[3], float v2[3]) -{ - float d[3]; - d[0]= v2[0]-v1[0]; - d[1]= v2[1]-v1[1]; - d[2]= v2[2]-v1[2]; - return dot_v3v3(d, d); -} - /*Copy a single vertex group from source to destination with weights by nearest weight in face*/ int ED_vgroup_copy_by_nearest_vertex_in_face_single(Object *ob_dst, Object *ob_src) { @@ -567,9 +557,9 @@ int ED_vgroup_copy_by_nearest_vertex_in_face_single(Object *ob_dst, Object *ob_s 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= sqr_dist_v3v3(tmp_co, mv_src[mface_src[nearest.index].v1].co); - dist_v2= sqr_dist_v3v3(tmp_co, mv_src[mface_src[nearest.index].v2].co); - dist_v3= sqr_dist_v3v3(tmp_co, mv_src[mface_src[nearest.index].v3].co); + 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_v1weight; @@ -684,7 +674,7 @@ int ED_vgroup_copy_by_nearest_face_single(Object *ob_dst, Object *ob_src) /*check for quad*/ if(mface_src[nearest.index].v4){ - distribution_v4= sqr_dist_v3v3(tmp_co, mv_src[mface_src->v4].co); + distribution_v4= len_squared_v3v3(tmp_co, mv_src[mface_src->v4].co); if(distribution_v4 == 0) weight= defvert_verify_index(dv_array_src[mface_src[nearest.index].v4], index_src)->weight; else{ distribution_v4= 1/distribution_v4; -- cgit v1.2.3 From 9331b5e92fc847841b04d8303132ac5779d9860c Mon Sep 17 00:00:00 2001 From: Ove Murberg Henriksen Date: Sun, 13 May 2012 08:16:41 +0000 Subject: Projection onto face added for: ED_vgroup_copy_by_nearest_face_single() --- source/blender/editors/object/object_vgroup.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/source/blender/editors/object/object_vgroup.c b/source/blender/editors/object/object_vgroup.c index a81fb87e9b1..392f56a6c5f 100644 --- a/source/blender/editors/object/object_vgroup.c +++ b/source/blender/editors/object/object_vgroup.c @@ -603,7 +603,7 @@ int ED_vgroup_copy_by_nearest_face_single(Object *ob_dst, Object *ob_src) BVHTreeNearest nearest; MDeformWeight *dw_dst, *dw_src; int dv_tot_src, dv_tot_dst, i, index_dst, index_src; - float weight, tot_distribution, distribution_v1, distribution_v2, distribution_v3, distribution_v4, tmp_co[3]; + float weight, tot_distribution, distribution_v1, distribution_v2, distribution_v3, distribution_v4, tmp_co[3], tmp_co_v4[3], normal[3]; /*get source deform group*/ dg_src= BLI_findlink(&ob_src->defbase, (ob_src->actdef-1)); @@ -651,8 +651,9 @@ int ED_vgroup_copy_by_nearest_face_single(Object *ob_dst, Object *ob_src) /*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); - /*TODO: Have to project onto face to get a decent result*/ - /*Smart solution might be to just substract the distance difference to plane instead.*/ + /*project destination coordinate onto face*/ + 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); + project_v3_plane(tmp_co, normal, mv_src[mface_src[nearest.index].v1].co); /*get distances*/ distribution_v1= len_squared_v3v3(tmp_co, mv_src[mface_src[nearest.index].v1].co); @@ -674,7 +675,10 @@ int ED_vgroup_copy_by_nearest_face_single(Object *ob_dst, Object *ob_src) /*check for quad*/ if(mface_src[nearest.index].v4){ - distribution_v4= len_squared_v3v3(tmp_co, mv_src[mface_src->v4].co); + /*project vertex nr4 coordinate onto face and distribute*/ + copy_v3_v3(tmp_co_v4, mv_src[mface_src[nearest.index].v4].co); + project_v3_plane(tmp_co_v4, normal, mv_src[mface_src[nearest.index].v1].co); + distribution_v4= len_squared_v3v3(tmp_co, tmp_co_v4); if(distribution_v4 == 0) weight= defvert_verify_index(dv_array_src[mface_src[nearest.index].v4], index_src)->weight; else{ distribution_v4= 1/distribution_v4; @@ -702,12 +706,12 @@ int ED_vgroup_copy_by_nearest_face_single(Object *ob_dst, Object *ob_src) } } - /*snap to valid number*/ + /*snap to valid number, for testing. This should not be nessecary if interpolation works as its supposed to! or is my logick wrong???*//* weight*= 1000; weight+= 0.5; weight= (int)weight; weight/=1000; - if(weight>1)weight= 1; + if(weight>1)weight= 1;*/ /*copy weight*/ dw_dst= defvert_verify_index(*dv_array_dst, index_dst); -- cgit v1.2.3 From 9af6397b2d7043de46926e23376717232576041a Mon Sep 17 00:00:00 2001 From: Ove Murberg Henriksen Date: Tue, 15 May 2012 02:47:23 +0000 Subject: Function for copying weights interpolated from faces complete! ED_vgroup_copy_by_nearest_face_single() --- source/blender/editors/object/object_vgroup.c | 90 ++++++--------------------- 1 file changed, 19 insertions(+), 71 deletions(-) diff --git a/source/blender/editors/object/object_vgroup.c b/source/blender/editors/object/object_vgroup.c index 855230c54f3..15b49feed0a 100644 --- a/source/blender/editors/object/object_vgroup.c +++ b/source/blender/editors/object/object_vgroup.c @@ -590,7 +590,6 @@ int ED_vgroup_copy_by_nearest_vertex_in_face_single(Object *ob_dst, Object *ob_s } /*Copy a single vertex group from source to destination with weights interpolated over nearest face*/ -/*TODO: transform into target space as in by_vertex function. postphoned due to easier testing during development*/ int ED_vgroup_copy_by_nearest_face_single(Object *ob_dst, Object *ob_src) { bDeformGroup *dg_src, *dg_dst; @@ -601,9 +600,9 @@ int ED_vgroup_copy_by_nearest_face_single(Object *ob_dst, Object *ob_src) MVert *mv_dst, *mv_src; MFace *mface_src; BVHTreeNearest nearest; - MDeformWeight *dw_dst, *dw_src; + MDeformWeight *dw_dst; int dv_tot_src, dv_tot_dst, i, index_dst, index_src; - float weight, tot_distribution, distribution_v1, distribution_v2, distribution_v3, distribution_v4, tmp_co[3], tmp_co_v4[3], normal[3]; + float weight, tmp_weight[4], tmp_co[3], normal[3], tmp_mat[4][4]; /*get source deform group*/ dg_src= BLI_findlink(&ob_src->defbase, (ob_src->actdef-1)); @@ -638,6 +637,10 @@ int ED_vgroup_copy_by_nearest_face_single(Object *ob_dst, Object *ob_src) /*get faces*/ mface_src= dmesh_src->getTessFaceArray(dmesh_src); + /*prepare transformation matrix*/ + 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 from nearest weight*/ for(i=0; i < me_dst->totvert; i++, mv_dst++, dv_array_dst++){ @@ -645,80 +648,25 @@ int ED_vgroup_copy_by_nearest_face_single(Object *ob_dst, Object *ob_src) nearest.index= -1; nearest.dist= FLT_MAX; - /*set destination coordinate*/ - copy_v3_v3(tmp_co, 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); - /*project destination coordinate onto face*/ + /*transform into target space onto face*/ + 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); project_v3_plane(tmp_co, normal, mv_src[mface_src[nearest.index].v1].co); - /*get distances*/ - distribution_v1= len_squared_v3v3(tmp_co, mv_src[mface_src[nearest.index].v1].co); - distribution_v2= len_squared_v3v3(tmp_co, mv_src[mface_src[nearest.index].v2].co); - distribution_v3= len_squared_v3v3(tmp_co, mv_src[mface_src[nearest.index].v3].co); - - /*get weight from overlapping vert if any*/ - if(distribution_v1 == 0) weight= defvert_verify_index(dv_array_src[mface_src[nearest.index].v1], index_src)->weight; - if(distribution_v2 == 0) weight= defvert_verify_index(dv_array_src[mface_src[nearest.index].v2], index_src)->weight; - if(distribution_v3 == 0) weight= defvert_verify_index(dv_array_src[mface_src[nearest.index].v3], index_src)->weight; - else{ - /*invert distribution*/ - distribution_v1= 1/distribution_v1; - distribution_v2= 1/distribution_v2; - distribution_v3= 1/distribution_v3; - - /*set total distribution*/ - tot_distribution= distribution_v1 + distribution_v2 + distribution_v3; - - /*check for quad*/ - if(mface_src[nearest.index].v4){ - /*project vertex nr4 coordinate onto face and distribute*/ - copy_v3_v3(tmp_co_v4, mv_src[mface_src[nearest.index].v4].co); - project_v3_plane(tmp_co_v4, normal, mv_src[mface_src[nearest.index].v1].co); - distribution_v4= len_squared_v3v3(tmp_co, tmp_co_v4); - if(distribution_v4 == 0) weight= defvert_verify_index(dv_array_src[mface_src[nearest.index].v4], index_src)->weight; - else{ - distribution_v4= 1/distribution_v4; - tot_distribution+= distribution_v4; - - /*get weight from quad*/ - dw_src= defvert_verify_index(dv_array_src[mface_src[nearest.index].v1], index_src); - weight= dw_src->weight * distribution_v1 / tot_distribution; - dw_src= defvert_verify_index(dv_array_src[mface_src[nearest.index].v2], index_src); - weight+= dw_src->weight * distribution_v2 / tot_distribution; - dw_src= defvert_verify_index(dv_array_src[mface_src[nearest.index].v3], index_src); - weight+= dw_src->weight * distribution_v3 / tot_distribution; - dw_src= defvert_verify_index(dv_array_src[mface_src[nearest.index].v4], index_src); - weight+= dw_src->weight * distribution_v4 / tot_distribution; - } - } - else{ - /*get weight from triangle*/ - dw_src= defvert_verify_index(dv_array_src[mface_src[nearest.index].v1], index_src); - weight= dw_src->weight * distribution_v1 / tot_distribution; - dw_src= defvert_verify_index(dv_array_src[mface_src[nearest.index].v2], index_src); - weight+= dw_src->weight * distribution_v2 / tot_distribution; - dw_src= defvert_verify_index(dv_array_src[mface_src[nearest.index].v3], index_src); - weight+= dw_src->weight * distribution_v3 / tot_distribution; - } - } - - /*dist_to_line_segment_v3()*/ - /*There is probably something fundamentaly wrong about the interpolation. - When a vertex is on an edge, it should get no weight from the vertex not connected to the edge... - Projected onto edge it should get linar interpolation from two vertices. - so it should get the interpolated weight from the third vertex based on the inverted distance from edge along normal to edge! - if I got this right! :P - */ - /*snap to valid number, for testing. This should not be nessecary if interpolation works as its supposed to! or is my logick wrong???*//* - weight*= 1000; - weight+= 0.5; - weight= (int)weight; - weight/=1000; - if(weight>1)weight= 1;*/ + /*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); -- cgit v1.2.3 From f386587e27b53599b25011f6398edb56ba8b4131 Mon Sep 17 00:00:00 2001 From: Ove Murberg Henriksen Date: Wed, 16 May 2012 05:16:34 +0000 Subject: Bugfix --- source/blender/editors/object/object_vgroup.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/source/blender/editors/object/object_vgroup.c b/source/blender/editors/object/object_vgroup.c index 15b49feed0a..de1161a771e 100644 --- a/source/blender/editors/object/object_vgroup.c +++ b/source/blender/editors/object/object_vgroup.c @@ -648,12 +648,14 @@ int ED_vgroup_copy_by_nearest_face_single(Object *ob_dst, Object *ob_src) 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); - /*transform into target space onto face*/ - 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); + /*project onto face*/ project_v3_plane(tmp_co, normal, mv_src[mface_src[nearest.index].v1].co); /*interpolate weights*/ -- cgit v1.2.3 From 0978d1eb9df6cb27bc98627e9688c3eeac5508a5 Mon Sep 17 00:00:00 2001 From: Ove Murberg Henriksen Date: Thu, 17 May 2012 01:42:06 +0000 Subject: Added framework for transfer weight options. vertex_group_transfer_weight_exec() governs all. Functions renamed/added with _transfer_weight_ as opposed to _copy_by_ This is to reflect changes in parameters and usage as the internal code will change. --- .../scripts/startup/bl_ui/space_view3d_toolbar.py | 3 +- source/blender/editors/object/object_intern.h | 1 + source/blender/editors/object/object_ops.c | 1 + source/blender/editors/object/object_vgroup.c | 208 +++++++++++++++++++-- 4 files changed, 198 insertions(+), 15 deletions(-) diff --git a/release/scripts/startup/bl_ui/space_view3d_toolbar.py b/release/scripts/startup/bl_ui/space_view3d_toolbar.py index 729380a0433..50f26c33e15 100644 --- a/release/scripts/startup/bl_ui/space_view3d_toolbar.py +++ b/release/scripts/startup/bl_ui/space_view3d_toolbar.py @@ -986,8 +986,7 @@ class VIEW3D_PT_tools_weightpaint(View3DPanel, Panel): col = layout.column() col.active = ob.vertex_groups.active is not None - col.operator("object.vertex_group_copy_to_selected", text="Transfer weight All") - col.operator("object.vertex_group_copy_to_selected_single", text="Transfer weight") + col.operator("object.vertex_group_transfer_weight", text="Transfer weight") col.operator("object.vertex_group_normalize_all", text="Normalize All") col.operator("object.vertex_group_normalize", text="Normalize") col.operator("object.vertex_group_mirror", text="Mirror") diff --git a/source/blender/editors/object/object_intern.h b/source/blender/editors/object/object_intern.h index e29ab687fff..5269caab426 100644 --- a/source/blender/editors/object/object_intern.h +++ b/source/blender/editors/object/object_intern.h @@ -196,6 +196,7 @@ void OBJECT_OT_vertex_group_remove_from(struct wmOperatorType *ot); void OBJECT_OT_vertex_group_select(struct wmOperatorType *ot); void OBJECT_OT_vertex_group_deselect(struct wmOperatorType *ot); void OBJECT_OT_vertex_group_copy_to_linked(struct wmOperatorType *ot); +void OBJECT_OT_vertex_group_transfer_weight(struct wmOperatorType *ot); void OBJECT_OT_vertex_group_copy_to_selected(struct wmOperatorType *ot); void OBJECT_OT_vertex_group_copy_to_selected_single(struct wmOperatorType *ot); void OBJECT_OT_vertex_group_copy(struct wmOperatorType *ot); diff --git a/source/blender/editors/object/object_ops.c b/source/blender/editors/object/object_ops.c index 9f5ae7e255f..7e535eed29d 100644 --- a/source/blender/editors/object/object_ops.c +++ b/source/blender/editors/object/object_ops.c @@ -170,6 +170,7 @@ void ED_operatortypes_object(void) WM_operatortype_append(OBJECT_OT_vertex_group_select); WM_operatortype_append(OBJECT_OT_vertex_group_deselect); WM_operatortype_append(OBJECT_OT_vertex_group_copy_to_linked); + WM_operatortype_append(OBJECT_OT_vertex_group_transfer_weight); WM_operatortype_append(OBJECT_OT_vertex_group_copy_to_selected); WM_operatortype_append(OBJECT_OT_vertex_group_copy_to_selected_single); WM_operatortype_append(OBJECT_OT_vertex_group_copy); diff --git a/source/blender/editors/object/object_vgroup.c b/source/blender/editors/object/object_vgroup.c index de1161a771e..7cbf0e2145c 100644 --- a/source/blender/editors/object/object_vgroup.c +++ b/source/blender/editors/object/object_vgroup.c @@ -420,8 +420,57 @@ int ED_vgroup_copy_single(Object *ob_dst, const Object *ob_src) return 1; } -/*Copy a single vertex group from source to destination with weights by nearest weight*/ -int ED_vgroup_copy_by_nearest_vertex_single(Object *ob_dst, Object *ob_src) +/********************** Start transfer weight functions *********************/ + +int ED_vgroup_transfer_weight_by_index_all(Object *ob_dst, Object *ob_src, short mode) +{ + /* mode 1 == replace all weights*/ + if(mode == 1){ + return ED_vgroup_copy_array(ob_dst, ob_src); + } + + /* mode 2 == apply to null/0 weights*/ + else if(mode == 2){ + return 0; + } + + /* mode 3 == apply to selected weights*/ + 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) +{ + /* mode 1 == replace all weights*/ + if(mode == 1){ + return ED_vgroup_copy_single(ob_dst, ob_src); + } + + /* mode 2 == apply to null/0 weights*/ + else if(mode == 2){ + return 0; + } + + /* mode 3 == apply to selected weights*/ + else if(mode == 3){ + 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; + /* mode 1 == replace all weights*/ + /* mode 2 == apply to null/0 weights*/ + /* mode 3 == apply to selected weights*/ + return mode; +} + +int ED_vgroup_transfer_weight_by_nearest_vertex_single(Object *ob_dst, Object *ob_src, short mode) { bDeformGroup *dg_src, *dg_dst; MDeformVert **dv_array_src, **dv_array_dst; @@ -434,6 +483,11 @@ int ED_vgroup_copy_by_nearest_vertex_single(Object *ob_dst, Object *ob_src) int dv_tot_src, dv_tot_dst, i, index_dst, index_src; float tmp_co[3], tmp_mat[4][4]; + /* mode 1 == replace all weights*/ + /* mode 2 == apply to null/0 weights*/ + /* mode 3 == apply to selected weights*/ + return mode; + /*get source deform group*/ dg_src= BLI_findlink(&ob_src->defbase, (ob_src->actdef-1)); @@ -491,8 +545,17 @@ int ED_vgroup_copy_by_nearest_vertex_single(Object *ob_dst, Object *ob_src) return 1; } -/*Copy a single vertex group from source to destination with weights by nearest weight in face*/ -int ED_vgroup_copy_by_nearest_vertex_in_face_single(Object *ob_dst, Object *ob_src) +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; + /* mode 1 == replace all weights*/ + /* mode 2 == apply to null/0 weights*/ + /* mode 3 == apply to selected weights*/ + return mode; +} + +int ED_vgroup_transfer_weight_by_nearest_vertex_in_face_single(Object *ob_dst, Object *ob_src, short mode) { bDeformGroup *dg_src, *dg_dst; Mesh *me_dst; @@ -506,6 +569,11 @@ int ED_vgroup_copy_by_nearest_vertex_in_face_single(Object *ob_dst, Object *ob_s 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]; + /* mode 1 == replace all weights*/ + /* mode 2 == apply to null/0 weights*/ + /* mode 3 == apply to selected weights*/ + return mode; + /*get source deform group*/ dg_src= BLI_findlink(&ob_src->defbase, (ob_src->actdef-1)); @@ -589,8 +657,17 @@ int ED_vgroup_copy_by_nearest_vertex_in_face_single(Object *ob_dst, Object *ob_s return 1; } -/*Copy a single vertex group from source to destination with weights interpolated over nearest face*/ -int ED_vgroup_copy_by_nearest_face_single(Object *ob_dst, Object *ob_src) +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; + /* mode 1 == replace all weights*/ + /* mode 2 == apply to null/0 weights*/ + /* mode 3 == apply to selected weights*/ + return mode; +} + +int ED_vgroup_transfer_weight_by_nearest_face_single(Object *ob_dst, Object *ob_src, short mode) { bDeformGroup *dg_src, *dg_dst; Mesh *me_dst; @@ -604,6 +681,11 @@ int ED_vgroup_copy_by_nearest_face_single(Object *ob_dst, Object *ob_src) 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]; + /* mode 1 == replace all weights*/ + /* mode 2 == apply to null/0 weights*/ + /* mode 3 == apply to selected weights*/ + return mode; + /*get source deform group*/ dg_src= BLI_findlink(&ob_src->defbase, (ob_src->actdef-1)); @@ -680,6 +762,7 @@ int ED_vgroup_copy_by_nearest_face_single(Object *ob_dst, Object *ob_src) return 1; } +/********************** End transfer weight functions *********************/ /* for Mesh in Object mode */ /* allows editmode for Lattice */ @@ -3048,7 +3131,6 @@ static int vertex_group_copy_to_selected_exec(bContext *C, wmOperator *op) return OPERATOR_FINISHED; } - void OBJECT_OT_vertex_group_copy_to_selected(wmOperatorType *ot) { /* identifiers */ @@ -3074,12 +3156,8 @@ static int vertex_group_copy_to_selected_single_exec(bContext *C, wmOperator *op CTX_DATA_BEGIN(C, Object*, obslc, selected_editable_objects) { if(obact != obslc) { - /*Try function for matching number of vertices*/ + /*Try function for matching indices*/ if(ED_vgroup_copy_single(obslc, obact)) change++; - /*Try function for get weight from closest vertex*/ - /*TODO: try this function*/ - /*Try function for get weight from closest face*/ - else if(ED_vgroup_copy_by_nearest_face_single(obslc, obact)) change++; /*Trigger error message*/ else fail++; /*Event notifiers for correct display of data*/ @@ -3093,7 +3171,7 @@ static int vertex_group_copy_to_selected_single_exec(bContext *C, wmOperator *op /*Report error when task can not be completed with available functions.*/ if((change == 0 && fail == 0) || fail) { BKE_reportf(op->reports, RPT_ERROR, - "Copy to VGroups to Selected warning done %d, failed %d, All functions failed!", + "Copy to VGroups to Selected single warning done %d, failed %d, object data must have matching indices", change, fail); } @@ -3116,6 +3194,110 @@ void OBJECT_OT_vertex_group_copy_to_selected_single(wmOperatorType *ot) ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; } +static int vertex_group_transfer_weight_exec(bContext *C, wmOperator *op) +{ + Object *obact= CTX_data_active_object(C); + int change= 0; + int fail= 0; + + /*TODO: get this parameter*/ + short option= 2; + /* option 1 == single*/ + /* option 2 == all*/ + + /*TODO: get this parameter*/ + short method= 1; + /*method 1 == by matching indices*/ + /*method 2 == by nearest vertex*/ + /*method 3 == by nearest vertex in face*/ + /*method 4 == by nearest face*/ + + /*TODO: get this parameter*/ + short mode= 1; + /* mode is passed on to lower funtions*/ + + /*Macro to loop through selected objects and perform operation*/ + CTX_DATA_BEGIN(C, Object*, obslc, selected_editable_objects) + { + /*check if object is the same*/ + if(obact != obslc) { + /*apply option*/ + if(option == 1){ + /*apply method*/ + if(method == 1){ + /*Try function with mode*/ + if(ED_vgroup_transfer_weight_by_index_single(obslc, obact, mode)) change++; /*(tmp dev info remove) tested and working*/ + else fail++; + } + else if(method == 2){ + if(ED_vgroup_transfer_weight_by_nearest_vertex_single(obslc, obact, mode)) change++; + else fail++; + } + else if(method == 3){ + if(ED_vgroup_transfer_weight_by_nearest_vertex_in_face_single(obslc, obact, mode)) change++; + else fail++; + } + else if(method == 4){ + if(ED_vgroup_transfer_weight_by_nearest_face_single(obslc, obact, mode)) change++; + else fail++; + } + else fail++; + } + else if(option == 2){ + if(method == 1){ + if(ED_vgroup_transfer_weight_by_index_all(obslc, obact, mode)) change++; /*(tmp dev info remove) tested and working*/ + else fail++; + } + else if(method == 2){ + if(ED_vgroup_transfer_weight_by_nearest_vertex_all(obslc, obact, mode)) change++; + else fail++; + } + else if(method == 3){ + if(ED_vgroup_transfer_weight_by_nearest_vertex_in_face_all(obslc, obact, mode)) change++; + else fail++; + } + else if(method == 4){ + if(ED_vgroup_transfer_weight_by_nearest_face_all(obslc, obact, mode)) change++; + else fail++; /*Trigger error message on function failed, includes unknown mode)*/ + } + else fail++; /*Trigger error message on unknown method*/ + } + else fail++; /*Trigger error message on unknown option*/ + + /*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; + + /*Report error when task can not be completed with available functions.*/ + if((change == 0 && fail == 0) || fail) { + BKE_reportf(op->reports, RPT_ERROR, + "Copy to VGroups to Selected warning done %d, failed %d, unknown option/method or All functions failed!", + change, fail); + } + + return OPERATOR_FINISHED; +} + +/*transfers weight from active to selected*/ +void OBJECT_OT_vertex_group_transfer_weight(wmOperatorType *ot) +{ + /* identifiers */ + ot->name= "Transfer weight to selected"; + ot->idname= "OBJECT_OT_vertex_group_transfer_weight"; + ot->description= "Transfers weight from active to selected depending on options"; + + /* api callbacks */ + ot->poll= vertex_group_poll; + ot->exec= vertex_group_transfer_weight_exec; + + /* flags */ + ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; +} + static EnumPropertyItem vgroup_items[] = { {0, NULL, 0, NULL, NULL} }; -- cgit v1.2.3 From 506057c83b2925bd17477a12a5e3fc26a3a9cd6a Mon Sep 17 00:00:00 2001 From: Ove Murberg Henriksen Date: Thu, 17 May 2012 03:15:39 +0000 Subject: Fixed readabillity of options framework by adding enums. --- source/blender/editors/object/object_vgroup.c | 82 ++++++++++++++------------- 1 file changed, 43 insertions(+), 39 deletions(-) diff --git a/source/blender/editors/object/object_vgroup.c b/source/blender/editors/object/object_vgroup.c index 7cbf0e2145c..c1338ceabe5 100644 --- a/source/blender/editors/object/object_vgroup.c +++ b/source/blender/editors/object/object_vgroup.c @@ -3201,68 +3201,72 @@ static int vertex_group_transfer_weight_exec(bContext *C, wmOperator *op) int fail= 0; /*TODO: get this parameter*/ - short option= 2; - /* option 1 == single*/ - /* option 2 == all*/ + enum option {single =1, all =2}; + enum option option_choise= 1; /*TODO: get this parameter*/ - short method= 1; - /*method 1 == by matching indices*/ - /*method 2 == by nearest vertex*/ - /*method 3 == by nearest vertex in face*/ - /*method 4 == by nearest face*/ + enum method {by_index = 1, by_nearest_vertex = 2, by_nearest_vertex_in_face = 3, by_nearest_face = 4}; + enum method method_choise= 1; /*TODO: get this parameter*/ short mode= 1; /* mode is passed on to lower funtions*/ - /*Macro to loop through selected objects and perform operation*/ + /*Macro to loop through selected objects and perform operation depending on option and method*/ CTX_DATA_BEGIN(C, Object*, obslc, selected_editable_objects) { - /*check if object is the same*/ if(obact != obslc) { - /*apply option*/ - if(option == 1){ - /*apply method*/ - if(method == 1){ - /*Try function with mode*/ - if(ED_vgroup_transfer_weight_by_index_single(obslc, obact, mode)) change++; /*(tmp dev info remove) tested and working*/ + switch(option_choise){ + + /*single*/ + case(single): + switch(method_choise){ + + case(by_index): + if(ED_vgroup_transfer_weight_by_index_single(obslc, obact, mode)) change++; else fail++; - } - else if(method == 2){ + break; + + case(by_nearest_vertex): if(ED_vgroup_transfer_weight_by_nearest_vertex_single(obslc, obact, mode)) change++; else fail++; - } - else if(method == 3){ + break; + + case(by_nearest_vertex_in_face): if(ED_vgroup_transfer_weight_by_nearest_vertex_in_face_single(obslc, obact, mode)) change++; else fail++; - } - else if(method == 4){ + break; + + case(by_nearest_face): if(ED_vgroup_transfer_weight_by_nearest_face_single(obslc, obact, mode)) change++; else fail++; + break; } - else fail++; - } - else if(option == 2){ - if(method == 1){ - if(ED_vgroup_transfer_weight_by_index_all(obslc, obact, mode)) change++; /*(tmp dev info remove) tested and working*/ + + /*all*/ + case(all): + switch(method_choise){ + case(by_index): + if(ED_vgroup_transfer_weight_by_index_all(obslc, obact, mode)) change++; else fail++; - } - else if(method == 2){ - if(ED_vgroup_transfer_weight_by_nearest_vertex_all(obslc, obact, mode)) change++; + break; + + case(by_nearest_vertex): + if(ED_vgroup_transfer_weight_by_nearest_vertex_single(obslc, obact, mode)) change++; else fail++; - } - else if(method == 3){ - if(ED_vgroup_transfer_weight_by_nearest_vertex_in_face_all(obslc, obact, mode)) change++; + break; + + case(by_nearest_vertex_in_face): + if(ED_vgroup_transfer_weight_by_nearest_vertex_in_face_single(obslc, obact, mode)) change++; else fail++; + break; + + case(by_nearest_face): + if(ED_vgroup_transfer_weight_by_nearest_face_single(obslc, obact, mode)) change++; + else fail++; + break; } - else if(method == 4){ - if(ED_vgroup_transfer_weight_by_nearest_face_all(obslc, obact, mode)) change++; - else fail++; /*Trigger error message on function failed, includes unknown mode)*/ - } - else fail++; /*Trigger error message on unknown method*/ } - else fail++; /*Trigger error message on unknown option*/ /*Event notifiers for correct display of data*/ DAG_id_tag_update(&obslc->id, OB_RECALC_DATA); -- cgit v1.2.3 From e7970575efe4a9efbf83917d85bb60db7364ee9f Mon Sep 17 00:00:00 2001 From: Ove Murberg Henriksen Date: Thu, 17 May 2012 03:18:47 +0000 Subject: bugfix (using _all not _single as postfix for functions); --- source/blender/editors/object/object_vgroup.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/source/blender/editors/object/object_vgroup.c b/source/blender/editors/object/object_vgroup.c index c1338ceabe5..0c53399c532 100644 --- a/source/blender/editors/object/object_vgroup.c +++ b/source/blender/editors/object/object_vgroup.c @@ -3252,17 +3252,17 @@ static int vertex_group_transfer_weight_exec(bContext *C, wmOperator *op) 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_all(obslc, obact, mode)) change++; else fail++; break; case(by_nearest_vertex_in_face): - if(ED_vgroup_transfer_weight_by_nearest_vertex_in_face_single(obslc, obact, mode)) change++; + 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_single(obslc, obact, mode)) change++; + if(ED_vgroup_transfer_weight_by_nearest_face_all(obslc, obact, mode)) change++; else fail++; break; } -- cgit v1.2.3 From daa4b41fb2fd3f154e4f582fbab1f8c2179cafa1 Mon Sep 17 00:00:00 2001 From: Ove Murberg Henriksen Date: Thu, 17 May 2012 08:10:19 +0000 Subject: Fucntions adjusted to support options. (still lacking feature for selected and option for all) --- source/blender/editors/object/object_vgroup.c | 554 ++++++++++++++++++-------- 1 file changed, 390 insertions(+), 164 deletions(-) diff --git a/source/blender/editors/object/object_vgroup.c b/source/blender/editors/object/object_vgroup.c index 0c53399c532..1c30c0b2510 100644 --- a/source/blender/editors/object/object_vgroup.c +++ b/source/blender/editors/object/object_vgroup.c @@ -424,17 +424,17 @@ int ED_vgroup_copy_single(Object *ob_dst, const Object *ob_src) int ED_vgroup_transfer_weight_by_index_all(Object *ob_dst, Object *ob_src, short mode) { - /* mode 1 == replace all weights*/ + if(mode == 1){ return ED_vgroup_copy_array(ob_dst, ob_src); } - /* mode 2 == apply to null/0 weights*/ + else if(mode == 2){ return 0; } - /* mode 3 == apply to selected weights*/ + else if(mode == 3){ return 0; } @@ -443,19 +443,72 @@ int ED_vgroup_transfer_weight_by_index_all(Object *ob_dst, Object *ob_src, short int ED_vgroup_transfer_weight_by_index_single(Object *ob_dst, Object *ob_src, short mode) { + 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*/ + if(!defgroup_find_name(ob_dst, dg_src->name) || mode == 1){ + 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; + } + /* mode 1 == replace all weights*/ if(mode == 1){ - return ED_vgroup_copy_single(ob_dst, ob_src); + /* loop through the vertices and copy weight*/ + for(i=0; iweight= dw_src->weight; + } + return 1; } - /* mode 2 == apply to null/0 weights*/ + /* mode 2 == replace null weights*/ else if(mode == 2){ - return 0; + /* loop through the vertices and copy weight*/ + for(i=0; iweight || dw_dst->weight == 0) dw_dst->weight= dw_src->weight; + } + return 1; } - /* mode 3 == apply to selected weights*/ + /* mode 3 == replace selected weights*/ else if(mode == 3){ - return 0; + /* loop through the vertices and copy weight*/ + for(i=0; iflag == 1) dw_dst->weight= dw_src->weight; /*this does not work*/ + } + return 1; } else return 0; } @@ -464,9 +517,6 @@ int ED_vgroup_transfer_weight_by_nearest_vertex_all(Object *ob_dst, Object *ob_s { ob_dst= ob_dst; ob_src= ob_src; - /* mode 1 == replace all weights*/ - /* mode 2 == apply to null/0 weights*/ - /* mode 3 == apply to selected weights*/ return mode; } @@ -483,17 +533,14 @@ 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]; - /* mode 1 == replace all weights*/ - /* mode 2 == apply to null/0 weights*/ - /* mode 3 == apply to selected weights*/ - return mode; - /*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); + if(!defgroup_find_name(ob_dst, dg_src->name) || mode == 1){ + 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); @@ -521,37 +568,74 @@ 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); - /* 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 vetex*/ - BLI_bvhtree_find_nearest(tree_mesh_src.tree, tmp_co, &nearest, tree_mesh_src.nearest_callback, &tree_mesh_src); - - /*copy weight*/ - 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; + /* 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; } - - /*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; - /* mode 1 == replace all weights*/ - /* mode 2 == apply to null/0 weights*/ - /* mode 3 == apply to selected weights*/ return mode; } @@ -569,17 +653,14 @@ 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]; - /* mode 1 == replace all weights*/ - /* mode 2 == apply to null/0 weights*/ - /* mode 3 == apply to selected weights*/ - return mode; - /*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); + if(!defgroup_find_name(ob_dst, dg_src->name) || mode == 1){ + 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); @@ -611,59 +692,136 @@ 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); - /* 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_v1totvert; 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_v1weight= dw_src->weight; } + /*free memory and return*/ + free_bvhtree_from_mesh(&tree_mesh_faces_src); + return 1; + } - /*copy weight*/ - dw_dst= defvert_verify_index(*dv_array_dst, index_dst); - dw_dst->weight= dw_src->weight; + /* 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_v1weight || dw_dst->weight == 0) dw_dst->weight= dw_src->weight; + } + /*free memory and return*/ + free_bvhtree_from_mesh(&tree_mesh_faces_src); + return 1; } - /*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_v1weight= dw_src->weight;*/ /*TODO: fix this!*/ + } + /*free memory and return*/ + free_bvhtree_from_mesh(&tree_mesh_faces_src); + return 1; + } + 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; - /* mode 1 == replace all weights*/ - /* mode 2 == apply to null/0 weights*/ - /* mode 3 == apply to selected weights*/ return mode; } @@ -681,17 +839,14 @@ 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]; - /* mode 1 == replace all weights*/ - /* mode 2 == apply to null/0 weights*/ - /* mode 3 == apply to selected weights*/ - return mode; - /*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); + if(!defgroup_find_name(ob_dst, dg_src->name) || mode == 1){ + 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); @@ -723,43 +878,106 @@ 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); - /* 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; + /* 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; } - - /*free memory and return*/ - free_bvhtree_from_mesh(&tree_mesh_faces_src); - return 1; + else return 0; } /********************** End transfer weight functions *********************/ @@ -3201,70 +3419,78 @@ static int vertex_group_transfer_weight_exec(bContext *C, wmOperator *op) int fail= 0; /*TODO: get this parameter*/ - enum option {single =1, all =2}; - enum option option_choise= 1; + enum option {single =1, all =2} option= 1; /*TODO: get this parameter*/ - enum method {by_index = 1, by_nearest_vertex = 2, by_nearest_vertex_in_face = 3, by_nearest_face = 4}; - enum method method_choise= 1; + 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*/ - short mode= 1; /* 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*/ CTX_DATA_BEGIN(C, Object*, obslc, selected_editable_objects) { if(obact != obslc) { - switch(option_choise){ + switch(option){ /*single*/ case(single): - switch(method_choise){ + switch(method){ case(by_index): if(ED_vgroup_transfer_weight_by_index_single(obslc, obact, mode)) change++; - else fail++; - break; + else fail++; break; case(by_nearest_vertex): if(ED_vgroup_transfer_weight_by_nearest_vertex_single(obslc, obact, mode)) change++; - else fail++; - break; + else fail++; break; - case(by_nearest_vertex_in_face): + case(by_nearest_face): if(ED_vgroup_transfer_weight_by_nearest_vertex_in_face_single(obslc, obact, mode)) change++; - else fail++; - break; + else fail++; break; - case(by_nearest_face): + case(by_nearest_vertex_in_face): if(ED_vgroup_transfer_weight_by_nearest_face_single(obslc, obact, mode)) change++; - else fail++; - break; + else fail++; break; } /*all*/ case(all): - switch(method_choise){ + switch(method){ case(by_index): - if(ED_vgroup_transfer_weight_by_index_all(obslc, obact, mode)) change++; - else fail++; - break; + /*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; + /*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; + /*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; + /*if(ED_vgroup_transfer_weight_by_nearest_face_all(obslc, obact, mode)) change++; + else fail++;*/ break; } } -- cgit v1.2.3 From f4f5254100c16f7e9906dffcdc9695295e27c7e2 Mon Sep 17 00:00:00 2001 From: Ove Murberg Henriksen Date: Thu, 17 May 2012 09:47:11 +0000 Subject: cleanup: Style = adding spaces around operators. --- source/blender/editors/object/object_vgroup.c | 326 +++++++++++++------------- 1 file changed, 163 insertions(+), 163 deletions(-) diff --git a/source/blender/editors/object/object_vgroup.c b/source/blender/editors/object/object_vgroup.c index 1c30c0b2510..fd98f7aaa3c 100644 --- a/source/blender/editors/object/object_vgroup.c +++ b/source/blender/editors/object/object_vgroup.c @@ -387,22 +387,22 @@ int ED_vgroup_copy_single(Object *ob_dst, const Object *ob_src) bDeformGroup *dg_src, *dg_dst; /*get source deform group*/ - dg_src= BLI_findlink(&ob_src->defbase, (ob_src->actdef-1)); + 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); + 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); + 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) { @@ -411,10 +411,10 @@ int ED_vgroup_copy_single(Object *ob_dst, const Object *ob_src) } /* loop through the vertices and copy weight*/ - for(i=0; iweight= dw_src->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; @@ -451,7 +451,7 @@ int ED_vgroup_transfer_weight_by_index_single(Object *ob_dst, Object *ob_src, sh bDeformGroup *dg_src, *dg_dst; /*get source deform group*/ - dg_src= BLI_findlink(&ob_src->defbase, (ob_src->actdef-1)); + 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){ @@ -460,15 +460,15 @@ int ED_vgroup_transfer_weight_by_index_single(Object *ob_dst, Object *ob_src, sh } /*get destination deformgroup*/ - dg_dst= defgroup_find_name(ob_dst, dg_src->name); + 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); + 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) { @@ -479,10 +479,10 @@ int ED_vgroup_transfer_weight_by_index_single(Object *ob_dst, Object *ob_src, sh /* mode 1 == replace all weights*/ if(mode == 1){ /* loop through the vertices and copy weight*/ - for(i=0; iweight= dw_src->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; } @@ -490,11 +490,11 @@ int ED_vgroup_transfer_weight_by_index_single(Object *ob_dst, Object *ob_src, sh /* mode 2 == replace null weights*/ else if(mode == 2){ /* loop through the vertices and copy weight*/ - for(i=0; iweight || dw_dst->weight == 0) dw_dst->weight= dw_src->weight; + if(!dw_dst->weight || dw_dst->weight == 0) dw_dst->weight = dw_src->weight; } return 1; } @@ -502,11 +502,11 @@ int ED_vgroup_transfer_weight_by_index_single(Object *ob_dst, Object *ob_src, sh /* mode 3 == replace selected weights*/ else if(mode == 3){ /* loop through the vertices and copy weight*/ - for(i=0; iflag == 1) dw_dst->weight= dw_src->weight; /*this does not work*/ + if((*dv_array_src)->flag == 1) dw_dst->weight = dw_src->weight; /*This does not work*/ } return 1; } @@ -515,8 +515,8 @@ int ED_vgroup_transfer_weight_by_index_single(Object *ob_dst, Object *ob_src, sh 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; + ob_dst = ob_dst; + ob_src = ob_src; return mode; } @@ -534,7 +534,7 @@ int ED_vgroup_transfer_weight_by_nearest_vertex_single(Object *ob_dst, Object *o float tmp_co[3], tmp_mat[4][4]; /*get source deform group*/ - dg_src= BLI_findlink(&ob_src->defbase, (ob_src->actdef-1)); + 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){ @@ -543,11 +543,11 @@ int ED_vgroup_transfer_weight_by_nearest_vertex_single(Object *ob_dst, Object *o } /*get destination deformgroup*/ - dg_dst= defgroup_find_name(ob_dst, dg_src->name); + dg_dst = defgroup_find_name(ob_dst, dg_src->name); /*get meshes*/ - me_dst= ob_dst->data; - dmesh_src= ob_src->derivedDeform; + me_dst = ob_dst->data; + dmesh_src = ob_src->derivedDeform; /*make node tree*/ bvhtree_from_mesh_verts(&tree_mesh_src, dmesh_src, 0.0, 2, 6); @@ -557,11 +557,11 @@ int ED_vgroup_transfer_weight_by_nearest_vertex_single(Object *ob_dst, Object *o 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); + index_src = BLI_findindex(&ob_src->defbase, dg_src); + index_dst = BLI_findindex(&ob_dst->defbase, dg_dst); /*get vertices*/ - mv_dst= me_dst->mvert; + 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*/ @@ -571,17 +571,17 @@ int ED_vgroup_transfer_weight_by_nearest_vertex_single(Object *ob_dst, Object *o /* 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++){ + for(i = 0; i < me_dst->totvert; i++, mv_dst++, dv_array_dst++){ /*reset nearest*/ - nearest.index= -1; - nearest.dist= FLT_MAX; + 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; + 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); @@ -591,18 +591,18 @@ int ED_vgroup_transfer_weight_by_nearest_vertex_single(Object *ob_dst, Object *o /* 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++){ + for(i = 0; i < me_dst->totvert; i++, mv_dst++, dv_array_dst++){ /*reset nearest*/ - nearest.index= -1; - nearest.dist= FLT_MAX; + 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_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; + 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); @@ -612,16 +612,16 @@ int ED_vgroup_transfer_weight_by_nearest_vertex_single(Object *ob_dst, Object *o /* 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++){ + for(i = 0; i < me_dst->totvert; i++, mv_dst++, dv_array_dst++){ /*reset nearest*/ - nearest.index= -1; - nearest.dist= FLT_MAX; + 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_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*/ } @@ -634,8 +634,8 @@ int ED_vgroup_transfer_weight_by_nearest_vertex_single(Object *ob_dst, Object *o 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; + ob_dst = ob_dst; + ob_src = ob_src; return mode; } @@ -654,7 +654,7 @@ int ED_vgroup_transfer_weight_by_nearest_vertex_in_face_single(Object *ob_dst, O float dist_v1, dist_v2, dist_v3, dist_v4, tmp_co[3], tmp_mat[4][4]; /*get source deform group*/ - dg_src= BLI_findlink(&ob_src->defbase, (ob_src->actdef-1)); + 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){ @@ -663,11 +663,11 @@ int ED_vgroup_transfer_weight_by_nearest_vertex_in_face_single(Object *ob_dst, O } /*get destination deformgroup*/ - dg_dst= defgroup_find_name(ob_dst, dg_src->name); + dg_dst = defgroup_find_name(ob_dst, dg_src->name); /*get meshes*/ - me_dst= ob_dst->data; - dmesh_src= ob_src->derivedDeform; + me_dst = ob_dst->data; + dmesh_src = ob_src->derivedDeform; /*make node tree*/ DM_ensure_tessface(dmesh_src); @@ -678,15 +678,15 @@ int ED_vgroup_transfer_weight_by_nearest_vertex_in_face_single(Object *ob_dst, O 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); + index_src = BLI_findindex(&ob_src->defbase, dg_src); + index_dst = BLI_findindex(&ob_dst->defbase, dg_dst); /*get vertices*/ - mv_dst= me_dst->mvert; - mv_src= dmesh_src->getVertArray(dmesh_src); + mv_dst = me_dst->mvert; + mv_src = dmesh_src->getVertArray(dmesh_src); /*get faces*/ - mface_src= dmesh_src->getTessFaceArray(dmesh_src); + mface_src = dmesh_src->getTessFaceArray(dmesh_src); /*prepare transformation matrix*/ invert_m4_m4(ob_src->imat, ob_src->obmat); @@ -695,38 +695,38 @@ int ED_vgroup_transfer_weight_by_nearest_vertex_in_face_single(Object *ob_dst, O /* 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++){ + for(i = 0; i < me_dst->totvert; i++, mv_dst++, dv_array_dst++){ /*reset nearest*/ - nearest.index= -1; - nearest.dist= FLT_MAX; + 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); + 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_v1weight= dw_src->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); @@ -738,37 +738,37 @@ int ED_vgroup_transfer_weight_by_nearest_vertex_in_face_single(Object *ob_dst, O /* 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; + 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); + 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_v1weight || dw_dst->weight == 0) dw_dst->weight= dw_src->weight; + 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); @@ -778,37 +778,37 @@ int ED_vgroup_transfer_weight_by_nearest_vertex_in_face_single(Object *ob_dst, O /* 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++){ + for(i = 0; i < me_dst->totvert; i++, mv_dst++, dv_array_dst++){ /*reset nearest*/ - nearest.index= -1; - nearest.dist= FLT_MAX; + 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); + 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_v1weight= dw_src->weight;*/ /*TODO: fix this!*/ } /*free memory and return*/ @@ -820,8 +820,8 @@ int ED_vgroup_transfer_weight_by_nearest_vertex_in_face_single(Object *ob_dst, O 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; + ob_dst = ob_dst; + ob_src = ob_src; return mode; } @@ -840,7 +840,7 @@ int ED_vgroup_transfer_weight_by_nearest_face_single(Object *ob_dst, Object *ob_ float weight, tmp_weight[4], tmp_co[3], normal[3], tmp_mat[4][4]; /*get source deform group*/ - dg_src= BLI_findlink(&ob_src->defbase, (ob_src->actdef-1)); + 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){ @@ -849,11 +849,11 @@ int ED_vgroup_transfer_weight_by_nearest_face_single(Object *ob_dst, Object *ob_ } /*get destination deformgroup*/ - dg_dst= defgroup_find_name(ob_dst, dg_src->name); + dg_dst = defgroup_find_name(ob_dst, dg_src->name); /*get meshes*/ - me_dst= ob_dst->data; - dmesh_src= ob_src->derivedDeform; + me_dst = ob_dst->data; + dmesh_src = ob_src->derivedDeform; /*make node tree*/ DM_ensure_tessface(dmesh_src); @@ -864,15 +864,15 @@ int ED_vgroup_transfer_weight_by_nearest_face_single(Object *ob_dst, Object *ob_ 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); + index_src = BLI_findindex(&ob_src->defbase, dg_src); + index_dst = BLI_findindex(&ob_dst->defbase, dg_dst); /*get vertices*/ - mv_dst= me_dst->mvert; - mv_src= dmesh_src->getVertArray(dmesh_src); + mv_dst = me_dst->mvert; + mv_src = dmesh_src->getVertArray(dmesh_src); /*get faces*/ - mface_src= dmesh_src->getTessFaceArray(dmesh_src); + mface_src = dmesh_src->getTessFaceArray(dmesh_src); /*prepare transformation matrix*/ invert_m4_m4(ob_src->imat, ob_src->obmat); @@ -881,10 +881,10 @@ int ED_vgroup_transfer_weight_by_nearest_face_single(Object *ob_dst, Object *ob_ /* 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++){ + for(i = 0; i < me_dst->totvert; i++, mv_dst++, dv_array_dst++){ /*reset nearest*/ - nearest.index= -1; - nearest.dist= FLT_MAX; + 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); @@ -898,13 +898,13 @@ int ED_vgroup_transfer_weight_by_nearest_face_single(Object *ob_dst, Object *ob_ 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; + 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; + 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); @@ -914,10 +914,10 @@ int ED_vgroup_transfer_weight_by_nearest_face_single(Object *ob_dst, Object *ob_ /* 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++){ + for(i = 0; i < me_dst->totvert; i++, mv_dst++, dv_array_dst++){ /*reset nearest*/ - nearest.index= -1; - nearest.dist= FLT_MAX; + 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); @@ -931,14 +931,14 @@ int ED_vgroup_transfer_weight_by_nearest_face_single(Object *ob_dst, Object *ob_ 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; + 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 = 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; + if(!dw_dst->weight || dw_dst->weight == 0) dw_dst->weight = weight; } /*free memory and return*/ free_bvhtree_from_mesh(&tree_mesh_faces_src); @@ -948,10 +948,10 @@ int ED_vgroup_transfer_weight_by_nearest_face_single(Object *ob_dst, Object *ob_ /* 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++){ + for(i = 0; i < me_dst->totvert; i++, mv_dst++, dv_array_dst++){ /*reset nearest*/ - nearest.index= -1; - nearest.dist= FLT_MAX; + 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); @@ -965,12 +965,12 @@ int ED_vgroup_transfer_weight_by_nearest_face_single(Object *ob_dst, Object *ob_ 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; + 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 = defvert_verify_index(*dv_array_dst, index_dst); /*dw_dst->weight= weight;*//*TODO: fix this!*/ } /*free memory and return*/ @@ -3366,9 +3366,9 @@ void OBJECT_OT_vertex_group_copy_to_selected(wmOperatorType *ot) static int vertex_group_copy_to_selected_single_exec(bContext *C, wmOperator *op) { - Object *obact= CTX_data_active_object(C); - int change= 0; - int fail= 0; + Object *obact = CTX_data_active_object(C); + int change = 0; + int fail = 0; /*Macro to loop through selected objects and perform operation*/ CTX_DATA_BEGIN(C, Object*, obslc, selected_editable_objects) @@ -3400,33 +3400,33 @@ static int vertex_group_copy_to_selected_single_exec(bContext *C, wmOperator *op void OBJECT_OT_vertex_group_copy_to_selected_single(wmOperatorType *ot) { /* identifiers */ - ot->name= "Copy a Vertex Group to Selected"; - ot->idname= "OBJECT_OT_vertex_group_copy_to_selected_single"; - ot->description= "Copy a vertex group to other selected objects with matching indices"; + ot->name = "Copy a Vertex Group to Selected"; + ot->idname = "OBJECT_OT_vertex_group_copy_to_selected_single"; + ot->description = "Copy a vertex group to other selected objects with matching indices"; /* api callbacks */ - ot->poll= vertex_group_poll; - ot->exec= vertex_group_copy_to_selected_single_exec; + ot->poll = vertex_group_poll; + ot->exec = vertex_group_copy_to_selected_single_exec; /* flags */ - ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; } static int vertex_group_transfer_weight_exec(bContext *C, wmOperator *op) { - Object *obact= CTX_data_active_object(C); - int change= 0; - int fail= 0; + Object *obact = CTX_data_active_object(C); + 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; + 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; + short mode = 2; /* mode 1 == replace all weights*/ /* mode 2 == replace null weights*/ @@ -3516,16 +3516,16 @@ static int vertex_group_transfer_weight_exec(bContext *C, wmOperator *op) void OBJECT_OT_vertex_group_transfer_weight(wmOperatorType *ot) { /* identifiers */ - ot->name= "Transfer weight to selected"; - ot->idname= "OBJECT_OT_vertex_group_transfer_weight"; - ot->description= "Transfers weight from active to selected depending on options"; + ot->name = "Transfer weight to selected"; + ot->idname = "OBJECT_OT_vertex_group_transfer_weight"; + ot->description = "Transfers weight from active to selected depending on options"; /* api callbacks */ - ot->poll= vertex_group_poll; - ot->exec= vertex_group_transfer_weight_exec; + ot->poll = vertex_group_poll; + ot->exec = vertex_group_transfer_weight_exec; /* flags */ - ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; } static EnumPropertyItem vgroup_items[] = { -- cgit v1.2.3 From 044fd86a15b358a5e250896b88d493c17c3d5e21 Mon Sep 17 00:00:00 2001 From: Ove Murberg Henriksen Date: Thu, 17 May 2012 12:15:39 +0000 Subject: Some changes to structure as a response to review. (I still havent adressed all issues.) --- source/blender/editors/object/object_vgroup.c | 585 +++++++------------------- 1 file 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; -- cgit v1.2.3 From 8521ca69fac26ebfa14910566f2271562e1ff0b5 Mon Sep 17 00:00:00 2001 From: Ove Murberg Henriksen Date: Thu, 17 May 2012 12:36:07 +0000 Subject: removed: OBJECT_OT_vertex_group_copy_to_selected_single() plan for future to implement option as an argument in: OBJECT_OT_vertex_group_copy_to_selected() --- source/blender/editors/object/object_intern.h | 1 - source/blender/editors/object/object_ops.c | 1 - source/blender/editors/object/object_vgroup.c | 71 +++++---------------------- 3 files changed, 13 insertions(+), 60 deletions(-) diff --git a/source/blender/editors/object/object_intern.h b/source/blender/editors/object/object_intern.h index 5269caab426..4d67a620939 100644 --- a/source/blender/editors/object/object_intern.h +++ b/source/blender/editors/object/object_intern.h @@ -198,7 +198,6 @@ void OBJECT_OT_vertex_group_deselect(struct wmOperatorType *ot); void OBJECT_OT_vertex_group_copy_to_linked(struct wmOperatorType *ot); void OBJECT_OT_vertex_group_transfer_weight(struct wmOperatorType *ot); void OBJECT_OT_vertex_group_copy_to_selected(struct wmOperatorType *ot); -void OBJECT_OT_vertex_group_copy_to_selected_single(struct wmOperatorType *ot); void OBJECT_OT_vertex_group_copy(struct wmOperatorType *ot); void OBJECT_OT_vertex_group_normalize(struct wmOperatorType *ot); void OBJECT_OT_vertex_group_normalize_all(struct wmOperatorType *ot); diff --git a/source/blender/editors/object/object_ops.c b/source/blender/editors/object/object_ops.c index 7e535eed29d..986a294d065 100644 --- a/source/blender/editors/object/object_ops.c +++ b/source/blender/editors/object/object_ops.c @@ -172,7 +172,6 @@ void ED_operatortypes_object(void) WM_operatortype_append(OBJECT_OT_vertex_group_copy_to_linked); WM_operatortype_append(OBJECT_OT_vertex_group_transfer_weight); WM_operatortype_append(OBJECT_OT_vertex_group_copy_to_selected); - WM_operatortype_append(OBJECT_OT_vertex_group_copy_to_selected_single); WM_operatortype_append(OBJECT_OT_vertex_group_copy); WM_operatortype_append(OBJECT_OT_vertex_group_normalize); WM_operatortype_append(OBJECT_OT_vertex_group_normalize_all); diff --git a/source/blender/editors/object/object_vgroup.c b/source/blender/editors/object/object_vgroup.c index d1622e507d0..41fbbfdac14 100644 --- a/source/blender/editors/object/object_vgroup.c +++ b/source/blender/editors/object/object_vgroup.c @@ -437,6 +437,7 @@ int ED_vgroup_transfer_weight_by_index(Object *ob_dst, Object *ob_src, short mod /*remove this:*/ option=option; + /*TODO: for option all, loop through all vertex groups*/ /*get source deform group*/ dg_src = BLI_findlink(&ob_src->defbase, (ob_src->actdef-1)); @@ -3110,6 +3111,10 @@ static int vertex_group_copy_to_selected_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. +*/ void OBJECT_OT_vertex_group_copy_to_selected(wmOperatorType *ot) { /* identifiers */ @@ -3125,64 +3130,6 @@ void OBJECT_OT_vertex_group_copy_to_selected(wmOperatorType *ot) ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; } -static int vertex_group_copy_to_selected_single_exec(bContext *C, wmOperator *op) -{ - Object *obact = CTX_data_active_object(C); - int change = 0; - int fail = 0; - - /*Macro to loop through selected objects and perform operation*/ - CTX_DATA_BEGIN(C, Object*, obslc, selected_editable_objects) - { - if(obact != obslc) { - /*Try function for matching indices*/ - if(ED_vgroup_copy_single(obslc, obact)) change++; - /*Trigger error message*/ - else fail++; - /*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; - - /*Report error when task can not be completed with available functions.*/ - if((change == 0 && fail == 0) || fail) { - BKE_reportf(op->reports, RPT_ERROR, - "Copy to VGroups to Selected single warning done %d, failed %d, object data must have matching indices", - change, fail); - } - - 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) -{ - /* identifiers */ - ot->name = "Copy a Vertex Group to Selected"; - ot->idname = "OBJECT_OT_vertex_group_copy_to_selected_single"; - ot->description = "Copy a vertex group to other selected objects with matching indices"; - - /* api callbacks */ - ot->poll = vertex_group_poll; - ot->exec = vertex_group_copy_to_selected_single_exec; - - /* flags */ - ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; -} - static int vertex_group_transfer_weight_exec(bContext *C, wmOperator *op) { Object *obact = CTX_data_active_object(C); @@ -3249,6 +3196,14 @@ void OBJECT_OT_vertex_group_transfer_weight(wmOperatorType *ot) /* flags */ ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; + + /* + 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; + */ } static EnumPropertyItem vgroup_items[] = { -- cgit v1.2.3 From 79031d35f1a180bed1212c15649bd2593c7de580 Mon Sep 17 00:00:00 2001 From: Ove Murberg Henriksen Date: Mon, 21 May 2012 17:00:08 +0000 Subject: Added support for replace_selected_weights in all weight transfer fucntions. --- source/blender/editors/object/object_vgroup.c | 58 ++++++++++++++++----------- 1 file changed, 34 insertions(+), 24 deletions(-) diff --git a/source/blender/editors/object/object_vgroup.c b/source/blender/editors/object/object_vgroup.c index 41fbbfdac14..8a82f2ae107 100644 --- a/source/blender/editors/object/object_vgroup.c +++ b/source/blender/editors/object/object_vgroup.c @@ -431,6 +431,8 @@ int ED_vgroup_transfer_weight_by_index(Object *ob_dst, Object *ob_src, short mod MDeformVert **dv_array_src; MDeformVert **dv_array_dst; MDeformWeight *dw_dst, *dw_src; + MVert *mv_src; + Mesh *me_src; int dv_tot_src, dv_tot_dst; int i, index_src, index_dst; bDeformGroup *dg_src, *dg_dst; @@ -448,6 +450,12 @@ int ED_vgroup_transfer_weight_by_index(Object *ob_dst, Object *ob_src, short mod ED_vgroup_add_name(ob_dst, dg_src->name); } + /*get meshes*/ + me_src = ob_src->data; + + /*get vertices*/ + mv_src = me_src->mvert; + /*get destination deformgroup*/ dg_dst = defgroup_find_name(ob_dst, dg_src->name); @@ -460,18 +468,18 @@ int ED_vgroup_transfer_weight_by_index(Object *ob_dst, Object *ob_src, short mod 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++){ + for(i = 0; i < dv_tot_dst; i++, dv_array_src++, dv_array_dst++, mv_src++){ 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 if(mode == 3) {if(mv_src->flag == 1) dw_dst->weight = dw_src->weight;} else return 0; } return 1; @@ -482,8 +490,8 @@ int ED_vgroup_transfer_weight_by_nearest_vertex(Object *ob_dst, Object *ob_src, bDeformGroup *dg_src, *dg_dst; MDeformVert **dv_array_src, **dv_array_dst; MDeformWeight *dw_dst, *dw_src; - MVert *mv_dst; - Mesh *me_dst; + MVert *mv_dst, *mv_src; + Mesh *me_dst, *me_src; BVHTreeFromMesh tree_mesh_src; BVHTreeNearest nearest; DerivedMesh *dmesh_src; @@ -507,6 +515,7 @@ int ED_vgroup_transfer_weight_by_nearest_vertex(Object *ob_dst, Object *ob_src, /*get meshes*/ me_dst = ob_dst->data; + me_src = ob_src->data; dmesh_src = ob_src->derivedDeform; /*make node tree*/ @@ -522,6 +531,7 @@ int ED_vgroup_transfer_weight_by_nearest_vertex(Object *ob_dst, Object *ob_src, /*get vertices*/ mv_dst = me_dst->mvert; + mv_src = me_src->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*/ @@ -541,7 +551,7 @@ int ED_vgroup_transfer_weight_by_nearest_vertex(Object *ob_dst, Object *ob_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 if(mode == 3) {if(mv_src[nearest.index].flag == 1) dw_dst->weight = dw_src->weight;} else return 0; } /*free memory and return*/ @@ -560,7 +570,7 @@ int ED_vgroup_transfer_weight_by_nearest_vertex_in_face(Object *ob_dst, Object * MFace *mface_src; BVHTreeNearest nearest; MDeformWeight *dw_dst, *dw_src; - int dv_tot_src, dv_tot_dst, i, index_dst, index_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]; /*remove this:*/ @@ -623,28 +633,21 @@ also mode == 1 isnt so readable, better define an enum. 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*/ + /*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); - 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); - } + if(dist_v4 < dist_v1 && dist_v4 < dist_v2 && dist_v4 < dist_v3) index_nearest_vertex = mface_src[nearest.index].v1; } /*copy weight*/ + dw_src = defvert_verify_index(dv_array_src[index_nearest_vertex], 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!*/ + /*ATTENTION: face select in weightpaint mode seems reversed. Might create bug when fixed*/ + else if(mode == 3) {if(mface_src[nearest.index].flag != SELECT) dw_dst->weight = dw_src->weight;} else return 0; } /*free memory and return*/ @@ -734,7 +737,8 @@ int ED_vgroup_transfer_weight_by_nearest_face(Object *ob_dst, Object *ob_src, sh 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!*/ + /*ATTENTION: face select in weightpaint mode seems reversed. Might create bug when fixed*/ + else if(mode == 3) {if(mface_src[nearest.index].flag != SELECT) dw_dst->weight = weight;} else return 0; } /*free memory and return*/ @@ -3139,9 +3143,15 @@ static int vertex_group_transfer_weight_exec(bContext *C, wmOperator *op) /*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 Mode {replace_all_weights = 1, replace_empty_weights = 2, replace_selected_weights = 3} mode= 3; enum Option {single = 1, all = 2} option = 1; + /*Truth table for testing:*/ + /*1,3,1 working*/ + /*2,3,1 working*/ + /*3,3,1 working*/ + /*4,3,1 working*/ + /*Macro to loop through selected objects and perform operation depending on function, option and method*/ CTX_DATA_BEGIN(C, Object*, obslc, selected_editable_objects) { -- cgit v1.2.3 From cc5582decbbe1c548cfb6d12958680025617e787 Mon Sep 17 00:00:00 2001 From: Ove Murberg Henriksen Date: Mon, 21 May 2012 17:39:56 +0000 Subject: Fixed SELECT comparisons --- source/blender/editors/object/object_vgroup.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/source/blender/editors/object/object_vgroup.c b/source/blender/editors/object/object_vgroup.c index 8a82f2ae107..648f83c9c48 100644 --- a/source/blender/editors/object/object_vgroup.c +++ b/source/blender/editors/object/object_vgroup.c @@ -479,7 +479,7 @@ int ED_vgroup_transfer_weight_by_index(Object *ob_dst, Object *ob_src, short mod 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_src->flag == 1) dw_dst->weight = dw_src->weight;} + else if(mode == 3) {if(mv_src->flag & SELECT) dw_dst->weight = dw_src->weight;} else return 0; } return 1; @@ -551,7 +551,7 @@ int ED_vgroup_transfer_weight_by_nearest_vertex(Object *ob_dst, Object *ob_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_src[nearest.index].flag == 1) dw_dst->weight = dw_src->weight;} + else if(mode == 3) {if(mv_src[nearest.index].flag & SELECT) dw_dst->weight = dw_src->weight;} else return 0; } /*free memory and return*/ @@ -646,8 +646,7 @@ also mode == 1 isnt so readable, better define an enum. 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;} - /*ATTENTION: face select in weightpaint mode seems reversed. Might create bug when fixed*/ - else if(mode == 3) {if(mface_src[nearest.index].flag != SELECT) dw_dst->weight = dw_src->weight;} + else if(mode == 3) {if(mface_src[nearest.index].flag & ME_FACE_SEL) dw_dst->weight = dw_src->weight;} else return 0; } /*free memory and return*/ @@ -737,8 +736,7 @@ int ED_vgroup_transfer_weight_by_nearest_face(Object *ob_dst, Object *ob_src, sh 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;} - /*ATTENTION: face select in weightpaint mode seems reversed. Might create bug when fixed*/ - else if(mode == 3) {if(mface_src[nearest.index].flag != SELECT) dw_dst->weight = weight;} + else if(mode == 3) {if(mface_src[nearest.index].flag & ME_FACE_SEL) dw_dst->weight = weight;} else return 0; } /*free memory and return*/ -- cgit v1.2.3 From 6913e6dd54a5f819838adef6374bb6a9996d0d81 Mon Sep 17 00:00:00 2001 From: Ove Murberg Henriksen Date: Mon, 21 May 2012 18:15:12 +0000 Subject: Changed functions to check for select on destination instead of source --- source/blender/editors/object/object_vgroup.c | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/source/blender/editors/object/object_vgroup.c b/source/blender/editors/object/object_vgroup.c index 648f83c9c48..3fac2a7c98f 100644 --- a/source/blender/editors/object/object_vgroup.c +++ b/source/blender/editors/object/object_vgroup.c @@ -431,8 +431,8 @@ int ED_vgroup_transfer_weight_by_index(Object *ob_dst, Object *ob_src, short mod MDeformVert **dv_array_src; MDeformVert **dv_array_dst; MDeformWeight *dw_dst, *dw_src; - MVert *mv_src; - Mesh *me_src; + MVert *mv_dst; + Mesh *me_dst; int dv_tot_src, dv_tot_dst; int i, index_src, index_dst; bDeformGroup *dg_src, *dg_dst; @@ -451,10 +451,10 @@ int ED_vgroup_transfer_weight_by_index(Object *ob_dst, Object *ob_src, short mod } /*get meshes*/ - me_src = ob_src->data; + me_dst = ob_dst->data; /*get vertices*/ - mv_src = me_src->mvert; + mv_dst = me_dst->mvert; /*get destination deformgroup*/ dg_dst = defgroup_find_name(ob_dst, dg_src->name); @@ -474,12 +474,12 @@ int ED_vgroup_transfer_weight_by_index(Object *ob_dst, Object *ob_src, short mod } /* loop through the vertices and copy weight*/ - for(i = 0; i < dv_tot_dst; i++, dv_array_src++, dv_array_dst++, mv_src++){ + 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_src->flag & SELECT) dw_dst->weight = dw_src->weight;} + else if(mode == 3) {if(mv_dst->flag & SELECT) dw_dst->weight = dw_src->weight;} else return 0; } return 1; @@ -490,8 +490,8 @@ int ED_vgroup_transfer_weight_by_nearest_vertex(Object *ob_dst, Object *ob_src, bDeformGroup *dg_src, *dg_dst; MDeformVert **dv_array_src, **dv_array_dst; MDeformWeight *dw_dst, *dw_src; - MVert *mv_dst, *mv_src; - Mesh *me_dst, *me_src; + MVert *mv_dst; + Mesh *me_dst; BVHTreeFromMesh tree_mesh_src; BVHTreeNearest nearest; DerivedMesh *dmesh_src; @@ -515,7 +515,6 @@ int ED_vgroup_transfer_weight_by_nearest_vertex(Object *ob_dst, Object *ob_src, /*get meshes*/ me_dst = ob_dst->data; - me_src = ob_src->data; dmesh_src = ob_src->derivedDeform; /*make node tree*/ @@ -531,7 +530,6 @@ int ED_vgroup_transfer_weight_by_nearest_vertex(Object *ob_dst, Object *ob_src, /*get vertices*/ mv_dst = me_dst->mvert; - mv_src = me_src->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*/ @@ -551,7 +549,7 @@ int ED_vgroup_transfer_weight_by_nearest_vertex(Object *ob_dst, Object *ob_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_src[nearest.index].flag & SELECT) dw_dst->weight = dw_src->weight;} + else if(mode == 3) {if(mv_dst->flag & SELECT) dw_dst->weight = dw_src->weight;} else return 0; } /*free memory and return*/ @@ -646,7 +644,7 @@ also mode == 1 isnt so readable, better define an enum. 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(mface_src[nearest.index].flag & ME_FACE_SEL) dw_dst->weight = dw_src->weight;} + else if(mode == 3) {if(mv_dst->flag & SELECT) dw_dst->weight = dw_src->weight;} else return 0; } /*free memory and return*/ @@ -736,7 +734,7 @@ int ED_vgroup_transfer_weight_by_nearest_face(Object *ob_dst, Object *ob_src, sh 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) {if(mface_src[nearest.index].flag & ME_FACE_SEL) dw_dst->weight = weight;} + else if(mode == 3) {if(mv_dst->flag & SELECT) dw_dst->weight = weight;} else return 0; } /*free memory and return*/ -- cgit v1.2.3 From c4c75c33d0dd3222285b6799da3656316776592a Mon Sep 17 00:00:00 2001 From: Ove Murberg Henriksen Date: Wed, 23 May 2012 10:21:57 +0000 Subject: Changed structure of the entire feature/code. It should now work in 24 different ways depending on options. Its not tested in depth yet... --- source/blender/editors/object/object_vgroup.c | 318 +++++++++++--------------- 1 file changed, 137 insertions(+), 181 deletions(-) diff --git a/source/blender/editors/object/object_vgroup.c b/source/blender/editors/object/object_vgroup.c index 3fac2a7c98f..6dc954b88ad 100644 --- a/source/blender/editors/object/object_vgroup.c +++ b/source/blender/editors/object/object_vgroup.c @@ -376,57 +376,9 @@ 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) -{ - 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 @@ int ED_vgroup_transfer_weight_by_index(Object *ob_dst, Object *ob_src, short mod Mesh *me_dst; int dv_tot_src, dv_tot_dst; int i, index_src, index_dst; - bDeformGroup *dg_src, *dg_dst; - - /*remove this:*/ - option=option; - /*TODO: for option all, loop through all vertex groups*/ + bDeformGroup *dg_dst; - /*get source deform group*/ - dg_src = BLI_findlink(&ob_src->defbase, (ob_src->actdef-1)); + enum dw_options {REPLACE_ALL_WEIGHTS = 1, REPLACE_EMPTY_WEIGHTS = 2, REPLACE_SELECTED_WEIGHTS = 3} dw_options = dw_replace_options; /*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 @@ int ED_vgroup_transfer_weight_by_index(Object *ob_dst, Object *ob_src, short mod 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 ED_vgroup_transfer_weight_by_nearest_vertex(Object *ob_dst, Object *ob_src, 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)); + enum dw_options {REPLACE_ALL_WEIGHTS = 1, REPLACE_EMPTY_WEIGHTS = 2, REPLACE_SELECTED_WEIGHTS = 3} dw_options = dw_replace_options; /*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 @@ int ED_vgroup_transfer_weight_by_nearest_vertex(Object *ob_dst, Object *ob_src, 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 @@ int ED_vgroup_transfer_weight_by_nearest_vertex_in_face(Object *ob_dst, Object * 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]; - - /*remove this:*/ - option=option; + 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]; - /*get source deform group*/ - dg_src = BLI_findlink(&ob_src->defbase, (ob_src->actdef-1)); + enum dw_options {REPLACE_ALL_WEIGHTS = 1, REPLACE_EMPTY_WEIGHTS = 2, REPLACE_SELECTED_WEIGHTS = 3} dw_options = dw_replace_options; /*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 @@ int ED_vgroup_transfer_weight_by_nearest_vertex_in_face(Object *ob_dst, Object * 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); - if(dist_v4 < dist_v1 && dist_v4 < dist_v2 && dist_v4 < dist_v3) index_nearest_vertex = mface_src[nearest.index].v1; - } + + /*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_src = defvert_verify_index(dv_array_src[index_nearest_vertex], 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 = weight; + else if (dw_options == REPLACE_EMPTY_WEIGHTS) {if (!dw_dst->weight || dw_dst->weight == 0) dw_dst->weight = weight;} + else if (dw_options == REPLACE_SELECTED_WEIGHTS) {if (mv_dst->flag & SELECT) dw_dst->weight = weight;} else return 0; } + /*free memory and return*/ free_bvhtree_from_mesh(&tree_mesh_faces_src); return 1; } -int ED_vgroup_transfer_weight_by_nearest_face(Object *ob_dst, Object *ob_src, short mode, short option) +int ED_vgroup_transfer_weight_by_nearest_vertex_in_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}; @@ -662,18 +607,14 @@ int ED_vgroup_transfer_weight_by_nearest_face(Object *ob_dst, Object *ob_src, sh MVert *mv_dst, *mv_src; MFace *mface_src; BVHTreeNearest nearest; - 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; + 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]; - /*get source deform group*/ - dg_src = BLI_findlink(&ob_src->defbase, (ob_src->actdef-1)); + enum dw_options {REPLACE_ALL_WEIGHTS = 1, REPLACE_EMPTY_WEIGHTS = 2, REPLACE_SELECTED_WEIGHTS = 3} dw_options = dw_replace_options; /*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); } @@ -709,34 +650,41 @@ int ED_vgroup_transfer_weight_by_nearest_face(Object *ob_dst, Object *ob_src, sh mult_m4_m4m4(tmp_mat, ob_src->imat, ob_dst->obmat); /* 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); - /*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; + + /*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); + if (dist_v4 < dist_v1 && dist_v4 < dist_v2 && dist_v4 < dist_v3) index_nearest_vertex = mface_src[nearest.index].v4; + } + /*copy weight*/ + dw_src = defvert_verify_index(dv_array_src[index_nearest_vertex], index_src); 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) {if(mv_dst->flag & SELECT) dw_dst->weight = 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_faces_src); return 1; @@ -3111,10 +3059,6 @@ static int vertex_group_copy_to_selected_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. -*/ void OBJECT_OT_vertex_group_copy_to_selected(wmOperatorType *ot) { /* identifiers */ @@ -3132,59 +3076,79 @@ void OBJECT_OT_vertex_group_copy_to_selected(wmOperatorType *ot) static int vertex_group_transfer_weight_exec(bContext *C, wmOperator *op) { - Object *obact = CTX_data_active_object(C); + Object *ob_act = CTX_data_active_object(C); int change = 0; int fail = 0; + short dw_replace_options; + bDeformGroup *dg_src; /*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= 3; - enum Option {single = 1, all = 2} option = 1; - - /*Truth table for testing:*/ - /*1,3,1 working*/ - /*2,3,1 working*/ - /*3,3,1 working*/ - /*4,3,1 working*/ + enum dg_options {REPLACE_SINGLE_VERTEX_GROUP = 1, REPLACE_ALL_VERTEX_GROUPS = 2} dg_options = 2; + enum function_options {BY_INDEX = 1, BY_NEAREST_VERTEX = 2, BY_NEAREST_FACE = 3, BY_NEAREST_VERTEX_IN_FACE = 4} function_options = 4; + dw_replace_options = 1; /*REPLACE_ALL_WEIGHTS = 1, REPLACE_EMPTY_WEIGHTS = 2, REPLACE_SELECTED_WEIGHTS = 3*/ /*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(function){ + CTX_DATA_BEGIN(C, Object*, ob_slc, selected_editable_objects){ + if (ob_act != ob_slc){ + switch(dg_options){ + + case(REPLACE_SINGLE_VERTEX_GROUP): + dg_src = BLI_findlink(&ob_act->defbase, ob_act->actdef -1); + switch(function_options){ + + case(BY_INDEX): + if (ED_vgroup_transfer_weight_by_index(ob_slc, ob_act, dw_replace_options, dg_src)) change++; + else fail++; break; + + case(BY_NEAREST_VERTEX): + if (ED_vgroup_transfer_weight_by_nearest_vertex(ob_slc, ob_act, dw_replace_options, dg_src)) change++; + else fail++; break; + + case(BY_NEAREST_FACE): + if (ED_vgroup_transfer_weight_by_nearest_face(ob_slc, ob_act, dw_replace_options, dg_src)) change++; + else fail++; break; + + case(BY_NEAREST_VERTEX_IN_FACE): + if (ED_vgroup_transfer_weight_by_nearest_vertex_in_face(ob_slc, ob_act, dw_replace_options, dg_src)) change++; + else fail++; break; + } - case(by_index): - if(ED_vgroup_transfer_weight_by_index(obslc, obact, mode, option)) change++; - else fail++; break; + case(REPLACE_ALL_VERTEX_GROUPS): + for (dg_src = ob_act->defbase.first; dg_src; dg_src = dg_src->next){ + switch(function_options){ - case(by_nearest_vertex): - if(ED_vgroup_transfer_weight_by_nearest_vertex(obslc, obact, mode, option)) change++; - else fail++; break; + case(BY_INDEX): + if (ED_vgroup_transfer_weight_by_index(ob_slc, ob_act, dw_replace_options, dg_src)) change++; + else fail++; break; - case(by_nearest_face): - if(ED_vgroup_transfer_weight_by_nearest_face(obslc, obact, mode, option)) change++; - else fail++; break; + case(BY_NEAREST_VERTEX): + if (ED_vgroup_transfer_weight_by_nearest_vertex(ob_slc, ob_act, dw_replace_options, dg_src)) change++; + else fail++; break; - case(by_nearest_vertex_in_face): - if(ED_vgroup_transfer_weight_by_nearest_vertex_in_face(obslc, obact, mode, option)) change++; - else fail++; break; + case(BY_NEAREST_FACE): + if (ED_vgroup_transfer_weight_by_nearest_face(ob_slc, ob_act, dw_replace_options, dg_src)) change++; + else fail++; break; + + case(BY_NEAREST_VERTEX_IN_FACE): + if (ED_vgroup_transfer_weight_by_nearest_vertex_in_face(ob_slc, ob_act, dw_replace_options, dg_src)) 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); + DAG_id_tag_update(&ob_slc->id, OB_RECALC_DATA); + WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, ob_slc); + WM_event_add_notifier(C, NC_GEOM|ND_DATA, ob_slc->data); } CTX_DATA_END; /*Report error when task can not be completed with available functions.*/ - if((change == 0 && fail == 0) || fail) { + if ((change == 0 && fail == 0) || fail) { BKE_reportf(op->reports, RPT_ERROR, "Copy to VGroups to Selected warning done %d, failed %d, unknown option/method or All functions failed!", change, fail); } - return OPERATOR_FINISHED; } @@ -3202,14 +3166,6 @@ void OBJECT_OT_vertex_group_transfer_weight(wmOperatorType *ot) /* flags */ ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; - - /* - 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; - */ } static EnumPropertyItem vgroup_items[] = { -- cgit v1.2.3 From c2c2611faa26cb7ebd1126ebe30520164a183184 Mon Sep 17 00:00:00 2001 From: Ove Murberg Henriksen Date: Thu, 24 May 2012 20:03:09 +0000 Subject: Restructuring code. All functions merged into ED_vgroup_transfer_weight() to avoid duplicate code. --- source/blender/editors/object/object_vgroup.c | 544 ++++++++++++-------------- 1 file changed, 252 insertions(+), 292 deletions(-) diff --git a/source/blender/editors/object/object_vgroup.c b/source/blender/editors/object/object_vgroup.c index 6dc954b88ad..c0fe8c1f342 100644 --- a/source/blender/editors/object/object_vgroup.c +++ b/source/blender/editors/object/object_vgroup.c @@ -376,79 +376,34 @@ int ED_vgroup_copy_array(Object *ob, Object *ob_from) return 1; } -/********************** Start transfer weight functions *********************/ +/***********************Start transfer weight function************************/ -int ED_vgroup_transfer_weight_by_index(Object *ob_dst, Object *ob_src, short dw_replace_options, bDeformGroup *dg_src) +int ED_vgroup_transfer_weight( + Object *ob_dst, Object *ob_src, bDeformGroup *dg_src, short replace_options, short method_options) { - MDeformVert **dv_array_src; - MDeformVert **dv_array_dst; - MDeformWeight *dw_dst, *dw_src; - MVert *mv_dst; - Mesh *me_dst; - int dv_tot_src, dv_tot_dst; - int i, index_src, index_dst; bDeformGroup *dg_dst; - - enum dw_options {REPLACE_ALL_WEIGHTS = 1, REPLACE_EMPTY_WEIGHTS = 2, REPLACE_SELECTED_WEIGHTS = 3} dw_options = dw_replace_options; - - /*create new and overwrite vertex group on destination without data*/ - 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); - } - - /*get meshes*/ - me_dst = ob_dst->data; - - /*get vertices*/ - mv_dst = me_dst->mvert; - - /*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++, mv_dst++){ - dw_src = defvert_verify_index(*dv_array_src, index_src); - dw_dst = defvert_verify_index(*dv_array_dst, index_dst); - 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 dw_replace_options, bDeformGroup *dg_src) -{ - bDeformGroup *dg_dst; - MDeformVert **dv_array_src, **dv_array_dst; - MDeformWeight *dw_dst, *dw_src; - MVert *mv_dst; Mesh *me_dst; - BVHTreeFromMesh tree_mesh_src; - BVHTreeNearest nearest; DerivedMesh *dmesh_src; - int dv_tot_src, dv_tot_dst, i, index_dst, index_src; - float tmp_co[3], tmp_mat[4][4]; + BVHTreeFromMesh tree_mesh_vertices_src, tree_mesh_faces_src = {NULL}; + MDeformVert **dv_array_src, **dv_array_dst; + 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, index_nearest_vertex; + float weight, tmp_weight[4], tmp_co[3], normal[3], tmp_mat[4][4], dist_v1, dist_v2, dist_v3, dist_v4; + + enum replace_option {REPLACE_ALL_WEIGHTS = 1, + REPLACE_EMPTY_WEIGHTS = 2, + REPLACE_SELECTED_WEIGHTS = 3} replace_option = replace_options; - enum dw_options {REPLACE_ALL_WEIGHTS = 1, REPLACE_EMPTY_WEIGHTS = 2, REPLACE_SELECTED_WEIGHTS = 3} dw_options = dw_replace_options; + enum method_option {BY_INDEX = 1, + BY_NEAREST_VERTEX = 2, + BY_NEAREST_FACE = 3, + BY_NEAREST_VERTEX_IN_FACE = 4} method_option = method_options; /*create new and overwrite vertex group on destination without data*/ - if (!defgroup_find_name(ob_dst, dg_src->name) || dw_replace_options == 1){ + if (!defgroup_find_name(ob_dst, dg_src->name) || replace_option == 1){ ED_vgroup_delete(ob_dst, defgroup_find_name(ob_dst, dg_src->name)); ED_vgroup_add_name(ob_dst, dg_src->name); } @@ -460,9 +415,6 @@ int ED_vgroup_transfer_weight_by_nearest_vertex(Object *ob_dst, Object *ob_src, me_dst = ob_dst->data; dmesh_src = ob_src->derivedDeform; - /*make node tree*/ - bvhtree_from_mesh_verts(&tree_mesh_src, dmesh_src, 0.0, 2, 6); - /*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); @@ -473,224 +425,224 @@ int ED_vgroup_transfer_weight_by_nearest_vertex(Object *ob_dst, Object *ob_src, /*get vertices*/ mv_dst = me_dst->mvert; + mv_src = dmesh_src->getVertArray(dmesh_src); /*prepare transformation matrix*/ 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++){ - - /*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 (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_face(Object *ob_dst, Object *ob_src, short dw_replace_options, bDeformGroup *dg_src) -{ - bDeformGroup *dg_dst; - Mesh *me_dst; - DerivedMesh *dmesh_src; - BVHTreeFromMesh tree_mesh_faces_src = {NULL}; - MDeformVert **dv_array_src, **dv_array_dst; - MVert *mv_dst, *mv_src; - MFace *mface_src; - BVHTreeNearest nearest; - 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]; - - enum dw_options {REPLACE_ALL_WEIGHTS = 1, REPLACE_EMPTY_WEIGHTS = 2, REPLACE_SELECTED_WEIGHTS = 3} dw_options = dw_replace_options; - - /*create new and overwrite vertex group on destination without data*/ - 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); - } - - /*get destination deformgroup*/ - dg_dst = defgroup_find_name(ob_dst, dg_src->name); - - /*get meshes*/ - me_dst = ob_dst->data; - dmesh_src = ob_src->derivedDeform; + switch (method_option) { - /*make node tree*/ - DM_ensure_tessface(dmesh_src); - bvhtree_from_mesh_faces(&tree_mesh_faces_src, dmesh_src, 0.0, 2, 6); + case (BY_INDEX): + /*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; + } - /*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); + /* loop through the vertices*/ + for (i = 0; i < dv_tot_dst; i++, dv_array_src++, dv_array_dst++, mv_dst++){ - /*get indexes of vertex groups*/ - index_src = BLI_findindex(&ob_src->defbase, dg_src); - index_dst = BLI_findindex(&ob_dst->defbase, dg_dst); + /*copy weight*/ + dw_src = defvert_verify_index(*dv_array_src, index_src); + dw_dst = defvert_verify_index(*dv_array_dst, index_dst); - /*get vertices*/ - mv_dst = me_dst->mvert; - mv_src = dmesh_src->getVertArray(dmesh_src); + switch (replace_option) { - /*get faces*/ - mface_src = dmesh_src->getTessFaceArray(dmesh_src); + case (REPLACE_ALL_WEIGHTS): + dw_dst->weight = dw_src->weight; + break; - /*prepare transformation matrix*/ - invert_m4_m4(ob_src->imat, ob_src->obmat); - mult_m4_m4m4(tmp_mat, ob_src->imat, ob_dst->obmat); + case(REPLACE_EMPTY_WEIGHTS): + if (!dw_dst->weight || dw_dst->weight == 0) dw_dst->weight = dw_src->weight; + break; - /* loop through the vertices and copy weight from nearest weight*/ - for (i = 0; i < me_dst->totvert; i++, mv_dst++, dv_array_dst++){ + case(REPLACE_SELECTED_WEIGHTS): + if (mv_dst->flag & SELECT) dw_dst->weight = dw_src->weight; + break; + } + } + break; - /*reset nearest*/ - nearest.index = -1; - nearest.dist = FLT_MAX; + case (BY_NEAREST_VERTEX): + /*make node tree*/ + bvhtree_from_mesh_verts(&tree_mesh_vertices_src, dmesh_src, 0.0, 2, 6); - /*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); + /* loop through the vertices*/ + for (i = 0; i < me_dst->totvert; i++, mv_dst++, dv_array_dst++){ - /*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); + /*reset nearest*/ + nearest.index = -1; + nearest.dist = FLT_MAX; - /*project onto face*/ - project_v3_plane(tmp_co, normal, mv_src[mface_src[nearest.index].v1].co); + /*transform into target space*/ + mul_v3_m4v3(tmp_co, tmp_mat, mv_dst->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); + /*node tree accelerated search for closest vetex*/ + BLI_bvhtree_find_nearest(tree_mesh_vertices_src.tree, tmp_co, &nearest, tree_mesh_vertices_src.nearest_callback, &tree_mesh_vertices_src); - /*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_src = defvert_verify_index(dv_array_src[nearest.index], index_src); + dw_dst = defvert_verify_index(*dv_array_dst, index_dst); - /*copy weight*/ - dw_dst = defvert_verify_index(*dv_array_dst, index_dst); - if (dw_options == REPLACE_ALL_WEIGHTS) dw_dst->weight = weight; - else if (dw_options == REPLACE_EMPTY_WEIGHTS) {if (!dw_dst->weight || dw_dst->weight == 0) dw_dst->weight = weight;} - else if (dw_options == REPLACE_SELECTED_WEIGHTS) {if (mv_dst->flag & SELECT) dw_dst->weight = weight;} - else return 0; - } + switch (replace_option) { - /*free memory and return*/ - free_bvhtree_from_mesh(&tree_mesh_faces_src); - return 1; -} + case (REPLACE_ALL_WEIGHTS): + dw_dst->weight = dw_src->weight; + break; -int ED_vgroup_transfer_weight_by_nearest_vertex_in_face(Object *ob_dst, Object *ob_src, short dw_replace_options, bDeformGroup *dg_src) -{ - bDeformGroup *dg_dst; - Mesh *me_dst; - DerivedMesh *dmesh_src; - BVHTreeFromMesh tree_mesh_faces_src = {NULL}; - MDeformVert **dv_array_src, **dv_array_dst; - 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]; + case(REPLACE_EMPTY_WEIGHTS): + if (!dw_dst->weight || dw_dst->weight == 0) dw_dst->weight = dw_src->weight; + break; - enum dw_options {REPLACE_ALL_WEIGHTS = 1, REPLACE_EMPTY_WEIGHTS = 2, REPLACE_SELECTED_WEIGHTS = 3} dw_options = dw_replace_options; + case(REPLACE_SELECTED_WEIGHTS): + if (mv_dst->flag & SELECT) dw_dst->weight = dw_src->weight; + break; + } + } + break; + + case (BY_NEAREST_FACE): + /*get faces*/ + DM_ensure_tessface(dmesh_src); + mface_src = dmesh_src->getTessFaceArray(dmesh_src); + + /*make node tree*/ + bvhtree_from_mesh_faces(&tree_mesh_faces_src, dmesh_src, 0.0, 2, 6); + + /* loop through the vertices*/ + 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); + index_nearest = nearest.index; + + /*project onto face*/ + 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); + project_v3_plane(tmp_co, normal, mv_src[mface_src[index_nearest].v1].co); + + /*interpolate weights*/ + interp_weights_face_v3(tmp_weight, + mv_src[mface_src[index_nearest].v1].co, + mv_src[mface_src[index_nearest].v2].co, + mv_src[mface_src[index_nearest].v3].co, + mv_src[mface_src[index_nearest].v4].co, + tmp_co); + + /*get weights*/ + weight = + tmp_weight[0] * defvert_verify_index(dv_array_src[mface_src[index_nearest].v1], index_src)->weight; + weight += + tmp_weight[1] * defvert_verify_index(dv_array_src[mface_src[index_nearest].v2], index_src)->weight; + weight += + tmp_weight[2] * defvert_verify_index(dv_array_src[mface_src[index_nearest].v3], index_src)->weight; + weight += + tmp_weight[3] * defvert_verify_index(dv_array_src[mface_src[index_nearest].v4], index_src)->weight; + + /*copy weight*/ + dw_dst = defvert_verify_index(*dv_array_dst, index_dst); + + switch (replace_option) { + + case (REPLACE_ALL_WEIGHTS): + dw_dst->weight = weight; + break; - /*create new and overwrite vertex group on destination without data*/ - 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); - } + case(REPLACE_EMPTY_WEIGHTS): + if (!dw_dst->weight || dw_dst->weight == 0) dw_dst->weight = weight; + break; - /*get destination deformgroup*/ - dg_dst = defgroup_find_name(ob_dst, dg_src->name); + case(REPLACE_SELECTED_WEIGHTS): + if (mv_dst->flag & SELECT) dw_dst->weight = weight; + break; + } + } + break; - /*get meshes*/ - me_dst = ob_dst->data; - dmesh_src = ob_src->derivedDeform; + case (BY_NEAREST_VERTEX_IN_FACE): + /*get faces*/ + DM_ensure_tessface(dmesh_src); + mface_src = dmesh_src->getTessFaceArray(dmesh_src); - /*make node tree*/ - DM_ensure_tessface(dmesh_src); - bvhtree_from_mesh_faces(&tree_mesh_faces_src, dmesh_src, 0.0, 2, 6); + /*make node tree*/ + bvhtree_from_mesh_faces(&tree_mesh_faces_src, dmesh_src, 0.0, 2, 6); - /*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); + /*loop through the vertices*/ + for (i = 0; i < me_dst->totvert; i++, mv_dst++, dv_array_dst++){ - /*get indexes of vertex groups*/ - index_src = BLI_findindex(&ob_src->defbase, dg_src); - index_dst = BLI_findindex(&ob_dst->defbase, dg_dst); + /*reset nearest*/ + nearest.index = -1; + nearest.dist = FLT_MAX; - /*get vertices*/ - mv_dst = me_dst->mvert; - mv_src = dmesh_src->getVertArray(dmesh_src); + /*transform into target space*/ + mul_v3_m4v3(tmp_co, tmp_mat, mv_dst->co); - /*get faces*/ - mface_src = dmesh_src->getTessFaceArray(dmesh_src); + /*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); + index_nearest = nearest.index; - /*prepare transformation matrix*/ - invert_m4_m4(ob_src->imat, ob_src->obmat); - mult_m4_m4m4(tmp_mat, ob_src->imat, ob_dst->obmat); + /*get distances*/ + dist_v1 = len_squared_v3v3(tmp_co, mv_src[mface_src[index_nearest].v1].co); + dist_v2 = len_squared_v3v3(tmp_co, mv_src[mface_src[index_nearest].v2].co); + dist_v3 = len_squared_v3v3(tmp_co, mv_src[mface_src[index_nearest].v3].co); - /* loop through the vertices and copy weight from nearest weight*/ - for (i = 0; i < me_dst->totvert; i++, mv_dst++, dv_array_dst++){ + /*get closest vertex*/ + if (dist_v1 < dist_v2 && dist_v1 < dist_v3) index_nearest_vertex = mface_src[index_nearest].v1; + else if (dist_v2 < dist_v3) index_nearest_vertex = mface_src[index_nearest].v2; + else index_nearest_vertex = mface_src[index_nearest].v3; + if (mface_src[index_nearest].v4){ + dist_v4 = len_squared_v3v3(tmp_co, mv_src[mface_src[index_nearest].v4].co); + if (dist_v4 < dist_v1 && dist_v4 < dist_v2 && dist_v4 < dist_v3) { + index_nearest_vertex = mface_src[index_nearest].v4; + } + } - /*reset nearest*/ - nearest.index = -1; - nearest.dist = FLT_MAX; + /*copy weight*/ + dw_src = defvert_verify_index(dv_array_src[index_nearest_vertex], index_src); + dw_dst = defvert_verify_index(*dv_array_dst, index_dst); - /*transform into target space*/ - mul_v3_m4v3(tmp_co, tmp_mat, mv_dst->co); + switch (replace_option) { - /*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); + case (REPLACE_ALL_WEIGHTS): + dw_dst->weight = dw_src->weight; + break; - /*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); + case(REPLACE_EMPTY_WEIGHTS): + if (!dw_dst->weight || dw_dst->weight == 0) dw_dst->weight = dw_src->weight; + break; - /*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); - if (dist_v4 < dist_v1 && dist_v4 < dist_v2 && dist_v4 < dist_v3) index_nearest_vertex = mface_src[nearest.index].v4; + case(REPLACE_SELECTED_WEIGHTS): + if (mv_dst->flag & SELECT) dw_dst->weight = dw_src->weight; + break; + } } - - /*copy weight*/ - dw_src = defvert_verify_index(dv_array_src[index_nearest_vertex], index_src); - dw_dst = defvert_verify_index(*dv_array_dst, index_dst); - 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; + break; } /*free memory and return*/ + free_bvhtree_from_mesh(&tree_mesh_vertices_src); free_bvhtree_from_mesh(&tree_mesh_faces_src); return 1; } -/********************** End transfer weight functions *********************/ +/***********************End transfer weight function**************************/ /* for Mesh in Object mode */ /* allows editmode for Lattice */ @@ -3079,68 +3031,76 @@ static int vertex_group_transfer_weight_exec(bContext *C, wmOperator *op) Object *ob_act = CTX_data_active_object(C); int change = 0; int fail = 0; - short dw_replace_options; bDeformGroup *dg_src; - /*TODO: get these parameters*/ - enum dg_options {REPLACE_SINGLE_VERTEX_GROUP = 1, REPLACE_ALL_VERTEX_GROUPS = 2} dg_options = 2; - enum function_options {BY_INDEX = 1, BY_NEAREST_VERTEX = 2, BY_NEAREST_FACE = 3, BY_NEAREST_VERTEX_IN_FACE = 4} function_options = 4; - dw_replace_options = 1; /*REPLACE_ALL_WEIGHTS = 1, REPLACE_EMPTY_WEIGHTS = 2, REPLACE_SELECTED_WEIGHTS = 3*/ + enum vertex_group_option {REPLACE_SINGLE_VERTEX_GROUP = 1, + REPLACE_ALL_VERTEX_GROUPS = 2} vertex_group_option; + + short replace_option; /*REPLACE_ALL_WEIGHTS = 1, + * REPLACE_EMPTY_WEIGHTS = 2, + * REPLACE_SELECTED_WEIGHTS = 3*/ + + short method_option; /*BY_INDEX = 1, + * BY_NEAREST_VERTEX = 2, + * BY_NEAREST_FACE = 3, + * BY_NEAREST_VERTEX_IN_FACE = 4*/ + + vertex_group_option = 1; + replace_option = 1; + method_option = 3; + + /*Truth table for testing*/ + /*1,1,1 working*/ + /*1,1,2 working*/ + /*1,1,3 working*/ + /*1,1,4 working*/ + /*1,2,1 working*/ + /*1,2,2 working*/ + /*1,2,3 working*/ + /*1,2,4 working*/ + /*1,3,1 working*/ + /*1,3,2 working*/ + /*1,3,3 working*/ + /*1,3,4 working*/ + /*2,1,1 */ + /*2,1,2*/ + /*2,1,3*/ + /*2,1,4*/ + /*2,2,1*/ + /*2,2,2*/ + /*2,2,3*/ + /*2,2,4*/ + /*2,3,1*/ + /*2,3,2*/ + /*2,3,3*/ + /*2,3,4*/ /*Macro to loop through selected objects and perform operation depending on function, option and method*/ CTX_DATA_BEGIN(C, Object*, ob_slc, selected_editable_objects){ - if (ob_act != ob_slc){ - switch(dg_options){ - - case(REPLACE_SINGLE_VERTEX_GROUP): - dg_src = BLI_findlink(&ob_act->defbase, ob_act->actdef -1); - switch(function_options){ - - case(BY_INDEX): - if (ED_vgroup_transfer_weight_by_index(ob_slc, ob_act, dw_replace_options, dg_src)) change++; - else fail++; break; - - case(BY_NEAREST_VERTEX): - if (ED_vgroup_transfer_weight_by_nearest_vertex(ob_slc, ob_act, dw_replace_options, dg_src)) change++; - else fail++; break; - - case(BY_NEAREST_FACE): - if (ED_vgroup_transfer_weight_by_nearest_face(ob_slc, ob_act, dw_replace_options, dg_src)) change++; - else fail++; break; - - case(BY_NEAREST_VERTEX_IN_FACE): - if (ED_vgroup_transfer_weight_by_nearest_vertex_in_face(ob_slc, ob_act, dw_replace_options, dg_src)) change++; - else fail++; break; - } - - case(REPLACE_ALL_VERTEX_GROUPS): - for (dg_src = ob_act->defbase.first; dg_src; dg_src = dg_src->next){ - switch(function_options){ - - case(BY_INDEX): - if (ED_vgroup_transfer_weight_by_index(ob_slc, ob_act, dw_replace_options, dg_src)) change++; - else fail++; break; - case(BY_NEAREST_VERTEX): - if (ED_vgroup_transfer_weight_by_nearest_vertex(ob_slc, ob_act, dw_replace_options, dg_src)) change++; - else fail++; break; + if (ob_act != ob_slc){ + switch(vertex_group_option){ - case(BY_NEAREST_FACE): - if (ED_vgroup_transfer_weight_by_nearest_face(ob_slc, ob_act, dw_replace_options, dg_src)) change++; - else fail++; break; + case(REPLACE_SINGLE_VERTEX_GROUP): + if (ED_vgroup_transfer_weight(ob_slc, ob_act, BLI_findlink(&ob_act->defbase, ob_act->actdef - 1), replace_option, method_option)) + change++; + else fail++; break; - case(BY_NEAREST_VERTEX_IN_FACE): - if (ED_vgroup_transfer_weight_by_nearest_vertex_in_face(ob_slc, ob_act, dw_replace_options, dg_src)) change++; - else fail++; break; - } - } + case(REPLACE_ALL_VERTEX_GROUPS): + for (dg_src = ob_act->defbase.first; dg_src; dg_src = dg_src->next){ + if (ED_vgroup_transfer_weight(ob_slc, ob_act, dg_src, replace_option, method_option)) change++; + else fail++; break; } + } - /*Event notifiers for correct display of data*/ - DAG_id_tag_update(&ob_slc->id, OB_RECALC_DATA); - WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, ob_slc); - WM_event_add_notifier(C, NC_GEOM|ND_DATA, ob_slc->data); + } } + + /*Event notifiers for correct display of data*/ + DAG_id_tag_update(&ob_slc->id, OB_RECALC_DATA); + WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, ob_slc); + WM_event_add_notifier(C, NC_GEOM|ND_DATA, ob_slc->data); + CTX_DATA_END; /*Report error when task can not be completed with available functions.*/ -- cgit v1.2.3 From b4a229c43afdefa7cca3462a9d14f1a3bcef9bd2 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sat, 26 May 2012 14:31:34 +0000 Subject: style edits --- source/blender/editors/object/object_vgroup.c | 52 ++++++++++++++------------- 1 file changed, 27 insertions(+), 25 deletions(-) diff --git a/source/blender/editors/object/object_vgroup.c b/source/blender/editors/object/object_vgroup.c index 81119c8292e..cc60cf9881d 100644 --- a/source/blender/editors/object/object_vgroup.c +++ b/source/blender/editors/object/object_vgroup.c @@ -29,7 +29,6 @@ * \ingroup edobj */ - #include #include #include @@ -458,9 +457,10 @@ int ED_vgroup_transfer_weight(Object *ob_dst, Object *ob_src, bDeformGroup *dg_s switch (method_option) { case BY_INDEX: - /*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) { + /* 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; } @@ -491,7 +491,7 @@ int ED_vgroup_transfer_weight(Object *ob_dst, Object *ob_src, bDeformGroup *dg_s /*node tree accelerated search for closest vetex*/ BLI_bvhtree_find_nearest(tree_mesh_vertices_src.tree, tmp_co, - &nearest, tree_mesh_vertices_src.nearest_callback, &tree_mesh_vertices_src); + &nearest, tree_mesh_vertices_src.nearest_callback, &tree_mesh_vertices_src); /*copy weight*/ dw_src = defvert_verify_index(dv_array_src[nearest.index], index_src); @@ -523,20 +523,21 @@ int ED_vgroup_transfer_weight(Object *ob_dst, Object *ob_src, bDeformGroup *dg_s /*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); + &nearest, tree_mesh_faces_src.nearest_callback, &tree_mesh_faces_src); index_nearest = nearest.index; /*project onto face*/ 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); + mv_src[mface_src[nearest.index].v2].co, + mv_src[mface_src[nearest.index].v3].co); + project_v3_plane(tmp_co, normal, mv_src[mface_src[index_nearest].v1].co); /*interpolate weights*/ interp_weights_face_v3(tmp_weight, mv_src[mface_src[index_nearest].v1].co, - mv_src[mface_src[index_nearest].v2].co, - mv_src[mface_src[index_nearest].v3].co, - mv_src[mface_src[index_nearest].v4].co, tmp_co); + mv_src[mface_src[index_nearest].v2].co, + mv_src[mface_src[index_nearest].v3].co, + mv_src[mface_src[index_nearest].v4].co, tmp_co); /*get weights*/ weight = tmp_weight[0] * defvert_verify_index(dv_array_src[mface_src[index_nearest].v1], index_src)->weight; @@ -573,7 +574,7 @@ int ED_vgroup_transfer_weight(Object *ob_dst, Object *ob_src, bDeformGroup *dg_s /*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); + &nearest, tree_mesh_faces_src.nearest_callback, &tree_mesh_faces_src); index_nearest = nearest.index; /*get distances*/ @@ -2996,30 +2997,31 @@ static int vertex_group_transfer_weight_exec(bContext *C, wmOperator *op) int fail = 0; bDeformGroup *dg_src; - /*TODO: get these parameters from gui. - *For now 1,3,1 is default because GUI doesnt contain more than one button yet: - *Replace all weights in single vertexgroup based on interpolation of nearest face*/ + /* TODO: get these parameters from gui. + * For now 1,3,1 is default because GUI doesnt contain more than one button yet: + * Replace all weights in single vertexgroup based on interpolation of nearest face*/ VertexGroupOption vertex_group_option = 1; MethodOption method_option = 3; ReplaceOption replace_option = 1; /*Macro to loop through selected objects and perform operation depending on function, option and method*/ - CTX_DATA_BEGIN(C, Object*, ob_slc, selected_editable_objects){ + CTX_DATA_BEGIN(C, Object*, ob_slc, selected_editable_objects) { if (ob_act != ob_slc){ switch(vertex_group_option){ - case REPLACE_SINGLE_VERTEX_GROUP: - if (ED_vgroup_transfer_weight(ob_slc, ob_act, BLI_findlink(&ob_act->defbase, ob_act->actdef - 1), method_option, replace_option)) - change++; - else fail++; break; + case REPLACE_SINGLE_VERTEX_GROUP: + if (ED_vgroup_transfer_weight(ob_slc, ob_act, BLI_findlink(&ob_act->defbase, ob_act->actdef - 1), method_option, replace_option)) + change++; + else fail++; + break; - case REPLACE_ALL_VERTEX_GROUPS: - for (dg_src = ob_act->defbase.first; dg_src; dg_src = dg_src->next){ - if (ED_vgroup_transfer_weight(ob_slc, ob_act, dg_src, method_option, replace_option)) change++; - else fail++; break; - } + case REPLACE_ALL_VERTEX_GROUPS: + for (dg_src = ob_act->defbase.first; dg_src; dg_src = dg_src->next){ + if (ED_vgroup_transfer_weight(ob_slc, ob_act, dg_src, method_option, replace_option)) change++; + else fail++;break; + } } } } -- cgit v1.2.3 From 25c7e8e1283c2ebc741bdd42dd0abc89eecd0486 Mon Sep 17 00:00:00 2001 From: Ove Murberg Henriksen Date: Sat, 26 May 2012 15:27:21 +0000 Subject: bug fixes, review issue 6256058. --- source/blender/editors/object/object_vgroup.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/source/blender/editors/object/object_vgroup.c b/source/blender/editors/object/object_vgroup.c index cc60cf9881d..83ef066f71f 100644 --- a/source/blender/editors/object/object_vgroup.c +++ b/source/blender/editors/object/object_vgroup.c @@ -402,12 +402,15 @@ void vgroup_transfer_weight(MVert *mv_dst, float *weight_dst, float weight_src, case REPLACE_ALL_WEIGHTS: *weight_dst = weight_src; + break; case REPLACE_EMPTY_WEIGHTS: if (!weight_dst || weight_dst == 0) *weight_dst = weight_src; + break; case REPLACE_SELECTED_WEIGHTS: if (mv_dst->flag & SELECT) *weight_dst = weight_src; + break; } } @@ -426,7 +429,7 @@ int ED_vgroup_transfer_weight(Object *ob_dst, Object *ob_src, bDeformGroup *dg_s float weight, tmp_weight[4], tmp_co[3], normal[3], tmp_mat[4][4], dist_v1, dist_v2, dist_v3, dist_v4; /*create new and overwrite vertex group on destination without data*/ - if (!defgroup_find_name(ob_dst, dg_src->name) || replace_option == (ReplaceOption)REPLACE_ALL_WEIGHTS){ + if (!defgroup_find_name(ob_dst, dg_src->name) || replace_option == REPLACE_ALL_WEIGHTS){ ED_vgroup_delete(ob_dst, defgroup_find_name(ob_dst, dg_src->name)); ED_vgroup_add_name(ob_dst, dg_src->name); } @@ -543,7 +546,9 @@ int ED_vgroup_transfer_weight(Object *ob_dst, Object *ob_src, bDeformGroup *dg_s weight = tmp_weight[0] * defvert_verify_index(dv_array_src[mface_src[index_nearest].v1], index_src)->weight; weight += tmp_weight[1] * defvert_verify_index(dv_array_src[mface_src[index_nearest].v2], index_src)->weight; weight += tmp_weight[2] * defvert_verify_index(dv_array_src[mface_src[index_nearest].v3], index_src)->weight; - weight += tmp_weight[3] * defvert_verify_index(dv_array_src[mface_src[index_nearest].v4], index_src)->weight; + if (mface_src[index_nearest].v4 || mface_src[index_nearest].v4 == 0){ + weight += tmp_weight[3] * defvert_verify_index(dv_array_src[mface_src[index_nearest].v4], index_src)->weight; + } /*copy weight*/ dw_dst = defvert_verify_index(*dv_array_dst, index_dst); @@ -3020,8 +3025,9 @@ static int vertex_group_transfer_weight_exec(bContext *C, wmOperator *op) case REPLACE_ALL_VERTEX_GROUPS: for (dg_src = ob_act->defbase.first; dg_src; dg_src = dg_src->next){ if (ED_vgroup_transfer_weight(ob_slc, ob_act, dg_src, method_option, replace_option)) change++; - else fail++;break; + else fail++; } + break; } } } -- cgit v1.2.3 From 6c41b326fee8dd919e6b5e1e93501364613ecd17 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sat, 26 May 2012 15:48:55 +0000 Subject: style cleanup --- source/blender/editors/object/object_vgroup.c | 37 ++++++++++++++------------- 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/source/blender/editors/object/object_vgroup.c b/source/blender/editors/object/object_vgroup.c index 83ef066f71f..81adb1c41ff 100644 --- a/source/blender/editors/object/object_vgroup.c +++ b/source/blender/editors/object/object_vgroup.c @@ -429,7 +429,7 @@ int ED_vgroup_transfer_weight(Object *ob_dst, Object *ob_src, bDeformGroup *dg_s float weight, tmp_weight[4], tmp_co[3], normal[3], tmp_mat[4][4], dist_v1, dist_v2, dist_v3, dist_v4; /*create new and overwrite vertex group on destination without data*/ - if (!defgroup_find_name(ob_dst, dg_src->name) || replace_option == REPLACE_ALL_WEIGHTS){ + if (!defgroup_find_name(ob_dst, dg_src->name) || replace_option == REPLACE_ALL_WEIGHTS) { ED_vgroup_delete(ob_dst, defgroup_find_name(ob_dst, dg_src->name)); ED_vgroup_add_name(ob_dst, dg_src->name); } @@ -469,7 +469,7 @@ int ED_vgroup_transfer_weight(Object *ob_dst, Object *ob_src, bDeformGroup *dg_s } /* loop through the vertices*/ - 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++) { /*copy weight*/ dw_src = defvert_verify_index(*dv_array_src, index_src); @@ -483,7 +483,7 @@ int ED_vgroup_transfer_weight(Object *ob_dst, Object *ob_src, bDeformGroup *dg_s bvhtree_from_mesh_verts(&tree_mesh_vertices_src, dmesh_src, 0.0, 2, 6); /* loop through the vertices*/ - 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; It is asumed using index of previous search as starting point result in speedup. It will be tested later*/ @@ -515,7 +515,7 @@ int ED_vgroup_transfer_weight(Object *ob_dst, Object *ob_src, bDeformGroup *dg_s bvhtree_from_mesh_faces(&tree_mesh_faces_src, dmesh_src, 0.0, 2, 6); /* loop through the vertices*/ - 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; It is asumed using index of previous search as starting point result in speedup. It will be tested later*/ @@ -531,8 +531,8 @@ int ED_vgroup_transfer_weight(Object *ob_dst, Object *ob_src, bDeformGroup *dg_s /*project onto face*/ 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); + mv_src[mface_src[nearest.index].v2].co, + mv_src[mface_src[nearest.index].v3].co); project_v3_plane(tmp_co, normal, mv_src[mface_src[index_nearest].v1].co); @@ -546,7 +546,7 @@ int ED_vgroup_transfer_weight(Object *ob_dst, Object *ob_src, bDeformGroup *dg_s weight = tmp_weight[0] * defvert_verify_index(dv_array_src[mface_src[index_nearest].v1], index_src)->weight; weight += tmp_weight[1] * defvert_verify_index(dv_array_src[mface_src[index_nearest].v2], index_src)->weight; weight += tmp_weight[2] * defvert_verify_index(dv_array_src[mface_src[index_nearest].v3], index_src)->weight; - if (mface_src[index_nearest].v4 || mface_src[index_nearest].v4 == 0){ + if (mface_src[index_nearest].v4 || mface_src[index_nearest].v4 == 0) { weight += tmp_weight[3] * defvert_verify_index(dv_array_src[mface_src[index_nearest].v4], index_src)->weight; } @@ -568,7 +568,7 @@ int ED_vgroup_transfer_weight(Object *ob_dst, Object *ob_src, bDeformGroup *dg_s bvhtree_from_mesh_faces(&tree_mesh_faces_src, dmesh_src, 0.0, 2, 6); /*loop through the vertices*/ - 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; It is asumed using index of previous search as starting point result in speedup. It will be tested later*/ @@ -591,9 +591,9 @@ int ED_vgroup_transfer_weight(Object *ob_dst, Object *ob_src, bDeformGroup *dg_s if (dist_v1 < dist_v2 && dist_v1 < dist_v3) index_nearest_vertex = mface_src[index_nearest].v1; else if (dist_v2 < dist_v3) index_nearest_vertex = mface_src[index_nearest].v2; else index_nearest_vertex = mface_src[index_nearest].v3; - if (mface_src[index_nearest].v4 || mface_src[index_nearest].v4 == 0){ + if (mface_src[index_nearest].v4 || mface_src[index_nearest].v4 == 0) { dist_v4 = len_squared_v3v3(tmp_co, mv_src[mface_src[index_nearest].v4].co); - if (dist_v4 < dist_v1 && dist_v4 < dist_v2 && dist_v4 < dist_v3){ + if (dist_v4 < dist_v1 && dist_v4 < dist_v2 && dist_v4 < dist_v3) { index_nearest_vertex = mface_src[index_nearest].v4; } } @@ -2962,7 +2962,7 @@ static int vertex_group_copy_to_selected_exec(bContext *C, wmOperator *op) int change = 0; int fail = 0; - CTX_DATA_BEGIN (C, Object *, ob, selected_editable_objects) + CTX_DATA_BEGIN(C, Object *, ob, selected_editable_objects) { if (obact != ob) { if (ED_vgroup_copy_array(ob, obact)) change++; @@ -3011,10 +3011,11 @@ static int vertex_group_transfer_weight_exec(bContext *C, wmOperator *op) ReplaceOption replace_option = 1; /*Macro to loop through selected objects and perform operation depending on function, option and method*/ - CTX_DATA_BEGIN(C, Object*, ob_slc, selected_editable_objects) { + CTX_DATA_BEGIN(C, Object *, ob_slc, selected_editable_objects) + { - if (ob_act != ob_slc){ - switch(vertex_group_option){ + if (ob_act != ob_slc) { + switch (vertex_group_option) { case REPLACE_SINGLE_VERTEX_GROUP: if (ED_vgroup_transfer_weight(ob_slc, ob_act, BLI_findlink(&ob_act->defbase, ob_act->actdef - 1), method_option, replace_option)) @@ -3023,7 +3024,7 @@ static int vertex_group_transfer_weight_exec(bContext *C, wmOperator *op) break; case REPLACE_ALL_VERTEX_GROUPS: - for (dg_src = ob_act->defbase.first; dg_src; dg_src = dg_src->next){ + for (dg_src = ob_act->defbase.first; dg_src; dg_src = dg_src->next) { if (ED_vgroup_transfer_weight(ob_slc, ob_act, dg_src, method_option, replace_option)) change++; else fail++; } @@ -3034,8 +3035,8 @@ static int vertex_group_transfer_weight_exec(bContext *C, wmOperator *op) /*Event notifiers for correct display of data*/ DAG_id_tag_update(&ob_slc->id, OB_RECALC_DATA); - WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, ob_slc); - WM_event_add_notifier(C, NC_GEOM|ND_DATA, ob_slc->data); + WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, ob_slc); + WM_event_add_notifier(C, NC_GEOM | ND_DATA, ob_slc->data); CTX_DATA_END; @@ -3061,7 +3062,7 @@ void OBJECT_OT_vertex_group_transfer_weight(wmOperatorType *ot) ot->exec = vertex_group_transfer_weight_exec; /* flags */ - ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; } static EnumPropertyItem vgroup_items[] = { -- cgit v1.2.3 From 89cc1b2e50787de180fd2fc7c6cc03274b4491ad Mon Sep 17 00:00:00 2001 From: Ove Murberg Henriksen Date: Sun, 27 May 2012 14:17:01 +0000 Subject: GUI added, but crashes becasuse: ob_act / ob_src ->DerivedDeform == 0x0 --- source/blender/editors/object/object_vgroup.c | 42 ++++++++++++++++++++++----- 1 file changed, 35 insertions(+), 7 deletions(-) diff --git a/source/blender/editors/object/object_vgroup.c b/source/blender/editors/object/object_vgroup.c index 81adb1c41ff..c88fa164fdc 100644 --- a/source/blender/editors/object/object_vgroup.c +++ b/source/blender/editors/object/object_vgroup.c @@ -395,6 +395,27 @@ typedef enum ReplaceOption { REPLACE_SELECTED_WEIGHTS = 3 } ReplaceOption; +static EnumPropertyItem vertex_group_option_item[] = { + {REPLACE_SINGLE_VERTEX_GROUP, "REPLACE_SINGLE_VERTEX_GROUP", 1, "Single", "Transfer single vertex group."}, + {REPLACE_ALL_VERTEX_GROUPS, "REPLACE_ALL_VERTEX_GROUPS", 1, "All", "Transfer all vertex groups."}, + {0, NULL, 0, NULL, NULL} +}; + +static EnumPropertyItem method_option_item[] = { + {BY_INDEX, "BY_INDEX", 1, "Vertex index", "Copy for identical meshes."}, + {BY_NEAREST_VERTEX, "BY_NEAREST_VERTEX", 1, "Nearest vertex", "Copy weight from closest vertex."}, + {BY_NEAREST_FACE, "BY_NEAREST_FACE", 1, "Nearest face", "Barycentric interpolation from nearest face."}, + {BY_NEAREST_VERTEX_IN_FACE, "BY_NEAREST_VERTEX_IN_FACE", 1, "Nearest vertex in face", "Copy weight from closest vertex in nearest face."}, + {0, NULL, 0, NULL, NULL} +}; + +static EnumPropertyItem replace_option_item[] = { + {REPLACE_ALL_WEIGHTS, "REPLACE_ALL_WEIGHTS", 1, "All", "Overwrites all weights."}, + {REPLACE_EMPTY_WEIGHTS, "REPLACE_EMPTY_WEIGHTS", 1, "Empty", "Adds weights to vertices with no weight."}, + {REPLACE_SELECTED_WEIGHTS, "REPLACE_SELECTED_WEIGHTS", 1, "Selected", "Replace selected weights."}, + {0, NULL, 0, NULL, NULL} +}; + /*copy weight*/ void vgroup_transfer_weight(MVert *mv_dst, float *weight_dst, float weight_src, ReplaceOption replace_option) { @@ -608,6 +629,12 @@ int ED_vgroup_transfer_weight(Object *ob_dst, Object *ob_src, bDeformGroup *dg_s free_bvhtree_from_mesh(&tree_mesh_faces_src); break; } + + /*free memory*/ + if (mface_src) MEM_freeN(mface_src); + if (dv_array_src) MEM_freeN(dv_array_src); + if (dv_array_dst) MEM_freeN(dv_array_dst); + return 1; } @@ -3002,13 +3029,9 @@ static int vertex_group_transfer_weight_exec(bContext *C, wmOperator *op) int fail = 0; bDeformGroup *dg_src; - /* TODO: get these parameters from gui. - * For now 1,3,1 is default because GUI doesnt contain more than one button yet: - * Replace all weights in single vertexgroup based on interpolation of nearest face*/ - - VertexGroupOption vertex_group_option = 1; - MethodOption method_option = 3; - ReplaceOption replace_option = 1; + VertexGroupOption vertex_group_option = RNA_enum_get(op->ptr, "VertexGroupOption"); + MethodOption method_option = RNA_enum_get(op->ptr, "MethodOption"); + ReplaceOption replace_option = RNA_enum_get(op->ptr, "ReplaceOption"); /*Macro to loop through selected objects and perform operation depending on function, option and method*/ CTX_DATA_BEGIN(C, Object *, ob_slc, selected_editable_objects) @@ -3063,6 +3086,11 @@ void OBJECT_OT_vertex_group_transfer_weight(wmOperatorType *ot) /* flags */ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; + + /* properties */ + ot->prop = RNA_def_enum(ot->srna, "VertexGroupOption", vertex_group_option_item, 1, "Group", "What groups to transfer."); + ot->prop = RNA_def_enum(ot->srna, "MethodOption", method_option_item, 3, "Method", "How to calculate weight."); + ot->prop = RNA_def_enum(ot->srna, "ReplaceOption", replace_option_item, 1, "Replace", "What weights to overwrite"); } static EnumPropertyItem vgroup_items[] = { -- cgit v1.2.3 From bfd894b267b9753b36db60ed45ab512665519a95 Mon Sep 17 00:00:00 2001 From: Ove Murberg Henriksen Date: Sun, 27 May 2012 15:57:43 +0000 Subject: added mesh_get_derived_deform(scene, ob_act, CD_MASK_BAREMESH | CD_MASK_ORIGINDEX) but now it crashes on: a: @0x9bc692c8 math_vector_inline.c 296 --- source/blender/editors/object/object_vgroup.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/source/blender/editors/object/object_vgroup.c b/source/blender/editors/object/object_vgroup.c index c88fa164fdc..b9e185423d3 100644 --- a/source/blender/editors/object/object_vgroup.c +++ b/source/blender/editors/object/object_vgroup.c @@ -435,7 +435,7 @@ void vgroup_transfer_weight(MVert *mv_dst, float *weight_dst, float weight_src, } } -int ED_vgroup_transfer_weight(Object *ob_dst, Object *ob_src, bDeformGroup *dg_src, MethodOption method_option, ReplaceOption replace_option) +int ED_vgroup_transfer_weight(Object *ob_dst, Object *ob_src, bDeformGroup *dg_src, Scene *scene, MethodOption method_option, ReplaceOption replace_option) { bDeformGroup *dg_dst; Mesh *me_dst; @@ -460,7 +460,7 @@ int ED_vgroup_transfer_weight(Object *ob_dst, Object *ob_src, bDeformGroup *dg_s /*get meshes*/ me_dst = ob_dst->data; - dmesh_src = ob_src->derivedDeform; + dmesh_src = mesh_get_derived_deform(scene, ob_src, CD_MASK_BAREMESH | CD_MASK_ORIGINDEX); /*get vertex group arrays*/ ED_vgroup_give_parray(ob_src->data, &dv_array_src, &dv_tot_src, FALSE); @@ -3024,6 +3024,7 @@ void OBJECT_OT_vertex_group_copy_to_selected(wmOperatorType *ot) static int vertex_group_transfer_weight_exec(bContext *C, wmOperator *op) { + Scene *scene = CTX_data_scene(C); Object *ob_act = CTX_data_active_object(C); int change = 0; int fail = 0; @@ -3041,14 +3042,14 @@ static int vertex_group_transfer_weight_exec(bContext *C, wmOperator *op) switch (vertex_group_option) { case REPLACE_SINGLE_VERTEX_GROUP: - if (ED_vgroup_transfer_weight(ob_slc, ob_act, BLI_findlink(&ob_act->defbase, ob_act->actdef - 1), method_option, replace_option)) + if (ED_vgroup_transfer_weight(ob_slc, ob_act, BLI_findlink(&ob_act->defbase, ob_act->actdef - 1), scene, method_option, replace_option)) change++; else fail++; break; case REPLACE_ALL_VERTEX_GROUPS: for (dg_src = ob_act->defbase.first; dg_src; dg_src = dg_src->next) { - if (ED_vgroup_transfer_weight(ob_slc, ob_act, dg_src, method_option, replace_option)) change++; + if (ED_vgroup_transfer_weight(ob_slc, ob_act, dg_src, scene, method_option, replace_option)) change++; else fail++; } break; -- cgit v1.2.3 From ea9655ce14982f8d3bfed3edf8159c99e694197b Mon Sep 17 00:00:00 2001 From: Ove Murberg Henriksen Date: Sun, 27 May 2012 17:34:10 +0000 Subject: Fixed iterators. Memory bugs persist... --- source/blender/editors/object/object_vgroup.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/source/blender/editors/object/object_vgroup.c b/source/blender/editors/object/object_vgroup.c index b9e185423d3..c6345aff227 100644 --- a/source/blender/editors/object/object_vgroup.c +++ b/source/blender/editors/object/object_vgroup.c @@ -441,7 +441,7 @@ int ED_vgroup_transfer_weight(Object *ob_dst, Object *ob_src, bDeformGroup *dg_s Mesh *me_dst; DerivedMesh *dmesh_src; BVHTreeFromMesh tree_mesh_vertices_src, tree_mesh_faces_src = {NULL}; - MDeformVert **dv_array_src, **dv_array_dst; + MDeformVert **dv_array_src, **dv_array_dst, **dv_src, **dv_dst; MVert *mv_dst, *mv_src; MFace *mface_src; BVHTreeNearest nearest; @@ -490,7 +490,7 @@ int ED_vgroup_transfer_weight(Object *ob_dst, Object *ob_src, bDeformGroup *dg_s } /* loop through the vertices*/ - for (i = 0; i < dv_tot_dst; i++, dv_array_src++, dv_array_dst++, mv_dst++) { + for(i = 0, dv_src = dv_array_src, dv_dst = dv_array_dst; i < me_dst->totvert; i++, dv_dst++, dv_src++, mv_src++) { /*copy weight*/ dw_src = defvert_verify_index(*dv_array_src, index_src); @@ -503,8 +503,8 @@ int ED_vgroup_transfer_weight(Object *ob_dst, Object *ob_src, bDeformGroup *dg_s /*make node tree*/ bvhtree_from_mesh_verts(&tree_mesh_vertices_src, dmesh_src, 0.0, 2, 6); - /* loop through the vertices*/ - for (i = 0; i < me_dst->totvert; i++, mv_dst++, dv_array_dst++) { + /* loop trough vertices*/ + for(i = 0, dv_dst = dv_array_dst; i < me_dst->totvert; i++, dv_dst++, mv_src++){ /*reset nearest*/ /*nearest.index = -1; It is asumed using index of previous search as starting point result in speedup. It will be tested later*/ @@ -536,7 +536,7 @@ int ED_vgroup_transfer_weight(Object *ob_dst, Object *ob_src, bDeformGroup *dg_s bvhtree_from_mesh_faces(&tree_mesh_faces_src, dmesh_src, 0.0, 2, 6); /* loop through the vertices*/ - for (i = 0; i < me_dst->totvert; i++, mv_dst++, dv_array_dst++) { + for(i = 0, dv_dst = dv_array_dst; i < me_dst->totvert; i++, dv_dst++, mv_src++) { /*reset nearest*/ /*nearest.index = -1; It is asumed using index of previous search as starting point result in speedup. It will be tested later*/ @@ -552,8 +552,8 @@ int ED_vgroup_transfer_weight(Object *ob_dst, Object *ob_src, bDeformGroup *dg_s /*project onto face*/ 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); + mv_src[mface_src[index_nearest].v2].co, + mv_src[mface_src[index_nearest].v3].co); project_v3_plane(tmp_co, normal, mv_src[mface_src[index_nearest].v1].co); @@ -589,7 +589,7 @@ int ED_vgroup_transfer_weight(Object *ob_dst, Object *ob_src, bDeformGroup *dg_s bvhtree_from_mesh_faces(&tree_mesh_faces_src, dmesh_src, 0.0, 2, 6); /*loop through the vertices*/ - for (i = 0; i < me_dst->totvert; i++, mv_dst++, dv_array_dst++) { + for(i = 0, dv_dst = dv_array_dst; i < me_dst->totvert; i++, dv_src++, mv_src++){ /*reset nearest*/ /*nearest.index = -1; It is asumed using index of previous search as starting point result in speedup. It will be tested later*/ @@ -630,10 +630,12 @@ int ED_vgroup_transfer_weight(Object *ob_dst, Object *ob_src, bDeformGroup *dg_s break; } - /*free memory*/ + /*free memory*//*TODO must free wehn function breaks on return 0 as well, right?*/ if (mface_src) MEM_freeN(mface_src); if (dv_array_src) MEM_freeN(dv_array_src); if (dv_array_dst) MEM_freeN(dv_array_dst); + if (dv_src) MEM_freeN(dv_src); + if (dv_dst) MEM_freeN(dv_dst); return 1; } -- cgit v1.2.3 From 1dce081e2ba094158ce062e439d613127c756821 Mon Sep 17 00:00:00 2001 From: Ove Murberg Henriksen Date: Sun, 27 May 2012 17:47:21 +0000 Subject: small cleaning --- source/blender/editors/object/object_vgroup.c | 94 +++++++++++++-------------- 1 file changed, 46 insertions(+), 48 deletions(-) diff --git a/source/blender/editors/object/object_vgroup.c b/source/blender/editors/object/object_vgroup.c index c6345aff227..15fca1548e0 100644 --- a/source/blender/editors/object/object_vgroup.c +++ b/source/blender/editors/object/object_vgroup.c @@ -449,32 +449,32 @@ int ED_vgroup_transfer_weight(Object *ob_dst, Object *ob_src, bDeformGroup *dg_s int dv_tot_src, dv_tot_dst, i, index_dst, index_src, index_nearest, index_nearest_vertex; float weight, tmp_weight[4], tmp_co[3], normal[3], tmp_mat[4][4], dist_v1, dist_v2, dist_v3, dist_v4; - /*create new and overwrite vertex group on destination without data*/ + /* create new and overwrite vertex group on destination without data */ if (!defgroup_find_name(ob_dst, dg_src->name) || replace_option == REPLACE_ALL_WEIGHTS) { 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*/ + /* get destination deformgroup */ dg_dst = defgroup_find_name(ob_dst, dg_src->name); - /*get meshes*/ + /* get meshes */ me_dst = ob_dst->data; dmesh_src = mesh_get_derived_deform(scene, ob_src, CD_MASK_BAREMESH | CD_MASK_ORIGINDEX); - /*get vertex group arrays*/ + /* 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*/ + /* get indexes of vertex groups */ index_src = BLI_findindex(&ob_src->defbase, dg_src); index_dst = BLI_findindex(&ob_dst->defbase, dg_dst); - /*get vertices*/ + /* get vertices */ mv_dst = me_dst->mvert; mv_src = dmesh_src->getVertArray(dmesh_src); - /*prepare transformation matrix*/ + /* prepare transformation matrix */ invert_m4_m4(ob_src->imat, ob_src->obmat); mult_m4_m4m4(tmp_mat, ob_src->imat, ob_dst->obmat); @@ -492,7 +492,7 @@ int ED_vgroup_transfer_weight(Object *ob_dst, Object *ob_src, bDeformGroup *dg_s /* loop through the vertices*/ for(i = 0, dv_src = dv_array_src, dv_dst = dv_array_dst; i < me_dst->totvert; i++, dv_dst++, dv_src++, mv_src++) { - /*copy weight*/ + /* copy weight */ dw_src = defvert_verify_index(*dv_array_src, index_src); dw_dst = defvert_verify_index(*dv_array_dst, index_dst); vgroup_transfer_weight(mv_dst, &dw_dst->weight, dw_src->weight, replace_option); @@ -500,70 +500,70 @@ int ED_vgroup_transfer_weight(Object *ob_dst, Object *ob_src, bDeformGroup *dg_s break; case BY_NEAREST_VERTEX: - /*make node tree*/ + /* make node tree */ bvhtree_from_mesh_verts(&tree_mesh_vertices_src, dmesh_src, 0.0, 2, 6); - /* loop trough vertices*/ + /* loop trough vertices */ for(i = 0, dv_dst = dv_array_dst; i < me_dst->totvert; i++, dv_dst++, mv_src++){ - /*reset nearest*/ - /*nearest.index = -1; It is asumed using index of previous search as starting point result in speedup. It will be tested later*/ + /* reset nearest */ + /* nearest.index = -1; It is asumed using index of previous search as starting point result in speedup. It will be tested later */ nearest.dist = FLT_MAX; - /*transform into target space*/ + /* transform into target space */ mul_v3_m4v3(tmp_co, tmp_mat, mv_dst->co); - /*node tree accelerated search for closest vetex*/ + /* node tree accelerated search for closest vetex */ BLI_bvhtree_find_nearest(tree_mesh_vertices_src.tree, tmp_co, &nearest, tree_mesh_vertices_src.nearest_callback, &tree_mesh_vertices_src); - /*copy weight*/ + /* copy weight */ dw_src = defvert_verify_index(dv_array_src[nearest.index], index_src); dw_dst = defvert_verify_index(*dv_array_dst, index_dst); vgroup_transfer_weight(mv_dst, &dw_dst->weight, dw_src->weight, replace_option); } - /*free memory*/ + /* free memory */ free_bvhtree_from_mesh(&tree_mesh_vertices_src); break; case BY_NEAREST_FACE: - /*get faces*/ + /* get faces */ DM_ensure_tessface(dmesh_src); mface_src = dmesh_src->getTessFaceArray(dmesh_src); - /*make node tree*/ + /* make node tree */ bvhtree_from_mesh_faces(&tree_mesh_faces_src, dmesh_src, 0.0, 2, 6); - /* loop through the vertices*/ + /* loop through the vertices */ for(i = 0, dv_dst = dv_array_dst; i < me_dst->totvert; i++, dv_dst++, mv_src++) { - /*reset nearest*/ - /*nearest.index = -1; It is asumed using index of previous search as starting point result in speedup. It will be tested later*/ + /* reset nearest */ + /* nearest.index = -1; It is asumed using index of previous search as starting point result in speedup. It will be tested later */ nearest.dist = FLT_MAX; - /*transform into target space*/ + /* transform into target space */ mul_v3_m4v3(tmp_co, tmp_mat, mv_dst->co); - /*node tree accelerated search for closest face*/ + /* 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); index_nearest = nearest.index; - /*project onto face*/ + /* project onto face */ normal_tri_v3(normal, mv_src[mface_src[nearest.index].v1].co, mv_src[mface_src[index_nearest].v2].co, mv_src[mface_src[index_nearest].v3].co); project_v3_plane(tmp_co, normal, mv_src[mface_src[index_nearest].v1].co); - /*interpolate weights*/ + /* interpolate weights */ interp_weights_face_v3(tmp_weight, mv_src[mface_src[index_nearest].v1].co, mv_src[mface_src[index_nearest].v2].co, mv_src[mface_src[index_nearest].v3].co, mv_src[mface_src[index_nearest].v4].co, tmp_co); - /*get weights*/ + /* get weights */ weight = tmp_weight[0] * defvert_verify_index(dv_array_src[mface_src[index_nearest].v1], index_src)->weight; weight += tmp_weight[1] * defvert_verify_index(dv_array_src[mface_src[index_nearest].v2], index_src)->weight; weight += tmp_weight[2] * defvert_verify_index(dv_array_src[mface_src[index_nearest].v3], index_src)->weight; @@ -571,44 +571,44 @@ int ED_vgroup_transfer_weight(Object *ob_dst, Object *ob_src, bDeformGroup *dg_s weight += tmp_weight[3] * defvert_verify_index(dv_array_src[mface_src[index_nearest].v4], index_src)->weight; } - /*copy weight*/ + /* copy weight */ dw_dst = defvert_verify_index(*dv_array_dst, index_dst); vgroup_transfer_weight(mv_dst, &dw_dst->weight, weight, replace_option); } - /*free memory*/ + /* free memory */ free_bvhtree_from_mesh(&tree_mesh_faces_src); break; case BY_NEAREST_VERTEX_IN_FACE: - /*get faces*/ + /* get faces */ DM_ensure_tessface(dmesh_src); mface_src = dmesh_src->getTessFaceArray(dmesh_src); - /*make node tree*/ + /* make node tree */ bvhtree_from_mesh_faces(&tree_mesh_faces_src, dmesh_src, 0.0, 2, 6); - /*loop through the vertices*/ + /* loop through the vertices */ for(i = 0, dv_dst = dv_array_dst; i < me_dst->totvert; i++, dv_src++, mv_src++){ - /*reset nearest*/ - /*nearest.index = -1; It is asumed using index of previous search as starting point result in speedup. It will be tested later*/ + /* reset nearest */ + /* nearest.index = -1; It is asumed using index of previous search as starting point result in speedup. It will be tested later */ nearest.dist = FLT_MAX; - /*transform into target space*/ + /* transform into target space */ mul_v3_m4v3(tmp_co, tmp_mat, mv_dst->co); - /*node tree accelerated search for closest face*/ + /* 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); index_nearest = nearest.index; - /*get distances*/ + /* get distances */ dist_v1 = len_squared_v3v3(tmp_co, mv_src[mface_src[index_nearest].v1].co); dist_v2 = len_squared_v3v3(tmp_co, mv_src[mface_src[index_nearest].v2].co); dist_v3 = len_squared_v3v3(tmp_co, mv_src[mface_src[index_nearest].v3].co); - /*get closest vertex*/ + /* get closest vertex */ if (dist_v1 < dist_v2 && dist_v1 < dist_v3) index_nearest_vertex = mface_src[index_nearest].v1; else if (dist_v2 < dist_v3) index_nearest_vertex = mface_src[index_nearest].v2; else index_nearest_vertex = mface_src[index_nearest].v3; @@ -619,23 +619,21 @@ int ED_vgroup_transfer_weight(Object *ob_dst, Object *ob_src, bDeformGroup *dg_s } } - /*copy weight*/ + /* copy weight */ dw_src = defvert_verify_index(dv_array_src[index_nearest_vertex], index_src); dw_dst = defvert_verify_index(*dv_array_dst, index_dst); vgroup_transfer_weight(mv_dst, &dw_dst->weight, dw_src->weight, replace_option); } - /*free memory*/ + /* free memory */ free_bvhtree_from_mesh(&tree_mesh_faces_src); break; } - /*free memory*//*TODO must free wehn function breaks on return 0 as well, right?*/ + /*free memory*//*TODO must free when function breaks on return 0 as well, right?*/ if (mface_src) MEM_freeN(mface_src); if (dv_array_src) MEM_freeN(dv_array_src); if (dv_array_dst) MEM_freeN(dv_array_dst); - if (dv_src) MEM_freeN(dv_src); - if (dv_dst) MEM_freeN(dv_dst); return 1; } @@ -3036,7 +3034,7 @@ static int vertex_group_transfer_weight_exec(bContext *C, wmOperator *op) MethodOption method_option = RNA_enum_get(op->ptr, "MethodOption"); ReplaceOption replace_option = RNA_enum_get(op->ptr, "ReplaceOption"); - /*Macro to loop through selected objects and perform operation depending on function, option and method*/ + /* Macro to loop through selected objects and perform operation depending on function, option and method */ CTX_DATA_BEGIN(C, Object *, ob_slc, selected_editable_objects) { @@ -3059,14 +3057,14 @@ static int vertex_group_transfer_weight_exec(bContext *C, wmOperator *op) } } - /*Event notifiers for correct display of data*/ + /* Event notifiers for correct display of data */ DAG_id_tag_update(&ob_slc->id, OB_RECALC_DATA); WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, ob_slc); WM_event_add_notifier(C, NC_GEOM | ND_DATA, ob_slc->data); CTX_DATA_END; - /*Report error when task can not be completed with available functions.*/ + /* Report error when task can not be completed with available functions. */ if ((change == 0 && fail == 0) || fail) { BKE_reportf(op->reports, RPT_ERROR, "Copy to VGroups to Selected warning done %d, failed %d, object data must have matching indices", @@ -3075,7 +3073,7 @@ static int vertex_group_transfer_weight_exec(bContext *C, wmOperator *op) return OPERATOR_FINISHED; } -/*transfers weight from active to selected*/ +/* transfers weight from active to selected */ void OBJECT_OT_vertex_group_transfer_weight(wmOperatorType *ot) { /* identifiers */ @@ -3091,8 +3089,8 @@ void OBJECT_OT_vertex_group_transfer_weight(wmOperatorType *ot) ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; /* properties */ - ot->prop = RNA_def_enum(ot->srna, "VertexGroupOption", vertex_group_option_item, 1, "Group", "What groups to transfer."); - ot->prop = RNA_def_enum(ot->srna, "MethodOption", method_option_item, 3, "Method", "How to calculate weight."); + ot->prop = RNA_def_enum(ot->srna, "VertexGroupOption", vertex_group_option_item, 1, "Group", "What groups to transfer"); + ot->prop = RNA_def_enum(ot->srna, "MethodOption", method_option_item, 3, "Method", "How to calculate weight"); ot->prop = RNA_def_enum(ot->srna, "ReplaceOption", replace_option_item, 1, "Replace", "What weights to overwrite"); } -- cgit v1.2.3 From be4d30bf8e03f878522b4422d30bb172e17bffc5 Mon Sep 17 00:00:00 2001 From: Ove Murberg Henriksen Date: Sun, 27 May 2012 18:05:10 +0000 Subject: Bogus MEM_freeN removed and cleaned descriptions. --- source/blender/editors/object/object_vgroup.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/source/blender/editors/object/object_vgroup.c b/source/blender/editors/object/object_vgroup.c index 15fca1548e0..e2dda936b19 100644 --- a/source/blender/editors/object/object_vgroup.c +++ b/source/blender/editors/object/object_vgroup.c @@ -631,7 +631,6 @@ int ED_vgroup_transfer_weight(Object *ob_dst, Object *ob_src, bDeformGroup *dg_s } /*free memory*//*TODO must free when function breaks on return 0 as well, right?*/ - if (mface_src) MEM_freeN(mface_src); if (dv_array_src) MEM_freeN(dv_array_src); if (dv_array_dst) MEM_freeN(dv_array_dst); @@ -3089,9 +3088,9 @@ void OBJECT_OT_vertex_group_transfer_weight(wmOperatorType *ot) ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; /* properties */ - ot->prop = RNA_def_enum(ot->srna, "VertexGroupOption", vertex_group_option_item, 1, "Group", "What groups to transfer"); - ot->prop = RNA_def_enum(ot->srna, "MethodOption", method_option_item, 3, "Method", "How to calculate weight"); - ot->prop = RNA_def_enum(ot->srna, "ReplaceOption", replace_option_item, 1, "Replace", "What weights to overwrite"); + ot->prop = RNA_def_enum(ot->srna, "VertexGroupOption", vertex_group_option_item, 1, "Group", ""); + ot->prop = RNA_def_enum(ot->srna, "MethodOption", method_option_item, 3, "Method", ""); + ot->prop = RNA_def_enum(ot->srna, "ReplaceOption", replace_option_item, 1, "Replace", ""); } static EnumPropertyItem vgroup_items[] = { -- cgit v1.2.3 From 0d42015671b3f835742c023178f040b898276a79 Mon Sep 17 00:00:00 2001 From: Ove Murberg Henriksen Date: Thu, 31 May 2012 19:09:23 +0000 Subject: Fixes to bugs that appeared during restructure. --- source/blender/editors/object/object_vgroup.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/source/blender/editors/object/object_vgroup.c b/source/blender/editors/object/object_vgroup.c index e2dda936b19..e74c16741d8 100644 --- a/source/blender/editors/object/object_vgroup.c +++ b/source/blender/editors/object/object_vgroup.c @@ -426,7 +426,7 @@ void vgroup_transfer_weight(MVert *mv_dst, float *weight_dst, float weight_src, break; case REPLACE_EMPTY_WEIGHTS: - if (!weight_dst || weight_dst == 0) *weight_dst = weight_src; + if (*weight_dst == 0) *weight_dst = weight_src; break; case REPLACE_SELECTED_WEIGHTS: @@ -493,8 +493,8 @@ int ED_vgroup_transfer_weight(Object *ob_dst, Object *ob_src, bDeformGroup *dg_s for(i = 0, dv_src = dv_array_src, dv_dst = dv_array_dst; i < me_dst->totvert; i++, dv_dst++, dv_src++, mv_src++) { /* copy weight */ - dw_src = defvert_verify_index(*dv_array_src, index_src); - dw_dst = defvert_verify_index(*dv_array_dst, index_dst); + dw_src = defvert_verify_index(*dv_src, index_src); + dw_dst = defvert_verify_index(*dv_dst, index_dst); vgroup_transfer_weight(mv_dst, &dw_dst->weight, dw_src->weight, replace_option); } break; @@ -504,7 +504,7 @@ int ED_vgroup_transfer_weight(Object *ob_dst, Object *ob_src, bDeformGroup *dg_s bvhtree_from_mesh_verts(&tree_mesh_vertices_src, dmesh_src, 0.0, 2, 6); /* loop trough vertices */ - for(i = 0, dv_dst = dv_array_dst; i < me_dst->totvert; i++, dv_dst++, mv_src++){ + for(i = 0, dv_dst = dv_array_dst; i < me_dst->totvert; i++, dv_dst++, mv_dst++){ /* reset nearest */ /* nearest.index = -1; It is asumed using index of previous search as starting point result in speedup. It will be tested later */ @@ -519,7 +519,7 @@ int ED_vgroup_transfer_weight(Object *ob_dst, Object *ob_src, bDeformGroup *dg_s /* copy weight */ dw_src = defvert_verify_index(dv_array_src[nearest.index], index_src); - dw_dst = defvert_verify_index(*dv_array_dst, index_dst); + dw_dst = defvert_verify_index(*dv_dst, index_dst); vgroup_transfer_weight(mv_dst, &dw_dst->weight, dw_src->weight, replace_option); } @@ -536,7 +536,7 @@ int ED_vgroup_transfer_weight(Object *ob_dst, Object *ob_src, bDeformGroup *dg_s bvhtree_from_mesh_faces(&tree_mesh_faces_src, dmesh_src, 0.0, 2, 6); /* loop through the vertices */ - for(i = 0, dv_dst = dv_array_dst; i < me_dst->totvert; i++, dv_dst++, mv_src++) { + for(i = 0, dv_dst = dv_array_dst; i < me_dst->totvert; i++, dv_dst++, mv_dst++) { /* reset nearest */ /* nearest.index = -1; It is asumed using index of previous search as starting point result in speedup. It will be tested later */ @@ -572,7 +572,7 @@ int ED_vgroup_transfer_weight(Object *ob_dst, Object *ob_src, bDeformGroup *dg_s } /* copy weight */ - dw_dst = defvert_verify_index(*dv_array_dst, index_dst); + dw_dst = defvert_verify_index(*dv_dst, index_dst); vgroup_transfer_weight(mv_dst, &dw_dst->weight, weight, replace_option); } @@ -589,7 +589,7 @@ int ED_vgroup_transfer_weight(Object *ob_dst, Object *ob_src, bDeformGroup *dg_s bvhtree_from_mesh_faces(&tree_mesh_faces_src, dmesh_src, 0.0, 2, 6); /* loop through the vertices */ - for(i = 0, dv_dst = dv_array_dst; i < me_dst->totvert; i++, dv_src++, mv_src++){ + for(i = 0, dv_dst = dv_array_dst; i < me_dst->totvert; i++, dv_dst++, mv_dst++){ /* reset nearest */ /* nearest.index = -1; It is asumed using index of previous search as starting point result in speedup. It will be tested later */ @@ -621,7 +621,7 @@ int ED_vgroup_transfer_weight(Object *ob_dst, Object *ob_src, bDeformGroup *dg_s /* copy weight */ dw_src = defvert_verify_index(dv_array_src[index_nearest_vertex], index_src); - dw_dst = defvert_verify_index(*dv_array_dst, index_dst); + dw_dst = defvert_verify_index(*dv_dst, index_dst); vgroup_transfer_weight(mv_dst, &dw_dst->weight, dw_src->weight, replace_option); } -- cgit v1.2.3 From 7b294890167dbc8850fc98e9d101c46359c27adb Mon Sep 17 00:00:00 2001 From: Ove Murberg Henriksen Date: Sun, 3 Jun 2012 16:44:48 +0000 Subject: BVHTree usage optimized for transferring between meshes of 300k faces. Mesh were the shape of a human. Optimizing for anything less would not make sense because it happens ~instant moving to 10 tree from binary tree increased speed by ~30% initiating additional searches with the first increased speed by ~99% Now function completes in less than two seconds on my amd 2,6ghz --- source/blender/editors/object/object_vgroup.c | 30 +++++++++++++-------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/source/blender/editors/object/object_vgroup.c b/source/blender/editors/object/object_vgroup.c index e74c16741d8..03147818360 100644 --- a/source/blender/editors/object/object_vgroup.c +++ b/source/blender/editors/object/object_vgroup.c @@ -501,15 +501,15 @@ int ED_vgroup_transfer_weight(Object *ob_dst, Object *ob_src, bDeformGroup *dg_s case BY_NEAREST_VERTEX: /* make node tree */ - bvhtree_from_mesh_verts(&tree_mesh_vertices_src, dmesh_src, 0.0, 2, 6); + bvhtree_from_mesh_verts(&tree_mesh_vertices_src, dmesh_src, FLT_EPSILON, 10, 6); + + /* reset nearest */ + nearest.dist = FLT_MAX; + nearest.index = -1; /* loop trough vertices */ for(i = 0, dv_dst = dv_array_dst; i < me_dst->totvert; i++, dv_dst++, mv_dst++){ - /* reset nearest */ - /* nearest.index = -1; It is asumed using index of previous search as starting point result in speedup. It will be tested later */ - nearest.dist = FLT_MAX; - /* transform into target space */ mul_v3_m4v3(tmp_co, tmp_mat, mv_dst->co); @@ -533,15 +533,15 @@ int ED_vgroup_transfer_weight(Object *ob_dst, Object *ob_src, bDeformGroup *dg_s mface_src = dmesh_src->getTessFaceArray(dmesh_src); /* make node tree */ - bvhtree_from_mesh_faces(&tree_mesh_faces_src, dmesh_src, 0.0, 2, 6); + bvhtree_from_mesh_faces(&tree_mesh_faces_src, dmesh_src, FLT_EPSILON, 10, 6); + + /* reset nearest */ + nearest.dist = FLT_MAX; + nearest.index = -1; /* loop through the vertices */ for(i = 0, dv_dst = dv_array_dst; i < me_dst->totvert; i++, dv_dst++, mv_dst++) { - /* reset nearest */ - /* nearest.index = -1; It is asumed using index of previous search as starting point result in speedup. It will be tested later */ - nearest.dist = FLT_MAX; - /* transform into target space */ mul_v3_m4v3(tmp_co, tmp_mat, mv_dst->co); @@ -586,15 +586,15 @@ int ED_vgroup_transfer_weight(Object *ob_dst, Object *ob_src, bDeformGroup *dg_s mface_src = dmesh_src->getTessFaceArray(dmesh_src); /* make node tree */ - bvhtree_from_mesh_faces(&tree_mesh_faces_src, dmesh_src, 0.0, 2, 6); + bvhtree_from_mesh_faces(&tree_mesh_faces_src, dmesh_src, FLT_EPSILON, 10, 6); + + /* reset nearest */ + nearest.dist = FLT_MAX; + nearest.index = -1; /* loop through the vertices */ for(i = 0, dv_dst = dv_array_dst; i < me_dst->totvert; i++, dv_dst++, mv_dst++){ - /* reset nearest */ - /* nearest.index = -1; It is asumed using index of previous search as starting point result in speedup. It will be tested later */ - nearest.dist = FLT_MAX; - /* transform into target space */ mul_v3_m4v3(tmp_co, tmp_mat, mv_dst->co); -- cgit v1.2.3 From 512b35754e81c8b5fc4fe93fc26b995f5083dc60 Mon Sep 17 00:00:00 2001 From: Ove Murberg Henriksen Date: Sun, 3 Jun 2012 17:16:50 +0000 Subject: Bugfix to bug from optimizing... --- source/blender/editors/object/object_vgroup.c | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/source/blender/editors/object/object_vgroup.c b/source/blender/editors/object/object_vgroup.c index 03147818360..b389b0b66b7 100644 --- a/source/blender/editors/object/object_vgroup.c +++ b/source/blender/editors/object/object_vgroup.c @@ -503,13 +503,12 @@ int ED_vgroup_transfer_weight(Object *ob_dst, Object *ob_src, bDeformGroup *dg_s /* make node tree */ bvhtree_from_mesh_verts(&tree_mesh_vertices_src, dmesh_src, FLT_EPSILON, 10, 6); - /* reset nearest */ - nearest.dist = FLT_MAX; - nearest.index = -1; - /* loop trough vertices */ for(i = 0, dv_dst = dv_array_dst; i < me_dst->totvert; i++, dv_dst++, mv_dst++){ + /* reset nearest */ + nearest.dist = FLT_MAX; + /* transform into target space */ mul_v3_m4v3(tmp_co, tmp_mat, mv_dst->co); @@ -535,13 +534,12 @@ int ED_vgroup_transfer_weight(Object *ob_dst, Object *ob_src, bDeformGroup *dg_s /* make node tree */ bvhtree_from_mesh_faces(&tree_mesh_faces_src, dmesh_src, FLT_EPSILON, 10, 6); - /* reset nearest */ - nearest.dist = FLT_MAX; - nearest.index = -1; - /* loop through the vertices */ for(i = 0, dv_dst = dv_array_dst; i < me_dst->totvert; i++, dv_dst++, mv_dst++) { + /* reset nearest */ + nearest.dist = FLT_MAX; + /* transform into target space */ mul_v3_m4v3(tmp_co, tmp_mat, mv_dst->co); @@ -588,13 +586,12 @@ int ED_vgroup_transfer_weight(Object *ob_dst, Object *ob_src, bDeformGroup *dg_s /* make node tree */ bvhtree_from_mesh_faces(&tree_mesh_faces_src, dmesh_src, FLT_EPSILON, 10, 6); - /* reset nearest */ - nearest.dist = FLT_MAX; - nearest.index = -1; - /* loop through the vertices */ for(i = 0, dv_dst = dv_array_dst; i < me_dst->totvert; i++, dv_dst++, mv_dst++){ + /* reset nearest */ + nearest.dist = FLT_MAX; + /* transform into target space */ mul_v3_m4v3(tmp_co, tmp_mat, mv_dst->co); -- cgit v1.2.3 From c63dcaee07d86a23652bb4fce6f3ecde94bbee38 Mon Sep 17 00:00:00 2001 From: Ove Murberg Henriksen Date: Sun, 3 Jun 2012 18:44:17 +0000 Subject: small fix to mem release when using index method --- source/blender/editors/object/object_vgroup.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/source/blender/editors/object/object_vgroup.c b/source/blender/editors/object/object_vgroup.c index b389b0b66b7..8347480ecda 100644 --- a/source/blender/editors/object/object_vgroup.c +++ b/source/blender/editors/object/object_vgroup.c @@ -486,6 +486,8 @@ int ED_vgroup_transfer_weight(Object *ob_dst, Object *ob_src, bDeformGroup *dg_s dv_array_src == NULL || dv_array_dst == NULL) { ED_vgroup_delete(ob_dst, defgroup_find_name(ob_dst, dg_dst->name)); + if (dv_array_src) MEM_freeN(dv_array_src); + if (dv_array_dst) MEM_freeN(dv_array_dst); return 0; } @@ -627,7 +629,7 @@ int ED_vgroup_transfer_weight(Object *ob_dst, Object *ob_src, bDeformGroup *dg_s break; } - /*free memory*//*TODO must free when function breaks on return 0 as well, right?*/ + /*free memory*/ if (dv_array_src) MEM_freeN(dv_array_src); if (dv_array_dst) MEM_freeN(dv_array_dst); -- cgit v1.2.3 From 87c585c1ba120d92a42add7ffe3c2aff12f93b30 Mon Sep 17 00:00:00 2001 From: Ove Murberg Henriksen Date: Sun, 3 Jun 2012 20:23:41 +0000 Subject: Reverting to binary tree because related optimization with type 10 tree were bugged. Now feature completes in ~5 sec for a mesh with 300k vertices. but it works as intended. --- source/blender/editors/object/object_vgroup.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/source/blender/editors/object/object_vgroup.c b/source/blender/editors/object/object_vgroup.c index 8347480ecda..d4d81501f9a 100644 --- a/source/blender/editors/object/object_vgroup.c +++ b/source/blender/editors/object/object_vgroup.c @@ -503,13 +503,14 @@ int ED_vgroup_transfer_weight(Object *ob_dst, Object *ob_src, bDeformGroup *dg_s case BY_NEAREST_VERTEX: /* make node tree */ - bvhtree_from_mesh_verts(&tree_mesh_vertices_src, dmesh_src, FLT_EPSILON, 10, 6); + bvhtree_from_mesh_verts(&tree_mesh_vertices_src, dmesh_src, FLT_EPSILON, 2, 6); /* loop trough vertices */ for(i = 0, dv_dst = dv_array_dst; i < me_dst->totvert; i++, dv_dst++, mv_dst++){ /* reset nearest */ nearest.dist = FLT_MAX; + /* nearest.index = -1; when this is commented out, the next search is initiated by the index of the previous. */ /* transform into target space */ mul_v3_m4v3(tmp_co, tmp_mat, mv_dst->co); @@ -534,13 +535,14 @@ int ED_vgroup_transfer_weight(Object *ob_dst, Object *ob_src, bDeformGroup *dg_s mface_src = dmesh_src->getTessFaceArray(dmesh_src); /* make node tree */ - bvhtree_from_mesh_faces(&tree_mesh_faces_src, dmesh_src, FLT_EPSILON, 10, 6); + bvhtree_from_mesh_faces(&tree_mesh_faces_src, dmesh_src, FLT_EPSILON, 2, 6); /* loop through the vertices */ for(i = 0, dv_dst = dv_array_dst; i < me_dst->totvert; i++, dv_dst++, mv_dst++) { /* reset nearest */ nearest.dist = FLT_MAX; + /* nearest.index = -1; when this is commented out, the next search is initiated by the index of the previous. */ /* transform into target space */ mul_v3_m4v3(tmp_co, tmp_mat, mv_dst->co); @@ -586,13 +588,14 @@ int ED_vgroup_transfer_weight(Object *ob_dst, Object *ob_src, bDeformGroup *dg_s mface_src = dmesh_src->getTessFaceArray(dmesh_src); /* make node tree */ - bvhtree_from_mesh_faces(&tree_mesh_faces_src, dmesh_src, FLT_EPSILON, 10, 6); + bvhtree_from_mesh_faces(&tree_mesh_faces_src, dmesh_src, FLT_EPSILON, 2, 6); /* loop through the vertices */ for(i = 0, dv_dst = dv_array_dst; i < me_dst->totvert; i++, dv_dst++, mv_dst++){ /* reset nearest */ nearest.dist = FLT_MAX; + /* nearest.index = -1; when this is commented out, the next search is initiated by the index of the previous. */ /* transform into target space */ mul_v3_m4v3(tmp_co, tmp_mat, mv_dst->co); -- cgit v1.2.3 From cd346252d720307c4943699f62f82289683fd9d1 Mon Sep 17 00:00:00 2001 From: Ove Murberg Henriksen Date: Sun, 3 Jun 2012 21:34:17 +0000 Subject: After reverting to binary tree, starting search at the top by reseting nearest is marginally faster than using previous search. --- source/blender/editors/object/object_vgroup.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/source/blender/editors/object/object_vgroup.c b/source/blender/editors/object/object_vgroup.c index d4d81501f9a..52d5bcaffa7 100644 --- a/source/blender/editors/object/object_vgroup.c +++ b/source/blender/editors/object/object_vgroup.c @@ -510,7 +510,8 @@ int ED_vgroup_transfer_weight(Object *ob_dst, Object *ob_src, bDeformGroup *dg_s /* reset nearest */ nearest.dist = FLT_MAX; - /* nearest.index = -1; when this is commented out, the next search is initiated by the index of the previous. */ + /* With current binary tree its marginally faster to start searching at the top, as opposed to previous search. */ + nearest.index = -1; /* transform into target space */ mul_v3_m4v3(tmp_co, tmp_mat, mv_dst->co); @@ -542,7 +543,8 @@ int ED_vgroup_transfer_weight(Object *ob_dst, Object *ob_src, bDeformGroup *dg_s /* reset nearest */ nearest.dist = FLT_MAX; - /* nearest.index = -1; when this is commented out, the next search is initiated by the index of the previous. */ + /* With current binary tree its marginally faster to start searching at the top, as opposed to previous search. */ + nearest.index = -1; /* transform into target space */ mul_v3_m4v3(tmp_co, tmp_mat, mv_dst->co); @@ -595,7 +597,8 @@ int ED_vgroup_transfer_weight(Object *ob_dst, Object *ob_src, bDeformGroup *dg_s /* reset nearest */ nearest.dist = FLT_MAX; - /* nearest.index = -1; when this is commented out, the next search is initiated by the index of the previous. */ + /* With current binary tree its marginally faster to start searching at the top, as opposed to previous search. */ + nearest.index = -1; /* transform into target space */ mul_v3_m4v3(tmp_co, tmp_mat, mv_dst->co); -- cgit v1.2.3 From 51cbfba3067fcd2e2d5c3966f563f8911f147d17 Mon Sep 17 00:00:00 2001 From: Ove Murberg Henriksen Date: Mon, 4 Jun 2012 22:17:40 +0000 Subject: Now the feature is more intuitive. copying from selected to active. --- source/blender/editors/object/object_vgroup.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/source/blender/editors/object/object_vgroup.c b/source/blender/editors/object/object_vgroup.c index 52d5bcaffa7..d58720d5293 100644 --- a/source/blender/editors/object/object_vgroup.c +++ b/source/blender/editors/object/object_vgroup.c @@ -3046,14 +3046,14 @@ static int vertex_group_transfer_weight_exec(bContext *C, wmOperator *op) switch (vertex_group_option) { case REPLACE_SINGLE_VERTEX_GROUP: - if (ED_vgroup_transfer_weight(ob_slc, ob_act, BLI_findlink(&ob_act->defbase, ob_act->actdef - 1), scene, method_option, replace_option)) + if (ED_vgroup_transfer_weight(ob_act, ob_slc, BLI_findlink(&ob_slc->defbase, ob_slc->actdef - 1), scene, method_option, replace_option)) change++; else fail++; break; case REPLACE_ALL_VERTEX_GROUPS: - for (dg_src = ob_act->defbase.first; dg_src; dg_src = dg_src->next) { - if (ED_vgroup_transfer_weight(ob_slc, ob_act, dg_src, scene, method_option, replace_option)) change++; + for (dg_src = ob_slc->defbase.first; dg_src; dg_src = dg_src->next) { + if (ED_vgroup_transfer_weight(ob_act, ob_slc, dg_src, scene, method_option, replace_option)) change++; else fail++; } break; -- cgit v1.2.3 From 59d699805c460f4f68e52f4005b6c43d6f4f7ea2 Mon Sep 17 00:00:00 2001 From: Ove Murberg Henriksen Date: Tue, 5 Jun 2012 20:48:01 +0000 Subject: Bugfix, no longer crashing wehn no source vertex group. --- source/blender/editors/object/object_vgroup.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/source/blender/editors/object/object_vgroup.c b/source/blender/editors/object/object_vgroup.c index d58720d5293..32433caee5a 100644 --- a/source/blender/editors/object/object_vgroup.c +++ b/source/blender/editors/object/object_vgroup.c @@ -396,8 +396,8 @@ typedef enum ReplaceOption { } ReplaceOption; static EnumPropertyItem vertex_group_option_item[] = { - {REPLACE_SINGLE_VERTEX_GROUP, "REPLACE_SINGLE_VERTEX_GROUP", 1, "Single", "Transfer single vertex group."}, - {REPLACE_ALL_VERTEX_GROUPS, "REPLACE_ALL_VERTEX_GROUPS", 1, "All", "Transfer all vertex groups."}, + {REPLACE_SINGLE_VERTEX_GROUP, "REPLACE_SINGLE_VERTEX_GROUP", 1, "Single", "Transfer single vertex group from selected to active mesh."}, + {REPLACE_ALL_VERTEX_GROUPS, "REPLACE_ALL_VERTEX_GROUPS", 1, "All", "Transfer all vertex groups from selected to active mesh."}, {0, NULL, 0, NULL, NULL} }; @@ -3042,12 +3042,12 @@ static int vertex_group_transfer_weight_exec(bContext *C, wmOperator *op) CTX_DATA_BEGIN(C, Object *, ob_slc, selected_editable_objects) { - if (ob_act != ob_slc) { + if (ob_act != ob_slc && ob_slc->defbase.first) { switch (vertex_group_option) { case REPLACE_SINGLE_VERTEX_GROUP: - if (ED_vgroup_transfer_weight(ob_act, ob_slc, BLI_findlink(&ob_slc->defbase, ob_slc->actdef - 1), scene, method_option, replace_option)) - change++; + if (ED_vgroup_transfer_weight(ob_act, ob_slc, + BLI_findlink(&ob_slc->defbase, ob_slc->actdef - 1), scene, method_option, replace_option)) change++; else fail++; break; @@ -3059,6 +3059,7 @@ static int vertex_group_transfer_weight_exec(bContext *C, wmOperator *op) break; } } + else change++; } /* Event notifiers for correct display of data */ @@ -3081,9 +3082,9 @@ static int vertex_group_transfer_weight_exec(bContext *C, wmOperator *op) void OBJECT_OT_vertex_group_transfer_weight(wmOperatorType *ot) { /* identifiers */ - ot->name = "Transfer weight to selected"; + ot->name = "Transfer weight"; ot->idname = "OBJECT_OT_vertex_group_transfer_weight"; - ot->description = "Transfers weight from active to selected depending on options"; + ot->description = "Transfer weight paint to active from selected mesh"; /* api callbacks */ ot->poll = vertex_group_poll; -- cgit v1.2.3 From 2548494bc19d1ade390050ef5af68c04047bb6e8 Mon Sep 17 00:00:00 2001 From: Ove Murberg Henriksen Date: Tue, 5 Jun 2012 21:10:15 +0000 Subject: Removed confusing error reporting code. The confusing part was inconsitent reporting. It reported un eaven indices when only one source and a fail, but not when several sources and some success and some fail. --- source/blender/editors/object/object_vgroup.c | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/source/blender/editors/object/object_vgroup.c b/source/blender/editors/object/object_vgroup.c index 32433caee5a..af5d61cac9d 100644 --- a/source/blender/editors/object/object_vgroup.c +++ b/source/blender/editors/object/object_vgroup.c @@ -3030,8 +3030,6 @@ static int vertex_group_transfer_weight_exec(bContext *C, wmOperator *op) { Scene *scene = CTX_data_scene(C); Object *ob_act = CTX_data_active_object(C); - int change = 0; - int fail = 0; bDeformGroup *dg_src; VertexGroupOption vertex_group_option = RNA_enum_get(op->ptr, "VertexGroupOption"); @@ -3046,20 +3044,16 @@ static int vertex_group_transfer_weight_exec(bContext *C, wmOperator *op) switch (vertex_group_option) { case REPLACE_SINGLE_VERTEX_GROUP: - if (ED_vgroup_transfer_weight(ob_act, ob_slc, - BLI_findlink(&ob_slc->defbase, ob_slc->actdef - 1), scene, method_option, replace_option)) change++; - else fail++; + ED_vgroup_transfer_weight(ob_act, ob_slc, BLI_findlink(&ob_slc->defbase, ob_slc->actdef - 1), scene, method_option, replace_option); break; case REPLACE_ALL_VERTEX_GROUPS: for (dg_src = ob_slc->defbase.first; dg_src; dg_src = dg_src->next) { - if (ED_vgroup_transfer_weight(ob_act, ob_slc, dg_src, scene, method_option, replace_option)) change++; - else fail++; + ED_vgroup_transfer_weight(ob_act, ob_slc, dg_src, scene, method_option, replace_option); } break; } } - else change++; } /* Event notifiers for correct display of data */ @@ -3069,12 +3063,6 @@ static int vertex_group_transfer_weight_exec(bContext *C, wmOperator *op) CTX_DATA_END; - /* Report error when task can not be completed with available functions. */ - if ((change == 0 && fail == 0) || fail) { - BKE_reportf(op->reports, RPT_ERROR, - "Copy to VGroups to Selected warning done %d, failed %d, object data must have matching indices", - change, fail); - } return OPERATOR_FINISHED; } -- cgit v1.2.3 From 5414ea4701c2e90cbef59bc8eef1f7a028a6738a Mon Sep 17 00:00:00 2001 From: Ove Murberg Henriksen Date: Wed, 6 Jun 2012 23:21:45 +0000 Subject: Fixed naming from "single vertex group" to "active vertex group" --- source/blender/editors/object/object_vgroup.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/source/blender/editors/object/object_vgroup.c b/source/blender/editors/object/object_vgroup.c index af5d61cac9d..f93867f4695 100644 --- a/source/blender/editors/object/object_vgroup.c +++ b/source/blender/editors/object/object_vgroup.c @@ -378,7 +378,7 @@ int ED_vgroup_copy_array(Object *ob, Object *ob_from) /***********************Start transfer weight*********************************/ typedef enum VertexGroupOption { - REPLACE_SINGLE_VERTEX_GROUP = 1, + REPLACE_ACTIVE_VERTEX_GROUP = 1, REPLACE_ALL_VERTEX_GROUPS = 2 } VertexGroupOption; @@ -396,7 +396,7 @@ typedef enum ReplaceOption { } ReplaceOption; static EnumPropertyItem vertex_group_option_item[] = { - {REPLACE_SINGLE_VERTEX_GROUP, "REPLACE_SINGLE_VERTEX_GROUP", 1, "Single", "Transfer single vertex group from selected to active mesh."}, + {REPLACE_ACTIVE_VERTEX_GROUP, "REPLACE_ACTIVE_VERTEX_GROUP", 1, "Active", "Transfer active vertex group from selected to active mesh."}, {REPLACE_ALL_VERTEX_GROUPS, "REPLACE_ALL_VERTEX_GROUPS", 1, "All", "Transfer all vertex groups from selected to active mesh."}, {0, NULL, 0, NULL, NULL} }; @@ -3043,7 +3043,7 @@ static int vertex_group_transfer_weight_exec(bContext *C, wmOperator *op) if (ob_act != ob_slc && ob_slc->defbase.first) { switch (vertex_group_option) { - case REPLACE_SINGLE_VERTEX_GROUP: + case REPLACE_ACTIVE_VERTEX_GROUP: ED_vgroup_transfer_weight(ob_act, ob_slc, BLI_findlink(&ob_slc->defbase, ob_slc->actdef - 1), scene, method_option, replace_option); break; -- cgit v1.2.3 From 340e156a2f8fd58e1ad4cba4464d347a2a5aeb6e Mon Sep 17 00:00:00 2001 From: Ove Murberg Henriksen Date: Mon, 11 Jun 2012 19:31:22 +0000 Subject: Bugfix: No longer crashes when there is no dverts on target mesh from before. --- source/blender/editors/object/object_vgroup.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/source/blender/editors/object/object_vgroup.c b/source/blender/editors/object/object_vgroup.c index f93867f4695..7f5c8d14f49 100644 --- a/source/blender/editors/object/object_vgroup.c +++ b/source/blender/editors/object/object_vgroup.c @@ -459,8 +459,11 @@ int ED_vgroup_transfer_weight(Object *ob_dst, Object *ob_src, bDeformGroup *dg_s dg_dst = defgroup_find_name(ob_dst, dg_src->name); /* get meshes */ - me_dst = ob_dst->data; dmesh_src = mesh_get_derived_deform(scene, ob_src, CD_MASK_BAREMESH | CD_MASK_ORIGINDEX); + me_dst = ob_dst->data; + + /* create data in memory when nothing there */ + if (!me_dst->dvert) ED_vgroup_data_create(ob_dst->data); /* get vertex group arrays */ ED_vgroup_give_parray(ob_src->data, &dv_array_src, &dv_tot_src, FALSE); -- cgit v1.2.3 From 995b9d5e8de4a69f96c5017a6ee859ab89785939 Mon Sep 17 00:00:00 2001 From: Ove Murberg Henriksen Date: Mon, 11 Jun 2012 20:32:34 +0000 Subject: style cleanup fixed naming --- source/blender/editors/object/object_vgroup.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/source/blender/editors/object/object_vgroup.c b/source/blender/editors/object/object_vgroup.c index 7f5c8d14f49..7873fa16ea3 100644 --- a/source/blender/editors/object/object_vgroup.c +++ b/source/blender/editors/object/object_vgroup.c @@ -3035,9 +3035,9 @@ static int vertex_group_transfer_weight_exec(bContext *C, wmOperator *op) Object *ob_act = CTX_data_active_object(C); bDeformGroup *dg_src; - VertexGroupOption vertex_group_option = RNA_enum_get(op->ptr, "VertexGroupOption"); - MethodOption method_option = RNA_enum_get(op->ptr, "MethodOption"); - ReplaceOption replace_option = RNA_enum_get(op->ptr, "ReplaceOption"); + VertexGroupOption vertex_group_option = RNA_enum_get(op->ptr, "vertex_group_option"); + MethodOption method_option = RNA_enum_get(op->ptr, "method_option"); + ReplaceOption replace_option = RNA_enum_get(op->ptr, "replace_option"); /* Macro to loop through selected objects and perform operation depending on function, option and method */ CTX_DATA_BEGIN(C, Object *, ob_slc, selected_editable_objects) @@ -3085,9 +3085,9 @@ void OBJECT_OT_vertex_group_transfer_weight(wmOperatorType *ot) ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; /* properties */ - ot->prop = RNA_def_enum(ot->srna, "VertexGroupOption", vertex_group_option_item, 1, "Group", ""); - ot->prop = RNA_def_enum(ot->srna, "MethodOption", method_option_item, 3, "Method", ""); - ot->prop = RNA_def_enum(ot->srna, "ReplaceOption", replace_option_item, 1, "Replace", ""); + ot->prop = RNA_def_enum(ot->srna, "vertex_group_option", vertex_group_option_item, 1, "Group", ""); + ot->prop = RNA_def_enum(ot->srna, "method_option", method_option_item, 3, "Method", ""); + ot->prop = RNA_def_enum(ot->srna, "replace_option", replace_option_item, 1, "Replace", ""); } static EnumPropertyItem vgroup_items[] = { -- cgit v1.2.3 From 9d32423f3e695f8bdd5a0d1b032b5e822613977a Mon Sep 17 00:00:00 2001 From: Ove Murberg Henriksen Date: Mon, 11 Jun 2012 22:58:49 +0000 Subject: Bugfix: no longer crashes when dverts does not exist on source. Added release for derivedmesh. --- source/blender/editors/object/object_vgroup.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/source/blender/editors/object/object_vgroup.c b/source/blender/editors/object/object_vgroup.c index 7873fa16ea3..5a2a9a06e39 100644 --- a/source/blender/editors/object/object_vgroup.c +++ b/source/blender/editors/object/object_vgroup.c @@ -438,7 +438,7 @@ void vgroup_transfer_weight(MVert *mv_dst, float *weight_dst, float weight_src, int ED_vgroup_transfer_weight(Object *ob_dst, Object *ob_src, bDeformGroup *dg_src, Scene *scene, MethodOption method_option, ReplaceOption replace_option) { bDeformGroup *dg_dst; - Mesh *me_dst; + Mesh *me_dst, *me_src; DerivedMesh *dmesh_src; BVHTreeFromMesh tree_mesh_vertices_src, tree_mesh_faces_src = {NULL}; MDeformVert **dv_array_src, **dv_array_dst, **dv_src, **dv_dst; @@ -461,6 +461,10 @@ int ED_vgroup_transfer_weight(Object *ob_dst, Object *ob_src, bDeformGroup *dg_s /* get meshes */ dmesh_src = mesh_get_derived_deform(scene, ob_src, CD_MASK_BAREMESH | CD_MASK_ORIGINDEX); me_dst = ob_dst->data; + me_src = ob_src->data; + + /* sanity check */ + if (!me_src->dvert) return 0; /* create data in memory when nothing there */ if (!me_dst->dvert) ED_vgroup_data_create(ob_dst->data); @@ -491,6 +495,7 @@ int ED_vgroup_transfer_weight(Object *ob_dst, Object *ob_src, bDeformGroup *dg_s ED_vgroup_delete(ob_dst, defgroup_find_name(ob_dst, dg_dst->name)); if (dv_array_src) MEM_freeN(dv_array_src); if (dv_array_dst) MEM_freeN(dv_array_dst); + dmesh_src->release(dmesh_src); return 0; } @@ -641,6 +646,7 @@ int ED_vgroup_transfer_weight(Object *ob_dst, Object *ob_src, bDeformGroup *dg_s /*free memory*/ if (dv_array_src) MEM_freeN(dv_array_src); if (dv_array_dst) MEM_freeN(dv_array_dst); + dmesh_src->release(dmesh_src); return 1; } -- cgit v1.2.3 From 108d157254f4e00aee11002020b899279d28d1f9 Mon Sep 17 00:00:00 2001 From: Ove Murberg Henriksen Date: Mon, 18 Jun 2012 17:11:53 +0000 Subject: Changed naming of "option" to "mode". No longer using defvert_verify_index() but defvert_find_index(). Changing function created error wehn not found. Must be adressed. --- source/blender/editors/object/object_vgroup.c | 125 +++++++++++++++----------- 1 file changed, 74 insertions(+), 51 deletions(-) diff --git a/source/blender/editors/object/object_vgroup.c b/source/blender/editors/object/object_vgroup.c index f56f9f657bc..188e1c2efca 100644 --- a/source/blender/editors/object/object_vgroup.c +++ b/source/blender/editors/object/object_vgroup.c @@ -377,31 +377,31 @@ int ED_vgroup_copy_array(Object *ob, Object *ob_from) /***********************Start transfer weight*********************************/ -typedef enum VertexGroupOption { +typedef enum VertexGroupMode { REPLACE_ACTIVE_VERTEX_GROUP = 1, REPLACE_ALL_VERTEX_GROUPS = 2 -} VertexGroupOption; +} VertexGroupMode; -typedef enum MethodOption { +typedef enum MethodMode { BY_INDEX = 1, BY_NEAREST_VERTEX = 2, BY_NEAREST_FACE = 3, BY_NEAREST_VERTEX_IN_FACE = 4 -} MethodOption; +} MethodMode; -typedef enum ReplaceOption { +typedef enum ReplaceMode { REPLACE_ALL_WEIGHTS = 1, REPLACE_EMPTY_WEIGHTS = 2, REPLACE_SELECTED_WEIGHTS = 3 -} ReplaceOption; +} ReplaceMode; -static EnumPropertyItem vertex_group_option_item[] = { +static EnumPropertyItem vertex_group_mode_item[] = { {REPLACE_ACTIVE_VERTEX_GROUP, "REPLACE_ACTIVE_VERTEX_GROUP", 1, "Active", "Transfer active vertex group from selected to active mesh."}, {REPLACE_ALL_VERTEX_GROUPS, "REPLACE_ALL_VERTEX_GROUPS", 1, "All", "Transfer all vertex groups from selected to active mesh."}, {0, NULL, 0, NULL, NULL} }; -static EnumPropertyItem method_option_item[] = { +static EnumPropertyItem method_mode_item[] = { {BY_INDEX, "BY_INDEX", 1, "Vertex index", "Copy for identical meshes."}, {BY_NEAREST_VERTEX, "BY_NEAREST_VERTEX", 1, "Nearest vertex", "Copy weight from closest vertex."}, {BY_NEAREST_FACE, "BY_NEAREST_FACE", 1, "Nearest face", "Barycentric interpolation from nearest face."}, @@ -409,7 +409,7 @@ static EnumPropertyItem method_option_item[] = { {0, NULL, 0, NULL, NULL} }; -static EnumPropertyItem replace_option_item[] = { +static EnumPropertyItem replace_mode_item[] = { {REPLACE_ALL_WEIGHTS, "REPLACE_ALL_WEIGHTS", 1, "All", "Overwrites all weights."}, {REPLACE_EMPTY_WEIGHTS, "REPLACE_EMPTY_WEIGHTS", 1, "Empty", "Adds weights to vertices with no weight."}, {REPLACE_SELECTED_WEIGHTS, "REPLACE_SELECTED_WEIGHTS", 1, "Selected", "Replace selected weights."}, @@ -417,9 +417,9 @@ static EnumPropertyItem replace_option_item[] = { }; /*copy weight*/ -void vgroup_transfer_weight(MVert *mv_dst, float *weight_dst, float weight_src, ReplaceOption replace_option) +void vgroup_transfer_weight(MVert *mv_dst, float *weight_dst, float weight_src, ReplaceMode replace_mode) { - switch (replace_option) { + switch (replace_mode) { case REPLACE_ALL_WEIGHTS: *weight_dst = weight_src; @@ -435,7 +435,8 @@ void vgroup_transfer_weight(MVert *mv_dst, float *weight_dst, float weight_src, } } -int ED_vgroup_transfer_weight(Object *ob_dst, Object *ob_src, bDeformGroup *dg_src, Scene *scene, MethodOption method_option, ReplaceOption replace_option) +int ED_vgroup_transfer_weight(Object *ob_dst, Object *ob_src, bDeformGroup *dg_src, Scene *scene, + MethodMode method_mode, ReplaceMode replace_mode) { bDeformGroup *dg_dst; Mesh *me_dst, *me_src; @@ -450,7 +451,7 @@ int ED_vgroup_transfer_weight(Object *ob_dst, Object *ob_src, bDeformGroup *dg_s float weight, tmp_weight[4], tmp_co[3], normal[3], tmp_mat[4][4], dist_v1, dist_v2, dist_v3, dist_v4; /* create new and overwrite vertex group on destination without data */ - if (!defgroup_find_name(ob_dst, dg_src->name) || replace_option == REPLACE_ALL_WEIGHTS) { + if (!defgroup_find_name(ob_dst, dg_src->name) || replace_mode == REPLACE_ALL_WEIGHTS) { ED_vgroup_delete(ob_dst, defgroup_find_name(ob_dst, dg_src->name)); ED_vgroup_add_name(ob_dst, dg_src->name); } @@ -464,7 +465,10 @@ int ED_vgroup_transfer_weight(Object *ob_dst, Object *ob_src, bDeformGroup *dg_s me_src = ob_src->data; /* sanity check */ - if (!me_src->dvert) return 0; + if (!me_src->dvert) { + /*todo fix!*/ + return 0; + } /* create data in memory when nothing there */ if (!me_dst->dvert) ED_vgroup_data_create(ob_dst->data); @@ -485,7 +489,7 @@ int ED_vgroup_transfer_weight(Object *ob_dst, Object *ob_src, bDeformGroup *dg_s invert_m4_m4(ob_src->imat, ob_src->obmat); mult_m4_m4m4(tmp_mat, ob_src->imat, ob_dst->obmat); - switch (method_option) { + switch (method_mode) { case BY_INDEX: /* check if indices are matching, delete and return if not */ @@ -496,6 +500,7 @@ int ED_vgroup_transfer_weight(Object *ob_dst, Object *ob_src, bDeformGroup *dg_s if (dv_array_src) MEM_freeN(dv_array_src); if (dv_array_dst) MEM_freeN(dv_array_dst); dmesh_src->release(dmesh_src); + /*todo: fix*/ return 0; } @@ -503,9 +508,9 @@ int ED_vgroup_transfer_weight(Object *ob_dst, Object *ob_src, bDeformGroup *dg_s for(i = 0, dv_src = dv_array_src, dv_dst = dv_array_dst; i < me_dst->totvert; i++, dv_dst++, dv_src++, mv_src++) { /* copy weight */ - dw_src = defvert_verify_index(*dv_src, index_src); - dw_dst = defvert_verify_index(*dv_dst, index_dst); - vgroup_transfer_weight(mv_dst, &dw_dst->weight, dw_src->weight, replace_option); + dw_src = defvert_find_index(*dv_src, index_src); + dw_dst = defvert_find_index(*dv_dst, index_dst); + vgroup_transfer_weight(mv_dst, &dw_dst->weight, dw_src->weight, replace_mode); } break; @@ -526,12 +531,18 @@ int ED_vgroup_transfer_weight(Object *ob_dst, Object *ob_src, bDeformGroup *dg_s /* node tree accelerated search for closest vetex */ BLI_bvhtree_find_nearest(tree_mesh_vertices_src.tree, tmp_co, - &nearest, tree_mesh_vertices_src.nearest_callback, &tree_mesh_vertices_src); + &nearest, tree_mesh_vertices_src.nearest_callback, &tree_mesh_vertices_src); /* copy weight */ - dw_src = defvert_verify_index(dv_array_src[nearest.index], index_src); - dw_dst = defvert_verify_index(*dv_dst, index_dst); - vgroup_transfer_weight(mv_dst, &dw_dst->weight, dw_src->weight, replace_option); + /* + ideasman42 2012/06/17 21:32:15 + this is very bad - this function will add a vertex weight if not found, thereby modifying the source which should never happen. +use defvert_find_index() instead. You will need to do something sane when the vgroup is not found - +it should not add any vgroups or act as if all vgroups are 0 weight. + */ + dw_src = defvert_find_index(dv_array_src[nearest.index], index_src); + dw_dst = defvert_find_index(*dv_dst, index_dst); + vgroup_transfer_weight(mv_dst, &dw_dst->weight, dw_src->weight, replace_mode); } /* free memory */ @@ -559,33 +570,45 @@ int ED_vgroup_transfer_weight(Object *ob_dst, Object *ob_src, bDeformGroup *dg_s /* 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); + &nearest, tree_mesh_faces_src.nearest_callback, &tree_mesh_faces_src); index_nearest = nearest.index; /* project onto face */ - normal_tri_v3(normal, mv_src[mface_src[nearest.index].v1].co, - mv_src[mface_src[index_nearest].v2].co, - mv_src[mface_src[index_nearest].v3].co); + normal_tri_v3(normal, + mv_src[mface_src[nearest.index].v1].co, + mv_src[mface_src[index_nearest].v2].co, + mv_src[mface_src[index_nearest].v3].co); project_v3_plane(tmp_co, normal, mv_src[mface_src[index_nearest].v1].co); /* interpolate weights */ - interp_weights_face_v3(tmp_weight, mv_src[mface_src[index_nearest].v1].co, - mv_src[mface_src[index_nearest].v2].co, - mv_src[mface_src[index_nearest].v3].co, - mv_src[mface_src[index_nearest].v4].co, tmp_co); + if (mface_src[index_nearest].v4) { + interp_weights_face_v3(tmp_weight, + mv_src[mface_src[index_nearest].v1].co, + mv_src[mface_src[index_nearest].v2].co, + mv_src[mface_src[index_nearest].v3].co, + mv_src[mface_src[index_nearest].v4].co, tmp_co); + } + else { + interp_weights_face_v3(tmp_weight, + mv_src[mface_src[index_nearest].v1].co, + mv_src[mface_src[index_nearest].v2].co, + mv_src[mface_src[index_nearest].v3].co, NULL, tmp_co); + } /* get weights */ - weight = tmp_weight[0] * defvert_verify_index(dv_array_src[mface_src[index_nearest].v1], index_src)->weight; - weight += tmp_weight[1] * defvert_verify_index(dv_array_src[mface_src[index_nearest].v2], index_src)->weight; - weight += tmp_weight[2] * defvert_verify_index(dv_array_src[mface_src[index_nearest].v3], index_src)->weight; + /* ideasman42 2012/06/17 21:32:15*/ + /* you can loop over 3-4 items here, ratrher then inline all 4 calls. paint_vertex.c has examples of this. */ + weight = tmp_weight[0] * defvert_find_index(dv_array_src[mface_src[index_nearest].v1], index_src)->weight; + weight += tmp_weight[1] * defvert_find_index(dv_array_src[mface_src[index_nearest].v2], index_src)->weight; + weight += tmp_weight[2] * defvert_find_index(dv_array_src[mface_src[index_nearest].v3], index_src)->weight; if (mface_src[index_nearest].v4 || mface_src[index_nearest].v4 == 0) { - weight += tmp_weight[3] * defvert_verify_index(dv_array_src[mface_src[index_nearest].v4], index_src)->weight; + weight += tmp_weight[3] * defvert_find_index(dv_array_src[mface_src[index_nearest].v4], index_src)->weight; } /* copy weight */ - dw_dst = defvert_verify_index(*dv_dst, index_dst); - vgroup_transfer_weight(mv_dst, &dw_dst->weight, weight, replace_option); + dw_dst = defvert_find_index(*dv_dst, index_dst); + vgroup_transfer_weight(mv_dst, &dw_dst->weight, weight, replace_mode); } /* free memory */ @@ -613,7 +636,7 @@ int ED_vgroup_transfer_weight(Object *ob_dst, Object *ob_src, bDeformGroup *dg_s /* 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); + &nearest, tree_mesh_faces_src.nearest_callback, &tree_mesh_faces_src); index_nearest = nearest.index; /* get distances */ @@ -633,9 +656,9 @@ int ED_vgroup_transfer_weight(Object *ob_dst, Object *ob_src, bDeformGroup *dg_s } /* copy weight */ - dw_src = defvert_verify_index(dv_array_src[index_nearest_vertex], index_src); - dw_dst = defvert_verify_index(*dv_dst, index_dst); - vgroup_transfer_weight(mv_dst, &dw_dst->weight, dw_src->weight, replace_option); + dw_src = defvert_find_index(dv_array_src[index_nearest_vertex], index_src); + dw_dst = defvert_find_index(*dv_dst, index_dst); + vgroup_transfer_weight(mv_dst, &dw_dst->weight, dw_src->weight, replace_mode); } /* free memory */ @@ -3001,7 +3024,7 @@ static int vertex_group_copy_to_selected_exec(bContext *C, wmOperator *op) int change = 0; int fail = 0; - CTX_DATA_BEGIN(C, Object *, ob, selected_editable_objects) + CTX_DATA_BEGIN (C, Object *, ob, selected_editable_objects) { if (obact != ob) { if (ED_vgroup_copy_array(ob, obact)) change++; @@ -3040,24 +3063,24 @@ static int vertex_group_transfer_weight_exec(bContext *C, wmOperator *op) Object *ob_act = CTX_data_active_object(C); bDeformGroup *dg_src; - VertexGroupOption vertex_group_option = RNA_enum_get(op->ptr, "vertex_group_option"); - MethodOption method_option = RNA_enum_get(op->ptr, "method_option"); - ReplaceOption replace_option = RNA_enum_get(op->ptr, "replace_option"); + VertexGroupMode vertex_group_mode = RNA_enum_get(op->ptr, "vertex_group_mode"); + MethodMode method_mode = RNA_enum_get(op->ptr, "method_mode"); + ReplaceMode replace_mode = RNA_enum_get(op->ptr, "replace_mode"); /* Macro to loop through selected objects and perform operation depending on function, option and method */ - CTX_DATA_BEGIN(C, Object *, ob_slc, selected_editable_objects) + CTX_DATA_BEGIN (C, Object *, ob_slc, selected_editable_objects) { if (ob_act != ob_slc && ob_slc->defbase.first) { - switch (vertex_group_option) { + switch (vertex_group_mode) { case REPLACE_ACTIVE_VERTEX_GROUP: - ED_vgroup_transfer_weight(ob_act, ob_slc, BLI_findlink(&ob_slc->defbase, ob_slc->actdef - 1), scene, method_option, replace_option); + ED_vgroup_transfer_weight(ob_act, ob_slc, BLI_findlink(&ob_slc->defbase, ob_slc->actdef - 1), scene, method_mode, replace_mode); break; case REPLACE_ALL_VERTEX_GROUPS: for (dg_src = ob_slc->defbase.first; dg_src; dg_src = dg_src->next) { - ED_vgroup_transfer_weight(ob_act, ob_slc, dg_src, scene, method_option, replace_option); + ED_vgroup_transfer_weight(ob_act, ob_slc, dg_src, scene, method_mode, replace_mode); } break; } @@ -3090,9 +3113,9 @@ void OBJECT_OT_vertex_group_transfer_weight(wmOperatorType *ot) ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; /* properties */ - ot->prop = RNA_def_enum(ot->srna, "vertex_group_option", vertex_group_option_item, 1, "Group", ""); - ot->prop = RNA_def_enum(ot->srna, "method_option", method_option_item, 3, "Method", ""); - ot->prop = RNA_def_enum(ot->srna, "replace_option", replace_option_item, 1, "Replace", ""); + ot->prop = RNA_def_enum(ot->srna, "vertex_group_mode", vertex_group_mode_item, 1, "Group", ""); + ot->prop = RNA_def_enum(ot->srna, "method_mode", method_mode_item, 3, "Method", ""); + ot->prop = RNA_def_enum(ot->srna, "replace_mode", replace_mode_item, 1, "Replace", ""); } static EnumPropertyItem vgroup_items[] = { -- cgit v1.2.3 From 3253716183383781904684629b1edc1f6d2cf4ea Mon Sep 17 00:00:00 2001 From: Ove Murberg Henriksen Date: Mon, 18 Jun 2012 19:32:45 +0000 Subject: Bugfix: no longer crashes when MDefomWeight is not fond on source. --- source/blender/editors/object/object_vgroup.c | 30 ++++++++++++++------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/source/blender/editors/object/object_vgroup.c b/source/blender/editors/object/object_vgroup.c index 188e1c2efca..47c0b26218c 100644 --- a/source/blender/editors/object/object_vgroup.c +++ b/source/blender/editors/object/object_vgroup.c @@ -509,8 +509,10 @@ int ED_vgroup_transfer_weight(Object *ob_dst, Object *ob_src, bDeformGroup *dg_s /* copy weight */ dw_src = defvert_find_index(*dv_src, index_src); - dw_dst = defvert_find_index(*dv_dst, index_dst); - vgroup_transfer_weight(mv_dst, &dw_dst->weight, dw_src->weight, replace_mode); + if(dw_src && dw_src->weight) { + dw_dst = defvert_verify_index(*dv_dst, index_dst); + vgroup_transfer_weight(mv_dst, &dw_dst->weight, dw_src->weight, replace_mode); + } } break; @@ -534,15 +536,11 @@ int ED_vgroup_transfer_weight(Object *ob_dst, Object *ob_src, bDeformGroup *dg_s &nearest, tree_mesh_vertices_src.nearest_callback, &tree_mesh_vertices_src); /* copy weight */ - /* - ideasman42 2012/06/17 21:32:15 - this is very bad - this function will add a vertex weight if not found, thereby modifying the source which should never happen. -use defvert_find_index() instead. You will need to do something sane when the vgroup is not found - -it should not add any vgroups or act as if all vgroups are 0 weight. - */ dw_src = defvert_find_index(dv_array_src[nearest.index], index_src); - dw_dst = defvert_find_index(*dv_dst, index_dst); - vgroup_transfer_weight(mv_dst, &dw_dst->weight, dw_src->weight, replace_mode); + if(dw_src && dw_src->weight) { + dw_dst = defvert_verify_index(*dv_dst, index_dst); + vgroup_transfer_weight(mv_dst, &dw_dst->weight, dw_src->weight, replace_mode); + } } /* free memory */ @@ -607,8 +605,10 @@ it should not add any vgroups or act as if all vgroups are 0 weight. } /* copy weight */ - dw_dst = defvert_find_index(*dv_dst, index_dst); - vgroup_transfer_weight(mv_dst, &dw_dst->weight, weight, replace_mode); + if(weight > 0) { + dw_dst = defvert_verify_index(*dv_dst, index_dst); + vgroup_transfer_weight(mv_dst, &dw_dst->weight, weight, replace_mode); + } } /* free memory */ @@ -657,8 +657,10 @@ it should not add any vgroups or act as if all vgroups are 0 weight. /* copy weight */ dw_src = defvert_find_index(dv_array_src[index_nearest_vertex], index_src); - dw_dst = defvert_find_index(*dv_dst, index_dst); - vgroup_transfer_weight(mv_dst, &dw_dst->weight, dw_src->weight, replace_mode); + if(dw_src && dw_src->weight) { + dw_dst = defvert_verify_index(*dv_dst, index_dst); + vgroup_transfer_weight(mv_dst, &dw_dst->weight, dw_src->weight, replace_mode); + } } /* free memory */ -- cgit v1.2.3 From 56ebb0b4a825af75ea6db03f1dc55c8933b0cc50 Mon Sep 17 00:00:00 2001 From: Ove Murberg Henriksen Date: Mon, 18 Jun 2012 19:59:15 +0000 Subject: style cleanup fixed indents (I belive!?!) --- source/blender/editors/object/object_vgroup.c | 54 +++++++++++++-------------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/source/blender/editors/object/object_vgroup.c b/source/blender/editors/object/object_vgroup.c index 47c0b26218c..a9ff41b8046 100644 --- a/source/blender/editors/object/object_vgroup.c +++ b/source/blender/editors/object/object_vgroup.c @@ -396,24 +396,24 @@ typedef enum ReplaceMode { } ReplaceMode; static EnumPropertyItem vertex_group_mode_item[] = { - {REPLACE_ACTIVE_VERTEX_GROUP, "REPLACE_ACTIVE_VERTEX_GROUP", 1, "Active", "Transfer active vertex group from selected to active mesh."}, - {REPLACE_ALL_VERTEX_GROUPS, "REPLACE_ALL_VERTEX_GROUPS", 1, "All", "Transfer all vertex groups from selected to active mesh."}, - {0, NULL, 0, NULL, NULL} + {REPLACE_ACTIVE_VERTEX_GROUP, "REPLACE_ACTIVE_VERTEX_GROUP", 1, "Active", "Transfer active vertex group from selected to active mesh."}, + {REPLACE_ALL_VERTEX_GROUPS, "REPLACE_ALL_VERTEX_GROUPS", 1, "All", "Transfer all vertex groups from selected to active mesh."}, + {0, NULL, 0, NULL, NULL} }; static EnumPropertyItem method_mode_item[] = { - {BY_INDEX, "BY_INDEX", 1, "Vertex index", "Copy for identical meshes."}, - {BY_NEAREST_VERTEX, "BY_NEAREST_VERTEX", 1, "Nearest vertex", "Copy weight from closest vertex."}, - {BY_NEAREST_FACE, "BY_NEAREST_FACE", 1, "Nearest face", "Barycentric interpolation from nearest face."}, - {BY_NEAREST_VERTEX_IN_FACE, "BY_NEAREST_VERTEX_IN_FACE", 1, "Nearest vertex in face", "Copy weight from closest vertex in nearest face."}, - {0, NULL, 0, NULL, NULL} + {BY_INDEX, "BY_INDEX", 1, "Vertex index", "Copy for identical meshes."}, + {BY_NEAREST_VERTEX, "BY_NEAREST_VERTEX", 1, "Nearest vertex", "Copy weight from closest vertex."}, + {BY_NEAREST_FACE, "BY_NEAREST_FACE", 1, "Nearest face", "Barycentric interpolation from nearest face."}, + {BY_NEAREST_VERTEX_IN_FACE, "BY_NEAREST_VERTEX_IN_FACE", 1, "Nearest vertex in face", "Copy weight from closest vertex in nearest face."}, + {0, NULL, 0, NULL, NULL} }; static EnumPropertyItem replace_mode_item[] = { - {REPLACE_ALL_WEIGHTS, "REPLACE_ALL_WEIGHTS", 1, "All", "Overwrites all weights."}, - {REPLACE_EMPTY_WEIGHTS, "REPLACE_EMPTY_WEIGHTS", 1, "Empty", "Adds weights to vertices with no weight."}, - {REPLACE_SELECTED_WEIGHTS, "REPLACE_SELECTED_WEIGHTS", 1, "Selected", "Replace selected weights."}, - {0, NULL, 0, NULL, NULL} + {REPLACE_ALL_WEIGHTS, "REPLACE_ALL_WEIGHTS", 1, "All", "Overwrites all weights."}, + {REPLACE_EMPTY_WEIGHTS, "REPLACE_EMPTY_WEIGHTS", 1, "Empty", "Adds weights to vertices with no weight."}, + {REPLACE_SELECTED_WEIGHTS, "REPLACE_SELECTED_WEIGHTS", 1, "Selected", "Replace selected weights."}, + {0, NULL, 0, NULL, NULL} }; /*copy weight*/ @@ -436,7 +436,7 @@ void vgroup_transfer_weight(MVert *mv_dst, float *weight_dst, float weight_src, } int ED_vgroup_transfer_weight(Object *ob_dst, Object *ob_src, bDeformGroup *dg_src, Scene *scene, - MethodMode method_mode, ReplaceMode replace_mode) + MethodMode method_mode, ReplaceMode replace_mode) { bDeformGroup *dg_dst; Mesh *me_dst, *me_src; @@ -533,7 +533,7 @@ int ED_vgroup_transfer_weight(Object *ob_dst, Object *ob_src, bDeformGroup *dg_s /* node tree accelerated search for closest vetex */ BLI_bvhtree_find_nearest(tree_mesh_vertices_src.tree, tmp_co, - &nearest, tree_mesh_vertices_src.nearest_callback, &tree_mesh_vertices_src); + &nearest, tree_mesh_vertices_src.nearest_callback, &tree_mesh_vertices_src); /* copy weight */ dw_src = defvert_find_index(dv_array_src[nearest.index], index_src); @@ -568,30 +568,30 @@ int ED_vgroup_transfer_weight(Object *ob_dst, Object *ob_src, bDeformGroup *dg_s /* 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); + &nearest, tree_mesh_faces_src.nearest_callback, &tree_mesh_faces_src); index_nearest = nearest.index; /* project onto face */ normal_tri_v3(normal, - mv_src[mface_src[nearest.index].v1].co, - mv_src[mface_src[index_nearest].v2].co, - mv_src[mface_src[index_nearest].v3].co); + mv_src[mface_src[nearest.index].v1].co, + mv_src[mface_src[index_nearest].v2].co, + mv_src[mface_src[index_nearest].v3].co); project_v3_plane(tmp_co, normal, mv_src[mface_src[index_nearest].v1].co); /* interpolate weights */ if (mface_src[index_nearest].v4) { interp_weights_face_v3(tmp_weight, - mv_src[mface_src[index_nearest].v1].co, - mv_src[mface_src[index_nearest].v2].co, - mv_src[mface_src[index_nearest].v3].co, - mv_src[mface_src[index_nearest].v4].co, tmp_co); + mv_src[mface_src[index_nearest].v1].co, + mv_src[mface_src[index_nearest].v2].co, + mv_src[mface_src[index_nearest].v3].co, + mv_src[mface_src[index_nearest].v4].co, tmp_co); } else { interp_weights_face_v3(tmp_weight, - mv_src[mface_src[index_nearest].v1].co, - mv_src[mface_src[index_nearest].v2].co, - mv_src[mface_src[index_nearest].v3].co, NULL, tmp_co); + mv_src[mface_src[index_nearest].v1].co, + mv_src[mface_src[index_nearest].v2].co, + mv_src[mface_src[index_nearest].v3].co, NULL, tmp_co); } /* get weights */ @@ -605,7 +605,7 @@ int ED_vgroup_transfer_weight(Object *ob_dst, Object *ob_src, bDeformGroup *dg_s } /* copy weight */ - if(weight > 0) { + if(weight > 0) {/*todo: handle NULL source properly*/ dw_dst = defvert_verify_index(*dv_dst, index_dst); vgroup_transfer_weight(mv_dst, &dw_dst->weight, weight, replace_mode); } @@ -636,7 +636,7 @@ int ED_vgroup_transfer_weight(Object *ob_dst, Object *ob_src, bDeformGroup *dg_s /* 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); + &nearest, tree_mesh_faces_src.nearest_callback, &tree_mesh_faces_src); index_nearest = nearest.index; /* get distances */ -- cgit v1.2.3 From fcb650a1545e7ad4ece61c69b83259349cde8231 Mon Sep 17 00:00:00 2001 From: Ove Murberg Henriksen Date: Tue, 19 Jun 2012 00:35:39 +0000 Subject: Fixed loop instead of one liners for interpolate over face method mode. --- source/blender/editors/object/object_vgroup.c | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/source/blender/editors/object/object_vgroup.c b/source/blender/editors/object/object_vgroup.c index a9ff41b8046..6f126ce3a91 100644 --- a/source/blender/editors/object/object_vgroup.c +++ b/source/blender/editors/object/object_vgroup.c @@ -447,7 +447,7 @@ int ED_vgroup_transfer_weight(Object *ob_dst, Object *ob_src, bDeformGroup *dg_s MFace *mface_src; BVHTreeNearest nearest; MDeformWeight *dw_dst, *dw_src; - int dv_tot_src, dv_tot_dst, i, index_dst, index_src, index_nearest, index_nearest_vertex; + int dv_tot_src, dv_tot_dst, i, j, v, index_dst, index_src, index_nearest, index_nearest_vertex; float weight, tmp_weight[4], tmp_co[3], normal[3], tmp_mat[4][4], dist_v1, dist_v2, dist_v3, dist_v4; /* create new and overwrite vertex group on destination without data */ @@ -579,7 +579,7 @@ int ED_vgroup_transfer_weight(Object *ob_dst, Object *ob_src, bDeformGroup *dg_s project_v3_plane(tmp_co, normal, mv_src[mface_src[index_nearest].v1].co); - /* interpolate weights */ + /* interpolate weights over face*/ if (mface_src[index_nearest].v4) { interp_weights_face_v3(tmp_weight, mv_src[mface_src[index_nearest].v1].co, @@ -594,18 +594,16 @@ int ED_vgroup_transfer_weight(Object *ob_dst, Object *ob_src, bDeformGroup *dg_s mv_src[mface_src[index_nearest].v3].co, NULL, tmp_co); } - /* get weights */ - /* ideasman42 2012/06/17 21:32:15*/ - /* you can loop over 3-4 items here, ratrher then inline all 4 calls. paint_vertex.c has examples of this. */ - weight = tmp_weight[0] * defvert_find_index(dv_array_src[mface_src[index_nearest].v1], index_src)->weight; - weight += tmp_weight[1] * defvert_find_index(dv_array_src[mface_src[index_nearest].v2], index_src)->weight; - weight += tmp_weight[2] * defvert_find_index(dv_array_src[mface_src[index_nearest].v3], index_src)->weight; - if (mface_src[index_nearest].v4 || mface_src[index_nearest].v4 == 0) { - weight += tmp_weight[3] * defvert_find_index(dv_array_src[mface_src[index_nearest].v4], index_src)->weight; + /* get weights from face*/ + weight = 0; + if (mface_src[index_nearest].v4 || mface_src[index_nearest].v4 == 0) v = 4; + else v = 3; + for (j = 0; j < v; j++) { + weight += tmp_weight[j] * defvert_find_index(dv_array_src[(&mface_src[index_nearest].v1)[j]], index_src)->weight; } /* copy weight */ - if(weight > 0) {/*todo: handle NULL source properly*/ + if(weight > 0) { dw_dst = defvert_verify_index(*dv_dst, index_dst); vgroup_transfer_weight(mv_dst, &dw_dst->weight, weight, replace_mode); } -- cgit v1.2.3 From 32992cabe795638ba4d5c44ab51637d6dc5b743c Mon Sep 17 00:00:00 2001 From: Ove Murberg Henriksen Date: Tue, 19 Jun 2012 01:19:44 +0000 Subject: Bugfix to if statement always reporting true --- source/blender/editors/object/object_vgroup.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/source/blender/editors/object/object_vgroup.c b/source/blender/editors/object/object_vgroup.c index 6f126ce3a91..ca6dfe08c4d 100644 --- a/source/blender/editors/object/object_vgroup.c +++ b/source/blender/editors/object/object_vgroup.c @@ -466,7 +466,7 @@ int ED_vgroup_transfer_weight(Object *ob_dst, Object *ob_src, bDeformGroup *dg_s /* sanity check */ if (!me_src->dvert) { - /*todo fix!*/ + /*todo fix!***********************************************************************************************/ return 0; } @@ -500,7 +500,7 @@ int ED_vgroup_transfer_weight(Object *ob_dst, Object *ob_src, bDeformGroup *dg_s if (dv_array_src) MEM_freeN(dv_array_src); if (dv_array_dst) MEM_freeN(dv_array_dst); dmesh_src->release(dmesh_src); - /*todo: fix*/ + /*todo: fix********************************************************************************************/ return 0; } @@ -580,7 +580,7 @@ int ED_vgroup_transfer_weight(Object *ob_dst, Object *ob_src, bDeformGroup *dg_s project_v3_plane(tmp_co, normal, mv_src[mface_src[index_nearest].v1].co); /* interpolate weights over face*/ - if (mface_src[index_nearest].v4) { + if (&mface_src[index_nearest].v4 != NULL) { interp_weights_face_v3(tmp_weight, mv_src[mface_src[index_nearest].v1].co, mv_src[mface_src[index_nearest].v2].co, @@ -596,7 +596,7 @@ int ED_vgroup_transfer_weight(Object *ob_dst, Object *ob_src, bDeformGroup *dg_s /* get weights from face*/ weight = 0; - if (mface_src[index_nearest].v4 || mface_src[index_nearest].v4 == 0) v = 4; + if (&mface_src[index_nearest].v4 != NULL) v = 4; else v = 3; for (j = 0; j < v; j++) { weight += tmp_weight[j] * defvert_find_index(dv_array_src[(&mface_src[index_nearest].v1)[j]], index_src)->weight; @@ -646,7 +646,7 @@ int ED_vgroup_transfer_weight(Object *ob_dst, Object *ob_src, bDeformGroup *dg_s if (dist_v1 < dist_v2 && dist_v1 < dist_v3) index_nearest_vertex = mface_src[index_nearest].v1; else if (dist_v2 < dist_v3) index_nearest_vertex = mface_src[index_nearest].v2; else index_nearest_vertex = mface_src[index_nearest].v3; - if (mface_src[index_nearest].v4 || mface_src[index_nearest].v4 == 0) { + if (&mface_src[index_nearest].v4 != NULL) { dist_v4 = len_squared_v3v3(tmp_co, mv_src[mface_src[index_nearest].v4].co); if (dist_v4 < dist_v1 && dist_v4 < dist_v2 && dist_v4 < dist_v3) { index_nearest_vertex = mface_src[index_nearest].v4; -- cgit v1.2.3 From 07aaf356f7c24f1ac2bcd2d01583de2df06894a6 Mon Sep 17 00:00:00 2001 From: Ove Murberg Henriksen Date: Tue, 19 Jun 2012 02:23:31 +0000 Subject: Error reporting added. Note that when changing to optional methods that fails, it fails silently still. Might have to adress this. --- source/blender/editors/object/object_vgroup.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/source/blender/editors/object/object_vgroup.c b/source/blender/editors/object/object_vgroup.c index ca6dfe08c4d..87d735da1e9 100644 --- a/source/blender/editors/object/object_vgroup.c +++ b/source/blender/editors/object/object_vgroup.c @@ -436,7 +436,7 @@ void vgroup_transfer_weight(MVert *mv_dst, float *weight_dst, float weight_src, } int ED_vgroup_transfer_weight(Object *ob_dst, Object *ob_src, bDeformGroup *dg_src, Scene *scene, - MethodMode method_mode, ReplaceMode replace_mode) + MethodMode method_mode, ReplaceMode replace_mode, wmOperator *op) { bDeformGroup *dg_dst; Mesh *me_dst, *me_src; @@ -466,7 +466,7 @@ int ED_vgroup_transfer_weight(Object *ob_dst, Object *ob_src, bDeformGroup *dg_s /* sanity check */ if (!me_src->dvert) { - /*todo fix!***********************************************************************************************/ + BKE_reportf(op->reports, RPT_ERROR, "Transfer failed. Source mesh does not have vertices"); return 0; } @@ -500,7 +500,7 @@ int ED_vgroup_transfer_weight(Object *ob_dst, Object *ob_src, bDeformGroup *dg_s if (dv_array_src) MEM_freeN(dv_array_src); if (dv_array_dst) MEM_freeN(dv_array_dst); dmesh_src->release(dmesh_src); - /*todo: fix********************************************************************************************/ + BKE_reportf(op->reports, RPT_ERROR, "Transfer failed. Indices are not matching"); return 0; } @@ -3062,6 +3062,7 @@ static int vertex_group_transfer_weight_exec(bContext *C, wmOperator *op) Scene *scene = CTX_data_scene(C); Object *ob_act = CTX_data_active_object(C); bDeformGroup *dg_src; + int fail = 0; VertexGroupMode vertex_group_mode = RNA_enum_get(op->ptr, "vertex_group_mode"); MethodMode method_mode = RNA_enum_get(op->ptr, "method_mode"); @@ -3075,12 +3076,14 @@ static int vertex_group_transfer_weight_exec(bContext *C, wmOperator *op) switch (vertex_group_mode) { case REPLACE_ACTIVE_VERTEX_GROUP: - ED_vgroup_transfer_weight(ob_act, ob_slc, BLI_findlink(&ob_slc->defbase, ob_slc->actdef - 1), scene, method_mode, replace_mode); + if (!ED_vgroup_transfer_weight( + ob_act, ob_slc, BLI_findlink(&ob_slc->defbase, ob_slc->actdef - 1), scene, method_mode, replace_mode, op)) fail++; break; case REPLACE_ALL_VERTEX_GROUPS: for (dg_src = ob_slc->defbase.first; dg_src; dg_src = dg_src->next) { - ED_vgroup_transfer_weight(ob_act, ob_slc, dg_src, scene, method_mode, replace_mode); + if (!ED_vgroup_transfer_weight( + ob_act, ob_slc, dg_src, scene, method_mode, replace_mode, op)) fail++; } break; } @@ -3094,6 +3097,7 @@ static int vertex_group_transfer_weight_exec(bContext *C, wmOperator *op) CTX_DATA_END; + if (fail != 0) return OPERATOR_CANCELLED; return OPERATOR_FINISHED; } -- cgit v1.2.3 From 873b26702937ec27d31de0efcec00e4997e81bf0 Mon Sep 17 00:00:00 2001 From: Ove Murberg Henriksen Date: Tue, 19 Jun 2012 09:52:16 +0000 Subject: cleanup for bwetter naming --- source/blender/editors/object/object_vgroup.c | 45 +++++++++++++++++++++------ 1 file changed, 35 insertions(+), 10 deletions(-) diff --git a/source/blender/editors/object/object_vgroup.c b/source/blender/editors/object/object_vgroup.c index 87d735da1e9..700534ba897 100644 --- a/source/blender/editors/object/object_vgroup.c +++ b/source/blender/editors/object/object_vgroup.c @@ -382,12 +382,12 @@ typedef enum VertexGroupMode { REPLACE_ALL_VERTEX_GROUPS = 2 } VertexGroupMode; -typedef enum MethodMode { +typedef enum Method { BY_INDEX = 1, BY_NEAREST_VERTEX = 2, BY_NEAREST_FACE = 3, BY_NEAREST_VERTEX_IN_FACE = 4 -} MethodMode; +} Method; typedef enum ReplaceMode { REPLACE_ALL_WEIGHTS = 1, @@ -401,7 +401,7 @@ static EnumPropertyItem vertex_group_mode_item[] = { {0, NULL, 0, NULL, NULL} }; -static EnumPropertyItem method_mode_item[] = { +static EnumPropertyItem method_item[] = { {BY_INDEX, "BY_INDEX", 1, "Vertex index", "Copy for identical meshes."}, {BY_NEAREST_VERTEX, "BY_NEAREST_VERTEX", 1, "Nearest vertex", "Copy weight from closest vertex."}, {BY_NEAREST_FACE, "BY_NEAREST_FACE", 1, "Nearest face", "Barycentric interpolation from nearest face."}, @@ -436,7 +436,7 @@ void vgroup_transfer_weight(MVert *mv_dst, float *weight_dst, float weight_src, } int ED_vgroup_transfer_weight(Object *ob_dst, Object *ob_src, bDeformGroup *dg_src, Scene *scene, - MethodMode method_mode, ReplaceMode replace_mode, wmOperator *op) + Method method, ReplaceMode replace_mode, wmOperator *op) { bDeformGroup *dg_dst; Mesh *me_dst, *me_src; @@ -466,7 +466,7 @@ int ED_vgroup_transfer_weight(Object *ob_dst, Object *ob_src, bDeformGroup *dg_s /* sanity check */ if (!me_src->dvert) { - BKE_reportf(op->reports, RPT_ERROR, "Transfer failed. Source mesh does not have vertices"); + BKE_reportf(op->reports, RPT_ERROR, "Transfer failed. Source mesh does not have any vertex groups"); return 0; } @@ -489,7 +489,7 @@ int ED_vgroup_transfer_weight(Object *ob_dst, Object *ob_src, bDeformGroup *dg_s invert_m4_m4(ob_src->imat, ob_src->obmat); mult_m4_m4m4(tmp_mat, ob_src->imat, ob_dst->obmat); - switch (method_mode) { + switch (method) { case BY_INDEX: /* check if indices are matching, delete and return if not */ @@ -513,6 +513,10 @@ int ED_vgroup_transfer_weight(Object *ob_dst, Object *ob_src, bDeformGroup *dg_s dw_dst = defvert_verify_index(*dv_dst, index_dst); vgroup_transfer_weight(mv_dst, &dw_dst->weight, dw_src->weight, replace_mode); } + /* why? + ideasman42 2012/06/19 07:27:34 + there should be an 'else {' ... here, which checks if 'dv_dst' has any weights and clears them (at least when overwrite is enabled). This will depend on the options selected, but you see the issue I hope. + */ } break; @@ -540,6 +544,10 @@ int ED_vgroup_transfer_weight(Object *ob_dst, Object *ob_src, bDeformGroup *dg_s if(dw_src && dw_src->weight) { dw_dst = defvert_verify_index(*dv_dst, index_dst); vgroup_transfer_weight(mv_dst, &dw_dst->weight, dw_src->weight, replace_mode); + /* why? + ideasman42 2012/06/19 07:27:34 + there should be an 'else {' ... here, which checks if 'dv_dst' has any weights and clears them (at least when overwrite is enabled). This will depend on the options selected, but you see the issue I hope. + */ } } @@ -597,9 +605,18 @@ int ED_vgroup_transfer_weight(Object *ob_dst, Object *ob_src, bDeformGroup *dg_s /* get weights from face*/ weight = 0; if (&mface_src[index_nearest].v4 != NULL) v = 4; + /* + ideasman42 2012/06/19 07:27:34 + comparing v4 with NULL is misleading, since its not a pointer. suggest to use this: +mf = &mface_src[index_nearest]; fidx = mf->v4 ? 3 : 2; do { unsigned int vidx = (&mf->v1)[fidx]; ... operate on vidx ... } while (fidx--); + */ else v = 3; for (j = 0; j < v; j++) { weight += tmp_weight[j] * defvert_find_index(dv_array_src[(&mface_src[index_nearest].v1)[j]], index_src)->weight; + /* +ideasman42 2012/06/19 07:27:34 +defvert_find_index may be a NULL pointer, so getting ->weight from it may crash. better use defvert_find_weight() here which falls back to 0.0 when not found. + */ } /* copy weight */ @@ -647,6 +664,10 @@ int ED_vgroup_transfer_weight(Object *ob_dst, Object *ob_src, bDeformGroup *dg_s else if (dist_v2 < dist_v3) index_nearest_vertex = mface_src[index_nearest].v2; else index_nearest_vertex = mface_src[index_nearest].v3; if (&mface_src[index_nearest].v4 != NULL) { + /* +ideasman42 2012/06/19 07:27:34 +comparing v4 with NULL is misleading... see above. + */ dist_v4 = len_squared_v3v3(tmp_co, mv_src[mface_src[index_nearest].v4].co); if (dist_v4 < dist_v1 && dist_v4 < dist_v2 && dist_v4 < dist_v3) { index_nearest_vertex = mface_src[index_nearest].v4; @@ -659,6 +680,10 @@ int ED_vgroup_transfer_weight(Object *ob_dst, Object *ob_src, bDeformGroup *dg_s dw_dst = defvert_verify_index(*dv_dst, index_dst); vgroup_transfer_weight(mv_dst, &dw_dst->weight, dw_src->weight, replace_mode); } + /* +ideasman42 2012/06/19 07:27:34 why? +there should be an 'else {' ... here, which checks if 'dv_dst' has any weights and clears them (at least when overwrite is enabled). This will depend on the options selected, but you see the issue I hope. + */ } /* free memory */ @@ -3065,7 +3090,7 @@ static int vertex_group_transfer_weight_exec(bContext *C, wmOperator *op) int fail = 0; VertexGroupMode vertex_group_mode = RNA_enum_get(op->ptr, "vertex_group_mode"); - MethodMode method_mode = RNA_enum_get(op->ptr, "method_mode"); + Method method = RNA_enum_get(op->ptr, "method"); ReplaceMode replace_mode = RNA_enum_get(op->ptr, "replace_mode"); /* Macro to loop through selected objects and perform operation depending on function, option and method */ @@ -3077,13 +3102,13 @@ static int vertex_group_transfer_weight_exec(bContext *C, wmOperator *op) case REPLACE_ACTIVE_VERTEX_GROUP: if (!ED_vgroup_transfer_weight( - ob_act, ob_slc, BLI_findlink(&ob_slc->defbase, ob_slc->actdef - 1), scene, method_mode, replace_mode, op)) fail++; + ob_act, ob_slc, BLI_findlink(&ob_slc->defbase, ob_slc->actdef - 1), scene, method, replace_mode, op)) fail++; break; case REPLACE_ALL_VERTEX_GROUPS: for (dg_src = ob_slc->defbase.first; dg_src; dg_src = dg_src->next) { if (!ED_vgroup_transfer_weight( - ob_act, ob_slc, dg_src, scene, method_mode, replace_mode, op)) fail++; + ob_act, ob_slc, dg_src, scene, method, replace_mode, op)) fail++; } break; } @@ -3118,7 +3143,7 @@ void OBJECT_OT_vertex_group_transfer_weight(wmOperatorType *ot) /* properties */ ot->prop = RNA_def_enum(ot->srna, "vertex_group_mode", vertex_group_mode_item, 1, "Group", ""); - ot->prop = RNA_def_enum(ot->srna, "method_mode", method_mode_item, 3, "Method", ""); + ot->prop = RNA_def_enum(ot->srna, "method", method_item, 3, "Method", ""); ot->prop = RNA_def_enum(ot->srna, "replace_mode", replace_mode_item, 1, "Replace", ""); } -- cgit v1.2.3 From 51036b31860a8ed4bffac8260aacaa8d972d6bc7 Mon Sep 17 00:00:00 2001 From: Ove Murberg Henriksen Date: Tue, 19 Jun 2012 16:23:52 +0000 Subject: Fixed better check for Mface.v4 --- source/blender/editors/object/object_vgroup.c | 37 ++++++++++----------------- 1 file changed, 14 insertions(+), 23 deletions(-) diff --git a/source/blender/editors/object/object_vgroup.c b/source/blender/editors/object/object_vgroup.c index 700534ba897..a90e3182923 100644 --- a/source/blender/editors/object/object_vgroup.c +++ b/source/blender/editors/object/object_vgroup.c @@ -444,10 +444,11 @@ int ED_vgroup_transfer_weight(Object *ob_dst, Object *ob_src, bDeformGroup *dg_s BVHTreeFromMesh tree_mesh_vertices_src, tree_mesh_faces_src = {NULL}; MDeformVert **dv_array_src, **dv_array_dst, **dv_src, **dv_dst; MVert *mv_dst, *mv_src; - MFace *mface_src; + MFace *mface_src, *mf; BVHTreeNearest nearest; MDeformWeight *dw_dst, *dw_src; - int dv_tot_src, dv_tot_dst, i, j, v, index_dst, index_src, index_nearest, index_nearest_vertex; + int dv_tot_src, dv_tot_dst, i, v_index, index_dst, index_src, index_nearest, index_nearest_vertex; + unsigned int f_index; float weight, tmp_weight[4], tmp_co[3], normal[3], tmp_mat[4][4], dist_v1, dist_v2, dist_v3, dist_v4; /* create new and overwrite vertex group on destination without data */ @@ -604,20 +605,12 @@ int ED_vgroup_transfer_weight(Object *ob_dst, Object *ob_src, bDeformGroup *dg_s /* get weights from face*/ weight = 0; - if (&mface_src[index_nearest].v4 != NULL) v = 4; - /* - ideasman42 2012/06/19 07:27:34 - comparing v4 with NULL is misleading, since its not a pointer. suggest to use this: -mf = &mface_src[index_nearest]; fidx = mf->v4 ? 3 : 2; do { unsigned int vidx = (&mf->v1)[fidx]; ... operate on vidx ... } while (fidx--); - */ - else v = 3; - for (j = 0; j < v; j++) { - weight += tmp_weight[j] * defvert_find_index(dv_array_src[(&mface_src[index_nearest].v1)[j]], index_src)->weight; - /* -ideasman42 2012/06/19 07:27:34 -defvert_find_index may be a NULL pointer, so getting ->weight from it may crash. better use defvert_find_weight() here which falls back to 0.0 when not found. - */ - } + mf = &mface_src[index_nearest]; + f_index = mf->v4 ? 3 : 2; + do { + v_index = (&mf->v1)[f_index]; + weight += tmp_weight[f_index] * defvert_find_weight(dv_array_src[v_index], index_src); + } while (f_index--); /* copy weight */ if(weight > 0) { @@ -663,14 +656,12 @@ defvert_find_index may be a NULL pointer, so getting ->weight from it may crash. if (dist_v1 < dist_v2 && dist_v1 < dist_v3) index_nearest_vertex = mface_src[index_nearest].v1; else if (dist_v2 < dist_v3) index_nearest_vertex = mface_src[index_nearest].v2; else index_nearest_vertex = mface_src[index_nearest].v3; - if (&mface_src[index_nearest].v4 != NULL) { - /* -ideasman42 2012/06/19 07:27:34 -comparing v4 with NULL is misleading... see above. - */ - dist_v4 = len_squared_v3v3(tmp_co, mv_src[mface_src[index_nearest].v4].co); + mf = &mface_src[index_nearest]; + f_index = mf->v4 ? 3 : 2; + if (f_index == 3) { + dist_v4 = len_squared_v3v3(tmp_co, mv_src[mf->v4].co); if (dist_v4 < dist_v1 && dist_v4 < dist_v2 && dist_v4 < dist_v3) { - index_nearest_vertex = mface_src[index_nearest].v4; + index_nearest_vertex = mf->v4; } } -- cgit v1.2.3 From 622ae0a1ca9ff9dae0670d4bc8fcd134110a8572 Mon Sep 17 00:00:00 2001 From: Ove Murberg Henriksen Date: Tue, 19 Jun 2012 18:26:55 +0000 Subject: clenaup. --- source/blender/editors/object/object_vgroup.c | 39 ++++++++++----------------- 1 file changed, 14 insertions(+), 25 deletions(-) diff --git a/source/blender/editors/object/object_vgroup.c b/source/blender/editors/object/object_vgroup.c index a90e3182923..7ca9e697229 100644 --- a/source/blender/editors/object/object_vgroup.c +++ b/source/blender/editors/object/object_vgroup.c @@ -581,32 +581,21 @@ int ED_vgroup_transfer_weight(Object *ob_dst, Object *ob_src, bDeformGroup *dg_s index_nearest = nearest.index; /* project onto face */ - normal_tri_v3(normal, - mv_src[mface_src[nearest.index].v1].co, - mv_src[mface_src[index_nearest].v2].co, - mv_src[mface_src[index_nearest].v3].co); - - project_v3_plane(tmp_co, normal, mv_src[mface_src[index_nearest].v1].co); + mf = &mface_src[index_nearest]; + normal_tri_v3(normal, mv_src[mf->v1].co, mv_src[mf->v2].co, mv_src[mf->v3].co); + project_v3_plane(tmp_co, normal, mv_src[mf->v1].co); /* interpolate weights over face*/ - if (&mface_src[index_nearest].v4 != NULL) { - interp_weights_face_v3(tmp_weight, - mv_src[mface_src[index_nearest].v1].co, - mv_src[mface_src[index_nearest].v2].co, - mv_src[mface_src[index_nearest].v3].co, - mv_src[mface_src[index_nearest].v4].co, tmp_co); + f_index = mf->v4 ? 3 : 2; + if (f_index == 3) { + interp_weights_face_v3(tmp_weight, mv_src[mf->v1].co, mv_src[mf->v2].co, mv_src[mf->v3].co, mv_src[mf->v4].co, tmp_co); } else { - interp_weights_face_v3(tmp_weight, - mv_src[mface_src[index_nearest].v1].co, - mv_src[mface_src[index_nearest].v2].co, - mv_src[mface_src[index_nearest].v3].co, NULL, tmp_co); + interp_weights_face_v3(tmp_weight, mv_src[mf->v1].co, mv_src[mf->v2].co, mv_src[mf->v3].co, NULL, tmp_co); } /* get weights from face*/ weight = 0; - mf = &mface_src[index_nearest]; - f_index = mf->v4 ? 3 : 2; do { v_index = (&mf->v1)[f_index]; weight += tmp_weight[f_index] * defvert_find_weight(dv_array_src[v_index], index_src); @@ -648,16 +637,16 @@ int ED_vgroup_transfer_weight(Object *ob_dst, Object *ob_src, bDeformGroup *dg_s index_nearest = nearest.index; /* get distances */ - dist_v1 = len_squared_v3v3(tmp_co, mv_src[mface_src[index_nearest].v1].co); - dist_v2 = len_squared_v3v3(tmp_co, mv_src[mface_src[index_nearest].v2].co); - dist_v3 = len_squared_v3v3(tmp_co, mv_src[mface_src[index_nearest].v3].co); + mf = &mface_src[index_nearest]; + dist_v1 = len_squared_v3v3(tmp_co, mv_src[mf->v1].co); + dist_v2 = len_squared_v3v3(tmp_co, mv_src[mf->v2].co); + dist_v3 = len_squared_v3v3(tmp_co, mv_src[mf->v3].co); /* get closest vertex */ - if (dist_v1 < dist_v2 && dist_v1 < dist_v3) index_nearest_vertex = mface_src[index_nearest].v1; - else if (dist_v2 < dist_v3) index_nearest_vertex = mface_src[index_nearest].v2; - else index_nearest_vertex = mface_src[index_nearest].v3; - mf = &mface_src[index_nearest]; f_index = mf->v4 ? 3 : 2; + if (dist_v1 < dist_v2 && dist_v1 < dist_v3) index_nearest_vertex = mf->v1; + else if (dist_v2 < dist_v3) index_nearest_vertex = mf->v2; + else index_nearest_vertex = mf->v3; if (f_index == 3) { dist_v4 = len_squared_v3v3(tmp_co, mv_src[mf->v4].co); if (dist_v4 < dist_v1 && dist_v4 < dist_v2 && dist_v4 < dist_v3) { -- cgit v1.2.3 From 370901890ac1177a4619b18613096391914204f8 Mon Sep 17 00:00:00 2001 From: Ove Murberg Henriksen Date: Tue, 19 Jun 2012 19:15:59 +0000 Subject: Its now overwriting properly by clearing weights when using replace_mode all. Reason for not going for suggested "else" on copy in each case is that it would present a paradox. (it would delete weights that got created in some instances) --- source/blender/editors/object/object_vgroup.c | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/source/blender/editors/object/object_vgroup.c b/source/blender/editors/object/object_vgroup.c index 7ca9e697229..5648a06f540 100644 --- a/source/blender/editors/object/object_vgroup.c +++ b/source/blender/editors/object/object_vgroup.c @@ -490,6 +490,14 @@ int ED_vgroup_transfer_weight(Object *ob_dst, Object *ob_src, bDeformGroup *dg_s invert_m4_m4(ob_src->imat, ob_src->obmat); mult_m4_m4m4(tmp_mat, ob_src->imat, ob_dst->obmat); + /* clear weights */ + if (replace_mode == REPLACE_ALL_WEIGHTS) { + for(i = 0, dv_dst = dv_array_dst; i < me_dst->totvert; i++, dv_dst++) { + dw_dst = defvert_verify_index(*dv_dst, index_dst); + if (dw_dst) (*dw_dst).weight = 0; + } + } + switch (method) { case BY_INDEX: @@ -514,10 +522,6 @@ int ED_vgroup_transfer_weight(Object *ob_dst, Object *ob_src, bDeformGroup *dg_s dw_dst = defvert_verify_index(*dv_dst, index_dst); vgroup_transfer_weight(mv_dst, &dw_dst->weight, dw_src->weight, replace_mode); } - /* why? - ideasman42 2012/06/19 07:27:34 - there should be an 'else {' ... here, which checks if 'dv_dst' has any weights and clears them (at least when overwrite is enabled). This will depend on the options selected, but you see the issue I hope. - */ } break; @@ -545,10 +549,6 @@ int ED_vgroup_transfer_weight(Object *ob_dst, Object *ob_src, bDeformGroup *dg_s if(dw_src && dw_src->weight) { dw_dst = defvert_verify_index(*dv_dst, index_dst); vgroup_transfer_weight(mv_dst, &dw_dst->weight, dw_src->weight, replace_mode); - /* why? - ideasman42 2012/06/19 07:27:34 - there should be an 'else {' ... here, which checks if 'dv_dst' has any weights and clears them (at least when overwrite is enabled). This will depend on the options selected, but you see the issue I hope. - */ } } @@ -660,10 +660,6 @@ int ED_vgroup_transfer_weight(Object *ob_dst, Object *ob_src, bDeformGroup *dg_s dw_dst = defvert_verify_index(*dv_dst, index_dst); vgroup_transfer_weight(mv_dst, &dw_dst->weight, dw_src->weight, replace_mode); } - /* -ideasman42 2012/06/19 07:27:34 why? -there should be an 'else {' ... here, which checks if 'dv_dst' has any weights and clears them (at least when overwrite is enabled). This will depend on the options selected, but you see the issue I hope. - */ } /* free memory */ -- cgit v1.2.3 From 30085e5ea96dcec5ef0afd239fbd33760cee83ce Mon Sep 17 00:00:00 2001 From: Ove Murberg Henriksen Date: Wed, 4 Jul 2012 16:30:12 +0000 Subject: response to code review: http://codereview.appspot.com/6301100/diff/1/source/blender/editors/object/object_vgroup.c --- source/blender/editors/object/object_vgroup.c | 122 ++++++++++++++------------ 1 file changed, 67 insertions(+), 55 deletions(-) diff --git a/source/blender/editors/object/object_vgroup.c b/source/blender/editors/object/object_vgroup.c index 5648a06f540..c5296d0f7a7 100644 --- a/source/blender/editors/object/object_vgroup.c +++ b/source/blender/editors/object/object_vgroup.c @@ -375,68 +375,72 @@ int ED_vgroup_copy_array(Object *ob, Object *ob_from) return 1; } -/***********************Start transfer weight*********************************/ - -typedef enum VertexGroupMode { - REPLACE_ACTIVE_VERTEX_GROUP = 1, - REPLACE_ALL_VERTEX_GROUPS = 2 -} VertexGroupMode; - -typedef enum Method { - BY_INDEX = 1, - BY_NEAREST_VERTEX = 2, - BY_NEAREST_FACE = 3, - BY_NEAREST_VERTEX_IN_FACE = 4 -} Method; - -typedef enum ReplaceMode { - REPLACE_ALL_WEIGHTS = 1, - REPLACE_EMPTY_WEIGHTS = 2, - REPLACE_SELECTED_WEIGHTS = 3 -} ReplaceMode; - -static EnumPropertyItem vertex_group_mode_item[] = { - {REPLACE_ACTIVE_VERTEX_GROUP, "REPLACE_ACTIVE_VERTEX_GROUP", 1, "Active", "Transfer active vertex group from selected to active mesh."}, - {REPLACE_ALL_VERTEX_GROUPS, "REPLACE_ALL_VERTEX_GROUPS", 1, "All", "Transfer all vertex groups from selected to active mesh."}, +/***********************Start weight transfer (WT)*********************************/ + +typedef enum WT_VertexGroupMode { + WT_REPLACE_ACTIVE_VERTEX_GROUP = 1, + WT_REPLACE_ALL_VERTEX_GROUPS = 2 +} WT_VertexGroupMode; + +typedef enum WT_Method { + WT_BY_INDEX = 1, + WT_BY_NEAREST_VERTEX = 2, + WT_BY_NEAREST_FACE = 3, + WT_BY_NEAREST_VERTEX_IN_FACE = 4 +} WT_Method; + +typedef enum WT_ReplaceMode { + WT_REPLACE_ALL_WEIGHTS = 1, + WT_REPLACE_EMPTY_WEIGHTS = 2, + WT_REPLACE_SELECTED_WEIGHTS = 3 +} WT_ReplaceMode; + +static EnumPropertyItem WT_vertex_group_mode_item[] = { + {WT_REPLACE_ACTIVE_VERTEX_GROUP, "WT_REPLACE_ACTIVE_VERTEX_GROUP", 1, "Active", "Transfer active vertex group from selected to active mesh."}, + {WT_REPLACE_ALL_VERTEX_GROUPS, "WT_REPLACE_ALL_VERTEX_GROUPS", 1, "All", "Transfer all vertex groups from selected to active mesh."}, {0, NULL, 0, NULL, NULL} }; -static EnumPropertyItem method_item[] = { - {BY_INDEX, "BY_INDEX", 1, "Vertex index", "Copy for identical meshes."}, - {BY_NEAREST_VERTEX, "BY_NEAREST_VERTEX", 1, "Nearest vertex", "Copy weight from closest vertex."}, - {BY_NEAREST_FACE, "BY_NEAREST_FACE", 1, "Nearest face", "Barycentric interpolation from nearest face."}, - {BY_NEAREST_VERTEX_IN_FACE, "BY_NEAREST_VERTEX_IN_FACE", 1, "Nearest vertex in face", "Copy weight from closest vertex in nearest face."}, +static EnumPropertyItem WT_method_item[] = { + {WT_BY_INDEX, "WT_BY_INDEX", 1, "Vertex index", "Copy for identical meshes."}, + {WT_BY_NEAREST_VERTEX, "WT_BY_NEAREST_VERTEX", 1, "Nearest vertex", "Copy weight from closest vertex."}, + {WT_BY_NEAREST_FACE, "WT_BY_NEAREST_FACE", 1, "Nearest face", "Barycentric interpolation from nearest face."}, + {WT_BY_NEAREST_VERTEX_IN_FACE, "WT_BY_NEAREST_VERTEX_IN_FACE", 1, "Nearest vertex in face", "Copy weight from closest vertex in nearest face."}, {0, NULL, 0, NULL, NULL} }; -static EnumPropertyItem replace_mode_item[] = { - {REPLACE_ALL_WEIGHTS, "REPLACE_ALL_WEIGHTS", 1, "All", "Overwrites all weights."}, - {REPLACE_EMPTY_WEIGHTS, "REPLACE_EMPTY_WEIGHTS", 1, "Empty", "Adds weights to vertices with no weight."}, - {REPLACE_SELECTED_WEIGHTS, "REPLACE_SELECTED_WEIGHTS", 1, "Selected", "Replace selected weights."}, +static EnumPropertyItem WT_replace_mode_item[] = { + {WT_REPLACE_ALL_WEIGHTS, "WT_REPLACE_ALL_WEIGHTS", 1, "All", "Overwrites all weights."}, + {WT_REPLACE_EMPTY_WEIGHTS, "WT_REPLACE_EMPTY_WEIGHTS", 1, "Empty", "Adds weights to vertices with no weight."}, + {WT_REPLACE_SELECTED_WEIGHTS, "WT_REPLACE_SELECTED_WEIGHTS", 1, "Selected", "Replace selected weights."}, {0, NULL, 0, NULL, NULL} }; /*copy weight*/ -void vgroup_transfer_weight(MVert *mv_dst, float *weight_dst, float weight_src, ReplaceMode replace_mode) +void vgroup_transfer_weight(MVert *mv_dst, float *weight_dst, float weight_src, WT_ReplaceMode replace_mode) { switch (replace_mode) { - case REPLACE_ALL_WEIGHTS: + case WT_REPLACE_ALL_WEIGHTS: *weight_dst = weight_src; break; - case REPLACE_EMPTY_WEIGHTS: + case WT_REPLACE_EMPTY_WEIGHTS: if (*weight_dst == 0) *weight_dst = weight_src; break; - case REPLACE_SELECTED_WEIGHTS: + case WT_REPLACE_SELECTED_WEIGHTS: if (mv_dst->flag & SELECT) *weight_dst = weight_src; break; + + default: + BLI_assert(0); + break; } } int ED_vgroup_transfer_weight(Object *ob_dst, Object *ob_src, bDeformGroup *dg_src, Scene *scene, - Method method, ReplaceMode replace_mode, wmOperator *op) + WT_Method method, WT_ReplaceMode replace_mode, wmOperator *op) { bDeformGroup *dg_dst; Mesh *me_dst, *me_src; @@ -452,7 +456,7 @@ int ED_vgroup_transfer_weight(Object *ob_dst, Object *ob_src, bDeformGroup *dg_s float weight, tmp_weight[4], tmp_co[3], normal[3], tmp_mat[4][4], dist_v1, dist_v2, dist_v3, dist_v4; /* create new and overwrite vertex group on destination without data */ - if (!defgroup_find_name(ob_dst, dg_src->name) || replace_mode == REPLACE_ALL_WEIGHTS) { + if (!defgroup_find_name(ob_dst, dg_src->name) || replace_mode == WT_REPLACE_ALL_WEIGHTS) { ED_vgroup_delete(ob_dst, defgroup_find_name(ob_dst, dg_src->name)); ED_vgroup_add_name(ob_dst, dg_src->name); } @@ -491,7 +495,7 @@ int ED_vgroup_transfer_weight(Object *ob_dst, Object *ob_src, bDeformGroup *dg_s mult_m4_m4m4(tmp_mat, ob_src->imat, ob_dst->obmat); /* clear weights */ - if (replace_mode == REPLACE_ALL_WEIGHTS) { + if (replace_mode == WT_REPLACE_ALL_WEIGHTS) { for(i = 0, dv_dst = dv_array_dst; i < me_dst->totvert; i++, dv_dst++) { dw_dst = defvert_verify_index(*dv_dst, index_dst); if (dw_dst) (*dw_dst).weight = 0; @@ -500,7 +504,7 @@ int ED_vgroup_transfer_weight(Object *ob_dst, Object *ob_src, bDeformGroup *dg_s switch (method) { - case BY_INDEX: + case WT_BY_INDEX: /* 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) @@ -525,7 +529,7 @@ int ED_vgroup_transfer_weight(Object *ob_dst, Object *ob_src, bDeformGroup *dg_s } break; - case BY_NEAREST_VERTEX: + case WT_BY_NEAREST_VERTEX: /* make node tree */ bvhtree_from_mesh_verts(&tree_mesh_vertices_src, dmesh_src, FLT_EPSILON, 2, 6); @@ -544,7 +548,7 @@ int ED_vgroup_transfer_weight(Object *ob_dst, Object *ob_src, bDeformGroup *dg_s BLI_bvhtree_find_nearest(tree_mesh_vertices_src.tree, tmp_co, &nearest, tree_mesh_vertices_src.nearest_callback, &tree_mesh_vertices_src); - /* copy weight */ + /* copy weight that are not NULL including weight value 0. Existing target weights are overwritten prior to this in relevant cases. */ dw_src = defvert_find_index(dv_array_src[nearest.index], index_src); if(dw_src && dw_src->weight) { dw_dst = defvert_verify_index(*dv_dst, index_dst); @@ -556,7 +560,7 @@ int ED_vgroup_transfer_weight(Object *ob_dst, Object *ob_src, bDeformGroup *dg_s free_bvhtree_from_mesh(&tree_mesh_vertices_src); break; - case BY_NEAREST_FACE: + case WT_BY_NEAREST_FACE: /* get faces */ DM_ensure_tessface(dmesh_src); mface_src = dmesh_src->getTessFaceArray(dmesh_src); @@ -601,7 +605,7 @@ int ED_vgroup_transfer_weight(Object *ob_dst, Object *ob_src, bDeformGroup *dg_s weight += tmp_weight[f_index] * defvert_find_weight(dv_array_src[v_index], index_src); } while (f_index--); - /* copy weight */ + /* copy weight that are not NULL including weight value 0. Existing target weights are overwritten prior to this in relevant cases. */ if(weight > 0) { dw_dst = defvert_verify_index(*dv_dst, index_dst); vgroup_transfer_weight(mv_dst, &dw_dst->weight, weight, replace_mode); @@ -612,7 +616,7 @@ int ED_vgroup_transfer_weight(Object *ob_dst, Object *ob_src, bDeformGroup *dg_s free_bvhtree_from_mesh(&tree_mesh_faces_src); break; - case BY_NEAREST_VERTEX_IN_FACE: + case WT_BY_NEAREST_VERTEX_IN_FACE: /* get faces */ DM_ensure_tessface(dmesh_src); mface_src = dmesh_src->getTessFaceArray(dmesh_src); @@ -654,7 +658,7 @@ int ED_vgroup_transfer_weight(Object *ob_dst, Object *ob_src, bDeformGroup *dg_s } } - /* copy weight */ + /* copy weight that are not NULL including weight value 0. Existing target weights are overwritten prior to this in relevant cases. */ dw_src = defvert_find_index(dv_array_src[index_nearest_vertex], index_src); if(dw_src && dw_src->weight) { dw_dst = defvert_verify_index(*dv_dst, index_dst); @@ -665,6 +669,10 @@ int ED_vgroup_transfer_weight(Object *ob_dst, Object *ob_src, bDeformGroup *dg_s /* free memory */ free_bvhtree_from_mesh(&tree_mesh_faces_src); break; + + default: + BLI_assert(0); + break; } /*free memory*/ @@ -675,7 +683,7 @@ int ED_vgroup_transfer_weight(Object *ob_dst, Object *ob_src, bDeformGroup *dg_s return 1; } -/***********************End transfer weight***********************************/ +/***********************End weight transfer (WT)***********************************/ /* for Mesh in Object mode */ /* allows editmode for Lattice */ @@ -3065,9 +3073,9 @@ static int vertex_group_transfer_weight_exec(bContext *C, wmOperator *op) bDeformGroup *dg_src; int fail = 0; - VertexGroupMode vertex_group_mode = RNA_enum_get(op->ptr, "vertex_group_mode"); - Method method = RNA_enum_get(op->ptr, "method"); - ReplaceMode replace_mode = RNA_enum_get(op->ptr, "replace_mode"); + WT_VertexGroupMode vertex_group_mode = RNA_enum_get(op->ptr, "WT_vertex_group_mode"); + WT_Method method = RNA_enum_get(op->ptr, "WT_method"); + WT_ReplaceMode replace_mode = RNA_enum_get(op->ptr, "WT_replace_mode"); /* Macro to loop through selected objects and perform operation depending on function, option and method */ CTX_DATA_BEGIN (C, Object *, ob_slc, selected_editable_objects) @@ -3076,17 +3084,21 @@ static int vertex_group_transfer_weight_exec(bContext *C, wmOperator *op) if (ob_act != ob_slc && ob_slc->defbase.first) { switch (vertex_group_mode) { - case REPLACE_ACTIVE_VERTEX_GROUP: + case WT_REPLACE_ACTIVE_VERTEX_GROUP: if (!ED_vgroup_transfer_weight( ob_act, ob_slc, BLI_findlink(&ob_slc->defbase, ob_slc->actdef - 1), scene, method, replace_mode, op)) fail++; break; - case REPLACE_ALL_VERTEX_GROUPS: + case WT_REPLACE_ALL_VERTEX_GROUPS: for (dg_src = ob_slc->defbase.first; dg_src; dg_src = dg_src->next) { if (!ED_vgroup_transfer_weight( ob_act, ob_slc, dg_src, scene, method, replace_mode, op)) fail++; } break; + + default: + BLI_assert(0); + break; } } } @@ -3118,9 +3130,9 @@ void OBJECT_OT_vertex_group_transfer_weight(wmOperatorType *ot) ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; /* properties */ - ot->prop = RNA_def_enum(ot->srna, "vertex_group_mode", vertex_group_mode_item, 1, "Group", ""); - ot->prop = RNA_def_enum(ot->srna, "method", method_item, 3, "Method", ""); - ot->prop = RNA_def_enum(ot->srna, "replace_mode", replace_mode_item, 1, "Replace", ""); + ot->prop = RNA_def_enum(ot->srna, "WT_vertex_group_mode", WT_vertex_group_mode_item, 1, "Group", ""); + ot->prop = RNA_def_enum(ot->srna, "WT_method", WT_method_item, 3, "Method", ""); + ot->prop = RNA_def_enum(ot->srna, "WT_replace_mode", WT_replace_mode_item, 1, "Replace", ""); } static EnumPropertyItem vgroup_items[] = { -- cgit v1.2.3 From ec689d650dd9e32b5f88a4f45f583b6733192ef0 Mon Sep 17 00:00:00 2001 From: Ove Murberg Henriksen Date: Tue, 9 Oct 2012 11:29:29 +0000 Subject: Fix based on code review Issue 6347064 --- source/blender/editors/object/object_vgroup.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/blender/editors/object/object_vgroup.c b/source/blender/editors/object/object_vgroup.c index a07bc3edda0..07df556b87d 100644 --- a/source/blender/editors/object/object_vgroup.c +++ b/source/blender/editors/object/object_vgroup.c @@ -466,7 +466,7 @@ int ED_vgroup_transfer_weight(Object *ob_dst, Object *ob_src, bDeformGroup *dg_s dg_dst = defgroup_find_name(ob_dst, dg_src->name); /* get meshes */ - dmesh_src = mesh_get_derived_deform(scene, ob_src, CD_MASK_BAREMESH | CD_MASK_ORIGINDEX); + dmesh_src = mesh_get_derived_deform(scene, ob_src, CD_MASK_BAREMESH); me_dst = ob_dst->data; me_src = ob_src->data; -- cgit v1.2.3 From 35504d627bf87c7d2e528870a3a215bd6b2b1876 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 9 Oct 2012 12:41:37 +0000 Subject: style cleanup: also made functions static --- source/blender/editors/object/object_vgroup.c | 38 ++++++++++++++++++--------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/source/blender/editors/object/object_vgroup.c b/source/blender/editors/object/object_vgroup.c index f7bc87177f8..dea7eb984ad 100644 --- a/source/blender/editors/object/object_vgroup.c +++ b/source/blender/editors/object/object_vgroup.c @@ -431,7 +431,7 @@ static EnumPropertyItem WT_replace_mode_item[] = { }; /*copy weight*/ -void vgroup_transfer_weight(MVert *mv_dst, float *weight_dst, float weight_src, WT_ReplaceMode replace_mode) +static void vgroup_transfer_weight(MVert *mv_dst, float *weight_dst, float weight_src, WT_ReplaceMode replace_mode) { switch (replace_mode) { @@ -453,8 +453,9 @@ void vgroup_transfer_weight(MVert *mv_dst, float *weight_dst, float weight_src, } } -int ED_vgroup_transfer_weight(Object *ob_dst, Object *ob_src, bDeformGroup *dg_src, Scene *scene, - WT_Method method, WT_ReplaceMode replace_mode, wmOperator *op) +/* could be exposed externally */ +static int ed_vgroup_transfer_weight(Object *ob_dst, Object *ob_src, bDeformGroup *dg_src, Scene *scene, + WT_Method method, WT_ReplaceMode replace_mode, wmOperator *op) { bDeformGroup *dg_dst; Mesh *me_dst, *me_src; @@ -536,7 +537,7 @@ int ED_vgroup_transfer_weight(Object *ob_dst, Object *ob_src, bDeformGroup *dg_s /* copy weight */ dw_src = defvert_find_index(*dv_src, index_src); - if(dw_src && dw_src->weight) { + if (dw_src && dw_src->weight) { dw_dst = defvert_verify_index(*dv_dst, index_dst); vgroup_transfer_weight(mv_dst, &dw_dst->weight, dw_src->weight, replace_mode); } @@ -564,7 +565,7 @@ int ED_vgroup_transfer_weight(Object *ob_dst, Object *ob_src, bDeformGroup *dg_s /* copy weight that are not NULL including weight value 0. Existing target weights are overwritten prior to this in relevant cases. */ dw_src = defvert_find_index(dv_array_src[nearest.index], index_src); - if(dw_src && dw_src->weight) { + if (dw_src && dw_src->weight) { dw_dst = defvert_verify_index(*dv_dst, index_dst); vgroup_transfer_weight(mv_dst, &dw_dst->weight, dw_src->weight, replace_mode); } @@ -620,7 +621,7 @@ int ED_vgroup_transfer_weight(Object *ob_dst, Object *ob_src, bDeformGroup *dg_s } while (f_index--); /* copy weight that are not NULL including weight value 0. Existing target weights are overwritten prior to this in relevant cases. */ - if(weight > 0) { + if (weight > 0) { dw_dst = defvert_verify_index(*dv_dst, index_dst); vgroup_transfer_weight(mv_dst, &dw_dst->weight, weight, replace_mode); } @@ -674,7 +675,7 @@ int ED_vgroup_transfer_weight(Object *ob_dst, Object *ob_src, bDeformGroup *dg_s /* copy weight that are not NULL including weight value 0. Existing target weights are overwritten prior to this in relevant cases. */ dw_src = defvert_find_index(dv_array_src[index_nearest_vertex], index_src); - if(dw_src && dw_src->weight) { + if (dw_src && dw_src->weight) { dw_dst = defvert_verify_index(*dv_dst, index_dst); vgroup_transfer_weight(mv_dst, &dw_dst->weight, dw_src->weight, replace_mode); } @@ -3271,14 +3272,21 @@ static int vertex_group_transfer_weight_exec(bContext *C, wmOperator *op) switch (vertex_group_mode) { case WT_REPLACE_ACTIVE_VERTEX_GROUP: - if (!ED_vgroup_transfer_weight( - ob_act, ob_slc, BLI_findlink(&ob_slc->defbase, ob_slc->actdef - 1), scene, method, replace_mode, op)) fail++; + if (!ed_vgroup_transfer_weight(ob_act, ob_slc, + BLI_findlink(&ob_slc->defbase, ob_slc->actdef - 1), + scene, method, replace_mode, op)) + { + fail++; + } break; case WT_REPLACE_ALL_VERTEX_GROUPS: for (dg_src = ob_slc->defbase.first; dg_src; dg_src = dg_src->next) { - if (!ED_vgroup_transfer_weight( - ob_act, ob_slc, dg_src, scene, method, replace_mode, op)) fail++; + if (!ed_vgroup_transfer_weight(ob_act, ob_slc, + dg_src, scene, method, replace_mode, op)) + { + fail++; + } } break; @@ -3296,8 +3304,12 @@ static int vertex_group_transfer_weight_exec(bContext *C, wmOperator *op) CTX_DATA_END; - if (fail != 0) return OPERATOR_CANCELLED; - return OPERATOR_FINISHED; + if (fail != 0) { + return OPERATOR_CANCELLED; + } + else { + return OPERATOR_FINISHED; + } } /* transfers weight from active to selected */ -- cgit v1.2.3 From f92305fcb40c882c10b1e4ede7b6bfdfb18c4941 Mon Sep 17 00:00:00 2001 From: Daniel Genrich Date: Tue, 9 Oct 2012 12:59:20 +0000 Subject: Bugfix [#32677] Cloth Pinning Does Not Obey Weight Map Problem occured when having more than one weight map available. --- source/blender/blenkernel/intern/cloth.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/source/blender/blenkernel/intern/cloth.c b/source/blender/blenkernel/intern/cloth.c index 4241756a109..da162ab37d0 100644 --- a/source/blender/blenkernel/intern/cloth.c +++ b/source/blender/blenkernel/intern/cloth.c @@ -773,11 +773,13 @@ static void cloth_apply_vgroup ( ClothModifierData *clmd, DerivedMesh *dm ) else verts->goal= 0.0f; + /* Reset vertex flags */ + verts->flags &= ~CLOTH_VERT_FLAG_PINNED; + verts->flags &= ~CLOTH_VERT_FLAG_NOSELFCOLL; + dvert = dm->getVertData ( dm, i, CD_MDEFORMVERT ); if ( dvert ) { - for ( j = 0; j < dvert->totweight; j++ ) { - verts->flags &= ~CLOTH_VERT_FLAG_PINNED; if (( dvert->dw[j].def_nr == (clmd->sim_parms->vgroup_mass-1)) && (clmd->sim_parms->flags & CLOTH_SIMSETTINGS_FLAG_GOAL )) { verts->goal = dvert->dw [j].weight; @@ -789,7 +791,7 @@ static void cloth_apply_vgroup ( ClothModifierData *clmd, DerivedMesh *dm ) */ verts->goal = powf(verts->goal, 4.0f); - if ( verts->goal >=SOFTGOALSNAP ) + if ( verts->goal >= SOFTGOALSNAP ) verts->flags |= CLOTH_VERT_FLAG_PINNED; } @@ -804,7 +806,6 @@ static void cloth_apply_vgroup ( ClothModifierData *clmd, DerivedMesh *dm ) } } - verts->flags &= ~CLOTH_VERT_FLAG_NOSELFCOLL; if (clmd->coll_parms->flags & CLOTH_COLLSETTINGS_FLAG_SELF ) { if ( dvert->dw[j].def_nr == (clmd->coll_parms->vgroup_selfcol-1)) { if (dvert->dw [j].weight > 0.0f) { -- cgit v1.2.3 From a580c891a7911c46a8d57703858904ca25f29c1a Mon Sep 17 00:00:00 2001 From: Daniel Genrich Date: Tue, 9 Oct 2012 13:09:03 +0000 Subject: Bugfix [#32703] elbeem's isSimworldOk() will never return FALSE Fixed as suggested by Campbell, thank you! --- intern/elbeem/intern/utilities.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/intern/elbeem/intern/utilities.cpp b/intern/elbeem/intern/utilities.cpp index c912e70b281..2b9b8d5b8a5 100644 --- a/intern/elbeem/intern/utilities.cpp +++ b/intern/elbeem/intern/utilities.cpp @@ -51,7 +51,7 @@ int getElbeemState(void) { return gElbeemState; } int isSimworldOk(void) { - return (getElbeemState>=0); + return (getElbeemState() >=0); } // last error as string, acces with get/setElbeemErrorString -- cgit v1.2.3