~ubuntu-branches/ubuntu/trusty/blender/trusty

« back to all changes in this revision

Viewing changes to source/blender/editors/object/object_transform.c

  • Committer: Package Import Robot
  • Author(s): Jeremy Bicha
  • Date: 2013-03-06 12:08:47 UTC
  • mfrom: (1.5.1) (14.1.8 experimental)
  • Revision ID: package-import@ubuntu.com-20130306120847-frjfaryb2zrotwcg
Tags: 2.66a-1ubuntu1
* Resynchronize with Debian (LP: #1076930, #1089256, #1052743, #999024,
  #1122888, #1147084)
* debian/control:
  - Lower build-depends on libavcodec-dev since we're not
    doing the libav9 transition in Ubuntu yet

Show diffs side-by-side

added added

removed removed

Lines of Context:
57
57
#include "BKE_tessmesh.h"
58
58
#include "BKE_multires.h"
59
59
#include "BKE_armature.h"
 
60
#include "BKE_lattice.h"
60
61
 
61
62
#include "RNA_define.h"
62
63
#include "RNA_access.h"
66
67
 
67
68
#include "ED_armature.h"
68
69
#include "ED_keyframing.h"
 
70
#include "ED_mball.h"
69
71
#include "ED_mesh.h"
70
72
#include "ED_screen.h"
71
73
#include "ED_view3d.h"
78
80
static void object_clear_loc(Object *ob)
79
81
{
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;
87
89
}
88
90
 
89
91
/* clear rotation of object */
90
92
static void object_clear_rot(Object *ob)
91
93
{
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;
105
107
                                        
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;
111
113
                        }
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;
121
123
                                        
122
 
                                // TODO: does this quat need normalizing now?
 
124
                                /* TODO: does this quat need normalizing now? */
123
125
                        }
124
126
                        else {
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;
132
134
                        }
133
135
                }
134
136
                else {
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};
138
140
                        
139
141
                        if (ob->rotmode == ROT_MODE_QUAT) {
147
149
                                copy_v3_v3(oldeul, ob->rot);
148
150
                        }
149
151
                        
150
 
                        eul[0]= eul[1]= eul[2]= 0.0f;
 
152
                        eul[0] = eul[1] = eul[2] = 0.0f;
151
153
                        
152
154
                        if (ob->protectflag & OB_LOCK_ROTX)
153
 
                                eul[0]= oldeul[0];
 
155
                                eul[0] = oldeul[0];
154
156
                        if (ob->protectflag & OB_LOCK_ROTY)
155
 
                                eul[1]= oldeul[1];
 
157
                                eul[1] = oldeul[1];
156
158
                        if (ob->protectflag & OB_LOCK_ROTZ)
157
 
                                eul[2]= oldeul[2];
 
159
                                eul[2] = oldeul[2];
158
160
                        
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);
164
166
                                }
165
167
                        }
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);
168
170
                        }
169
171
                        else {
170
172
                                copy_v3_v3(ob->rot, eul);
171
173
                        }
172
174
                }
173
 
        }                                                // Duplicated in source/blender/editors/armature/editarmature.c
174
 
        else { 
 
175
        }                        // Duplicated in source/blender/editors/armature/editarmature.c
 
