Blender V4.3
object_relations.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
9#include <cstdio>
10#include <cstdlib>
11#include <cstring>
12
13#include <fmt/format.h>
14
15#include "MEM_guardedalloc.h"
16
17#include "DNA_anim_types.h"
18#include "DNA_armature_types.h"
19#include "DNA_camera_types.h"
22#include "DNA_lattice_types.h"
23#include "DNA_material_types.h"
24#include "DNA_mesh_types.h"
25#include "DNA_object_types.h"
26#include "DNA_particle_types.h"
27#include "DNA_scene_types.h"
28#include "DNA_vfont_types.h"
29
30#include "BLI_kdtree.h"
31#include "BLI_linklist.h"
32#include "BLI_listbase.h"
33#include "BLI_math_matrix.h"
34#include "BLI_math_vector.h"
35#include "BLI_string.h"
36#include "BLI_utildefines.h"
37#include "BLI_vector_set.hh"
38
39#include "BLT_translation.hh"
40
41#include "BKE_action.hh"
42#include "BKE_anim_data.hh"
43#include "BKE_armature.hh"
44#include "BKE_collection.hh"
45#include "BKE_constraint.h"
46#include "BKE_context.hh"
47#include "BKE_curve.hh"
48#include "BKE_displist.h"
49#include "BKE_editmesh.hh"
50#include "BKE_fcurve.hh"
51#include "BKE_idtype.hh"
52#include "BKE_layer.hh"
53#include "BKE_lib_id.hh"
54#include "BKE_lib_override.hh"
55#include "BKE_lib_query.hh"
56#include "BKE_lib_remap.hh"
57#include "BKE_main.hh"
58#include "BKE_material.h"
59#include "BKE_mesh_types.hh"
60#include "BKE_modifier.hh"
61#include "BKE_node.hh"
62#include "BKE_node_runtime.hh"
64#include "BKE_object.hh"
65#include "BKE_object_types.hh"
66#include "BKE_report.hh"
67#include "BKE_scene.hh"
68
69#include "DEG_depsgraph.hh"
72
73#include "WM_api.hh"
74#include "WM_types.hh"
75
76#include "UI_interface.hh"
77#include "UI_resources.hh"
78
79#include "RNA_access.hh"
80#include "RNA_define.hh"
81#include "RNA_enum_types.hh"
82
83#include "ED_armature.hh"
84#include "ED_curve.hh"
85#include "ED_gpencil_legacy.hh"
86#include "ED_grease_pencil.hh"
87#include "ED_mesh.hh"
88#include "ED_object.hh"
89#include "ED_screen.hh"
90#include "ED_view3d.hh"
91
92#include "ANIM_action.hh"
93#include "ANIM_animdata.hh"
94
95#include "MOD_nodes.hh"
96
97#include "object_intern.hh"
98
99namespace blender::ed::object {
100
101/* ------------------------------------------------------------------- */
109
111{
112 Main *bmain = CTX_data_main(C);
113 Scene *scene = CTX_data_scene(C);
114 View3D *v3d = CTX_wm_view3d(C);
116 ViewLayer *view_layer = CTX_data_view_layer(C);
117 Object *obedit = CTX_data_edit_object(C);
118 Object *par;
119
120#define INDEX_UNSET -1
121 int par1, par2, par3, par4;
122 par1 = par2 = par3 = par4 = INDEX_UNSET;
123
124 /* we need 1 to 3 selected vertices */
125
126 if (obedit->type == OB_MESH) {
127 Mesh *mesh = static_cast<Mesh *>(obedit->data);
128
129 EDBM_mesh_load(bmain, obedit);
130 EDBM_mesh_make(obedit, scene->toolsettings->selectmode, true);
131
132 DEG_id_tag_update(static_cast<ID *>(obedit->data), 0);
133
134 BMEditMesh *em = mesh->runtime->edit_mesh.get();
135
137
138 /* Make sure the evaluated mesh is updated.
139 *
140 * Most reliable way is to update the tagged objects, which will ensure
141 * proper copy-on-evaluation update, but also will make sure all dependent
142 * objects are also up to date. */
144
145 BMVert *eve;
146 BMIter iter;
147 int curr_index;
148 BM_ITER_MESH_INDEX (eve, &iter, em->bm, BM_VERTS_OF_MESH, curr_index) {
150 if (par1 == INDEX_UNSET) {
151 par1 = curr_index;
152 }
153 else if (par2 == INDEX_UNSET) {
154 par2 = curr_index;
155 }
156 else if (par3 == INDEX_UNSET) {
157 par3 = curr_index;
158 }
159 else if (par4 == INDEX_UNSET) {
160 par4 = curr_index;
161 }
162 else {
163 break;
164 }
165 }
166 }
167 }
168 else if (ELEM(obedit->type, OB_SURF, OB_CURVES_LEGACY)) {
169 ListBase *editnurb = object_editcurve_get(obedit);
170 int curr_index = 0;
171 for (Nurb *nu = static_cast<Nurb *>(editnurb->first); nu != nullptr; nu = nu->next) {
172 if (nu->type == CU_BEZIER) {
173 BezTriple *bezt = nu->bezt;
174 for (int nurb_index = 0; nurb_index < nu->pntsu; nurb_index++, bezt++, curr_index++) {
175 if (BEZT_ISSEL_ANY_HIDDENHANDLES(v3d, bezt)) {
176 if (par1 == INDEX_UNSET) {
177 par1 = curr_index;
178 }
179 else if (par2 == INDEX_UNSET) {
180 par2 = curr_index;
181 }
182 else if (par3 == INDEX_UNSET) {
183 par3 = curr_index;
184 }
185 else if (par4 == INDEX_UNSET) {
186 par4 = curr_index;
187 }
188 else {
189 break;
190 }
191 }
192 }
193 }
194 else {
195 BPoint *bp = nu->bp;
196 const int points_num = nu->pntsu * nu->pntsv;
197 for (int nurb_index = 0; nurb_index < points_num; nurb_index++, bp++, curr_index++) {
198 if (bp->f1 & SELECT) {
199 if (par1 == INDEX_UNSET) {
200 par1 = curr_index;
201 }
202 else if (par2 == INDEX_UNSET) {
203 par2 = curr_index;
204 }
205 else if (par3 == INDEX_UNSET) {
206 par3 = curr_index;
207 }
208 else if (par4 == INDEX_UNSET) {
209 par4 = curr_index;
210 }
211 else {
212 break;
213 }
214 }
215 }
216 }
217 }
218 }
219 else if (obedit->type == OB_LATTICE) {
220 Lattice *lt = static_cast<Lattice *>(obedit->data);
221
222 const int points_num = lt->editlatt->latt->pntsu * lt->editlatt->latt->pntsv *
223 lt->editlatt->latt->pntsw;
224 BPoint *bp = lt->editlatt->latt->def;
225 for (int curr_index = 0; curr_index < points_num; curr_index++, bp++) {
226 if (bp->f1 & SELECT) {
227 if (par1 == INDEX_UNSET) {
228 par1 = curr_index;
229 }
230 else if (par2 == INDEX_UNSET) {
231 par2 = curr_index;
232 }
233 else if (par3 == INDEX_UNSET) {
234 par3 = curr_index;
235 }
236 else if (par4 == INDEX_UNSET) {
237 par4 = curr_index;
238 }
239 else {
240 break;
241 }
242 }
243 }
244 }
245
246 if (par4 != INDEX_UNSET || par1 == INDEX_UNSET || (par2 != INDEX_UNSET && par3 == INDEX_UNSET)) {
247 BKE_report(op->reports, RPT_ERROR, "Select either 1 or 3 vertices to parent to");
248 return OPERATOR_CANCELLED;
249 }
250
251 CTX_DATA_BEGIN (C, Object *, ob, selected_editable_objects) {
252 if (ob != obedit) {
254 par = obedit->parent;
255
256 if (BKE_object_parent_loop_check(par, ob)) {
257 BKE_report(op->reports, RPT_ERROR, "Loop in parents");
258 }
259 else {
260 BKE_view_layer_synced_ensure(scene, view_layer);
261 ob->parent = BKE_view_layer_active_object_get(view_layer);
262 if (par3 != INDEX_UNSET) {
263 ob->partype = PARVERT3;
264 ob->par1 = par1;
265 ob->par2 = par2;
266 ob->par3 = par3;
267
268 /* inverse parent matrix */
269 invert_m4_m4(ob->parentinv, BKE_object_calc_parent(depsgraph, scene, ob).ptr());
270 }
271 else {
272 ob->partype = PARVERT1;
273 ob->par1 = par1;
274
275 /* inverse parent matrix */
276 invert_m4_m4(ob->parentinv, BKE_object_calc_parent(depsgraph, scene, ob).ptr());
277 }
278 }
279 }
280 }
282
284
285 WM_event_add_notifier(C, NC_OBJECT, nullptr);
286
287 return OPERATOR_FINISHED;
288
289#undef INDEX_UNSET
290}
291
293{
294 /* identifiers */
295 ot->name = "Make Vertex Parent";
296 ot->description = "Parent selected objects to the selected vertices";
297 ot->idname = "OBJECT_OT_vertex_parent_set";
298
299 /* api callbacks */
302
303 /* flags */
305}
306
309/* ------------------------------------------------------------------- */
315 "CLEAR",
316 0,
317 "Clear Parent",
318 "Completely clear the parenting relationship, including involved modifiers if any"},
320 "CLEAR_KEEP_TRANSFORM",
321 0,
322 "Clear and Keep Transformation",
323 "As 'Clear Parent', but keep the current visual transformations of the object"},
325 "CLEAR_INVERSE",
326 0,
327 "Clear Parent Inverse",
328 "Reset the transform corrections applied to the parenting relationship, does not remove "
329 "parenting itself"},
330 {0, nullptr, 0, nullptr, nullptr},
331};
332
333/* Helper for parent_clear() - Remove deform-modifiers associated with parent */
335{
337 ModifierData *md, *mdn;
338
339 /* assume that we only need to remove the first instance of matching deform modifier here */
340 for (md = static_cast<ModifierData *>(ob->modifiers.first); md; md = mdn) {
341 bool free = false;
342
343 mdn = md->next;
344
345 /* need to match types (modifier + parent) and references */
346 if ((md->type == eModifierType_Armature) && (par->type == OB_ARMATURE)) {
348 if (amd->object == par) {
349 free = true;
350 }
351 }
352 else if ((md->type == eModifierType_Lattice) && (par->type == OB_LATTICE)) {
354 if (lmd->object == par) {
355 free = true;
356 }
357 }
358 else if ((md->type == eModifierType_Curve) && (par->type == OB_CURVES_LEGACY)) {
360 if (cmd->object == par) {
361 free = true;
362 }
363 }
364
365 /* free modifier if match */
366 if (free) {
369 }
370 }
371 }
372}
373
374void parent_clear(Object *ob, const int type)
375{
376 if (ob->parent == nullptr) {
377 return;
378 }
380 switch (type) {
381 case CLEAR_PARENT_ALL: {
382 /* for deformers, remove corresponding modifiers to prevent
383 * a large number of modifiers building up */
385
386 /* clear parenting relationship completely */
387 ob->parent = nullptr;
388 ob->partype = PAROBJECT;
389 ob->parsubstr[0] = 0;
390 break;
391 }
393 /* remove parent, and apply the parented transform
394 * result as object's local transforms */
395 ob->parent = nullptr;
396 BKE_object_apply_mat4(ob, ob->object_to_world().ptr(), true, false);
397 /* Don't recalculate the animation because it would change the transform
398 * instead of keeping it. */
399 flags &= ~ID_RECALC_ANIMATION;
400 break;
401 }
403 /* object stays parented, but the parent inverse
404 * (i.e. offset from parent to retain binding state)
405 * is cleared. In other words: nothing to do here! */
406 break;
407 }
408 }
409
410 /* Always clear parentinv matrix for sake of consistency, see #41950. */
411 unit_m4(ob->parentinv);
412
413 DEG_id_tag_update(&ob->id, flags);
414}
415
416/* NOTE: poll should check for editable scene. */
418{
419 Main *bmain = CTX_data_main(C);
420 /* Dependency graph must be evaluated for access to object's evaluated transform matrices. */
422 const int type = RNA_enum_get(op->ptr, "type");
423
424 CTX_DATA_BEGIN (C, Object *, ob, selected_editable_objects) {
425 parent_clear(ob, type);
426 }
428
432 return OPERATOR_FINISHED;
433}
434
436{
437 /* identifiers */
438 ot->name = "Clear Parent";
439 ot->description = "Clear the object's parenting";
440 ot->idname = "OBJECT_OT_parent_clear";
441
442 /* api callbacks */
445
446 /* flags */
448
450}
451
454/* ------------------------------------------------------------------- */
458void parent_set(Object *ob, Object *par, const int type, const char *substr)
459{
460 /* Always clear parentinv matrix for sake of consistency, see #41950. */
461 unit_m4(ob->parentinv);
462
463 if (!par || BKE_object_parent_loop_check(par, ob)) {
464 ob->parent = nullptr;
465 ob->partype = PAROBJECT;
466 ob->parsubstr[0] = 0;
467 return;
468 }
469
470 /* Other partypes are deprecated, do not use here! */
472
473 /* this could use some more checks */
474
475 ob->parent = par;
476 ob->partype &= ~PARTYPE;
477 ob->partype |= type;
478 STRNCPY(ob->parsubstr, substr);
479}
480
482 {PAR_OBJECT, "OBJECT", 0, "Object", ""},
483 {PAR_ARMATURE, "ARMATURE", 0, "Armature Deform", ""},
484 {PAR_ARMATURE_NAME, "ARMATURE_NAME", 0, " With Empty Groups", ""},
485 {PAR_ARMATURE_AUTO, "ARMATURE_AUTO", 0, " With Automatic Weights", ""},
486 {PAR_ARMATURE_ENVELOPE, "ARMATURE_ENVELOPE", 0, " With Envelope Weights", ""},
487 {PAR_BONE, "BONE", 0, "Bone", ""},
488 {PAR_BONE_RELATIVE, "BONE_RELATIVE", 0, "Bone Relative", ""},
489 {PAR_CURVE, "CURVE", 0, "Curve Deform", ""},
490 {PAR_FOLLOW, "FOLLOW", 0, "Follow Path", ""},
491 {PAR_PATH_CONST, "PATH_CONST", 0, "Path Constraint", ""},
492 {PAR_LATTICE, "LATTICE", 0, "Lattice Deform", ""},
493 {PAR_VERTEX, "VERTEX", 0, "Vertex", ""},
494 {PAR_VERTEX_TRI, "VERTEX_TRI", 0, "Vertex (Triangle)", ""},
495 {0, nullptr, 0, nullptr, nullptr},
496};
497
498bool parent_set(ReportList *reports,
499 const bContext *C,
500 Scene *scene,
501 Object *const ob,
502 Object *const par,
503 int partype,
504 const bool xmirror,
505 const bool keep_transform,
506 const int vert_par[3])
507{
508 Main *bmain = CTX_data_main(C);
510 bPoseChannel *pchan = nullptr;
511 bPoseChannel *pchan_eval = nullptr;
512 Object *parent_eval = DEG_get_evaluated_object(depsgraph, par);
513
514 /* Preconditions. */
515 if (ob == par) {
516 /* Parenting an object to itself is impossible. */
517 return false;
518 }
519
520 if (BKE_object_parent_loop_check(par, ob)) {
521 BKE_report(reports, RPT_ERROR, "Loop in parents");
522 return false;
523 }
524
525 switch (partype) {
526 case PAR_FOLLOW:
527 case PAR_PATH_CONST: {
528 if (par->type != OB_CURVES_LEGACY) {
529 return false;
530 }
531 Curve *cu = static_cast<Curve *>(par->data);
532 Curve *cu_eval = static_cast<Curve *>(parent_eval->data);
533 if ((cu->flag & CU_PATH) == 0) {
534 cu->flag |= CU_PATH | CU_FOLLOW;
535 cu_eval->flag |= CU_PATH | CU_FOLLOW;
536 /* force creation of path data */
537 BKE_displist_make_curveTypes(depsgraph, scene, par, false);
538 }
539 else {
540 cu->flag |= CU_FOLLOW;
541 cu_eval->flag |= CU_FOLLOW;
542 }
543
544 /* if follow, add F-Curve for ctime (i.e. "eval_time") so that path-follow works */
545 if (partype == PAR_FOLLOW) {
546 /* get or create F-Curve */
547 bAction *act = animrig::id_action_ensure(bmain, &cu->id);
548 PointerRNA id_ptr = RNA_id_pointer_create(&cu->id);
550 bmain, act, nullptr, &id_ptr, {"eval_time", 0});
551
552 /* setup dummy 'generator' modifier here to get 1-1 correspondence still working */
553 if (!fcu->bezt && !fcu->fpt && !fcu->modifiers.first) {
555 }
556 }
557
558 /* fall back on regular parenting now (for follow only) */
559 if (partype == PAR_FOLLOW) {
560 partype = PAR_OBJECT;
561 }
562 break;
563 }
564 case PAR_BONE:
567 pchan_eval = BKE_pose_channel_active_if_bonecoll_visible(parent_eval);
568
569 if (pchan == nullptr || pchan_eval == nullptr) {
570 /* If pchan_eval is nullptr, pchan should also be nullptr. */
571 BLI_assert_msg(pchan == nullptr, "Missing evaluated bone data");
572 BKE_report(reports, RPT_ERROR, "No active bone");
573 return false;
574 }
575 }
576
577 /* Apply transformation of previous parenting. */
578 if (keep_transform) {
579 /* Was removed because of bug #23577, * but this can be handy in some cases too #32616, so
580 * make optional. */
581 BKE_object_apply_mat4(ob, ob->object_to_world().ptr(), false, false);
582 }
583
584 /* Set the parent (except for follow-path constraint option). */
585 if (partype != PAR_PATH_CONST) {
586 ob->parent = par;
587 /* Always clear parentinv matrix for sake of consistency, see #41950. */
588 unit_m4(ob->parentinv);
589 }
590
591 /* Handle types. */
592 if (pchan) {
593 STRNCPY(ob->parsubstr, pchan->name);
594 }
595 else {
596 ob->parsubstr[0] = 0;
597 }
598
599 switch (partype) {
600 case PAR_PATH_CONST:
601 /* Don't do anything here, since this is not technically "parenting". */
602 break;
603 case PAR_CURVE:
604 case PAR_LATTICE:
605 case PAR_ARMATURE:
609 /* partype is now set to PAROBJECT so that invisible 'virtual'
610 * modifiers don't need to be created.
611 * NOTE: the old (2.4x) method was to set ob->partype = PARSKEL, * creating the
612 * virtual modifiers.
613 */
614 ob->partype = PAROBJECT; /* NOTE: DNA define, not operator property. */
615 // ob->partype = PARSKEL; /* NOTE: DNA define, not operator property. */
616
617 /* BUT, to keep the deforms, we need a modifier, * and then we need to set the object
618 * that it uses
619 * - We need to ensure that the modifier we're adding doesn't already exist, * so we
620 * check this by assuming that the parent is selected too.
621 */
622 /* XXX currently this should only happen for meshes, curves, surfaces, * and lattices
623 * - this stuff isn't available for meta-balls yet. */
624 if (ELEM(
626 {
627 ModifierData *md;
628
629 switch (partype) {
630 case PAR_CURVE: /* curve deform */
631 if (BKE_modifiers_is_deformed_by_curve(ob) != par) {
632 md = modifier_add(reports, bmain, scene, ob, nullptr, eModifierType_Curve);
633 if (md) {
634 ((CurveModifierData *)md)->object = par;
635 }
636 if (par->runtime->curve_cache &&
637 par->runtime->curve_cache->anim_path_accum_length == nullptr)
638 {
640 }
641 }
642 break;
643 case PAR_LATTICE: /* lattice deform */
645 md = modifier_add(reports, bmain, scene, ob, nullptr, eModifierType_Lattice);
646 if (md) {
647 ((LatticeModifierData *)md)->object = par;
648 }
649 }
650 break;
651 default: /* armature deform */
653 if (ob->type == OB_GREASE_PENCIL) {
654 md = modifier_add(
655 reports, bmain, scene, ob, nullptr, eModifierType_GreasePencilArmature);
656 if (md) {
657 ((GreasePencilArmatureModifierData *)md)->object = par;
658 }
659 }
660 else {
661 md = modifier_add(reports, bmain, scene, ob, nullptr, eModifierType_Armature);
662 if (md) {
663 ((ArmatureModifierData *)md)->object = par;
664 }
665 }
666 }
667 break;
668 }
669 }
670 break;
671 case PAR_BONE:
672 ob->partype = PARBONE; /* NOTE: DNA define, not operator property. */
673 if (pchan->bone) {
674 pchan->bone->flag &= ~BONE_RELATIVE_PARENTING;
675 pchan_eval->bone->flag &= ~BONE_RELATIVE_PARENTING;
676 }
677 break;
679 ob->partype = PARBONE; /* NOTE: DNA define, not operator property. */
680 if (pchan->bone) {
682 pchan_eval->bone->flag |= BONE_RELATIVE_PARENTING;
683 }
684 break;
685 case PAR_VERTEX:
686 ob->partype = PARVERT1;
687 ob->par1 = vert_par[0];
688 break;
689 case PAR_VERTEX_TRI:
690 ob->partype = PARVERT3;
691 copy_v3_v3_int(&ob->par1, vert_par);
692 break;
693 case PAR_OBJECT:
694 case PAR_FOLLOW:
695 ob->partype = PAROBJECT; /* NOTE: DNA define, not operator property. */
696 break;
697 }
698
699 /* Constraint and set parent inverse. */
700 const bool is_armature_parent = ELEM(
702 if (partype == PAR_PATH_CONST) {
703 bConstraint *con;
705 float cmat[4][4], vec[3];
706
708
709 data = static_cast<bFollowPathConstraint *>(con->data);
710 data->tar = par;
711
713 depsgraph, scene, con, 0, CONSTRAINT_OBTYPE_OBJECT, nullptr, cmat, scene->r.cfra);
714 sub_v3_v3v3(vec, ob->object_to_world().location(), cmat[3]);
715
716 copy_v3_v3(ob->loc, vec);
717 }
718 else if (is_armature_parent && (ob->type == OB_MESH) && (par->type == OB_ARMATURE)) {
719 if (partype == PAR_ARMATURE_NAME) {
721 reports, depsgraph, scene, ob, par, ARM_GROUPS_NAME, false);
722 }
723 else if (partype == PAR_ARMATURE_ENVELOPE) {
725 reports, depsgraph, scene, ob, par, ARM_GROUPS_ENVELOPE, xmirror);
726 }
727 else if (partype == PAR_ARMATURE_AUTO) {
728 WM_cursor_wait(true);
730 reports, depsgraph, scene, ob, par, ARM_GROUPS_AUTO, xmirror);
731 WM_cursor_wait(false);
732 }
733 /* Get corrected inverse. */
734 ob->partype = PAROBJECT;
735
737 }
738 else if (is_armature_parent && (ob->type == OB_GREASE_PENCIL) && (par->type == OB_ARMATURE)) {
739 if (partype == PAR_ARMATURE_NAME) {
741 }
742 else if (partype == PAR_ARMATURE_ENVELOPE) {
744 }
745 else if (partype == PAR_ARMATURE_AUTO) {
747 }
748 /* get corrected inverse */
749 ob->partype = PAROBJECT;
750
752 }
753 else {
754 /* calculate inverse parent matrix */
756 }
757
760 return true;
761}
762
763static void parent_set_vert_find(KDTree_3d *tree, Object *child, int vert_par[3], bool is_tri)
764{
765 const float *co_find = child->object_to_world().location();
766 if (is_tri) {
767 KDTreeNearest_3d nearest[3];
768 int tot;
769
770 tot = BLI_kdtree_3d_find_nearest_n(tree, co_find, nearest, 3);
771 BLI_assert(tot == 3);
772 UNUSED_VARS(tot);
773
774 vert_par[0] = nearest[0].index;
775 vert_par[1] = nearest[1].index;
776 vert_par[2] = nearest[2].index;
777
778 BLI_assert(min_iii(UNPACK3(vert_par)) >= 0);
779 }
780 else {
781 vert_par[0] = BLI_kdtree_3d_find_nearest(tree, co_find, nullptr);
782 BLI_assert(vert_par[0] >= 0);
783 vert_par[1] = 0;
784 vert_par[2] = 0;
785 }
786}
787
797
798static bool parent_set_nonvertex_parent(bContext *C, ParentingContext *parenting_context)
799{
800 CTX_DATA_BEGIN (C, Object *, ob, selected_editable_objects) {
801 if (ob == parenting_context->par) {
802 /* parent_set() will fail (and thus return false), but this case
803 * shouldn't break this loop. It's expected that the active object is also selected. */
804 continue;
805 }
806
807 if (!parent_set(parenting_context->reports,
808 C,
809 parenting_context->scene,
810 ob,
811 parenting_context->par,
812 parenting_context->partype,
813 parenting_context->xmirror,
814 parenting_context->keep_transform,
815 nullptr))
816 {
817 return false;
818 }
819 }
821
822 return true;
823}
824
826 ParentingContext *parenting_context,
827 KDTree_3d *tree)
828{
829 int vert_par[3] = {0, 0, 0};
830
831 CTX_DATA_BEGIN (C, Object *, ob, selected_editable_objects) {
832 if (ob == parenting_context->par) {
833 /* parent_set() will fail (and thus return false), but this case
834 * shouldn't break this loop. It's expected that the active object is also selected. */
835 continue;
836 }
837
838 parent_set_vert_find(tree, ob, vert_par, parenting_context->is_vertex_tri);
839 if (!parent_set(parenting_context->reports,
840 C,
841 parenting_context->scene,
842 ob,
843 parenting_context->par,
844 parenting_context->partype,
845 parenting_context->xmirror,
846 parenting_context->keep_transform,
847 vert_par))
848 {
849 return false;
850 }
851 }
853 return true;
854}
855
856static bool parent_set_vertex_parent(bContext *C, ParentingContext *parenting_context)
857{
858 KDTree_3d *tree = nullptr;
859 int tree_tot;
860
862 Object *par_eval = DEG_get_evaluated_object(depsgraph, parenting_context->par);
863
864 tree = BKE_object_as_kdtree(par_eval, &tree_tot);
865 BLI_assert(tree != nullptr);
866
867 if (tree_tot < (parenting_context->is_vertex_tri ? 3 : 1)) {
868 BKE_report(parenting_context->reports, RPT_ERROR, "Not enough vertices for vertex-parent");
869 BLI_kdtree_3d_free(tree);
870 return false;
871 }
872
873 const bool ok = parent_set_vertex_parent_with_kdtree(C, parenting_context, tree);
874 BLI_kdtree_3d_free(tree);
875 return ok;
876}
877
879{
880 const int partype = RNA_enum_get(op->ptr, "type");
881 ParentingContext parenting_context{};
882 parenting_context.reports = op->reports;
883 parenting_context.scene = CTX_data_scene(C);
884 parenting_context.par = context_active_object(C);
885 parenting_context.partype = partype;
886 parenting_context.is_vertex_tri = partype == PAR_VERTEX_TRI;
887 parenting_context.xmirror = RNA_boolean_get(op->ptr, "xmirror");
888 parenting_context.keep_transform = RNA_boolean_get(op->ptr, "keep_transform");
889
890 bool ok;
891 if (ELEM(parenting_context.partype, PAR_VERTEX, PAR_VERTEX_TRI)) {
892 ok = parent_set_vertex_parent(C, &parenting_context);
893 }
894 else {
895 ok = parent_set_nonvertex_parent(C, &parenting_context);
896 }
897 if (!ok) {
898 return OPERATOR_CANCELLED;
899 }
900
901 Main *bmain = CTX_data_main(C);
905
906 return OPERATOR_FINISHED;
907}
908
910{
911 Object *parent = context_active_object(C);
912 uiPopupMenu *pup = UI_popup_menu_begin(C, IFACE_("Set Parent To"), ICON_NONE);
913 uiLayout *layout = UI_popup_menu_layout(pup);
914
915 PointerRNA opptr;
916#if 0
917 uiItemEnumO_ptr(layout, ot, nullptr, ICON_NONE, "type", PAR_OBJECT);
918#else
920 layout, ot, IFACE_("Object"), ICON_NONE, nullptr, WM_OP_EXEC_DEFAULT, UI_ITEM_NONE, &opptr);
921 RNA_enum_set(&opptr, "type", PAR_OBJECT);
922 RNA_boolean_set(&opptr, "keep_transform", false);
923
924 uiItemFullO_ptr(layout,
925 ot,
926 IFACE_("Object (Keep Transform)"),
927 ICON_NONE,
928 nullptr,
931 &opptr);
932 RNA_enum_set(&opptr, "type", PAR_OBJECT);
933 RNA_boolean_set(&opptr, "keep_transform", true);
934#endif
935
936 uiItemBooleanO(layout,
937 IFACE_("Object (Without Inverse)"),
938 ICON_NONE,
939 "OBJECT_OT_parent_no_inverse_set",
940 "keep_transform",
941 0);
942
943 uiItemBooleanO(layout,
944 IFACE_("Object (Keep Transform Without Inverse)"),
945 ICON_NONE,
946 "OBJECT_OT_parent_no_inverse_set",
947 "keep_transform",
948 1);
949
950 struct {
951 bool mesh, gpencil, curves;
952 } has_children_of_type = {false};
953
954 CTX_DATA_BEGIN (C, Object *, child, selected_editable_objects) {
955 if (child == parent) {
956 continue;
957 }
958 if (child->type == OB_MESH) {
959 has_children_of_type.mesh = true;
960 }
961 if (ELEM(child->type, OB_GPENCIL_LEGACY, OB_GREASE_PENCIL)) {
962 has_children_of_type.gpencil = true;
963 }
964 if (child->type == OB_CURVES) {
965 has_children_of_type.curves = true;
966 }
967 }
969
970 if (parent->type == OB_ARMATURE) {
971 uiItemEnumO_ptr(layout, ot, nullptr, ICON_NONE, "type", PAR_ARMATURE);
972 uiItemEnumO_ptr(layout, ot, nullptr, ICON_NONE, "type", PAR_ARMATURE_NAME);
973 uiItemEnumO_ptr(layout, ot, nullptr, ICON_NONE, "type", PAR_ARMATURE_ENVELOPE);
974 if (has_children_of_type.mesh || has_children_of_type.gpencil) {
975 uiItemEnumO_ptr(layout, ot, nullptr, ICON_NONE, "type", PAR_ARMATURE_AUTO);
976 }
977 uiItemEnumO_ptr(layout, ot, nullptr, ICON_NONE, "type", PAR_BONE);
978 uiItemEnumO_ptr(layout, ot, nullptr, ICON_NONE, "type", PAR_BONE_RELATIVE);
979 }
980 else if (parent->type == OB_CURVES_LEGACY) {
981 uiItemEnumO_ptr(layout, ot, nullptr, ICON_NONE, "type", PAR_CURVE);
982 uiItemEnumO_ptr(layout, ot, nullptr, ICON_NONE, "type", PAR_FOLLOW);
983 uiItemEnumO_ptr(layout, ot, nullptr, ICON_NONE, "type", PAR_PATH_CONST);
984 }
985 else if (parent->type == OB_LATTICE) {
986 uiItemEnumO_ptr(layout, ot, nullptr, ICON_NONE, "type", PAR_LATTICE);
987 }
988 else if (parent->type == OB_MESH) {
989 if (has_children_of_type.curves) {
990 uiItemO(layout, "Object (Attach Curves to Surface)", ICON_NONE, "CURVES_OT_surface_set");
991 }
992 }
993
994 /* vertex parenting */
995 if (OB_TYPE_SUPPORT_PARVERT(parent->type)) {
996 uiItemEnumO_ptr(layout, ot, nullptr, ICON_NONE, "type", PAR_VERTEX);
997 uiItemEnumO_ptr(layout, ot, nullptr, ICON_NONE, "type", PAR_VERTEX_TRI);
998 }
999
1000 UI_popup_menu_end(C, pup);
1001
1002 return OPERATOR_INTERFACE;
1003}
1004
1005static int parent_set_invoke(bContext *C, wmOperator *op, const wmEvent * /*event*/)
1006{
1007 if (RNA_property_is_set(op->ptr, op->type->prop)) {
1008 return parent_set_exec(C, op);
1009 }
1010 return parent_set_invoke_menu(C, op->type);
1011}
1012
1013static bool parent_set_poll_property(const bContext * /*C*/,
1014 wmOperator *op,
1015 const PropertyRNA *prop)
1016{
1017 const char *prop_id = RNA_property_identifier(prop);
1018
1019 /* Only show XMirror for PAR_ARMATURE_ENVELOPE and PAR_ARMATURE_AUTO! */
1020 if (STREQ(prop_id, "xmirror")) {
1021 const int type = RNA_enum_get(op->ptr, "type");
1023 return true;
1024 }
1025 return false;
1026 }
1027
1028 return true;
1029}
1030
1032{
1033 /* identifiers */
1034 ot->name = "Make Parent";
1035 ot->description = "Set the object's parenting";
1036 ot->idname = "OBJECT_OT_parent_set";
1037
1038 /* api callbacks */
1043
1044 /* flags */
1046
1047 ot->prop = RNA_def_enum(ot->srna, "type", prop_make_parent_types, 0, "Type", "");
1049 ot->srna,
1050 "xmirror",
1051 false,
1052 "X Mirror",
1053 "Apply weights symmetrically along X axis, for Envelope/Automatic vertex groups creation");
1055 "keep_transform",
1056 false,
1057 "Keep Transform",
1058 "Apply transformation before parenting");
1059}
1060
1063/* ------------------------------------------------------------------- */
1068{
1069 Main *bmain = CTX_data_main(C);
1070 Object *par = context_active_object(C);
1071
1072 const bool keep_transform = RNA_boolean_get(op->ptr, "keep_transform");
1073
1075
1076 /* context iterator */
1077 CTX_DATA_BEGIN (C, Object *, ob, selected_editable_objects) {
1078 if (ob != par) {
1079 if (BKE_object_parent_loop_check(par, ob)) {
1080 BKE_report(op->reports, RPT_ERROR, "Loop in parents");
1081 }
1082 else {
1083 /* set recalc flags */
1085
1086 /* set parenting type for object - object only... */
1087 ob->parent = par;
1088 ob->partype = PAROBJECT; /* NOTE: DNA define, not operator property. */
1089
1090 if (keep_transform) {
1092 continue;
1093 }
1094
1095 /* clear inverse matrix and also the object location */
1096 unit_m4(ob->parentinv);
1097 memset(ob->loc, 0, sizeof(float[3]));
1098 }
1099 }
1100 }
1102
1106
1107 return OPERATOR_FINISHED;
1108}
1109
1111{
1112 /* identifiers */
1113 ot->name = "Make Parent without Inverse";
1114 ot->description = "Set the object's parenting without setting the inverse parent correction";
1115 ot->idname = "OBJECT_OT_parent_no_inverse_set";
1116
1117 /* api callbacks */
1120
1121 /* flags */
1123
1125 "keep_transform",
1126 false,
1127 "Keep Transform",
1128 "Preserve the world transform throughout parenting");
1129}
1130
1133/* ------------------------------------------------------------------- */
1137enum {
1140};
1141
1143 {CLEAR_TRACK, "CLEAR", 0, "Clear Track", ""},
1145 "CLEAR_KEEP_TRANSFORM",
1146 0,
1147 "Clear and Keep Transformation (Clear Track)",
1148 ""},
1149 {0, nullptr, 0, nullptr, nullptr},
1150};
1151
1152/* NOTE: poll should check for editable scene. */
1154{
1155 Main *bmain = CTX_data_main(C);
1156 const int type = RNA_enum_get(op->ptr, "type");
1157
1158 if (CTX_data_edit_object(C)) {
1159 BKE_report(op->reports, RPT_ERROR, "Operation cannot be performed in edit mode");
1160 return OPERATOR_CANCELLED;
1161 }
1162 CTX_DATA_BEGIN (C, Object *, ob, selected_editable_objects) {
1163 bConstraint *con, *pcon;
1164
1165 /* remove track-object for old track */
1166 ob->track = nullptr;
1168
1169 /* also remove all tracking constraints */
1170 for (con = static_cast<bConstraint *>(ob->constraints.last); con; con = pcon) {
1171 pcon = con->prev;
1172 if (ELEM(con->type,
1176 {
1177 BKE_constraint_remove(&ob->constraints, con);
1178 }
1179 }
1180
1181 if (type == CLEAR_TRACK_KEEP_TRANSFORM) {
1182 BKE_object_apply_mat4(ob, ob->object_to_world().ptr(), true, true);
1183 }
1184 }
1186
1189
1190 return OPERATOR_FINISHED;
1191}
1192
1194{
1195 /* identifiers */
1196 ot->name = "Clear Track";
1197 ot->description = "Clear tracking constraint or flag from object";
1198 ot->idname = "OBJECT_OT_track_clear";
1199
1200 /* api callbacks */
1203
1205
1206 /* flags */
1208
1209 ot->prop = RNA_def_enum(ot->srna, "type", prop_clear_track_types, 0, "Type", "");
1210}
1211
1214/* ------------------------------------------------------------------- */
1218enum {
1222};
1223
1225 {CREATE_TRACK_DAMPTRACK, "DAMPTRACK", 0, "Damped Track Constraint", ""},
1226 {CREATE_TRACK_TRACKTO, "TRACKTO", 0, "Track to Constraint", ""},
1227 {CREATE_TRACK_LOCKTRACK, "LOCKTRACK", 0, "Lock Track Constraint", ""},
1228 {0, nullptr, 0, nullptr, nullptr},
1229};
1230
1232{
1233 Main *bmain = CTX_data_main(C);
1234 Object *obact = context_active_object(C);
1235
1236 const int type = RNA_enum_get(op->ptr, "type");
1237
1238 switch (type) {
1240 bConstraint *con;
1242
1243 CTX_DATA_BEGIN (C, Object *, ob, selected_editable_objects) {
1244 if (ob != obact) {
1246
1247 data = static_cast<bDampTrackConstraint *>(con->data);
1248 data->tar = obact;
1249 DEG_id_tag_update(&ob->id,
1251
1252 /* Light, Camera and Speaker track differently by default */
1253 if (ELEM(ob->type, OB_LAMP, OB_CAMERA, OB_SPEAKER)) {
1254 data->trackflag = TRACK_nZ;
1255 }
1256 }
1257 }
1259 break;
1260 }
1261 case CREATE_TRACK_TRACKTO: {
1262 bConstraint *con;
1264
1265 CTX_DATA_BEGIN (C, Object *, ob, selected_editable_objects) {
1266 if (ob != obact) {
1268
1269 data = static_cast<bTrackToConstraint *>(con->data);
1270 data->tar = obact;
1271 DEG_id_tag_update(&ob->id,
1273
1274 /* Light, Camera and Speaker track differently by default */
1275 if (ELEM(ob->type, OB_LAMP, OB_CAMERA, OB_SPEAKER)) {
1276 data->reserved1 = TRACK_nZ;
1277 data->reserved2 = UP_Y;
1278 }
1279 }
1280 }
1282 break;
1283 }
1285 bConstraint *con;
1287
1288 CTX_DATA_BEGIN (C, Object *, ob, selected_editable_objects) {
1289 if (ob != obact) {
1291
1292 data = static_cast<bLockTrackConstraint *>(con->data);
1293 data->tar = obact;
1294 DEG_id_tag_update(&ob->id,
1296
1297 /* Light, Camera and Speaker track differently by default */
1298 if (ELEM(ob->type, OB_LAMP, OB_CAMERA, OB_SPEAKER)) {
1299 data->trackflag = TRACK_nZ;
1300 data->lockflag = LOCK_Y;
1301 }
1302 }
1303 }
1305 break;
1306 }
1307 }
1308
1311
1312 return OPERATOR_FINISHED;
1313}
1314
1316{
1317 /* identifiers */
1318 ot->name = "Make Track";
1319 ot->description = "Make the object track another object, using various methods/constraints";
1320 ot->idname = "OBJECT_OT_track_set";
1321
1322 /* api callbacks */
1325
1327
1328 /* flags */
1330
1331 /* properties */
1332 ot->prop = RNA_def_enum(ot->srna, "type", prop_make_track_types, 0, "Type", "");
1333}
1334
1337/* ------------------------------------------------------------------- */
1341#if 0
1342static void link_to_scene(Main * /*bmain*/, ushort /*nr*/)
1343{
1344 Scene *sce = (Scene *)BLI_findlink(&bmain->scene, G.curscreen->scenenr - 1);
1345 Base *base, *nbase;
1346
1347 if (sce == nullptr) {
1348 return;
1349 }
1350 if (sce->id.lib) {
1351 return;
1352 }
1353
1354 for (base = FIRSTBASE; base; base = base->next) {
1355 if (BASE_SELECTED(v3d, base)) {
1356 nbase = MEM_mallocN(sizeof(Base), "newbase");
1357 *nbase = *base;
1358 BLI_addhead(&(sce->base), nbase);
1359 id_us_plus((ID *)base->object);
1360 }
1361 }
1362}
1363#endif
1364
1366{
1367 Main *bmain = CTX_data_main(C);
1368 Scene *scene_to = static_cast<Scene *>(
1369 BLI_findlink(&bmain->scenes, RNA_enum_get(op->ptr, "scene")));
1370
1371 if (scene_to == nullptr) {
1372 BKE_report(op->reports, RPT_ERROR, "Could not find scene");
1373 return OPERATOR_CANCELLED;
1374 }
1375
1376 if (scene_to == CTX_data_scene(C)) {
1377 BKE_report(op->reports, RPT_ERROR, "Cannot link objects into the same scene");
1378 return OPERATOR_CANCELLED;
1379 }
1380
1381 if (!BKE_id_is_editable(bmain, &scene_to->id)) {
1382 BKE_report(op->reports, RPT_ERROR, "Cannot link objects into a linked scene");
1383 return OPERATOR_CANCELLED;
1384 }
1385
1386 Collection *collection_to = scene_to->master_collection;
1387 CTX_DATA_BEGIN (C, Base *, base, selected_bases) {
1388 BKE_collection_object_add(bmain, collection_to, base->object);
1389 }
1391
1392 DEG_id_tag_update(&collection_to->id, ID_RECALC_HIERARCHY);
1393
1395
1396 /* redraw the 3D view because the object center points are colored differently */
1398
1399 /* one day multiple scenes will be visible, then we should have some update function for them
1400 */
1401 return OPERATOR_FINISHED;
1402}
1403
1404enum {
1413};
1414
1415/* Return true if make link data is allowed, false otherwise */
1416static bool allow_make_links_data(const int type, Object *ob_src, Object *ob_dst)
1417{
1418 switch (type) {
1419 case MAKE_LINKS_OBDATA:
1420 if (ob_src->type == ob_dst->type && ob_src->type != OB_EMPTY) {
1421 return true;
1422 }
1423 break;
1426 /* Linking non-grease-pencil materials to a grease-pencil object causes issues.
1427 * We make sure that if one of the objects is a grease-pencil object, the other must be
1428 * as well. */
1429 ((ob_src->type == OB_GREASE_PENCIL) == (ob_dst->type == OB_GREASE_PENCIL)))
1430 {
1431 return true;
1432 }
1433 break;
1435 if (ob_dst->type == OB_EMPTY) {
1436 return true;
1437 }
1438 break;
1440 case MAKE_LINKS_GROUP:
1441 return true;
1443 if (!ELEM(OB_EMPTY, ob_src->type, ob_dst->type)) {
1444 return true;
1445 }
1446 break;
1447 case MAKE_LINKS_FONTS:
1448 if ((ob_src->data != ob_dst->data) && (ob_src->type == OB_FONT) && (ob_dst->type == OB_FONT))
1449 {
1450 return true;
1451 }
1452 break;
1454 if ((ob_src->type == OB_GREASE_PENCIL) && (ob_dst->type == OB_GREASE_PENCIL)) {
1455 return true;
1456 }
1457 break;
1458 }
1459 return false;
1460}
1461
1463{
1464 Scene *scene = CTX_data_scene(C);
1465 Main *bmain = CTX_data_main(C);
1466 const int type = RNA_enum_get(op->ptr, "type");
1467 Object *ob_src;
1468 ID *obdata_id;
1469 int a;
1470
1471 /* collection */
1472 LinkNode *ob_collections = nullptr;
1473 bool is_cycle = false;
1474 bool is_lib = false;
1475
1476 ob_src = context_active_object(C);
1477
1478 /* avoid searching all collections in source object each time */
1479 if (type == MAKE_LINKS_GROUP) {
1480 ob_collections = BKE_object_groups(bmain, scene, ob_src);
1481 }
1482
1483 CTX_DATA_BEGIN (C, Base *, base_dst, selected_editable_bases) {
1484 Object *ob_dst = base_dst->object;
1485
1486 if (ob_src != ob_dst) {
1487 if (allow_make_links_data(type, ob_src, ob_dst)) {
1488 obdata_id = static_cast<ID *>(ob_dst->data);
1489
1490 switch (type) {
1491 case MAKE_LINKS_OBDATA: /* obdata */
1492 id_us_min(obdata_id);
1493
1494 obdata_id = static_cast<ID *>(ob_src->data);
1495 id_us_plus(obdata_id);
1496 ob_dst->data = obdata_id;
1497
1498 /* if amount of material indices changed: */
1499 BKE_object_materials_test(bmain, ob_dst, static_cast<ID *>(ob_dst->data));
1500
1501 if (ob_dst->type == OB_ARMATURE) {
1502 BKE_pose_rebuild(bmain, ob_dst, static_cast<bArmature *>(ob_dst->data), true);
1503 }
1505 break;
1507 /* new approach, using functions from kernel */
1508 for (a = 0; a < ob_src->totcol; a++) {
1509 Material *ma = BKE_object_material_get(ob_src, a + 1);
1510 /* also works with `ma == nullptr` */
1511 BKE_object_material_assign(bmain, ob_dst, ma, a + 1, BKE_MAT_ASSIGN_USERPREF);
1512 }
1514 break;
1516 BKE_animdata_copy_id(bmain, (ID *)ob_dst, (ID *)ob_src, 0);
1517 if (ob_dst->data && ob_src->data) {
1518 if (BKE_id_is_editable(bmain, obdata_id)) {
1519 BKE_animdata_copy_id(bmain, (ID *)ob_dst->data, (ID *)ob_src->data, 0);
1520 }
1521 else {
1522 is_lib = true;
1523 }
1524 }
1525 DEG_id_tag_update(&ob_dst->id,
1527 break;
1528 case MAKE_LINKS_GROUP: {
1529 LinkNode *collection_node;
1530
1531 /* first clear collections */
1532 BKE_object_groups_clear(bmain, scene, ob_dst);
1533
1534 /* now add in the collections from the link nodes */
1535 for (collection_node = ob_collections; collection_node;
1536 collection_node = collection_node->next)
1537 {
1538 if (ob_dst->instance_collection != collection_node->link) {
1540 bmain, static_cast<Collection *>(collection_node->link), ob_dst);
1541 }
1542 else {
1543 is_cycle = true;
1544 }
1545 }
1546 break;
1547 }
1549 ob_dst->instance_collection = ob_src->instance_collection;
1550 if (ob_dst->instance_collection) {
1551 id_us_plus(&ob_dst->instance_collection->id);
1552 ob_dst->transflag |= OB_DUPLICOLLECTION;
1553 }
1555 break;
1557 BKE_object_link_modifiers(ob_dst, ob_src);
1558 DEG_id_tag_update(&ob_dst->id,
1560 break;
1561 case MAKE_LINKS_FONTS: {
1562 Curve *cu_src = static_cast<Curve *>(ob_src->data);
1563 Curve *cu_dst = static_cast<Curve *>(ob_dst->data);
1564
1565 if (!BKE_id_is_editable(bmain, obdata_id)) {
1566 is_lib = true;
1567 break;
1568 }
1569
1570 if (cu_dst->vfont) {
1571 id_us_min(&cu_dst->vfont->id);
1572 }
1573 cu_dst->vfont = cu_src->vfont;
1574 id_us_plus((ID *)cu_dst->vfont);
1575 if (cu_dst->vfontb) {
1576 id_us_min(&cu_dst->vfontb->id);
1577 }
1578 cu_dst->vfontb = cu_src->vfontb;
1579 id_us_plus((ID *)cu_dst->vfontb);
1580 if (cu_dst->vfonti) {
1581 id_us_min(&cu_dst->vfonti->id);
1582 }
1583 cu_dst->vfonti = cu_src->vfonti;
1584 id_us_plus((ID *)cu_dst->vfonti);
1585 if (cu_dst->vfontbi) {
1586 id_us_min(&cu_dst->vfontbi->id);
1587 }
1588 cu_dst->vfontbi = cu_src->vfontbi;
1589 id_us_plus((ID *)cu_dst->vfontbi);
1590
1591 DEG_id_tag_update(&ob_dst->id,
1593 break;
1594 }
1596 shaderfx_link(ob_dst, ob_src);
1597 DEG_id_tag_update(&ob_dst->id,
1599 break;
1600 }
1601 }
1602 }
1603 }
1605
1606 if (type == MAKE_LINKS_GROUP) {
1607 if (ob_collections) {
1608 BLI_linklist_free(ob_collections, nullptr);
1609 }
1610
1611 if (is_cycle) {
1612 BKE_report(op->reports, RPT_WARNING, "Skipped some collections because of cycle detected");
1613 }
1614 }
1615
1616 if (is_lib) {
1617 BKE_report(op->reports, RPT_WARNING, "Skipped editing library object data");
1618 }
1619
1623 WM_event_add_notifier(C, NC_OBJECT, nullptr);
1624
1625 return OPERATOR_FINISHED;
1626}
1627
1629{
1630 PropertyRNA *prop;
1631
1632 /* identifiers */
1633 ot->name = "Link Objects to Scene";
1634 ot->description = "Link selection to another scene";
1635 ot->idname = "OBJECT_OT_make_links_scene";
1636
1637 /* api callbacks */
1640 /* better not run the poll check */
1641
1642 /* flags */
1644
1645 /* properties */
1646 prop = RNA_def_enum(ot->srna, "scene", rna_enum_dummy_NULL_items, 0, "Scene", "");
1649 ot->prop = prop;
1650}
1651
1653{
1654 static const EnumPropertyItem make_links_items[] = {
1655 {MAKE_LINKS_OBDATA, "OBDATA", 0, "Link Object Data", "Replace assigned Object Data"},
1656 {MAKE_LINKS_MATERIALS, "MATERIAL", 0, "Link Materials", "Replace assigned Materials"},
1658 "ANIMATION",
1659 0,
1660 "Link Animation Data",
1661 "Replace assigned Animation Data"},
1662 {MAKE_LINKS_GROUP, "GROUPS", 0, "Link Collections", "Replace assigned Collections"},
1664 "DUPLICOLLECTION",
1665 0,
1666 "Link Instance Collection",
1667 "Replace assigned Collection Instance"},
1668 {MAKE_LINKS_FONTS, "FONTS", 0, "Link Fonts to Text", "Replace Text object Fonts"},
1670 {MAKE_LINKS_MODIFIERS, "MODIFIERS", 0, "Copy Modifiers", "Replace Modifiers"},
1672 "EFFECTS",
1673 0,
1674 "Copy Grease Pencil Effects",
1675 "Replace Grease Pencil Effects"},
1676 {0, nullptr, 0, nullptr, nullptr},
1677 };
1678
1679 /* identifiers */
1680 ot->name = "Link/Transfer Data";
1681 ot->description = "Transfer data from active object to selected objects";
1682 ot->idname = "OBJECT_OT_make_links_data";
1683
1684 /* api callbacks */
1687
1688 /* flags */
1690
1691 /* properties */
1692 ot->prop = RNA_def_enum(ot->srna, "type", make_links_items, 0, "Type", "");
1693}
1694
1697/* ------------------------------------------------------------------- */
1702{
1703 /* NOTE: When dealing with linked data, we always make a local copy of it.
1704 * While in theory we could rather make it local when it only has one user, this is difficult
1705 * in practice with current code of this function. */
1706 return (id != nullptr && (id->us > 1 || ID_IS_LINKED(id)));
1707}
1708
1710 Collection *collection,
1711 const bool do_collection)
1712{
1713 if (do_collection) {
1714 BKE_libblock_relink_to_newid(bmain, &collection->id, 0);
1715 }
1716
1717 for (CollectionObject *cob = static_cast<CollectionObject *>(collection->gobject.first);
1718 cob != nullptr;
1719 cob = cob->next)
1720 {
1721 BKE_libblock_relink_to_newid(bmain, &cob->ob->id, 0);
1722 }
1723
1724 LISTBASE_FOREACH (CollectionChild *, child, &collection->children) {
1725 libblock_relink_collection(bmain, child->collection, true);
1726 }
1727}
1728
1730 Scene *scene,
1731 Collection *collection,
1732 const int flag,
1733 const bool copy_collections,
1734 const bool is_master_collection)
1735{
1736 /* Generate new copies for objects in given collection and all its children, * and
1737 * optionally also copy collections themselves. */
1738 if (copy_collections && !is_master_collection) {
1739 Collection *collection_new = (Collection *)BKE_id_copy_ex(
1740 bmain, &collection->id, nullptr, LIB_ID_COPY_DEFAULT | LIB_ID_COPY_ACTIONS);
1741 id_us_min(&collection_new->id);
1742 collection = static_cast<Collection *>(ID_NEW_SET(collection, collection_new));
1743 }
1744
1745 /* We do not remap to new objects here, this is done in separate step. */
1746 LISTBASE_FOREACH (CollectionObject *, cob, &collection->gobject) {
1747 Object *ob = cob->ob;
1748 /* an object may be in more than one collection */
1749 if ((ob->id.newid == nullptr) && ((ob->flag & flag) == flag)) {
1750 if (!ID_IS_LINKED(ob) && BKE_object_scenes_users_get(bmain, ob) > 1) {
1751 ID_NEW_SET(
1752 ob,
1753 BKE_id_copy_ex(bmain, &ob->id, nullptr, LIB_ID_COPY_DEFAULT | LIB_ID_COPY_ACTIONS));
1754 id_us_min(ob->id.newid);
1755 }
1756 }
1757 }
1758
1759 /* Since master collection has already be duplicated as part of scene copy, * we do not
1760 * duplicate it here. However, this means its children need to be re-added manually here, *
1761 * otherwise their parent lists are empty (which will lead to crashes, see #63101). */
1762 CollectionChild *child_next, *child = static_cast<CollectionChild *>(collection->children.first);
1763 CollectionChild *orig_child_last = static_cast<CollectionChild *>(collection->children.last);
1764 for (; child != nullptr; child = child_next) {
1765 child_next = child->next;
1766 Collection *collection_child_new = single_object_users_collection(
1767 bmain, scene, child->collection, flag, copy_collections, false);
1768
1769 if (is_master_collection && copy_collections && child->collection != collection_child_new) {
1770 /* We do not want a collection sync here, our collections are in a complete uninitialized
1771 * state currently. With current code, that would lead to a memory leak - because of
1772 * reasons. It would be a useless loss of computing anyway, since caller has to fully
1773 * refresh view-layers/collections caching at the end. */
1774 BKE_collection_child_add_no_sync(bmain, collection, collection_child_new);
1775 BLI_remlink(&collection->children, child);
1776 MEM_freeN(child);
1777 if (child == orig_child_last) {
1778 break;
1779 }
1780 }
1781 }
1782
1783 return collection;
1784}
1785
1786/* Warning, sets ID->newid pointers of objects and collections, but does not clear them. */
1788 Main *bmain, Scene *scene, View3D *v3d, const int flag, const bool copy_collections)
1789{
1790 /* duplicate all the objects of the scene (and matching collections, if required). */
1791 Collection *master_collection = scene->master_collection;
1792 single_object_users_collection(bmain, scene, master_collection, flag, copy_collections, true);
1793
1794 /* Will also handle the master collection. */
1795 BKE_libblock_relink_to_newid(bmain, &scene->id, 0);
1796
1797 /* Collection and object pointers in collections */
1798 libblock_relink_collection(bmain, scene->master_collection, false);
1799
1800 /* We also have to handle runtime things in UI. */
1801 if (v3d) {
1802 ID_NEW_REMAP(v3d->camera);
1803 }
1804
1805 /* Making single user may affect other scenes if they share
1806 * with current one some collections in their ViewLayer. */
1808}
1809
1810void object_single_user_make(Main *bmain, Scene *scene, Object *ob)
1811{
1812 FOREACH_SCENE_OBJECT_BEGIN (scene, ob_iter) {
1813 ob_iter->flag &= ~OB_DONE;
1814 }
1816
1817 /* tag only the one object */
1818 ob->flag |= OB_DONE;
1819
1820 single_object_users(bmain, scene, nullptr, OB_DONE, false);
1822}
1823
1825 Main *bmain, Scene *scene, ViewLayer *view_layer, View3D *v3d, const int flag)
1826{
1827 Light *la;
1828 Curve *cu;
1829 Camera *cam;
1830 Mesh *mesh;
1831 Lattice *lat;
1832 ID *id;
1833
1834 FOREACH_OBJECT_FLAG_BEGIN (scene, view_layer, v3d, flag, ob) {
1835 if (BKE_id_is_editable(bmain, &ob->id)) {
1836 id = static_cast<ID *>(ob->data);
1839
1840 switch (ob->type) {
1841 case OB_EMPTY:
1842 ob->data = ID_NEW_SET(ob->data,
1843 BKE_id_copy_ex(bmain,
1844 static_cast<const ID *>(ob->data),
1845 nullptr,
1847 break;
1848 case OB_LAMP:
1849 ob->data = la = static_cast<Light *>(
1850 ID_NEW_SET(ob->data,
1851 BKE_id_copy_ex(bmain,
1852 static_cast<const ID *>(ob->data),
1853 nullptr,
1855 break;
1856 case OB_CAMERA:
1857 ob->data = cam = static_cast<Camera *>(
1858 ID_NEW_SET(ob->data,
1859 BKE_id_copy_ex(bmain,
1860 static_cast<const ID *>(ob->data),
1861 nullptr,
1864 break;
1865 case OB_MESH:
1866 /* Needed to remap texcomesh below. */
1867 ob->data = mesh = static_cast<Mesh *>(
1868 ID_NEW_SET(ob->data,
1869 BKE_id_copy_ex(bmain,
1870 static_cast<const ID *>(ob->data),
1871 nullptr,
1873 break;
1874 case OB_MBALL:
1875 ob->data = ID_NEW_SET(ob->data,
1876 BKE_id_copy_ex(bmain,
1877 static_cast<const ID *>(ob->data),
1878 nullptr,
1880 break;
1881 case OB_CURVES_LEGACY:
1882 case OB_SURF:
1883 case OB_FONT:
1884 ob->data = cu = static_cast<Curve *>(
1885 ID_NEW_SET(ob->data,
1886 BKE_id_copy_ex(bmain,
1887 static_cast<const ID *>(ob->data),
1888 nullptr,
1890 ID_NEW_REMAP(cu->bevobj);
1892 break;
1893 case OB_LATTICE:
1894 ob->data = lat = static_cast<Lattice *>(
1895 ID_NEW_SET(ob->data,
1896 BKE_id_copy_ex(bmain,
1897 static_cast<const ID *>(ob->data),
1898 nullptr,
1900 break;
1901 case OB_ARMATURE:
1903 ob->data = ID_NEW_SET(ob->data,
1904 BKE_id_copy_ex(bmain,
1905 static_cast<const ID *>(ob->data),
1906 nullptr,
1908 BKE_pose_rebuild(bmain, ob, static_cast<bArmature *>(ob->data), true);
1909 break;
1910 case OB_SPEAKER:
1911 ob->data = ID_NEW_SET(ob->data,
1912 BKE_id_copy_ex(bmain,
1913 static_cast<const ID *>(ob->data),
1914 nullptr,
1916 break;
1917 case OB_LIGHTPROBE:
1918 ob->data = ID_NEW_SET(ob->data,
1919 BKE_id_copy_ex(bmain,
1920 static_cast<const ID *>(ob->data),
1921 nullptr,
1923 break;
1924 case OB_GPENCIL_LEGACY:
1925 ob->data = ID_NEW_SET(ob->data,
1926 BKE_id_copy_ex(bmain,
1927 static_cast<const ID *>(ob->data),
1928 nullptr,
1930 break;
1931 case OB_CURVES:
1932 ob->data = ID_NEW_SET(ob->data,
1933 BKE_id_copy_ex(bmain,
1934 static_cast<const ID *>(ob->data),
1935 nullptr,
1937 break;
1938 case OB_POINTCLOUD:
1939 ob->data = ID_NEW_SET(ob->data,
1940 BKE_id_copy_ex(bmain,
1941 static_cast<const ID *>(ob->data),
1942 nullptr,
1944 break;
1945 case OB_VOLUME:
1946 ob->data = ID_NEW_SET(ob->data,
1947 BKE_id_copy_ex(bmain,
1948 static_cast<const ID *>(ob->data),
1949 nullptr,
1951 break;
1952 case OB_GREASE_PENCIL:
1953 ob->data = ID_NEW_SET(ob->data,
1954 BKE_id_copy_ex(bmain,
1955 static_cast<const ID *>(ob->data),
1956 nullptr,
1958 break;
1959 default:
1960 printf("ERROR %s: can't copy %s\n", __func__, id->name);
1961 BLI_assert_msg(0, "This should never happen.");
1962
1963 /* We need to end the FOREACH_OBJECT_FLAG_BEGIN iterator to prevent memory leak. */
1964 BKE_scene_objects_iterator_end(&iter_macro);
1965 return;
1966 }
1967
1968 id_us_min(id);
1969 }
1970 }
1971 }
1973
1974 mesh = static_cast<Mesh *>(bmain->meshes.first);
1975 while (mesh) {
1976 ID_NEW_REMAP(mesh->texcomesh);
1977 mesh = static_cast<Mesh *>(mesh->id.next);
1978 }
1979}
1980
1981void single_obdata_user_make(Main *bmain, Scene *scene, Object *ob)
1982{
1983 FOREACH_SCENE_OBJECT_BEGIN (scene, ob_iter) {
1984 ob_iter->flag &= ~OB_DONE;
1985 }
1987
1988 /* Tag only the one object. */
1989 ob->flag |= OB_DONE;
1990
1991 single_obdata_users(bmain, scene, nullptr, nullptr, OB_DONE);
1992}
1993
1995 Main *bmain, Scene *scene, ViewLayer *view_layer, View3D *v3d, const int flag)
1996{
1997 FOREACH_OBJECT_FLAG_BEGIN (scene, view_layer, v3d, flag, ob) {
1998 if (BKE_id_is_editable(bmain, &ob->id)) {
1999 AnimData *adt = BKE_animdata_from_id(&ob->id);
2000 if (adt == nullptr) {
2001 continue;
2002 }
2003
2004 ID *id_act = (ID *)adt->action;
2005 if (single_data_needs_duplication(id_act)) {
2008 }
2009 }
2010 }
2012}
2013
2015 Main *bmain, Scene *scene, ViewLayer *view_layer, View3D *v3d, const int flag)
2016{
2017 FOREACH_OBJECT_FLAG_BEGIN (scene, view_layer, v3d, flag, ob) {
2018 if (BKE_id_is_editable(bmain, &ob->id) && ob->data != nullptr) {
2019 ID *id_obdata = (ID *)ob->data;
2020 AnimData *adt = BKE_animdata_from_id(id_obdata);
2021 if (adt == nullptr) {
2022 continue;
2023 }
2024
2025 ID *id_act = (ID *)adt->action;
2026 if (single_data_needs_duplication(id_act)) {
2029 }
2030 }
2031 }
2033}
2034
2036 Main *bmain, Scene *scene, ViewLayer *view_layer, View3D *v3d, const int flag)
2037{
2038 Material *ma, *man;
2039 int a;
2040
2041 FOREACH_OBJECT_FLAG_BEGIN (scene, view_layer, v3d, flag, ob) {
2042 if (BKE_id_is_editable(bmain, &ob->id)) {
2043 for (a = 1; a <= ob->totcol; a++) {
2044 ma = BKE_object_material_get(ob, short(a));
2046 man = (Material *)BKE_id_copy_ex(
2047 bmain, &ma->id, nullptr, LIB_ID_COPY_DEFAULT | LIB_ID_COPY_ACTIONS);
2048 man->id.us = 0;
2049 BKE_object_material_assign(bmain, ob, man, short(a), BKE_MAT_ASSIGN_USERPREF);
2050 }
2051 }
2052 }
2053 }
2055}
2056
2059/* ------------------------------------------------------------------- */
2063enum {
2068};
2069
2071{
2072 ID **id_pointer = cb_data->id_pointer;
2073 if (*id_pointer) {
2074 (*id_pointer)->tag &= ~ID_TAG_DOIT;
2075 }
2076
2077 return IDWALK_RET_NOP;
2078}
2079
2080static void tag_localizable_objects(bContext *C, const int mode)
2081{
2082 Main *bmain = CTX_data_main(C);
2083
2084 BKE_main_id_tag_all(bmain, ID_TAG_DOIT, false);
2085
2086 /* Set ID_TAG_DOIT flag for all selected objects, so next we can check whether
2087 * object is gonna to become local or not.
2088 */
2089 CTX_DATA_BEGIN (C, Object *, object, selected_objects) {
2090 object->id.tag |= ID_TAG_DOIT;
2091
2092 /* If obdata is also going to become local, mark it as such too. */
2093 if (mode == MAKE_LOCAL_SELECT_OBDATA && object->data) {
2094 ID *data_id = (ID *)object->data;
2095 data_id->tag |= ID_TAG_DOIT;
2096 }
2097 }
2099
2100 /* Also forbid making objects local if other library objects are using
2101 * them for modifiers or constraints.
2102 *
2103 * FIXME This is ignoring all other linked ID types potentially using the selected tagged
2104 * objects! Probably works fine in most 'usual' cases though.
2105 */
2106 for (Object *object = static_cast<Object *>(bmain->objects.first); object;
2107 object = static_cast<Object *>(object->id.next))
2108 {
2109 if ((object->id.tag & ID_TAG_DOIT) == 0 && ID_IS_LINKED(object)) {
2111 nullptr, &object->id, tag_localizable_looper, nullptr, IDWALK_READONLY);
2112 }
2113 if (object->data) {
2114 ID *data_id = (ID *)object->data;
2115 if ((data_id->tag & ID_TAG_DOIT) == 0 && ID_IS_LINKED(data_id)) {
2117 nullptr, data_id, tag_localizable_looper, nullptr, IDWALK_READONLY);
2118 }
2119 }
2120 }
2121
2122 /* TODO(sergey): Drivers targets? */
2123}
2124
2130 const Scene *scene,
2131 ViewLayer *view_layer,
2132 Collection *collection)
2133{
2134 Object *ob;
2135 bool changed = false;
2136
2137 for (ob = static_cast<Object *>(bmain->objects.first); ob;
2138 ob = static_cast<Object *>(ob->id.next))
2139 {
2140 if (ID_IS_LINKED(ob) && (ob->id.us == 0)) {
2141 Base *base;
2142
2143 id_us_plus(&ob->id);
2144
2145 BKE_collection_object_add(bmain, collection, ob);
2146 BKE_view_layer_synced_ensure(scene, view_layer);
2147 base = BKE_view_layer_base_find(view_layer, ob);
2148 base_select(base, BA_SELECT);
2150
2151 changed = true;
2152 }
2153 }
2154
2155 return changed;
2156}
2157
2159{
2160 LISTBASE_FOREACH (NlaStrip *, strip, strips) {
2161 if (strip->act) {
2162 strip->act->id.tag &= ~ID_TAG_PRE_EXISTING;
2163 }
2164
2165 make_local_animdata_tag_strips(&strip->strips);
2166 }
2167}
2168
2169/* Tag all actions used by given animdata to be made local. */
2171{
2172 if (adt) {
2173 /* Actions - Active and Temp */
2174 if (adt->action) {
2175 adt->action->id.tag &= ~ID_TAG_PRE_EXISTING;
2176 }
2177 if (adt->tmpact) {
2178 adt->tmpact->id.tag &= ~ID_TAG_PRE_EXISTING;
2179 }
2180
2181 /* Drivers */
2182 /* TODO: need to handle the ID-targets too? */
2183
2184 /* NLA Data */
2185 LISTBASE_FOREACH (NlaTrack *, nlt, &adt->nla_tracks) {
2186 make_local_animdata_tag_strips(&nlt->strips);
2187 }
2188 }
2189}
2190
2192{
2193 if (ma) {
2194 ma->id.tag &= ~ID_TAG_PRE_EXISTING;
2196
2197 /* About node-trees: root one is made local together with material,
2198 * others we keep linked (for now). */
2199 }
2200}
2201
2203{
2204 Main *bmain = CTX_data_main(C);
2205 Material *ma, ***matarar;
2206 const int mode = RNA_enum_get(op->ptr, "type");
2207 int a;
2208
2209 /* NOTE: we (ab)use ID_TAG_PRE_EXISTING to cherry pick which ID to make local... */
2210 if (mode == MAKE_LOCAL_ALL) {
2211 const Scene *scene = CTX_data_scene(C);
2212 ViewLayer *view_layer = CTX_data_view_layer(C);
2213 Collection *collection = CTX_data_collection(C);
2214
2216
2217 /* De-select so the user can differentiate newly instanced from existing objects. */
2218 BKE_view_layer_base_deselect_all(scene, view_layer);
2219
2220 if (make_local_all__instance_indirect_unused(bmain, scene, view_layer, collection)) {
2221 BKE_report(op->reports,
2222 RPT_INFO,
2223 "Orphan library objects added to the current scene to avoid loss");
2224 }
2225 }
2226 else {
2228 tag_localizable_objects(C, mode);
2229
2230 CTX_DATA_BEGIN (C, Object *, ob, selected_objects) {
2231 if ((ob->id.tag & ID_TAG_DOIT) == 0) {
2232 continue;
2233 }
2234
2235 ob->id.tag &= ~ID_TAG_PRE_EXISTING;
2237 LISTBASE_FOREACH (ParticleSystem *, psys, &ob->particlesystem) {
2238 psys->part->id.tag &= ~ID_TAG_PRE_EXISTING;
2239 }
2240
2242 for (a = 0; a < ob->totcol; a++) {
2243 ma = ob->mat[a];
2244 if (ma) {
2246 }
2247 }
2248
2249 matarar = BKE_object_material_array_p(ob);
2250 if (matarar) {
2251 for (a = 0; a < ob->totcol; a++) {
2252 ma = (*matarar)[a];
2253 if (ma) {
2255 }
2256 }
2257 }
2258 }
2259
2261 ob->data != nullptr)
2262 {
2263 ID *ob_data = static_cast<ID *>(ob->data);
2264 ob_data->tag &= ~ID_TAG_PRE_EXISTING;
2266 }
2267 }
2269 }
2270
2272 bmain, nullptr, nullptr, true, false, true); /* nullptr is all libraries. */
2273
2274 WM_event_add_notifier(C, NC_WINDOW, nullptr);
2275 return OPERATOR_FINISHED;
2276}
2277
2279{
2280 static const EnumPropertyItem type_items[] = {
2281 {MAKE_LOCAL_SELECT_OB, "SELECT_OBJECT", 0, "Selected Objects", ""},
2282 {MAKE_LOCAL_SELECT_OBDATA, "SELECT_OBDATA", 0, "Selected Objects and Data", ""},
2284 "SELECT_OBDATA_MATERIAL",
2285 0,
2286 "Selected Objects, Data and Materials",
2287 ""},
2288 {MAKE_LOCAL_ALL, "ALL", 0, "All", ""},
2289 {0, nullptr, 0, nullptr, nullptr},
2290 };
2291
2292 /* identifiers */
2293 ot->name = "Make Local";
2294 ot->description = "Make library linked data-blocks local to this file";
2295 ot->idname = "OBJECT_OT_make_local";
2296
2297 /* api callbacks */
2301
2302 /* flags */
2304
2305 /* properties */
2306 ot->prop = RNA_def_enum(ot->srna, "type", type_items, 0, "Type", "");
2307}
2308
2311/* ------------------------------------------------------------------- */
2316{
2317 /* An object is actually overridable only if it is in at least one local collection.
2318 * Unfortunately 'direct link' flag is not enough here. */
2319 LISTBASE_FOREACH (Collection *, collection, &bmain->collections) {
2320 if (!ID_IS_LINKED(collection) && BKE_collection_has_object(collection, object)) {
2321 return true;
2322 }
2323 }
2324 LISTBASE_FOREACH (Scene *, scene, &bmain->scenes) {
2325 if (!ID_IS_LINKED(scene) && BKE_collection_has_object(scene->master_collection, object)) {
2326 return true;
2327 }
2328 }
2329 return false;
2330}
2331
2333{
2334 Main *bmain = CTX_data_main(C);
2335 Scene *scene = CTX_data_scene(C);
2336 ViewLayer *view_layer = CTX_data_view_layer(C);
2337 Object *obact = CTX_data_active_object(C);
2338 ID *id_root = nullptr;
2339 bool is_override_instancing_object = false;
2340
2341 bool user_overrides_from_selected_objects = false;
2342
2343 if (!ID_IS_LINKED(obact) && obact->instance_collection != nullptr &&
2345 {
2347 BKE_reportf(op->reports,
2349 "Collection '%s' (instantiated by the active object) is not overridable",
2350 obact->instance_collection->id.name + 2);
2351 return OPERATOR_CANCELLED;
2352 }
2353
2354 id_root = &obact->instance_collection->id;
2355 is_override_instancing_object = true;
2356 user_overrides_from_selected_objects = false;
2357 }
2358 else if (!make_override_library_object_overridable_check(bmain, obact)) {
2359 const int i = RNA_property_int_get(op->ptr, op->type->prop);
2360 const uint collection_session_uid = *((const uint *)&i);
2361 if (collection_session_uid == MAIN_ID_SESSION_UID_UNSET) {
2362 BKE_reportf(op->reports,
2364 "Could not find an overridable root hierarchy for object '%s'",
2365 obact->id.name + 2);
2366 return OPERATOR_CANCELLED;
2367 }
2368 Collection *collection = static_cast<Collection *>(
2370 &collection_session_uid,
2371 sizeof(collection_session_uid),
2372 offsetof(ID, session_uid)));
2373 id_root = &collection->id;
2374 user_overrides_from_selected_objects = true;
2375 }
2376 /* Else, poll func ensures us that ID_IS_LINKED(obact) is true, or that it is already an
2377 * existing liboverride. */
2378 else {
2380 id_root = &obact->id;
2381 user_overrides_from_selected_objects = true;
2382 }
2383
2384 /* Make already existing selected liboverrides editable. */
2385 bool is_active_override = false;
2386 FOREACH_SELECTED_OBJECT_BEGIN (view_layer, CTX_wm_view3d(C), ob_iter) {
2387 if (ID_IS_OVERRIDE_LIBRARY_REAL(ob_iter) && !ID_IS_LINKED(ob_iter)) {
2388 ob_iter->id.override_library->flag &= ~LIBOVERRIDE_FLAG_SYSTEM_DEFINED;
2389 is_active_override = is_active_override || (&ob_iter->id == id_root);
2391 }
2392 }
2394 /* If the active object is a liboverride, there is no point going further, since in the weird
2395 * case where some other selected objects would be linked ones, there is no way to properly
2396 * create overrides for them currently.
2397 *
2398 * Could be added later if really needed, but would rather avoid that extra complexity here. */
2399 if (is_active_override) {
2400 return OPERATOR_FINISHED;
2401 }
2402
2404 const bool do_fully_editable = false;
2405
2406 GSet *user_overrides_objects_uids = do_fully_editable ? nullptr :
2409 __func__);
2410
2411 if (do_fully_editable) {
2412 /* Pass. */
2413 }
2414 else if (user_overrides_from_selected_objects) {
2415 /* Only selected objects can be 'user overrides'. */
2416 FOREACH_SELECTED_OBJECT_BEGIN (view_layer, CTX_wm_view3d(C), ob_iter) {
2417 BLI_gset_add(user_overrides_objects_uids, POINTER_FROM_UINT(ob_iter->id.session_uid));
2418 }
2420 }
2421 else {
2422 /* Only armatures inside the root collection (and their children) can be 'user overrides'. */
2424 if (ob_iter->type == OB_ARMATURE) {
2425 BLI_gset_add(user_overrides_objects_uids, POINTER_FROM_UINT(ob_iter->id.session_uid));
2426 }
2427 }
2429 }
2430
2431 BKE_main_id_tag_all(bmain, ID_TAG_DOIT, false);
2432
2433 /* For the time being, replace selected linked objects by their overrides in all collections.
2434 * While this may not be the absolute best behavior in all cases, in most common one this
2435 * should match the expected result. */
2436 if (user_overrides_objects_uids != nullptr) {
2437 LISTBASE_FOREACH (Collection *, coll_iter, &bmain->collections) {
2438 if (ID_IS_LINKED(coll_iter)) {
2439 continue;
2440 }
2441 LISTBASE_FOREACH (CollectionObject *, coll_ob_iter, &coll_iter->gobject) {
2442 if (BLI_gset_haskey(user_overrides_objects_uids,
2443 POINTER_FROM_UINT(coll_ob_iter->ob->id.session_uid)))
2444 {
2445 /* Tag for remapping when creating overrides. */
2446 coll_iter->id.tag |= ID_TAG_DOIT;
2447 break;
2448 }
2449 }
2450 }
2451 /* Also tag the Scene itself for remapping when creating overrides (includes the scene's master
2452 * collection too). */
2453 scene->id.tag |= ID_TAG_DOIT;
2454 }
2455
2456 ID *id_root_override;
2457 const bool success = BKE_lib_override_library_create(bmain,
2458 scene,
2459 view_layer,
2460 nullptr,
2461 id_root,
2462 id_root,
2463 &obact->id,
2464 &id_root_override,
2465 do_fully_editable);
2466
2467 if (!do_fully_editable) {
2468 /* Define liboverrides from selected/validated objects as user defined. */
2469 ID *id_hierarchy_root_override = id_root_override->override_library->hierarchy_root;
2470 ID *id_iter;
2471 FOREACH_MAIN_ID_BEGIN (bmain, id_iter) {
2472 if (ID_IS_LINKED(id_iter) || !ID_IS_OVERRIDE_LIBRARY_REAL(id_iter) ||
2473 id_iter->override_library->hierarchy_root != id_hierarchy_root_override)
2474 {
2475 continue;
2476 }
2477 if (BLI_gset_haskey(user_overrides_objects_uids,
2479 {
2480 id_iter->override_library->flag &= ~LIBOVERRIDE_FLAG_SYSTEM_DEFINED;
2481 }
2482 }
2484
2485 BLI_gset_free(user_overrides_objects_uids, nullptr);
2486 }
2487
2488 if (success) {
2489 if (is_override_instancing_object) {
2490 /* Remove the instance empty from this scene, the items now have an overridden collection
2491 * instead. */
2492 base_free_and_unlink(bmain, scene, obact);
2493 }
2494 else {
2495 /* Remove the found root ID from the view layer. */
2496 switch (GS(id_root->name)) {
2497 case ID_GR: {
2498 Collection *collection_root = (Collection *)id_root;
2500 CollectionParent *, collection_parent, &collection_root->runtime.parents)
2501 {
2502 if (ID_IS_LINKED(collection_parent->collection) ||
2503 !BKE_view_layer_has_collection(view_layer, collection_parent->collection))
2504 {
2505 continue;
2506 }
2507 BKE_collection_child_remove(bmain, collection_parent->collection, collection_root);
2508 }
2509 break;
2510 }
2511 case ID_OB: {
2512 /* TODO: Not sure how well we can handle this case, when we don't have the collections
2513 * as reference containers... */
2514 break;
2515 }
2516 default:
2517 break;
2518 }
2519 }
2520 }
2521
2523 WM_event_add_notifier(C, NC_WINDOW, nullptr);
2526
2527 return success ? OPERATOR_FINISHED : OPERATOR_CANCELLED;
2528}
2529
2530/* Set the object to override. */
2531static int make_override_library_invoke(bContext *C, wmOperator *op, const wmEvent * /*event*/)
2532{
2533 Main *bmain = CTX_data_main(C);
2534 Scene *scene = CTX_data_scene(C);
2535 ViewLayer *view_layer = CTX_data_view_layer(C);
2536 Object *obact = context_active_object(C);
2537
2538 /* Sanity checks. */
2539 if (!scene || ID_IS_LINKED(scene) || !obact) {
2540 return OPERATOR_CANCELLED;
2541 }
2542
2543 if ((!ID_IS_LINKED(obact) && obact->instance_collection != nullptr &&
2546 {
2547 return make_override_library_exec(C, op);
2548 }
2549
2550 if (!ID_IS_LINKED(obact)) {
2551 if (ID_IS_OVERRIDE_LIBRARY_REAL(obact)) {
2552 return make_override_library_exec(C, op);
2553 }
2554 BKE_report(op->reports, RPT_ERROR, "Cannot make library override from a local object");
2555 return OPERATOR_CANCELLED;
2556 }
2557
2558 VectorSet<Collection *> potential_root_collections;
2559 LISTBASE_FOREACH (Collection *, collection, &bmain->collections) {
2560 /* Only check for linked collections from the same library, in the current view-layer. */
2561 if (!ID_IS_LINKED(&collection->id) || collection->id.lib != obact->id.lib ||
2562 !BKE_view_layer_has_collection(view_layer, collection))
2563 {
2564 continue;
2565 }
2566 if (!BKE_collection_has_object_recursive(collection, obact)) {
2567 continue;
2568 }
2569 if (potential_root_collections.is_empty()) {
2570 potential_root_collections.add_new(collection);
2571 }
2572 else {
2573 bool has_parents_in_potential_roots = false;
2574 bool is_potential_root = false;
2575 for (auto collection_root_iter : potential_root_collections) {
2576 if (BKE_collection_has_collection(collection_root_iter, collection)) {
2577 BLI_assert_msg(!BKE_collection_has_collection(collection, collection_root_iter),
2578 "Invalid loop in collection hierarchy");
2579 /* Current potential root is already 'better' (higher up in the collection hierarchy)
2580 * than current collection, nothing else to do. */
2581 has_parents_in_potential_roots = true;
2582 }
2583 else if (BKE_collection_has_collection(collection, collection_root_iter)) {
2584 BLI_assert_msg(!BKE_collection_has_collection(collection_root_iter, collection),
2585 "Invalid loop in collection hierarchy");
2586 /* Current potential root is in the current collection's hierarchy, so the later is a
2587 * better candidate as root collection. */
2588 is_potential_root = true;
2589 potential_root_collections.remove(collection_root_iter);
2590 }
2591 else {
2592 /* Current potential root is not found in current collection's hierarchy, so the later
2593 * is a potential candidate as root collection. */
2594 is_potential_root = true;
2595 }
2596 }
2597 /* Only add the current collection as potential root if it is not a descendant of any
2598 * already known potential root collections. */
2599 if (is_potential_root && !has_parents_in_potential_roots) {
2600 potential_root_collections.add_new(collection);
2601 }
2602 }
2603 }
2604
2605 if (potential_root_collections.is_empty()) {
2607 return make_override_library_exec(C, op);
2608 }
2609 if (potential_root_collections.size() == 1) {
2610 Collection *collection_root = potential_root_collections.pop();
2611 RNA_property_int_set(op->ptr, op->type->prop, *((int *)&collection_root->id.session_uid));
2612 return make_override_library_exec(C, op);
2613 }
2614
2615 BKE_reportf(op->reports,
2616 RPT_ERROR,
2617 "Too many potential root collections (%d) for the override hierarchy, "
2618 "please use the Outliner instead",
2619 int(potential_root_collections.size()));
2620 return OPERATOR_CANCELLED;
2621}
2622
2624{
2625 Base *base_act = CTX_data_active_base(C);
2626 /* If the active object is not selected, do nothing (operators rely on selection too, they will
2627 * misbehave if the active object is not also selected, see e.g. #120701. */
2628 if ((base_act == nullptr) || ((base_act->flag & BASE_SELECTED) == 0)) {
2629 return false;
2630 }
2631
2632 /* Object must be directly linked to be overridable. */
2633 Object *obact = base_act->object;
2634 return (
2635 ED_operator_objectmode(C) && obact != nullptr &&
2636 (ID_IS_LINKED(obact) || ID_IS_OVERRIDE_LIBRARY(obact) ||
2637 (obact->instance_collection != nullptr &&
2639}
2640
2642{
2643 /* identifiers */
2644 ot->name = "Make Library Override";
2645 ot->description =
2646 "Create a local override of the selected linked objects, and their hierarchy of "
2647 "dependencies";
2648 ot->idname = "OBJECT_OT_make_override_library";
2649
2650 /* api callbacks */
2654
2655 /* flags */
2657
2658 /* properties */
2659 PropertyRNA *prop;
2660 prop = RNA_def_int(ot->srna,
2661 "collection",
2663 INT_MIN,
2664 INT_MAX,
2665 "Override Collection",
2666 "Session UID of the directly linked collection containing the selected "
2667 "object, to make an override from",
2668 INT_MIN,
2669 INT_MAX);
2671 ot->prop = prop;
2672}
2673
2676/* ------------------------------------------------------------------- */
2681{
2682 Base *base_act = CTX_data_active_base(C);
2683 /* If the active object is not selected, do nothing (operators rely on selection too, they will
2684 * misbehave if the active object is not also selected, see e.g. #120701. */
2685 if ((base_act == nullptr) || ((base_act->flag & BASE_SELECTED) == 0)) {
2686 return false;
2687 }
2688
2689 /* Object must be local and an override. */
2690 Object *obact = base_act->object;
2691 return (ED_operator_objectmode(C) && obact != nullptr && !ID_IS_LINKED(obact) &&
2692 ID_IS_OVERRIDE_LIBRARY(obact));
2693}
2694
2696{
2697 Main *bmain = CTX_data_main(C);
2698
2699 /* Reset all selected liboverrides. */
2701 if (ID_IS_OVERRIDE_LIBRARY_REAL(ob_iter) && !ID_IS_LINKED(ob_iter)) {
2702 BKE_lib_override_library_id_reset(bmain, &ob_iter->id, false);
2703 }
2704 }
2706
2707 WM_event_add_notifier(C, NC_WINDOW, nullptr);
2710
2711 return OPERATOR_FINISHED;
2712}
2713
2715{
2716 /* identifiers */
2717 ot->name = "Reset Library Override";
2718 ot->description = "Reset the selected local overrides to their linked references values";
2719 ot->idname = "OBJECT_OT_reset_override_library";
2720
2721 /* api callbacks */
2724
2725 /* flags */
2727}
2728
2731/* ------------------------------------------------------------------- */
2736{
2737 Main *bmain = CTX_data_main(C);
2738 ViewLayer *view_layer = CTX_data_view_layer(C);
2739 Scene *scene = CTX_data_scene(C);
2740 LinkNode *todo_objects = nullptr, *todo_object_iter;
2741
2742 /* Make already existing selected liboverrides editable. */
2743 FOREACH_SELECTED_OBJECT_BEGIN (view_layer, CTX_wm_view3d(C), ob_iter) {
2744 if (ID_IS_LINKED(ob_iter)) {
2745 continue;
2746 }
2747 BLI_linklist_prepend_alloca(&todo_objects, ob_iter);
2748 }
2750
2751 for (todo_object_iter = todo_objects; todo_object_iter != nullptr;
2752 todo_object_iter = todo_object_iter->next)
2753 {
2754 Object *ob_iter = static_cast<Object *>(todo_object_iter->link);
2755 if (BKE_lib_override_library_is_hierarchy_leaf(bmain, &ob_iter->id)) {
2756 bool do_remap_active = false;
2757 BKE_view_layer_synced_ensure(scene, view_layer);
2758 if (BKE_view_layer_active_object_get(view_layer) == ob_iter) {
2759 do_remap_active = true;
2760 }
2761 BKE_libblock_remap(bmain,
2762 &ob_iter->id,
2763 ob_iter->id.override_library->reference,
2765 if (do_remap_active) {
2766 BKE_view_layer_synced_ensure(scene, view_layer);
2767 Object *ref_object = (Object *)ob_iter->id.override_library->reference;
2768 Base *basact = BKE_view_layer_base_find(view_layer, ref_object);
2769 if (basact != nullptr) {
2770 view_layer->basact = basact;
2771 }
2773 }
2774 BKE_id_delete(bmain, &ob_iter->id);
2775 }
2776 else {
2777 BKE_lib_override_library_id_reset(bmain, &ob_iter->id, true);
2778 }
2779 }
2780
2782 WM_event_add_notifier(C, NC_WINDOW, nullptr);
2785
2786 return OPERATOR_FINISHED;
2787}
2788
2790{
2791 /* identifiers */
2792 ot->name = "Clear Library Override";
2793 ot->description =
2794 "Delete the selected local overrides and relink their usages to the linked data-blocks if "
2795 "possible, else reset them and mark them as non editable";
2796 ot->idname = "OBJECT_OT_clear_override_library";
2797
2798 /* api callbacks */
2801
2802 /* flags */
2804}
2805
2808/* ------------------------------------------------------------------- */
2812enum {
2815};
2816
2818{
2819 Main *bmain = CTX_data_main(C);
2820 Scene *scene = CTX_data_scene(C);
2821 ViewLayer *view_layer = CTX_data_view_layer(C);
2822 View3D *v3d = CTX_wm_view3d(C); /* ok if this is nullptr */
2823 const int flag = (RNA_enum_get(op->ptr, "type") == MAKE_SINGLE_USER_SELECTED) ? SELECT : 0;
2824 const bool copy_collections = false;
2825 bool update_deps = false;
2826
2827 if (RNA_boolean_get(op->ptr, "object")) {
2828 if (flag == SELECT) {
2829 BKE_view_layer_selected_objects_tag(scene, view_layer, OB_DONE);
2830 single_object_users(bmain, scene, v3d, OB_DONE, copy_collections);
2831 }
2832 else {
2833 single_object_users(bmain, scene, v3d, 0, copy_collections);
2834 }
2835
2836 /* needed since object relationships may have changed */
2837 update_deps = true;
2838 }
2839
2840 if (RNA_boolean_get(op->ptr, "obdata")) {
2841 single_obdata_users(bmain, scene, view_layer, v3d, flag);
2842
2843 /* Needed since some IDs were remapped? (incl. mesh->texcomesh, see #73797). */
2844 update_deps = true;
2845 }
2846
2847 if (RNA_boolean_get(op->ptr, "material")) {
2848 single_mat_users(bmain, scene, view_layer, v3d, flag);
2849 }
2850
2851 if (RNA_boolean_get(op->ptr, "animation")) {
2852 single_object_action_users(bmain, scene, view_layer, v3d, flag);
2853 }
2854
2855 if (RNA_boolean_get(op->ptr, "obdata_animation")) {
2856 single_objectdata_action_users(bmain, scene, view_layer, v3d, flag);
2857 }
2858
2860
2861 WM_event_add_notifier(C, NC_WINDOW, nullptr);
2862
2863 if (update_deps) {
2865 }
2866
2867 return OPERATOR_FINISHED;
2868}
2869
2870static int make_single_user_invoke(bContext *C, wmOperator *op, const wmEvent *event)
2871{
2873 C, op, event, IFACE_("Make Selected Objects Single-User"), IFACE_("Make Single"));
2874}
2875
2877{
2878 static const EnumPropertyItem type_items[] = {
2879 {MAKE_SINGLE_USER_SELECTED, "SELECTED_OBJECTS", 0, "Selected Objects", ""},
2880 {MAKE_SINGLE_USER_ALL, "ALL", 0, "All", ""},
2881 {0, nullptr, 0, nullptr, nullptr},
2882 };
2883
2884 /* identifiers */
2885 ot->name = "Make Single User";
2886 ot->description = "Make linked data local to each object";
2887 ot->idname = "OBJECT_OT_make_single_user";
2888
2889 /* Note that the invoke callback is only used from operator search, * otherwise this does
2890 * nothing by default. */
2891
2892 /* api callbacks */
2896
2897 /* flags */
2899
2900 /* properties */
2901 ot->prop = RNA_def_enum(ot->srna, "type", type_items, MAKE_SINGLE_USER_SELECTED, "Type", "");
2902
2903 RNA_def_boolean(ot->srna, "object", false, "Object", "Make single user objects");
2904 RNA_def_boolean(ot->srna, "obdata", false, "Object Data", "Make single user object data");
2906 ot->srna, "material", false, "Materials", "Make materials local to each data-block");
2908 "animation",
2909 false,
2910 "Object Animation",
2911 "Make object animation data local to each object");
2913 "obdata_animation",
2914 false,
2915 "Object Data Animation",
2916 "Make object data (mesh, curve etc.) animation data local to each object");
2917}
2918
2921/* ------------------------------------------------------------------- */
2925std::string drop_named_material_tooltip(bContext *C, const char *name, const int mval[2])
2926{
2927 int mat_slot = 0;
2928 Object *ob = ED_view3d_give_material_slot_under_cursor(C, mval, &mat_slot);
2929 if (ob == nullptr) {
2930 return {};
2931 }
2932 mat_slot = max_ii(mat_slot, 1);
2933
2934 Material *prev_mat = BKE_object_material_get(ob, mat_slot);
2935
2936 if (prev_mat) {
2937 return fmt::format(TIP_("Drop {} on {} (slot {}, replacing {})"),
2938 name,
2939 ob->id.name + 2,
2940 mat_slot,
2941 prev_mat->id.name + 2);
2942 }
2943 return fmt::format(TIP_("Drop {} on {} (slot {})"), name, ob->id.name + 2, mat_slot);
2944}
2945
2947{
2948 Main *bmain = CTX_data_main(C);
2949 int mat_slot = 0;
2950 Object *ob = ED_view3d_give_material_slot_under_cursor(C, event->mval, &mat_slot);
2951 mat_slot = max_ii(mat_slot, 1);
2952
2954 bmain, op->ptr, ID_MA);
2955
2956 if (ob == nullptr || ma == nullptr) {
2957 return OPERATOR_CANCELLED;
2958 }
2959
2961
2963
2967
2968 return OPERATOR_FINISHED;
2969}
2970
2972{
2973 /* identifiers */
2974 ot->name = "Drop Named Material on Object";
2975 ot->idname = "OBJECT_OT_drop_named_material";
2976
2977 /* api callbacks */
2980
2981 /* flags */
2983
2984 /* properties */
2986}
2987
2990/* ------------------------------------------------------------------- */
2994std::string drop_geometry_nodes_tooltip(bContext *C, PointerRNA *properties, const int mval[2])
2995{
2996 const Object *ob = ED_view3d_give_object_under_cursor(C, mval);
2997 if (ob == nullptr) {
2998 return {};
2999 }
3000
3001 const uint32_t session_uid = RNA_int_get(properties, "session_uid");
3002 const ID *id = BKE_libblock_find_session_uid(CTX_data_main(C), ID_NT, session_uid);
3003 if (!id) {
3004 return {};
3005 }
3006
3007 return fmt::format(
3008 TIP_("Add modifier with node group \"{}\" on object \"{}\""), id->name, ob->id.name);
3009}
3010
3012{
3013 tree->ensure_interface_cache();
3014 if (!tree->interface_outputs().is_empty()) {
3015 const bNodeTreeInterfaceSocket *first_output = tree->interface_outputs()[0];
3016 if (!first_output) {
3017 BKE_report(op->reports, RPT_ERROR, "The node group must have a geometry output socket");
3018 return false;
3019 }
3020 const bke::bNodeSocketType *typeinfo = first_output->socket_typeinfo();
3021 const eNodeSocketDatatype type = typeinfo ? eNodeSocketDatatype(typeinfo->type) : SOCK_CUSTOM;
3022 if (type != SOCK_GEOMETRY) {
3023 BKE_report(op->reports, RPT_ERROR, "The first output must be a geometry socket");
3024 return false;
3025 }
3026 }
3027 return true;
3028}
3029
3031{
3033 if (!ob) {
3034 return OPERATOR_CANCELLED;
3035 }
3036
3037 Main *bmain = CTX_data_main(C);
3038 Scene *scene = CTX_data_scene(C);
3039
3040 const uint32_t uid = RNA_int_get(op->ptr, "session_uid");
3042 if (!node_tree) {
3043 return OPERATOR_CANCELLED;
3044 }
3045 if (node_tree->type != NTREE_GEOMETRY) {
3046 BKE_report(op->reports, RPT_ERROR, "Node group must be a geometry node tree");
3047 return OPERATOR_CANCELLED;
3048 }
3049
3051 return OPERATOR_CANCELLED;
3052 }
3053
3055 op->reports, bmain, scene, ob, node_tree->id.name + 2, eModifierType_Nodes);
3056 if (!nmd) {
3057 BKE_report(op->reports, RPT_ERROR, "Could not add geometry nodes modifier");
3058 return OPERATOR_CANCELLED;
3059 }
3060
3061 if (!RNA_boolean_get(op->ptr, "show_datablock_in_modifier")) {
3063 }
3064
3065 nmd->node_group = node_tree;
3066 id_us_plus(&node_tree->id);
3068
3071
3072 return OPERATOR_FINISHED;
3073}
3074
3076{
3077 ot->name = "Drop Geometry Node Group on Object";
3078 ot->idname = "OBJECT_OT_drop_geometry_nodes";
3079
3082
3084
3085 PropertyRNA *prop = RNA_def_int(ot->srna,
3086 "session_uid",
3087 0,
3088 INT32_MIN,
3089 INT32_MAX,
3090 "Session UID",
3091 "Session UID of the geometry node group being dropped",
3092 INT32_MIN,
3093 INT32_MAX);
3096 "show_datablock_in_modifier",
3097 true,
3098 "Show the datablock selector in the modifier",
3099 "");
3100}
3101
3104/* ------------------------------------------------------------------- */
3109{
3110 ID *id;
3111 PropertyPointerRNA pprop;
3112
3114
3115 if (pprop.prop == nullptr) {
3116 BKE_report(op->reports, RPT_ERROR, "Incorrect context for running object data unlink");
3117 return OPERATOR_CANCELLED;
3118 }
3119
3120 id = pprop.ptr.owner_id;
3121
3122 if (GS(id->name) == ID_OB) {
3123 Object *ob = (Object *)id;
3124 if (ob->data) {
3125 ID *id_data = static_cast<ID *>(ob->data);
3126
3127 if (GS(id_data->name) == ID_IM) {
3128 id_us_min(id_data);
3129 ob->data = nullptr;
3130 }
3131 else {
3132 BKE_report(op->reports, RPT_ERROR, "Can't unlink this object data");
3133 return OPERATOR_CANCELLED;
3134 }
3135 }
3136 }
3137
3138 RNA_property_update(C, &pprop.ptr, pprop.prop);
3139
3140 return OPERATOR_FINISHED;
3141}
3142
3144{
3145 /* identifiers */
3146 ot->name = "Unlink";
3147 ot->idname = "OBJECT_OT_unlink_data";
3148
3149 /* api callbacks */
3151
3152 /* flags */
3154}
3155
3158} // namespace blender::ed::object
Functions and classes to work with Actions.
Functions to work with AnimData.
Blender kernel action and pose functionality.
bPoseChannel * BKE_pose_channel_active_if_bonecoll_visible(Object *ob) ATTR_WARN_UNUSED_RESULT
bool BKE_animdata_copy_id(Main *bmain, ID *id_to, ID *id_from, int flag)
Definition anim_data.cc:452
AnimData * BKE_animdata_from_id(const ID *id)
Definition anim_data.cc:89
void BKE_animdata_duplicate_id_action(Main *bmain, ID *id, uint duplicate_flags)
Definition anim_data.cc:521
void BKE_pose_rebuild(Main *bmain, Object *ob, bArmature *arm, bool do_id_user)
Definition armature.cc:2767
bool BKE_collection_has_object_recursive(Collection *collection, Object *ob)
#define FOREACH_COLLECTION_OBJECT_RECURSIVE_END
#define FOREACH_SCENE_OBJECT_END
bool BKE_collection_child_remove(Main *bmain, Collection *parent, Collection *child)
bool BKE_collection_has_object(Collection *collection, const Object *ob)
void BKE_scene_objects_iterator_end(BLI_Iterator *iter)
bool BKE_collection_child_add_no_sync(Main *bmain, Collection *parent, Collection *child)
#define FOREACH_COLLECTION_OBJECT_RECURSIVE_BEGIN(_collection, _object)
#define FOREACH_SCENE_OBJECT_BEGIN(scene, _instance)
bool BKE_collection_has_collection(const Collection *parent, const Collection *collection)
bool BKE_collection_object_add(Main *bmain, Collection *collection, Object *ob)
bool BKE_constraint_remove(ListBase *list, struct bConstraint *con)
struct bConstraint * BKE_constraint_add_for_object(struct Object *ob, const char *name, short type)
void BKE_constraint_target_matrix_get(struct Depsgraph *depsgraph, struct Scene *scene, struct bConstraint *con, int index, short ownertype, void *ownerdata, float mat[4][4], float ctime)
#define CTX_DATA_BEGIN(C, Type, instance, member)
Depsgraph * CTX_data_ensure_evaluated_depsgraph(const bContext *C)
Object * CTX_data_active_object(const bContext *C)
Scene * CTX_data_scene(const bContext *C)
Object * CTX_data_edit_object(const bContext *C)
Base * CTX_data_active_base(const bContext *C)
Main * CTX_data_main(const bContext *C)
Collection * CTX_data_collection(const bContext *C)
#define CTX_DATA_END
View3D * CTX_wm_view3d(const bContext *C)
ViewLayer * CTX_data_view_layer(const bContext *C)
display list (or rather multi purpose list) stuff.
void BKE_displist_make_curveTypes(struct Depsgraph *depsgraph, const struct Scene *scene, struct Object *ob, bool for_render)
void BKE_editmesh_looptris_and_normals_calc(BMEditMesh *em)
Definition editmesh.cc:83
FModifier * add_fmodifier(ListBase *modifiers, int type, FCurve *owner_fcu)
bool BKE_view_layer_has_collection(const ViewLayer *view_layer, const Collection *collection)
void BKE_view_layer_selected_objects_tag(const Scene *scene, ViewLayer *view_layer, int tag)
void BKE_view_layer_synced_ensure(const Scene *scene, ViewLayer *view_layer)
#define FOREACH_OBJECT_FLAG_END
Definition BKE_layer.hh:477
#define FOREACH_SELECTED_OBJECT_BEGIN(_view_layer, _v3d, _instance)
Definition BKE_layer.hh:298
void BKE_view_layer_base_deselect_all(const Scene *scene, ViewLayer *view_layer)
void BKE_main_collection_sync_remap(const Main *bmain)
Object * BKE_view_layer_active_object_get(const ViewLayer *view_layer)
Base * BKE_view_layer_base_find(ViewLayer *view_layer, Object *ob)
#define FOREACH_OBJECT_FLAG_BEGIN(_scene, _view_layer, _v3d, _flag, _instance)
Definition BKE_layer.hh:437
#define FOREACH_SELECTED_OBJECT_END
Definition BKE_layer.hh:310
ID * BKE_libblock_find_session_uid(Main *bmain, short type, uint32_t session_uid)
Definition lib_id.cc:1675
void BKE_id_delete(Main *bmain, void *idv) ATTR_NONNULL()
bool BKE_id_is_editable(const Main *bmain, const ID *id)
Definition lib_id.cc:2456
@ LIB_ID_COPY_ACTIONS
@ LIB_ID_COPY_DEFAULT
void id_us_plus(ID *id)
Definition lib_id.cc:351
#define MAIN_ID_SESSION_UID_UNSET
void BKE_library_make_local(Main *bmain, const Library *lib, GHash *old_to_new_ids, bool untagged_only, bool set_fake, bool clear_asset_data)
Definition lib_id.cc:2075
void BKE_main_id_newptr_and_tag_clear(Main *bmain)
Definition lib_id.cc:1947
ID * BKE_id_copy_ex(Main *bmain, const ID *id, ID **new_id_p, int flag)
Definition lib_id.cc:760
void id_us_min(ID *id)
Definition lib_id.cc:359
void BKE_main_id_tag_all(Main *mainvar, int tag, bool value)
Definition lib_id.cc:1198
void BKE_lib_override_library_id_reset(Main *bmain, ID *id_root, bool do_reset_system_override)
bool BKE_lib_override_library_create(Main *bmain, Scene *scene, ViewLayer *view_layer, Library *owner_library, ID *id_root_reference, ID *id_hierarchy_root_reference, ID *id_instance_hint, ID **r_id_root_override, const bool do_fully_editable)
bool BKE_lib_override_library_is_hierarchy_leaf(Main *bmain, ID *id)
@ IDWALK_RET_NOP
void BKE_library_foreach_ID_link(Main *bmain, ID *id, blender::FunctionRef< LibraryIDLinkCallback > callback, void *user_data, int flag)
Definition lib_query.cc:416
@ IDWALK_READONLY
@ ID_REMAP_SKIP_INDIRECT_USAGE
void BKE_libblock_relink_to_newid(Main *bmain, ID *id, int remap_flag) ATTR_NONNULL()
Definition lib_remap.cc:921
void void BKE_libblock_remap(Main *bmain, void *old_idv, void *new_idv, int remap_flags) ATTR_NONNULL(1
#define FOREACH_MAIN_ID_END
Definition BKE_main.hh:500
#define FOREACH_MAIN_ID_BEGIN(_bmain, _id)
Definition BKE_main.hh:494
General operations, lookup, etc. for materials.
struct Material * BKE_object_material_get(struct Object *ob, short act)
void BKE_object_materials_test(struct Main *bmain, struct Object *ob, struct ID *id)
void BKE_object_material_assign(struct Main *bmain, struct Object *ob, struct Material *ma, short act, int assign_type)
struct Material *** BKE_object_material_array_p(struct Object *ob)
@ BKE_MAT_ASSIGN_USERPREF
Object * BKE_modifiers_is_deformed_by_curve(Object *ob)
Object * BKE_modifiers_is_deformed_by_lattice(Object *ob)
void BKE_modifier_free(ModifierData *md)
void BKE_modifier_remove_from_list(Object *ob, ModifierData *md)
Object * BKE_modifiers_is_deformed_by_armature(Object *ob)
General operations, lookup, etc. for blender objects.
blender::float4x4 BKE_object_calc_parent(Depsgraph *depsgraph, Scene *scene, Object *ob)
KDTree_3d * BKE_object_as_kdtree(Object *ob, int *r_tot)
void BKE_object_groups_clear(Main *bmain, Scene *scene, Object *object)
void BKE_object_apply_mat4(Object *ob, const float mat[4][4], bool use_compat, bool use_parent)
int BKE_object_scenes_users_get(Main *bmain, Object *ob)
bool BKE_object_parent_loop_check(const Object *parent, const Object *ob)
void BKE_object_link_modifiers(Object *ob_dst, const Object *ob_src)
void BKE_object_apply_parent_inverse(Object *ob)
LinkNode * BKE_object_groups(Main *bmain, Scene *scene, Object *ob)
void BKE_reportf(ReportList *reports, eReportType type, const char *format,...) ATTR_PRINTF_FORMAT(3
void BKE_report(ReportList *reports, eReportType type, const char *message)
Definition report.cc:125
void BKE_scene_graph_update_tagged(Depsgraph *depsgraph, Main *bmain)
Definition scene.cc:2568
#define BLI_assert(a)
Definition BLI_assert.h:50
#define BLI_assert_msg(a, msg)
Definition BLI_assert.h:57
struct GSet GSet
Definition BLI_ghash.h:341
bool BLI_gset_haskey(const GSet *gs, const void *key) ATTR_WARN_UNUSED_RESULT
Definition BLI_ghash.c:1004
GSet * BLI_gset_new(GSetHashFP hashfp, GSetCmpFP cmpfp, const char *info) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT
Definition BLI_ghash.c:944
bool BLI_ghashutil_intcmp(const void *a, const void *b)
unsigned int BLI_ghashutil_inthash_p(const void *ptr)
void BLI_gset_free(GSet *gs, GSetKeyFreeFP keyfreefp)
Definition BLI_ghash.c:1034
bool BLI_gset_add(GSet *gs, void *key)
Definition BLI_ghash.c:966
A KD-tree for nearest neighbor search.
void BLI_kdtree_nd_ free(KDTree *tree)
void BLI_addhead(struct ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:90
#define LISTBASE_FOREACH(type, var, list)
#define LISTBASE_FOREACH_MUTABLE(type, var, list)
void * BLI_findlink(const struct ListBase *listbase, int number) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
void BLI_remlink(struct ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:130
void * BLI_listbase_bytes_find(const ListBase *listbase, const void *bytes, size_t bytes_size, int offset) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1
MINLINE int max_ii(int a, int b)
MINLINE int min_iii(int a, int b, int c)
void unit_m4(float m[4][4])
Definition rct.c:1127
bool invert_m4_m4(float inverse[4][4], const float mat[4][4])
MINLINE void sub_v3_v3v3(float r[3], const float a[3], const float b[3])
MINLINE void copy_v3_v3(float r[3], const float a[3])
MINLINE void copy_v3_v3_int(int r[3], const int a[3])
#define STRNCPY(dst, src)
Definition BLI_string.h:593
unsigned short ushort
unsigned int uint
#define UNUSED_VARS(...)
#define UNPACK3(a)
#define ELEM(...)
#define POINTER_FROM_UINT(i)
#define STREQ(a, b)
#define TIP_(msgid)
#define IFACE_(msgid)
void DEG_id_tag_update(ID *id, unsigned int flags)
void DEG_relations_tag_update(Main *bmain)
Object * DEG_get_evaluated_object(const Depsgraph *depsgraph, Object *object)
#define ID_NEW_REMAP(a)
Definition DNA_ID.h:711
@ ID_RECALC_TRANSFORM
Definition DNA_ID.h:1021
@ ID_RECALC_SELECT
Definition DNA_ID.h:1068
@ ID_RECALC_HIERARCHY
Definition DNA_ID.h:1125
@ ID_RECALC_SYNC_TO_EVAL
Definition DNA_ID.h:1085
@ ID_RECALC_ANIMATION
Definition DNA_ID.h:1044
@ ID_RECALC_GEOMETRY
Definition DNA_ID.h:1041
@ ID_RECALC_BASE_FLAGS
Definition DNA_ID.h:1071
#define ID_IS_OVERRIDE_LIBRARY_REAL(_id)
Definition DNA_ID.h:676
#define ID_IS_OVERRIDABLE_LIBRARY(_id)
Definition DNA_ID.h:669
#define ID_IS_LINKED(_id)
Definition DNA_ID.h:654
@ ID_TAG_PRE_EXISTING
Definition DNA_ID.h:872
@ ID_TAG_DOIT
Definition DNA_ID.h:1003
#define ID_IS_OVERRIDE_LIBRARY(_id)
Definition DNA_ID.h:683
#define ID_NEW_SET(_id, _idn)
Definition DNA_ID.h:707
@ ID_IM
@ ID_NT
@ ID_MA
@ ID_GR
@ ID_OB
@ FMODIFIER_TYPE_GENERATOR
@ BONE_RELATIVE_PARENTING
Object groups, one object can be in many groups at once.
@ CONSTRAINT_TYPE_TRACKTO
@ CONSTRAINT_TYPE_LOCKTRACK
@ CONSTRAINT_TYPE_FOLLOWPATH
@ CONSTRAINT_TYPE_DAMPTRACK
@ CONSTRAINT_OBTYPE_OBJECT
#define BEZT_ISSEL_ANY_HIDDENHANDLES(v3d, bezt)
@ CU_BEZIER
@ CU_FOLLOW
@ CU_PATH
@ NODES_MODIFIER_HIDE_DATABLOCK_SELECTOR
@ eModifierType_Curve
@ eModifierType_Lattice
@ eModifierType_GreasePencilArmature
@ eModifierType_Armature
@ eModifierType_Nodes
@ NTREE_GEOMETRY
eNodeSocketDatatype
@ SOCK_CUSTOM
@ SOCK_GEOMETRY
Object is a sort of wrapper for general info.
@ OB_DONE
@ PARVERT1
@ PARSKEL
@ PAROBJECT
@ PARTYPE
@ PARVERT3
@ PARBONE
#define OB_TYPE_SUPPORT_PARVERT(_type)
@ OB_SPEAKER
@ OB_LATTICE
@ OB_MBALL
@ OB_EMPTY
@ OB_SURF
@ OB_CAMERA
@ OB_FONT
@ OB_GREASE_PENCIL
@ OB_ARMATURE
@ OB_LAMP
@ OB_MESH
@ OB_POINTCLOUD
@ OB_VOLUME
@ OB_CURVES_LEGACY
@ OB_GPENCIL_LEGACY
@ OB_CURVES
@ OB_LIGHTPROBE
@ OB_DUPLICOLLECTION
#define OB_TYPE_SUPPORT_MATERIAL(_type)
#define BASE_SELECTED(v3d, base)
@ USER_DUP_LINKED_ID
@ USER_DUP_ACT
@ RPT_ERROR_INVALID_INPUT
#define ARM_GROUPS_ENVELOPE
#define ARM_GROUPS_NAME
#define ARM_GROUPS_AUTO
void EDBM_mesh_make(Object *ob, int select_mode, bool add_key_index)
void EDBM_mesh_load(Main *bmain, Object *ob)
bool ED_operator_object_active(bContext *C)
bool ED_operator_editsurfcurve(bContext *C)
bool ED_operator_objectmode(bContext *C)
bool ED_operator_objectmode_with_view3d_poll_msg(bContext *C)
bool ED_operator_view3d_active(bContext *C)
bool ED_operator_object_active_editable(bContext *C)
bool ED_operator_editlattice(bContext *C)
bool ED_operator_editmesh(bContext *C)
Object * ED_view3d_give_material_slot_under_cursor(bContext *C, const int mval[2], int *r_material_slot)
Object * ED_view3d_give_object_under_cursor(bContext *C, const int mval[2])
Read Guarded memory(de)allocation.
void MOD_nodes_update_interface(Object *object, NodesModifierData *nmd)
Definition MOD_nodes.cc:453
const EnumPropertyItem * RNA_scene_local_itemf(bContext *C, PointerRNA *ptr, PropertyRNA *prop, bool *r_free)
#define RNA_ENUM_ITEM_SEPR
Definition RNA_types.hh:528
PropertyFlag
Definition RNA_types.hh:201
@ PROP_ENUM_NO_TRANSLATE
Definition RNA_types.hh:321
@ PROP_SKIP_SAVE
Definition RNA_types.hh:245
@ PROP_HIDDEN
Definition RNA_types.hh:239
void uiItemBooleanO(uiLayout *layout, const char *name, int icon, const char *opname, const char *propname, int value)
void UI_popup_menu_end(bContext *C, uiPopupMenu *pup)
void uiItemFullO_ptr(uiLayout *layout, wmOperatorType *ot, const char *name, int icon, IDProperty *properties, wmOperatorCallContext context, eUI_Item_Flag flag, PointerRNA *r_opptr)
#define UI_ITEM_NONE
uiPopupMenu * UI_popup_menu_begin(bContext *C, const char *title, int icon) ATTR_NONNULL()
uiLayout * UI_popup_menu_layout(uiPopupMenu *pup)
void uiItemO(uiLayout *layout, const char *name, int icon, const char *opname)
void UI_context_active_but_prop_get_templateID(const bContext *C, PointerRNA *r_ptr, PropertyRNA **r_prop)
void uiItemEnumO_ptr(uiLayout *layout, wmOperatorType *ot, const char *name, int icon, const char *propname, int value)
@ OPTYPE_INTERNAL
Definition WM_types.hh:182
@ OPTYPE_UNDO
Definition WM_types.hh:162
@ OPTYPE_REGISTER
Definition WM_types.hh:160
#define NC_WINDOW
Definition WM_types.hh:342
#define ND_NLA_ACTCHANGE
Definition WM_types.hh:465
#define ND_DRAW
Definition WM_types.hh:428
#define NC_WM
Definition WM_types.hh:341
#define NC_ANIMATION
Definition WM_types.hh:355
#define ND_LIB_OVERRIDE_CHANGED
Definition WM_types.hh:386
#define ND_MODIFIER
Definition WM_types.hh:429
#define ND_PARENT
Definition WM_types.hh:434
#define NC_MATERIAL
Definition WM_types.hh:347
#define ND_TRANSFORM
Definition WM_types.hh:423
@ WM_OP_EXEC_DEFAULT
Definition WM_types.hh:225
#define ND_OB_SHADING
Definition WM_types.hh:424
#define ND_SPACE_VIEW3D
Definition WM_types.hh:494
#define NC_OBJECT
Definition WM_types.hh:346
#define ND_SHADING_LINKS
Definition WM_types.hh:446
#define NC_SPACE
Definition WM_types.hh:359
void ED_object_vgroup_calc_from_armature(ReportList *reports, Depsgraph *depsgraph, Scene *scene, Object *ob, Object *par, const int mode, const bool mirror)
@ BM_ELEM_SELECT
#define BM_elem_flag_test(ele, hflag)
#define BM_ITER_MESH_INDEX(ele, iter, bm, itype, indexvar)
@ BM_VERTS_OF_MESH
void add_new(const Key &key)
int64_t size() const
bool remove(const Key &key)
#define printf
#define SELECT
const Depsgraph * depsgraph
#define offsetof(t, d)
ListBase * object_editcurve_get(Object *ob)
Definition editcurve.cc:88
KDTree_3d * tree
#define GS(x)
Definition iris.cc:202
void *(* MEM_mallocN)(size_t len, const char *str)
Definition mallocn.cc:44
void MEM_freeN(void *vmemh)
Definition mallocn.cc:105
#define G(x, y, z)
#define INDEX_UNSET
bAction * id_action_ensure(Main *bmain, ID *id)
Definition animdata.cc:195
FCurve * action_fcurve_ensure(Main *bmain, bAction *act, const char group[], PointerRNA *ptr, FCurveDescriptor fcurve_descriptor)
void add_armature_automatic_weights(Scene &scene, Object &object, const Object &ob_armature)
void add_armature_envelope_weights(Scene &scene, Object &object, const Object &ob_armature)
bool add_armature_vertex_groups(Object &object, const Object &ob_armature)
ModifierData * modifier_add(ReportList *reports, Main *bmain, Scene *scene, Object *ob, const char *name, int type)
static int vertex_parent_set_exec(bContext *C, wmOperator *op)
void single_obdata_user_make(Main *bmain, Scene *scene, Object *ob)
static int reset_override_library_exec(bContext *C, wmOperator *)
static bool make_override_library_object_overridable_check(Main *bmain, Object *object)
static int object_unlink_data_exec(bContext *C, wmOperator *op)
void OBJECT_OT_make_local(wmOperatorType *ot)
void OBJECT_OT_clear_override_library(wmOperatorType *ot)
const EnumPropertyItem prop_clear_parent_types[]
static const EnumPropertyItem prop_clear_track_types[]
static bool parent_set_vertex_parent_with_kdtree(bContext *C, ParentingContext *parenting_context, KDTree_3d *tree)
void OBJECT_OT_unlink_data(wmOperatorType *ot)
static bool check_geometry_node_group_sockets(wmOperator *op, const bNodeTree *tree)
static void single_mat_users(Main *bmain, Scene *scene, ViewLayer *view_layer, View3D *v3d, const int flag)
static bool parent_set_vertex_parent(bContext *C, ParentingContext *parenting_context)
static void make_local_animdata_tag_strips(ListBase *strips)
static int make_override_library_exec(bContext *C, wmOperator *op)
std::string drop_named_material_tooltip(bContext *C, const char *name, const int mval[2])
static int drop_geometry_nodes_invoke(bContext *C, wmOperator *op, const wmEvent *event)
void OBJECT_OT_make_links_scene(wmOperatorType *ot)
std::string drop_geometry_nodes_tooltip(bContext *C, PointerRNA *properties, const int mval[2])
void OBJECT_OT_track_clear(wmOperatorType *ot)
static int make_single_user_exec(bContext *C, wmOperator *op)
static void single_obdata_users(Main *bmain, Scene *scene, ViewLayer *view_layer, View3D *v3d, const int flag)
void OBJECT_OT_drop_named_material(wmOperatorType *ot)
const EnumPropertyItem prop_make_parent_types[]
static int parent_noinv_set_exec(bContext *C, wmOperator *op)
void base_select(Base *base, eObjectSelect_Mode mode)
void parent_clear(Object *ob, int type)
void OBJECT_OT_parent_no_inverse_set(wmOperatorType *ot)
static void object_remove_parent_deform_modifiers(Object *ob, const Object *par)
static int make_local_exec(bContext *C, wmOperator *op)
static int parent_clear_exec(bContext *C, wmOperator *op)
static bool single_data_needs_duplication(ID *id)
static void parent_set_vert_find(KDTree_3d *tree, Object *child, int vert_par[3], bool is_tri)
void OBJECT_OT_track_set(wmOperatorType *ot)
static int make_single_user_invoke(bContext *C, wmOperator *op, const wmEvent *event)
static const EnumPropertyItem prop_make_track_types[]
void OBJECT_OT_vertex_parent_set(wmOperatorType *ot)
static void single_objectdata_action_users(Main *bmain, Scene *scene, ViewLayer *view_layer, View3D *v3d, const int flag)
bool parent_set(ReportList *reports, const bContext *C, Scene *scene, Object *const ob, Object *const par, int partype, bool xmirror, bool keep_transform, const int vert_par[3])
Object * context_active_object(const bContext *C)
static int parent_set_exec(bContext *C, wmOperator *op)
static int clear_override_library_exec(bContext *C, wmOperator *)
void OBJECT_OT_make_links_data(wmOperatorType *ot)
static bool allow_make_links_data(const int type, Object *ob_src, Object *ob_dst)
static int make_override_library_invoke(bContext *C, wmOperator *op, const wmEvent *)
static int parent_set_invoke(bContext *C, wmOperator *op, const wmEvent *)
static bool reset_clear_override_library_poll(bContext *C)
static bool make_override_library_poll(bContext *C)
static int drop_named_material_invoke(bContext *C, wmOperator *op, const wmEvent *event)
void OBJECT_OT_reset_override_library(wmOperatorType *ot)
void OBJECT_OT_parent_clear(wmOperatorType *ot)
static void make_local_animdata_tag(AnimData *adt)
void base_free_and_unlink(Main *bmain, Scene *scene, Object *ob)
void OBJECT_OT_make_override_library(wmOperatorType *ot)
static bool parent_set_nonvertex_parent(bContext *C, ParentingContext *parenting_context)
void OBJECT_OT_drop_geometry_nodes(wmOperatorType *ot)
static void single_object_users(Main *bmain, Scene *scene, View3D *v3d, const int flag, const bool copy_collections)
void OBJECT_OT_make_single_user(wmOperatorType *ot)
static bool vertex_parent_set_poll(bContext *C)
static void make_local_material_tag(Material *ma)
static void libblock_relink_collection(Main *bmain, Collection *collection, const bool do_collection)
static int track_set_exec(bContext *C, wmOperator *op)
static void tag_localizable_objects(bContext *C, const int mode)
static bool parent_set_poll_property(const bContext *, wmOperator *op, const PropertyRNA *prop)
static int object_track_clear_exec(bContext *C, wmOperator *op)
void OBJECT_OT_parent_set(wmOperatorType *ot)
static int make_links_data_exec(bContext *C, wmOperator *op)
static int tag_localizable_looper(LibraryIDLinkCallbackData *cb_data)
static bool make_local_all__instance_indirect_unused(Main *bmain, const Scene *scene, ViewLayer *view_layer, Collection *collection)
void object_single_user_make(Main *bmain, Scene *scene, Object *ob)
static void single_object_action_users(Main *bmain, Scene *scene, ViewLayer *view_layer, View3D *v3d, const int flag)
static int parent_set_invoke_menu(bContext *C, wmOperatorType *ot)
static Collection * single_object_users_collection(Main *bmain, Scene *scene, Collection *collection, const int flag, const bool copy_collections, const bool is_master_collection)
static int make_links_scene_exec(bContext *C, wmOperator *op)
void shaderfx_link(Object *dst, Object *src)
void RNA_property_int_set(PointerRNA *ptr, PropertyRNA *prop, int value)
void RNA_boolean_set(PointerRNA *ptr, const char *name, bool value)
bool RNA_property_is_set(PointerRNA *ptr, PropertyRNA *prop)
void RNA_property_update(bContext *C, PointerRNA *ptr, PropertyRNA *prop)
int RNA_property_int_get(PointerRNA *ptr, PropertyRNA *prop)
int RNA_int_get(PointerRNA *ptr, const char *name)
bool RNA_boolean_get(PointerRNA *ptr, const char *name)
void RNA_enum_set(PointerRNA *ptr, const char *name, int value)
int RNA_enum_get(PointerRNA *ptr, const char *name)
const char * RNA_property_identifier(const PropertyRNA *prop)
PointerRNA RNA_id_pointer_create(ID *id)
PropertyRNA * RNA_def_enum(StructOrFunctionRNA *cont_, const char *identifier, const EnumPropertyItem *items, const int default_value, const char *ui_name, const char *ui_description)
PropertyRNA * RNA_def_boolean(StructOrFunctionRNA *cont_, const char *identifier, const bool default_value, const char *ui_name, const char *ui_description)
void RNA_def_property_flag(PropertyRNA *prop, PropertyFlag flag)
void RNA_def_enum_funcs(PropertyRNA *prop, EnumPropertyItemFunc itemfunc)
PropertyRNA * RNA_def_int(StructOrFunctionRNA *cont_, const char *identifier, const int default_value, const int hardmin, const int hardmax, const char *ui_name, const char *ui_description, const int softmin, const int softmax)
const EnumPropertyItem rna_enum_dummy_NULL_items[]
Definition rna_rna.cc:29
#define INT32_MAX
Definition stdint.h:137
unsigned int uint32_t
Definition stdint.h:80
#define INT32_MIN
Definition stdint.h:136
bAction * action
bAction * tmpact
ListBase nla_tracks
uint8_t f1
struct Base * next
short flag
struct Object * object
struct Object * focus_object
struct CameraDOFSettings dof
struct Collection * collection
struct CollectionChild * next
Collection_Runtime runtime
struct Object * object
struct Object * bevobj
struct VFont * vfont
struct VFont * vfontb
struct VFont * vfonti
struct VFont * vfontbi
struct Object * taperobj
struct Lattice * latt
FPoint * fpt
BezTriple * bezt
ListBase modifiers
unsigned int flag
Definition DNA_ID.h:352
struct ID * hierarchy_root
Definition DNA_ID.h:343
struct ID * reference
Definition DNA_ID.h:333
Definition DNA_ID.h:413
int tag
Definition DNA_ID.h:434
struct Library * lib
Definition DNA_ID.h:419
int us
Definition DNA_ID.h:435
struct ID * newid
Definition DNA_ID.h:417
IDOverrideLibrary * override_library
Definition DNA_ID.h:459
void * next
Definition DNA_ID.h:416
char name[66]
Definition DNA_ID.h:425
unsigned int session_uid
Definition DNA_ID.h:454
struct EditLatt * editlatt
struct BPoint * def
void * link
struct LinkNode * next
void * first
ListBase scenes
Definition BKE_main.hh:210
ListBase meshes
Definition BKE_main.hh:213
ListBase collections
Definition BKE_main.hh:231
ListBase objects
Definition BKE_main.hh:212
uint16_t flag
struct ModifierData * next
struct bNodeTree * node_group
struct Collection * instance_collection
ObjectRuntimeHandle * runtime
ListBase modifiers
float loc[3]
float parentinv[4][4]
struct Object * parent
char parsubstr[64]
ID * owner_id
Definition RNA_types.hh:40
PropertyRNA * prop
Definition RNA_types.hh:49
struct Collection * master_collection
struct Object * camera
struct Base * basact
struct bConstraint * prev
struct Bone * bone
Defines a socket type.
Definition BKE_node.hh:151
int mval[2]
Definition WM_types.hh:728
const char * name
Definition WM_types.hh:990
bool(* poll_property)(const bContext *C, wmOperator *op, const PropertyRNA *prop) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1048
bool(* poll)(bContext *C) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1042
const char * idname
Definition WM_types.hh:992
int(* invoke)(bContext *C, wmOperator *op, const wmEvent *event) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1022
int(* exec)(bContext *C, wmOperator *op) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1006
const char * description
Definition WM_types.hh:996
PropertyRNA * prop
Definition WM_types.hh:1092
StructRNA * srna
Definition WM_types.hh:1080
struct ReportList * reports
struct wmOperatorType * type
struct PointerRNA * ptr
void WM_cursor_wait(bool val)
void WM_event_add_notifier(const bContext *C, uint type, void *reference)
PointerRNA * ptr
Definition wm_files.cc:4126
wmOperatorType * ot
Definition wm_files.cc:4125
ID * WM_operator_properties_id_lookup_from_name_or_session_uid(Main *bmain, PointerRNA *ptr, const ID_Type type)
void WM_operator_properties_id_lookup(wmOperatorType *ot, const bool add_name_prop)
int WM_menu_invoke(bContext *C, wmOperator *op, const wmEvent *)
int WM_operator_props_popup_confirm_ex(bContext *C, wmOperator *op, const wmEvent *, std::optional< std::string > title, std::optional< std::string > confirm_text, const bool cancel_default)
int WM_enum_search_invoke(bContext *C, wmOperator *op, const wmEvent *)
uint8_t flag
Definition wm_window.cc:138