Blender V5.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
8
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.hh"
31#include "BLI_linklist.hh"
32#include "BLI_listbase.hh"
33#include "BLI_math_matrix_c.hh"
34#include "BLI_math_vector_c.hh"
35#include "BLI_string_utf8.hh"
36#include "BLI_utildefines.hh"
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_light_linking.h"
58#include "BKE_main.hh"
59#include "BKE_material.hh"
60#include "BKE_mesh_types.hh"
61#include "BKE_modifier.hh"
62#include "BKE_node.hh"
63#include "BKE_node_runtime.hh"
65#include "BKE_object.hh"
66#include "BKE_object_types.hh"
67#include "BKE_paint.hh"
68#include "BKE_report.hh"
69#include "BKE_scene.hh"
70
71#include "DEG_depsgraph.hh"
74
75#include "WM_api.hh"
76#include "WM_types.hh"
77
78#include "UI_interface.hh"
80#include "UI_resources.hh"
81
82#include "RNA_access.hh"
83#include "RNA_define.hh"
84#include "RNA_enum_types.hh"
85
86#include "ED_armature.hh"
87#include "ED_curve.hh"
88#include "ED_gpencil_legacy.hh"
89#include "ED_grease_pencil.hh"
90#include "ED_mesh.hh"
91#include "ED_object.hh"
92#include "ED_screen.hh"
93#include "ED_view3d.hh"
94
95#include "ANIM_action.hh"
96#include "ANIM_animdata.hh"
97
98#include "MOD_nodes.hh"
99
100#include "object_intern.hh"
101
102namespace blender::ed::object {
103
104/* ------------------------------------------------------------------- */
107
112
114{
115 Main *bmain = CTX_data_main(C);
116 Scene *scene = CTX_data_scene(C);
117 View3D *v3d = CTX_wm_view3d(C);
118 Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
119 ViewLayer *view_layer = CTX_data_view_layer(C);
120 Object *obedit = CTX_data_edit_object(C);
121 Object *par;
122
123#define INDEX_UNSET -1
124 int par1, par2, par3, par4;
125 par1 = par2 = par3 = par4 = INDEX_UNSET;
126
127 /* we need 1 to 3 selected vertices */
128
129 if (obedit->type == OB_MESH) {
130 Mesh *mesh = id_cast<Mesh *>(obedit->data);
131
132 EDBM_mesh_load(bmain, obedit);
133 EDBM_mesh_make(obedit, scene->toolsettings->selectmode, true);
134
135 DEG_id_tag_update(obedit->data, 0);
136
137 BMEditMesh *em = mesh->runtime->edit_mesh.get();
138
140
141 /* Make sure the evaluated mesh is updated.
142 *
143 * Most reliable way is to update the tagged objects, which will ensure
144 * proper copy-on-evaluation update, but also will make sure all dependent
145 * objects are also up to date. */
146 BKE_scene_graph_update_tagged(depsgraph, bmain);
147
148 BMVert *eve;
149 BMIter iter;
150 int curr_index;
152 BM_ITER_MESH_INDEX (eve, &iter, bm, BM_VERTS_OF_MESH, curr_index) {
154 if (par1 == INDEX_UNSET) {
155 par1 = curr_index;
156 }
157 else if (par2 == INDEX_UNSET) {
158 par2 = curr_index;
159 }
160 else if (par3 == INDEX_UNSET) {
161 par3 = curr_index;
162 }
163 else if (par4 == INDEX_UNSET) {
164 par4 = curr_index;
165 }
166 else {
167 break;
168 }
169 }
170 }
171 }
172 else if (ELEM(obedit->type, OB_SURF, OB_CURVES_LEGACY)) {
173 ListBaseT<Nurb> *editnurb = object_editcurve_get(obedit);
174 int curr_index = 0;
175 for (Nurb *nu = editnurb->first(); nu != nullptr; nu = nu->next) {
176 if (nu->type == CU_BEZIER) {
177 BezTriple *bezt = nu->bezt;
178 for (int nurb_index = 0; nurb_index < nu->pntsu; nurb_index++, bezt++, curr_index++) {
179 if (BEZT_ISSEL_ANY_HIDDENHANDLES(v3d, bezt)) {
180 if (par1 == INDEX_UNSET) {
181 par1 = curr_index;
182 }
183 else if (par2 == INDEX_UNSET) {
184 par2 = curr_index;
185 }
186 else if (par3 == INDEX_UNSET) {
187 par3 = curr_index;
188 }
189 else if (par4 == INDEX_UNSET) {
190 par4 = curr_index;
191 }
192 else {
193 break;
194 }
195 }
196 }
197 }
198 else {
199 BPoint *bp = nu->bp;
200 const int points_num = nu->pntsu * nu->pntsv;
201 for (int nurb_index = 0; nurb_index < points_num; nurb_index++, bp++, curr_index++) {
202 if (bp->f1 & SELECT) {
203 if (par1 == INDEX_UNSET) {
204 par1 = curr_index;
205 }
206 else if (par2 == INDEX_UNSET) {
207 par2 = curr_index;
208 }
209 else if (par3 == INDEX_UNSET) {
210 par3 = curr_index;
211 }
212 else if (par4 == INDEX_UNSET) {
213 par4 = curr_index;
214 }
215 else {
216 break;
217 }
218 }
219 }
220 }
221 }
222 }
223 else if (obedit->type == OB_LATTICE) {
224 Lattice *lt = id_cast<Lattice *>(obedit->data);
225
226 const int points_num = lt->editlatt->latt->pntsu * lt->editlatt->latt->pntsv *
227 lt->editlatt->latt->pntsw;
228 BPoint *bp = lt->editlatt->latt->def;
229 for (int curr_index = 0; curr_index < points_num; curr_index++, bp++) {
230 if (bp->f1 & SELECT) {
231 if (par1 == INDEX_UNSET) {
232 par1 = curr_index;
233 }
234 else if (par2 == INDEX_UNSET) {
235 par2 = curr_index;
236 }
237 else if (par3 == INDEX_UNSET) {
238 par3 = curr_index;
239 }
240 else if (par4 == INDEX_UNSET) {
241 par4 = curr_index;
242 }
243 else {
244 break;
245 }
246 }
247 }
248 }
249
250 if (par4 != INDEX_UNSET || par1 == INDEX_UNSET || (par2 != INDEX_UNSET && par3 == INDEX_UNSET)) {
251 BKE_report(op->reports, RPT_ERROR, "Select either 1 or 3 vertices to parent to");
252 return OPERATOR_CANCELLED;
253 }
254
255 CTX_DATA_BEGIN (C, Object *, ob, selected_editable_objects) {
256 if (ob != obedit) {
258 par = obedit->parent;
259
260 if (BKE_object_parent_loop_check(par, ob)) {
261 BKE_report(op->reports, RPT_ERROR, "Loop in parents");
262 }
263 else {
264 BKE_view_layer_synced_ensure(*bmain, scene, view_layer);
265 ob->parent = BKE_view_layer_active_object_get(view_layer);
267 if (par3 != INDEX_UNSET) {
268 ob->partype = PARVERT3;
269 ob->par1 = par1;
270 ob->par2 = par2;
271 ob->par3 = par3;
272
273 /* inverse parent matrix */
274 invert_m4_m4(ob->parentinv, BKE_object_calc_parent(depsgraph, scene, ob).ptr());
275 }
276 else {
277 ob->partype = PARVERT1;
278 ob->par1 = par1;
279
280 /* inverse parent matrix */
281 invert_m4_m4(ob->parentinv, BKE_object_calc_parent(depsgraph, scene, ob).ptr());
282 }
283 }
284 }
285 }
287
289
291
292 return OPERATOR_FINISHED;
293
294#undef INDEX_UNSET
295}
296
298{
299 /* identifiers */
300 ot->name = "Make Vertex Parent";
301 ot->description = "Parent selected objects to the selected vertices";
302 ot->idname = "OBJECT_OT_vertex_parent_set";
303
304 /* API callbacks. */
307
308 /* flags */
310}
311
313
314/* ------------------------------------------------------------------- */
317
320 "CLEAR",
321 0,
322 "Clear Parent",
323 "Completely clear the parenting relationship, including involved modifiers if any"},
325 "CLEAR_KEEP_TRANSFORM",
326 0,
327 "Clear and Keep Transformation",
328 "As 'Clear Parent', but keep the current visual transformations of the object"},
330 "CLEAR_INVERSE",
331 0,
332 "Clear Parent Inverse",
333 "Reset the transform corrections applied to the parenting relationship, does not remove "
334 "parenting itself"},
335 {0, nullptr, 0, nullptr, nullptr},
336};
337
338/* Helper for parent_clear() - Remove deform-modifiers associated with parent */
340{
342 ModifierData *md, *mdn;
343
344 /* assume that we only need to remove the first instance of matching deform modifier here */
345 for (md = ob->modifiers.first(); md; md = mdn) {
346 bool free = false;
347
348 mdn = md->next;
349
350 /* need to match types (modifier + parent) and references */
351 if ((md->type == eModifierType_Armature) && (par->type == OB_ARMATURE)) {
352 ArmatureModifierData *amd = reinterpret_cast<ArmatureModifierData *>(md);
353 if (amd->object == par) {
354 free = true;
355 }
356 }
357 else if ((md->type == eModifierType_Lattice) && (par->type == OB_LATTICE)) {
358 LatticeModifierData *lmd = reinterpret_cast<LatticeModifierData *>(md);
359 if (lmd->object == par) {
360 free = true;
361 }
362 }
363 else if ((md->type == eModifierType_Curve) && (par->type == OB_CURVES_LEGACY)) {
364 CurveModifierData *cmd = reinterpret_cast<CurveModifierData *>(md);
365 if (cmd->object == par) {
366 free = true;
367 }
368 }
369
370 /* free modifier if match */
371 if (free) {
374 }
375 }
376 }
377}
378
379static void parent_clear_data(Object *ob)
380{
381 ob->parent = nullptr;
382 /* Set parent type to default PAROBJECT and reset enum explicitly, to prevent rna enum errors
383 * later. */
384 ob->partype = PAROBJECT;
385 ob->parsubstr[0] = '\0';
386}
387
388void parent_clear(Main *bmain, Object *ob, const int type)
389{
390 if (ob->parent == nullptr) {
391 return;
392 }
394 if (type != CLEAR_PARENT_INVERSE) {
396 }
397 switch (type) {
398 case CLEAR_PARENT_ALL: {
399 /* for deformers, remove corresponding modifiers to prevent
400 * a large number of modifiers building up */
402
403 /* clear parenting relationship completely */
405 break;
406 }
408 /* remove parent, and apply the parented transform
409 * result as object's local transforms */
411 BKE_object_apply_mat4(ob, ob->object_to_world().ptr(), true, false);
412 /* Don't recalculate the animation because it would change the transform
413 * instead of keeping it. */
414 flags &= ~ID_RECALC_ANIMATION;
415 break;
416 }
418 /* object stays parented, but the parent inverse
419 * (i.e. offset from parent to retain binding state)
420 * is cleared. In other words: nothing to do here! */
421 break;
422 }
423 }
424
425 /* Always clear parentinv matrix for sake of consistency, see #41950. */
426 unit_m4(ob->parentinv);
427
428 DEG_id_tag_update(&ob->id, flags);
429}
430
431/* NOTE: poll should check for editable scene. */
433{
434 Main *bmain = CTX_data_main(C);
435 /* Dependency graph must be evaluated for access to object's evaluated transform matrices. */
437 const int type = RNA_enum_get(op->ptr, "type");
438
439 CTX_DATA_BEGIN (C, Object *, ob, selected_editable_objects) {
440 parent_clear(bmain, ob, type);
441 }
443
447 return OPERATOR_FINISHED;
448}
449
451{
452 /* identifiers */
453 ot->name = "Clear Parent";
454 ot->description = "Clear the object's parenting";
455 ot->idname = "OBJECT_OT_parent_clear";
456
457 /* API callbacks. */
460
461 /* flags */
463
464 ot->prop = RNA_def_enum(ot->srna, "type", prop_clear_parent_types, CLEAR_PARENT_ALL, "Type", "");
465}
466
468
469/* ------------------------------------------------------------------- */
472
473void parent_set(Object *ob, Object *par, const eObject_Partype type, const char *substr)
474{
475 /* Always clear parentinv matrix for sake of consistency, see #41950. */
476 unit_m4(ob->parentinv);
477
478 if (!par || BKE_object_parent_loop_check(par, ob)) {
480 return;
481 }
482
483 /* Other partypes are deprecated, do not use here! */
485
486 /* this could use some more checks */
487
488 ob->parent = par;
489 ob->partype &= ~PARTYPE;
490 ob->partype |= type;
491 STRNCPY_UTF8(ob->parsubstr, substr);
492}
493
495 {PAR_OBJECT, "OBJECT", 0, "Object", ""},
496 {PAR_ARMATURE, "ARMATURE", 0, "Armature Deform", ""},
497 {PAR_ARMATURE_NAME, "ARMATURE_NAME", 0, " With Empty Groups", ""},
498 {PAR_ARMATURE_AUTO, "ARMATURE_AUTO", 0, " With Automatic Weights", ""},
499 {PAR_ARMATURE_ENVELOPE, "ARMATURE_ENVELOPE", 0, " With Envelope Weights", ""},
500 {PAR_BONE, "BONE", 0, "Bone", ""},
501 {PAR_BONE_RELATIVE, "BONE_RELATIVE", 0, "Bone Relative", ""},
502 {PAR_CURVE, "CURVE", 0, "Curve Deform", ""},
503 {PAR_FOLLOW, "FOLLOW", 0, "Follow Path", ""},
504 {PAR_PATH_CONST, "PATH_CONST", 0, "Path Constraint", ""},
505 {PAR_LATTICE, "LATTICE", 0, "Lattice Deform", ""},
506 {PAR_VERTEX, "VERTEX", 0, "Vertex", ""},
507 {PAR_VERTEX_TRI, "VERTEX_TRI", 0, "Vertex (Triangle)", ""},
508 {0, nullptr, 0, nullptr, nullptr},
509};
510
512 const bContext *C,
513 Scene *scene,
514 Depsgraph *depsgraph,
515 Object *const ob,
516 Object *const par,
517 Object *const parent_eval,
518 int partype,
519 const bool xmirror,
520 const bool keep_transform,
521 const int vert_par[3])
522{
523 Main *bmain = CTX_data_main(C);
524 bPoseChannel *pchan = nullptr;
525 bPoseChannel *pchan_eval = nullptr;
526
527 /* Preconditions. */
528 if (ob == par) {
529 /* Parenting an object to itself is impossible. */
530 return false;
531 }
532
533 if (BKE_object_parent_loop_check(par, ob)) {
534 BKE_report(reports, RPT_ERROR, "Loop in parents");
535 return false;
536 }
537
538 switch (partype) {
539 case PAR_FOLLOW:
540 case PAR_PATH_CONST: {
541 if (par->type != OB_CURVES_LEGACY) {
542 return false;
543 }
544 Curve *cu = id_cast<Curve *>(par->data);
545 Curve *cu_eval = id_cast<Curve *>(parent_eval->data);
546 if ((cu->flag & CU_PATH) == 0) {
547 cu->flag |= CU_PATH | CU_FOLLOW;
548 cu_eval->flag |= CU_PATH | CU_FOLLOW;
549 /* force creation of path data */
550 BKE_displist_make_curveTypes(depsgraph, scene, par, false);
551 }
552 else {
553 cu->flag |= CU_FOLLOW;
554 cu_eval->flag |= CU_FOLLOW;
555 }
556
557 /* if follow, add F-Curve for ctime (i.e. "eval_time") so that path-follow works */
558 if (partype == PAR_FOLLOW) {
559 /* get or create F-Curve */
560 bAction *act = animrig::id_action_ensure(bmain, &cu->id);
561 PointerRNA id_ptr = RNA_id_pointer_create(&cu->id);
562 FCurve *fcu = animrig::action_fcurve_ensure_ex(bmain, act, &id_ptr, {"eval_time", 0});
563
564 /* setup dummy 'generator' modifier here to get 1-1 correspondence still working */
565 if (!fcu->bezt && !fcu->fpt && !fcu->modifiers.first_) {
567 }
568 }
569
570 /* fall back on regular parenting now (for follow only) */
571 if (partype == PAR_FOLLOW) {
572 partype = PAR_OBJECT;
573 }
574 break;
575 }
576 case PAR_BONE:
579 pchan_eval = BKE_pose_channel_active_if_bonecoll_visible(parent_eval);
580
581 if (pchan == nullptr || pchan_eval == nullptr) {
582 /* If pchan_eval is nullptr, pchan should also be nullptr. */
583 BLI_assert_msg(pchan == nullptr, "Missing evaluated bone data");
584 BKE_report(reports, RPT_ERROR, "No active bone");
585 return false;
586 }
587 }
588
589 /* Apply transformation of previous parenting. */
590 if (keep_transform) {
591 /* Was removed because of bug #23577, * but this can be handy in some cases too #32616, so
592 * make optional. */
593 BKE_object_apply_mat4(ob, ob->object_to_world().ptr(), false, false);
594 }
595
596 /* Set the parent (except for follow-path constraint option). */
597 if (partype != PAR_PATH_CONST) {
598 ob->parent = par;
600 /* Always clear parentinv matrix for sake of consistency, see #41950. */
601 unit_m4(ob->parentinv);
602 }
603
604 /* Handle types. */
605 if (pchan) {
606 STRNCPY_UTF8(ob->parsubstr, pchan->name);
607 }
608 else {
609 ob->parsubstr[0] = 0;
610 }
611
612 switch (partype) {
613 case PAR_PATH_CONST:
614 /* Don't do anything here, since this is not technically "parenting". */
615 break;
616 case PAR_CURVE:
617 case PAR_LATTICE:
618 case PAR_ARMATURE:
622 /* partype is now set to PAROBJECT so that invisible 'virtual'
623 * modifiers don't need to be created.
624 * NOTE: the old (2.4x) method was to set ob->partype = PARSKEL, * creating the
625 * virtual modifiers.
626 */
627 ob->partype = PAROBJECT; /* NOTE: DNA define, not operator property. */
628 // ob->partype = PARSKEL; /* NOTE: DNA define, not operator property. */
629
630 /* BUT, to keep the deforms, we need a modifier, * and then we need to set the object
631 * that it uses
632 * - We need to ensure that the modifier we're adding doesn't already exist, * so we
633 * check this by assuming that the parent is selected too.
634 */
635 /* XXX currently this should only happen for meshes, curves, surfaces, * and lattices
636 * - this stuff isn't available for meta-balls yet. */
637 if (ELEM(
639 {
640 ModifierData *md;
641
642 switch (partype) {
643 case PAR_CURVE: /* curve deform */
644 if (BKE_modifiers_is_deformed_by_curve(ob) != par) {
645 md = modifier_add(reports, bmain, scene, ob, nullptr, eModifierType_Curve);
646 if (md) {
647 (reinterpret_cast<CurveModifierData *>(md))->object = par;
648 }
649 if (par->runtime->curve_cache &&
651 {
653 }
654 }
655 break;
656 case PAR_LATTICE: /* lattice deform */
658 const bool is_grease_pencil = ob->type == OB_GREASE_PENCIL;
659 const ModifierType lattice_modifier_type = is_grease_pencil ?
662 md = modifier_add(reports, bmain, scene, ob, nullptr, lattice_modifier_type);
663 if (md) {
664 if (is_grease_pencil) {
665 reinterpret_cast<GreasePencilLatticeModifierData *>(md)->object = par;
666 }
667 else {
668 reinterpret_cast<LatticeModifierData *>(md)->object = par;
669 }
670 }
671 }
672 break;
673 default: /* armature deform */
675 if (ob->type == OB_GREASE_PENCIL) {
676 md = modifier_add(
677 reports, bmain, scene, ob, nullptr, eModifierType_GreasePencilArmature);
678 if (md) {
679 (reinterpret_cast<GreasePencilArmatureModifierData *>(md))->object = par;
680 }
681 }
682 else {
683 md = modifier_add(reports, bmain, scene, ob, nullptr, eModifierType_Armature);
684 if (md) {
685 (reinterpret_cast<ArmatureModifierData *>(md))->object = par;
686 }
687 }
688 }
689 break;
690 }
691 }
692 break;
693 case PAR_BONE:
694 ob->partype = PARBONE; /* NOTE: DNA define, not operator property. */
695 if (Bone *bone = pchan->bone_get(*par)) {
696 bone->flag &= ~BONE_RELATIVE_PARENTING;
697 pchan_eval->bone_get(*parent_eval)->flag &= ~BONE_RELATIVE_PARENTING;
698 }
699 break;
701 ob->partype = PARBONE; /* NOTE: DNA define, not operator property. */
702 if (Bone *bone = pchan->bone_get(*par)) {
703 bone->flag |= BONE_RELATIVE_PARENTING;
704 pchan_eval->bone_get(*parent_eval)->flag |= BONE_RELATIVE_PARENTING;
705 }
706 break;
707 case PAR_VERTEX:
708 ob->partype = PARVERT1;
709 ob->par1 = vert_par[0];
710 break;
711 case PAR_VERTEX_TRI:
712 ob->partype = PARVERT3;
713 copy_v3_v3_int(&ob->par1, vert_par);
714 break;
715 case PAR_OBJECT:
716 case PAR_FOLLOW:
717 ob->partype = PAROBJECT; /* NOTE: DNA define, not operator property. */
718 break;
719 }
720
721 /* Constraint and set parent inverse. */
722 const bool is_armature_parent = ELEM(
724 if (partype == PAR_PATH_CONST) {
725 bConstraint *con;
727 float cmat[4][4], vec[3];
728
730
731 data = static_cast<bFollowPathConstraint *>(con->data);
732 data->tar = par;
733
735 depsgraph, scene, con, 0, CONSTRAINT_OBTYPE_OBJECT, nullptr, cmat, scene->r.cfra);
736 sub_v3_v3v3(vec, ob->object_to_world().location(), cmat[3]);
737
738 copy_v3_v3(ob->loc, vec);
739 }
740 else if (is_armature_parent && (ob->type == OB_LATTICE) && (par->type == OB_ARMATURE) &&
741 (partype == PAR_ARMATURE_NAME))
742 {
744 reports, depsgraph, scene, ob, par, ARM_GROUPS_NAME, false);
745 }
746 else if (is_armature_parent && (ob->type == OB_MESH) && (par->type == OB_ARMATURE)) {
747 if (partype == PAR_ARMATURE_NAME) {
749 reports, depsgraph, scene, ob, par, ARM_GROUPS_NAME, false);
750 }
751 else if (partype == PAR_ARMATURE_ENVELOPE) {
753 reports, depsgraph, scene, ob, par, ARM_GROUPS_ENVELOPE, xmirror);
754 }
755 else if (partype == PAR_ARMATURE_AUTO) {
756 WM_cursor_wait(true);
758 reports, depsgraph, scene, ob, par, ARM_GROUPS_AUTO, xmirror);
759 WM_cursor_wait(false);
760 }
761 /* Get corrected inverse. */
762 ob->partype = PAROBJECT;
763
764 invert_m4_m4(ob->parentinv, BKE_object_calc_parent(depsgraph, scene, ob).ptr());
765 }
766 else if (is_armature_parent && (ob->type == OB_GREASE_PENCIL) && (par->type == OB_ARMATURE)) {
767 if (partype == PAR_ARMATURE_NAME) {
769 }
770 else if (partype == PAR_ARMATURE_ENVELOPE) {
772 }
773 else if (partype == PAR_ARMATURE_AUTO) {
775 }
776 /* get corrected inverse */
777 ob->partype = PAROBJECT;
778
779 invert_m4_m4(ob->parentinv, BKE_object_calc_parent(depsgraph, scene, ob).ptr());
780 }
781 else {
782 /* calculate inverse parent matrix */
783 invert_m4_m4(ob->parentinv, BKE_object_calc_parent(depsgraph, scene, ob).ptr());
784 }
785
788 return true;
789}
790
791bool parent_set(ReportList *reports,
792 const bContext *C,
793 Scene *scene,
794 Object *const ob,
795 Object *const par,
796 int partype,
797 const bool xmirror,
798 const bool keep_transform,
799 const int vert_par[3])
800{
801 Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
802 Object *parent_eval = DEG_get_evaluated(depsgraph, par);
803
804 return parent_set_with_depsgraph(reports,
805 C,
806 scene,
807 depsgraph,
808 ob,
809 par,
810 parent_eval,
811 partype,
812 xmirror,
813 keep_transform,
814 vert_par);
815}
816
817static void parent_set_vert_find(KDTree<float3> *tree, Object *child, int vert_par[3], bool is_tri)
818{
819 const float *co_find = child->object_to_world().location();
820 if (is_tri) {
821 KDTreeNearest<float3> nearest[3];
822 int tot;
823
824 tot = kdtree_find_nearest_n<float3>(tree, co_find, nearest, 3);
825 BLI_assert(tot == 3);
826 UNUSED_VARS(tot);
827
828 vert_par[0] = nearest[0].index;
829 vert_par[1] = nearest[1].index;
830 vert_par[2] = nearest[2].index;
831
832 BLI_assert(std::min({UNPACK3(vert_par)}) >= 0);
833 }
834 else {
835 vert_par[0] = kdtree_find_nearest<float3>(tree, co_find, nullptr);
836 BLI_assert(vert_par[0] >= 0);
837 vert_par[1] = 0;
838 vert_par[2] = 0;
839 }
840}
841
851
853{
854 Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
855 Object *parent_eval = DEG_get_evaluated(depsgraph, parenting_context->par);
856
857 CTX_DATA_BEGIN (C, Object *, ob, selected_editable_objects) {
858 if (ob == parenting_context->par) {
859 /* parent_set() will fail (and thus return false), but this case
860 * shouldn't break this loop. It's expected that the active object is also selected. */
861 continue;
862 }
863
864 if (!parent_set_with_depsgraph(parenting_context->reports,
865 C,
866 parenting_context->scene,
867 depsgraph,
868 ob,
869 parenting_context->par,
870 parent_eval,
871 parenting_context->partype,
872 parenting_context->xmirror,
873 parenting_context->keep_transform,
874 nullptr))
875 {
876 return false;
877 }
878 }
880
881 return true;
882}
883
885 ParentingContext *parenting_context,
886 KDTree<float3> *tree)
887{
888 int vert_par[3] = {0, 0, 0};
889
890 CTX_DATA_BEGIN (C, Object *, ob, selected_editable_objects) {
891 if (ob == parenting_context->par) {
892 /* parent_set() will fail (and thus return false), but this case
893 * shouldn't break this loop. It's expected that the active object is also selected. */
894 continue;
895 }
896
897 parent_set_vert_find(tree, ob, vert_par, parenting_context->is_vertex_tri);
898 if (!parent_set(parenting_context->reports,
899 C,
900 parenting_context->scene,
901 ob,
902 parenting_context->par,
903 parenting_context->partype,
904 parenting_context->xmirror,
905 parenting_context->keep_transform,
906 vert_par))
907 {
908 return false;
909 }
910 }
912 return true;
913}
914
915static bool parent_set_vertex_parent(bContext *C, ParentingContext *parenting_context)
916{
917 KDTree<float3> *tree = nullptr;
918 int tree_tot;
919
920 Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
921 Object *par_eval = DEG_get_evaluated(depsgraph, parenting_context->par);
922
923 tree = BKE_object_as_kdtree(par_eval, &tree_tot);
924 /* Zero & null for unsupported object types. */
925 BLI_assert((tree != nullptr) || (tree_tot == 0));
926
927 if (tree_tot < (parenting_context->is_vertex_tri ? 3 : 1)) {
928 BKE_report(parenting_context->reports, RPT_ERROR, "Not enough vertices for vertex-parent");
930 return false;
931 }
932
933 const bool ok = parent_set_vertex_parent_with_kdtree(C, parenting_context, tree);
935 return ok;
936}
937
939{
940 const int partype = RNA_enum_get(op->ptr, "type");
941 ParentingContext parenting_context{};
942 parenting_context.reports = op->reports;
943 parenting_context.scene = CTX_data_scene(C);
944 parenting_context.par = context_active_object(C);
945 parenting_context.partype = partype;
946 parenting_context.is_vertex_tri = partype == PAR_VERTEX_TRI;
947 parenting_context.xmirror = RNA_boolean_get(op->ptr, "xmirror");
948 parenting_context.keep_transform = RNA_boolean_get(op->ptr, "keep_transform");
949
950 bool ok;
951 if (ELEM(parenting_context.partype, PAR_VERTEX, PAR_VERTEX_TRI)) {
952 ok = parent_set_vertex_parent(C, &parenting_context);
953 }
954 else {
955 ok = parent_set_nonvertex_parent(C, &parenting_context);
956 }
957 if (!ok) {
958 return OPERATOR_CANCELLED;
959 }
960
961 Main *bmain = CTX_data_main(C);
965
966 return OPERATOR_FINISHED;
967}
968
970{
971 Object *parent = context_active_object(C);
972 ui::PopupMenu *pup = ui::popup_menu_begin(C, IFACE_("Set Parent To"), ICON_NONE);
973 ui::Layout &layout = *popup_menu_layout(pup);
974
975 PointerRNA opptr = layout.op(
976 ot, IFACE_("Object"), ICON_OBJECT_DATA, wm::OpCallContext::ExecDefault, UI_ITEM_NONE);
977 RNA_enum_set(&opptr, "type", PAR_OBJECT);
978 RNA_boolean_set(&opptr, "keep_transform", false);
979
980 opptr = layout.op(ot,
981 IFACE_("Object (Keep Transform)"),
982 ICON_NONE,
985 RNA_enum_set(&opptr, "type", PAR_OBJECT);
986 RNA_boolean_set(&opptr, "keep_transform", true);
987
988 PointerRNA op_ptr = layout.op(
989 "OBJECT_OT_parent_no_inverse_set", IFACE_("Object (Without Inverse)"), ICON_NONE);
990 RNA_boolean_set(&op_ptr, "keep_transform", false);
991
992 op_ptr = layout.op("OBJECT_OT_parent_no_inverse_set",
993 IFACE_("Object (Keep Transform Without Inverse)"),
994 ICON_NONE);
995 RNA_boolean_set(&op_ptr, "keep_transform", true);
996
997 struct {
998 bool armature_deform, empty_groups, envelope_weights, automatic_weights, attach_surface;
999 } can_support = {false};
1000
1001 CTX_DATA_BEGIN (C, Object *, child, selected_editable_objects) {
1002 if (child == parent) {
1003 continue;
1004 }
1005 if (ELEM(child->type,
1006 OB_MESH,
1008 OB_SURF,
1009 OB_FONT,
1011 OB_LATTICE))
1012 {
1013 can_support.armature_deform = true;
1014 can_support.envelope_weights = true;
1015 }
1016 if (ELEM(child->type, OB_MESH, OB_GREASE_PENCIL, OB_LATTICE)) {
1017 can_support.empty_groups = true;
1018 }
1019 if (ELEM(child->type, OB_MESH, OB_GREASE_PENCIL)) {
1020 can_support.automatic_weights = true;
1021 }
1022 if (child->type == OB_CURVES) {
1023 can_support.attach_surface = true;
1024 }
1025 }
1027
1028 if (parent->type == OB_ARMATURE) {
1029
1030 if (can_support.armature_deform) {
1031 op_ptr = layout.op(ot, IFACE_("Armature Deform"), ICON_OUTLINER_OB_ARMATURE);
1032 RNA_enum_set(&op_ptr, "type", PAR_ARMATURE);
1033 }
1034 if (can_support.empty_groups) {
1035 op_ptr = layout.op(ot, IFACE_(" With Empty Groups"), ICON_NONE);
1036 RNA_enum_set(&op_ptr, "type", PAR_ARMATURE_NAME);
1037 }
1038 if (can_support.envelope_weights) {
1039 op_ptr = layout.op(ot, IFACE_(" With Envelope Weights"), ICON_NONE);
1040 RNA_enum_set(&op_ptr, "type", PAR_ARMATURE_ENVELOPE);
1041 }
1042 if (can_support.automatic_weights) {
1043 op_ptr = layout.op(ot, IFACE_(" With Automatic Weights"), ICON_NONE);
1044 RNA_enum_set(&op_ptr, "type", PAR_ARMATURE_AUTO);
1045 }
1046 op_ptr = layout.op(ot, IFACE_("Bone"), ICON_BONE_DATA);
1047 RNA_enum_set(&op_ptr, "type", PAR_BONE);
1048 op_ptr = layout.op(ot, IFACE_("Bone Relative"), ICON_NONE);
1049 RNA_enum_set(&op_ptr, "type", PAR_BONE_RELATIVE);
1050 }
1051 else if (parent->type == OB_CURVES_LEGACY) {
1052 op_ptr = layout.op(ot, IFACE_("Curve Deform"), ICON_OUTLINER_OB_CURVE);
1053 RNA_enum_set(&op_ptr, "type", PAR_CURVE);
1054 op_ptr = layout.op(ot, IFACE_("Follow Path"), ICON_CURVE_PATH);
1055 RNA_enum_set(&op_ptr, "type", PAR_FOLLOW);
1056 op_ptr = layout.op(ot, IFACE_("Path Constraint"), ICON_NONE);
1057 RNA_enum_set(&op_ptr, "type", PAR_PATH_CONST);
1058 }
1059 else if (parent->type == OB_LATTICE) {
1060 op_ptr = layout.op(ot, IFACE_("Lattice Deform"), ICON_OUTLINER_OB_LATTICE);
1061 RNA_enum_set(&op_ptr, "type", PAR_LATTICE);
1062 }
1063 else if (parent->type == OB_MESH) {
1064 if (can_support.attach_surface) {
1065 layout.op("CURVES_OT_surface_set", IFACE_("Object (Attach Curves to Surface)"), ICON_NONE);
1066 }
1067 }
1068
1069 /* vertex parenting */
1070 if (OB_TYPE_SUPPORT_PARVERT(parent->type)) {
1071 op_ptr = layout.op(ot, IFACE_("Vertex"), ICON_VERTEXSEL);
1072 RNA_enum_set(&op_ptr, "type", PAR_VERTEX);
1073 op_ptr = layout.op(ot, IFACE_("Vertex (Triangle)"), ICON_NONE);
1074 RNA_enum_set(&op_ptr, "type", PAR_VERTEX_TRI);
1075 }
1076
1077 popup_menu_end(C, pup);
1078
1079 return OPERATOR_INTERFACE;
1080}
1081
1083{
1084 if (RNA_property_is_set(op->ptr, op->type->prop)) {
1085 return parent_set_exec(C, op);
1086 }
1087 return parent_set_invoke_menu(C, op->type);
1088}
1089
1090static bool parent_set_poll_property(const bContext * /*C*/,
1091 wmOperator *op,
1092 const PropertyRNA *prop)
1093{
1094 const char *prop_id = RNA_property_identifier(prop);
1095
1096 /* Only show XMirror for PAR_ARMATURE_ENVELOPE and PAR_ARMATURE_AUTO! */
1097 if (STREQ(prop_id, "xmirror")) {
1098 const int type = RNA_enum_get(op->ptr, "type");
1100 return true;
1101 }
1102 return false;
1103 }
1104
1105 return true;
1106}
1107
1109{
1110 /* identifiers */
1111 ot->name = "Make Parent";
1112 ot->description = "Set the object's parenting";
1113 ot->idname = "OBJECT_OT_parent_set";
1114
1115 /* API callbacks. */
1117 ot->exec = parent_set_exec;
1120
1121 /* flags */
1123
1124 ot->prop = RNA_def_enum(ot->srna, "type", prop_make_parent_types, 0, "Type", "");
1126 ot->srna,
1127 "xmirror",
1128 false,
1129 "X Mirror",
1130 "Apply weights symmetrically along X axis, for Envelope/Automatic vertex groups creation");
1132 "keep_transform",
1133 false,
1134 "Keep Transform",
1135 "Apply transformation before parenting");
1136}
1137
1139
1140/* ------------------------------------------------------------------- */
1143
1145{
1146 Main *bmain = CTX_data_main(C);
1148
1149 const bool keep_transform = RNA_boolean_get(op->ptr, "keep_transform");
1150
1152
1153 /* context iterator */
1154 CTX_DATA_BEGIN (C, Object *, ob, selected_editable_objects) {
1155 if (ob != par) {
1156 if (BKE_object_parent_loop_check(par, ob)) {
1157 BKE_report(op->reports, RPT_ERROR, "Loop in parents");
1158 }
1159 else {
1160 /* set recalc flags */
1162
1163 /* set parenting type for object - object only... */
1164 ob->parent = par;
1165 ob->partype = PAROBJECT; /* NOTE: DNA define, not operator property. */
1166
1167 if (keep_transform) {
1169 continue;
1170 }
1171
1172 /* clear inverse matrix and also the object location */
1173 unit_m4(ob->parentinv);
1174 memset(ob->loc, 0, sizeof(float[3]));
1175 }
1176 }
1177 }
1179
1183
1184 return OPERATOR_FINISHED;
1185}
1186
1188{
1189 /* identifiers */
1190 ot->name = "Make Parent without Inverse";
1191 ot->description = "Set the object's parenting without setting the inverse parent correction";
1192 ot->idname = "OBJECT_OT_parent_no_inverse_set";
1193
1194 /* API callbacks. */
1197
1198 /* flags */
1200
1202 "keep_transform",
1203 false,
1204 "Keep Transform",
1205 "Preserve the world transform throughout parenting");
1206}
1207
1209
1210/* ------------------------------------------------------------------- */
1213
1214enum {
1217};
1218
1220 {CLEAR_TRACK, "CLEAR", 0, "Clear Track", ""},
1222 "CLEAR_KEEP_TRANSFORM",
1223 0,
1224 "Clear and Keep Transformation (Clear Track)",
1225 ""},
1226 {0, nullptr, 0, nullptr, nullptr},
1227};
1228
1229/* NOTE: poll should check for editable scene. */
1231{
1232 Main *bmain = CTX_data_main(C);
1233 const int type = RNA_enum_get(op->ptr, "type");
1234
1235 if (CTX_data_edit_object(C)) {
1236 BKE_report(op->reports, RPT_ERROR, "Operation cannot be performed in edit mode");
1237 return OPERATOR_CANCELLED;
1238 }
1239 CTX_DATA_BEGIN (C, Object *, ob, selected_editable_objects) {
1240 bConstraint *con, *pcon;
1241
1242 /* remove track-object for old track */
1243 ob->track = nullptr;
1245
1246 /* also remove all tracking constraints */
1247 for (con = ob->constraints.last(); con; con = pcon) {
1248 pcon = con->prev;
1249 if (ELEM(con->type,
1253 {
1254 BKE_constraint_remove_ex(&ob->constraints, ob, con);
1255 }
1256 }
1257
1258 if (type == CLEAR_TRACK_KEEP_TRANSFORM) {
1259 BKE_object_apply_mat4(ob, ob->object_to_world().ptr(), true, true);
1260 }
1261 }
1263
1266
1267 return OPERATOR_FINISHED;
1268}
1269
1271{
1272 /* identifiers */
1273 ot->name = "Clear Track";
1274 ot->description = "Clear tracking constraint or flag from object";
1275 ot->idname = "OBJECT_OT_track_clear";
1276
1277 /* API callbacks. */
1278 ot->invoke = WM_menu_invoke;
1280
1282
1283 /* flags */
1285
1286 ot->prop = RNA_def_enum(ot->srna, "type", prop_clear_track_types, 0, "Type", "");
1287}
1288
1290
1291/* ------------------------------------------------------------------- */
1294
1295enum {
1299};
1300
1302 {CREATE_TRACK_DAMPTRACK, "DAMPTRACK", 0, "Damped Track Constraint", ""},
1303 {CREATE_TRACK_TRACKTO, "TRACKTO", 0, "Track to Constraint", ""},
1304 {CREATE_TRACK_LOCKTRACK, "LOCKTRACK", 0, "Lock Track Constraint", ""},
1305 {0, nullptr, 0, nullptr, nullptr},
1306};
1307
1309{
1310 Main *bmain = CTX_data_main(C);
1311 Object *obact = context_active_object(C);
1312
1313 const int type = RNA_enum_get(op->ptr, "type");
1314
1315 switch (type) {
1317 bConstraint *con;
1319
1320 CTX_DATA_BEGIN (C, Object *, ob, selected_editable_objects) {
1321 if (ob != obact) {
1323
1324 data = static_cast<bDampTrackConstraint *>(con->data);
1325 data->tar = obact;
1326 DEG_id_tag_update(&ob->id,
1328
1329 /* Light, Camera and Speaker track differently by default */
1330 if (ELEM(ob->type, OB_LAMP, OB_CAMERA, OB_SPEAKER)) {
1331 data->trackflag = TRACK_nZ;
1332 }
1333 }
1334 }
1336 break;
1337 }
1338 case CREATE_TRACK_TRACKTO: {
1339 bConstraint *con;
1341
1342 CTX_DATA_BEGIN (C, Object *, ob, selected_editable_objects) {
1343 if (ob != obact) {
1345
1346 data = static_cast<bTrackToConstraint *>(con->data);
1347 data->tar = obact;
1348 DEG_id_tag_update(&ob->id,
1350
1351 /* Light, Camera and Speaker track differently by default */
1352 if (ELEM(ob->type, OB_LAMP, OB_CAMERA, OB_SPEAKER)) {
1353 data->reserved1 = TRACK_nZ;
1354 data->reserved2 = UP_Y;
1355 }
1356 }
1357 }
1359 break;
1360 }
1362 bConstraint *con;
1364
1365 CTX_DATA_BEGIN (C, Object *, ob, selected_editable_objects) {
1366 if (ob != obact) {
1368
1369 data = static_cast<bLockTrackConstraint *>(con->data);
1370 data->tar = obact;
1371 DEG_id_tag_update(&ob->id,
1373
1374 /* Light, Camera and Speaker track differently by default */
1375 if (ELEM(ob->type, OB_LAMP, OB_CAMERA, OB_SPEAKER)) {
1376 data->trackflag = TRACK_nZ;
1377 data->lockflag = LOCK_Y;
1378 }
1379 }
1380 }
1382 break;
1383 }
1384 }
1385
1388
1389 return OPERATOR_FINISHED;
1390}
1391
1393{
1394 /* identifiers */
1395 ot->name = "Make Track";
1396 ot->description = "Make the object track another object, using various methods/constraints";
1397 ot->idname = "OBJECT_OT_track_set";
1398
1399 /* API callbacks. */
1400 ot->invoke = WM_menu_invoke;
1401 ot->exec = track_set_exec;
1402
1404
1405 /* flags */
1407
1408 /* properties */
1409 ot->prop = RNA_def_enum(ot->srna, "type", prop_make_track_types, 0, "Type", "");
1410}
1411
1413
1414/* ------------------------------------------------------------------- */
1417
1418#if 0
1419static void link_to_scene(Main * /*bmain*/, ushort /*nr*/)
1420{
1421 Scene *sce = (Scene *)BLI_findlink(&bmain->scene, G.curscreen->scenenr - 1);
1422 Base *base, *nbase;
1423
1424 if (sce == nullptr) {
1425 return;
1426 }
1427 if (sce->id.lib) {
1428 return;
1429 }
1430
1431 for (base = FIRSTBASE; base; base = base->next) {
1432 if (BASE_SELECTED(v3d, base)) {
1433 nbase = MEM_new_uninitialized<Base>("newbase");
1434 *nbase = *base;
1435 BLI_addhead(&(sce->base), nbase);
1436 id_us_plus((ID *)base->object);
1437 }
1438 }
1439}
1440#endif
1441
1443{
1444 Main *bmain = CTX_data_main(C);
1445 Scene *scene_to = static_cast<Scene *>(
1446 BLI_findlink(&bmain->scenes, RNA_enum_get(op->ptr, "scene")));
1447
1448 if (scene_to == nullptr) {
1449 BKE_report(op->reports, RPT_ERROR, "Could not find scene");
1450 return OPERATOR_CANCELLED;
1451 }
1452
1453 if (scene_to == CTX_data_scene(C)) {
1454 BKE_report(op->reports, RPT_ERROR, "Cannot link objects into the same scene");
1455 return OPERATOR_CANCELLED;
1456 }
1457
1458 if (!BKE_id_is_editable(bmain, &scene_to->id)) {
1459 BKE_report(op->reports, RPT_ERROR, "Cannot link objects into a linked scene");
1460 return OPERATOR_CANCELLED;
1461 }
1462
1463 Collection *collection_to = scene_to->master_collection;
1464 CTX_DATA_BEGIN (C, Base *, base, selected_bases) {
1465 BKE_collection_object_add(bmain, collection_to, base->object);
1466 }
1468
1469 DEG_id_tag_update(&collection_to->id, ID_RECALC_HIERARCHY);
1470
1472
1473 /* redraw the 3D view because the object center points are colored differently */
1475
1476 /* one day multiple scenes will be visible, then we should have some update function for them
1477 */
1478 return OPERATOR_FINISHED;
1479}
1480
1481enum {
1493};
1494
1495/* Matches has_geometry_visibility() from Python.
1496 * Indicates whether an object has shading/visibility settings. */
1497static bool has_geometry_visibility(const Object &object)
1498{
1499 if (ELEM(object.type,
1500 OB_MESH,
1502 OB_SURF,
1503 OB_FONT,
1504 OB_MBALL,
1505 OB_LAMP,
1506 OB_VOLUME,
1508 OB_CURVES))
1509 {
1510 return true;
1511 }
1512
1513 if (object.transflag & OB_DUPLICOLLECTION && object.instance_collection) {
1514 return true;
1515 }
1516
1517 return false;
1518}
1519
1520/* Return true if make link data is allowed, false otherwise */
1521static bool allow_make_links_data(const int type, Object *ob_src, Object *ob_dst)
1522{
1523 switch (type) {
1524 case MAKE_LINKS_OBDATA:
1525 /* Replacing data of an object in edit-mode is not supported, see #160956. */
1526 if (ob_src->type == ob_dst->type && ob_src->type != OB_EMPTY &&
1527 (ob_dst->mode & OB_MODE_EDIT) == 0)
1528 {
1529 return true;
1530 }
1531 break;
1534 /* Linking non-grease-pencil materials to a grease-pencil object causes issues.
1535 * We make sure that if one of the objects is a grease-pencil object, the other must be
1536 * as well. */
1537 ((ob_src->type == OB_GREASE_PENCIL) == (ob_dst->type == OB_GREASE_PENCIL)))
1538 {
1539 return true;
1540 }
1541 break;
1543 if (ob_dst->type == OB_EMPTY) {
1544 return true;
1545 }
1546 break;
1548 case MAKE_LINKS_GROUP:
1549 return true;
1552 return true;
1553 }
1554 break;
1556 return true;
1557 case MAKE_LINKS_FONTS:
1558 if ((ob_src->data != ob_dst->data) && (ob_src->type == OB_FONT) && (ob_dst->type == OB_FONT))
1559 {
1560 return true;
1561 }
1562 break;
1564 if ((ob_src->type == OB_GREASE_PENCIL) && (ob_dst->type == OB_GREASE_PENCIL)) {
1565 return true;
1566 }
1567 break;
1570 return has_geometry_visibility(*ob_src) && has_geometry_visibility(*ob_dst);
1571 }
1572 return false;
1573}
1574
1576{
1577 Scene *scene = CTX_data_scene(C);
1578 Main *bmain = CTX_data_main(C);
1579 const int type = RNA_enum_get(op->ptr, "type");
1580 Object *ob_src;
1581 ID *obdata_id;
1582 int a;
1583
1584 /* collection */
1585 LinkNode *ob_collections = nullptr;
1586 bool is_cycle = false;
1587 bool is_lib = false;
1588
1589 ob_src = context_active_object(C);
1590
1591 /* avoid searching all collections in source object each time */
1592 if (type == MAKE_LINKS_GROUP) {
1593 ob_collections = BKE_object_groups(bmain, scene, ob_src);
1594 }
1595
1596 CTX_DATA_BEGIN (C, Base *, base_dst, selected_editable_bases) {
1597 Object *ob_dst = base_dst->object;
1598
1599 if (ob_src != ob_dst) {
1600 if (allow_make_links_data(type, ob_src, ob_dst)) {
1601 obdata_id = ob_dst->data;
1602
1603 switch (type) {
1604 case MAKE_LINKS_OBDATA: /* obdata */
1605 id_us_min(obdata_id);
1606
1607 obdata_id = ob_src->data;
1608 id_us_plus(obdata_id);
1609 ob_dst->data = obdata_id;
1610
1612 /* if amount of material indices changed: */
1613 BKE_object_materials_sync_length(bmain, ob_dst, ob_dst->data);
1614
1615 if (ob_dst->type == OB_ARMATURE) {
1616 BKE_pose_rebuild(bmain, ob_dst, id_cast<bArmature *>(ob_dst->data), true);
1617 }
1619 break;
1621 /* new approach, using functions from kernel */
1622 for (a = 0; a < ob_src->totcol; a++) {
1623 Material *ma = BKE_object_material_get(ob_src, a + 1);
1624 /* also works with `ma == nullptr` */
1625 BKE_object_material_assign(bmain, ob_dst, ma, a + 1, BKE_MAT_ASSIGN_USERPREF);
1626 }
1628 break;
1630 BKE_animdata_copy_id(bmain, id_cast<ID *>(ob_dst), id_cast<ID *>(ob_src), 0);
1631 if (ob_dst->data && ob_src->data) {
1632 if (BKE_id_is_editable(bmain, obdata_id)) {
1633 BKE_animdata_copy_id(bmain, ob_dst->data, ob_src->data, 0);
1634 }
1635 else {
1636 is_lib = true;
1637 }
1638 }
1639 DEG_id_tag_update(&ob_dst->id,
1641 break;
1642 case MAKE_LINKS_GROUP: {
1643 LinkNode *collection_node;
1644
1645 /* first clear collections */
1646 BKE_object_groups_clear(bmain, scene, ob_dst);
1647
1648 /* now add in the collections from the link nodes */
1649 for (collection_node = ob_collections; collection_node;
1650 collection_node = collection_node->next)
1651 {
1652 if (ob_dst->instance_collection != collection_node->link) {
1654 bmain, static_cast<Collection *>(collection_node->link), ob_dst);
1655 }
1656 else {
1657 is_cycle = true;
1658 }
1659 }
1660 break;
1661 }
1663 ob_dst->instance_collection = ob_src->instance_collection;
1664 if (ob_dst->instance_collection) {
1666 ob_dst->transflag |= OB_DUPLICOLLECTION;
1667 }
1669 break;
1671 BKE_object_link_modifiers(ob_dst, ob_src);
1672 DEG_id_tag_update(&ob_dst->id,
1674 break;
1677 BKE_constraints_copy(&ob_dst->constraints, &ob_src->constraints, true);
1680 break;
1681 case MAKE_LINKS_FONTS: {
1682 Curve *cu_src = id_cast<Curve *>(ob_src->data);
1683 Curve *cu_dst = id_cast<Curve *>(ob_dst->data);
1684
1685 if (!BKE_id_is_editable(bmain, obdata_id)) {
1686 is_lib = true;
1687 break;
1688 }
1689
1690#define CURVE_VFONT_SET(vfont_member) \
1691 { \
1692 if (cu_dst->vfont_member) { \
1693 id_us_min(&cu_dst->vfont_member->id); \
1694 } \
1695 cu_dst->vfont_member = cu_src->vfont_member; \
1696 id_us_plus((ID *)cu_dst->vfont_member); \
1697 } \
1698 ((void)0)
1699
1700 CURVE_VFONT_SET(vfont);
1701 CURVE_VFONT_SET(vfontb);
1702 CURVE_VFONT_SET(vfonti);
1703 CURVE_VFONT_SET(vfontbi);
1704
1705#undef CURVE_VFONT_SET
1706
1707 DEG_id_tag_update(&ob_dst->id,
1709 break;
1710 }
1712 shaderfx_link(ob_dst, ob_src);
1713 DEG_id_tag_update(&ob_dst->id,
1715 break;
1717 BKE_light_linking_copy_receiver_collection(bmain, *ob_dst, *ob_src);
1718 break;
1720 BKE_light_linking_copy_blocker_collection(bmain, *ob_dst, *ob_src);
1721 break;
1722 }
1723 }
1724 }
1725 }
1727
1728 if (type == MAKE_LINKS_GROUP) {
1729 if (ob_collections) {
1730 BLI_linklist_free(ob_collections, nullptr);
1731 }
1732
1733 if (is_cycle) {
1734 BKE_report(op->reports, RPT_WARNING, "Skipped some collections because of cycle detected");
1735 }
1736 }
1737
1738 if (is_lib) {
1739 BKE_report(op->reports, RPT_WARNING, "Skipped editing library object data");
1740 }
1741
1746
1747 return OPERATOR_FINISHED;
1748}
1749
1751{
1752 PropertyRNA *prop;
1753
1754 /* identifiers */
1755 ot->name = "Link Objects to Scene";
1756 ot->description = "Link selection to another scene";
1757 ot->idname = "OBJECT_OT_make_links_scene";
1758
1759 /* API callbacks. */
1762 /* better not run the poll check */
1763
1764 /* flags */
1766
1767 /* properties */
1768 prop = RNA_def_enum(ot->srna, "scene", rna_enum_dummy_NULL_items, 0, "Scene", "");
1771 ot->prop = prop;
1772}
1773
1775{
1776 static const EnumPropertyItem make_links_items[] = {
1777 {MAKE_LINKS_OBDATA, "OBDATA", 0, "Link Object Data", "Replace assigned Object Data"},
1778 {MAKE_LINKS_MATERIALS, "MATERIAL", 0, "Link Materials", "Replace assigned Materials"},
1780 "ANIMATION",
1781 0,
1782 "Link Animation Data",
1783 "Replace assigned Animation Data"},
1784 {MAKE_LINKS_GROUP, "GROUPS", 0, "Link Collections", "Replace assigned Collections"},
1786 "DUPLICOLLECTION",
1787 0,
1788 "Link Instance Collection",
1789 "Replace assigned Collection Instance"},
1790 {MAKE_LINKS_FONTS, "FONTS", 0, "Link Fonts to Text", "Replace Text object Fonts"},
1792 {MAKE_LINKS_MODIFIERS, "MODIFIERS", 0, "Copy Modifiers", "Replace Modifiers"},
1793 {MAKE_LINKS_CONSTRAINTS, "CONSTRAINTS", 0, "Copy Constraints", "Replace Constraints"},
1795 "EFFECTS",
1796 0,
1797 "Copy Grease Pencil Effects",
1798 "Replace Grease Pencil Effects"},
1800 "LIGHT_LINKING",
1801 0,
1802 "Copy Light Linking",
1803 "Replace assigned Light Linking collection"},
1805 "SHADOW_LINKING",
1806 0,
1807 "Copy Shadow Linking",
1808 "Replace assigned Shadow Linking collection"},
1809 {0, nullptr, 0, nullptr, nullptr},
1810 };
1811
1812 /* identifiers */
1813 ot->name = "Link/Transfer Data";
1814 ot->description = "Transfer data from active object to selected objects";
1815 ot->idname = "OBJECT_OT_make_links_data";
1816
1817 /* API callbacks. */
1819 /* The object must not be in edit-mode because multiple objects in edit-mode
1820 * sharing data is an invalid state which can cause crashes. See: #160956. */
1822
1823 /* flags */
1825
1826 /* properties */
1827 ot->prop = RNA_def_enum(ot->srna, "type", make_links_items, 0, "Type", "");
1828}
1829
1831
1832/* ------------------------------------------------------------------- */
1835
1837{
1838 /* NOTE: When dealing with linked data, we always make a local copy of it.
1839 * While in theory we could rather make it local when it only has one user, this is difficult
1840 * in practice with current code of this function. */
1841 return (id != nullptr && (id->us > 1 || ID_IS_LINKED(id)));
1842}
1843
1845 Collection *collection,
1846 const bool do_collection)
1847{
1848 if (do_collection) {
1849 BKE_libblock_relink_to_newid(bmain, &collection->id, 0);
1850 }
1851
1852 for (CollectionObject *cob = collection->gobject.first(); cob != nullptr; cob = cob->next) {
1853 BKE_libblock_relink_to_newid(bmain, &cob->ob->id, 0);
1854 }
1855
1856 for (CollectionChild &child : collection->children) {
1857 libblock_relink_collection(bmain, child.collection, true);
1858 }
1859}
1860
1862 Scene *scene,
1863 Collection *collection,
1864 const int flag,
1865 const bool copy_collections,
1866 const bool is_master_collection)
1867{
1868 /* Generate new copies for objects in given collection and all its children, * and
1869 * optionally also copy collections themselves. */
1870 if (copy_collections && !is_master_collection) {
1871 Collection *collection_new = id_cast<Collection *>(BKE_id_copy_ex(
1872 bmain, &collection->id, nullptr, LIB_ID_COPY_DEFAULT | LIB_ID_COPY_ACTIONS));
1873 id_us_min(&collection_new->id);
1874 collection = id_cast<Collection *>(ID_NEW_SET(collection, collection_new));
1875 }
1876
1877 /* We do not remap to new objects here, this is done in separate step. */
1878 for (CollectionObject &cob : collection->gobject) {
1879 Object *ob = cob.ob;
1880 /* an object may be in more than one collection */
1881 if ((ob->id.newid == nullptr) && ((ob->flag & flag) == flag)) {
1882 if (!ID_IS_LINKED(ob) && BKE_object_scenes_users_get(bmain, ob) > 1) {
1883 ID_NEW_SET(
1884 ob,
1885 BKE_id_copy_ex(bmain, &ob->id, nullptr, LIB_ID_COPY_DEFAULT | LIB_ID_COPY_ACTIONS));
1886 id_us_min(ob->id.newid);
1887 }
1888 }
1889 }
1890
1891 /* Since master collection has already be duplicated as part of scene copy, * we do not
1892 * duplicate it here. However, this means its children need to be re-added manually here, *
1893 * otherwise their parent lists are empty (which will lead to crashes, see #63101). */
1894 CollectionChild *child_next, *child = collection->children.first();
1895 CollectionChild *orig_child_last = collection->children.last();
1896 for (; child != nullptr; child = child_next) {
1897 child_next = child->next;
1898 Collection *collection_child_new = single_object_users_collection(
1899 bmain, scene, child->collection, flag, copy_collections, false);
1900
1901 if (is_master_collection && copy_collections && child->collection != collection_child_new) {
1902 /* We do not want a collection sync here, our collections are in a complete uninitialized
1903 * state currently. With current code, that would lead to a memory leak - because of
1904 * reasons. It would be a useless loss of computing anyway, since caller has to fully
1905 * refresh view-layers/collections caching at the end. */
1906 BKE_collection_child_add_no_sync(bmain, collection, collection_child_new);
1907 BLI_remlink(&collection->children, child);
1908 MEM_delete(child);
1909 if (child == orig_child_last) {
1910 break;
1911 }
1912 }
1913 }
1914
1915 return collection;
1916}
1917
1918/* Warning, sets ID->newid pointers of objects and collections, but does not clear them. */
1920 Main *bmain, Scene *scene, View3D *v3d, const int flag, const bool copy_collections)
1921{
1922 /* duplicate all the objects of the scene (and matching collections, if required). */
1923 Collection *master_collection = scene->master_collection;
1924 single_object_users_collection(bmain, scene, master_collection, flag, copy_collections, true);
1925
1926 /* Will also handle the master collection. */
1927 BKE_libblock_relink_to_newid(bmain, &scene->id, 0);
1928
1929 /* Collection and object pointers in collections */
1930 libblock_relink_collection(bmain, scene->master_collection, false);
1931
1932 /* We also have to handle runtime things in UI. */
1933 if (v3d) {
1934 ID_NEW_REMAP(v3d->camera);
1935 }
1936
1937 /* Making single user may affect other scenes if they share
1938 * with current one some collections in their ViewLayer. */
1940}
1941
1942void object_single_user_make(Main *bmain, Scene *scene, Object *ob)
1943{
1944 FOREACH_SCENE_OBJECT_BEGIN (scene, ob_iter) {
1945 ob_iter->flag &= ~OB_DONE;
1946 }
1948
1949 /* tag only the one object */
1950 ob->flag |= OB_DONE;
1951
1952 single_object_users(bmain, scene, nullptr, OB_DONE, false);
1954}
1955
1957 Main *bmain, Scene *scene, ViewLayer *view_layer, View3D *v3d, const int flag)
1958{
1959 ID *id;
1960
1961 FOREACH_OBJECT_FLAG_BEGIN (bmain, scene, view_layer, v3d, flag, ob) {
1962 if (BKE_id_is_editable(bmain, &ob->id)) {
1963 id = ob->data;
1966
1967 switch (ob->type) {
1968 case OB_EMPTY:
1969 ob->data = ID_NEW_SET(ob->data,
1970 BKE_id_copy_ex(bmain,
1971 static_cast<const ID *>(ob->data),
1972 nullptr,
1974 break;
1975 case OB_LAMP:
1976 ob->data = ID_NEW_SET(ob->data,
1977 BKE_id_copy_ex(bmain,
1978 static_cast<const ID *>(ob->data),
1979 nullptr,
1981 break;
1982 case OB_CAMERA: {
1983 ob->data = ID_NEW_SET(ob->data,
1984 BKE_id_copy_ex(bmain,
1985 static_cast<const ID *>(ob->data),
1986 nullptr,
1988 Camera *cam = id_cast<Camera *>(ob->data);
1989 ID_NEW_REMAP(cam->dof.focus_object);
1990 break;
1991 }
1992 case OB_MESH:
1993 /* Needed to remap texcomesh below. */
1994 ob->data = ID_NEW_SET(ob->data,
1995 BKE_id_copy_ex(bmain,
1996 static_cast<const ID *>(ob->data),
1997 nullptr,
1999 break;
2000 case OB_MBALL:
2001 ob->data = ID_NEW_SET(ob->data,
2002 BKE_id_copy_ex(bmain,
2003 static_cast<const ID *>(ob->data),
2004 nullptr,
2006 break;
2007 case OB_CURVES_LEGACY:
2008 case OB_SURF:
2009 case OB_FONT: {
2010 ob->data = ID_NEW_SET(ob->data,
2011 BKE_id_copy_ex(bmain,
2012 static_cast<const ID *>(ob->data),
2013 nullptr,
2015 Curve *cu = id_cast<Curve *>(ob->data);
2016 ID_NEW_REMAP(cu->bevobj);
2018 break;
2019 }
2020 case OB_LATTICE:
2021 ob->data = ID_NEW_SET(ob->data,
2022 BKE_id_copy_ex(bmain,
2023 static_cast<const ID *>(ob->data),
2024 nullptr,
2026 break;
2027 case OB_ARMATURE:
2029 ob->data = ID_NEW_SET(ob->data,
2030 BKE_id_copy_ex(bmain,
2031 static_cast<const ID *>(ob->data),
2032 nullptr,
2034 BKE_pose_rebuild(bmain, ob, id_cast<bArmature *>(ob->data), true);
2035 break;
2036 case OB_SPEAKER:
2037 ob->data = ID_NEW_SET(ob->data,
2038 BKE_id_copy_ex(bmain,
2039 static_cast<const ID *>(ob->data),
2040 nullptr,
2042 break;
2043 case OB_LIGHTPROBE:
2044 ob->data = ID_NEW_SET(ob->data,
2045 BKE_id_copy_ex(bmain,
2046 static_cast<const ID *>(ob->data),
2047 nullptr,
2049 break;
2050 case OB_CURVES:
2051 ob->data = ID_NEW_SET(ob->data,
2052 BKE_id_copy_ex(bmain,
2053 static_cast<const ID *>(ob->data),
2054 nullptr,
2056 break;
2057 case OB_POINTCLOUD:
2058 ob->data = ID_NEW_SET(ob->data,
2059 BKE_id_copy_ex(bmain,
2060 static_cast<const ID *>(ob->data),
2061 nullptr,
2063 break;
2064 case OB_VOLUME:
2065 ob->data = ID_NEW_SET(ob->data,
2066 BKE_id_copy_ex(bmain,
2067 static_cast<const ID *>(ob->data),
2068 nullptr,
2070 break;
2071 case OB_GREASE_PENCIL:
2072 ob->data = ID_NEW_SET(ob->data,
2073 BKE_id_copy_ex(bmain,
2074 static_cast<const ID *>(ob->data),
2075 nullptr,
2077 break;
2078 default:
2079 printf("ERROR %s: cannot copy %s\n", __func__, id->name);
2080 BLI_assert_msg(0, "This should never happen.");
2081
2082 /* We need to end the FOREACH_OBJECT_FLAG_BEGIN iterator to prevent memory leak. */
2083 BKE_scene_objects_iterator_end(&iter_macro);
2084 return;
2085 }
2086
2087 id_us_min(id);
2088 }
2089 }
2090 }
2092
2093 Mesh *mesh = bmain->meshes.first();
2094 while (mesh) {
2095 ID_NEW_REMAP(mesh->texcomesh);
2096 mesh = static_cast<Mesh *>(mesh->id.next);
2097 }
2098}
2099
2100void single_obdata_user_make(Main *bmain, Scene *scene, Object *ob)
2101{
2102 FOREACH_SCENE_OBJECT_BEGIN (scene, ob_iter) {
2103 ob_iter->flag &= ~OB_DONE;
2104 }
2106
2107 /* Tag only the one object. */
2108 ob->flag |= OB_DONE;
2109
2110 single_obdata_users(bmain, scene, nullptr, nullptr, OB_DONE);
2111}
2112
2114 Main *bmain, Scene *scene, ViewLayer *view_layer, View3D *v3d, const int flag)
2115{
2116 FOREACH_OBJECT_FLAG_BEGIN (bmain, scene, view_layer, v3d, flag, ob) {
2117 if (BKE_id_is_editable(bmain, &ob->id)) {
2118 AnimData *adt = BKE_animdata_from_id(&ob->id);
2119 if (adt == nullptr) {
2120 continue;
2121 }
2122
2123 ID *id_act = id_cast<ID *>(adt->action);
2124 if (single_data_needs_duplication(id_act)) {
2127 }
2128 }
2129 }
2131}
2132
2134 Main *bmain, Scene *scene, ViewLayer *view_layer, View3D *v3d, const int flag)
2135{
2136 FOREACH_OBJECT_FLAG_BEGIN (bmain, scene, view_layer, v3d, flag, ob) {
2137 if (BKE_id_is_editable(bmain, &ob->id) && ob->data != nullptr) {
2138 ID *id_obdata = ob->data;
2139 AnimData *adt = BKE_animdata_from_id(id_obdata);
2140 if (adt == nullptr) {
2141 continue;
2142 }
2143
2144 ID *id_act = id_cast<ID *>(adt->action);
2145 if (single_data_needs_duplication(id_act)) {
2148 }
2149 }
2150 }
2152}
2153
2155 Main *bmain, Scene *scene, ViewLayer *view_layer, View3D *v3d, const int flag)
2156{
2157 Material *ma, *man;
2158 int a;
2159
2160 FOREACH_OBJECT_FLAG_BEGIN (bmain, scene, view_layer, v3d, flag, ob) {
2161 if (BKE_id_is_editable(bmain, &ob->id)) {
2162 const bool is_obdata_editable = ob->data ? BKE_id_is_editable(bmain, ob->data) : false;
2163 for (a = 1; a <= ob->totcol; a++) {
2164 if (!ob->matbits[a - 1] && !is_obdata_editable) {
2165 /* Cannot edit material usage of obdata if it's not editable (e.g. local object using a
2166 * linked mesh). See also #161211. */
2167 continue;
2168 }
2169 ma = BKE_object_material_get(ob, short(a));
2170 if (single_data_needs_duplication(&ma->id)) {
2171 man = id_cast<Material *>(
2172 BKE_id_copy_ex(bmain, &ma->id, nullptr, LIB_ID_COPY_DEFAULT | LIB_ID_COPY_ACTIONS));
2173 man->id.us = 0;
2174 BKE_object_material_assign(bmain, ob, man, short(a), BKE_MAT_ASSIGN_EXISTING);
2175 }
2176 }
2177 }
2178 }
2180}
2181
2183
2184/* ------------------------------------------------------------------- */
2187
2188enum {
2193};
2194
2196{
2197 ID **id_pointer = cb_data->id_pointer;
2198 if (*id_pointer) {
2199 (*id_pointer)->tag &= ~ID_TAG_DOIT;
2200 }
2201
2202 return IDWALK_RET_NOP;
2203}
2204
2205static void tag_localizable_objects(bContext *C, const int mode)
2206{
2207 Main *bmain = CTX_data_main(C);
2208
2209 BKE_main_id_tag_all(bmain, ID_TAG_DOIT, false);
2210
2211 /* Set ID_TAG_DOIT flag for all selected objects, so next we can check whether
2212 * object is gonna to become local or not.
2213 */
2214 CTX_DATA_BEGIN (C, Object *, object, selected_objects) {
2215 object->id.tag |= ID_TAG_DOIT;
2216
2217 /* If obdata is also going to become local, mark it as such too. */
2218 if (mode == MAKE_LOCAL_SELECT_OBDATA && object->data) {
2219 ID *data_id = object->data;
2220 data_id->tag |= ID_TAG_DOIT;
2221 }
2222 }
2224
2225 /* Also forbid making objects local if other library objects are using
2226 * them for modifiers or constraints.
2227 *
2228 * FIXME This is ignoring all other linked ID types potentially using the selected tagged
2229 * objects! Probably works fine in most 'usual' cases though.
2230 */
2231 for (Object *object = bmain->objects.first(); object;
2232 object = static_cast<Object *>(object->id.next))
2233 {
2234 if ((object->id.tag & ID_TAG_DOIT) == 0 && ID_IS_LINKED(object)) {
2236 nullptr, &object->id, tag_localizable_looper, nullptr, IDWALK_READONLY);
2237 }
2238 if (object->data) {
2239 ID *data_id = object->data;
2240 if ((data_id->tag & ID_TAG_DOIT) == 0 && ID_IS_LINKED(data_id)) {
2242 nullptr, data_id, tag_localizable_looper, nullptr, IDWALK_READONLY);
2243 }
2244 }
2245 }
2246
2247 /* TODO(sergey): Drivers targets? */
2248}
2249
2255 const Scene *scene,
2256 ViewLayer *view_layer,
2257 Collection *collection)
2258{
2259 Object *ob;
2260 bool changed = false;
2261
2262 for (ob = bmain->objects.first(); ob; ob = static_cast<Object *>(ob->id.next)) {
2263 if (ID_IS_LINKED(ob) && (ob->id.us == 0)) {
2264 Base *base;
2265
2266 id_us_plus(&ob->id);
2267
2268 BKE_collection_object_add(bmain, collection, ob);
2269 BKE_view_layer_synced_ensure(*bmain, scene, view_layer);
2270 base = BKE_view_layer_base_find(view_layer, ob);
2271 base_select(base, BA_SELECT);
2273
2274 changed = true;
2275 }
2276 }
2277
2278 return changed;
2279}
2280
2281static void make_local_animdata_tag_strips(ListBaseT<NlaStrip> *strips)
2282{
2283 for (NlaStrip &strip : *strips) {
2284 if (strip.act) {
2285 strip.act->id.tag &= ~ID_TAG_PRE_EXISTING;
2286 }
2287
2288 make_local_animdata_tag_strips(&strip.strips);
2289 }
2290}
2291
2292/* Tag all actions used by given animdata to be made local. */
2294{
2295 if (adt) {
2296 /* Actions - Active and Temp */
2297 if (adt->action) {
2299 }
2300 if (adt->tmpact) {
2302 }
2303
2304 /* Drivers */
2305 /* TODO: need to handle the ID-targets too? */
2306
2307 /* NLA Data */
2308 for (NlaTrack &nlt : adt->nla_tracks) {
2310 }
2311 }
2312}
2313
2315{
2316 if (ma) {
2317 ma->id.tag &= ~ID_TAG_PRE_EXISTING;
2319
2320 /* About node-trees: root one is made local together with material,
2321 * others we keep linked (for now). */
2322 }
2323}
2324
2326{
2327 Main *bmain = CTX_data_main(C);
2328 Material *ma, ***matarar;
2329 const int mode = RNA_enum_get(op->ptr, "type");
2330 int a;
2331
2332 /* NOTE: we (ab)use ID_TAG_PRE_EXISTING to cherry pick which ID to make local... */
2333 if (mode == MAKE_LOCAL_ALL) {
2334 const Scene *scene = CTX_data_scene(C);
2335 ViewLayer *view_layer = CTX_data_view_layer(C);
2336 Collection *collection = CTX_data_collection(C);
2337
2339
2340 /* De-select so the user can differentiate newly instanced from existing objects. */
2341 BKE_view_layer_base_deselect_all(*bmain, scene, view_layer);
2342
2343 if (make_local_all__instance_indirect_unused(bmain, scene, view_layer, collection)) {
2344 BKE_report(op->reports,
2345 RPT_INFO,
2346 "Orphan library objects added to the current scene to avoid loss");
2347 }
2348 }
2349 else {
2352
2353 CTX_DATA_BEGIN (C, Object *, ob, selected_objects) {
2354 if ((ob->id.tag & ID_TAG_DOIT) == 0) {
2355 continue;
2356 }
2357
2358 ob->id.tag &= ~ID_TAG_PRE_EXISTING;
2360 for (ParticleSystem &psys : ob->particlesystem) {
2362 }
2363
2365 for (a = 0; a < ob->totcol; a++) {
2366 ma = ob->mat[a];
2367 if (ma) {
2369 }
2370 }
2371
2372 matarar = BKE_object_material_array_p(ob);
2373 if (matarar) {
2374 for (a = 0; a < ob->totcol; a++) {
2375 ma = (*matarar)[a];
2376 if (ma) {
2378 }
2379 }
2380 }
2381 }
2382
2384 ob->data != nullptr)
2385 {
2386 ID *ob_data = ob->data;
2387 ob_data->tag &= ~ID_TAG_PRE_EXISTING;
2389 }
2390 }
2392 }
2393
2395 bmain, nullptr, nullptr, true, false, true); /* nullptr is all libraries. */
2396
2398 return OPERATOR_FINISHED;
2399}
2400
2402{
2403 static const EnumPropertyItem type_items[] = {
2404 {MAKE_LOCAL_SELECT_OB, "SELECT_OBJECT", 0, "Selected Objects", ""},
2405 {MAKE_LOCAL_SELECT_OBDATA, "SELECT_OBDATA", 0, "Selected Objects and Data", ""},
2407 "SELECT_OBDATA_MATERIAL",
2408 0,
2409 "Selected Objects, Data and Materials",
2410 ""},
2411 {MAKE_LOCAL_ALL, "ALL", 0, "All", ""},
2412 {0, nullptr, 0, nullptr, nullptr},
2413 };
2414
2415 /* identifiers */
2416 ot->name = "Make Local";
2417 ot->description = "Make library linked data-blocks local to this file";
2418 ot->idname = "OBJECT_OT_make_local";
2419
2420 /* API callbacks. */
2421 ot->invoke = WM_menu_invoke;
2422 ot->exec = make_local_exec;
2424
2425 /* flags */
2427
2428 /* properties */
2429 ot->prop = RNA_def_enum(ot->srna, "type", type_items, 0, "Type", "");
2430}
2431
2433
2434/* ------------------------------------------------------------------- */
2437
2439{
2440 /* An object is actually overridable only if it is in at least one local collection.
2441 * Unfortunately 'direct link' flag is not enough here. */
2442 for (Collection &collection : bmain->collections) {
2443 if (!ID_IS_LINKED(&collection) && BKE_collection_has_object(&collection, object)) {
2444 return true;
2445 }
2446 }
2447 for (Scene &scene : bmain->scenes) {
2448 if (!ID_IS_LINKED(&scene) && BKE_collection_has_object(scene.master_collection, object)) {
2449 return true;
2450 }
2451 }
2452 return false;
2453}
2454
2456{
2457 Main *bmain = CTX_data_main(C);
2458 Scene *scene = CTX_data_scene(C);
2459 ViewLayer *view_layer = CTX_data_view_layer(C);
2461 ID *id_root = nullptr;
2462 bool is_override_instancing_object = false;
2463
2464 bool user_overrides_from_selected_objects = false;
2465
2466 if (!ID_IS_LINKED(obact) && obact->instance_collection != nullptr &&
2468 {
2470 BKE_reportf(op->reports,
2472 "Collection '%s' (instantiated by the active object) is not overridable",
2473 obact->instance_collection->id.name + 2);
2474 return OPERATOR_CANCELLED;
2475 }
2476
2477 id_root = &obact->instance_collection->id;
2478 is_override_instancing_object = true;
2479 user_overrides_from_selected_objects = false;
2480 }
2481 else if (!make_override_library_object_overridable_check(bmain, obact)) {
2482 const int i = RNA_property_int_get(op->ptr, op->type->prop);
2483 const uint collection_session_uid = *(reinterpret_cast<const uint *>(&i));
2484 if (collection_session_uid == MAIN_ID_SESSION_UID_UNSET) {
2485 BKE_reportf(op->reports,
2487 "Could not find an overridable root hierarchy for object '%s'",
2488 obact->id.name + 2);
2489 return OPERATOR_CANCELLED;
2490 }
2491 Collection *collection = static_cast<Collection *>(
2493 &collection_session_uid,
2494 sizeof(collection_session_uid),
2495 offsetof(ID, session_uid)));
2496 id_root = &collection->id;
2497 user_overrides_from_selected_objects = true;
2498 }
2499 /* Else, poll func ensures us that ID_IS_LINKED(obact) is true, or that it is already an
2500 * existing liboverride. */
2501 else {
2503 id_root = &obact->id;
2504 user_overrides_from_selected_objects = true;
2505 }
2506
2507 /* Make already existing selected liboverrides editable. */
2508 bool is_active_override = false;
2509 FOREACH_SELECTED_OBJECT_BEGIN (view_layer, CTX_wm_view3d(C), ob_iter) {
2510 if (ID_IS_OVERRIDE_LIBRARY_REAL(ob_iter) && !ID_IS_LINKED(ob_iter)) {
2511 ob_iter->id.override_library->flag &= ~LIBOVERRIDE_FLAG_SYSTEM_DEFINED;
2512 is_active_override = is_active_override || (&ob_iter->id == id_root);
2514 }
2515 }
2517 /* If the active object is a liboverride, there is no point going further, since in the weird
2518 * case where some other selected objects would be linked ones, there is no way to properly
2519 * create overrides for them currently.
2520 *
2521 * Could be added later if really needed, but would rather avoid that extra complexity here. */
2522 if (is_active_override) {
2523 return OPERATOR_FINISHED;
2524 }
2525
2527 const bool do_fully_editable = false;
2528
2529 std::unique_ptr<Set<uint32_t>> user_overrides_objects_uids =
2530 do_fully_editable ? nullptr : std::make_unique<Set<uint32_t>>();
2531
2532 if (do_fully_editable) {
2533 /* Pass. */
2534 }
2535 else if (user_overrides_from_selected_objects) {
2536 /* Only selected objects can be 'user overrides'. */
2537 FOREACH_SELECTED_OBJECT_BEGIN (view_layer, CTX_wm_view3d(C), ob_iter) {
2538 user_overrides_objects_uids->add(ob_iter->id.session_uid);
2539 }
2541 }
2542 else {
2543 /* Only armatures inside the root collection (and their children) can be 'user overrides'. */
2545 if (ob_iter->type == OB_ARMATURE) {
2546 user_overrides_objects_uids->add(ob_iter->id.session_uid);
2547 }
2548 }
2550 }
2551
2552 BKE_main_id_tag_all(bmain, ID_TAG_DOIT, false);
2553
2554 /* For the time being, replace selected linked objects by their overrides in all collections.
2555 * While this may not be the absolute best behavior in all cases, in most common one this
2556 * should match the expected result. */
2557 if (user_overrides_objects_uids != nullptr) {
2558 for (Collection &coll_iter : bmain->collections) {
2559 if (ID_IS_LINKED(&coll_iter)) {
2560 continue;
2561 }
2562 for (CollectionObject &coll_ob_iter : coll_iter.gobject) {
2563 if (user_overrides_objects_uids->contains(coll_ob_iter.ob->id.session_uid)) {
2564 /* Tag for remapping when creating overrides. */
2565 coll_iter.id.tag |= ID_TAG_DOIT;
2566 break;
2567 }
2568 }
2569 }
2570 /* Also tag the Scene itself for remapping when creating overrides (includes the scene's master
2571 * collection too). */
2572 scene->id.tag |= ID_TAG_DOIT;
2573 }
2574
2575 ID *id_root_override;
2576 const bool success = BKE_lib_override_library_create(bmain,
2577 scene,
2578 view_layer,
2579 nullptr,
2580 id_root,
2581 id_root,
2582 &obact->id,
2583 &id_root_override,
2584 do_fully_editable);
2585
2586 if (!do_fully_editable) {
2587 /* Define liboverrides from selected/validated objects as user defined. */
2588 ID *id_hierarchy_root_override = id_root_override->override_library->hierarchy_root;
2589 ID *id_iter;
2590 FOREACH_MAIN_ID_BEGIN (bmain, id_iter) {
2591 if (ID_IS_LINKED(id_iter) || !ID_IS_OVERRIDE_LIBRARY_REAL(id_iter) ||
2592 id_iter->override_library->hierarchy_root != id_hierarchy_root_override)
2593 {
2594 continue;
2595 }
2596 if (user_overrides_objects_uids->contains(id_iter->override_library->reference->session_uid))
2597 {
2599 }
2600 }
2602 }
2603
2604 if (success) {
2605 if (is_override_instancing_object) {
2606 /* Remove the instance empty from this scene, the items now have an overridden collection
2607 * instead. */
2608 base_free_and_unlink(bmain, scene, obact);
2609 }
2610 else {
2611 /* Remove the found root ID from the view layer. */
2612 switch (GS(id_root->name)) {
2613 case ID_GR: {
2614 Collection *collection_root = id_cast<Collection *>(id_root);
2615 for (CollectionParent &collection_parent :
2616 collection_root->runtime->parents.items_mutable())
2617 {
2618 if (ID_IS_LINKED(collection_parent.collection) ||
2619 !BKE_view_layer_has_collection(view_layer, collection_parent.collection))
2620 {
2621 continue;
2622 }
2623 BKE_collection_child_remove(bmain, collection_parent.collection, collection_root);
2624 }
2625 break;
2626 }
2627 case ID_OB: {
2628 /* TODO: Not sure how well we can handle this case, when we don't have the collections
2629 * as reference containers... */
2630 break;
2631 }
2632 default:
2633 break;
2634 }
2635 }
2636 }
2637
2642
2643 return success ? OPERATOR_FINISHED : OPERATOR_CANCELLED;
2644}
2645
2646/* Set the object to override. */
2648 wmOperator *op,
2649 const wmEvent * /*event*/)
2650{
2651 Main *bmain = CTX_data_main(C);
2652 Scene *scene = CTX_data_scene(C);
2653 ViewLayer *view_layer = CTX_data_view_layer(C);
2654 Object *obact = context_active_object(C);
2655
2656 /* Sanity checks. */
2657 if (!scene || ID_IS_LINKED(scene) || !obact) {
2658 return OPERATOR_CANCELLED;
2659 }
2660
2661 if ((!ID_IS_LINKED(obact) && obact->instance_collection != nullptr &&
2664 {
2665 return make_override_library_exec(C, op);
2666 }
2667
2668 if (!ID_IS_LINKED(obact)) {
2669 if (ID_IS_OVERRIDE_LIBRARY_REAL(obact)) {
2670 return make_override_library_exec(C, op);
2671 }
2672 BKE_report(op->reports, RPT_ERROR, "Cannot make library override from a local object");
2673 return OPERATOR_CANCELLED;
2674 }
2675
2676 VectorSet<Collection *> potential_root_collections;
2677 for (Collection &collection : bmain->collections) {
2678 /* Only check for linked collections from the same library, in the current view-layer. */
2679 if (!ID_IS_LINKED(&collection.id) || collection.id.lib != obact->id.lib ||
2680 !BKE_view_layer_has_collection(view_layer, &collection))
2681 {
2682 continue;
2683 }
2684 if (!BKE_collection_has_object_recursive(&collection, obact)) {
2685 continue;
2686 }
2687 if (potential_root_collections.is_empty()) {
2688 potential_root_collections.add_new(&collection);
2689 }
2690 else {
2691 bool has_parents_in_potential_roots = false;
2692 bool is_potential_root = false;
2693 for (auto *collection_root_iter : potential_root_collections) {
2694 if (BKE_collection_has_collection(collection_root_iter, &collection)) {
2695 BLI_assert_msg(!BKE_collection_has_collection(&collection, collection_root_iter),
2696 "Invalid loop in collection hierarchy");
2697 /* Current potential root is already 'better' (higher up in the collection hierarchy)
2698 * than current collection, nothing else to do. */
2699 has_parents_in_potential_roots = true;
2700 }
2701 else if (BKE_collection_has_collection(&collection, collection_root_iter)) {
2702 BLI_assert_msg(!BKE_collection_has_collection(collection_root_iter, &collection),
2703 "Invalid loop in collection hierarchy");
2704 /* Current potential root is in the current collection's hierarchy, so the later is a
2705 * better candidate as root collection. */
2706 is_potential_root = true;
2707 potential_root_collections.remove(collection_root_iter);
2708 }
2709 else {
2710 /* Current potential root is not found in current collection's hierarchy, so the later
2711 * is a potential candidate as root collection. */
2712 is_potential_root = true;
2713 }
2714 }
2715 /* Only add the current collection as potential root if it is not a descendant of any
2716 * already known potential root collections. */
2717 if (is_potential_root && !has_parents_in_potential_roots) {
2718 potential_root_collections.add_new(&collection);
2719 }
2720 }
2721 }
2722
2723 if (potential_root_collections.is_empty()) {
2725 return make_override_library_exec(C, op);
2726 }
2727 if (potential_root_collections.size() == 1) {
2728 Collection *collection_root = potential_root_collections.pop();
2730 op->ptr, op->type->prop, *(reinterpret_cast<int *>(&collection_root->id.session_uid)));
2731 return make_override_library_exec(C, op);
2732 }
2733
2734 BKE_reportf(op->reports,
2735 RPT_ERROR,
2736 "Too many potential root collections (%d) for the override hierarchy, "
2737 "please use the Outliner instead",
2738 int(potential_root_collections.size()));
2739 return OPERATOR_CANCELLED;
2740}
2741
2743{
2744 Base *base_act = CTX_data_active_base(C);
2745 /* If the active object is not selected, do nothing (operators rely on selection too, they will
2746 * misbehave if the active object is not also selected, see e.g. #120701). */
2747 if ((base_act == nullptr) || ((base_act->flag & BASE_SELECTED) == 0)) {
2748 return false;
2749 }
2750
2751 /* Object must be directly linked to be overridable. */
2752 Object *obact = base_act->object;
2753 return (
2754 ED_operator_objectmode(C) && obact != nullptr &&
2755 (ID_IS_LINKED(obact) || ID_IS_OVERRIDE_LIBRARY(obact) ||
2756 (obact->instance_collection != nullptr &&
2758}
2759
2761{
2762 /* identifiers */
2763 ot->name = "Make Library Override";
2764 ot->description =
2765 "Create a local override of the selected linked objects, and their hierarchy of "
2766 "dependencies";
2767 ot->idname = "OBJECT_OT_make_override_library";
2768
2769 /* API callbacks. */
2773
2774 /* flags */
2776
2777 /* properties */
2778 PropertyRNA *prop;
2779 prop = RNA_def_int(ot->srna,
2780 "collection",
2782 INT_MIN,
2783 INT_MAX,
2784 "Override Collection",
2785 "Session UID of the directly linked collection containing the selected "
2786 "object, to make an override from",
2787 INT_MIN,
2788 INT_MAX);
2790 ot->prop = prop;
2791}
2792
2794
2795/* ------------------------------------------------------------------- */
2798
2800{
2801 Base *base_act = CTX_data_active_base(C);
2802 /* If the active object is not selected, do nothing (operators rely on selection too, they will
2803 * misbehave if the active object is not also selected, see e.g. #120701). */
2804 if ((base_act == nullptr) || ((base_act->flag & BASE_SELECTED) == 0)) {
2805 return false;
2806 }
2807
2808 /* Object must be local and an override. */
2809 Object *obact = base_act->object;
2810 return (ED_operator_objectmode(C) && obact != nullptr && !ID_IS_LINKED(obact) &&
2811 ID_IS_OVERRIDE_LIBRARY(obact));
2812}
2813
2815{
2816 Main *bmain = CTX_data_main(C);
2817
2818 /* Reset all selected liboverrides. */
2820 if (ID_IS_OVERRIDE_LIBRARY_REAL(ob_iter) && !ID_IS_LINKED(ob_iter)) {
2821 BKE_lib_override_library_id_reset(bmain, &ob_iter->id, false);
2822 }
2823 }
2825
2829
2830 return OPERATOR_FINISHED;
2831}
2832
2834{
2835 /* identifiers */
2836 ot->name = "Reset Library Override";
2837 ot->description = "Reset the selected local overrides to their linked references values";
2838 ot->idname = "OBJECT_OT_reset_override_library";
2839
2840 /* API callbacks. */
2843
2844 /* flags */
2846}
2847
2849
2850/* ------------------------------------------------------------------- */
2853
2855{
2856 Main *bmain = CTX_data_main(C);
2857 ViewLayer *view_layer = CTX_data_view_layer(C);
2858 Scene *scene = CTX_data_scene(C);
2859 LinkNode *todo_objects = nullptr, *todo_object_iter;
2860
2861 /* Make already existing selected liboverrides editable. */
2862 FOREACH_SELECTED_OBJECT_BEGIN (view_layer, CTX_wm_view3d(C), ob_iter) {
2863 if (ID_IS_LINKED(ob_iter)) {
2864 continue;
2865 }
2866 BLI_linklist_prepend_alloca(&todo_objects, ob_iter);
2867 }
2869
2870 for (todo_object_iter = todo_objects; todo_object_iter != nullptr;
2871 todo_object_iter = todo_object_iter->next)
2872 {
2873 Object *ob_iter = static_cast<Object *>(todo_object_iter->link);
2874 if (BKE_lib_override_library_is_hierarchy_leaf(bmain, &ob_iter->id)) {
2875 bool do_remap_active = false;
2876 BKE_view_layer_synced_ensure(*bmain, scene, view_layer);
2877 if (BKE_view_layer_active_object_get(view_layer) == ob_iter) {
2878 do_remap_active = true;
2879 }
2880 BKE_libblock_remap(bmain,
2881 &ob_iter->id,
2882 ob_iter->id.override_library->reference,
2884 if (do_remap_active) {
2885 BKE_view_layer_synced_ensure(*bmain, scene, view_layer);
2886 Object *ref_object = id_cast<Object *>(ob_iter->id.override_library->reference);
2887 Base *basact = BKE_view_layer_base_find(view_layer, ref_object);
2888 if (basact != nullptr) {
2889 view_layer->basact = basact;
2890 }
2892 }
2893 BKE_id_delete(bmain, &ob_iter->id);
2894 }
2895 else {
2896 BKE_lib_override_library_id_reset(bmain, &ob_iter->id, true);
2897 }
2898 }
2899
2904
2905 return OPERATOR_FINISHED;
2906}
2907
2909{
2910 /* identifiers */
2911 ot->name = "Clear Library Override";
2912 ot->description =
2913 "Delete the selected local overrides and relink their usages to the linked data-blocks if "
2914 "possible, else reset them and mark them as non editable";
2915 ot->idname = "OBJECT_OT_clear_override_library";
2916
2917 /* API callbacks. */
2920
2921 /* flags */
2923}
2924
2926
2927/* ------------------------------------------------------------------- */
2930
2931enum {
2934};
2935
2937{
2938 Main *bmain = CTX_data_main(C);
2939 Scene *scene = CTX_data_scene(C);
2940 ViewLayer *view_layer = CTX_data_view_layer(C);
2941 View3D *v3d = CTX_wm_view3d(C); /* ok if this is nullptr */
2942 const int flag = (RNA_enum_get(op->ptr, "type") == MAKE_SINGLE_USER_SELECTED) ? SELECT : 0;
2943 const bool copy_collections = false;
2944 bool update_deps = false;
2945
2946 if (RNA_boolean_get(op->ptr, "object")) {
2947 if (flag == SELECT) {
2948 BKE_view_layer_selected_objects_tag(*bmain, scene, view_layer, OB_DONE);
2949 single_object_users(bmain, scene, v3d, OB_DONE, copy_collections);
2950 }
2951 else {
2952 single_object_users(bmain, scene, v3d, 0, copy_collections);
2953 }
2954
2955 /* needed since object relationships may have changed */
2956 update_deps = true;
2957 }
2958
2959 if (RNA_boolean_get(op->ptr, "obdata")) {
2960 single_obdata_users(bmain, scene, view_layer, v3d, flag);
2961
2962 /* Needed since some IDs were remapped? (incl. mesh->texcomesh, see #73797). */
2963 update_deps = true;
2964 }
2965
2966 if (RNA_boolean_get(op->ptr, "material")) {
2967 single_mat_users(bmain, scene, view_layer, v3d, flag);
2968 }
2969
2970 if (RNA_boolean_get(op->ptr, "animation")) {
2971 single_object_action_users(bmain, scene, view_layer, v3d, flag);
2972 }
2973
2974 if (RNA_boolean_get(op->ptr, "obdata_animation")) {
2975 single_objectdata_action_users(bmain, scene, view_layer, v3d, flag);
2976 }
2977
2979
2981
2982 if (update_deps) {
2984 }
2985
2986 return OPERATOR_FINISHED;
2987}
2988
2990{
2992 C, op, event, IFACE_("Make Selected Objects Single-User"), IFACE_("Make Single"));
2993}
2994
2996{
2997 static const EnumPropertyItem type_items[] = {
2998 {MAKE_SINGLE_USER_SELECTED, "SELECTED_OBJECTS", 0, "Selected Objects", ""},
2999 {MAKE_SINGLE_USER_ALL, "ALL", 0, "All", ""},
3000 {0, nullptr, 0, nullptr, nullptr},
3001 };
3002
3003 /* identifiers */
3004 ot->name = "Make Single User";
3005 ot->description = "Make linked data local to each object";
3006 ot->idname = "OBJECT_OT_make_single_user";
3007
3008 /* Note that the invoke callback is only used from operator search, * otherwise this does
3009 * nothing by default. */
3010
3011 /* API callbacks. */
3015
3016 /* flags */
3018
3019 /* properties */
3020 ot->prop = RNA_def_enum(ot->srna, "type", type_items, MAKE_SINGLE_USER_SELECTED, "Type", "");
3021
3022 RNA_def_boolean(ot->srna, "object", false, "Object", "Make single user objects");
3023 RNA_def_boolean(ot->srna, "obdata", false, "Object Data", "Make single user object data");
3025 ot->srna, "material", false, "Materials", "Make materials local to each data-block");
3027 "animation",
3028 false,
3029 "Object Animation",
3030 "Make object animation data local to each object");
3032 "obdata_animation",
3033 false,
3034 "Object Data Animation",
3035 "Make object data (mesh, curve etc.) animation data local to each object");
3036}
3037
3039
3040/* ------------------------------------------------------------------- */
3043
3044std::string drop_named_material_tooltip(bContext *C, StringRef name, const int mval[2])
3045{
3046 int mat_slot = 0;
3047 Object *ob = ED_view3d_give_material_slot_under_cursor(C, mval, &mat_slot);
3048 if (ob == nullptr) {
3049 return {};
3050 }
3051 mat_slot = max_ii(mat_slot, 1);
3052
3053 Material *prev_mat = BKE_object_material_get(ob, mat_slot);
3054
3055 if (prev_mat) {
3056 return fmt::format(fmt::runtime(TIP_("Drop {} on {} (slot {}, replacing {})")),
3057 name,
3058 ob->id.name + 2,
3059 mat_slot,
3060 prev_mat->id.name + 2);
3061 }
3062 return fmt::format(
3063 fmt::runtime(TIP_("Drop {} on {} (slot {})")), name, ob->id.name + 2, mat_slot);
3064}
3065
3067 wmOperator *op,
3068 const wmEvent *event)
3069{
3070 Main *bmain = CTX_data_main(C);
3071 int mat_slot = 0;
3072 Object *ob = ED_view3d_give_material_slot_under_cursor(C, event->mval, &mat_slot);
3073 mat_slot = max_ii(mat_slot, 1);
3074
3075 Material *ma = id_cast<Material *>(
3077
3078 if (ob == nullptr || ma == nullptr) {
3079 return OPERATOR_CANCELLED;
3080 }
3081
3082 int assign_type = BKE_MAT_ASSIGN_USERPREF;
3083 /* When trying to assign to non-editable object data, assign to the object instead. */
3084 if (BKE_id_is_editable(bmain, &ob->id) && ob->data && !BKE_id_is_editable(bmain, ob->data)) {
3085 assign_type = BKE_MAT_ASSIGN_OBJECT;
3086 }
3087
3088 BKE_object_material_assign(CTX_data_main(C), ob, ma, mat_slot, assign_type);
3089
3091
3095
3096 return OPERATOR_FINISHED;
3097}
3098
3100{
3101 /* identifiers */
3102 ot->name = "Drop Named Material on Object";
3103 ot->idname = "OBJECT_OT_drop_named_material";
3104
3105 /* API callbacks. */
3108
3109 /* flags */
3111
3112 /* properties */
3114}
3115
3117
3118/* ------------------------------------------------------------------- */
3121
3122std::string drop_geometry_nodes_tooltip(bContext *C, PointerRNA *properties, const int mval[2])
3123{
3124 const Object *ob = ED_view3d_give_object_under_cursor(C, mval);
3125 if (ob == nullptr) {
3126 return {};
3127 }
3128
3129 const uint32_t session_uid = RNA_int_get(properties, "session_uid");
3130 const ID *id = BKE_libblock_find_session_uid(CTX_data_main(C), ID_NT, session_uid);
3131 if (!id) {
3132 return {};
3133 }
3134
3135 return fmt::format(fmt::runtime(TIP_("Add modifier with node group \"{}\" on object \"{}\"")),
3136 id->name,
3137 ob->id.name);
3138}
3139
3141{
3142 tree->ensure_interface_cache();
3143 if (!tree->interface_outputs().is_empty()) {
3144 const bNodeTreeInterfaceSocket *first_output = tree->interface_outputs()[0];
3145 if (!first_output) {
3146 BKE_report(op->reports, RPT_ERROR, "The node group must have a geometry output socket");
3147 return false;
3148 }
3149 const bke::bNodeSocketType *typeinfo = first_output->socket_typeinfo();
3150 const eNodeSocketDatatype type = typeinfo ? typeinfo->type : SOCK_CUSTOM;
3151 if (type != SOCK_GEOMETRY) {
3152 BKE_report(op->reports, RPT_ERROR, "The first output must be a geometry socket");
3153 return false;
3154 }
3155 }
3156 return true;
3157}
3158
3160 wmOperator *op,
3161 const wmEvent *event)
3162{
3164 if (!ob) {
3165 return OPERATOR_CANCELLED;
3166 }
3167
3168 Main *bmain = CTX_data_main(C);
3169 Scene *scene = CTX_data_scene(C);
3170
3171 const uint32_t uid = RNA_int_get(op->ptr, "session_uid");
3172 bNodeTree *node_tree = id_cast<bNodeTree *>(BKE_libblock_find_session_uid(bmain, ID_NT, uid));
3173 if (!node_tree) {
3174 return OPERATOR_CANCELLED;
3175 }
3176 if (node_tree->type != NTREE_GEOMETRY) {
3177 BKE_report(op->reports, RPT_ERROR, "Node group must be a geometry node tree");
3178 return OPERATOR_CANCELLED;
3179 }
3180
3181 if (!check_geometry_node_group_sockets(op, node_tree)) {
3182 return OPERATOR_CANCELLED;
3183 }
3184
3185 NodesModifierData *nmd = reinterpret_cast<NodesModifierData *>(
3186 modifier_add(op->reports, bmain, scene, ob, node_tree->id.name + 2, eModifierType_Nodes));
3187 if (!nmd) {
3188 BKE_report(op->reports, RPT_ERROR, "Could not add geometry nodes modifier");
3189 return OPERATOR_CANCELLED;
3190 }
3191
3192 if (!RNA_boolean_get(op->ptr, "show_datablock_in_modifier")) {
3194 }
3196 node_tree->geometry_node_asset_traits &&
3197 (node_tree->geometry_node_asset_traits->flag &
3200
3201 nmd->node_group = node_tree;
3202 id_us_plus(&node_tree->id);
3203 MOD_nodes_update_interface(*bmain, ob, nmd);
3204
3207
3208 return OPERATOR_FINISHED;
3209}
3210
3212{
3213 ot->name = "Drop Geometry Node Group on Object";
3214 ot->idname = "OBJECT_OT_drop_geometry_nodes";
3215
3218
3220
3221 PropertyRNA *prop = RNA_def_int(ot->srna,
3222 "session_uid",
3223 0,
3224 INT32_MIN,
3225 INT32_MAX,
3226 "Session UID",
3227 "Session UID of the geometry node group being dropped",
3228 INT32_MIN,
3229 INT32_MAX);
3232 "show_datablock_in_modifier",
3233 true,
3234 "Show the data-block selector in the modifier",
3235 "");
3236}
3237
3239
3240/* ------------------------------------------------------------------- */
3243
3245{
3246 ID *id;
3247 PropertyPointerRNA pprop;
3248
3250
3251 if (pprop.prop == nullptr) {
3252 BKE_report(op->reports, RPT_ERROR, "Incorrect context for running object data unlink");
3253 return OPERATOR_CANCELLED;
3254 }
3255
3256 id = pprop.ptr.owner_id;
3257
3258 if (GS(id->name) == ID_OB) {
3259 Object *ob = id_cast<Object *>(id);
3260 if (ob->data) {
3261 ID *id_data = ob->data;
3262
3263 if (GS(id_data->name) == ID_IM) {
3264 id_us_min(id_data);
3265 ob->data = nullptr;
3266 }
3267 else {
3268 BKE_report(op->reports, RPT_ERROR, "Cannot unlink this object data");
3269 return OPERATOR_CANCELLED;
3270 }
3271 }
3272 }
3273
3274 RNA_property_update(C, &pprop.ptr, pprop.prop);
3275
3276 return OPERATOR_FINISHED;
3277}
3278
3280{
3281 /* identifiers */
3282 ot->name = "Unlink";
3283 ot->idname = "OBJECT_OT_unlink_data";
3284
3285 /* API callbacks. */
3287
3288 /* flags */
3289 ot->flag = OPTYPE_INTERNAL;
3290}
3291
3293
3294} // namespace blender::ed::object
Functions and classes to work with Actions.
Functions to work with AnimData.
Blender kernel action and pose functionality.
#define FOREACH_COLLECTION_OBJECT_RECURSIVE_END
#define FOREACH_SCENE_OBJECT_END
#define FOREACH_COLLECTION_OBJECT_RECURSIVE_BEGIN(_collection, _object)
#define FOREACH_SCENE_OBJECT_BEGIN(scene, _instance)
#define CTX_DATA_BEGIN(C, Type, instance, member)
#define CTX_DATA_END
display list (or rather multi purpose list) stuff.
#define FOREACH_OBJECT_FLAG_BEGIN(_bmain, _scene, _view_layer, _v3d, _flag, _instance)
Definition BKE_layer.hh:541
#define FOREACH_OBJECT_FLAG_END
Definition BKE_layer.hh:583
#define FOREACH_SELECTED_OBJECT_BEGIN(_view_layer, _v3d, _instance)
Definition BKE_layer.hh:374
#define FOREACH_SELECTED_OBJECT_END
Definition BKE_layer.hh:386
#define MAIN_ID_SESSION_UID_UNSET
#define FOREACH_MAIN_ID_END
Definition BKE_main.hh:735
#define FOREACH_MAIN_ID_BEGIN(_bmain, _id)
Definition BKE_main.hh:729
#define SELECT
Definition BKE_mask.hh:19
General operations, lookup, etc. for materials.
General operations, lookup, etc. for blender objects.
#define INT32_MAX
#define INT32_MIN
A KD-tree for nearest neighbor search.
#define STRNCPY_UTF8(dst, src)
#define TIP_(msgid)
#define IFACE_(msgid)
#define ID_NEW_REMAP(a)
Definition DNA_ID.h:761
#define ID_IS_OVERRIDE_LIBRARY_REAL(_id)
Definition DNA_ID.h:729
#define ID_IS_OVERRIDABLE_LIBRARY(_id)
Definition DNA_ID.h:721
#define ID_IS_LINKED(_id)
Definition DNA_ID.h:697
#define ID_IS_OVERRIDE_LIBRARY(_id)
Definition DNA_ID.h:736
#define ID_NEW_SET(_id, _idn)
Definition DNA_ID.h:757
Object groups, one object can be in many groups at once.
#define BEZT_ISSEL_ANY_HIDDENHANDLES(v3d, bezt)
Object is a sort of wrapper for general info.
#define OB_TYPE_SUPPORT_PARVERT(_type)
#define OB_TYPE_SUPPORT_MATERIAL(_type)
#define BASE_SELECTED(v3d, base)
#define ARM_GROUPS_ENVELOPE
#define ARM_GROUPS_NAME
#define ARM_GROUPS_AUTO
Read Blender memory allocation and freeing.
#define RNA_ENUM_ITEM_SEPR
Definition RNA_types.hh:762
#define C
Definition RandGen.cpp:29
#define UI_ITEM_NONE
#define NC_WINDOW
Definition WM_types.hh:388
#define ND_NLA_ACTCHANGE
Definition WM_types.hh:541
#define ND_DRAW
Definition WM_types.hh:502
#define NC_WM
Definition WM_types.hh:387
#define NC_ANIMATION
Definition WM_types.hh:401
#define ND_LIB_OVERRIDE_CHANGED
Definition WM_types.hh:435
#define ND_MODIFIER
Definition WM_types.hh:503
#define ND_PARENT
Definition WM_types.hh:508
#define NC_MATERIAL
Definition WM_types.hh:393
#define ND_CONSTRAINT
Definition WM_types.hh:505
#define ND_TRANSFORM
Definition WM_types.hh:475
#define ND_OB_SHADING
Definition WM_types.hh:476
#define ND_SPACE_VIEW3D
Definition WM_types.hh:571
#define NC_OBJECT
Definition WM_types.hh:392
#define ND_SHADING_LINKS
Definition WM_types.hh:522
#define NC_SPACE
Definition WM_types.hh:405
#define UNUSED_VARS(...)
#define SET_FLAG_FROM_TEST(value, test, flag)
#define UNPACK3(a)
#define ELEM(...)
#define BLI_assert_msg(a, msg)
#define STREQ(a, b)
#define BM_elem_flag_test(ele, hflag)
#define BM_ITER_MESH_INDEX(ele, iter, bm, itype, indexvar)
int64_t size() const
void add_new(const Key &key)
#define offsetof(t, d)
#define INT_MAX
void * MEM_new_uninitialized(size_t len, const char *str)
Definition mallocn.cc:124
#define INDEX_UNSET
bAction * id_action_ensure(Main *bmain, ID *id)
Definition animdata.cc:195
FCurve * action_fcurve_ensure_ex(Main *bmain, bAction *act, PointerRNA *ptr, const FCurveDescriptor &fcurve_descriptor)
void free(Subdiv *subdiv)
Definition subdiv.cc:192
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 wmOperatorStatus object_unlink_data_exec(bContext *C, wmOperator *op)
void single_obdata_user_make(Main *bmain, Scene *scene, Object *ob)
static bool has_geometry_visibility(const Object &object)
static bool make_override_library_object_overridable_check(Main *bmain, Object *object)
static wmOperatorStatus drop_geometry_nodes_invoke(bContext *C, wmOperator *op, const wmEvent *event)
void OBJECT_OT_make_local(wmOperatorType *ot)
static wmOperatorStatus clear_override_library_exec(bContext *C, wmOperator *)
void OBJECT_OT_clear_override_library(wmOperatorType *ot)
const EnumPropertyItem prop_clear_parent_types[]
static const EnumPropertyItem prop_clear_track_types[]
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 parent_clear_data(Object *ob)
static wmOperatorStatus object_track_clear_exec(bContext *C, wmOperator *op)
static wmOperatorStatus parent_set_invoke(bContext *C, wmOperator *op, const wmEvent *)
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 void single_obdata_users(Main *bmain, Scene *scene, ViewLayer *view_layer, View3D *v3d, const int flag)
static wmOperatorStatus make_links_scene_exec(bContext *C, wmOperator *op)
void OBJECT_OT_drop_named_material(wmOperatorType *ot)
static void make_local_animdata_tag_strips(ListBaseT< NlaStrip > *strips)
const EnumPropertyItem prop_make_parent_types[]
void base_select(Base *base, eObjectSelect_Mode mode)
void OBJECT_OT_parent_no_inverse_set(wmOperatorType *ot)
static wmOperatorStatus make_single_user_exec(bContext *C, wmOperator *op)
static void object_remove_parent_deform_modifiers(Object *ob, const Object *par)
static bool single_data_needs_duplication(ID *id)
void OBJECT_OT_track_set(wmOperatorType *ot)
static const EnumPropertyItem prop_make_track_types[]
static wmOperatorStatus track_set_exec(bContext *C, wmOperator *op)
static wmOperatorStatus vertex_parent_set_exec(bContext *C, wmOperator *op)
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)
static wmOperatorStatus parent_clear_exec(bContext *C, wmOperator *op)
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])
static wmOperatorStatus make_local_exec(bContext *C, wmOperator *op)
static wmOperatorStatus make_override_library_invoke(bContext *C, wmOperator *op, const wmEvent *)
Object * context_active_object(const bContext *C)
void OBJECT_OT_make_links_data(wmOperatorType *ot)
static wmOperatorStatus parent_noinv_set_exec(bContext *C, wmOperator *op)
static void parent_set_vert_find(KDTree< float3 > *tree, Object *child, int vert_par[3], bool is_tri)
static bool allow_make_links_data(const int type, Object *ob_src, Object *ob_dst)
void parent_clear(Main *bmain, Object *ob, int type)
static wmOperatorStatus reset_override_library_exec(bContext *C, wmOperator *)
static wmOperatorStatus make_links_data_exec(bContext *C, wmOperator *op)
std::string drop_named_material_tooltip(bContext *C, StringRef name, const int mval[2])
static bool reset_clear_override_library_poll(bContext *C)
static bool make_override_library_poll(bContext *C)
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 wmOperatorStatus parent_set_invoke_menu(bContext *C, 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 void tag_localizable_objects(bContext *C, const int mode)
static bool parent_set_poll_property(const bContext *, wmOperator *op, const PropertyRNA *prop)
static wmOperatorStatus drop_named_material_invoke(bContext *C, wmOperator *op, const wmEvent *event)
void OBJECT_OT_parent_set(wmOperatorType *ot)
static bool parent_set_with_depsgraph(ReportList *reports, const bContext *C, Scene *scene, Depsgraph *depsgraph, Object *const ob, Object *const par, Object *const parent_eval, int partype, const bool xmirror, const bool keep_transform, const int vert_par[3])
static wmOperatorStatus parent_set_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 Collection * single_object_users_collection(Main *bmain, Scene *scene, Collection *collection, const int flag, const bool copy_collections, const bool is_master_collection)
static wmOperatorStatus make_override_library_exec(bContext *C, wmOperator *op)
static wmOperatorStatus make_single_user_invoke(bContext *C, wmOperator *op, const wmEvent *event)
static bool parent_set_vertex_parent_with_kdtree(bContext *C, ParentingContext *parenting_context, KDTree< float3 > *tree)
void shaderfx_link(Object *dst, Object *src)
PopupMenu * popup_menu_begin(bContext *C, const char *title, int icon) ATTR_NONNULL()
void context_active_but_prop_get_templateID(const bContext *C, PointerRNA *r_ptr, PropertyRNA **r_prop)
void BKE_constraints_free(ListBaseT< bConstraint > *list)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
void RNA_def_enum_funcs(PropertyRNA *prop, EnumPropertyItemFunc itemfunc)
wmOperatorStatus WM_menu_invoke(bContext *C, wmOperator *op, const wmEvent *)
void BKE_scene_objects_iterator_end(BLI_Iterator *iter)
int RNA_enum_get(PointerRNA *ptr, const char *name)
Object * BKE_view_layer_active_object_get(const ViewLayer *view_layer)
void BKE_pose_rebuild(Main *bmain, Object *ob, bArmature *arm, bool do_id_user)
@ RPT_ERROR_INVALID_INPUT
Definition BKE_report.hh:42
@ RPT_WARNING
Definition BKE_report.hh:40
void BKE_id_delete(Main *bmain, void *idv, const BKEIDDeleteOptions &options={}) ATTR_NONNULL()
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)
void RNA_property_update(bContext *C, PointerRNA *ptr, PropertyRNA *prop)
BMesh * BKE_editmesh_bmesh_get_for_write(Mesh *mesh)
Definition editmesh.cc:79
void BKE_object_apply_parent_inverse(Object *ob)
Definition object.cc:3671
void WM_operator_properties_id_lookup(wmOperatorType *ot, const bool add_name_prop)
MINLINE void copy_v3_v3(float r[3], const float a[3])
unsigned int uint
Definition BKE_text.h:55
void BKE_libblock_relink_to_newid(Main *bmain, ID *id, int remap_flag) ATTR_NONNULL()
Definition lib_remap.cc:932
void BLI_addhead(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:98
bool ED_operator_editlattice(bContext *C)
Material *** BKE_object_material_array_p(Object *ob)
void id_us_plus(ID *id)
Definition lib_id.cc:433
PointerRNA RNA_id_pointer_create(ID *id)
ID * BKE_libblock_find_session_uid(Main *bmain, short type, uint32_t session_uid)
Definition lib_id.cc:1826
ID * WM_operator_properties_id_lookup_from_name_or_session_uid(Main *bmain, PointerRNA *ptr, const ID_Type type)
const char * RNA_property_identifier(const PropertyRNA *prop)
Material * BKE_object_material_get(Object *ob, short act)
MINLINE void copy_v3_v3_int(int r[3], const int a[3])
bool ED_operator_object_active_objectmode(bContext *C)
Object * ED_view3d_give_material_slot_under_cursor(bContext *C, const int mval[2], int *r_material_slot)
void void BKE_libblock_remap(Main *bmain, void *old_idv, void *new_idv, int remap_flags) ATTR_NONNULL(1
Definition lib_remap.cc:701
bool invert_m4_m4(float inverse[4][4], const float mat[4][4])
Object * BKE_modifiers_is_deformed_by_curve(Object *ob)
@ eModifierType_GreasePencilLattice
@ eModifierType_GreasePencilArmature
unsigned short ushort
Definition BKE_text.h:56
Object * BKE_modifiers_is_deformed_by_armature(Object *ob)
void MOD_nodes_update_interface(Main &bmain, Object *object, NodesModifierData *nmd)
Definition MOD_nodes.cc:405
PropertyRNA * RNA_def_enum(StructOrFunctionRNA *cont_, const char *identifier, const EnumPropertyItem *items, const int default_value, const char *ui_name, const char *ui_description)
int RNA_int_get(PointerRNA *ptr, const char *name)
void RNA_enum_set(PointerRNA *ptr, const char *name, int value)
@ GEO_NODE_ASSET_HIDE_MODIFIER_MANAGE_PANEL
FModifier * add_fmodifier(ListBaseT< FModifier > *modifiers, int type, FCurve *owner_fcu)
@ ID_REMAP_SKIP_INDIRECT_USAGE
MINLINE int max_ii(int a, int b)
void BKE_object_material_assign(Main *bmain, Object *ob, Material *ma, short act, int assign_type)
struct bConstraint * BKE_constraint_add_for_object(struct Object *ob, const char *name, eBConstraint_Types type)
void BKE_collection_object_parent_clear_sort_index_reset(Main &bmain, Object &ob)
void BKE_animdata_duplicate_id_action(Main *bmain, ID *id, uint duplicate_flags)
Definition anim_data.cc:434
Base * CTX_data_active_base(const bContext *C)
@ LIBOVERRIDE_FLAG_SYSTEM_DEFINED
Definition DNA_ID.h:308
void BKE_sculptsession_free_pbvh(Object &object)
bool BKE_object_supports_modifiers(const Object *ob)
Definition object.cc:1449
@ LIB_ID_COPY_DEFAULT
@ LIB_ID_COPY_ACTIONS
ViewLayer * CTX_data_view_layer(const bContext *C)
void BKE_object_apply_mat4(Object *ob, const float mat[4][4], bool use_compat, bool use_parent)
Definition object.cc:3663
bool BKE_collection_has_object(Collection *collection, const Object *ob)
bool BKE_object_parent_loop_check(const Object *parent, const Object *ob)
Definition object.cc:4898
Global G
Definition blender.cc:57
void BKE_light_linking_copy_receiver_collection(Main *bmain, Object &object_dst, const Object &object_src)
void RNA_property_int_set(PointerRNA *ptr, PropertyRNA *prop, int value)
@ FMODIFIER_TYPE_GENERATOR
bool BKE_main_collection_sync_remap(const Main *bmain)
AnimData * BKE_animdata_from_id(const ID *id)
Definition anim_data.cc:93
void * BLI_findlink(const ListBase *listbase, int number) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition listbase.cc:541
unsigned int uint32_t
Definition BKE_text.h:81
bool ED_operator_editmesh(bContext *C)
void BKE_object_groups_clear(Main *bmain, Scene *scene, Object *object)
Definition object.cc:5362
void BKE_light_linking_copy_blocker_collection(Main *bmain, Object &object_dst, const Object &object_src)
void BKE_collection_object_parented_sort_index_reset(Main &bmain, Object &ob)
void BLI_remlink(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:138
void DEG_id_tag_update(ID *id, unsigned int flags)
void BKE_report(ReportList *reports, eReportType type, const char *message)
Definition report.cc:162
BMesh const char void * data
void BKE_object_materials_sync_length(Main *bmain, Object *ob, ID *id)
void BKE_constraints_copy(ListBaseT< bConstraint > *dst, const ListBaseT< bConstraint > *src, bool do_extern)
T * DEG_get_evaluated(const Depsgraph *depsgraph, T *id)
int kdtree_find_nearest_n(const KDTree< CoordT > *tree, const CoordT &co, KDTreeNearest< CoordT > r_nearest[], uint nearest_len_capacity)
Depsgraph * CTX_data_ensure_evaluated_depsgraph(const bContext *C, bool rna_write_check=false)
Object * CTX_data_edit_object(const bContext *C)
@ BKE_MAT_ASSIGN_EXISTING
@ BKE_MAT_ASSIGN_USERPREF
@ BKE_MAT_ASSIGN_OBJECT
void BKE_modifier_free(ModifierData *md)
void BKE_scene_graph_update_tagged(Depsgraph *depsgraph, Main *bmain)
Definition scene.cc:2867
int kdtree_find_nearest(const KDTree< CoordT > *tree, const CoordT &co, KDTreeNearest< CoordT > *r_nearest)
KDTree< float3 > * BKE_object_as_kdtree(Object *ob, int *r_tot)
Definition object.cc:5377
bool BKE_view_layer_synced_ensure(const Main &bmain, const Scene *scene, ViewLayer *view_layer)
bool BKE_animdata_copy_id(Main *bmain, ID *id_to, ID *id_from, int flag)
Definition anim_data.cc:351
void BKE_editmesh_looptris_and_normals_calc(BMEditMesh *em, BMesh *bm)
Definition editmesh.cc:122
bool ED_operator_editsurfcurve(bContext *C)
bool BKE_collection_child_remove(Main *bmain, Collection *parent, Collection *child)
const EnumPropertyItem * RNA_scene_local_itemf(bContext *C, PointerRNA *ptr, PropertyRNA *prop, bool *r_free)
bool BKE_collection_object_add(Main *bmain, Collection *collection, Object *ob)
void unit_m4(float m[4][4])
bool ED_operator_view3d_active(bContext *C)
bool BKE_constraint_remove_ex(ListBaseT< bConstraint > *list, struct Object *ob, struct bConstraint *con)
bool BKE_collection_has_collection(const Collection *parent, const Collection *collection)
void BKE_lib_override_library_id_reset(Main *bmain, ID *id_root, bool do_reset_system_override)
bool ED_operator_object_active(bContext *C)
void BKE_modifier_remove_from_list(Object *ob, ModifierData *md)
bool RNA_boolean_get(PointerRNA *ptr, const char *name)
ListBaseT< Nurb > * object_editcurve_get(Object *ob)
Definition editcurve.cc:95
const EnumPropertyItem rna_enum_dummy_NULL_items[]
Definition rna_rna.cc:28
bool ED_operator_object_active_editable(bContext *C)
bool ED_operator_objectmode_with_view3d_poll_msg(bContext *C)
void BKE_main_id_tag_all(Main *mainvar, int tag, bool value)
Definition lib_id.cc:1314
void WM_event_add_notifier(const bContext *C, uint type, void *reference)
void EDBM_mesh_load(Main *bmain, Object *ob)
void RNA_boolean_set(PointerRNA *ptr, const char *name, bool value)
void BKE_view_layer_base_deselect_all(const Main &bmain, const Scene *scene, ViewLayer *view_layer)
bool BKE_collection_child_add_no_sync(Main *bmain, Collection *parent, Collection *child)
wmOperatorStatus 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, std::optional< std::string > message)
void BKE_main_id_newptr_and_tag_clear(Main *bmain)
Definition lib_id.cc:2097
int BKE_object_scenes_users_get(Main *bmain, Object *ob)
Definition object.cc:5143
void kdtree_free(KDTree< CoordT > *tree)
Definition BLI_kdtree.hh:84
void RNA_def_property_flag(PropertyRNA *prop, PropertyFlag flag)
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)
MINLINE void sub_v3_v3v3(float r[3], const float a[3], const float b[3])
bool ED_operator_objectmode(bContext *C)
void BKE_reportf(ReportList *reports, eReportType type, const char *format,...) ATTR_PRINTF_FORMAT(3
Definition report.cc:191
void EDBM_mesh_make(Object *ob, int select_mode, bool add_key_index)
float4x4 BKE_object_calc_parent(Depsgraph *depsgraph, Scene *scene, Object *ob)
Definition object.cc:3583
void BLI_linklist_free(LinkNode *list, LinkNodeFreeFP freefunc)
Main * CTX_data_main(const bContext *C)
@ NODES_MODIFIER_HIDE_DATABLOCK_SELECTOR
@ NODES_MODIFIER_HIDE_MANAGE_PANEL
bool BKE_lib_override_library_is_hierarchy_leaf(Main *bmain, ID *id)
void * BLI_listbase_bytes_find(const ListBase *listbase, const void *bytes, size_t bytes_size, int offset) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1
Definition listbase.cc:737
LinkNode * BKE_object_groups(Main *bmain, Scene *scene, Object *ob)
Definition object.cc:5351
@ ID_RECALC_SELECT
Definition DNA_ID.h:1101
@ ID_RECALC_ANIMATION
Definition DNA_ID.h:1077
@ ID_RECALC_HIERARCHY
Definition DNA_ID.h:1158
@ ID_RECALC_TRANSFORM
Definition DNA_ID.h:1054
@ ID_RECALC_SYNC_TO_EVAL
Definition DNA_ID.h:1118
@ ID_RECALC_GEOMETRY
Definition DNA_ID.h:1074
@ ID_RECALC_BASE_FLAGS
Definition DNA_ID.h:1104
ID_Type GS(const char *name)
Definition DNA_ID.h:410
@ PROP_SKIP_SAVE
Definition RNA_types.hh:414
@ PROP_ENUM_NO_TRANSLATE
Definition RNA_types.hh:502
@ PROP_HIDDEN
Definition RNA_types.hh:408
Base * BKE_view_layer_base_find(ViewLayer *view_layer, Object *ob)
@ ID_TAG_PRE_EXISTING
Definition DNA_ID.h:929
@ ID_TAG_DOIT
Definition DNA_ID.h:1029
Object * ED_view3d_give_object_under_cursor(bContext *C, const int mval[2])
wmOperatorStatus WM_enum_search_invoke(bContext *C, wmOperator *op, const wmEvent *)
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)
void DEG_relations_tag_update(Main *bmain)
bPoseChannel * BKE_pose_channel_active_if_bonecoll_visible(Object *ob) ATTR_WARN_UNUSED_RESULT
Scene * CTX_data_scene(const bContext *C)
bool BKE_collection_has_object_recursive(Collection *collection, Object *ob)
@ OPTYPE_REGISTER
Definition WM_types.hh:188
@ OPTYPE_UNDO
Definition WM_types.hh:190
@ OPTYPE_INTERNAL
Definition WM_types.hh:210
ID * BKE_id_copy_ex(Main *bmain, const ID *id, ID **new_id_p, int flag)
Definition lib_id.cc:851
void BKE_displist_make_curveTypes(struct Depsgraph *depsgraph, const struct Scene *scene, struct Object *ob, bool for_render)
void ED_object_vgroup_calc_from_armature(ReportList *reports, Depsgraph *, Scene *scene, Object *ob, Object *par, const int mode, const bool mirror)
PropertyRNA * RNA_def_boolean(StructOrFunctionRNA *cont_, const char *identifier, const bool default_value, const char *ui_name, const char *ui_description)
void BKE_object_link_modifiers(Object *ob_dst, const Object *ob_src)
Definition object.cc:1682
int RNA_property_int_get(PointerRNA *ptr, PropertyRNA *prop)
bool BKE_id_is_editable(const Main *bmain, const ID *id)
Definition lib_id.cc:2782
void WM_cursor_wait(bool val)
Object * CTX_data_active_object(const bContext *C)
void id_us_min(ID *id)
Definition lib_id.cc:441
void BKE_library_foreach_ID_link(Main *bmain, ID *id, FunctionRef< LibraryIDLinkCallback > callback, void *user_data, LibraryForeachIDFlag flag)
Definition lib_query.cc:449
bool RNA_property_is_set(PointerRNA *ptr, PropertyRNA *prop)
void BKE_view_layer_selected_objects_tag(const Main &bmain, const Scene *scene, ViewLayer *view_layer, eObject_Flag tag)
View3D * CTX_wm_view3d(const bContext *C)
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:2395
bool BKE_view_layer_has_collection(const ViewLayer *view_layer, const Collection *collection)
Object * BKE_modifiers_is_deformed_by_lattice(Object *ob)
Collection * CTX_data_collection(const bContext *C)
#define CURVE_VFONT_SET(vfont_member)
ListBaseT< NlaTrack > nla_tracks
struct Object * object
struct Base * next
struct CollectionChild * next
bke::CollectionRuntime * runtime
ListBaseT< CollectionChild > children
ListBaseT< CollectionObject > gobject
const float * anim_path_accum_length
Definition BKE_curve.hh:53
struct Object * bevobj
struct Object * taperobj
struct Lattice * latt
ListBaseT< FModifier > modifiers
eID_OverrideLib_Flag flag
Definition DNA_ID.h:356
struct ID * hierarchy_root
Definition DNA_ID.h:352
char name[258]
Definition DNA_ID.h:433
unsigned int session_uid
Definition DNA_ID.h:463
struct ID * newid
Definition DNA_ID.h:419
struct Library * lib
Definition DNA_ID.h:421
void * next
Definition DNA_ID.h:418
IDOverrideLibrary * override_library
Definition DNA_ID.h:495
struct EditLatt * editlatt
struct BPoint * def
struct LinkNode * next
ListBaseT< Collection > collections
Definition BKE_main.hh:406
ListBaseT< Object > objects
Definition BKE_main.hh:388
ListBaseT< Mesh > meshes
Definition BKE_main.hh:389
ListBaseT< Scene > scenes
Definition BKE_main.hh:386
struct ModifierData * next
ListBaseT< NlaStrip > strips
struct Nurb * next
struct Object * parent
ListBaseT< ModifierData > modifiers
float parentinv[4][4]
bke::ObjectRuntime * runtime
eObject_Partype partype
ListBaseT< bConstraint > constraints
eObject_TransFlag transflag
struct Collection * instance_collection
struct Collection * master_collection
ListBaseT< Base > base
struct RenderData r
struct ToolSettings * toolsettings
struct Object * camera
struct bConstraint * prev
struct GeometryNodeAssetTraits * geometry_node_asset_traits
eNodeTree_Type type
ListBaseT< CollectionParent > parents
Defines a socket type.
Definition BKE_node.hh:163
eNodeSocketDatatype type
Definition BKE_node.hh:198
PointerRNA op(wmOperatorType *ot, std::optional< StringRef > name, int icon, wm::OpCallContext context, eUI_Item_Flag flag)
wmOperatorStatus(*) exec(bContext *C, wmOperator *op) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1125
bool(*) poll_property(const bContext *C, wmOperator *op, const PropertyRNA *prop) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1171
const char * description
Definition WM_types.hh:1115
bool(*) poll(bContext *C) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1165
wmOperatorStatus(*) invoke(bContext *C, wmOperator *op, const wmEvent *event) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1141
struct ReportList * reports
struct wmOperatorType * type