Blender  V2.93
object_add.c
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
17  * All rights reserved.
18  */
19 
24 #include <ctype.h>
25 #include <stdlib.h>
26 #include <string.h>
27 
28 #include "MEM_guardedalloc.h"
29 
30 #include "DNA_anim_types.h"
31 #include "DNA_camera_types.h"
32 #include "DNA_collection_types.h"
33 #include "DNA_curve_types.h"
35 #include "DNA_gpencil_types.h"
36 #include "DNA_key_types.h"
37 #include "DNA_light_types.h"
38 #include "DNA_lightprobe_types.h"
39 #include "DNA_material_types.h"
40 #include "DNA_mesh_types.h"
41 #include "DNA_meta_types.h"
43 #include "DNA_object_force_types.h"
44 #include "DNA_object_types.h"
45 #include "DNA_pointcloud_types.h"
46 #include "DNA_scene_types.h"
47 #include "DNA_vfont_types.h"
48 
49 #include "BLI_ghash.h"
50 #include "BLI_listbase.h"
51 #include "BLI_math.h"
52 #include "BLI_string.h"
53 #include "BLI_utildefines.h"
54 
55 #include "BLT_translation.h"
56 
57 #include "BKE_action.h"
58 #include "BKE_anim_data.h"
59 #include "BKE_armature.h"
60 #include "BKE_camera.h"
61 #include "BKE_collection.h"
62 #include "BKE_constraint.h"
63 #include "BKE_context.h"
64 #include "BKE_curve.h"
65 #include "BKE_displist.h"
66 #include "BKE_duplilist.h"
67 #include "BKE_effect.h"
68 #include "BKE_font.h"
69 #include "BKE_geometry_set.h"
70 #include "BKE_gpencil_curve.h"
71 #include "BKE_gpencil_geom.h"
72 #include "BKE_gpencil_modifier.h"
73 #include "BKE_hair.h"
74 #include "BKE_key.h"
75 #include "BKE_lattice.h"
76 #include "BKE_layer.h"
77 #include "BKE_lib_id.h"
78 #include "BKE_lib_query.h"
79 #include "BKE_lib_remap.h"
80 #include "BKE_light.h"
81 #include "BKE_lightprobe.h"
82 #include "BKE_main.h"
83 #include "BKE_material.h"
84 #include "BKE_mball.h"
85 #include "BKE_mesh.h"
86 #include "BKE_mesh_runtime.h"
87 #include "BKE_nla.h"
88 #include "BKE_object.h"
89 #include "BKE_particle.h"
90 #include "BKE_pointcloud.h"
91 #include "BKE_report.h"
92 #include "BKE_scene.h"
93 #include "BKE_speaker.h"
94 #include "BKE_volume.h"
95 
96 #include "DEG_depsgraph.h"
97 #include "DEG_depsgraph_build.h"
98 #include "DEG_depsgraph_query.h"
99 
100 #include "RNA_access.h"
101 #include "RNA_define.h"
102 #include "RNA_enum_types.h"
103 
104 #include "UI_interface.h"
105 
106 #include "WM_api.h"
107 #include "WM_types.h"
108 
109 #include "ED_armature.h"
110 #include "ED_curve.h"
111 #include "ED_gpencil.h"
112 #include "ED_mball.h"
113 #include "ED_mesh.h"
114 #include "ED_node.h"
115 #include "ED_object.h"
116 #include "ED_outliner.h"
117 #include "ED_physics.h"
118 #include "ED_render.h"
119 #include "ED_screen.h"
120 #include "ED_transform.h"
121 #include "ED_view3d.h"
122 
123 #include "UI_resources.h"
124 
125 #include "object_intern.h"
126 
127 /* -------------------------------------------------------------------- */
131 /* this is an exact copy of the define in rna_light.c
132  * kept here because of linking order.
133  * Icons are only defined here */
135  {LA_LOCAL, "POINT", ICON_LIGHT_POINT, "Point", "Omnidirectional point light source"},
136  {LA_SUN, "SUN", ICON_LIGHT_SUN, "Sun", "Constant direction parallel ray light source"},
137  {LA_SPOT, "SPOT", ICON_LIGHT_SPOT, "Spot", "Directional cone light source"},
138  {LA_AREA, "AREA", ICON_LIGHT_AREA, "Area", "Directional area light source"},
139  {0, NULL, 0, NULL, NULL},
140 };
141 
142 /* copy from rna_object_force.c */
144  {PFIELD_FORCE, "FORCE", ICON_FORCE_FORCE, "Force", ""},
145  {PFIELD_WIND, "WIND", ICON_FORCE_WIND, "Wind", ""},
146  {PFIELD_VORTEX, "VORTEX", ICON_FORCE_VORTEX, "Vortex", ""},
147  {PFIELD_MAGNET, "MAGNET", ICON_FORCE_MAGNETIC, "Magnetic", ""},
148  {PFIELD_HARMONIC, "HARMONIC", ICON_FORCE_HARMONIC, "Harmonic", ""},
149  {PFIELD_CHARGE, "CHARGE", ICON_FORCE_CHARGE, "Charge", ""},
150  {PFIELD_LENNARDJ, "LENNARDJ", ICON_FORCE_LENNARDJONES, "Lennard-Jones", ""},
151  {PFIELD_TEXTURE, "TEXTURE", ICON_FORCE_TEXTURE, "Texture", ""},
152  {PFIELD_GUIDE, "GUIDE", ICON_FORCE_CURVE, "Curve Guide", ""},
153  {PFIELD_BOID, "BOID", ICON_FORCE_BOID, "Boid", ""},
154  {PFIELD_TURBULENCE, "TURBULENCE", ICON_FORCE_TURBULENCE, "Turbulence", ""},
155  {PFIELD_DRAG, "DRAG", ICON_FORCE_DRAG, "Drag", ""},
156  {PFIELD_FLUIDFLOW, "FLUID", ICON_FORCE_FLUIDFLOW, "Fluid Flow", ""},
157  {0, NULL, 0, NULL, NULL},
158 };
159 
162  "CUBEMAP",
163  ICON_LIGHTPROBE_CUBEMAP,
164  "Reflection Cubemap",
165  "Reflection probe with spherical or cubic attenuation"},
167  "PLANAR",
168  ICON_LIGHTPROBE_PLANAR,
169  "Reflection Plane",
170  "Planar reflection probe"},
172  "GRID",
173  ICON_LIGHTPROBE_GRID,
174  "Irradiance Volume",
175  "Irradiance probe to capture diffuse indirect lighting"},
176  {0, NULL, 0, NULL, NULL},
177 };
178 
179 enum {
183 };
184 
185 static const EnumPropertyItem align_options[] = {
186  {ALIGN_WORLD, "WORLD", 0, "World", "Align the new object to the world"},
187  {ALIGN_VIEW, "VIEW", 0, "View", "Align the new object to the view"},
188  {ALIGN_CURSOR, "CURSOR", 0, "3D Cursor", "Use the 3D cursor orientation for the new object"},
189  {0, NULL, 0, NULL, NULL},
190 };
191 
194 /* -------------------------------------------------------------------- */
203 {
204  PropertyRNA *prop;
205 
206  prop = RNA_def_int(ot->srna,
207  "drop_x",
208  0,
209  INT_MIN,
210  INT_MAX,
211  "Drop X",
212  "X-coordinate (screen space) to place the new object under",
213  INT_MIN,
214  INT_MAX);
216  prop = RNA_def_int(ot->srna,
217  "drop_y",
218  0,
219  INT_MIN,
220  INT_MAX,
221  "Drop Y",
222  "Y-coordinate (screen space) to place the new object under",
223  INT_MIN,
224  INT_MAX);
226 }
227 
228 static bool object_add_drop_xy_is_set(const wmOperator *op)
229 {
230  return RNA_struct_property_is_set(op->ptr, "drop_x") &&
231  RNA_struct_property_is_set(op->ptr, "drop_y");
232 }
233 
238 static bool object_add_drop_xy_get(bContext *C, wmOperator *op, int (*r_mval)[2])
239 {
240  if (!object_add_drop_xy_is_set(op)) {
241  (*r_mval)[0] = 0.0f;
242  (*r_mval)[1] = 0.0f;
243  return false;
244  }
245 
246  const ARegion *region = CTX_wm_region(C);
247  (*r_mval)[0] = RNA_int_get(op->ptr, "drop_x") - region->winrct.xmin;
248  (*r_mval)[1] = RNA_int_get(op->ptr, "drop_y") - region->winrct.ymin;
249 
250  return true;
251 }
252 
258 {
259  if (!object_add_drop_xy_is_set(op)) {
260  RNA_int_set(op->ptr, "drop_x", event->x);
261  RNA_int_set(op->ptr, "drop_y", event->y);
262  }
263  return op->type->exec(C, op);
264 }
265 
268 /* -------------------------------------------------------------------- */
273 {
274  const Scene *scene = CTX_data_scene(C);
276 }
277 
278 void ED_object_rotation_from_quat(float rot[3], const float viewquat[4], const char align_axis)
279 {
280  BLI_assert(align_axis >= 'X' && align_axis <= 'Z');
281 
282  switch (align_axis) {
283  case 'X': {
284  /* Same as 'rv3d->viewinv[1]' */
285  const float axis_y[4] = {0.0f, 1.0f, 0.0f};
286  float quat_y[4], quat[4];
287  axis_angle_to_quat(quat_y, axis_y, M_PI_2);
288  mul_qt_qtqt(quat, viewquat, quat_y);
289  quat_to_eul(rot, quat);
290  break;
291  }
292  case 'Y': {
293  quat_to_eul(rot, viewquat);
294  rot[0] -= (float)M_PI_2;
295  break;
296  }
297  case 'Z': {
298  quat_to_eul(rot, viewquat);
299  break;
300  }
301  }
302 }
303 
304 void ED_object_rotation_from_view(bContext *C, float rot[3], const char align_axis)
305 {
307  BLI_assert(align_axis >= 'X' && align_axis <= 'Z');
308  if (rv3d) {
309  float viewquat[4];
310  copy_qt_qt(viewquat, rv3d->viewquat);
311  viewquat[0] *= -1.0f;
312  ED_object_rotation_from_quat(rot, viewquat, align_axis);
313  }
314  else {
315  zero_v3(rot);
316  }
317 }
318 
319 void ED_object_base_init_transform_on_add(Object *object, const float loc[3], const float rot[3])
320 {
321  if (loc) {
322  copy_v3_v3(object->loc, loc);
323  }
324 
325  if (rot) {
326  copy_v3_v3(object->rot, rot);
327  }
328 
329  BKE_object_to_mat4(object, object->obmat);
330 }
331 
332 /* Uses context to figure out transform for primitive.
333  * Returns standard diameter. */
335  bContext *C, Object *obedit, const float loc[3], const float rot[3], float r_primmat[4][4])
336 {
338  View3D *v3d = CTX_wm_view3d(C);
339  float mat[3][3], rmat[3][3], cmat[3][3], imat[3][3];
340 
341  unit_m4(r_primmat);
342 
343  eul_to_mat3(rmat, rot);
344  invert_m3(rmat);
345 
346  /* inverse transform for initial rotation and object */
347  copy_m3_m4(mat, obedit->obmat);
348  mul_m3_m3m3(cmat, rmat, mat);
349  invert_m3_m3(imat, cmat);
350  copy_m4_m3(r_primmat, imat);
351 
352  /* center */
353  copy_v3_v3(r_primmat[3], loc);
354  sub_v3_v3v3(r_primmat[3], r_primmat[3], obedit->obmat[3]);
355  invert_m3_m3(imat, mat);
356  mul_m3_v3(imat, r_primmat[3]);
357 
358  {
359  const float dia = v3d ? ED_view3d_grid_scale(scene, v3d, NULL) :
361  return dia;
362  }
363 
364  /* return 1.0f; */
365 }
366 
369 /* -------------------------------------------------------------------- */
373 static void view_align_update(struct Main *UNUSED(main),
374  struct Scene *UNUSED(scene),
375  struct PointerRNA *ptr)
376 {
377  RNA_struct_idprops_unset(ptr, "rotation");
378 }
379 
381 {
383  ot->srna, "size", 2.0f, 0.0, OBJECT_ADD_SIZE_MAXF, "Size", "", 0.001, 100.00);
384 }
385 
387 {
389  ot->srna, "radius", default_value, 0.0, OBJECT_ADD_SIZE_MAXF, "Radius", "", 0.001, 100.00);
390 }
391 
393 {
395 }
396 
398 {
399  PropertyRNA *prop;
400 
401  if (do_editmode) {
402  prop = RNA_def_boolean(ot->srna,
403  "enter_editmode",
404  0,
405  "Enter Edit Mode",
406  "Enter edit mode when adding this object");
408  }
409  /* note: this property gets hidden for add-camera operator */
410  prop = RNA_def_enum(
411  ot->srna, "align", align_options, ALIGN_WORLD, "Align", "The alignment of the new object");
413 
415  "location",
416  3,
417  NULL,
420  "Location",
421  "Location for the newly added object",
422  -1000.0f,
423  1000.0f);
426  "rotation",
427  3,
428  NULL,
431  "Rotation",
432  "Rotation for the newly added object",
433  DEG2RADF(-360.0f),
434  DEG2RADF(360.0f));
436 
438  "scale",
439  3,
440  NULL,
443  "Scale",
444  "Scale for the newly added object",
445  -1000.0f,
446  1000.0f);
448 }
449 
451 {
452  RNA_def_boolean(ot->srna, "calc_uvs", true, "Generate UVs", "Generate a default UV map");
453 }
454 
456  wmOperator *op,
457  const char view_align_axis,
458  float loc[3],
459  float rot[3],
460  float scale[3],
461  bool *enter_editmode,
462  ushort *local_view_bits,
463  bool *is_view_aligned)
464 {
465  PropertyRNA *prop;
466 
467  /* Switch to Edit mode? optional prop */
468  if ((prop = RNA_struct_find_property(op->ptr, "enter_editmode"))) {
469  bool _enter_editmode;
470  if (!enter_editmode) {
471  enter_editmode = &_enter_editmode;
472  }
473 
474  if (RNA_property_is_set(op->ptr, prop) && enter_editmode) {
475  *enter_editmode = RNA_property_boolean_get(op->ptr, prop);
476  }
477  else {
478  *enter_editmode = (U.flag & USER_ADD_EDITMODE) != 0;
479  RNA_property_boolean_set(op->ptr, prop, *enter_editmode);
480  }
481  }
482 
483  if (local_view_bits) {
484  View3D *v3d = CTX_wm_view3d(C);
485  *local_view_bits = (v3d && v3d->localvd) ? v3d->local_view_uuid : 0;
486  }
487 
488  /* Location! */
489  {
490  float _loc[3];
491  if (!loc) {
492  loc = _loc;
493  }
494 
495  if (RNA_struct_property_is_set(op->ptr, "location")) {
496  RNA_float_get_array(op->ptr, "location", loc);
497  }
498  else {
500  RNA_float_set_array(op->ptr, "location", loc);
501  }
502  }
503 
504  /* Rotation! */
505  {
506  bool _is_view_aligned;
507  float _rot[3];
508  if (!is_view_aligned) {
509  is_view_aligned = &_is_view_aligned;
510  }
511  if (!rot) {
512  rot = _rot;
513  }
514 
515  if (RNA_struct_property_is_set(op->ptr, "rotation")) {
516  /* If rotation is set, always use it. Alignment (and corresponding user preference)
517  * can be ignored since this is in world space anyways.
518  * To not confuse (e.g. on redo), don't set it to #ALIGN_WORLD in the op UI though. */
519  *is_view_aligned = false;
520  RNA_float_get_array(op->ptr, "rotation", rot);
521  }
522  else {
523  int alignment = ALIGN_WORLD;
524  prop = RNA_struct_find_property(op->ptr, "align");
525 
526  if (RNA_property_is_set(op->ptr, prop)) {
527  /* If alignment is set, always use it. */
528  *is_view_aligned = alignment == ALIGN_VIEW;
529  alignment = RNA_property_enum_get(op->ptr, prop);
530  }
531  else {
532  /* If alignment is not set, use User Preferences. */
533  *is_view_aligned = (U.flag & USER_ADD_VIEWALIGNED) != 0;
534  if (*is_view_aligned) {
536  alignment = ALIGN_VIEW;
537  }
538  else if ((U.flag & USER_ADD_CURSORALIGNED) != 0) {
540  alignment = ALIGN_CURSOR;
541  }
542  else {
544  alignment = ALIGN_WORLD;
545  }
546  }
547  switch (alignment) {
548  case ALIGN_WORLD:
549  RNA_float_get_array(op->ptr, "rotation", rot);
550  break;
551  case ALIGN_VIEW:
552  ED_object_rotation_from_view(C, rot, view_align_axis);
553  RNA_float_set_array(op->ptr, "rotation", rot);
554  break;
555  case ALIGN_CURSOR: {
556  const Scene *scene = CTX_data_scene(C);
557  float tmat[3][3];
560  RNA_float_set_array(op->ptr, "rotation", rot);
561  break;
562  }
563  }
564  }
565  }
566 
567  /* Scale! */
568  {
569  float _scale[3];
570  if (!scale) {
571  scale = _scale;
572  }
573 
574  /* For now this is optional, we can make it always use. */
575  copy_v3_fl(scale, 1.0f);
576  if ((prop = RNA_struct_find_property(op->ptr, "scale"))) {
577  if (RNA_property_is_set(op->ptr, prop)) {
578  RNA_property_float_get_array(op->ptr, prop, scale);
579  }
580  else {
581  copy_v3_fl(scale, 1.0f);
582  RNA_property_float_set_array(op->ptr, prop, scale);
583  }
584  }
585  }
586 
587  return true;
588 }
589 
597  const int type,
598  const char *name,
599  const float loc[3],
600  const float rot[3],
601  const bool enter_editmode,
602  const ushort local_view_bits,
603  ID *obdata)
604 {
605  Main *bmain = CTX_data_main(C);
607  ViewLayer *view_layer = CTX_data_view_layer(C);
608 
609  {
610  Object *obedit = OBEDIT_FROM_VIEW_LAYER(view_layer);
611  if (obedit != NULL) {
613  }
614  }
615 
616  /* deselects all, sets active object */
617  Object *ob;
618  if (obdata != NULL) {
620  ob = BKE_object_add_for_data(bmain, view_layer, type, name, obdata, true);
621  const short *materials_len_p = BKE_id_material_len_p(obdata);
622  if (materials_len_p && *materials_len_p > 0) {
623  BKE_object_materials_test(bmain, ob, ob->data);
624  }
625  }
626  else {
627  ob = BKE_object_add(bmain, view_layer, type, name);
628  }
629  BASACT(view_layer)->local_view_bits = local_view_bits;
630  /* editor level activate, notifiers */
631  ED_object_base_activate(C, view_layer->basact);
632 
633  /* more editor stuff */
635 
636  /* TODO(sergey): This is weird to manually tag objects for update, better to
637  * use DEG_id_tag_update here perhaps.
638  */
639  DEG_id_type_tag(bmain, ID_OB);
641  if (ob->data != NULL) {
643  }
644 
645  if (enter_editmode) {
646  ED_object_editmode_enter_ex(bmain, scene, ob, 0);
647  }
648 
650 
651  /* TODO(sergey): Use proper flag for tagging here. */
652  DEG_id_tag_update(&scene->id, 0);
653 
655 
656  return ob;
657 }
658 
660  const int type,
661  const char *name,
662  const float loc[3],
663  const float rot[3],
664  const bool enter_editmode,
665  const ushort local_view_bits)
666 {
668  C, type, name, loc, rot, enter_editmode, local_view_bits, NULL);
669 }
670 
671 /* for object add operator */
673 {
674  ushort local_view_bits;
675  bool enter_editmode;
676  float loc[3], rot[3], radius;
679  C, op, 'Z', loc, rot, NULL, &enter_editmode, &local_view_bits, NULL)) {
680  return OPERATOR_CANCELLED;
681  }
682  radius = RNA_float_get(op->ptr, "radius");
684  C, RNA_enum_get(op->ptr, "type"), NULL, loc, rot, enter_editmode, local_view_bits);
685 
686  if (ob->type == OB_LATTICE) {
687  /* lattice is a special case!
688  * we never want to scale the obdata since that is the rest-state */
689  copy_v3_fl(ob->scale, radius);
690  }
691  else {
692  BKE_object_obdata_size_init(ob, radius);
693  }
694 
695  return OPERATOR_FINISHED;
696 }
697 
699 {
700  /* identifiers */
701  ot->name = "Add Object";
702  ot->description = "Add an object to the scene";
703  ot->idname = "OBJECT_OT_add";
704 
705  /* api callbacks */
708 
709  /* flags */
711 
712  /* properties */
714  PropertyRNA *prop = RNA_def_enum(ot->srna, "type", rna_enum_object_type_items, 0, "Type", "");
716 
718 }
719 
722 /* -------------------------------------------------------------------- */
726 /* for object add operator */
727 static const char *get_lightprobe_defname(int type)
728 {
729  switch (type) {
731  return CTX_DATA_(BLT_I18NCONTEXT_ID_LIGHT, "IrradianceVolume");
733  return CTX_DATA_(BLT_I18NCONTEXT_ID_LIGHT, "ReflectionPlane");
735  return CTX_DATA_(BLT_I18NCONTEXT_ID_LIGHT, "ReflectionCubemap");
736  default:
737  return CTX_DATA_(BLT_I18NCONTEXT_ID_LIGHT, "LightProbe");
738  }
739 }
740 
742 {
743  bool enter_editmode;
744  ushort local_view_bits;
745  float loc[3], rot[3];
748  C, op, 'Z', loc, rot, NULL, &enter_editmode, &local_view_bits, NULL)) {
749  return OPERATOR_CANCELLED;
750  }
751  int type = RNA_enum_get(op->ptr, "type");
752  float radius = RNA_float_get(op->ptr, "radius");
753 
755  C, OB_LIGHTPROBE, get_lightprobe_defname(type), loc, rot, false, local_view_bits);
756  copy_v3_fl(ob->scale, radius);
757 
758  LightProbe *probe = (LightProbe *)ob->data;
759 
761 
763 
764  return OPERATOR_FINISHED;
765 }
766 
768 {
769  /* identifiers */
770  ot->name = "Add Light Probe";
771  ot->description = "Add a light probe object";
772  ot->idname = "OBJECT_OT_lightprobe_add";
773 
774  /* api callbacks */
777 
778  /* flags */
780 
781  /* properties */
782  ot->prop = RNA_def_enum(ot->srna, "type", lightprobe_type_items, 0, "Type", "");
783 
786 }
787 
790 /* -------------------------------------------------------------------- */
794 /* for object add operator */
795 
797 {
798  switch (type) {
799  case PFIELD_FORCE:
800  return CTX_DATA_(BLT_I18NCONTEXT_ID_OBJECT, "Force");
801  case PFIELD_VORTEX:
802  return CTX_DATA_(BLT_I18NCONTEXT_ID_OBJECT, "Vortex");
803  case PFIELD_MAGNET:
804  return CTX_DATA_(BLT_I18NCONTEXT_ID_OBJECT, "Magnet");
805  case PFIELD_WIND:
806  return CTX_DATA_(BLT_I18NCONTEXT_ID_OBJECT, "Wind");
807  case PFIELD_GUIDE:
808  return CTX_DATA_(BLT_I18NCONTEXT_ID_OBJECT, "CurveGuide");
809  case PFIELD_TEXTURE:
810  return CTX_DATA_(BLT_I18NCONTEXT_ID_OBJECT, "TextureField");
811  case PFIELD_HARMONIC:
812  return CTX_DATA_(BLT_I18NCONTEXT_ID_OBJECT, "Harmonic");
813  case PFIELD_CHARGE:
814  return CTX_DATA_(BLT_I18NCONTEXT_ID_OBJECT, "Charge");
815  case PFIELD_LENNARDJ:
816  return CTX_DATA_(BLT_I18NCONTEXT_ID_OBJECT, "Lennard-Jones");
817  case PFIELD_BOID:
818  return CTX_DATA_(BLT_I18NCONTEXT_ID_OBJECT, "Boid");
819  case PFIELD_TURBULENCE:
820  return CTX_DATA_(BLT_I18NCONTEXT_ID_OBJECT, "Turbulence");
821  case PFIELD_DRAG:
822  return CTX_DATA_(BLT_I18NCONTEXT_ID_OBJECT, "Drag");
823  case PFIELD_FLUIDFLOW:
824  return CTX_DATA_(BLT_I18NCONTEXT_ID_OBJECT, "FluidField");
825  case PFIELD_NULL:
826  return CTX_DATA_(BLT_I18NCONTEXT_ID_OBJECT, "Field");
827  case NUM_PFIELD_TYPES:
828  break;
829  }
830 
831  BLI_assert(false);
832  return CTX_DATA_(BLT_I18NCONTEXT_ID_OBJECT, "Field");
833 }
834 
836 {
837  bool enter_editmode;
838  ushort local_view_bits;
839  float loc[3], rot[3];
842  C, op, 'Z', loc, rot, NULL, &enter_editmode, &local_view_bits, NULL)) {
843  return OPERATOR_CANCELLED;
844  }
845  int type = RNA_enum_get(op->ptr, "type");
846  float dia = RNA_float_get(op->ptr, "radius");
847 
848  Object *ob;
849  if (type == PFIELD_GUIDE) {
850  Main *bmain = CTX_data_main(C);
852  Curve *cu;
853  ob = ED_object_add_type(
854  C, OB_CURVE, get_effector_defname(type), loc, rot, false, local_view_bits);
855 
856  cu = ob->data;
857  cu->flag |= CU_PATH | CU_3D;
858  ED_object_editmode_enter_ex(bmain, scene, ob, 0);
859 
860  float mat[4][4];
861  ED_object_new_primitive_matrix(C, ob, loc, rot, mat);
862  mul_mat3_m4_fl(mat, dia);
863  BLI_addtail(&cu->editnurb->nurbs,
865  if (!enter_editmode) {
867  }
868  }
869  else {
870  ob = ED_object_add_type(
871  C, OB_EMPTY, get_effector_defname(type), loc, rot, false, local_view_bits);
875  }
876  }
877 
878  ob->pd = BKE_partdeflect_new(type);
879 
881 
882  return OPERATOR_FINISHED;
883 }
884 
886 {
887  /* identifiers */
888  ot->name = "Add Effector";
889  ot->description = "Add an empty object with a physics effector to the scene";
890  ot->idname = "OBJECT_OT_effector_add";
891 
892  /* api callbacks */
895 
896  /* flags */
898 
899  /* properties */
900  ot->prop = RNA_def_enum(ot->srna, "type", field_type_items, 0, "Type", "");
901 
904 }
905 
908 /* -------------------------------------------------------------------- */
913 {
914  View3D *v3d = CTX_wm_view3d(C);
916 
917  /* force view align for cameras */
918  RNA_enum_set(op->ptr, "align", ALIGN_VIEW);
919 
920  ushort local_view_bits;
921  bool enter_editmode;
922  float loc[3], rot[3];
924  C, op, 'Z', loc, rot, NULL, &enter_editmode, &local_view_bits, NULL)) {
925  return OPERATOR_CANCELLED;
926  }
927  Object *ob = ED_object_add_type(C, OB_CAMERA, NULL, loc, rot, false, local_view_bits);
928 
929  if (v3d) {
930  if (v3d->camera == NULL) {
931  v3d->camera = ob;
932  }
933  if (v3d->scenelock && scene->camera == NULL) {
934  scene->camera = ob;
935  }
936  }
937 
938  Camera *cam = ob->data;
940 
941  return OPERATOR_FINISHED;
942 }
943 
945 {
946  PropertyRNA *prop;
947 
948  /* identifiers */
949  ot->name = "Add Camera";
950  ot->description = "Add a camera object to the scene";
951  ot->idname = "OBJECT_OT_camera_add";
952 
953  /* api callbacks */
956 
957  /* flags */
959 
961 
962  /* hide this for cameras, default */
963  prop = RNA_struct_type_find_property(ot->srna, "align");
965 }
966 
969 /* -------------------------------------------------------------------- */
974 {
975  Main *bmain = CTX_data_main(C);
977  ViewLayer *view_layer = CTX_data_view_layer(C);
978 
979  ushort local_view_bits;
980  bool enter_editmode;
981  float loc[3], rot[3];
984  C, op, 'Z', loc, rot, NULL, &enter_editmode, &local_view_bits, NULL)) {
985  return OPERATOR_CANCELLED;
986  }
987 
988  bool newob = false;
989  Object *obedit = OBEDIT_FROM_VIEW_LAYER(view_layer);
990  if (obedit == NULL || obedit->type != OB_MBALL) {
991  obedit = ED_object_add_type(C, OB_MBALL, NULL, loc, rot, true, local_view_bits);
992  newob = true;
993  }
994  else {
996  }
997 
998  float mat[4][4];
999  ED_object_new_primitive_matrix(C, obedit, loc, rot, mat);
1000  /* Halving here is done to account for constant values from #BKE_mball_element_add.
1001  * While the default radius of the resulting meta element is 2,
1002  * we want to pass in 1 so other values such as resolution are scaled by 1.0. */
1003  float dia = RNA_float_get(op->ptr, "radius") / 2;
1004 
1005  ED_mball_add_primitive(C, obedit, newob, mat, dia, RNA_enum_get(op->ptr, "type"));
1006 
1007  /* userdef */
1008  if (newob && !enter_editmode) {
1009  ED_object_editmode_exit_ex(bmain, scene, obedit, EM_FREEDATA);
1010  }
1011 
1013 
1014  return OPERATOR_FINISHED;
1015 }
1016 
1018 {
1019  /* identifiers */
1020  ot->name = "Add Metaball";
1021  ot->description = "Add an metaball object to the scene";
1022  ot->idname = "OBJECT_OT_metaball_add";
1023 
1024  /* api callbacks */
1028 
1029  /* flags */
1031 
1032  ot->prop = RNA_def_enum(ot->srna, "type", rna_enum_metaelem_type_items, 0, "Primitive", "");
1033 
1036 }
1037 
1040 /* -------------------------------------------------------------------- */
1045 {
1046  Object *obedit = CTX_data_edit_object(C);
1047  bool enter_editmode;
1048  ushort local_view_bits;
1049  float loc[3], rot[3];
1050 
1053  C, op, 'Z', loc, rot, NULL, &enter_editmode, &local_view_bits, NULL)) {
1054  return OPERATOR_CANCELLED;
1055  }
1056  if (obedit && obedit->type == OB_FONT) {
1057  return OPERATOR_CANCELLED;
1058  }
1059 
1060  obedit = ED_object_add_type(C, OB_FONT, NULL, loc, rot, enter_editmode, local_view_bits);
1061  BKE_object_obdata_size_init(obedit, RNA_float_get(op->ptr, "radius"));
1062 
1064 
1065  return OPERATOR_FINISHED;
1066 }
1067 
1069 {
1070  /* identifiers */
1071  ot->name = "Add Text";
1072  ot->description = "Add a text object to the scene";
1073  ot->idname = "OBJECT_OT_text_add";
1074 
1075  /* api callbacks */
1078 
1079  /* flags */
1081 
1082  /* properties */
1085 }
1086 
1089 /* -------------------------------------------------------------------- */
1094 {
1095  Main *bmain = CTX_data_main(C);
1097  ViewLayer *view_layer = CTX_data_view_layer(C);
1098  Object *obedit = OBEDIT_FROM_VIEW_LAYER(view_layer);
1099 
1101  bool newob = false;
1102  bool enter_editmode;
1103  ushort local_view_bits;
1104  float loc[3], rot[3], dia;
1105  bool view_aligned = rv3d && (U.flag & USER_ADD_VIEWALIGNED);
1106 
1109  C, op, 'Z', loc, rot, NULL, &enter_editmode, &local_view_bits, NULL)) {
1110  return OPERATOR_CANCELLED;
1111  }
1112  if ((obedit == NULL) || (obedit->type != OB_ARMATURE)) {
1113  obedit = ED_object_add_type(C, OB_ARMATURE, NULL, loc, rot, true, local_view_bits);
1114  ED_object_editmode_enter_ex(bmain, scene, obedit, 0);
1115  newob = true;
1116  }
1117  else {
1119  }
1120 
1121  if (obedit == NULL) {
1122  BKE_report(op->reports, RPT_ERROR, "Cannot create editmode armature");
1123  return OPERATOR_CANCELLED;
1124  }
1125 
1126  dia = RNA_float_get(op->ptr, "radius");
1127  ED_armature_ebone_add_primitive(obedit, dia, view_aligned);
1128 
1129  /* userdef */
1130  if (newob && !enter_editmode) {
1131  ED_object_editmode_exit_ex(bmain, scene, obedit, EM_FREEDATA);
1132  }
1133 
1135 
1136  return OPERATOR_FINISHED;
1137 }
1138 
1140 {
1141  /* identifiers */
1142  ot->name = "Add Armature";
1143  ot->description = "Add an armature object to the scene";
1144  ot->idname = "OBJECT_OT_armature_add";
1145 
1146  /* api callbacks */
1149 
1150  /* flags */
1152 
1153  /* properties */
1156 }
1157 
1160 /* -------------------------------------------------------------------- */
1165 {
1166  Object *ob;
1167  int type = RNA_enum_get(op->ptr, "type");
1168  ushort local_view_bits;
1169  float loc[3], rot[3];
1170 
1172  if (!ED_object_add_generic_get_opts(C, op, 'Z', loc, rot, NULL, NULL, &local_view_bits, NULL)) {
1173  return OPERATOR_CANCELLED;
1174  }
1175  ob = ED_object_add_type(C, OB_EMPTY, NULL, loc, rot, false, local_view_bits);
1176 
1178  BKE_object_obdata_size_init(ob, RNA_float_get(op->ptr, "radius"));
1179 
1180  return OPERATOR_FINISHED;
1181 }
1182 
1184 {
1185  /* identifiers */
1186  ot->name = "Add Empty";
1187  ot->description = "Add an empty object to the scene";
1188  ot->idname = "OBJECT_OT_empty_add";
1189 
1190  /* api callbacks */
1194 
1195  /* flags */
1197 
1198  /* properties */
1199  ot->prop = RNA_def_enum(ot->srna, "type", rna_enum_object_empty_drawtype_items, 0, "Type", "");
1200 
1203 }
1204 
1206 {
1208 
1209  Image *ima = NULL;
1210 
1211  ima = (Image *)WM_operator_drop_load_path(C, op, ID_IM);
1212  if (!ima) {
1213  return OPERATOR_CANCELLED;
1214  }
1215  /* handled below */
1216  id_us_min(&ima->id);
1217 
1218  Object *ob = NULL;
1219  Object *ob_cursor = ED_view3d_give_object_under_cursor(C, event->mval);
1220 
1221  /* either change empty under cursor or create a new empty */
1222  if (ob_cursor && ob_cursor->type == OB_EMPTY) {
1224  DEG_id_tag_update((ID *)ob_cursor, ID_RECALC_TRANSFORM);
1225  ob = ob_cursor;
1226  }
1227  else {
1228  /* add new empty */
1229  ushort local_view_bits;
1230  float rot[3];
1231 
1233  C, op, 'Z', NULL, rot, NULL, NULL, &local_view_bits, NULL)) {
1234  return OPERATOR_CANCELLED;
1235  }
1236  ob = ED_object_add_type(C, OB_EMPTY, NULL, NULL, rot, false, local_view_bits);
1237 
1239  ED_view3d_cursor3d_position(C, event->mval, false, ob->loc);
1240  ED_object_rotation_from_view(C, ob->rot, 'Z');
1241  ob->empty_drawsize = 5.0f;
1242  }
1243 
1245 
1246  id_us_min(ob->data);
1247  ob->data = ima;
1248  id_us_plus(ob->data);
1249 
1250  return OPERATOR_FINISHED;
1251 }
1252 
1254 {
1255  PropertyRNA *prop;
1256 
1257  /* identifiers */
1258  ot->name = "Add Empty Image/Drop Image to Empty";
1259  ot->description = "Add an empty image type to scene with data";
1260  ot->idname = "OBJECT_OT_drop_named_image";
1261 
1262  /* api callbacks */
1265 
1266  /* flags */
1268 
1269  /* properties */
1270  prop = RNA_def_string(ot->srna, "filepath", NULL, FILE_MAX, "Filepath", "Path to image file");
1273  "relative_path",
1274  true,
1275  "Relative Path",
1276  "Select the file relative to the blend file");
1278  prop = RNA_def_string(ot->srna, "name", NULL, MAX_ID_NAME - 2, "Name", "Image name to assign");
1281 }
1282 
1285 /* -------------------------------------------------------------------- */
1290 {
1292  Object *obact = CTX_data_active_object(C);
1293 
1294  if ((scene == NULL) || (ID_IS_LINKED(scene))) {
1295  return false;
1296  }
1297 
1298  if (obact && obact->type == OB_GPENCIL) {
1299  if (obact->mode != OB_MODE_OBJECT) {
1300  return false;
1301  }
1302  }
1303 
1304  return true;
1305 }
1306 
1308 {
1309  Object *ob = CTX_data_active_object(C), *ob_orig = ob;
1310  bGPdata *gpd = (ob && (ob->type == OB_GPENCIL)) ? ob->data : NULL;
1311 
1312  const int type = RNA_enum_get(op->ptr, "type");
1313  const bool use_in_front = RNA_boolean_get(op->ptr, "use_in_front");
1314  const int stroke_depth_order = RNA_enum_get(op->ptr, "stroke_depth_order");
1315 
1316  ushort local_view_bits;
1317  float loc[3], rot[3];
1318  bool newob = false;
1319 
1320  /* Note: We use 'Y' here (not 'Z'), as */
1322  if (!ED_object_add_generic_get_opts(C, op, 'Y', loc, rot, NULL, NULL, &local_view_bits, NULL)) {
1323  return OPERATOR_CANCELLED;
1324  }
1325  /* add new object if not currently editing a GP object,
1326  * or if "empty" was chosen (i.e. user wants a blank GP canvas)
1327  */
1328  if ((gpd == NULL) || (GPENCIL_ANY_MODE(gpd) == false) || (type == GP_EMPTY)) {
1329  const char *ob_name = NULL;
1330  switch (type) {
1331  case GP_MONKEY: {
1332  ob_name = "Suzanne";
1333  break;
1334  }
1335  case GP_STROKE: {
1336  ob_name = "Stroke";
1337  break;
1338  }
1339  case GP_LRT_OBJECT:
1340  case GP_LRT_SCENE:
1341  case GP_LRT_COLLECTION: {
1342  ob_name = "Line Art";
1343  break;
1344  }
1345  default: {
1346  break;
1347  }
1348  }
1349 
1350  ob = ED_object_add_type(C, OB_GPENCIL, ob_name, loc, rot, true, local_view_bits);
1351  gpd = ob->data;
1352  newob = true;
1353  }
1354  else {
1357  }
1358 
1359  /* create relevant geometry */
1360  switch (type) {
1361  case GP_STROKE: {
1362  float radius = RNA_float_get(op->ptr, "radius");
1363  float mat[4][4];
1364 
1365  ED_object_new_primitive_matrix(C, ob, loc, rot, mat);
1366  mul_v3_fl(mat[0], radius);
1367  mul_v3_fl(mat[1], radius);
1368  mul_v3_fl(mat[2], radius);
1369 
1370  ED_gpencil_create_stroke(C, ob, mat);
1371  break;
1372  }
1373  case GP_MONKEY: {
1374  float radius = RNA_float_get(op->ptr, "radius");
1375  float mat[4][4];
1376 
1377  ED_object_new_primitive_matrix(C, ob, loc, rot, mat);
1378  mul_v3_fl(mat[0], radius);
1379  mul_v3_fl(mat[1], radius);
1380  mul_v3_fl(mat[2], radius);
1381 
1382  ED_gpencil_create_monkey(C, ob, mat);
1383  break;
1384  }
1385  case GP_LRT_SCENE:
1386  case GP_LRT_COLLECTION:
1387  case GP_LRT_OBJECT: {
1388  float radius = RNA_float_get(op->ptr, "radius");
1389  float mat[4][4];
1390 
1391  ED_object_new_primitive_matrix(C, ob, loc, rot, mat);
1392  mul_v3_fl(mat[0], radius);
1393  mul_v3_fl(mat[1], radius);
1394  mul_v3_fl(mat[2], radius);
1395 
1397 
1398  gpd = ob->data;
1399 
1400  /* Add Line Art modifier */
1405 
1406  if (type == GP_LRT_COLLECTION) {
1409  }
1410  else if (type == GP_LRT_OBJECT) {
1412  md->source_object = ob_orig;
1413  }
1414  else {
1415  /* Whole scene. */
1417  }
1418  /* Only created one layer and one material. */
1419  strcpy(md->target_layer, ((bGPDlayer *)gpd->layers.first)->info);
1421  if (md->target_material) {
1422  id_us_plus(&md->target_material->id);
1423  }
1424 
1425  /* Stroke object is drawn in front of meshes by default. */
1426  if (use_in_front) {
1427  ob->dtx |= OB_DRAW_IN_FRONT;
1428  }
1429  else {
1430  if (stroke_depth_order == GP_DRAWMODE_3D) {
1431  gpd->draw_mode = GP_DRAWMODE_3D;
1432  }
1433  }
1434 
1435  break;
1436  }
1437  case GP_EMPTY:
1438  /* do nothing */
1439  break;
1440 
1441  default:
1442  BKE_report(op->reports, RPT_WARNING, "Not implemented");
1443  break;
1444  }
1445 
1446  /* If this is a new object, initialize default stuff (colors, etc.) */
1447  if (newob) {
1448  /* set default viewport color to black */
1449  copy_v3_fl(ob->color, 0.0f);
1450 
1452  }
1453 
1454  return OPERATOR_FINISHED;
1455 }
1456 
1458 {
1459  uiLayout *layout = op->layout;
1460 
1461  uiLayoutSetPropSep(layout, true);
1462 
1463  uiItemR(layout, op->ptr, "radius", 0, NULL, ICON_NONE);
1464  uiItemR(layout, op->ptr, "align", 0, NULL, ICON_NONE);
1465  uiItemR(layout, op->ptr, "location", 0, NULL, ICON_NONE);
1466  uiItemR(layout, op->ptr, "rotation", 0, NULL, ICON_NONE);
1467  uiItemR(layout, op->ptr, "type", 0, NULL, ICON_NONE);
1468 
1469  int type = RNA_enum_get(op->ptr, "type");
1471  uiItemR(layout, op->ptr, "use_in_front", 0, NULL, ICON_NONE);
1472  bool in_front = RNA_boolean_get(op->ptr, "use_in_front");
1473  uiLayout *row = uiLayoutRow(layout, false);
1474  uiLayoutSetActive(row, !in_front);
1475  uiItemR(row, op->ptr, "stroke_depth_order", 0, NULL, ICON_NONE);
1476  }
1477 }
1478 
1480  {GP_DRAWMODE_2D,
1481  "2D",
1482  0,
1483  "2D Layers",
1484  "Display strokes using grease pencil layers to define order"},
1485  {GP_DRAWMODE_3D, "3D", 0, "3D Location", "Display strokes using real 3D position in 3D space"},
1486  {0, NULL, 0, NULL, NULL},
1487 };
1488 
1490 {
1491  /* identifiers */
1492  ot->name = "Add Grease Pencil";
1493  ot->description = "Add a Grease Pencil object to the scene";
1494  ot->idname = "OBJECT_OT_gpencil_add";
1495 
1496  /* api callbacks */
1500 
1501  /* flags */
1503 
1504  /* ui */
1505  ot->ui = object_add_ui;
1506 
1507  /* properties */
1510 
1511  ot->prop = RNA_def_enum(ot->srna, "type", rna_enum_object_gpencil_type_items, 0, "Type", "");
1513  "use_in_front",
1514  true,
1515  "In Front",
1516  "Show line art grease pencil in front of everything");
1517  RNA_def_enum(
1518  ot->srna,
1519  "stroke_depth_order",
1522  "Stroke Depth Order",
1523  "Defines how the strokes are ordered in 3D space for objects not displayed 'In Front'");
1524 }
1525 
1528 /* -------------------------------------------------------------------- */
1532 static const char *get_light_defname(int type)
1533 {
1534  switch (type) {
1535  case LA_LOCAL:
1536  return CTX_DATA_(BLT_I18NCONTEXT_ID_LIGHT, "Point");
1537  case LA_SUN:
1538  return CTX_DATA_(BLT_I18NCONTEXT_ID_LIGHT, "Sun");
1539  case LA_SPOT:
1540  return CTX_DATA_(BLT_I18NCONTEXT_ID_LIGHT, "Spot");
1541  case LA_AREA:
1542  return CTX_DATA_(BLT_I18NCONTEXT_ID_LIGHT, "Area");
1543  default:
1544  return CTX_DATA_(BLT_I18NCONTEXT_ID_LIGHT, "Light");
1545  }
1546 }
1547 
1549 {
1550  Object *ob;
1551  Light *la;
1552  int type = RNA_enum_get(op->ptr, "type");
1553  ushort local_view_bits;
1554  float loc[3], rot[3];
1555 
1557  if (!ED_object_add_generic_get_opts(C, op, 'Z', loc, rot, NULL, NULL, &local_view_bits, NULL)) {
1558  return OPERATOR_CANCELLED;
1559  }
1560  ob = ED_object_add_type(C, OB_LAMP, get_light_defname(type), loc, rot, false, local_view_bits);
1561 
1562  float size = RNA_float_get(op->ptr, "radius");
1563  /* Better defaults for light size. */
1564  switch (type) {
1565  case LA_LOCAL:
1566  case LA_SPOT:
1567  break;
1568  case LA_AREA:
1569  size *= 4.0f;
1570  break;
1571  default:
1572  size *= 0.5f;
1573  break;
1574  }
1576 
1577  la = (Light *)ob->data;
1578  la->type = type;
1579 
1580  if (type == LA_SUN) {
1581  la->energy = 1.0f;
1582  }
1583 
1584  return OPERATOR_FINISHED;
1585 }
1586 
1588 {
1589  /* identifiers */
1590  ot->name = "Add Light";
1591  ot->description = "Add a light object to the scene";
1592  ot->idname = "OBJECT_OT_light_add";
1593 
1594  /* api callbacks */
1598 
1599  /* flags */
1601 
1602  /* properties */
1603  ot->prop = RNA_def_enum(ot->srna, "type", rna_enum_light_type_items, 0, "Type", "");
1605 
1608 }
1609 
1612 /* -------------------------------------------------------------------- */
1617 {
1618  Main *bmain = CTX_data_main(C);
1619  Collection *collection;
1620  ushort local_view_bits;
1621  float loc[3], rot[3];
1622 
1623  PropertyRNA *prop_name = RNA_struct_find_property(op->ptr, "name");
1624  PropertyRNA *prop_location = RNA_struct_find_property(op->ptr, "location");
1625 
1626  if (RNA_property_is_set(op->ptr, prop_name)) {
1627  char name[MAX_ID_NAME - 2];
1628  RNA_property_string_get(op->ptr, prop_name, name);
1629  collection = (Collection *)BKE_libblock_find_name(bmain, ID_GR, name);
1630 
1631  int mval[2];
1632  if (!RNA_property_is_set(op->ptr, prop_location) && object_add_drop_xy_get(C, op, &mval)) {
1634  ED_view3d_cursor3d_position(C, mval, false, loc);
1635  RNA_property_float_set_array(op->ptr, prop_location, loc);
1636  }
1637  }
1638  else {
1639  collection = BLI_findlink(&bmain->collections, RNA_enum_get(op->ptr, "collection"));
1640  }
1641 
1642  if (collection == NULL) {
1643  return OPERATOR_CANCELLED;
1644  }
1645 
1646  if (!ED_object_add_generic_get_opts(C, op, 'Z', loc, rot, NULL, NULL, &local_view_bits, NULL)) {
1647  return OPERATOR_CANCELLED;
1648  }
1649 
1651  ViewLayer *view_layer = CTX_data_view_layer(C);
1652 
1653  /* Avoid dependency cycles. */
1654  LayerCollection *active_lc = BKE_layer_collection_get_active(view_layer);
1655  while (BKE_collection_cycle_find(active_lc->collection, collection)) {
1656  active_lc = BKE_layer_collection_activate_parent(view_layer, active_lc);
1657  }
1658 
1659  Object *ob = ED_object_add_type(
1660  C, OB_EMPTY, collection->id.name + 2, loc, rot, false, local_view_bits);
1661  ob->instance_collection = collection;
1662  ob->empty_drawsize = U.collection_instance_empty_size;
1664  id_us_plus(&collection->id);
1665 
1666  /* works without this except if you try render right after, see: 22027 */
1667  DEG_relations_tag_update(bmain);
1671 
1672  return OPERATOR_FINISHED;
1673 }
1674 
1675 static int object_instance_add_invoke(bContext *C, wmOperator *op, const wmEvent *event)
1676 {
1677  if (!object_add_drop_xy_is_set(op)) {
1678  RNA_int_set(op->ptr, "drop_x", event->x);
1679  RNA_int_set(op->ptr, "drop_y", event->y);
1680  }
1681 
1682  if (!RNA_struct_property_is_set(op->ptr, "name")) {
1683  return WM_enum_search_invoke(C, op, event);
1684  }
1685  return op->type->exec(C, op);
1686 }
1687 
1688 /* only used as menu */
1690 {
1691  PropertyRNA *prop;
1692 
1693  /* identifiers */
1694  ot->name = "Add Collection Instance";
1695  ot->description = "Add a collection instance";
1696  ot->idname = "OBJECT_OT_collection_instance_add";
1697 
1698  /* api callbacks */
1702 
1703  /* flags */
1705 
1706  /* properties */
1708  ot->srna, "name", "Collection", MAX_ID_NAME - 2, "Name", "Collection name to add");
1709  prop = RNA_def_enum(ot->srna, "collection", DummyRNA_NULL_items, 0, "Collection", "");
1712  ot->prop = prop;
1714 
1716 }
1717 
1720 /* -------------------------------------------------------------------- */
1727 {
1728  Main *bmain = CTX_data_main(C);
1729  ID *id = NULL;
1730  ushort local_view_bits;
1731  float loc[3], rot[3];
1732 
1733  PropertyRNA *prop_name = RNA_struct_find_property(op->ptr, "name");
1734  PropertyRNA *prop_type = RNA_struct_find_property(op->ptr, "type");
1735  PropertyRNA *prop_location = RNA_struct_find_property(op->ptr, "location");
1736 
1737  /* These shouldn't fail when created by outliner dropping as it checks the ID is valid. */
1738  if (!RNA_property_is_set(op->ptr, prop_name) || !RNA_property_is_set(op->ptr, prop_type)) {
1739  return OPERATOR_CANCELLED;
1740  }
1741  const short id_type = RNA_property_enum_get(op->ptr, prop_type);
1742  char name[MAX_ID_NAME - 2];
1743  RNA_property_string_get(op->ptr, prop_name, name);
1744  id = BKE_libblock_find_name(bmain, id_type, name);
1745  if (id == NULL) {
1746  return OPERATOR_CANCELLED;
1747  }
1748  const int object_type = BKE_object_obdata_to_type(id);
1749  if (object_type == -1) {
1750  return OPERATOR_CANCELLED;
1751  }
1752 
1753  int mval[2];
1754  if (!RNA_property_is_set(op->ptr, prop_location) && object_add_drop_xy_get(C, op, &mval)) {
1756  ED_view3d_cursor3d_position(C, mval, false, loc);
1757  RNA_property_float_set_array(op->ptr, prop_location, loc);
1758  }
1759 
1760  if (!ED_object_add_generic_get_opts(C, op, 'Z', loc, rot, NULL, NULL, &local_view_bits, NULL)) {
1761  return OPERATOR_CANCELLED;
1762  }
1763 
1765 
1767  C, object_type, id->name + 2, loc, rot, false, local_view_bits, id);
1768 
1769  /* Works without this except if you try render right after, see: T22027. */
1770  DEG_relations_tag_update(bmain);
1774 
1775  return OPERATOR_FINISHED;
1776 }
1777 
1779 {
1780  /* identifiers */
1781  ot->name = "Add Object Data Instance";
1782  ot->description = "Add an object data instance";
1783  ot->idname = "OBJECT_OT_data_instance_add";
1784 
1785  /* api callbacks */
1789 
1790  /* flags */
1792 
1793  /* properties */
1794  RNA_def_string(ot->srna, "name", "Name", MAX_ID_NAME - 2, "Name", "ID name to add");
1795  PropertyRNA *prop = RNA_def_enum(ot->srna, "type", rna_enum_id_type_items, 0, "Type", "");
1798 
1800 }
1801 
1804 /* -------------------------------------------------------------------- */
1809 {
1810  Main *bmain = CTX_data_main(C);
1812 
1813  ushort local_view_bits;
1814  float loc[3], rot[3];
1815  if (!ED_object_add_generic_get_opts(C, op, 'Z', loc, rot, NULL, NULL, &local_view_bits, NULL)) {
1816  return OPERATOR_CANCELLED;
1817  }
1818  Object *ob = ED_object_add_type(C, OB_SPEAKER, NULL, loc, rot, false, local_view_bits);
1819  const bool is_liboverride = ID_IS_OVERRIDE_LIBRARY(ob);
1820 
1821  /* To make it easier to start using this immediately in NLA, a default sound clip is created
1822  * ready to be moved around to re-time the sound and/or make new sound clips. */
1823  {
1824  /* create new data for NLA hierarchy */
1825  AnimData *adt = BKE_animdata_add_id(&ob->id);
1826  NlaTrack *nlt = BKE_nlatrack_add(adt, NULL, is_liboverride);
1827  NlaStrip *strip = BKE_nla_add_soundstrip(bmain, scene, ob->data);
1828  strip->start = CFRA;
1829  strip->end += strip->start;
1830 
1831  /* hook them up */
1832  BKE_nlatrack_add_strip(nlt, strip, is_liboverride);
1833 
1834  /* auto-name the strip, and give the track an interesting name */
1835  BLI_strncpy(nlt->name, DATA_("SoundTrack"), sizeof(nlt->name));
1836  BKE_nlastrip_validate_name(adt, strip);
1837 
1839  }
1840 
1841  return OPERATOR_FINISHED;
1842 }
1843 
1845 {
1846  /* identifiers */
1847  ot->name = "Add Speaker";
1848  ot->description = "Add a speaker object to the scene";
1849  ot->idname = "OBJECT_OT_speaker_add";
1850 
1851  /* api callbacks */
1854 
1855  /* flags */
1857 
1859 }
1860 
1863 /* -------------------------------------------------------------------- */
1868 {
1869  if (!U.experimental.use_new_hair_type) {
1870  return false;
1871  }
1872  return ED_operator_objectmode(C);
1873 }
1874 
1876 {
1877  ushort local_view_bits;
1878  float loc[3], rot[3];
1879  if (!ED_object_add_generic_get_opts(C, op, 'Z', loc, rot, NULL, NULL, &local_view_bits, NULL)) {
1880  return OPERATOR_CANCELLED;
1881  }
1882 
1883  Object *object = ED_object_add_type(C, OB_HAIR, NULL, loc, rot, false, local_view_bits);
1884  object->dtx |= OB_DRAWBOUNDOX; /* TODO: remove once there is actual drawing. */
1885 
1886  return OPERATOR_FINISHED;
1887 }
1888 
1890 {
1891  /* identifiers */
1892  ot->name = "Add Hair";
1893  ot->description = "Add a hair object to the scene";
1894  ot->idname = "OBJECT_OT_hair_add";
1895 
1896  /* api callbacks */
1899 
1900  /* flags */
1902 
1904 }
1905 
1908 /* -------------------------------------------------------------------- */
1913 {
1914  if (!U.experimental.use_new_point_cloud_type) {
1915  return false;
1916  }
1917  return ED_operator_objectmode(C);
1918 }
1919 
1921 {
1922  ushort local_view_bits;
1923  float loc[3], rot[3];
1924  if (!ED_object_add_generic_get_opts(C, op, 'Z', loc, rot, NULL, NULL, &local_view_bits, NULL)) {
1925  return OPERATOR_CANCELLED;
1926  }
1927 
1928  Object *object = ED_object_add_type(C, OB_POINTCLOUD, NULL, loc, rot, false, local_view_bits);
1929  object->dtx |= OB_DRAWBOUNDOX; /* TODO: remove once there is actual drawing. */
1930 
1931  return OPERATOR_FINISHED;
1932 }
1933 
1935 {
1936  /* identifiers */
1937  ot->name = "Add Point Cloud";
1938  ot->description = "Add a point cloud object to the scene";
1939  ot->idname = "OBJECT_OT_pointcloud_add";
1940 
1941  /* api callbacks */
1944 
1945  /* flags */
1947 
1949 }
1950 
1953 /* -------------------------------------------------------------------- */
1956 /* remove base from a specific scene */
1957 /* note: now unlinks constraints as well */
1959 {
1960  if (ID_REAL_USERS(ob) <= 1 && ID_EXTRA_USERS(ob) == 0 &&
1961  BKE_library_ID_is_indirectly_used(bmain, ob)) {
1962  /* We cannot delete indirectly used object... */
1963  printf(
1964  "WARNING, undeletable object '%s', should have been caught before reaching this "
1965  "function!",
1966  ob->id.name + 2);
1967  return;
1968  }
1969 
1971 
1972  BKE_scene_collections_object_remove(bmain, scene, ob, true);
1973 }
1974 
1980 {
1983  BKE_scene_collections_object_remove(bmain, scene, ob, true);
1984 }
1985 
1987 {
1988  Main *bmain = CTX_data_main(C);
1991  const bool use_global = RNA_boolean_get(op->ptr, "use_global");
1992  uint changed_count = 0;
1993  uint tagged_count = 0;
1994 
1995  if (CTX_data_edit_object(C)) {
1996  return OPERATOR_CANCELLED;
1997  }
1998 
1999  BKE_main_id_tag_all(bmain, LIB_TAG_DOIT, false);
2000 
2001  CTX_DATA_BEGIN (C, Object *, ob, selected_objects) {
2002  if (ob->id.tag & LIB_TAG_INDIRECT) {
2003  /* Can this case ever happen? */
2004  BKE_reportf(op->reports,
2005  RPT_WARNING,
2006  "Cannot delete indirectly linked object '%s'",
2007  ob->id.name + 2);
2008  continue;
2009  }
2010 
2011  if (ID_REAL_USERS(ob) <= 1 && ID_EXTRA_USERS(ob) == 0 &&
2012  BKE_library_ID_is_indirectly_used(bmain, ob)) {
2013  BKE_reportf(op->reports,
2014  RPT_WARNING,
2015  "Cannot delete object '%s' from scene '%s', indirectly used objects need at "
2016  "least one user",
2017  ob->id.name + 2,
2018  scene->id.name + 2);
2019  continue;
2020  }
2021 
2022  /* if grease pencil object, set cache as dirty */
2023  if (ob->type == OB_GPENCIL) {
2024  bGPdata *gpd = (bGPdata *)ob->data;
2026  }
2027 
2028  /* Use multi tagged delete if `use_global=True`, or the object is used only in one scene. */
2029  if (use_global || ID_REAL_USERS(ob) <= 1) {
2030  ob->id.tag |= LIB_TAG_DOIT;
2031  tagged_count += 1;
2032  }
2033  else {
2034  /* Object is used in multiple scenes. Delete the object from the current scene only. */
2036  changed_count += 1;
2037 
2038  /* FIXME: this will also remove parent from grease pencil from other scenes. */
2039  /* Remove from Grease Pencil parent */
2040  for (bGPdata *gpd = bmain->gpencils.first; gpd; gpd = gpd->id.next) {
2041  LISTBASE_FOREACH (bGPDlayer *, gpl, &gpd->layers) {
2042  if (gpl->parent != NULL) {
2043  if (gpl->parent == ob) {
2044  gpl->parent = NULL;
2045  }
2046  }
2047  }
2048  }
2049  }
2050  }
2051  CTX_DATA_END;
2052 
2053  if ((changed_count + tagged_count) == 0) {
2054  return OPERATOR_CANCELLED;
2055  }
2056 
2057  if (tagged_count > 0) {
2059  }
2060 
2061  BKE_reportf(op->reports, RPT_INFO, "Deleted %u object(s)", (changed_count + tagged_count));
2062 
2063  /* delete has to handle all open scenes */
2065  LISTBASE_FOREACH (wmWindow *, win, &wm->windows) {
2067 
2068  if (scene->id.tag & LIB_TAG_DOIT) {
2069  scene->id.tag &= ~LIB_TAG_DOIT;
2070 
2071  DEG_relations_tag_update(bmain);
2072 
2076  }
2077  }
2078 
2079  return OPERATOR_FINISHED;
2080 }
2081 
2083 {
2084  /* identifiers */
2085  ot->name = "Delete";
2086  ot->description = "Delete selected objects";
2087  ot->idname = "OBJECT_OT_delete";
2088 
2089  /* api callbacks */
2093 
2094  /* flags */
2096 
2097  PropertyRNA *prop;
2098  prop = RNA_def_boolean(
2099  ot->srna, "use_global", 0, "Delete Globally", "Remove object from all scenes");
2102 }
2103 
2106 /* -------------------------------------------------------------------- */
2110 /* after copying objects, copied data should get new pointers */
2112 {
2113  Main *bmain = CTX_data_main(C);
2114 
2115  CTX_DATA_BEGIN (C, Object *, ob, selected_editable_objects) {
2117  }
2118  CTX_DATA_END;
2119 
2120 #ifndef NDEBUG
2121  /* Call to `BKE_libblock_relink_to_newid` above is supposed to have cleared all those flags. */
2122  ID *id_iter;
2123  FOREACH_MAIN_ID_BEGIN (bmain, id_iter) {
2124  if (GS(id_iter->name) == ID_OB) {
2125  /* Not all duplicated objects would be used by other newly duplicated data, so their flag
2126  * will not always be cleared. */
2127  continue;
2128  }
2129  BLI_assert((id_iter->tag & LIB_TAG_NEW) == 0);
2130  }
2132 #endif
2133 
2134  BKE_main_id_tag_all(bmain, LIB_TAG_NEW, false);
2136 }
2137 
2140 /* -------------------------------------------------------------------- */
2144 /* XXX TODO That whole hierarchy handling based on persistent_id tricks is
2145  * very confusing and convoluted, and it will fail in many cases besides basic ones.
2146  * Think this should be replaced by a proper tree-like representation of the instantiations,
2147  * should help a lot in both readability, and precise consistent rebuilding of hierarchy.
2148  */
2149 
2163 static uint dupliobject_hash(const void *ptr)
2164 {
2165  const DupliObject *dob = ptr;
2167 
2168  if (dob->type == OB_DUPLICOLLECTION) {
2169  for (int i = 1; (i < MAX_DUPLI_RECUR) && dob->persistent_id[i] != INT_MAX; i++) {
2170  hash ^= (dob->persistent_id[i] ^ i);
2171  }
2172  }
2173  else {
2174  hash ^= (dob->persistent_id[0] ^ 0);
2175  }
2176  return hash;
2177 }
2178 
2186 {
2187  const DupliObject *dob = ptr;
2189  for (int i = 1; (i < MAX_DUPLI_RECUR) && dob->persistent_id[i] != INT_MAX; i++) {
2190  hash ^= (dob->persistent_id[i] ^ i);
2191  }
2192  return hash;
2193 }
2194 
2195 /* Compare function that matches dupliobject_hash */
2196 static bool dupliobject_cmp(const void *a_, const void *b_)
2197 {
2198  const DupliObject *a = a_;
2199  const DupliObject *b = b_;
2200 
2201  if (a->ob != b->ob) {
2202  return true;
2203  }
2204 
2205  if (a->type != b->type) {
2206  return true;
2207  }
2208 
2209  if (a->type == OB_DUPLICOLLECTION) {
2210  for (int i = 1; (i < MAX_DUPLI_RECUR); i++) {
2211  if (a->persistent_id[i] != b->persistent_id[i]) {
2212  return true;
2213  }
2214  if (a->persistent_id[i] == INT_MAX) {
2215  break;
2216  }
2217  }
2218  }
2219  else {
2220  if (a->persistent_id[0] != b->persistent_id[0]) {
2221  return true;
2222  }
2223  }
2224 
2225  /* matching */
2226  return false;
2227 }
2228 
2229 /* Compare function that matches dupliobject_instancer_hash. */
2230 static bool dupliobject_instancer_cmp(const void *a_, const void *b_)
2231 {
2232  const DupliObject *a = a_;
2233  const DupliObject *b = b_;
2234 
2235  for (int i = 0; (i < MAX_DUPLI_RECUR); i++) {
2236  if (a->persistent_id[i] != b->persistent_id[i]) {
2237  return true;
2238  }
2239  if (a->persistent_id[i] == INT_MAX) {
2240  break;
2241  }
2242  }
2243 
2244  /* matching */
2245  return false;
2246 }
2247 
2248 static bool object_has_geometry_set_instances(const Object *object_eval)
2249 {
2250  struct GeometrySet *geometry_set = object_eval->runtime.geometry_set_eval;
2251 
2252  return (geometry_set != NULL) && BKE_geometry_set_has_instances(geometry_set);
2253 }
2254 
2257  Scene *scene,
2258  Base *base,
2259  const bool use_base_parent,
2260  const bool use_hierarchy)
2261 {
2262  Main *bmain = CTX_data_main(C);
2263  ViewLayer *view_layer = CTX_data_view_layer(C);
2264  GHash *parent_gh = NULL, *instancer_gh = NULL;
2265 
2266  Object *object_eval = DEG_get_evaluated_object(depsgraph, base->object);
2267 
2268  if (!(base->object->transflag & OB_DUPLI) && !object_has_geometry_set_instances(object_eval)) {
2269  return;
2270  }
2271 
2272  ListBase *lb_duplis = object_duplilist(depsgraph, scene, object_eval);
2273 
2274  if (BLI_listbase_is_empty(lb_duplis)) {
2275  free_object_duplilist(lb_duplis);
2276  return;
2277  }
2278 
2279  GHash *dupli_gh = BLI_ghash_ptr_new(__func__);
2280  if (use_hierarchy) {
2281  parent_gh = BLI_ghash_new(dupliobject_hash, dupliobject_cmp, __func__);
2282 
2283  if (use_base_parent) {
2284  instancer_gh = BLI_ghash_new(
2286  }
2287  }
2288 
2289  LISTBASE_FOREACH (DupliObject *, dob, lb_duplis) {
2290  Object *ob_src = DEG_get_original_object(dob->ob);
2291  Object *ob_dst = ID_NEW_SET(ob_src, BKE_id_copy(bmain, &ob_src->id));
2292  id_us_min(&ob_dst->id);
2293 
2294  /* font duplis can have a totcol without material, we get them from parent
2295  * should be implemented better...
2296  */
2297  if (ob_dst->mat == NULL) {
2298  ob_dst->totcol = 0;
2299  }
2300 
2301  BKE_collection_object_add_from(bmain, scene, base->object, ob_dst);
2302  Base *base_dst = BKE_view_layer_base_find(view_layer, ob_dst);
2303  BLI_assert(base_dst != NULL);
2304 
2305  ED_object_base_select(base_dst, BA_SELECT);
2307 
2309 
2310  /* make sure apply works */
2311  BKE_animdata_free(&ob_dst->id, true);
2312  ob_dst->adt = NULL;
2313 
2314  /* Proxies are not to be copied. */
2315  ob_dst->proxy_from = NULL;
2316  ob_dst->proxy_group = NULL;
2317  ob_dst->proxy = NULL;
2318 
2319  ob_dst->parent = NULL;
2321  ob_dst->runtime.curve_cache = NULL;
2322  const bool is_dupli_instancer = (ob_dst->transflag & OB_DUPLI) != 0;
2323  ob_dst->transflag &= ~OB_DUPLI;
2324  /* Remove instantiated collection, it's annoying to keep it here
2325  * (and get potentially a lot of usages of it then...). */
2326  id_us_min((ID *)ob_dst->instance_collection);
2327  ob_dst->instance_collection = NULL;
2328 
2329  copy_m4_m4(ob_dst->obmat, dob->mat);
2330  BKE_object_apply_mat4(ob_dst, ob_dst->obmat, false, false);
2331 
2332  BLI_ghash_insert(dupli_gh, dob, ob_dst);
2333  if (parent_gh) {
2334  void **val;
2335  /* Due to nature of hash/comparison of this ghash, a lot of duplis may be considered as
2336  * 'the same', this avoids trying to insert same key several time and
2337  * raise asserts in debug builds... */
2338  if (!BLI_ghash_ensure_p(parent_gh, dob, &val)) {
2339  *val = ob_dst;
2340  }
2341 
2342  if (is_dupli_instancer && instancer_gh) {
2343  /* Same as above, we may have several 'hits'. */
2344  if (!BLI_ghash_ensure_p(instancer_gh, dob, &val)) {
2345  *val = ob_dst;
2346  }
2347  }
2348  }
2349  }
2350 
2351  LISTBASE_FOREACH (DupliObject *, dob, lb_duplis) {
2352  Object *ob_src = dob->ob;
2353  Object *ob_dst = BLI_ghash_lookup(dupli_gh, dob);
2354 
2355  /* Remap new object to itself, and clear again newid pointer of orig object. */
2356  BKE_libblock_relink_to_newid(&ob_dst->id);
2357 
2359 
2360  if (use_hierarchy) {
2361  /* original parents */
2362  Object *ob_src_par = ob_src->parent;
2363  Object *ob_dst_par = NULL;
2364 
2365  /* find parent that was also made real */
2366  if (ob_src_par) {
2367  /* OK to keep most of the members uninitialized,
2368  * they won't be read, this is simply for a hash lookup. */
2369  DupliObject dob_key;
2370  dob_key.ob = ob_src_par;
2371  dob_key.type = dob->type;
2372  if (dob->type == OB_DUPLICOLLECTION) {
2373  memcpy(&dob_key.persistent_id[1],
2374  &dob->persistent_id[1],
2375  sizeof(dob->persistent_id[1]) * (MAX_DUPLI_RECUR - 1));
2376  }
2377  else {
2378  dob_key.persistent_id[0] = dob->persistent_id[0];
2379  }
2380  ob_dst_par = BLI_ghash_lookup(parent_gh, &dob_key);
2381  }
2382 
2383  if (ob_dst_par) {
2384  /* allow for all possible parent types */
2385  ob_dst->partype = ob_src->partype;
2386  BLI_strncpy(ob_dst->parsubstr, ob_src->parsubstr, sizeof(ob_dst->parsubstr));
2387  ob_dst->par1 = ob_src->par1;
2388  ob_dst->par2 = ob_src->par2;
2389  ob_dst->par3 = ob_src->par3;
2390 
2391  copy_m4_m4(ob_dst->parentinv, ob_src->parentinv);
2392 
2393  ob_dst->parent = ob_dst_par;
2394  }
2395  }
2396  if (use_base_parent && ob_dst->parent == NULL) {
2397  Object *ob_dst_par = NULL;
2398 
2399  if (instancer_gh != NULL) {
2400  /* OK to keep most of the members uninitialized,
2401  * they won't be read, this is simply for a hash lookup. */
2402  DupliObject dob_key;
2403  /* We are looking one step upper in hierarchy, so we need to 'shift' the `persistent_id`,
2404  * ignoring the first item.
2405  * We only check on persistent_id here, since we have no idea what object it might be. */
2406  memcpy(&dob_key.persistent_id[0],
2407  &dob->persistent_id[1],
2408  sizeof(dob_key.persistent_id[0]) * (MAX_DUPLI_RECUR - 1));
2409  ob_dst_par = BLI_ghash_lookup(instancer_gh, &dob_key);
2410  }
2411 
2412  if (ob_dst_par == NULL) {
2413  /* Default to parenting to root object...
2414  * Always the case when use_hierarchy is false. */
2415  ob_dst_par = base->object;
2416  }
2417 
2418  ob_dst->parent = ob_dst_par;
2419  ob_dst->partype = PAROBJECT;
2420  }
2421 
2422  if (ob_dst->parent) {
2423  /* note, this may be the parent of other objects, but it should
2424  * still work out ok */
2425  BKE_object_apply_mat4(ob_dst, dob->mat, false, true);
2426 
2427  /* to set ob_dst->orig and in case there's any other discrepancies */
2429  }
2430  }
2431 
2433  LISTBASE_FOREACH (Object *, ob, &bmain->objects) {
2434  if (ob->proxy_group == base->object) {
2435  ob->proxy = NULL;
2436  ob->proxy_from = NULL;
2438  }
2439  }
2440  base->object->instance_collection = NULL;
2441  }
2442 
2445 
2446  BLI_ghash_free(dupli_gh, NULL, NULL);
2447  if (parent_gh) {
2448  BLI_ghash_free(parent_gh, NULL, NULL);
2449  }
2450  if (instancer_gh) {
2451  BLI_ghash_free(instancer_gh, NULL, NULL);
2452  }
2453 
2454  free_object_duplilist(lb_duplis);
2455 
2457 
2458  base->object->transflag &= ~OB_DUPLI;
2460 }
2461 
2463 {
2464  Main *bmain = CTX_data_main(C);
2467 
2468  const bool use_base_parent = RNA_boolean_get(op->ptr, "use_base_parent");
2469  const bool use_hierarchy = RNA_boolean_get(op->ptr, "use_hierarchy");
2470 
2472 
2473  CTX_DATA_BEGIN (C, Base *, base, selected_editable_bases) {
2474  make_object_duplilist_real(C, depsgraph, scene, base, use_base_parent, use_hierarchy);
2475 
2476  /* dependencies were changed */
2477  WM_event_add_notifier(C, NC_OBJECT | ND_PARENT, base->object);
2478  }
2479  CTX_DATA_END;
2480 
2481  DEG_relations_tag_update(bmain);
2485 
2486  return OPERATOR_FINISHED;
2487 }
2488 
2490 {
2491  /* identifiers */
2492  ot->name = "Make Instances Real";
2493  ot->description = "Make instanced objects attached to this object real";
2494  ot->idname = "OBJECT_OT_duplicates_make_real";
2495 
2496  /* api callbacks */
2498 
2500 
2501  /* flags */
2503 
2505  "use_base_parent",
2506  0,
2507  "Parent",
2508  "Parent newly created objects to the original instancer");
2510  ot->srna, "use_hierarchy", 0, "Keep Hierarchy", "Maintain parent child relationships");
2511 }
2512 
2515 /* -------------------------------------------------------------------- */
2520  {OB_CURVE, "CURVE", ICON_OUTLINER_OB_CURVE, "Curve", "Curve from Mesh or Text objects"},
2521  {OB_MESH,
2522  "MESH",
2523  ICON_OUTLINER_OB_MESH,
2524  "Mesh",
2525 #ifdef WITH_POINT_CLOUD
2526  "Mesh from Curve, Surface, Metaball, Text, or Point Cloud objects"},
2527 #else
2528  "Mesh from Curve, Surface, Metaball, or Text objects"},
2529 #endif
2530  {OB_GPENCIL,
2531  "GPENCIL",
2532  ICON_OUTLINER_OB_GREASEPENCIL,
2533  "Grease Pencil",
2534  "Grease Pencil from Curve or Mesh objects"},
2535 #ifdef WITH_POINT_CLOUD
2536  {OB_POINTCLOUD,
2537  "POINTCLOUD",
2538  ICON_OUTLINER_OB_POINTCLOUD,
2539  "Point Cloud",
2540  "Point Cloud from Mesh objects"},
2541 #endif
2542  {0, NULL, 0, NULL, NULL},
2543 };
2544 
2546 {
2547  if (ob->runtime.curve_cache == NULL) {
2548  /* Force creation. This is normally not needed but on operator
2549  * redo we might end up with an object which isn't evaluated yet.
2550  * Also happens in case we are working on a copy of the object
2551  * (all its caches have been nuked then).
2552  */
2553  if (ELEM(ob->type, OB_SURF, OB_CURVE, OB_FONT)) {
2554  /* We need 'for render' ON here, to enable computing bevel dipslist if needed.
2555  * Also makes sense anyway, we would not want e.g. to lose hidden parts etc. */
2556  BKE_displist_make_curveTypes(depsgraph, scene, ob, true, false);
2557  }
2558  else if (ob->type == OB_MBALL) {
2560  }
2561  }
2562 }
2563 
2565 {
2566  Object *object_eval = DEG_get_evaluated_object(depsgraph, ob);
2567  Curve *curve = ob->data;
2568 
2569  Mesh *mesh = BKE_mesh_new_from_object_to_bmain(bmain, depsgraph, object_eval, true);
2570  if (mesh == NULL) {
2571  /* Unable to convert the curve to a mesh. */
2572  return;
2573  }
2574 
2576  /* Replace curve used by the object itself. */
2577  ob->data = mesh;
2578  ob->type = OB_MESH;
2579  id_us_min(&curve->id);
2580  id_us_plus(&mesh->id);
2581  /* Change objects which are using same curve.
2582  * A bit annoying, but:
2583  * - It's possible to have multiple curve objects selected which are sharing the same curve
2584  * datablock. We don't want mesh to be created for every of those objects.
2585  * - This is how conversion worked for a long long time. */
2586  LISTBASE_FOREACH (Object *, other_object, &bmain->objects) {
2587  if (other_object->data == curve) {
2588  other_object->type = OB_MESH;
2589 
2590  id_us_min((ID *)other_object->data);
2591  other_object->data = ob->data;
2592  id_us_plus((ID *)other_object->data);
2593  }
2594  }
2595 }
2596 
2598 {
2600  Base *base_act = CTX_data_active_base(C);
2601  Object *obact = base_act ? base_act->object : NULL;
2602 
2603  if (obact == NULL || obact->data == NULL || ID_IS_LINKED(obact) ||
2605  return false;
2606  }
2607 
2608  return (!ID_IS_LINKED(scene) && (BKE_object_is_in_editmode(obact) == false) &&
2609  (base_act->flag & BASE_SELECTED));
2610 }
2611 
2612 /* Helper for object_convert_exec */
2614  Main *bmain, Depsgraph *depsgraph, Scene *scene, ViewLayer *view_layer, Base *base, Object *ob)
2615 {
2616  if (ob == NULL) {
2617  ob = base->object;
2618  }
2619 
2620  Object *obn = (Object *)BKE_id_copy(bmain, &ob->id);
2621  id_us_min(&obn->id);
2623  BKE_collection_object_add_from(bmain, scene, ob, obn);
2624 
2625  Base *basen = BKE_view_layer_base_find(view_layer, obn);
2628 
2629  /* XXX An ugly hack needed because if we re-run depsgraph with some new MBall objects
2630  * having same 'family name' as orig ones, they will affect end result of MBall computation...
2631  * For until we get rid of that name-based thingy in MBalls, that should do the trick
2632  * (this is weak, but other solution (to change name of obn) is even worse imho).
2633  * See T65996. */
2634  const bool is_meta_ball = (obn->type == OB_MBALL);
2635  void *obdata = obn->data;
2636  if (is_meta_ball) {
2637  obn->type = OB_EMPTY;
2638  obn->data = NULL;
2639  }
2640 
2641  /* XXX Doing that here is stupid, it means we update and re-evaluate the whole depsgraph every
2642  * time we need to duplicate an object to convert it. Even worse, this is not 100% correct, since
2643  * we do not yet have duplicated obdata.
2644  * However, that is a safe solution for now. Proper, longer-term solution is to refactor
2645  * object_convert_exec to:
2646  * - duplicate all data it needs to in a first loop.
2647  * - do a single update.
2648  * - convert data in a second loop. */
2650  CustomData_MeshMasks customdata_mask_prev = scene->customdata_mask;
2653  scene->customdata_mask = customdata_mask_prev;
2654 
2655  if (is_meta_ball) {
2656  obn->type = OB_MBALL;
2657  obn->data = obdata;
2658  }
2659 
2660  return basen;
2661 }
2662 
2664 {
2665  Main *bmain = CTX_data_main(C);
2668  ViewLayer *view_layer = CTX_data_view_layer(C);
2669  View3D *v3d = CTX_wm_view3d(C);
2670  Base *basen = NULL, *basact = NULL;
2671  Object *ob1, *obact = CTX_data_active_object(C);
2672  const short target = RNA_enum_get(op->ptr, "target");
2673  bool keep_original = RNA_boolean_get(op->ptr, "keep_original");
2674 
2675  const float angle = RNA_float_get(op->ptr, "angle");
2676  const int thickness = RNA_int_get(op->ptr, "thickness");
2677  const bool use_seams = RNA_boolean_get(op->ptr, "seams");
2678  const bool use_faces = RNA_boolean_get(op->ptr, "faces");
2679  const float offset = RNA_float_get(op->ptr, "offset");
2680 
2681  int a, mballConverted = 0;
2682  bool gpencilConverted = false;
2683 
2684  /* don't forget multiple users! */
2685 
2686  {
2688  ob->flag &= ~OB_DONE;
2689 
2690  /* flag data that's not been edited (only needed for !keep_original) */
2691  if (ob->data) {
2692  ((ID *)ob->data)->tag |= LIB_TAG_DOIT;
2693  }
2694 
2695  /* possible metaball basis is not in this scene */
2696  if (ob->type == OB_MBALL && target == OB_MESH) {
2697  if (BKE_mball_is_basis(ob) == false) {
2698  Object *ob_basis;
2699  ob_basis = BKE_mball_basis_find(scene, ob);
2700  if (ob_basis) {
2701  ob_basis->flag &= ~OB_DONE;
2702  }
2703  }
2704  }
2705  }
2707  }
2708 
2709  ListBase selected_editable_bases;
2710  CTX_data_selected_editable_bases(C, &selected_editable_bases);
2711 
2712  /* Ensure we get all meshes calculated with a sufficient data-mask,
2713  * needed since re-evaluating single modifiers causes bugs if they depend
2714  * on other objects data masks too, see: T50950. */
2715  {
2716  LISTBASE_FOREACH (CollectionPointerLink *, link, &selected_editable_bases) {
2717  Base *base = link->ptr.data;
2718  Object *ob = base->object;
2719 
2720  /* The way object type conversion works currently (enforcing conversion of *all* objects
2721  * using converted object-data, even some un-selected/hidden/another scene ones,
2722  * sounds totally bad to me.
2723  * However, changing this is more design than bug-fix, not to mention convoluted code below,
2724  * so that will be for later.
2725  * But at the very least, do not do that with linked IDs! */
2726  if ((ID_IS_LINKED(ob) || (ob->data && ID_IS_LINKED(ob->data))) && !keep_original) {
2727  keep_original = true;
2728  BKE_report(
2729  op->reports,
2730  RPT_INFO,
2731  "Converting some linked object/object data, enforcing 'Keep Original' option to True");
2732  }
2733 
2735  }
2736 
2737  CustomData_MeshMasks customdata_mask_prev = scene->customdata_mask;
2740  scene->customdata_mask = customdata_mask_prev;
2741  }
2742 
2743  LISTBASE_FOREACH (CollectionPointerLink *, link, &selected_editable_bases) {
2744  Object *newob = NULL;
2745  Base *base = link->ptr.data;
2746  Object *ob = base->object;
2747 
2748  if (ob->flag & OB_DONE || !IS_TAGGED(ob->data)) {
2749  if (ob->type != target) {
2750  base->flag &= ~SELECT;
2751  ob->flag &= ~SELECT;
2752  }
2753 
2754  /* obdata already modified */
2755  if (!IS_TAGGED(ob->data)) {
2756  /* When 2 objects with linked data are selected, converting both
2757  * would keep modifiers on all but the converted object T26003. */
2758  if (ob->type == OB_MESH) {
2759  BKE_object_free_modifiers(ob, 0); /* after derivedmesh calls! */
2760  }
2761  if (ob->type == OB_GPENCIL) {
2762  BKE_object_free_modifiers(ob, 0); /* after derivedmesh calls! */
2763  BKE_object_free_shaderfx(ob, 0);
2764  }
2765  }
2766  }
2767  else if (ob->type == OB_MESH && target == OB_CURVE) {
2768  ob->flag |= OB_DONE;
2769 
2770  if (keep_original) {
2771  basen = duplibase_for_convert(bmain, depsgraph, scene, view_layer, base, NULL);
2772  newob = basen->object;
2773 
2774  /* decrement original mesh's usage count */
2775  Mesh *me = newob->data;
2776  id_us_min(&me->id);
2777 
2778  /* make a new copy of the mesh */
2779  newob->data = BKE_id_copy(bmain, &me->id);
2780  }
2781  else {
2782  newob = ob;
2783  }
2784 
2785  BKE_mesh_to_curve(bmain, depsgraph, scene, newob);
2786 
2787  if (newob->type == OB_CURVE) {
2788  BKE_object_free_modifiers(newob, 0); /* after derivedmesh calls! */
2789  if (newob->rigidbody_object != NULL) {
2790  ED_rigidbody_object_remove(bmain, scene, newob);
2791  }
2792  }
2793  }
2794  else if (ob->type == OB_MESH && target == OB_GPENCIL) {
2795  ob->flag |= OB_DONE;
2796 
2797  /* Create a new grease pencil object and copy transformations. */
2798  ushort local_view_bits = (v3d && v3d->localvd) ? v3d->local_view_uuid : 0;
2799  float loc[3], size[3], rot[3][3], eul[3];
2800  float matrix[4][4];
2801  mat4_to_loc_rot_size(loc, rot, size, ob->obmat);
2802  mat3_to_eul(eul, rot);
2803 
2804  Object *ob_gpencil = ED_gpencil_add_object(C, loc, local_view_bits);
2805  copy_v3_v3(ob_gpencil->loc, loc);
2806  copy_v3_v3(ob_gpencil->rot, eul);
2807  copy_v3_v3(ob_gpencil->scale, size);
2808  unit_m4(matrix);
2809  /* Set object in 3D mode. */
2810  bGPdata *gpd = (bGPdata *)ob_gpencil->data;
2811  gpd->draw_mode = GP_DRAWMODE_3D;
2812 
2813  gpencilConverted |= BKE_gpencil_convert_mesh(bmain,
2814  depsgraph,
2815  scene,
2816  ob_gpencil,
2817  ob,
2818  angle,
2819  thickness,
2820  offset,
2821  matrix,
2822  0,
2823  use_seams,
2824  use_faces);
2825 
2826  /* Remove unused materials. */
2827  int actcol = ob_gpencil->actcol;
2828  for (int slot = 1; slot <= ob_gpencil->totcol; slot++) {
2829  while (slot <= ob_gpencil->totcol &&
2830  !BKE_object_material_slot_used(ob_gpencil->data, slot)) {
2831  ob_gpencil->actcol = slot;
2833 
2834  if (actcol >= slot) {
2835  actcol--;
2836  }
2837  }
2838  }
2839  ob_gpencil->actcol = actcol;
2840  }
2841  else if (ob->type == OB_MESH && target == OB_POINTCLOUD) {
2842  ob->flag |= OB_DONE;
2843 
2844  if (keep_original) {
2845  basen = duplibase_for_convert(bmain, depsgraph, scene, view_layer, base, NULL);
2846  newob = basen->object;
2847 
2848  /* decrement original mesh's usage count */
2849  Mesh *me = newob->data;
2850  id_us_min(&me->id);
2851 
2852  /* make a new copy of the mesh */
2853  newob->data = BKE_id_copy(bmain, &me->id);
2854  }
2855  else {
2856  newob = ob;
2857  }
2858 
2859  BKE_mesh_to_pointcloud(bmain, depsgraph, scene, newob);
2860 
2861  if (newob->type == OB_POINTCLOUD) {
2862  BKE_object_free_modifiers(newob, 0); /* after derivedmesh calls! */
2863  ED_rigidbody_object_remove(bmain, scene, newob);
2864  }
2865  }
2866  else if (ob->type == OB_MESH) {
2867  ob->flag |= OB_DONE;
2868 
2869  if (keep_original) {
2870  basen = duplibase_for_convert(bmain, depsgraph, scene, view_layer, base, NULL);
2871  newob = basen->object;
2872 
2873  /* decrement original mesh's usage count */
2874  Mesh *me = newob->data;
2875  id_us_min(&me->id);
2876 
2877  /* make a new copy of the mesh */
2878  newob->data = BKE_id_copy(bmain, &me->id);
2879  }
2880  else {
2881  newob = ob;
2883  }
2884 
2885  /* make new mesh data from the original copy */
2886  /* note: get the mesh from the original, not from the copy in some
2887  * cases this doesn't give correct results (when MDEF is used for eg)
2888  */
2889  Scene *scene_eval = (Scene *)DEG_get_evaluated_id(depsgraph, &scene->id);
2890  Object *ob_eval = DEG_get_evaluated_object(depsgraph, ob);
2891  Mesh *me_eval = mesh_get_eval_final(depsgraph, scene_eval, ob_eval, &CD_MASK_MESH);
2892  me_eval = BKE_mesh_copy_for_eval(me_eval, false);
2893  /* Full (edge-angle based) draw calculation should ideally be performed. */
2895  BKE_mesh_nomain_to_mesh(me_eval, newob->data, newob, &CD_MASK_MESH, true);
2896  BKE_object_free_modifiers(newob, 0); /* after derivedmesh calls! */
2897  }
2898  else if (ob->type == OB_FONT) {
2899  ob->flag |= OB_DONE;
2900 
2901  if (keep_original) {
2902  basen = duplibase_for_convert(bmain, depsgraph, scene, view_layer, base, NULL);
2903  newob = basen->object;
2904 
2905  /* decrement original curve's usage count */
2906  id_us_min(&((Curve *)newob->data)->id);
2907 
2908  /* make a new copy of the curve */
2909  newob->data = BKE_id_copy(bmain, ob->data);
2910  }
2911  else {
2912  newob = ob;
2913  }
2914 
2915  Curve *cu = newob->data;
2916 
2917  Object *ob_eval = DEG_get_evaluated_object(depsgraph, ob);
2918  BKE_vfont_to_curve_ex(ob_eval, ob_eval->data, FO_EDIT, &cu->nurb, NULL, NULL, NULL, NULL);
2919 
2920  newob->type = OB_CURVE;
2921  cu->type = OB_CURVE;
2922 
2923  if (cu->vfont) {
2924  id_us_min(&cu->vfont->id);
2925  cu->vfont = NULL;
2926  }
2927  if (cu->vfontb) {
2928  id_us_min(&cu->vfontb->id);
2929  cu->vfontb = NULL;
2930  }
2931  if (cu->vfonti) {
2932  id_us_min(&cu->vfonti->id);
2933  cu->vfonti = NULL;
2934  }
2935  if (cu->vfontbi) {
2936  id_us_min(&cu->vfontbi->id);
2937  cu->vfontbi = NULL;
2938  }
2939 
2940  if (!keep_original) {
2941  /* other users */
2942  if (ID_REAL_USERS(&cu->id) > 1) {
2943  for (ob1 = bmain->objects.first; ob1; ob1 = ob1->id.next) {
2944  if (ob1->data == ob->data) {
2945  ob1->type = OB_CURVE;
2946  DEG_id_tag_update(&ob1->id,
2948  }
2949  }
2950  }
2951  }
2952 
2953  LISTBASE_FOREACH (Nurb *, nu, &cu->nurb) {
2954  nu->charidx = 0;
2955  }
2956 
2957  cu->flag &= ~CU_3D;
2959 
2960  if (target == OB_MESH) {
2961  /* No assumption should be made that the resulting objects is a mesh, as conversion can
2962  * fail. */
2964  /* meshes doesn't use displist */
2966  }
2967  }
2968  else if (ELEM(ob->type, OB_CURVE, OB_SURF)) {
2969  ob->flag |= OB_DONE;
2970 
2971  if (target == OB_MESH) {
2972  if (keep_original) {
2973  basen = duplibase_for_convert(bmain, depsgraph, scene, view_layer, base, NULL);
2974  newob = basen->object;
2975 
2976  /* decrement original curve's usage count */
2977  id_us_min(&((Curve *)newob->data)->id);
2978 
2979  /* make a new copy of the curve */
2980  newob->data = BKE_id_copy(bmain, ob->data);
2981  }
2982  else {
2983  newob = ob;
2984  }
2985 
2986  /* No assumption should be made that the resulting objects is a mesh, as conversion can
2987  * fail. */
2989  /* meshes doesn't use displist */
2991  }
2992  else if (target == OB_GPENCIL) {
2993  if (ob->type != OB_CURVE) {
2994  ob->flag &= ~OB_DONE;
2995  BKE_report(op->reports, RPT_ERROR, "Convert Surfaces to Grease Pencil is not supported");
2996  }
2997  else {
2998  /* Create a new grease pencil object and copy transformations.
2999  * Nurbs Surface are not supported.
3000  */
3001  ushort local_view_bits = (v3d && v3d->localvd) ? v3d->local_view_uuid : 0;
3002  Object *ob_gpencil = ED_gpencil_add_object(C, ob->loc, local_view_bits);
3003  copy_v3_v3(ob_gpencil->rot, ob->rot);
3004  copy_v3_v3(ob_gpencil->scale, ob->scale);
3005  BKE_gpencil_convert_curve(bmain, scene, ob_gpencil, ob, false, 1.0f, 0.0f);
3006  gpencilConverted = true;
3007  }
3008  }
3009  }
3010  else if (ob->type == OB_MBALL && target == OB_MESH) {
3011  Object *baseob;
3012 
3013  base->flag &= ~BASE_SELECTED;
3014  ob->base_flag &= ~BASE_SELECTED;
3015 
3016  baseob = BKE_mball_basis_find(scene, ob);
3017 
3018  if (ob != baseob) {
3019  /* if motherball is converting it would be marked as done later */
3020  ob->flag |= OB_DONE;
3021  }
3022 
3023  if (!(baseob->flag & OB_DONE)) {
3024  basen = duplibase_for_convert(bmain, depsgraph, scene, view_layer, base, baseob);
3025  newob = basen->object;
3026 
3027  MetaBall *mb = newob->data;
3028  id_us_min(&mb->id);
3029 
3030  newob->data = BKE_mesh_add(bmain, "Mesh");
3031  newob->type = OB_MESH;
3032 
3033  Mesh *me = newob->data;
3034  me->totcol = mb->totcol;
3035  if (newob->totcol) {
3036  me->mat = MEM_dupallocN(mb->mat);
3037  for (a = 0; a < newob->totcol; a++) {
3038  id_us_plus((ID *)me->mat[a]);
3039  }
3040  }
3041 
3043  BKE_mesh_from_metaball(&baseob->runtime.curve_cache->disp, newob->data);
3044 
3045  if (obact->type == OB_MBALL) {
3046  basact = basen;
3047  }
3048 
3049  baseob->flag |= OB_DONE;
3050  mballConverted = 1;
3051  }
3052  }
3053  else if (ob->type == OB_POINTCLOUD && target == OB_MESH) {
3054  ob->flag |= OB_DONE;
3055 
3056  if (keep_original) {
3057  basen = duplibase_for_convert(bmain, depsgraph, scene, view_layer, base, NULL);
3058  newob = basen->object;
3059 
3060  /* decrement original pointclouds's usage count */
3061  PointCloud *pointcloud = newob->data;
3062  id_us_min(&pointcloud->id);
3063 
3064  /* make a new copy of the pointcloud */
3065  newob->data = BKE_id_copy(bmain, &pointcloud->id);
3066  }
3067  else {
3068  newob = ob;
3069  }
3070 
3071  BKE_pointcloud_to_mesh(bmain, depsgraph, scene, newob);
3072 
3073  if (newob->type == OB_MESH) {
3074  BKE_object_free_modifiers(newob, 0); /* after derivedmesh calls! */
3075  ED_rigidbody_object_remove(bmain, scene, newob);
3076  }
3077  }
3078  else {
3079  continue;
3080  }
3081 
3082  /* Ensure new object has consistent material data with its new obdata. */
3083  if (newob) {
3084  BKE_object_materials_test(bmain, newob, newob->data);
3085  }
3086 
3087  /* tag obdata if it was been changed */
3088 
3089  /* If the original object is active then make this object active */
3090  if (basen) {
3091  if (ob == obact) {
3092  /* store new active base to update BASACT */
3093  basact = basen;
3094  }
3095 
3096  basen = NULL;
3097  }
3098 
3099  if (!keep_original && (ob->flag & OB_DONE)) {
3100  /* NOTE: Tag transform for update because object parenting to curve with path is handled
3101  * differently from all other cases. Converting curve to mesh and mesh to curve will likely
3102  * affect the way children are evaluated.
3103  * It is not enough to tag only geometry and rely on the curve parenting relations because
3104  * this relation is lost when curve is converted to mesh. */
3106  ((ID *)ob->data)->tag &= ~LIB_TAG_DOIT; /* flag not to convert this datablock again */
3107  }
3108  }
3109  BLI_freelistN(&selected_editable_bases);
3110 
3111  if (!keep_original) {
3112  if (mballConverted) {
3113  /* We need to remove non-basis MBalls first, otherwise we won't be able to detect them if
3114  * their basis happens to be removed first. */
3115  FOREACH_SCENE_OBJECT_BEGIN (scene, ob_mball) {
3116  if (ob_mball->type == OB_MBALL) {
3117  Object *ob_basis = NULL;
3118  if (!BKE_mball_is_basis(ob_mball) &&
3119  ((ob_basis = BKE_mball_basis_find(scene, ob_mball)) && (ob_basis->flag & OB_DONE))) {
3120  ED_object_base_free_and_unlink(bmain, scene, ob_mball);
3121  }
3122  }
3123  }
3125  FOREACH_SCENE_OBJECT_BEGIN (scene, ob_mball) {
3126  if (ob_mball->type == OB_MBALL) {
3127  if (ob_mball->flag & OB_DONE) {
3128  if (BKE_mball_is_basis(ob_mball)) {
3129  ED_object_base_free_and_unlink(bmain, scene, ob_mball);
3130  }
3131  }
3132  }
3133  }
3135  }
3136  /* Remove curves and meshes converted to Grease Pencil object. */
3137  if (gpencilConverted) {
3138  FOREACH_SCENE_OBJECT_BEGIN (scene, ob_delete) {
3139  if (ELEM(ob_delete->type, OB_CURVE, OB_MESH)) {
3140  if (ob_delete->flag & OB_DONE) {
3141  ED_object_base_free_and_unlink(bmain, scene, ob_delete);
3142  }
3143  }
3144  }
3146  }
3147  }
3148 
3149  // XXX ED_object_editmode_enter(C, 0);
3150  // XXX exit_editmode(C, EM_FREEDATA|); /* freedata, but no undo */
3151 
3152  if (basact) {
3153  /* active base was changed */
3154  ED_object_base_activate(C, basact);
3155  BASACT(view_layer) = basact;
3156  }
3157  else if (BASACT(view_layer)->object->flag & OB_DONE) {
3158  WM_event_add_notifier(C, NC_OBJECT | ND_MODIFIER, BASACT(view_layer)->object);
3159  WM_event_add_notifier(C, NC_OBJECT | ND_DATA, BASACT(view_layer)->object);
3160  }
3161 
3162  DEG_relations_tag_update(bmain);
3167 
3168  return OPERATOR_FINISHED;
3169 }
3170 
3172 {
3173  uiLayout *layout = op->layout;
3175  PointerRNA ptr;
3176 
3177  uiLayoutSetPropSep(layout, true);
3178 
3179  RNA_pointer_create(&wm->id, op->type->srna, op->properties, &ptr);
3180  uiItemR(layout, &ptr, "target", 0, NULL, ICON_NONE);
3181  uiItemR(layout, &ptr, "keep_original", 0, NULL, ICON_NONE);
3182 
3183  if (RNA_enum_get(&ptr, "target") == OB_GPENCIL) {
3184  uiItemR(layout, &ptr, "thickness", 0, NULL, ICON_NONE);
3185  uiItemR(layout, &ptr, "angle", 0, NULL, ICON_NONE);
3186  uiItemR(layout, &ptr, "offset", 0, NULL, ICON_NONE);
3187  uiItemR(layout, &ptr, "seams", 0, NULL, ICON_NONE);
3188  uiItemR(layout, &ptr, "faces", 0, NULL, ICON_NONE);
3189  }
3190 }
3191 
3193 {
3194  PropertyRNA *prop;
3195 
3196  /* identifiers */
3197  ot->name = "Convert To";
3198  ot->description = "Convert selected objects to another type";
3199  ot->idname = "OBJECT_OT_convert";
3200 
3201  /* api callbacks */
3205  ot->ui = object_convert_ui;
3206 
3207  /* flags */
3209 
3210  /* properties */
3211  ot->prop = RNA_def_enum(
3212  ot->srna, "target", convert_target_items, OB_MESH, "Target", "Type of object to convert to");
3214  "keep_original",
3215  0,
3216  "Keep Original",
3217  "Keep original objects instead of replacing them");
3218 
3219  prop = RNA_def_float_rotation(ot->srna,
3220  "angle",
3221  0,
3222  NULL,
3223  DEG2RADF(0.0f),
3224  DEG2RADF(180.0f),
3225  "Threshold Angle",
3226  "Threshold to determine ends of the strokes",
3227  DEG2RADF(0.0f),
3228  DEG2RADF(180.0f));
3230 
3231  RNA_def_int(ot->srna, "thickness", 5, 1, 100, "Thickness", "", 1, 100);
3232  RNA_def_boolean(ot->srna, "seams", 0, "Only Seam Edges", "Convert only seam edges");
3233  RNA_def_boolean(ot->srna, "faces", 1, "Export Faces", "Export faces as filled strokes");
3235  "offset",
3236  0.01f,
3237  0.0,
3239  "Stroke Offset",
3240  "Offset strokes from fill",
3241  0.0,
3242  100.00);
3243 }
3244 
3247 /* -------------------------------------------------------------------- */
3251 /*
3252  * dupflag: a flag made from constants declared in DNA_userdef_types.h
3253  * The flag tells adduplicate() whether to copy data linked to the object,
3254  * or to reference the existing data.
3255  * U.dupflag for default operations or you can construct a flag as python does
3256  * if the dupflag is 0 then no data will be copied (linked duplicate). */
3257 
3258 /* used below, assumes id.new is correct */
3259 /* leaves selection of base/object unaltered */
3260 /* Does set ID->newid pointers. */
3262  Scene *scene,
3263  ViewLayer *view_layer,
3264  Object *ob,
3265  const eDupli_ID_Flags dupflag,
3266  const eLibIDDuplicateFlags duplicate_options)
3267 {
3268  Base *base, *basen = NULL;
3269  Object *obn;
3270 
3271  if (ob->mode & OB_MODE_POSE) {
3272  /* nothing? */
3273  }
3274  else {
3275  obn = ID_NEW_SET(ob, BKE_object_duplicate(bmain, ob, dupflag, duplicate_options));
3277 
3278  base = BKE_view_layer_base_find(view_layer, ob);
3279  if ((base != NULL) && (base->flag & BASE_VISIBLE_DEPSGRAPH)) {
3280  BKE_collection_object_add_from(bmain, scene, ob, obn);
3281  }
3282  else {
3283  LayerCollection *layer_collection = BKE_layer_collection_get_active(view_layer);
3284  BKE_collection_object_add(bmain, layer_collection->collection, obn);
3285  }
3286 
3287  basen = BKE_view_layer_base_find(view_layer, obn);
3288  if (base != NULL) {
3289  basen->local_view_bits = base->local_view_bits;
3290  }
3291 
3292  /* 1) duplis should end up in same collection as the original
3293  * 2) Rigid Body sim participants MUST always be part of a collection...
3294  */
3295  /* XXX: is 2) really a good measure here? */
3296  if (ob->rigidbody_object || ob->rigidbody_constraint) {
3297  Collection *collection;
3298  for (collection = bmain->collections.first; collection; collection = collection->id.next) {
3299  if (BKE_collection_has_object(collection, ob)) {
3300  BKE_collection_object_add(bmain, collection, obn);
3301  }
3302  }
3303  }
3304  }
3305  return basen;
3306 }
3307 
3308 /* single object duplicate, if dupflag==0, fully linked, else it uses the flags given */
3309 /* leaves selection of base/object unaltered.
3310  * note: don't call this within a loop since clear_* funcs loop over the entire database.
3311  * note: caller must do DAG_relations_tag_update(bmain);
3312  * this is not done automatic since we may duplicate many objects in a batch */
3314  Main *bmain, Scene *scene, ViewLayer *view_layer, Base *base, const eDupli_ID_Flags dupflag)
3315 {
3316  Base *basen;
3317  Object *ob;
3318 
3319  basen = object_add_duplicate_internal(bmain,
3320  scene,
3321  view_layer,
3322  base->object,
3323  dupflag,
3326  if (basen == NULL) {
3327  return NULL;
3328  }
3329 
3330  ob = basen->object;
3331 
3332  /* link own references to the newly duplicated data T26816. */
3334 
3335  /* DAG_relations_tag_update(bmain); */ /* caller must do */
3336 
3337  if (ob->data != NULL) {
3339  }
3340 
3342 
3343  return basen;
3344 }
3345 
3346 /* contextual operator dupli */
3348 {
3349  Main *bmain = CTX_data_main(C);
3351  ViewLayer *view_layer = CTX_data_view_layer(C);
3352  const bool linked = RNA_boolean_get(op->ptr, "linked");
3353  const eDupli_ID_Flags dupflag = (linked) ? 0 : (eDupli_ID_Flags)U.dupflag;
3354 
3355  /* We need to handle that here ourselves, because we may duplicate several objects, in which case
3356  * we also want to remap pointers between those... */
3357  BKE_main_id_tag_all(bmain, LIB_TAG_NEW, false);
3359 
3360  CTX_DATA_BEGIN (C, Base *, base, selected_bases) {
3361  Base *basen = object_add_duplicate_internal(bmain,
3362  scene,
3363  view_layer,
3364  base->object,
3365  dupflag,
3368 
3369  /* note that this is safe to do with this context iterator,
3370  * the list is made in advance */
3373 
3374  if (basen == NULL) {
3375  continue;
3376  }
3377 
3378  /* new object becomes active */
3379  if (BASACT(view_layer) == base) {
3380  ED_object_base_activate(C, basen);
3381  }
3382 
3383  if (basen->object->data) {
3384  DEG_id_tag_update(basen->object->data, 0);
3385  }
3386  }
3387  CTX_DATA_END;
3388 
3389  /* Note that this will also clear newid pointers and tags. */
3391 
3393 
3394  DEG_relations_tag_update(bmain);
3396 
3399 
3400  return OPERATOR_FINISHED;
3401 }
3402 
3404 {
3405  PropertyRNA *prop;
3406 
3407  /* identifiers */
3408  ot->name = "Duplicate Objects";
3409  ot->description = "Duplicate selected objects";
3410  ot->idname = "OBJECT_OT_duplicate";
3411 
3412  /* api callbacks */
3413  ot->exec = duplicate_exec;
3415 
3416  /* flags */
3418 
3419  /* to give to transform */
3420  prop = RNA_def_boolean(ot->srna,
3421  "linked",
3422  0,
3423  "Linked",
3424  "Duplicate object but not object data, linking to the original data");
3426 
3427  prop = RNA_def_enum(
3428  ot->srna, "mode", rna_enum_transform_mode_types, TFM_TRANSLATION, "Mode", "");
3430 }
3431 
3434 /* -------------------------------------------------------------------- */
3441 {
3442  Main *bmain = CTX_data_main(C);
3444  ViewLayer *view_layer = CTX_data_view_layer(C);
3445  Base *basen;
3446  Object *ob;
3447  const bool linked = RNA_boolean_get(op->ptr, "linked");
3448  const eDupli_ID_Flags dupflag = (linked) ? 0 : (eDupli_ID_Flags)U.dupflag;
3449  char name[MAX_ID_NAME - 2];
3450 
3451  /* find object, create fake base */
3452  RNA_string_get(op->ptr, "name", name);
3453  ob = (Object *)BKE_libblock_find_name(bmain, ID_OB, name);
3454 
3455  if (ob == NULL) {
3456  BKE_report(op->reports, RPT_ERROR, "Object not found");
3457  return OPERATOR_CANCELLED;
3458  }
3459 
3460  /* prepare dupli */
3462  bmain,
3463  scene,
3464  view_layer,
3465  ob,
3466  dupflag,
3467  /* Sub-process flag because the new-ID remapping (#BKE_libblock_relink_to_newid()) in this
3468  * function will only work if the object is already linked in the view layer, which is not
3469  * the case here. So we have to do the new-ID relinking ourselves (#copy_object_set_idnew()).
3470  */
3472 
3473  if (basen == NULL) {
3474  BKE_report(op->reports, RPT_ERROR, "Object could not be duplicated");
3475  return OPERATOR_CANCELLED;
3476  }
3477 
3479 
3480  int mval[2];
3481  if (object_add_drop_xy_get(C, op, &mval)) {
3483  ED_view3d_cursor3d_position(C, mval, false, basen->object->loc);
3484  }
3485 
3486  /* object_add_duplicate_internal() doesn't deselect other objects, unlike object_add_common() or
3487  * BKE_view_layer_base_deselect_all(). */
3490  ED_object_base_activate(C, basen);
3491 
3493 
3494  /* TODO(sergey): Only update relations for the current scene. */
3495  DEG_relations_tag_update(bmain);
3496 
3502 
3503  return OPERATOR_FINISHED;
3504 }
3505 
3507 {
3508  /* identifiers */
3509  ot->name = "Add Named Object";
3510  ot->description = "Add named object";
3511  ot->idname = "OBJECT_OT_add_named";
3512 
3513  /* api callbacks */
3517 
3518  /* flags */
3520 
3522  "linked",
3523  0,
3524  "Linked",
3525  "Duplicate object but not object data, linking to the original data");
3526  RNA_def_string(ot->srna, "name", NULL, MAX_ID_NAME - 2, "Name", "Object name to add");
3527 
3529 }
3530 
3533 /* -------------------------------------------------------------------- */
3538 {
3540 
3541  if (ob == NULL || ob->data == NULL || ID_IS_LINKED(ob) || ID_IS_OVERRIDE_LIBRARY(ob) ||
3543  return false;
3544  }
3545 
3547  return ED_operator_screenactive(C);
3548  }
3549  return false;
3550 }
3551 
3553 {
3555 
3556  if (ob->mode & OB_MODE_EDIT) {
3557  BKE_report(op->reports, RPT_ERROR, "This data does not support joining in edit mode");
3558  return OPERATOR_CANCELLED;
3559  }
3560  if (BKE_object_obdata_is_libdata(ob)) {
3561  BKE_report(op->reports, RPT_ERROR, "Cannot edit external library data");
3562  return OPERATOR_CANCELLED;
3563  }
3564  if (ob->type == OB_GPENCIL) {
3565  bGPdata *gpd = (bGPdata *)ob->data;
3566  if ((!gpd) || GPENCIL_ANY_MODE(gpd)) {
3567  BKE_report(op->reports, RPT_ERROR, "This data does not support joining in this mode");
3568  return OPERATOR_CANCELLED;
3569  }
3570  }
3571 
3572  int ret = OPERATOR_CANCELLED;
3573  if (ob->type == OB_MESH) {
3575  }
3576  else if (ELEM(ob->type, OB_CURVE, OB_SURF)) {
3578  }
3579  else if (ob->type == OB_ARMATURE) {
3581  }
3582  else if (ob->type == OB_GPENCIL) {
3584  }
3585 
3586  if (ret & OPERATOR_FINISHED) {
3587  /* Even though internally failure to invert is accounted for with a fallback,
3588  * show a warning since the result may not be what the user expects. See T80077.
3589  *
3590  * Failure to invert the matrix is typically caused by zero scaled axes
3591  * (which can be caused by constraints, even if the input scale isn't zero).
3592  *
3593  * Internally the join functions use #invert_m4_m4_safe_ortho which creates
3594  * an inevitable matrix from one that has one or more degenerate axes.
3595  *
3596  * In most cases we don't worry about special handling for non-inevitable matrices however for
3597  * joining objects there may be flat 2D objects where it's not obvious the scale is zero.
3598  * In this case, using #invert_m4_m4_safe_ortho works as well as we can expect,
3599  * joining the contents, flattening on the axis that's zero scaled.
3600  * If the zero scale is removed, the data on this axis remains un-scaled
3601  * (something that wouldn't work for #invert_m4_m4_safe). */
3602  float imat_test[4][4];
3603  if (!invert_m4_m4(imat_test, ob->obmat)) {
3604  BKE_report(op->reports,
3605  RPT_WARNING,
3606  "Active object final transform has one or more zero scaled axes");
3607  }
3608  }
3609 
3610  return ret;
3611 }
3612 
3614 {
3615  /* identifiers */
3616  ot->name = "Join";
3617  ot->description = "Join selected objects into active object";
3618  ot->idname = "OBJECT_OT_join";
3619 
3620  /* api callbacks */
3623 
3624  /* flags */
3626 }
3627 
3630 /* -------------------------------------------------------------------- */
3635 {
3637 
3638  if (ob == NULL || ob->data == NULL || ID_IS_LINKED(ob) || ID_IS_OVERRIDE_LIBRARY(ob) ||
3640  return false;
3641  }
3642 
3643  /* only meshes supported at the moment */
3644  if (ob->type == OB_MESH) {
3645  return ED_operator_screenactive(C);
3646  }
3647  return false;
3648 }
3649 
3651 {
3653 
3654  if (ob->mode & OB_MODE_EDIT) {
3655  BKE_report(op->reports, RPT_ERROR, "This data does not support joining in edit mode");
3656  return OPERATOR_CANCELLED;
3657  }
3658  if (BKE_object_obdata_is_libdata(ob)) {
3659  BKE_report(op->reports, RPT_ERROR, "Cannot edit external library data");
3660  return OPERATOR_CANCELLED;
3661  }
3662 
3663  if (ob->type == OB_MESH) {
3664  return ED_mesh_shapes_join_objects_exec(C, op);
3665  }
3666 
3667  return OPERATOR_CANCELLED;
3668 }
3669 
3671 {
3672  /* identifiers */
3673  ot->name = "Join as Shapes";
3674  ot->description = "Copy the current resulting shape of another selected object to this one";
3675  ot->idname = "OBJECT_OT_join_shapes";
3676 
3677  /* api callbacks */
3680 
3681  /* flags */
3683 }
3684 
typedef float(TangentPoint)[2]
Blender kernel action and pose functionality.
void BKE_animdata_free(struct ID *id, const bool do_id_user)
Definition: anim_data.c:230
struct AnimData * BKE_animdata_add_id(struct ID *id)
Definition: anim_data.c:113
Camera data-block and utility functions.
bool BKE_collection_cycle_find(struct Collection *new_ancestor, struct Collection *collection)
Definition: collection.c:1450
#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:1168
bool BKE_collection_object_add(struct Main *bmain, struct Collection *collection, struct Object *ob)
Definition: collection.c:1134
bool BKE_collection_has_object(struct Collection *collection, const struct Object *ob)
bool BKE_scene_collections_object_remove(struct Main *bmain, struct Scene *scene, struct Object *object, const bool free_us)
Definition: collection.c:1243
#define FOREACH_SCENE_OBJECT_BEGIN(scene, _instance)
void BKE_constraints_free(struct ListBase *list)
Definition: constraint.c:5509
struct Scene * CTX_data_scene(const bContext *C)
Definition: context.c:1034
struct Object * CTX_data_edit_object(const bContext *C)
Definition: context.c:1296
int CTX_data_selected_editable_bases(const bContext *C, ListBase *list)
Definition: context.c:1234
struct Base * CTX_data_active_base(const bContext *C)
Definition: context.c:1284
struct wmWindowManager * CTX_wm_manager(const bContext *C)
Definition: context.c:689
#define CTX_DATA_BEGIN(C, Type, instance, member)
Definition: BKE_context.h:252
struct ViewLayer * CTX_data_view_layer(const bContext *C)
Definition: context.c:1044
struct Collection * CTX_data_collection(const bContext *C)
Definition: context.c:1092
struct Depsgraph * CTX_data_ensure_evaluated_depsgraph(const bContext *C)
Definition: context.c:1424
struct Object * CTX_data_active_object(const bContext *C)
Definition: context.c:1279
struct View3D * CTX_wm_view3d(const bContext *C)
Definition: context.c:760
struct ARegion * CTX_wm_region(const bContext *C)
Definition: context.c:725
struct Main * CTX_data_main(const bContext *C)
Definition: context.c:1018
struct RegionView3D * CTX_wm_region_view3d(const bContext *C)
Definition: context.c:769
#define CTX_DATA_END
Definition: BKE_context.h:260
void BKE_curve_dimension_update(struct Curve *cu)
Definition: curve.c:467
void CustomData_MeshMasks_update(CustomData_MeshMasks *mask_dst, const CustomData_MeshMasks *mask_src)
Definition: customdata.c:76
const CustomData_MeshMasks CD_MASK_MESH
Definition: customdata.c:1933
display list (or rather multi purpose list) stuff.
void BKE_displist_make_curveTypes(struct Depsgraph *depsgraph, const struct Scene *scene, struct Object *ob, const bool for_render, const bool for_orco)
void BKE_displist_make_mball(struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob)
Definition: displist.c:685
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:86
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: font.c:1704
bool BKE_geometry_set_has_instances(const struct GeometrySet *geometry_set)
void BKE_gpencil_convert_curve(struct Main *bmain, struct Scene *scene, struct Object *ob_gp, struct Object *ob_cu, const bool use_collections, const float scale_thickness, const float sample)
bool BKE_gpencil_convert_mesh(struct Main *bmain, struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob_gp, struct Object *ob_mesh, const float angle, const int thickness, const float offset, const float matrix[4][4], const int frame_offset, const bool use_seams, const bool use_faces)
bool BKE_gpencil_modifier_unique_name(struct ListBase *modifiers, struct GpencilModifierData *gmd)
struct GpencilModifierData * BKE_gpencil_modifier_new(int type)
General operations for hairs.
struct LayerCollection * BKE_layer_collection_get_active(struct ViewLayer *view_layer)
Definition: layer.c:630
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:394
struct ID * BKE_id_copy(struct Main *bmain, const struct ID *id)
void id_us_min(struct ID *id)
Definition: lib_id.c:297
void BKE_main_id_tag_all(struct Main *mainvar, const int tag, const bool value)
Definition: lib_id.c:923
void BKE_main_id_clear_newpoins(struct Main *bmain)
Definition: lib_id.c:1738
void id_us_plus(struct ID *id)
Definition: lib_id.c:288
#define IS_TAGGED(_id)
Definition: BKE_lib_id.h:322
void BKE_main_id_tag_listbase(struct ListBase *lb, const int tag, const bool value)
Definition: lib_id.c:891
struct ID * BKE_libblock_find_name(struct Main *bmain, const short type, const char *name) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition: lib_id.c:1333
size_t BKE_id_multi_tagged_delete(struct Main *bmain) ATTR_NONNULL()
eLibIDDuplicateFlags
Definition: BKE_lib_id.h:169
@ LIB_ID_DUPLICATE_IS_ROOT_ID
Definition: BKE_lib_id.h:178
@ LIB_ID_DUPLICATE_IS_SUBPROCESS
Definition: BKE_lib_id.h:175
bool BKE_library_ID_is_indirectly_used(struct Main *bmain, void *idv)
Definition: lib_query.c:588
void void BKE_libblock_relink_to_newid(struct ID *id) ATTR_NONNULL()
Definition: lib_remap.c:702
General operations, lookup, etc. for blender lights.
General operations for probes.
void BKE_lightprobe_type_set(struct LightProbe *probe, const short lightprobe_type)
Definition: lightprobe.c:115
#define FOREACH_MAIN_ID_END
Definition: BKE_main.h:250
#define FOREACH_MAIN_ID_BEGIN(_bmain, _id)
Definition: BKE_main.h:244
General operations, lookup, etc. for materials.
bool BKE_object_material_slot_remove(struct Main *bmain, struct Object *ob)
Definition: material.c:1107
bool BKE_object_material_slot_used(struct ID *id, short actcol)
Definition: material.c:465
struct Material * BKE_gpencil_material(struct Object *ob, short act)
Definition: material.c:703
void BKE_object_materials_test(struct Main *bmain, struct Object *ob, struct ID *id)
Definition: material.c:772
short * BKE_id_material_len_p(struct ID *id)
Definition: material.c:416
struct Object * BKE_mball_basis_find(struct Scene *scene, struct Object *ob)
This function finds the basis MetaBall.
Definition: mball.c:511
bool BKE_mball_is_basis(struct Object *ob)
Test, if ob is a basis meta-ball.
Definition: mball.c:398
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)
Definition: mesh_convert.c:983
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.c:77
struct Mesh * BKE_mesh_add(struct Main *bmain, const char *name)
Definition: mesh.c:849
void BKE_mesh_to_pointcloud(struct Main *bmain, struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob)
struct Mesh * BKE_mesh_copy_for_eval(struct Mesh *source, bool reference)
Definition: mesh.c:995
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, 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:1626
struct NlaStrip * BKE_nla_add_soundstrip(struct Main *bmain, struct Scene *scene, struct Speaker *speaker)
Definition: nla.c:401
struct NlaTrack * BKE_nlatrack_add(struct AnimData *adt, struct NlaTrack *prev, bool is_liboverride)
Definition: nla.c:283
bool BKE_nlatrack_add_strip(struct NlaTrack *nlt, struct NlaStrip *strip, const bool is_liboverride)
Definition: nla.c:1149
General operations, lookup, etc. for blender objects.
bool BKE_object_obdata_is_libdata(const struct Object *ob)
void BKE_object_free_modifiers(struct Object *ob, const int flag)
Definition: object.c:1200
void BKE_object_obdata_size_init(struct Object *ob, const float size)
Definition: object.c:2991
void BKE_object_empty_draw_type_set(struct Object *ob, const int value)
Definition: object.c:4061
struct Object * BKE_object_add(struct Main *bmain, struct ViewLayer *view_layer, int type, const char *name) ATTR_NONNULL(1
void BKE_object_free_shaderfx(struct Object *ob, const int flag)
Definition: object.c:1222
void BKE_object_to_mat4(struct Object *ob, float r_mat[4][4])
Definition: object.c:3234
void BKE_object_free_curve_cache(struct Object *ob)
Definition: object.c:1186
struct Object * BKE_object_duplicate(struct Main *bmain, struct Object *ob, uint dupflag, const uint duplicate_options)
int BKE_object_obdata_to_type(const struct ID *id) ATTR_NONNULL(1)
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.c:2269
void BKE_object_apply_mat4(struct Object *ob, const float mat[4][4], const bool use_compat, const bool use_parent)
Definition: object.c:3754
bool BKE_object_is_in_editmode(const struct Object *ob)
General operations for point-clouds.
void BKE_report(ReportList *reports, ReportType type, const char *message)
Definition: report.c:104
void BKE_reportf(ReportList *reports, ReportType type, const char *format,...) ATTR_PRINTF_FORMAT(3
void BKE_scene_graph_update_tagged(struct Depsgraph *depsgraph, struct Main *bmain)
Definition: scene.c:2713
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.c:2966
General operations for speakers.
Volume datablock.
#define BLI_assert(a)
Definition: BLI_assert.h:58
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:718
void BLI_ghash_insert(GHash *gh, void *key, void *val)
Definition: BLI_ghash.c:756
void BLI_ghash_free(GHash *gh, GHashKeyFreeFP keyfreefp, GHashValFreeFP valfreefp)
Definition: BLI_ghash.c:1008
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:851
#define BLI_ghashutil_inthash(key)
Definition: BLI_ghash.h:356
void * BLI_ghash_lookup(GHash *gh, const void *key) ATTR_WARN_UNUSED_RESULT
Definition: BLI_ghash.c:803
BLI_INLINE bool BLI_listbase_is_empty(const struct ListBase *lb)
Definition: BLI_listbase.h:124
#define LISTBASE_FOREACH(type, var, list)
Definition: BLI_listbase.h:172
void void BLI_freelistN(struct ListBase *listbase) ATTR_NONNULL(1)
Definition: listbase.c:547
void BLI_addtail(struct ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition: listbase.c:110
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:41
void mul_m3_v3(const float M[3][3], float r[3])
Definition: math_matrix.c:930
void mul_mat3_m4_fl(float R[4][4], float f)
Definition: math_matrix.c:982
void copy_m3_m4(float m1[3][3], const float m2[4][4])
Definition: math_matrix.c:105
void unit_m4(float m[4][4])
Definition: rct.c:1140
void copy_m4_m3(float m1[4][4], const float m2[3][3])
Definition: math_matrix.c:120
bool invert_m4_m4(float R[4][4], const float A[4][4])
Definition: math_matrix.c:1278
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:2236
bool invert_m3_m3(float R[3][3], const float A[3][3])
Definition: math_matrix.c:1161
void copy_m4_m4(float m1[4][4], const float m2[4][4])
Definition: math_matrix.c:95
bool invert_m3(float R[3][3])
Definition: math_matrix.c:1152
void mul_m3_m3m3(float R[3][3], const float A[3][3], const float B[3][3])
Definition: math_matrix.c:391
void eul_to_mat3(float mat[3][3], const float eul[3])
void axis_angle_to_quat(float r[4], const float axis[3], const 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:65
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:52
MINLINE void sub_v3_v3v3(float r[3], const float a[3], const float b[3])
MINLINE void mul_v3_fl(float r[3], float f)
MINLINE void copy_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_strncpy(char *__restrict dst, const char *__restrict src, const size_t maxncpy) ATTR_NONNULL()
Definition: string.c:108
unsigned int uint
Definition: BLI_sys_types.h:83
unsigned short ushort
Definition: BLI_sys_types.h:84
#define UNUSED(x)
#define ELEM(...)
#define BLT_I18NCONTEXT_ID_ID
#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:51
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:414
@ ID_RECALC_TRANSFORM
Definition: DNA_ID.h:599
@ ID_RECALC_COPY_ON_WRITE
Definition: DNA_ID.h:654
@ ID_RECALC_SELECT
Definition: DNA_ID.h:638
@ ID_RECALC_EDITORS
Definition: DNA_ID.h:648
@ ID_RECALC_ANIMATION
Definition: DNA_ID.h:614
@ ID_RECALC_GEOMETRY
Definition: DNA_ID.h:611
@ ID_RECALC_BASE_FLAGS
Definition: DNA_ID.h:641
@ LIB_TAG_INDIRECT
Definition: DNA_ID.h:524
@ LIB_TAG_NEW
Definition: DNA_ID.h:551
@ LIB_TAG_DOIT
Definition: DNA_ID.h:554
#define ID_IS_LINKED(_id)
Definition: DNA_ID.h:426
#define MAX_ID_NAME
Definition: DNA_ID.h:269
#define ID_REAL_USERS(id)
Definition: DNA_ID.h:413
#define ID_IS_OVERRIDE_LIBRARY(_id)
Definition: DNA_ID.h:445
#define ID_NEW_SET(_id, _idn)
Definition: DNA_ID.h:464
@ ID_IM
Definition: DNA_ID_enums.h:65
@ ID_GR
Definition: DNA_ID_enums.h:77
@ ID_OB
Definition: DNA_ID_enums.h:59
Object groups, one object can be in many groups at once.
@ CU_NURBS
@ CU_PRIM_PATH
@ CU_3D
@ CU_PATH
@ 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.
#define OB_DONE
#define MAX_DUPLI_RECUR
@ OB_DUPLI
@ OB_DUPLICOLLECTION
@ OB_DRAWBOUNDOX
@ OB_DRAW_IN_FRONT
@ OB_SINGLE_ARROW
@ OB_EMPTY_IMAGE
@ PAROBJECT
@ GP_STROKE
@ GP_MONKEY
@ GP_EMPTY
@ GP_LRT_OBJECT
@ GP_LRT_COLLECTION
@ GP_LRT_SCENE
@ OB_SPEAKER
@ OB_LATTICE
@ OB_MBALL
@ OB_EMPTY
@ OB_SURF
@ OB_CAMERA
@ OB_FONT
@ OB_ARMATURE
@ OB_LAMP
@ OB_MESH
@ OB_POINTCLOUD
@ OB_HAIR
@ OB_CURVE
@ OB_GPENCIL
@ OB_LIGHTPROBE
@ OB_RESTRICT_VIEWPORT
#define OBEDIT_FROM_VIEW_LAYER(view_layer)
#define CFRA
#define BASACT(_view_layer)
@ USER_ADD_VIEWALIGNED
@ USER_ADD_CURSORALIGNED
@ USER_ADD_EDITMODE
eDupli_ID_Flags
#define FO_EDIT
@ 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.c:757
int ED_mesh_join_objects_exec(struct bContext *C, struct wmOperator *op)
Definition: meshtools.c:331
void ED_object_base_select(struct Base *base, eObjectSelect_Mode mode)
Definition: object_select.c:98
@ EM_FREEDATA
Definition: ED_object.h:204
bool ED_object_editmode_exit_ex(struct Main *bmain, struct Scene *scene, struct Object *obedit, int flag)
Definition: object_edit.c:676
#define OBJECT_ADD_SIZE_MAXF
Definition: ED_object.h:288
bool ED_object_editmode_enter_ex(struct Main *bmain, struct Scene *scene, struct Object *ob, int flag)
Definition: object_edit.c:762
void ED_object_base_activate(struct bContext *C, struct Base *base)
@ BA_DESELECT
Definition: ED_object.h:146
@ BA_SELECT
Definition: ED_object.h:147
bool ED_object_base_deselect_all(struct ViewLayer *view_layer, struct View3D *v3d, int action)
void ED_outliner_select_sync_from_object_tag(struct bContext *C)
Definition: outliner_sync.c:56
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:133
bool ED_operator_objectmode(struct bContext *C)
Definition: screen_ops.c:201
bool ED_operator_scene_editable(struct bContext *C)
Definition: screen_ops.c:192
@ TFM_TRANSLATION
Definition: ED_transform.h:46
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], const bool use_depth, float r_cursor_co[3])
Definition: view3d_edit.c:4993
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
Read Guarded memory(de)allocation.
const EnumPropertyItem * RNA_collection_itemf(struct bContext *C, struct PointerRNA *ptr, struct PropertyRNA *prop, bool *r_free)
@ PROP_ENUM_NO_TRANSLATE
Definition: RNA_types.h:279
@ PROP_SKIP_SAVE
Definition: RNA_types.h:204
@ PROP_HIDDEN
Definition: RNA_types.h:202
#define C
Definition: RandGen.cpp:39
void uiLayoutSetActive(uiLayout *layout, bool active)
void uiLayoutSetPropSep(uiLayout *layout, bool is_sep)
uiLayout * uiLayoutRow(uiLayout *layout, bool align)
void uiItemR(uiLayout *layout, struct PointerRNA *ptr, const char *propname, int flag, const char *name, int icon)
#define ND_DRAW
Definition: WM_types.h:362
#define ND_OB_ACTIVE
Definition: WM_types.h:340
@ OPTYPE_UNDO
Definition: WM_types.h:155
@ OPTYPE_REGISTER
Definition: WM_types.h:153
#define ND_DATA
Definition: WM_types.h:408
#define NC_ANIMATION
Definition: WM_types.h:289
#define ND_OB_SELECT
Definition: WM_types.h:342
#define NC_SCENE
Definition: WM_types.h:279
#define NA_ADDED
Definition: WM_types.h:464
#define ND_LAYER_CONTENT
Definition: WM_types.h:354
#define ND_MODIFIER
Definition: WM_types.h:363
#define ND_PARENT
Definition: WM_types.h:368
#define NC_GPENCIL
Definition: WM_types.h:300
#define ND_NLA
Definition: WM_types.h:397
#define NC_OBJECT
Definition: WM_types.h:280
EditBone * ED_armature_ebone_add_primitive(Object *obedit_arm, float length, bool view_aligned)
Definition: armature_add.c:105
int ED_armature_join_objects_exec(bContext *C, wmOperator *op)
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
#define SELECT
Scene scene
Curve curve
const Depsgraph * depsgraph
int ED_curve_join_objects_exec(bContext *C, wmOperator *op)
Definition: editcurve.c:6824
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_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)
#define GS(x)
Definition: iris.c:241
void *(* MEM_dupallocN)(const void *vmemh)
Definition: mallocn.c:42
int main(int argc, char **argv)
Definition: msgfmt.c:457
static unsigned a[3]
Definition: RandGen.cpp:92
#define hash
Definition: noise.c:169
static void object_add_ui(bContext *UNUSED(C), wmOperator *op)
Definition: object_add.c:1457
static void view_align_update(struct Main *UNUSED(main), struct Scene *UNUSED(scene), struct PointerRNA *ptr)
Definition: object_add.c:373
static bool object_gpencil_add_poll(bContext *C)
Definition: object_add.c:1289
void ED_object_add_unit_props_size(wmOperatorType *ot)
Definition: object_add.c:380
static uint dupliobject_hash(const void *ptr)
Definition: object_add.c:2163
static const EnumPropertyItem convert_target_items[]
Definition: object_add.c:2519
static int object_delete_exec(bContext *C, wmOperator *op)
Definition: object_add.c:1986
static bool object_convert_poll(bContext *C)
Definition: object_add.c:2597
void OBJECT_OT_drop_named_image(wmOperatorType *ot)
Definition: object_add.c:1253
static const EnumPropertyItem align_options[]
Definition: object_add.c:185
void OBJECT_OT_convert(wmOperatorType *ot)
Definition: object_add.c:3192
void OBJECT_OT_speaker_add(wmOperatorType *ot)
Definition: object_add.c:1844
static bool object_hair_add_poll(bContext *C)
Definition: object_add.c:1867
static int collection_instance_add_exec(bContext *C, wmOperator *op)
Definition: object_add.c:1616
static int empty_drop_named_image_invoke(bContext *C, wmOperator *op, const wmEvent *event)
Definition: object_add.c:1205
static int object_add_drop_xy_generic_invoke(bContext *C, wmOperator *op, const wmEvent *event)
Definition: object_add.c:257
static int object_instance_add_invoke(bContext *C, wmOperator *op, const wmEvent *event)
Definition: object_add.c:1675
static bool dupliobject_instancer_cmp(const void *a_, const void *b_)
Definition: object_add.c:2230
void ED_object_rotation_from_view(bContext *C, float rot[3], const char align_axis)
Definition: object_add.c:304
void OBJECT_OT_metaball_add(wmOperatorType *ot)
Definition: object_add.c:1017
void OBJECT_OT_add_named(wmOperatorType *ot)
Definition: object_add.c:3506
void OBJECT_OT_duplicate(wmOperatorType *ot)
Definition: object_add.c:3403
void OBJECT_OT_effector_add(wmOperatorType *ot)
Definition: object_add.c:885
bool ED_object_add_generic_get_opts(bContext *C, wmOperator *op, const char view_align_axis, float loc[3], float rot[3], float scale[3], bool *enter_editmode, ushort *local_view_bits, bool *is_view_aligned)
Definition: object_add.c:455
static int join_shapes_exec(bContext *C, wmOperator *op)
Definition: object_add.c:3650
void OBJECT_OT_light_add(wmOperatorType *ot)
Definition: object_add.c:1587
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.c:659
static bool dupliobject_cmp(const void *a_, const void *b_)
Definition: object_add.c:2196
void ED_object_base_init_transform_on_add(Object *object, const float loc[3], const float rot[3])
Definition: object_add.c:319
void OBJECT_OT_delete(wmOperatorType *ot)
Definition: object_add.c:2082
static void object_data_convert_ensure_curve_cache(Depsgraph *depsgraph, Scene *scene, Object *ob)
Definition: object_add.c:2545
void ED_object_add_unit_props_radius_ex(wmOperatorType *ot, float default_value)
Definition: object_add.c:386
static const char * get_effector_defname(ePFieldType type)
Definition: object_add.c:796
void OBJECT_OT_empty_add(wmOperatorType *ot)
Definition: object_add.c:1183
void OBJECT_OT_lightprobe_add(wmOperatorType *ot)
Definition: object_add.c:767
static int object_add_named_exec(bContext *C, wmOperator *op)
Definition: object_add.c:3440
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.c:596
void ED_object_base_free_and_unlink(Main *bmain, Scene *scene, Object *ob)
Definition: object_add.c:1958
static int object_pointcloud_add_exec(bContext *C, wmOperator *op)
Definition: object_add.c:1920
static void object_add_drop_xy_props(wmOperatorType *ot)
Definition: object_add.c:202
static const char * get_lightprobe_defname(int type)
Definition: object_add.c:727
static bool object_add_drop_xy_get(bContext *C, wmOperator *op, int(*r_mval)[2])
Definition: object_add.c:238
void OBJECT_OT_duplicates_make_real(wmOperatorType *ot)
Definition: object_add.c:2489
static int object_add_text_exec(bContext *C, wmOperator *op)
Definition: object_add.c:1044
void OBJECT_OT_text_add(wmOperatorType *ot)
Definition: object_add.c:1068
void ED_object_location_from_view(bContext *C, float loc[3])
Definition: object_add.c:272
static void object_convert_ui(bContext *C, wmOperator *op)
Definition: object_add.c:3171
void OBJECT_OT_add(wmOperatorType *ot)
Definition: object_add.c:698
static int object_add_exec(bContext *C, wmOperator *op)
Definition: object_add.c:672
float ED_object_new_primitive_matrix(bContext *C, Object *obedit, const float loc[3], const float rot[3], float r_primmat[4][4])
Definition: object_add.c:334
static int lightprobe_add_exec(bContext *C, wmOperator *op)
Definition: object_add.c:741
static uint dupliobject_instancer_hash(const void *ptr)
Definition: object_add.c:2185
static int object_light_add_exec(bContext *C, wmOperator *op)
Definition: object_add.c:1548
void OBJECT_OT_pointcloud_add(wmOperatorType *ot)
Definition: object_add.c:1934
static int object_empty_add_exec(bContext *C, wmOperator *op)
Definition: object_add.c:1164
static int object_speaker_add_exec(bContext *C, wmOperator *op)
Definition: object_add.c:1808
static int object_join_exec(bContext *C, wmOperator *op)
Definition: object_add.c:3552
static bool object_has_geometry_set_instances(const Object *object_eval)
Definition: object_add.c:2248
static Base * object_add_duplicate_internal(Main *bmain, Scene *scene, ViewLayer *view_layer, Object *ob, const eDupli_ID_Flags dupflag, const eLibIDDuplicateFlags duplicate_options)
Definition: object_add.c:3261
static bool object_add_drop_xy_is_set(const wmOperator *op)
Definition: object_add.c:228
const EnumPropertyItem rna_enum_light_type_items[]
Definition: object_add.c:134
static int object_duplicates_make_real_exec(bContext *C, wmOperator *op)
Definition: object_add.c:2462
static EnumPropertyItem lightprobe_type_items[]
Definition: object_add.c:160
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.c:2255
void ED_object_base_free_and_unlink_no_indirect_check(Main *bmain, Scene *scene, Object *ob)
Definition: object_add.c:1979
static bool join_shapes_poll(bContext *C)
Definition: object_add.c:3634
static int object_data_instance_add_exec(bContext *C, wmOperator *op)
Definition: object_add.c:1726
void ED_object_rotation_from_quat(float rot[3], const float viewquat[4], const char align_axis)
Definition: object_add.c:278
static int duplicate_exec(bContext *C, wmOperator *op)
Definition: object_add.c:3347
static const EnumPropertyItem field_type_items[]
Definition: object_add.c:143
static int object_armature_add_exec(bContext *C, wmOperator *op)
Definition: object_add.c:1093
static int object_metaball_add_exec(bContext *C, wmOperator *op)
Definition: object_add.c:973
static int object_camera_add_exec(bContext *C, wmOperator *op)
Definition: object_add.c:912
@ ALIGN_VIEW
Definition: object_add.c:181
@ ALIGN_WORLD
Definition: object_add.c:180
@ ALIGN_CURSOR
Definition: object_add.c:182
static int object_convert_exec(bContext *C, wmOperator *op)
Definition: object_add.c:2663
Base * ED_object_add_duplicate(Main *bmain, Scene *scene, ViewLayer *view_layer, Base *base, const eDupli_ID_Flags dupflag)
Definition: object_add.c:3313
void OBJECT_OT_hair_add(wmOperatorType *ot)
Definition: object_add.c:1889
void OBJECT_OT_join(wmOperatorType *ot)
Definition: object_add.c:3613
static int effector_add_exec(bContext *C, wmOperator *op)
Definition: object_add.c:835
void OBJECT_OT_collection_instance_add(wmOperatorType *ot)
Definition: object_add.c:1689
void OBJECT_OT_armature_add(wmOperatorType *ot)
Definition: object_add.c:1139
static void copy_object_set_idnew(bContext *C)
Definition: object_add.c:2111
void OBJECT_OT_camera_add(wmOperatorType *ot)
Definition: object_add.c:944
static void object_data_convert_curve_to_mesh(Main *bmain, Depsgraph *depsgraph, Object *ob)
Definition: object_add.c:2564
void ED_object_add_mesh_props(wmOperatorType *ot)
Definition: object_add.c:450
static EnumPropertyItem rna_enum_gpencil_add_stroke_depth_order_items[]
Definition: object_add.c:1479
static Base * duplibase_for_convert(Main *bmain, Depsgraph *depsgraph, Scene *scene, ViewLayer *view_layer, Base *base, Object *ob)
Definition: object_add.c:2613
static bool object_pointcloud_add_poll(bContext *C)
Definition: object_add.c:1912
void OBJECT_OT_join_shapes(wmOperatorType *ot)
Definition: object_add.c:3670
static int object_gpencil_add_exec(bContext *C, wmOperator *op)
Definition: object_add.c:1307
static int object_hair_add_exec(bContext *C, wmOperator *op)
Definition: object_add.c:1875
void ED_object_add_generic_props(wmOperatorType *ot, bool do_editmode)
Definition: object_add.c:397
static bool object_join_poll(bContext *C)
Definition: object_add.c:3537
void OBJECT_OT_gpencil_add(wmOperatorType *ot)
Definition: object_add.c:1489
void ED_object_add_unit_props_radius(wmOperatorType *ot)
Definition: object_add.c:392
static const char * get_light_defname(int type)
Definition: object_add.c:1532
void OBJECT_OT_data_instance_add(wmOperatorType *ot)
Definition: object_add.c:1778
return ret
const EnumPropertyItem rna_enum_id_type_items[]
Definition: rna_ID.c:46
void RNA_property_float_get_array(PointerRNA *ptr, PropertyRNA *prop, float *values)
Definition: rna_access.c:3033
void RNA_pointer_create(ID *id, StructRNA *type, void *data, PointerRNA *r_ptr)
Definition: rna_access.c:146
bool RNA_property_is_set(PointerRNA *ptr, PropertyRNA *prop)
Definition: rna_access.c:6655
void RNA_int_set(PointerRNA *ptr, const char *name, int value)
Definition: rna_access.c:6319
void RNA_property_enum_set(PointerRNA *ptr, PropertyRNA *prop, int value)
Definition: rna_access.c:3562
PropertyRNA * RNA_struct_find_property(PointerRNA *ptr, const char *identifier)
Definition: rna_access.c:866
void RNA_float_get_array(PointerRNA *ptr, const char *name, float *values)
Definition: rna_access.c:6378
bool RNA_property_boolean_get(PointerRNA *ptr, PropertyRNA *prop)
Definition: rna_access.c:2331
void RNA_string_get(PointerRNA *ptr, const char *name, char *value)
Definition: rna_access.c:6514
int RNA_int_get(PointerRNA *ptr, const char *name)
Definition: rna_access.c:6308
PropertyRNA * RNA_struct_type_find_property(StructRNA *srna, const char *identifier)
Definition: rna_access.c:953
void RNA_property_string_get(PointerRNA *ptr, PropertyRNA *prop, char *value)
Definition: rna_access.c:3310
void RNA_property_boolean_set(PointerRNA *ptr, PropertyRNA *prop, bool value)
Definition: rna_access.c:2358
float RNA_float_get(PointerRNA *ptr, const char *name)
Definition: rna_access.c:6355
void RNA_property_float_set_array(PointerRNA *ptr, PropertyRNA *prop, const float *values)
Definition: rna_access.c:3132
int RNA_property_enum_get(PointerRNA *ptr, PropertyRNA *prop)
Definition: rna_access.c:3543
bool RNA_struct_property_is_set(PointerRNA *ptr, const char *identifier)
Definition: rna_access.c:6685
bool RNA_struct_idprops_unset(PointerRNA *ptr, const char *identifier)
Definition: rna_access.c:829
bool RNA_boolean_get(PointerRNA *ptr, const char *name)
Definition: rna_access.c:6261
void RNA_enum_set(PointerRNA *ptr, const char *name, int value)
Definition: rna_access.c:6413
void RNA_float_set_array(PointerRNA *ptr, const char *name, const float *values)
Definition: rna_access.c:6390
int RNA_enum_get(PointerRNA *ptr, const char *name)
Definition: rna_access.c:6402
PropertyRNA * RNA_def_boolean(StructOrFunctionRNA *cont_, const char *identifier, bool default_value, const char *ui_name, const char *ui_description)
Definition: rna_define.c:3481
void RNA_def_property_float_default(PropertyRNA *prop, float value)
Definition: rna_define.c:2042
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:4041
PropertyRNA * RNA_def_string(StructOrFunctionRNA *cont_, const char *identifier, const char *default_value, int maxlen, const char *ui_name, const char *ui_description)
Definition: rna_define.c:3675
void RNA_def_property_translation_context(PropertyRNA *prop, const char *context)
Definition: rna_define.c:2870
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:3883
void RNA_def_property_flag(PropertyRNA *prop, PropertyFlag flag)
Definition: rna_define.c:1512
void RNA_def_property_update_runtime(PropertyRNA *prop, const void *func)
Definition: rna_define.c:2938
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:3585
void RNA_def_enum_funcs(PropertyRNA *prop, EnumPropertyItemFunc itemfunc)
Definition: rna_define.c:3819
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:4005
PropertyRNA * RNA_def_enum(StructOrFunctionRNA *cont_, const char *identifier, const EnumPropertyItem *items, int default_value, const char *ui_name, const char *ui_description)
Definition: rna_define.c:3771
const EnumPropertyItem rna_enum_object_empty_drawtype_items[]
Definition: rna_object.c:140
const EnumPropertyItem rna_enum_metaelem_type_items[]
Definition: rna_object.c:223
const EnumPropertyItem rna_enum_object_gpencil_type_items[]
Definition: rna_object.c:159
const EnumPropertyItem rna_enum_object_type_items[]
Definition: rna_object.c:254
const EnumPropertyItem DummyRNA_NULL_items[]
Definition: rna_rna.c:40
short flag
struct Object * object
unsigned short local_view_bits
float drawsize
ListBase disp
Definition: BKE_curve.h:49
struct VFont * vfont
struct VFont * vfontb
EditNurb * editnurb
struct VFont * vfonti
ListBase nurb
struct VFont * vfontbi
short type
int persistent_id[8]
Definition: BKE_duplilist.h:54
struct Object * ob
Definition: BKE_duplilist.h:45
ListBase nurbs
Definition: DNA_ID.h:273
int tag
Definition: DNA_ID.h:292
void * next
Definition: DNA_ID.h:274
char name[66]
Definition: DNA_ID.h:283
struct Collection * collection
float energy
short type
void * first
Definition: DNA_listBase.h:47
Definition: BKE_main.h:116
ListBase scenes
Definition: BKE_main.h:146
ListBase collections
Definition: BKE_main.h:167
ListBase gpencils
Definition: BKE_main.h:176
ListBase objects
Definition: BKE_main.h:148
struct Material ** mat
short totcol
short totcol
struct Material ** mat
char name[64]
struct CurveCache * curve_cache
struct GeometrySet * geometry_set_eval
struct Object * proxy_group
short partype
short transflag
ListBase constraints
struct Collection * instance_collection
short base_flag
struct Object * proxy_from
struct RigidBodyOb * rigidbody_object
ListBase greasepencil_modifiers
struct Material ** mat
struct Object * proxy
float loc[3]
struct PartDeflect * pd
float scale[3]
float rot[3]
float parentinv[4][4]
char empty_drawtype
Object_Runtime runtime
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]
char restrictflag
float viewquat[4]
struct CustomData_MeshMasks customdata_mask
View3DCursor cursor
struct Object * camera
unsigned short local_view_uuid
struct Object * camera
struct View3D * localvd
short scenelock
struct Base * basact
ListBase layers
int ymin
Definition: DNA_vec_types.h:80
int xmin
Definition: DNA_vec_types.h:79
int y
Definition: WM_types.h:581
int mval[2]
Definition: WM_types.h:583
int x
Definition: WM_types.h:581
int(* invoke)(struct bContext *, struct wmOperator *, const struct wmEvent *) ATTR_WARN_UNUSED_RESULT
Definition: WM_types.h:752
const char * name
Definition: WM_types.h:721
const char * idname
Definition: WM_types.h:723
bool(* poll)(struct bContext *) ATTR_WARN_UNUSED_RESULT
Definition: WM_types.h:776
struct StructRNA * srna
Definition: WM_types.h:802
const char * description
Definition: WM_types.h:726
void(* ui)(struct bContext *, struct wmOperator *)
Definition: WM_types.h:787
int(* exec)(struct bContext *, struct wmOperator *) ATTR_WARN_UNUSED_RESULT
Definition: WM_types.h:736
PropertyRNA * prop
Definition: WM_types.h:814
struct ReportList * reports
IDProperty * properties
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:3157
wmOperatorType * ot
Definition: wm_files.c:3156
void WM_operator_properties_confirm_or_exec(wmOperatorType *ot)
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))
Definition: wm_operators.c:982
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:915
Scene * WM_window_get_active_scene(const wmWindow *win)
Definition: wm_window.c:2249