Blender V5.3
object_transform.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 <cstdlib>
10#include <cstring>
11#include <numeric>
12
13#include "DNA_anim_types.h"
14#include "DNA_armature_types.h"
17#include "DNA_lattice_types.h"
18#include "DNA_light_types.h"
19#include "DNA_mesh_types.h"
20#include "DNA_meta_types.h"
21#include "DNA_object_types.h"
23#include "DNA_scene_types.h"
24
25#include "BLI_array.hh"
26#include "BLI_listbase.hh"
27#include "BLI_math_geom_c.hh"
28#include "BLI_math_matrix.hh"
29#include "BLI_math_matrix_c.hh"
31#include "BLI_task.hh"
32#include "BLI_utildefines.hh"
33#include "BLI_vector.hh"
34
35#include "BKE_armature.hh"
36#include "BKE_context.hh"
37#include "BKE_curve.hh"
38#include "BKE_curves.hh"
39#include "BKE_editmesh.hh"
40#include "BKE_grease_pencil.hh"
41#include "BKE_idtype.hh"
42#include "BKE_lattice.hh"
43#include "BKE_layer.hh"
44#include "BKE_lib_id.hh"
45#include "BKE_library.hh"
46#include "BKE_main.hh"
47#include "BKE_mball.hh"
48#include "BKE_mesh.hh"
49#include "BKE_multires.hh"
50#include "BKE_object.hh"
51#include "BKE_report.hh"
52#include "BKE_scene.hh"
53#include "BKE_tracking.hh"
54
55#include "BLT_translation.hh"
56
57#include "DEG_depsgraph.hh"
59
60#include "RNA_access.hh"
61#include "RNA_define.hh"
62
63#include "UI_interface_icons.hh"
64
65#include "WM_api.hh"
66#include "WM_types.hh"
67
68#include "ANIM_keyframing.hh"
69#include "ANIM_keyingsets.hh"
70
71#include "ED_anim_api.hh"
72#include "ED_armature.hh"
73#include "ED_mesh.hh"
74#include "ED_object.hh"
75#include "ED_screen.hh"
76#include "ED_view3d.hh"
77
78#include "MEM_guardedalloc.h"
79
80#include "RNA_prototypes.hh"
81
82#include "object_intern.hh"
83
84namespace blender::ed::object {
85
86/* -------------------------------------------------------------------- */
89
90/* clear location of object */
91static void object_clear_loc(Object *ob, const bool clear_delta)
92{
93 /* clear location if not locked */
94 if ((ob->protectflag & OB_LOCK_LOCX) == 0) {
95 ob->loc[0] = 0.0f;
96 if (clear_delta) {
97 ob->dloc[0] = 0.0f;
98 }
99 }
100 if ((ob->protectflag & OB_LOCK_LOCY) == 0) {
101 ob->loc[1] = 0.0f;
102 if (clear_delta) {
103 ob->dloc[1] = 0.0f;
104 }
105 }
106 if ((ob->protectflag & OB_LOCK_LOCZ) == 0) {
107 ob->loc[2] = 0.0f;
108 if (clear_delta) {
109 ob->dloc[2] = 0.0f;
110 }
111 }
112}
113
114/* clear rotation of object */
115static void object_clear_rot(Object *ob, const bool clear_delta)
116{
117 /* clear rotations that aren't locked */
119 if (ob->protectflag & OB_LOCK_ROT4D) {
120 /* perform clamping on a component by component basis */
121 if (ob->rotmode == ROT_MODE_AXISANGLE) {
122 if ((ob->protectflag & OB_LOCK_ROTW) == 0) {
123 ob->rotAngle = 0.0f;
124 if (clear_delta) {
125 ob->drotAngle = 0.0f;
126 }
127 }
128 if ((ob->protectflag & OB_LOCK_ROTX) == 0) {
129 ob->rotAxis[0] = 0.0f;
130 if (clear_delta) {
131 ob->drotAxis[0] = 0.0f;
132 }
133 }
134 if ((ob->protectflag & OB_LOCK_ROTY) == 0) {
135 ob->rotAxis[1] = 0.0f;
136 if (clear_delta) {
137 ob->drotAxis[1] = 0.0f;
138 }
139 }
140 if ((ob->protectflag & OB_LOCK_ROTZ) == 0) {
141 ob->rotAxis[2] = 0.0f;
142 if (clear_delta) {
143 ob->drotAxis[2] = 0.0f;
144 }
145 }
146
147 /* Check validity of axis - axis should never be 0,0,0
148 * (if so, then we make it rotate about y). */
149 if (IS_EQF(ob->rotAxis[0], ob->rotAxis[1]) && IS_EQF(ob->rotAxis[1], ob->rotAxis[2])) {
150 ob->rotAxis[1] = 1.0f;
151 }
152 if (IS_EQF(ob->drotAxis[0], ob->drotAxis[1]) && IS_EQF(ob->drotAxis[1], ob->drotAxis[2]) &&
153 clear_delta)
154 {
155 ob->drotAxis[1] = 1.0f;
156 }
157 }
158 else if (ob->rotmode == ROT_MODE_QUAT) {
159 if ((ob->protectflag & OB_LOCK_ROTW) == 0) {
160 ob->quat[0] = 1.0f;
161 if (clear_delta) {
162 ob->dquat[0] = 1.0f;
163 }
164 }
165 if ((ob->protectflag & OB_LOCK_ROTX) == 0) {
166 ob->quat[1] = 0.0f;
167 if (clear_delta) {
168 ob->dquat[1] = 0.0f;
169 }
170 }
171 if ((ob->protectflag & OB_LOCK_ROTY) == 0) {
172 ob->quat[2] = 0.0f;
173 if (clear_delta) {
174 ob->dquat[2] = 0.0f;
175 }
176 }
177 if ((ob->protectflag & OB_LOCK_ROTZ) == 0) {
178 ob->quat[3] = 0.0f;
179 if (clear_delta) {
180 ob->dquat[3] = 0.0f;
181 }
182 }
183 /* TODO: does this quat need normalizing now? */
184 }
185 else {
186 /* the flag may have been set for the other modes, so just ignore the extra flag... */
187 if ((ob->protectflag & OB_LOCK_ROTX) == 0) {
188 ob->rot[0] = 0.0f;
189 if (clear_delta) {
190 ob->drot[0] = 0.0f;
191 }
192 }
193 if ((ob->protectflag & OB_LOCK_ROTY) == 0) {
194 ob->rot[1] = 0.0f;
195 if (clear_delta) {
196 ob->drot[1] = 0.0f;
197 }
198 }
199 if ((ob->protectflag & OB_LOCK_ROTZ) == 0) {
200 ob->rot[2] = 0.0f;
201 if (clear_delta) {
202 ob->drot[2] = 0.0f;
203 }
204 }
205 }
206 }
207 else {
208 /* perform clamping using euler form (3-components) */
209 /* FIXME: deltas are not handled for these cases yet... */
210 float eul[3], oldeul[3], quat1[4] = {0};
211
212 if (ob->rotmode == ROT_MODE_QUAT) {
213 copy_qt_qt(quat1, ob->quat);
214 quat_to_eul(oldeul, ob->quat);
215 }
216 else if (ob->rotmode == ROT_MODE_AXISANGLE) {
218 }
219 else {
220 copy_v3_v3(oldeul, ob->rot);
221 }
222
223 eul[0] = eul[1] = eul[2] = 0.0f;
224
225 if (ob->protectflag & OB_LOCK_ROTX) {
226 eul[0] = oldeul[0];
227 }
228 if (ob->protectflag & OB_LOCK_ROTY) {
229 eul[1] = oldeul[1];
230 }
231 if (ob->protectflag & OB_LOCK_ROTZ) {
232 eul[2] = oldeul[2];
233 }
234
235 if (ob->rotmode == ROT_MODE_QUAT) {
236 eul_to_quat(ob->quat, eul);
237 /* quaternions flip w sign to accumulate rotations correctly */
238 if ((quat1[0] < 0.0f && ob->quat[0] > 0.0f) || (quat1[0] > 0.0f && ob->quat[0] < 0.0f)) {
239 mul_qt_fl(ob->quat, -1.0f);
240 }
241 }
242 else if (ob->rotmode == ROT_MODE_AXISANGLE) {
244 }
245 else {
246 copy_v3_v3(ob->rot, eul);
247 }
248 }
249 } /* Duplicated in source/blender/editors/armature/armature_edit.cc */
250 else {
251 if (ob->rotmode == ROT_MODE_QUAT) {
252 unit_qt(ob->quat);
253 if (clear_delta) {
254 unit_qt(ob->dquat);
255 }
256 }
257 else if (ob->rotmode == ROT_MODE_AXISANGLE) {
259 if (clear_delta) {
261 }
262 }
263 else {
264 zero_v3(ob->rot);
265 if (clear_delta) {
266 zero_v3(ob->drot);
267 }
268 }
269 }
270}
271
272/* clear scale of object */
273static void object_clear_scale(Object *ob, const bool clear_delta)
274{
275 /* clear scale factors which are not locked */
276 if ((ob->protectflag & OB_LOCK_SCALEX) == 0) {
277 ob->scale[0] = 1.0f;
278 if (clear_delta) {
279 ob->dscale[0] = 1.0f;
280 }
281 }
282 if ((ob->protectflag & OB_LOCK_SCALEY) == 0) {
283 ob->scale[1] = 1.0f;
284 if (clear_delta) {
285 ob->dscale[1] = 1.0f;
286 }
287 }
288 if ((ob->protectflag & OB_LOCK_SCALEZ) == 0) {
289 ob->scale[2] = 1.0f;
290 if (clear_delta) {
291 ob->dscale[2] = 1.0f;
292 }
293 }
294}
295
296/* generic exec for clear-transform operators */
298 wmOperator *op,
299 void (*clear_func)(Object *,
300 const bool),
301 const char default_ksName[])
302{
303 Depsgraph *depsgraph = CTX_data_depsgraph_pointer(C);
304 Main *bmain = CTX_data_main(C);
305 Scene *scene = CTX_data_scene(C);
306 ViewLayer *view_layer = CTX_data_view_layer(C);
307 /* May be null. */
308 View3D *v3d = CTX_wm_view3d(C);
309 KeyingSet *ks;
310 const bool clear_delta = RNA_boolean_get(op->ptr, "clear_delta");
311
312 BLI_assert(!ELEM(nullptr, clear_func, default_ksName));
313
314 Vector<Object *> objects;
315 FOREACH_SELECTED_EDITABLE_OBJECT_BEGIN (view_layer, v3d, ob) {
316 objects.append(ob);
317 }
319
320 if (objects.is_empty()) {
321 return OPERATOR_CANCELLED;
322 }
323
324 /* Support transforming the object data. */
325 const bool use_transform_skip_children = (scene->toolsettings->transform_flag &
327 const bool use_transform_data_origin = (scene->toolsettings->transform_flag &
329 XFormObjectSkipChild_Container *xcs = nullptr;
330 XFormObjectData_Container *xds = nullptr;
331
332 if (use_transform_skip_children) {
333 BKE_scene_graph_evaluated_ensure(depsgraph, bmain);
336 xcs, *bmain, scene, view_layer, objects.data(), objects.size());
337 }
338 if (use_transform_data_origin) {
339 BKE_scene_graph_evaluated_ensure(depsgraph, bmain);
341 }
342
343 /* get KeyingSet to use */
344 ks = animrig::get_keyingset_for_autokeying(scene, default_ksName);
345
346 if (animrig::is_autokey_on(scene)) {
348 }
349
350 for (Object *ob : objects) {
351 if (use_transform_data_origin) {
353 }
354
355 /* run provided clearing function */
356 clear_func(ob, clear_delta);
357
358 animrig::autokeyframe_object(C, scene, ob, ks);
359
360 /* tag for updates */
362 }
363
364 if (use_transform_skip_children) {
367 }
368
369 if (use_transform_data_origin) {
370 data_xform_container_update_all(xds, bmain, depsgraph);
372 }
373
374 /* this is needed so children are also updated */
376
377 return OPERATOR_FINISHED;
378}
379
381
382/* -------------------------------------------------------------------- */
385
390
392{
393 /* identifiers */
394 ot->name = "Clear Location";
395 ot->description = "Clear the object's location";
396 ot->idname = "OBJECT_OT_location_clear";
397
398 /* API callbacks. */
401
402 /* flags */
404
405 /* properties */
406 ot->prop = RNA_def_boolean(
407 ot->srna,
408 "clear_delta",
409 false,
410 "Clear Delta",
411 "Clear delta location in addition to clearing the normal location transform");
412}
413
415
416/* -------------------------------------------------------------------- */
419
424
426{
427 /* identifiers */
428 ot->name = "Clear Rotation";
429 ot->description = "Clear the object's rotation";
430 ot->idname = "OBJECT_OT_rotation_clear";
431
432 /* API callbacks. */
435
436 /* flags */
438
439 /* properties */
440 ot->prop = RNA_def_boolean(
441 ot->srna,
442 "clear_delta",
443 false,
444 "Clear Delta",
445 "Clear delta rotation in addition to clearing the normal rotation transform");
446}
447
449
450/* -------------------------------------------------------------------- */
453
458
460{
461 /* identifiers */
462 ot->name = "Clear Scale";
463 ot->description = "Clear the object's scale";
464 ot->idname = "OBJECT_OT_scale_clear";
465
466 /* API callbacks. */
469
470 /* flags */
472
473 /* properties */
474 ot->prop = RNA_def_boolean(
475 ot->srna,
476 "clear_delta",
477 false,
478 "Clear Delta",
479 "Clear delta scale in addition to clearing the normal scale transform");
480}
481
483
484/* -------------------------------------------------------------------- */
487
489{
490 float *v1, *v3;
491 float mat[3][3];
492
493 CTX_DATA_BEGIN (C, Object *, ob, selected_editable_objects) {
494 if (ob->parent) {
495 /* vectors pointed to by v1 and v3 will get modified */
496 v1 = ob->loc;
497 v3 = ob->parentinv[3];
498
499 copy_m3_m4(mat, ob->parentinv);
500 negate_v3_v3(v3, v1);
501 mul_m3_v3(mat, v3);
502 }
503
505 }
507
509
510 return OPERATOR_FINISHED;
511}
512
514{
515 /* identifiers */
516 ot->name = "Clear Origin";
517 ot->description = "Clear the object's origin";
518 ot->idname = "OBJECT_OT_origin_clear";
519
520 /* API callbacks. */
523
524 /* flags */
526}
527
529
530/* -------------------------------------------------------------------- */
533
534/* use this when the loc/size/rot of the parent has changed but the children
535 * should stay in the same place, e.g. for apply-size-rot or object center */
536static void ignore_parent_tx(Main *bmain, Depsgraph *depsgraph, Scene *scene, Object *ob)
537{
538 Scene *scene_eval = DEG_get_evaluated_scene(depsgraph);
539
540 /* a change was made, adjust the children to compensate */
541 for (Object &ob_child : bmain->objects) {
542 if (ob_child.parent == ob) {
543 Object *ob_child_eval = DEG_get_evaluated(depsgraph, &ob_child);
544 BKE_object_apply_mat4(ob_child_eval, ob_child_eval->object_to_world().ptr(), true, false);
545 invert_m4_m4(ob_child.parentinv,
546 BKE_object_calc_parent(depsgraph, scene, ob_child_eval).ptr());
547 /* Copy result of BKE_object_apply_mat4(). */
548 BKE_object_transform_copy(&ob_child, ob_child_eval);
549 /* Make sure evaluated object is in a consistent state with the original one.
550 * It might be needed for applying transform on its children. */
551 copy_m4_m4(ob_child_eval->parentinv, ob_child.parentinv);
552 BKE_object_eval_transform_all(depsgraph, scene_eval, ob_child_eval);
553 /* Tag for update.
554 * This is because parent matrix did change, so in theory the child object might now be
555 * evaluated to a different location in another editing context. */
557 }
558 }
559}
560
562 Object *object,
563 Object **sorted_objects,
564 int *object_index)
565{
566 if (!ELEM(object->parent, nullptr, root_object)) {
568 root_object, object->parent, sorted_objects, object_index);
569 }
570 if (object->id.tag & ID_TAG_DOIT) {
571 sorted_objects[*object_index] = object;
572 (*object_index)++;
573 object->id.tag &= ~ID_TAG_DOIT;
574 }
575}
576
578{
579 Main *bmain = CTX_data_main(C);
580
581 /* Count all objects, but also tag all the selected ones. */
582 BKE_main_id_tag_all(bmain, ID_TAG_DOIT, false);
583 int objects_num = 0;
584 CTX_DATA_BEGIN (C, Object *, object, selected_editable_objects) {
585 object->id.tag |= ID_TAG_DOIT;
586 objects_num++;
587 }
589 if (objects_num == 0) {
590 return {};
591 }
592
593 /* Append all the objects. */
594 Array<Object *> sorted_objects(objects_num);
595 int object_index = 0;
596 CTX_DATA_BEGIN (C, Object *, object, selected_editable_objects) {
597 if ((object->id.tag & ID_TAG_DOIT) == 0) {
598 continue;
599 }
600 append_sorted_object_parent_hierarchy(object, object, sorted_objects.data(), &object_index);
601 }
603
604 return sorted_objects;
605}
606
611{
613
614 if (ELEM(nullptr, obact, obact->data)) {
615 return false;
616 }
617
618 if (ID_REAL_USERS(obact->data) == 1) {
619 return false;
620 }
621
622 bool all_objects_same_data = true;
623 bool obact_selected = false;
624
625 CTX_DATA_BEGIN (C, Object *, ob, selected_editable_objects) {
626 if (ob->data != obact->data) {
627 all_objects_same_data = false;
628 break;
629 }
630
631 if (ob == obact) {
632 obact_selected = true;
633 }
634 }
636
637 return all_objects_same_data && obact_selected;
638}
639
646{
649
650 /* Counting the number of objects is valid since it's known the
651 * selection is only made up of users of the active objects data. */
652 return (ID_REAL_USERS(ob->data) > CTX_DATA_COUNT(C, selected_editable_objects));
653}
654
656 ReportList *reports,
657 bool apply_loc,
658 bool apply_rot,
659 bool apply_scale,
660 bool do_props,
661 bool do_single_user,
662 bool corrective_flip_normals)
663{
664 Main *bmain = CTX_data_main(C);
665 Scene *scene = CTX_data_scene(C);
666 Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
667 float rsmat[3][3], obmat[3][3], iobmat[3][3], mat[4][4], scale;
668 bool changed = true;
669 bool const do_multi_user = apply_objects_internal_can_multiuser(C);
670 float obact_invmat[4][4], obact_parent[4][4], obact_parentinv[4][4];
671
672 /* Only used when do_multi_user is set. */
673 Object *obact = nullptr;
674 bool make_single_user = false;
675
676 if (do_multi_user) {
677 obact = CTX_data_active_object(C);
678 invert_m4_m4(obact_invmat, obact->object_to_world().ptr());
679
680 copy_m4_m4(obact_parent, BKE_object_calc_parent(depsgraph, scene, obact).ptr());
681 copy_m4_m4(obact_parentinv, obact->parentinv);
682
684 if (do_single_user) {
685 make_single_user = true;
686 }
687 else {
688 ID *obact_data = obact->data;
689 BKE_reportf(reports,
690 RPT_ERROR,
691 R"(Cannot apply to a multi user: Object "%s", %s "%s", aborting)",
692 obact->id.name + 2,
693 BKE_idtype_idcode_to_name(GS(obact_data->name)),
694 obact_data->name + 2);
695 return OPERATOR_CANCELLED;
696 }
697 }
698 }
699
700 /* first check if we can execute */
701 CTX_DATA_BEGIN (C, Object *, ob, selected_editable_objects) {
702 if (ELEM(ob->type,
703 OB_MESH,
706 OB_MBALL,
708 OB_SURF,
709 OB_FONT,
710 OB_CURVES,
713 {
714 ID *obdata = ob->data;
715 if (!do_multi_user && ID_REAL_USERS(obdata) > 1) {
716 BKE_reportf(reports,
717 RPT_ERROR,
718 R"(Cannot apply to a multi user: Object "%s", %s "%s", aborting)",
719 ob->id.name + 2,
721 obdata->name + 2);
722 changed = false;
723 }
724
725 if (!ID_IS_EDITABLE(obdata) || ID_IS_OVERRIDE_LIBRARY(obdata)) {
726 BKE_reportf(reports,
727 RPT_ERROR,
728 R"(Cannot apply to library or override data: Object "%s", %s "%s", aborting)",
729 ob->id.name + 2,
731 obdata->name + 2);
732 changed = false;
733 }
734 }
735
736 if (ELEM(ob->type, OB_CURVES_LEGACY, OB_SURF)) {
737 ID *obdata = ob->data;
738 Curve *cu = id_cast<Curve *>(ob->data);
739
740 if (((ob->type == OB_CURVES_LEGACY) && !(cu->flag & CU_3D)) && (apply_rot || apply_loc)) {
742 reports,
743 RPT_ERROR,
744 R"(Rotation/Location cannot apply to a 2D curve: Object "%s", %s "%s", aborting)",
745 ob->id.name + 2,
747 obdata->name + 2);
748 changed = false;
749 }
750 if (cu->key) {
751 BKE_reportf(reports,
752 RPT_ERROR,
753 R"(Can't apply to a curve with shape-keys: Object "%s", %s "%s", aborting)",
754 ob->id.name + 2,
756 obdata->name + 2);
757 changed = false;
758 }
759 }
760
761 if (ob->type == OB_FONT) {
762 if (apply_rot || apply_loc) {
763 BKE_reportf(reports,
764 RPT_ERROR,
765 "Text objects can only have their scale applied: \"%s\"",
766 ob->id.name + 2);
767 changed = false;
768 }
769 }
770
771 if (ob->type == OB_LAMP) {
772 Light *la = id_cast<Light *>(ob->data);
773 if (la->type == LA_AREA) {
774 if (apply_rot || apply_loc) {
775 BKE_reportf(reports,
776 RPT_ERROR,
777 "Area Lights can only have scale applied: \"%s\"",
778 ob->id.name + 2);
779 changed = false;
780 }
781 }
782 }
783 }
785
786 if (!changed) {
787 return OPERATOR_CANCELLED;
788 }
789
790 changed = false;
791
792 /* now execute */
793
794 if (make_single_user) {
795 /* Make single user. */
796 single_obdata_user_make(bmain, scene, obact);
800 }
801
803 if (objects.is_empty()) {
804 return OPERATOR_CANCELLED;
805 }
806
807 bool has_non_invertable_matrix = false;
808
809 for (Object *ob : objects) {
810 /* calculate rotation/scale matrix */
811 if (apply_scale && apply_rot) {
812 BKE_object_to_mat3(ob, rsmat);
813 }
814 else if (apply_scale) {
815 BKE_object_scale_to_mat3(ob, rsmat);
816 }
817 else if (apply_rot) {
818 float tmat[3][3], timat[3][3];
819
820 /* simple rotation matrix */
821 BKE_object_rot_to_mat3(ob, rsmat, true);
822
823 /* correct for scale, note mul_m3_m3m3 has swapped args! */
824 BKE_object_scale_to_mat3(ob, tmat);
825 if (!invert_m3_m3(timat, tmat)) {
827 reports,
829 "Object \"%s\" has a non-invertible transformation matrix, not applying transform",
830 ob->id.name + 2);
831 has_non_invertable_matrix = true;
832 continue;
833 }
834 mul_m3_m3m3(rsmat, timat, rsmat);
835 mul_m3_m3m3(rsmat, rsmat, tmat);
836 }
837 else {
838 unit_m3(rsmat);
839 }
840
841 copy_m4_m3(mat, rsmat);
842
843 /* calculate translation */
844 if (apply_loc) {
845 add_v3_v3v3(mat[3], ob->loc, ob->dloc);
846
847 if (!(apply_scale && apply_rot)) {
848 float tmat[3][3];
849 /* correct for scale and rotation that is still applied */
850 BKE_object_to_mat3(ob, obmat);
851 invert_m3_m3(iobmat, obmat);
852 mul_m3_m3m3(tmat, rsmat, iobmat);
853 mul_m3_v3(tmat, mat[3]);
854 }
855 }
856
857 /* apply to object data */
858 if (do_multi_user && ob != obact) {
859 /* Don't apply, just set the new object data, the correct
860 * transformations will happen later. */
861 id_us_min(ob->data);
862 ob->data = obact->data;
863 id_us_plus(ob->data);
864 }
865 else if (ob->type == OB_MESH) {
866 Mesh *mesh = id_cast<Mesh *>(ob->data);
867
868 if (apply_scale) {
869 multiresModifier_scale_disp(depsgraph, scene, ob);
870 }
871
872 /* adjust data */
873 bke::mesh_transform(*mesh, float4x4(mat), true);
874 /* The determinant of mat will be negative for objects with an odd number of negative scale
875 * axes, since the normals will be flipped when scale is applied, we provide the option to
876 * flip them back. */
877 if (corrective_flip_normals && math::determinant(float4x4(mat)) < 0.0f) {
879 }
880 }
881 else if (ob->type == OB_ARMATURE) {
882 bArmature *arm = id_cast<bArmature *>(ob->data);
883 BKE_armature_transform(arm, mat, do_props);
884 }
885 else if (ob->type == OB_LATTICE) {
886 Lattice *lt = id_cast<Lattice *>(ob->data);
887
888 BKE_lattice_transform(lt, mat, true);
889 }
890 else if (ob->type == OB_MBALL) {
891 MetaBall *mb = id_cast<MetaBall *>(ob->data);
892 BKE_mball_transform(mb, mat, do_props);
893 }
894 else if (ELEM(ob->type, OB_CURVES_LEGACY, OB_SURF)) {
895 Curve *cu = id_cast<Curve *>(ob->data);
896 scale = mat3_to_scale(rsmat);
897 BKE_curve_transform_ex(cu, mat, true, do_props, scale);
898 }
899 else if (ob->type == OB_FONT) {
900 Curve *cu = id_cast<Curve *>(ob->data);
901
902 scale = mat3_to_scale(rsmat);
903
904 for (int i = 0; i < cu->totbox; i++) {
905 TextBox *tb = &cu->tb[i];
906 tb->x *= scale;
907 tb->y *= scale;
908 tb->w *= scale;
909 tb->h *= scale;
910 }
911
912 if (do_props) {
913 cu->fsize *= scale;
914 }
915 }
916 else if (ob->type == OB_CURVES) {
917 Curves &curves = *id_cast<Curves *>(ob->data);
918 curves.geometry.wrap().transform(float4x4(mat));
919 curves.geometry.wrap().calculate_bezier_auto_handles();
920 }
921 else if (ob->type == OB_GREASE_PENCIL) {
922 GreasePencil &grease_pencil = *id_cast<GreasePencil *>(ob->data);
923
924 const float scalef = mat4_to_scale(mat);
925
926 for (const int layer_i : grease_pencil.layers().index_range()) {
928 const float4x4 layer_to_object = layer.to_object_space(*ob);
929 const float4x4 object_to_layer = math::invert(layer_to_object);
931 frames.foreach_item(
934 if (base->type != GP_DRAWING) {
935 return;
936 }
938 reinterpret_cast<GreasePencilDrawing *>(base)->wrap();
940 MutableSpan<float> radii = drawing.radii_for_write();
941 threading::parallel_for(radii.index_range(), 8192, [&](const IndexRange range) {
942 for (const int i : range) {
943 radii[i] *= scalef;
944 }
945 });
946
947 curves.transform(object_to_layer * float4x4(mat) * layer_to_object);
948 curves.calculate_bezier_auto_handles();
949 });
950 }
951 }
952 else if (ob->type == OB_POINTCLOUD) {
953 PointCloud &pointcloud = *id_cast<PointCloud *>(ob->data);
954 math::transform_points(float4x4(mat), pointcloud.positions_for_write());
955 pointcloud.tag_positions_changed();
956 }
957 else if (ob->type == OB_CAMERA) {
958 MovieClip *clip = BKE_object_movieclip_get(scene, ob, false);
959
960 /* applying scale on camera actually scales clip's reconstruction.
961 * of there's clip assigned to camera nothing to do actually.
962 */
963 if (!clip) {
964 continue;
965 }
966
967 if (apply_scale) {
969 }
970 }
971 else if (ob->type == OB_EMPTY) {
972 /* It's possible for empties too, even though they don't
973 * really have obdata, since we can simply apply the maximum
974 * scaling to the empty's drawsize.
975 *
976 * Core Assumptions:
977 * 1) Most scaled empties have uniform scaling
978 * (i.e. for visibility reasons), AND/OR
979 * 2) Preserving non-uniform scaling is not that important,
980 * and is something that many users would be willing to
981 * sacrifice for having an easy way to do this.
982 */
983
984 if (apply_scale) {
985 float max_scale = std::max(
986 {fabsf(ob->scale[0]), fabsf(ob->scale[1]), fabsf(ob->scale[2])});
987 ob->empty_drawsize *= max_scale;
988 }
989 }
990 else if (ob->type == OB_LAMP) {
991 Light *la = id_cast<Light *>(ob->data);
992 if (la->type != LA_AREA) {
993 continue;
994 }
995
996 bool keeps_aspect_ratio = compare_ff_relative(rsmat[0][0], rsmat[1][1], FLT_EPSILON, 64);
997 if ((la->area_shape == LA_AREA_SQUARE) && !keeps_aspect_ratio) {
998 la->area_shape = LA_AREA_RECT;
999 la->area_sizey = la->area_size;
1000 }
1001 else if ((la->area_shape == LA_AREA_DISK) && !keeps_aspect_ratio) {
1002 la->area_shape = LA_AREA_ELLIPSE;
1003 la->area_sizey = la->area_size;
1004 }
1005
1006 la->area_size *= rsmat[0][0];
1007 la->area_sizey *= rsmat[1][1];
1008 la->area_sizez *= rsmat[2][2];
1009
1010 /* Explicit tagging is required for Lamp ID because, unlike Geometry IDs like Mesh,
1011 * it is not covered by the `ID_RECALC_GEOMETRY` flag applied to the object at the end
1012 * of this loop. */
1014 }
1015 else {
1016 continue;
1017 }
1018
1019 if (do_multi_user && ob != obact) {
1020 float _obmat[4][4], _iobmat[4][4];
1021 float _mat[4][4];
1022
1023 copy_m4_m4(_obmat, ob->object_to_world().ptr());
1024 invert_m4_m4(_iobmat, _obmat);
1025
1026 copy_m4_m4(_mat, _obmat);
1027 mul_m4_m4_post(_mat, obact_invmat);
1028 mul_m4_m4_post(_mat, obact_parent);
1029 mul_m4_m4_post(_mat, obact_parentinv);
1030
1031 if (apply_loc && apply_scale && apply_rot) {
1032 BKE_object_apply_mat4(ob, _mat, false, true);
1033 }
1034 else {
1035 Object ob_temp = dna::shallow_copy(*ob);
1036 BKE_object_apply_mat4(&ob_temp, _mat, false, true);
1037
1038 if (apply_loc) {
1039 copy_v3_v3(ob->loc, ob_temp.loc);
1040 }
1041
1042 if (apply_scale) {
1043 copy_v3_v3(ob->scale, ob_temp.scale);
1044 }
1045
1046 if (apply_rot) {
1047 copy_v4_v4(ob->quat, ob_temp.quat);
1048 copy_v3_v3(ob->rot, ob_temp.rot);
1049 copy_v3_v3(ob->rotAxis, ob_temp.rotAxis);
1050 ob->rotAngle = ob_temp.rotAngle;
1051 }
1052 }
1053 }
1054 else {
1055 if (apply_loc) {
1056 zero_v3(ob->loc);
1057 zero_v3(ob->dloc);
1058 }
1059 if (apply_scale) {
1060 copy_v3_fl(ob->scale, 1.0f);
1061 copy_v3_fl(ob->dscale, 1.0f);
1062 }
1063 if (apply_rot) {
1064 zero_v3(ob->rot);
1065 zero_v3(ob->drot);
1066 unit_qt(ob->quat);
1067 unit_qt(ob->dquat);
1068 unit_axis_angle(ob->rotAxis, &ob->rotAngle);
1069 unit_axis_angle(ob->drotAxis, &ob->drotAngle);
1070 }
1071 }
1072
1073 Object *ob_eval = DEG_get_evaluated(depsgraph, ob);
1074 BKE_object_transform_copy(ob_eval, ob);
1075
1076 BKE_object_where_is_calc(depsgraph, scene, ob_eval);
1077 if (ob->type == OB_ARMATURE) {
1078 /* needed for bone parents */
1079 BKE_armature_copy_bone_transforms(id_cast<bArmature *>(ob_eval->data),
1080 id_cast<bArmature *>(ob->data));
1081 BKE_pose_where_is(depsgraph, scene, ob_eval);
1082 }
1083
1084 ignore_parent_tx(bmain, depsgraph, scene, ob);
1085
1087
1088 changed = true;
1089 }
1090
1091 if (!changed) {
1092 BKE_report(reports, RPT_WARNING, "Objects have no data to transform");
1093 return OPERATOR_CANCELLED;
1094 }
1095 if (has_non_invertable_matrix) {
1096 BKE_report(reports, RPT_WARNING, "Failed to apply rotation to some of the objects");
1097 }
1098
1100 return OPERATOR_FINISHED;
1101}
1102
1104{
1105 Scene *scene = CTX_data_scene(C);
1106 Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
1107 bool changed = false;
1108
1109 CTX_DATA_BEGIN (C, Object *, ob, selected_editable_objects) {
1110 Object *ob_eval = DEG_get_evaluated(depsgraph, ob);
1111 BKE_object_where_is_calc(depsgraph, scene, ob_eval);
1112 BKE_object_apply_mat4(ob_eval, ob_eval->object_to_world().ptr(), true, true);
1113 BKE_object_transform_copy(ob, ob_eval);
1114
1115 /* update for any children that may get moved */
1117
1118 changed = true;
1119 }
1121
1122 if (!changed) {
1123 return OPERATOR_CANCELLED;
1124 }
1125
1127 return OPERATOR_FINISHED;
1128}
1129
1131{
1132 /* identifiers */
1133 ot->name = "Apply Visual Transform";
1134 ot->description = "Apply the object's visual transformation to its data";
1135 ot->idname = "OBJECT_OT_visual_transform_apply";
1136
1137 /* API callbacks. */
1140
1141 /* flags */
1143}
1144
1146{
1147 const bool loc = RNA_boolean_get(op->ptr, "location");
1148 const bool rot = RNA_boolean_get(op->ptr, "rotation");
1149 const bool sca = RNA_boolean_get(op->ptr, "scale");
1150 const bool do_props = RNA_boolean_get(op->ptr, "properties");
1151 const bool do_single_user = RNA_boolean_get(op->ptr, "isolate_users");
1152 const bool corrective_flip_normals = RNA_boolean_get(op->ptr, "corrective_flip_normals");
1153
1154 if (loc || rot || sca) {
1156 C, op->reports, loc, rot, sca, do_props, do_single_user, corrective_flip_normals);
1157 }
1158 /* allow for redo */
1159 return OPERATOR_FINISHED;
1160}
1161
1163 wmOperator *op,
1164 const wmEvent * /*event*/)
1165{
1167
1168 bool can_handle_multiuser = apply_objects_internal_can_multiuser(C);
1169 bool need_single_user = can_handle_multiuser && apply_objects_internal_need_single_user(C);
1170
1171 if ((ob != nullptr) && (ob->data != nullptr) && need_single_user) {
1172 PropertyRNA *prop = RNA_struct_find_property(op->ptr, "isolate_users");
1173 if (!RNA_property_is_set(op->ptr, prop)) {
1174 RNA_property_boolean_set(op->ptr, prop, true);
1175 }
1176 if (RNA_property_boolean_get(op->ptr, prop)) {
1178 op,
1179 IFACE_("Apply Object Transformations"),
1180 IFACE_("Warning: Multiple objects share the same data.\nMake "
1181 "single user and then apply transformations?"),
1182 IFACE_("Apply"),
1184 false);
1185 }
1186 }
1187 return object_transform_apply_exec(C, op);
1188}
1189
1191{
1192 /* identifiers */
1193 ot->name = "Apply Object Transform";
1194 ot->description = "Apply the object's transformation to its data";
1195 ot->idname = "OBJECT_OT_transform_apply";
1196
1197 /* API callbacks. */
1201
1202 /* flags */
1204
1205 RNA_def_boolean(ot->srna, "location", true, "Location", "");
1206 RNA_def_boolean(ot->srna, "rotation", true, "Rotation", "");
1207 RNA_def_boolean(ot->srna, "scale", true, "Scale", "");
1209 "properties",
1210 true,
1211 "Apply Properties",
1212 "Modify properties such as curve vertex radius, font size and bone envelope");
1214 "corrective_flip_normals",
1215 true,
1216 "Corrective Flip Normals",
1217 "Invert normals for negative scaled objects.");
1218 PropertyRNA *prop = RNA_def_boolean(ot->srna,
1219 "isolate_users",
1220 false,
1221 "Isolate Multi User Data",
1222 "Create new object-data users if needed");
1225}
1226
1228
1229/* -------------------------------------------------------------------- */
1232
1234{
1235 CTX_DATA_BEGIN (C, Object *, ob, selected_editable_objects) {
1236 if (ob->parent == nullptr) {
1237 continue;
1238 }
1239
1242 }
1244
1246
1247 return OPERATOR_FINISHED;
1248}
1249
1251{
1252 /* identifiers */
1253 ot->name = "Apply Parent Inverse";
1254 ot->description = "Apply the object's parent inverse to its data";
1255 ot->idname = "OBJECT_OT_parent_inverse_apply";
1256
1257 /* API callbacks. */
1260
1261 /* flags */
1263}
1264
1266
1267/* -------------------------------------------------------------------- */
1270
1271enum {
1277};
1278
1280{
1281 if (values.is_empty()) {
1282 return float3(0);
1283 }
1284 /* TODO: Use a method that avoids overflow. */
1285 return std::accumulate(values.begin(), values.end(), float3(0)) / values.size();
1286}
1287
1288static void translate_positions(MutableSpan<float3> positions, const float3 &translation)
1289{
1290 threading::parallel_for(positions.index_range(), 2048, [&](const IndexRange range) {
1291 for (float3 &position : positions.slice(range)) {
1292 position += translation;
1293 }
1294 });
1295}
1296
1298{
1299 Main *bmain = CTX_data_main(C);
1300 Scene *scene = CTX_data_scene(C);
1302 Object *obedit = CTX_data_edit_object(C);
1303 Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
1304 float3 cent, cent_neg, centn;
1305 const float *cursor = scene->cursor.location;
1306 int centermode = RNA_enum_get(op->ptr, "type");
1307
1308 /* keep track of what is changed */
1309 int tot_change = 0, tot_lib_error = 0, tot_multiuser_arm_error = 0;
1310
1311 if (obedit && centermode != GEOMETRY_TO_ORIGIN) {
1312 BKE_report(op->reports, RPT_ERROR, "Operation cannot be performed in edit mode");
1313 return OPERATOR_CANCELLED;
1314 }
1315
1316 int around;
1317 {
1318 PropertyRNA *prop_center = RNA_struct_find_property(op->ptr, "center");
1319 if (RNA_property_is_set(op->ptr, prop_center)) {
1320 around = RNA_property_enum_get(op->ptr, prop_center);
1321 }
1322 else {
1324 around = V3D_AROUND_CENTER_BOUNDS;
1325 }
1326 else {
1327 around = V3D_AROUND_CENTER_MEDIAN;
1328 }
1329 RNA_property_enum_set(op->ptr, prop_center, around);
1330 }
1331 }
1332
1333 zero_v3(cent);
1334
1335 if (obedit) {
1336 if (obedit->type == OB_MESH) {
1337 Mesh *mesh = id_cast<Mesh *>(obedit->data);
1339 BMVert *eve;
1340 BMIter iter;
1341
1342 if (centermode == ORIGIN_TO_CURSOR) {
1343 copy_v3_v3(cent, cursor);
1344 invert_m4_m4(obedit->runtime->world_to_object.ptr(), obedit->object_to_world().ptr());
1345 mul_m4_v3(obedit->world_to_object().ptr(), cent);
1346 }
1347 else {
1348 if (around == V3D_AROUND_CENTER_BOUNDS) {
1349 float min[3], max[3];
1351 BM_ITER_MESH (eve, &iter, bm, BM_VERTS_OF_MESH) {
1352 minmax_v3v3_v3(min, max, eve->co);
1353 }
1354 mid_v3_v3v3(cent, min, max);
1355 }
1356 else { /* #V3D_AROUND_CENTER_MEDIAN. */
1357 if (bm->totvert) {
1358 const float total_div = 1.0f / float(bm->totvert);
1359 BM_ITER_MESH (eve, &iter, bm, BM_VERTS_OF_MESH) {
1360 madd_v3_v3fl(cent, eve->co, total_div);
1361 }
1362 }
1363 }
1364 }
1365
1366 BM_ITER_MESH (eve, &iter, bm, BM_VERTS_OF_MESH) {
1367 sub_v3_v3(eve->co, cent);
1368 }
1369
1371 tot_change++;
1373 }
1374 }
1375
1377 if (objects.is_empty()) {
1378 return OPERATOR_CANCELLED;
1379 }
1380
1381 /* reset flags */
1382 for (const int object_index : objects.index_range()) {
1383 Object *ob = objects[object_index];
1384 ob->flag &= ~OB_DONE;
1385
1386 /* move active first */
1387 if (ob == obact && objects.size() > 1) {
1388 memmove(&objects[1], objects.data(), object_index * sizeof(Object *));
1389 objects[0] = ob;
1390 }
1391 }
1392
1393 for (Object &tob : bmain->objects) {
1394 if (tob.data) {
1395 (tob.data)->tag &= ~ID_TAG_DOIT;
1396 }
1397 if (tob.instance_collection) {
1398 (id_cast<ID *>(tob.instance_collection))->tag &= ~ID_TAG_DOIT;
1399 }
1400 }
1401
1402 bool reported_empty = false;
1403 std::array<bool, INDEX_ID_MAX> reported{false};
1404 for (Object *ob : objects) {
1405 if (ob->flag & OB_DONE) {
1406 continue;
1407 }
1408
1409 bool do_inverse_offset = false;
1410 ob->flag |= OB_DONE;
1411
1412 if (centermode == ORIGIN_TO_CURSOR) {
1413 copy_v3_v3(cent, cursor);
1414 invert_m4_m4(ob->runtime->world_to_object.ptr(), ob->object_to_world().ptr());
1415 mul_m4_v3(ob->world_to_object().ptr(), cent);
1416 }
1417
1418 if (ob->data == nullptr) {
1419 /* Special support for instanced collections. */
1420 if ((ob->transflag & OB_DUPLICOLLECTION) && ob->instance_collection &&
1421 (ob->instance_collection->id.tag & ID_TAG_DOIT) == 0)
1422 {
1423 if (!BKE_id_is_editable(bmain, &ob->instance_collection->id)) {
1424 tot_lib_error++;
1425 }
1426 else {
1427 if (centermode == ORIGIN_TO_CURSOR) {
1428 /* done */
1429 }
1430 else {
1431 float3 min, max;
1432 /* only bounds support */
1434 BKE_object_minmax_dupli(depsgraph, ob, min, max, true);
1435 mid_v3_v3v3(cent, min, max);
1436 invert_m4_m4(ob->runtime->world_to_object.ptr(), ob->object_to_world().ptr());
1437 mul_m4_v3(ob->world_to_object().ptr(), cent);
1438 }
1439 add_v3_v3(ob->instance_collection->instance_offset, cent);
1440
1441 tot_change++;
1442 ob->instance_collection->id.tag |= ID_TAG_DOIT;
1443 do_inverse_offset = true;
1444 }
1445 }
1446 else {
1447 BLI_assert(ob->type == OB_EMPTY);
1448 if (!reported_empty) {
1449 reported_empty = true;
1450 BKE_report(op->reports, RPT_INFO, "Set Origin not supported for Empty object(s)");
1451 }
1452 }
1453 }
1454 else if (!ID_IS_EDITABLE(ob->data) || ID_IS_OVERRIDE_LIBRARY(ob->data)) {
1455 tot_lib_error++;
1456 }
1457 else if (ob->type == OB_MESH) {
1458 if (obedit == nullptr) {
1459 Mesh *mesh = id_cast<Mesh *>(ob->data);
1460
1461 if (centermode == ORIGIN_TO_CURSOR) {
1462 /* done */
1463 }
1464 else if (centermode == ORIGIN_TO_CENTER_OF_MASS_SURFACE) {
1466 }
1467 else if (centermode == ORIGIN_TO_CENTER_OF_MASS_VOLUME) {
1469 }
1470 else if (around == V3D_AROUND_CENTER_BOUNDS) {
1471 if (const std::optional<Bounds<float3>> bounds = mesh->bounds_min_max()) {
1472 cent = math::midpoint(bounds->min, bounds->max);
1473 }
1474 }
1475 else { /* #V3D_AROUND_CENTER_MEDIAN. */
1477 }
1478
1479 negate_v3_v3(cent_neg, cent);
1480 bke::mesh_translate(*mesh, cent_neg, true);
1481
1482 tot_change++;
1483 mesh->id.tag |= ID_TAG_DOIT;
1484 do_inverse_offset = true;
1485 }
1486 }
1487 else if (ELEM(ob->type, OB_CURVES_LEGACY, OB_SURF)) {
1488 Curve *cu = id_cast<Curve *>(ob->data);
1489
1490 if (centermode == ORIGIN_TO_CURSOR) {
1491 /* done */
1492 }
1493 else if (around == V3D_AROUND_CENTER_BOUNDS) {
1494 if (std::optional<Bounds<float3>> bounds = BKE_curve_minmax(cu, true)) {
1495 cent = math::midpoint(bounds->min, bounds->max);
1496 }
1497 }
1498 else { /* #V3D_AROUND_CENTER_MEDIAN. */
1499 BKE_curve_center_median(cu, cent);
1500 }
1501
1502 /* don't allow Z change if curve is 2D */
1503 if ((ob->type == OB_CURVES_LEGACY) && !(cu->flag & CU_3D)) {
1504 cent[2] = 0.0;
1505 }
1506
1507 negate_v3_v3(cent_neg, cent);
1508 BKE_curve_translate(cu, cent_neg, true);
1509
1510 tot_change++;
1511 cu->id.tag |= ID_TAG_DOIT;
1512 do_inverse_offset = true;
1513
1514 if (obedit) {
1515 if (centermode == GEOMETRY_TO_ORIGIN) {
1517 }
1518 break;
1519 }
1520 }
1521 else if (ob->type == OB_FONT) {
1522 /* Get from bounding-box. */
1523
1524 Curve *cu = id_cast<Curve *>(ob->data);
1525 std::optional<Bounds<float3>> bounds = BKE_curve_minmax(cu, true);
1526
1527 if (!bounds && (centermode != ORIGIN_TO_CURSOR)) {
1528 /* Do nothing. */
1529 }
1530 else {
1531 if (centermode == ORIGIN_TO_CURSOR) {
1532 /* Done. */
1533 }
1534 else {
1535 /* extra 0.5 is the height o above line */
1536 cent = math::midpoint(bounds->min, bounds->max);
1537 }
1538
1539 cent[2] = 0.0f;
1540
1541 cu->xof = cu->xof - cent[0];
1542 cu->yof = cu->yof - cent[1];
1543
1544 tot_change++;
1545 cu->id.tag |= ID_TAG_DOIT;
1546 do_inverse_offset = true;
1547 }
1548 }
1549 else if (ob->type == OB_ARMATURE) {
1550 bArmature *arm = id_cast<bArmature *>(ob->data);
1551
1552 if (ID_REAL_USERS(arm) > 1) {
1553#if 0
1554 BKE_report(op->reports, RPT_ERROR, "Cannot apply to a multi user armature");
1555 return;
1556#endif
1557 tot_multiuser_arm_error++;
1558 }
1559 else {
1560 /* Function to recenter armatures in editarmature.c
1561 * Bone + object locations are handled there.
1562 */
1563 ED_armature_origin_set(bmain, ob, cursor, centermode, around);
1564
1565 tot_change++;
1566 arm->id.tag |= ID_TAG_DOIT;
1567 // do_inverse_offset = true; /* docenter_armature() handles this. */
1568
1569 Object *ob_eval = DEG_get_evaluated(depsgraph, ob);
1570 BKE_object_transform_copy(ob_eval, ob);
1571 BKE_armature_copy_bone_transforms(id_cast<bArmature *>(ob_eval->data),
1572 id_cast<bArmature *>(ob->data));
1573 BKE_object_where_is_calc(depsgraph, scene, ob_eval);
1574 BKE_pose_where_is(depsgraph, scene, ob_eval); /* needed for bone parents */
1575
1576 ignore_parent_tx(bmain, depsgraph, scene, ob);
1577
1578 if (obedit) {
1579 break;
1580 }
1581 }
1582 }
1583 else if (ob->type == OB_MBALL) {
1584 MetaBall *mb = id_cast<MetaBall *>(ob->data);
1585
1586 if (centermode == ORIGIN_TO_CURSOR) {
1587 /* done */
1588 }
1589 else if (around == V3D_AROUND_CENTER_BOUNDS) {
1590 BKE_mball_center_bounds(mb, cent);
1591 }
1592 else { /* #V3D_AROUND_CENTER_MEDIAN. */
1593 BKE_mball_center_median(mb, cent);
1594 }
1595
1596 negate_v3_v3(cent_neg, cent);
1597 BKE_mball_translate(mb, cent_neg);
1598
1599 tot_change++;
1600 mb->id.tag |= ID_TAG_DOIT;
1601 do_inverse_offset = true;
1602
1603 if (obedit) {
1604 if (centermode == GEOMETRY_TO_ORIGIN) {
1606 }
1607 break;
1608 }
1609 }
1610 else if (ob->type == OB_LATTICE) {
1611 Lattice *lt = id_cast<Lattice *>(ob->data);
1612
1613 if (centermode == ORIGIN_TO_CURSOR) {
1614 /* done */
1615 }
1616 else if (around == V3D_AROUND_CENTER_BOUNDS) {
1617 if (std::optional<Bounds<float3>> bounds = BKE_lattice_minmax(lt)) {
1618 cent = math::midpoint(bounds->min, bounds->max);
1619 }
1620 }
1621 else { /* #V3D_AROUND_CENTER_MEDIAN. */
1622 BKE_lattice_center_median(lt, cent);
1623 }
1624
1625 negate_v3_v3(cent_neg, cent);
1626 BKE_lattice_translate(lt, cent_neg, true);
1627
1628 tot_change++;
1629 lt->id.tag |= ID_TAG_DOIT;
1630 do_inverse_offset = true;
1631 }
1632 else if (ob->type == OB_CURVES) {
1633 Curves &curves_id = *id_cast<Curves *>(ob->data);
1634 bke::CurvesGeometry &curves = curves_id.geometry.wrap();
1637 {
1638 BKE_report(
1639 op->reports, RPT_WARNING, "Curves Object does not support this set origin operation");
1640 continue;
1641 }
1642
1643 if (curves.is_empty()) {
1644 continue;
1645 }
1646
1647 if (centermode == ORIGIN_TO_CURSOR) {
1648 /* done */
1649 }
1650 else if (around == V3D_AROUND_CENTER_BOUNDS) {
1651 const Bounds<float3> bounds = *curves.bounds_min_max();
1652 cent = math::midpoint(bounds.min, bounds.max);
1653 }
1654 else if (around == V3D_AROUND_CENTER_MEDIAN) {
1655 cent = arithmetic_mean(curves.positions());
1656 }
1657
1658 tot_change++;
1659 curves.translate(-cent);
1660 curves_id.id.tag |= ID_TAG_DOIT;
1661 do_inverse_offset = true;
1662 }
1663 else if (ob->type == OB_GREASE_PENCIL) {
1664 GreasePencil &grease_pencil = *id_cast<GreasePencil *>(ob->data);
1667 {
1668 BKE_report(op->reports,
1670 "Grease Pencil Object does not support this set origin operation");
1671 continue;
1672 }
1673
1674 if (centermode == ORIGIN_TO_CURSOR) {
1675 /* done */
1676 }
1677 else if (around == V3D_AROUND_CENTER_BOUNDS) {
1678 const int current_frame = scene->r.cfra;
1679 if (const std::optional<Bounds<float3>> bounds = grease_pencil.bounds_min_max(
1680 current_frame))
1681 {
1682 cent = math::midpoint(bounds->min, bounds->max);
1683 }
1684 }
1685 else if (around == V3D_AROUND_CENTER_MEDIAN) {
1686 const int current_frame = scene->r.cfra;
1687 float3 center = float3(0.0f);
1688 int total_points = 0;
1689
1690 for (const int layer_i : grease_pencil.layers().index_range()) {
1691 const bke::greasepencil::Layer &layer = grease_pencil.layer(layer_i);
1692 const float4x4 layer_to_object = layer.local_transform();
1693 if (!layer.is_visible()) {
1694 continue;
1695 }
1696 if (const bke::greasepencil::Drawing *drawing = grease_pencil.get_drawing_at(
1697 layer, current_frame))
1698 {
1699 const bke::CurvesGeometry &curves = drawing->strokes();
1700 const Span<float3> positions = curves.positions();
1701
1702 for (const int i : positions.index_range()) {
1703 center += math::transform_point(layer_to_object, positions[i]);
1704 }
1705 total_points += positions.size();
1706 }
1707 }
1708
1709 if (total_points != 0) {
1710 cent = center / total_points;
1711 }
1712 }
1713
1714 tot_change++;
1715
1716 for (const int layer_i : grease_pencil.layers().index_range()) {
1718 const float4x4 layer_to_object = layer.local_transform();
1719 const float4x4 object_to_layer = math::invert(layer_to_object);
1721 frames.foreach_item(
1724 if (base->type != GP_DRAWING) {
1725 return;
1726 }
1728 reinterpret_cast<GreasePencilDrawing *>(base)->wrap();
1730
1731 curves.translate(math::transform_direction(object_to_layer, -cent));
1732 curves.calculate_bezier_auto_handles();
1733 });
1734 }
1735
1736 grease_pencil.id.tag |= ID_TAG_DOIT;
1737 do_inverse_offset = true;
1738 }
1739 else if (ob->type == OB_POINTCLOUD) {
1740 PointCloud &pointcloud = *id_cast<PointCloud *>(ob->data);
1741 MutableSpan<float3> positions = pointcloud.positions_for_write();
1744 {
1745 BKE_report(op->reports,
1747 "Point cloud object does not support this set origin operation");
1748 continue;
1749 }
1750
1751 if (centermode == ORIGIN_TO_CURSOR) {
1752 /* Done. */
1753 }
1754 else if (around == V3D_AROUND_CENTER_BOUNDS) {
1755 if (const std::optional<Bounds<float3>> bounds = pointcloud.bounds_min_max()) {
1756 cent = math::midpoint(bounds->min, bounds->max);
1757 }
1758 }
1759 else if (around == V3D_AROUND_CENTER_MEDIAN) {
1760 cent = arithmetic_mean(positions);
1761 }
1762
1763 tot_change++;
1764 translate_positions(positions, -cent);
1765 pointcloud.tag_positions_changed();
1766 pointcloud.id.tag |= ID_TAG_DOIT;
1767 do_inverse_offset = true;
1768 }
1769 else {
1770 const ID *obdata = static_cast<const ID *>(ob->data);
1771 const short idcode = GS(obdata->name);
1772 const int id_index = BKE_idtype_idcode_to_index(idcode);
1773
1774 if (!reported[id_index]) {
1775 reported[id_index] = true;
1776 BKE_reportf(op->reports,
1777 RPT_INFO,
1778 "Set Origin not supported for %s object(s)",
1780 }
1781 }
1782
1783 /* offset other selected objects */
1784 if (do_inverse_offset && (centermode != GEOMETRY_TO_ORIGIN)) {
1785 float obmat[4][4];
1786
1787 /* was the object data modified
1788 * NOTE: the functions above must set 'cent'. */
1789
1790 /* convert the offset to parent space */
1791 BKE_object_to_mat4(ob, obmat);
1792 mul_v3_mat3_m4v3(centn, obmat, cent); /* omit translation part */
1793
1794 add_v3_v3(ob->loc, centn);
1795
1796 Object *ob_eval = DEG_get_evaluated(depsgraph, ob);
1797 BKE_object_transform_copy(ob_eval, ob);
1798 BKE_object_where_is_calc(depsgraph, scene, ob_eval);
1799 if (ob->type == OB_ARMATURE) {
1800 /* needed for bone parents */
1801 BKE_armature_copy_bone_transforms(id_cast<bArmature *>(ob_eval->data),
1802 id_cast<bArmature *>(ob->data));
1803 BKE_pose_where_is(depsgraph, scene, ob_eval);
1804 }
1805
1806 ignore_parent_tx(bmain, depsgraph, scene, ob);
1807
1808 /* other users? */
1809 // CTX_DATA_BEGIN (C, Object *, ob_other, selected_editable_objects)
1810 //{
1811
1812 /* use existing context looper */
1813 for (Object *ob_other : objects) {
1814 if ((ob_other->flag & OB_DONE) == 0 &&
1815 ((ob->data && (ob->data == ob_other->data)) ||
1816 (ob->instance_collection == ob_other->instance_collection &&
1817 (ob->transflag | ob_other->transflag) & OB_DUPLICOLLECTION)))
1818 {
1819 ob_other->flag |= OB_DONE;
1821
1823 centn, ob_other->object_to_world().ptr(), cent); /* omit translation part */
1824 add_v3_v3(ob_other->loc, centn);
1825
1826 Object *ob_other_eval = DEG_get_evaluated(depsgraph, ob_other);
1827 BKE_object_transform_copy(ob_other_eval, ob_other);
1828 BKE_object_where_is_calc(depsgraph, scene, ob_other_eval);
1829 if (ob_other->type == OB_ARMATURE) {
1830 /* needed for bone parents */
1831 BKE_armature_copy_bone_transforms(id_cast<bArmature *>(ob_eval->data),
1832 id_cast<bArmature *>(ob->data));
1833 BKE_pose_where_is(depsgraph, scene, ob_other_eval);
1834 }
1835 ignore_parent_tx(bmain, depsgraph, scene, ob_other);
1836 }
1837 }
1838 // CTX_DATA_END;
1839 }
1840 }
1841
1842 for (Object &tob : bmain->objects) {
1843 if (tob.data && ((tob.data)->tag & ID_TAG_DOIT)) {
1846 }
1847 /* Special support for dupli-groups. */
1848 else if (tob.instance_collection && tob.instance_collection->id.tag & ID_TAG_DOIT) {
1851 }
1852 }
1853
1854 if (tot_change) {
1856 }
1857
1858 /* Warn if any errors occurred */
1859 if (tot_lib_error + tot_multiuser_arm_error) {
1860 BKE_reportf(op->reports,
1862 "%i object(s) not centered, %i changed:",
1863 tot_lib_error + tot_multiuser_arm_error,
1864 tot_change);
1865 if (tot_lib_error) {
1866 BKE_reportf(op->reports, RPT_WARNING, "|%i linked library object(s)", tot_lib_error);
1867 }
1868 if (tot_multiuser_arm_error) {
1870 op->reports, RPT_WARNING, "|%i multiuser armature object(s)", tot_multiuser_arm_error);
1871 }
1872 }
1873
1874 return OPERATOR_FINISHED;
1875}
1876
1878{
1879 static const EnumPropertyItem prop_set_center_types[] = {
1881 "GEOMETRY_ORIGIN",
1882 0,
1883 "Geometry to Origin",
1884 "Move object geometry to object origin"},
1886 "ORIGIN_GEOMETRY",
1887 0,
1888 "Origin to Geometry",
1889 "Calculate the center of geometry based on the current pivot point (median, otherwise "
1890 "bounding box)"},
1892 "ORIGIN_CURSOR",
1893 0,
1894 "Origin to 3D Cursor",
1895 "Move object origin to position of the 3D cursor"},
1896 /* Intentional naming mismatch since some scripts refer to this. */
1898 "ORIGIN_CENTER_OF_MASS",
1899 0,
1900 "Origin to Center of Mass (Surface)",
1901 "Calculate the center of mass from the surface area"},
1903 "ORIGIN_CENTER_OF_VOLUME",
1904 0,
1905 "Origin to Center of Mass (Volume)",
1906 "Calculate the center of mass from the volume (must be manifold geometry with consistent "
1907 "normals)"},
1908 {0, nullptr, 0, nullptr, nullptr},
1909 };
1910
1911 static const EnumPropertyItem prop_set_bounds_types[] = {
1912 {V3D_AROUND_CENTER_MEDIAN, "MEDIAN", 0, "Median Center", ""},
1913 {V3D_AROUND_CENTER_BOUNDS, "BOUNDS", 0, "Bounds Center", ""},
1914 {0, nullptr, 0, nullptr, nullptr},
1915 };
1916
1917 /* identifiers */
1918 ot->name = "Set Origin";
1919 ot->description =
1920 "Set the object's origin, by either moving the data, or set to center of data, or use 3D "
1921 "cursor";
1922 ot->idname = "OBJECT_OT_origin_set";
1923
1924 /* API callbacks. */
1925 ot->invoke = WM_menu_invoke;
1927
1929
1930 /* flags */
1932
1933 ot->prop = RNA_def_enum(ot->srna, "type", prop_set_center_types, 0, "Type", "");
1934 RNA_def_enum(ot->srna, "center", prop_set_bounds_types, V3D_AROUND_CENTER_MEDIAN, "Center", "");
1935}
1936
1938
1939/* -------------------------------------------------------------------- */
1946
1948#define USE_RELATIVE_ROTATION
1950#define USE_RENDER_OVERRIDE
1955#define USE_FAKE_DEPTH_INIT
1956
1957enum {
1962};
1963
1966 float rot_mat[3][3];
1967 void *obtfm;
1970
1971#ifdef USE_RELATIVE_ROTATION
1972 /* use when translating multiple */
1973 float xform_rot_offset[3][3];
1974#endif
1975};
1976
1980 struct {
1981 float depth;
1982 float normal[3];
1983 bool is_depth_valid;
1984 bool is_normal_valid;
1985 } prev;
1986
1989
1991};
1992
1993#ifdef USE_FAKE_DEPTH_INIT
1995{
1996 float view_co_a[3], view_co_b[3];
1997 const float2 mval_fl = {float(mval[0]), float(mval[1])};
1998 ED_view3d_win_to_ray(xfd->vc.region, mval_fl, view_co_a, view_co_b);
1999 add_v3_v3(view_co_b, view_co_a);
2000 float center[3] = {0.0f};
2001 int center_tot = 0;
2002 for (XFormAxisItem &item : xfd->object_data) {
2003 const Object *ob = item.ob;
2004 const float *ob_co_a = ob->object_to_world().location();
2005 float ob_co_b[3];
2006 add_v3_v3v3(ob_co_b, ob->object_to_world().location(), ob->object_to_world().ptr()[2]);
2007 float view_isect[3], ob_isect[3];
2008 if (isect_line_line_v3(view_co_a, view_co_b, ob_co_a, ob_co_b, view_isect, ob_isect)) {
2009 add_v3_v3(center, view_isect);
2010 center_tot += 1;
2011 }
2012 }
2013 if (center_tot) {
2014 mul_v3_fl(center, 1.0f / center_tot);
2015 float center_proj[3];
2016 ED_view3d_project_v3(xfd->vc.region, center, center_proj);
2017 xfd->prev.depth = center_proj[2];
2018 xfd->prev.is_depth_valid = true;
2019 }
2020}
2021#endif /* USE_FAKE_DEPTH_INIT */
2022
2023static bool object_is_target_compat(const Object *ob)
2024{
2025 if (ob->type == OB_LAMP) {
2026 const Light *la = id_cast<Light *>(ob->data);
2027 if (ELEM(la->type, LA_SUN, LA_SPOT, LA_AREA)) {
2028 return true;
2029 }
2030 }
2031 else if (ob->type == OB_CAMERA) {
2032 return true;
2033 }
2034 return false;
2035}
2036
2038{
2039 XFormAxisData *xfd = static_cast<XFormAxisData *>(op->customdata);
2040
2041#ifdef USE_RENDER_OVERRIDE
2042 if (xfd->depths) {
2044 }
2045#endif
2046
2047 for (XFormAxisItem &item : xfd->object_data) {
2049 }
2050 MEM_delete(xfd);
2051 op->customdata = nullptr;
2052}
2053
2054/* We may want to expose as alternative to: BKE_object_apply_rotation */
2055static void object_apply_rotation(Object *ob, const float rmat[3][3])
2056{
2057 float size[3];
2058 float loc[3];
2059 float rmat4[4][4];
2060 copy_m4_m3(rmat4, rmat);
2061
2062 copy_v3_v3(size, ob->scale);
2063 copy_v3_v3(loc, ob->loc);
2064 BKE_object_apply_mat4(ob, rmat4, true, true);
2065 copy_v3_v3(ob->scale, size);
2066 copy_v3_v3(ob->loc, loc);
2067}
2068/* We may want to extract this to: BKE_object_apply_location */
2069static void object_apply_location(Object *ob, const float loc[3])
2070{
2071 /* quick but weak */
2072 Object ob_prev = dna::shallow_copy(*ob);
2073 float mat[4][4];
2074 copy_m4_m4(mat, ob->object_to_world().ptr());
2075 copy_v3_v3(mat[3], loc);
2076 BKE_object_apply_mat4(ob, mat, true, true);
2077 copy_v3_v3(mat[3], ob->loc);
2078 *ob = dna::shallow_copy(ob_prev);
2079 copy_v3_v3(ob->loc, mat[3]);
2080}
2081
2083 const float rot_orig[3][3],
2084 const float axis[3],
2085 const float location[3],
2086 const bool z_flip)
2087{
2088 float delta[3];
2089 sub_v3_v3v3(delta, ob->object_to_world().location(), location);
2090 if (normalize_v3(delta) != 0.0f) {
2091 if (z_flip) {
2092 negate_v3(delta);
2093 }
2094
2095 if (len_squared_v3v3(delta, axis) > FLT_EPSILON) {
2096 float delta_rot[3][3];
2097 float final_rot[3][3];
2098 rotation_between_vecs_to_mat3(delta_rot, axis, delta);
2099
2100 mul_m3_m3m3(final_rot, delta_rot, rot_orig);
2101
2102 object_apply_rotation(ob, final_rot);
2103
2104 return true;
2105 }
2106 }
2107 return false;
2108}
2109
2111 wmOperator *op,
2112 const XFormAxisData *xfd)
2113{
2114 WorkspaceStatus status(C);
2115 status.opmodal(IFACE_("Confirm"), op->type, AXIS_TARGET_MODAL_CONFIRM);
2116 status.opmodal(IFACE_("Cancel"), op->type, AXIS_TARGET_MODAL_CANCEL);
2117 status.opmodal(
2119}
2120
2122{
2123 static const EnumPropertyItem modal_items[] = {
2124 {AXIS_TARGET_MODAL_CONFIRM, "CONFIRM", 0, "Confirm", ""},
2125 {AXIS_TARGET_MODAL_CANCEL, "CANCEL", 0, "Cancel", ""},
2126 {AXIS_TARGET_MODAL_TRANSLATE_ENABLE, "TRANSLATE_ENABLE", 0, "Translate On", ""},
2127 {AXIS_TARGET_MODAL_TRANSLATE_DISABLE, "TRANSLATE_DISABLE", 0, "Translate Off", ""},
2128 {0, nullptr, 0, nullptr, nullptr},
2129 };
2130
2132 keyconf, "Transform Axis Target Modal Map", modal_items);
2133 WM_modalkeymap_assign(keymap, "OBJECT_OT_transform_axis_target");
2134}
2135
2137{
2138 XFormAxisData *xfd = static_cast<XFormAxisData *>(op->customdata);
2139 for (XFormAxisItem &item : xfd->object_data) {
2140 BKE_object_tfm_restore(item.ob, item.obtfm);
2143 }
2144
2145 ED_workspace_status_text(C, nullptr);
2147}
2148
2150 wmOperator *op,
2151 const wmEvent *event)
2152{
2153 Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
2154 ViewContext vc = ED_view3d_viewcontext_init(C, depsgraph);
2155
2156 if (vc.obact == nullptr || !object_is_target_compat(vc.obact)) {
2157 /* Falls back to texture space transform. */
2158 return OPERATOR_PASS_THROUGH;
2159 }
2160
2161#ifdef USE_RENDER_OVERRIDE
2162 eView3D_Flag2 flag2_prev = vc.v3d->flag2;
2164#endif
2165
2166 ViewDepths *depths = nullptr;
2168 vc.depsgraph, vc.region, vc.v3d, nullptr, V3D_DEPTH_NO_GPENCIL, false, &depths);
2169
2170#ifdef USE_RENDER_OVERRIDE
2171 vc.v3d->flag2 = flag2_prev;
2172#endif
2173
2174 if (depths == nullptr) {
2175 BKE_report(op->reports, RPT_WARNING, "Unable to access depth buffer, using view plane");
2176 return OPERATOR_CANCELLED;
2177 }
2178
2180
2181 XFormAxisData *xfd = MEM_new<XFormAxisData>(__func__);
2182 op->customdata = xfd;
2183
2184 /* Don't change this at runtime. */
2185 xfd->vc = vc;
2186 xfd->depths = depths;
2187 xfd->vc.mval[0] = event->mval[0];
2188 xfd->vc.mval[1] = event->mval[1];
2189
2190 xfd->prev.depth = 1.0f;
2191 xfd->prev.is_depth_valid = false;
2192 xfd->prev.is_normal_valid = false;
2193 xfd->is_translate = false;
2194
2196
2197 xfd->object_data.append({});
2198 xfd->object_data.last().ob = xfd->vc.obact;
2199
2200 CTX_DATA_BEGIN (C, Object *, ob, selected_editable_objects) {
2201 if ((ob != xfd->vc.obact) && object_is_target_compat(ob)) {
2202 xfd->object_data.append({});
2203 xfd->object_data.last().ob = ob;
2204 }
2205 }
2207
2208 for (XFormAxisItem &item : xfd->object_data) {
2209 item.obtfm = BKE_object_tfm_backup(item.ob);
2210 BKE_object_rot_to_mat3(item.ob, item.rot_mat, true);
2211
2212 /* Detect negative scale matrix. */
2213 float full_mat3[3][3];
2214 BKE_object_to_mat3(item.ob, full_mat3);
2215 item.is_z_flip = dot_v3v3(item.rot_mat[2], full_mat3[2]) < 0.0f;
2216 }
2217
2219
2221}
2222
2224 wmOperator *op,
2225 const wmEvent *event)
2226{
2227 XFormAxisData *xfd = static_cast<XFormAxisData *>(op->customdata);
2228 ARegion *region = xfd->vc.region;
2229
2231
2232 bool is_translate = xfd->is_translate;
2233 bool is_translate_init = false;
2234
2236 bool update = false;
2237
2238 /* Handle modal keymap events. */
2239 if (event->type == EVT_MODAL_MAP) {
2240 switch (event->val) {
2242 status = OPERATOR_FINISHED;
2243 break;
2244 }
2246 status = OPERATOR_CANCELLED;
2247 break;
2248 }
2250 if (!is_translate) {
2251 is_translate = true;
2252 is_translate_init = true;
2253 update = true;
2254 }
2255 break;
2256 }
2258 if (is_translate) {
2259 is_translate = false;
2260 update = true;
2261 }
2262 break;
2263 }
2264 }
2265 }
2266 else if (event->type == MOUSEMOVE) {
2267 update = true;
2268 }
2269 else {
2270 if (ISMOUSE_BUTTON(xfd->init_event)) {
2271 if ((event->type == xfd->init_event) && (event->val == KM_RELEASE)) {
2272 status = OPERATOR_FINISHED;
2273 }
2274 }
2275 }
2276
2277 if (update) {
2278 const ViewDepths *depths = xfd->depths;
2279 if (depths && (uint(event->mval[0]) < depths->w) && (uint(event->mval[1]) < depths->h)) {
2280 float depth_fl = 1.0f;
2281 ED_view3d_depth_read_cached(depths, event->mval, 0, &depth_fl);
2282 float location_world[3];
2283 if (depth_fl == 1.0f) {
2284 if (xfd->prev.is_depth_valid) {
2285 depth_fl = xfd->prev.depth;
2286 }
2287 }
2288
2289#ifdef USE_FAKE_DEPTH_INIT
2290 /* First time only. */
2291 if (depth_fl == 1.0f) {
2292 if (xfd->prev.is_depth_valid == false) {
2294 if (xfd->prev.is_depth_valid) {
2295 depth_fl = xfd->prev.depth;
2296 }
2297 }
2298 }
2299#endif
2300
2301 double depth = double(depth_fl);
2302 if ((depth > depths->depth_range[0]) && (depth < depths->depth_range[1])) {
2303 xfd->prev.depth = depth_fl;
2304 xfd->prev.is_depth_valid = true;
2305 if (ED_view3d_depth_unproject_v3(region, event->mval, depth, location_world)) {
2306 if (is_translate) {
2307
2308 float normal[3];
2309 bool normal_found = false;
2310 if (ED_view3d_depth_read_cached_normal(region, depths, event->mval, normal)) {
2311 normal_found = true;
2312
2313 /* cheap attempt to smooth normals out a bit! */
2314 const int ofs = 2;
2315 for (int x = -ofs; x <= ofs; x += ofs / 2) {
2316 for (int y = -ofs; y <= ofs; y += ofs / 2) {
2317 if (x != 0 && y != 0) {
2318 const int mval_ofs[2] = {event->mval[0] + x, event->mval[1] + y};
2319 float n[3];
2320 if (ED_view3d_depth_read_cached_normal(region, depths, mval_ofs, n)) {
2321 add_v3_v3(normal, n);
2322 }
2323 }
2324 }
2325 }
2326 normalize_v3(normal);
2327 }
2328 else if (xfd->prev.is_normal_valid) {
2329 copy_v3_v3(normal, xfd->prev.normal);
2330 normal_found = true;
2331 }
2332
2333 {
2334#ifdef USE_RELATIVE_ROTATION
2335 if (is_translate_init && xfd->object_data.size() > 1) {
2336 float xform_rot_offset_inv_first[3][3];
2337 for (const int i : xfd->object_data.index_range()) {
2338 XFormAxisItem &item = xfd->object_data[i];
2339 copy_m3_m4(item.xform_rot_offset, item.ob->object_to_world().ptr());
2341
2342 if (i == 0) {
2343 invert_m3_m3(xform_rot_offset_inv_first, xfd->object_data[0].xform_rot_offset);
2344 }
2345 else {
2347 item.xform_rot_offset, item.xform_rot_offset, xform_rot_offset_inv_first);
2348 }
2349 }
2350 }
2351
2352#endif
2353
2354 for (const int i : xfd->object_data.index_range()) {
2355 XFormAxisItem &item = xfd->object_data[i];
2356 if (is_translate_init) {
2357 float ob_axis[3];
2358 item.xform_dist = len_v3v3(item.ob->object_to_world().location(),
2359 location_world);
2360 normalize_v3_v3(ob_axis, item.ob->object_to_world().ptr()[2]);
2361 /* Scale to avoid adding distance when moving between surfaces. */
2362 if (normal_found) {
2363 float scale = fabsf(dot_v3v3(ob_axis, normal));
2364 item.xform_dist *= scale;
2365 }
2366 }
2367
2368 float target_normal[3];
2369
2370 if (normal_found) {
2371 copy_v3_v3(target_normal, normal);
2372 }
2373 else {
2374 normalize_v3_v3(target_normal, item.ob->object_to_world().ptr()[2]);
2375 }
2376
2377#ifdef USE_RELATIVE_ROTATION
2378 if (normal_found) {
2379 if (i != 0) {
2380 mul_m3_v3(item.xform_rot_offset, target_normal);
2381 }
2382 }
2383#endif
2384 {
2385 float loc[3];
2386
2387 copy_v3_v3(loc, location_world);
2388 madd_v3_v3fl(loc, target_normal, item.xform_dist);
2389 object_apply_location(item.ob, loc);
2390 /* so orient behaves as expected */
2392 }
2393
2395 item.ob, item.rot_mat, item.rot_mat[2], location_world, item.is_z_flip);
2396
2399 }
2400 if (normal_found) {
2401 copy_v3_v3(xfd->prev.normal, normal);
2402 xfd->prev.is_normal_valid = true;
2403 }
2404 }
2405 }
2406 else {
2407 for (XFormAxisItem &item : xfd->object_data) {
2409 item.ob, item.rot_mat, item.rot_mat[2], location_world, item.is_z_flip))
2410 {
2413 }
2414 }
2415 xfd->prev.is_normal_valid = false;
2416 }
2417 }
2418 }
2419 }
2420 xfd->is_translate = is_translate;
2421
2423 }
2424
2425 if (status & OPERATOR_RUNNING_MODAL) {
2427 }
2428 else if (status & OPERATOR_FINISHED) {
2429 Scene *scene = CTX_data_scene(C);
2430 /* Perform auto-keying for rotational changes for all objects. */
2431 for (XFormAxisItem &item : xfd->object_data) {
2432 PointerRNA ptr = RNA_pointer_create_discrete(&item.ob->id, RNA_Object, &item.ob->id);
2433 const char *rotation_property = "rotation_euler";
2434 switch (item.ob->rotmode) {
2435 case ROT_MODE_QUAT:
2436 rotation_property = "rotation_quaternion";
2437 break;
2438 case ROT_MODE_AXISANGLE:
2439 rotation_property = "rotation_axis_angle";
2440 break;
2441 default:
2442 break;
2443 }
2444 PropertyRNA *prop = RNA_struct_find_property(&ptr, rotation_property);
2445 animrig::autokeyframe_property(C, scene, &ptr, prop, -1, scene->r.cfra, true);
2446 }
2447 ED_workspace_status_text(C, nullptr);
2449 }
2450 else if (status & OPERATOR_CANCELLED) {
2452 }
2453
2454 return status;
2455}
2456
2458{
2459 /* identifiers */
2460 ot->name = "Look at Surface";
2461 ot->description =
2462 "Interactively point cameras and lights to the surface under the pointer (Ctrl to "
2463 "translate)";
2464 ot->idname = "OBJECT_OT_transform_axis_target";
2465
2466 /* API callbacks. */
2471
2472 /* flags */
2474}
2475
2476#undef USE_RELATIVE_ROTATION
2477
2479
2480} // namespace blender::ed::object
Functions to insert, delete or modify keyframes.
Functionality to interact with keying sets.
#define CTX_DATA_BEGIN(C, Type, instance, member)
#define CTX_DATA_COUNT(C, member)
#define CTX_DATA_END
Low-level operations for curves.
Low-level operations for grease pencil.
#define FOREACH_SELECTED_EDITABLE_OBJECT_END
Definition BKE_layer.hh:403
#define FOREACH_SELECTED_EDITABLE_OBJECT_BEGIN(_view_layer, _v3d, _instance)
Definition BKE_layer.hh:391
General operations, lookup, etc. for blender objects.
#define IFACE_(msgid)
#define ID_IS_EDITABLE(_id)
Definition DNA_ID.h:708
#define ID_REAL_USERS(id)
Definition DNA_ID.h:679
#define ID_IS_OVERRIDE_LIBRARY(_id)
Definition DNA_ID.h:736
Object groups, one object can be in many groups at once.
Object is a sort of wrapper for general info.
Read Blender memory allocation and freeing.
#define C
Definition RandGen.cpp:29
#define NC_WINDOW
Definition WM_types.hh:388
#define ND_TRANSFORM
Definition WM_types.hh:475
#define NC_OBJECT
Definition WM_types.hh:392
#define INIT_MINMAX(min, max)
#define ELEM(...)
#define IS_EQF(a, b)
#define BM_ITER_MESH(ele, iter, bm, itype)
btScalar max
int64_t size() const
Definition BLI_array.hh:267
const T * data() const
Definition BLI_array.hh:323
IndexRange index_range() const
Definition BLI_array.hh:371
bool is_empty() const
Definition BLI_array.hh:275
void foreach_item(const FuncT &func) const
Definition BLI_map.hh:687
constexpr IndexRange index_range() const
Definition BLI_span.hh:676
constexpr int64_t size() const
Definition BLI_span.hh:256
constexpr const T * end() const
Definition BLI_span.hh:228
constexpr IndexRange index_range() const
Definition BLI_span.hh:405
constexpr const T * begin() const
Definition BLI_span.hh:224
constexpr bool is_empty() const
Definition BLI_span.hh:264
int64_t size() const
void append(const T &value)
bool is_empty() const
void opmodal(std::string text, const wmOperatorType *ot, int propvalue, bool inverted=false)
Definition area.cc:1107
MutableSpan< float > radii_for_write()
bke::CurvesGeometry & strokes_for_write()
#define rot(x, k)
#define FLT_EPSILON
#define layer
float3x3 scale(float3x3 mat, float2 scale)
bool is_autokey_on(const Scene *scene)
KeyingSet * get_keyingset_for_autokeying(const Scene *scene, const char *transformKSName)
bool autokeyframe_property(bContext *C, Scene *scene, PointerRNA *ptr, PropertyRNA *prop, int rnaindex, float cfra, bool only_if_property_keyed)
void autokeyframe_object(bContext *C, const Scene *scene, Object *ob, Span< RNAPath > rna_paths)
void mesh_flip_faces(Mesh &mesh, const IndexMask &selection)
void mesh_transform(Mesh &mesh, const float4x4 &transform, bool do_shape_keys)
void mesh_translate(Mesh &mesh, const float3 &translation, bool do_shape_keys)
internal::ShallowDataConstRef< T > shallow_copy(const T &other)
Definition DNA_defs.h:147
static wmOperatorStatus visual_transform_apply_exec(bContext *C, wmOperator *)
static bool apply_objects_internal_need_single_user(bContext *C)
void single_obdata_user_make(Main *bmain, Scene *scene, Object *ob)
static Array< Object * > sorted_selected_editable_objects(bContext *C)
static void translate_positions(MutableSpan< float3 > positions, const float3 &translation)
static void object_transform_axis_target_calc_depth_init(XFormAxisData *xfd, const int mval[2])
static void object_clear_scale(Object *ob, const bool clear_delta)
void OBJECT_OT_origin_set(wmOperatorType *ot)
static bool object_orient_to_location(Object *ob, const float rot_orig[3][3], const float axis[3], const float location[3], const bool z_flip)
void data_xform_container_destroy(XFormObjectData_Container *xds)
static void object_apply_location(Object *ob, const float loc[3])
static wmOperatorStatus object_transform_axis_target_modal(bContext *C, wmOperator *op, const wmEvent *event)
void OBJECT_OT_transform_axis_target(wmOperatorType *ot)
static void object_clear_loc(Object *ob, const bool clear_delta)
static void object_transform_axis_target_update_status(bContext *C, wmOperator *op, const XFormAxisData *xfd)
static wmOperatorStatus object_clear_transform_generic_exec(bContext *C, wmOperator *op, void(*clear_func)(Object *, const bool), const char default_ksName[])
void OBJECT_OT_origin_clear(wmOperatorType *ot)
static wmOperatorStatus object_origin_set_exec(bContext *C, wmOperator *op)
static void object_transform_axis_target_free_data(wmOperator *op)
XFormObjectSkipChild_Container * xform_skip_child_container_create()
static void append_sorted_object_parent_hierarchy(Object *root_object, Object *object, Object **sorted_objects, int *object_index)
void OBJECT_OT_rotation_clear(wmOperatorType *ot)
void object_transform_axis_target_modal_keymap(wmKeyConfig *keyconf)
static bool apply_objects_internal_can_multiuser(bContext *C)
void data_xform_container_update_all(XFormObjectData_Container *xds, Main *bmain, Depsgraph *depsgraph)
static wmOperatorStatus object_scale_clear_exec(bContext *C, wmOperator *op)
void object_xform_skip_child_container_destroy(XFormObjectSkipChild_Container *xcs)
static void object_clear_rot(Object *ob, const bool clear_delta)
Object * context_active_object(const bContext *C)
static bool object_is_target_compat(const Object *ob)
static void object_transform_axis_target_cancel(bContext *C, wmOperator *op)
static void ignore_parent_tx(Main *bmain, Depsgraph *depsgraph, Scene *scene, Object *ob)
void OBJECT_OT_scale_clear(wmOperatorType *ot)
static wmOperatorStatus object_transform_apply_invoke(bContext *C, wmOperator *op, const wmEvent *)
void OBJECT_OT_visual_transform_apply(wmOperatorType *ot)
static wmOperatorStatus object_parent_inverse_apply_exec(bContext *C, wmOperator *)
static wmOperatorStatus object_transform_apply_exec(bContext *C, wmOperator *op)
static wmOperatorStatus object_origin_clear_exec(bContext *C, wmOperator *)
void OBJECT_OT_location_clear(wmOperatorType *ot)
static wmOperatorStatus object_transform_axis_target_invoke(bContext *C, wmOperator *op, const wmEvent *event)
void OBJECT_OT_parent_inverse_apply(wmOperatorType *ot)
static float3 arithmetic_mean(const Span< float3 > values)
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)
void xform_skip_child_container_item_ensure_from_array(XFormObjectSkipChild_Container *xcs, const Main &bmain, const Scene *scene, ViewLayer *view_layer, Object **objects, uint objects_len)
XFormObjectData_Container * data_xform_container_create()
static void object_apply_rotation(Object *ob, const float rmat[3][3])
static wmOperatorStatus object_rotation_clear_exec(bContext *C, wmOperator *op)
static wmOperatorStatus apply_objects_internal(bContext *C, ReportList *reports, bool apply_loc, bool apply_rot, bool apply_scale, bool do_props, bool do_single_user, bool corrective_flip_normals)
void OBJECT_OT_transform_apply(wmOperatorType *ot)
static wmOperatorStatus object_location_clear_exec(bContext *C, wmOperator *op)
BLI_INLINE Texture * wrap(MTLTexture *texture)
CartesianBasis invert(const CartesianBasis &basis)
T midpoint(const T &a, const T &b)
VecBase< T, 3 > transform_direction(const MatBase< T, 3, 3 > &mat, const VecBase< T, 3 > &direction)
T determinant(const MatBase< T, Size, Size > &mat)
void transform_points(const float4x4 &transform, MutableSpan< float3 > points, bool use_threading=true)
VecBase< T, 3 > transform_point(const CartesianBasis &basis, const VecBase< T, 3 > &v)
void parallel_for(const IndexRange range, const int64_t grain_size, const Function &function, const TaskSizeHints &size_hints=detail::TaskSizeHints_Static(1))
Definition BLI_task.hh:69
const char * BKE_idtype_idcode_to_name(short idcode)
Definition idtype.cc:261
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
MINLINE float len_squared_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT
MINLINE void negate_v3_v3(float r[3], const float a[3])
void mul_m3_v3(const float M[3][3], float r[3])
bool BKE_mesh_center_median(const Mesh *mesh, float r_cent[3])
bool ED_operator_scene_editable(bContext *C)
wmOperatorStatus WM_menu_invoke(bContext *C, wmOperator *op, const wmEvent *)
void BKE_object_rot_to_mat3(const Object *ob, float r_mat[3][3], bool use_drot)
Definition object.cc:2906
int RNA_enum_get(PointerRNA *ptr, const char *name)
MINLINE int compare_ff_relative(float a, float b, float max_diff, int max_ulps)
@ RPT_WARNING
Definition BKE_report.hh:40
void axis_angle_to_eulO(float eul[3], short order, const float axis[3], float angle)
void ED_view3d_win_to_ray(const ARegion *region, const float mval[2], float r_ray_start[3], float r_ray_normal[3])
void BKE_mball_translate(MetaBall *mb, const float offset[3])
Definition mball.cc:549
PropertyRNA * RNA_struct_find_property(PointerRNA *ptr, const char *identifier)
BMesh * BKE_editmesh_bmesh_get_for_write(Mesh *mesh)
Definition editmesh.cc:79
void BKE_object_apply_parent_inverse(Object *ob)
Definition object.cc:3671
ViewContext ED_view3d_viewcontext_init(bContext *C, Depsgraph *depsgraph)
MINLINE void copy_v3_v3(float r[3], const float a[3])
unsigned int uint
Definition BKE_text.h:55
void ED_armature_origin_set(Main *bmain, Object *ob, const float cursor[3], int centermode, int around)
void BKE_curve_translate(Curve *cu, const float offset[3], bool do_keys)
Definition curve.cc:5266
void copy_m3_m4(float m1[3][3], const float m2[4][4])
@ SCE_XFORM_SKIP_CHILDREN
void minmax_v3v3_v3(float min[3], float max[3], const float vec[3])
void ED_view3d_depths_free(ViewDepths *depths)
void id_us_plus(ID *id)
Definition lib_id.cc:433
MINLINE void add_v3_v3v3(float r[3], const float a[3], const float b[3])
void multiresModifier_scale_disp(Depsgraph *depsgraph, Scene *scene, Object *ob)
Definition multires.cc:709
void copy_m4_m3(float m1[4][4], const float m2[3][3])
bool BKE_mball_center_bounds(const MetaBall *mb, float r_cent[3])
Definition mball.cc:511
Depsgraph * CTX_data_depsgraph_pointer(const bContext *C)
float mat4_to_scale(const float mat[4][4])
bool invert_m3_m3(float inverse[3][3], const float mat[3][3])
void normalize_m3(float R[3][3]) ATTR_NONNULL()
void BKE_lattice_transform(Lattice *lt, const float mat[4][4], bool do_keys)
Definition lattice.cc:645
int RNA_property_enum_get(PointerRNA *ptr, PropertyRNA *prop)
std::optional< Bounds< float3 > > BKE_lattice_minmax(const Lattice *lt)
Definition lattice.cc:625
bool invert_m4_m4(float inverse[4][4], const float mat[4][4])
@ V3D_AROUND_CENTER_BOUNDS
@ V3D_AROUND_CENTER_MEDIAN
PropertyRNA * RNA_def_enum(StructOrFunctionRNA *cont_, const char *identifier, const EnumPropertyItem *items, const int default_value, const char *ui_name, const char *ui_description)
void quat_to_eul(float eul[3], const float quat[4])
void mul_v3_mat3_m4v3(float r[3], const float mat[4][4], const float vec[3])
void BKE_curve_transform_ex(Curve *cu, const float mat[4][4], bool do_keys, bool do_props, float unit_scale)
Definition curve.cc:5188
void view3d_operator_needs_gpu(const bContext *C)
void BKE_pose_where_is(Depsgraph *depsgraph, Scene *scene, Object *ob)
MatBase< float, 4, 4 > float4x4
void ED_region_tag_redraw(ARegion *region)
Definition area.cc:681
MovieClip * BKE_object_movieclip_get(Scene *scene, const Object *ob, bool use_default)
Definition object.cc:5154
ViewLayer * CTX_data_view_layer(const bContext *C)
void BKE_object_apply_mat4(Object *ob, const float mat[4][4], bool use_compat, bool use_parent)
Definition object.cc:3663
void BKE_object_batch_cache_dirty_tag(Object *ob)
void BKE_scene_graph_evaluated_ensure(Depsgraph *depsgraph, Main *bmain)
Definition scene.cc:2872
MINLINE void mul_v3_fl(float r[3], float f)
bool RNA_property_boolean_get(PointerRNA *ptr, PropertyRNA *prop)
MINLINE void sub_v3_v3(float r[3], const float a[3])
void unit_axis_angle(float axis[3], float *angle)
void mul_m4_v3(const float M[4][4], float r[3])
void unit_qt(float q[4])
MINLINE void madd_v3_v3fl(float r[3], const float a[3], float f)
void BKE_tracking_reconstruction_scale(MovieTracking *tracking, float scale[3])
VecBase< float, 2 > float2
void eulO_to_axis_angle(float axis[3], float *angle, const float eul[3], short order)
bool BKE_mesh_center_of_surface(const Mesh *mesh, float r_cent[3])
void BKE_object_scale_to_mat3(const Object *ob, float r_mat[3][3])
Definition object.cc:2899
void copy_qt_qt(float q[4], const float a[4])
void BKE_object_to_mat4(const Object *ob, float r_mat[4][4])
Definition object.cc:3125
void DEG_id_tag_update(ID *id, unsigned int flags)
void BKE_report(ReportList *reports, eReportType type, const char *message)
Definition report.cc:162
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)
void * BKE_object_tfm_backup(Object *ob)
Definition object.cc:4141
Object * CTX_data_edit_object(const bContext *C)
void eul_to_quat(float quat[4], const float eul[3])
int BKE_idtype_idcode_to_index(short idcode)
Definition idtype.cc:338
MINLINE void negate_v3(float r[3])
PointerRNA RNA_pointer_create_discrete(ID *id, StructRNA *type, void *data)
void BKE_mball_transform(MetaBall *mb, const float mat[4][4], bool do_props)
Definition mball.cc:523
bool RNA_boolean_get(PointerRNA *ptr, const char *name)
void ED_view3d_project_v3(const ARegion *region, const float world[3], float r_region_co[3])
wmOperatorStatus WM_operator_confirm_ex(bContext *C, wmOperator *op, const char *title, const char *message, const char *confirm_text, ui::AlertIcon icon, bool cancel_default)
MINLINE void zero_v3(float r[3])
void BKE_main_id_tag_all(Main *mainvar, int tag, bool value)
Definition lib_id.cc:1314
void WM_event_add_notifier(const bContext *C, uint type, void *reference)
void BKE_object_tfm_restore(Object *ob, void *obtfm_pt)
Definition object.cc:4164
void BKE_object_transform_copy(Object *ob_tar, const Object *ob_src)
Definition object.cc:2648
MINLINE float normalize_v3_v3(float r[3], const float a[3])
void BKE_main_id_newptr_and_tag_clear(Main *bmain)
Definition lib_id.cc:2097
MINLINE float normalize_v3(float n[3])
MINLINE void add_v3_v3(float r[3], const float a[3])
wmEventHandler_Op * WM_event_add_modal_handler(bContext *C, wmOperator *op)
void RNA_def_property_flag(PropertyRNA *prop, PropertyFlag flag)
MINLINE void sub_v3_v3v3(float r[3], const float a[3], const float b[3])
void mid_v3_v3v3(float r[3], const float a[3], const float b[3])
bool ED_operator_objectmode(bContext *C)
void BKE_reportf(ReportList *reports, eReportType type, const char *format,...) ATTR_PRINTF_FORMAT(3
Definition report.cc:191
bool BKE_curve_center_median(Curve *cu, float cent[3])
Definition curve.cc:5151
float4x4 BKE_object_calc_parent(Depsgraph *depsgraph, Scene *scene, Object *ob)
Definition object.cc:3583
Main * CTX_data_main(const bContext *C)
void unit_m3(float m[3][3])
MINLINE void copy_v3_fl(float r[3], float f)
void BKE_object_to_mat3(const Object *ob, float r_mat[3][3])
Definition object.cc:3112
void ED_view3d_depth_override(Depsgraph *depsgraph, ARegion *region, View3D *v3d, Object *obact, eV3DDepthOverrideMode mode, bool use_overlay, ViewDepths **r_depths)
bool ED_view3d_depth_read_cached(const ViewDepths *vd, const int mval[2], int margin, float *r_depth)
void EDBM_mesh_normals_update(BMesh *bm)
void mul_m4_m4_post(float R[4][4], const float B[4][4])
@ ID_RECALC_PARAMETERS
Definition DNA_ID.h:1138
@ ID_RECALC_TRANSFORM
Definition DNA_ID.h:1054
@ ID_RECALC_SYNC_TO_EVAL
Definition DNA_ID.h:1118
@ ID_RECALC_GEOMETRY
Definition DNA_ID.h:1074
ID_Type GS(const char *name)
Definition DNA_ID.h:410
@ PROP_SKIP_SAVE
Definition RNA_types.hh:414
@ PROP_HIDDEN
Definition RNA_types.hh:408
void BKE_lattice_translate(Lattice *lt, const float offset[3], bool do_keys)
Definition lattice.cc:665
bool BKE_object_minmax_dupli(Depsgraph *depsgraph, Object *ob, float3 &r_min, float3 &r_max, bool use_hidden)
Definition object.cc:3999
bool ED_operator_region_view3d_active(bContext *C)
@ ID_TAG_DOIT
Definition DNA_ID.h:1029
void RNA_property_enum_set(PointerRNA *ptr, PropertyRNA *prop, int value)
@ V3D_DEPTH_NO_GPENCIL
Definition ED_view3d.hh:209
bool ED_view3d_depth_read_cached_normal(const ARegion *region, const ViewDepths *depths, const int mval[2], float r_normal[3])
@ KM_RELEASE
Definition WM_types.hh:325
void WM_modalkeymap_assign(wmKeyMap *km, const char *opname)
bool BKE_mesh_center_of_volume(const Mesh *mesh, float r_cent[3])
void BKE_armature_copy_bone_transforms(bArmature *armature_dst, const bArmature *armature_src)
void DEG_relations_tag_update(Main *bmain)
void RNA_property_boolean_set(PointerRNA *ptr, PropertyRNA *prop, bool value)
Scene * CTX_data_scene(const bContext *C)
MINLINE void copy_v4_v4(float r[4], const float a[4])
wmKeyMap * WM_modalkeymap_ensure(wmKeyConfig *keyconf, const char *idname, const EnumPropertyItem *items)
Definition wm_keymap.cc:972
@ OPTYPE_REGISTER
Definition WM_types.hh:188
@ OPTYPE_UNDO
Definition WM_types.hh:190
@ OPTYPE_BLOCKING
Definition WM_types.hh:192
void BKE_lattice_center_median(Lattice *lt, float cent[3])
Definition lattice.cc:607
bool ED_view3d_depth_unproject_v3(const ARegion *region, const int mval[2], double depth, float r_location_world[3])
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
std::optional< Bounds< float3 > > BKE_curve_minmax(const Curve *cu, bool use_radius)
Definition curve.cc:5131
VecBase< float, 3 > float3
PropertyRNA * RNA_def_boolean(StructOrFunctionRNA *cont_, const char *identifier, const bool default_value, const char *ui_name, const char *ui_description)
MINLINE float len_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT
int WM_userdef_event_type_from_keymap_type(int kmitype)
Scene * DEG_get_evaluated_scene(const Depsgraph *graph)
bool BKE_id_is_editable(const Main *bmain, const ID *id)
Definition lib_id.cc:2782
void BKE_object_tfm_free(void *obtfm_pt)
Definition object.cc:4185
Object * CTX_data_active_object(const bContext *C)
MINLINE float dot_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT
void id_us_min(ID *id)
Definition lib_id.cc:441
void ED_workspace_status_text(bContext *C, const char *str)
Definition area.cc:1153
bool BKE_mball_center_median(const MetaBall *mb, float r_cent[3])
Definition mball.cc:493
float mat3_to_scale(const float mat[3][3])
void mul_qt_fl(float q[4], float f)
bool RNA_property_is_set(PointerRNA *ptr, PropertyRNA *prop)
void rotation_between_vecs_to_mat3(float m[3][3], const float v1[3], const float v2[3])
void BKE_object_eval_transform_all(Depsgraph *depsgraph, Scene *scene, Object *object)
View3D * CTX_wm_view3d(const bContext *C)
void BKE_armature_transform(bArmature *arm, const float mat[4][4], bool do_props)
int isect_line_line_v3(const float v1[3], const float v2[3], const float v3[3], const float v4[3], float r_i1[3], float r_i2[3])
#define fabsf
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
#define min(a, b)
Definition sort.cc:38
struct TextBox * tb
struct Key * key
char name[258]
Definition DNA_ID.h:433
ListBaseT< Object > objects
Definition BKE_main.hh:388
const c_style_mat & ptr() const
struct MovieTracking tracking
struct Object * parent
float parentinv[4][4]
bke::ObjectRuntime * runtime
eObject_ProtectFlag protectflag
struct Collection * instance_collection
View3DCursor cursor
struct RenderData r
struct ToolSettings * toolsettings
eView3D_Flag2 flag2
Depsgraph * depsgraph
Definition ED_view3d.hh:78
unsigned short w
Definition ED_view3d.hh:92
unsigned short h
Definition ED_view3d.hh:92
double depth_range[2]
Definition ED_view3d.hh:96
struct blender::ed::object::XFormAxisData::@341104147223060271170006317374300127132163113176 prev
wmEventType type
Definition WM_types.hh:817
wmOperatorStatus(*) exec(bContext *C, wmOperator *op) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1125
const char * description
Definition WM_types.hh:1115
void(*) cancel(bContext *C, wmOperator *op)
Definition WM_types.hh:1149
bool(*) poll(bContext *C) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1165
wmOperatorStatus(*) invoke(bContext *C, wmOperator *op, const wmEvent *event) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1141
wmOperatorStatus(*) modal(bContext *C, wmOperator *op, const wmEvent *event) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1157
struct ReportList * reports
struct wmOperatorType * type
#define ISMOUSE_BUTTON(event_type)