diff options
Diffstat (limited to 'source/blender/editors/armature/armature_add.c')
-rw-r--r-- | source/blender/editors/armature/armature_add.c | 176 |
1 files changed, 88 insertions, 88 deletions
diff --git a/source/blender/editors/armature/armature_add.c b/source/blender/editors/armature/armature_add.c index d80d3d6964c..c1fb1dcf82f 100644 --- a/source/blender/editors/armature/armature_add.c +++ b/source/blender/editors/armature/armature_add.c @@ -66,12 +66,12 @@ EditBone *ED_armature_ebone_add(bArmature *arm, const char *name) { EditBone *bone = MEM_callocN(sizeof(EditBone), "eBone"); - + BLI_strncpy(bone->name, name, sizeof(bone->name)); ED_armature_ebone_unique_name(arm->edbo, bone->name, NULL); - + BLI_addtail(arm->edbo, bone); - + bone->flag |= BONE_TIPSEL; bone->weight = 1.0f; bone->dist = 0.25f; @@ -81,7 +81,7 @@ EditBone *ED_armature_ebone_add(bArmature *arm, const char *name) bone->rad_tail = 0.05f; bone->segments = 1; bone->layer = arm->layer; - + /* Bendy-Bone parameters */ bone->roll1 = 0.0f; bone->roll2 = 0.0f; @@ -103,7 +103,7 @@ EditBone *ED_armature_ebone_add_primitive(Object *obedit_arm, float length, bool EditBone *bone; ED_armature_edit_deselect_all(obedit_arm); - + /* Create a bone */ bone = ED_armature_ebone_add(arm, "Bone"); @@ -134,7 +134,7 @@ static int armature_click_extrude_exec(bContext *C, wmOperator *UNUSED(op)) v3d = CTX_wm_view3d(C); obedit = CTX_data_edit_object(C); arm = obedit->data; - + /* find the active or selected bone */ for (ebone = arm->edbo->first; ebone; ebone = ebone->next) { if (EBONE_VISIBLE(arm, ebone)) { @@ -142,7 +142,7 @@ static int armature_click_extrude_exec(bContext *C, wmOperator *UNUSED(op)) break; } } - + if (ebone == NULL) { for (ebone = arm->edbo->first; ebone; ebone = ebone->next) { if (EBONE_VISIBLE(arm, ebone)) { @@ -150,14 +150,14 @@ static int armature_click_extrude_exec(bContext *C, wmOperator *UNUSED(op)) break; } } - if (ebone == NULL) + if (ebone == NULL) return OPERATOR_CANCELLED; - + to_root = 1; } - + ED_armature_edit_deselect_all(obedit); - + /* we re-use code for mirror editing... */ flipbone = NULL; if (arm->flag & ARM_MIRROR_EDIT) @@ -171,10 +171,10 @@ static int armature_click_extrude_exec(bContext *C, wmOperator *UNUSED(op)) SWAP(EditBone *, flipbone, ebone); } } - + newbone = ED_armature_ebone_add(arm, ebone->name); arm->act_edbone = newbone; - + if (to_root) { copy_v3_v3(newbone->head, ebone->head); newbone->rad_head = ebone->rad_tail; @@ -186,28 +186,28 @@ static int armature_click_extrude_exec(bContext *C, wmOperator *UNUSED(op)) newbone->parent = ebone; newbone->flag |= BONE_CONNECTED; } - + const View3DCursor *curs = ED_view3d_cursor3d_get(scene, v3d); copy_v3_v3(newbone->tail, curs->location); sub_v3_v3v3(newbone->tail, newbone->tail, obedit->obmat[3]); - + if (a == 1) newbone->tail[0] = -newbone->tail[0]; - + copy_m3_m4(mat, obedit->obmat); invert_m3_m3(imat, mat); mul_m3_v3(imat, newbone->tail); - + newbone->length = len_v3v3(newbone->head, newbone->tail); newbone->rad_tail = newbone->length * 0.05f; newbone->dist = newbone->length * 0.25f; - + } - + ED_armature_edit_sync_selection(arm->edbo); WM_event_add_notifier(C, NC_OBJECT | ND_BONE_SELECT, obedit); - + return OPERATOR_FINISHED; } @@ -226,9 +226,9 @@ static int armature_click_extrude_invoke(bContext *C, wmOperator *op, const wmEv scene = CTX_data_scene(C); ar = CTX_wm_region(C); v3d = CTX_wm_view3d(C); - + View3DCursor *cursor = ED_view3d_cursor3d_get(scene, v3d); - + copy_v3_v3(oldcurs, cursor->location); VECCOPY2D(mval_f, event->mval); @@ -250,12 +250,12 @@ void ARMATURE_OT_click_extrude(wmOperatorType *ot) ot->name = "Click-Extrude"; ot->idname = "ARMATURE_OT_click_extrude"; ot->description = "Create a new bone going from the last selected joint to the mouse position"; - + /* api callbacks */ ot->invoke = armature_click_extrude_invoke; ot->exec = armature_click_extrude_exec; ot->poll = ED_operator_editarmature; - + /* flags */ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; @@ -266,12 +266,12 @@ void ARMATURE_OT_click_extrude(wmOperatorType *ot) EditBone *add_points_bone(Object *obedit, float head[3], float tail[3]) { EditBone *ebo; - + ebo = ED_armature_ebone_add(obedit->data, "Bone"); - + copy_v3_v3(ebo->head, head); copy_v3_v3(ebo->tail, tail); - + return ebo; } @@ -377,7 +377,7 @@ void updateDuplicateSubtargetObjects(EditBone *dupBone, ListBase *editbones, Obj bPoseChannel *pchan; bConstraint *curcon; ListBase *conlist; - + if ((pchan = BKE_pose_channel_verify(dst_ob->pose, dupBone->name))) { if ((conlist = &pchan->constraints)) { for (curcon = conlist->first; curcon; curcon = curcon->next) { @@ -387,17 +387,17 @@ void updateDuplicateSubtargetObjects(EditBone *dupBone, ListBase *editbones, Obj const bConstraintTypeInfo *cti = BKE_constraint_typeinfo_get(curcon); ListBase targets = {NULL, NULL}; bConstraintTarget *ct; - + if (cti && cti->get_constraint_targets) { cti->get_constraint_targets(curcon, &targets); - + for (ct = targets.first; ct; ct = ct->next) { if ((ct->tar == src_ob) && (ct->subtarget[0])) { - ct->tar = dst_ob; /* update target */ + ct->tar = dst_ob; /* update target */ oldtarget = get_named_editbone(editbones, ct->subtarget); if (oldtarget) { /* was the subtarget bone duplicated too? If - * so, update the constraint to point at the + * so, update the constraint to point at the * duplicate of the old subtarget. */ if (oldtarget->temp.ebone) { @@ -407,7 +407,7 @@ void updateDuplicateSubtargetObjects(EditBone *dupBone, ListBase *editbones, Obj } } } - + if (cti->flush_constraint_targets) cti->flush_constraint_targets(curcon, &targets, 0); } @@ -426,20 +426,20 @@ EditBone *duplicateEditBoneObjects(EditBone *curBone, const char *name, ListBase Object *src_ob, Object *dst_ob) { EditBone *eBone = MEM_mallocN(sizeof(EditBone), "addup_editbone"); - + /* Copy data from old bone to new bone */ memcpy(eBone, curBone, sizeof(EditBone)); - + curBone->temp.ebone = eBone; eBone->temp.ebone = curBone; - + if (name != NULL) { BLI_strncpy(eBone->name, name, sizeof(eBone->name)); } ED_armature_ebone_unique_name(editbones, eBone->name, NULL); BLI_addtail(editbones, eBone); - + /* copy the ID property */ if (curBone->prop) eBone->prop = IDP_CopyProperty(curBone->prop); @@ -449,7 +449,7 @@ EditBone *duplicateEditBoneObjects(EditBone *curBone, const char *name, ListBase */ if (src_ob->pose) { bPoseChannel *chanold, *channew; - + chanold = BKE_pose_channel_verify(src_ob->pose, curBone->name); if (chanold) { /* WARNING: this creates a new posechannel, but there will not be an attached bone @@ -462,7 +462,7 @@ EditBone *duplicateEditBoneObjects(EditBone *curBone, const char *name, ListBase } } } - + return eBone; } @@ -506,7 +506,7 @@ static int armature_duplicate_selected_exec(bContext *C, wmOperator *op) } } - + /* Find the selected bones and duplicate them as needed */ for (ebone_iter = arm->edbo->first; ebone_iter && ebone_iter != ebone_first_dupe; ebone_iter = ebone_iter->next) { if (EBONE_VISIBLE(arm, ebone_iter) && @@ -567,7 +567,7 @@ static int armature_duplicate_selected_exec(bContext *C, wmOperator *op) updateDuplicateSubtarget(ebone, arm->edbo, obedit); } } - + /* correct the active bone */ if (arm->act_edbone && arm->act_edbone->temp.ebone) { arm->act_edbone = arm->act_edbone->temp.ebone; @@ -585,7 +585,7 @@ static int armature_duplicate_selected_exec(bContext *C, wmOperator *op) ED_armature_edit_validate_active(arm); WM_event_add_notifier(C, NC_OBJECT | ND_BONE_SELECT, obedit); - + return OPERATOR_FINISHED; } @@ -596,11 +596,11 @@ void ARMATURE_OT_duplicate(wmOperatorType *ot) ot->name = "Duplicate Selected Bone(s)"; ot->idname = "ARMATURE_OT_duplicate"; ot->description = "Make copies of the selected bones within the same armature"; - + /* api callbacks */ ot->exec = armature_duplicate_selected_exec; ot->poll = ED_operator_editarmature; - + /* flags */ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; @@ -846,7 +846,7 @@ static int armature_extrude_exec(bContext *C, wmOperator *op) } } } - + /* Duplicate the necessary bones */ for (ebone = arm->edbo->first; ((ebone) && (ebone != first)); ebone = ebone->next) { if (EBONE_VISIBLE(arm, ebone)) { @@ -864,7 +864,7 @@ static int armature_extrude_exec(bContext *C, wmOperator *op) do_extrude = 2; } } - + if (do_extrude) { /* we re-use code for mirror editing... */ flipbone = NULL; @@ -879,7 +879,7 @@ static int armature_extrude_exec(bContext *C, wmOperator *op) if ((flipbone == NULL) && (forked)) flipbone = ebone; } - + for (a = 0; a < 2; a++) { if (a == 1) { if (flipbone == NULL) @@ -888,31 +888,31 @@ static int armature_extrude_exec(bContext *C, wmOperator *op) SWAP(EditBone *, flipbone, ebone); } } - + totbone++; newbone = MEM_callocN(sizeof(EditBone), "extrudebone"); - + if (do_extrude == true) { copy_v3_v3(newbone->head, ebone->tail); copy_v3_v3(newbone->tail, newbone->head); newbone->parent = ebone; - + newbone->flag = ebone->flag & (BONE_TIPSEL | BONE_RELATIVE_PARENTING); // copies it, in case mirrored bone - + if (newbone->parent) newbone->flag |= BONE_CONNECTED; } else { copy_v3_v3(newbone->head, ebone->head); copy_v3_v3(newbone->tail, ebone->head); newbone->parent = ebone->parent; - + newbone->flag = BONE_TIPSEL; - + if (newbone->parent && (ebone->flag & BONE_CONNECTED)) { newbone->flag |= BONE_CONNECTED; } } - + newbone->weight = ebone->weight; newbone->dist = ebone->dist; newbone->xwidth = ebone->xwidth; @@ -921,7 +921,7 @@ static int armature_extrude_exec(bContext *C, wmOperator *op) newbone->rad_tail = ebone->rad_tail; newbone->segments = 1; newbone->layer = ebone->layer; - + /* Bendy-Bone parameters */ newbone->roll1 = ebone->roll1; newbone->roll2 = ebone->roll2; @@ -936,7 +936,7 @@ static int armature_extrude_exec(bContext *C, wmOperator *op) BLI_strncpy(newbone->name, ebone->name, sizeof(newbone->name)); - + if (flipbone && forked) { // only set if mirror edit if (strlen(newbone->name) < (MAXBONENAME - 2)) { if (a == 0) strcat(newbone->name, "_L"); @@ -944,18 +944,18 @@ static int armature_extrude_exec(bContext *C, wmOperator *op) } } ED_armature_ebone_unique_name(arm->edbo, newbone->name, NULL); - + /* Add the new bone to the list */ BLI_addtail(arm->edbo, newbone); if (!first) first = newbone; - + /* restore ebone if we were flipping */ if (a == 1 && flipbone) SWAP(EditBone *, flipbone, ebone); } } - + /* Deselect the old bone */ ebone->flag &= ~(BONE_TIPSEL | BONE_SELECTED | BONE_ROOTSEL); } @@ -986,14 +986,14 @@ void ARMATURE_OT_extrude(wmOperatorType *ot) ot->name = "Extrude"; ot->idname = "ARMATURE_OT_extrude"; ot->description = "Create new bones from the selected joints"; - + /* api callbacks */ ot->exec = armature_extrude_exec; ot->poll = ED_operator_editarmature; - + /* flags */ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; - + /* props */ RNA_def_boolean(ot->srna, "forked", 0, "Forked", ""); } @@ -1002,16 +1002,16 @@ void ARMATURE_OT_extrude(wmOperatorType *ot) /*op makes a new bone and returns it with its tip selected */ -static int armature_bone_primitive_add_exec(bContext *C, wmOperator *op) +static int armature_bone_primitive_add_exec(bContext *C, wmOperator *op) { RegionView3D *rv3d = CTX_wm_region_view3d(C); Object *obedit = CTX_data_edit_object(C); EditBone *bone; float obmat[3][3], curs[3], viewmat[3][3], totmat[3][3], imat[3][3]; char name[MAXBONENAME]; - + RNA_string_get(op->ptr, "name", name); - + copy_v3_v3(curs, ED_view3d_cursor3d_get(CTX_data_scene(C), CTX_wm_view3d(C))->location); /* Get inverse point for head and orientation for tail */ @@ -1021,18 +1021,18 @@ static int armature_bone_primitive_add_exec(bContext *C, wmOperator *op) if (rv3d && (U.flag & USER_ADD_VIEWALIGNED)) copy_m3_m4(obmat, rv3d->viewmat); else unit_m3(obmat); - + copy_m3_m4(viewmat, obedit->obmat); mul_m3_m3m3(totmat, obmat, viewmat); invert_m3_m3(imat, totmat); - + ED_armature_edit_deselect_all(obedit); - + /* Create a bone */ bone = ED_armature_ebone_add(obedit->data, name); copy_v3_v3(bone->head, curs); - + if (rv3d && (U.flag & USER_ADD_VIEWALIGNED)) add_v3_v3v3(bone->tail, bone->head, imat[1]); // bone with unit length 1 else @@ -1050,16 +1050,16 @@ void ARMATURE_OT_bone_primitive_add(wmOperatorType *ot) ot->name = "Add Bone"; ot->idname = "ARMATURE_OT_bone_primitive_add"; ot->description = "Add a new bone located at the 3D-Cursor"; - + /* api callbacks */ ot->exec = armature_bone_primitive_add_exec; ot->poll = ED_operator_editarmature; - + /* flags */ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; - + RNA_def_string(ot->srna, "name", "Bone", MAXBONENAME, "Name", "Name of the newly created bone"); - + } /* ********************** Subdivide *******************************/ @@ -1075,10 +1075,10 @@ static int armature_subdivide_exec(bContext *C, wmOperator *op) Object *obedit = CTX_data_edit_object(C); EditBone *newbone, *tbone; int cuts, i; - + /* there may not be a number_cuts property defined (for 'simple' subdivide) */ cuts = RNA_int_get(op->ptr, "number_cuts"); - + /* loop over all editable bones */ // XXX the old code did this in reverse order though! CTX_DATA_BEGIN_WITH_ID(C, EditBone *, ebone, selected_editable_bones, bArmature *, arm) @@ -1087,37 +1087,37 @@ static int armature_subdivide_exec(bContext *C, wmOperator *op) /* compute cut ratio first */ float cutratio = 1.0f / (float)i; float cutratioI = 1.0f - cutratio; - + float val1[3]; float val2[3]; float val3[3]; - + newbone = MEM_mallocN(sizeof(EditBone), "ebone subdiv"); *newbone = *ebone; BLI_addtail(arm->edbo, newbone); - + /* calculate location of newbone->head */ copy_v3_v3(val1, ebone->head); copy_v3_v3(val2, ebone->tail); copy_v3_v3(val3, newbone->head); - + val3[0] = val1[0] * cutratio + val2[0] * cutratioI; val3[1] = val1[1] * cutratio + val2[1] * cutratioI; val3[2] = val1[2] * cutratio + val2[2] * cutratioI; - + copy_v3_v3(newbone->head, val3); copy_v3_v3(newbone->tail, ebone->tail); copy_v3_v3(ebone->tail, newbone->head); - + newbone->rad_head = ((ebone->rad_head * cutratio) + (ebone->rad_tail * cutratioI)); ebone->rad_tail = newbone->rad_head; - + newbone->flag |= BONE_CONNECTED; newbone->prop = NULL; ED_armature_ebone_unique_name(arm->edbo, newbone->name, NULL); - + /* correct parent bones */ for (tbone = arm->edbo->first; tbone; tbone = tbone->next) { if (tbone->parent == ebone) @@ -1127,10 +1127,10 @@ static int armature_subdivide_exec(bContext *C, wmOperator *op) } } CTX_DATA_END; - + /* note, notifier might evolve */ WM_event_add_notifier(C, NC_OBJECT | ND_BONE_SELECT, obedit); - + return OPERATOR_FINISHED; } @@ -1142,14 +1142,14 @@ void ARMATURE_OT_subdivide(wmOperatorType *ot) ot->name = "Subdivide Multi"; ot->idname = "ARMATURE_OT_subdivide"; ot->description = "Break selected bones into chains of smaller bones"; - + /* api callbacks */ ot->exec = armature_subdivide_exec; ot->poll = ED_operator_editarmature; - + /* flags */ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; - + /* Properties */ prop = RNA_def_int(ot->srna, "number_cuts", 1, 1, 1000, "Number of Cuts", "", 1, 10); /* avoid re-using last var because it can cause _very_ high poly meshes and annoy users (or worse crash) */ |