diff options
Diffstat (limited to 'source/blender/editors/object/object_transform.c')
-rw-r--r-- | source/blender/editors/object/object_transform.c | 70 |
1 files changed, 47 insertions, 23 deletions
diff --git a/source/blender/editors/object/object_transform.c b/source/blender/editors/object/object_transform.c index 9129d651d4d..900bf57b509 100644 --- a/source/blender/editors/object/object_transform.c +++ b/source/blender/editors/object/object_transform.c @@ -171,7 +171,7 @@ static void object_clear_rot(Object *ob) } } } // Duplicated in source/blender/editors/armature/editarmature.c - else { + else { if (ob->rotmode == ROT_MODE_QUAT) { unit_qt(ob->quat); unit_qt(ob->dquat); @@ -217,7 +217,7 @@ static int object_clear_transform_generic_exec(bContext *C, wmOperator *op, /* sanity checks */ if (ELEM(NULL, clear_func, default_ksName)) { - BKE_report(op->reports, RPT_ERROR, "Programming error: missing clear transform func or Keying Set Name"); + BKE_report(op->reports, RPT_ERROR, "Programming error: missing clear transform function or keying set name"); return OPERATOR_CANCELLED; } @@ -381,8 +381,8 @@ static int apply_objects_internal(bContext *C, ReportList *reports, int apply_lo { Main *bmain = CTX_data_main(C); Scene *scene = CTX_data_scene(C); - float rsmat[3][3], tmat[3][3], obmat[3][3], iobmat[3][3], mat[4][4], scale; - int a, change = 1; + float rsmat[3][3], obmat[3][3], iobmat[3][3], mat[4][4], scale; + int change = 1; /* first check if we can execute */ CTX_DATA_BEGIN (C, Object *, ob, selected_editable_objects) @@ -390,19 +390,19 @@ static int apply_objects_internal(bContext *C, ReportList *reports, int apply_lo if (ob->type == OB_MESH) { if (ID_REAL_USERS(ob->data) > 1) { - BKE_report(reports, RPT_ERROR, "Can't apply to a multi user mesh, doing nothing"); + BKE_report(reports, RPT_ERROR, "Cannot apply to a multi user mesh, doing nothing"); change = 0; } } else if (ob->type == OB_ARMATURE) { if (ID_REAL_USERS(ob->data) > 1) { - BKE_report(reports, RPT_ERROR, "Can't apply to a multi user armature, doing nothing"); + BKE_report(reports, RPT_ERROR, "Cannot apply to a multi user armature, doing nothing"); change = 0; } } else if (ob->type == OB_LATTICE) { if (ID_REAL_USERS(ob->data) > 1) { - BKE_report(reports, RPT_ERROR, "Can't apply to a multi user lattice, doing nothing"); + BKE_report(reports, RPT_ERROR, "Cannot apply to a multi user lattice, doing nothing"); change = 0; } } @@ -410,18 +410,19 @@ static int apply_objects_internal(bContext *C, ReportList *reports, int apply_lo Curve *cu; if (ID_REAL_USERS(ob->data) > 1) { - BKE_report(reports, RPT_ERROR, "Can't apply to a multi user curve, doing nothing"); + BKE_report(reports, RPT_ERROR, "Cannot apply to a multi user curve, doing nothing"); change = 0; } cu = ob->data; if (!(cu->flag & CU_3D) && (apply_rot || apply_loc)) { - BKE_report(reports, RPT_ERROR, "Neither rotation nor location could be applied to a 2d curve, doing nothing"); + BKE_report(reports, RPT_ERROR, + "Neither rotation nor location could be applied to a 2D curve, doing nothing"); change = 0; } if (cu->key) { - BKE_report(reports, RPT_ERROR, "Can't apply to a curve with vertex keys, doing nothing"); + BKE_report(reports, RPT_ERROR, "Cannot apply to a curve with vertex keys, doing nothing"); change = 0; } } @@ -464,6 +465,7 @@ static int apply_objects_internal(bContext *C, ReportList *reports, int apply_lo copy_v3_v3(mat[3], ob->loc); if (!(apply_scale && apply_rot)) { + float tmat[3][3]; /* correct for scale and rotation that is still applied */ BKE_object_to_mat3(ob, obmat); invert_m3_m3(iobmat, obmat); @@ -476,6 +478,7 @@ static int apply_objects_internal(bContext *C, ReportList *reports, int apply_lo if (ob->type == OB_MESH) { Mesh *me = ob->data; MVert *mvert; + int a; if (apply_scale) multiresModifier_scale_disp(scene, ob); @@ -518,6 +521,7 @@ static int apply_objects_internal(bContext *C, ReportList *reports, int apply_lo Nurb *nu; BPoint *bp; BezTriple *bezt; + int a; scale = mat3_to_scale(rsmat); @@ -650,7 +654,8 @@ void OBJECT_OT_transform_apply(wmOperatorType *ot) enum { GEOMETRY_TO_ORIGIN = 0, ORIGIN_TO_GEOMETRY, - ORIGIN_TO_CURSOR + ORIGIN_TO_CURSOR, + ORIGIN_TO_CENTER_OF_MASS }; static int object_origin_set_exec(bContext *C, wmOperator *op) @@ -667,7 +672,7 @@ static int object_origin_set_exec(bContext *C, wmOperator *op) int tot_change = 0, tot_lib_error = 0, tot_multiuser_arm_error = 0; if (obedit && centermode != GEOMETRY_TO_ORIGIN) { - BKE_report(op->reports, RPT_ERROR, "Operation cannot be performed in EditMode"); + BKE_report(op->reports, RPT_ERROR, "Operation cannot be performed in edit mode"); return OPERATOR_CANCELLED; } else { @@ -781,6 +786,7 @@ static int object_origin_set_exec(bContext *C, wmOperator *op) Mesh *me = ob->data; if (centermode == ORIGIN_TO_CURSOR) { /* done */ } + else if (centermode == ORIGIN_TO_CENTER_OF_MASS) { BKE_mesh_center_centroid(me, cent); } else if (around == V3D_CENTROID) { BKE_mesh_center_median(me, cent); } else { BKE_mesh_center_bounds(me, cent); } @@ -848,7 +854,7 @@ static int object_origin_set_exec(bContext *C, wmOperator *op) if (ID_REAL_USERS(arm) > 1) { #if 0 - BKE_report(op->reports, RPT_ERROR, "Can't apply to a multi user armature"); + BKE_report(op->reports, RPT_ERROR, "Cannot apply to a multi user armature"); return; #endif tot_multiuser_arm_error++; @@ -861,7 +867,7 @@ static int object_origin_set_exec(bContext *C, wmOperator *op) tot_change++; arm->id.flag |= LIB_DOIT; - /* do_inverse_offset= TRUE; */ /* docenter_armature() handles this */ + /* do_inverse_offset = TRUE; */ /* docenter_armature() handles this */ BKE_object_where_is_calc(scene, ob); BKE_pose_where_is(scene, ob); /* needed for bone parents */ @@ -896,10 +902,17 @@ static int object_origin_set_exec(bContext *C, wmOperator *op) /* offset other selected objects */ if (do_inverse_offset && (centermode != GEOMETRY_TO_ORIGIN)) { + CollectionPointerLink *ctx_link_other; + float obmat[4][4]; + /* was the object data modified * note: the functions above must set 'cent' */ + + /* convert the offset to parent space */ + BKE_object_to_mat4(ob, obmat); copy_v3_v3(centn, cent); - mul_mat3_m4_v3(ob->obmat, centn); /* ommit translation part */ + mul_mat3_m4_v3(obmat, centn); /* omit translation part */ + add_v3_v3(ob->loc, centn); BKE_object_where_is_calc(scene, ob); @@ -910,8 +923,16 @@ static int object_origin_set_exec(bContext *C, wmOperator *op) ignore_parent_tx(bmain, scene, ob); /* other users? */ - CTX_DATA_BEGIN (C, Object *, ob_other, selected_editable_objects) + //CTX_DATA_BEGIN (C, Object *, ob_other, selected_editable_objects) + //{ + + /* use existing context looper */ + for (ctx_link_other = ctx_data_list.first; + ctx_link_other; + ctx_link_other = ctx_link_other->next) { + Object *ob_other = ctx_link_other->ptr.data; + if ((ob_other->flag & OB_DONE) == 0 && ((ob->data && (ob->data == ob_other->data)) || (ob->dup_group == ob_other->dup_group && @@ -931,7 +952,7 @@ static int object_origin_set_exec(bContext *C, wmOperator *op) ignore_parent_tx(bmain, scene, ob_other); } } - CTX_DATA_END; + //CTX_DATA_END; } } } @@ -948,9 +969,9 @@ static int object_origin_set_exec(bContext *C, wmOperator *op) /* Warn if any errors occurred */ if (tot_lib_error + tot_multiuser_arm_error) { - BKE_reportf(op->reports, RPT_WARNING, "%i Object(s) Not Centered, %i Changed:", tot_lib_error + tot_multiuser_arm_error, tot_change); + BKE_reportf(op->reports, RPT_WARNING, "%i object(s) not centered, %i changed:", tot_lib_error + tot_multiuser_arm_error, tot_change); if (tot_lib_error) - BKE_reportf(op->reports, RPT_WARNING, "|%i linked library objects", tot_lib_error); + BKE_reportf(op->reports, RPT_WARNING, "|%i linked library object(s)", tot_lib_error); if (tot_multiuser_arm_error) BKE_reportf(op->reports, RPT_WARNING, "|%i multiuser armature object(s)", tot_multiuser_arm_error); } @@ -962,8 +983,12 @@ void OBJECT_OT_origin_set(wmOperatorType *ot) { static EnumPropertyItem prop_set_center_types[] = { {GEOMETRY_TO_ORIGIN, "GEOMETRY_ORIGIN", 0, "Geometry to Origin", "Move object geometry to object origin"}, - {ORIGIN_TO_GEOMETRY, "ORIGIN_GEOMETRY", 0, "Origin to Geometry", "Move object origin to center of object geometry"}, - {ORIGIN_TO_CURSOR, "ORIGIN_CURSOR", 0, "Origin to 3D Cursor", "Move object origin to position of the 3d cursor"}, + {ORIGIN_TO_GEOMETRY, "ORIGIN_GEOMETRY", 0, "Origin to Geometry", + "Move object origin to center of object geometry"}, + {ORIGIN_TO_CURSOR, "ORIGIN_CURSOR", 0, "Origin to 3D Cursor", + "Move object origin to position of the 3D cursor"}, + {ORIGIN_TO_CENTER_OF_MASS, "ORIGIN_CENTER_OF_MASS", 0, "Origin to Center of Mass", + "Move object origin to the object center of mass (assuming uniform density)"}, {0, NULL, 0, NULL, NULL} }; @@ -975,7 +1000,7 @@ void OBJECT_OT_origin_set(wmOperatorType *ot) /* identifiers */ ot->name = "Set Origin"; - ot->description = "Set the object's origin, by either moving the data, or set to center of data, or use 3d cursor"; + ot->description = "Set the object's origin, by either moving the data, or set to center of data, or use 3D cursor"; ot->idname = "OBJECT_OT_origin_set"; /* api callbacks */ @@ -990,4 +1015,3 @@ void OBJECT_OT_origin_set(wmOperatorType *ot) ot->prop = RNA_def_enum(ot->srna, "type", prop_set_center_types, 0, "Type", ""); RNA_def_enum(ot->srna, "center", prop_set_bounds_types, V3D_CENTROID, "Center", ""); } - |