Blender V5.3
transform_convert_object.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2001-2002 NaN Holding BV. All rights reserved.
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include "MEM_guardedalloc.h"
10
11#include "BLI_listbase.hh"
12#include "BLI_math_matrix_c.hh"
14#include "BLI_math_vector_c.hh"
15
16#include "BKE_context.hh"
17#include "BKE_duplilist.hh"
18#include "BKE_layer.hh"
19#include "BKE_lib_id.hh"
20#include "BKE_library.hh"
21#include "BKE_object.hh"
22#include "BKE_pointcache.h"
23#include "BKE_rigidbody.h"
24#include "BKE_scene.hh"
25
26#include "ANIM_action.hh"
27#include "ANIM_keyframing.hh"
28#include "ANIM_rna.hh"
29
30#include "ED_anim_api.hh"
31#include "ED_object.hh"
32
34
35#include "transform.hh"
37#include "transform_snap.hh"
38
39/* Own include. */
40#include "transform_convert.hh"
41
42namespace blender::ed::transform {
43
44/* -------------------------------------------------------------------- */
47
64
66 TransDataContainer * /*tc*/,
67 TransCustomData *custom_data)
68{
69 TransDataObject *tdo = static_cast<TransDataObject *>(custom_data->data);
70 custom_data->data = nullptr;
71
74 }
75
78 }
79 MEM_delete(tdo);
80}
81
83
84/* -------------------------------------------------------------------- */
93
95{
96 TransDataObject *tdo = static_cast<TransDataObject *>(t->custom.type.data);
97 if (tdo->xds == nullptr) {
98 return;
99 }
100
101 Main *bmain = CTX_data_main(t->context);
103}
104
106
107/* -------------------------------------------------------------------- */
116
118{
119 TransDataObject *tdo = static_cast<TransDataObject *>(t->custom.type.data);
120 if (tdo->xcs == nullptr) {
121 return;
122 }
123
124 Main *bmain = CTX_data_main(t->context);
126}
127
129
130/* -------------------------------------------------------------------- */
133
138{
139 Scene *scene = t->scene;
140 bool constinv;
141 bool skip_invert = false;
142
143 if (t->mode != TFM_DUMMY && ob->rigidbody_object) {
144 float rot[3][3], scale[3];
145 float ctime = BKE_scene_ctime_get(scene);
146
147 /* Only use rigid body transform if simulation is running,
148 * avoids problems with initial setup of rigid bodies. */
150
151 /* Save original object transform. */
152 copy_v3_v3(td_ext->oloc, ob->loc);
153
154 if (ob->rotmode > 0) {
155 copy_v3_v3(td_ext->orot, ob->rot);
156 }
157 else if (ob->rotmode == ROT_MODE_AXISANGLE) {
158 td_ext->orotAngle = ob->rotAngle;
159 copy_v3_v3(td_ext->orotAxis, ob->rotAxis);
160 }
161 else {
162 copy_qt_qt(td_ext->oquat, ob->quat);
163 }
164 /* Update object's loc/rot to get current rigid body transform. */
165 mat4_to_loc_rot_size(ob->loc, rot, scale, ob->object_to_world().ptr());
166 sub_v3_v3(ob->loc, ob->dloc);
167 BKE_object_mat3_to_rot(ob, rot, false); /* `drot` is already corrected here. */
168 }
169 }
170
171 /* `axismtx` has the real orientation. */
172 transform_orientations_create_from_axis(td->axismtx, UNPACK3(ob->object_to_world().ptr()));
173 if (t->orient_type_mask & (1 << V3D_ORIENT_GIMBAL)) {
174 if (!gimbal_axis_object(ob, td_ext->axismtx_gimbal)) {
175 copy_m3_m3(td_ext->axismtx_gimbal, td->axismtx);
176 }
177 }
178
179 td->con = ob->constraints.first();
180
181 /* HACK: temporarily disable tracking and/or constraints when getting
182 * object matrix, if tracking is on, or if constraints don't need
183 * inverse correction to stop it from screwing up space conversion
184 * matrix later. */
185 constinv = constraints_list_needinv(t, &ob->constraints);
186
187 /* Disable constraints inversion for dummy pass. */
188 if (t->mode == TFM_DUMMY) {
189 skip_invert = true;
190 }
191
192 /* NOTE: This is not really following copy-on-evaluation design and we should not
193 * be re-evaluating the evaluated object. But as the comment above mentioned
194 * this is part of a hack.
195 * More proper solution would be to make a shallow copy of the object and
196 * evaluate that, and access matrix of that evaluated copy of the object.
197 * Might be more tricky than it sounds, if some logic later on accesses the
198 * object matrix via td->ob->object_to_world().ptr(). */
199 Object *object_eval = DEG_get_evaluated(t->depsgraph, ob);
200 if (skip_invert == false && constinv == false) {
201 object_eval->transflag |= OB_NO_CONSTRAINTS; /* #BKE_object_where_is_calc checks this. */
202 /* It is possible to have transform data initialization prior to a
203 * complete dependency graph evaluated. Happens, for example, when
204 * changing transformation mode. */
205 BKE_object_tfm_copy(object_eval, ob);
206 BKE_object_where_is_calc(t->depsgraph, t->scene, object_eval);
207 object_eval->transflag &= ~OB_NO_CONSTRAINTS;
208 }
209 else {
210 BKE_object_where_is_calc(t->depsgraph, t->scene, object_eval);
211 }
212 /* Copy newly evaluated fields to the original object, similar to how
213 * active dependency graph will do it. */
214 copy_m4_m4(ob->runtime->object_to_world.ptr(), object_eval->object_to_world().ptr());
215 /* Only copy negative scale flag, this is the only flag which is modified by
216 * the BKE_object_where_is_calc(). The rest of the flags we need to keep,
217 * otherwise we might lose dupli flags (see #61787). */
219 ob->transflag |= (object_eval->transflag & OB_NEG_SCALE);
220
221 td->extra = ob;
222 td->loc = ob->loc;
223 copy_v3_v3(td->iloc, td->loc);
224
225 if (ob->rotmode > 0) {
226 td_ext->rot = ob->rot;
227 td_ext->rotAxis = nullptr;
228 td_ext->rotAngle = nullptr;
229 td_ext->quat = nullptr;
230
231 copy_v3_v3(td_ext->irot, ob->rot);
232 copy_v3_v3(td_ext->drot, ob->drot);
233 }
234 else if (ob->rotmode == ROT_MODE_AXISANGLE) {
235 td_ext->rot = nullptr;
236 td_ext->rotAxis = ob->rotAxis;
237 td_ext->rotAngle = &ob->rotAngle;
238 td_ext->quat = nullptr;
239
240 td_ext->irotAngle = ob->rotAngle;
241 copy_v3_v3(td_ext->irotAxis, ob->rotAxis);
242/* XXX, not implemented. */
243#if 0
244 td_ext->drotAngle = ob->drotAngle;
245 copy_v3_v3(td_ext->drotAxis, ob->drotAxis);
246#endif
247 }
248 else {
249 td_ext->rot = nullptr;
250 td_ext->rotAxis = nullptr;
251 td_ext->rotAngle = nullptr;
252 td_ext->quat = ob->quat;
253
254 copy_qt_qt(td_ext->iquat, ob->quat);
255 copy_qt_qt(td_ext->dquat, ob->dquat);
256 }
257 td_ext->rotOrder = ob->rotmode;
258
259 td_ext->scale = ob->scale;
260 copy_v3_v3(td_ext->iscale, ob->scale);
261 copy_v3_v3(td_ext->dscale, ob->dscale);
262
263 copy_v3_v3(td->center, ob->object_to_world().location());
264
265 copy_m4_m4(td_ext->obmat, ob->object_to_world().ptr());
266
267 /* Is there a need to set the global<->data space conversion matrices? */
268 if (ob->parent || constinv) {
269 float obmtx[3][3], totmat[3][3], obinv[3][3];
270
271 /* Get the effect of parenting, and/or certain constraints.
272 * NOTE: some Constraints, and also Tracking should never get this
273 * done, as it doesn't work well.
274 */
275 BKE_object_to_mat3(ob, obmtx);
276 copy_m3_m4(totmat, ob->object_to_world().ptr());
277
278 /* If the object scale is zero on any axis, this might result in a zero matrix.
279 * In this case, the transformation would not do anything, see: #50103. */
280 orthogonalize_m3_zero_axes(obmtx, 1.0f);
281 orthogonalize_m3_zero_axes(totmat, 1.0f);
282
283 /* Use safe invert even though the input matrices have had zero axes set to unit length,
284 * in the unlikely case of failure (float precision for eg) this uses unit matrix fallback. */
285 invert_m3_m3_safe_ortho(obinv, totmat);
286 mul_m3_m3m3(td->smtx, obmtx, obinv);
288 }
289 else {
290 /* No conversion to/from data-space. */
291 unit_m3(td->smtx);
292 unit_m3(td->mtx);
293 }
294}
295
297 const Scene *scene,
298 ViewLayer *view_layer)
299{
301 return;
302 }
303 BKE_view_layer_synced_ensure(*t->bmain, scene, view_layer);
304 for (Base &base : *BKE_view_layer_object_bases_get(view_layer)) {
305 base.object->id.tag &= ~ID_TAG_DOIT;
306 }
307}
308
310{
311 /* Here we only handle object IDs. */
312 if (GS(id->name) != ID_OB) {
313 return;
314 }
315 if (component == DEG_OB_COMP_GEOMETRY) {
316 id->tag |= ID_TAG_DOIT;
317 }
318}
319
321{
322 /* Here we only handle object IDs. */
323 if (GS(id->name) != ID_OB) {
324 return;
325 }
327 return;
328 }
329 id->tag |= ID_TAG_DOIT;
330}
331
333{
335 return;
336 }
337 object->id.tag |= ID_TAG_DOIT;
338
340 t->depsgraph,
341 &object->id,
344
345 /* When we transform parents while skipping children, we only traverse the GEOMETRY-dependent
346 * components. This avoids marking children as not participating in snapping but still marks
347 * objects with modifier dependencies.
348 * Unfortunately, some transform-dependent objects that are not children may also be skipped,
349 * such as constrained ones.
350 * See #121378 for details. */
353}
354
356 const Scene *scene,
357 ViewLayer *view_layer)
358{
360 return;
361 }
362 BKE_view_layer_synced_ensure(*t->bmain, scene, view_layer);
363 for (Base &base : *BKE_view_layer_object_bases_get(view_layer)) {
364 if (base.object->id.tag & ID_TAG_DOIT) {
365 base.flag_legacy |= BA_SNAP_FIX_DEPS_FIASCO;
366 }
367 }
368}
369
375{
376 Main *bmain = CTX_data_main(t->context);
377 ViewLayer *view_layer = t->view_layer;
378 View3D *v3d = static_cast<View3D *>(t->view);
379 Scene *scene = t->scene;
380 Depsgraph *depsgraph = BKE_scene_ensure_depsgraph(bmain, scene, view_layer);
381 /* NOTE: if Base selected and has parent selected:
382 * base->flag_legacy = BA_WAS_SEL
383 */
384 /* Don't do it if we're not actually going to recalculate anything. */
385 if (t->mode == TFM_DUMMY) {
386 return;
387 }
388 /* Makes sure base flags and object flags are identical. */
390 /* Make sure depsgraph is here. */
392 /* Clear all flags we need. It will be used to detect dependencies. */
393 trans_object_base_deps_flag_prepare(t, scene, view_layer);
394 /* Traverse all bases and set all possible flags. */
395 BKE_view_layer_synced_ensure(*t->bmain, scene, view_layer);
396 for (Base &base : *BKE_view_layer_object_bases_get(view_layer)) {
397 base.flag_legacy &= ~(BA_WAS_SEL | BA_TRANSFORM_LOCKED_IN_PLACE);
398 if (BASE_SELECTED_EDITABLE(v3d, &base)) {
399 Object *ob = base.object;
400 Object *parsel = ob->parent;
401 /* If parent selected, deselect. */
402 while (parsel != nullptr) {
403 if (parsel->base_flag & BASE_SELECTED) {
404 Base *parbase = BKE_view_layer_base_find(view_layer, parsel);
405 if (parbase != nullptr) { /* In rare cases this can fail. */
406 if (BASE_SELECTED_EDITABLE(v3d, parbase)) {
407 break;
408 }
409 }
410 }
411 parsel = parsel->parent;
412 }
413 if (parsel != nullptr) {
414 /* Rotation around local centers are allowed to propagate. */
416 {
417 base.flag_legacy |= BA_TRANSFORM_CHILD;
418 }
419 else {
420 base.flag &= ~BASE_SELECTED;
421 base.flag_legacy |= BA_WAS_SEL;
422 }
423 }
425 }
426 }
427 /* Store temporary bits in base indicating that base is being modified
428 * (directly or indirectly) by transforming objects.
429 */
430 trans_object_base_deps_flag_finish(t, scene, view_layer);
431}
432
433static bool mark_children(Object *ob)
434{
435 if (ob->flag & (SELECT | BA_TRANSFORM_CHILD)) {
436 return true;
437 }
438
439 if (ob->parent) {
440 if (mark_children(ob->parent)) {
442 return true;
443 }
444 }
445
446 return false;
447}
448
450{
451 int total = 0;
452 ViewLayer *view_layer = t->view_layer;
453 View3D *v3d = static_cast<View3D *>(t->view);
454 Scene *scene = t->scene;
455 /* Clear all flags we need. It will be used to detect dependencies. */
456 trans_object_base_deps_flag_prepare(t, scene, view_layer);
457 /* Rotations around local centers are allowed to propagate, so we take all objects. */
459 /* Mark all parents. */
460 for (Base &base : *BKE_view_layer_object_bases_get(view_layer)) {
461 if (BASE_SELECTED_EDITABLE(v3d, &base) && BASE_SELECTABLE(v3d, &base)) {
462 Object *parent = base.object->parent;
463 /* Flag all parents. */
464 while (parent != nullptr) {
465 parent->flag |= BA_TRANSFORM_PARENT;
466 parent = parent->parent;
467 }
468 }
469 }
470 /* Mark all children. */
471 for (Base &base : *BKE_view_layer_object_bases_get(view_layer)) {
472 /* All base not already selected or marked that is editable. */
473 if ((base.object->flag & (BA_TRANSFORM_CHILD | BA_TRANSFORM_PARENT)) == 0 &&
474 (base.flag & BASE_SELECTED) == 0 &&
475 (BASE_EDITABLE(v3d, &base) && BASE_SELECTABLE(v3d, &base)))
476 {
477 mark_children(base.object);
478 }
479 }
480 }
481 /* Flush changed flags to all dependencies. */
482 for (Base &base : *BKE_view_layer_object_bases_get(view_layer)) {
483 Object *ob = base.object;
484 /* If base is not selected, not a parent of selection or not a child of
485 * selection and it is editable and selectable.
486 */
487 if ((ob->flag & (BA_TRANSFORM_CHILD | BA_TRANSFORM_PARENT)) == 0 &&
488 (base.flag & BASE_SELECTED) == 0 &&
489 (BASE_EDITABLE(v3d, &base) && BASE_SELECTABLE(v3d, &base)))
490 {
492 total += 1;
493 }
494 }
495 /* Store temporary bits in base indicating that base is being modified
496 * (directly or indirectly) by transforming objects.
497 */
498 trans_object_base_deps_flag_finish(t, scene, view_layer);
499 return total;
500}
501
503{
504 Scene *scene = t->scene;
505 ViewLayer *view_layer = t->view_layer;
506
507 BKE_view_layer_synced_ensure(*t->bmain, scene, view_layer);
508 for (Base &base : *BKE_view_layer_object_bases_get(view_layer)) {
509 if (base.flag_legacy & BA_WAS_SEL) {
511 }
512
515 }
516}
517
519{
520 Main *bmain = CTX_data_main(C);
521 TransData *td = nullptr;
523 const bool is_prop_edit = (t->flag & T_PROP_EDIT) != 0;
524
526
528
529 /* Count. */
530 tc->data_len = CTX_DATA_COUNT(C, selected_bases);
531
532 if (!tc->data_len) {
533 /* Clear here, main transform function escapes too. */
535 return;
536 }
537
538 if (is_prop_edit) {
540 }
541
542 td = tc->data = MEM_new_array_zeroed<TransData>(tc->data_len, "TransOb");
543 tx = tc->data_ext = MEM_new_array_zeroed<TransDataExtension>(tc->data_len, "TransObExtension");
544
546 t->custom.type.data = tdo;
548
551 }
552
553 CTX_DATA_BEGIN (C, Base *, base, selected_bases) {
554 Object *ob = base->object;
555
556 td->flag = TD_SELECTED;
557 td->protectflag = ob->protectflag;
558 tx->rotOrder = ob->rotmode;
559
560 if (base->flag_legacy & BA_TRANSFORM_CHILD) {
561 td->flag |= TD_NOCENTER;
562 td->flag |= TD_NO_LOC;
563 }
564
565 /* Select linked objects, but skip them later. */
566 if (!BKE_id_is_editable(bmain, &ob->id)) {
567 td->flag |= TD_SKIP;
568 }
569
571 ID *id = ob->data;
572 if (!id || id->lib) {
573 td->flag |= TD_SKIP;
574 }
575 else if (BKE_object_is_in_editmode(ob)) {
576 /* NOTE(@ideasman42): The object could have edit-mode data from another view-layer,
577 * it's such a corner-case it can be skipped for now. */
578 td->flag |= TD_SKIP;
579 }
580 }
581
583 if ((td->flag & TD_SKIP) == 0) {
585 }
586 }
587
588 ObjectToTransData(t, td, tx, ob);
589 td->val = nullptr;
590 td++;
591 tx++;
592 }
594
595 if (is_prop_edit) {
596 Scene *scene = t->scene;
597 ViewLayer *view_layer = t->view_layer;
598 View3D *v3d = static_cast<View3D *>(t->view);
599
600 BKE_view_layer_synced_ensure(*t->bmain, scene, view_layer);
601 for (Base &base : *BKE_view_layer_object_bases_get(view_layer)) {
602 Object *ob = base.object;
603
604 /* If base is not selected, not a parent of selection
605 * or not a child of selection and it is editable and selectable. */
606 if ((ob->flag & (BA_TRANSFORM_CHILD | BA_TRANSFORM_PARENT)) == 0 &&
607 (base.flag & BASE_SELECTED) == 0 && BASE_EDITABLE(v3d, &base) &&
608 BASE_SELECTABLE(v3d, &base))
609 {
610 td->protectflag = ob->protectflag;
611 tx->rotOrder = ob->rotmode;
612
613 ObjectToTransData(t, td, tx, ob);
614 td->val = nullptr;
615 td++;
616 tx++;
617 }
618 }
619 }
620
622 Set<Object *> objects_in_transdata;
623 td = tc->data;
624 for (int i = 0; i < tc->data_len; i++, td++) {
625 if ((td->flag & TD_SKIP) == 0) {
626 objects_in_transdata.add(static_cast<Object *>(td->extra));
627 }
628 }
629
630 Scene *scene = t->scene;
631 ViewLayer *view_layer = t->view_layer;
632 View3D *v3d = static_cast<View3D *>(t->view);
633
634 BKE_view_layer_synced_ensure(*t->bmain, scene, view_layer);
635 for (Base &base : *BKE_view_layer_object_bases_get(view_layer)) {
636 Object *ob = base.object;
637
638 /* If base is not selected, not a parent of selection
639 * or not a child of selection and it is editable and selectable. */
640 if ((base.flag_legacy & BA_WAS_SEL) && (base.flag & BASE_SELECTED) == 0 &&
641 BASE_EDITABLE(v3d, &base) && BASE_SELECTABLE(v3d, &base))
642 {
643
644 Object *ob_parent = ob->parent;
645 if (ob_parent != nullptr) {
646 if (!objects_in_transdata.contains(ob)) {
647 bool parent_in_transdata = false;
648 while (ob_parent != nullptr) {
649 if (objects_in_transdata.contains(ob_parent)) {
650 parent_in_transdata = true;
651 break;
652 }
653 ob_parent = ob_parent->parent;
654 }
655 if (parent_in_transdata) {
657 }
658 }
659 }
660 }
661 }
662 }
663
665
667
668#define BASE_XFORM_INDIRECT(base) \
669\
670 (((base)->flag_legacy & BA_WAS_SEL) && ((base)->flag & BASE_SELECTED) == 0)
671
672 Set<Object *> objects_in_transdata;
673 Map<Object *, Object *> objects_parent_root;
674 objects_parent_root.reserve(tc->data_len);
675 td = tc->data;
676 for (int i = 0; i < tc->data_len; i++, td++) {
677 if ((td->flag & TD_SKIP) == 0) {
678 objects_in_transdata.add(static_cast<Object *>(td->extra));
679 }
680 }
681
682 Scene *scene = t->scene;
683 ViewLayer *view_layer = t->view_layer;
684
685 BKE_view_layer_synced_ensure(*t->bmain, scene, view_layer);
686 for (Base &base : *BKE_view_layer_object_bases_get(view_layer)) {
687 Object *ob = base.object;
688 if (ob->parent != nullptr) {
689 if (ob->parent && !objects_in_transdata.contains(ob->parent) &&
690 !objects_in_transdata.contains(ob))
691 {
692 if ((base.flag_legacy & BA_WAS_SEL) && (base.flag & BASE_SELECTED) == 0) {
693 Base *base_parent = BKE_view_layer_base_find(view_layer, ob->parent);
694 if (base_parent && !BASE_XFORM_INDIRECT(base_parent)) {
695 Object *ob_parent_recurse = ob->parent;
696 if (ob_parent_recurse != nullptr) {
697 while (ob_parent_recurse != nullptr) {
698 if (objects_in_transdata.contains(ob_parent_recurse)) {
699 break;
700 }
701 ob_parent_recurse = ob_parent_recurse->parent;
702 }
703
704 if (ob_parent_recurse) {
706 tdo->xcs, ob, ob_parent_recurse, object::XFORM_OB_SKIP_CHILD_PARENT_APPLY);
707 objects_parent_root.add(ob, ob_parent_recurse);
708 base.flag_legacy |= BA_TRANSFORM_LOCKED_IN_PLACE;
709 base.flag_legacy &= ~BA_SNAP_FIX_DEPS_FIASCO;
710 }
711 }
712 }
713 }
714 }
715 }
716 }
717
718 for (Base &base : *BKE_view_layer_object_bases_get(view_layer)) {
719 Object *ob = base.object;
720
721 if (BASE_XFORM_INDIRECT(&base) || objects_in_transdata.contains(ob)) {
722 /* Pass. */
723 }
724 else if (ob->parent != nullptr) {
725 Base *base_parent = BKE_view_layer_base_find(view_layer, ob->parent);
726 if (base_parent) {
727 if (BASE_XFORM_INDIRECT(base_parent) || objects_in_transdata.contains(ob->parent)) {
730 base.flag_legacy |= BA_TRANSFORM_LOCKED_IN_PLACE;
731 base.flag_legacy &= ~BA_SNAP_FIX_DEPS_FIASCO;
732 }
733 else {
734 Object *ob_parent_recurse = objects_parent_root.lookup_default(ob->parent, nullptr);
735 if (ob_parent_recurse) {
737 tdo->xcs,
738 ob,
739 ob_parent_recurse,
741 }
742 }
743 }
744 }
745 }
746
747#undef BASE_XFORM_INDIRECT
748 }
749}
750
752
753/* -------------------------------------------------------------------- */
756
757/* Return if we need to update motion paths, only if they already exist,
758 * and we will insert a keyframe at the end of transform. */
760{
761 /* XXX: there's potential here for problems with unkeyed rotations/scale,
762 * but for now (until proper data-locality for baking operations),
763 * this should be a better fix for #24451 and #37755
764 */
765
766 if (animrig::autokeyframe_cfra_can_key(scene, &ob->id)) {
767 return (ob->avs.path_bakeflag & MOTIONPATH_BAKE_HAS_PATHS) != 0;
768 }
769
770 return false;
771}
772
774
775/* -------------------------------------------------------------------- */
778
779/* Given the transform mode `tmode` return a Vector of RNA paths that were possibly modified during
780 * that transformation. */
782 const Main &bmain,
783 const eTfmMode tmode,
784 Scene *scene,
785 ViewLayer *view_layer,
786 Object *ob,
787 const StringRef rotation_path,
788 const bool transforming_more_than_one_object)
789{
790 Vector<RNAPath> rna_paths;
791
792 /* Handle the cases where we always need to key location, regardless of
793 * transform mode. */
795 BKE_view_layer_synced_ensure(bmain, scene, view_layer);
796 if (ob != BKE_view_layer_active_object_get(view_layer)) {
797 rna_paths.append({"location"});
798 }
799 }
800 else if (transforming_more_than_one_object &&
802 {
803 rna_paths.append({"location"});
804 }
806 rna_paths.append({"location"});
807 }
808
809 /* Handle the transform-mode-specific cases. */
810 switch (tmode) {
811 case TFM_TRANSLATION:
812 rna_paths.append_non_duplicates({"location"});
813 break;
814
815 case TFM_ROTATION:
816 case TFM_TRACKBALL:
817 if ((scene->toolsettings->transform_flag & SCE_XFORM_AXIS_ALIGN) == 0) {
818 rna_paths.append({rotation_path});
819 }
820 break;
821
822 case TFM_RESIZE:
823 if ((scene->toolsettings->transform_flag & SCE_XFORM_AXIS_ALIGN) == 0) {
824 rna_paths.append({"scale"});
825 }
826 break;
827
828 default:
829 rna_paths.append_non_duplicates({"location"});
830 rna_paths.append({rotation_path});
831 rna_paths.append({"scale"});
832 }
833
834 return rna_paths;
835}
836
838 Scene *scene,
839 Object *ob,
840 const eTfmMode tmode,
841 const bool transforming_more_than_one_object)
842{
843 Vector<RNAPath> rna_paths;
844 ViewLayer *view_layer = CTX_data_view_layer(C);
846
848 const Main *bmain = CTX_data_main(C);
850 *bmain, tmode, scene, view_layer, ob, rotation_path, transforming_more_than_one_object);
851 }
852 else {
853 rna_paths = {{"location"}, {rotation_path}, {"scale"}};
854 }
855 animrig::autokeyframe_object(C, scene, ob, rna_paths.as_span());
856}
857
859{
860 if (t->state != TRANS_CANCEL) {
862 }
863 Set<Object *> motionpath_updates;
865 TransData *td = tc->data;
866
867 for (int i = 0; i < tc->data_len; i++, td++) {
868 Object *ob = static_cast<Object *>(td->extra);
869 if (td->flag & TD_SKIP) {
870 continue;
871 }
872
873 /* If animtimer is running, and the object already has animation data,
874 * check if the auto-record feature means that we should record 'samples'
875 * (i.e. uneditable animation values). */
876
877 /* TODO: auto-keyframe calls need some setting to specify to add samples
878 * (FPoints) instead of keyframes? */
879 if ((t->animtimer) && animrig::is_autokey_on(t->scene)) {
880 animrecord_check_state(t, &ob->id);
881 autokeyframe_object(t->context, t->scene, ob, t->mode, t->data_len_all > 1);
882 }
883
885 motionpath_updates.add(ob);
886 }
887
888 /* Sets recalc flags fully, instead of flushing existing ones
889 * otherwise proxies don't function correctly. */
891 }
892 }
893
894 if (!motionpath_updates.is_empty()) {
895 Depsgraph *evaluated_dg = CTX_data_ensure_evaluated_depsgraph(t->context);
896 for (Object *ob : motionpath_updates) {
897 MPathTarget mpt;
898 mpt.mpath = ob->mpath;
899 mpt.ob = ob;
900 animviz_update_motionpath_preview(*evaluated_dg, {mpt});
901 }
902 }
903
906 }
907
910 }
911}
912
914
915/* -------------------------------------------------------------------- */
918
920{
922
923 Object *ob;
924 const bool canceled = (t->state == TRANS_CANCEL);
925
927 bool motionpath_update = false;
928
929 if (animrig::is_autokey_on(t->scene) && !canceled) {
931 }
932
933 VectorSet<Object *> modified_objects;
934 for (int i = 0; i < tc->data_len; i++) {
935 TransData *td = tc->data + i;
936 TransDataExtension *td_ext = tc->data_ext + i;
937 ListBaseT<PTCacheID> pidlist;
938 ob = static_cast<Object *>(td->extra);
939 modified_objects.add(ob);
940
941 if (td->flag & TD_SKIP) {
942 continue;
943 }
944
945 /* Flag object caches as outdated. */
947 for (PTCacheID &pid : pidlist) {
948 if (pid.type != PTCACHE_TYPE_PARTICLES) {
949 /* Particles don't need reset on geometry change. */
950 pid.cache->flag |= PTCACHE_OUTDATED;
951 }
952 }
953 pidlist.free_no_destruct();
954
955 /* Point-cache refresh. */
958 }
959
960 /* Needed for proper updating of "quick cached" dynamics.
961 * Creates troubles for moving animated objects without
962 * auto-key though, probably needed is an animation-system override?
963 * NOTE(@jahka): Please remove if some other solution is found. */
965
966 /* Set auto-key if necessary. */
967 if (!canceled) {
968 autokeyframe_object(C, t->scene, ob, t->mode, tc->data_len > 1);
969 }
970
972 motionpath_update = true;
973 MPathTarget mpt;
974 mpt.mpath = ob->mpath;
975 mpt.ob = ob;
977 }
978
979 /* Restore rigid body transform. */
980 if (ob->rigidbody_object && canceled) {
981 float ctime = BKE_scene_ctime_get(t->scene);
984 ob, td_ext->oloc, td_ext->orot, td_ext->oquat, td_ext->orotAxis, td_ext->orotAngle);
985 }
986 }
987 }
988
989 if (!canceled && motionpath_update) {
990 /* Update motion paths once for all transformed objects. */
991 object::motion_paths_recalc(C, t->scene, modified_objects);
992 }
993
995}
996
998
1000 /*flags*/ 0,
1001 /*create_trans_data*/ createTransObject,
1002 /*recalc_data*/ recalcData_objects,
1003 /*special_aftertrans_update*/ special_aftertrans_update__object,
1004};
1005
1006} // namespace blender::ed::transform
Functions and classes to work with Actions.
Functions to insert, delete or modify keyframes.
Helper functions for animation to interact with the RNA system.
#define CTX_DATA_BEGIN(C, Type, instance, member)
#define CTX_DATA_COUNT(C, member)
#define CTX_DATA_END
#define SELECT
Definition BKE_mask.hh:19
General operations, lookup, etc. for blender objects.
#define PTCACHE_TYPE_PARTICLES
#define PTCACHE_RESET_OUTDATED
API for Blender-side Rigid Body stuff.
#define BASE_SELECTED_EDITABLE(v3d, base)
#define BASE_EDITABLE(v3d, base)
Read Blender memory allocation and freeing.
#define C
Definition RandGen.cpp:29
#define UNPACK3(a)
#define ELEM(...)
bool add(const Key &key, const Value &value)
Definition BLI_map.hh:295
Value lookup_default(const Key &key, const Value &default_value) const
Definition BLI_map.hh:570
void reserve(int64_t n)
Definition BLI_map.hh:1028
bool contains(const Key &key) const
Definition BLI_set.hh:310
bool add(const Key &key)
Definition BLI_set.hh:248
bool is_empty() const
Definition BLI_set.hh:614
bool add(const Key &key)
void append(const T &value)
void append_non_duplicates(const T &value)
Span< T > as_span() const
#define rot(x, k)
float3x3 scale(float3x3 mat, float2 scale)
bool is_autokey_on(const Scene *scene)
bool autokeyframe_cfra_can_key(const Scene *scene, ID *id)
StringRefNull get_rotation_mode_path(eRotationModes rotation_mode)
Definition anim_rna.cc:109
void autokeyframe_object(bContext *C, const Scene *scene, Object *ob, Span< RNAPath > rna_paths)
bool is_keying_flag(const Scene *scene, eKeying_Flag flag)
void motion_paths_recalc(bContext *C, Scene *scene, const Span< Object * > objects)
@ XFORM_OB_SKIP_CHILD_PARENT_IS_XFORM
Definition ED_object.hh:147
@ XFORM_OB_SKIP_CHILD_PARENT_IS_XFORM_INDIRECT
Definition ED_object.hh:152
void data_xform_container_destroy(XFormObjectData_Container *xds)
void base_select(Base *base, eObjectSelect_Mode mode)
XFormObjectSkipChild_Container * xform_skip_child_container_create()
void data_xform_container_update_all(XFormObjectData_Container *xds, Main *bmain, Depsgraph *depsgraph)
void object_xform_skip_child_container_destroy(XFormObjectSkipChild_Container *xcs)
void object_xform_skip_child_container_item_ensure(XFormObjectSkipChild_Container *xcs, Object *ob, Object *ob_parent_recurse, int mode)
void data_xform_container_item_ensure(XFormObjectData_Container *xds, Object *ob)
void object_xform_skip_child_container_update_all(XFormObjectSkipChild_Container *xcs, Main *bmain, Depsgraph *depsgraph)
XFormObjectData_Container * data_xform_container_create()
static void trans_obdata_in_obmode_update_all(TransInfo *t)
static int count_proportional_objects(TransInfo *t)
static void freeTransObjectCustomData(TransInfo *t, TransDataContainer *, TransCustomData *custom_data)
void animrecord_check_state(TransInfo *t, ID *id)
static void ObjectToTransData(TransInfo *t, TransData *td, TransDataExtension *td_ext, Object *ob)
static Vector< RNAPath > get_affected_rna_paths_from_transform_mode(const eTfmMode tmode, ToolSettings *toolsettings, const StringRef rotation_path, const bool targetless_ik, const bool is_connected, const bool transforming_more_than_one_bone)
static void special_aftertrans_update__object(bContext *C, TransInfo *t)
void transform_snap_project_individual_apply(TransInfo *t)
bool constraints_list_needinv(TransInfo *t, ListBaseT< bConstraint > *list)
static void autokeyframe_object(bContext *C, Scene *scene, Object *ob, const eTfmMode tmode, const bool transforming_more_than_one_object)
static void recalcData_objects(TransInfo *t)
static void flush_trans_object_base_deps_flag(const TransInfo *t, Object *object)
static void tag_trans_objects_dep_fn(ID *id, eDepsObjectComponentType component)
static void createTransObject(bContext *C, TransInfo *t)
static bool motionpath_need_update_object(Scene *scene, Object *ob)
static void set_trans_object_base_flags(TransInfo *t)
static void tag_trans_objects_with_geometry_dep_only_fn(ID *id, eDepsObjectComponentType component)
bool transform_orientations_create_from_axis(float mat[3][3], const float x[3], const float y[3], const float z[3])
static bool mark_children(Object *ob)
TransConvertTypeInfo TransConvertType_Object
static void trans_object_base_deps_flag_prepare(const TransInfo *t, const Scene *scene, ViewLayer *view_layer)
bool gimbal_axis_object(Object *ob, float gmat[3][3])
static void trans_object_base_deps_flag_finish(const TransInfo *t, const Scene *scene, ViewLayer *view_layer)
static void clear_trans_object_base_flags(TransInfo *t)
static void trans_obchild_in_obmode_update_all(TransInfo *t)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
void mat4_to_loc_rot_size(float loc[3], float rot[3][3], float size[3], const float wmat[4][4])
void BKE_object_tfm_copy(Object *object_dst, const Object *object_src)
Definition object.cc:3088
void animviz_clear_motionpath_preview(Span< MPathTarget > targets)
Object * BKE_view_layer_active_object_get(const ViewLayer *view_layer)
void BKE_rigidbody_aftertrans_update(struct Object *ob, float loc[3], float rot[3], float quat[4], float rotAxis[3], float rotAngle)
int BKE_ptcache_object_reset(struct Scene *scene, struct Object *ob, int mode)
MINLINE void copy_v3_v3(float r[3], const float a[3])
void copy_m3_m4(float m1[3][3], const float m2[4][4])
void copy_m3_m3(float m1[3][3], const float m2[3][3])
bool BKE_rigidbody_check_sim_running(struct RigidBodyWorld *rbw, float ctime)
@ BA_SNAP_FIX_DEPS_FIASCO
@ BA_TRANSFORM_LOCKED_IN_PLACE
@ V3D_AROUND_LOCAL_ORIGINS
bool orthogonalize_m3_zero_axes(float m[3][3], float unit_length)
ViewLayer * CTX_data_view_layer(const bContext *C)
MINLINE void sub_v3_v3(float r[3], const float a[3])
void * MEM_new_zeroed(size_t len, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1) ATTR_NONNULL(2)
void copy_qt_qt(float q[4], const float a[4])
void DEG_id_tag_update(ID *id, unsigned int flags)
T * DEG_get_evaluated(const Depsgraph *depsgraph, T *id)
void ANIM_deselect_keys_in_animation_editors(bContext *C)
Definition anim_deps.cc:487
Depsgraph * CTX_data_ensure_evaluated_depsgraph(const bContext *C, bool rna_write_check=false)
bool BKE_view_layer_synced_ensure(const Main &bmain, const Scene *scene, ViewLayer *view_layer)
void BKE_ptcache_ids_from_object(ListBaseT< PTCacheID > *lb, struct Object *ob, struct Scene *scene, int duplis)
void invert_m3_m3_safe_ortho(float inverse[3][3], const float mat[3][3])
void DEG_foreach_dependent_ID_component(const Depsgraph *depsgraph, const ID *id, eDepsObjectComponentType source_component_type, int flags, DEGForeachIDComponentCallback callback)
bool BKE_object_is_in_editmode(const Object *ob)
Definition object.cc:1898
constexpr int MAX_DUPLI_RECUR
void BKE_object_mat3_to_rot(Object *ob, float r_mat[3][3], bool use_compat)
Definition object.cc:2946
@ DEG_FOREACH_COMPONENT_IGNORE_TRANSFORM_SOLVERS
Main * CTX_data_main(const bContext *C)
void unit_m3(float m[3][3])
float BKE_scene_ctime_get(const Scene *scene)
Definition scene.cc:2581
void BKE_object_to_mat3(const Object *ob, float r_mat[3][3])
Definition object.cc:3112
void BKE_scene_base_flag_to_objects(const Main &bmain, const Scene *scene, ViewLayer *view_layer)
Definition scene.cc:3103
@ ID_RECALC_TRANSFORM
Definition DNA_ID.h:1054
@ ID_RECALC_GEOMETRY
Definition DNA_ID.h:1074
ID_Type GS(const char *name)
Definition DNA_ID.h:410
Base * BKE_view_layer_base_find(ViewLayer *view_layer, Object *ob)
@ ID_TAG_DOIT
Definition DNA_ID.h:1029
void DEG_graph_relations_update(Depsgraph *graph)
Depsgraph * BKE_scene_ensure_depsgraph(Main *bmain, Scene *scene, ViewLayer *view_layer)
Definition scene.cc:3644
@ AUTOKEY_FLAG_INSERTNEEDED
void mul_m3_m3m3(float R[3][3], const float A[3][3], const float B[3][3])
void copy_m4_m4(float m1[4][4], const float m2[4][4])
void BKE_object_where_is_calc(Depsgraph *depsgraph, Scene *scene, Object *ob)
Definition object.cc:3577
bool BKE_id_is_editable(const Main *bmain, const ID *id)
Definition lib_id.cc:2782
@ MOTIONPATH_BAKE_HAS_PATHS
ListBaseT< Base > * BKE_view_layer_object_bases_get(ViewLayer *view_layer)
void animviz_update_motionpath_preview(Depsgraph &depsgraph, Span< MPathTarget > targets)
void * MEM_new_array_zeroed(size_t len, size_t size, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
bMotionPath * mpath
const c_style_mat & ptr() const
struct Object * parent
bke::ObjectRuntime * runtime
bAnimVizSettings avs
ListBaseT< bConstraint > constraints
bMotionPath * mpath
struct RigidBodyOb * rigidbody_object
eObject_TransFlag transflag
eObject_ProtectFlag protectflag
struct ToolSettings * toolsettings
struct RigidBodyWorld * rigidbody_world
eMotionPath_BakeFlag path_bakeflag
void(*) free_cb(TransInfo *, TransDataContainer *tc, TransCustomData *custom_data)
Definition transform.hh:655
object::XFormObjectData_Container * xds
object::XFormObjectSkipChild_Container * xcs
TransCustomDataContainer custom
#define TRANS_DATA_CONTAINER_FIRST_SINGLE(t)
Definition transform.hh:45
#define FOREACH_TRANS_DATA_CONTAINER(t, th)
Definition transform.hh:48
conversion and adaptation of different datablocks to a common struct.
#define BASE_XFORM_INDIRECT(base)