176
        else {
175
177
                if (ob->rotmode == ROT_MODE_QUAT) {
176
178
                        unit_qt(ob->quat);
177
179
                        unit_qt(ob->dquat);
191
193
static void object_clear_scale(Object *ob)
192
194
{
193
195
        /* clear scale factors which are not locked */
194
 
        if ((ob->protectflag & OB_LOCK_SCALEX)==0) {
195
 
                ob->dscale[0]= 1.0f;
196
 
                ob->size[0]= 1.0f;
197
 
        }
198
 
        if ((ob->protectflag & OB_LOCK_SCALEY)==0) {
199
 
                ob->dscale[1]= 1.0f;
200
 
                ob->size[1]= 1.0f;
201
 
        }
202
 
        if ((ob->protectflag & OB_LOCK_SCALEZ)==0) {
203
 
                ob->dscale[2]= 1.0f;
204
 
                ob->size[2]= 1.0f;
 
196
        if ((ob->protectflag & OB_LOCK_SCALEX) == 0) {
 
197
                ob->dscale[0] = 1.0f;
 
198
                ob->size[0] = 1.0f;
 
199
        }
 
200
        if ((ob->protectflag & OB_LOCK_SCALEY) == 0) {
 
201
                ob->dscale[1] = 1.0f;
 
202
                ob->size[1] = 1.0f;
 
203
        }
 
204
        if ((ob->protectflag & OB_LOCK_SCALEZ) == 0) {
 
205
                ob->dscale[2] = 1.0f;
 
206
                ob->size[2] = 1.0f;
205
207
        }
206
208
}
207
209
 
209
211
 
210
212
/* generic exec for clear-transform operators */
211
213
static int object_clear_transform_generic_exec(bContext *C, wmOperator *op, 
212
 
                void (*clear_func)(Object*), const char default_ksName[])
 
214
                                               void (*clear_func)(Object *), const char default_ksName[])
213
215
{
214
216
        Main *bmain = CTX_data_main(C);
215
 
        Scene *scene= CTX_data_scene(C);
 
217
        Scene *scene = CTX_data_scene(C);
216
218
        KeyingSet *ks;
217
219
        
218
220
        /* sanity checks */
219
221
        if (ELEM(NULL, clear_func, default_ksName)) {
220
 
                BKE_report(op->reports, RPT_ERROR, "Programming error: missing clear transform func or Keying Set Name");
 
222
                BKE_report(op->reports, RPT_ERROR, "Programming error: missing clear transform function or keying set name");
221
223
                return OPERATOR_CANCELLED;
222
224
        }
223
225
        
227
229
        /* operate on selected objects only if they aren't in weight-paint mode 
228
230
         * (so that object-transform clearing won't be applied at same time as bone-clearing)
229
231
         */
230
 
        CTX_DATA_BEGIN(C, Object*, ob, selected_editable_objects) 
 
232
        CTX_DATA_BEGIN (C, Object *, ob, selected_editable_objects)
231
233
        {
232
234
                if (!(ob->mode & OB_MODE_WEIGHT_PAINT)) {
233
235
                        /* run provided clearing function */
244
246
        /* this is needed so children are also updated */
245
247
        DAG_ids_flush_update(bmain, 0);
246
248
 
247
 
        WM_event_add_notifier(C, NC_OBJECT|ND_TRANSFORM, NULL);
 
249
        WM_event_add_notifier(C, NC_OBJECT | ND_TRANSFORM, NULL);
248
250
 
249
251
        return OPERATOR_FINISHED;
250
252
}
269
271
        ot->poll = ED_operator_scene_editable;
270
272
        
271
273
        /* flags */
272
 
        ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
 
274
        ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
273
275
}
274
276
 
275
277
static int object_rotation_clear_exec(bContext *C, wmOperator *op)
289
291
        ot->poll = ED_operator_scene_editable;
290
292
        
291
293
        /* flags */
292
 
        ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
 
294
        ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
293
295
}
294
296
 
295
297
static int object_scale_clear_exec(bContext *C, wmOperator *op)
309
311
        ot->poll = ED_operator_scene_editable;
310
312
        
311
313
        /* flags */
312
 
        ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
 
314
        ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
313
315
}
314
316
 
315
317
/* --------------- */
316
318
 
317
319
static int object_origin_clear_exec(bContext *C, wmOperator *UNUSED(op))
318
320
{
319
 
        Main *bmain= CTX_data_main(C);
 
321
        Main *bmain = CTX_data_main(C);
320
322
        float *v1, *v3;
321
323
        float mat[3][3];
322
324
 
323
 
        CTX_DATA_BEGIN(C, Object*, ob, selected_editable_objects) 
 
325
        CTX_DATA_BEGIN (C, Object *, ob, selected_editable_objects)
324
326
        {
325
327
                if (ob->parent) {
326
328
                        /* vectors pointed to by v1 and v3 will get modified */
327
 
                        v1= ob->loc;
328
 
                        v3= ob->parentinv[3];
 
329
                        v1 = ob->loc;
 
330
                        v3 = ob->parentinv[3];
329
331
                        
330
332
                        copy_m3_m4(mat, ob->parentinv);
331
333
                        negate_v3_v3(v3, v1);
338
340
 
339
341
        DAG_ids_flush_update(bmain, 0);
340
342
        
341
 
        WM_event_add_notifier(C, NC_OBJECT|ND_TRANSFORM, NULL);
 
343
        WM_event_add_notifier(C, NC_OBJECT | ND_TRANSFORM, NULL);
342
344
        
343
345
        return OPERATOR_FINISHED;
344
346
}
355
357
        ot->poll = ED_operator_scene_editable;
356
358
        
357
359
        /* flags */
358
 
        ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
 
360
        ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
359
361
}
360
362
 
361
363
/*************************** Apply Transformation ****************************/
362
364
 
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)
366
368
{
367
369
        Object workob;
368
370
        Object *ob_child;
369
371
        
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);
376
378
                }
