Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/object/object_constraint.c
| Show First 20 Lines • Show All 1,682 Lines • ▼ Show 20 Lines | if (found == false) { | ||||
| } | } | ||||
| CTX_DATA_END; | CTX_DATA_END; | ||||
| } | } | ||||
| /* if still not found, add a new empty to act as a target (if allowed) */ | /* if still not found, add a new empty to act as a target (if allowed) */ | ||||
| if ((found == false) && (add)) { | if ((found == false) && (add)) { | ||||
| Main *bmain = CTX_data_main(C); | Main *bmain = CTX_data_main(C); | ||||
| Scene *scene = CTX_data_scene(C); | Scene *scene = CTX_data_scene(C); | ||||
| SceneLayer *sl = CTX_data_scene_layer(C); | ViewLayer *view_layer = CTX_data_view_layer(C); | ||||
| Base *base = BASACT(sl), *newbase = NULL; | Base *base = BASACT(view_layer), *newbase = NULL; | ||||
| Object *obt; | Object *obt; | ||||
| /* add new target object */ | /* add new target object */ | ||||
| obt = BKE_object_add(bmain, scene, sl, OB_EMPTY, NULL); | obt = BKE_object_add(bmain, scene, view_layer, OB_EMPTY, NULL); | ||||
| /* set layers OK */ | /* set layers OK */ | ||||
| newbase = BASACT(sl); | newbase = BASACT(view_layer); | ||||
| newbase->lay = base->lay; | newbase->lay = base->lay; | ||||
| obt->lay = newbase->lay; | obt->lay = newbase->lay; | ||||
| /* transform cent to global coords for loc */ | /* transform cent to global coords for loc */ | ||||
| if (pchanact) { | if (pchanact) { | ||||
| /* since by default, IK targets the tip of the last bone, use the tip of the active PoseChannel | /* since by default, IK targets the tip of the last bone, use the tip of the active PoseChannel | ||||
| * if adding a target for an IK Constraint | * if adding a target for an IK Constraint | ||||
| */ | */ | ||||
| if (con_type == CONSTRAINT_TYPE_KINEMATIC) | if (con_type == CONSTRAINT_TYPE_KINEMATIC) | ||||
| mul_v3_m4v3(obt->loc, obact->obmat, pchanact->pose_tail); | mul_v3_m4v3(obt->loc, obact->obmat, pchanact->pose_tail); | ||||
| else | else | ||||
| mul_v3_m4v3(obt->loc, obact->obmat, pchanact->pose_head); | mul_v3_m4v3(obt->loc, obact->obmat, pchanact->pose_head); | ||||
| } | } | ||||
| else { | else { | ||||
| copy_v3_v3(obt->loc, obact->obmat[3]); | copy_v3_v3(obt->loc, obact->obmat[3]); | ||||
| } | } | ||||
| /* restore, BKE_object_add sets active */ | /* restore, BKE_object_add sets active */ | ||||
| BASACT(sl) = base; | BASACT(view_layer) = base; | ||||
| base->flag |= BASE_SELECTED; | base->flag |= BASE_SELECTED; | ||||
| /* make our new target the new object */ | /* make our new target the new object */ | ||||
| *tar_ob = obt; | *tar_ob = obt; | ||||
| found = true; | found = true; | ||||
| } | } | ||||
| /* return whether there's any target */ | /* return whether there's any target */ | ||||
| ▲ Show 20 Lines • Show All 376 Lines • Show Last 20 Lines | |||||