Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/armature/armature_edit.c
| Show First 20 Lines • Show All 42 Lines • ▼ Show 20 Lines | |||||
| #include "BLI_blenlib.h" | #include "BLI_blenlib.h" | ||||
| #include "BLI_math.h" | #include "BLI_math.h" | ||||
| #include "BLI_ghash.h" | #include "BLI_ghash.h" | ||||
| #include "BKE_action.h" | #include "BKE_action.h" | ||||
| #include "BKE_armature.h" | #include "BKE_armature.h" | ||||
| #include "BKE_constraint.h" | #include "BKE_constraint.h" | ||||
| #include "BKE_context.h" | #include "BKE_context.h" | ||||
| #include "BKE_layer.h" | |||||
| #include "BKE_global.h" | #include "BKE_global.h" | ||||
| #include "BKE_report.h" | #include "BKE_report.h" | ||||
| #include "BKE_object.h" | #include "BKE_object.h" | ||||
| #include "RNA_access.h" | #include "RNA_access.h" | ||||
| #include "RNA_define.h" | #include "RNA_define.h" | ||||
| #include "WM_api.h" | #include "WM_api.h" | ||||
| ▲ Show 20 Lines • Show All 566 Lines • ▼ Show 20 Lines | if (found == 0) { | ||||
| BLI_addtail(points, ebp); | BLI_addtail(points, ebp); | ||||
| } | } | ||||
| } | } | ||||
| /* bone adding between selected joints */ | /* bone adding between selected joints */ | ||||
| static int armature_fill_bones_exec(bContext *C, wmOperator *op) | static int armature_fill_bones_exec(bContext *C, wmOperator *op) | ||||
| { | { | ||||
| Object *obedit = CTX_data_edit_object(C); | Object *obedit_active = CTX_data_edit_object(C); | ||||
| bArmature *arm = (obedit) ? obedit->data : NULL; | |||||
| Scene *scene = CTX_data_scene(C); | Scene *scene = CTX_data_scene(C); | ||||
| View3D *v3d = CTX_wm_view3d(C); | View3D *v3d = CTX_wm_view3d(C); | ||||
| ListBase points = {NULL, NULL}; | ListBase points = {NULL, NULL}; | ||||
| EditBone *newbone = NULL; | EditBone *newbone = NULL; | ||||
| int count; | int count; | ||||
| bool mixed_object_error = false; | |||||
| /* sanity checks */ | /* sanity checks */ | ||||
| if (ELEM(NULL, obedit, arm)) | if (ELEM(NULL, obedit_active, obedit_active->data)) { | ||||
| return OPERATOR_CANCELLED; | return OPERATOR_CANCELLED; | ||||
| } | |||||
| /* loop over all bones, and only consider if visible */ | /* loop over all bones, and only consider if visible */ | ||||
| CTX_DATA_BEGIN(C, EditBone *, ebone, visible_bones) | bArmature *arm = NULL; | ||||
| CTX_DATA_BEGIN_WITH_ID(C, EditBone *, ebone, visible_bones, bArmature *, arm_iter) | |||||
| { | { | ||||
| if (!(ebone->flag & BONE_CONNECTED) && (ebone->flag & BONE_ROOTSEL)) | bool check = false; | ||||
| if (!(ebone->flag & BONE_CONNECTED) && (ebone->flag & BONE_ROOTSEL)) { | |||||
| fill_add_joint(ebone, 0, &points); | fill_add_joint(ebone, 0, &points); | ||||
| if (ebone->flag & BONE_TIPSEL) | check = true; | ||||
| } | |||||
| if (ebone->flag & BONE_TIPSEL) { | |||||
| fill_add_joint(ebone, 1, &points); | fill_add_joint(ebone, 1, &points); | ||||
| check = true; | |||||
| } | |||||
| if (check) { | |||||
| if (arm && (arm != arm_iter)) { | |||||
| mixed_object_error = true; | |||||
| } | |||||
| arm = arm_iter; | |||||
| } | |||||
| } | } | ||||
| CTX_DATA_END; | CTX_DATA_END; | ||||
| /* the number of joints determines how we fill: | /* the number of joints determines how we fill: | ||||
| * 1) between joint and cursor (joint=head, cursor=tail) | * 1) between joint and cursor (joint=head, cursor=tail) | ||||
| * 2) between the two joints (order is dependent on active-bone/hierarchy) | * 2) between the two joints (order is dependent on active-bone/hierarchy) | ||||
| * 3+) error (a smarter method involving finding chains needs to be worked out | * 3+) error (a smarter method involving finding chains needs to be worked out | ||||
| */ | */ | ||||
| count = BLI_listbase_count(&points); | count = BLI_listbase_count(&points); | ||||
| if (count == 0) { | if (count == 0) { | ||||
| BKE_report(op->reports, RPT_ERROR, "No joints selected"); | BKE_report(op->reports, RPT_ERROR, "No joints selected"); | ||||
| return OPERATOR_CANCELLED; | return OPERATOR_CANCELLED; | ||||
| } | } | ||||
| else if (count == 1) { | else if (mixed_object_error) { | ||||
| BKE_report(op->reports, RPT_ERROR, "Bones for different objects selected"); | |||||
| BLI_freelistN(&points); | |||||
| return OPERATOR_CANCELLED; | |||||
| } | |||||
| Object *obedit = NULL; | |||||
| { | |||||
| ViewLayer *view_layer = CTX_data_view_layer(C); | |||||
| FOREACH_OBJECT_IN_MODE_BEGIN (view_layer, OB_MODE_EDIT, ob_iter) { | |||||
| if (ob_iter->data == arm) { | |||||
| obedit = ob_iter; | |||||
| } | |||||
| } | |||||
| FOREACH_OBJECT_IN_MODE_END; | |||||
| } | |||||
| BLI_assert(obedit != NULL); | |||||
| if (count == 1) { | |||||
| EditBonePoint *ebp; | EditBonePoint *ebp; | ||||
| float curs[3]; | float curs[3]; | ||||
| /* Get Points - selected joint */ | /* Get Points - selected joint */ | ||||
| ebp = points.first; | ebp = points.first; | ||||
| /* Get points - cursor (tail) */ | /* Get points - cursor (tail) */ | ||||
| invert_m4_m4(obedit->imat, obedit->obmat); | invert_m4_m4(obedit->imat, obedit->obmat); | ||||
| ▲ Show 20 Lines • Show All 933 Lines • Show Last 20 Lines | |||||