Blender  V3.3
object_add.cc
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 <cctype>
9 #include <cstdlib>
10 #include <cstring>
11 #include <optional>
12 
13 #include "MEM_guardedalloc.h"
14 
15 #include "DNA_anim_types.h"
16 #include "DNA_camera_types.h"
17 #include "DNA_collection_types.h"
18 #include "DNA_curve_types.h"
20 #include "DNA_gpencil_types.h"
21 #include "DNA_key_types.h"
22 #include "DNA_light_types.h"
23 #include "DNA_lightprobe_types.h"
24 #include "DNA_material_types.h"
25 #include "DNA_mesh_types.h"
26 #include "DNA_meta_types.h"
27 #include "DNA_modifier_types.h"
29 #include "DNA_object_force_types.h"
30 #include "DNA_object_types.h"
31 #include "DNA_pointcloud_types.h"
32 #include "DNA_scene_types.h"
33 #include "DNA_vfont_types.h"
34 
35 #include "BLI_ghash.h"
36 #include "BLI_listbase.h"
37 #include "BLI_math.h"
38 #include "BLI_string.h"
39 #include "BLI_utildefines.h"
40 #include "BLI_vector.hh"
41 
42 #include "BLT_translation.h"
43 
44 #include "BKE_action.h"
45 #include "BKE_anim_data.h"
46 #include "BKE_armature.h"
47 #include "BKE_camera.h"
48 #include "BKE_collection.h"
49 #include "BKE_constraint.h"
50 #include "BKE_context.h"
51 #include "BKE_curve.h"
52 #include "BKE_curves.h"
53 #include "BKE_displist.h"
54 #include "BKE_duplilist.h"
55 #include "BKE_effect.h"
56 #include "BKE_geometry_set.h"
57 #include "BKE_geometry_set.hh"
58 #include "BKE_gpencil_curve.h"
59 #include "BKE_gpencil_geom.h"
60 #include "BKE_gpencil_modifier.h"
61 #include "BKE_key.h"
62 #include "BKE_lattice.h"
63 #include "BKE_layer.h"
64 #include "BKE_lib_id.h"
65 #include "BKE_lib_override.h"
66 #include "BKE_lib_query.h"
67 #include "BKE_lib_remap.h"
68 #include "BKE_light.h"
69 #include "BKE_lightprobe.h"
70 #include "BKE_main.h"
71 #include "BKE_material.h"
72 #include "BKE_mball.h"
73 #include "BKE_mesh.h"
74 #include "BKE_mesh_runtime.h"
75 #include "BKE_nla.h"
76 #include "BKE_node.h"
77 #include "BKE_object.h"
78 #include "BKE_particle.h"
79 #include "BKE_pointcloud.h"
80 #include "BKE_report.h"
81 #include "BKE_scene.h"
82 #include "BKE_speaker.h"
83 #include "BKE_vfont.h"
84 #include "BKE_volume.h"
85 
86 #include "DEG_depsgraph.h"
87 #include "DEG_depsgraph_build.h"
88 #include "DEG_depsgraph_query.h"
89 
90 #include "RNA_access.h"
91 #include "RNA_define.h"
92 #include "RNA_enum_types.h"
93 
94 #include "UI_interface.h"
95 
96 #include "WM_api.h"
97 #include "WM_types.h"
98 
99 #include "ED_armature.h"
100 #include "ED_curve.h"
101 #include "ED_curves.h"
102 #include "ED_gpencil.h"
103 #include "ED_mball.h"
104 #include "ED_mesh.h"
105 #include "ED_node.h"
106 #include "ED_object.h"
107 #include "ED_outliner.h"
108 #include "ED_physics.h"
109 #include "ED_render.h"
110 #include "ED_screen.h"
111 #include "ED_select_utils.h"
112 #include "ED_transform.h"
113 #include "ED_view3d.h"
114 
115 #include "UI_resources.h"
116 
117 #include "object_intern.h"
118 
119 using blender::float3;
120 using blender::float4x4;
121 using blender::Vector;
122 
123 /* -------------------------------------------------------------------- */
127 /* This is an exact copy of the define in `rna_light.c`
128  * kept here because of linking order.
129  * Icons are only defined here */
131  {LA_LOCAL, "POINT", ICON_LIGHT_POINT, "Point", "Omnidirectional point light source"},
132  {LA_SUN, "SUN", ICON_LIGHT_SUN, "Sun", "Constant direction parallel ray light source"},
133  {LA_SPOT, "SPOT", ICON_LIGHT_SPOT, "Spot", "Directional cone light source"},
134  {LA_AREA, "AREA", ICON_LIGHT_AREA, "Area", "Directional area light source"},
135  {0, nullptr, 0, nullptr, nullptr},
136 };
137 
138 /* copy from rna_object_force.c */
140  {PFIELD_FORCE, "FORCE", ICON_FORCE_FORCE, "Force", ""},
141  {PFIELD_WIND, "WIND", ICON_FORCE_WIND, "Wind", ""},
142  {PFIELD_VORTEX, "VORTEX", ICON_FORCE_VORTEX, "Vortex", ""},
143  {PFIELD_MAGNET, "MAGNET", ICON_FORCE_MAGNETIC, "Magnetic", ""},
144  {PFIELD_HARMONIC, "HARMONIC", ICON_FORCE_HARMONIC, "Harmonic", ""},
145  {PFIELD_CHARGE, "CHARGE", ICON_FORCE_CHARGE, "Charge", ""},
146  {PFIELD_LENNARDJ, "LENNARDJ", ICON_FORCE_LENNARDJONES, "Lennard-Jones", ""},
147  {PFIELD_TEXTURE, "TEXTURE", ICON_FORCE_TEXTURE, "Texture", ""},
148  {PFIELD_GUIDE, "GUIDE", ICON_FORCE_CURVE, "Curve Guide", ""},
149  {PFIELD_BOID, "BOID", ICON_FORCE_BOID, "Boid", ""},
150  {PFIELD_TURBULENCE, "TURBULENCE", ICON_FORCE_TURBULENCE, "Turbulence", ""},
151  {PFIELD_DRAG, "DRAG", ICON_FORCE_DRAG, "Drag", ""},
152  {PFIELD_FLUIDFLOW, "FLUID", ICON_FORCE_FLUIDFLOW, "Fluid Flow", ""},
153  {0, nullptr, 0, nullptr, nullptr},
154 };
155 
158  "CUBEMAP",
159  ICON_LIGHTPROBE_CUBEMAP,
160  "Reflection Cubemap",
161  "Reflection probe with spherical or cubic attenuation"},
163  "PLANAR",
164  ICON_LIGHTPROBE_PLANAR,
165  "Reflection Plane",
166  "Planar reflection probe"},
168  "GRID",
169  ICON_LIGHTPROBE_GRID,
170  "Irradiance Volume",
171  "Irradiance probe to capture diffuse indirect lighting"},
172  {0, nullptr, 0, nullptr, nullptr},
173 };
174 
175 enum {
179 };
180 
181 static const EnumPropertyItem align_options[] = {
182  {ALIGN_WORLD, "WORLD", 0, "World", "Align the new object to the world"},
183  {ALIGN_VIEW, "VIEW", 0, "View", "Align the new object to the view"},
184  {ALIGN_CURSOR, "CURSOR", 0, "3D Cursor", "Use the 3D cursor orientation for the new object"},
185  {0, nullptr, 0, nullptr, nullptr},
186 };
187 
190 /* -------------------------------------------------------------------- */
199 {
200  PropertyRNA *prop;
201 
202  prop = RNA_def_int(ot->srna,
203  "drop_x",
204  0,
205  INT_MIN,
206  INT_MAX,
207  "Drop X",
208  "X-coordinate (screen space) to place the new object under",
209  INT_MIN,
210  INT_MAX);
212  prop = RNA_def_int(ot->srna,
213  "drop_y",
214  0,
215  INT_MIN,
216  INT_MAX,
217  "Drop Y",
218  "Y-coordinate (screen space) to place the new object under",
219  INT_MIN,
220  INT_MAX);
222 }
223 
224 static bool object_add_drop_xy_is_set(const wmOperator *op)
225 {
226  return RNA_struct_property_is_set(op->ptr, "drop_x") &&
227  RNA_struct_property_is_set(op->ptr, "drop_y");
228 }
229 
234 static bool object_add_drop_xy_get(bContext *C, wmOperator *op, int (*r_mval)[2])
235 {
236  if (!object_add_drop_xy_is_set(op)) {
237  (*r_mval)[0] = 0.0f;
238  (*r_mval)[1] = 0.0f;
239  return false;
240  }
241 
242  const ARegion *region = CTX_wm_region(C);
243  (*r_mval)[0] = RNA_int_get(op->ptr, "drop_x") - region->winrct.xmin;
244  (*r_mval)[1] = RNA_int_get(op->ptr, "drop_y") - region->winrct.ymin;
245 
246  return true;
247 }
248 
254 {
255  if (!object_add_drop_xy_is_set(op)) {
256  RNA_int_set(op->ptr, "drop_x", event->xy[0]);
257  RNA_int_set(op->ptr, "drop_y", event->xy[1]);
258  }
259  return op->type->exec(C, op);
260 }
261 
264 /* -------------------------------------------------------------------- */
269 {
270  const Scene *scene = CTX_data_scene(C);
272 }
273 
274 void ED_object_rotation_from_quat(float rot[3], const float viewquat[4], const char align_axis)
275 {
276  BLI_assert(align_axis >= 'X' && align_axis <= 'Z');
277 
278  switch (align_axis) {
279  case 'X': {
280  /* Same as 'rv3d->viewinv[1]' */
281  const float axis_y[4] = {0.0f, 1.0f, 0.0f};
282  float quat_y[4], quat[4];
283  axis_angle_to_quat(quat_y, axis_y, M_PI_2);
284  mul_qt_qtqt(quat, viewquat, quat_y);
285  quat_to_eul(rot, quat);
286  break;
287  }
288  case 'Y': {
289  quat_to_eul(rot, viewquat);
290  rot[0] -= (float)M_PI_2;
291  break;
292  }
293  case 'Z': {
294  quat_to_eul(rot, viewquat);
295  break;
296  }
297  }
298 }
299 
300 void ED_object_rotation_from_view(bContext *C, float rot[3], const char align_axis)
301 {
303  BLI_assert(align_axis >= 'X' && align_axis <= 'Z');
304  if (rv3d) {
305  float viewquat[4];
306  copy_qt_qt(viewquat, rv3d->viewquat);
307  viewquat[0] *= -1.0f;
308  ED_object_rotation_from_quat(rot, viewquat, align_axis);
309  }
310  else {
311  zero_v3(rot);
312  }
313 }
314 
315 void ED_object_base_init_transform_on_add(Object *object, const float loc[3], const float rot[3])
316 {
317  if (loc) {
318  copy_v3_v3(object->loc, loc);
319  }
320 
321  if (rot) {
322  copy_v3_v3(object->rot, rot);
323  }
324 
325  BKE_object_to_mat4(object, object->obmat);
326 }
327 
329  Object *obedit,
330  const float loc[3],
331  const float rot[3],
332  const float scale[3],
333  float r_primmat[4][4])
334 {
336  View3D *v3d = CTX_wm_view3d(C);
337  float mat[3][3], rmat[3][3], cmat[3][3], imat[3][3];
338 
339  unit_m4(r_primmat);
340 
341  eul_to_mat3(rmat, rot);
342  invert_m3(rmat);
343 
344  /* inverse transform for initial rotation and object */
345  copy_m3_m4(mat, obedit->obmat);
346  mul_m3_m3m3(cmat, rmat, mat);
347  invert_m3_m3(imat, cmat);
348  copy_m4_m3(r_primmat, imat);
349 
350  /* center */
351  copy_v3_v3(r_primmat[3], loc);
352  sub_v3_v3v3(r_primmat[3], r_primmat[3], obedit->obmat[3]);
353  invert_m3_m3(imat, mat);
354  mul_m3_v3(imat, r_primmat[3]);
355 
356  if (scale != nullptr) {
357  rescale_m4(r_primmat, scale);
358  }
359 
360  {
361  const float dia = v3d ? ED_view3d_grid_scale(scene, v3d, nullptr) :
362  ED_scene_grid_scale(scene, nullptr);
363  return dia;
364  }
365 
366  /* return 1.0f; */
367 }
368 
371 /* -------------------------------------------------------------------- */
375 static void view_align_update(struct Main *UNUSED(main),
376  struct Scene *UNUSED(scene),
377  struct PointerRNA *ptr)
378 {
379  RNA_struct_idprops_unset(ptr, "rotation");
380 }
381 
383 {
385  ot->srna, "size", 2.0f, 0.0, OBJECT_ADD_SIZE_MAXF, "Size", "", 0.001, 100.00);
386 }
387 
389 {
391  ot->srna, "radius", default_value, 0.0, OBJECT_ADD_SIZE_MAXF, "Radius", "", 0.001, 100.00);
392 }
393 
395 {
397 }
398 
400 {
401  PropertyRNA *prop;
402 
403  if (do_editmode) {
404  prop = RNA_def_boolean(ot->srna,
405  "enter_editmode",
406  false,
407  "Enter Edit Mode",
408  "Enter edit mode when adding this object");
410  }
411  /* NOTE: this property gets hidden for add-camera operator. */
412  prop = RNA_def_enum(
413  ot->srna, "align", align_options, ALIGN_WORLD, "Align", "The alignment of the new object");
415 
417  "location",
418  3,
419  nullptr,
422  "Location",
423  "Location for the newly added object",
424  -1000.0f,
425  1000.0f);
428  "rotation",
429  3,
430  nullptr,
433  "Rotation",
434  "Rotation for the newly added object",
435  DEG2RADF(-360.0f),
436  DEG2RADF(360.0f));
438 
440  "scale",
441  3,
442  nullptr,
445  "Scale",
446  "Scale for the newly added object",
447  -1000.0f,
448  1000.0f);
450 }
451 
453 {
454  RNA_def_boolean(ot->srna, "calc_uvs", true, "Generate UVs", "Generate a default UV map");
455 }
456 
458  wmOperator *op,
459  const char view_align_axis,
460  float r_loc[3],
461  float r_rot[3],
462  float r_scale[3],
463  bool *r_enter_editmode,
464  ushort *r_local_view_bits,
465  bool *r_is_view_aligned)
466 {
467  /* Edit Mode! (optional) */
468  {
469  bool _enter_editmode;
470  if (!r_enter_editmode) {
471  r_enter_editmode = &_enter_editmode;
472  }
473  /* Only to ensure the value is _always_ set.
474  * Typically the property will exist when the argument is non-nullptr. */
475  *r_enter_editmode = false;
476 
477  PropertyRNA *prop = RNA_struct_find_property(op->ptr, "enter_editmode");
478  if (prop != nullptr) {
479  if (RNA_property_is_set(op->ptr, prop) && r_enter_editmode) {
480  *r_enter_editmode = RNA_property_boolean_get(op->ptr, prop);
481  }
482  else {
483  *r_enter_editmode = (U.flag & USER_ADD_EDITMODE) != 0;
484  RNA_property_boolean_set(op->ptr, prop, *r_enter_editmode);
485  }
486  }
487  }
488 
489  if (r_local_view_bits) {
490  View3D *v3d = CTX_wm_view3d(C);
491  *r_local_view_bits = (v3d && v3d->localvd) ? v3d->local_view_uuid : 0;
492  }
493 
494  /* Location! */
495  {
496  float _loc[3];
497  if (!r_loc) {
498  r_loc = _loc;
499  }
500 
501  if (RNA_struct_property_is_set(op->ptr, "location")) {
502  RNA_float_get_array(op->ptr, "location", r_loc);
503  }
504  else {
506  RNA_float_set_array(op->ptr, "location", r_loc);
507  }
508  }
509 
510  /* Rotation! */
511  {
512  bool _is_view_aligned;
513  float _rot[3];
514  if (!r_is_view_aligned) {
515  r_is_view_aligned = &_is_view_aligned;
516  }
517  if (!r_rot) {
518  r_rot = _rot;
519  }
520 
521  if (RNA_struct_property_is_set(op->ptr, "rotation")) {
522  /* If rotation is set, always use it. Alignment (and corresponding user preference)
523  * can be ignored since this is in world space anyways.
524  * To not confuse (e.g. on redo), don't set it to #ALIGN_WORLD in the op UI though. */
525  *r_is_view_aligned = false;
526  RNA_float_get_array(op->ptr, "rotation", r_rot);
527  }
528  else {
529  int alignment = ALIGN_WORLD;
530  PropertyRNA *prop = RNA_struct_find_property(op->ptr, "align");
531 
532  if (RNA_property_is_set(op->ptr, prop)) {
533  /* If alignment is set, always use it. */
534  *r_is_view_aligned = alignment == ALIGN_VIEW;
535  alignment = RNA_property_enum_get(op->ptr, prop);
536  }
537  else {
538  /* If alignment is not set, use User Preferences. */
539  *r_is_view_aligned = (U.flag & USER_ADD_VIEWALIGNED) != 0;
540  if (*r_is_view_aligned) {
542  alignment = ALIGN_VIEW;
543  }
544  else if ((U.flag & USER_ADD_CURSORALIGNED) != 0) {
546  alignment = ALIGN_CURSOR;
547  }
548  else {
550  alignment = ALIGN_WORLD;
551  }
552  }
553  switch (alignment) {
554  case ALIGN_WORLD:
555  RNA_float_get_array(op->ptr, "rotation", r_rot);
556  break;
557  case ALIGN_VIEW:
558  ED_object_rotation_from_view(C, r_rot, view_align_axis);
559  RNA_float_set_array(op->ptr, "rotation", r_rot);
560  break;
561  case ALIGN_CURSOR: {
562  const Scene *scene = CTX_data_scene(C);
563  float tmat[3][3];
565  mat3_normalized_to_eul(r_rot, tmat);
566  RNA_float_set_array(op->ptr, "rotation", r_rot);
567  break;
568  }
569  }
570  }
571  }
572 
573  /* Scale! */
574  {
575  float _scale[3];
576  if (!r_scale) {
577  r_scale = _scale;
578  }
579 
580  /* For now this is optional, we can make it always use. */
581  copy_v3_fl(r_scale, 1.0f);
582 
583  PropertyRNA *prop = RNA_struct_find_property(op->ptr, "scale");
584  if (prop != nullptr) {
585  if (RNA_property_is_set(op->ptr, prop)) {
586  RNA_property_float_get_array(op->ptr, prop, r_scale);
587  }
588  else {
589  copy_v3_fl(r_scale, 1.0f);
590  RNA_property_float_set_array(op->ptr, prop, r_scale);
591  }
592  }
593  }
594 
595  return true;
596 }
597 
599  const int type,
600  const char *name,
601  const float loc[3],
602  const float rot[3],
603  const bool enter_editmode,
604  const ushort local_view_bits,
605  ID *obdata)
606 {
607  Main *bmain = CTX_data_main(C);
609  ViewLayer *view_layer = CTX_data_view_layer(C);
610 
611  {
612  Object *obedit = OBEDIT_FROM_VIEW_LAYER(view_layer);
613  if (obedit != nullptr) {
615  }
616  }
617 
618  /* deselects all, sets active object */
619  Object *ob;
620  if (obdata != nullptr) {
622  ob = BKE_object_add_for_data(bmain, view_layer, type, name, obdata, true);
623  const short *materials_len_p = BKE_id_material_len_p(obdata);
624  if (materials_len_p && *materials_len_p > 0) {
625  BKE_object_materials_test(bmain, ob, static_cast<ID *>(ob->data));
626  }
627  }
628  else {
629  ob = BKE_object_add(bmain, view_layer, type, name);
630  }
631 
632  Base *ob_base_act = BASACT(view_layer);
633  /* While not getting a valid base is not a good thing, it can happen in convoluted corner cases,
634  * better not crash on it in releases. */
635  BLI_assert(ob_base_act != nullptr);
636  if (ob_base_act != nullptr) {
637  ob_base_act->local_view_bits = local_view_bits;
638  /* editor level activate, notifiers */
639  ED_object_base_activate(C, ob_base_act);
640  }
641 
642  /* more editor stuff */
644 
645  /* TODO(sergey): This is weird to manually tag objects for update, better to
646  * use DEG_id_tag_update here perhaps.
647  */
648  DEG_id_type_tag(bmain, ID_OB);
650  if (ob->data != nullptr) {
652  }
653 
654  if (enter_editmode) {
655  ED_object_editmode_enter_ex(bmain, scene, ob, 0);
656  }
657 
659 
660  /* TODO(sergey): Use proper flag for tagging here. */
661  DEG_id_tag_update(&scene->id, 0);
662 
664 
665  return ob;
666 }
667 
669  const int type,
670  const char *name,
671  const float loc[3],
672  const float rot[3],
673  const bool enter_editmode,
674  const ushort local_view_bits)
675 {
677  C, type, name, loc, rot, enter_editmode, local_view_bits, nullptr);
678 }
679 
680 /* for object add operator */
682 {
683  ushort local_view_bits;
684  bool enter_editmode;
685  float loc[3], rot[3], radius;
688  C, op, 'Z', loc, rot, nullptr, &enter_editmode, &local_view_bits, nullptr)) {
689  return OPERATOR_CANCELLED;
690  }
691  radius = RNA_float_get(op->ptr, "radius");
693  C, RNA_enum_get(op->ptr, "type"), nullptr, loc, rot, enter_editmode, local_view_bits);
694 
695  if (ob->type == OB_LATTICE) {
696  /* lattice is a special case!
697  * we never want to scale the obdata since that is the rest-state */
698  copy_v3_fl(ob->scale, radius);
699  }
700  else {
701  BKE_object_obdata_size_init(ob, radius);
702  }
703 
704  return OPERATOR_FINISHED;
705 }
706 
708 {
709  /* identifiers */
710  ot->name = "Add Object";
711  ot->description = "Add an object to the scene";
712  ot->idname = "OBJECT_OT_add";
713 
714  /* api callbacks */
717 
718  /* flags */
720 
721  /* properties */
723  PropertyRNA *prop = RNA_def_enum(ot->srna, "type", rna_enum_object_type_items, 0, "Type", "");
725 
727 }
728 
731 /* -------------------------------------------------------------------- */
735 /* for object add operator */
736 static const char *get_lightprobe_defname(int type)
737 {
738  switch (type) {
740  return CTX_DATA_(BLT_I18NCONTEXT_ID_LIGHT, "IrradianceVolume");
742  return CTX_DATA_(BLT_I18NCONTEXT_ID_LIGHT, "ReflectionPlane");
744  return CTX_DATA_(BLT_I18NCONTEXT_ID_LIGHT, "ReflectionCubemap");
745  default:
746  return CTX_DATA_(BLT_I18NCONTEXT_ID_LIGHT, "LightProbe");
747  }
748 }
749 
751 {
752  bool enter_editmode;
753  ushort local_view_bits;
754  float loc[3], rot[3];
757  C, op, 'Z', loc, rot, nullptr, &enter_editmode, &local_view_bits, nullptr)) {
758  return OPERATOR_CANCELLED;
759  }
760  int type = RNA_enum_get(op->ptr, "type");
761  float radius = RNA_float_get(op->ptr, "radius");
762 
764  C, OB_LIGHTPROBE, get_lightprobe_defname(type), loc, rot, false, local_view_bits);
765  copy_v3_fl(ob->scale, radius);
766 
767  LightProbe *probe = (LightProbe *)ob->data;
768 
770 
771  return OPERATOR_FINISHED;
772 }
773 
775 {
776  /* identifiers */
777  ot->name = "Add Light Probe";
778  ot->description = "Add a light probe object";
779  ot->idname = "OBJECT_OT_lightprobe_add";
780 
781  /* api callbacks */
784 
785  /* flags */
787 
788  /* properties */
789  ot->prop = RNA_def_enum(ot->srna, "type", lightprobe_type_items, 0, "Type", "");
790 
793 }
794 
797 /* -------------------------------------------------------------------- */
801 /* for object add operator */
802 
804 {
805  switch (type) {
806  case PFIELD_FORCE:
807  return CTX_DATA_(BLT_I18NCONTEXT_ID_OBJECT, "Force");
808  case PFIELD_VORTEX:
809  return CTX_DATA_(BLT_I18NCONTEXT_ID_OBJECT, "Vortex");
810  case PFIELD_MAGNET:
811  return CTX_DATA_(BLT_I18NCONTEXT_ID_OBJECT, "Magnet");
812  case PFIELD_WIND:
813  return CTX_DATA_(BLT_I18NCONTEXT_ID_OBJECT, "Wind");
814  case PFIELD_GUIDE:
815  return CTX_DATA_(BLT_I18NCONTEXT_ID_OBJECT, "CurveGuide");
816  case PFIELD_TEXTURE:
817  return CTX_DATA_(BLT_I18NCONTEXT_ID_OBJECT, "TextureField");
818  case PFIELD_HARMONIC:
819  return CTX_DATA_(BLT_I18NCONTEXT_ID_OBJECT, "Harmonic");
820  case PFIELD_CHARGE:
821  return CTX_DATA_(BLT_I18NCONTEXT_ID_OBJECT, "Charge");
822  case PFIELD_LENNARDJ:
823  return CTX_DATA_(BLT_I18NCONTEXT_ID_OBJECT, "Lennard-Jones");
824  case PFIELD_BOID:
825  return CTX_DATA_(BLT_I18NCONTEXT_ID_OBJECT, "Boid");
826  case PFIELD_TURBULENCE:
827  return CTX_DATA_(BLT_I18NCONTEXT_ID_OBJECT, "Turbulence");
828  case PFIELD_DRAG:
829  return CTX_DATA_(BLT_I18NCONTEXT_ID_OBJECT, "Drag");
830  case PFIELD_FLUIDFLOW:
831  return CTX_DATA_(BLT_I18NCONTEXT_ID_OBJECT, "FluidField");
832  case PFIELD_NULL:
833  return CTX_DATA_(BLT_I18NCONTEXT_ID_OBJECT, "Field");
834  case NUM_PFIELD_TYPES:
835  break;
836  }
837 
838  BLI_assert(false);
839  return CTX_DATA_(BLT_I18NCONTEXT_ID_OBJECT, "Field");
840 }
841 
843 {
844  bool enter_editmode;
845  ushort local_view_bits;
846  float loc[3], rot[3];
849  C, op, 'Z', loc, rot, nullptr, &enter_editmode, &local_view_bits, nullptr)) {
850  return OPERATOR_CANCELLED;
851  }
852  const ePFieldType type = static_cast<ePFieldType>(RNA_enum_get(op->ptr, "type"));
853  float dia = RNA_float_get(op->ptr, "radius");
854 
855  Object *ob;
856  if (type == PFIELD_GUIDE) {
857  Main *bmain = CTX_data_main(C);
859  ob = ED_object_add_type(
860  C, OB_CURVES_LEGACY, get_effector_defname(type), loc, rot, false, local_view_bits);
861 
862  Curve *cu = static_cast<Curve *>(ob->data);
863  cu->flag |= CU_PATH | CU_3D;
864  ED_object_editmode_enter_ex(bmain, scene, ob, 0);
865 
866  float mat[4][4];
867  ED_object_new_primitive_matrix(C, ob, loc, rot, nullptr, mat);
868  mul_mat3_m4_fl(mat, dia);
869  BLI_addtail(&cu->editnurb->nurbs,
871  if (!enter_editmode) {
873  }
874  }
875  else {
876  ob = ED_object_add_type(
877  C, OB_EMPTY, get_effector_defname(type), loc, rot, false, local_view_bits);
881  }
882  }
883 
884  ob->pd = BKE_partdeflect_new(type);
885 
886  return OPERATOR_FINISHED;
887 }
888 
890 {
891  /* identifiers */
892  ot->name = "Add Effector";
893  ot->description = "Add an empty object with a physics effector to the scene";
894  ot->idname = "OBJECT_OT_effector_add";
895 
896  /* api callbacks */
899 
900  /* flags */
902 
903  /* properties */
904  ot->prop = RNA_def_enum(ot->srna, "type", field_type_items, 0, "Type", "");
905 
908 }
909 
912 /* -------------------------------------------------------------------- */
917 {
918  View3D *v3d = CTX_wm_view3d(C);
920 
921  /* force view align for cameras */
922  RNA_enum_set(op->ptr, "align", ALIGN_VIEW);
923 
924  ushort local_view_bits;
925  bool enter_editmode;
926  float loc[3], rot[3];
928  C, op, 'Z', loc, rot, nullptr, &enter_editmode, &local_view_bits, nullptr)) {
929  return OPERATOR_CANCELLED;
930  }
931  Object *ob = ED_object_add_type(C, OB_CAMERA, nullptr, loc, rot, false, local_view_bits);
932 
933  if (v3d) {
934  if (v3d->camera == nullptr) {
935  v3d->camera = ob;
936  }
937  if (v3d->scenelock && scene->camera == nullptr) {
938  scene->camera = ob;
939  }
940  }
941 
942  Camera *cam = static_cast<Camera *>(ob->data);
943  cam->drawsize = v3d ? ED_view3d_grid_scale(scene, v3d, nullptr) :
944  ED_scene_grid_scale(scene, nullptr);
945 
946  return OPERATOR_FINISHED;
947 }
948 
950 {
951  PropertyRNA *prop;
952 
953  /* identifiers */
954  ot->name = "Add Camera";
955  ot->description = "Add a camera object to the scene";
956  ot->idname = "OBJECT_OT_camera_add";
957 
958  /* api callbacks */
961 
962  /* flags */
964 
966 
967  /* hide this for cameras, default */
968  prop = RNA_struct_type_find_property(ot->srna, "align");
970 }
971 
974 /* -------------------------------------------------------------------- */
979 {
980  Main *bmain = CTX_data_main(C);
982  ViewLayer *view_layer = CTX_data_view_layer(C);
983 
984  ushort local_view_bits;
985  bool enter_editmode;
986  float loc[3], rot[3];
989  C, op, 'Z', loc, rot, nullptr, &enter_editmode, &local_view_bits, nullptr)) {
990  return OPERATOR_CANCELLED;
991  }
992 
993  bool newob = false;
994  Object *obedit = OBEDIT_FROM_VIEW_LAYER(view_layer);
995  if (obedit == nullptr || obedit->type != OB_MBALL) {
996  obedit = ED_object_add_type(C, OB_MBALL, nullptr, loc, rot, true, local_view_bits);
997  newob = true;
998  }
999  else {
1001  }
1002 
1003  float mat[4][4];
1004  ED_object_new_primitive_matrix(C, obedit, loc, rot, nullptr, mat);
1005  /* Halving here is done to account for constant values from #BKE_mball_element_add.
1006  * While the default radius of the resulting meta element is 2,
1007  * we want to pass in 1 so other values such as resolution are scaled by 1.0. */
1008  float dia = RNA_float_get(op->ptr, "radius") / 2;
1009 
1010  ED_mball_add_primitive(C, obedit, newob, mat, dia, RNA_enum_get(op->ptr, "type"));
1011 
1012  /* userdef */
1013  if (newob && !enter_editmode) {
1014  ED_object_editmode_exit_ex(bmain, scene, obedit, EM_FREEDATA);
1015  }
1016  else {
1017  /* Only needed in edit-mode (#ED_object_add_type normally handles this). */
1019  }
1020 
1021  return OPERATOR_FINISHED;
1022 }
1023 
1025 {
1026  /* identifiers */
1027  ot->name = "Add Metaball";
1028  ot->description = "Add an metaball object to the scene";
1029  ot->idname = "OBJECT_OT_metaball_add";
1030 
1031  /* api callbacks */
1035 
1036  /* flags */
1038 
1039  ot->prop = RNA_def_enum(ot->srna, "type", rna_enum_metaelem_type_items, 0, "Primitive", "");
1040 
1043 }
1044 
1047 /* -------------------------------------------------------------------- */
1052 {
1053  Object *obedit = CTX_data_edit_object(C);
1054  bool enter_editmode;
1055  ushort local_view_bits;
1056  float loc[3], rot[3];
1057 
1060  C, op, 'Z', loc, rot, nullptr, &enter_editmode, &local_view_bits, nullptr)) {
1061  return OPERATOR_CANCELLED;
1062  }
1063  if (obedit && obedit->type == OB_FONT) {
1064  return OPERATOR_CANCELLED;
1065  }
1066 
1067  obedit = ED_object_add_type(C, OB_FONT, nullptr, loc, rot, enter_editmode, local_view_bits);
1068  BKE_object_obdata_size_init(obedit, RNA_float_get(op->ptr, "radius"));
1069 
1070  return OPERATOR_FINISHED;
1071 }
1072 
1074 {
1075  /* identifiers */
1076  ot->name = "Add Text";
1077  ot->description = "Add a text object to the scene";
1078  ot->idname = "OBJECT_OT_text_add";
1079 
1080  /* api callbacks */
1083 
1084  /* flags */
1086 
1087  /* properties */
1090 }
1091 
1094 /* -------------------------------------------------------------------- */
1099 {
1100  Main *bmain = CTX_data_main(C);
1102  ViewLayer *view_layer = CTX_data_view_layer(C);
1103  Object *obedit = OBEDIT_FROM_VIEW_LAYER(view_layer);
1104 
1106  bool newob = false;
1107  bool enter_editmode;
1108  ushort local_view_bits;
1109  float loc[3], rot[3], dia;
1110  bool view_aligned = rv3d && (U.flag & USER_ADD_VIEWALIGNED);
1111 
1114  C, op, 'Z', loc, rot, nullptr, &enter_editmode, &local_view_bits, nullptr)) {
1115  return OPERATOR_CANCELLED;
1116  }
1117  if ((obedit == nullptr) || (obedit->type != OB_ARMATURE)) {
1118  obedit = ED_object_add_type(C, OB_ARMATURE, nullptr, loc, rot, true, local_view_bits);
1119  ED_object_editmode_enter_ex(bmain, scene, obedit, 0);
1120  newob = true;
1121  }
1122  else {
1124  }
1125 
1126  if (obedit == nullptr) {
1127  BKE_report(op->reports, RPT_ERROR, "Cannot create editmode armature");
1128  return OPERATOR_CANCELLED;
1129  }
1130 
1131  dia = RNA_float_get(op->ptr, "radius");
1132  ED_armature_ebone_add_primitive(obedit, dia, view_aligned);
1133 
1134  /* userdef */
1135  if (newob && !enter_editmode) {
1136  ED_object_editmode_exit_ex(bmain, scene, obedit, EM_FREEDATA);
1137  }
1138 
1139  return OPERATOR_FINISHED;
1140 }
1141 
1143 {
1144  /* identifiers */
1145  ot->name = "Add Armature";
1146  ot->description = "Add an armature object to the scene";
1147  ot->idname = "OBJECT_OT_armature_add";
1148 
1149  /* api callbacks */
1152 
1153  /* flags */
1155 
1156  /* properties */
1159 }
1160 
1163 /* -------------------------------------------------------------------- */
1168 {
1169  Object *ob;
1170  int type = RNA_enum_get(op->ptr, "type");
1171  ushort local_view_bits;
1172  float loc[3], rot[3];
1173 
1176  C, op, 'Z', loc, rot, nullptr, nullptr, &local_view_bits, nullptr)) {
1177  return OPERATOR_CANCELLED;
1178  }
1179  ob = ED_object_add_type(C, OB_EMPTY, nullptr, loc, rot, false, local_view_bits);
1180 
1182  BKE_object_obdata_size_init(ob, RNA_float_get(op->ptr, "radius"));
1183 
1184  return OPERATOR_FINISHED;
1185 }
1186 
1188 {
1189  /* identifiers */
1190  ot->name = "Add Empty";
1191  ot->description = "Add an empty object to the scene";
1192  ot->idname = "OBJECT_OT_empty_add";
1193 
1194  /* api callbacks */
1198 
1199  /* flags */
1201 
1202  /* properties */
1203  ot->prop = RNA_def_enum(ot->srna, "type", rna_enum_object_empty_drawtype_items, 0, "Type", "");
1204 
1207 }
1208 
1210 {
1212 
1213  Image *ima = nullptr;
1214 
1215  ima = (Image *)WM_operator_drop_load_path(C, op, ID_IM);
1216  if (!ima) {
1217  return OPERATOR_CANCELLED;
1218  }
1219  /* handled below */
1220  id_us_min(&ima->id);
1221 
1222  Object *ob = nullptr;
1223  Object *ob_cursor = ED_view3d_give_object_under_cursor(C, event->mval);
1224 
1225  /* either change empty under cursor or create a new empty */
1226  if (ob_cursor && ob_cursor->type == OB_EMPTY) {
1228  DEG_id_tag_update((ID *)ob_cursor, ID_RECALC_TRANSFORM);
1229  ob = ob_cursor;
1230  }
1231  else {
1232  /* add new empty */
1233  ushort local_view_bits;
1234  float rot[3];
1235 
1237  C, op, 'Z', nullptr, rot, nullptr, nullptr, &local_view_bits, nullptr)) {
1238  return OPERATOR_CANCELLED;
1239  }
1240  ob = ED_object_add_type(C, OB_EMPTY, nullptr, nullptr, rot, false, local_view_bits);
1241 
1243  ED_view3d_cursor3d_position(C, event->mval, false, ob->loc);
1244  ED_object_rotation_from_view(C, ob->rot, 'Z');
1245  ob->empty_drawsize = 5.0f;
1246  }
1247 
1249 
1250  id_us_min(static_cast<ID *>(ob->data));
1251  ob->data = ima;
1252  id_us_plus(static_cast<ID *>(ob->data));
1253 
1254  return OPERATOR_FINISHED;
1255 }
1256 
1258 {
1259  PropertyRNA *prop;
1260 
1261  /* identifiers */
1262  ot->name = "Add Empty Image/Drop Image to Empty";
1263  ot->description = "Add an empty image type to scene with data";
1264  ot->idname = "OBJECT_OT_drop_named_image";
1265 
1266  /* api callbacks */
1269 
1270  /* flags */
1272 
1273  /* properties */
1274  prop = RNA_def_string(ot->srna, "filepath", nullptr, FILE_MAX, "Filepath", "Path to image file");
1277  "relative_path",
1278  true,
1279  "Relative Path",
1280  "Select the file relative to the blend file");
1282 
1284 
1286 }
1287 
1290 /* -------------------------------------------------------------------- */
1295 {
1297  Object *obact = CTX_data_active_object(C);
1298 
1299  if ((scene == nullptr) || ID_IS_LINKED(scene) || ID_IS_OVERRIDE_LIBRARY(scene)) {
1300  return false;
1301  }
1302 
1303  if (obact && obact->type == OB_GPENCIL) {
1304  if (obact->mode != OB_MODE_OBJECT) {
1305  return false;
1306  }
1307  }
1308 
1309  return true;
1310 }
1311 
1313 {
1314  Object *ob = CTX_data_active_object(C), *ob_orig = ob;
1315  bGPdata *gpd = (ob && (ob->type == OB_GPENCIL)) ? static_cast<bGPdata *>(ob->data) : nullptr;
1316 
1317  const int type = RNA_enum_get(op->ptr, "type");
1318  const bool use_in_front = RNA_boolean_get(op->ptr, "use_in_front");
1319  const bool use_lights = RNA_boolean_get(op->ptr, "use_lights");
1320  const int stroke_depth_order = RNA_enum_get(op->ptr, "stroke_depth_order");
1321  const float stroke_depth_offset = RNA_float_get(op->ptr, "stroke_depth_offset");
1322 
1323  ushort local_view_bits;
1324  float loc[3], rot[3];
1325  bool newob = false;
1326 
1327  /* NOTE: We use 'Y' here (not 'Z'), as. */
1330  C, op, 'Y', loc, rot, nullptr, nullptr, &local_view_bits, nullptr)) {
1331  return OPERATOR_CANCELLED;
1332  }
1333  /* Add new object if not currently editing a GP object. */
1334  if ((gpd == nullptr) || (GPENCIL_ANY_MODE(gpd) == false)) {
1335  const char *ob_name = nullptr;
1336  switch (type) {
1337  case GP_EMPTY: {
1338  ob_name = CTX_DATA_(BLT_I18NCONTEXT_ID_GPENCIL, "GPencil");
1339  break;
1340  }
1341  case GP_MONKEY: {
1342  ob_name = CTX_DATA_(BLT_I18NCONTEXT_ID_GPENCIL, "Suzanne");
1343  break;
1344  }
1345  case GP_STROKE: {
1346  ob_name = CTX_DATA_(BLT_I18NCONTEXT_ID_GPENCIL, "Stroke");
1347  break;
1348  }
1349  case GP_LRT_OBJECT:
1350  case GP_LRT_SCENE:
1351  case GP_LRT_COLLECTION: {
1352  ob_name = CTX_DATA_(BLT_I18NCONTEXT_ID_GPENCIL, "LineArt");
1353  break;
1354  }
1355  default: {
1356  break;
1357  }
1358  }
1359 
1360  ob = ED_object_add_type(C, OB_GPENCIL, ob_name, loc, rot, true, local_view_bits);
1361  gpd = static_cast<bGPdata *>(ob->data);
1362  newob = true;
1363  }
1364  else {
1367  }
1368 
1369  /* create relevant geometry */
1370  switch (type) {
1371  case GP_EMPTY: {
1372  float mat[4][4];
1373 
1374  ED_object_new_primitive_matrix(C, ob, loc, rot, nullptr, mat);
1375  ED_gpencil_create_blank(C, ob, mat);
1376  break;
1377  }
1378  case GP_STROKE: {
1379  float radius = RNA_float_get(op->ptr, "radius");
1380  float scale[3];
1381  copy_v3_fl(scale, radius);
1382  float mat[4][4];
1383 
1384  ED_object_new_primitive_matrix(C, ob, loc, rot, scale, mat);
1385 
1386  ED_gpencil_create_stroke(C, ob, mat);
1387  break;
1388  }
1389  case GP_MONKEY: {
1390  float radius = RNA_float_get(op->ptr, "radius");
1391  float scale[3];
1392  copy_v3_fl(scale, radius);
1393  float mat[4][4];
1394 
1395  ED_object_new_primitive_matrix(C, ob, loc, rot, scale, mat);
1396 
1397  ED_gpencil_create_monkey(C, ob, mat);
1398  break;
1399  }
1400  case GP_LRT_SCENE:
1401  case GP_LRT_COLLECTION:
1402  case GP_LRT_OBJECT: {
1403  float radius = RNA_float_get(op->ptr, "radius");
1404  float scale[3];
1405  copy_v3_fl(scale, radius);
1406  float mat[4][4];
1407 
1408  ED_object_new_primitive_matrix(C, ob, loc, rot, scale, mat);
1409 
1411 
1412  gpd = static_cast<bGPdata *>(ob->data);
1413 
1414  /* Add Line Art modifier */
1419 
1420  if (type == GP_LRT_COLLECTION) {
1423  }
1424  else if (type == GP_LRT_OBJECT) {
1426  md->source_object = ob_orig;
1427  }
1428  else {
1429  /* Whole scene. */
1431  }
1432  /* Only created one layer and one material. */
1433  strcpy(md->target_layer, ((bGPDlayer *)gpd->layers.first)->info);
1435  if (md->target_material) {
1436  id_us_plus(&md->target_material->id);
1437  }
1438 
1439  if (use_lights) {
1440  ob->dtx |= OB_USE_GPENCIL_LIGHTS;
1441  }
1442  else {
1443  ob->dtx &= ~OB_USE_GPENCIL_LIGHTS;
1444  }
1445 
1446  /* Stroke object is drawn in front of meshes by default. */
1447  if (use_in_front) {
1448  ob->dtx |= OB_DRAW_IN_FRONT;
1449  }
1450  else {
1451  if (stroke_depth_order == GP_DRAWMODE_3D) {
1452  gpd->draw_mode = GP_DRAWMODE_3D;
1453  }
1454  md->stroke_depth_offset = stroke_depth_offset;
1455  }
1456 
1457  break;
1458  }
1459  default:
1460  BKE_report(op->reports, RPT_WARNING, "Not implemented");
1461  break;
1462  }
1463 
1464  /* If this is a new object, initialize default stuff (colors, etc.) */
1465  if (newob) {
1466  /* set default viewport color to black */
1467  copy_v3_fl(ob->color, 0.0f);
1468 
1470  }
1471 
1472  return OPERATOR_FINISHED;
1473 }
1474 
1476 {
1477  uiLayout *layout = op->layout;
1478 
1479  uiLayoutSetPropSep(layout, true);
1480 
1481  uiItemR(layout, op->ptr, "radius", 0, nullptr, ICON_NONE);
1482  uiItemR(layout, op->ptr, "align", 0, nullptr, ICON_NONE);
1483  uiItemR(layout, op->ptr, "location", 0, nullptr, ICON_NONE);
1484  uiItemR(layout, op->ptr, "rotation", 0, nullptr, ICON_NONE);
1485  uiItemR(layout, op->ptr, "type", 0, nullptr, ICON_NONE);
1486 
1487  int type = RNA_enum_get(op->ptr, "type");
1489  uiItemR(layout, op->ptr, "use_lights", 0, nullptr, ICON_NONE);
1490  uiItemR(layout, op->ptr, "use_in_front", 0, nullptr, ICON_NONE);
1491  bool in_front = RNA_boolean_get(op->ptr, "use_in_front");
1492  uiLayout *col = uiLayoutColumn(layout, false);
1493  uiLayoutSetActive(col, !in_front);
1494  uiItemR(col, op->ptr, "stroke_depth_offset", 0, nullptr, ICON_NONE);
1495  uiItemR(col, op->ptr, "stroke_depth_order", 0, nullptr, ICON_NONE);
1496  }
1497 }
1498 
1500  {GP_DRAWMODE_2D,
1501  "2D",
1502  0,
1503  "2D Layers",
1504  "Display strokes using grease pencil layers to define order"},
1505  {GP_DRAWMODE_3D, "3D", 0, "3D Location", "Display strokes using real 3D position in 3D space"},
1506  {0, nullptr, 0, nullptr, nullptr},
1507 };
1508 
1510 {
1511  /* identifiers */
1512  ot->name = "Add Grease Pencil";
1513  ot->description = "Add a Grease Pencil object to the scene";
1514  ot->idname = "OBJECT_OT_gpencil_add";
1515 
1516  /* api callbacks */
1520 
1521  /* flags */
1523 
1524  /* ui */
1525  ot->ui = object_add_ui;
1526 
1527  /* properties */
1530 
1531  ot->prop = RNA_def_enum(ot->srna, "type", rna_enum_object_gpencil_type_items, 0, "Type", "");
1533  "use_in_front",
1534  true,
1535  "Show In Front",
1536  "Show line art grease pencil in front of everything");
1538  "stroke_depth_offset",
1539  0.05f,
1540  0.0f,
1541  FLT_MAX,
1542  "Stroke Offset",
1543  "Stroke offset for the line art modifier",
1544  0.0f,
1545  0.5f);
1547  ot->srna, "use_lights", false, "Use Lights", "Use lights for this grease pencil object");
1548  RNA_def_enum(
1549  ot->srna,
1550  "stroke_depth_order",
1553  "Stroke Depth Order",
1554  "Defines how the strokes are ordered in 3D space for objects not displayed 'In Front')");
1555 }
1556 
1559 /* -------------------------------------------------------------------- */
1563 static const char *get_light_defname(int type)
1564 {
1565  switch (type) {
1566  case LA_LOCAL:
1567  return CTX_DATA_(BLT_I18NCONTEXT_ID_LIGHT, "Point");
1568  case LA_SUN:
1569  return CTX_DATA_(BLT_I18NCONTEXT_ID_LIGHT, "Sun");
1570  case LA_SPOT:
1571  return CTX_DATA_(BLT_I18NCONTEXT_ID_LIGHT, "Spot");
1572  case LA_AREA:
1573  return CTX_DATA_(BLT_I18NCONTEXT_ID_LIGHT, "Area");
1574  default:
1575  return CTX_DATA_(BLT_I18NCONTEXT_ID_LIGHT, "Light");
1576  }
1577 }
1578 
1580 {
1581  Object *ob;
1582  Light *la;
1583  int type = RNA_enum_get(op->ptr, "type");
1584  ushort local_view_bits;
1585  float loc[3], rot[3];
1586 
1589  C, op, 'Z', loc, rot, nullptr, nullptr, &local_view_bits, nullptr)) {
1590  return OPERATOR_CANCELLED;
1591  }
1592  ob = ED_object_add_type(C, OB_LAMP, get_light_defname(type), loc, rot, false, local_view_bits);
1593 
1594  float size = RNA_float_get(op->ptr, "radius");
1595  /* Better defaults for light size. */
1596  switch (type) {
1597  case LA_LOCAL:
1598  case LA_SPOT:
1599  break;
1600  case LA_AREA:
1601  size *= 4.0f;
1602  break;
1603  default:
1604  size *= 0.5f;
1605  break;
1606  }
1608 
1609  la = (Light *)ob->data;
1610  la->type = type;
1611 
1612  if (type == LA_SUN) {
1613  la->energy = 1.0f;
1614  }
1615 
1616  return OPERATOR_FINISHED;
1617 }
1618 
1620 {
1621  /* identifiers */
1622  ot->name = "Add Light";
1623  ot->description = "Add a light object to the scene";
1624  ot->idname = "OBJECT_OT_light_add";
1625 
1626  /* api callbacks */
1630 
1631  /* flags */
1633 
1634  /* properties */
1635  ot->prop = RNA_def_enum(ot->srna, "type", rna_enum_light_type_items, 0, "Type", "");
1637 
1640 }
1641 
1644 /* -------------------------------------------------------------------- */
1649  /* The collection that is supposed to be added, determined through operator properties. */
1651  /* The local-view bits (if any) the object should have set to become visible in current context.
1652  */
1654  /* The transform that should be applied to the collection, determined through operator properties
1655  * if set (e.g. to place the collection under the cursor), otherwise through context (e.g. 3D
1656  * cursor location). */
1657  float loc[3], rot[3];
1658 };
1659 
1660 static std::optional<CollectionAddInfo> collection_add_info_get_from_op(bContext *C,
1661  wmOperator *op)
1662 {
1663  CollectionAddInfo add_info{};
1664 
1665  Main *bmain = CTX_data_main(C);
1666 
1667  PropertyRNA *prop_location = RNA_struct_find_property(op->ptr, "location");
1668 
1669  add_info.collection = reinterpret_cast<Collection *>(
1671 
1672  bool update_location_if_necessary = false;
1673  if (add_info.collection) {
1674  update_location_if_necessary = true;
1675  }
1676  else {
1677  add_info.collection = static_cast<Collection *>(
1678  BLI_findlink(&bmain->collections, RNA_enum_get(op->ptr, "collection")));
1679  }
1680 
1681  if (update_location_if_necessary) {
1682  int mval[2];
1683  if (!RNA_property_is_set(op->ptr, prop_location) && object_add_drop_xy_get(C, op, &mval)) {
1684  ED_object_location_from_view(C, add_info.loc);
1685  ED_view3d_cursor3d_position(C, mval, false, add_info.loc);
1686  RNA_property_float_set_array(op->ptr, prop_location, add_info.loc);
1687  }
1688  }
1689 
1690  if (add_info.collection == nullptr) {
1691  return std::nullopt;
1692  }
1693 
1695  op,
1696  'Z',
1697  add_info.loc,
1698  add_info.rot,
1699  nullptr,
1700  nullptr,
1701  &add_info.local_view_bits,
1702  nullptr)) {
1703  return std::nullopt;
1704  }
1705 
1706  ViewLayer *view_layer = CTX_data_view_layer(C);
1707 
1708  /* Avoid dependency cycles. */
1709  LayerCollection *active_lc = BKE_layer_collection_get_active(view_layer);
1710  while (BKE_collection_cycle_find(active_lc->collection, add_info.collection)) {
1711  active_lc = BKE_layer_collection_activate_parent(view_layer, active_lc);
1712  }
1713 
1714  return add_info;
1715 }
1716 
1718 {
1719  std::optional<CollectionAddInfo> add_info = collection_add_info_get_from_op(C, op);
1720  if (!add_info) {
1721  return OPERATOR_CANCELLED;
1722  }
1723 
1724  Object *ob = ED_object_add_type(C,
1725  OB_EMPTY,
1726  add_info->collection->id.name + 2,
1727  add_info->loc,
1728  add_info->rot,
1729  false,
1730  add_info->local_view_bits);
1731  ob->instance_collection = add_info->collection;
1732  ob->empty_drawsize = U.collection_instance_empty_size;
1734  id_us_plus(&add_info->collection->id);
1735 
1736  return OPERATOR_FINISHED;
1737 }
1738 
1739 static int object_instance_add_invoke(bContext *C, wmOperator *op, const wmEvent *event)
1740 {
1741  if (!object_add_drop_xy_is_set(op)) {
1742  RNA_int_set(op->ptr, "drop_x", event->xy[0]);
1743  RNA_int_set(op->ptr, "drop_y", event->xy[1]);
1744  }
1745 
1747  return WM_enum_search_invoke(C, op, event);
1748  }
1749  return op->type->exec(C, op);
1750 }
1751 
1753 {
1754  PropertyRNA *prop;
1755 
1756  /* identifiers */
1757  ot->name = "Add Collection Instance";
1758  ot->description = "Add a collection instance";
1759  ot->idname = "OBJECT_OT_collection_instance_add";
1760 
1761  /* api callbacks */
1765 
1766  /* flags */
1768 
1769  /* properties */
1771  ot->srna, "name", "Collection", MAX_ID_NAME - 2, "Name", "Collection name to add");
1772  prop = RNA_def_enum(ot->srna, "collection", DummyRNA_NULL_items, 0, "Collection", "");
1775  ot->prop = prop;
1777 
1779 
1781 }
1782 
1785 /* -------------------------------------------------------------------- */
1805 {
1806  Main *bmain = CTX_data_main(C);
1807  LayerCollection *active_collection = CTX_data_layer_collection(C);
1808  std::optional<CollectionAddInfo> add_info = collection_add_info_get_from_op(C, op);
1809  if (!add_info) {
1810  return OPERATOR_CANCELLED;
1811  }
1812 
1813  if (RNA_boolean_get(op->ptr, "use_instance")) {
1814  BKE_collection_child_remove(bmain, active_collection->collection, add_info->collection);
1815  DEG_id_tag_update(&active_collection->collection->id, ID_RECALC_COPY_ON_WRITE);
1816  DEG_relations_tag_update(bmain);
1817 
1818  Object *ob = ED_object_add_type(C,
1819  OB_EMPTY,
1820  add_info->collection->id.name + 2,
1821  add_info->loc,
1822  add_info->rot,
1823  false,
1824  add_info->local_view_bits);
1825  ob->instance_collection = add_info->collection;
1826  ob->empty_drawsize = U.collection_instance_empty_size;
1828  id_us_plus(&add_info->collection->id);
1829  }
1830  else {
1831  ViewLayer *view_layer = CTX_data_view_layer(C);
1832  float delta_mat[4][4];
1833  unit_m4(delta_mat);
1834 
1835  const float scale[3] = {1.0f, 1.0f, 1.0f};
1836  loc_eul_size_to_mat4(delta_mat, add_info->loc, add_info->rot, scale);
1837 
1838  float offset[3];
1839  /* Reverse apply the instance offset, so toggling the Instance option doesn't cause the
1840  * collection to jump. */
1841  negate_v3_v3(offset, add_info->collection->instance_offset);
1842  translate_m4(delta_mat, UNPACK3(offset));
1843 
1845  uint objects_len;
1847  view_layer, nullptr, &objects_len, &params);
1848  ED_object_xform_array_m4(objects, objects_len, delta_mat);
1849 
1850  MEM_freeN(objects);
1851  }
1852 
1853  return OPERATOR_FINISHED;
1854 }
1855 
1857 {
1858  PropertyRNA *prop;
1859 
1860  /* identifiers */
1861  /* Name should only be displayed in the drag tooltip. */
1862  ot->name = "Add Collection";
1863  ot->description = "Add the dragged collection to the scene";
1864  ot->idname = "OBJECT_OT_collection_external_asset_drop";
1865 
1866  /* api callbacks */
1870 
1871  /* flags */
1873 
1874  /* properties */
1876 
1878 
1879  /* IMPORTANT: Instancing option. Intentionally remembered across executions (no #PROP_SKIP_SAVE).
1880  */
1882  "use_instance",
1883  true,
1884  "Instance",
1885  "Add the dropped collection as collection instance");
1886 
1888 
1889  prop = RNA_def_enum(ot->srna, "collection", DummyRNA_NULL_items, 0, "Collection", "");
1891  RNA_def_property_flag(prop,
1893  ot->prop = prop;
1894 }
1895 
1898 /* -------------------------------------------------------------------- */
1905 {
1906  Main *bmain = CTX_data_main(C);
1907  ID *id = nullptr;
1908  ushort local_view_bits;
1909  float loc[3], rot[3];
1910 
1911  PropertyRNA *prop_type = RNA_struct_find_property(op->ptr, "type");
1912  PropertyRNA *prop_location = RNA_struct_find_property(op->ptr, "location");
1913 
1914  const short id_type = RNA_property_enum_get(op->ptr, prop_type);
1916  bmain, op->ptr, (ID_Type)id_type);
1917  if (id == nullptr) {
1918  return OPERATOR_CANCELLED;
1919  }
1920  const int object_type = BKE_object_obdata_to_type(id);
1921  if (object_type == -1) {
1922  return OPERATOR_CANCELLED;
1923  }
1924 
1925  int mval[2];
1926  if (!RNA_property_is_set(op->ptr, prop_location) && object_add_drop_xy_get(C, op, &mval)) {
1928  ED_view3d_cursor3d_position(C, mval, false, loc);
1929  RNA_property_float_set_array(op->ptr, prop_location, loc);
1930  }
1931 
1933  C, op, 'Z', loc, rot, nullptr, nullptr, &local_view_bits, nullptr)) {
1934  return OPERATOR_CANCELLED;
1935  }
1936 
1938  C, object_type, id->name + 2, loc, rot, false, local_view_bits, id);
1939 
1940  return OPERATOR_FINISHED;
1941 }
1942 
1944 {
1945  /* identifiers */
1946  ot->name = "Add Object Data Instance";
1947  ot->description = "Add an object data instance";
1948  ot->idname = "OBJECT_OT_data_instance_add";
1949 
1950  /* api callbacks */
1954 
1955  /* flags */
1957 
1958  /* properties */
1960  PropertyRNA *prop = RNA_def_enum(ot->srna, "type", rna_enum_id_type_items, 0, "Type", "");
1963 
1965 }
1966 
1969 /* -------------------------------------------------------------------- */
1974 {
1975  Main *bmain = CTX_data_main(C);
1977 
1978  ushort local_view_bits;
1979  float loc[3], rot[3];
1981  C, op, 'Z', loc, rot, nullptr, nullptr, &local_view_bits, nullptr)) {
1982  return OPERATOR_CANCELLED;
1983  }
1984  Object *ob = ED_object_add_type(C, OB_SPEAKER, nullptr, loc, rot, false, local_view_bits);
1985  const bool is_liboverride = ID_IS_OVERRIDE_LIBRARY(ob);
1986 
1987  /* To make it easier to start using this immediately in NLA, a default sound clip is created
1988  * ready to be moved around to re-time the sound and/or make new sound clips. */
1989  {
1990  /* create new data for NLA hierarchy */
1991  AnimData *adt = BKE_animdata_ensure_id(&ob->id);
1992  NlaTrack *nlt = BKE_nlatrack_add(adt, nullptr, is_liboverride);
1993  NlaStrip *strip = BKE_nla_add_soundstrip(bmain, scene, static_cast<Speaker *>(ob->data));
1994  strip->start = scene->r.cfra;
1995  strip->end += strip->start;
1996 
1997  /* hook them up */
1998  BKE_nlatrack_add_strip(nlt, strip, is_liboverride);
1999 
2000  /* Auto-name the strip, and give the track an interesting name. */
2001  BLI_strncpy(nlt->name, DATA_("SoundTrack"), sizeof(nlt->name));
2002  BKE_nlastrip_validate_name(adt, strip);
2003 
2005  }
2006 
2007  return OPERATOR_FINISHED;
2008 }
2009 
2011 {
2012  /* identifiers */
2013  ot->name = "Add Speaker";
2014  ot->description = "Add a speaker object to the scene";
2015  ot->idname = "OBJECT_OT_speaker_add";
2016 
2017  /* api callbacks */
2020 
2021  /* flags */
2023 
2025 }
2026 
2029 /* -------------------------------------------------------------------- */
2034 {
2035  using namespace blender;
2036 
2037  ushort local_view_bits;
2038  float loc[3], rot[3];
2040  C, op, 'Z', loc, rot, nullptr, nullptr, &local_view_bits, nullptr)) {
2041  return OPERATOR_CANCELLED;
2042  }
2043 
2044  Object *object = ED_object_add_type(C, OB_CURVES, nullptr, loc, rot, false, local_view_bits);
2045 
2046  Curves *curves_id = static_cast<Curves *>(object->data);
2048 
2049  return OPERATOR_FINISHED;
2050 }
2051 
2053 {
2054  /* identifiers */
2055  ot->name = "Add Random Curves";
2056  ot->description = "Add a curves object with random curves to the scene";
2057  ot->idname = "OBJECT_OT_curves_random_add";
2058 
2059  /* api callbacks */
2062 
2063  /* flags */
2065 
2067 }
2068 
2070 {
2072 
2073  ushort local_view_bits;
2075  C, op, 'Z', nullptr, nullptr, nullptr, nullptr, &local_view_bits, nullptr)) {
2076  return OPERATOR_CANCELLED;
2077  }
2078 
2079  Object *surface_ob = CTX_data_active_object(C);
2080  BLI_assert(surface_ob != nullptr);
2081 
2082  Object *curves_ob = ED_object_add_type(
2083  C, OB_CURVES, nullptr, nullptr, nullptr, false, local_view_bits);
2084  BKE_object_apply_mat4(curves_ob, surface_ob->obmat, false, false);
2085 
2086  /* Set surface object. */
2087  Curves *curves_id = static_cast<Curves *>(curves_ob->data);
2088  curves_id->surface = surface_ob;
2089 
2090  /* Parent to surface object. */
2092  op->reports, C, scene, curves_ob, surface_ob, PAR_OBJECT, false, true, nullptr);
2093 
2094  /* Decide which UV map to use for attachment. */
2095  Mesh *surface_mesh = static_cast<Mesh *>(surface_ob->data);
2096  const char *uv_name = CustomData_get_active_layer_name(&surface_mesh->ldata, CD_MLOOPUV);
2097  if (uv_name != nullptr) {
2098  curves_id->surface_uv_map = BLI_strdup(uv_name);
2099  }
2100 
2101  /* Add deformation modifier. */
2103 
2104  /* Make sure the surface object has a rest position attribute which is necessary for
2105  * deformations. */
2107 
2108  return OPERATOR_FINISHED;
2109 }
2110 
2112 {
2113  if (!ED_operator_objectmode(C)) {
2114  return false;
2115  }
2117  if (ob == nullptr || ob->type != OB_MESH) {
2118  CTX_wm_operator_poll_msg_set(C, "No active mesh object");
2119  return false;
2120  }
2121  return true;
2122 }
2123 
2125 {
2126  ot->name = "Add Empty Curves";
2127  ot->description = "Add an empty curve object to the scene with the selected mesh as surface";
2128  ot->idname = "OBJECT_OT_curves_empty_hair_add";
2129 
2132 
2134 
2136 }
2137 
2140 /* -------------------------------------------------------------------- */
2145 {
2146  if (!U.experimental.use_new_point_cloud_type) {
2147  return false;
2148  }
2149  return ED_operator_objectmode(C);
2150 }
2151 
2153 {
2154  ushort local_view_bits;
2155  float loc[3], rot[3];
2157  C, op, 'Z', loc, rot, nullptr, nullptr, &local_view_bits, nullptr)) {
2158  return OPERATOR_CANCELLED;
2159  }
2160 
2161  Object *object = ED_object_add_type(C, OB_POINTCLOUD, nullptr, loc, rot, false, local_view_bits);
2162  object->dtx |= OB_DRAWBOUNDOX; /* TODO: remove once there is actual drawing. */
2163 
2164  return OPERATOR_FINISHED;
2165 }
2166 
2168 {
2169  /* identifiers */
2170  ot->name = "Add Point Cloud";
2171  ot->description = "Add a point cloud object to the scene";
2172  ot->idname = "OBJECT_OT_pointcloud_add";
2173 
2174  /* api callbacks */
2177 
2178  /* flags */
2180 
2182 }
2183 
2186 /* -------------------------------------------------------------------- */
2191 {
2192  if (ID_REAL_USERS(ob) <= 1 && ID_EXTRA_USERS(ob) == 0 &&
2193  BKE_library_ID_is_indirectly_used(bmain, ob)) {
2194  /* We cannot delete indirectly used object... */
2195  printf(
2196  "WARNING, undeletable object '%s', should have been caught before reaching this "
2197  "function!",
2198  ob->id.name + 2);
2199  return;
2200  }
2202  /* Do not delete objects used by overrides of collections. */
2203  return;
2204  }
2205 
2207 
2208  BKE_scene_collections_object_remove(bmain, scene, ob, true);
2209 }
2210 
2212 {
2215  BKE_scene_collections_object_remove(bmain, scene, ob, true);
2216 }
2217 
2219 {
2220  Main *bmain = CTX_data_main(C);
2223  const bool use_global = RNA_boolean_get(op->ptr, "use_global");
2224  const bool confirm = op->flag & OP_IS_INVOKE;
2225  uint changed_count = 0;
2226  uint tagged_count = 0;
2227 
2228  if (CTX_data_edit_object(C)) {
2229  return OPERATOR_CANCELLED;
2230  }
2231 
2232  BKE_main_id_tag_all(bmain, LIB_TAG_DOIT, false);
2233 
2234  CTX_DATA_BEGIN (C, Object *, ob, selected_objects) {
2235  if (ob->id.tag & LIB_TAG_INDIRECT) {
2236  /* Can this case ever happen? */
2237  BKE_reportf(op->reports,
2238  RPT_WARNING,
2239  "Cannot delete indirectly linked object '%s'",
2240  ob->id.name + 2);
2241  continue;
2242  }
2243 
2244  if (!BKE_lib_override_library_id_is_user_deletable(bmain, &ob->id)) {
2245  BKE_reportf(op->reports,
2246  RPT_WARNING,
2247  "Cannot delete object '%s' as it is used by override collections",
2248  ob->id.name + 2);
2249  continue;
2250  }
2251 
2252  if (ID_REAL_USERS(ob) <= 1 && ID_EXTRA_USERS(ob) == 0 &&
2253  BKE_library_ID_is_indirectly_used(bmain, ob)) {
2254  BKE_reportf(op->reports,
2255  RPT_WARNING,
2256  "Cannot delete object '%s' from scene '%s', indirectly used objects need at "
2257  "least one user",
2258  ob->id.name + 2,
2259  scene->id.name + 2);
2260  continue;
2261  }
2262 
2263  /* if grease pencil object, set cache as dirty */
2264  if (ob->type == OB_GPENCIL) {
2265  bGPdata *gpd = (bGPdata *)ob->data;
2267  }
2268 
2269  /* Use multi tagged delete if `use_global=True`, or the object is used only in one scene. */
2270  if (use_global || ID_REAL_USERS(ob) <= 1) {
2271  ob->id.tag |= LIB_TAG_DOIT;
2272  tagged_count += 1;
2273  }
2274  else {
2275  /* Object is used in multiple scenes. Delete the object from the current scene only. */
2277  changed_count += 1;
2278 
2279  /* FIXME: this will also remove parent from grease pencil from other scenes. */
2280  /* Remove from Grease Pencil parent */
2281  LISTBASE_FOREACH (bGPdata *, gpd, &bmain->gpencils) {
2282  LISTBASE_FOREACH (bGPDlayer *, gpl, &gpd->layers) {
2283  if (gpl->parent != nullptr) {
2284  if (gpl->parent == ob) {
2285  gpl->parent = nullptr;
2286  }
2287  }
2288  }
2289  }
2290  }
2291  }
2292  CTX_DATA_END;
2293 
2294  if ((changed_count + tagged_count) == 0) {
2295  return OPERATOR_CANCELLED;
2296  }
2297 
2298  if (tagged_count > 0) {
2300  }
2301 
2302  if (confirm) {
2303  BKE_reportf(op->reports, RPT_INFO, "Deleted %u object(s)", (changed_count + tagged_count));
2304  }
2305 
2306  /* delete has to handle all open scenes */
2308  LISTBASE_FOREACH (wmWindow *, win, &wm->windows) {
2310 
2311  if (scene->id.tag & LIB_TAG_DOIT) {
2312  scene->id.tag &= ~LIB_TAG_DOIT;
2313 
2314  DEG_relations_tag_update(bmain);
2315 
2319  }
2320  }
2321 
2322  return OPERATOR_FINISHED;
2323 }
2324 
2326 {
2327  /* identifiers */
2328  ot->name = "Delete";
2329  ot->description = "Delete selected objects";
2330  ot->idname = "OBJECT_OT_delete";
2331 
2332  /* api callbacks */
2336 
2337  /* flags */
2339 
2340  PropertyRNA *prop;
2341  prop = RNA_def_boolean(
2342  ot->srna, "use_global", false, "Delete Globally", "Remove object from all scenes");
2345 }
2346 
2349 /* -------------------------------------------------------------------- */
2353 /* after copying objects, copied data should get new pointers */
2355 {
2356  Main *bmain = CTX_data_main(C);
2357 
2358  CTX_DATA_BEGIN (C, Object *, ob, selected_editable_objects) {
2359  BKE_libblock_relink_to_newid(bmain, &ob->id, 0);
2360  }
2361  CTX_DATA_END;
2362 
2363 #ifndef NDEBUG
2364  /* Call to `BKE_libblock_relink_to_newid` above is supposed to have cleared all those flags. */
2365  ID *id_iter;
2366  FOREACH_MAIN_ID_BEGIN (bmain, id_iter) {
2367  if (GS(id_iter->name) == ID_OB) {
2368  /* Not all duplicated objects would be used by other newly duplicated data, so their flag
2369  * will not always be cleared. */
2370  continue;
2371  }
2372  BLI_assert((id_iter->tag & LIB_TAG_NEW) == 0);
2373  }
2375 #endif
2376 
2378 }
2379 
2382 /* -------------------------------------------------------------------- */
2386 /* XXX TODO: That whole hierarchy handling based on persistent_id tricks is
2387  * very confusing and convoluted, and it will fail in many cases besides basic ones.
2388  * Think this should be replaced by a proper tree-like representation of the instantiations,
2389  * should help a lot in both readability, and precise consistent rebuilding of hierarchy.
2390  */
2391 
2405 static uint dupliobject_hash(const void *ptr)
2406 {
2407  const DupliObject *dob = static_cast<const DupliObject *>(ptr);
2409 
2410  if (dob->type == OB_DUPLICOLLECTION) {
2411  for (int i = 1; (i < MAX_DUPLI_RECUR) && dob->persistent_id[i] != INT_MAX; i++) {
2412  hash ^= (dob->persistent_id[i] ^ i);
2413  }
2414  }
2415  else {
2416  hash ^= (dob->persistent_id[0] ^ 0);
2417  }
2418  return hash;
2419 }
2420 
2428 {
2429  const DupliObject *dob = static_cast<const DupliObject *>(ptr);
2431  for (int i = 1; (i < MAX_DUPLI_RECUR) && dob->persistent_id[i] != INT_MAX; i++) {
2432  hash ^= (dob->persistent_id[i] ^ i);
2433  }
2434  return hash;
2435 }
2436 
2437 /* Compare function that matches dupliobject_hash */
2438 static bool dupliobject_cmp(const void *a_, const void *b_)
2439 {
2440  const DupliObject *a = static_cast<const DupliObject *>(a_);
2441  const DupliObject *b = static_cast<const DupliObject *>(b_);
2442 
2443  if (a->ob != b->ob) {
2444  return true;
2445  }
2446 
2447  if (a->type != b->type) {
2448  return true;
2449  }
2450 
2451  if (a->type == OB_DUPLICOLLECTION) {
2452  for (int i = 1; (i < MAX_DUPLI_RECUR); i++) {
2453  if (a->persistent_id[i] != b->persistent_id[i]) {
2454  return true;
2455  }
2456  if (a->persistent_id[i] == INT_MAX) {
2457  break;
2458  }
2459  }
2460  }
2461  else {
2462  if (a->persistent_id[0] != b->persistent_id[0]) {
2463  return true;
2464  }
2465  }
2466 
2467  /* matching */
2468  return false;
2469 }
2470 
2471 /* Compare function that matches dupliobject_instancer_hash. */
2472 static bool dupliobject_instancer_cmp(const void *a_, const void *b_)
2473 {
2474  const DupliObject *a = static_cast<const DupliObject *>(a_);
2475  const DupliObject *b = static_cast<const DupliObject *>(b_);
2476 
2477  for (int i = 0; (i < MAX_DUPLI_RECUR); i++) {
2478  if (a->persistent_id[i] != b->persistent_id[i]) {
2479  return true;
2480  }
2481  if (a->persistent_id[i] == INT_MAX) {
2482  break;
2483  }
2484  }
2485 
2486  /* matching */
2487  return false;
2488 }
2489 
2492  Scene *scene,
2493  Base *base,
2494  const bool use_base_parent,
2495  const bool use_hierarchy)
2496 {
2497  Main *bmain = CTX_data_main(C);
2498  ViewLayer *view_layer = CTX_data_view_layer(C);
2499  GHash *parent_gh = nullptr, *instancer_gh = nullptr;
2500 
2501  Object *object_eval = DEG_get_evaluated_object(depsgraph, base->object);
2502 
2503  if (!(base->object->transflag & OB_DUPLI) &&
2504  !BKE_object_has_geometry_set_instances(object_eval)) {
2505  return;
2506  }
2507 
2508  ListBase *lb_duplis = object_duplilist(depsgraph, scene, object_eval);
2509 
2510  if (BLI_listbase_is_empty(lb_duplis)) {
2511  free_object_duplilist(lb_duplis);
2512  return;
2513  }
2514 
2515  GHash *dupli_gh = BLI_ghash_ptr_new(__func__);
2516  if (use_hierarchy) {
2517  parent_gh = BLI_ghash_new(dupliobject_hash, dupliobject_cmp, __func__);
2518 
2519  if (use_base_parent) {
2520  instancer_gh = BLI_ghash_new(
2522  }
2523  }
2524 
2525  LISTBASE_FOREACH (DupliObject *, dob, lb_duplis) {
2526  Object *ob_src = DEG_get_original_object(dob->ob);
2527  Object *ob_dst = static_cast<Object *>(ID_NEW_SET(ob_src, BKE_id_copy(bmain, &ob_src->id)));
2528  id_us_min(&ob_dst->id);
2529 
2530  /* font duplis can have a totcol without material, we get them from parent
2531  * should be implemented better...
2532  */
2533  if (ob_dst->mat == nullptr) {
2534  ob_dst->totcol = 0;
2535  }
2536 
2537  BKE_collection_object_add_from(bmain, scene, base->object, ob_dst);
2538  Base *base_dst = BKE_view_layer_base_find(view_layer, ob_dst);
2539  BLI_assert(base_dst != nullptr);
2540 
2541  ED_object_base_select(base_dst, BA_SELECT);
2543 
2545 
2546  /* make sure apply works */
2547  BKE_animdata_free(&ob_dst->id, true);
2548  ob_dst->adt = nullptr;
2549 
2550  ob_dst->parent = nullptr;
2552  ob_dst->runtime.curve_cache = nullptr;
2553  const bool is_dupli_instancer = (ob_dst->transflag & OB_DUPLI) != 0;
2554  ob_dst->transflag &= ~OB_DUPLI;
2555  /* Remove instantiated collection, it's annoying to keep it here
2556  * (and get potentially a lot of usages of it then...). */
2557  id_us_min((ID *)ob_dst->instance_collection);
2558  ob_dst->instance_collection = nullptr;
2559 
2560  copy_m4_m4(ob_dst->obmat, dob->mat);
2561  BKE_object_apply_mat4(ob_dst, ob_dst->obmat, false, false);
2562 
2563  BLI_ghash_insert(dupli_gh, dob, ob_dst);
2564  if (parent_gh) {
2565  void **val;
2566  /* Due to nature of hash/comparison of this ghash, a lot of duplis may be considered as
2567  * 'the same', this avoids trying to insert same key several time and
2568  * raise asserts in debug builds... */
2569  if (!BLI_ghash_ensure_p(parent_gh, dob, &val)) {
2570  *val = ob_dst;
2571  }
2572 
2573  if (is_dupli_instancer && instancer_gh) {
2574  /* Same as above, we may have several 'hits'. */
2575  if (!BLI_ghash_ensure_p(instancer_gh, dob, &val)) {
2576  *val = ob_dst;
2577  }
2578  }
2579  }
2580  }
2581 
2582  LISTBASE_FOREACH (DupliObject *, dob, lb_duplis) {
2583  Object *ob_src = dob->ob;
2584  Object *ob_dst = static_cast<Object *>(BLI_ghash_lookup(dupli_gh, dob));
2585 
2586  /* Remap new object to itself, and clear again newid pointer of orig object. */
2587  BKE_libblock_relink_to_newid(bmain, &ob_dst->id, 0);
2588 
2590 
2591  if (use_hierarchy) {
2592  /* original parents */
2593  Object *ob_src_par = ob_src->parent;
2594  Object *ob_dst_par = nullptr;
2595 
2596  /* find parent that was also made real */
2597  if (ob_src_par) {
2598  /* OK to keep most of the members uninitialized,
2599  * they won't be read, this is simply for a hash lookup. */
2600  DupliObject dob_key;
2601  dob_key.ob = ob_src_par;
2602  dob_key.type = dob->type;
2603  if (dob->type == OB_DUPLICOLLECTION) {
2604  memcpy(&dob_key.persistent_id[1],
2605  &dob->persistent_id[1],
2606  sizeof(dob->persistent_id[1]) * (MAX_DUPLI_RECUR - 1));
2607  }
2608  else {
2609  dob_key.persistent_id[0] = dob->persistent_id[0];
2610  }
2611  ob_dst_par = static_cast<Object *>(BLI_ghash_lookup(parent_gh, &dob_key));
2612  }
2613 
2614  if (ob_dst_par) {
2615  /* allow for all possible parent types */
2616  ob_dst->partype = ob_src->partype;
2617  BLI_strncpy(ob_dst->parsubstr, ob_src->parsubstr, sizeof(ob_dst->parsubstr));
2618  ob_dst->par1 = ob_src->par1;
2619  ob_dst->par2 = ob_src->par2;
2620  ob_dst->par3 = ob_src->par3;
2621 
2622  copy_m4_m4(ob_dst->parentinv, ob_src->parentinv);
2623 
2624  ob_dst->parent = ob_dst_par;
2625  }
2626  }
2627  if (use_base_parent && ob_dst->parent == nullptr) {
2628  Object *ob_dst_par = nullptr;
2629 
2630  if (instancer_gh != nullptr) {
2631  /* OK to keep most of the members uninitialized,
2632  * they won't be read, this is simply for a hash lookup. */
2633  DupliObject dob_key;
2634  /* We are looking one step upper in hierarchy, so we need to 'shift' the `persistent_id`,
2635  * ignoring the first item.
2636  * We only check on persistent_id here, since we have no idea what object it might be. */
2637  memcpy(&dob_key.persistent_id[0],
2638  &dob->persistent_id[1],
2639  sizeof(dob_key.persistent_id[0]) * (MAX_DUPLI_RECUR - 1));
2640  ob_dst_par = static_cast<Object *>(BLI_ghash_lookup(instancer_gh, &dob_key));
2641  }
2642 
2643  if (ob_dst_par == nullptr) {
2644  /* Default to parenting to root object...
2645  * Always the case when use_hierarchy is false. */
2646  ob_dst_par = base->object;
2647  }
2648 
2649  ob_dst->parent = ob_dst_par;
2650  ob_dst->partype = PAROBJECT;
2651  }
2652 
2653  if (ob_dst->parent) {
2654  /* NOTE: this may be the parent of other objects, but it should
2655  * still work out ok */
2656  BKE_object_apply_mat4(ob_dst, dob->mat, false, true);
2657 
2658  /* to set ob_dst->orig and in case there's any other discrepancies */
2660  }
2661  }
2662 
2664  base->object->instance_collection = nullptr;
2665  }
2666 
2669 
2670  BLI_ghash_free(dupli_gh, nullptr, nullptr);
2671  if (parent_gh) {
2672  BLI_ghash_free(parent_gh, nullptr, nullptr);
2673  }
2674  if (instancer_gh) {
2675  BLI_ghash_free(instancer_gh, nullptr, nullptr);
2676  }
2677 
2678  free_object_duplilist(lb_duplis);
2679 
2681 
2682  base->object->transflag &= ~OB_DUPLI;
2684 }
2685 
2687 {
2688  Main *bmain = CTX_data_main(C);
2691 
2692  const bool use_base_parent = RNA_boolean_get(op->ptr, "use_base_parent");
2693  const bool use_hierarchy = RNA_boolean_get(op->ptr, "use_hierarchy");
2694 
2696 
2697  CTX_DATA_BEGIN (C, Base *, base, selected_editable_bases) {
2698  make_object_duplilist_real(C, depsgraph, scene, base, use_base_parent, use_hierarchy);
2699 
2700  /* dependencies were changed */
2701  WM_event_add_notifier(C, NC_OBJECT | ND_PARENT, base->object);
2702  }
2703  CTX_DATA_END;
2704 
2705  DEG_relations_tag_update(bmain);
2709 
2710  return OPERATOR_FINISHED;
2711 }
2712 
2714 {
2715  /* identifiers */
2716  ot->name = "Make Instances Real";
2717  ot->description = "Make instanced objects attached to this object real";
2718  ot->idname = "OBJECT_OT_duplicates_make_real";
2719 
2720  /* api callbacks */
2722 
2724 
2725  /* flags */
2727 
2729  "use_base_parent",
2730  false,
2731  "Parent",
2732  "Parent newly created objects to the original instancer");
2734  ot->srna, "use_hierarchy", false, "Keep Hierarchy", "Maintain parent child relationships");
2735 }
2736 
2739 /* -------------------------------------------------------------------- */
2745  "CURVE",
2746  ICON_OUTLINER_OB_CURVE,
2747  "Curve",
2748  "Curve from Mesh or Text objects"},
2749  {OB_MESH,
2750  "MESH",
2751  ICON_OUTLINER_OB_MESH,
2752  "Mesh",
2753 #ifdef WITH_POINT_CLOUD
2754  "Mesh from Curve, Surface, Metaball, Text, or Point Cloud objects"},
2755 #else
2756  "Mesh from Curve, Surface, Metaball, or Text objects"},
2757 #endif
2758  {OB_GPENCIL,
2759  "GPENCIL",
2760  ICON_OUTLINER_OB_GREASEPENCIL,
2761  "Grease Pencil",
2762  "Grease Pencil from Curve or Mesh objects"},
2763 #ifdef WITH_POINT_CLOUD
2764  {OB_POINTCLOUD,
2765  "POINTCLOUD",
2766  ICON_OUTLINER_OB_POINTCLOUD,
2767  "Point Cloud",
2768  "Point Cloud from Mesh objects"},
2769 #endif
2770  {OB_CURVES, "CURVES", ICON_OUTLINER_OB_CURVES, "Curves", "Curves from evaluated curve data"},
2771  {0, nullptr, 0, nullptr, nullptr},
2772 };
2773 
2775 {
2776  if (ob->runtime.curve_cache == nullptr) {
2777  /* Force creation. This is normally not needed but on operator
2778  * redo we might end up with an object which isn't evaluated yet.
2779  * Also happens in case we are working on a copy of the object
2780  * (all its caches have been nuked then).
2781  */
2782  if (ELEM(ob->type, OB_SURF, OB_CURVES_LEGACY, OB_FONT)) {
2783  /* We need 'for render' ON here, to enable computing bevel #DispList if needed.
2784  * Also makes sense anyway, we would not want e.g. to lose hidden parts etc. */
2786  }
2787  else if (ob->type == OB_MBALL) {
2789  }
2790  }
2791 }
2792 
2794 {
2795  Object *object_eval = DEG_get_evaluated_object(depsgraph, ob);
2796  Curve *curve = static_cast<Curve *>(ob->data);
2797 
2798  Mesh *mesh = BKE_mesh_new_from_object_to_bmain(bmain, depsgraph, object_eval, true);
2799  if (mesh == nullptr) {
2800  /* Unable to convert the curve to a mesh. */
2801  return;
2802  }
2803 
2805  /* Replace curve used by the object itself. */
2806  ob->data = mesh;
2807  ob->type = OB_MESH;
2808  id_us_min(&curve->id);
2809  id_us_plus(&mesh->id);
2810  /* Change objects which are using same curve.
2811  * A bit annoying, but:
2812  * - It's possible to have multiple curve objects selected which are sharing the same curve
2813  * data-block. We don't want mesh to be created for every of those objects.
2814  * - This is how conversion worked for a long time. */
2815  LISTBASE_FOREACH (Object *, other_object, &bmain->objects) {
2816  if (other_object->data == curve) {
2817  other_object->type = OB_MESH;
2818 
2819  id_us_min((ID *)other_object->data);
2820  other_object->data = ob->data;
2821  id_us_plus((ID *)other_object->data);
2822  }
2823  }
2824 }
2825 
2827 {
2829  Base *base_act = CTX_data_active_base(C);
2830  Object *obact = base_act ? base_act->object : nullptr;
2831 
2832  if (obact == nullptr || obact->data == nullptr || ID_IS_LINKED(obact) ||
2834  return false;
2835  }
2836 
2837  return (!ID_IS_LINKED(scene) && (BKE_object_is_in_editmode(obact) == false) &&
2838  (base_act->flag & BASE_SELECTED));
2839 }
2840 
2841 /* Helper for object_convert_exec */
2843  Main *bmain, Depsgraph *depsgraph, Scene *scene, ViewLayer *view_layer, Base *base, Object *ob)
2844 {
2845  if (ob == nullptr) {
2846  ob = base->object;
2847  }
2848 
2849  Object *obn = (Object *)BKE_id_copy(bmain, &ob->id);
2850  id_us_min(&obn->id);
2852  BKE_collection_object_add_from(bmain, scene, ob, obn);
2853 
2854  Base *basen = BKE_view_layer_base_find(view_layer, obn);
2857 
2858  /* XXX: An ugly hack needed because if we re-run depsgraph with some new meta-ball objects
2859  * having same 'family name' as orig ones, they will affect end result of meta-ball computation.
2860  * For until we get rid of that name-based thingy in meta-balls, that should do the trick
2861  * (this is weak, but other solution (to change name of `obn`) is even worse IMHO).
2862  * See T65996. */
2863  const bool is_meta_ball = (obn->type == OB_MBALL);
2864  void *obdata = obn->data;
2865  if (is_meta_ball) {
2866  obn->type = OB_EMPTY;
2867  obn->data = nullptr;
2868  }
2869 
2870  /* XXX Doing that here is stupid, it means we update and re-evaluate the whole depsgraph every
2871  * time we need to duplicate an object to convert it. Even worse, this is not 100% correct, since
2872  * we do not yet have duplicated obdata.
2873  * However, that is a safe solution for now. Proper, longer-term solution is to refactor
2874  * object_convert_exec to:
2875  * - duplicate all data it needs to in a first loop.
2876  * - do a single update.
2877  * - convert data in a second loop. */
2879  CustomData_MeshMasks customdata_mask_prev = scene->customdata_mask;
2882  scene->customdata_mask = customdata_mask_prev;
2883 
2884  if (is_meta_ball) {
2885  obn->type = OB_MBALL;
2886  obn->data = obdata;
2887  }
2888 
2889  return basen;
2890 }
2891 
2893 {
2894  Main *bmain = CTX_data_main(C);
2897  ViewLayer *view_layer = CTX_data_view_layer(C);
2898  View3D *v3d = CTX_wm_view3d(C);
2899  Base *basen = nullptr, *basact = nullptr;
2900  Object *ob1, *obact = CTX_data_active_object(C);
2901  const short target = RNA_enum_get(op->ptr, "target");
2902  bool keep_original = RNA_boolean_get(op->ptr, "keep_original");
2903  const bool do_merge_customdata = RNA_boolean_get(op->ptr, "merge_customdata");
2904 
2905  const float angle = RNA_float_get(op->ptr, "angle");
2906  const int thickness = RNA_int_get(op->ptr, "thickness");
2907  const bool use_seams = RNA_boolean_get(op->ptr, "seams");
2908  const bool use_faces = RNA_boolean_get(op->ptr, "faces");
2909  const float offset = RNA_float_get(op->ptr, "offset");
2910 
2911  int a, mballConverted = 0;
2912  bool gpencilConverted = false;
2913  bool gpencilCurveConverted = false;
2914 
2915  /* don't forget multiple users! */
2916 
2917  {
2919  ob->flag &= ~OB_DONE;
2920 
2921  /* flag data that's not been edited (only needed for !keep_original) */
2922  if (ob->data) {
2923  ((ID *)ob->data)->tag |= LIB_TAG_DOIT;
2924  }
2925 
2926  /* possible metaball basis is not in this scene */
2927  if (ob->type == OB_MBALL && target == OB_MESH) {
2928  if (BKE_mball_is_basis(ob) == false) {
2929  Object *ob_basis;
2930  ob_basis = BKE_mball_basis_find(scene, ob);
2931  if (ob_basis) {
2932  ob_basis->flag &= ~OB_DONE;
2933  }
2934  }
2935  }
2936  }
2938  }
2939 
2940  ListBase selected_editable_bases;
2941  CTX_data_selected_editable_bases(C, &selected_editable_bases);
2942 
2943  /* Ensure we get all meshes calculated with a sufficient data-mask,
2944  * needed since re-evaluating single modifiers causes bugs if they depend
2945  * on other objects data masks too, see: T50950. */
2946  {
2947  LISTBASE_FOREACH (CollectionPointerLink *, link, &selected_editable_bases) {
2948  Base *base = static_cast<Base *>(link->ptr.data);
2949  Object *ob = base->object;
2950 
2951  /* The way object type conversion works currently (enforcing conversion of *all* objects
2952  * using converted object-data, even some un-selected/hidden/another scene ones,
2953  * sounds totally bad to me.
2954  * However, changing this is more design than bug-fix, not to mention convoluted code below,
2955  * so that will be for later.
2956  * But at the very least, do not do that with linked IDs! */
2957  if ((!BKE_id_is_editable(bmain, &ob->id) ||
2958  (ob->data && !BKE_id_is_editable(bmain, static_cast<ID *>(ob->data)))) &&
2959  !keep_original) {
2960  keep_original = true;
2961  BKE_report(op->reports,
2962  RPT_INFO,
2963  "Converting some non-editable object/object data, enforcing 'Keep Original' "
2964  "option to True");
2965  }
2966 
2968  }
2969 
2970  CustomData_MeshMasks customdata_mask_prev = scene->customdata_mask;
2973  scene->customdata_mask = customdata_mask_prev;
2974  }
2975 
2976  LISTBASE_FOREACH (CollectionPointerLink *, link, &selected_editable_bases) {
2977  Object *newob = nullptr;
2978  Base *base = static_cast<Base *>(link->ptr.data);
2979  Object *ob = base->object;
2980 
2981  if (ob->flag & OB_DONE || !IS_TAGGED(ob->data)) {
2982  if (ob->type != target) {
2983  base->flag &= ~SELECT;
2984  ob->flag &= ~SELECT;
2985  }
2986 
2987  /* obdata already modified */
2988  if (!IS_TAGGED(ob->data)) {
2989  /* When 2 objects with linked data are selected, converting both
2990  * would keep modifiers on all but the converted object T26003. */
2991  if (ob->type == OB_MESH) {
2992  BKE_object_free_modifiers(ob, 0); /* after derivedmesh calls! */
2993  }
2994  if (ob->type == OB_GPENCIL) {
2995  BKE_object_free_modifiers(ob, 0); /* after derivedmesh calls! */
2996  BKE_object_free_shaderfx(ob, 0);
2997  }
2998  }
2999  }
3000  else if (ob->type == OB_MESH && target == OB_CURVES_LEGACY) {
3001  ob->flag |= OB_DONE;
3002 
3003  if (keep_original) {
3004  basen = duplibase_for_convert(bmain, depsgraph, scene, view_layer, base, nullptr);
3005  newob = basen->object;
3006 
3007  /* Decrement original mesh's usage count. */
3008  Mesh *me = static_cast<Mesh *>(newob->data);
3009  id_us_min(&me->id);
3010 
3011  /* Make a new copy of the mesh. */
3012  newob->data = BKE_id_copy(bmain, &me->id);
3013  }
3014  else {
3015  newob = ob;
3016  }
3017 
3018  BKE_mesh_to_curve(bmain, depsgraph, scene, newob);
3019 
3020  if (newob->type == OB_CURVES_LEGACY) {
3021  BKE_object_free_modifiers(newob, 0); /* after derivedmesh calls! */
3022  if (newob->rigidbody_object != nullptr) {
3023  ED_rigidbody_object_remove(bmain, scene, newob);
3024  }
3025  }
3026  }
3027  else if (ob->type == OB_MESH && target == OB_GPENCIL) {
3028  ob->flag |= OB_DONE;
3029 
3030  /* Create a new grease pencil object and copy transformations. */
3031  ushort local_view_bits = (v3d && v3d->localvd) ? v3d->local_view_uuid : 0;
3032  float loc[3], size[3], rot[3][3], eul[3];
3033  float matrix[4][4];
3034  mat4_to_loc_rot_size(loc, rot, size, ob->obmat);
3035  mat3_to_eul(eul, rot);
3036 
3037  Object *ob_gpencil = ED_gpencil_add_object(C, loc, local_view_bits);
3038  copy_v3_v3(ob_gpencil->loc, loc);
3039  copy_v3_v3(ob_gpencil->rot, eul);
3040  copy_v3_v3(ob_gpencil->scale, size);
3041  unit_m4(matrix);
3042  /* Set object in 3D mode. */
3043  bGPdata *gpd = (bGPdata *)ob_gpencil->data;
3044  gpd->draw_mode = GP_DRAWMODE_3D;
3045 
3046  gpencilConverted |= BKE_gpencil_convert_mesh(bmain,
3047  depsgraph,
3048  scene,
3049  ob_gpencil,
3050  ob,
3051  angle,
3052  thickness,
3053  offset,
3054  matrix,
3055  0,
3056  use_seams,
3057  use_faces,
3058  true);
3059 
3060  /* Remove unused materials. */
3061  int actcol = ob_gpencil->actcol;
3062  for (int slot = 1; slot <= ob_gpencil->totcol; slot++) {
3063  while (slot <= ob_gpencil->totcol && !BKE_object_material_slot_used(ob_gpencil, slot)) {
3064  ob_gpencil->actcol = slot;
3066 
3067  if (actcol >= slot) {
3068  actcol--;
3069  }
3070  }
3071  }
3072  ob_gpencil->actcol = actcol;
3073  }
3074  else if (target == OB_CURVES) {
3075  ob->flag |= OB_DONE;
3076 
3077  Object *ob_eval = DEG_get_evaluated_object(depsgraph, ob);
3078  GeometrySet geometry;
3079  if (ob_eval->runtime.geometry_set_eval != nullptr) {
3080  geometry = *ob_eval->runtime.geometry_set_eval;
3081  }
3082 
3083  if (geometry.has_curves()) {
3084  if (keep_original) {
3085  basen = duplibase_for_convert(bmain, depsgraph, scene, view_layer, base, nullptr);
3086  newob = basen->object;
3087 
3088  /* Decrement original curve's usage count. */
3089  Curve *legacy_curve = static_cast<Curve *>(newob->data);
3090  id_us_min(&legacy_curve->id);
3091 
3092  /* Make a copy of the curve. */
3093  newob->data = BKE_id_copy(bmain, &legacy_curve->id);
3094  }
3095  else {
3096  newob = ob;
3097  }
3098 
3099  const CurveComponent &curve_component = *geometry.get_component_for_read<CurveComponent>();
3100  const Curves *curves_eval = curve_component.get_for_read();
3101  Curves *new_curves = static_cast<Curves *>(BKE_id_new(bmain, ID_CV, newob->id.name + 2));
3102 
3103  newob->data = new_curves;
3104  newob->type = OB_CURVES;
3105 
3107  new_curves->geometry) = blender::bke::CurvesGeometry::wrap(curves_eval->geometry);
3108  BKE_object_material_from_eval_data(bmain, newob, &curves_eval->id);
3109 
3111  BKE_object_free_modifiers(newob, 0);
3112  }
3113  else {
3114  BKE_reportf(
3115  op->reports, RPT_WARNING, "Object '%s' has no evaluated curves data", ob->id.name + 2);
3116  }
3117  }
3118  else if (ob->type == OB_MESH && target == OB_POINTCLOUD) {
3119  ob->flag |= OB_DONE;
3120 
3121  if (keep_original) {
3122  basen = duplibase_for_convert(bmain, depsgraph, scene, view_layer, base, nullptr);
3123  newob = basen->object;
3124 
3125  /* Decrement original mesh's usage count. */
3126  Mesh *me = static_cast<Mesh *>(newob->data);
3127  id_us_min(&me->id);
3128 
3129  /* Make a new copy of the mesh. */
3130  newob->data = BKE_id_copy(bmain, &me->id);
3131  }
3132  else {
3133  newob = ob;
3134  }
3135 
3136  BKE_mesh_to_pointcloud(bmain, depsgraph, scene, newob);
3137 
3138  if (newob->type == OB_POINTCLOUD) {
3139  BKE_object_free_modifiers(newob, 0); /* after derivedmesh calls! */
3140  ED_rigidbody_object_remove(bmain, scene, newob);
3141  }
3142  }
3143  else if (ob->type == OB_MESH) {
3144  ob->flag |= OB_DONE;
3145 
3146  if (keep_original) {
3147  basen = duplibase_for_convert(bmain, depsgraph, scene, view_layer, base, nullptr);
3148  newob = basen->object;
3149 
3150  /* Decrement original mesh's usage count. */
3151  Mesh *me = static_cast<Mesh *>(newob->data);
3152  id_us_min(&me->id);
3153 
3154  /* Make a new copy of the mesh. */
3155  newob->data = BKE_id_copy(bmain, &me->id);
3156  }
3157  else {
3158  newob = ob;
3160  }
3161 
3162  /* make new mesh data from the original copy */
3163  /* NOTE: get the mesh from the original, not from the copy in some
3164  * cases this doesn't give correct results (when MDEF is used for eg)
3165  */
3166  Scene *scene_eval = (Scene *)DEG_get_evaluated_id(depsgraph, &scene->id);
3167  Object *ob_eval = DEG_get_evaluated_object(depsgraph, ob);
3168  Mesh *me_eval = mesh_get_eval_final(depsgraph, scene_eval, ob_eval, &CD_MASK_MESH);
3169  me_eval = BKE_mesh_copy_for_eval(me_eval, false);
3170  /* Full (edge-angle based) draw calculation should ideally be performed. */
3172  BKE_object_material_from_eval_data(bmain, newob, &me_eval->id);
3173  Mesh *new_mesh = (Mesh *)newob->data;
3174  BKE_mesh_nomain_to_mesh(me_eval, new_mesh, newob, &CD_MASK_MESH, true);
3175 
3176  if (do_merge_customdata) {
3178  }
3179 
3180  /* Anonymous attributes shouldn't be available on the applied geometry. */
3182 
3183  BKE_object_free_modifiers(newob, 0); /* after derivedmesh calls! */
3184  }
3185  else if (ob->type == OB_FONT) {
3186  ob->flag |= OB_DONE;
3187 
3188  if (keep_original) {
3189  basen = duplibase_for_convert(bmain, depsgraph, scene, view_layer, base, nullptr);
3190  newob = basen->object;
3191 
3192  /* Decrement original curve's usage count. */
3193  id_us_min(&((Curve *)newob->data)->id);
3194 
3195  /* Make a new copy of the curve. */
3196  newob->data = BKE_id_copy(bmain, static_cast<ID *>(ob->data));
3197  }
3198  else {
3199  newob = ob;
3200  }
3201 
3202  Curve *cu = static_cast<Curve *>(newob->data);
3203 
3204  Object *ob_eval = DEG_get_evaluated_object(depsgraph, ob);
3205  BKE_vfont_to_curve_ex(ob_eval,
3206  static_cast<Curve *>(ob_eval->data),
3207  FO_EDIT,
3208  &cu->nurb,
3209  nullptr,
3210  nullptr,
3211  nullptr,
3212  nullptr);
3213 
3214  newob->type = OB_CURVES_LEGACY;
3215  cu->type = OB_CURVES_LEGACY;
3216 
3217  if (cu->vfont) {
3218  id_us_min(&cu->vfont->id);
3219  cu->vfont = nullptr;
3220  }
3221  if (cu->vfontb) {
3222  id_us_min(&cu->vfontb->id);
3223  cu->vfontb = nullptr;
3224  }
3225  if (cu->vfonti) {
3226  id_us_min(&cu->vfonti->id);
3227  cu->vfonti = nullptr;
3228  }
3229  if (cu->vfontbi) {
3230  id_us_min(&cu->vfontbi->id);
3231  cu->vfontbi = nullptr;
3232  }
3233 
3234  if (!keep_original) {
3235  /* other users */
3236  if (ID_REAL_USERS(&cu->id) > 1) {
3237  for (ob1 = static_cast<Object *>(bmain->objects.first); ob1;
3238  ob1 = static_cast<Object *>(ob1->id.next)) {
3239  if (ob1->data == ob->data) {
3240  ob1->type = OB_CURVES_LEGACY;
3241  DEG_id_tag_update(&ob1->id,
3243  }
3244  }
3245  }
3246  }
3247 
3248  LISTBASE_FOREACH (Nurb *, nu, &cu->nurb) {
3249  nu->charidx = 0;
3250  }
3251 
3252  cu->flag &= ~CU_3D;
3254 
3255  if (target == OB_MESH) {
3256  /* No assumption should be made that the resulting objects is a mesh, as conversion can
3257  * fail. */
3259  /* meshes doesn't use displist */
3261  }
3262  else if (target == OB_GPENCIL) {
3263  ushort local_view_bits = (v3d && v3d->localvd) ? v3d->local_view_uuid : 0;
3264  Object *ob_gpencil = ED_gpencil_add_object(C, newob->loc, local_view_bits);
3265  copy_v3_v3(ob_gpencil->rot, newob->rot);
3266  copy_v3_v3(ob_gpencil->scale, newob->scale);
3267  BKE_gpencil_convert_curve(bmain, scene, ob_gpencil, newob, false, 1.0f, 0.0f);
3268  gpencilConverted = true;
3269  gpencilCurveConverted = true;
3270  basen = nullptr;
3271  }
3272  }
3273  else if (ELEM(ob->type, OB_CURVES_LEGACY, OB_SURF)) {
3274  ob->flag |= OB_DONE;
3275 
3276  if (target == OB_MESH) {
3277  if (keep_original) {
3278  basen = duplibase_for_convert(bmain, depsgraph, scene, view_layer, base, nullptr);
3279  newob = basen->object;
3280 
3281  /* Decrement original curve's usage count. */
3282  id_us_min(&((Curve *)newob->data)->id);
3283 
3284  /* make a new copy of the curve */
3285  newob->data = BKE_id_copy(bmain, static_cast<ID *>(ob->data));
3286  }
3287  else {
3288  newob = ob;
3289  }
3290 
3291  /* No assumption should be made that the resulting objects is a mesh, as conversion can
3292  * fail. */
3294  /* meshes doesn't use displist */
3296  }
3297  else if (target == OB_GPENCIL) {
3298  if (ob->type != OB_CURVES_LEGACY) {
3299  ob->flag &= ~OB_DONE;
3300  BKE_report(op->reports, RPT_ERROR, "Convert Surfaces to Grease Pencil is not supported");
3301  }
3302  else {
3303  /* Create a new grease pencil object and copy transformations.
3304  * Nurbs Surface are not supported.
3305  */
3306  ushort local_view_bits = (v3d && v3d->localvd) ? v3d->local_view_uuid : 0;
3307  Object *ob_gpencil = ED_gpencil_add_object(C, ob->loc, local_view_bits);
3308  copy_v3_v3(ob_gpencil->rot, ob->rot);
3309  copy_v3_v3(ob_gpencil->scale, ob->scale);
3310  BKE_gpencil_convert_curve(bmain, scene, ob_gpencil, ob, false, 1.0f, 0.0f);
3311  gpencilConverted = true;
3312  }
3313  }
3314  }
3315  else if (ob->type == OB_MBALL && target == OB_MESH) {
3316  Object *baseob;
3317 
3318  base->flag &= ~BASE_SELECTED;
3319  ob->base_flag &= ~BASE_SELECTED;
3320 
3321  baseob = BKE_mball_basis_find(scene, ob);
3322 
3323  if (ob != baseob) {
3324  /* if motherball is converting it would be marked as done later */
3325  ob->flag |= OB_DONE;
3326  }
3327 
3328  if (!(baseob->flag & OB_DONE)) {
3329  basen = duplibase_for_convert(bmain, depsgraph, scene, view_layer, base, baseob);
3330  newob = basen->object;
3331 
3332  MetaBall *mb = static_cast<MetaBall *>(newob->data);
3333  id_us_min(&mb->id);
3334 
3335  newob->data = BKE_mesh_add(bmain, "Mesh");
3336  newob->type = OB_MESH;
3337 
3338  Mesh *me = static_cast<Mesh *>(newob->data);
3339  me->totcol = mb->totcol;
3340  if (newob->totcol) {
3341  me->mat = static_cast<Material **>(MEM_dupallocN(mb->mat));
3342  for (a = 0; a < newob->totcol; a++) {
3343  id_us_plus((ID *)me->mat[a]);
3344  }
3345  }
3346 
3349  static_cast<Mesh *>(newob->data));
3350 
3351  if (obact->type == OB_MBALL) {
3352  basact = basen;
3353  }
3354 
3355  baseob->flag |= OB_DONE;
3356  mballConverted = 1;
3357  }
3358  }
3359  else if (ob->type == OB_POINTCLOUD && target == OB_MESH) {
3360  ob->flag |= OB_DONE;
3361 
3362  if (keep_original) {
3363  basen = duplibase_for_convert(bmain, depsgraph, scene, view_layer, base, nullptr);
3364  newob = basen->object;
3365 
3366  /* Decrement original point cloud's usage count. */
3367  PointCloud *pointcloud = static_cast<PointCloud *>(newob->data);
3368  id_us_min(&pointcloud->id);
3369 
3370  /* Make a new copy of the point cloud. */
3371  newob->data = BKE_id_copy(bmain, &pointcloud->id);
3372  }
3373  else {
3374  newob = ob;
3375  }
3376 
3377  BKE_pointcloud_to_mesh(bmain, depsgraph, scene, newob);
3378 
3379  if (newob->type == OB_MESH) {
3380  BKE_object_free_modifiers(newob, 0); /* after derivedmesh calls! */
3381  ED_rigidbody_object_remove(bmain, scene, newob);
3382  }
3383  }
3384  else {
3385  continue;
3386  }
3387 
3388  /* Ensure new object has consistent material data with its new obdata. */
3389  if (newob) {
3390  BKE_object_materials_test(bmain, newob, static_cast<ID *>(newob->data));
3391  }
3392 
3393  /* tag obdata if it was been changed */
3394 
3395  /* If the original object is active then make this object active */
3396  if (basen) {
3397  if (ob == obact) {
3398  /* store new active base to update BASACT */
3399  basact = basen;
3400  }
3401 
3402  basen = nullptr;
3403  }
3404 
3405  if (!keep_original && (ob->flag & OB_DONE)) {
3406  /* NOTE: Tag transform for update because object parenting to curve with path is handled
3407  * differently from all other cases. Converting curve to mesh and mesh to curve will likely
3408  * affect the way children are evaluated.
3409  * It is not enough to tag only geometry and rely on the curve parenting relations because
3410  * this relation is lost when curve is converted to mesh. */
3412  ((ID *)ob->data)->tag &= ~LIB_TAG_DOIT; /* flag not to convert this datablock again */
3413  }
3414  }
3415  BLI_freelistN(&selected_editable_bases);
3416 
3417  if (!keep_original) {
3418  if (mballConverted) {
3419  /* We need to remove non-basis MBalls first, otherwise we won't be able to detect them if
3420  * their basis happens to be removed first. */
3421  FOREACH_SCENE_OBJECT_BEGIN (scene, ob_mball) {
3422  if (ob_mball->type == OB_MBALL) {
3423  Object *ob_basis = nullptr;
3424  if (!BKE_mball_is_basis(ob_mball) &&
3425  ((ob_basis = BKE_mball_basis_find(scene, ob_mball)) && (ob_basis->flag & OB_DONE))) {
3426  ED_object_base_free_and_unlink(bmain, scene, ob_mball);
3427  }
3428  }
3429  }
3431  FOREACH_SCENE_OBJECT_BEGIN (scene, ob_mball) {
3432  if (ob_mball->type == OB_MBALL) {
3433  if (ob_mball->flag & OB_DONE) {
3434  if (BKE_mball_is_basis(ob_mball)) {
3435  ED_object_base_free_and_unlink(bmain, scene, ob_mball);
3436  }
3437  }
3438  }
3439  }
3441  }
3442  /* Remove curves and meshes converted to Grease Pencil object. */
3443  if (gpencilConverted) {
3444  FOREACH_SCENE_OBJECT_BEGIN (scene, ob_delete) {
3445  if (ELEM(ob_delete->type, OB_CURVES_LEGACY, OB_MESH)) {
3446  if (ob_delete->flag & OB_DONE) {
3447  ED_object_base_free_and_unlink(bmain, scene, ob_delete);
3448  }
3449  }
3450  }
3452  }
3453  }
3454  else {
3455  /* Remove Text curves converted to Grease Pencil object to avoid duplicated curves. */
3456  if (gpencilCurveConverted) {
3457  FOREACH_SCENE_OBJECT_BEGIN (scene, ob_delete) {
3458  if (ELEM(ob_delete->type, OB_CURVES_LEGACY) && (ob_delete->flag & OB_DONE)) {
3459  ED_object_base_free_and_unlink(bmain, scene, ob_delete);
3460  }
3461  }
3463  }
3464  }
3465 
3466  // XXX ED_object_editmode_enter(C, 0);
3467  // XXX exit_editmode(C, EM_FREEDATA|); /* free data, but no undo */
3468 
3469  if (basact) {
3470  /* active base was changed */
3471  ED_object_base_activate(C, basact);
3472  BASACT(view_layer) = basact;
3473  }
3474  else if (BASACT(view_layer)->object->flag & OB_DONE) {
3475  WM_event_add_notifier(C, NC_OBJECT | ND_MODIFIER, BASACT(view_layer)->object);
3476  WM_event_add_notifier(C, NC_OBJECT | ND_DATA, BASACT(view_layer)->object);
3477  }
3478 
3479  DEG_relations_tag_update(bmain);
3484 
3485  return OPERATOR_FINISHED;
3486 }
3487 
3489 {
3490  uiLayout *layout = op->layout;
3491 
3492  uiLayoutSetPropSep(layout, true);
3493 
3494  uiItemR(layout, op->ptr, "target", 0, nullptr, ICON_NONE);
3495  uiItemR(layout, op->ptr, "keep_original", 0, nullptr, ICON_NONE);
3496 
3497  const int target = RNA_enum_get(op->ptr, "target");
3498  if (target == OB_MESH) {
3499  uiItemR(layout, op->ptr, "merge_customdata", 0, nullptr, ICON_NONE);
3500  }
3501  else if (target == OB_GPENCIL) {
3502  uiItemR(layout, op->ptr, "thickness", 0, nullptr, ICON_NONE);
3503  uiItemR(layout, op->ptr, "angle", 0, nullptr, ICON_NONE);
3504  uiItemR(layout, op->ptr, "offset", 0, nullptr, ICON_NONE);
3505  uiItemR(layout, op->ptr, "seams", 0, nullptr, ICON_NONE);
3506  uiItemR(layout, op->ptr, "faces", 0, nullptr, ICON_NONE);
3507  }
3508 }
3509 
3511 {
3512  PropertyRNA *prop;
3513 
3514  /* identifiers */
3515  ot->name = "Convert To";
3516  ot->description = "Convert selected objects to another type";
3517  ot->idname = "OBJECT_OT_convert";
3518 
3519  /* api callbacks */
3523  ot->ui = object_convert_ui;
3524 
3525  /* flags */
3527 
3528  /* properties */
3529  ot->prop = RNA_def_enum(
3530  ot->srna, "target", convert_target_items, OB_MESH, "Target", "Type of object to convert to");
3532  "keep_original",
3533  false,
3534  "Keep Original",
3535  "Keep original objects instead of replacing them");
3536 
3538  ot->srna,
3539  "merge_customdata",
3540  true,
3541  "Merge UV's",
3542  "Merge UV coordinates that share a vertex to account for imprecision in some modifiers");
3543 
3544  prop = RNA_def_float_rotation(ot->srna,
3545  "angle",
3546  0,
3547  nullptr,
3548  DEG2RADF(0.0f),
3549  DEG2RADF(180.0f),
3550  "Threshold Angle",
3551  "Threshold to determine ends of the strokes",
3552  DEG2RADF(0.0f),
3553  DEG2RADF(180.0f));
3555 
3556  RNA_def_int(ot->srna, "thickness", 5, 1, 100, "Thickness", "", 1, 100);
3557  RNA_def_boolean(ot->srna, "seams", false, "Only Seam Edges", "Convert only seam edges");
3558  RNA_def_boolean(ot->srna, "faces", true, "Export Faces", "Export faces as filled strokes");
3560  "offset",
3561  0.01f,
3562  0.0,
3564  "Stroke Offset",
3565  "Offset strokes from fill",
3566  0.0,
3567  100.00);
3568 }
3569 
3572 /* -------------------------------------------------------------------- */
3582  Scene *scene,
3583  ViewLayer *view_layer,
3584  Object *ob,
3585  const eDupli_ID_Flags dupflag,
3586  const eLibIDDuplicateFlags duplicate_options,
3587  Object **r_ob_new)
3588 {
3589  Base *base, *basen = nullptr;
3590  Object *obn;
3591 
3592  if (ob->mode & OB_MODE_POSE) {
3593  /* nothing? */
3594  }
3595  else {
3596  obn = static_cast<Object *>(
3597  ID_NEW_SET(ob, BKE_object_duplicate(bmain, ob, dupflag, duplicate_options)));
3598  if (r_ob_new) {
3599  *r_ob_new = obn;
3600  }
3602 
3603  base = BKE_view_layer_base_find(view_layer, ob);
3604  if ((base != nullptr) && (base->flag & BASE_VISIBLE_DEPSGRAPH)) {
3605  BKE_collection_object_add_from(bmain, scene, ob, obn);
3606  }
3607  else {
3608  LayerCollection *layer_collection = BKE_layer_collection_get_active(view_layer);
3609  BKE_collection_object_add(bmain, layer_collection->collection, obn);
3610  }
3611 
3612  basen = BKE_view_layer_base_find(view_layer, obn);
3613  if (base != nullptr && basen != nullptr) {
3614  basen->local_view_bits = base->local_view_bits;
3615  }
3616 
3617  /* 1) duplis should end up in same collection as the original
3618  * 2) Rigid Body sim participants MUST always be part of a collection...
3619  */
3620  /* XXX: is 2) really a good measure here? */
3621  if (ob->rigidbody_object || ob->rigidbody_constraint) {
3622  LISTBASE_FOREACH (Collection *, collection, &bmain->collections) {
3623  if (BKE_collection_has_object(collection, ob)) {
3624  BKE_collection_object_add(bmain, collection, obn);
3625  }
3626  }
3627  }
3628  }
3629  return basen;
3630 }
3631 
3633  Main *bmain, Scene *scene, ViewLayer *view_layer, Base *base, const eDupli_ID_Flags dupflag)
3634 {
3635  Base *basen;
3636  Object *ob;
3637 
3638  basen = object_add_duplicate_internal(bmain,
3639  scene,
3640  view_layer,
3641  base->object,
3642  dupflag,
3645  nullptr);
3646  if (basen == nullptr) {
3647  return nullptr;
3648  }
3649 
3650  ob = basen->object;
3651 
3652  /* Link own references to the newly duplicated data T26816.
3653  * Note that this function can be called from edit-mode code, in which case we may have to
3654  * enforce remapping obdata (by default this is forbidden in edit mode). */
3655  const int remap_flag = BKE_object_is_in_editmode(ob) ? ID_REMAP_FORCE_OBDATA_IN_EDITMODE : 0;
3656  BKE_libblock_relink_to_newid(bmain, &ob->id, remap_flag);
3657 
3658  /* Correct but the caller must do this. */
3659  // DAG_relations_tag_update(bmain);
3660 
3661  if (ob->data != nullptr) {
3663  }
3664 
3666 
3667  return basen;
3668 }
3669 
3670 /* contextual operator dupli */
3672 {
3673  Main *bmain = CTX_data_main(C);
3675  ViewLayer *view_layer = CTX_data_view_layer(C);
3676  const bool linked = RNA_boolean_get(op->ptr, "linked");
3677  const eDupli_ID_Flags dupflag = (linked) ? (eDupli_ID_Flags)0 : (eDupli_ID_Flags)U.dupflag;
3678 
3679  /* We need to handle that here ourselves, because we may duplicate several objects, in which case
3680  * we also want to remap pointers between those... */
3682 
3683  /* Do not do collection re-syncs for each object; will do it once afterwards.
3684  * However this means we can't get to new duplicated Base's immediately, will
3685  * have to process them after the sync. */
3687 
3688  /* Duplicate the selected objects, remember data needed to process
3689  * after the sync (the base of the original object, and the copy of the
3690  * original object). */
3691  blender::Vector<std::pair<Base *, Object *>> source_bases_new_objects;
3692  Object *ob_new_active = nullptr;
3693 
3694  CTX_DATA_BEGIN (C, Base *, base, selected_bases) {
3695  Object *ob_new = NULL;
3697  scene,
3698  view_layer,
3699  base->object,
3700  dupflag,
3702  &ob_new);
3703  if (ob_new == nullptr) {
3704  continue;
3705  }
3706  source_bases_new_objects.append({base, ob_new});
3707 
3708  /* note that this is safe to do with this context iterator,
3709  * the list is made in advance */
3711 
3712  /* new object will become active */
3713  if (BASACT(view_layer) == base) {
3714  ob_new_active = ob_new;
3715  }
3716  }
3717  CTX_DATA_END;
3719 
3720  if (source_bases_new_objects.is_empty()) {
3721  return OPERATOR_CANCELLED;
3722  }
3723 
3724  /* Sync the collection now, after everything is duplicated. */
3725  BKE_main_collection_sync(bmain);
3726 
3727  /* After sync we can get to the new Base data, process it here. */
3728  for (const auto &item : source_bases_new_objects) {
3729  Object *ob_new = item.second;
3730  Base *base_source = item.first;
3731  Base *base_new = BKE_view_layer_base_find(view_layer, ob_new);
3732  if (base_new == nullptr) {
3733  continue;
3734  }
3735  ED_object_base_select(base_new, BA_SELECT);
3736  if (ob_new == ob_new_active) {
3737  ED_object_base_activate(C, base_new);
3738  }
3739  if (base_new->object->data) {
3740  DEG_id_tag_update(static_cast<ID *>(base_new->object->data), 0);
3741  }
3742  /* #object_add_duplicate_internal will not have done this, since
3743  * before the collection sync it would not have found the new base yet. */
3744  base_new->local_view_bits = base_source->local_view_bits;
3745  }
3746 
3747  /* Note that this will also clear newid pointers and tags. */
3749 
3751 
3752  DEG_relations_tag_update(bmain);
3754 
3757 
3758  return OPERATOR_FINISHED;
3759 }
3760 
3762 {
3763  PropertyRNA *prop;
3764 
3765  /* identifiers */
3766  ot->name = "Duplicate Objects";
3767  ot->description = "Duplicate selected objects";
3768  ot->idname = "OBJECT_OT_duplicate";
3769 
3770  /* api callbacks */
3771  ot->exec = duplicate_exec;
3773 
3774  /* flags */
3776 
3777  /* to give to transform */
3778  prop = RNA_def_boolean(ot->srna,
3779  "linked",
3780  false,
3781  "Linked",
3782  "Duplicate object but not object data, linking to the original data");
3784 
3785  prop = RNA_def_enum(
3786  ot->srna, "mode", rna_enum_transform_mode_types, TFM_TRANSLATION, "Mode", "");
3788 }
3789 
3792 /* -------------------------------------------------------------------- */
3799 {
3800  Main *bmain = CTX_data_main(C);
3802  ViewLayer *view_layer = CTX_data_view_layer(C);
3803  const bool linked = RNA_boolean_get(op->ptr, "linked");
3804  const eDupli_ID_Flags dupflag = (linked) ? (eDupli_ID_Flags)0 : (eDupli_ID_Flags)U.dupflag;
3805 
3806  /* Find object, create fake base. */
3807 
3808  Object *ob = reinterpret_cast<Object *>(
3810 
3811  if (ob == nullptr) {
3812  BKE_report(op->reports, RPT_ERROR, "Object not found");
3813  return OPERATOR_CANCELLED;
3814  }
3815 
3816  /* prepare dupli */
3818  bmain,
3819  scene,
3820  view_layer,
3821  ob,
3822  dupflag,
3823  /* Sub-process flag because the new-ID remapping (#BKE_libblock_relink_to_newid()) in this
3824  * function will only work if the object is already linked in the view layer, which is not
3825  * the case here. So we have to do the new-ID relinking ourselves
3826  * (#copy_object_set_idnew()).
3827  */
3829  nullptr);
3830 
3831  if (basen == nullptr) {
3832  BKE_report(op->reports, RPT_ERROR, "Object could not be duplicated");
3833  return OPERATOR_CANCELLED;
3834  }
3835 
3837  /* Do immediately, as #copy_object_set_idnew() below operates on visible objects. */
3838  BKE_base_eval_flags(basen);
3839 
3840  /* object_add_duplicate_internal() doesn't deselect other objects, unlike object_add_common() or
3841  * BKE_view_layer_base_deselect_all(). */
3842  ED_object_base_deselect_all(view_layer, nullptr, SEL_DESELECT);
3844  ED_object_base_activate(C, basen);
3845 
3847 
3848  /* TODO(sergey): Only update relations for the current scene. */
3849  DEG_relations_tag_update(bmain);
3850 
3856 
3857  PropertyRNA *prop_matrix = RNA_struct_find_property(op->ptr, "matrix");
3858  if (RNA_property_is_set(op->ptr, prop_matrix)) {
3859  Object *ob_add = basen->object;
3860  RNA_property_float_get_array(op->ptr, prop_matrix, &ob_add->obmat[0][0]);
3861  BKE_object_apply_mat4(ob_add, ob_add->obmat, true, true);
3862 
3864  }
3865  else {
3866  int mval[2];
3867  if (object_add_drop_xy_get(C, op, &mval)) {
3869  ED_view3d_cursor3d_position(C, mval, false, basen->object->loc);
3870  }
3871  }
3872 
3873  return OPERATOR_FINISHED;
3874 }
3875 
3877 {
3878  /* identifiers */
3879  ot->name = "Add Object";
3880  ot->description = "Add named object";
3881  ot->idname = "OBJECT_OT_add_named";
3882 
3883  /* api callbacks */
3887 
3888  /* flags */
3890 
3891  PropertyRNA *prop;
3893  "linked",
3894  false,
3895  "Linked",
3896  "Duplicate object but not object data, linking to the original data");
3897 
3899 
3900  prop = RNA_def_float_matrix(
3901  ot->srna, "matrix", 4, 4, nullptr, 0.0f, 0.0f, "Matrix", "", 0.0f, 0.0f);
3903 
3905 }
3906 
3909 /* -------------------------------------------------------------------- */
3917 {
3918  Main *bmain = CTX_data_main(C);
3919  ViewLayer *view_layer = CTX_data_view_layer(C);
3920 
3921  Object *ob = reinterpret_cast<Object *>(
3923 
3924  if (!ob) {
3925  ob = OBACT(view_layer);
3926  }
3927 
3928  if (ob == nullptr) {
3929  BKE_report(op->reports, RPT_ERROR, "Object not found");
3930  return OPERATOR_CANCELLED;
3931  }
3932 
3933  /* Don't transform a linked object. There's just nothing to do here in this case, so return
3934  * #OPERATOR_FINISHED. */
3935  if (!BKE_id_is_editable(bmain, &ob->id)) {
3936  return OPERATOR_FINISHED;
3937  }
3938 
3939  /* Ensure the locations are updated so snap reads the evaluated active location. */
3941 
3942  PropertyRNA *prop_matrix = RNA_struct_find_property(op->ptr, "matrix");
3943  if (RNA_property_is_set(op->ptr, prop_matrix)) {
3945  uint objects_len;
3947  view_layer, nullptr, &objects_len, &params);
3948 
3949  float matrix[4][4];
3950  RNA_property_float_get_array(op->ptr, prop_matrix, &matrix[0][0]);
3951 
3952  float mat_src_unit[4][4];
3953  float mat_dst_unit[4][4];
3954  float final_delta[4][4];
3955 
3956  normalize_m4_m4(mat_src_unit, ob->obmat);
3957  normalize_m4_m4(mat_dst_unit, matrix);
3958  invert_m4(mat_src_unit);
3959  mul_m4_m4m4(final_delta, mat_dst_unit, mat_src_unit);
3960 
3961  ED_object_xform_array_m4(objects, objects_len, final_delta);
3962 
3963  MEM_freeN(objects);
3964  }
3965  else {
3966  int mval[2];
3967  if (object_add_drop_xy_get(C, op, &mval)) {
3968  float cursor[3];
3970  ED_view3d_cursor3d_position(C, mval, false, cursor);
3971 
3972  /* Use the active objects location since this is the ID which the user selected to drop.
3973  *
3974  * This transforms all selected objects, so that dropping a single object which links in
3975  * other objects will have their relative transformation preserved.
3976  * For example a child/parent relationship or other objects used with a boolean modifier.
3977  *
3978  * The caller is responsible for ensuring the selection state gives useful results.
3979  * Link/append does this using #FILE_AUTOSELECT. */
3981  }
3982  }
3983 
3984  return OPERATOR_FINISHED;
3985 }
3986 
3988 {
3989  /* identifiers */
3990  ot->name = "Place Object Under Mouse";
3991  ot->description = "Snap selected item(s) to the mouse location";
3992  ot->idname = "OBJECT_OT_transform_to_mouse";
3993 
3994  /* api callbacks */
3998 
3999  /* flags */
4001 
4002  PropertyRNA *prop;
4003  prop = RNA_def_string(
4004  ot->srna,
4005  "name",
4006  nullptr,
4007  MAX_ID_NAME - 2,
4008  "Name",
4009  "Object name to place (uses the active object when this and 'session_uuid' are unset)");
4011  prop = RNA_def_int(ot->srna,
4012  "session_uuid",
4013  0,
4014  INT32_MIN,
4015  INT32_MAX,
4016  "Session UUID",
4017  "Session UUID of the object to place (uses the active object when this and "
4018  "'name' are unset)",
4019  INT32_MIN,
4020  INT32_MAX);
4022 
4023  prop = RNA_def_float_matrix(
4024  ot->srna, "matrix", 4, 4, nullptr, 0.0f, 0.0f, "Matrix", "", 0.0f, 0.0f);
4026 
4028 }
4029 
4032 /* -------------------------------------------------------------------- */
4037 {
4039 
4040  if (ob == nullptr || ob->data == nullptr || ID_IS_LINKED(ob) || ID_IS_OVERRIDE_LIBRARY(ob) ||
4042  return false;
4043  }
4044 
4046  return ED_operator_screenactive(C);
4047  }
4048  return false;
4049 }
4050 
4052 {
4053  Main *bmain = CTX_data_main(C);
4055 
4056  if (ob->mode & OB_MODE_EDIT) {
4057  BKE_report(op->reports, RPT_ERROR, "This data does not support joining in edit mode");
4058  return OPERATOR_CANCELLED;
4059  }
4060  if (BKE_object_obdata_is_libdata(ob)) {
4061  BKE_report(op->reports, RPT_ERROR, "Cannot edit external library data");
4062  return OPERATOR_CANCELLED;
4063  }
4065  BKE_reportf(op->reports,
4066  RPT_WARNING,
4067  "Cannot edit object '%s' as it is used by override collections",
4068  ob->id.name + 2);
4069  return OPERATOR_CANCELLED;
4070  }
4071 
4072  if (ob->type == OB_GPENCIL) {
4073  bGPdata *gpd = (bGPdata *)ob->data;
4074  if ((!gpd) || GPENCIL_ANY_MODE(gpd)) {
4075  BKE_report(op->reports, RPT_ERROR, "This data does not support joining in this mode");
4076  return OPERATOR_CANCELLED;
4077  }
4078  }
4079 
4080  int ret = OPERATOR_CANCELLED;
4081  if (ob->type == OB_MESH) {
4083  }
4084  else if (ELEM(ob->type, OB_CURVES_LEGACY, OB_SURF)) {
4086  }
4087  else if (ob->type == OB_ARMATURE) {
4089  }
4090  else if (ob->type == OB_GPENCIL) {
4092  }
4093 
4094  if (ret & OPERATOR_FINISHED) {
4095  /* Even though internally failure to invert is accounted for with a fallback,
4096  * show a warning since the result may not be what the user expects. See T80077.
4097  *
4098  * Failure to invert the matrix is typically caused by zero scaled axes
4099  * (which can be caused by constraints, even if the input scale isn't zero).
4100  *
4101  * Internally the join functions use #invert_m4_m4_safe_ortho which creates
4102  * an inevitable matrix from one that has one or more degenerate axes.
4103  *
4104  * In most cases we don't worry about special handling for non-inevitable matrices however for
4105  * joining objects there may be flat 2D objects where it's not obvious the scale is zero.
4106  * In this case, using #invert_m4_m4_safe_ortho works as well as we can expect,
4107  * joining the contents, flattening on the axis that's zero scaled.
4108  * If the zero scale is removed, the data on this axis remains un-scaled
4109  * (something that wouldn't work for #invert_m4_m4_safe). */
4110  float imat_test[4][4];
4111  if (!invert_m4_m4(imat_test, ob->obmat)) {
4112  BKE_report(op->reports,
4113  RPT_WARNING,
4114  "Active object final transform has one or more zero scaled axes");
4115  }
4116  }
4117 
4118  return ret;
4119 }
4120 
4122 {
4123  /* identifiers */
4124  ot->name = "Join";
4125  ot->description = "Join selected objects into active object";
4126  ot->idname = "OBJECT_OT_join";
4127 
4128  /* api callbacks */
4131 
4132  /* flags */
4134 }
4135 
4138 /* -------------------------------------------------------------------- */
4143 {
4145 
4146  if (ob == nullptr || ob->data == nullptr || ID_IS_LINKED(ob) || ID_IS_OVERRIDE_LIBRARY(ob) ||
4148  return false;
4149  }
4150 
4151  /* only meshes supported at the moment */
4152  if (ob->type == OB_MESH) {
4153  return ED_operator_screenactive(C);
4154  }
4155  return false;
4156 }
4157 
4159 {
4160  Main *bmain = CTX_data_main(C);
4162 
4163  if (ob->mode & OB_MODE_EDIT) {
4164  BKE_report(op->reports, RPT_ERROR, "This data does not support joining in edit mode");
4165  return OPERATOR_CANCELLED;
4166  }
4167  if (BKE_object_obdata_is_libdata(ob)) {
4168  BKE_report(op->reports, RPT_ERROR, "Cannot edit external library data");
4169  return OPERATOR_CANCELLED;
4170  }
4172  BKE_reportf(op->reports,
4173  RPT_WARNING,
4174  "Cannot edit object '%s' as it is used by override collections",
4175  ob->id.name + 2);
4176  return OPERATOR_CANCELLED;
4177  }
4178 
4179  if (ob->type == OB_MESH) {
4180  return ED_mesh_shapes_join_objects_exec(C, op);
4181  }
4182 
4183  return OPERATOR_CANCELLED;
4184 }
4185 
4187 {
4188  /* identifiers */
4189  ot->name = "Join as Shapes";
4190  ot->description = "Copy the current resulting shape of another selected object to this one";
4191  ot->idname = "OBJECT_OT_join_shapes";
4192 
4193  /* api callbacks */
4196 
4197  /* flags */
4199 }
4200 
typedef float(TangentPoint)[2]
Blender kernel action and pose functionality.
void BKE_animdata_free(struct ID *id, bool do_id_user)
Definition: anim_data.c:197
struct AnimData * BKE_animdata_ensure_id(struct ID *id)
Definition: anim_data.c:90
Camera data-block and utility functions.
bool BKE_collection_cycle_find(struct Collection *new_ancestor, struct Collection *collection)
Definition: collection.c:1435
#define FOREACH_SCENE_OBJECT_END
void BKE_collection_object_add_from(struct Main *bmain, struct Scene *scene, struct Object *ob_src, struct Object *ob_dst)
Definition: collection.c:1148
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_child_remove(struct Main *bmain, struct Collection *parent, struct Collection *child)
Definition: collection.c:1600
bool BKE_scene_collections_object_remove(struct Main *bmain, struct Scene *scene, struct Object *object, bool free_us)
Definition: collection.c:1224
#define FOREACH_SCENE_OBJECT_BEGIN(scene, _instance)
void BKE_constraints_free(struct ListBase *list)
Definition: constraint.c:5587
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
int CTX_data_selected_editable_bases(const bContext *C, ListBase *list)
Definition: context.c:1308
struct Base * CTX_data_active_base(const bContext *C)
Definition: context.c:1358
struct LayerCollection * CTX_data_layer_collection(const bContext *C)
Definition: context.c:1126
struct wmWindowManager * CTX_wm_manager(const bContext *C)
Definition: context.c:713
#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 ARegion * CTX_wm_region(const bContext *C)
Definition: context.c:749
void CTX_wm_operator_poll_msg_set(struct bContext *C, const char *msg)
Definition: context.c:1042
struct Main * CTX_data_main(const bContext *C)
Definition: context.c:1074
struct RegionView3D * CTX_wm_region_view3d(const bContext *C)
Definition: context.c:793
#define CTX_DATA_END
Definition: BKE_context.h:278
void BKE_curve_dimension_update(struct Curve *cu)
Definition: curve.cc:465
Low-level operations for curves that cannot be defined in the C++ header yet.
void CustomData_MeshMasks_update(CustomData_MeshMasks *mask_dst, const CustomData_MeshMasks *mask_src)
Definition: customdata.cc:77
const char * CustomData_get_active_layer_name(const struct CustomData *data, int type)
const CustomData_MeshMasks CD_MASK_MESH
Definition: customdata.cc:2065
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_displist_make_mball(struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob)
Definition: displist.cc:641
struct ListBase * object_duplilist(struct Depsgraph *depsgraph, struct Scene *sce, struct Object *ob)
void free_object_duplilist(struct ListBase *lb)
struct PartDeflect * BKE_partdeflect_new(int type)
Definition: effect.c:71
bool BKE_object_has_geometry_set_instances(const struct Object *ob)
void BKE_gpencil_convert_curve(struct Main *bmain, struct Scene *scene, struct Object *ob_gp, struct Object *ob_cu, bool use_collections, float scale_thickness, float sample)
bool BKE_gpencil_convert_mesh(struct Main *bmain, struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob_gp, struct Object *ob_mesh, float angle, int thickness, float offset, const float matrix[4][4], int frame_offset, bool use_seams, bool use_faces, bool use_vgroups)
bool BKE_gpencil_modifier_unique_name(struct ListBase *modifiers, struct GpencilModifierData *gmd)
struct GpencilModifierData * BKE_gpencil_modifier_new(int type)
void BKE_base_eval_flags(struct Base *base)
Definition: layer.c:2200
struct LayerCollection * BKE_layer_collection_get_active(struct ViewLayer *view_layer)
Definition: layer.c:636
void BKE_main_collection_sync(const struct Main *bmain)
void BKE_layer_collection_resync_allow(void)
Definition: layer.c:766
struct LayerCollection * BKE_layer_collection_activate_parent(struct ViewLayer *view_layer, struct LayerCollection *lc)
Definition: layer.c:651
struct Base * BKE_view_layer_base_find(struct ViewLayer *view_layer, struct Object *ob)
Definition: layer.c:379
struct Object ** BKE_view_layer_array_selected_objects_params(struct ViewLayer *view_layer, const struct View3D *v3d, uint *r_len, const struct ObjectsInViewLayerParams *params)
Definition: layer_utils.c:28
void BKE_layer_collection_resync_forbid(void)
Definition: layer.c:761
struct ID * BKE_id_copy(struct Main *bmain, const struct ID *id)
void BKE_main_id_newptr_and_tag_clear(struct Main *bmain)
Definition: lib_id.c:1465
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
#define IS_TAGGED(_id)
Definition: BKE_lib_id.h:639
void * BKE_id_new(struct Main *bmain, short type, const char *name)
Definition: lib_id.c:1159
void BKE_main_id_tag_listbase(struct ListBase *lb, int tag, bool value)
Definition: lib_id.c:904
size_t BKE_id_multi_tagged_delete(struct Main *bmain) ATTR_NONNULL()
eLibIDDuplicateFlags
Definition: BKE_lib_id.h:219
@ LIB_ID_DUPLICATE_IS_ROOT_ID
Definition: BKE_lib_id.h:228
@ LIB_ID_DUPLICATE_IS_SUBPROCESS
Definition: BKE_lib_id.h:225
bool BKE_lib_override_library_id_is_user_deletable(struct Main *bmain, struct ID *id)
bool BKE_library_ID_is_indirectly_used(struct Main *bmain, void *idv)
Definition: lib_query.c:615
@ ID_REMAP_FORCE_OBDATA_IN_EDITMODE
Definition: BKE_lib_remap.h:80
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.
void BKE_lightprobe_type_set(struct LightProbe *probe, short lightprobe_type)
Definition: lightprobe.c:100
#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.
bool BKE_object_material_slot_remove(struct Main *bmain, struct Object *ob)
Definition: material.c:1248
bool BKE_object_material_slot_used(struct Object *object, short actcol)
Definition: material.c:452
struct Material * BKE_gpencil_material(struct Object *ob, short act)
Definition: material.c:795
void BKE_object_materials_test(struct Main *bmain, struct Object *ob, struct ID *id)
Definition: material.c:864
short * BKE_id_material_len_p(struct ID *id)
Definition: material.c:403
void BKE_object_material_from_eval_data(struct Main *bmain, struct Object *ob_orig, const struct ID *data_eval)
struct Object * BKE_mball_basis_find(struct Scene *scene, struct Object *ob)
Definition: mball.c:508
bool BKE_mball_is_basis(const struct Object *ob)
struct Mesh * BKE_mesh_copy_for_eval(const struct Mesh *source, bool reference)
struct Mesh * BKE_mesh_new_from_object_to_bmain(struct Main *bmain, struct Depsgraph *depsgraph, struct Object *object, bool preserve_all_data_layers)
void BKE_mesh_edges_set_draw_render(struct Mesh *me)
void BKE_mesh_nomain_to_mesh(struct Mesh *mesh_src, struct Mesh *mesh_dst, struct Object *ob, const struct CustomData_MeshMasks *mask, bool take_ownership)
void BKE_pointcloud_to_mesh(struct Main *bmain, struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob)
void BKE_mesh_from_metaball(struct ListBase *lb, struct Mesh *me)
Definition: mesh_convert.cc:72
struct Mesh * BKE_mesh_add(struct Main *bmain, const char *name)
Definition: mesh.cc:963
void BKE_mesh_to_pointcloud(struct Main *bmain, struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob)
void BKE_mesh_merge_customdata_for_apply_modifier(struct Mesh *me)
void BKE_mesh_to_curve(struct Main *bmain, struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob)
struct Mesh * mesh_get_eval_final(struct Depsgraph *depsgraph, const struct Scene *scene, struct Object *ob, const struct CustomData_MeshMasks *dataMask)
void BKE_nlastrip_validate_name(struct AnimData *adt, struct NlaStrip *strip)
Definition: nla.c:1625
bool BKE_nlatrack_add_strip(struct NlaTrack *nlt, struct NlaStrip *strip, bool is_liboverride)
Definition: nla.c:1168
struct NlaStrip * BKE_nla_add_soundstrip(struct Main *bmain, struct Scene *scene, struct Speaker *speaker)
Definition: nla.c:477
struct NlaTrack * BKE_nlatrack_add(struct AnimData *adt, struct NlaTrack *prev, bool is_liboverride)
Definition: nla.c:353
General operations, lookup, etc. for blender objects.
void BKE_object_empty_draw_type_set(struct Object *ob, int value)
Definition: object.cc:3937
void BKE_object_free_modifiers(struct Object *ob, int flag)
Definition: object.cc:1289
bool BKE_object_obdata_is_libdata(const struct Object *ob)
void BKE_object_obdata_size_init(struct Object *ob, float size)
Definition: object.cc:2842
struct Object * BKE_object_add(struct Main *bmain, struct ViewLayer *view_layer, int type, const char *name) ATTR_NONNULL(1
void BKE_object_to_mat4(struct Object *ob, float r_mat[4][4])
Definition: object.cc:3082
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_free_derived_caches(struct Object *ob)
Definition: object.cc:1774
void BKE_object_free_curve_cache(struct Object *ob)
Definition: object.cc:1275
void BKE_object_free_shaderfx(struct Object *ob, int flag)
Definition: object.cc:1311
int BKE_object_obdata_to_type(const struct ID *id) ATTR_NONNULL(1)
struct Object * BKE_object_duplicate(struct Main *bmain, struct Object *ob, uint dupflag, uint duplicate_options)
Definition: object.cc:2661
struct Object * BKE_object_add_for_data(struct Main *bmain, struct ViewLayer *view_layer, int type, const char *name, struct ID *data, bool do_id_user) ATTR_RETURNS_NONNULL
Definition: object.cc:2299
bool BKE_object_is_in_editmode(const struct Object *ob)
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
void BKE_scene_cursor_rot_to_mat3(const struct View3DCursor *cursor, float mat[3][3])
void BKE_scene_object_base_flag_sync_from_base(struct Base *base)
Definition: scene.cc:2896
General operations for speakers.
bool BKE_vfont_to_curve_ex(struct Object *ob, struct Curve *cu, int mode, struct ListBase *r_nubase, const char32_t **r_text, int *r_text_len, bool *r_text_free, struct CharTrans **r_chartransdata)
Definition: vfont.c:1709
Volume data-block.
#define BLI_assert(a)
Definition: BLI_assert.h:46
unsigned int BLI_ghashutil_ptrhash(const void *key)
GHash * BLI_ghash_new(GHashHashFP hashfp, GHashCmpFP cmpfp, const char *info) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT
Definition: BLI_ghash.c:689
void * BLI_ghash_lookup(const GHash *gh, const void *key) ATTR_WARN_UNUSED_RESULT
Definition: BLI_ghash.c:734
void BLI_ghash_insert(GHash *gh, void *key, void *val)
Definition: BLI_ghash.c:710
void BLI_ghash_free(GHash *gh, GHashKeyFreeFP keyfreefp, GHashValFreeFP valfreefp)
Definition: BLI_ghash.c:863
GHash * BLI_ghash_ptr_new(const char *info) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT
bool BLI_ghash_ensure_p(GHash *gh, void *key, void ***r_val) ATTR_WARN_UNUSED_RESULT
Definition: BLI_ghash.c:755
#define BLI_ghashutil_inthash(key)
Definition: BLI_ghash.h:579
BLI_INLINE bool BLI_listbase_is_empty(const struct ListBase *lb)
Definition: BLI_listbase.h:269
#define LISTBASE_FOREACH(type, var, list)
Definition: BLI_listbase.h:336
void void BLI_freelistN(struct ListBase *listbase) ATTR_NONNULL(1)
Definition: listbase.c:466
void BLI_addtail(struct ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition: listbase.c:80
void * BLI_findlink(const struct ListBase *listbase, int number) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
#define M_PI_2
Definition: BLI_math_base.h:23
void mul_m3_v3(const float M[3][3], float r[3])
Definition: math_matrix.c:926
void mul_m4_m4m4(float R[4][4], const float A[4][4], const float B[4][4])
Definition: math_matrix.c:259
void mul_mat3_m4_fl(float R[4][4], float f)
Definition: math_matrix.c:978
bool invert_m4(float R[4][4])
Definition: math_matrix.c:1206
void copy_m3_m4(float m1[3][3], const float m2[4][4])
Definition: math_matrix.c:87
void unit_m4(float m[4][4])
Definition: rct.c:1090
void copy_m4_m3(float m1[4][4], const float m2[3][3])
Definition: math_matrix.c:102
void translate_m4(float mat[4][4], float tx, float ty, float tz)
Definition: math_matrix.c:2318
bool invert_m4_m4(float R[4][4], const float A[4][4])
Definition: math_matrix.c:1287
void mat4_to_loc_rot_size(float loc[3], float rot[3][3], float size[3], const float wmat[4][4])
Definition: math_matrix.c:2224
void rescale_m4(float mat[4][4], const float scale[3])
Definition: math_matrix.c:2362
void normalize_m4_m4(float R[4][4], const float M[4][4]) ATTR_NONNULL()
Definition: math_matrix.c:1965
bool invert_m3_m3(float R[3][3], const float A[3][3])
Definition: math_matrix.c:1180
void copy_m4_m4(float m1[4][4], const float m2[4][4])
Definition: math_matrix.c:77
bool invert_m3(float R[3][3])
Definition: math_matrix.c:1171
void loc_eul_size_to_mat4(float R[4][4], const float loc[3], const float eul[3], const float size[3])
Definition: math_matrix.c:2547
void mul_m3_m3m3(float R[3][3], const float A[3][3], const float B[3][3])
Definition: math_matrix.c:388
void eul_to_mat3(float mat[3][3], const float eul[3])
void axis_angle_to_quat(float r[4], const float axis[3], float angle)
#define DEG2RADF(_deg)
void quat_to_eul(float eul[3], const float quat[4])
void mat3_normalized_to_eul(float eul[3], const float mat[3][3])
void mul_qt_qtqt(float q[4], const float a[4], const float b[4])
Definition: math_rotation.c:46
void mat3_to_eul(float eul[3], const float mat[3][3])
void copy_qt_qt(float q[4], const float a[4])
Definition: math_rotation.c:33
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 negate_v3_v3(float r[3], const float a[3])
MINLINE void copy_v3_fl(float r[3], float f)
MINLINE void zero_v3(float r[3])
#define FILE_MAX
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(x)
#define UNPACK3(a)
#define ELEM(...)
#define BLT_I18NCONTEXT_ID_ID
#define BLT_I18NCONTEXT_ID_GPENCIL
#define BLT_I18NCONTEXT_ID_LIGHT
#define BLT_I18NCONTEXT_ID_OBJECT
#define CTX_DATA_(context, msgid)
#define DATA_(msgid)
struct Depsgraph Depsgraph
Definition: DEG_depsgraph.h:35
void DEG_id_type_tag(struct Main *bmain, short id_type)
void DEG_id_tag_update_ex(struct Main *bmain, struct ID *id, int flag)
void DEG_id_tag_update(struct ID *id, int flag)
void DEG_graph_tag_relations_update(struct Depsgraph *graph)
void DEG_relations_tag_update(struct Main *bmain)
struct Object * DEG_get_original_object(struct Object *object)
struct ID * DEG_get_evaluated_id(const struct Depsgraph *depsgraph, struct ID *id)
struct Object * DEG_get_evaluated_object(const struct Depsgraph *depsgraph, struct Object *object)
#define ID_EXTRA_USERS(id)
Definition: DNA_ID.h:554
@ 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_EDITORS
Definition: DNA_ID.h:828
@ 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_LINKED(_id)
Definition: DNA_ID.h:566
#define MAX_ID_NAME
Definition: DNA_ID.h:337
@ LIB_TAG_INDIRECT
Definition: DNA_ID.h:677
@ LIB_TAG_NEW
Definition: DNA_ID.h:704
@ LIB_TAG_DOIT
Definition: DNA_ID.h:707
#define ID_REAL_USERS(id)
Definition: DNA_ID.h:553
#define ID_IS_OVERRIDE_LIBRARY(_id)
Definition: DNA_ID.h:588
#define ID_NEW_SET(_id, _idn)
Definition: DNA_ID.h:617
ID_Type
Definition: DNA_ID_enums.h:44
@ ID_IM
Definition: DNA_ID_enums.h:53
@ ID_CV
Definition: DNA_ID_enums.h:81
@ ID_GR
Definition: DNA_ID_enums.h:65
@ ID_OB
Definition: DNA_ID_enums.h:47
Object groups, one object can be in many groups at once.
@ CU_NURBS
@ CU_PRIM_PATH
@ CU_3D
@ CU_PATH
@ CD_MLOOPUV
@ eGpencilModifierType_Lineart
@ GP_DRAWMODE_3D
@ GP_DRAWMODE_2D
#define GPENCIL_ANY_MODE(gpd)
@ BASE_VISIBLE_DEPSGRAPH
@ BASE_SELECTED
#define LA_AREA
#define LA_SPOT
#define LA_SUN
#define LA_LOCAL
@ LIGHTPROBE_TYPE_CUBE
@ LIGHTPROBE_TYPE_PLANAR
@ LIGHTPROBE_TYPE_GRID
@ OB_MODE_EDIT
@ OB_MODE_POSE
@ OB_MODE_OBJECT
@ NUM_PFIELD_TYPES
@ PFIELD_MAGNET
@ PFIELD_FLUIDFLOW
@ PFIELD_FORCE
@ PFIELD_CHARGE
@ PFIELD_HARMONIC
@ PFIELD_TURBULENCE
@ PFIELD_GUIDE
@ PFIELD_LENNARDJ
@ PFIELD_VORTEX
@ PFIELD_TEXTURE
Object is a sort of wrapper for general info.
@ OB_HIDE_VIEWPORT
#define OB_DONE
@ OB_SINGLE_ARROW
@ OB_EMPTY_IMAGE
#define MAX_DUPLI_RECUR
@ OB_MODIFIER_FLAG_ADD_REST_POSITION
@ OB_SPEAKER
@ OB_LATTICE
@ OB_MBALL
@ OB_EMPTY
@ OB_SURF
@ OB_CAMERA
@ OB_FONT
@ OB_ARMATURE
@ OB_LAMP
@ OB_MESH
@ OB_POINTCLOUD
@ OB_CURVES_LEGACY
@ OB_CURVES
@ OB_GPENCIL
@ OB_LIGHTPROBE
@ GP_STROKE
@ GP_MONKEY
@ GP_EMPTY
@ GP_LRT_OBJECT
@ GP_LRT_COLLECTION
@ GP_LRT_SCENE
@ OB_DRAWBOUNDOX
@ OB_USE_GPENCIL_LIGHTS
@ OB_DRAW_IN_FRONT
@ OB_DUPLI
@ OB_DUPLICOLLECTION
@ PAROBJECT
#define OBEDIT_FROM_VIEW_LAYER(view_layer)
#define BASACT(_view_layer)
#define OBACT(_view_layer)
eDupli_ID_Flags
@ USER_ADD_VIEWALIGNED
@ USER_ADD_CURSORALIGNED
@ USER_ADD_EDITMODE
#define FO_EDIT
@ V3D_AROUND_ACTIVE
@ OPERATOR_CANCELLED
@ OPERATOR_FINISHED
struct MetaElem * ED_mball_add_primitive(struct bContext *C, struct Object *obedit, bool obedit_is_new, float mat[4][4], float dia, int type)
int ED_mesh_shapes_join_objects_exec(struct bContext *C, struct wmOperator *op)
Definition: meshtools.cc:747
int ED_mesh_join_objects_exec(struct bContext *C, struct wmOperator *op)
Definition: meshtools.cc:314
@ EM_FREEDATA
Definition: ED_object.h:242
@ PAR_OBJECT
Definition: ED_object.h:138
void ED_object_base_select(struct Base *base, eObjectSelect_Mode mode)
Definition: object_select.c:76
bool ED_object_editmode_exit_ex(struct Main *bmain, struct Scene *scene, struct Object *obedit, int flag)
Definition: object_edit.c:653
#define OBJECT_ADD_SIZE_MAXF
Definition: ED_object.h:341
bool ED_object_editmode_enter_ex(struct Main *bmain, struct Scene *scene, struct Object *ob, int flag)
Definition: object_edit.c:734
void ED_object_base_activate(struct bContext *C, struct Base *base)
@ BA_DESELECT
Definition: ED_object.h:154
@ BA_SELECT
Definition: ED_object.h:155
void ED_object_xform_array_m4(struct Object **objects, uint objects_len, const float matrix[4][4])
Definition: object_utils.c:434
bool ED_object_base_deselect_all(struct ViewLayer *view_layer, struct View3D *v3d, int action)
bool ED_object_parent_set(struct ReportList *reports, const struct bContext *C, struct Scene *scene, struct Object *const ob, struct Object *const par, int partype, bool xmirror, bool keep_transform, const int vert_par[3])
void ED_outliner_select_sync_from_object_tag(struct bContext *C)
void ED_rigidbody_object_remove(struct Main *bmain, struct Scene *scene, struct Object *ob)
bool ED_operator_screenactive(struct bContext *C)
Definition: screen_ops.c:119
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_scene_editable(struct bContext *C)
Definition: screen_ops.c:177
@ SEL_DESELECT
@ TFM_TRANSLATION
Definition: ED_transform.h:30
bool ED_view3d_snap_selected_to_location(struct bContext *C, const float snap_target_global[3], int pivot_point)
Definition: view3d_snap.c:573
float ED_scene_grid_scale(const struct Scene *scene, const char **r_grid_unit)
float ED_view3d_grid_scale(const struct Scene *scene, struct View3D *v3d, const char **r_grid_unit)
void ED_view3d_cursor3d_position(struct bContext *C, const int mval[2], bool use_depth, float r_cursor_co[3])
Definition: view3d_edit.c:823
struct Object * ED_view3d_give_object_under_cursor(struct bContext *C, const int mval[2])
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum type
float float4x4[4][4]
Read Guarded memory(de)allocation.
const EnumPropertyItem * RNA_collection_itemf(struct bContext *C, struct PointerRNA *ptr, struct PropertyRNA *prop, bool *r_free)
PropertyFlag
Definition: RNA_types.h:183
@ 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 uiLayoutSetActive(uiLayout *layout, bool active)
uiLayout * uiLayoutColumn(uiLayout *layout, bool align)
void uiLayoutSetPropSep(uiLayout *layout, bool is_sep)
void uiItemR(uiLayout *layout, struct PointerRNA *ptr, const char *propname, int flag, const char *name, int icon)
@ OPTYPE_INTERNAL
Definition: WM_types.h:168
@ OPTYPE_UNDO
Definition: WM_types.h:148
@ OPTYPE_REGISTER
Definition: WM_types.h:146
#define ND_DRAW
Definition: WM_types.h:410
#define ND_OB_ACTIVE
Definition: WM_types.h:388
#define ND_DATA
Definition: WM_types.h:456
#define NC_ANIMATION
Definition: WM_types.h:338
#define ND_OB_SELECT
Definition: WM_types.h:390
#define NC_SCENE
Definition: WM_types.h:328
#define NA_ADDED
Definition: WM_types.h:525
#define ND_LAYER_CONTENT
Definition: WM_types.h:402
#define ND_MODIFIER
Definition: WM_types.h:411
#define ND_PARENT
Definition: WM_types.h:416
#define NC_GPENCIL
Definition: WM_types.h:349
#define ND_NLA
Definition: WM_types.h:445
#define NC_OBJECT
Definition: WM_types.h:329
EditBone * ED_armature_ebone_add_primitive(Object *obedit_arm, float length, bool view_aligned)
Definition: armature_add.c:86
int ED_armature_join_objects_exec(bContext *C, wmOperator *op)
int main(int argc, char *argv[])
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
Definition: btDbvt.cpp:52
unsigned int U
Definition: btGjkEpa3.h:78
SIMD_FORCE_INLINE btScalar angle(const btVector3 &v) const
Return the angle between this and another vector.
Definition: btVector3.h:356
const Curves * get_for_read() const
void append(const T &value)
Definition: BLI_vector.hh:433
bool is_empty() const
Definition: BLI_vector.hh:706
static CurvesGeometry & wrap(::CurvesGeometry &dna_struct)
Definition: BKE_curves.hh:138
#define SELECT
Scene scene
Curve curve
const Depsgraph * depsgraph
int ED_curve_join_objects_exec(bContext *C, wmOperator *op)
Definition: editcurve.c:6863
Nurb * ED_curve_add_nurbs_primitive(bContext *C, Object *obedit, float mat[4][4], int type, int newob)
#define rot(x, k)
void ED_gpencil_create_blank(bContext *C, Object *ob, float UNUSED(mat[4][4]))
void ED_gpencil_create_lineart(bContext *C, Object *ob)
void ED_gpencil_create_monkey(bContext *C, Object *ob, float mat[4][4])
void ED_gpencil_create_stroke(bContext *C, Object *ob, float mat[4][4])
int ED_gpencil_join_objects_exec(bContext *C, wmOperator *op)
Object * ED_gpencil_add_object(bContext *C, const float loc[3], ushort local_view_bits)
void ED_gpencil_add_defaults(bContext *C, Object *ob)
uint col
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
#define GS(x)
Definition: iris.c:225
ccl_gpu_kernel_postfix ccl_global float int int int int float bool int offset
void(* MEM_freeN)(void *vmemh)
Definition: mallocn.c:27
void *(* MEM_dupallocN)(const void *vmemh)
Definition: mallocn.c:28
static unsigned a[3]
Definition: RandGen.cpp:78
MutableAttributeAccessor mesh_attributes_for_write(Mesh &mesh)
bke::CurvesGeometry primitive_random_sphere(const int curves_size, const int points_per_curve)
Definition: curves_add.cc:99
void ensure_surface_deformation_node_exists(bContext &C, Object &curves_ob)
Definition: curves_add.cc:58
vec_base< float, 3 > float3
static const pxr::TfToken b("b", pxr::TfToken::Immortal)
#define hash
Definition: noise.c:153
static void object_add_ui(bContext *UNUSED(C), wmOperator *op)
Definition: object_add.cc:1475
static void view_align_update(struct Main *UNUSED(main), struct Scene *UNUSED(scene), struct PointerRNA *ptr)
Definition: object_add.cc:375
static bool object_gpencil_add_poll(bContext *C)
Definition: object_add.cc:1294
void ED_object_add_unit_props_size(wmOperatorType *ot)
Definition: object_add.cc:382
void OBJECT_OT_curves_empty_hair_add(wmOperatorType *ot)
Definition: object_add.cc:2124
static uint dupliobject_hash(const void *ptr)
Definition: object_add.cc:2405
static const EnumPropertyItem convert_target_items[]
Definition: object_add.cc:2743
static int object_delete_exec(bContext *C, wmOperator *op)
Definition: object_add.cc:2218
static bool object_convert_poll(bContext *C)
Definition: object_add.cc:2826
void OBJECT_OT_drop_named_image(wmOperatorType *ot)
Definition: object_add.cc:1257
static const EnumPropertyItem align_options[]
Definition: object_add.cc:181
void OBJECT_OT_convert(wmOperatorType *ot)
Definition: object_add.cc:3510
void OBJECT_OT_speaker_add(wmOperatorType *ot)
Definition: object_add.cc:2010
static int object_curves_empty_hair_add_exec(bContext *C, wmOperator *op)
Definition: object_add.cc:2069
static int collection_instance_add_exec(bContext *C, wmOperator *op)
Definition: object_add.cc:1717
static int empty_drop_named_image_invoke(bContext *C, wmOperator *op, const wmEvent *event)
Definition: object_add.cc:1209
static int object_add_drop_xy_generic_invoke(bContext *C, wmOperator *op, const wmEvent *event)
Definition: object_add.cc:253
static int object_instance_add_invoke(bContext *C, wmOperator *op, const wmEvent *event)
Definition: object_add.cc:1739
void OBJECT_OT_transform_to_mouse(wmOperatorType *ot)
Definition: object_add.cc:3987
static bool dupliobject_instancer_cmp(const void *a_, const void *b_)
Definition: object_add.cc:2472
void ED_object_rotation_from_view(bContext *C, float rot[3], const char align_axis)
Definition: object_add.cc:300
void OBJECT_OT_metaball_add(wmOperatorType *ot)
Definition: object_add.cc:1024
void OBJECT_OT_add_named(wmOperatorType *ot)
Definition: object_add.cc:3876
void OBJECT_OT_duplicate(wmOperatorType *ot)
Definition: object_add.cc:3761
void OBJECT_OT_effector_add(wmOperatorType *ot)
Definition: object_add.cc:889
static int join_shapes_exec(bContext *C, wmOperator *op)
Definition: object_add.cc:4158
void OBJECT_OT_light_add(wmOperatorType *ot)
Definition: object_add.cc:1619
Object * ED_object_add_type(bContext *C, const int type, const char *name, const float loc[3], const float rot[3], const bool enter_editmode, const ushort local_view_bits)
Definition: object_add.cc:668
static bool dupliobject_cmp(const void *a_, const void *b_)
Definition: object_add.cc:2438
void ED_object_base_init_transform_on_add(Object *object, const float loc[3], const float rot[3])
Definition: object_add.cc:315
void OBJECT_OT_delete(wmOperatorType *ot)
Definition: object_add.cc:2325
static void object_data_convert_ensure_curve_cache(Depsgraph *depsgraph, Scene *scene, Object *ob)
Definition: object_add.cc:2774
void ED_object_add_unit_props_radius_ex(wmOperatorType *ot, float default_value)
Definition: object_add.cc:388
static const char * get_effector_defname(ePFieldType type)
Definition: object_add.cc:803
void OBJECT_OT_empty_add(wmOperatorType *ot)
Definition: object_add.cc:1187
void OBJECT_OT_lightprobe_add(wmOperatorType *ot)
Definition: object_add.cc:774
static int object_add_named_exec(bContext *C, wmOperator *op)
Definition: object_add.cc:3798
Object * ED_object_add_type_with_obdata(bContext *C, const int type, const char *name, const float loc[3], const float rot[3], const bool enter_editmode, const ushort local_view_bits, ID *obdata)
Definition: object_add.cc:598
void ED_object_base_free_and_unlink(Main *bmain, Scene *scene, Object *ob)
Definition: object_add.cc:2190
static int object_pointcloud_add_exec(bContext *C, wmOperator *op)
Definition: object_add.cc:2152
static void object_add_drop_xy_props(wmOperatorType *ot)
Definition: object_add.cc:198
static const char * get_lightprobe_defname(int type)
Definition: object_add.cc:736
static bool object_add_drop_xy_get(bContext *C, wmOperator *op, int(*r_mval)[2])
Definition: object_add.cc:234
static int collection_drop_exec(bContext *C, wmOperator *op)
Definition: object_add.cc:1804
void OBJECT_OT_duplicates_make_real(wmOperatorType *ot)
Definition: object_add.cc:2713
static int object_transform_to_mouse_exec(bContext *C, wmOperator *op)
Definition: object_add.cc:3916
static int object_add_text_exec(bContext *C, wmOperator *op)
Definition: object_add.cc:1051
void OBJECT_OT_text_add(wmOperatorType *ot)
Definition: object_add.cc:1073
void ED_object_location_from_view(bContext *C, float loc[3])
Definition: object_add.cc:268
void OBJECT_OT_add(wmOperatorType *ot)
Definition: object_add.cc:707
static int object_add_exec(bContext *C, wmOperator *op)
Definition: object_add.cc:681
static int lightprobe_add_exec(bContext *C, wmOperator *op)
Definition: object_add.cc:750
static uint dupliobject_instancer_hash(const void *ptr)
Definition: object_add.cc:2427
static int object_light_add_exec(bContext *C, wmOperator *op)
Definition: object_add.cc:1579
void OBJECT_OT_pointcloud_add(wmOperatorType *ot)
Definition: object_add.cc:2167
static bool object_curves_empty_hair_add_poll(bContext *C)
Definition: object_add.cc:2111
static int object_empty_add_exec(bContext *C, wmOperator *op)
Definition: object_add.cc:1167
static int object_speaker_add_exec(bContext *C, wmOperator *op)
Definition: object_add.cc:1973
static int object_join_exec(bContext *C, wmOperator *op)
Definition: object_add.cc:4051
static bool object_add_drop_xy_is_set(const wmOperator *op)
Definition: object_add.cc:224
const EnumPropertyItem rna_enum_light_type_items[]
Definition: object_add.cc:130
void OBJECT_OT_curves_random_add(wmOperatorType *ot)
Definition: object_add.cc:2052
static int object_duplicates_make_real_exec(bContext *C, wmOperator *op)
Definition: object_add.cc:2686
static EnumPropertyItem lightprobe_type_items[]
Definition: object_add.cc:156
static int object_curves_random_add_exec(bContext *C, wmOperator *op)
Definition: object_add.cc:2033
static Base * object_add_duplicate_internal(Main *bmain, Scene *scene, ViewLayer *view_layer, Object *ob, const eDupli_ID_Flags dupflag, const eLibIDDuplicateFlags duplicate_options, Object **r_ob_new)
Definition: object_add.cc:3581
static std::optional< CollectionAddInfo > collection_add_info_get_from_op(bContext *C, wmOperator *op)
Definition: object_add.cc:1660
static void make_object_duplilist_real(bContext *C, Depsgraph *depsgraph, Scene *scene, Base *base, const bool use_base_parent, const bool use_hierarchy)
Definition: object_add.cc:2490
void ED_object_base_free_and_unlink_no_indirect_check(Main *bmain, Scene *scene, Object *ob)
Definition: object_add.cc:2211
static bool join_shapes_poll(bContext *C)
Definition: object_add.cc:4142
static int object_data_instance_add_exec(bContext *C, wmOperator *op)
Definition: object_add.cc:1904
void ED_object_rotation_from_quat(float rot[3], const float viewquat[4], const char align_axis)
Definition: object_add.cc:274
static int duplicate_exec(bContext *C, wmOperator *op)
Definition: object_add.cc:3671
static const EnumPropertyItem field_type_items[]
Definition: object_add.cc:139
static int object_armature_add_exec(bContext *C, wmOperator *op)
Definition: object_add.cc:1098
static int object_metaball_add_exec(bContext *C, wmOperator *op)
Definition: object_add.cc:978
void OBJECT_OT_collection_external_asset_drop(wmOperatorType *ot)
Definition: object_add.cc:1856
bool ED_object_add_generic_get_opts(bContext *C, wmOperator *op, const char view_align_axis, float r_loc[3], float r_rot[3], float r_scale[3], bool *r_enter_editmode, ushort *r_local_view_bits, bool *r_is_view_aligned)
Definition: object_add.cc:457
float ED_object_new_primitive_matrix(bContext *C, Object *obedit, const float loc[3], const float rot[3], const float scale[3], float r_primmat[4][4])
Definition: object_add.cc:328
static void object_convert_ui(bContext *UNUSED(C), wmOperator *op)
Definition: object_add.cc:3488
static int object_camera_add_exec(bContext *C, wmOperator *op)
Definition: object_add.cc:916
static int object_convert_exec(bContext *C, wmOperator *op)
Definition: object_add.cc:2892
Base * ED_object_add_duplicate(Main *bmain, Scene *scene, ViewLayer *view_layer, Base *base, const eDupli_ID_Flags dupflag)
Definition: object_add.cc:3632
void OBJECT_OT_join(wmOperatorType *ot)
Definition: object_add.cc:4121
static int effector_add_exec(bContext *C, wmOperator *op)
Definition: object_add.cc:842
void OBJECT_OT_collection_instance_add(wmOperatorType *ot)
Definition: object_add.cc:1752
void OBJECT_OT_armature_add(wmOperatorType *ot)
Definition: object_add.cc:1142
static void copy_object_set_idnew(bContext *C)
Definition: object_add.cc:2354
void OBJECT_OT_camera_add(wmOperatorType *ot)
Definition: object_add.cc:949
static void object_data_convert_curve_to_mesh(Main *bmain, Depsgraph *depsgraph, Object *ob)
Definition: object_add.cc:2793
void ED_object_add_mesh_props(wmOperatorType *ot)
Definition: object_add.cc:452
static EnumPropertyItem rna_enum_gpencil_add_stroke_depth_order_items[]
Definition: object_add.cc:1499
@ ALIGN_VIEW
Definition: object_add.cc:177
@ ALIGN_WORLD
Definition: object_add.cc:176
@ ALIGN_CURSOR
Definition: object_add.cc:178
static Base * duplibase_for_convert(Main *bmain, Depsgraph *depsgraph, Scene *scene, ViewLayer *view_layer, Base *base, Object *ob)
Definition: object_add.cc:2842
static bool object_pointcloud_add_poll(bContext *C)
Definition: object_add.cc:2144
void OBJECT_OT_join_shapes(wmOperatorType *ot)
Definition: object_add.cc:4186
static int object_gpencil_add_exec(bContext *C, wmOperator *op)
Definition: object_add.cc:1312
void ED_object_add_generic_props(wmOperatorType *ot, bool do_editmode)
Definition: object_add.cc:399
static bool object_join_poll(bContext *C)
Definition: object_add.cc:4036
void OBJECT_OT_gpencil_add(wmOperatorType *ot)
Definition: object_add.cc:1509
void ED_object_add_unit_props_radius(wmOperatorType *ot)
Definition: object_add.cc:394
static const char * get_light_defname(int type)
Definition: object_add.cc:1563
void OBJECT_OT_data_instance_add(wmOperatorType *ot)
Definition: object_add.cc:1943
return ret
const EnumPropertyItem rna_enum_id_type_items[]
Definition: rna_ID.c:33
void RNA_property_float_get_array(PointerRNA *ptr, PropertyRNA *prop, float *values)
Definition: rna_access.c:2879
bool RNA_property_is_set(PointerRNA *ptr, PropertyRNA *prop)
Definition: rna_access.c:5271
void RNA_int_set(PointerRNA *ptr, const char *name, int value)
Definition: rna_access.c:4921
void RNA_property_enum_set(PointerRNA *ptr, PropertyRNA *prop, int value)
Definition: rna_access.c:3421
PropertyRNA * RNA_struct_find_property(PointerRNA *ptr, const char *identifier)
Definition: rna_access.c:717
void RNA_float_get_array(PointerRNA *ptr, const char *name, float *values)
Definition: rna_access.c:4980
bool RNA_property_boolean_get(PointerRNA *ptr, PropertyRNA *prop)
Definition: rna_access.c:2153
int RNA_int_get(PointerRNA *ptr, const char *name)
Definition: rna_access.c:4910
PropertyRNA * RNA_struct_type_find_property(StructRNA *srna, const char *identifier)
Definition: rna_access.c:806
void RNA_property_boolean_set(PointerRNA *ptr, PropertyRNA *prop, bool value)
Definition: rna_access.c:2180
float RNA_float_get(PointerRNA *ptr, const char *name)
Definition: rna_access.c:4957
void RNA_property_float_set_array(PointerRNA *ptr, PropertyRNA *prop, const float *values)
Definition: rna_access.c:2978
int RNA_property_enum_get(PointerRNA *ptr, PropertyRNA *prop)
Definition: rna_access.c:3402
bool RNA_struct_property_is_set(PointerRNA *ptr, const char *identifier)
Definition: rna_access.c:5301
bool RNA_struct_idprops_unset(PointerRNA *ptr, const char *identifier)
Definition: rna_access.c:680
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
void RNA_float_set_array(PointerRNA *ptr, const char *name, const float *values)
Definition: rna_access.c:4992
int RNA_enum_get(PointerRNA *ptr, const char *name)
Definition: rna_access.c:5004
PropertyRNA * RNA_def_float(StructOrFunctionRNA *cont_, const char *identifier, float default_value, float hardmin, float hardmax, const char *ui_name, const char *ui_description, float softmin, float softmax)
Definition: rna_define.c:3836
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_float_default(PropertyRNA *prop, float value)
Definition: rna_define.c:2022
PropertyRNA * RNA_def_float_matrix(StructOrFunctionRNA *cont_, const char *identifier, int rows, int columns, const float *default_value, float hardmin, float hardmax, const char *ui_name, const char *ui_description, float softmin, float softmax)
Definition: rna_define.c:3954
PropertyRNA * RNA_def_float_distance(StructOrFunctionRNA *cont_, const char *identifier, float default_value, float hardmin, float hardmax, const char *ui_name, const char *ui_description, float softmin, float softmax)
Definition: rna_define.c:4052
PropertyRNA * RNA_def_string(StructOrFunctionRNA *cont_, const char *identifier, const char *default_value, int maxlen, const char *ui_name, const char *ui_description)
Definition: rna_define.c:3687
void RNA_def_property_translation_context(PropertyRNA *prop, const char *context)
Definition: rna_define.c:2848
PropertyRNA * RNA_def_float_vector_xyz(StructOrFunctionRNA *cont_, const char *identifier, int len, const float *default_value, float hardmin, float hardmax, const char *ui_name, const char *ui_description, float softmin, float softmax)
Definition: rna_define.c:3894
void RNA_def_property_flag(PropertyRNA *prop, PropertyFlag flag)
Definition: rna_define.c:1490
void RNA_def_property_update_runtime(PropertyRNA *prop, const void *func)
Definition: rna_define.c:2911
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_float_rotation(StructOrFunctionRNA *cont_, const char *identifier, int len, const float *default_value, float hardmin, float hardmax, const char *ui_name, const char *ui_description, float softmin, float softmax)
Definition: rna_define.c:4016
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 rna_enum_object_empty_drawtype_items[]
Definition: rna_object.c:129
const EnumPropertyItem rna_enum_metaelem_type_items[]
Definition: rna_object.c:218
const EnumPropertyItem rna_enum_object_gpencil_type_items[]
Definition: rna_object.c:148
const EnumPropertyItem rna_enum_object_type_items[]
Definition: rna_object.c:249
const EnumPropertyItem DummyRNA_NULL_items[]
Definition: rna_rna.c:26
#define INT32_MAX
Definition: stdint.h:137
#define INT32_MIN
Definition: stdint.h:136
short flag
struct Object * object
unsigned short local_view_bits
float drawsize
Collection * collection
Definition: object_add.cc:1650
ListBase disp
Definition: BKE_curve.h:33
struct VFont * vfont
struct VFont * vfontb
EditNurb * editnurb
struct VFont * vfonti
ListBase nurb
struct VFont * vfontbi
short type
CurvesGeometry geometry
struct Object * surface
char * surface_uv_map
int persistent_id[8]
Definition: BKE_duplilist.h:45
struct Object * ob
Definition: BKE_duplilist.h:34
ListBase nurbs
const GeometryComponent * get_component_for_read(GeometryComponentType component_type) const
bool has_curves() const
Definition: DNA_ID.h:368
int tag
Definition: DNA_ID.h:387
void * next
Definition: DNA_ID.h:369
char name[66]
Definition: DNA_ID.h:378
struct Collection * collection
float energy
short type
void * first
Definition: DNA_listBase.h:31
Definition: BKE_main.h:121
ListBase scenes
Definition: BKE_main.h:168
ListBase collections
Definition: BKE_main.h:189
ListBase gpencils
Definition: BKE_main.h:198
ListBase objects
Definition: BKE_main.h:170
struct Material ** mat
short totcol
CustomData ldata
short totcol
struct Material ** mat
char name[64]
struct CurveCache * curve_cache
struct GeometrySet * geometry_set_eval
short partype
short transflag
ListBase constraints
struct Collection * instance_collection
short base_flag
struct RigidBodyOb * rigidbody_object
ListBase greasepencil_modifiers
struct Material ** mat
float loc[3]
struct PartDeflect * pd
float scale[3]
float rot[3]
float parentinv[4][4]
char empty_drawtype
Object_Runtime runtime
short visibility_flag
uint8_t modifier_flag
float empty_drawsize
float obmat[4][4]
float color[4]
struct AnimData * adt
struct Object * parent
struct RigidBodyCon * rigidbody_constraint
void * data
char parsubstr[64]
float viewquat[4]
struct CustomData_MeshMasks customdata_mask
struct RenderData r
View3DCursor cursor
struct Object * camera
unsigned short local_view_uuid
struct Object * camera
struct View3D * localvd
short scenelock
ListBase layers
int ymin
Definition: DNA_vec_types.h:64
int xmin
Definition: DNA_vec_types.h:63
int xy[2]
Definition: WM_types.h:682
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
struct StructRNA * srna
Definition: WM_types.h:969
const char * description
Definition: WM_types.h:893
void(* ui)(struct bContext *, struct wmOperator *)
Definition: WM_types.h:954
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 uiLayout * layout
struct wmOperatorType * type
struct PointerRNA * ptr
const EnumPropertyItem rna_enum_transform_mode_types[]
void WM_main_add_notifier(unsigned int type, void *reference)
void WM_event_add_notifier(const bContext *C, uint type, void *reference)
PointerRNA * ptr
Definition: wm_files.c:3480
wmOperatorType * ot
Definition: wm_files.c:3479
void WM_operator_properties_confirm_or_exec(wmOperatorType *ot)
ID * WM_operator_properties_id_lookup_from_name_or_session_uuid(Main *bmain, PointerRNA *ptr, const ID_Type type)
bool WM_operator_properties_id_lookup_is_set(PointerRNA *ptr)
void WM_operator_properties_id_lookup(wmOperatorType *ot, const bool add_name_prop)
int WM_operator_confirm_or_exec(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
int WM_menu_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
ID * WM_operator_drop_load_path(struct bContext *C, wmOperator *op, const short idcode)
int WM_enum_search_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
void WM_operator_view3d_unit_defaults(struct bContext *C, struct wmOperator *op)
Definition: wm_operators.c:977
Scene * WM_window_get_active_scene(const wmWindow *win)
Definition: wm_window.c:2183