78
80
static void object_clear_loc(Object *ob)
80
82
/* clear location if not locked */
81
if ((ob->protectflag & OB_LOCK_LOCX)==0)
82
ob->loc[0]= ob->dloc[0]= 0.0f;
83
if ((ob->protectflag & OB_LOCK_LOCY)==0)
84
ob->loc[1]= ob->dloc[1]= 0.0f;
85
if ((ob->protectflag & OB_LOCK_LOCZ)==0)
86
ob->loc[2]= ob->dloc[2]= 0.0f;
83
if ((ob->protectflag & OB_LOCK_LOCX) == 0)
84
ob->loc[0] = ob->dloc[0] = 0.0f;
85
if ((ob->protectflag & OB_LOCK_LOCY) == 0)
86
ob->loc[1] = ob->dloc[1] = 0.0f;
87
if ((ob->protectflag & OB_LOCK_LOCZ) == 0)
88
ob->loc[2] = ob->dloc[2] = 0.0f;
89
91
/* clear rotation of object */
90
92
static void object_clear_rot(Object *ob)
92
94
/* clear rotations that aren't locked */
93
if (ob->protectflag & (OB_LOCK_ROTX|OB_LOCK_ROTY|OB_LOCK_ROTZ|OB_LOCK_ROTW)) {
95
if (ob->protectflag & (OB_LOCK_ROTX | OB_LOCK_ROTY | OB_LOCK_ROTZ | OB_LOCK_ROTW)) {
94
96
if (ob->protectflag & OB_LOCK_ROT4D) {
95
97
/* perform clamping on a component by component basis */
96
98
if (ob->rotmode == ROT_MODE_AXISANGLE) {
97
99
if ((ob->protectflag & OB_LOCK_ROTW) == 0)
98
ob->rotAngle= ob->drotAngle= 0.0f;
100
ob->rotAngle = ob->drotAngle = 0.0f;
99
101
if ((ob->protectflag & OB_LOCK_ROTX) == 0)
100
ob->rotAxis[0]= ob->drotAxis[0]= 0.0f;
102
ob->rotAxis[0] = ob->drotAxis[0] = 0.0f;
101
103
if ((ob->protectflag & OB_LOCK_ROTY) == 0)
102
ob->rotAxis[1]= ob->drotAxis[1]= 0.0f;
104
ob->rotAxis[1] = ob->drotAxis[1] = 0.0f;
103
105
if ((ob->protectflag & OB_LOCK_ROTZ) == 0)
104
ob->rotAxis[2]= ob->drotAxis[2]= 0.0f;
106
ob->rotAxis[2] = ob->drotAxis[2] = 0.0f;
106
108
/* check validity of axis - axis should never be 0,0,0 (if so, then we make it rotate about y) */
107
109
if (IS_EQF(ob->rotAxis[0], ob->rotAxis[1]) && IS_EQF(ob->rotAxis[1], ob->rotAxis[2]))
108
110
ob->rotAxis[1] = 1.0f;
109
111
if (IS_EQF(ob->drotAxis[0], ob->drotAxis[1]) && IS_EQF(ob->drotAxis[1], ob->drotAxis[2]))
110
ob->drotAxis[1]= 1.0f;
112
ob->drotAxis[1] = 1.0f;
112
114
else if (ob->rotmode == ROT_MODE_QUAT) {
113
115
if ((ob->protectflag & OB_LOCK_ROTW) == 0)
114
ob->quat[0]= ob->dquat[0]= 1.0f;
116
ob->quat[0] = ob->dquat[0] = 1.0f;
115
117
if ((ob->protectflag & OB_LOCK_ROTX) == 0)
116
ob->quat[1]= ob->dquat[1]= 0.0f;
118
ob->quat[1] = ob->dquat[1] = 0.0f;
117
119
if ((ob->protectflag & OB_LOCK_ROTY) == 0)
118
ob->quat[2]= ob->dquat[2]= 0.0f;
120
ob->quat[2] = ob->dquat[2] = 0.0f;
119
121
if ((ob->protectflag & OB_LOCK_ROTZ) == 0)
120
ob->quat[3]= ob->dquat[3]= 0.0f;
122
ob->quat[3] = ob->dquat[3] = 0.0f;
122
// TODO: does this quat need normalizing now?
124
/* TODO: does this quat need normalizing now? */
125
127
/* the flag may have been set for the other modes, so just ignore the extra flag... */
126
128
if ((ob->protectflag & OB_LOCK_ROTX) == 0)
127
ob->rot[0]= ob->drot[0]= 0.0f;
129
ob->rot[0] = ob->drot[0] = 0.0f;
128
130
if ((ob->protectflag & OB_LOCK_ROTY) == 0)
129
ob->rot[1]= ob->drot[1]= 0.0f;
131
ob->rot[1] = ob->drot[1] = 0.0f;
130
132
if ((ob->protectflag & OB_LOCK_ROTZ) == 0)
131
ob->rot[2]= ob->drot[2]= 0.0f;
133
ob->rot[2] = ob->drot[2] = 0.0f;
135
137
/* perform clamping using euler form (3-components) */
136
// FIXME: deltas are not handled for these cases yet...
138
/* FIXME: deltas are not handled for these cases yet... */
137
139
float eul[3], oldeul[3], quat1[4] = {0};
139
141
if (ob->rotmode == ROT_MODE_QUAT) {
147
149
copy_v3_v3(oldeul, ob->rot);
150
eul[0]= eul[1]= eul[2]= 0.0f;
152
eul[0] = eul[1] = eul[2] = 0.0f;
152
154
if (ob->protectflag & OB_LOCK_ROTX)
154
156
if (ob->protectflag & OB_LOCK_ROTY)
156
158
if (ob->protectflag & OB_LOCK_ROTZ)
159
161
if (ob->rotmode == ROT_MODE_QUAT) {
160
162
eul_to_quat(ob->quat, eul);
161
163
/* quaternions flip w sign to accumulate rotations correctly */
162
if ((quat1[0]<0.0f && ob->quat[0]>0.0f) || (quat1[0]>0.0f && ob->quat[0]<0.0f)) {
164
if ((quat1[0] < 0.0f && ob->quat[0] > 0.0f) || (quat1[0] > 0.0f && ob->quat[0] < 0.0f)) {
163
165
mul_qt_fl(ob->quat, -1.0f);
166
168
else if (ob->rotmode == ROT_MODE_AXISANGLE) {
167
eulO_to_axis_angle(ob->rotAxis, &ob->rotAngle,eul, EULER_ORDER_DEFAULT);
169
eulO_to_axis_angle(ob->rotAxis, &ob->rotAngle, eul, EULER_ORDER_DEFAULT);
170
172
copy_v3_v3(ob->rot, eul);
173
} // Duplicated in source/blender/editors/armature/editarmature.c
175
} // Duplicated in source/blender/editors/armature/editarmature.c
175
177
if (ob->rotmode == ROT_MODE_QUAT) {
176
178
unit_qt(ob->quat);
177
179
unit_qt(ob->dquat);
355
357
ot->poll = ED_operator_scene_editable;
358
ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
360
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
361
363
/*************************** Apply Transformation ****************************/
363
365
/* use this when the loc/size/rot of the parent has changed but the children
364
366
* should stay in the same place, e.g. for apply-size-rot or object center */
365
static void ignore_parent_tx(Main *bmain, Scene *scene, Object *ob )
367
static void ignore_parent_tx(Main *bmain, Scene *scene, Object *ob)
368
370
Object *ob_child;
370
372
/* a change was made, adjust the children to compensate */
371
for (ob_child=bmain->object.first; ob_child; ob_child=ob_child->id.next) {
373
for (ob_child = bmain->object.first; ob_child; ob_child = ob_child->id.next) {
372
374
if (ob_child->parent == ob) {
373
object_apply_mat4(ob_child, ob_child->obmat, TRUE, FALSE);
374
what_does_parent(scene, ob_child, &workob);
375
BKE_object_apply_mat4(ob_child, ob_child->obmat, TRUE, FALSE);
376
BKE_object_workob_calc_parent(scene, ob_child, &workob);
375
377
invert_m4_m4(ob_child->parentinv, workob.obmat);
380
382
static int apply_objects_internal(bContext *C, ReportList *reports, int apply_loc, int apply_rot, int apply_scale)
382
Main *bmain= CTX_data_main(C);
383
Scene *scene= CTX_data_scene(C);
384
float rsmat[3][3], tmat[3][3], obmat[3][3], iobmat[3][3], mat[4][4], scale;
384
Main *bmain = CTX_data_main(C);
385
Scene *scene = CTX_data_scene(C);
386
float rsmat[3][3], obmat[3][3], iobmat[3][3], mat[4][4], scale;
387
389
/* first check if we can execute */
388
CTX_DATA_BEGIN(C, Object*, ob, selected_editable_objects) {
390
CTX_DATA_BEGIN (C, Object *, ob, selected_editable_objects)
390
if (ob->type==OB_MESH) {
393
if (ob->type == OB_MESH) {
391
394
if (ID_REAL_USERS(ob->data) > 1) {
392
BKE_report(reports, RPT_ERROR, "Can't apply to a multi user mesh, doing nothing");
393
return OPERATOR_CANCELLED;
395
BKE_report(reports, RPT_ERROR, "Cannot apply to a multi user mesh, doing nothing");
396
else if (ob->type==OB_ARMATURE) {
399
else if (ob->type == OB_ARMATURE) {
397
400
if (ID_REAL_USERS(ob->data) > 1) {
398
BKE_report(reports, RPT_ERROR, "Can't apply to a multi user armature, doing nothing");
399
return OPERATOR_CANCELLED;
401
BKE_report(reports, RPT_ERROR, "Cannot apply to a multi user armature, doing nothing");
402
405
else if (ob->type == OB_LATTICE) {
403
406
if (ID_REAL_USERS(ob->data) > 1) {
404
BKE_report(reports, RPT_ERROR, "Can't apply to a multi user lattice, doing nothing");
405
return OPERATOR_CANCELLED;
407
BKE_report(reports, RPT_ERROR, "Cannot apply to a multi user lattice, doing nothing");
411
else if (ob->type == OB_MBALL) {
412
if (ID_REAL_USERS(ob->data) > 1) {
413
BKE_report(reports, RPT_ERROR, "Cannot apply to a multi user metaball, doing nothing");
408
417
else if (ELEM(ob->type, OB_CURVE, OB_SURF)) {
411
420
if (ID_REAL_USERS(ob->data) > 1) {
412
BKE_report(reports, RPT_ERROR, "Can't apply to a multi user curve, doing nothing");
413
return OPERATOR_CANCELLED;
421
BKE_report(reports, RPT_ERROR, "Cannot apply to a multi user curve, doing nothing");
418
if (!(cu->flag & CU_3D) && (apply_rot || apply_loc)) {
419
BKE_report(reports, RPT_ERROR, "Neither rotation nor location could be applied to a 2d curve, doing nothing");
420
return OPERATOR_CANCELLED;
427
if (((ob->type == OB_CURVE) && !(cu->flag & CU_3D)) && (apply_rot || apply_loc)) {
428
BKE_report(reports, RPT_ERROR,
429
"Neither rotation nor location could be applied to a 2D curve, doing nothing");
423
BKE_report(reports, RPT_ERROR, "Can't apply to a curve with vertex keys, doing nothing");
424
return OPERATOR_CANCELLED;
433
BKE_report(reports, RPT_ERROR, "Cannot apply to a curve with vertex keys, doing nothing");
441
return OPERATOR_CANCELLED;
430
445
/* now execute */
431
CTX_DATA_BEGIN(C, Object*, ob, selected_editable_objects) {
446
CTX_DATA_BEGIN (C, Object *, ob, selected_editable_objects)
433
449
/* calculate rotation/scale matrix */
434
450
if (apply_scale && apply_rot)
435
object_to_mat3(ob, rsmat);
451
BKE_object_to_mat3(ob, rsmat);
436
452
else if (apply_scale)
437
object_scale_to_mat3(ob, rsmat);
453
BKE_object_scale_to_mat3(ob, rsmat);
438
454
else if (apply_rot) {
439
455
float tmat[3][3], timat[3][3];
441
457
/* simple rotation matrix */
442
object_rot_to_mat3(ob, rsmat);
458
BKE_object_rot_to_mat3(ob, rsmat, TRUE);
444
460
/* correct for scale, note mul_m3_m3m3 has swapped args! */
445
object_scale_to_mat3(ob, tmat);
461
BKE_object_scale_to_mat3(ob, tmat);
446
462
invert_m3_m3(timat, tmat);
447
463
mul_m3_m3m3(rsmat, timat, rsmat);
448
464
mul_m3_m3m3(rsmat, rsmat, tmat);
468
485
/* apply to object data */
469
if (ob->type==OB_MESH) {
486
if (ob->type == OB_MESH) {
473
multiresModifier_scale_disp(scene, ob);
492
multiresModifier_scale_disp(scene, ob);
475
494
/* adjust data */
477
for (a=0; a<me->totvert; a++, mvert++)
496
for (a = 0; a < me->totvert; a++, mvert++)
478
497
mul_m4_v3(mat, mvert->co);
483
for (kb=me->key->block.first; kb; kb=kb->next) {
502
for (kb = me->key->block.first; kb; kb = kb->next) {
503
float *fp = kb->data;
486
for (a=0; a<kb->totelem; a++, fp+=3)
505
for (a = 0; a < kb->totelem; a++, fp += 3)
487
506
mul_m4_v3(mat, fp);
491
510
/* update normals */
492
mesh_calc_normals_mapping(me->mvert, me->totvert, me->mloop, me->mpoly, me->totloop, me->totpoly, NULL, NULL, 0, NULL, NULL);
511
BKE_mesh_calc_normals_mapping(me->mvert, me->totvert, me->mloop, me->mpoly, me->totloop, me->totpoly, NULL, NULL, 0, NULL, NULL);
494
else if (ob->type==OB_ARMATURE) {
513
else if (ob->type == OB_ARMATURE) {
495
514
ED_armature_apply_transform(ob, mat);
497
516
else if (ob->type == OB_LATTICE) {
526
else if (ob->type == OB_MBALL) {
527
MetaBall *mb = ob->data;
528
ED_mball_transform(mb, (float *)mat);
507
530
else if (ELEM(ob->type, OB_CURVE, OB_SURF)) {
531
Curve *cu = ob->data;
514
538
scale = mat3_to_scale(rsmat);
516
for (nu=cu->nurb.first; nu; nu=nu->next) {
540
for (nu = cu->nurb.first; nu; nu = nu->next) {
517
541
if (nu->type == CU_BEZIER) {
519
for (bezt= nu->bezt; a--; bezt++) {
543
for (bezt = nu->bezt; a--; bezt++) {
520
544
mul_m4_v3(mat, bezt->vec[0]);
521
545
mul_m4_v3(mat, bezt->vec[1]);
522
546
mul_m4_v3(mat, bezt->vec[2]);
523
547
bezt->radius *= scale;
549
BKE_nurb_handles_calc(nu);
528
a= nu->pntsu*nu->pntsv;
529
for (bp= nu->bp; a--; bp++)
552
a = nu->pntsu * nu->pntsv;
553
for (bp = nu->bp; a--; bp++)
530
554
mul_m4_v3(mat, bp->vec);
561
585
return OPERATOR_CANCELLED;
563
WM_event_add_notifier(C, NC_OBJECT|ND_TRANSFORM, NULL);
587
WM_event_add_notifier(C, NC_OBJECT | ND_TRANSFORM, NULL);
564
588
return OPERATOR_FINISHED;
567
591
static int visual_transform_apply_exec(bContext *C, wmOperator *UNUSED(op))
569
Scene *scene= CTX_data_scene(C);
593
Scene *scene = CTX_data_scene(C);
572
CTX_DATA_BEGIN(C, Object*, ob, selected_editable_objects) {
573
where_is_object(scene, ob);
574
object_apply_mat4(ob, ob->obmat, TRUE, TRUE);
575
where_is_object(scene, ob);
596
CTX_DATA_BEGIN (C, Object *, ob, selected_editable_objects)
598
BKE_object_where_is_calc(scene, ob);
599
BKE_object_apply_mat4(ob, ob->obmat, TRUE, TRUE);
600
BKE_object_where_is_calc(scene, ob);
577
602
/* update for any children that may get moved */
578
603
DAG_id_tag_update(&ob->id, OB_RECALC_OB);
639
664
/********************* Set Object Center ************************/
642
GEOMETRY_TO_ORIGIN=0,
667
GEOMETRY_TO_ORIGIN = 0,
643
668
ORIGIN_TO_GEOMETRY,
670
ORIGIN_TO_CENTER_OF_MASS
647
673
static int object_origin_set_exec(bContext *C, wmOperator *op)
649
Main *bmain= CTX_data_main(C);
650
Scene *scene= CTX_data_scene(C);
651
Object *obedit= CTX_data_edit_object(C);
675
Main *bmain = CTX_data_main(C);
676
Scene *scene = CTX_data_scene(C);
677
Object *obedit = CTX_data_edit_object(C);
653
float cursor[3], cent[3], cent_neg[3], centn[3], min[3], max[3];
679
float cursor[3], cent[3], cent_neg[3], centn[3];
654
680
int centermode = RNA_enum_get(op->ptr, "type");
655
681
int around = RNA_enum_get(op->ptr, "center"); /* initialized from v3d->around */
657
683
/* keep track of what is changed */
658
int tot_change=0, tot_lib_error=0, tot_multiuser_arm_error=0;
684
int tot_change = 0, tot_lib_error = 0, tot_multiuser_arm_error = 0;
660
686
if (obedit && centermode != GEOMETRY_TO_ORIGIN) {
661
BKE_report(op->reports, RPT_ERROR, "Operation cannot be performed in EditMode");
687
BKE_report(op->reports, RPT_ERROR, "Operation cannot be performed in edit mode");
662
688
return OPERATOR_CANCELLED;
665
691
/* get the view settings if 'around' isn't set and the view is available */
666
View3D *v3d= CTX_wm_view3d(C);
692
View3D *v3d = CTX_wm_view3d(C);
667
693
copy_v3_v3(cursor, give_cursor(scene, v3d));
668
694
if (v3d && !RNA_struct_property_is_set(op->ptr, "center"))
695
around = v3d->around;
675
INIT_MINMAX(min, max);
677
if (obedit->type==OB_MESH) {
678
Mesh *me= obedit->data;
701
if (obedit->type == OB_MESH) {
702
Mesh *me = obedit->data;
679
703
BMEditMesh *em = me->edit_btmesh;
684
707
if (centermode == ORIGIN_TO_CURSOR) {
685
708
copy_v3_v3(cent, cursor);
687
710
mul_m4_v3(obedit->imat, cent);
690
BM_ITER_MESH (eve, &iter, em->bm, BM_VERTS_OF_MESH) {
691
if (around==V3D_CENTROID) {
693
add_v3_v3(cent, eve->co);
694
mul_v3_fl(cent, 1.0f/(float)total);
697
DO_MINMAX(eve->co, min, max);
698
mid_v3_v3v3(cent, min, max);
713
if (around == V3D_CENTROID) {
714
if (em->bm->totvert) {
715
const float total_div = 1.0f / (float)em->bm->totvert;
716
BM_ITER_MESH (eve, &iter, em->bm, BM_VERTS_OF_MESH) {
717
madd_v3_v3fl(cent, eve->co, total_div);
722
float min[3], max[3];
723
INIT_MINMAX(min, max);
724
BM_ITER_MESH (eve, &iter, em->bm, BM_VERTS_OF_MESH) {
725
minmax_v3v3_v3(min, max, eve->co);
727
mid_v3_v3v3(cent, min, max);
707
735
EDBM_mesh_normals_update(em);
709
737
DAG_id_tag_update(&obedit->id, OB_RECALC_DATA);
713
741
/* reset flags */
714
CTX_DATA_BEGIN(C, Object*, ob, selected_editable_objects) {
715
ob->flag &= ~OB_DONE;
742
CTX_DATA_BEGIN (C, Object *, ob, selected_editable_objects)
744
ob->flag &= ~OB_DONE;
719
for (tob= bmain->object.first; tob; tob= tob->id.next) {
748
for (tob = bmain->object.first; tob; tob = tob->id.next) {
721
750
((ID *)tob->data)->flag &= ~LIB_DOIT;
722
751
if (tob->dup_group)
723
752
((ID *)tob->dup_group)->flag &= ~LIB_DOIT;
726
CTX_DATA_BEGIN(C, Object*, ob, selected_editable_objects) {
727
if ((ob->flag & OB_DONE)==0) {
755
CTX_DATA_BEGIN (C, Object *, ob, selected_editable_objects)
757
if ((ob->flag & OB_DONE) == 0) {
728
758
int do_inverse_offset = FALSE;
729
759
ob->flag |= OB_DONE;
737
767
if (ob->data == NULL) {
738
768
/* special support for dupligroups */
739
if ((ob->transflag & OB_DUPLIGROUP) && ob->dup_group && (ob->dup_group->id.flag & LIB_DOIT)==0) {
769
if ((ob->transflag & OB_DUPLIGROUP) && ob->dup_group && (ob->dup_group->id.flag & LIB_DOIT) == 0) {
740
770
if (ob->dup_group->id.lib) {
744
if (centermode == ORIGIN_TO_CURSOR) { /* done */ }
774
if (centermode == ORIGIN_TO_CURSOR) {
778
float min[3], max[3];
746
779
/* only bounds support */
747
780
INIT_MINMAX(min, max);
748
minmax_object_duplis(scene, ob, min, max);
781
BKE_object_minmax_dupli(scene, ob, min, max, TRUE);
749
782
mid_v3_v3v3(cent, min, max);
750
783
invert_m4_m4(ob->imat, ob->obmat);
751
784
mul_m4_v3(ob->imat, cent);
766
if (obedit==NULL && ob->type==OB_MESH) {
799
if (obedit == NULL && ob->type == OB_MESH) {
769
802
if (centermode == ORIGIN_TO_CURSOR) { /* done */ }
770
else if (around==V3D_CENTROID) { mesh_center_median(me, cent); }
771
else { mesh_center_bounds(me, cent); }
803
else if (centermode == ORIGIN_TO_CENTER_OF_MASS) { BKE_mesh_center_centroid(me, cent); }
804
else if (around == V3D_CENTROID) { BKE_mesh_center_median(me, cent); }
805
else { BKE_mesh_center_bounds(me, cent); }
773
807
negate_v3_v3(cent_neg, cent);
774
mesh_translate(me, cent_neg, 1);
808
BKE_mesh_translate(me, cent_neg, 1);
777
811
me->id.flag |= LIB_DOIT;
778
do_inverse_offset= TRUE;
812
do_inverse_offset = TRUE;
780
814
else if (ELEM(ob->type, OB_CURVE, OB_SURF)) {
815
Curve *cu = ob->data;
783
817
if (centermode == ORIGIN_TO_CURSOR) { /* done */ }
784
else if (around==V3D_CENTROID) { curve_center_median(cu, cent); }
785
else { curve_center_bounds(cu, cent); }
818
else if (around == V3D_CENTROID) { BKE_curve_center_median(cu, cent); }
819
else { BKE_curve_center_bounds(cu, cent); }
787
821
/* don't allow Z change if curve is 2D */
788
822
if ((ob->type == OB_CURVE) && !(cu->flag & CU_3D))
791
825
negate_v3_v3(cent_neg, cent);
792
curve_translate(cu, cent_neg, 1);
826
BKE_curve_translate(cu, cent_neg, 1);
795
829
cu->id.flag |= LIB_DOIT;
796
do_inverse_offset= TRUE;
830
do_inverse_offset = TRUE;
799
833
if (centermode == GEOMETRY_TO_ORIGIN) {
818
cent[0]= 0.5f * ( cu->bb->vec[4][0] + cu->bb->vec[0][0]);
819
cent[1]= 0.5f * ( cu->bb->vec[0][1] + cu->bb->vec[2][1]) - 0.5f; /* extra 0.5 is the height o above line */
852
cent[0] = 0.5f * (cu->bb->vec[4][0] + cu->bb->vec[0][0]);
853
cent[1] = 0.5f * (cu->bb->vec[0][1] + cu->bb->vec[2][1]) - 0.5f; /* extra 0.5 is the height o above line */
824
cu->xof= cu->xof - (cent[0] / cu->fsize);
825
cu->yof= cu->yof - (cent[1] / cu->fsize);
858
cu->xof = cu->xof - (cent[0] / cu->fsize);
859
cu->yof = cu->yof - (cent[1] / cu->fsize);
828
862
cu->id.flag |= LIB_DOIT;
829
do_inverse_offset= TRUE;
863
do_inverse_offset = TRUE;
832
else if (ob->type==OB_ARMATURE) {
866
else if (ob->type == OB_ARMATURE) {
833
867
bArmature *arm = ob->data;
835
869
if (ID_REAL_USERS(arm) > 1) {
837
BKE_report(op->reports, RPT_ERROR, "Can't apply to a multi user armature");
871
BKE_report(op->reports, RPT_ERROR, "Cannot apply to a multi user armature");
840
874
tot_multiuser_arm_error++;
916
else if (ob->type == OB_LATTICE) {
917
Lattice *lt = ob->data;
919
if (centermode == ORIGIN_TO_CURSOR) { /* done */ }
920
else if (around == V3D_CENTROID) { BKE_lattice_center_median(lt, cent); }
921
else { BKE_lattice_center_bounds(lt, cent); }
923
negate_v3_v3(cent_neg, cent);
924
BKE_lattice_translate(lt, cent_neg, 1);
927
lt->id.flag |= LIB_DOIT;
928
do_inverse_offset = TRUE;
883
931
/* offset other selected objects */
884
932
if (do_inverse_offset && (centermode != GEOMETRY_TO_ORIGIN)) {
933
CollectionPointerLink *ctx_link_other;
885
936
/* was the object data modified
886
937
* note: the functions above must set 'cent' */
939
/* convert the offset to parent space */
940
BKE_object_to_mat4(ob, obmat);
887
941
copy_v3_v3(centn, cent);
888
mul_mat3_m4_v3(ob->obmat, centn); /* ommit translation part */
942
mul_mat3_m4_v3(obmat, centn); /* omit translation part */
889
944
add_v3_v3(ob->loc, centn);
891
where_is_object(scene, ob);
892
if (ob->type==OB_ARMATURE) {
893
where_is_pose(scene, ob); /* needed for bone parents */
946
BKE_object_where_is_calc(scene, ob);
947
if (ob->type == OB_ARMATURE) {
948
BKE_pose_where_is(scene, ob); /* needed for bone parents */
896
951
ignore_parent_tx(bmain, scene, ob);
898
953
/* other users? */
899
CTX_DATA_BEGIN(C, Object*, ob_other, selected_editable_objects) {
900
if ( (ob_other->flag & OB_DONE)==0 &&
901
( (ob->data && (ob->data == ob_other->data)) ||
902
(ob->dup_group==ob_other->dup_group && (ob->transflag|ob_other->transflag) & OB_DUPLIGROUP) )
954
//CTX_DATA_BEGIN (C, Object *, ob_other, selected_editable_objects)
957
/* use existing context looper */
958
for (ctx_link_other = ctx_data_list.first;
960
ctx_link_other = ctx_link_other->next)
962
Object *ob_other = ctx_link_other->ptr.data;
964
if ((ob_other->flag & OB_DONE) == 0 &&
965
((ob->data && (ob->data == ob_other->data)) ||
966
(ob->dup_group == ob_other->dup_group &&
967
(ob->transflag | ob_other->transflag) & OB_DUPLIGROUP)))
904
969
ob_other->flag |= OB_DONE;
905
DAG_id_tag_update(&ob_other->id, OB_RECALC_OB|OB_RECALC_DATA);
970
DAG_id_tag_update(&ob_other->id, OB_RECALC_OB | OB_RECALC_DATA);
907
972
copy_v3_v3(centn, cent);
908
973
mul_mat3_m4_v3(ob_other->obmat, centn); /* ommit translation part */
909
974
add_v3_v3(ob_other->loc, centn);
911
where_is_object(scene, ob_other);
912
if (ob_other->type==OB_ARMATURE) {
913
where_is_pose(scene, ob_other); /* needed for bone parents */
976
BKE_object_where_is_calc(scene, ob_other);
977
if (ob_other->type == OB_ARMATURE) {
978
BKE_pose_where_is(scene, ob_other); /* needed for bone parents */
915
980
ignore_parent_tx(bmain, scene, ob_other);
924
for (tob= bmain->object.first; tob; tob= tob->id.next)
989
for (tob = bmain->object.first; tob; tob = tob->id.next)
925
990
if (tob->data && (((ID *)tob->data)->flag & LIB_DOIT))
926
DAG_id_tag_update(&tob->id, OB_RECALC_OB|OB_RECALC_DATA);
991
DAG_id_tag_update(&tob->id, OB_RECALC_OB | OB_RECALC_DATA);
928
993
if (tot_change) {
929
994
DAG_ids_flush_update(bmain, 0);
930
WM_event_add_notifier(C, NC_OBJECT|ND_TRANSFORM, NULL);
995
WM_event_add_notifier(C, NC_OBJECT | ND_TRANSFORM, NULL);
933
998
/* Warn if any errors occurred */
934
if (tot_lib_error+tot_multiuser_arm_error) {
935
BKE_reportf(op->reports, RPT_WARNING, "%i Object(s) Not Centered, %i Changed:",tot_lib_error+tot_multiuser_arm_error, tot_change);
999
if (tot_lib_error + tot_multiuser_arm_error) {
1000
BKE_reportf(op->reports, RPT_WARNING, "%i object(s) not centered, %i changed:", tot_lib_error + tot_multiuser_arm_error, tot_change);
936
1001
if (tot_lib_error)
937
BKE_reportf(op->reports, RPT_WARNING, "|%i linked library objects",tot_lib_error);
1002
BKE_reportf(op->reports, RPT_WARNING, "|%i linked library object(s)", tot_lib_error);
938
1003
if (tot_multiuser_arm_error)
939
BKE_reportf(op->reports, RPT_WARNING, "|%i multiuser armature object(s)",tot_multiuser_arm_error);
1004
BKE_reportf(op->reports, RPT_WARNING, "|%i multiuser armature object(s)", tot_multiuser_arm_error);
942
1007
return OPERATOR_FINISHED;
947
1012
static EnumPropertyItem prop_set_center_types[] = {
948
1013
{GEOMETRY_TO_ORIGIN, "GEOMETRY_ORIGIN", 0, "Geometry to Origin", "Move object geometry to object origin"},
949
{ORIGIN_TO_GEOMETRY, "ORIGIN_GEOMETRY", 0, "Origin to Geometry", "Move object origin to center of object geometry"},
950
{ORIGIN_TO_CURSOR, "ORIGIN_CURSOR", 0, "Origin to 3D Cursor", "Move object origin to position of the 3d cursor"},
1014
{ORIGIN_TO_GEOMETRY, "ORIGIN_GEOMETRY", 0, "Origin to Geometry",
1015
"Move object origin to center of object geometry"},
1016
{ORIGIN_TO_CURSOR, "ORIGIN_CURSOR", 0, "Origin to 3D Cursor",
1017
"Move object origin to position of the 3D cursor"},
1018
{ORIGIN_TO_CENTER_OF_MASS, "ORIGIN_CENTER_OF_MASS", 0, "Origin to Center of Mass",
1019
"Move object origin to the object center of mass (assuming uniform density)"},
951
1020
{0, NULL, 0, NULL, NULL}