Blender  V3.3
object_relations.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2001-2002 NaN Holding BV. All rights reserved. */
3 
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include <string.h>
11 
12 #include "MEM_guardedalloc.h"
13 
14 #include "DNA_anim_types.h"
15 #include "DNA_armature_types.h"
16 #include "DNA_camera_types.h"
17 #include "DNA_collection_types.h"
18 #include "DNA_constraint_types.h"
19 #include "DNA_gpencil_types.h"
20 #include "DNA_key_types.h"
21 #include "DNA_lattice_types.h"
22 #include "DNA_light_types.h"
23 #include "DNA_material_types.h"
24 #include "DNA_mesh_types.h"
25 #include "DNA_meta_types.h"
26 #include "DNA_object_types.h"
27 #include "DNA_particle_types.h"
28 #include "DNA_scene_types.h"
29 #include "DNA_vfont_types.h"
30 #include "DNA_world_types.h"
31 
32 #include "BLI_kdtree.h"
33 #include "BLI_linklist.h"
34 #include "BLI_listbase.h"
35 #include "BLI_math.h"
36 #include "BLI_string.h"
37 #include "BLI_utildefines.h"
38 
39 #include "BLT_translation.h"
40 
41 #include "BKE_DerivedMesh.h"
42 #include "BKE_action.h"
43 #include "BKE_anim_data.h"
44 #include "BKE_armature.h"
45 #include "BKE_camera.h"
46 #include "BKE_collection.h"
47 #include "BKE_constraint.h"
48 #include "BKE_context.h"
49 #include "BKE_curve.h"
50 #include "BKE_curves.h"
51 #include "BKE_displist.h"
52 #include "BKE_editmesh.h"
53 #include "BKE_fcurve.h"
54 #include "BKE_gpencil.h"
55 #include "BKE_idprop.h"
56 #include "BKE_idtype.h"
57 #include "BKE_lattice.h"
58 #include "BKE_layer.h"
59 #include "BKE_lib_id.h"
60 #include "BKE_lib_override.h"
61 #include "BKE_lib_query.h"
62 #include "BKE_lib_remap.h"
63 #include "BKE_light.h"
64 #include "BKE_lightprobe.h"
65 #include "BKE_main.h"
66 #include "BKE_material.h"
67 #include "BKE_mball.h"
68 #include "BKE_mesh.h"
69 #include "BKE_modifier.h"
70 #include "BKE_node.h"
71 #include "BKE_object.h"
72 #include "BKE_pointcloud.h"
73 #include "BKE_report.h"
74 #include "BKE_scene.h"
75 #include "BKE_speaker.h"
76 #include "BKE_texture.h"
77 #include "BKE_volume.h"
78 
79 #include "DEG_depsgraph.h"
80 #include "DEG_depsgraph_build.h"
81 #include "DEG_depsgraph_query.h"
82 
83 #include "WM_api.h"
84 #include "WM_types.h"
85 
86 #include "UI_interface.h"
87 #include "UI_resources.h"
88 
89 #include "RNA_access.h"
90 #include "RNA_define.h"
91 #include "RNA_enum_types.h"
92 
93 #include "ED_armature.h"
94 #include "ED_curve.h"
95 #include "ED_gpencil.h"
96 #include "ED_keyframing.h"
97 #include "ED_mesh.h"
98 #include "ED_object.h"
99 #include "ED_screen.h"
100 #include "ED_view3d.h"
101 
102 #include "object_intern.h"
103 
104 /* ------------------------------------------------------------------- */
109 {
111 }
112 
114 {
115  Main *bmain = CTX_data_main(C);
117  View3D *v3d = CTX_wm_view3d(C);
119  ViewLayer *view_layer = CTX_data_view_layer(C);
120  Object *obedit = CTX_data_edit_object(C);
121  Object *par;
122 
123 #define INDEX_UNSET -1
124  int par1, par2, par3, par4;
125  par1 = par2 = par3 = par4 = INDEX_UNSET;
126 
127  /* we need 1 to 3 selected vertices */
128 
129  if (obedit->type == OB_MESH) {
130  Mesh *me = obedit->data;
131  BMEditMesh *em;
132 
133  EDBM_mesh_load(bmain, obedit);
134  EDBM_mesh_make(obedit, scene->toolsettings->selectmode, true);
135 
136  DEG_id_tag_update(obedit->data, 0);
137 
138  em = me->edit_mesh;
139 
141 
142  /* Make sure the evaluated mesh is updated.
143  *
144  * Most reliable way is to update the tagged objects, which will ensure
145  * proper copy-on-write update, but also will make sure all dependent
146  * objects are also up to date. */
148 
149  BMVert *eve;
150  BMIter iter;
151  int curr_index;
152  BM_ITER_MESH_INDEX (eve, &iter, em->bm, BM_VERTS_OF_MESH, curr_index) {
153  if (BM_elem_flag_test(eve, BM_ELEM_SELECT)) {
154  if (par1 == INDEX_UNSET) {
155  par1 = curr_index;
156  }
157  else if (par2 == INDEX_UNSET) {
158  par2 = curr_index;
159  }
160  else if (par3 == INDEX_UNSET) {
161  par3 = curr_index;
162  }
163  else if (par4 == INDEX_UNSET) {
164  par4 = curr_index;
165  }
166  else {
167  break;
168  }
169  }
170  }
171  }
172  else if (ELEM(obedit->type, OB_SURF, OB_CURVES_LEGACY)) {
173  ListBase *editnurb = object_editcurve_get(obedit);
174  int curr_index = 0;
175  for (Nurb *nu = editnurb->first; nu != NULL; nu = nu->next) {
176  if (nu->type == CU_BEZIER) {
177  BezTriple *bezt = nu->bezt;
178  for (int nurb_index = 0; nurb_index < nu->pntsu; nurb_index++, bezt++, curr_index++) {
179  if (BEZT_ISSEL_ANY_HIDDENHANDLES(v3d, bezt)) {
180  if (par1 == INDEX_UNSET) {
181  par1 = curr_index;
182  }
183  else if (par2 == INDEX_UNSET) {
184  par2 = curr_index;
185  }
186  else if (par3 == INDEX_UNSET) {
187  par3 = curr_index;
188  }
189  else if (par4 == INDEX_UNSET) {
190  par4 = curr_index;
191  }
192  else {
193  break;
194  }
195  }
196  }
197  }
198  else {
199  BPoint *bp = nu->bp;
200  const int num_points = nu->pntsu * nu->pntsv;
201  for (int nurb_index = 0; nurb_index < num_points; nurb_index++, bp++, curr_index++) {
202  if (bp->f1 & SELECT) {
203  if (par1 == INDEX_UNSET) {
204  par1 = curr_index;
205  }
206  else if (par2 == INDEX_UNSET) {
207  par2 = curr_index;
208  }
209  else if (par3 == INDEX_UNSET) {
210  par3 = curr_index;
211  }
212  else if (par4 == INDEX_UNSET) {
213  par4 = curr_index;
214  }
215  else {
216  break;
217  }
218  }
219  }
220  }
221  }
222  }
223  else if (obedit->type == OB_LATTICE) {
224  Lattice *lt = obedit->data;
225 
226  const int num_points = lt->editlatt->latt->pntsu * lt->editlatt->latt->pntsv *
227  lt->editlatt->latt->pntsw;
228  BPoint *bp = lt->editlatt->latt->def;
229  for (int curr_index = 0; curr_index < num_points; curr_index++, bp++) {
230  if (bp->f1 & SELECT) {
231  if (par1 == INDEX_UNSET) {
232  par1 = curr_index;
233  }
234  else if (par2 == INDEX_UNSET) {
235  par2 = curr_index;
236  }
237  else if (par3 == INDEX_UNSET) {
238  par3 = curr_index;
239  }
240  else if (par4 == INDEX_UNSET) {
241  par4 = curr_index;
242  }
243  else {
244  break;
245  }
246  }
247  }
248  }
249 
250  if (par4 != INDEX_UNSET || par1 == INDEX_UNSET || (par2 != INDEX_UNSET && par3 == INDEX_UNSET)) {
251  BKE_report(op->reports, RPT_ERROR, "Select either 1 or 3 vertices to parent to");
252  return OPERATOR_CANCELLED;
253  }
254 
255  CTX_DATA_BEGIN (C, Object *, ob, selected_editable_objects) {
256  if (ob != obedit) {
258  par = obedit->parent;
259 
260  if (BKE_object_parent_loop_check(par, ob)) {
261  BKE_report(op->reports, RPT_ERROR, "Loop in parents");
262  }
263  else {
264  Object workob;
265 
266  ob->parent = BASACT(view_layer)->object;
267  if (par3 != INDEX_UNSET) {
268  ob->partype = PARVERT3;
269  ob->par1 = par1;
270  ob->par2 = par2;
271  ob->par3 = par3;
272 
273  /* inverse parent matrix */
275  invert_m4_m4(ob->parentinv, workob.obmat);
276  }
277  else {
278  ob->partype = PARVERT1;
279  ob->par1 = par1;
280 
281  /* inverse parent matrix */
283  invert_m4_m4(ob->parentinv, workob.obmat);
284  }
285  }
286  }
287  }
288  CTX_DATA_END;
289 
291 
293 
294  return OPERATOR_FINISHED;
295 
296 #undef INDEX_UNSET
297 }
298 
300 {
301  /* identifiers */
302  ot->name = "Make Vertex Parent";
303  ot->description = "Parent selected objects to the selected vertices";
304  ot->idname = "OBJECT_OT_vertex_parent_set";
305 
306  /* api callbacks */
310 
311  /* flags */
313 }
314 
317 /* ------------------------------------------------------------------- */
323  "CLEAR",
324  0,
325  "Clear Parent",
326  "Completely clear the parenting relationship, including involved modifiers if any"},
328  "CLEAR_KEEP_TRANSFORM",
329  0,
330  "Clear and Keep Transformation",
331  "As 'Clear Parent', but keep the current visual transformations of the object"},
333  "CLEAR_INVERSE",
334  0,
335  "Clear Parent Inverse",
336  "Reset the transform corrections applied to the parenting relationship, does not remove "
337  "parenting itself"},
338  {0, NULL, 0, NULL, NULL},
339 };
340 
341 /* Helper for ED_object_parent_clear() - Remove deform-modifiers associated with parent */
343 {
345  ModifierData *md, *mdn;
346 
347  /* assume that we only need to remove the first instance of matching deform modifier here */
348  for (md = ob->modifiers.first; md; md = mdn) {
349  bool free = false;
350 
351  mdn = md->next;
352 
353  /* need to match types (modifier + parent) and references */
354  if ((md->type == eModifierType_Armature) && (par->type == OB_ARMATURE)) {
356  if (amd->object == par) {
357  free = true;
358  }
359  }
360  else if ((md->type == eModifierType_Lattice) && (par->type == OB_LATTICE)) {
362  if (lmd->object == par) {
363  free = true;
364  }
365  }
366  else if ((md->type == eModifierType_Curve) && (par->type == OB_CURVES_LEGACY)) {
368  if (cmd->object == par) {
369  free = true;
370  }
371  }
372 
373  /* free modifier if match */
374  if (free) {
376  BKE_modifier_free(md);
377  }
378  }
379  }
380 }
381 
382 void ED_object_parent_clear(Object *ob, const int type)
383 {
384  if (ob->parent == NULL) {
385  return;
386  }
388  switch (type) {
389  case CLEAR_PARENT_ALL: {
390  /* for deformers, remove corresponding modifiers to prevent
391  * a large number of modifiers building up */
393 
394  /* clear parenting relationship completely */
395  ob->parent = NULL;
396  ob->partype = PAROBJECT;
397  ob->parsubstr[0] = 0;
398  break;
399  }
401  /* remove parent, and apply the parented transform
402  * result as object's local transforms */
403  ob->parent = NULL;
404  BKE_object_apply_mat4(ob, ob->obmat, true, false);
405 
406  /* Don't recalculate the animation because it would change the transform
407  * instead of keeping it. */
408  flags &= ~ID_RECALC_ANIMATION;
409  break;
410  }
411  case CLEAR_PARENT_INVERSE: {
412  /* object stays parented, but the parent inverse
413  * (i.e. offset from parent to retain binding state)
414  * is cleared. In other words: nothing to do here! */
415  break;
416  }
417  }
418 
419  /* Always clear parentinv matrix for sake of consistency, see T41950. */
420  unit_m4(ob->parentinv);
421 
422  DEG_id_tag_update(&ob->id, flags);
423 }
424 
425 /* NOTE: poll should check for editable scene. */
427 {
428  Main *bmain = CTX_data_main(C);
429  const int type = RNA_enum_get(op->ptr, "type");
430 
431  CTX_DATA_BEGIN (C, Object *, ob, selected_editable_objects) {
433  }
434  CTX_DATA_END;
435 
439  return OPERATOR_FINISHED;
440 }
441 
443 {
444  /* identifiers */
445  ot->name = "Clear Parent";
446  ot->description = "Clear the object's parenting";
447  ot->idname = "OBJECT_OT_parent_clear";
448 
449  /* api callbacks */
452 
453  /* flags */
455 
457 }
458 
461 /* ------------------------------------------------------------------- */
465 void ED_object_parent(Object *ob, Object *par, const int type, const char *substr)
466 {
467  /* Always clear parentinv matrix for sake of consistency, see T41950. */
468  unit_m4(ob->parentinv);
469 
470  if (!par || BKE_object_parent_loop_check(par, ob)) {
471  ob->parent = NULL;
472  ob->partype = PAROBJECT;
473  ob->parsubstr[0] = 0;
474  return;
475  }
476 
477  /* Other partypes are deprecated, do not use here! */
479 
480  /* this could use some more checks */
481 
482  ob->parent = par;
483  ob->partype &= ~PARTYPE;
484  ob->partype |= type;
485  BLI_strncpy(ob->parsubstr, substr, sizeof(ob->parsubstr));
486 }
487 
488 /* Operator Property */
490  {PAR_OBJECT, "OBJECT", 0, "Object", ""},
491  {PAR_ARMATURE, "ARMATURE", 0, "Armature Deform", ""},
492  {PAR_ARMATURE_NAME, "ARMATURE_NAME", 0, " With Empty Groups", ""},
493  {PAR_ARMATURE_AUTO, "ARMATURE_AUTO", 0, " With Automatic Weights", ""},
494  {PAR_ARMATURE_ENVELOPE, "ARMATURE_ENVELOPE", 0, " With Envelope Weights", ""},
495  {PAR_BONE, "BONE", 0, "Bone", ""},
496  {PAR_BONE_RELATIVE, "BONE_RELATIVE", 0, "Bone Relative", ""},
497  {PAR_CURVE, "CURVE", 0, "Curve Deform", ""},
498  {PAR_FOLLOW, "FOLLOW", 0, "Follow Path", ""},
499  {PAR_PATH_CONST, "PATH_CONST", 0, "Path Constraint", ""},
500  {PAR_LATTICE, "LATTICE", 0, "Lattice Deform", ""},
501  {PAR_VERTEX, "VERTEX", 0, "Vertex", ""},
502  {PAR_VERTEX_TRI, "VERTEX_TRI", 0, "Vertex (Triangle)", ""},
503  {0, NULL, 0, NULL, NULL},
504 };
505 
507  const bContext *C,
508  Scene *scene,
509  Object *const ob,
510  Object *const par,
511  int partype,
512  const bool xmirror,
513  const bool keep_transform,
514  const int vert_par[3])
515 {
516  Main *bmain = CTX_data_main(C);
518  bPoseChannel *pchan = NULL;
519  bPoseChannel *pchan_eval = NULL;
520  Object *parent_eval = DEG_get_evaluated_object(depsgraph, par);
521 
523 
524  /* Preconditions. */
525  if (ob == par) {
526  /* Parenting an object to itself is impossible. */
527  return false;
528  }
529 
530  if (BKE_object_parent_loop_check(par, ob)) {
531  BKE_report(reports, RPT_ERROR, "Loop in parents");
532  return false;
533  }
534 
535  switch (partype) {
536  case PAR_FOLLOW:
537  case PAR_PATH_CONST: {
538  if (par->type != OB_CURVES_LEGACY) {
539  return false;
540  }
541  Curve *cu = par->data;
542  Curve *cu_eval = parent_eval->data;
543  if ((cu->flag & CU_PATH) == 0) {
544  cu->flag |= CU_PATH | CU_FOLLOW;
545  cu_eval->flag |= CU_PATH | CU_FOLLOW;
546  /* force creation of path data */
548  }
549  else {
550  cu->flag |= CU_FOLLOW;
551  cu_eval->flag |= CU_FOLLOW;
552  }
553 
554  /* if follow, add F-Curve for ctime (i.e. "eval_time") so that path-follow works */
555  if (partype == PAR_FOLLOW) {
556  /* get or create F-Curve */
557  bAction *act = ED_id_action_ensure(bmain, &cu->id);
558  FCurve *fcu = ED_action_fcurve_ensure(bmain, act, NULL, NULL, "eval_time", 0);
559 
560  /* setup dummy 'generator' modifier here to get 1-1 correspondence still working */
561  if (!fcu->bezt && !fcu->fpt && !fcu->modifiers.first) {
563  }
564  }
565 
566  /* fall back on regular parenting now (for follow only) */
567  if (partype == PAR_FOLLOW) {
568  partype = PAR_OBJECT;
569  }
570  break;
571  }
572  case PAR_BONE:
573  case PAR_BONE_RELATIVE:
575  pchan_eval = BKE_pose_channel_active_if_layer_visible(parent_eval);
576 
577  if (pchan == NULL) {
578  BKE_report(reports, RPT_ERROR, "No active bone");
579  return false;
580  }
581  }
582 
583  Object workob;
584 
585  /* Apply transformation of previous parenting. */
586  if (keep_transform) {
587  /* Was removed because of bug T23577,
588  * but this can be handy in some cases too T32616, so make optional. */
589  BKE_object_apply_mat4(ob, ob->obmat, false, false);
590  }
591 
592  /* Set the parent (except for follow-path constraint option). */
593  if (partype != PAR_PATH_CONST) {
594  ob->parent = par;
595  /* Always clear parentinv matrix for sake of consistency, see T41950. */
596  unit_m4(ob->parentinv);
598  }
599 
600  /* Handle types. */
601  if (pchan) {
602  BLI_strncpy(ob->parsubstr, pchan->name, sizeof(ob->parsubstr));
603  }
604  else {
605  ob->parsubstr[0] = 0;
606  }
607 
608  switch (partype) {
609  case PAR_PATH_CONST:
610  /* Don't do anything here, since this is not technically "parenting". */
611  break;
612  case PAR_CURVE:
613  case PAR_LATTICE:
614  case PAR_ARMATURE:
615  case PAR_ARMATURE_NAME:
617  case PAR_ARMATURE_AUTO:
618  /* partype is now set to PAROBJECT so that invisible 'virtual'
619  * modifiers don't need to be created.
620  * NOTE: the old (2.4x) method was to set ob->partype = PARSKEL,
621  * creating the virtual modifiers.
622  */
623  ob->partype = PAROBJECT; /* NOTE: DNA define, not operator property. */
624  /* ob->partype = PARSKEL; */ /* NOTE: DNA define, not operator property. */
625 
626  /* BUT, to keep the deforms, we need a modifier,
627  * and then we need to set the object that it uses
628  * - We need to ensure that the modifier we're adding doesn't already exist,
629  * so we check this by assuming that the parent is selected too.
630  */
631  /* XXX currently this should only happen for meshes, curves, surfaces,
632  * and lattices - this stuff isn't available for meta-balls yet. */
634  ModifierData *md;
635 
636  switch (partype) {
637  case PAR_CURVE: /* curve deform */
638  if (BKE_modifiers_is_deformed_by_curve(ob) != par) {
639  md = ED_object_modifier_add(reports, bmain, scene, ob, NULL, eModifierType_Curve);
640  if (md) {
641  ((CurveModifierData *)md)->object = par;
642  }
643  if (par->runtime.curve_cache &&
646  }
647  }
648  break;
649  case PAR_LATTICE: /* lattice deform */
650  if (BKE_modifiers_is_deformed_by_lattice(ob) != par) {
651  md = ED_object_modifier_add(reports, bmain, scene, ob, NULL, eModifierType_Lattice);
652  if (md) {
653  ((LatticeModifierData *)md)->object = par;
654  }
655  }
656  break;
657  default: /* armature deform */
658  if (BKE_modifiers_is_deformed_by_armature(ob) != par) {
659  md = ED_object_modifier_add(reports, bmain, scene, ob, NULL, eModifierType_Armature);
660  if (md) {
661  ((ArmatureModifierData *)md)->object = par;
662  }
663  }
664  break;
665  }
666  }
667  break;
668  case PAR_BONE:
669  ob->partype = PARBONE; /* NOTE: DNA define, not operator property. */
670  if (pchan->bone) {
671  pchan->bone->flag &= ~BONE_RELATIVE_PARENTING;
672  pchan_eval->bone->flag &= ~BONE_RELATIVE_PARENTING;
673  }
674  break;
675  case PAR_BONE_RELATIVE:
676  ob->partype = PARBONE; /* NOTE: DNA define, not operator property. */
677  if (pchan->bone) {
678  pchan->bone->flag |= BONE_RELATIVE_PARENTING;
679  pchan_eval->bone->flag |= BONE_RELATIVE_PARENTING;
680  }
681  break;
682  case PAR_VERTEX:
683  ob->partype = PARVERT1;
684  ob->par1 = vert_par[0];
685  break;
686  case PAR_VERTEX_TRI:
687  ob->partype = PARVERT3;
688  copy_v3_v3_int(&ob->par1, vert_par);
689  break;
690  case PAR_OBJECT:
691  case PAR_FOLLOW:
692  ob->partype = PAROBJECT; /* NOTE: DNA define, not operator property. */
693  break;
694  }
695 
696  /* Constraint and set parent inverse. */
697  const bool is_armature_parent = ELEM(
699  if (partype == PAR_PATH_CONST) {
700  bConstraint *con;
702  float cmat[4][4], vec[3];
703 
705 
706  data = con->data;
707  data->tar = par;
708 
711  sub_v3_v3v3(vec, ob->obmat[3], cmat[3]);
712 
713  copy_v3_v3(ob->loc, vec);
714  }
715  else if (is_armature_parent && (ob->type == OB_MESH) && (par->type == OB_ARMATURE)) {
716  if (partype == PAR_ARMATURE_NAME) {
718  reports, depsgraph, scene, ob, par, ARM_GROUPS_NAME, false);
719  }
720  else if (partype == PAR_ARMATURE_ENVELOPE) {
722  reports, depsgraph, scene, ob, par, ARM_GROUPS_ENVELOPE, xmirror);
723  }
724  else if (partype == PAR_ARMATURE_AUTO) {
725  WM_cursor_wait(true);
727  reports, depsgraph, scene, ob, par, ARM_GROUPS_AUTO, xmirror);
728  WM_cursor_wait(false);
729  }
730  /* get corrected inverse */
731  ob->partype = PAROBJECT;
733 
734  invert_m4_m4(ob->parentinv, workob.obmat);
735  }
736  else if (is_armature_parent && (ob->type == OB_GPENCIL) && (par->type == OB_ARMATURE)) {
737  if (partype == PAR_ARMATURE) {
738  ED_gpencil_add_armature(C, reports, ob, par);
739  }
740  else if (partype == PAR_ARMATURE_NAME) {
742  }
743  else if (ELEM(partype, PAR_ARMATURE_AUTO, PAR_ARMATURE_ENVELOPE)) {
744  WM_cursor_wait(true);
746  WM_cursor_wait(false);
747  }
748  /* get corrected inverse */
749  ob->partype = PAROBJECT;
751 
752  invert_m4_m4(ob->parentinv, workob.obmat);
753  }
754  else if ((ob->type == OB_GPENCIL) && (par->type == OB_LATTICE)) {
755  /* Add Lattice modifier */
756  if (partype == PAR_LATTICE) {
757  ED_gpencil_add_lattice_modifier(C, reports, ob, par);
758  }
759  /* get corrected inverse */
760  ob->partype = PAROBJECT;
762 
763  invert_m4_m4(ob->parentinv, workob.obmat);
764  }
765  else {
766  /* calculate inverse parent matrix */
768  invert_m4_m4(ob->parentinv, workob.obmat);
769  }
770 
772  return true;
773 }
774 
775 static void parent_set_vert_find(KDTree_3d *tree, Object *child, int vert_par[3], bool is_tri)
776 {
777  const float *co_find = child->obmat[3];
778  if (is_tri) {
779  KDTreeNearest_3d nearest[3];
780  int tot;
781 
782  tot = BLI_kdtree_3d_find_nearest_n(tree, co_find, nearest, 3);
783  BLI_assert(tot == 3);
784  UNUSED_VARS(tot);
785 
786  vert_par[0] = nearest[0].index;
787  vert_par[1] = nearest[1].index;
788  vert_par[2] = nearest[2].index;
789 
790  BLI_assert(min_iii(UNPACK3(vert_par)) >= 0);
791  }
792  else {
793  vert_par[0] = BLI_kdtree_3d_find_nearest(tree, co_find, NULL);
794  BLI_assert(vert_par[0] >= 0);
795  vert_par[1] = 0;
796  vert_par[2] = 0;
797  }
798 }
799 
804  int partype;
806  bool xmirror;
808 };
809 
810 static bool parent_set_nonvertex_parent(bContext *C, struct ParentingContext *parenting_context)
811 {
812  CTX_DATA_BEGIN (C, Object *, ob, selected_editable_objects) {
813  if (ob == parenting_context->par) {
814  /* ED_object_parent_set() will fail (and thus return false), but this case shouldn't break
815  * this loop. It's expected that the active object is also selected. */
816  continue;
817  }
818 
819  if (!ED_object_parent_set(parenting_context->reports,
820  C,
821  parenting_context->scene,
822  ob,
823  parenting_context->par,
824  parenting_context->partype,
825  parenting_context->xmirror,
826  parenting_context->keep_transform,
827  NULL)) {
828  return false;
829  }
830  }
831  CTX_DATA_END;
832 
833  return true;
834 }
835 
837  struct ParentingContext *parenting_context,
838  struct KDTree_3d *tree)
839 {
840  int vert_par[3] = {0, 0, 0};
841 
842  CTX_DATA_BEGIN (C, Object *, ob, selected_editable_objects) {
843  if (ob == parenting_context->par) {
844  /* ED_object_parent_set() will fail (and thus return false), but this case shouldn't break
845  * this loop. It's expected that the active object is also selected. */
846  continue;
847  }
848 
849  parent_set_vert_find(tree, ob, vert_par, parenting_context->is_vertex_tri);
850  if (!ED_object_parent_set(parenting_context->reports,
851  C,
852  parenting_context->scene,
853  ob,
854  parenting_context->par,
855  parenting_context->partype,
856  parenting_context->xmirror,
857  parenting_context->keep_transform,
858  vert_par)) {
859  return false;
860  }
861  }
862  CTX_DATA_END;
863  return true;
864 }
865 
866 static bool parent_set_vertex_parent(bContext *C, struct ParentingContext *parenting_context)
867 {
868  struct KDTree_3d *tree = NULL;
869  int tree_tot;
870 
871  tree = BKE_object_as_kdtree(parenting_context->par, &tree_tot);
872  BLI_assert(tree != NULL);
873 
874  if (tree_tot < (parenting_context->is_vertex_tri ? 3 : 1)) {
875  BKE_report(parenting_context->reports, RPT_ERROR, "Not enough vertices for vertex-parent");
876  BLI_kdtree_3d_free(tree);
877  return false;
878  }
879 
880  const bool ok = parent_set_vertex_parent_with_kdtree(C, parenting_context, tree);
881  BLI_kdtree_3d_free(tree);
882  return ok;
883 }
884 
886 {
887  const int partype = RNA_enum_get(op->ptr, "type");
888  struct ParentingContext parenting_context = {
889  .reports = op->reports,
890  .scene = CTX_data_scene(C),
891  .par = ED_object_active_context(C),
892  .partype = partype,
893  .is_vertex_tri = partype == PAR_VERTEX_TRI,
894  .xmirror = RNA_boolean_get(op->ptr, "xmirror"),
895  .keep_transform = RNA_boolean_get(op->ptr, "keep_transform"),
896  };
897 
898  bool ok;
899  if (ELEM(parenting_context.partype, PAR_VERTEX, PAR_VERTEX_TRI)) {
900  ok = parent_set_vertex_parent(C, &parenting_context);
901  }
902  else {
903  ok = parent_set_nonvertex_parent(C, &parenting_context);
904  }
905  if (!ok) {
906  return OPERATOR_CANCELLED;
907  }
908 
909  Main *bmain = CTX_data_main(C);
913 
914  return OPERATOR_FINISHED;
915 }
916 
918 {
919  Object *parent = ED_object_active_context(C);
920  uiPopupMenu *pup = UI_popup_menu_begin(C, IFACE_("Set Parent To"), ICON_NONE);
921  uiLayout *layout = UI_popup_menu_layout(pup);
922 
923  PointerRNA opptr;
924 #if 0
925  uiItemEnumO_ptr(layout, ot, NULL, 0, "type", PAR_OBJECT);
926 #else
927  uiItemFullO_ptr(layout, ot, IFACE_("Object"), ICON_NONE, NULL, WM_OP_EXEC_DEFAULT, 0, &opptr);
928  RNA_enum_set(&opptr, "type", PAR_OBJECT);
929  RNA_boolean_set(&opptr, "keep_transform", false);
930 
931  uiItemFullO_ptr(layout,
932  ot,
933  IFACE_("Object (Keep Transform)"),
934  ICON_NONE,
935  NULL,
937  0,
938  &opptr);
939  RNA_enum_set(&opptr, "type", PAR_OBJECT);
940  RNA_boolean_set(&opptr, "keep_transform", true);
941 #endif
942 
943  uiItemBooleanO(layout,
944  IFACE_("Object (Without Inverse)"),
945  ICON_NONE,
946  "OBJECT_OT_parent_no_inverse_set",
947  "keep_transform",
948  0);
949 
950  uiItemBooleanO(layout,
951  IFACE_("Object (Keep Transform Without Inverse)"),
952  ICON_NONE,
953  "OBJECT_OT_parent_no_inverse_set",
954  "keep_transform",
955  1);
956 
957  struct {
958  bool mesh, gpencil, curves;
959  } has_children_of_type = {0};
960 
961  CTX_DATA_BEGIN (C, Object *, child, selected_editable_objects) {
962  if (child == parent) {
963  continue;
964  }
965  if (child->type == OB_MESH) {
966  has_children_of_type.mesh = true;
967  }
968  if (child->type == OB_GPENCIL) {
969  has_children_of_type.gpencil = true;
970  }
971  if (child->type == OB_CURVES) {
972  has_children_of_type.curves = true;
973  }
974  }
975  CTX_DATA_END;
976 
977  if (parent->type == OB_ARMATURE) {
978  uiItemEnumO_ptr(layout, ot, NULL, 0, "type", PAR_ARMATURE);
979  uiItemEnumO_ptr(layout, ot, NULL, 0, "type", PAR_ARMATURE_NAME);
980  if (!has_children_of_type.gpencil) {
981  uiItemEnumO_ptr(layout, ot, NULL, 0, "type", PAR_ARMATURE_ENVELOPE);
982  }
983  if (has_children_of_type.mesh || has_children_of_type.gpencil) {
984  uiItemEnumO_ptr(layout, ot, NULL, 0, "type", PAR_ARMATURE_AUTO);
985  }
986  uiItemEnumO_ptr(layout, ot, NULL, 0, "type", PAR_BONE);
987  uiItemEnumO_ptr(layout, ot, NULL, 0, "type", PAR_BONE_RELATIVE);
988  }
989  else if (parent->type == OB_CURVES_LEGACY) {
990  uiItemEnumO_ptr(layout, ot, NULL, 0, "type", PAR_CURVE);
991  uiItemEnumO_ptr(layout, ot, NULL, 0, "type", PAR_FOLLOW);
992  uiItemEnumO_ptr(layout, ot, NULL, 0, "type", PAR_PATH_CONST);
993  }
994  else if (parent->type == OB_LATTICE) {
995  uiItemEnumO_ptr(layout, ot, NULL, 0, "type", PAR_LATTICE);
996  }
997  else if (parent->type == OB_MESH) {
998  if (has_children_of_type.curves) {
999  uiItemO(layout, "Object (Attach Curves to Surface)", ICON_NONE, "CURVES_OT_surface_set");
1000  }
1001  }
1002 
1003  /* vertex parenting */
1004  if (OB_TYPE_SUPPORT_PARVERT(parent->type)) {
1005  uiItemEnumO_ptr(layout, ot, NULL, 0, "type", PAR_VERTEX);
1006  uiItemEnumO_ptr(layout, ot, NULL, 0, "type", PAR_VERTEX_TRI);
1007  }
1008 
1009  UI_popup_menu_end(C, pup);
1010 
1011  return OPERATOR_INTERFACE;
1012 }
1013 
1014 static int parent_set_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
1015 {
1016  if (RNA_property_is_set(op->ptr, op->type->prop)) {
1017  return parent_set_exec(C, op);
1018  }
1019  return parent_set_invoke_menu(C, op->type);
1020 }
1021 
1023  wmOperator *op,
1024  const PropertyRNA *prop)
1025 {
1026  const char *prop_id = RNA_property_identifier(prop);
1027 
1028  /* Only show XMirror for PAR_ARMATURE_ENVELOPE and PAR_ARMATURE_AUTO! */
1029  if (STREQ(prop_id, "xmirror")) {
1030  const int type = RNA_enum_get(op->ptr, "type");
1032  return true;
1033  }
1034  return false;
1035  }
1036 
1037  return true;
1038 }
1039 
1041 {
1042  /* identifiers */
1043  ot->name = "Make Parent";
1044  ot->description = "Set the object's parenting";
1045  ot->idname = "OBJECT_OT_parent_set";
1046 
1047  /* api callbacks */
1049  ot->exec = parent_set_exec;
1052 
1053  /* flags */
1055 
1056  ot->prop = RNA_def_enum(ot->srna, "type", prop_make_parent_types, 0, "Type", "");
1058  ot->srna,
1059  "xmirror",
1060  false,
1061  "X Mirror",
1062  "Apply weights symmetrically along X axis, for Envelope/Automatic vertex groups creation");
1064  "keep_transform",
1065  false,
1066  "Keep Transform",
1067  "Apply transformation before parenting");
1068 }
1069 
1072 /* ------------------------------------------------------------------- */
1077 {
1078  Main *bmain = CTX_data_main(C);
1080 
1081  const bool keep_transform = RNA_boolean_get(op->ptr, "keep_transform");
1082 
1084 
1085  /* context iterator */
1086  CTX_DATA_BEGIN (C, Object *, ob, selected_editable_objects) {
1087  if (ob != par) {
1088  if (BKE_object_parent_loop_check(par, ob)) {
1089  BKE_report(op->reports, RPT_ERROR, "Loop in parents");
1090  }
1091  else {
1092  /* set recalc flags */
1094 
1095  /* set parenting type for object - object only... */
1096  ob->parent = par;
1097  ob->partype = PAROBJECT; /* NOTE: DNA define, not operator property. */
1098 
1099  if (keep_transform) {
1101  continue;
1102  }
1103 
1104  /* clear inverse matrix and also the object location */
1105  unit_m4(ob->parentinv);
1106  memset(ob->loc, 0, sizeof(float[3]));
1107  }
1108  }
1109  }
1110  CTX_DATA_END;
1111 
1112  DEG_relations_tag_update(bmain);
1115 
1116  return OPERATOR_FINISHED;
1117 }
1118 
1120 {
1121  /* identifiers */
1122  ot->name = "Make Parent without Inverse";
1123  ot->description = "Set the object's parenting without setting the inverse parent correction";
1124  ot->idname = "OBJECT_OT_parent_no_inverse_set";
1125 
1126  /* api callbacks */
1130 
1131  /* flags */
1133 
1135  "keep_transform",
1136  false,
1137  "Keep Transform",
1138  "Preserve the world transform throughout parenting");
1139 }
1140 
1143 /* ------------------------------------------------------------------- */
1147 enum {
1150 };
1151 
1153  {CLEAR_TRACK, "CLEAR", 0, "Clear Track", ""},
1155  "CLEAR_KEEP_TRANSFORM",
1156  0,
1157  "Clear and Keep Transformation (Clear Track)",
1158  ""},
1159  {0, NULL, 0, NULL, NULL},
1160 };
1161 
1162 /* NOTE: poll should check for editable scene. */
1164 {
1165  Main *bmain = CTX_data_main(C);
1166  const int type = RNA_enum_get(op->ptr, "type");
1167 
1168  if (CTX_data_edit_object(C)) {
1169  BKE_report(op->reports, RPT_ERROR, "Operation cannot be performed in edit mode");
1170  return OPERATOR_CANCELLED;
1171  }
1172  CTX_DATA_BEGIN (C, Object *, ob, selected_editable_objects) {
1173  bConstraint *con, *pcon;
1174 
1175  /* remove track-object for old track */
1176  ob->track = NULL;
1178 
1179  /* also remove all tracking constraints */
1180  for (con = ob->constraints.last; con; con = pcon) {
1181  pcon = con->prev;
1182  if (ELEM(con->type,
1186  BKE_constraint_remove(&ob->constraints, con);
1187  }
1188  }
1189 
1191  BKE_object_apply_mat4(ob, ob->obmat, true, true);
1192  }
1193  }
1194  CTX_DATA_END;
1195 
1196  DEG_relations_tag_update(bmain);
1198 
1199  return OPERATOR_FINISHED;
1200 }
1201 
1203 {
1204  /* identifiers */
1205  ot->name = "Clear Track";
1206  ot->description = "Clear tracking constraint or flag from object";
1207  ot->idname = "OBJECT_OT_track_clear";
1208 
1209  /* api callbacks */
1212 
1214 
1215  /* flags */
1217 
1218  ot->prop = RNA_def_enum(ot->srna, "type", prop_clear_track_types, 0, "Type", "");
1219 }
1220 
1223 /* ------------------------------------------------------------------- */
1227 enum {
1231 };
1232 
1234  {CREATE_TRACK_DAMPTRACK, "DAMPTRACK", 0, "Damped Track Constraint", ""},
1235  {CREATE_TRACK_TRACKTO, "TRACKTO", 0, "Track to Constraint", ""},
1236  {CREATE_TRACK_LOCKTRACK, "LOCKTRACK", 0, "Lock Track Constraint", ""},
1237  {0, NULL, 0, NULL, NULL},
1238 };
1239 
1241 {
1242  Main *bmain = CTX_data_main(C);
1243  Object *obact = ED_object_active_context(C);
1244 
1245  const int type = RNA_enum_get(op->ptr, "type");
1246 
1247  switch (type) {
1248  case CREATE_TRACK_DAMPTRACK: {
1249  bConstraint *con;
1251 
1252  CTX_DATA_BEGIN (C, Object *, ob, selected_editable_objects) {
1253  if (ob != obact) {
1255 
1256  data = con->data;
1257  data->tar = obact;
1258  DEG_id_tag_update(&ob->id,
1260 
1261  /* Light, Camera and Speaker track differently by default */
1262  if (ELEM(ob->type, OB_LAMP, OB_CAMERA, OB_SPEAKER)) {
1263  data->trackflag = TRACK_nZ;
1264  }
1265  }
1266  }
1267  CTX_DATA_END;
1268  break;
1269  }
1270  case CREATE_TRACK_TRACKTO: {
1271  bConstraint *con;
1273 
1274  CTX_DATA_BEGIN (C, Object *, ob, selected_editable_objects) {
1275  if (ob != obact) {
1277 
1278  data = con->data;
1279  data->tar = obact;
1280  DEG_id_tag_update(&ob->id,
1282 
1283  /* Light, Camera and Speaker track differently by default */
1284  if (ELEM(ob->type, OB_LAMP, OB_CAMERA, OB_SPEAKER)) {
1285  data->reserved1 = TRACK_nZ;
1286  data->reserved2 = UP_Y;
1287  }
1288  }
1289  }
1290  CTX_DATA_END;
1291  break;
1292  }
1293  case CREATE_TRACK_LOCKTRACK: {
1294  bConstraint *con;
1296 
1297  CTX_DATA_BEGIN (C, Object *, ob, selected_editable_objects) {
1298  if (ob != obact) {
1300 
1301  data = con->data;
1302  data->tar = obact;
1303  DEG_id_tag_update(&ob->id,
1305 
1306  /* Light, Camera and Speaker track differently by default */
1307  if (ELEM(ob->type, OB_LAMP, OB_CAMERA, OB_SPEAKER)) {
1308  data->trackflag = TRACK_nZ;
1309  data->lockflag = LOCK_Y;
1310  }
1311  }
1312  }
1313  CTX_DATA_END;
1314  break;
1315  }
1316  }
1317 
1318  DEG_relations_tag_update(bmain);
1320 
1321  return OPERATOR_FINISHED;
1322 }
1323 
1325 {
1326  /* identifiers */
1327  ot->name = "Make Track";
1328  ot->description = "Make the object track another object, using various methods/constraints";
1329  ot->idname = "OBJECT_OT_track_set";
1330 
1331  /* api callbacks */
1333  ot->exec = track_set_exec;
1334 
1336 
1337  /* flags */
1339 
1340  /* properties */
1341  ot->prop = RNA_def_enum(ot->srna, "type", prop_make_track_types, 0, "Type", "");
1342 }
1343 
1346 /* ------------------------------------------------------------------- */
1350 #if 0
1351 static void link_to_scene(Main *UNUSED(bmain), ushort UNUSED(nr))
1352 {
1353  Scene *sce = (Scene *)BLI_findlink(&bmain->scene, G.curscreen->scenenr - 1);
1354  Base *base, *nbase;
1355 
1356  if (sce == NULL) {
1357  return;
1358  }
1359  if (sce->id.lib) {
1360  return;
1361  }
1362 
1363  for (base = FIRSTBASE; base; base = base->next) {
1364  if (BASE_SELECTED(v3d, base)) {
1365  nbase = MEM_mallocN(sizeof(Base), "newbase");
1366  *nbase = *base;
1367  BLI_addhead(&(sce->base), nbase);
1368  id_us_plus((ID *)base->object);
1369  }
1370  }
1371 }
1372 #endif
1373 
1375 {
1376  Main *bmain = CTX_data_main(C);
1377  Scene *scene_to = BLI_findlink(&bmain->scenes, RNA_enum_get(op->ptr, "scene"));
1378 
1379  if (scene_to == NULL) {
1380  BKE_report(op->reports, RPT_ERROR, "Could not find scene");
1381  return OPERATOR_CANCELLED;
1382  }
1383 
1384  if (scene_to == CTX_data_scene(C)) {
1385  BKE_report(op->reports, RPT_ERROR, "Cannot link objects into the same scene");
1386  return OPERATOR_CANCELLED;
1387  }
1388 
1389  if (!BKE_id_is_editable(bmain, &scene_to->id)) {
1390  BKE_report(op->reports, RPT_ERROR, "Cannot link objects into a linked scene");
1391  return OPERATOR_CANCELLED;
1392  }
1393 
1394  Collection *collection_to = scene_to->master_collection;
1395  CTX_DATA_BEGIN (C, Base *, base, selected_bases) {
1396  BKE_collection_object_add(bmain, collection_to, base->object);
1397  }
1398  CTX_DATA_END;
1399 
1400  DEG_relations_tag_update(bmain);
1401 
1402  /* redraw the 3D view because the object center points are colored differently */
1404 
1405  /* one day multiple scenes will be visible, then we should have some update function for them
1406  */
1407  return OPERATOR_FINISHED;
1408 }
1409 
1410 enum {
1419 };
1420 
1421 /* Return true if make link data is allowed, false otherwise */
1422 static bool allow_make_links_data(const int type, Object *ob_src, Object *ob_dst)
1423 {
1424  switch (type) {
1425  case MAKE_LINKS_OBDATA:
1426  if (ob_src->type == ob_dst->type && ob_src->type != OB_EMPTY) {
1427  return true;
1428  }
1429  break;
1430  case MAKE_LINKS_MATERIALS:
1431  if (OB_TYPE_SUPPORT_MATERIAL(ob_src->type) && OB_TYPE_SUPPORT_MATERIAL(ob_dst->type) &&
1432  /* Linking non-grease-pencil materials to a grease-pencil object causes issues.
1433  * We make sure that if one of the objects is a grease-pencil object, the other must be
1434  * as well. */
1435  ((ob_src->type == OB_GPENCIL) == (ob_dst->type == OB_GPENCIL))) {
1436  return true;
1437  }
1438  break;
1440  if (ob_dst->type == OB_EMPTY) {
1441  return true;
1442  }
1443  break;
1444  case MAKE_LINKS_ANIMDATA:
1445  case MAKE_LINKS_GROUP:
1446  return true;
1447  case MAKE_LINKS_MODIFIERS:
1448  if (!ELEM(OB_EMPTY, ob_src->type, ob_dst->type)) {
1449  return true;
1450  }
1451  break;
1452  case MAKE_LINKS_FONTS:
1453  if ((ob_src->data != ob_dst->data) && (ob_src->type == OB_FONT) &&
1454  (ob_dst->type == OB_FONT)) {
1455  return true;
1456  }
1457  break;
1458  case MAKE_LINKS_SHADERFX:
1459  if ((ob_src->type == OB_GPENCIL) && (ob_dst->type == OB_GPENCIL)) {
1460  return true;
1461  }
1462  break;
1463  }
1464  return false;
1465 }
1466 
1468 {
1470  Main *bmain = CTX_data_main(C);
1471  const int type = RNA_enum_get(op->ptr, "type");
1472  Object *ob_src;
1473  ID *obdata_id;
1474  int a;
1475 
1476  /* collection */
1477  LinkNode *ob_collections = NULL;
1478  bool is_cycle = false;
1479  bool is_lib = false;
1480 
1481  ob_src = ED_object_active_context(C);
1482 
1483  /* avoid searching all collections in source object each time */
1484  if (type == MAKE_LINKS_GROUP) {
1485  ob_collections = BKE_object_groups(bmain, scene, ob_src);
1486  }
1487 
1488  CTX_DATA_BEGIN (C, Base *, base_dst, selected_editable_bases) {
1489  Object *ob_dst = base_dst->object;
1490 
1491  if (ob_src != ob_dst) {
1492  if (allow_make_links_data(type, ob_src, ob_dst)) {
1493  obdata_id = ob_dst->data;
1494 
1495  switch (type) {
1496  case MAKE_LINKS_OBDATA: /* obdata */
1497  id_us_min(obdata_id);
1498 
1499  obdata_id = ob_src->data;
1500  id_us_plus(obdata_id);
1501  ob_dst->data = obdata_id;
1502 
1503  /* if amount of material indices changed: */
1504  BKE_object_materials_test(bmain, ob_dst, ob_dst->data);
1505 
1507  break;
1508  case MAKE_LINKS_MATERIALS:
1509  /* new approach, using functions from kernel */
1510  for (a = 0; a < ob_src->totcol; a++) {
1511  Material *ma = BKE_object_material_get(ob_src, a + 1);
1512  /* also works with `ma == NULL` */
1513  BKE_object_material_assign(bmain, ob_dst, ma, a + 1, BKE_MAT_ASSIGN_USERPREF);
1514  }
1516  break;
1517  case MAKE_LINKS_ANIMDATA:
1518  BKE_animdata_copy_id(bmain, (ID *)ob_dst, (ID *)ob_src, 0);
1519  if (ob_dst->data && ob_src->data) {
1520  if (!BKE_id_is_editable(bmain, obdata_id)) {
1521  is_lib = true;
1522  break;
1523  }
1524  BKE_animdata_copy_id(bmain, (ID *)ob_dst->data, (ID *)ob_src->data, 0);
1525  }
1526  DEG_id_tag_update(&ob_dst->id,
1528  break;
1529  case MAKE_LINKS_GROUP: {
1530  LinkNode *collection_node;
1531 
1532  /* first clear collections */
1533  BKE_object_groups_clear(bmain, scene, ob_dst);
1534 
1535  /* now add in the collections from the link nodes */
1536  for (collection_node = ob_collections; collection_node;
1537  collection_node = collection_node->next) {
1538  if (ob_dst->instance_collection != collection_node->link) {
1539  BKE_collection_object_add(bmain, collection_node->link, ob_dst);
1540  }
1541  else {
1542  is_cycle = true;
1543  }
1544  }
1545  break;
1546  }
1548  ob_dst->instance_collection = ob_src->instance_collection;
1549  if (ob_dst->instance_collection) {
1550  id_us_plus(&ob_dst->instance_collection->id);
1551  ob_dst->transflag |= OB_DUPLICOLLECTION;
1552  }
1554  break;
1555  case MAKE_LINKS_MODIFIERS:
1556  BKE_object_link_modifiers(ob_dst, ob_src);
1557  DEG_id_tag_update(&ob_dst->id,
1559  break;
1560  case MAKE_LINKS_FONTS: {
1561  Curve *cu_src = ob_src->data;
1562  Curve *cu_dst = ob_dst->data;
1563 
1564  if (!BKE_id_is_editable(bmain, obdata_id)) {
1565  is_lib = true;
1566  break;
1567  }
1568 
1569  if (cu_dst->vfont) {
1570  id_us_min(&cu_dst->vfont->id);
1571  }
1572  cu_dst->vfont = cu_src->vfont;
1573  id_us_plus((ID *)cu_dst->vfont);
1574  if (cu_dst->vfontb) {
1575  id_us_min(&cu_dst->vfontb->id);
1576  }
1577  cu_dst->vfontb = cu_src->vfontb;
1578  id_us_plus((ID *)cu_dst->vfontb);
1579  if (cu_dst->vfonti) {
1580  id_us_min(&cu_dst->vfonti->id);
1581  }
1582  cu_dst->vfonti = cu_src->vfonti;
1583  id_us_plus((ID *)cu_dst->vfonti);
1584  if (cu_dst->vfontbi) {
1585  id_us_min(&cu_dst->vfontbi->id);
1586  }
1587  cu_dst->vfontbi = cu_src->vfontbi;
1588  id_us_plus((ID *)cu_dst->vfontbi);
1589 
1590  DEG_id_tag_update(&ob_dst->id,
1592  break;
1593  }
1594  case MAKE_LINKS_SHADERFX:
1595  ED_object_shaderfx_link(ob_dst, ob_src);
1596  DEG_id_tag_update(&ob_dst->id,
1598  break;
1599  }
1600  }
1601  }
1602  }
1603  CTX_DATA_END;
1604 
1605  if (type == MAKE_LINKS_GROUP) {
1606  if (ob_collections) {
1607  BLI_linklist_free(ob_collections, NULL);
1608  }
1609 
1610  if (is_cycle) {
1611  BKE_report(op->reports, RPT_WARNING, "Skipped some collections because of cycle detected");
1612  }
1613  }
1614 
1615  if (is_lib) {
1616  BKE_report(op->reports, RPT_WARNING, "Skipped editing library object data");
1617  }
1618 
1619  DEG_relations_tag_update(bmain);
1623 
1624  return OPERATOR_FINISHED;
1625 }
1626 
1628 {
1629  PropertyRNA *prop;
1630 
1631  /* identifiers */
1632  ot->name = "Link Objects to Scene";
1633  ot->description = "Link selection to another scene";
1634  ot->idname = "OBJECT_OT_make_links_scene";
1635 
1636  /* api callbacks */
1639  /* better not run the poll check */
1640 
1641  /* flags */
1643 
1644  /* properties */
1645  prop = RNA_def_enum(ot->srna, "scene", DummyRNA_NULL_items, 0, "Scene", "");
1648  ot->prop = prop;
1649 }
1650 
1652 {
1653  static const EnumPropertyItem make_links_items[] = {
1654  {MAKE_LINKS_OBDATA, "OBDATA", 0, "Link Object Data", "Replace assigned Object Data"},
1655  {MAKE_LINKS_MATERIALS, "MATERIAL", 0, "Link Materials", "Replace assigned Materials"},
1657  "ANIMATION",
1658  0,
1659  "Link Animation Data",
1660  "Replace assigned Animation Data"},
1661  {MAKE_LINKS_GROUP, "GROUPS", 0, "Link Collections", "Replace assigned Collections"},
1663  "DUPLICOLLECTION",
1664  0,
1665  "Link Instance Collection",
1666  "Replace assigned Collection Instance"},
1667  {MAKE_LINKS_FONTS, "FONTS", 0, "Link Fonts to Text", "Replace Text object Fonts"},
1669  {MAKE_LINKS_MODIFIERS, "MODIFIERS", 0, "Copy Modifiers", "Replace Modifiers"},
1671  "EFFECTS",
1672  0,
1673  "Copy Grease Pencil Effects",
1674  "Replace Grease Pencil Effects"},
1675  {0, NULL, 0, NULL, NULL},
1676  };
1677 
1678  /* identifiers */
1679  ot->name = "Link/Transfer Data";
1680  ot->description = "Transfer data from active object to selected objects";
1681  ot->idname = "OBJECT_OT_make_links_data";
1682 
1683  /* api callbacks */
1686 
1687  /* flags */
1689 
1690  /* properties */
1691  ot->prop = RNA_def_enum(ot->srna, "type", make_links_items, 0, "Type", "");
1692 }
1693 
1696 /* ------------------------------------------------------------------- */
1701 {
1702  /* NOTE: When dealing with linked data, we always make a local copy of it.
1703  * While in theory we could rather make it local when it only has one user, this is difficult
1704  * in practice with current code of this function. */
1705  return (id != NULL && (id->us > 1 || ID_IS_LINKED(id)));
1706 }
1707 
1709  Collection *collection,
1710  const bool do_collection)
1711 {
1712  if (do_collection) {
1713  BKE_libblock_relink_to_newid(bmain, &collection->id, 0);
1714  }
1715 
1716  for (CollectionObject *cob = collection->gobject.first; cob != NULL; cob = cob->next) {
1717  BKE_libblock_relink_to_newid(bmain, &cob->ob->id, 0);
1718  }
1719 
1720  LISTBASE_FOREACH (CollectionChild *, child, &collection->children) {
1721  libblock_relink_collection(bmain, child->collection, true);
1722  }
1723 }
1724 
1726  Scene *scene,
1727  Collection *collection,
1728  const int flag,
1729  const bool copy_collections,
1730  const bool is_master_collection)
1731 {
1732  /* Generate new copies for objects in given collection and all its children,
1733  * and optionally also copy collections themselves. */
1734  if (copy_collections && !is_master_collection) {
1735  Collection *collection_new = (Collection *)BKE_id_copy_ex(
1736  bmain, &collection->id, NULL, LIB_ID_COPY_DEFAULT | LIB_ID_COPY_ACTIONS);
1737  id_us_min(&collection_new->id);
1738  collection = ID_NEW_SET(collection, collection_new);
1739  }
1740 
1741  /* We do not remap to new objects here, this is done in separate step. */
1742  LISTBASE_FOREACH (CollectionObject *, cob, &collection->gobject) {
1743  Object *ob = cob->ob;
1744  /* an object may be in more than one collection */
1745  if ((ob->id.newid == NULL) && ((ob->flag & flag) == flag)) {
1746  if (!ID_IS_LINKED(ob) && BKE_object_scenes_users_get(bmain, ob) > 1) {
1747  ID_NEW_SET(
1749  id_us_min(ob->id.newid);
1750  }
1751  }
1752  }
1753 
1754  /* Since master collection has already be duplicated as part of scene copy,
1755  * we do not duplicate it here.
1756  * However, this means its children need to be re-added manually here,
1757  * otherwise their parent lists are empty (which will lead to crashes, see T63101). */
1758  CollectionChild *child_next, *child = collection->children.first;
1759  CollectionChild *orig_child_last = collection->children.last;
1760  for (; child != NULL; child = child_next) {
1761  child_next = child->next;
1762  Collection *collection_child_new = single_object_users_collection(
1763  bmain, scene, child->collection, flag, copy_collections, false);
1764 
1765  if (is_master_collection && copy_collections && child->collection != collection_child_new) {
1766  /* We do not want a collection sync here, our collections are in a complete uninitialized
1767  * state currently. With current code, that would lead to a memory leak - because of
1768  * reasons. It would be a useless loss of computing anyway, since caller has to fully
1769  * refresh view-layers/collections caching at the end. */
1770  BKE_collection_child_add_no_sync(collection, collection_child_new);
1771  BLI_remlink(&collection->children, child);
1772  MEM_freeN(child);
1773  if (child == orig_child_last) {
1774  break;
1775  }
1776  }
1777  }
1778 
1779  return collection;
1780 }
1781 
1782 /* Warning, sets ID->newid pointers of objects and collections, but does not clear them. */
1784  Main *bmain, Scene *scene, View3D *v3d, const int flag, const bool copy_collections)
1785 {
1786  /* duplicate all the objects of the scene (and matching collections, if required). */
1787  Collection *master_collection = scene->master_collection;
1788  single_object_users_collection(bmain, scene, master_collection, flag, copy_collections, true);
1789 
1790  /* Will also handle the master collection. */
1791  BKE_libblock_relink_to_newid(bmain, &scene->id, 0);
1792 
1793  /* Collection and object pointers in collections */
1795 
1796  /* We also have to handle runtime things in UI. */
1797  if (v3d) {
1798  ID_NEW_REMAP(v3d->camera);
1799  }
1800 
1801  /* Making single user may affect other scenes if they share
1802  * with current one some collections in their ViewLayer. */
1804 }
1805 
1807 {
1808  FOREACH_SCENE_OBJECT_BEGIN (scene, ob_iter) {
1809  ob_iter->flag &= ~OB_DONE;
1810  }
1812 
1813  /* tag only the one object */
1814  ob->flag |= OB_DONE;
1815 
1816  single_object_users(bmain, scene, NULL, OB_DONE, false);
1818 }
1819 
1821  Main *bmain, Scene *scene, ViewLayer *view_layer, View3D *v3d, const int flag)
1822 {
1823  Light *la;
1824  Curve *cu;
1825  Camera *cam;
1826  Mesh *me;
1827  Lattice *lat;
1828  ID *id;
1829 
1830  FOREACH_OBJECT_FLAG_BEGIN (scene, view_layer, v3d, flag, ob) {
1831  if (BKE_id_is_editable(bmain, &ob->id)) {
1832  id = ob->data;
1835 
1836  switch (ob->type) {
1837  case OB_EMPTY:
1838  ob->data = ID_NEW_SET(
1839  ob->data,
1841  break;
1842  case OB_LAMP:
1843  ob->data = la = ID_NEW_SET(
1844  ob->data,
1846  break;
1847  case OB_CAMERA:
1848  cam = ob->data = ID_NEW_SET(
1849  ob->data,
1852  break;
1853  case OB_MESH:
1854  /* Needed to remap texcomesh below. */
1855  me = ob->data = ID_NEW_SET(
1856  ob->data,
1858  break;
1859  case OB_MBALL:
1860  ob->data = ID_NEW_SET(
1861  ob->data,
1863  break;
1864  case OB_CURVES_LEGACY:
1865  case OB_SURF:
1866  case OB_FONT:
1867  ob->data = cu = ID_NEW_SET(
1868  ob->data,
1870  ID_NEW_REMAP(cu->bevobj);
1871  ID_NEW_REMAP(cu->taperobj);
1872  break;
1873  case OB_LATTICE:
1874  ob->data = lat = ID_NEW_SET(
1875  ob->data,
1877  break;
1878  case OB_ARMATURE:
1880  ob->data = ID_NEW_SET(
1881  ob->data,
1883  BKE_pose_rebuild(bmain, ob, ob->data, true);
1884  break;
1885  case OB_SPEAKER:
1886  ob->data = ID_NEW_SET(
1887  ob->data,
1889  break;
1890  case OB_LIGHTPROBE:
1891  ob->data = ID_NEW_SET(
1892  ob->data,
1894  break;
1895  case OB_GPENCIL:
1896  ob->data = ID_NEW_SET(
1897  ob->data,
1899  break;
1900  case OB_CURVES:
1901  ob->data = ID_NEW_SET(
1902  ob->data,
1904  break;
1905  case OB_POINTCLOUD:
1906  ob->data = ID_NEW_SET(
1907  ob->data,
1909  break;
1910  case OB_VOLUME:
1911  ob->data = ID_NEW_SET(
1912  ob->data,
1914  break;
1915  default:
1916  printf("ERROR %s: can't copy %s\n", __func__, id->name);
1917  BLI_assert_msg(0, "This should never happen.");
1918 
1919  /* We need to end the FOREACH_OBJECT_FLAG_BEGIN iterator to prevent memory leak. */
1920  BKE_scene_objects_iterator_end(&iter_macro);
1921  return;
1922  }
1923 
1924  id_us_min(id);
1925  }
1926  }
1927  }
1929 
1930  me = bmain->meshes.first;
1931  while (me) {
1932  ID_NEW_REMAP(me->texcomesh);
1933  me = me->id.next;
1934  }
1935 }
1936 
1938 {
1939  FOREACH_SCENE_OBJECT_BEGIN (scene, ob_iter) {
1940  ob_iter->flag &= ~OB_DONE;
1941  }
1943 
1944  /* Tag only the one object. */
1945  ob->flag |= OB_DONE;
1946 
1948 }
1949 
1951  Main *bmain, Scene *scene, ViewLayer *view_layer, View3D *v3d, const int flag)
1952 {
1953  FOREACH_OBJECT_FLAG_BEGIN (scene, view_layer, v3d, flag, ob) {
1954  if (BKE_id_is_editable(bmain, &ob->id)) {
1955  AnimData *adt = BKE_animdata_from_id(&ob->id);
1956  if (adt == NULL) {
1957  continue;
1958  }
1959 
1960  ID *id_act = (ID *)adt->action;
1961  if (single_data_needs_duplication(id_act)) {
1964  }
1965  }
1966  }
1968 }
1969 
1971  Main *bmain, Scene *scene, ViewLayer *view_layer, View3D *v3d, const int flag)
1972 {
1973  FOREACH_OBJECT_FLAG_BEGIN (scene, view_layer, v3d, flag, ob) {
1974  if (BKE_id_is_editable(bmain, &ob->id) && ob->data != NULL) {
1975  ID *id_obdata = (ID *)ob->data;
1976  AnimData *adt = BKE_animdata_from_id(id_obdata);
1977  if (adt == NULL) {
1978  continue;
1979  }
1980 
1981  ID *id_act = (ID *)adt->action;
1982  if (single_data_needs_duplication(id_act)) {
1985  }
1986  }
1987  }
1989 }
1990 
1991 static void single_mat_users(
1992  Main *bmain, Scene *scene, ViewLayer *view_layer, View3D *v3d, const int flag)
1993 {
1994  Material *ma, *man;
1995  int a;
1996 
1997  FOREACH_OBJECT_FLAG_BEGIN (scene, view_layer, v3d, flag, ob) {
1998  if (BKE_id_is_editable(bmain, &ob->id)) {
1999  for (a = 1; a <= ob->totcol; a++) {
2000  ma = BKE_object_material_get(ob, (short)a);
2001  if (single_data_needs_duplication(&ma->id)) {
2002  man = (Material *)BKE_id_copy_ex(
2004  man->id.us = 0;
2005  BKE_object_material_assign(bmain, ob, man, (short)a, BKE_MAT_ASSIGN_USERPREF);
2006  }
2007  }
2008  }
2009  }
2011 }
2012 
2015 /* ------------------------------------------------------------------- */
2019 enum {
2024 };
2025 
2027 {
2028  ID **id_pointer = cb_data->id_pointer;
2029  if (*id_pointer) {
2030  (*id_pointer)->tag &= ~LIB_TAG_DOIT;
2031  }
2032 
2033  return IDWALK_RET_NOP;
2034 }
2035 
2036 static void tag_localizable_objects(bContext *C, const int mode)
2037 {
2038  Main *bmain = CTX_data_main(C);
2039 
2040  BKE_main_id_tag_all(bmain, LIB_TAG_DOIT, false);
2041 
2042  /* Set LIB_TAG_DOIT flag for all selected objects, so next we can check whether
2043  * object is gonna to become local or not.
2044  */
2045  CTX_DATA_BEGIN (C, Object *, object, selected_objects) {
2046  object->id.tag |= LIB_TAG_DOIT;
2047 
2048  /* If obdata is also going to become local, mark it as such too. */
2049  if (mode == MAKE_LOCAL_SELECT_OBDATA && object->data) {
2050  ID *data_id = (ID *)object->data;
2051  data_id->tag |= LIB_TAG_DOIT;
2052  }
2053  }
2054  CTX_DATA_END;
2055 
2056  /* Also forbid making objects local if other library objects are using
2057  * them for modifiers or constraints.
2058  */
2059  for (Object *object = bmain->objects.first; object; object = object->id.next) {
2060  if ((object->id.tag & LIB_TAG_DOIT) == 0) {
2063  }
2064  if (object->data) {
2065  ID *data_id = (ID *)object->data;
2066  if ((data_id->tag & LIB_TAG_DOIT) == 0) {
2068  }
2069  }
2070  }
2071 
2072  /* TODO(sergey): Drivers targets? */
2073 }
2074 
2080  ViewLayer *view_layer,
2081  Collection *collection)
2082 {
2083  Object *ob;
2084  bool changed = false;
2085 
2086  for (ob = bmain->objects.first; ob; ob = ob->id.next) {
2087  if (ID_IS_LINKED(ob) && (ob->id.us == 0)) {
2088  Base *base;
2089 
2090  id_us_plus(&ob->id);
2091 
2092  BKE_collection_object_add(bmain, collection, ob);
2093  base = BKE_view_layer_base_find(view_layer, ob);
2096 
2097  changed = true;
2098  }
2099  }
2100 
2101  return changed;
2102 }
2103 
2105 {
2106  NlaStrip *strip;
2107 
2108  for (strip = strips->first; strip; strip = strip->next) {
2109  if (strip->act) {
2110  strip->act->id.tag &= ~LIB_TAG_PRE_EXISTING;
2111  }
2112 
2114  }
2115 }
2116 
2117 /* Tag all actions used by given animdata to be made local. */
2119 {
2120  if (adt) {
2121  /* Actions - Active and Temp */
2122  if (adt->action) {
2123  adt->action->id.tag &= ~LIB_TAG_PRE_EXISTING;
2124  }
2125  if (adt->tmpact) {
2126  adt->tmpact->id.tag &= ~LIB_TAG_PRE_EXISTING;
2127  }
2128 
2129  /* Drivers */
2130  /* TODO: need to handle the ID-targets too? */
2131 
2132  /* NLA Data */
2133  LISTBASE_FOREACH (NlaTrack *, nlt, &adt->nla_tracks) {
2134  make_local_animdata_tag_strips(&nlt->strips);
2135  }
2136  }
2137 }
2138 
2140 {
2141  if (ma) {
2142  ma->id.tag &= ~LIB_TAG_PRE_EXISTING;
2144 
2145  /* About nodetrees: root one is made local together with material,
2146  * others we keep linked for now... */
2147  }
2148 }
2149 
2151 {
2152  Main *bmain = CTX_data_main(C);
2153  ParticleSystem *psys;
2154  Material *ma, ***matarar;
2155  const int mode = RNA_enum_get(op->ptr, "type");
2156  int a;
2157 
2158  /* NOTE: we (ab)use LIB_TAG_PRE_EXISTING to cherry pick which ID to make local... */
2159  if (mode == MAKE_LOCAL_ALL) {
2160  ViewLayer *view_layer = CTX_data_view_layer(C);
2161  Collection *collection = CTX_data_collection(C);
2162 
2164 
2165  /* De-select so the user can differentiate newly instanced from existing objects. */
2167 
2168  if (make_local_all__instance_indirect_unused(bmain, view_layer, collection)) {
2169  BKE_report(op->reports,
2170  RPT_INFO,
2171  "Orphan library objects added to the current scene to avoid loss");
2172  }
2173  }
2174  else {
2176  tag_localizable_objects(C, mode);
2177 
2178  CTX_DATA_BEGIN (C, Object *, ob, selected_objects) {
2179  if ((ob->id.tag & LIB_TAG_DOIT) == 0) {
2180  continue;
2181  }
2182 
2183  ob->id.tag &= ~LIB_TAG_PRE_EXISTING;
2185  for (psys = ob->particlesystem.first; psys; psys = psys->next) {
2186  psys->part->id.tag &= ~LIB_TAG_PRE_EXISTING;
2187  }
2188 
2189  if (mode == MAKE_LOCAL_SELECT_OBDATA_MATERIAL) {
2190  for (a = 0; a < ob->totcol; a++) {
2191  ma = ob->mat[a];
2192  if (ma) {
2194  }
2195  }
2196 
2197  matarar = BKE_object_material_array_p(ob);
2198  if (matarar) {
2199  for (a = 0; a < ob->totcol; a++) {
2200  ma = (*matarar)[a];
2201  if (ma) {
2203  }
2204  }
2205  }
2206  }
2207 
2209  ob->data != NULL) {
2210  ID *ob_data = ob->data;
2211  ob_data->tag &= ~LIB_TAG_PRE_EXISTING;
2213  }
2214  }
2215  CTX_DATA_END;
2216  }
2217 
2218  BKE_library_make_local(bmain, NULL, NULL, true, false); /* NULL is all libs */
2219 
2221  return OPERATOR_FINISHED;
2222 }
2223 
2225 {
2226  static const EnumPropertyItem type_items[] = {
2227  {MAKE_LOCAL_SELECT_OB, "SELECT_OBJECT", 0, "Selected Objects", ""},
2228  {MAKE_LOCAL_SELECT_OBDATA, "SELECT_OBDATA", 0, "Selected Objects and Data", ""},
2230  "SELECT_OBDATA_MATERIAL",
2231  0,
2232  "Selected Objects, Data and Materials",
2233  ""},
2234  {MAKE_LOCAL_ALL, "ALL", 0, "All", ""},
2235  {0, NULL, 0, NULL, NULL},
2236  };
2237 
2238  /* identifiers */
2239  ot->name = "Make Local";
2240  ot->description = "Make library linked data-blocks local to this file";
2241  ot->idname = "OBJECT_OT_make_local";
2242 
2243  /* api callbacks */
2245  ot->exec = make_local_exec;
2247 
2248  /* flags */
2250 
2251  /* properties */
2252  ot->prop = RNA_def_enum(ot->srna, "type", type_items, 0, "Type", "");
2253 }
2254 
2257 /* ------------------------------------------------------------------- */
2262 {
2263  /* An object is actually overridable only if it is in at least one local collection.
2264  * Unfortunately 'direct link' flag is not enough here. */
2265  LISTBASE_FOREACH (Collection *, collection, &bmain->collections) {
2266  if (!ID_IS_LINKED(collection) && BKE_collection_has_object(collection, object)) {
2267  return true;
2268  }
2269  }
2270  LISTBASE_FOREACH (Scene *, scene, &bmain->scenes) {
2272  return true;
2273  }
2274  }
2275  return false;
2276 }
2277 
2279 {
2280  Main *bmain = CTX_data_main(C);
2282  ViewLayer *view_layer = CTX_data_view_layer(C);
2283  Object *obact = CTX_data_active_object(C);
2284  ID *id_root = NULL;
2285  bool is_override_instancing_object = false;
2286 
2287  bool user_overrides_from_selected_objects = false;
2288 
2289  if (!ID_IS_LINKED(obact) && obact->instance_collection != NULL &&
2292  BKE_reportf(op->reports,
2294  "Collection '%s' (instantiated by the active object) is not overridable",
2295  obact->instance_collection->id.name + 2);
2296  return OPERATOR_CANCELLED;
2297  }
2298 
2299  id_root = &obact->instance_collection->id;
2300  is_override_instancing_object = true;
2301  user_overrides_from_selected_objects = false;
2302  }
2303  else if (!make_override_library_object_overridable_check(bmain, obact)) {
2304  const int i = RNA_property_int_get(op->ptr, op->type->prop);
2305  const uint collection_session_uuid = *((const uint *)&i);
2306  if (collection_session_uuid == MAIN_ID_SESSION_UUID_UNSET) {
2307  BKE_reportf(op->reports,
2309  "Could not find an overridable root hierarchy for object '%s'",
2310  obact->id.name + 2);
2311  return OPERATOR_CANCELLED;
2312  }
2313  Collection *collection = BLI_listbase_bytes_find(&bmain->collections,
2314  &collection_session_uuid,
2315  sizeof(collection_session_uuid),
2316  offsetof(ID, session_uuid));
2317  id_root = &collection->id;
2318  user_overrides_from_selected_objects = true;
2319  }
2320  /* Else, poll func ensures us that ID_IS_LINKED(obact) is true, or that it is already an existing
2321  * liboverride. */
2322  else {
2324  id_root = &obact->id;
2325  user_overrides_from_selected_objects = true;
2326  }
2327 
2328  /* Make already existing selected liboverrides editable. */
2329  bool is_active_override = false;
2330  FOREACH_SELECTED_OBJECT_BEGIN (view_layer, CTX_wm_view3d(C), ob_iter) {
2331  if (ID_IS_OVERRIDE_LIBRARY_REAL(ob_iter) && !ID_IS_LINKED(ob_iter)) {
2332  ob_iter->id.override_library->flag &= ~IDOVERRIDE_LIBRARY_FLAG_SYSTEM_DEFINED;
2333  is_active_override = is_active_override || (&ob_iter->id == id_root);
2335  }
2336  }
2338  /* If the active object is a liboverride, there is no point going further, since in the weird
2339  * case where some other selected objects would be linked ones, there is no way to properly
2340  * create overrides for them currently.
2341  *
2342  * Could be added later if really needed, but would rather avoid that extra complexity here. */
2343  if (is_active_override) {
2344  return OPERATOR_FINISHED;
2345  }
2346 
2347  const bool do_fully_editable = !user_overrides_from_selected_objects;
2348 
2349  GSet *user_overrides_objects_uids = do_fully_editable ? NULL :
2352  __func__);
2353 
2354  if (do_fully_editable) {
2355  /* Pass. */
2356  }
2357  else if (user_overrides_from_selected_objects) {
2358  /* Only selected objects can be 'user overrides'. */
2359  FOREACH_SELECTED_OBJECT_BEGIN (view_layer, CTX_wm_view3d(C), ob_iter) {
2360  BLI_gset_add(user_overrides_objects_uids, POINTER_FROM_UINT(ob_iter->id.session_uuid));
2361  }
2363  }
2364  else {
2365  /* Only armatures inside the root collection (and their children) can be 'user overrides'. */
2367  if (ob_iter->type == OB_ARMATURE) {
2368  BLI_gset_add(user_overrides_objects_uids, POINTER_FROM_UINT(ob_iter->id.session_uuid));
2369  }
2370  }
2372  }
2373 
2374  BKE_main_id_tag_all(bmain, LIB_TAG_DOIT, false);
2375 
2376  /* For the time being, replace selected linked objects by their overrides in all collections.
2377  * While this may not be the absolute best behavior in all cases, in most common one this should
2378  * match the expected result. */
2379  if (user_overrides_objects_uids != NULL) {
2380  LISTBASE_FOREACH (Collection *, coll_iter, &bmain->collections) {
2381  if (ID_IS_LINKED(coll_iter)) {
2382  continue;
2383  }
2384  LISTBASE_FOREACH (CollectionObject *, coll_ob_iter, &coll_iter->gobject) {
2385  if (BLI_gset_haskey(user_overrides_objects_uids,
2386  POINTER_FROM_UINT(coll_ob_iter->ob->id.session_uuid))) {
2387  /* Tag for remapping when creating overrides. */
2388  coll_iter->id.tag |= LIB_TAG_DOIT;
2389  break;
2390  }
2391  }
2392  }
2393  }
2394 
2395  ID *id_root_override;
2396  const bool success = BKE_lib_override_library_create(bmain,
2397  scene,
2398  view_layer,
2399  NULL,
2400  id_root,
2401  id_root,
2402  &obact->id,
2403  &id_root_override,
2404  do_fully_editable);
2405 
2406  if (!do_fully_editable) {
2407  /* Define liboverrides from selected/validated objects as user defined. */
2408  ID *id_hierarchy_root_override = id_root_override->override_library->hierarchy_root;
2409  ID *id_iter;
2410  FOREACH_MAIN_ID_BEGIN (bmain, id_iter) {
2411  if (ID_IS_LINKED(id_iter) || !ID_IS_OVERRIDE_LIBRARY_REAL(id_iter) ||
2412  id_iter->override_library->hierarchy_root != id_hierarchy_root_override) {
2413  continue;
2414  }
2415  if (BLI_gset_haskey(user_overrides_objects_uids,
2418  }
2419  }
2421 
2422  BLI_gset_free(user_overrides_objects_uids, NULL);
2423  }
2424 
2425  if (success) {
2426  if (is_override_instancing_object) {
2427  /* Remove the instance empty from this scene, the items now have an overridden collection
2428  * instead. */
2429  ED_object_base_free_and_unlink(bmain, scene, obact);
2430  }
2431  else {
2432  /* Remove the found root ID from the view layer. */
2433  switch (GS(id_root->name)) {
2434  case ID_GR: {
2435  Collection *collection_root = (Collection *)id_root;
2437  CollectionParent *, collection_parent, &collection_root->parents) {
2438  if (ID_IS_LINKED(collection_parent->collection) ||
2439  !BKE_view_layer_has_collection(view_layer, collection_parent->collection)) {
2440  continue;
2441  }
2442  BKE_collection_child_remove(bmain, collection_parent->collection, collection_root);
2443  }
2444  break;
2445  }
2446  case ID_OB: {
2447  /* TODO: Not sure how well we can handle this case, when we don't have the collections as
2448  * reference containers... */
2449  break;
2450  }
2451  default:
2452  break;
2453  }
2454  }
2455  }
2456 
2461 
2462  return success ? OPERATOR_FINISHED : OPERATOR_CANCELLED;
2463 }
2464 
2465 /* Set the object to override. */
2467 {
2468  Main *bmain = CTX_data_main(C);
2470  ViewLayer *view_layer = CTX_data_view_layer(C);
2471  Object *obact = ED_object_active_context(C);
2472 
2473  /* Sanity checks. */
2474  if (!scene || ID_IS_LINKED(scene) || !obact) {
2475  return OPERATOR_CANCELLED;
2476  }
2477 
2478  if ((!ID_IS_LINKED(obact) && obact->instance_collection != NULL &&
2481  return make_override_library_exec(C, op);
2482  }
2483 
2484  if (!ID_IS_LINKED(obact)) {
2485  if (ID_IS_OVERRIDE_LIBRARY_REAL(obact)) {
2486  return make_override_library_exec(C, op);
2487  }
2488  BKE_report(op->reports, RPT_ERROR, "Cannot make library override from a local object");
2489  return OPERATOR_CANCELLED;
2490  }
2491 
2492  int potential_root_collections_num = 0;
2493  uint collection_session_uuid = MAIN_ID_SESSION_UUID_UNSET;
2494  LISTBASE_FOREACH (Collection *, collection, &bmain->collections) {
2495  /* Only check for directly linked collections. */
2496  if (!ID_IS_LINKED(&collection->id) || (collection->id.tag & LIB_TAG_INDIRECT) != 0 ||
2497  !BKE_view_layer_has_collection(view_layer, collection)) {
2498  continue;
2499  }
2500  if (BKE_collection_has_object_recursive(collection, obact)) {
2501  if (potential_root_collections_num == 0) {
2502  collection_session_uuid = collection->id.session_uuid;
2503  }
2504  potential_root_collections_num++;
2505  }
2506  }
2507 
2508  if (potential_root_collections_num <= 1) {
2509  RNA_property_int_set(op->ptr, op->type->prop, *((int *)&collection_session_uuid));
2510  return make_override_library_exec(C, op);
2511  }
2512 
2513  BKE_reportf(op->reports,
2514  RPT_ERROR,
2515  "Too many potential root collections (%d) for the override hierarchy, "
2516  "please use the Outliner instead",
2517  potential_root_collections_num);
2518  return OPERATOR_CANCELLED;
2519 }
2520 
2522 {
2523  Object *obact = CTX_data_active_object(C);
2524 
2525  /* Object must be directly linked to be overridable. */
2526  return (
2527  ED_operator_objectmode(C) && obact != NULL &&
2528  (ID_IS_LINKED(obact) || ID_IS_OVERRIDE_LIBRARY(obact) ||
2529  (obact->instance_collection != NULL &&
2531 }
2532 
2534 {
2535  /* identifiers */
2536  ot->name = "Make Library Override";
2537  ot->description =
2538  "Create a local override of the selected linked objects, and their hierarchy of "
2539  "dependencies";
2540  ot->idname = "OBJECT_OT_make_override_library";
2541 
2542  /* api callbacks */
2546 
2547  /* flags */
2549 
2550  /* properties */
2551  PropertyRNA *prop;
2552  prop = RNA_def_int(ot->srna,
2553  "collection",
2555  INT_MIN,
2556  INT_MAX,
2557  "Override Collection",
2558  "Session UUID of the directly linked collection containing the selected "
2559  "object, to make an override from",
2560  INT_MIN,
2561  INT_MAX);
2563  ot->prop = prop;
2564 }
2565 
2567 {
2568  Object *obact = CTX_data_active_object(C);
2569 
2570  /* Object must be local and an override. */
2571  return (ED_operator_objectmode(C) && obact != NULL && !ID_IS_LINKED(obact) &&
2572  ID_IS_OVERRIDE_LIBRARY(obact));
2573 }
2574 
2576 {
2577  Main *bmain = CTX_data_main(C);
2578 
2579  /* Make already existing selected liboverrides editable. */
2581  if (ID_IS_OVERRIDE_LIBRARY_REAL(ob_iter) && !ID_IS_LINKED(ob_iter)) {
2582  BKE_lib_override_library_id_reset(bmain, &ob_iter->id, false);
2583  }
2584  }
2586 
2590 
2591  return OPERATOR_FINISHED;
2592 }
2593 
2595 {
2596  /* identifiers */
2597  ot->name = "Reset Library Override";
2598  ot->description = "Reset the selected local overrides to their linked references values";
2599  ot->idname = "OBJECT_OT_reset_override_library";
2600 
2601  /* api callbacks */
2604 
2605  /* flags */
2607 }
2608 
2610 {
2611  Main *bmain = CTX_data_main(C);
2612  ViewLayer *view_layer = CTX_data_view_layer(C);
2614  LinkNode *todo_objects = NULL, *todo_object_iter;
2615 
2616  /* Make already existing selected liboverrides editable. */
2617  FOREACH_SELECTED_OBJECT_BEGIN (view_layer, CTX_wm_view3d(C), ob_iter) {
2618  if (ID_IS_LINKED(ob_iter)) {
2619  continue;
2620  }
2621  BLI_linklist_prepend_alloca(&todo_objects, ob_iter);
2622  }
2624 
2625  for (todo_object_iter = todo_objects; todo_object_iter != NULL;
2626  todo_object_iter = todo_object_iter->next) {
2627  Object *ob_iter = todo_object_iter->link;
2628  if (BKE_lib_override_library_is_hierarchy_leaf(bmain, &ob_iter->id)) {
2629  bool do_remap_active = false;
2630  if (OBACT(view_layer) == ob_iter) {
2631  do_remap_active = true;
2632  }
2633  BKE_libblock_remap(bmain,
2634  &ob_iter->id,
2635  ob_iter->id.override_library->reference,
2637  if (do_remap_active) {
2638  Object *ref_object = (Object *)ob_iter->id.override_library->reference;
2639  Base *basact = BKE_view_layer_base_find(view_layer, ref_object);
2640  if (basact != NULL) {
2641  view_layer->basact = basact;
2642  }
2644  }
2645  BKE_id_delete(bmain, &ob_iter->id);
2646  }
2647  else {
2648  BKE_lib_override_library_id_reset(bmain, &ob_iter->id, true);
2649  }
2650  }
2651 
2656 
2657  return OPERATOR_FINISHED;
2658 }
2659 
2661 {
2662  /* identifiers */
2663  ot->name = "Clear Library Override";
2664  ot->description =
2665  "Delete the selected local overrides and relink their usages to the linked data-blocks if "
2666  "possible, else reset them and mark them as non editable";
2667  ot->idname = "OBJECT_OT_clear_override_library";
2668 
2669  /* api callbacks */
2672 
2673  /* flags */
2675 }
2676 
2679 /* ------------------------------------------------------------------- */
2683 enum {
2686 };
2687 
2689 {
2690  Main *bmain = CTX_data_main(C);
2692  ViewLayer *view_layer = CTX_data_view_layer(C);
2693  View3D *v3d = CTX_wm_view3d(C); /* ok if this is NULL */
2694  const int flag = (RNA_enum_get(op->ptr, "type") == MAKE_SINGLE_USER_SELECTED) ? SELECT : 0;
2695  const bool copy_collections = false;
2696  bool update_deps = false;
2697 
2698  if (RNA_boolean_get(op->ptr, "object")) {
2699  if (flag == SELECT) {
2701  single_object_users(bmain, scene, v3d, OB_DONE, copy_collections);
2702  }
2703  else {
2704  single_object_users(bmain, scene, v3d, 0, copy_collections);
2705  }
2706 
2707  /* needed since object relationships may have changed */
2708  update_deps = true;
2709  }
2710 
2711  if (RNA_boolean_get(op->ptr, "obdata")) {
2712  single_obdata_users(bmain, scene, view_layer, v3d, flag);
2713 
2714  /* Needed since some IDs were remapped? (incl. me->texcomesh, see T73797). */
2715  update_deps = true;
2716  }
2717 
2718  if (RNA_boolean_get(op->ptr, "material")) {
2719  single_mat_users(bmain, scene, view_layer, v3d, flag);
2720  }
2721 
2722  if (RNA_boolean_get(op->ptr, "animation")) {
2723  single_object_action_users(bmain, scene, view_layer, v3d, flag);
2724  }
2725 
2726  if (RNA_boolean_get(op->ptr, "obdata_animation")) {
2727  single_objectdata_action_users(bmain, scene, view_layer, v3d, flag);
2728  }
2729 
2731 
2733 
2734  if (update_deps) {
2735  DEG_relations_tag_update(bmain);
2736  }
2737 
2738  return OPERATOR_FINISHED;
2739 }
2740 
2742 {
2743  static const EnumPropertyItem type_items[] = {
2744  {MAKE_SINGLE_USER_SELECTED, "SELECTED_OBJECTS", 0, "Selected Objects", ""},
2745  {MAKE_SINGLE_USER_ALL, "ALL", 0, "All", ""},
2746  {0, NULL, 0, NULL, NULL},
2747  };
2748 
2749  /* identifiers */
2750  ot->name = "Make Single User";
2751  ot->description = "Make linked data local to each object";
2752  ot->idname = "OBJECT_OT_make_single_user";
2753 
2754  /* Note that the invoke callback is only used from operator search,
2755  * otherwise this does nothing by default. */
2756 
2757  /* api callbacks */
2761 
2762  /* flags */
2764 
2765  /* properties */
2766  ot->prop = RNA_def_enum(ot->srna, "type", type_items, MAKE_SINGLE_USER_SELECTED, "Type", "");
2767 
2768  RNA_def_boolean(ot->srna, "object", 0, "Object", "Make single user objects");
2769  RNA_def_boolean(ot->srna, "obdata", 0, "Object Data", "Make single user object data");
2770  RNA_def_boolean(ot->srna, "material", 0, "Materials", "Make materials local to each data-block");
2772  "animation",
2773  0,
2774  "Object Animation",
2775  "Make object animation data local to each object");
2777  "obdata_animation",
2778  0,
2779  "Object Data Animation",
2780  "Make object data (mesh, curve etc.) animation data local to each object");
2781 }
2782 
2785 /* ------------------------------------------------------------------- */
2789 char *ED_object_ot_drop_named_material_tooltip(bContext *C, const char *name, const int mval[2])
2790 {
2791  int mat_slot = 0;
2792  Object *ob = ED_view3d_give_material_slot_under_cursor(C, mval, &mat_slot);
2793  if (ob == NULL) {
2794  return BLI_strdup("");
2795  }
2796  mat_slot = max_ii(mat_slot, 1);
2797 
2798  Material *prev_mat = BKE_object_material_get(ob, mat_slot);
2799 
2800  char *result;
2801  if (prev_mat) {
2802  const char *tooltip = TIP_("Drop %s on %s (slot %d, replacing %s)");
2803  result = BLI_sprintfN(tooltip, name, ob->id.name + 2, mat_slot, prev_mat->id.name + 2);
2804  }
2805  else {
2806  const char *tooltip = TIP_("Drop %s on %s (slot %d)");
2807  result = BLI_sprintfN(tooltip, name, ob->id.name + 2, mat_slot);
2808  }
2809  return result;
2810 }
2811 
2812 static int drop_named_material_invoke(bContext *C, wmOperator *op, const wmEvent *event)
2813 {
2814  Main *bmain = CTX_data_main(C);
2815  int mat_slot = 0;
2816  Object *ob = ED_view3d_give_material_slot_under_cursor(C, event->mval, &mat_slot);
2817  mat_slot = max_ii(mat_slot, 1);
2818 
2820  bmain, op->ptr, ID_MA);
2821 
2822  if (ob == NULL || ma == NULL) {
2823  return OPERATOR_CANCELLED;
2824  }
2825 
2827 
2829 
2833 
2834  return OPERATOR_FINISHED;
2835 }
2836 
2838 {
2839  /* identifiers */
2840  ot->name = "Drop Named Material on Object";
2841  ot->idname = "OBJECT_OT_drop_named_material";
2842 
2843  /* api callbacks */
2846 
2847  /* flags */
2849 
2850  /* properties */
2852 }
2853 
2856 /* ------------------------------------------------------------------- */
2861 {
2862  ID *id;
2863  PropertyPointerRNA pprop;
2864 
2866 
2867  if (pprop.prop == NULL) {
2868  BKE_report(op->reports, RPT_ERROR, "Incorrect context for running object data unlink");
2869  return OPERATOR_CANCELLED;
2870  }
2871 
2872  id = pprop.ptr.owner_id;
2873 
2874  if (GS(id->name) == ID_OB) {
2875  Object *ob = (Object *)id;
2876  if (ob->data) {
2877  ID *id_data = ob->data;
2878 
2879  if (GS(id_data->name) == ID_IM) {
2880  id_us_min(id_data);
2881  ob->data = NULL;
2882  }
2883  else {
2884  BKE_report(op->reports, RPT_ERROR, "Can't unlink this object data");
2885  return OPERATOR_CANCELLED;
2886  }
2887  }
2888  }
2889 
2890  RNA_property_update(C, &pprop.ptr, pprop.prop);
2891 
2892  return OPERATOR_FINISHED;
2893 }
2894 
2896 {
2897  /* identifiers */
2898  ot->name = "Unlink";
2899  ot->idname = "OBJECT_OT_unlink_data";
2900 
2901  /* api callbacks */
2903 
2904  /* flags */
2905  ot->flag = OPTYPE_INTERNAL;
2906 }
2907 
Blender kernel action and pose functionality.
struct bPoseChannel * BKE_pose_channel_active_if_layer_visible(struct Object *ob)
Definition: action.c:720
void BKE_animdata_duplicate_id_action(struct Main *bmain, struct ID *id, uint duplicate_flags)
bool BKE_animdata_copy_id(struct Main *bmain, struct ID *id_to, struct ID *id_from, int flag)
Definition: anim_data.c:327
struct AnimData * BKE_animdata_from_id(const struct ID *id)
void BKE_pose_rebuild(struct Main *bmain, struct Object *ob, struct bArmature *arm, bool do_id_user)
Definition: armature.c:2362
Camera data-block and utility functions.
#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:1125
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:921
bool BKE_collection_child_remove(struct Main *bmain, struct Collection *parent, struct Collection *child)
Definition: collection.c:1600
bool BKE_collection_child_add_no_sync(struct Collection *parent, struct Collection *child)
Definition: collection.c:1595
#define FOREACH_COLLECTION_OBJECT_RECURSIVE_BEGIN(_collection, _object)
void BKE_scene_objects_iterator_end(struct BLI_Iterator *iter)
Definition: collection.c:2074
#define FOREACH_SCENE_OBJECT_BEGIN(scene, _instance)
bool BKE_constraint_remove(ListBase *list, struct bConstraint *con)
Definition: constraint.c:5592
struct bConstraint * BKE_constraint_add_for_object(struct Object *ob, const char *name, short type)
Definition: constraint.c:5870
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:6214
struct Scene * CTX_data_scene(const bContext *C)
Definition: context.c:1090
struct Object * CTX_data_edit_object(const bContext *C)
Definition: context.c:1370
#define CTX_DATA_BEGIN(C, Type, instance, member)
Definition: BKE_context.h:269
struct ViewLayer * CTX_data_view_layer(const bContext *C)
Definition: context.c:1100
struct Collection * CTX_data_collection(const bContext *C)
Definition: context.c:1141
struct Depsgraph * CTX_data_ensure_evaluated_depsgraph(const bContext *C)
Definition: context.c:1528
struct Object * CTX_data_active_object(const bContext *C)
Definition: context.c:1353
struct View3D * CTX_wm_view3d(const bContext *C)
Definition: context.c:784
struct Main * CTX_data_main(const bContext *C)
Definition: context.c:1074
#define CTX_DATA_END
Definition: BKE_context.h:278
Low-level operations for curves that cannot be defined in the C++ header yet.
display list (or rather multi purpose list) stuff.
void BKE_displist_make_curveTypes(struct Depsgraph *depsgraph, const struct Scene *scene, struct Object *ob, bool for_render)
void BKE_editmesh_looptri_and_normals_calc(BMEditMesh *em)
Definition: editmesh.c:135
struct FModifier * add_fmodifier(ListBase *modifiers, int type, struct FCurve *owner_fcu)
Definition: fmodifier.c:1087
#define FOREACH_OBJECT_FLAG_END
Definition: BKE_layer.h:469
#define FOREACH_SELECTED_OBJECT_BEGIN(_view_layer, _v3d, _instance)
Definition: BKE_layer.h:303
void BKE_view_layer_selected_objects_tag(struct ViewLayer *view_layer, int tag)
Definition: layer.c:286
bool BKE_view_layer_has_collection(const struct ViewLayer *view_layer, const struct Collection *collection)
void BKE_view_layer_base_deselect_all(struct ViewLayer *view_layer)
Definition: layer.c:388
struct Base * BKE_view_layer_base_find(struct ViewLayer *view_layer, struct Object *ob)
Definition: layer.c:379
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:435
#define FOREACH_SELECTED_OBJECT_END
Definition: BKE_layer.h:315
@ LIB_ID_COPY_ACTIONS
Definition: BKE_lib_id.h:166
@ LIB_ID_COPY_DEFAULT
Definition: BKE_lib_id.h:181
void BKE_main_id_newptr_and_tag_clear(struct Main *bmain)
Definition: lib_id.c:1465
void BKE_library_make_local(struct Main *bmain, const struct Library *lib, struct GHash *old_to_new_ids, bool untagged_only, bool set_fake)
struct ID * BKE_id_copy_ex(struct Main *bmain, const struct ID *id, struct ID **r_newid, int flag)
void BKE_main_id_tag_all(struct Main *mainvar, int tag, bool value)
Definition: lib_id.c:930
bool BKE_id_is_editable(const struct Main *bmain, const struct ID *id)
void id_us_min(struct ID *id)
Definition: lib_id.c:313
void id_us_plus(struct ID *id)
Definition: lib_id.c:305
void BKE_id_delete(struct Main *bmain, void *idv) ATTR_NONNULL()
#define MAIN_ID_SESSION_UUID_UNSET
Definition: BKE_lib_id.h:82
bool BKE_lib_override_library_create(struct Main *bmain, struct Scene *scene, struct ViewLayer *view_layer, struct Library *owner_library, struct ID *id_root_reference, struct ID *id_hierarchy_root_reference, struct ID *id_instance_hint, struct ID **r_id_root_override, const bool do_fully_editable)
bool BKE_lib_override_library_is_hierarchy_leaf(struct Main *bmain, struct ID *id)
void BKE_lib_override_library_id_reset(struct Main *bmain, struct ID *id_root, bool do_reset_system_override)
void BKE_library_foreach_ID_link(struct Main *bmain, struct ID *id, LibraryIDLinkCallback callback, void *user_data, int flag)
Definition: lib_query.c:350
@ IDWALK_READONLY
@ IDWALK_RET_NOP
Definition: BKE_lib_query.h:83
@ ID_REMAP_SKIP_INDIRECT_USAGE
Definition: BKE_lib_remap.h:36
void void BKE_libblock_remap(struct Main *bmain, void *old_idv, void *new_idv, short remap_flags) ATTR_NONNULL(1
void BKE_libblock_relink_to_newid(struct Main *bmain, struct ID *id, int remap_flag) ATTR_NONNULL()
Definition: lib_remap.c:894
General operations, lookup, etc. for blender lights.
General operations for probes.
#define FOREACH_MAIN_ID_END
Definition: BKE_main.h:367
#define FOREACH_MAIN_ID_BEGIN(_bmain, _id)
Definition: BKE_main.h:361
General operations, lookup, etc. for materials.
struct Material *** BKE_object_material_array_p(struct Object *ob)
Definition: material.c:311
struct Material * BKE_object_material_get(struct Object *ob, short act)
Definition: material.c:687
void BKE_object_materials_test(struct Main *bmain, struct Object *ob, struct ID *id)
Definition: material.c:864
void BKE_object_material_assign(struct Main *bmain, struct Object *ob, struct Material *ma, short act, int assign_type)
Definition: material.c:1047
@ BKE_MAT_ASSIGN_USERPREF
Definition: BKE_material.h:80
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.cc:5234
void BKE_object_groups_clear(struct Main *bmain, struct Scene *scene, struct Object *object)
Definition: object.cc:5245
void BKE_object_apply_parent_inverse(struct Object *ob)
Definition: object.cc:3583
void BKE_object_apply_mat4(struct Object *ob, const float mat[4][4], bool use_compat, bool use_parent)
Definition: object.cc:3575
void BKE_object_workob_calc_parent(struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob, struct Object *workob)
Definition: object.cc:3501
struct KDTree_3d * BKE_object_as_kdtree(struct Object *ob, int *r_tot)
Definition: object.cc:5260
int BKE_object_scenes_users_get(struct Main *bmain, struct Object *ob)
Definition: object.cc:5031
General operations for point clouds.
void BKE_reportf(ReportList *reports, eReportType type, const char *format,...) ATTR_PRINTF_FORMAT(3
void BKE_report(ReportList *reports, eReportType type, const char *message)
Definition: report.c:83
void BKE_scene_graph_update_tagged(struct Depsgraph *depsgraph, struct Main *bmain)
Definition: scene.cc:2648
General operations for speakers.
Volume data-block.
#define BLI_assert(a)
Definition: BLI_assert.h:46
#define BLI_assert_msg(a, msg)
Definition: BLI_assert.h:53
struct GSet GSet
Definition: BLI_ghash.h:340
bool BLI_gset_haskey(const GSet *gs, const void *key) ATTR_WARN_UNUSED_RESULT
Definition: BLI_ghash.c:1007
GSet * BLI_gset_new(GSetHashFP hashfp, GSetCmpFP cmpfp, const char *info) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT
Definition: BLI_ghash.c:947
bool BLI_ghashutil_intcmp(const void *a, const void *b)
unsigned int BLI_ghashutil_inthash_p(const void *ptr)
void BLI_gset_free(GSet *gs, GSetKeyFreeFP keyfreefp)
Definition: BLI_ghash.c:1037
bool BLI_gset_add(GSet *gs, void *key)
Definition: BLI_ghash.c:969
A KD-tree for nearest neighbor search.
void BLI_kdtree_nd_() free(KDTree *tree)
Definition: kdtree_impl.h:102
void BLI_addhead(struct ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition: listbase.c:60
#define LISTBASE_FOREACH(type, var, list)
Definition: BLI_listbase.h:336
#define LISTBASE_FOREACH_MUTABLE(type, var, list)
Definition: BLI_listbase.h:354
void * BLI_listbase_bytes_find(const ListBase *listbase, const void *bytes, size_t bytes_size, int offset) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1
void BLI_remlink(struct ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition: listbase.c:100
void * BLI_findlink(const struct ListBase *listbase, int number) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
MINLINE int max_ii(int a, int b)
MINLINE int min_iii(int a, int b, int c)
void unit_m4(float m[4][4])
Definition: rct.c:1090
bool invert_m4_m4(float R[4][4], const float A[4][4])
Definition: math_matrix.c:1287
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 size_t char * BLI_sprintfN(const char *__restrict format,...) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1) ATTR_MALLOC ATTR_PRINTF_FORMAT(1
char * BLI_strdup(const char *str) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL() ATTR_MALLOC
Definition: string.c:42
char * BLI_strncpy(char *__restrict dst, const char *__restrict src, size_t maxncpy) ATTR_NONNULL()
Definition: string.c:64
unsigned int uint
Definition: BLI_sys_types.h:67
unsigned short ushort
Definition: BLI_sys_types.h:68
#define UNUSED_VARS(...)
#define UNUSED(x)
#define UNPACK3(a)
#define ELEM(...)
#define POINTER_FROM_UINT(i)
#define STREQ(a, b)
#define TIP_(msgid)
#define IFACE_(msgid)
struct Depsgraph Depsgraph
Definition: DEG_depsgraph.h:35
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:621
@ ID_RECALC_TRANSFORM
Definition: DNA_ID.h:771
@ ID_RECALC_COPY_ON_WRITE
Definition: DNA_ID.h:834
@ ID_RECALC_SELECT
Definition: DNA_ID.h:818
@ ID_RECALC_ANIMATION
Definition: DNA_ID.h:794
@ ID_RECALC_GEOMETRY
Definition: DNA_ID.h:791
@ ID_RECALC_BASE_FLAGS
Definition: DNA_ID.h:821
#define ID_IS_OVERRIDE_LIBRARY_REAL(_id)
Definition: DNA_ID.h:581
#define ID_IS_OVERRIDABLE_LIBRARY(_id)
Definition: DNA_ID.h:574
#define ID_IS_LINKED(_id)
Definition: DNA_ID.h:566
@ LIB_TAG_INDIRECT
Definition: DNA_ID.h:677
@ LIB_TAG_PRE_EXISTING
Definition: DNA_ID.h:709
@ LIB_TAG_DOIT
Definition: DNA_ID.h:707
#define ID_IS_OVERRIDE_LIBRARY(_id)
Definition: DNA_ID.h:588
#define ID_NEW_SET(_id, _idn)
Definition: DNA_ID.h:617
@ IDOVERRIDE_LIBRARY_FLAG_SYSTEM_DEFINED
Definition: DNA_ID.h:327
@ ID_IM
Definition: DNA_ID_enums.h:53
@ ID_MA
Definition: DNA_ID_enums.h:51
@ ID_GR
Definition: DNA_ID_enums.h:65
@ ID_OB
Definition: DNA_ID_enums.h:47
@ 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_SPEAKER
@ OB_LATTICE
@ OB_MBALL
@ OB_EMPTY
@ OB_SURF
@ OB_CAMERA
@ OB_FONT
@ OB_ARMATURE
@ OB_LAMP
@ OB_MESH
@ OB_POINTCLOUD
@ OB_VOLUME
@ OB_CURVES_LEGACY
@ OB_CURVES
@ OB_GPENCIL
@ OB_LIGHTPROBE
#define OB_TYPE_SUPPORT_MATERIAL(_type)
@ OB_DUPLICOLLECTION
@ PARVERT1
@ PARSKEL
@ PAROBJECT
@ PARTYPE
@ PARVERT3
@ PARBONE
#define FIRSTBASE(_view_layer)
#define BASACT(_view_layer)
#define OBACT(_view_layer)
@ USER_DUP_LINKED_ID
@ USER_DUP_ACT
@ OPERATOR_CANCELLED
@ OPERATOR_INTERFACE
@ OPERATOR_FINISHED
@ RPT_ERROR_INVALID_INPUT
#define ARM_GROUPS_ENVELOPE
Definition: ED_armature.h:199
#define ARM_GROUPS_NAME
Definition: ED_armature.h:198
#define ARM_GROUPS_AUTO
Definition: ED_armature.h:200
#define GP_PAR_ARMATURE_NAME
Definition: ED_gpencil.h:366
#define GP_PAR_ARMATURE_AUTO
Definition: ED_gpencil.h:367
void EDBM_mesh_load(struct Main *bmain, struct Object *ob)
void EDBM_mesh_make(struct Object *ob, int select_mode, bool add_key_index)
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:160
@ CLEAR_PARENT_KEEP_TRANSFORM
Definition: ED_object.h:161
@ CLEAR_PARENT_INVERSE
Definition: ED_object.h:162
void ED_object_shaderfx_link(struct Object *dst, struct Object *src)
@ PAR_OBJECT
Definition: ED_object.h:138
@ PAR_BONE
Definition: ED_object.h:143
@ PAR_BONE_RELATIVE
Definition: ED_object.h:144
@ PAR_ARMATURE_ENVELOPE
Definition: ED_object.h:141
@ PAR_CURVE
Definition: ED_object.h:145
@ PAR_ARMATURE_AUTO
Definition: ED_object.h:142
@ PAR_VERTEX
Definition: ED_object.h:149
@ PAR_LATTICE
Definition: ED_object.h:148
@ PAR_VERTEX_TRI
Definition: ED_object.h:150
@ PAR_ARMATURE_NAME
Definition: ED_object.h:140
@ PAR_ARMATURE
Definition: ED_object.h:139
@ PAR_FOLLOW
Definition: ED_object.h:146
@ PAR_PATH_CONST
Definition: ED_object.h:147
void ED_object_base_select(struct Base *base, eObjectSelect_Mode mode)
Definition: object_select.c:76
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.cc:2190
@ BA_SELECT
Definition: ED_object.h:155
bool ED_operator_editsurfcurve(struct bContext *C)
Definition: screen_ops.c:587
bool ED_operator_object_active_editable(struct bContext *C)
Definition: screen_ops.c:396
bool ED_operator_editlattice(struct bContext *C)
Definition: screen_ops.c:644
bool ED_operator_editmesh(struct bContext *C)
Definition: screen_ops.c:433
bool ED_operator_objectmode(struct bContext *C)
Definition: screen_ops.c:186
bool ED_operator_objectmode_poll_msg(struct bContext *C)
Definition: screen_ops.c:206
bool ED_operator_object_active(struct bContext *C)
Definition: screen_ops.c:370
struct Object * ED_view3d_give_material_slot_under_cursor(struct bContext *C, const int mval[2], int *r_material_slot)
_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.
Group Output data from inside of a node group A color picker Mix two input colors RGB to Convert a color s luminance to a grayscale value Generate a normal vector and a dot product Bright Control the brightness and contrast of the input color Vector Map an input vectors to curves
const EnumPropertyItem * RNA_scene_local_itemf(struct bContext *C, struct PointerRNA *ptr, struct PropertyRNA *prop, bool *r_free)
#define RNA_ENUM_ITEM_SEPR
Definition: RNA_types.h:483
@ PROP_ENUM_NO_TRANSLATE
Definition: RNA_types.h:294
@ PROP_SKIP_SAVE
Definition: RNA_types.h:218
@ PROP_HIDDEN
Definition: RNA_types.h:216
#define C
Definition: RandGen.cpp:25
void uiItemBooleanO(uiLayout *layout, const char *name, int icon, const char *opname, const char *propname, int value)
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, wmOperatorCallContext 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()
@ OPTYPE_INTERNAL
Definition: WM_types.h:168
@ OPTYPE_UNDO
Definition: WM_types.h:148
@ OPTYPE_REGISTER
Definition: WM_types.h:146
#define NC_WINDOW
Definition: WM_types.h:325
#define ND_NLA_ACTCHANGE
Definition: WM_types.h:446
#define ND_DRAW
Definition: WM_types.h:410
#define NC_WM
Definition: WM_types.h:324
#define NC_ANIMATION
Definition: WM_types.h:338
#define ND_LIB_OVERRIDE_CHANGED
Definition: WM_types.h:367
#define ND_PARENT
Definition: WM_types.h:416
#define NC_MATERIAL
Definition: WM_types.h:330
#define ND_TRANSFORM
Definition: WM_types.h:405
@ WM_OP_EXEC_DEFAULT
Definition: WM_types.h:208
#define ND_OB_SHADING
Definition: WM_types.h:406
#define ND_SPACE_VIEW3D
Definition: WM_types.h:471
#define NC_OBJECT
Definition: WM_types.h:329
#define ND_SHADING_LINKS
Definition: WM_types.h:427
#define NC_SPACE
Definition: WM_types.h:342
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:12
#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:74
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:225
bAction * ED_id_action_ensure(Main *bmain, ID *id)
Definition: keyframing.c:123
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:173
void(* MEM_freeN)(void *vmemh)
Definition: mallocn.c:27
void *(* MEM_mallocN)(size_t len, const char *str)
Definition: mallocn.c:33
#define G(x, y, z)
static unsigned a[3]
Definition: RandGen.cpp:78
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)
void OBJECT_OT_clear_override_library(wmOperatorType *ot)
static bool parent_set_vertex_parent(bContext *C, struct ParentingContext *parenting_context)
static int object_track_clear_exec(bContext *C, wmOperator *op)
static void make_local_material_tag(Material *ma)
static int track_set_exec(bContext *C, wmOperator *op)
static int parent_set_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
static void single_objectdata_action_users(Main *bmain, Scene *scene, ViewLayer *view_layer, View3D *v3d, const int flag)
void ED_object_single_obdata_user(Main *bmain, Scene *scene, Object *ob)
static int make_links_scene_exec(bContext *C, wmOperator *op)
static bool reset_clear_override_library_poll(bContext *C)
void OBJECT_OT_parent_clear(wmOperatorType *ot)
static const EnumPropertyItem prop_make_track_types[]
void OBJECT_OT_reset_override_library(wmOperatorType *ot)
static int clear_override_library_exec(bContext *C, wmOperator *UNUSED(op))
static void make_local_animdata_tag(AnimData *adt)
void ED_object_parent_clear(Object *ob, const int type)
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)
void OBJECT_OT_track_set(wmOperatorType *ot)
static int object_unlink_data_exec(bContext *C, wmOperator *op)
void OBJECT_OT_track_clear(wmOperatorType *ot)
static int make_override_library_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
@ MAKE_SINGLE_USER_SELECTED
@ MAKE_SINGLE_USER_ALL
void OBJECT_OT_unlink_data(wmOperatorType *ot)
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)
@ MAKE_LINKS_MODIFIERS
@ MAKE_LINKS_ANIMDATA
@ MAKE_LINKS_DUPLICOLLECTION
@ MAKE_LINKS_MATERIALS
@ MAKE_LINKS_SHADERFX
@ MAKE_LINKS_OBDATA
@ MAKE_LINKS_FONTS
@ MAKE_LINKS_GROUP
char * ED_object_ot_drop_named_material_tooltip(bContext *C, const char *name, const int mval[2])
static int reset_override_library_exec(bContext *C, wmOperator *UNUSED(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)
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)
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])
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 int parent_set_exec(bContext *C, wmOperator *op)
static bool parent_set_poll_property(const bContext *UNUSED(C), wmOperator *op, const PropertyRNA *prop)
@ CLEAR_TRACK
@ CLEAR_TRACK_KEEP_TRANSFORM
void OBJECT_OT_make_local(wmOperatorType *ot)
@ CREATE_TRACK_DAMPTRACK
@ CREATE_TRACK_LOCKTRACK
@ CREATE_TRACK_TRACKTO
static int parent_noinv_set_exec(bContext *C, wmOperator *op)
static void libblock_relink_collection(Main *bmain, Collection *collection, const bool do_collection)
static bool allow_make_links_data(const int type, Object *ob_src, Object *ob_dst)
@ MAKE_LOCAL_SELECT_OBDATA_MATERIAL
@ MAKE_LOCAL_SELECT_OBDATA
@ MAKE_LOCAL_SELECT_OB
@ MAKE_LOCAL_ALL
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[]
static bool single_data_needs_duplication(ID *id)
void RNA_property_int_set(PointerRNA *ptr, PropertyRNA *prop, int value)
Definition: rna_access.c:2449
const char * RNA_property_identifier(const PropertyRNA *prop)
Definition: rna_access.c:1000
void RNA_boolean_set(PointerRNA *ptr, const char *name, bool value)
Definition: rna_access.c:4874
bool RNA_property_is_set(PointerRNA *ptr, PropertyRNA *prop)
Definition: rna_access.c:5271
void RNA_property_update(bContext *C, PointerRNA *ptr, PropertyRNA *prop)
Definition: rna_access.c:2138
int RNA_property_int_get(PointerRNA *ptr, PropertyRNA *prop)
Definition: rna_access.c:2429
bool RNA_boolean_get(PointerRNA *ptr, const char *name)
Definition: rna_access.c:4863
void RNA_enum_set(PointerRNA *ptr, const char *name, int value)
Definition: rna_access.c:5015
int RNA_enum_get(PointerRNA *ptr, const char *name)
Definition: rna_access.c:5004
PropertyRNA * RNA_def_boolean(StructOrFunctionRNA *cont_, const char *identifier, bool default_value, const char *ui_name, const char *ui_description)
Definition: rna_define.c:3493
void RNA_def_property_flag(PropertyRNA *prop, PropertyFlag flag)
Definition: rna_define.c:1490
PropertyRNA * RNA_def_int(StructOrFunctionRNA *cont_, const char *identifier, int default_value, int hardmin, int hardmax, const char *ui_name, const char *ui_description, int softmin, int softmax)
Definition: rna_define.c:3597
void RNA_def_enum_funcs(PropertyRNA *prop, EnumPropertyItemFunc itemfunc)
Definition: rna_define.c:3830
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:3783
const EnumPropertyItem DummyRNA_NULL_items[]
Definition: rna_rna.c:26
bAction * action
bAction * tmpact
ListBase nla_tracks
struct BMesh * bm
Definition: BKE_editmesh.h:40
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:42
struct Object * object
struct Object * bevobj
struct VFont * vfont
struct VFont * vfontb
struct VFont * vfonti
struct VFont * vfontbi
struct Object * taperobj
struct Lattice * latt
FPoint * fpt
BezTriple * bezt
ListBase modifiers
unsigned int flag
Definition: DNA_ID.h:312
struct ID * hierarchy_root
Definition: DNA_ID.h:303
struct ID * reference
Definition: DNA_ID.h:294
Definition: DNA_ID.h:368
int tag
Definition: DNA_ID.h:387
struct Library * lib
Definition: DNA_ID.h:372
int us
Definition: DNA_ID.h:388
struct ID * newid
Definition: DNA_ID.h:370
IDOverrideLibrary * override_library
Definition: DNA_ID.h:412
unsigned int session_uuid
Definition: DNA_ID.h:407
void * next
Definition: DNA_ID.h:369
char name[66]
Definition: DNA_ID.h:378
struct Object * object
struct EditLatt * editlatt
struct BPoint * def
void * link
Definition: BLI_linklist.h:24
struct LinkNode * next
Definition: BLI_linklist.h:23
void * last
Definition: DNA_listBase.h:31
void * first
Definition: DNA_listBase.h:31
Definition: BKE_main.h:121
ListBase scenes
Definition: BKE_main.h:168
ListBase meshes
Definition: BKE_main.h:171
ListBase collections
Definition: BKE_main.h:189
ListBase objects
Definition: BKE_main.h:170
struct BMEditMesh * edit_mesh
struct Mesh * texcomesh
struct ModifierData * next
struct NlaStrip * next
ListBase strips
bAction * act
struct CurveCache * curve_cache
short partype
struct Collection * instance_collection
ListBase modifiers
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:36
struct PropertyRNA * prop
Definition: RNA_types.h:43
PointerRNA ptr
Definition: RNA_types.h:42
struct Collection * master_collection
struct ToolSettings * toolsettings
struct RenderData r
struct Object * camera
struct Base * basact
struct bConstraint * prev
struct Bone * bone
int mval[2]
Definition: WM_types.h:684
int(* invoke)(struct bContext *, struct wmOperator *, const struct wmEvent *) ATTR_WARN_UNUSED_RESULT
Definition: WM_types.h:919
const char * name
Definition: WM_types.h:888
const char * idname
Definition: WM_types.h:890
bool(* poll)(struct bContext *) ATTR_WARN_UNUSED_RESULT
Definition: WM_types.h:943
bool(* poll_property)(const struct bContext *C, struct wmOperator *op, const PropertyRNA *prop) ATTR_WARN_UNUSED_RESULT
Definition: WM_types.h:949
struct StructRNA * srna
Definition: WM_types.h:969
const char * description
Definition: WM_types.h:893
int(* exec)(struct bContext *, struct wmOperator *) ATTR_WARN_UNUSED_RESULT
Definition: WM_types.h:903
PropertyRNA * prop
Definition: WM_types.h:981
struct ReportList * reports
struct wmOperatorType * type
struct PointerRNA * ptr
void WM_cursor_wait(bool val)
Definition: wm_cursors.c:209
void WM_event_add_notifier(const bContext *C, uint type, void *reference)
wmOperatorType * ot
Definition: wm_files.c:3479
ID * WM_operator_properties_id_lookup_from_name_or_session_uuid(Main *bmain, PointerRNA *ptr, const ID_Type type)
void WM_operator_properties_id_lookup(wmOperatorType *ot, const bool add_name_prop)
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))
int WM_enum_search_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))