diff options
Diffstat (limited to 'source/blender/editors/object/object_transform.c')
-rw-r--r-- | source/blender/editors/object/object_transform.c | 134 |
1 files changed, 88 insertions, 46 deletions
diff --git a/source/blender/editors/object/object_transform.c b/source/blender/editors/object/object_transform.c index d2bbb73b597..4d7d7df0d2f 100644 --- a/source/blender/editors/object/object_transform.c +++ b/source/blender/editors/object/object_transform.c @@ -76,60 +76,87 @@ /*************************** Clear Transformation ****************************/ /* clear location of object */ -static void object_clear_loc(Object *ob) +static void object_clear_loc(Object *ob, const bool clear_delta) { /* clear location if not locked */ - if ((ob->protectflag & OB_LOCK_LOCX) == 0) - ob->loc[0] = ob->dloc[0] = 0.0f; - if ((ob->protectflag & OB_LOCK_LOCY) == 0) - ob->loc[1] = ob->dloc[1] = 0.0f; - if ((ob->protectflag & OB_LOCK_LOCZ) == 0) - ob->loc[2] = ob->dloc[2] = 0.0f; + if ((ob->protectflag & OB_LOCK_LOCX) == 0) { + ob->loc[0] = 0.0f; + if (clear_delta) ob->dloc[0] = 0.0f; + } + if ((ob->protectflag & OB_LOCK_LOCY) == 0) { + ob->loc[1] = 0.0f; + if (clear_delta) ob->dloc[1] = 0.0f; + } + if ((ob->protectflag & OB_LOCK_LOCZ) == 0) { + ob->loc[2] = 0.0f; + if (clear_delta) ob->dloc[2] = 0.0f; + } } /* clear rotation of object */ -static void object_clear_rot(Object *ob) +static void object_clear_rot(Object *ob, const bool clear_delta) { /* clear rotations that aren't locked */ if (ob->protectflag & (OB_LOCK_ROTX | OB_LOCK_ROTY | OB_LOCK_ROTZ | OB_LOCK_ROTW)) { if (ob->protectflag & OB_LOCK_ROT4D) { /* perform clamping on a component by component basis */ if (ob->rotmode == ROT_MODE_AXISANGLE) { - if ((ob->protectflag & OB_LOCK_ROTW) == 0) - ob->rotAngle = ob->drotAngle = 0.0f; - if ((ob->protectflag & OB_LOCK_ROTX) == 0) - ob->rotAxis[0] = ob->drotAxis[0] = 0.0f; - if ((ob->protectflag & OB_LOCK_ROTY) == 0) - ob->rotAxis[1] = ob->drotAxis[1] = 0.0f; - if ((ob->protectflag & OB_LOCK_ROTZ) == 0) - ob->rotAxis[2] = ob->drotAxis[2] = 0.0f; + if ((ob->protectflag & OB_LOCK_ROTW) == 0) { + ob->rotAngle = 0.0f; + if (clear_delta) ob->drotAngle = 0.0f; + } + if ((ob->protectflag & OB_LOCK_ROTX) == 0) { + ob->rotAxis[0] = 0.0f; + if (clear_delta) ob->drotAxis[0] = 0.0f; + } + if ((ob->protectflag & OB_LOCK_ROTY) == 0) { + ob->rotAxis[1] = 0.0f; + if (clear_delta) ob->drotAxis[1] = 0.0f; + } + if ((ob->protectflag & OB_LOCK_ROTZ) == 0) { + ob->rotAxis[2] = 0.0f; + if (clear_delta) ob->drotAxis[2] = 0.0f; + } /* check validity of axis - axis should never be 0,0,0 (if so, then we make it rotate about y) */ if (IS_EQF(ob->rotAxis[0], ob->rotAxis[1]) && IS_EQF(ob->rotAxis[1], ob->rotAxis[2])) ob->rotAxis[1] = 1.0f; - if (IS_EQF(ob->drotAxis[0], ob->drotAxis[1]) && IS_EQF(ob->drotAxis[1], ob->drotAxis[2])) + if (IS_EQF(ob->drotAxis[0], ob->drotAxis[1]) && IS_EQF(ob->drotAxis[1], ob->drotAxis[2]) && clear_delta) ob->drotAxis[1] = 1.0f; } else if (ob->rotmode == ROT_MODE_QUAT) { - if ((ob->protectflag & OB_LOCK_ROTW) == 0) - ob->quat[0] = ob->dquat[0] = 1.0f; - if ((ob->protectflag & OB_LOCK_ROTX) == 0) - ob->quat[1] = ob->dquat[1] = 0.0f; - if ((ob->protectflag & OB_LOCK_ROTY) == 0) - ob->quat[2] = ob->dquat[2] = 0.0f; - if ((ob->protectflag & OB_LOCK_ROTZ) == 0) - ob->quat[3] = ob->dquat[3] = 0.0f; - + if ((ob->protectflag & OB_LOCK_ROTW) == 0) { + ob->quat[0] = 1.0f; + if (clear_delta) ob->dquat[0] = 1.0f; + } + if ((ob->protectflag & OB_LOCK_ROTX) == 0) { + ob->quat[1] = 0.0f; + if (clear_delta) ob->dquat[1] = 0.0f; + } + if ((ob->protectflag & OB_LOCK_ROTY) == 0) { + ob->quat[2] = 0.0f; + if (clear_delta) ob->dquat[2] = 0.0f; + } + if ((ob->protectflag & OB_LOCK_ROTZ) == 0) { + ob->quat[3] = 0.0f; + if (clear_delta) ob->dquat[3] = 0.0f; + } /* TODO: does this quat need normalizing now? */ } else { /* the flag may have been set for the other modes, so just ignore the extra flag... */ - if ((ob->protectflag & OB_LOCK_ROTX) == 0) - ob->rot[0] = ob->drot[0] = 0.0f; - if ((ob->protectflag & OB_LOCK_ROTY) == 0) - ob->rot[1] = ob->drot[1] = 0.0f; - if ((ob->protectflag & OB_LOCK_ROTZ) == 0) - ob->rot[2] = ob->drot[2] = 0.0f; + if ((ob->protectflag & OB_LOCK_ROTX) == 0) { + ob->rot[0] = 0.0f; + if (clear_delta) ob->drot[0] = 0.0f; + } + if ((ob->protectflag & OB_LOCK_ROTY) == 0) { + ob->rot[1] = 0.0f; + if (clear_delta) ob->drot[1] = 0.0f; + } + if ((ob->protectflag & OB_LOCK_ROTZ) == 0) { + ob->rot[2] = 0.0f; + if (clear_delta) ob->drot[2] = 0.0f; + } } } else { @@ -175,34 +202,34 @@ static void object_clear_rot(Object *ob) else { if (ob->rotmode == ROT_MODE_QUAT) { unit_qt(ob->quat); - unit_qt(ob->dquat); + if (clear_delta) unit_qt(ob->dquat); } else if (ob->rotmode == ROT_MODE_AXISANGLE) { unit_axis_angle(ob->rotAxis, &ob->rotAngle); - unit_axis_angle(ob->drotAxis, &ob->drotAngle); + if (clear_delta) unit_axis_angle(ob->drotAxis, &ob->drotAngle); } else { zero_v3(ob->rot); - zero_v3(ob->drot); + if (clear_delta) zero_v3(ob->drot); } } } /* clear scale of object */ -static void object_clear_scale(Object *ob) +static void object_clear_scale(Object *ob, const bool clear_delta) { /* clear scale factors which are not locked */ if ((ob->protectflag & OB_LOCK_SCALEX) == 0) { - ob->dscale[0] = 1.0f; ob->size[0] = 1.0f; + if (clear_delta) ob->dscale[0] = 1.0f; } if ((ob->protectflag & OB_LOCK_SCALEY) == 0) { - ob->dscale[1] = 1.0f; ob->size[1] = 1.0f; + if (clear_delta) ob->dscale[1] = 1.0f; } if ((ob->protectflag & OB_LOCK_SCALEZ) == 0) { - ob->dscale[2] = 1.0f; ob->size[2] = 1.0f; + if (clear_delta) ob->dscale[2] = 1.0f; } } @@ -210,10 +237,12 @@ static void object_clear_scale(Object *ob) /* generic exec for clear-transform operators */ static int object_clear_transform_generic_exec(bContext *C, wmOperator *op, - void (*clear_func)(Object *), const char default_ksName[]) + void (*clear_func)(Object *, const bool), + const char default_ksName[]) { Scene *scene = CTX_data_scene(C); KeyingSet *ks; + const bool clear_delta = RNA_boolean_get(op->ptr, "clear_delta"); /* sanity checks */ if (ELEM(NULL, clear_func, default_ksName)) { @@ -231,10 +260,10 @@ static int object_clear_transform_generic_exec(bContext *C, wmOperator *op, { if (!(ob->mode & OB_MODE_WEIGHT_PAINT)) { /* run provided clearing function */ - clear_func(ob); - + clear_func(ob, clear_delta); + ED_autokeyframe_object(C, scene, ob, ks); - + /* tag for updates */ DAG_id_tag_update(&ob->id, OB_RECALC_OB); } @@ -268,6 +297,11 @@ void OBJECT_OT_location_clear(wmOperatorType *ot) /* flags */ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; + + + /* properties */ + ot->prop = RNA_def_boolean(ot->srna, "clear_delta", false, "Clear Delta", + "Clear delta location in addition to clearing the normal location transform"); } static int object_rotation_clear_exec(bContext *C, wmOperator *op) @@ -288,6 +322,10 @@ void OBJECT_OT_rotation_clear(wmOperatorType *ot) /* flags */ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; + + /* properties */ + ot->prop = RNA_def_boolean(ot->srna, "clear_delta", false, "Clear Delta", + "Clear delta rotation in addition to clearing the normal rotation transform"); } static int object_scale_clear_exec(bContext *C, wmOperator *op) @@ -308,6 +346,10 @@ void OBJECT_OT_scale_clear(wmOperatorType *ot) /* flags */ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; + + /* properties */ + ot->prop = RNA_def_boolean(ot->srna, "clear_delta", false, "Clear Delta", + "Clear delta scale in addition to clearing the normal scale transform"); } /* --------------- */ @@ -391,7 +433,7 @@ static int apply_objects_internal(bContext *C, ReportList *reports, bool apply_l changed = false; } - if (obdata->lib) { + if (ID_IS_LINKED_DATABLOCK(obdata)) { BKE_reportf(reports, RPT_ERROR, "Cannot apply to library data: Object \"%s\", %s \"%s\", aborting", ob->id.name + 2, BKE_idcode_to_name(GS(obdata->name)), obdata->name + 2); @@ -792,7 +834,7 @@ static int object_origin_set_exec(bContext *C, wmOperator *op) if (ob->data == NULL) { /* special support for dupligroups */ if ((ob->transflag & OB_DUPLIGROUP) && ob->dup_group && (ob->dup_group->id.tag & LIB_TAG_DOIT) == 0) { - if (ob->dup_group->id.lib) { + if (ID_IS_LINKED_DATABLOCK(ob->dup_group)) { tot_lib_error++; } else { @@ -817,7 +859,7 @@ static int object_origin_set_exec(bContext *C, wmOperator *op) } } } - else if (((ID *)ob->data)->lib) { + else if (ID_IS_LINKED_DATABLOCK(ob->data)) { tot_lib_error++; } |