377
379
        }
379
381
 
380
382
static int apply_objects_internal(bContext *C, ReportList *reports, int apply_loc, int apply_rot, int apply_scale)
381
383
{
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;
385
 
        int a, change = 0;
 
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
        int change = 1;
386
388
        
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)
 
391
        {
389
392
 
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
                                change = 0;
394
397
                        }
395
398
                }
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
                                change = 0;
400
403
                        }
401
404
                }
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");
 
408
                                change = 0;
 
409
                        }
 
410
                }
 
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");
 
414
                                change = 0;
406
415
                        }
407
416
                }
408
417
                else if (ELEM(ob->type, OB_CURVE, OB_SURF)) {
409
418
                        Curve *cu;
410
419
 
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");
 
422
                                change = 0;
414
423
                        }
415
424
 
416
 
                        cu= ob->data;
 
425
                        cu = ob->data;
417
426
 
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");
 
430
                                change = 0;
421
431
                        }
422
432
                        if (cu->key) {
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");
 
434
                                change = 0;
425
435
                        }
426
436
                }
427
437
        }
428
438
        CTX_DATA_END;
429
439
        
 
440
        if (!change)
 
441
                return OPERATOR_CANCELLED;
 
442
 
 
443
        change = 0;
 
444
 
430
445
        /* now execute */
431
 
        CTX_DATA_BEGIN(C, Object*, ob, selected_editable_objects) {
 
446
        CTX_DATA_BEGIN (C, Object *, ob, selected_editable_objects)
 
447
        {
432
448
 
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];
440
456
 
441
457
                        /* simple rotation matrix */
442
 
                        object_rot_to_mat3(ob, rsmat);
 
458
                        BKE_object_rot_to_mat3(ob, rsmat, TRUE);
443
459
 
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);
457
473
                        copy_v3_v3(mat[3], ob->loc);
458
474
 
459
475
                        if (!(apply_scale && apply_rot)) {
 
476
                                float tmat[3][3];
460
477
                                /* correct for scale and rotation that is still applied */
461
 
                                object_to_mat3(ob, obmat);
 
478
                                BKE_object_to_mat3(ob, obmat);
462
479
                                invert_m3_m3(iobmat, obmat);
463
480
                                mul_m3_m3m3(tmat, rsmat, iobmat);
464
481
                                mul_m3_v3(tmat, mat[3]);
466
483
                }
467
484
 
468
485
                /* apply to object data */
469
 
                if (ob->type==OB_MESH) {
470
 
                        Mesh *me= ob->data;
 
486
                if (ob->type == OB_MESH) {
 
487
                        Mesh *me = ob->data;
471
488
                        MVert *mvert;
 
489
                        int a;
472
490
 
473
 
                        multiresModifier_scale_disp(scene, ob);
 
491
                        if (apply_scale)
 
492
                                multiresModifier_scale_disp(scene, ob);
474
493
                        
475
494
                        /* adjust data */
476
 
                        mvert= me->mvert;
477
 
                        for (a=0; a<me->totvert; a++, mvert++)
 
495
                        mvert = me->mvert;
 
496
                        for (a = 0; a < me->totvert; a++, mvert++)
478
497
                                mul_m4_v3(mat, mvert->co);
479
498
                        
480
499
                        if (me->key) {
481
500
                                KeyBlock *kb;
482
501
                                
483
 
                                for (kb=me->key->block.first; kb; kb=kb->next) {
484
 
                                        float *fp= kb->data;
 
502
                                for (kb = me->key->block.first; kb; kb = kb->next) {
 
503
                                        float *fp = kb->data;
485
504
                                        
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);
488
507
                                }
489
508
                        }
490
509
                        
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);
493
512
                }
