Blender  V2.93
object_relations.c
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
17  * All rights reserved.
18  */
19 
24 #include <stdio.h>
25 #include <stdlib.h>
26 #include <string.h>
27 
28 #include "MEM_guardedalloc.h"
29 
30 #include "DNA_anim_types.h"
31 #include "DNA_armature_types.h"
32 #include "DNA_camera_types.h"
33 #include "DNA_collection_types.h"
34 #include "DNA_constraint_types.h"
35 #include "DNA_gpencil_types.h"
36 #include "DNA_key_types.h"
37 #include "DNA_lattice_types.h"
38 #include "DNA_light_types.h"
39 #include "DNA_material_types.h"
40 #include "DNA_mesh_types.h"
41 #include "DNA_meta_types.h"
42 #include "DNA_object_types.h"
43 #include "DNA_particle_types.h"
44 #include "DNA_scene_types.h"
45 #include "DNA_vfont_types.h"
46 #include "DNA_world_types.h"
47 
48 #include "BLI_kdtree.h"
49 #include "BLI_linklist.h"
50 #include "BLI_listbase.h"
51 #include "BLI_math.h"
52 #include "BLI_string.h"
53 #include "BLI_utildefines.h"
54 
55 #include "BLT_translation.h"
56 
57 #include "BKE_DerivedMesh.h"
58 #include "BKE_action.h"
59 #include "BKE_anim_data.h"
60 #include "BKE_armature.h"
61 #include "BKE_camera.h"
62 #include "BKE_collection.h"
63 #include "BKE_constraint.h"
64 #include "BKE_context.h"
65 #include "BKE_curve.h"
66 #include "BKE_displist.h"
67 #include "BKE_editmesh.h"
68 #include "BKE_fcurve.h"
69 #include "BKE_gpencil.h"
70 #include "BKE_hair.h"
71 #include "BKE_idprop.h"
72 #include "BKE_idtype.h"
73 #include "BKE_lattice.h"
74 #include "BKE_layer.h"
75 #include "BKE_lib_id.h"
76 #include "BKE_lib_override.h"
77 #include "BKE_lib_query.h"
78 #include "BKE_lib_remap.h"
79 #include "BKE_light.h"
80 #include "BKE_lightprobe.h"
81 #include "BKE_main.h"
82 #include "BKE_material.h"
83 #include "BKE_mball.h"
84 #include "BKE_mesh.h"
85 #include "BKE_modifier.h"
86 #include "BKE_node.h"
87 #include "BKE_object.h"
88 #include "BKE_pointcloud.h"
89 #include "BKE_report.h"
90 #include "BKE_scene.h"
91 #include "BKE_speaker.h"
92 #include "BKE_texture.h"
93 #include "BKE_volume.h"
94 
95 #include "DEG_depsgraph.h"
96 #include "DEG_depsgraph_build.h"
97 #include "DEG_depsgraph_query.h"
98 
99 #include "WM_api.h"
100 #include "WM_types.h"
101 
102 #include "UI_interface.h"
103 #include "UI_resources.h"
104 
105 #include "RNA_access.h"
106 #include "RNA_define.h"
107 #include "RNA_enum_types.h"
108 
109 #include "ED_armature.h"
110 #include "ED_curve.h"
111 #include "ED_gpencil.h"
112 #include "ED_keyframing.h"
113 #include "ED_mesh.h"
114 #include "ED_object.h"
115 #include "ED_screen.h"
116 #include "ED_view3d.h"
117 
118 #include "object_intern.h"
119 
120 /* ------------------------------------------------------------------- */
125 {
127 }
128 
130 {
131  Main *bmain = CTX_data_main(C);
133  View3D *v3d = CTX_wm_view3d(C);
135  ViewLayer *view_layer = CTX_data_view_layer(C);
136  Object *obedit = CTX_data_edit_object(C);
137  Object *par;
138 
139 #define INDEX_UNSET -1
140  int par1, par2, par3, par4;
141  par1 = par2 = par3 = par4 = INDEX_UNSET;
142 
143  /* we need 1 to 3 selected vertices */
144 
145  if (obedit->type == OB_MESH) {
146  Mesh *me = obedit->data;
147  BMEditMesh *em;
148 
149  EDBM_mesh_load(bmain, obedit);
150  EDBM_mesh_make(obedit, scene->toolsettings->selectmode, true);
151 
152  DEG_id_tag_update(obedit->data, 0);
153 
154  em = me->edit_mesh;
155 
158 
159  /* Make sure the evaluated mesh is updated.
160  *
161  * Most reliable way is to update the tagged objects, which will ensure
162  * proper copy-on-write update, but also will make sure all dependent
163  * objects are also up to date. */
165 
166  BMVert *eve;
167  BMIter iter;
168  int curr_index;
169  BM_ITER_MESH_INDEX (eve, &iter, em->bm, BM_VERTS_OF_MESH, curr_index) {
170  if (BM_elem_flag_test(eve, BM_ELEM_SELECT)) {
171  if (par1 == INDEX_UNSET) {
172  par1 = curr_index;
173  }
174  else if (par2 == INDEX_UNSET) {
175  par2 = curr_index;
176  }
177  else if (par3 == INDEX_UNSET) {
178  par3 = curr_index;
179  }
180  else if (par4 == INDEX_UNSET) {
181  par4 = curr_index;
182  }
183  else {
184  break;
185  }
186  }
187  }
188  }
189  else if (ELEM(obedit->type, OB_SURF, OB_CURVE)) {
190  ListBase *editnurb = object_editcurve_get(obedit);
191 
192  for (Nurb *nu = editnurb->first; nu != NULL; nu = nu->next) {
193  if (nu->type == CU_BEZIER) {
194  BezTriple *bezt = nu->bezt;
195  for (int curr_index = 0; curr_index < nu->pntsu; curr_index++, bezt++) {
196  if (BEZT_ISSEL_ANY_HIDDENHANDLES(v3d, bezt)) {
197  if (par1 == INDEX_UNSET) {
198  par1 = curr_index;
199  }
200  else if (par2 == INDEX_UNSET) {
201  par2 = curr_index;
202  }
203  else if (par3 == INDEX_UNSET) {
204  par3 = curr_index;
205  }
206  else if (par4 == INDEX_UNSET) {
207  par4 = curr_index;
208  }
209  else {
210  break;
211  }
212  }
213  }
214  }
215  else {
216  BPoint *bp = nu->bp;
217  const int num_points = nu->pntsu * nu->pntsv;
218  for (int curr_index = 0; curr_index < num_points; curr_index++, bp++) {
219  if (bp->f1 & SELECT) {
220  if (par1 == INDEX_UNSET) {
221  par1 = curr_index;
222  }
223  else if (par2 == INDEX_UNSET) {
224  par2 = curr_index;
225  }
226  else if (par3 == INDEX_UNSET) {
227  par3 = curr_index;
228  }
229  else if (par4 == INDEX_UNSET) {
230  par4 = curr_index;
231  }
232  else {
233  break;
234  }
235  }
236  }
237  }
238  }
239  }
240  else if (obedit->type == OB_LATTICE) {
241  Lattice *lt = obedit->data;
242 
243  const int num_points = lt->editlatt->latt->pntsu * lt->editlatt->latt->pntsv *
244  lt->editlatt->latt->pntsw;
245  BPoint *bp = lt->editlatt->latt->def;
246  for (int curr_index = 0; curr_index < num_points; curr_index++, bp++) {
247  if (bp->f1 & SELECT) {
248  if (par1 == INDEX_UNSET) {
249  par1 = curr_index;
250  }
251  else if (par2 == INDEX_UNSET) {
252  par2 = curr_index;
253  }
254  else if (par3 == INDEX_UNSET) {
255  par3 = curr_index;
256  }
257  else if (par4 == INDEX_UNSET) {
258  par4 = curr_index;
259  }
260  else {
261  break;
262  }
263  }
264  }
265  }
266 
267  if (par4 != INDEX_UNSET || par1 == INDEX_UNSET || (par2 != INDEX_UNSET && par3 == INDEX_UNSET)) {
268  BKE_report(op->reports, RPT_ERROR, "Select either 1 or 3 vertices to parent to");
269  return OPERATOR_CANCELLED;
270  }
271 
272  CTX_DATA_BEGIN (C, Object *, ob, selected_editable_objects) {
273  if (ob != obedit) {
275  par = obedit->parent;
276 
277  if (BKE_object_parent_loop_check(par, ob)) {
278  BKE_report(op->reports, RPT_ERROR, "Loop in parents");
279  }
280  else {
281  Object workob;
282 
283  ob->parent = BASACT(view_layer)->object;
284  if (par3 != INDEX_UNSET) {
285  ob->partype = PARVERT3;
286  ob->par1 = par1;
287  ob->par2 = par2;
288  ob->par3 = par3;
289 
290  /* inverse parent matrix */
292  invert_m4_m4(ob->parentinv, workob.obmat);
293  }
294  else {
295  ob->partype = PARVERT1;
296  ob->par1 = par1;
297 
298  /* inverse parent matrix */
300  invert_m4_m4(ob->parentinv, workob.obmat);
301  }
302  }
303  }
304  }
305  CTX_DATA_END;
306 
308 
310 
311  return OPERATOR_FINISHED;
312 
313 #undef INDEX_UNSET
314 }
315 
317 {
318  /* identifiers */
319  ot->name = "Make Vertex Parent";
320  ot->description = "Parent selected objects to the selected vertices";
321  ot->idname = "OBJECT_OT_vertex_parent_set";
322 
323  /* api callbacks */
327 
328  /* flags */
330 }
331 
334 /* ------------------------------------------------------------------- */
338 /* set the object to proxify */
339 static int make_proxy_invoke(bContext *C, wmOperator *op, const wmEvent *event)
340 {
343 
344  /* sanity checks */
345  if (!scene || ID_IS_LINKED(scene) || !ob) {
346  return OPERATOR_CANCELLED;
347  }
348 
349  /* Get object to work on - use a menu if we need to... */
351  /* gives menu with list of objects in group */
352  /* proxy_group_objects_menu(C, op, ob, ob->instance_collection); */
353  WM_enum_search_invoke(C, op, event);
354  return OPERATOR_CANCELLED;
355  }
356  if (ID_IS_LINKED(ob)) {
357  uiPopupMenu *pup = UI_popup_menu_begin(C, IFACE_("OK?"), ICON_QUESTION);
358  uiLayout *layout = UI_popup_menu_layout(pup);
359 
360  /* create operator menu item with relevant properties filled in */
361  PointerRNA opptr_dummy;
363  layout, op->type, op->type->name, ICON_NONE, NULL, WM_OP_EXEC_REGION_WIN, 0, &opptr_dummy);
364 
365  /* present the menu and be done... */
366  UI_popup_menu_end(C, pup);
367 
368  /* this invoke just calls another instance of this operator... */
369  return OPERATOR_INTERFACE;
370  }
371 
372  /* error.. cannot continue */
373  BKE_report(op->reports, RPT_ERROR, "Can only make proxy for a referenced object or collection");
374  return OPERATOR_CANCELLED;
375 }
376 
378 {
379  Main *bmain = CTX_data_main(C);
380  Object *ob, *gob = ED_object_active_context(C);
382  ViewLayer *view_layer = CTX_data_view_layer(C);
383 
384  if (gob->instance_collection != NULL) {
385  const ListBase instance_collection_objects = BKE_collection_object_cache_get(
386  gob->instance_collection);
387  Base *base = BLI_findlink(&instance_collection_objects, RNA_enum_get(op->ptr, "object"));
388  ob = base->object;
389  }
390  else {
391  ob = gob;
392  gob = NULL;
393  }
394 
395  if (ob) {
396  Object *newob;
397  char name[MAX_ID_NAME + 4];
398 
399  BLI_snprintf(name, sizeof(name), "%s_proxy", ((ID *)(gob ? gob : ob))->name + 2);
400 
401  /* Add new object for the proxy */
402  newob = BKE_object_add_from(bmain, scene, view_layer, OB_EMPTY, name, gob ? gob : ob);
403 
404  /* set layers OK */
405  BKE_object_make_proxy(bmain, newob, ob, gob);
406 
407  /* Set back pointer immediately so dependency graph knows that this is
408  * is a proxy and will act accordingly. Otherwise correctness of graph
409  * will depend on order of bases.
410  *
411  * TODO(sergey): We really need to get rid of this bi-directional links
412  * in proxies with something like library overrides.
413  */
414  if (newob->proxy != NULL) {
415  newob->proxy->proxy_from = newob;
416  }
417  else {
418  BKE_report(op->reports, RPT_ERROR, "Unable to assign proxy");
419  }
420 
421  /* depsgraph flushes are needed for the new data */
425  }
426  else {
427  BKE_report(op->reports, RPT_ERROR, "No object to make proxy for");
428  return OPERATOR_CANCELLED;
429  }
430 
431  return OPERATOR_FINISHED;
432 }
433 
434 /* Generic itemf's for operators that take library args */
437  PropertyRNA *UNUSED(prop),
438  bool *r_free)
439 {
440  EnumPropertyItem item_tmp = {0}, *item = NULL;
441  int totitem = 0;
442  int i = 0;
444 
445  if (!ob || !ob->instance_collection) {
446  return DummyRNA_DEFAULT_items;
447  }
448 
449  /* find the object to affect */
451  item_tmp.identifier = item_tmp.name = object->id.name + 2;
452  item_tmp.value = i++;
453  RNA_enum_item_add(&item, &totitem, &item_tmp);
454  }
456 
457  RNA_enum_item_end(&item, &totitem);
458  *r_free = true;
459 
460  return item;
461 }
462 
464 {
465  PropertyRNA *prop;
466 
467  /* identifiers */
468  ot->name = "Make Proxy";
469  ot->idname = "OBJECT_OT_proxy_make";
470  ot->description = "Add empty object to become local replacement data of a library-linked object";
471 
472  /* callbacks */
476 
477  /* flags */
479 
480  /* properties */
481  /* XXX, relies on hard coded ID at the moment */
482  prop = RNA_def_enum(ot->srna,
483  "object",
485  0,
486  "Proxy Object",
487  "Name of library-linked/collection object to make a proxy for");
490  ot->prop = prop;
491 }
492 
495 /* ------------------------------------------------------------------- */
501  "CLEAR",
502  0,
503  "Clear Parent",
504  "Completely clear the parenting relationship, including involved modifiers if any"},
506  "CLEAR_KEEP_TRANSFORM",
507  0,
508  "Clear and Keep Transformation",
509  "As 'Clear Parent', but keep the current visual transformations of the object"},
511  "CLEAR_INVERSE",
512  0,
513  "Clear Parent Inverse",
514  "Reset the transform corrections applied to the parenting relationship, does not remove "
515  "parenting itself"},
516  {0, NULL, 0, NULL, NULL},
517 };
518 
519 /* Helper for ED_object_parent_clear() - Remove deform-modifiers associated with parent */
521 {
522  if (ELEM(par->type, OB_ARMATURE, OB_LATTICE, OB_CURVE)) {
523  ModifierData *md, *mdn;
524 
525  /* assume that we only need to remove the first instance of matching deform modifier here */
526  for (md = ob->modifiers.first; md; md = mdn) {
527  bool free = false;
528 
529  mdn = md->next;
530 
531  /* need to match types (modifier + parent) and references */
532  if ((md->type == eModifierType_Armature) && (par->type == OB_ARMATURE)) {
534  if (amd->object == par) {
535  free = true;
536  }
537  }
538  else if ((md->type == eModifierType_Lattice) && (par->type == OB_LATTICE)) {
540  if (lmd->object == par) {
541  free = true;
542  }
543  }
544  else if ((md->type == eModifierType_Curve) && (par->type == OB_CURVE)) {
546  if (cmd->object == par) {
547  free = true;
548  }
549  }
550 
551  /* free modifier if match */
552  if (free) {
554  BKE_modifier_free(md);
555  }
556  }
557  }
558 }
559 
560 void ED_object_parent_clear(Object *ob, const int type)
561 {
562  if (ob->parent == NULL) {
563  return;
564  }
565 
566  switch (type) {
567  case CLEAR_PARENT_ALL: {
568  /* for deformers, remove corresponding modifiers to prevent
569  * a large number of modifiers building up */
571 
572  /* clear parenting relationship completely */
573  ob->parent = NULL;
574  ob->partype = PAROBJECT;
575  ob->parsubstr[0] = 0;
576  break;
577  }
579  /* remove parent, and apply the parented transform
580  * result as object's local transforms */
581  ob->parent = NULL;
582  BKE_object_apply_mat4(ob, ob->obmat, true, false);
583  break;
584  }
585  case CLEAR_PARENT_INVERSE: {
586  /* object stays parented, but the parent inverse
587  * (i.e. offset from parent to retain binding state)
588  * is cleared. In other words: nothing to do here! */
589  break;
590  }
591  }
592 
593  /* Always clear parentinv matrix for sake of consistency, see T41950. */
594  unit_m4(ob->parentinv);
595 
597 }
598 
599 /* note, poll should check for editable scene */
601 {
602  Main *bmain = CTX_data_main(C);
603  const int type = RNA_enum_get(op->ptr, "type");
604 
605  CTX_DATA_BEGIN (C, Object *, ob, selected_editable_objects) {
607  }
608  CTX_DATA_END;
609 
613  return OPERATOR_FINISHED;
614 }
615 
617 {
618  /* identifiers */
619  ot->name = "Clear Parent";
620  ot->description = "Clear the object's parenting";
621  ot->idname = "OBJECT_OT_parent_clear";
622 
623  /* api callbacks */
626 
627  /* flags */
629 
631 }
632 
635 /* ------------------------------------------------------------------- */
639 void ED_object_parent(Object *ob, Object *par, const int type, const char *substr)
640 {
641  /* Always clear parentinv matrix for sake of consistency, see T41950. */
642  unit_m4(ob->parentinv);
643 
644  if (!par || BKE_object_parent_loop_check(par, ob)) {
645  ob->parent = NULL;
646  ob->partype = PAROBJECT;
647  ob->parsubstr[0] = 0;
648  return;
649  }
650 
651  /* Other partypes are deprecated, do not use here! */
653 
654  /* this could use some more checks */
655 
656  ob->parent = par;
657  ob->partype &= ~PARTYPE;
658  ob->partype |= type;
659  BLI_strncpy(ob->parsubstr, substr, sizeof(ob->parsubstr));
660 }
661 
662 /* Operator Property */
664  {PAR_OBJECT, "OBJECT", 0, "Object", ""},
665  {PAR_ARMATURE, "ARMATURE", 0, "Armature Deform", ""},
666  {PAR_ARMATURE_NAME, "ARMATURE_NAME", 0, " With Empty Groups", ""},
667  {PAR_ARMATURE_AUTO, "ARMATURE_AUTO", 0, " With Automatic Weights", ""},
668  {PAR_ARMATURE_ENVELOPE, "ARMATURE_ENVELOPE", 0, " With Envelope Weights", ""},
669  {PAR_BONE, "BONE", 0, "Bone", ""},
670  {PAR_BONE_RELATIVE, "BONE_RELATIVE", 0, "Bone Relative", ""},
671  {PAR_CURVE, "CURVE", 0, "Curve Deform", ""},
672  {PAR_FOLLOW, "FOLLOW", 0, "Follow Path", ""},
673  {PAR_PATH_CONST, "PATH_CONST", 0, "Path Constraint", ""},
674  {PAR_LATTICE, "LATTICE", 0, "Lattice Deform", ""},
675  {PAR_VERTEX, "VERTEX", 0, "Vertex", ""},
676  {PAR_VERTEX_TRI, "VERTEX_TRI", 0, "Vertex (Triangle)", ""},
677  {0, NULL, 0, NULL, NULL},
678 };
679 
681  const bContext *C,
682  Scene *scene,
683  Object *const ob,
684  Object *const par,
685  int partype,
686  const bool xmirror,
687  const bool keep_transform,
688  const int vert_par[3])
689 {
690  Main *bmain = CTX_data_main(C);
692  bPoseChannel *pchan = NULL;
693  bPoseChannel *pchan_eval = NULL;
694  Object *parent_eval = DEG_get_evaluated_object(depsgraph, par);
695 
697 
698  /* Preconditions. */
699  if (ob == par) {
700  /* Parenting an object to itself is impossible. */
701  return false;
702  }
703 
704  if (BKE_object_parent_loop_check(par, ob)) {
705  BKE_report(reports, RPT_ERROR, "Loop in parents");
706  return false;
707  }
708 
709  switch (partype) {
710  case PAR_FOLLOW:
711  case PAR_PATH_CONST: {
712  if (par->type != OB_CURVE) {
713  return false;
714  }
715  Curve *cu = par->data;
716  Curve *cu_eval = parent_eval->data;
717  if ((cu->flag & CU_PATH) == 0) {
718  cu->flag |= CU_PATH | CU_FOLLOW;
719  cu_eval->flag |= CU_PATH | CU_FOLLOW;
720  /* force creation of path data */
721  BKE_displist_make_curveTypes(depsgraph, scene, par, false, false);
722  }
723  else {
724  cu->flag |= CU_FOLLOW;
725  cu_eval->flag |= CU_FOLLOW;
726  }
727 
728  /* if follow, add F-Curve for ctime (i.e. "eval_time") so that path-follow works */
729  if (partype == PAR_FOLLOW) {
730  /* get or create F-Curve */
731  bAction *act = ED_id_action_ensure(bmain, &cu->id);
732  FCurve *fcu = ED_action_fcurve_ensure(bmain, act, NULL, NULL, "eval_time", 0);
733 
734  /* setup dummy 'generator' modifier here to get 1-1 correspondence still working */
735  if (!fcu->bezt && !fcu->fpt && !fcu->modifiers.first) {
737  }
738  }
739 
740  /* fall back on regular parenting now (for follow only) */
741  if (partype == PAR_FOLLOW) {
742  partype = PAR_OBJECT;
743  }
744  break;
745  }
746  case PAR_BONE:
747  case PAR_BONE_RELATIVE:
748  pchan = BKE_pose_channel_active(par);
749  pchan_eval = BKE_pose_channel_active(parent_eval);
750 
751  if (pchan == NULL) {
752  BKE_report(reports, RPT_ERROR, "No active bone");
753  return false;
754  }
755  }
756 
757  Object workob;
758 
759  /* Apply transformation of previous parenting. */
760  if (keep_transform) {
761  /* Was removed because of bug T23577,
762  * but this can be handy in some cases too T32616, so make optional. */
763  BKE_object_apply_mat4(ob, ob->obmat, false, false);
764  }
765 
766  /* Set the parent (except for follow-path constraint option). */
767  if (partype != PAR_PATH_CONST) {
768  ob->parent = par;
769  /* Always clear parentinv matrix for sake of consistency, see T41950. */
770  unit_m4(ob->parentinv);
772  }
773 
774  /* Handle types. */
775  if (pchan) {
776  BLI_strncpy(ob->parsubstr, pchan->name, sizeof(ob->parsubstr));
777  }
778  else {
779  ob->parsubstr[0] = 0;
780  }
781 
782  switch (partype) {
783  case PAR_PATH_CONST:
784  /* Don't do anything here, since this is not technically "parenting". */
785  break;
786  case PAR_CURVE:
787  case PAR_LATTICE:
788  case PAR_ARMATURE:
789  case PAR_ARMATURE_NAME:
791  case PAR_ARMATURE_AUTO:
792  /* partype is now set to PAROBJECT so that invisible 'virtual'
793  * modifiers don't need to be created.
794  * NOTE: the old (2.4x) method was to set ob->partype = PARSKEL,
795  * creating the virtual modifiers.
796  */
797  ob->partype = PAROBJECT; /* Note: DNA define, not operator property. */
798  /* ob->partype = PARSKEL; */ /* Note: DNA define, not operator property. */
799 
800  /* BUT, to keep the deforms, we need a modifier,
801  * and then we need to set the object that it uses
802  * - We need to ensure that the modifier we're adding doesn't already exist,
803  * so we check this by assuming that the parent is selected too.
804  */
805  /* XXX currently this should only happen for meshes, curves, surfaces,
806  * and lattices - this stuff isn't available for metas yet */
808  ModifierData *md;
809 
810  switch (partype) {
811  case PAR_CURVE: /* curve deform */
812  if (BKE_modifiers_is_deformed_by_curve(ob) != par) {
813  md = ED_object_modifier_add(reports, bmain, scene, ob, NULL, eModifierType_Curve);
814  if (md) {
815  ((CurveModifierData *)md)->object = par;
816  }
817  if (par->runtime.curve_cache &&
820  }
821  }
822  break;
823  case PAR_LATTICE: /* lattice deform */
824  if (BKE_modifiers_is_deformed_by_lattice(ob) != par) {
825  md = ED_object_modifier_add(reports, bmain, scene, ob, NULL, eModifierType_Lattice);
826  if (md) {
827  ((LatticeModifierData *)md)->object = par;
828  }
829  }
830  break;
831  default: /* armature deform */
832  if (BKE_modifiers_is_deformed_by_armature(ob) != par) {
833  md = ED_object_modifier_add(reports, bmain, scene, ob, NULL, eModifierType_Armature);
834  if (md) {
835  ((ArmatureModifierData *)md)->object = par;
836  }
837  }
838  break;
839  }
840  }
841  break;
842  case PAR_BONE:
843  ob->partype = PARBONE; /* Note: DNA define, not operator property. */
844  if (pchan->bone) {
845  pchan->bone->flag &= ~BONE_RELATIVE_PARENTING;
846  pchan_eval->bone->flag &= ~BONE_RELATIVE_PARENTING;
847  }
848  break;
849  case PAR_BONE_RELATIVE:
850  ob->partype = PARBONE; /* Note: DNA define, not operator property. */
851  if (pchan->bone) {
852  pchan->bone->flag |= BONE_RELATIVE_PARENTING;
853  pchan_eval->bone->flag |= BONE_RELATIVE_PARENTING;
854  }
855  break;
856  case PAR_VERTEX:
857  ob->partype = PARVERT1;
858  ob->par1 = vert_par[0];
859  break;
860  case PAR_VERTEX_TRI:
861  ob->partype = PARVERT3;
862  copy_v3_v3_int(&ob->par1, vert_par);
863  break;
864  case PAR_OBJECT:
865  case PAR_FOLLOW:
866  ob->partype = PAROBJECT; /* Note: DNA define, not operator property. */
867  break;
868  }
869 
870  /* Constraint and set parent inverse. */
871  const bool is_armature_parent = ELEM(
873  if (partype == PAR_PATH_CONST) {
874  bConstraint *con;
876  float cmat[4][4], vec[3];
877 
879 
880  data = con->data;
881  data->tar = par;
882 
885  sub_v3_v3v3(vec, ob->obmat[3], cmat[3]);
886 
887  copy_v3_v3(ob->loc, vec);
888  }
889  else if (is_armature_parent && (ob->type == OB_MESH) && (par->type == OB_ARMATURE)) {
890  if (partype == PAR_ARMATURE_NAME) {
892  reports, depsgraph, scene, ob, par, ARM_GROUPS_NAME, false);
893  }
894  else if (partype == PAR_ARMATURE_ENVELOPE) {
896  reports, depsgraph, scene, ob, par, ARM_GROUPS_ENVELOPE, xmirror);
897  }
898  else if (partype == PAR_ARMATURE_AUTO) {
899  WM_cursor_wait(true);
901  reports, depsgraph, scene, ob, par, ARM_GROUPS_AUTO, xmirror);
902  WM_cursor_wait(false);
903  }
904  /* get corrected inverse */
905  ob->partype = PAROBJECT;
907 
908  invert_m4_m4(ob->parentinv, workob.obmat);
909  }
910  else if (is_armature_parent && (ob->type == OB_GPENCIL) && (par->type == OB_ARMATURE)) {
911  if (partype == PAR_ARMATURE) {
912  ED_gpencil_add_armature(C, reports, ob, par);
913  }
914  else if (partype == PAR_ARMATURE_NAME) {
916  }
917  else if (ELEM(partype, PAR_ARMATURE_AUTO, PAR_ARMATURE_ENVELOPE)) {
918  WM_cursor_wait(true);
920  WM_cursor_wait(false);
921  }
922  /* get corrected inverse */
923  ob->partype = PAROBJECT;
925 
926  invert_m4_m4(ob->parentinv, workob.obmat);
927  }
928  else if ((ob->type == OB_GPENCIL) && (par->type == OB_LATTICE)) {
929  /* Add Lattice modifier */
930  if (partype == PAR_LATTICE) {
931  ED_gpencil_add_lattice_modifier(C, reports, ob, par);
932  }
933  /* get corrected inverse */
934  ob->partype = PAROBJECT;
936 
937  invert_m4_m4(ob->parentinv, workob.obmat);
938  }
939  else {
940  /* calculate inverse parent matrix */
942  invert_m4_m4(ob->parentinv, workob.obmat);
943  }
944 
946  return true;
947 }
948 
949 static void parent_set_vert_find(KDTree_3d *tree, Object *child, int vert_par[3], bool is_tri)
950 {
951  const float *co_find = child->obmat[3];
952  if (is_tri) {
953  KDTreeNearest_3d nearest[3];
954  int tot;
955 
956  tot = BLI_kdtree_3d_find_nearest_n(tree, co_find, nearest, 3);
957  BLI_assert(tot == 3);
958  UNUSED_VARS(tot);
959 
960  vert_par[0] = nearest[0].index;
961  vert_par[1] = nearest[1].index;
962  vert_par[2] = nearest[2].index;
963 
964  BLI_assert(min_iii(UNPACK3(vert_par)) >= 0);
965  }
966  else {
967  vert_par[0] = BLI_kdtree_3d_find_nearest(tree, co_find, NULL);
968  BLI_assert(vert_par[0] >= 0);
969  vert_par[1] = 0;
970  vert_par[2] = 0;
971  }
972 }
973 
978  int partype;
980  bool xmirror;
982 };
983 
984 static bool parent_set_nonvertex_parent(bContext *C, struct ParentingContext *parenting_context)
985 {
986  CTX_DATA_BEGIN (C, Object *, ob, selected_editable_objects) {
987  if (ob == parenting_context->par) {
988  /* ED_object_parent_set() will fail (and thus return false), but this case shouldn't break
989  * this loop. It's expected that the active object is also selected. */
990  continue;
991  }
992 
993  if (!ED_object_parent_set(parenting_context->reports,
994  C,
995  parenting_context->scene,
996  ob,
997  parenting_context->par,
998  parenting_context->partype,
999  parenting_context->xmirror,
1000  parenting_context->keep_transform,
1001  NULL)) {
1002  return false;
1003  }
1004  }
1005  CTX_DATA_END;
1006 
1007  return true;
1008 }
1009 
1011  struct ParentingContext *parenting_context,
1012  struct KDTree_3d *tree)
1013 {
1014  int vert_par[3] = {0, 0, 0};
1015 
1016  CTX_DATA_BEGIN (C, Object *, ob, selected_editable_objects) {
1017  if (ob == parenting_context->par) {
1018  /* ED_object_parent_set() will fail (and thus return false), but this case shouldn't break
1019  * this loop. It's expected that the active object is also selected. */
1020  continue;
1021  }
1022 
1023  parent_set_vert_find(tree, ob, vert_par, parenting_context->is_vertex_tri);
1024  if (!ED_object_parent_set(parenting_context->reports,
1025  C,
1026  parenting_context->scene,
1027  ob,
1028  parenting_context->par,
1029  parenting_context->partype,
1030  parenting_context->xmirror,
1031  parenting_context->keep_transform,
1032  vert_par)) {
1033  return false;
1034  }
1035  }
1036  CTX_DATA_END;
1037  return true;
1038 }
1039 
1040 static bool parent_set_vertex_parent(bContext *C, struct ParentingContext *parenting_context)
1041 {
1042  struct KDTree_3d *tree = NULL;
1043  int tree_tot;
1044 
1045  tree = BKE_object_as_kdtree(parenting_context->par, &tree_tot);
1046  BLI_assert(tree != NULL);
1047 
1048  if (tree_tot < (parenting_context->is_vertex_tri ? 3 : 1)) {
1049  BKE_report(parenting_context->reports, RPT_ERROR, "Not enough vertices for vertex-parent");
1050  BLI_kdtree_3d_free(tree);
1051  return false;
1052  }
1053 
1054  const bool ok = parent_set_vertex_parent_with_kdtree(C, parenting_context, tree);
1055  BLI_kdtree_3d_free(tree);
1056  return ok;
1057 }
1058 
1060 {
1061  const int partype = RNA_enum_get(op->ptr, "type");
1062  struct ParentingContext parenting_context = {
1063  .reports = op->reports,
1064  .scene = CTX_data_scene(C),
1065  .par = ED_object_active_context(C),
1066  .partype = partype,
1067  .is_vertex_tri = partype == PAR_VERTEX_TRI,
1068  .xmirror = RNA_boolean_get(op->ptr, "xmirror"),
1069  .keep_transform = RNA_boolean_get(op->ptr, "keep_transform"),
1070  };
1071 
1072  bool ok;
1073  if (ELEM(parenting_context.partype, PAR_VERTEX, PAR_VERTEX_TRI)) {
1074  ok = parent_set_vertex_parent(C, &parenting_context);
1075  }
1076  else {
1077  ok = parent_set_nonvertex_parent(C, &parenting_context);
1078  }
1079  if (!ok) {
1080  return OPERATOR_CANCELLED;
1081  }
1082 
1083  Main *bmain = CTX_data_main(C);
1084  DEG_relations_tag_update(bmain);
1087 
1088  return OPERATOR_FINISHED;
1089 }
1090 
1092 {
1093  Object *parent = ED_object_active_context(C);
1094  uiPopupMenu *pup = UI_popup_menu_begin(C, IFACE_("Set Parent To"), ICON_NONE);
1095  uiLayout *layout = UI_popup_menu_layout(pup);
1096 
1097  PointerRNA opptr;
1098 #if 0
1099  uiItemEnumO_ptr(layout, ot, NULL, 0, "type", PAR_OBJECT);
1100 #else
1101  uiItemFullO_ptr(layout, ot, IFACE_("Object"), ICON_NONE, NULL, WM_OP_EXEC_DEFAULT, 0, &opptr);
1102  RNA_enum_set(&opptr, "type", PAR_OBJECT);
1103  RNA_boolean_set(&opptr, "keep_transform", false);
1104 
1105  uiItemFullO_ptr(layout,
1106  ot,
1107  IFACE_("Object (Keep Transform)"),
1108  ICON_NONE,
1109  NULL,
1111  0,
1112  &opptr);
1113  RNA_enum_set(&opptr, "type", PAR_OBJECT);
1114  RNA_boolean_set(&opptr, "keep_transform", true);
1115 #endif
1116 
1117  uiItemO(
1118  layout, IFACE_("Object (Without Inverse)"), ICON_NONE, "OBJECT_OT_parent_no_inverse_set");
1119 
1120  struct {
1121  bool mesh, gpencil;
1122  } has_children_of_type = {0};
1123 
1124  CTX_DATA_BEGIN (C, Object *, child, selected_editable_objects) {
1125  if (child == parent) {
1126  continue;
1127  }
1128  if (child->type == OB_MESH) {
1129  has_children_of_type.mesh = true;
1130  }
1131  if (child->type == OB_GPENCIL) {
1132  has_children_of_type.gpencil = true;
1133  }
1134  }
1135  CTX_DATA_END;
1136 
1137  if (parent->type == OB_ARMATURE) {
1138  uiItemEnumO_ptr(layout, ot, NULL, 0, "type", PAR_ARMATURE);
1139  uiItemEnumO_ptr(layout, ot, NULL, 0, "type", PAR_ARMATURE_NAME);
1140  if (!has_children_of_type.gpencil) {
1141  uiItemEnumO_ptr(layout, ot, NULL, 0, "type", PAR_ARMATURE_ENVELOPE);
1142  }
1143  if (has_children_of_type.mesh || has_children_of_type.gpencil) {
1144  uiItemEnumO_ptr(layout, ot, NULL, 0, "type", PAR_ARMATURE_AUTO);
1145  }
1146  uiItemEnumO_ptr(layout, ot, NULL, 0, "type", PAR_BONE);
1147  uiItemEnumO_ptr(layout, ot, NULL, 0, "type", PAR_BONE_RELATIVE);
1148  }
1149  else if (parent->type == OB_CURVE) {
1150  uiItemEnumO_ptr(layout, ot, NULL, 0, "type", PAR_CURVE);
1151  uiItemEnumO_ptr(layout, ot, NULL, 0, "type", PAR_FOLLOW);
1152  uiItemEnumO_ptr(layout, ot, NULL, 0, "type", PAR_PATH_CONST);
1153  }
1154  else if (parent->type == OB_LATTICE) {
1155  uiItemEnumO_ptr(layout, ot, NULL, 0, "type", PAR_LATTICE);
1156  }
1157 
1158  /* vertex parenting */
1159  if (OB_TYPE_SUPPORT_PARVERT(parent->type)) {
1160  uiItemEnumO_ptr(layout, ot, NULL, 0, "type", PAR_VERTEX);
1161  uiItemEnumO_ptr(layout, ot, NULL, 0, "type", PAR_VERTEX_TRI);
1162  }
1163 
1164  UI_popup_menu_end(C, pup);
1165 
1166  return OPERATOR_INTERFACE;
1167 }
1168 
1169 static int parent_set_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
1170 {
1171  if (RNA_property_is_set(op->ptr, op->type->prop)) {
1172  return parent_set_exec(C, op);
1173  }
1174  return parent_set_invoke_menu(C, op->type);
1175 }
1176 
1178  wmOperator *op,
1179  const PropertyRNA *prop)
1180 {
1181  const char *prop_id = RNA_property_identifier(prop);
1182 
1183  /* Only show XMirror for PAR_ARMATURE_ENVELOPE and PAR_ARMATURE_AUTO! */
1184  if (STREQ(prop_id, "xmirror")) {
1185  const int type = RNA_enum_get(op->ptr, "type");
1187  return true;
1188  }
1189  return false;
1190  }
1191 
1192  return true;
1193 }
1194 
1196 {
1197  /* identifiers */
1198  ot->name = "Make Parent";
1199  ot->description = "Set the object's parenting";
1200  ot->idname = "OBJECT_OT_parent_set";
1201 
1202  /* api callbacks */
1204  ot->exec = parent_set_exec;
1207 
1208  /* flags */
1210 
1211  ot->prop = RNA_def_enum(ot->srna, "type", prop_make_parent_types, 0, "Type", "");
1213  ot->srna,
1214  "xmirror",
1215  false,
1216  "X Mirror",
1217  "Apply weights symmetrically along X axis, for Envelope/Automatic vertex groups creation");
1219  "keep_transform",
1220  false,
1221  "Keep Transform",
1222  "Apply transformation before parenting");
1223 }
1224 
1227 /* ------------------------------------------------------------------- */
1232 {
1233  Main *bmain = CTX_data_main(C);
1235 
1237 
1238  /* context iterator */
1239  CTX_DATA_BEGIN (C, Object *, ob, selected_editable_objects) {
1240  if (ob != par) {
1241  if (BKE_object_parent_loop_check(par, ob)) {
1242  BKE_report(op->reports, RPT_ERROR, "Loop in parents");
1243  }
1244  else {
1245  /* clear inverse matrix and also the object location */
1246  unit_m4(ob->parentinv);
1247  memset(ob->loc, 0, sizeof(float[3]));
1248 
1249  /* set recalc flags */
1251 
1252  /* set parenting type for object - object only... */
1253  ob->parent = par;
1254  ob->partype = PAROBJECT; /* note, dna define, not operator property */
1255  }
1256  }
1257  }
1258  CTX_DATA_END;
1259 
1260  DEG_relations_tag_update(bmain);
1263 
1264  return OPERATOR_FINISHED;
1265 }
1266 
1268 {
1269  /* identifiers */
1270  ot->name = "Make Parent without Inverse";
1271  ot->description = "Set the object's parenting without setting the inverse parent correction";
1272  ot->idname = "OBJECT_OT_parent_no_inverse_set";
1273 
1274  /* api callbacks */
1278 
1279  /* flags */
1281 }
1282 
1285 /* ------------------------------------------------------------------- */
1289 enum {
1292 };
1293 
1295  {CLEAR_TRACK, "CLEAR", 0, "Clear Track", ""},
1297  "CLEAR_KEEP_TRANSFORM",
1298  0,
1299  "Clear and Keep Transformation (Clear Track)",
1300  ""},
1301  {0, NULL, 0, NULL, NULL},
1302 };
1303 
1304 /* note, poll should check for editable scene */
1306 {
1307  Main *bmain = CTX_data_main(C);
1308  const int type = RNA_enum_get(op->ptr, "type");
1309 
1310  if (CTX_data_edit_object(C)) {
1311  BKE_report(op->reports, RPT_ERROR, "Operation cannot be performed in edit mode");
1312  return OPERATOR_CANCELLED;
1313  }
1314  CTX_DATA_BEGIN (C, Object *, ob, selected_editable_objects) {
1315  bConstraint *con, *pcon;
1316 
1317  /* remove track-object for old track */
1318  ob->track = NULL;
1320 
1321  /* also remove all tracking constraints */
1322  for (con = ob->constraints.last; con; con = pcon) {
1323  pcon = con->prev;
1324  if (ELEM(con->type,
1328  BKE_constraint_remove(&ob->constraints, con);
1329  }
1330  }
1331 
1333  BKE_object_apply_mat4(ob, ob->obmat, true, true);
1334  }
1335  }
1336  CTX_DATA_END;
1337 
1338  DEG_relations_tag_update(bmain);
1340 
1341  return OPERATOR_FINISHED;
1342 }
1343 
1345 {
1346  /* identifiers */
1347  ot->name = "Clear Track";
1348  ot->description = "Clear tracking constraint or flag from object";
1349  ot->idname = "OBJECT_OT_track_clear";
1350 
1351  /* api callbacks */
1354 
1356 
1357  /* flags */
1359 
1360  ot->prop = RNA_def_enum(ot->srna, "type", prop_clear_track_types, 0, "Type", "");
1361 }
1362 
1365 /* ------------------------------------------------------------------- */
1369 enum {
1373 };
1374 
1376  {CREATE_TRACK_DAMPTRACK, "DAMPTRACK", 0, "Damped Track Constraint", ""},
1377  {CREATE_TRACK_TRACKTO, "TRACKTO", 0, "Track to Constraint", ""},
1378  {CREATE_TRACK_LOCKTRACK, "LOCKTRACK", 0, "Lock Track Constraint", ""},
1379  {0, NULL, 0, NULL, NULL},
1380 };
1381 
1383 {
1384  Main *bmain = CTX_data_main(C);
1385  Object *obact = ED_object_active_context(C);
1386 
1387  const int type = RNA_enum_get(op->ptr, "type");
1388 
1389  switch (type) {
1390  case CREATE_TRACK_DAMPTRACK: {
1391  bConstraint *con;
1393 
1394  CTX_DATA_BEGIN (C, Object *, ob, selected_editable_objects) {
1395  if (ob != obact) {
1397 
1398  data = con->data;
1399  data->tar = obact;
1400  DEG_id_tag_update(&ob->id,
1402 
1403  /* Light, Camera and Speaker track differently by default */
1404  if (ELEM(ob->type, OB_LAMP, OB_CAMERA, OB_SPEAKER)) {
1405  data->trackflag = TRACK_nZ;
1406  }
1407  }
1408  }
1409  CTX_DATA_END;
1410  break;
1411  }
1412  case CREATE_TRACK_TRACKTO: {
1413  bConstraint *con;
1415 
1416  CTX_DATA_BEGIN (C, Object *, ob, selected_editable_objects) {
1417  if (ob != obact) {
1419 
1420  data = con->data;
1421  data->tar = obact;
1422  DEG_id_tag_update(&ob->id,
1424 
1425  /* Light, Camera and Speaker track differently by default */
1426  if (ELEM(ob->type, OB_LAMP, OB_CAMERA, OB_SPEAKER)) {
1427  data->reserved1 = TRACK_nZ;
1428  data->reserved2 = UP_Y;
1429  }
1430  }
1431  }
1432  CTX_DATA_END;
1433  break;
1434  }
1435  case CREATE_TRACK_LOCKTRACK: {
1436  bConstraint *con;
1438 
1439  CTX_DATA_BEGIN (C, Object *, ob, selected_editable_objects) {
1440  if (ob != obact) {
1442 
1443  data = con->data;
1444  data->tar = obact;
1445  DEG_id_tag_update(&ob->id,
1447 
1448  /* Light, Camera and Speaker track differently by default */
1449  if (ELEM(ob->type, OB_LAMP, OB_CAMERA, OB_SPEAKER)) {
1450  data->trackflag = TRACK_nZ;
1451  data->lockflag = LOCK_Y;
1452  }
1453  }
1454  }
1455  CTX_DATA_END;
1456  break;
1457  }
1458  }
1459 
1460  DEG_relations_tag_update(bmain);
1462 
1463  return OPERATOR_FINISHED;
1464 }
1465 
1467 {
1468  /* identifiers */
1469  ot->name = "Make Track";
1470  ot->description = "Make the object track another object, using various methods/constraints";
1471  ot->idname = "OBJECT_OT_track_set";
1472 
1473  /* api callbacks */
1475  ot->exec = track_set_exec;
1476 
1478 
1479  /* flags */
1481 
1482  /* properties */
1483  ot->prop = RNA_def_enum(ot->srna, "type", prop_make_track_types, 0, "Type", "");
1484 }
1485 
1488 /* ------------------------------------------------------------------- */
1492 #if 0
1493 static void link_to_scene(Main *UNUSED(bmain), ushort UNUSED(nr))
1494 {
1495  Scene *sce = (Scene *)BLI_findlink(&bmain->scene, G.curscreen->scenenr - 1);
1496  Base *base, *nbase;
1497 
1498  if (sce == NULL) {
1499  return;
1500  }
1501  if (sce->id.lib) {
1502  return;
1503  }
1504 
1505  for (base = FIRSTBASE; base; base = base->next) {
1506  if (BASE_SELECTED(v3d, base)) {
1507  nbase = MEM_mallocN(sizeof(Base), "newbase");
1508  *nbase = *base;
1509  BLI_addhead(&(sce->base), nbase);
1510  id_us_plus((ID *)base->object);
1511  }
1512  }
1513 }
1514 #endif
1515 
1517 {
1518  Main *bmain = CTX_data_main(C);
1519  Scene *scene_to = BLI_findlink(&bmain->scenes, RNA_enum_get(op->ptr, "scene"));
1520 
1521  if (scene_to == NULL) {
1522  BKE_report(op->reports, RPT_ERROR, "Could not find scene");
1523  return OPERATOR_CANCELLED;
1524  }
1525 
1526  if (scene_to == CTX_data_scene(C)) {
1527  BKE_report(op->reports, RPT_ERROR, "Cannot link objects into the same scene");
1528  return OPERATOR_CANCELLED;
1529  }
1530 
1531  if (ID_IS_LINKED(scene_to)) {
1532  BKE_report(op->reports, RPT_ERROR, "Cannot link objects into a linked scene");
1533  return OPERATOR_CANCELLED;
1534  }
1535 
1536  Collection *collection_to = scene_to->master_collection;
1537  CTX_DATA_BEGIN (C, Base *, base, selected_bases) {
1538  BKE_collection_object_add(bmain, collection_to, base->object);
1539  }
1540  CTX_DATA_END;
1541 
1542  DEG_relations_tag_update(bmain);
1543 
1544  /* redraw the 3D view because the object center points are colored differently */
1546 
1547  /* one day multiple scenes will be visible, then we should have some update function for them
1548  */
1549  return OPERATOR_FINISHED;
1550 }
1551 
1552 enum {
1561 };
1562 
1563 /* Return true if make link data is allowed, false otherwise */
1564 static bool allow_make_links_data(const int type, Object *ob_src, Object *ob_dst)
1565 {
1566  switch (type) {
1567  case MAKE_LINKS_OBDATA:
1568  if (ob_src->type == ob_dst->type && ob_src->type != OB_EMPTY) {
1569  return true;
1570  }
1571  break;
1572  case MAKE_LINKS_MATERIALS:
1573  if (OB_TYPE_SUPPORT_MATERIAL(ob_src->type) && OB_TYPE_SUPPORT_MATERIAL(ob_dst->type) &&
1574  /* Linking non-grease-pencil materials to a grease-pencil object causes issues.
1575  * We make sure that if one of the objects is a grease-pencil object, the other must be
1576  * as well. */
1577  ((ob_src->type == OB_GPENCIL) == (ob_dst->type == OB_GPENCIL))) {
1578  return true;
1579  }
1580  break;
1582  if (ob_dst->type == OB_EMPTY) {
1583  return true;
1584  }
1585  break;
1586  case MAKE_LINKS_ANIMDATA:
1587  case MAKE_LINKS_GROUP:
1588  return true;
1589  case MAKE_LINKS_MODIFIERS:
1590  if (!ELEM(OB_EMPTY, ob_src->type, ob_dst->type)) {
1591  return true;
1592  }
1593  break;
1594  case MAKE_LINKS_FONTS:
1595  if ((ob_src->data != ob_dst->data) && (ob_src->type == OB_FONT) &&
1596  (ob_dst->type == OB_FONT)) {
1597  return true;
1598  }
1599  break;
1600  case MAKE_LINKS_SHADERFX:
1601  if ((ob_src->type == OB_GPENCIL) && (ob_dst->type == OB_GPENCIL)) {
1602  return true;
1603  }
1604  break;
1605  }
1606  return false;
1607 }
1608 
1610 {
1612  Main *bmain = CTX_data_main(C);
1613  const int type = RNA_enum_get(op->ptr, "type");
1614  Object *ob_src;
1615  ID *obdata_id;
1616  int a;
1617 
1618  /* collection */
1619  LinkNode *ob_collections = NULL;
1620  bool is_cycle = false;
1621  bool is_lib = false;
1622 
1623  ob_src = ED_object_active_context(C);
1624 
1625  /* avoid searching all collections in source object each time */
1626  if (type == MAKE_LINKS_GROUP) {
1627  ob_collections = BKE_object_groups(bmain, scene, ob_src);
1628  }
1629 
1630  CTX_DATA_BEGIN (C, Base *, base_dst, selected_editable_bases) {
1631  Object *ob_dst = base_dst->object;
1632 
1633  if (ob_src != ob_dst) {
1634  if (allow_make_links_data(type, ob_src, ob_dst)) {
1635  obdata_id = ob_dst->data;
1636 
1637  switch (type) {
1638  case MAKE_LINKS_OBDATA: /* obdata */
1639  id_us_min(obdata_id);
1640 
1641  obdata_id = ob_src->data;
1642  id_us_plus(obdata_id);
1643  ob_dst->data = obdata_id;
1644 
1645  /* if amount of material indices changed: */
1646  BKE_object_materials_test(bmain, ob_dst, ob_dst->data);
1647 
1649  break;
1650  case MAKE_LINKS_MATERIALS:
1651  /* new approach, using functions from kernel */
1652  for (a = 0; a < ob_src->totcol; a++) {
1653  Material *ma = BKE_object_material_get(ob_src, a + 1);
1654  /* also works with `ma == NULL` */
1655  BKE_object_material_assign(bmain, ob_dst, ma, a + 1, BKE_MAT_ASSIGN_USERPREF);
1656  }
1658  break;
1659  case MAKE_LINKS_ANIMDATA:
1660  BKE_animdata_copy_id(bmain, (ID *)ob_dst, (ID *)ob_src, 0);
1661  if (ob_dst->data && ob_src->data) {
1662  if (ID_IS_LINKED(obdata_id)) {
1663  is_lib = true;
1664  break;
1665  }
1666  BKE_animdata_copy_id(bmain, (ID *)ob_dst->data, (ID *)ob_src->data, 0);
1667  }
1668  DEG_id_tag_update(&ob_dst->id,
1670  break;
1671  case MAKE_LINKS_GROUP: {
1672  LinkNode *collection_node;
1673 
1674  /* first clear collections */
1675  BKE_object_groups_clear(bmain, scene, ob_dst);
1676 
1677  /* now add in the collections from the link nodes */
1678  for (collection_node = ob_collections; collection_node;
1679  collection_node = collection_node->next) {
1680  if (ob_dst->instance_collection != collection_node->link) {
1681  BKE_collection_object_add(bmain, collection_node->link, ob_dst);
1682  }
1683  else {
1684  is_cycle = true;
1685  }
1686  }
1687  break;
1688  }
1690  ob_dst->instance_collection = ob_src->instance_collection;
1691  if (ob_dst->instance_collection) {
1692  id_us_plus(&ob_dst->instance_collection->id);
1693  ob_dst->transflag |= OB_DUPLICOLLECTION;
1694  }
1696  break;
1697  case MAKE_LINKS_MODIFIERS:
1698  BKE_object_link_modifiers(ob_dst, ob_src);
1699  DEG_id_tag_update(&ob_dst->id,
1701  break;
1702  case MAKE_LINKS_FONTS: {
1703  Curve *cu_src = ob_src->data;
1704  Curve *cu_dst = ob_dst->data;
1705 
1706  if (ID_IS_LINKED(obdata_id)) {
1707  is_lib = true;
1708  break;
1709  }
1710 
1711  if (cu_dst->vfont) {
1712  id_us_min(&cu_dst->vfont->id);
1713  }
1714  cu_dst->vfont = cu_src->vfont;
1715  id_us_plus((ID *)cu_dst->vfont);
1716  if (cu_dst->vfontb) {
1717  id_us_min(&cu_dst->vfontb->id);
1718  }
1719  cu_dst->vfontb = cu_src->vfontb;
1720  id_us_plus((ID *)cu_dst->vfontb);
1721  if (cu_dst->vfonti) {
1722  id_us_min(&cu_dst->vfonti->id);
1723  }
1724  cu_dst->vfonti = cu_src->vfonti;
1725  id_us_plus((ID *)cu_dst->vfonti);
1726  if (cu_dst->vfontbi) {
1727  id_us_min(&cu_dst->vfontbi->id);
1728  }
1729  cu_dst->vfontbi = cu_src->vfontbi;
1730  id_us_plus((ID *)cu_dst->vfontbi);
1731 
1732  DEG_id_tag_update(&ob_dst->id,
1734  break;
1735  }
1736  case MAKE_LINKS_SHADERFX:
1737  ED_object_shaderfx_link(ob_dst, ob_src);
1738  DEG_id_tag_update(&ob_dst->id,
1740  break;
1741  }
1742  }
1743  }
1744  }
1745  CTX_DATA_END;
1746 
1747  if (type == MAKE_LINKS_GROUP) {
1748  if (ob_collections) {
1749  BLI_linklist_free(ob_collections, NULL);
1750  }
1751 
1752  if (is_cycle) {
1753  BKE_report(op->reports, RPT_WARNING, "Skipped some collections because of cycle detected");
1754  }
1755  }
1756 
1757  if (is_lib) {
1758  BKE_report(op->reports, RPT_WARNING, "Skipped editing library object data");
1759  }
1760 
1761  DEG_relations_tag_update(bmain);
1765 
1766  return OPERATOR_FINISHED;
1767 }
1768 
1770 {
1771  PropertyRNA *prop;
1772 
1773  /* identifiers */
1774  ot->name = "Link Objects to Scene";
1775  ot->description = "Link selection to another scene";
1776  ot->idname = "OBJECT_OT_make_links_scene";
1777 
1778  /* api callbacks */
1781  /* better not run the poll check */
1782 
1783  /* flags */
1785 
1786  /* properties */
1787  prop = RNA_def_enum(ot->srna, "scene", DummyRNA_NULL_items, 0, "Scene", "");
1790  ot->prop = prop;
1791 }
1792 
1794 {
1795  static const EnumPropertyItem make_links_items[] = {
1796  {MAKE_LINKS_OBDATA, "OBDATA", 0, "Link Object Data", "Replace assigned Object Data"},
1797  {MAKE_LINKS_MATERIALS, "MATERIAL", 0, "Link Materials", "Replace assigned Materials"},
1799  "ANIMATION",
1800  0,
1801  "Link Animation Data",
1802  "Replace assigned Animation Data"},
1803  {MAKE_LINKS_GROUP, "GROUPS", 0, "Link Collections", "Replace assigned Collections"},
1805  "DUPLICOLLECTION",
1806  0,
1807  "Link Instance Collection",
1808  "Replace assigned Collection Instance"},
1809  {MAKE_LINKS_FONTS, "FONTS", 0, "Link Fonts to Text", "Replace Text object Fonts"},
1810  {0, "", 0, NULL, NULL},
1811  {MAKE_LINKS_MODIFIERS, "MODIFIERS", 0, "Copy Modifiers", "Replace Modifiers"},
1813  "EFFECTS",
1814  0,
1815  "Copy Grease Pencil Effects",
1816  "Replace Grease Pencil Effects"},
1817  {0, NULL, 0, NULL, NULL},
1818  };
1819 
1820  /* identifiers */
1821  ot->name = "Link/Transfer Data";
1822  ot->description = "Transfer data from active object to selected objects";
1823  ot->idname = "OBJECT_OT_make_links_data";
1824 
1825  /* api callbacks */
1828 
1829  /* flags */
1831 
1832  /* properties */
1833  ot->prop = RNA_def_enum(ot->srna, "type", make_links_items, 0, "Type", "");
1834 }
1835 
1838 /* ------------------------------------------------------------------- */
1842 static void libblock_relink_collection(Collection *collection, const bool do_collection)
1843 {
1844  if (do_collection) {
1845  BKE_libblock_relink_to_newid(&collection->id);
1846  }
1847 
1848  for (CollectionObject *cob = collection->gobject.first; cob != NULL; cob = cob->next) {
1849  BKE_libblock_relink_to_newid(&cob->ob->id);
1850  }
1851 
1852  LISTBASE_FOREACH (CollectionChild *, child, &collection->children) {
1853  libblock_relink_collection(child->collection, true);
1854  }
1855 }
1856 
1858  Scene *scene,
1859  Collection *collection,
1860  const int flag,
1861  const bool copy_collections,
1862  const bool is_master_collection)
1863 {
1864  /* Generate new copies for objects in given collection and all its children,
1865  * and optionally also copy collections themselves. */
1866  if (copy_collections && !is_master_collection) {
1867  Collection *collection_new = (Collection *)BKE_id_copy(bmain, &collection->id);
1868  id_us_min(&collection_new->id);
1869  collection = ID_NEW_SET(collection, collection_new);
1870  }
1871 
1872  /* We do not remap to new objects here, this is done in separate step. */
1873  LISTBASE_FOREACH (CollectionObject *, cob, &collection->gobject) {
1874  Object *ob = cob->ob;
1875  /* an object may be in more than one collection */
1876  if ((ob->id.newid == NULL) && ((ob->flag & flag) == flag)) {
1877  if (!ID_IS_LINKED(ob) && BKE_object_scenes_users_get(bmain, ob) > 1) {
1878  ID_NEW_SET(ob, BKE_id_copy(bmain, &ob->id));
1879  id_us_min(ob->id.newid);
1880  }
1881  }
1882  }
1883 
1884  /* Since master collection has already be duplicated as part of scene copy,
1885  * we do not duplicate it here.
1886  * However, this means its children need to be re-added manually here,
1887  * otherwise their parent lists are empty (which will lead to crashes, see T63101). */
1888  CollectionChild *child_next, *child = collection->children.first;
1889  CollectionChild *orig_child_last = collection->children.last;
1890  for (; child != NULL; child = child_next) {
1891  child_next = child->next;
1892  Collection *collection_child_new = single_object_users_collection(
1893  bmain, scene, child->collection, flag, copy_collections, false);
1894 
1895  if (is_master_collection && copy_collections && child->collection != collection_child_new) {
1896  /* We do not want a collection sync here, our collections are in a complete uninitialized
1897  * state currently. With current code, that would lead to a memory leak - because of
1898  * reasons. It would be a useless loss of computing anyway, since caller has to fully
1899  * refresh view-layers/collections caching at the end. */
1900  BKE_collection_child_add_no_sync(collection, collection_child_new);
1901  BLI_remlink(&collection->children, child);
1902  MEM_freeN(child);
1903  if (child == orig_child_last) {
1904  break;
1905  }
1906  }
1907  }
1908 
1909  return collection;
1910 }
1911 
1912 /* Warning, sets ID->newid pointers of objects and collections, but does not clear them. */
1914  Main *bmain, Scene *scene, View3D *v3d, const int flag, const bool copy_collections)
1915 {
1916  /* duplicate all the objects of the scene (and matching collections, if required). */
1917  Collection *master_collection = scene->master_collection;
1918  single_object_users_collection(bmain, scene, master_collection, flag, copy_collections, true);
1919 
1920  /* Will also handle the master collection. */
1922 
1923  /* Collection and object pointers in collections */
1925 
1926  /* We also have to handle runtime things in UI. */
1927  if (v3d) {
1928  ID_NEW_REMAP(v3d->camera);
1929  }
1930 
1931  /* Making single user may affect other scenes if they share
1932  * with current one some collections in their ViewLayer. */
1934 }
1935 
1936 /* not an especially efficient function, only added so the single user
1937  * button can be functional.*/
1939 {
1940  FOREACH_SCENE_OBJECT_BEGIN (scene, ob_iter) {
1941  ob_iter->flag &= ~OB_DONE;
1942  }
1944 
1945  /* tag only the one object */
1946  ob->flag |= OB_DONE;
1947 
1948  single_object_users(bmain, scene, NULL, OB_DONE, false);
1950 }
1951 
1953  Main *bmain, Scene *scene, ViewLayer *view_layer, View3D *v3d, const int flag)
1954 {
1955  Light *la;
1956  Curve *cu;
1957  Camera *cam;
1958  Mesh *me;
1959  Lattice *lat;
1960  ID *id;
1961 
1962  FOREACH_OBJECT_FLAG_BEGIN (scene, view_layer, v3d, flag, ob) {
1963  if (!ID_IS_LINKED(ob)) {
1964  id = ob->data;
1965 
1966  if (id && id->us > 1 && !ID_IS_LINKED(id)) {
1968 
1969  switch (ob->type) {
1970  case OB_LAMP:
1971  ob->data = la = ID_NEW_SET(ob->data, BKE_id_copy(bmain, ob->data));
1972  break;
1973  case OB_CAMERA:
1974  cam = ob->data = ID_NEW_SET(ob->data, BKE_id_copy(bmain, ob->data));
1976  break;
1977  case OB_MESH:
1978  /* Needed to remap texcomesh below. */
1979  me = ob->data = ID_NEW_SET(ob->data, BKE_id_copy(bmain, ob->data));
1980  if (me->key) { /* We do not need to set me->key->id.newid here... */
1981  BKE_animdata_copy_id_action(bmain, (ID *)me->key);
1982  }
1983  break;
1984  case OB_MBALL:
1985  ob->data = ID_NEW_SET(ob->data, BKE_id_copy(bmain, ob->data));
1986  break;
1987  case OB_CURVE:
1988  case OB_SURF:
1989  case OB_FONT:
1990  ob->data = cu = ID_NEW_SET(ob->data, BKE_id_copy(bmain, ob->data));
1991  ID_NEW_REMAP(cu->bevobj);
1992  ID_NEW_REMAP(cu->taperobj);
1993  if (cu->key) { /* We do not need to set cu->key->id.newid here... */
1994  BKE_animdata_copy_id_action(bmain, (ID *)cu->key);
1995  }
1996  break;
1997  case OB_LATTICE:
1998  ob->data = lat = ID_NEW_SET(ob->data, BKE_id_copy(bmain, ob->data));
1999  if (lat->key) { /* We do not need to set lat->key->id.newid here... */
2000  BKE_animdata_copy_id_action(bmain, (ID *)lat->key);
2001  }
2002  break;
2003  case OB_ARMATURE:
2005  ob->data = ID_NEW_SET(ob->data, BKE_id_copy(bmain, ob->data));
2006  BKE_pose_rebuild(bmain, ob, ob->data, true);
2007  break;
2008  case OB_SPEAKER:
2009  ob->data = ID_NEW_SET(ob->data, BKE_id_copy(bmain, ob->data));
2010  break;
2011  case OB_LIGHTPROBE:
2012  ob->data = ID_NEW_SET(ob->data, BKE_id_copy(bmain, ob->data));
2013  break;
2014  case OB_GPENCIL:
2015  ob->data = ID_NEW_SET(ob->data, BKE_id_copy(bmain, ob->data));
2016  break;
2017  case OB_HAIR:
2018  ob->data = ID_NEW_SET(ob->data, BKE_id_copy(bmain, ob->data));
2019  break;
2020  case OB_POINTCLOUD:
2021  ob->data = ID_NEW_SET(ob->data, BKE_id_copy(bmain, ob->data));
2022  break;
2023  case OB_VOLUME:
2024  ob->data = ID_NEW_SET(ob->data, BKE_id_copy(bmain, ob->data));
2025  break;
2026  default:
2027  printf("ERROR %s: can't copy %s\n", __func__, id->name);
2028  BLI_assert(!"This should never happen.");
2029 
2030  /* We need to end the FOREACH_OBJECT_FLAG_BEGIN iterator to prevent memory leak. */
2031  BKE_scene_objects_iterator_end(&iter_macro);
2032  return;
2033  }
2034 
2035  /* Copy animation data after object data became local,
2036  * otherwise old and new object data will share the same
2037  * AnimData structure, which is not what we want.
2038  * (sergey)
2039  */
2040  BKE_animdata_copy_id_action(bmain, (ID *)ob->data);
2041 
2042  id_us_min(id);
2043  }
2044  }
2045  }
2047 
2048  me = bmain->meshes.first;
2049  while (me) {
2050  ID_NEW_REMAP(me->texcomesh);
2051  me = me->id.next;
2052  }
2053 }
2054 
2056  Main *bmain, Scene *scene, ViewLayer *view_layer, View3D *v3d, const int flag)
2057 {
2058  FOREACH_OBJECT_FLAG_BEGIN (scene, view_layer, v3d, flag, ob) {
2059  if (!ID_IS_LINKED(ob)) {
2061  BKE_animdata_copy_id_action(bmain, &ob->id);
2062  }
2063  }
2065 }
2066 
2067 static void single_mat_users(
2068  Main *bmain, Scene *scene, ViewLayer *view_layer, View3D *v3d, const int flag)
2069 {
2070  Material *ma, *man;
2071  int a;
2072 
2073  FOREACH_OBJECT_FLAG_BEGIN (scene, view_layer, v3d, flag, ob) {
2074  if (!ID_IS_LINKED(ob)) {
2075  for (a = 1; a <= ob->totcol; a++) {
2076  ma = BKE_object_material_get(ob, a);
2077  if (ma) {
2078  /* do not test for LIB_TAG_NEW or use newid:
2079  * this functions guaranteed delivers single_users! */
2080 
2081  if (ma->id.us > 1) {
2082  man = (Material *)BKE_id_copy(bmain, &ma->id);
2083  BKE_animdata_copy_id_action(bmain, &man->id);
2084 
2085  man->id.us = 0;
2087  }
2088  }
2089  }
2090  }
2091  }
2093 }
2094 
2097 /* ------------------------------------------------------------------- */
2101 enum {
2106 };
2107 
2109 {
2110  ID **id_pointer = cb_data->id_pointer;
2111  if (*id_pointer) {
2112  (*id_pointer)->tag &= ~LIB_TAG_DOIT;
2113  }
2114 
2115  return IDWALK_RET_NOP;
2116 }
2117 
2118 static void tag_localizable_objects(bContext *C, const int mode)
2119 {
2120  Main *bmain = CTX_data_main(C);
2121 
2122  BKE_main_id_tag_all(bmain, LIB_TAG_DOIT, false);
2123 
2124  /* Set LIB_TAG_DOIT flag for all selected objects, so next we can check whether
2125  * object is gonna to become local or not.
2126  */
2127  CTX_DATA_BEGIN (C, Object *, object, selected_objects) {
2128  object->id.tag |= LIB_TAG_DOIT;
2129 
2130  /* If data is also gonna to become local, mark data we're interested in
2131  * as gonna-to-be-local.
2132  */
2133  if (mode == MAKE_LOCAL_SELECT_OBDATA && object->data) {
2134  ID *data_id = (ID *)object->data;
2135  data_id->tag |= LIB_TAG_DOIT;
2136  }
2137  }
2138  CTX_DATA_END;
2139 
2140  /* Also forbid making objects local if other library objects are using
2141  * them for modifiers or constraints.
2142  */
2143  for (Object *object = bmain->objects.first; object; object = object->id.next) {
2144  if ((object->id.tag & LIB_TAG_DOIT) == 0) {
2147  }
2148  if (object->data) {
2149  ID *data_id = (ID *)object->data;
2150  if ((data_id->tag & LIB_TAG_DOIT) == 0) {
2152  }
2153  }
2154  }
2155 
2156  /* TODO(sergey): Drivers targets? */
2157 }
2158 
2164  ViewLayer *view_layer,
2165  Collection *collection)
2166 {
2167  Object *ob;
2168  bool changed = false;
2169 
2170  for (ob = bmain->objects.first; ob; ob = ob->id.next) {
2171  if (ID_IS_LINKED(ob) && (ob->id.us == 0)) {
2172  Base *base;
2173 
2174  id_us_plus(&ob->id);
2175 
2176  BKE_collection_object_add(bmain, collection, ob);
2177  base = BKE_view_layer_base_find(view_layer, ob);
2180 
2181  changed = true;
2182  }
2183  }
2184 
2185  return changed;
2186 }
2187 
2189 {
2190  NlaStrip *strip;
2191 
2192  for (strip = strips->first; strip; strip = strip->next) {
2193  if (strip->act) {
2194  strip->act->id.tag &= ~LIB_TAG_PRE_EXISTING;
2195  }
2196 
2198  }
2199 }
2200 
2201 /* Tag all actions used by given animdata to be made local. */
2203 {
2204  if (adt) {
2205  /* Actions - Active and Temp */
2206  if (adt->action) {
2207  adt->action->id.tag &= ~LIB_TAG_PRE_EXISTING;
2208  }
2209  if (adt->tmpact) {
2210  adt->tmpact->id.tag &= ~LIB_TAG_PRE_EXISTING;
2211  }
2212 
2213  /* Drivers */
2214  /* TODO: need to handle the ID-targets too? */
2215 
2216  /* NLA Data */
2217  LISTBASE_FOREACH (NlaTrack *, nlt, &adt->nla_tracks) {
2218  make_local_animdata_tag_strips(&nlt->strips);
2219  }
2220  }
2221 }
2222 
2224 {
2225  if (ma) {
2226  ma->id.tag &= ~LIB_TAG_PRE_EXISTING;
2228 
2229  /* About nodetrees: root one is made local together with material,
2230  * others we keep linked for now... */
2231  }
2232 }
2233 
2235 {
2236  Main *bmain = CTX_data_main(C);
2237  ParticleSystem *psys;
2238  Material *ma, ***matarar;
2239  const int mode = RNA_enum_get(op->ptr, "type");
2240  int a;
2241 
2242  /* Note: we (ab)use LIB_TAG_PRE_EXISTING to cherry pick which ID to make local... */
2243  if (mode == MAKE_LOCAL_ALL) {
2244  ViewLayer *view_layer = CTX_data_view_layer(C);
2245  Collection *collection = CTX_data_collection(C);
2246 
2248 
2249  /* De-select so the user can differentiate newly instanced from existing objects. */
2251 
2252  if (make_local_all__instance_indirect_unused(bmain, view_layer, collection)) {
2253  BKE_report(op->reports,
2254  RPT_INFO,
2255  "Orphan library objects added to the current scene to avoid loss");
2256  }
2257  }
2258  else {
2260  tag_localizable_objects(C, mode);
2261 
2262  CTX_DATA_BEGIN (C, Object *, ob, selected_objects) {
2263  if ((ob->id.tag & LIB_TAG_DOIT) == 0) {
2264  continue;
2265  }
2266 
2267  ob->id.tag &= ~LIB_TAG_PRE_EXISTING;
2269  for (psys = ob->particlesystem.first; psys; psys = psys->next) {
2270  psys->part->id.tag &= ~LIB_TAG_PRE_EXISTING;
2271  }
2272 
2273  if (mode == MAKE_LOCAL_SELECT_OBDATA_MATERIAL) {
2274  for (a = 0; a < ob->totcol; a++) {
2275  ma = ob->mat[a];
2276  if (ma) {
2278  }
2279  }
2280 
2281  matarar = BKE_object_material_array_p(ob);
2282  if (matarar) {
2283  for (a = 0; a < ob->totcol; a++) {
2284  ma = (*matarar)[a];
2285  if (ma) {
2287  }
2288  }
2289  }
2290  }
2291 
2293  ob->data != NULL) {
2294  ID *ob_data = ob->data;
2295  ob_data->tag &= ~LIB_TAG_PRE_EXISTING;
2297  }
2298  }
2299  CTX_DATA_END;
2300  }
2301 
2302  BKE_library_make_local(bmain, NULL, NULL, true, false); /* NULL is all libs */
2303 
2305  return OPERATOR_FINISHED;
2306 }
2307 
2309 {
2310  static const EnumPropertyItem type_items[] = {
2311  {MAKE_LOCAL_SELECT_OB, "SELECT_OBJECT", 0, "Selected Objects", ""},
2312  {MAKE_LOCAL_SELECT_OBDATA, "SELECT_OBDATA", 0, "Selected Objects and Data", ""},
2314  "SELECT_OBDATA_MATERIAL",
2315  0,
2316  "Selected Objects, Data and Materials",
2317  ""},
2318  {MAKE_LOCAL_ALL, "ALL", 0, "All", ""},
2319  {0, NULL, 0, NULL, NULL},
2320  };
2321 
2322  /* identifiers */
2323  ot->name = "Make Local";
2324  ot->description = "Make library linked data-blocks local to this file";
2325  ot->idname = "OBJECT_OT_make_local";
2326 
2327  /* api callbacks */
2329  ot->exec = make_local_exec;
2331 
2332  /* flags */
2334 
2335  /* properties */
2336  ot->prop = RNA_def_enum(ot->srna, "type", type_items, 0, "Type", "");
2337 }
2338 
2341 /* ------------------------------------------------------------------- */
2346 {
2347  /* An object is actually overridable only if it is in at least one local collection.
2348  * Unfortunately 'direct link' flag is not enough here. */
2349  LISTBASE_FOREACH (Collection *, collection, &bmain->collections) {
2350  if (!ID_IS_LINKED(collection) && BKE_collection_has_object(collection, object)) {
2351  return true;
2352  }
2353  }
2354  LISTBASE_FOREACH (Scene *, scene, &bmain->scenes) {
2356  return true;
2357  }
2358  }
2359  return false;
2360 }
2361 
2362 /* Set the object to override. */
2364 {
2365  Main *bmain = CTX_data_main(C);
2367  Object *obact = ED_object_active_context(C);
2368 
2369  /* Sanity checks. */
2370  if (!scene || ID_IS_LINKED(scene) || !obact) {
2371  return OPERATOR_CANCELLED;
2372  }
2373 
2374  if ((!ID_IS_LINKED(obact) && obact->instance_collection != NULL &&
2377  uiPopupMenu *pup = UI_popup_menu_begin(C, IFACE_("OK?"), ICON_QUESTION);
2378  uiLayout *layout = UI_popup_menu_layout(pup);
2379 
2380  /* Create operator menu item with relevant properties filled in. */
2381  PointerRNA opptr_dummy;
2383  layout, op->type, op->type->name, ICON_NONE, NULL, WM_OP_EXEC_REGION_WIN, 0, &opptr_dummy);
2384 
2385  /* Present the menu and be done... */
2386  UI_popup_menu_end(C, pup);
2387 
2388  /* This invoke just calls another instance of this operator... */
2389  return OPERATOR_INTERFACE;
2390  }
2391 
2392  if (ID_IS_LINKED(obact)) {
2393  /* Show menu with list of directly linked collections containing the active object. */
2394  WM_enum_search_invoke(C, op, event);
2395  return OPERATOR_CANCELLED;
2396  }
2397 
2398  /* Error.. cannot continue. */
2399  BKE_report(op->reports,
2400  RPT_ERROR,
2401  "Can only make library override for a referenced object or collection");
2402  return OPERATOR_CANCELLED;
2403 }
2404 
2406 {
2407  Main *bmain = CTX_data_main(C);
2409  ViewLayer *view_layer = CTX_data_view_layer(C);
2410  Object *obact = CTX_data_active_object(C);
2411  ID *id_root = NULL;
2412  bool is_override_instancing_object = false;
2413 
2414  if (!ID_IS_LINKED(obact) && obact->instance_collection != NULL &&
2417  BKE_reportf(op->reports,
2419  "Collection '%s' (instantiated by the active object) is not overridable",
2420  obact->instance_collection->id.name + 2);
2421  return OPERATOR_CANCELLED;
2422  }
2423 
2424  id_root = &obact->instance_collection->id;
2425  is_override_instancing_object = true;
2426  }
2427  else if (!make_override_library_object_overridable_check(bmain, obact)) {
2428  const int i = RNA_property_enum_get(op->ptr, op->type->prop);
2429  const uint collection_session_uuid = *((uint *)&i);
2430  if (collection_session_uuid == MAIN_ID_SESSION_UUID_UNSET) {
2431  BKE_reportf(op->reports,
2433  "Active object '%s' is not overridable",
2434  obact->id.name + 2);
2435  return OPERATOR_CANCELLED;
2436  }
2437 
2438  Collection *collection = BLI_listbase_bytes_find(&bmain->collections,
2439  &collection_session_uuid,
2440  sizeof(collection_session_uuid),
2441  offsetof(ID, session_uuid));
2442  if (!ID_IS_OVERRIDABLE_LIBRARY(collection)) {
2443  BKE_reportf(op->reports,
2445  "Could not find an overridable collection containing object '%s'",
2446  obact->id.name + 2);
2447  return OPERATOR_CANCELLED;
2448  }
2449  id_root = &collection->id;
2450  }
2451  /* Else, poll func ensures us that ID_IS_LINKED(obact) is true. */
2452  else {
2453  id_root = &obact->id;
2454  }
2455 
2456  BKE_main_id_tag_all(bmain, LIB_TAG_DOIT, false);
2457 
2458  const bool success = BKE_lib_override_library_create(
2459  bmain, scene, view_layer, id_root, &obact->id);
2460 
2461  /* Remove the instance empty from this scene, the items now have an overridden collection
2462  * instead. */
2463  if (success && is_override_instancing_object) {
2464  ED_object_base_free_and_unlink(bmain, scene, obact);
2465  }
2466 
2469 
2470  return success ? OPERATOR_FINISHED : OPERATOR_CANCELLED;
2471 }
2472 
2474 {
2475  Object *obact = CTX_data_active_object(C);
2476 
2477  /* Object must be directly linked to be overridable. */
2478  return (ED_operator_objectmode(C) && obact != NULL &&
2479  (ID_IS_LINKED(obact) || (obact->instance_collection != NULL &&
2481 }
2482 
2484  bContext *C, PointerRNA *UNUSED(ptr), PropertyRNA *UNUSED(prop), bool *r_free)
2485 {
2486  EnumPropertyItem item_tmp = {0}, *item = NULL;
2487  int totitem = 0;
2488 
2489  Object *object = ED_object_active_context(C);
2490  Main *bmain = CTX_data_main(C);
2491 
2492  if (!object || !ID_IS_LINKED(object)) {
2493  return DummyRNA_DEFAULT_items;
2494  }
2495 
2496  LISTBASE_FOREACH (Collection *, collection, &bmain->collections) {
2497  /* Only check for directly linked collections. */
2498  if (!ID_IS_LINKED(&collection->id) || (collection->id.tag & LIB_TAG_INDIRECT) != 0) {
2499  continue;
2500  }
2501  if (BKE_collection_has_object_recursive(collection, object)) {
2502  item_tmp.identifier = item_tmp.name = collection->id.name + 2;
2503  item_tmp.value = *((int *)&collection->id.session_uuid);
2504  RNA_enum_item_add(&item, &totitem, &item_tmp);
2505  }
2506  }
2507 
2508  RNA_enum_item_end(&item, &totitem);
2509  *r_free = true;
2510 
2511  return item;
2512 }
2513 
2515 {
2516  /* identifiers */
2517  ot->name = "Make Library Override";
2518  ot->description = "Make a local override of this library linked data-block";
2519  ot->idname = "OBJECT_OT_make_override_library";
2520 
2521  /* api callbacks */
2525 
2526  /* flags */
2528 
2529  /* properties */
2530  PropertyRNA *prop;
2531  prop = RNA_def_enum(ot->srna,
2532  "collection",
2535  "Override Collection",
2536  "Name of directly linked collection containing the selected object, to make "
2537  "an override from");
2540  ot->prop = prop;
2541 }
2542 
2544 {
2545  Object *obact = CTX_data_active_object(C);
2546 
2547  return obact != NULL && obact->proxy != NULL;
2548 }
2549 
2551 {
2552  Main *bmain = CTX_data_main(C);
2554  ViewLayer *view_layer = CTX_data_view_layer(C);
2555 
2556  BKE_main_id_tag_all(bmain, LIB_TAG_DOIT, false);
2557 
2558  Object *ob_proxy = CTX_data_active_object(C);
2559  Object *ob_proxy_group = ob_proxy->proxy_group;
2560  const bool is_override_instancing_object = ob_proxy_group != NULL;
2561 
2562  const bool success = BKE_lib_override_library_proxy_convert(bmain, scene, view_layer, ob_proxy);
2563 
2564  if (!success) {
2565  BKE_reportf(
2566  op->reports,
2568  "Could not create a library override from proxy '%s' (might use already local data?)",
2569  ob_proxy->id.name + 2);
2570  return OPERATOR_CANCELLED;
2571  }
2572 
2573  /* Remove the instance empty from this scene, the items now have an overridden collection
2574  * instead. */
2575  if (success && is_override_instancing_object) {
2576  ED_object_base_free_and_unlink(bmain, scene, ob_proxy_group);
2577  }
2578 
2581 
2582  return success ? OPERATOR_FINISHED : OPERATOR_CANCELLED;
2583 }
2584 
2586 {
2587  /* identifiers */
2588  ot->name = "Convert Proxy to Override";
2589  ot->description = "Convert a proxy to a local library override";
2590  ot->idname = "OBJECT_OT_convert_proxy_to_override";
2591 
2592  /* api callbacks */
2595 
2596  /* flags */
2598 }
2599 
2602 /* ------------------------------------------------------------------- */
2606 enum {
2609 };
2610 
2612 {
2613  Main *bmain = CTX_data_main(C);
2615  ViewLayer *view_layer = CTX_data_view_layer(C);
2616  View3D *v3d = CTX_wm_view3d(C); /* ok if this is NULL */
2617  const int flag = (RNA_enum_get(op->ptr, "type") == MAKE_SINGLE_USER_SELECTED) ? SELECT : 0;
2618  const bool copy_collections = false;
2619  bool update_deps = false;
2620 
2621  if (RNA_boolean_get(op->ptr, "object")) {
2622  if (flag == SELECT) {
2624  single_object_users(bmain, scene, v3d, OB_DONE, copy_collections);
2625  }
2626  else {
2627  single_object_users(bmain, scene, v3d, 0, copy_collections);
2628  }
2629 
2630  /* needed since object relationships may have changed */
2631  update_deps = true;
2632  }
2633 
2634  if (RNA_boolean_get(op->ptr, "obdata")) {
2635  single_obdata_users(bmain, scene, view_layer, v3d, flag);
2636 
2637  /* Needed since some IDs were remapped? (incl. me->texcomesh, see T73797). */
2638  update_deps = true;
2639  }
2640 
2641  if (RNA_boolean_get(op->ptr, "material")) {
2642  single_mat_users(bmain, scene, view_layer, v3d, flag);
2643  }
2644 
2645  if (RNA_boolean_get(op->ptr, "animation")) {
2646  single_object_action_users(bmain, scene, view_layer, v3d, flag);
2647  }
2648 
2650 
2652 
2653  if (update_deps) {
2654  DEG_relations_tag_update(bmain);
2655  }
2656 
2657  return OPERATOR_FINISHED;
2658 }
2659 
2661 {
2662  static const EnumPropertyItem type_items[] = {
2663  {MAKE_SINGLE_USER_SELECTED, "SELECTED_OBJECTS", 0, "Selected Objects", ""},
2664  {MAKE_SINGLE_USER_ALL, "ALL", 0, "All", ""},
2665  {0, NULL, 0, NULL, NULL},
2666  };
2667 
2668  /* identifiers */
2669  ot->name = "Make Single User";
2670  ot->description = "Make linked data local to each object";
2671  ot->idname = "OBJECT_OT_make_single_user";
2672 
2673  /* Note that the invoke callback is only used from operator search,
2674  * otherwise this does nothing by default. */
2675 
2676  /* api callbacks */
2680 
2681  /* flags */
2683 
2684  /* properties */
2685  ot->prop = RNA_def_enum(ot->srna, "type", type_items, MAKE_SINGLE_USER_SELECTED, "Type", "");
2686 
2687  RNA_def_boolean(ot->srna, "object", 0, "Object", "Make single user objects");
2688  RNA_def_boolean(ot->srna, "obdata", 0, "Object Data", "Make single user object data");
2689  RNA_def_boolean(ot->srna, "material", 0, "Materials", "Make materials local to each data-block");
2691  ot->srna, "animation", 0, "Object Animation", "Make animation data local to each object");
2692 }
2693 
2696 /* ------------------------------------------------------------------- */
2700 static int drop_named_material_invoke(bContext *C, wmOperator *op, const wmEvent *event)
2701 {
2702  Main *bmain = CTX_data_main(C);
2703  Base *base = ED_view3d_give_base_under_cursor(C, event->mval);
2704  Material *ma;
2705  char name[MAX_ID_NAME - 2];
2706 
2707  RNA_string_get(op->ptr, "name", name);
2708  ma = (Material *)BKE_libblock_find_name(bmain, ID_MA, name);
2709  if (base == NULL || ma == NULL) {
2710  return OPERATOR_CANCELLED;
2711  }
2712 
2714 
2716 
2720 
2721  return OPERATOR_FINISHED;
2722 }
2723 
2724 /* used for dropbox */
2725 /* assigns to object under cursor, only first material slot */
2727 {
2728  /* identifiers */
2729  ot->name = "Drop Named Material on Object";
2730  ot->idname = "OBJECT_OT_drop_named_material";
2731 
2732  /* api callbacks */
2735 
2736  /* flags */
2738 
2739  /* properties */
2740  RNA_def_string(ot->srna, "name", "Material", MAX_ID_NAME - 2, "Name", "Material name to assign");
2741 }
2742 
2745 /* ------------------------------------------------------------------- */
2750 {
2751  ID *id;
2752  PropertyPointerRNA pprop;
2753 
2755 
2756  if (pprop.prop == NULL) {
2757  BKE_report(op->reports, RPT_ERROR, "Incorrect context for running object data unlink");
2758  return OPERATOR_CANCELLED;
2759  }
2760 
2761  id = pprop.ptr.owner_id;
2762 
2763  if (GS(id->name) == ID_OB) {
2764  Object *ob = (Object *)id;
2765  if (ob->data) {
2766  ID *id_data = ob->data;
2767 
2768  if (GS(id_data->name) == ID_IM) {
2769  id_us_min(id_data);
2770  ob->data = NULL;
2771  }
2772  else {
2773  BKE_report(op->reports, RPT_ERROR, "Can't unlink this object data");
2774  return OPERATOR_CANCELLED;
2775  }
2776  }
2777  }
2778 
2779  RNA_property_update(C, &pprop.ptr, pprop.prop);
2780 
2781  return OPERATOR_FINISHED;
2782 }
2783 
2788 {
2789  /* identifiers */
2790  ot->name = "Unlink";
2791  ot->idname = "OBJECT_OT_unlink_data";
2792 
2793  /* api callbacks */
2795 
2796  /* flags */
2797  ot->flag = OPTYPE_INTERNAL;
2798 }
2799 
Blender kernel action and pose functionality.
struct bPoseChannel * BKE_pose_channel_active(struct Object *ob)
Definition: action.c:708
void BKE_animdata_copy_id_action(struct Main *bmain, struct ID *id)
Definition: anim_data.c:420
bool BKE_animdata_copy_id(struct Main *bmain, struct ID *id_to, struct ID *id_from, const int flag)
Definition: anim_data.c:375
struct AnimData * BKE_animdata_from_id(struct ID *id)
Definition: anim_data.c:96
void BKE_pose_rebuild(struct Main *bmain, struct Object *ob, struct bArmature *arm, const bool do_id_user)
Definition: armature.c:2536
Camera data-block and utility functions.
struct ListBase BKE_collection_object_cache_get(struct Collection *collection)
Definition: collection.c:827
#define FOREACH_COLLECTION_OBJECT_RECURSIVE_END
#define FOREACH_SCENE_OBJECT_END
bool BKE_collection_object_add(struct Main *bmain, struct Collection *collection, struct Object *ob)
Definition: collection.c:1134
bool BKE_collection_has_object(struct Collection *collection, const struct Object *ob)
bool BKE_collection_has_object_recursive(struct Collection *collection, struct Object *ob)
Definition: collection.c:961
bool BKE_collection_child_add_no_sync(struct Collection *parent, struct Collection *child)
Definition: collection.c:1616
#define FOREACH_COLLECTION_OBJECT_RECURSIVE_BEGIN(_collection, _object)
void BKE_scene_objects_iterator_end(struct BLI_Iterator *iter)
Definition: collection.c:2177
#define FOREACH_SCENE_OBJECT_BEGIN(scene, _instance)
bool BKE_constraint_remove(ListBase *list, struct bConstraint *con)
Definition: constraint.c:5515
struct bConstraint * BKE_constraint_add_for_object(struct Object *ob, const char *name, short type)
Definition: constraint.c:5672
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)
Definition: constraint.c:6025
struct Scene * CTX_data_scene(const bContext *C)
Definition: context.c:1034
struct Object * CTX_data_edit_object(const bContext *C)
Definition: context.c:1296
#define CTX_DATA_BEGIN(C, Type, instance, member)
Definition: BKE_context.h:252
struct ViewLayer * CTX_data_view_layer(const bContext *C)
Definition: context.c:1044
struct Collection * CTX_data_collection(const bContext *C)
Definition: context.c:1092
struct Depsgraph * CTX_data_ensure_evaluated_depsgraph(const bContext *C)
Definition: context.c:1424
struct Object * CTX_data_active_object(const bContext *C)
Definition: context.c:1279
struct View3D * CTX_wm_view3d(const bContext *C)
Definition: context.c:760
struct Main * CTX_data_main(const bContext *C)
Definition: context.c:1018
#define CTX_DATA_END
Definition: BKE_context.h:260
display list (or rather multi purpose list) stuff.
void BKE_displist_make_curveTypes(struct Depsgraph *depsgraph, const struct Scene *scene, struct Object *ob, const bool for_render, const bool for_orco)
void BKE_editmesh_looptri_calc(BMEditMesh *em)
Definition: editmesh.c:135
struct FModifier * add_fmodifier(ListBase *modifiers, int type, struct FCurve *owner_fcu)
Definition: fmodifier.c:1114
General operations for hairs.
void BKE_view_layer_selected_objects_tag(struct ViewLayer *view_layer, const int tag)
Definition: layer.c:305
#define FOREACH_OBJECT_FLAG_END
Definition: BKE_layer.h:360
void BKE_view_layer_base_deselect_all(struct ViewLayer *view_layer)
Definition: layer.c:403
struct Base * BKE_view_layer_base_find(struct ViewLayer *view_layer, struct Object *ob)
Definition: layer.c:394
void BKE_main_collection_sync_remap(const struct Main *bmain)
#define FOREACH_OBJECT_FLAG_BEGIN(scene, _view_layer, _v3d, flag, _instance)
Definition: BKE_layer.h:336
struct ID * BKE_id_copy(struct Main *bmain, const struct ID *id)
void id_us_min(struct ID *id)
Definition: lib_id.c:297
void BKE_main_id_tag_all(struct Main *mainvar, const int tag, const bool value)
Definition: lib_id.c:923
void BKE_main_id_clear_newpoins(struct Main *bmain)
Definition: lib_id.c:1738
void BKE_library_make_local(struct Main *bmain, const struct Library *lib, struct GHash *old_to_new_ids, const bool untagged_only, const bool set_fake)
void id_us_plus(struct ID *id)
Definition: lib_id.c:288
struct ID * BKE_libblock_find_name(struct Main *bmain, const short type, const char *name) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition: lib_id.c:1333
#define MAIN_ID_SESSION_UUID_UNSET
Definition: BKE_lib_id.h:73
bool BKE_lib_override_library_create(struct Main *bmain, struct Scene *scene, struct ViewLayer *view_layer, struct ID *id_root, struct ID *id_reference)
Definition: lib_override.c:788
bool BKE_lib_override_library_proxy_convert(struct Main *bmain, struct Scene *scene, struct ViewLayer *view_layer, struct Object *ob_proxy)
Definition: lib_override.c:834
@ IDWALK_READONLY
void BKE_library_foreach_ID_link(struct Main *bmain, struct ID *id, LibraryIDLinkCallback callback, void *user_data, int flag)
Definition: lib_query.c:322
@ IDWALK_RET_NOP
Definition: BKE_lib_query.h:97
void void BKE_libblock_relink_to_newid(struct ID *id) ATTR_NONNULL()
Definition: lib_remap.c:702
General operations, lookup, etc. for blender lights.
General operations for probes.
General operations, lookup, etc. for materials.
struct Material *** BKE_object_material_array_p(struct Object *ob)
Definition: material.c:323
struct Material * BKE_object_material_get(struct Object *ob, short act)
Definition: material.c:697
@ BKE_MAT_ASSIGN_USERPREF
Definition: BKE_material.h:71
void BKE_object_materials_test(struct Main *bmain, struct Object *ob, struct ID *id)
Definition: material.c:772
void BKE_object_material_assign(struct Main *bmain, struct Object *ob, struct Material *ma, short act, int assign_type)
Definition: material.c:850
struct Object * BKE_modifiers_is_deformed_by_armature(struct Object *ob)
struct Object * BKE_modifiers_is_deformed_by_curve(struct Object *ob)
void BKE_modifier_free(struct ModifierData *md)
void BKE_modifier_remove_from_list(struct Object *ob, struct ModifierData *md)
struct Object * BKE_modifiers_is_deformed_by_lattice(struct Object *ob)
General operations, lookup, etc. for blender objects.
bool BKE_object_parent_loop_check(const struct Object *parent, const struct Object *ob)
void BKE_object_link_modifiers(struct Object *ob_dst, const struct Object *ob_src)
struct LinkNode * BKE_object_groups(struct Main *bmain, struct Scene *scene, struct Object *ob)
Definition: object.c:5251
void BKE_object_groups_clear(struct Main *bmain, struct Scene *scene, struct Object *object)
Definition: object.c:5262
void BKE_object_workob_calc_parent(struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob, struct Object *workob)
Definition: object.c:3667
struct KDTree_3d * BKE_object_as_kdtree(struct Object *ob, int *r_tot)
Definition: object.c:5280
struct Object * BKE_object_add_from(struct Main *bmain, struct Scene *scene, struct ViewLayer *view_layer, int type, const char *name, struct Object *ob_src) ATTR_NONNULL(1
int BKE_object_scenes_users_get(struct Main *bmain, struct Object *ob)
Definition: object.c:5068
void BKE_object_make_proxy(struct Main *bmain, struct Object *ob, struct Object *target, struct Object *cob)
Definition: object.c:2885
void BKE_object_apply_mat4(struct Object *ob, const float mat[4][4], const bool use_compat, const bool use_parent)
Definition: object.c:3754
General operations for point-clouds.
void BKE_report(ReportList *reports, ReportType type, const char *message)
Definition: report.c:104
void BKE_reportf(ReportList *reports, ReportType type, const char *format,...) ATTR_PRINTF_FORMAT(3
void BKE_scene_graph_update_tagged(struct Depsgraph *depsgraph, struct Main *bmain)
Definition: scene.c:2713
General operations for speakers.
Volume datablock.
#define BLI_assert(a)
Definition: BLI_assert.h:58
A kd-tree for nearest neighbor search.
void BLI_kdtree_nd_() free(KDTree *tree)
Definition: kdtree_impl.h:116
void BLI_addhead(struct ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition: listbase.c:87
#define LISTBASE_FOREACH(type, var, list)
Definition: BLI_listbase.h:172
void * BLI_listbase_bytes_find(const ListBase *listbase, const void *bytes, const size_t bytes_size, const int offset) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1
void BLI_remlink(struct ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition: listbase.c:133
void * BLI_findlink(const struct ListBase *listbase, int number) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
MINLINE int min_iii(int a, int b, int c)
void unit_m4(float m[4][4])
Definition: rct.c:1140
bool invert_m4_m4(float R[4][4], const float A[4][4])
Definition: math_matrix.c:1278
MINLINE void sub_v3_v3v3(float r[3], const float a[3], const float b[3])
MINLINE void copy_v3_v3(float r[3], const float a[3])
MINLINE void copy_v3_v3_int(int r[3], const int a[3])
size_t BLI_snprintf(char *__restrict dst, size_t maxncpy, const char *__restrict format,...) ATTR_NONNULL(1
char * BLI_strncpy(char *__restrict dst, const char *__restrict src, const size_t maxncpy) ATTR_NONNULL()
Definition: string.c:108
unsigned int uint
Definition: BLI_sys_types.h:83
unsigned short ushort
Definition: BLI_sys_types.h:84
#define UNUSED_VARS(...)
#define UNUSED(x)
#define UNPACK3(a)
#define ELEM(...)
#define STREQ(a, b)
#define IFACE_(msgid)
struct Depsgraph Depsgraph
Definition: DEG_depsgraph.h:51
void DEG_id_tag_update(struct ID *id, int flag)
void DEG_relations_tag_update(struct Main *bmain)
struct Object * DEG_get_evaluated_object(const struct Depsgraph *depsgraph, struct Object *object)
#define ID_NEW_REMAP(a)
Definition: DNA_ID.h:468
@ ID_RECALC_TRANSFORM
Definition: DNA_ID.h:599
@ ID_RECALC_COPY_ON_WRITE
Definition: DNA_ID.h:654
@ ID_RECALC_ANIMATION
Definition: DNA_ID.h:614
@ ID_RECALC_GEOMETRY
Definition: DNA_ID.h:611
@ ID_RECALC_BASE_FLAGS
Definition: DNA_ID.h:641
@ LIB_TAG_INDIRECT
Definition: DNA_ID.h:524
@ LIB_TAG_PRE_EXISTING
Definition: DNA_ID.h:556
@ LIB_TAG_DOIT
Definition: DNA_ID.h:554
#define ID_IS_OVERRIDABLE_LIBRARY(_id)
Definition: DNA_ID.h:430
#define ID_IS_LINKED(_id)
Definition: DNA_ID.h:426
#define MAX_ID_NAME
Definition: DNA_ID.h:269
#define ID_NEW_SET(_id, _idn)
Definition: DNA_ID.h:464
@ ID_IM
Definition: DNA_ID_enums.h:65
@ ID_MA
Definition: DNA_ID_enums.h:63
@ ID_OB
Definition: DNA_ID_enums.h:59
@ FMODIFIER_TYPE_GENERATOR
@ BONE_RELATIVE_PARENTING
Object groups, one object can be in many groups at once.
@ CONSTRAINT_TYPE_TRACKTO
@ CONSTRAINT_TYPE_LOCKTRACK
@ CONSTRAINT_TYPE_FOLLOWPATH
@ CONSTRAINT_TYPE_DAMPTRACK
@ CONSTRAINT_OBTYPE_OBJECT
@ CU_BEZIER
#define BEZT_ISSEL_ANY_HIDDENHANDLES(v3d, bezt)
@ CU_FOLLOW
@ CU_PATH
@ BASE_SELECTED
@ eModifierType_Curve
@ eModifierType_Lattice
@ eModifierType_Armature
Object is a sort of wrapper for general info.
#define OB_DONE
#define OB_TYPE_SUPPORT_PARVERT(_type)
@ OB_DUPLICOLLECTION
@ PARVERT1
@ PARSKEL
@ PAROBJECT
@ PARTYPE
@ PARVERT3
@ PARBONE
#define OB_TYPE_SUPPORT_MATERIAL(_type)
@ OB_SPEAKER
@ OB_LATTICE
@ OB_MBALL
@ OB_EMPTY
@ OB_SURF
@ OB_CAMERA
@ OB_FONT
@ OB_ARMATURE
@ OB_LAMP
@ OB_MESH
@ OB_POINTCLOUD
@ OB_HAIR
@ OB_VOLUME
@ OB_CURVE
@ OB_GPENCIL
@ OB_LIGHTPROBE
#define FIRSTBASE(_view_layer)
#define BASACT(_view_layer)
@ OPERATOR_CANCELLED
@ OPERATOR_INTERFACE
@ OPERATOR_FINISHED
@ RPT_ERROR_INVALID_INPUT
#define ARM_GROUPS_ENVELOPE
Definition: ED_armature.h:141
#define ARM_GROUPS_NAME
Definition: ED_armature.h:140
#define ARM_GROUPS_AUTO
Definition: ED_armature.h:142
#define GP_PAR_ARMATURE_NAME
Definition: ED_gpencil.h:239
#define GP_PAR_ARMATURE_AUTO
Definition: ED_gpencil.h:240
void EDBM_mesh_load(struct Main *bmain, struct Object *ob)
void EDBM_mesh_make(struct Object *ob, const int select_mode, const bool add_key_index)
void EDBM_mesh_normals_update(struct BMEditMesh *em)
struct ModifierData * ED_object_modifier_add(struct ReportList *reports, struct Main *bmain, struct Scene *scene, struct Object *ob, const char *name, int type)
@ CLEAR_PARENT_ALL
Definition: ED_object.h:152
@ CLEAR_PARENT_KEEP_TRANSFORM
Definition: ED_object.h:153
@ CLEAR_PARENT_INVERSE
Definition: ED_object.h:154
void ED_object_shaderfx_link(struct Object *dst, struct Object *src)
@ PAR_OBJECT
Definition: ED_object.h:130
@ PAR_BONE
Definition: ED_object.h:135
@ PAR_BONE_RELATIVE
Definition: ED_object.h:136
@ PAR_ARMATURE_ENVELOPE
Definition: ED_object.h:133
@ PAR_CURVE
Definition: ED_object.h:137
@ PAR_ARMATURE_AUTO
Definition: ED_object.h:134
@ PAR_VERTEX
Definition: ED_object.h:141
@ PAR_LATTICE
Definition: ED_object.h:140
@ PAR_VERTEX_TRI
Definition: ED_object.h:142
@ PAR_ARMATURE_NAME
Definition: ED_object.h:132
@ PAR_ARMATURE
Definition: ED_object.h:131
@ PAR_FOLLOW
Definition: ED_object.h:138
@ PAR_PATH_CONST
Definition: ED_object.h:139
void ED_object_base_select(struct Base *base, eObjectSelect_Mode mode)
Definition: object_select.c:98
struct Object * ED_object_active_context(const struct bContext *C)
void ED_object_base_free_and_unlink(struct Main *bmain, struct Scene *scene, struct Object *ob)
Definition: object_add.c:1958
@ BA_SELECT
Definition: ED_object.h:147
bool ED_operator_editsurfcurve(struct bContext *C)
Definition: screen_ops.c:541
bool ED_operator_object_active_editable(struct bContext *C)
Definition: screen_ops.c:366
bool ED_operator_editlattice(struct bContext *C)
Definition: screen_ops.c:598
bool ED_operator_editmesh(struct bContext *C)
Definition: screen_ops.c:404
bool ED_operator_objectmode(struct bContext *C)
Definition: screen_ops.c:201
bool ED_operator_object_active(struct bContext *C)
Definition: screen_ops.c:355
struct Base * ED_view3d_give_base_under_cursor(struct bContext *C, const int mval[2])
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum type
Read Guarded memory(de)allocation.
const EnumPropertyItem * RNA_scene_local_itemf(struct bContext *C, struct PointerRNA *ptr, struct PropertyRNA *prop, bool *r_free)
@ PROP_ENUM_NO_TRANSLATE
Definition: RNA_types.h:279
#define C
Definition: RandGen.cpp:39
struct uiLayout * UI_popup_menu_layout(uiPopupMenu *pup)
void UI_context_active_but_prop_get_templateID(struct bContext *C, struct PointerRNA *r_ptr, struct PropertyRNA **r_prop)
void uiItemFullO_ptr(uiLayout *layout, struct wmOperatorType *ot, const char *name, int icon, struct IDProperty *properties, int context, int flag, struct PointerRNA *r_opptr)
void uiItemO(uiLayout *layout, const char *name, int icon, const char *opname)
void UI_popup_menu_end(struct bContext *C, struct uiPopupMenu *pup)
void uiItemEnumO_ptr(uiLayout *layout, struct wmOperatorType *ot, const char *name, int icon, const char *propname, int value)
uiPopupMenu * UI_popup_menu_begin(struct bContext *C, const char *title, int icon) ATTR_NONNULL()
#define NC_WINDOW
Definition: WM_types.h:277
#define ND_NLA_ACTCHANGE
Definition: WM_types.h:398
#define ND_DRAW
Definition: WM_types.h:362
@ OPTYPE_INTERNAL
Definition: WM_types.h:175
@ OPTYPE_UNDO
Definition: WM_types.h:155
@ OPTYPE_REGISTER
Definition: WM_types.h:153
#define NC_ANIMATION
Definition: WM_types.h:289
@ WM_OP_EXEC_REGION_WIN
Definition: WM_types.h:205
@ WM_OP_EXEC_DEFAULT
Definition: WM_types.h:204
#define ND_PARENT
Definition: WM_types.h:368
#define NC_MATERIAL
Definition: WM_types.h:281
#define ND_TRANSFORM
Definition: WM_types.h:357
#define ND_OB_SHADING
Definition: WM_types.h:358
#define ND_SPACE_VIEW3D
Definition: WM_types.h:423
#define NC_OBJECT
Definition: WM_types.h:280
#define ND_SHADING_LINKS
Definition: WM_types.h:379
#define NC_SPACE
Definition: WM_types.h:293
void ED_object_vgroup_calc_from_armature(ReportList *reports, Depsgraph *depsgraph, Scene *scene, Object *ob, Object *par, const int mode, const bool mirror)
@ BM_ELEM_SELECT
Definition: bmesh_class.h:471
#define BM_elem_flag_test(ele, hflag)
Definition: bmesh_inline.h:26
#define BM_ITER_MESH_INDEX(ele, iter, bm, itype, indexvar)
@ BM_VERTS_OF_MESH
#define SELECT
Scene scene
const Depsgraph * depsgraph
ListBase * object_editcurve_get(Object *ob)
Definition: editcurve.c:89
void * tree
bool ED_gpencil_add_armature_weights(const bContext *C, ReportList *reports, Object *ob, Object *ob_arm, int mode)
bool ED_gpencil_add_armature(const bContext *C, ReportList *reports, Object *ob, Object *ob_arm)
bool ED_gpencil_add_lattice_modifier(const bContext *C, ReportList *reports, Object *ob, Object *ob_latt)
#define GS(x)
Definition: iris.c:241
bAction * ED_id_action_ensure(Main *bmain, ID *id)
Definition: keyframing.c:136
FCurve * ED_action_fcurve_ensure(struct Main *bmain, struct bAction *act, const char group[], struct PointerRNA *ptr, const char rna_path[], const int array_index)
Definition: keyframing.c:194
void(* MEM_freeN)(void *vmemh)
Definition: mallocn.c:41
void *(* MEM_mallocN)(size_t len, const char *str)
Definition: mallocn.c:47
static unsigned a[3]
Definition: RandGen.cpp:92
static void single_object_action_users(Main *bmain, Scene *scene, ViewLayer *view_layer, View3D *v3d, const int flag)
static int make_local_exec(bContext *C, wmOperator *op)
static bool parent_set_vertex_parent(bContext *C, struct ParentingContext *parenting_context)
void OBJECT_OT_convert_proxy_to_override(wmOperatorType *ot)
static int object_track_clear_exec(bContext *C, wmOperator *op)
static void libblock_relink_collection(Collection *collection, const bool do_collection)
static void make_local_material_tag(Material *ma)
static int track_set_exec(bContext *C, wmOperator *op)
@ MAKE_SINGLE_USER_SELECTED
@ MAKE_SINGLE_USER_ALL
static int parent_set_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
static int make_proxy_invoke(bContext *C, wmOperator *op, const wmEvent *event)
static int make_links_scene_exec(bContext *C, wmOperator *op)
void OBJECT_OT_parent_clear(wmOperatorType *ot)
static const EnumPropertyItem prop_make_track_types[]
static void make_local_animdata_tag(AnimData *adt)
void ED_object_parent_clear(Object *ob, const int type)
static int make_proxy_exec(bContext *C, wmOperator *op)
static bool make_override_library_poll(bContext *C)
static bool make_override_library_object_overridable_check(Main *bmain, Object *object)
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 bool parent_set_vertex_parent_with_kdtree(bContext *C, struct ParentingContext *parenting_context, struct KDTree_3d *tree)
void ED_object_parent(Object *ob, Object *par, const int type, const char *substr)
static int convert_proxy_to_override_exec(bContext *C, wmOperator *op)
void OBJECT_OT_track_set(wmOperatorType *ot)
static int object_unlink_data_exec(bContext *C, wmOperator *op)
void OBJECT_OT_track_clear(wmOperatorType *ot)
void OBJECT_OT_unlink_data(wmOperatorType *ot)
static int make_override_library_invoke(bContext *C, wmOperator *op, const wmEvent *event)
static bool parent_set_nonvertex_parent(bContext *C, struct ParentingContext *parenting_context)
void OBJECT_OT_make_override_library(wmOperatorType *ot)
static void object_remove_parent_deform_modifiers(Object *ob, const Object *par)
#define INDEX_UNSET
static int parent_clear_exec(bContext *C, wmOperator *op)
static int make_single_user_exec(bContext *C, wmOperator *op)
void OBJECT_OT_make_links_scene(wmOperatorType *ot)
static int parent_set_invoke_menu(bContext *C, wmOperatorType *ot)
void OBJECT_OT_parent_no_inverse_set(wmOperatorType *ot)
static void single_obdata_users(Main *bmain, Scene *scene, ViewLayer *view_layer, View3D *v3d, const int flag)
static void single_object_users(Main *bmain, Scene *scene, View3D *v3d, const int flag, const bool copy_collections)
@ MAKE_LOCAL_SELECT_OBDATA_MATERIAL
@ MAKE_LOCAL_SELECT_OBDATA
@ MAKE_LOCAL_SELECT_OB
@ MAKE_LOCAL_ALL
static void single_mat_users(Main *bmain, Scene *scene, ViewLayer *view_layer, View3D *v3d, const int flag)
static int drop_named_material_invoke(bContext *C, wmOperator *op, const wmEvent *event)
@ MAKE_LINKS_MODIFIERS
@ MAKE_LINKS_ANIMDATA
@ MAKE_LINKS_DUPLICOLLECTION
@ MAKE_LINKS_MATERIALS
@ MAKE_LINKS_SHADERFX
@ MAKE_LINKS_OBDATA
@ MAKE_LINKS_FONTS
@ MAKE_LINKS_GROUP
@ CLEAR_TRACK
@ CLEAR_TRACK_KEEP_TRANSFORM
EnumPropertyItem prop_clear_parent_types[]
static bool make_local_all__instance_indirect_unused(Main *bmain, ViewLayer *view_layer, Collection *collection)
static int make_override_library_exec(bContext *C, wmOperator *op)
void ED_object_single_user(Main *bmain, Scene *scene, Object *ob)
static void make_local_animdata_tag_strips(ListBase *strips)
void OBJECT_OT_make_single_user(wmOperatorType *ot)
static int make_links_data_exec(bContext *C, wmOperator *op)
bool ED_object_parent_set(ReportList *reports, const bContext *C, Scene *scene, Object *const ob, Object *const par, int partype, const bool xmirror, const bool keep_transform, const int vert_par[3])
static const EnumPropertyItem * proxy_collection_object_itemf(bContext *C, PointerRNA *UNUSED(ptr), PropertyRNA *UNUSED(prop), bool *r_free)
void OBJECT_OT_drop_named_material(wmOperatorType *ot)
void OBJECT_OT_vertex_parent_set(wmOperatorType *ot)
static void tag_localizable_objects(bContext *C, const int mode)
void OBJECT_OT_make_links_data(wmOperatorType *ot)
static int vertex_parent_set_exec(bContext *C, wmOperator *op)
static bool convert_proxy_to_override_poll(bContext *C)
static int parent_set_exec(bContext *C, wmOperator *op)
static bool parent_set_poll_property(const bContext *UNUSED(C), wmOperator *op, const PropertyRNA *prop)
void OBJECT_OT_make_local(wmOperatorType *ot)
static int parent_noinv_set_exec(bContext *C, wmOperator *op)
static const EnumPropertyItem * make_override_collections_of_linked_object_itemf(bContext *C, PointerRNA *UNUSED(ptr), PropertyRNA *UNUSED(prop), bool *r_free)
@ CREATE_TRACK_DAMPTRACK
@ CREATE_TRACK_LOCKTRACK
@ CREATE_TRACK_TRACKTO
void OBJECT_OT_proxy_make(wmOperatorType *ot)
static bool allow_make_links_data(const int type, Object *ob_src, Object *ob_dst)
void OBJECT_OT_parent_set(wmOperatorType *ot)
static int tag_localizable_looper(LibraryIDLinkCallbackData *cb_data)
EnumPropertyItem prop_make_parent_types[]
static void parent_set_vert_find(KDTree_3d *tree, Object *child, int vert_par[3], bool is_tri)
static bool vertex_parent_set_poll(bContext *C)
static const EnumPropertyItem prop_clear_track_types[]
const char * RNA_property_identifier(const PropertyRNA *prop)
Definition: rna_access.c:1145
void RNA_boolean_set(PointerRNA *ptr, const char *name, bool value)
Definition: rna_access.c:6272
bool RNA_property_is_set(PointerRNA *ptr, PropertyRNA *prop)
Definition: rna_access.c:6655
void RNA_property_update(bContext *C, PointerRNA *ptr, PropertyRNA *prop)
Definition: rna_access.c:2317
void RNA_string_get(PointerRNA *ptr, const char *name, char *value)
Definition: rna_access.c:6514
int RNA_property_enum_get(PointerRNA *ptr, PropertyRNA *prop)
Definition: rna_access.c:3543
bool RNA_boolean_get(PointerRNA *ptr, const char *name)
Definition: rna_access.c:6261
void RNA_enum_set(PointerRNA *ptr, const char *name, int value)
Definition: rna_access.c:6413
int RNA_enum_get(PointerRNA *ptr, const char *name)
Definition: rna_access.c:6402
PropertyRNA * RNA_def_boolean(StructOrFunctionRNA *cont_, const char *identifier, bool default_value, const char *ui_name, const char *ui_description)
Definition: rna_define.c:3481
void RNA_enum_item_end(EnumPropertyItem **items, int *totitem)
Definition: rna_define.c:4470
void RNA_enum_item_add(EnumPropertyItem **items, int *totitem, const EnumPropertyItem *item)
Definition: rna_define.c:4416
PropertyRNA * RNA_def_string(StructOrFunctionRNA *cont_, const char *identifier, const char *default_value, int maxlen, const char *ui_name, const char *ui_description)
Definition: rna_define.c:3675
void RNA_def_property_flag(PropertyRNA *prop, PropertyFlag flag)
Definition: rna_define.c:1512
void RNA_def_enum_funcs(PropertyRNA *prop, EnumPropertyItemFunc itemfunc)
Definition: rna_define.c:3819
PropertyRNA * RNA_def_enum(StructOrFunctionRNA *cont_, const char *identifier, const EnumPropertyItem *items, int default_value, const char *ui_name, const char *ui_description)
Definition: rna_define.c:3771
const EnumPropertyItem DummyRNA_DEFAULT_items[]
Definition: rna_rna.c:45
const EnumPropertyItem DummyRNA_NULL_items[]
Definition: rna_rna.c:40
bAction * action
bAction * tmpact
ListBase nla_tracks
struct BMesh * bm
Definition: BKE_editmesh.h:52
uint8_t f1
struct Base * next
struct Object * object
struct Object * focus_object
struct CameraDOFSettings dof
struct Collection * collection
struct CollectionChild * next
const float * anim_path_accum_length
Definition: BKE_curve.h:58
struct Object * object
struct Object * bevobj
struct VFont * vfont
struct Key * key
struct VFont * vfontb
struct VFont * vfonti
struct VFont * vfontbi
struct Object * taperobj
struct Lattice * latt
const char * identifier
Definition: RNA_types.h:446
const char * name
Definition: RNA_types.h:450
FPoint * fpt
BezTriple * bezt
ListBase modifiers
Definition: DNA_ID.h:273
int tag
Definition: DNA_ID.h:292
struct Library * lib
Definition: DNA_ID.h:277
int us
Definition: DNA_ID.h:293
struct ID * newid
Definition: DNA_ID.h:275
void * next
Definition: DNA_ID.h:274
char name[66]
Definition: DNA_ID.h:283
struct Object * object
struct Key * key
struct EditLatt * editlatt
struct BPoint * def
void * link
Definition: BLI_linklist.h:40
struct LinkNode * next
Definition: BLI_linklist.h:39
void * last
Definition: DNA_listBase.h:47
void * first
Definition: DNA_listBase.h:47
Definition: BKE_main.h:116
ListBase scenes
Definition: BKE_main.h:146
ListBase meshes
Definition: BKE_main.h:149
ListBase collections
Definition: BKE_main.h:167
ListBase objects
Definition: BKE_main.h:148
struct BMEditMesh * edit_mesh
struct Mesh * texcomesh
struct Key * key
struct ModifierData * next
struct NlaStrip * next
ListBase strips
bAction * act
struct CurveCache * curve_cache
struct Object * proxy_group
short partype
struct Collection * instance_collection
ListBase modifiers
struct Object * proxy_from
struct Object * proxy
float loc[3]
float parentinv[4][4]
Object_Runtime runtime
float obmat[4][4]
struct Object * parent
void * data
char parsubstr[64]
ReportList * reports
ParticleSettings * part
struct ParticleSystem * next
struct ID * owner_id
Definition: RNA_types.h:50
struct PropertyRNA * prop
Definition: RNA_types.h:57
PointerRNA ptr
Definition: RNA_types.h:56
struct Collection * master_collection
struct ToolSettings * toolsettings
struct RenderData r
struct Object * camera
struct bConstraint * prev
struct Bone * bone
int mval[2]
Definition: WM_types.h:583
int(* invoke)(struct bContext *, struct wmOperator *, const struct wmEvent *) ATTR_WARN_UNUSED_RESULT
Definition: WM_types.h:752
const char * name
Definition: WM_types.h:721
const char * idname
Definition: WM_types.h:723
bool(* poll)(struct bContext *) ATTR_WARN_UNUSED_RESULT
Definition: WM_types.h:776
bool(* poll_property)(const struct bContext *C, struct wmOperator *op, const PropertyRNA *prop) ATTR_WARN_UNUSED_RESULT
Definition: WM_types.h:782
struct StructRNA * srna
Definition: WM_types.h:802
const char * description
Definition: WM_types.h:726
int(* exec)(struct bContext *, struct wmOperator *) ATTR_WARN_UNUSED_RESULT
Definition: WM_types.h:736
PropertyRNA * prop
Definition: WM_types.h:814
struct ReportList * reports
struct wmOperatorType * type
struct PointerRNA * ptr
#define G(x, y, z)
void WM_cursor_wait(bool val)
Definition: wm_cursors.c:226
void WM_event_add_notifier(const bContext *C, uint type, void *reference)
PointerRNA * ptr
Definition: wm_files.c:3157
wmOperatorType * ot
Definition: wm_files.c:3156
int WM_operator_confirm(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
int WM_operator_props_popup_confirm(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
int WM_menu_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
Definition: wm_operators.c:982
int WM_enum_search_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))