Blender V5.3
view3d_snap.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
10#include "DNA_meta_types.h"
11#include "DNA_object_types.h"
13
14#include "BLI_bounds.hh"
15#include "BLI_listbase.hh"
16#include "BLI_math_matrix.hh"
17#include "BLI_math_matrix_c.hh"
19#include "BLI_math_vector.hh"
20#include "BLI_math_vector_c.hh"
21#include "BLI_utildefines.hh"
22#include "BLI_vector.hh"
23
24#include "BKE_action.hh"
25#include "BKE_armature.hh"
26#include "BKE_context.hh"
27#include "BKE_crazyspace.hh"
28#include "BKE_editmesh.hh"
29#include "BKE_layer.hh"
30#include "BKE_main.hh"
31#include "BKE_mball.hh"
32#include "BKE_object.hh"
33#include "BKE_report.hh"
34#include "BKE_scene.hh"
35#include "BKE_tracking.hh"
36
37#include "DEG_depsgraph.hh"
39
40#include "WM_api.hh"
41#include "WM_types.hh"
42
43#include "RNA_access.hh"
44#include "RNA_define.hh"
45
46#include "ED_anim_api.hh"
47#include "ED_curves.hh"
48#include "ED_grease_pencil.hh"
49#include "ED_keyframing.hh"
50#include "ED_object.hh"
51#include "ED_pointcloud.hh"
52#include "ED_screen.hh"
53#include "ED_transverts.hh"
54
55#include "ANIM_action.hh"
56#include "ANIM_armature.hh"
58#include "ANIM_keyframing.hh"
59#include "ANIM_keyingsets.hh"
60
61#include "view3d_intern.hh"
62
63namespace blender {
64
65static bool snap_curs_to_sel_ex(bContext *C, const int pivot_point, float r_cursor[3]);
66static bool snap_calc_active_center(bContext *C, const bool select_only, float r_center[3]);
67
68/* -------------------------------------------------------------------- */
71
74{
75 using namespace blender::ed;
76 Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
77 ViewLayer *view_layer_eval = DEG_get_evaluated_view_layer(depsgraph);
79 const Main *bmain = CTX_data_main(C);
80 Scene *scene = CTX_data_scene(C);
81 ARegion *region = CTX_wm_region(C);
82 View3D *v3d = CTX_wm_view3d(C);
83 TransVertStore tvs = {nullptr};
84 TransVert *tv;
85 float gridf, imat[3][3], bmat[3][3], vec[3];
86 int a;
87
88 gridf = ED_view3d_grid_view_scale(scene, v3d, region, nullptr);
89
90 if (OBEDIT_FROM_OBACT(obact)) {
91 const Main *bmain = CTX_data_main(C);
92 ViewLayer *view_layer = CTX_data_view_layer(C);
94 *bmain, scene, view_layer, CTX_wm_view3d(C));
95 for (Object *obedit : objects) {
96 if (obedit->type == OB_MESH) {
97 const BMesh *bm = BKE_editmesh_bmesh_get(obedit);
98 if (bm->totvertsel == 0) {
99 continue;
100 }
101 }
102
104 continue;
105 }
106
107 if (ED_transverts_check_obedit(obedit)) {
108 const Object *obedit_eval = DEG_get_evaluated(depsgraph, obedit);
109 ED_transverts_create_from_obedit(&tvs, obedit_eval, 0);
110 }
111
112 if (tvs.transverts_tot != 0) {
113 copy_m3_m4(bmat, obedit->object_to_world().ptr());
114 invert_m3_m3(imat, bmat);
115
116 tv = tvs.transverts;
117 for (a = 0; a < tvs.transverts_tot; a++, tv++) {
118 copy_v3_v3(vec, tv->loc);
119 mul_m3_v3(bmat, vec);
120 add_v3_v3(vec, obedit->object_to_world().location());
121 vec[0] = gridf * floorf(0.5f + vec[0] / gridf);
122 vec[1] = gridf * floorf(0.5f + vec[1] / gridf);
123 vec[2] = gridf * floorf(0.5f + vec[2] / gridf);
124 sub_v3_v3(vec, obedit->object_to_world().location());
125
126 mul_m3_v3(imat, vec);
127 copy_v3_v3(tv->loc, vec);
128 }
129 ED_transverts_update_obedit(&tvs, obedit);
130 }
131 ED_transverts_free(&tvs);
132 }
133 }
134 else if (OBPOSE_FROM_OBACT(obact)) {
136 Vector<Object *> objects_eval = BKE_object_pose_array_get(*bmain, scene, view_layer_eval, v3d);
137 for (Object *ob_eval : objects_eval) {
138 Object *ob = DEG_get_original(ob_eval);
139 bArmature *arm_eval = id_cast<bArmature *>(ob_eval->data);
140
141 invert_m4_m4(ob_eval->runtime->world_to_object.ptr(), ob_eval->object_to_world().ptr());
142
143 for (bPoseChannel &pchan_eval : ob_eval->pose->chanbase) {
144 if (pchan_eval.flag & POSE_SELECTED) {
145 if (ANIM_bonecoll_is_visible_pchan(arm_eval, &pchan_eval)) {
146 const Bone *bone_eval = pchan_eval.bone_get(*ob_eval);
147 if ((bone_eval->flag & BONE_CONNECTED) == 0) {
148 float nLoc[3];
149
150 /* get nearest grid point to snap to */
151 copy_v3_v3(nLoc, pchan_eval.pose_mat[3]);
152 /* We must operate in world space! */
153 mul_m4_v3(ob_eval->object_to_world().ptr(), nLoc);
154 vec[0] = gridf * floorf(0.5f + nLoc[0] / gridf);
155 vec[1] = gridf * floorf(0.5f + nLoc[1] / gridf);
156 vec[2] = gridf * floorf(0.5f + nLoc[2] / gridf);
157 /* Back in object space... */
158 mul_m4_v3(ob_eval->world_to_object().ptr(), vec);
159
160 /* Get location of grid point in pose space. */
161 BKE_armature_loc_pose_to_bone({&pchan_eval, bone_eval}, vec, vec);
162
163 /* Adjust location on the original pchan. */
164 bPoseChannel *pchan = BKE_pose_channel_find_name(ob->pose, pchan_eval.name);
166
167 /* auto-keyframing */
168 animrig::autokeyframe_pchan(C, scene, ob, pchan, ks);
169 }
170 /* if the bone has a parent and is connected to the parent,
171 * don't do anything - will break chain unless we do auto-ik.
172 */
173 }
174 }
175 }
176
178 }
179 }
180 else {
181 /* Object mode. */
182 Main *bmain = CTX_data_main(C);
183
185
186 const bool use_transform_skip_children = (scene->toolsettings->transform_flag &
188 const bool use_transform_data_origin = (scene->toolsettings->transform_flag &
192
193 /* Build object array. */
194 Vector<Object *> objects_eval;
195 Vector<Object *> objects_orig;
196 {
197 FOREACH_SELECTED_EDITABLE_OBJECT_BEGIN (view_layer_eval, v3d, ob_eval) {
198 objects_eval.append(ob_eval);
199 objects_orig.append(DEG_get_original(ob_eval));
200 }
202 }
203
204 if (use_transform_skip_children) {
205 ViewLayer *view_layer = CTX_data_view_layer(C);
206
207 Vector<Object *> objects(objects_eval.size());
208 for (Object *ob_eval : objects_eval) {
209 objects.append_unchecked(DEG_get_original(ob_eval));
210 }
211 BKE_scene_graph_evaluated_ensure(depsgraph, bmain);
214 xcs, *bmain, scene, view_layer, objects.data(), objects.size());
215 }
216 if (use_transform_data_origin) {
217 BKE_scene_graph_evaluated_ensure(depsgraph, bmain);
219 }
220
221 if (animrig::is_autokey_on(scene)) {
223 }
224
225 for (Object *ob_eval : objects_eval) {
226 Object *ob = DEG_get_original(ob_eval);
227 vec[0] = -ob_eval->object_to_world().location()[0] +
228 gridf * floorf(0.5f + ob_eval->object_to_world().location()[0] / gridf);
229 vec[1] = -ob_eval->object_to_world().location()[1] +
230 gridf * floorf(0.5f + ob_eval->object_to_world().location()[1] / gridf);
231 vec[2] = -ob_eval->object_to_world().location()[2] +
232 gridf * floorf(0.5f + ob_eval->object_to_world().location()[2] / gridf);
233
234 if (ob->parent) {
235 float originmat[3][3];
236 BKE_object_where_is_calc_ex(depsgraph, scene, nullptr, ob, originmat);
237
238 invert_m3_m3(imat, originmat);
239 mul_m3_v3(imat, vec);
240 }
241
242 const float3 loc_final = float3(ob_eval->loc) + float3(vec);
244
245 /* auto-keyframing */
246 animrig::autokeyframe_object(C, scene, ob, ks);
247
248 if (use_transform_data_origin) {
250 }
251
253 }
254
255 if (use_transform_skip_children) {
258 }
259 if (use_transform_data_origin) {
260 object::data_xform_container_update_all(xds, bmain, depsgraph);
262 }
263 }
264
266
267 return OPERATOR_FINISHED;
268}
269
271{
272 /* identifiers */
273 ot->name = "Snap Selection to Grid";
274 ot->description = "Snap selected item(s) to their nearest grid division";
275 ot->idname = "VIEW3D_OT_snap_selected_to_grid";
276
277 /* API callbacks. */
280
281 /* flags */
283}
284
286
287/* -------------------------------------------------------------------- */
290
291/* Return true if the bone or any of its parents has the given runtime flag set. */
292static bool pose_bone_runtime_flag_test_recursive(const bPoseChannel *pose_bone, int flag)
293{
294 if (pose_bone->runtime.flag & flag) {
295 return true;
296 }
297 if (pose_bone->parent) {
298 return pose_bone_runtime_flag_test_recursive(pose_bone->parent, flag);
299 }
300 return false;
301}
302
318 wmOperator *op,
319 const float3 &target_loc_global,
320 const View3DCursor *target_orientation_global,
321 const bool use_offset,
322 const int pivot_point,
323 const bool use_toolsettings)
324{
325 using namespace blender::ed;
326 Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
327 Scene *scene = CTX_data_scene(C);
328 Object *obedit = CTX_data_edit_object(C);
330 View3D *v3d = CTX_wm_view3d(C);
331 TransVertStore tvs = {nullptr};
332 TransVert *tv;
333 float imat[3][3], bmat[3][3];
334 float center_global[3];
335 float offset_global[3];
336 int a;
337
338 /* Some use of this needs to transform into local-space. */
339 const bool use_rotation = target_orientation_global != nullptr;
340 const float3x3 target_rot_global = target_orientation_global ?
341 target_orientation_global->matrix<float3x3>() :
343
344 if (use_offset) {
345 if ((pivot_point == V3D_AROUND_ACTIVE) && snap_calc_active_center(C, true, center_global)) {
346 /* pass */
347 }
348 else {
349 snap_curs_to_sel_ex(C, pivot_point, center_global);
350 }
351 sub_v3_v3v3(offset_global, target_loc_global, center_global);
352 }
353
354 if (obedit) {
355 float3 target_loc_local;
356 const Main *bmain = CTX_data_main(C);
357 ViewLayer *view_layer = CTX_data_view_layer(C);
359 *bmain, scene, view_layer, v3d);
360 for (const int ob_index : objects.index_range()) {
361 obedit = objects[ob_index];
362
363 if (obedit->type == OB_MESH) {
364 const BMesh *bm = BKE_editmesh_bmesh_get(obedit);
365 if (bm->totvertsel == 0) {
366 continue;
367 }
368 }
369
371 continue;
372 }
373
374 if (ED_transverts_check_obedit(obedit)) {
375 const Object *ob_eval = DEG_get_evaluated(depsgraph, obedit);
376 ED_transverts_create_from_obedit(&tvs, ob_eval, 0);
377 }
378
379 if (tvs.transverts_tot != 0) {
380 copy_m3_m4(bmat, obedit->object_to_world().ptr());
381 invert_m3_m3(imat, bmat);
382
383 /* Get the `target_loc_global` in object space. */
384 sub_v3_v3v3(target_loc_local, target_loc_global, obedit->object_to_world().location());
385 mul_m3_v3(imat, target_loc_local);
386
387 if (use_offset) {
388 float3 offset_local;
389
390 mul_v3_m3v3(offset_local, imat, offset_global);
391
392 tv = tvs.transverts;
393 for (a = 0; a < tvs.transverts_tot; a++, tv++) {
394 add_v3_v3(tv->loc, offset_local);
395 }
396 }
397 else {
398 tv = tvs.transverts;
399 for (a = 0; a < tvs.transverts_tot; a++, tv++) {
400 copy_v3_v3(tv->loc, target_loc_local);
401 }
402 }
403 ED_transverts_update_obedit(&tvs, obedit);
404 }
405 ED_transverts_free(&tvs);
406 }
407 }
408 else if (OBPOSE_FROM_OBACT(obact)) {
410 Main *bmain = CTX_data_main(C);
411 ViewLayer *view_layer = CTX_data_view_layer(C);
412 Vector<Object *> objects = BKE_object_pose_array_get(*bmain, scene, view_layer, v3d);
413 Depsgraph *depsgraph = CTX_data_depsgraph_pointer(C);
414 BKE_scene_graph_evaluated_ensure(depsgraph, bmain);
415
416 for (Object *ob : objects) {
417 bArmature *arm = id_cast<bArmature *>(ob->data);
418 float3 target_loc_local;
419
420 invert_m4_m4(ob->runtime->world_to_object.ptr(), ob->object_to_world().ptr());
421 mul_v3_m4v3(target_loc_local, ob->world_to_object().ptr(), target_loc_global);
422
423 for (bPoseChannel &pchan : ob->pose->chanbase) {
424 const Bone *bone = pchan.bone_get(*ob);
425 if ((pchan.flag & POSE_SELECTED) && animrig::bone_is_visible(arm, {&pchan, bone}) &&
426 /* if the bone has a parent and is connected to the parent,
427 * don't do anything - will break chain unless we do auto-ik.
428 */
429 (bone->flag & BONE_CONNECTED) == 0)
430 {
432 }
433 else {
435 }
436 }
437
438 for (bPoseChannel &pchan : ob->pose->chanbase) {
439 if ((pchan.runtime.flag & POSE_RUNTIME_TRANSFORM) &&
440 /* check that our parents not transformed (if we have one) */
441 ((pchan.parent &&
443 {
444 /* Get position in pchan (pose) space. */
445 float3 target_loc_pose;
446
447 Bone *bone = pchan.bone_get(*ob);
448 if (use_offset) {
449 mul_v3_m4v3(target_loc_pose, ob->object_to_world().ptr(), pchan.pose_mat[3]);
450 add_v3_v3(target_loc_pose, offset_global);
451
452 if (use_rotation) {
453 sub_v3_v3(target_loc_pose, target_loc_global);
454 mul_m3_v3(target_rot_global.ptr(), target_loc_pose);
455 add_v3_v3(target_loc_pose, target_loc_global);
456 }
457
458 mul_m4_v3(ob->world_to_object().ptr(), target_loc_pose);
459 BKE_armature_loc_pose_to_bone({&pchan, bone}, target_loc_pose, target_loc_pose);
460 }
461 else {
462 BKE_armature_loc_pose_to_bone({&pchan, bone}, target_loc_local, target_loc_pose);
463 }
464
465 if (use_rotation) {
466 BKE_pchan_mat3_to_rot(&pchan, target_rot_global.ptr(), false);
467
468 if (pchan.rotmode == ROT_MODE_QUAT) {
469 float quat[4];
470 mat3_normalized_to_quat(quat, target_rot_global.ptr());
471
472 if (use_toolsettings) {
474 }
475 else {
476 copy_v4_v4(pchan.quat, quat);
477 }
478 }
479 else if (pchan.rotmode == ROT_MODE_AXISANGLE) {
480 float rot_axis[3];
481 float rot_angle;
482 mat3_to_axis_angle(rot_axis, &rot_angle, target_rot_global.ptr());
483
484 if (use_toolsettings) {
485 BKE_pchan_protected_rotation_axisangle_set(&pchan, rot_axis, rot_angle);
486 }
487 else {
488 copy_v3_v3(pchan.rotAxis, rot_axis);
489 pchan.rotAngle = rot_angle;
490 }
491 }
492 else {
493 float rot_euler[3];
494 mat3_to_eulO(rot_euler, pchan.rotmode, target_rot_global.ptr());
495
496 if (use_toolsettings) {
498 }
499 else {
500 copy_v3_v3(pchan.eul, rot_euler);
501 }
502 }
503 }
504
505 /* copy new position */
506 if (use_toolsettings) {
507 BKE_pchan_protected_location_set(&pchan, target_loc_pose);
508
509 /* auto-keyframing */
510 animrig::autokeyframe_pchan(C, scene, ob, &pchan, ks);
511 }
512 else {
513 copy_v3_v3(pchan.loc, target_loc_pose);
514 }
515 }
516 }
517
518 for (bPoseChannel &pchan : ob->pose->chanbase) {
520 }
521
523 }
524 }
525 else {
527 Main *bmain = CTX_data_main(C);
528 Depsgraph *depsgraph = CTX_data_depsgraph_pointer(C);
529 BKE_scene_graph_evaluated_ensure(depsgraph, bmain);
530
531 /* Reset flags. */
532 for (Object *ob = bmain->objects.first(); ob; ob = static_cast<Object *>(ob->id.next)) {
533 ob->flag &= ~OB_DONE;
534 }
535
536 /* Build object array, tag objects we're transforming. */
537 ViewLayer *view_layer = CTX_data_view_layer(C);
538 Vector<Object *> objects;
539 {
540 FOREACH_SELECTED_EDITABLE_OBJECT_BEGIN (view_layer, v3d, ob) {
541 objects.append(ob);
542 ob->flag |= OB_DONE;
543 }
545 }
546
547 const bool use_transform_skip_children = use_toolsettings &&
550 const bool use_transform_data_origin = use_toolsettings &&
555
556 if (use_transform_skip_children) {
559 xcs, *bmain, scene, view_layer, objects.data(), objects.size());
560 }
561 if (use_transform_data_origin) {
563
564 /* Initialize the transform data in a separate loop because the depsgraph
565 * may be evaluated while setting the locations. */
566 for (Object *ob : objects) {
568 }
569 }
570
571 if (animrig::is_autokey_on(scene)) {
573 }
574
575 for (Object *ob : objects) {
576 /* With offset enabled, skip child objects whose parents are also transformed
577 * to avoid double transform. */
578 if (use_offset) {
579 if (ob->parent && BKE_object_flag_test_recursive(ob->parent, OB_DONE)) {
580 continue;
581 }
582 }
583
584 float3 target_loc_local; /* parent-relative */
585
586 if (use_offset) {
587 add_v3_v3v3(target_loc_local, ob->object_to_world().location(), offset_global);
588
589 if (use_rotation) {
590 sub_v3_v3(target_loc_local, target_loc_global);
591 mul_m3_v3(target_rot_global.ptr(), target_loc_local);
592 add_v3_v3(target_loc_local, target_loc_global);
593 }
594 }
595 else {
596 copy_v3_v3(target_loc_local, target_loc_global);
597 }
598 sub_v3_v3(target_loc_local, ob->object_to_world().location());
599
600 /* Calculate a parent relative copy. */
601 float3x3 target_rot = target_rot_global;
602 if (ob->parent) {
603 float originmat[3][3], parentmat[4][4];
604 /* Use the evaluated object here because sometimes
605 * `ob->parent->runtime->curve_cache` is required. */
606 BKE_scene_graph_evaluated_ensure(depsgraph, bmain);
607 Object *ob_eval = DEG_get_evaluated(depsgraph, ob);
608
609 BKE_object_get_parent_matrix(ob_eval, ob_eval->parent, parentmat);
610 mul_m3_m4m4(originmat, parentmat, ob->parentinv);
611 invert_m3_m3(imat, originmat);
612 mul_m3_v3(imat, target_loc_local);
613 mul_m3_m3m3(target_rot.ptr(), imat, target_rot.ptr());
614 }
615 if (use_toolsettings) {
616 const float3 loc_final = float3(ob->loc) + target_loc_local;
618
619 /* auto-keyframing */
620 animrig::autokeyframe_object(C, scene, ob, ks);
621 }
622 else {
623 add_v3_v3(ob->loc, target_loc_local);
624 }
625
626 if (use_rotation) {
627 const bool assign_rotation_directly = (ob->rotmode ==
628 target_orientation_global->rotation_mode &&
629 ob->parent == nullptr);
630
631 if (ob->rotmode == ROT_MODE_QUAT) {
632 float quat[4];
633 if (assign_rotation_directly) {
634 copy_v4_v4(quat, target_orientation_global->rotation_quaternion);
635 }
636 else {
637 mat3_normalized_to_quat(quat, target_rot.ptr());
638 }
639 if (use_toolsettings) {
641 }
642 else {
643 copy_v4_v4(ob->quat, quat);
644 }
645 }
646 else if (ob->rotmode == ROT_MODE_AXISANGLE) {
647 float rot_axis[3];
648 float rot_angle;
649 if (assign_rotation_directly) {
650 copy_v3_v3(rot_axis, target_orientation_global->rotation_axis);
651 rot_angle = target_orientation_global->rotation_angle;
652 }
653 else {
654 mat3_to_axis_angle(rot_axis, &rot_angle, target_rot.ptr());
655 }
656 if (use_toolsettings) {
657 BKE_object_protected_rotation_axisangle_set(ob, rot_axis, rot_angle);
658 }
659 else {
660 copy_v3_v3(ob->rotAxis, rot_axis);
661 ob->rotAngle = rot_angle;
662 }
663 }
664 else {
665 float rot_euler[3];
666 if (assign_rotation_directly) {
667 copy_v3_v3(rot_euler, target_orientation_global->rotation_euler);
668 }
669 else {
670 mat3_to_eulO(rot_euler, ob->rotmode, target_rot.ptr());
671 }
672 if (use_toolsettings) {
674 }
675 else {
676 copy_v3_v3(ob->rot, rot_euler);
677 }
678 }
679
680 /* auto-keyframing */
681 animrig::autokeyframe_object(C, scene, ob, ks);
682 }
683
685 }
686
687 if (use_transform_skip_children) {
690 }
691 if (use_transform_data_origin) {
692 object::data_xform_container_update_all(xds, bmain, depsgraph);
694 }
695 }
696
698
699 return true;
700}
701
703 wmOperator *op,
704 const float target_loc_global[3],
705 const int pivot_point)
706{
707 /* These could be passed as arguments if needed. */
708 /* Always use pivot point. */
709 const bool use_offset = true;
710 /* Disable object protected flags & auto-keyframing,
711 * so this can be used as a low level function. */
712 const bool use_toolsettings = false;
714 C, op, target_loc_global, nullptr, use_offset, pivot_point, use_toolsettings);
715}
716
718
719/* -------------------------------------------------------------------- */
722
724{
725 const bool use_offset = RNA_boolean_get(op->ptr, "use_offset");
726 const bool use_rotation = RNA_boolean_get(op->ptr, "use_rotation");
727
728 Scene *scene = CTX_data_scene(C);
729
730 const float *target_loc_global = scene->cursor.location;
731 const View3DCursor *snap_orientation = use_rotation ? &scene->cursor : nullptr;
732 const int pivot_point = scene->toolsettings->transform_pivot_point;
733
735 C, op, target_loc_global, snap_orientation, use_offset, pivot_point, true))
736 {
737 return OPERATOR_FINISHED;
738 }
739 return OPERATOR_CANCELLED;
740}
741
743{
744 /* identifiers */
745 ot->name = "Snap Selection to Cursor";
746 ot->description = "Snap selected item(s) to the 3D cursor";
747 ot->idname = "VIEW3D_OT_snap_selected_to_cursor";
748
749 /* API callbacks. */
752
753 /* flags */
755
756 /* rna */
758 "use_offset",
759 true,
760 "Offset",
761 "If the selection should be snapped as a whole or by each object center");
763 "use_rotation",
764 false,
765 "Rotation",
766 "If the selection should be rotated to match the cursor");
767}
768
770
771/* -------------------------------------------------------------------- */
774
777{
778 float target_loc_global[3];
779
780 if (snap_calc_active_center(C, false, target_loc_global) == false) {
781 BKE_report(op->reports, RPT_ERROR, "No active element found!");
782 return OPERATOR_CANCELLED;
783 }
784
785 if (!snap_selected_to_location_rotation(C, op, target_loc_global, nullptr, false, -1, true)) {
786 return OPERATOR_CANCELLED;
787 }
788 return OPERATOR_FINISHED;
789}
790
792{
793 /* identifiers */
794 ot->name = "Snap Selection to Active";
795 ot->description = "Snap selected item(s) to the active item";
796 ot->idname = "VIEW3D_OT_snap_selected_to_active";
797
798 /* API callbacks. */
801
802 /* flags */
804}
805
807
808/* -------------------------------------------------------------------- */
811
814{
815 Scene *scene = CTX_data_scene(C);
816 ARegion *region = CTX_wm_region(C);
817 View3D *v3d = CTX_wm_view3d(C);
818 float gridf, *curs;
819
820 gridf = ED_view3d_grid_view_scale(scene, v3d, region, nullptr);
821 curs = scene->cursor.location;
822
823 curs[0] = gridf * floorf(0.5f + curs[0] / gridf);
824 curs[1] = gridf * floorf(0.5f + curs[1] / gridf);
825 curs[2] = gridf * floorf(0.5f + curs[2] / gridf);
826
827 WM_event_add_notifier(C, NC_SPACE | ND_SPACE_VIEW3D, nullptr); /* hrm */
829
830 return OPERATOR_FINISHED;
831}
832
834{
835 /* identifiers */
836 ot->name = "Snap Cursor to Grid";
837 ot->description = "Snap 3D cursor to the nearest grid division";
838 ot->idname = "VIEW3D_OT_snap_cursor_to_grid";
839
840 /* API callbacks. */
843
844 /* flags */
845 ot->flag = OPTYPE_REGISTER;
846}
847
849
850/* -------------------------------------------------------------------- */
853
858static void bundle_midpoint(Scene *scene, Object *ob, float r_vec[3])
859{
860 MovieClip *clip = BKE_object_movieclip_get(scene, ob, false);
861 bool ok = false;
862 float min[3], max[3], mat[4][4], pos[3], cammat[4][4];
863
864 if (!clip) {
865 return;
866 }
867
868 MovieTracking *tracking = &clip->tracking;
869
870 copy_m4_m4(cammat, ob->object_to_world().ptr());
871
873
875
876 for (MovieTrackingObject &tracking_object : tracking->objects) {
877 float obmat[4][4];
878
879 if (tracking_object.flag & TRACKING_OBJECT_CAMERA) {
880 copy_m4_m4(obmat, mat);
881 }
882 else {
883 float imat[4][4];
884
886 tracking, &tracking_object, scene->r.cfra, imat);
887 invert_m4(imat);
888
889 mul_m4_m4m4(obmat, cammat, imat);
890 }
891
892 for (const MovieTrackingTrack &track : tracking_object.tracks) {
893 if ((track.flag & TRACK_HAS_BUNDLE) && TRACK_SELECTED(&track)) {
894 ok = true;
895 mul_v3_m4v3(pos, obmat, track.bundle_pos);
896 minmax_v3v3_v3(min, max, pos);
897 }
898 }
899 }
900
901 if (ok) {
902 mid_v3_v3v3(r_vec, min, max);
903 }
904}
905
907static bool snap_curs_to_sel_ex(bContext *C, const int pivot_point, float r_cursor[3])
908{
909 Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
910 ViewLayer *view_layer_eval = DEG_get_evaluated_view_layer(depsgraph);
911 Object *obedit = CTX_data_edit_object(C);
912 const Main *bmain = CTX_data_main(C);
913 Scene *scene = CTX_data_scene(C);
914 View3D *v3d = CTX_wm_view3d(C);
915 TransVertStore tvs = {nullptr};
916 TransVert *tv;
917 float bmat[3][3], vec[3], min[3], max[3], centroid[3];
918 int count = 0;
919
921 zero_v3(centroid);
922
923 if (obedit) {
924 ViewLayer *view_layer = CTX_data_view_layer(C);
926 *bmain, scene, view_layer, CTX_wm_view3d(C));
927 for (const int ob_index : objects.index_range()) {
928 obedit = objects[ob_index];
929
930 /* We can do that quick check for meshes only... */
931 if (obedit->type == OB_MESH) {
932 const BMesh *bm = BKE_editmesh_bmesh_get(obedit);
933 if (bm->totvertsel == 0) {
934 continue;
935 }
936 }
937
938 if (ED_transverts_check_obedit(obedit)) {
939 const Object *obedit_eval = DEG_get_evaluated(depsgraph, obedit);
941 }
942
943 count += tvs.transverts_tot;
944 if (tvs.transverts_tot != 0) {
945 Object *obedit_eval = DEG_get_evaluated(depsgraph, obedit);
946 copy_m3_m4(bmat, obedit_eval->object_to_world().ptr());
947
948 tv = tvs.transverts;
949 for (int i = 0; i < tvs.transverts_tot; i++, tv++) {
950 copy_v3_v3(vec, tv->loc);
951 mul_m3_v3(bmat, vec);
952 add_v3_v3(vec, obedit_eval->object_to_world().location());
953 add_v3_v3(centroid, vec);
954 minmax_v3v3_v3(min, max, vec);
955 }
956 }
957 ED_transverts_free(&tvs);
958 }
959 }
960 else {
962
963 if (obact && (obact->mode & OB_MODE_POSE)) {
964 Object *obact_eval = DEG_get_evaluated(depsgraph, obact);
965 bArmature *arm = id_cast<bArmature *>(obact_eval->data);
966 for (bPoseChannel &pchan : obact_eval->pose->chanbase) {
967 if (ANIM_bonecoll_is_visible_pchan(arm, &pchan)) {
968 if (pchan.flag & POSE_SELECTED) {
969 copy_v3_v3(vec, pchan.pose_head);
970 mul_m4_v3(obact_eval->object_to_world().ptr(), vec);
971 add_v3_v3(centroid, vec);
972 minmax_v3v3_v3(min, max, vec);
973 count++;
974 }
975 }
976 }
977 }
978 else {
979 FOREACH_SELECTED_OBJECT_BEGIN (view_layer_eval, v3d, ob_eval) {
980 copy_v3_v3(vec, ob_eval->object_to_world().location());
981
982 /* special case for camera -- snap to bundles */
983 if (ob_eval->type == OB_CAMERA) {
984 /* snap to bundles should happen only when bundles are visible */
985 if (v3d->flag2 & V3D_SHOW_RECONSTRUCTION) {
986 bundle_midpoint(scene, DEG_get_original(ob_eval), vec);
987 }
988 }
989
990 add_v3_v3(centroid, vec);
991 minmax_v3v3_v3(min, max, vec);
992 count++;
993 }
995 }
996 }
997
998 if (count == 0) {
999 return false;
1000 }
1001
1002 if (pivot_point == V3D_AROUND_CENTER_BOUNDS) {
1003 mid_v3_v3v3(r_cursor, min, max);
1004 }
1005 else {
1006 mul_v3_fl(centroid, 1.0f / float(count));
1007 copy_v3_v3(r_cursor, centroid);
1008 }
1009 return true;
1010}
1011
1013{
1014 Scene *scene = CTX_data_scene(C);
1015 const int pivot_point = scene->toolsettings->transform_pivot_point;
1016 if (snap_curs_to_sel_ex(C, pivot_point, scene->cursor.location)) {
1019
1020 return OPERATOR_FINISHED;
1021 }
1022 return OPERATOR_CANCELLED;
1023}
1024
1026{
1027 /* identifiers */
1028 ot->name = "Snap Cursor to Selected";
1029 ot->description = "Snap 3D cursor to the middle of the selected item(s)";
1030 ot->idname = "VIEW3D_OT_snap_cursor_to_selected";
1031
1032 /* API callbacks. */
1035
1036 /* flags */
1037 ot->flag = OPTYPE_REGISTER;
1038}
1039
1041
1042/* -------------------------------------------------------------------- */
1045
1052static bool snap_calc_active_center(bContext *C, const bool select_only, float r_center[3])
1053{
1055 if (ob == nullptr) {
1056 return false;
1057 }
1058 return ed::object::calc_active_center(ob, select_only, r_center);
1059}
1060
1062{
1063 Scene *scene = CTX_data_scene(C);
1064
1065 if (snap_calc_active_center(C, false, scene->cursor.location)) {
1068
1069 return OPERATOR_FINISHED;
1070 }
1071 return OPERATOR_CANCELLED;
1072}
1073
1075{
1076 /* identifiers */
1077 ot->name = "Snap Cursor to Active";
1078 ot->description = "Snap 3D cursor to the active item";
1079 ot->idname = "VIEW3D_OT_snap_cursor_to_active";
1080
1081 /* API callbacks. */
1084
1085 /* flags */
1086 ot->flag = OPTYPE_REGISTER;
1087}
1088
1090
1091/* -------------------------------------------------------------------- */
1094
1097{
1098 Scene *scene = CTX_data_scene(C);
1099
1100 scene->cursor.set_matrix(float4x4::identity(), false);
1101
1103
1105 return OPERATOR_FINISHED;
1106}
1107
1109{
1110 /* identifiers */
1111 ot->name = "Snap Cursor to World Origin";
1112 ot->description = "Snap 3D cursor to the world origin";
1113 ot->idname = "VIEW3D_OT_snap_cursor_to_center";
1114
1115 /* API callbacks. */
1118
1119 /* flags */
1120 ot->flag = OPTYPE_REGISTER;
1121}
1122
1124
1125/* -------------------------------------------------------------------- */
1128
1129static std::optional<Bounds<float3>> bounds_min_max_with_transform(const float4x4 &transform,
1130 const Span<float3> positions,
1131 const IndexMask &mask)
1132{
1133 if (mask.is_empty()) {
1134 return std::nullopt;
1135 }
1137 mask.index_range(),
1138 1024,
1139 Bounds<float3>(math::transform_point(transform, positions[mask.first()])),
1140 [&](const IndexRange range, Bounds<float3> init) {
1141 mask.slice(range).foreach_index_optimized<int>([&](const int i) {
1142 math::min_max(math::transform_point(transform, positions[i]), init.min, init.max);
1143 });
1144 return init;
1145 },
1146 [](const Bounds<float3> &a, const Bounds<float3> &b) { return bounds::merge(a, b); });
1147}
1148
1149bool ED_view3d_minmax_verts(const Scene *scene, Object *obedit, float r_min[3], float r_max[3])
1150{
1151 using namespace blender::ed;
1152 TransVertStore tvs = {nullptr};
1153 TransVert *tv;
1154 float centroid[3], vec[3], bmat[3][3];
1155
1156 /* Meta-balls are an exception. */
1157 if (obedit->type == OB_MBALL) {
1158 float ob_min[3], ob_max[3];
1159 bool changed;
1160
1161 changed = BKE_mball_minmax_ex(id_cast<const MetaBall *>(obedit->data),
1162 ob_min,
1163 ob_max,
1164 obedit->object_to_world().ptr(),
1165 SELECT);
1166 if (changed) {
1167 minmax_v3v3_v3(r_min, r_max, ob_min);
1168 minmax_v3v3_v3(r_min, r_max, ob_max);
1169 }
1170 return changed;
1171 }
1172 if (obedit->type == OB_POINTCLOUD) {
1173 const Object &ob_orig = *DEG_get_original(obedit);
1174 const PointCloud &pointcloud = *id_cast<const PointCloud *>(ob_orig.data);
1175
1176 IndexMaskMemory memory;
1178
1179 const std::optional<Bounds<float3>> bounds = bounds_min_max_with_transform(
1180 obedit->object_to_world(), pointcloud.positions(), mask);
1181
1182 if (bounds) {
1183 minmax_v3v3_v3(r_min, r_max, bounds->min);
1184 minmax_v3v3_v3(r_min, r_max, bounds->max);
1185 return true;
1186 }
1187 return false;
1188 }
1189 if (obedit->type == OB_CURVES) {
1190 const Object &ob_orig = *DEG_get_original(obedit);
1191 const Curves &curves_id = *id_cast<const Curves *>(ob_orig.data);
1192 const bke::CurvesGeometry &curves = curves_id.geometry.wrap();
1193
1194 IndexMaskMemory memory;
1196
1197 const bke::crazyspace::GeometryDeformation deformation =
1199
1200 const std::optional<Bounds<float3>> bounds = bounds_min_max_with_transform(
1201 obedit->object_to_world(), deformation.positions, mask);
1202
1203 if (bounds) {
1204 minmax_v3v3_v3(r_min, r_max, bounds->min);
1205 minmax_v3v3_v3(r_min, r_max, bounds->max);
1206 return true;
1207 }
1208 return false;
1209 }
1210 if (obedit->type == OB_GREASE_PENCIL) {
1211 Object &ob_orig = *DEG_get_original(obedit);
1212 GreasePencil &grease_pencil = *id_cast<GreasePencil *>(ob_orig.data);
1213
1214 std::optional<Bounds<float3>> bounds = std::nullopt;
1215
1218 for (const greasepencil::MutableDrawingInfo info : drawings) {
1219 const bke::CurvesGeometry &curves = info.drawing.strokes();
1220 if (curves.is_empty()) {
1221 continue;
1222 }
1223
1224 IndexMaskMemory memory;
1226 ob_orig, info.drawing, info.layer_index, memory);
1227 if (points.is_empty()) {
1228 continue;
1229 }
1230
1231 const bke::crazyspace::GeometryDeformation deformation =
1233 obedit, ob_orig, info.drawing);
1234
1235 const bke::greasepencil::Layer &layer = grease_pencil.layer(info.layer_index);
1236 const float4x4 layer_to_world = layer.to_world_space(*obedit);
1237
1239 bounds, bounds_min_max_with_transform(layer_to_world, deformation.positions, points));
1240 }
1241
1242 if (bounds) {
1243 minmax_v3v3_v3(r_min, r_max, bounds->min);
1244 minmax_v3v3_v3(r_min, r_max, bounds->max);
1245 return true;
1246 }
1247 return false;
1248 }
1249
1250 if (ED_transverts_check_obedit(obedit)) {
1252 }
1253
1254 if (tvs.transverts_tot == 0) {
1255 return false;
1256 }
1257
1258 copy_m3_m4(bmat, obedit->object_to_world().ptr());
1259
1260 tv = tvs.transverts;
1261 for (int a = 0; a < tvs.transverts_tot; a++, tv++) {
1262 copy_v3_v3(vec, (tv->flag & TX_VERT_USE_MAPLOC) ? tv->maploc : tv->loc);
1263 mul_m3_v3(bmat, vec);
1264 add_v3_v3(vec, obedit->object_to_world().location());
1265 add_v3_v3(centroid, vec);
1266 minmax_v3v3_v3(r_min, r_max, vec);
1267 }
1268
1269 ED_transverts_free(&tvs);
1270
1271 return true;
1272}
1273
1275
1276} // namespace blender
Functions and classes to work with Actions.
Functions to deal with Armatures.
C++ functions to deal with Armature collections (i.e. the successor of bone layers).
Functions to insert, delete or modify keyframes.
Functionality to interact with keying sets.
Blender kernel action and pose functionality.
#define FOREACH_SELECTED_EDITABLE_OBJECT_END
Definition BKE_layer.hh:403
#define FOREACH_SELECTED_OBJECT_BEGIN(_view_layer, _v3d, _instance)
Definition BKE_layer.hh:374
#define FOREACH_SELECTED_EDITABLE_OBJECT_BEGIN(_view_layer, _v3d, _instance)
Definition BKE_layer.hh:391
#define FOREACH_SELECTED_OBJECT_END
Definition BKE_layer.hh:386
#define SELECT
Definition BKE_mask.hh:19
General operations, lookup, etc. for blender objects.
#define TRACK_SELECTED(track)
Object is a sort of wrapper for general info.
#define OBPOSE_FROM_OBACT(ob)
#define OBEDIT_FROM_OBACT(ob)
#define C
Definition RandGen.cpp:29
#define ND_TRANSFORM
Definition WM_types.hh:475
#define ND_SPACE_VIEW3D
Definition WM_types.hh:571
#define NC_OBJECT
Definition WM_types.hh:392
#define NC_SPACE
Definition WM_types.hh:405
#define INIT_MINMAX(min, max)
btScalar max
int64_t size() const
void append(const T &value)
IndexRange index_range() const
void append_unchecked(const T &value)
#define layer
bool is_autokey_on(const Scene *scene)
bool bone_is_visible(const bArmature *armature, const Bone *bone)
KeyingSet * get_keyingset_for_autokeying(const Scene *scene, const char *transformKSName)
bool autokeyframe_pchan(bContext *C, Scene *scene, Object *ob, bPoseChannel *pchan, KeyingSet *ks)
void autokeyframe_object(bContext *C, const Scene *scene, Object *ob, Span< RNAPath > rna_paths)
GeometryDeformation get_evaluated_grease_pencil_drawing_deformation(const Object *ob_eval, const Object &ob_orig, const bke::greasepencil::Drawing &drawing_orig)
GeometryDeformation get_evaluated_curves_deformation(const Object *ob_eval, const Object &ob_orig)
Bounds< T > merge(const Bounds< T > &a, const Bounds< T > &b)
Definition BLI_bounds.hh:27
IndexMask retrieve_selected_points(const bke::CurvesGeometry &curves, LinearAllocator<> &memory)
IndexMask retrieve_editable_and_selected_points(Object &object, const bke::greasepencil::Drawing &drawing, int layer_index, IndexMaskMemory &memory)
Vector< MutableDrawingInfo > retrieve_editable_drawings(const Scene &scene, GreasePencil &grease_pencil)
bool calc_active_center(Object *ob, bool select_only, float r_center[3])
void data_xform_container_destroy(XFormObjectData_Container *xds)
bool shape_key_report_if_locked(const Object *obedit, ReportList *reports)
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 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()
IndexMask retrieve_selected_points(const PointCloud &pointcloud, IndexMaskMemory &memory)
Definition selection.cc:274
VecBase< T, 3 > transform_point(const CartesianBasis &basis, const VecBase< T, 3 > &v)
Value parallel_reduce(IndexRange range, int64_t grain_size, const Value &identity, const Function &function, const Reduction &reduction)
Definition BLI_task.hh:127
BMesh Iterators.
void mul_m3_v3(const float M[3][3], float r[3])
void BKE_pchan_mat3_to_rot(bPoseChannel *pchan, const float mat[3][3], bool use_compat)
void VIEW3D_OT_snap_cursor_to_active(wmOperatorType *ot)
void ED_transverts_update_obedit(TransVertStore *tvs, Object *obedit)
static bool snap_curs_to_sel_ex(bContext *C, const int pivot_point, float r_cursor[3])
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])
@ SCE_XFORM_SKIP_CHILDREN
void minmax_v3v3_v3(float min[3], float max[3], const float vec[3])
static std::optional< Bounds< float3 > > bounds_min_max_with_transform(const float4x4 &transform, const Span< float3 > positions, const IndexMask &mask)
@ TX_VERT_USE_MAPLOC
MINLINE void add_v3_v3v3(float r[3], const float a[3], const float b[3])
void BKE_object_get_parent_matrix(const Object *ob, Object *par, float r_parentmat[4][4])
Definition object.cc:3419
void mat3_normalized_to_quat(float q[4], const float mat[3][3])
Depsgraph * CTX_data_depsgraph_pointer(const bContext *C)
bool invert_m3_m3(float inverse[3][3], const float mat[3][3])
void mul_v3_m4v3(float r[3], const float mat[4][4], const float vec[3])
void BKE_pchan_protected_rotation_quaternion_set(bPoseChannel *pchan, const float quat[4])
void VIEW3D_OT_snap_selected_to_active(wmOperatorType *ot)
bool invert_m4_m4(float inverse[4][4], const float mat[4][4])
void BKE_pchan_protected_location_set(bPoseChannel *pchan, const float location[3])
@ V3D_AROUND_CENTER_BOUNDS
void mul_m4_m4m4(float R[4][4], const float A[4][4], const float B[4][4])
bool invert_m4(float mat[4][4])
void mul_m3_m4m4(float R[3][3], const float A[4][4], const float B[4][4])
bool ANIM_bonecoll_is_visible_pchan(const bArmature *armature, const bPoseChannel *pchan)
MatBase< float, 4, 4 > float4x4
static constexpr const char * ANIM_KS_LOCATION_ID
static bool pose_bone_runtime_flag_test_recursive(const bPoseChannel *pose_bone, int flag)
MovieClip * BKE_object_movieclip_get(Scene *scene, const Object *ob, bool use_default)
Definition object.cc:5154
@ V3D_SHOW_RECONSTRUCTION
void BKE_object_protected_location_set(Object *ob, const float location[3])
Definition object.cc:4197
ViewLayer * CTX_data_view_layer(const bContext *C)
void BKE_scene_graph_evaluated_ensure(Depsgraph *depsgraph, Main *bmain)
Definition scene.cc:2872
MINLINE void mul_v3_fl(float r[3], float f)
MINLINE void sub_v3_v3(float r[3], const float a[3])
void mul_m4_v3(const float M[4][4], float r[3])
void VIEW3D_OT_snap_selected_to_grid(wmOperatorType *ot)
static void bundle_midpoint(Scene *scene, Object *ob, float r_vec[3])
void BKE_object_protected_rotation_axisangle_set(Object *ob, const float axis[3], float angle)
Definition object.cc:4252
bool BKE_mball_minmax_ex(const MetaBall *mb, float min[3], float max[3], const float obmat[4][4], short flag)
Definition mball.cc:449
static wmOperatorStatus snap_curs_to_active_exec(bContext *C, wmOperator *)
void DEG_id_tag_update(ID *id, unsigned int flags)
void BKE_report(ReportList *reports, eReportType type, const char *message)
Definition report.cc:162
void ED_transverts_create_from_obedit(TransVertStore *tvs, const Object *obedit, int mode)
void BKE_armature_loc_pose_to_bone(bke::PChanBoneConst pchanbone, const float inloc[3], float outloc[3])
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)
Object * CTX_data_edit_object(const bContext *C)
void BKE_tracking_camera_get_reconstructed_interpolate(MovieTracking *tracking, MovieTrackingObject *tracking_object, float framenr, float mat[4][4])
Definition tracking.cc:2151
static wmOperatorStatus snap_curs_to_grid_exec(bContext *C, wmOperator *)
float ED_view3d_grid_view_scale(const Scene *scene, const View3D *v3d, const ARegion *region, const char **r_grid_unit)
bool ED_view3d_snap_selected_to_location(bContext *C, wmOperator *op, const float target_loc_global[3], int pivot_point)
void BKE_pchan_protected_rotation_euler_set(bPoseChannel *pchan, const float rotation_euler[3])
ViewLayer * DEG_get_evaluated_view_layer(const Depsgraph *graph)
bool ED_operator_view3d_active(bContext *C)
void VIEW3D_OT_snap_selected_to_cursor(wmOperatorType *ot)
bool RNA_boolean_get(PointerRNA *ptr, const char *name)
void mat3_to_axis_angle(float axis[3], float *angle, const float mat[3][3])
void BKE_object_protected_rotation_quaternion_set(Object *ob, const float quat[4])
Definition object.cc:4223
MINLINE void zero_v3(float r[3])
MatBase< float, 3, 3 > float3x3
void VIEW3D_OT_snap_cursor_to_grid(wmOperatorType *ot)
void WM_event_add_notifier(const bContext *C, uint type, void *reference)
static wmOperatorStatus snap_curs_to_sel_exec(bContext *C, wmOperator *)
void BKE_object_protected_rotation_euler_set(Object *ob, const float euler[3])
Definition object.cc:4239
static wmOperatorStatus snap_selected_to_cursor_exec(bContext *C, wmOperator *op)
MINLINE void add_v3_v3(float r[3], const float a[3])
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])
void BKE_pchan_protected_rotation_axisangle_set(bPoseChannel *pchan, const float axis[3], float angle)
T * DEG_get_original(T *id)
Main * CTX_data_main(const bContext *C)
bool BKE_object_flag_test_recursive(const Object *ob, short flag)
Definition object.cc:4910
void BKE_object_where_is_calc_ex(Depsgraph *depsgraph, Scene *scene, RigidBodyWorld *rbw, Object *ob, float r_originmat[3][3])
Definition object.cc:3571
void ED_transverts_free(TransVertStore *tvs)
static bool snap_calc_active_center(bContext *C, const bool select_only, float r_center[3])
@ 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
bool ED_operator_region_view3d_active(bContext *C)
Vector< Object * > BKE_view_layer_array_from_objects_in_edit_mode_unique_data(const Main &bmain, const Scene *scene, ViewLayer *view_layer, const View3D *v3d)
const BMesh * BKE_editmesh_bmesh_get(const Object *ob)
Definition editmesh.cc:65
void VIEW3D_OT_snap_cursor_to_center(wmOperatorType *ot)
Scene * CTX_data_scene(const bContext *C)
void BKE_tracking_get_camera_object_matrix(const Object *camera_object, float mat[4][4])
Definition tracking.cc:372
MINLINE void copy_v4_v4(float r[4], const float a[4])
static wmOperatorStatus snap_selected_to_active_exec(bContext *C, wmOperator *op)
static wmOperatorStatus snap_curs_to_center_exec(bContext *C, wmOperator *)
@ OPTYPE_REGISTER
Definition WM_types.hh:188
@ OPTYPE_UNDO
Definition WM_types.hh:190
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])
bool ED_view3d_minmax_verts(const Scene *scene, Object *obedit, float min[3], float max[3])
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)
static bool snap_selected_to_location_rotation(bContext *C, wmOperator *op, const float3 &target_loc_global, const View3DCursor *target_orientation_global, const bool use_offset, const int pivot_point, const bool use_toolsettings)
void VIEW3D_OT_snap_cursor_to_selected(wmOperatorType *ot)
void mat3_to_eulO(float eul[3], short order, const float m[3][3])
void mul_v3_m3v3(float r[3], const float M[3][3], const float a[3])
Object * CTX_data_active_object(const bContext *C)
Vector< Object * > BKE_object_pose_array_get(const Main &bmain, const Scene *scene, ViewLayer *view_layer, View3D *v3d)
Definition object.cc:2594
ARegion * CTX_wm_region(const bContext *C)
bPoseChannel * BKE_pose_channel_find_name(const bPose *pose, const char *name)
static wmOperatorStatus snap_sel_to_grid_exec(bContext *C, wmOperator *op)
View3D * CTX_wm_view3d(const bContext *C)
bool ED_transverts_check_obedit(const Object *obedit)
#define floorf
#define min(a, b)
Definition sort.cc:38
ListBaseT< Object > objects
Definition BKE_main.hh:388
const c_style_mat & ptr() const
struct MovieTracking tracking
ListBaseT< MovieTrackingTrack > tracks
ListBaseT< MovieTrackingObject > objects
struct Object * parent
struct bPose * pose
View3DCursor cursor
struct RenderData r
struct ToolSettings * toolsettings
eView3D_Flag2 flag2
bPoseChannelRuntimeFlag flag
struct bPoseChannel_Runtime runtime
struct bPoseChannel * parent
ListBaseT< bPoseChannel > chanbase
wmOperatorStatus(*) exec(bContext *C, wmOperator *op) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1125
const char * description
Definition WM_types.hh:1115
bool(*) poll(bContext *C) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1165
struct ReportList * reports