494
 
                else if (ob->type==OB_ARMATURE) {
 
513
                else if (ob->type == OB_ARMATURE) {
495
514
                        ED_armature_apply_transform(ob, mat);
496
515
                }
497
516
                else if (ob->type == OB_LATTICE) {
504
523
                                bp++;
505
524
                        }
506
525
                }
 
526
                else if (ob->type == OB_MBALL) {
 
527
                        MetaBall *mb = ob->data;
 
528
                        ED_mball_transform(mb, (float *)mat);
 
529
                }
507
530
                else if (ELEM(ob->type, OB_CURVE, OB_SURF)) {
508
 
                        Curve *cu= ob->data;
 
531
                        Curve *cu = ob->data;
509
532
 
510
533
                        Nurb *nu;
511
534
                        BPoint *bp;
512
535
                        BezTriple *bezt;
 
536
                        int a;
513
537
 
514
538
                        scale = mat3_to_scale(rsmat);
515
539
 
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) {
518
 
                                        a= nu->pntsu;
519
 
                                        for (bezt= nu->bezt; a--; bezt++) {
 
542
                                        a = nu->pntsu;
 
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;
524
548
                                        }
525
 
                                        calchandlesNurb(nu);
 
549
                                        BKE_nurb_handles_calc(nu);
526
550
                                }
527
551
                                else {
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);
531
555
                                }
532
556
                        }
537
561
                if (apply_loc)
538
562
                        zero_v3(ob->loc);
539
563
                if (apply_scale)
540
 
                        ob->size[0]= ob->size[1]= ob->size[2]= 1.0f;
 
564
                        ob->size[0] = ob->size[1] = ob->size[2] = 1.0f;
541
565
                if (apply_rot) {
542
566
                        zero_v3(ob->rot);
543
567
                        unit_qt(ob->quat);
544
568
                        unit_axis_angle(ob->rotAxis, &ob->rotAngle);
545
569
                }
546
570
 
547
 
                where_is_object(scene, ob);
548
 
                if (ob->type==OB_ARMATURE) {
549
 
                        where_is_pose(scene, ob); /* needed for bone parents */
 
571
                BKE_object_where_is_calc(scene, ob);
 
572
                if (ob->type == OB_ARMATURE) {
 
573
                        BKE_pose_where_is(scene, ob); /* needed for bone parents */
550
574
                }
551
575
 
552
576
                ignore_parent_tx(bmain, scene, ob);
553
577
 
554
 
                DAG_id_tag_update(&ob->id, OB_RECALC_OB|OB_RECALC_DATA);
 
578
                DAG_id_tag_update(&ob->id, OB_RECALC_OB | OB_RECALC_DATA);
555
579
 
556
580
                change = 1;
557
581
        }
560
584
        if (!change)
561
585
                return OPERATOR_CANCELLED;
562
586
 
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;
565
589
}
566
590
 
567
591
static int visual_transform_apply_exec(bContext *C, wmOperator *UNUSED(op))
568
592
{
569
 
        Scene *scene= CTX_data_scene(C);
 
593
        Scene *scene = CTX_data_scene(C);
570
594
        int change = 0;
571
595
        
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)
 
597
        {
 
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);
576
601
 
577
602
                /* update for any children that may get moved */
578
603
                DAG_id_tag_update(&ob->id, OB_RECALC_OB);
584
609
        if (!change)
585
610
                return OPERATOR_CANCELLED;
586
611
 
587
 
        WM_event_add_notifier(C, NC_OBJECT|ND_TRANSFORM, NULL);
 
612
        WM_event_add_notifier(C, NC_OBJECT | ND_TRANSFORM, NULL);
588
613
        return OPERATOR_FINISHED;
589
614
}
590
615
 
600
625
        ot->poll = ED_operator_scene_editable;
601
626
        
602
627
        /* flags */
603
 
        ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
 
628
        ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
604
629
}
605
630
 
606
631
static int object_transform_apply_exec(bContext *C, wmOperator *op)
607
632
{
608
 
        const int loc= RNA_boolean_get(op->ptr, "location");
609
 
        const int rot= RNA_boolean_get(op->ptr, "rotation");
610
 
        const int sca= RNA_boolean_get(op->ptr, "scale");
 
633
        const int loc = RNA_boolean_get(op->ptr, "location");
 
634
        const int rot = RNA_boolean_get(op->ptr, "rotation");
 
635
        const int sca = RNA_boolean_get(op->ptr, "scale");
611
636
 
612
637
        if (loc || rot || sca) {
613
638
                return apply_objects_internal(C, op->reports, loc, rot, sca);
629
654
        ot->poll = ED_operator_objectmode;
630
655
 
631
656
        /* flags */
632
 
        ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
 
657
        ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
633
658
 
634
659
        RNA_def_boolean(ot->srna, "location", 0, "Location", "");
635
660
        RNA_def_boolean(ot->srna, "rotation", 0, "Rotation", "");
639
664
/********************* Set Object Center ************************/
640
665
 
641
666
enum {
642
 
        GEOMETRY_TO_ORIGIN=0,
 
667
        GEOMETRY_TO_ORIGIN = 0,
643
668
        ORIGIN_TO_GEOMETRY,
644
 
        ORIGIN_TO_CURSOR
 
669
        ORIGIN_TO_CURSOR,
 
670
        ORIGIN_TO_CENTER_OF_MASS
645
671
};
646
672
 
647
673
static int object_origin_set_exec(bContext *C, wmOperator *op)
648
674
{
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);
652
678
        Object *tob;
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 */
656
682
 
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;
659
685
 
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;
663
689
        }
664
690
        else {
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"))
669
 
                        around= v3d->around;
 
695
                        around = v3d->around;
670
696
        }
671
697
 
672
698
        zero_v3(cent);
673
699
 
674
700
        if (obedit) {
675
 
                INIT_MINMAX(min, max);
676
 
 
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;
680
704
                        BMVert *eve;
681
705
                        BMIter iter;
682
 
                        int total = 0;
683
706
                        
684
707
                        if (centermode == ORIGIN_TO_CURSOR) {
685
708
                                copy_v3_v3(cent, cursor);
687
710
                                mul_m4_v3(obedit->imat, cent);
688
711
                        }
689
712
                        else {
690
 
                                BM_ITER_MESH (eve, &iter, em->bm, BM_VERTS_OF_MESH) {
691
 
                                        if (around==V3D_CENTROID) {
692
 
                                                total++;
693
 
                                                add_v3_v3(cent, eve->co);
694
 
                                                mul_v3_fl(cent, 1.0f/(float)total);
695
 
                                        }
696
 
                                        else {
697
 
                                                DO_MINMAX(eve->co, min, max);
698
 
                                                mid_v3_v3v3(cent, min, max);
699
 
                                        }
 
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);
 
718
                                                }
 
719
                                        }
 
720
                                }
 
721
                                else {
 
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);
 
726
                                        }
 
727
                                        mid_v3_v3v3(cent, min, max);
700
728
                                }
701
729
                        }
702
730
                        
707
735
                        EDBM_mesh_normals_update(em);
708
736
                        tot_change++;
709
737
                        DAG_id_tag_update(&obedit->id, OB_RECALC_DATA);
710
 
            }
 
738
                }
711
739
        }
712
740
 
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)
 
743
        {
 
744
                ob->flag &= ~OB_DONE;
716
745
        }
717
746
        CTX_DATA_END;
718
747
 
719
 
        for (tob= bmain->object.first; tob; tob= tob->id.next) {
 
748
        for (tob = bmain->object.first; tob; tob = tob->id.next) {
720
749
                if (tob->data)
721
750
                        ((ID *)tob->data)->flag &= ~LIB_DOIT;
722
751
                if (tob->dup_group)
723
752
                        ((ID *)tob->dup_group)->flag &= ~LIB_DOIT;
724
753
        }
725
754
 
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)
 
756
        {
 
757
                if ((ob->flag & OB_DONE) == 0) {
728
758
                        int do_inverse_offset = FALSE;
729
759
                        ob->flag |= OB_DONE;
730
760
 
736
766
                        
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) {
741
771
                                                tot_lib_error++;
742
772
                                        }
743
773
                                        else {
744
 
                                                if (centermode == ORIGIN_TO_CURSOR) { /* done */ }
 
774
                                                if (centermode == ORIGIN_TO_CURSOR) {
 
775
                                                        /* done */
 
776
                                                }
745
777
                                                else {
 
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);
755
788
 
756
789
                                                tot_change++;
757
790
                                                ob->dup_group->id.flag |= LIB_DOIT;
758
 
                                                do_inverse_offset= TRUE;
 
791
                                                do_inverse_offset = TRUE;
759
792
                                        }
760
793
                                }
761
794
                        }
763
796
                                tot_lib_error++;
764
797
                        }
765
798
 
766
 
                        if (obedit==NULL && ob->type==OB_MESH) {
767
 
                                Mesh *me= ob->data;
 
799
                        if (obedit == NULL && ob->type == OB_MESH) {
 
800
                                Mesh *me = ob->data;
768
801
 
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); }
772
806
 
773
807
                                negate_v3_v3(cent_neg, cent);
774
 
                                mesh_translate(me, cent_neg, 1);
 
808
                                BKE_mesh_translate(me, cent_neg, 1);
775
809
 
776
810
                                tot_change++;
777
811
                                me->id.flag |= LIB_DOIT;
778
 
                                do_inverse_offset= TRUE;
 
812
                                do_inverse_offset = TRUE;
779
813
                        }
780
814
                        else if (ELEM(ob->type, OB_CURVE, OB_SURF)) {
781
 
                                Curve *cu= ob->data;
 
815
                                Curve *cu = ob->data;
782
816
 
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);   }
786
820
 
787
821
                                /* don't allow Z change if curve is 2D */
788
822
                                if ((ob->type == OB_CURVE) && !(cu->flag & CU_3D))
789
823
                                        cent[2] = 0.0;
790
824
 
791
825
                                negate_v3_v3(cent_neg, cent);
792
 
                                curve_translate(cu, cent_neg, 1);
 
826
                                BKE_curve_translate(cu, cent_neg, 1);
793
827
 
794
828
                                tot_change++;
795
829
                                cu->id.flag |= LIB_DOIT;
796
 
                                do_inverse_offset= TRUE;
 
830
                                do_inverse_offset = TRUE;
797
831
 
798
832
                                if (obedit) {
799
833
                                        if (centermode == GEOMETRY_TO_ORIGIN) {
802
836
                                        break;
803
837
                                }
804
838
                        }
805
 
                        else if (ob->type==OB_FONT) {
 
839
                        else if (ob->type == OB_FONT) {
806
840
                                /* get from bb */
807
841
 
808
 
                                Curve *cu= ob->data;
 
842
                                Curve *cu = ob->data;
809
843
 
810
 
                                if (cu->bb==NULL && (centermode != ORIGIN_TO_CURSOR)) {
 
844
                                if (cu->bb == NULL && (centermode != ORIGIN_TO_CURSOR)) {
811
845
                                        /* do nothing*/
812
846
                                }
813
847
                                else {
815
849
                                                /* done */
816
850
                                        }
817
851
                                        else {
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 */
820
854
                                        }
821
855
 
822
 
                                        cent[2]= 0.0f;
 
856
                                        cent[2] = 0.0f;
823
857
 
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);
826
860
 
827
861
                                        tot_change++;
828
862
                                        cu->id.flag |= LIB_DOIT;
829
 
                                        do_inverse_offset= TRUE;
 
863
                                        do_inverse_offset = TRUE;
830
864
                                }
831
865
                        }
832
 
                        else if (ob->type==OB_ARMATURE) {
 
866
                        else if (ob->type == OB_ARMATURE) {
833
867
                                bArmature *arm = ob->data;
834
868
 
835
869
                                if (ID_REAL_USERS(arm) > 1) {
836
870
#if 0
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");
838
872
                                        return;
839
873
#endif
840
874
                                        tot_multiuser_arm_error++;
847
881
 
848
882
                                        tot_change++;
849
883
                                        arm->id.flag |= LIB_DOIT;
850
 
                                        /* do_inverse_offset= TRUE; */ /* docenter_armature() handles this */
 
884
                                        /* do_inverse_offset = TRUE; */ /* docenter_armature() handles this */
851
885
 
852
 
                                        where_is_object(scene, ob);
853
 
                                        where_is_pose(scene, ob); /* needed for bone parents */
 
886
                                        BKE_object_where_is_calc(scene, ob);
 
887
                                        BKE_pose_where_is(scene, ob); /* needed for bone parents */
854
888
 
855
889
                                        ignore_parent_tx(bmain, scene, ob);
856
890
 
862
896
                                MetaBall *mb = ob->data;
863
897
 
864
898
                                if (centermode == ORIGIN_TO_CURSOR) { /* done */ }
865
 
                                else if (around==V3D_CENTROID) { BKE_metaball_center_median(mb, cent); }
866
 
                                else { BKE_metaball_center_bounds(mb, cent);    }
 
899
                                else if (around == V3D_CENTROID) { BKE_mball_center_median(mb, cent); }
 
900
                                else { BKE_mball_center_bounds(mb, cent);    }
867
901
 
868
902
                                negate_v3_v3(cent_neg, cent);
869
 
                                BKE_metaball_translate(mb, cent_neg);
 
903
                                BKE_mball_translate(mb, cent_neg);
870
904
 
871
905
                                tot_change++;
872
906
                                mb->id.flag |= LIB_DOIT;
873
 
                                do_inverse_offset= TRUE;
 
907
                                do_inverse_offset = TRUE;
874
908
 
875
909
                                if (obedit) {
876
910
                                        if (centermode == GEOMETRY_TO_ORIGIN) {
879
913
                                        break;
880
914
                                }
881
915
                        }
 
916
                        else if (ob->type == OB_LATTICE) {
 
917
                                Lattice *lt = ob->data;
 
918
 
 
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); }
 
922
 
 
923
                                negate_v3_v3(cent_neg, cent);
 
924
                                BKE_lattice_translate(lt, cent_neg, 1);
 
925
 
 
926
                                tot_change++;
 
927
                                lt->id.flag |= LIB_DOIT;
 
928
                                do_inverse_offset = TRUE;
 
929
                        }
882
930
 
883
931
                        /* offset other selected objects */
884
932
                        if (do_inverse_offset && (centermode != GEOMETRY_TO_ORIGIN)) {
 
933
                                CollectionPointerLink *ctx_link_other;
 
934
                                float obmat[4][4];
 
935
 
885
936
                                /* was the object data modified
886
937
                                 * note: the functions above must set 'cent' */
 
938
 
 
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 */
 
943
 
889
944
                                add_v3_v3(ob->loc, centn);
890
945
 
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 */
894
949
                                }
895
950
 
896
951
                                ignore_parent_tx(bmain, scene, ob);
897
952
                                
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) )
903
 
                                        ) {
 
954
                                //CTX_DATA_BEGIN (C, Object *, ob_other, selected_editable_objects)
 
955
                                //{
 
956
 
 
957
                                /* use existing context looper */
 
958
                                for (ctx_link_other = ctx_data_list.first;
 
959
                                     ctx_link_other;
 
960
                                     ctx_link_other = ctx_link_other->next)
 
961
                                {
 
962
                                        Object *ob_other = ctx_link_other->ptr.data;
 
963
 
 
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)))
 
968
                                        {
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);
906
971
 
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);
910
975
 
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 */
914
979
                                                }
915
980
                                                ignore_parent_tx(bmain, scene, ob_other);
916
981
                                        }
917
982
                                }
918
 
                                CTX_DATA_END;
 
983
                                //CTX_DATA_END;
919
984
                        }
920
985
                }
921
986
        }
922
987
        CTX_DATA_END;
923
988
 
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);
927
992
 
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);
931
996
        }
932
997
 
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);
940
1005
        }
941
1006
 
942
1007
        return OPERATOR_FINISHED;
946
1011
{
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}
952
1021
        };
953
1022
        
959
1028
        
960
1029
        /* identifiers */
961
1030
        ot->name = "Set Origin";
962
 
        ot->description = "Set the object's origin, by either moving the data, or set to center of data, or use 3d cursor";
 
1031
        ot->description = "Set the object's origin, by either moving the data, or set to center of data, or use 3D cursor";
963
1032
        ot->idname = "OBJECT_OT_origin_set";
964
1033
        
965
1034
        /* api callbacks */
969
1038
        ot->poll = ED_operator_scene_editable;
970
1039
        
971
1040
        /* flags */
972
 
        ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
 
1041
        ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
973
1042
        
974
1043
        ot->prop = RNA_def_enum(ot->srna, "type", prop_set_center_types, 0, "Type", "");
975
1044
        RNA_def_enum(ot->srna, "center", prop_set_bounds_types, V3D_CENTROID, "Center", "");
976
1045
}
977