Blender V5.3
object_add.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2001-2002 NaN Holding BV. All rights reserved.
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include <cctype>
10#include <cstdlib>
11#include <cstring>
12#include <optional>
13
14#include "DNA_anim_types.h"
15#include "DNA_camera_types.h"
17#include "DNA_curve_types.h"
19#include "DNA_key_types.h"
20#include "DNA_lattice_types.h"
21#include "DNA_light_types.h"
23#include "DNA_material_types.h"
24#include "DNA_mesh_types.h"
25#include "DNA_meta_types.h"
26#include "DNA_modifier_types.h"
28#include "DNA_object_types.h"
30#include "DNA_scene_types.h"
31#include "DNA_speaker_types.h"
32#include "DNA_vfont_types.h"
33
34#include "BLI_array_utils.hh"
35#include "BLI_bounds.hh"
36#include "BLI_ghash.hh"
37#include "BLI_listbase.hh"
38#include "BLI_math_color_c.hh"
39#include "BLI_math_matrix_c.hh"
43#include "BLI_rand.hh"
44#include "BLI_string.hh"
45#include "BLI_string_utf8.hh"
46#include "BLI_utildefines.hh"
47#include "BLI_vector.hh"
48
49#include "BLT_translation.hh"
50
51#include "BKE_action.hh"
52#include "BKE_anim_data.hh"
54#include "BKE_armature.hh"
55#include "BKE_attribute.h"
56#include "BKE_camera.h"
57#include "BKE_collection.hh"
58#include "BKE_constraint.h"
59#include "BKE_context.hh"
60#include "BKE_curve.hh"
62#include "BKE_curve_to_mesh.hh"
63#include "BKE_curves.h"
64#include "BKE_curves.hh"
65#include "BKE_customdata.hh"
66#include "BKE_deform.hh"
67#include "BKE_displist.h"
68#include "BKE_duplilist.hh"
69#include "BKE_effect.h"
70#include "BKE_geometry_set.hh"
72#include "BKE_global.hh"
73#include "BKE_grease_pencil.hh"
74#include "BKE_key.hh"
75#include "BKE_lattice.hh"
76#include "BKE_layer.hh"
77#include "BKE_lib_id.hh"
78#include "BKE_lib_override.hh"
79#include "BKE_lib_query.hh"
80#include "BKE_lib_remap.hh"
81#include "BKE_library.hh"
82#include "BKE_light.h"
83#include "BKE_lightprobe.h"
84#include "BKE_main.hh"
85#include "BKE_material.hh"
86#include "BKE_mball.hh"
87#include "BKE_mesh.hh"
88#include "BKE_mesh_runtime.hh"
89#include "BKE_mesh_wrapper.hh"
90#include "BKE_modifier.hh"
91#include "BKE_nla.hh"
92#include "BKE_node.hh"
93#include "BKE_object.hh"
94#include "BKE_object_types.hh"
95#include "BKE_paint.hh"
96#include "BKE_particle.h"
97#include "BKE_pointcloud.hh"
98#include "BKE_report.hh"
99#include "BKE_scene.hh"
100#include "BKE_vfont.hh"
101#include "BKE_volume.hh"
102
103#include "DEG_depsgraph.hh"
104#include "DEG_depsgraph_build.hh"
105#include "DEG_depsgraph_query.hh"
106
107#include "GEO_join_geometries.hh"
108#include "GEO_mesh_to_curve.hh"
109
110#include "RNA_access.hh"
111#include "RNA_define.hh"
112#include "RNA_enum_types.hh"
113
114#include "UI_interface_icons.hh"
115#include "UI_interface_layout.hh"
116
117#include "WM_api.hh"
118#include "WM_types.hh"
119
120#include "ED_armature.hh"
121#include "ED_asset.hh"
122#include "ED_asset_menu_utils.hh"
123#include "ED_curve.hh"
124#include "ED_curves.hh"
125#include "ED_gpencil_legacy.hh"
126#include "ED_grease_pencil.hh"
127#include "ED_mball.hh"
128#include "ED_mesh.hh"
129#include "ED_node.hh"
130#include "ED_object.hh"
131#include "ED_outliner.hh"
132#include "ED_physics.hh"
133#include "ED_pointcloud.hh"
134#include "ED_render.hh"
135#include "ED_screen.hh"
136#include "ED_select_utils.hh"
137#include "ED_transform.hh"
138#include "ED_view3d.hh"
139
140#include "MOD_nodes.hh"
141
142#include "AS_asset_library.hh"
143
145
146#include "UI_resources.hh"
147
148#include "object_intern.hh"
149
150namespace blender {
151
153 {LA_LOCAL, "POINT", ICON_LIGHT_POINT, "Point", "Omnidirectional point light source"},
154 {LA_SUN, "SUN", ICON_LIGHT_SUN, "Sun", "Constant direction parallel ray light source"},
155 {LA_SPOT, "SPOT", ICON_LIGHT_SPOT, "Spot", "Directional cone light source"},
156 {LA_AREA, "AREA", ICON_LIGHT_AREA, "Area", "Directional area light source"},
157 {0, nullptr, 0, nullptr, nullptr},
158};
159
160namespace ed::object {
161
162/* -------------------------------------------------------------------- */
165
166/* This is an exact copy of the define in `rna_light.cc`
167 * kept here because of linking order.
168 * Icons are only defined here. */
169
170/* copy from rna_object_force.cc */
172 {PFIELD_FORCE, "FORCE", ICON_FORCE_FORCE, "Force", ""},
173 {PFIELD_WIND, "WIND", ICON_FORCE_WIND, "Wind", ""},
174 {PFIELD_VORTEX, "VORTEX", ICON_FORCE_VORTEX, "Vortex", ""},
175 {PFIELD_MAGNET, "MAGNET", ICON_FORCE_MAGNETIC, "Magnetic", ""},
176 {PFIELD_HARMONIC, "HARMONIC", ICON_FORCE_HARMONIC, "Harmonic", ""},
177 {PFIELD_CHARGE, "CHARGE", ICON_FORCE_CHARGE, "Charge", ""},
178 {PFIELD_LENNARDJ, "LENNARDJ", ICON_FORCE_LENNARDJONES, "Lennard-Jones", ""},
179 {PFIELD_TEXTURE, "TEXTURE", ICON_FORCE_TEXTURE, "Texture", ""},
180 {PFIELD_GUIDE, "GUIDE", ICON_FORCE_CURVE, "Curve Guide", ""},
181 {PFIELD_BOID, "BOID", ICON_FORCE_BOID, "Boid", ""},
182 {PFIELD_TURBULENCE, "TURBULENCE", ICON_FORCE_TURBULENCE, "Turbulence", ""},
183 {PFIELD_DRAG, "DRAG", ICON_FORCE_DRAG, "Drag", ""},
184 {PFIELD_FLUIDFLOW, "FLUID", ICON_FORCE_FLUIDFLOW, "Fluid Flow", ""},
185 {0, nullptr, 0, nullptr, nullptr},
186};
187
190 "SPHERE",
191 ICON_LIGHTPROBE_SPHERE,
192 "Sphere",
193 "Light probe that captures precise lighting from all directions at a single point in space"},
195 "PLANE",
196 ICON_LIGHTPROBE_PLANE,
197 "Plane",
198 "Light probe that captures incoming light from a single direction on a plane"},
200 "VOLUME",
201 ICON_LIGHTPROBE_VOLUME,
202 "Volume",
203 "Light probe that captures low frequency lighting inside a volume"},
204 {0, nullptr, 0, nullptr, nullptr},
205};
206
207enum {
211};
212
214 {ALIGN_WORLD, "WORLD", 0, "World", "Align the new object to the world"},
215 {ALIGN_VIEW, "VIEW", 0, "View", "Align the new object to the view"},
216 {ALIGN_CURSOR, "CURSOR", 0, "3D Cursor", "Use the 3D cursor orientation for the new object"},
217 {0, nullptr, 0, nullptr, nullptr},
218};
219
221
222/* -------------------------------------------------------------------- */
225
231{
232 PropertyRNA *prop;
233
234 prop = RNA_def_int(ot->srna,
235 "drop_x",
236 0,
237 INT_MIN,
238 INT_MAX,
239 "Drop X",
240 "X-coordinate (screen space) to place the new object under",
241 INT_MIN,
242 INT_MAX);
244 prop = RNA_def_int(ot->srna,
245 "drop_y",
246 0,
247 INT_MIN,
248 INT_MAX,
249 "Drop Y",
250 "Y-coordinate (screen space) to place the new object under",
251 INT_MIN,
252 INT_MAX);
254}
255
257{
258 return RNA_struct_property_is_set(op->ptr, "drop_x") &&
259 RNA_struct_property_is_set(op->ptr, "drop_y");
260}
261
266static bool object_add_drop_xy_get(bContext *C, wmOperator *op, int (*r_mval)[2])
267{
268 if (!object_add_drop_xy_is_set(op)) {
269 (*r_mval)[0] = 0.0f;
270 (*r_mval)[1] = 0.0f;
271 return false;
272 }
273
274 const ARegion *region = CTX_wm_region(C);
275 (*r_mval)[0] = RNA_int_get(op->ptr, "drop_x") - region->winrct.xmin;
276 (*r_mval)[1] = RNA_int_get(op->ptr, "drop_y") - region->winrct.ymin;
277
278 return true;
279}
280
286 wmOperator *op,
287 const wmEvent *event)
288{
289 if (!object_add_drop_xy_is_set(op)) {
290 RNA_int_set(op->ptr, "drop_x", event->xy[0]);
291 RNA_int_set(op->ptr, "drop_y", event->xy[1]);
292 }
293 return op->type->exec(C, op);
294}
295
297
298/* -------------------------------------------------------------------- */
301
302void location_from_view(bContext *C, float loc[3])
303{
304 const Scene *scene = CTX_data_scene(C);
305 copy_v3_v3(loc, scene->cursor.location);
306}
307
308void rotation_from_quat(float rot[3], const float viewquat[4], const char align_axis)
309{
310 BLI_assert(align_axis >= 'X' && align_axis <= 'Z');
311
312 switch (align_axis) {
313 case 'X': {
314 /* Same as 'rv3d->viewinv[1]' */
315 const float axis_y[4] = {0.0f, 1.0f, 0.0f};
316 float quat_y[4], quat[4];
317 axis_angle_to_quat(quat_y, axis_y, M_PI_2);
318 mul_qt_qtqt(quat, viewquat, quat_y);
319 quat_to_eul(rot, quat);
320 break;
321 }
322 case 'Y': {
323 quat_to_eul(rot, viewquat);
324 rot[0] -= float(M_PI_2);
325 break;
326 }
327 case 'Z': {
328 quat_to_eul(rot, viewquat);
329 break;
330 }
331 }
332}
333
334void rotation_from_view(bContext *C, float rot[3], const char align_axis)
335{
337 BLI_assert(align_axis >= 'X' && align_axis <= 'Z');
338 if (rv3d) {
339 float viewquat[4];
340 copy_qt_qt(viewquat, rv3d->viewquat);
341 viewquat[0] *= -1.0f;
342 rotation_from_quat(rot, viewquat, align_axis);
343 }
344 else {
345 zero_v3(rot);
346 }
347}
348
349void init_transform_on_add(Object *object, const float loc[3], const float rot[3])
350{
351 if (loc) {
352 copy_v3_v3(object->loc, loc);
353 }
354
355 if (rot) {
356 copy_v3_v3(object->rot, rot);
357 }
358
359 BKE_object_to_mat4(object, object->runtime->object_to_world.ptr());
360}
361
363 Object *obedit,
364 const float loc[3],
365 const float rot[3],
366 const float scale[3],
367 float r_primmat[4][4])
368{
369 Scene *scene = CTX_data_scene(C);
370 View3D *v3d = CTX_wm_view3d(C);
371 float mat[3][3], rmat[3][3], cmat[3][3], imat[3][3];
372
373 unit_m4(r_primmat);
374
375 eul_to_mat3(rmat, rot);
376 invert_m3(rmat);
377
378 /* inverse transform for initial rotation and object */
379 copy_m3_m4(mat, obedit->object_to_world().ptr());
380 mul_m3_m3m3(cmat, rmat, mat);
381 invert_m3_m3(imat, cmat);
382 copy_m4_m3(r_primmat, imat);
383
384 /* center */
385 copy_v3_v3(r_primmat[3], loc);
386 sub_v3_v3v3(r_primmat[3], r_primmat[3], obedit->object_to_world().location());
387 invert_m3_m3(imat, mat);
388 mul_m3_v3(imat, r_primmat[3]);
389
390 if (scale != nullptr) {
391 rescale_m4(r_primmat, scale);
392 }
393
394 {
395 const float dia = v3d ? ED_view3d_grid_scale(scene, v3d, nullptr) :
396 ED_scene_grid_scale(scene, nullptr);
397 return dia;
398 }
399
400 // return 1.0f;
401}
402
404
405/* -------------------------------------------------------------------- */
408
409static void view_align_update(Main * /*main*/, Scene * /*scene*/, PointerRNA *ptr)
410{
411 RNA_struct_system_idprops_unset(ptr, "rotation");
412}
413
414void add_unit_props_size(wmOperatorType *ot, float default_value)
415{
417 ot->srna, "size", default_value, 0.0, OBJECT_ADD_SIZE_MAXF, "Size", "", 0.001, 100.00);
418}
419
420void add_unit_props_radius_ex(wmOperatorType *ot, float default_value)
421{
423 ot->srna, "radius", default_value, 0.0, OBJECT_ADD_SIZE_MAXF, "Radius", "", 0.001, 100.00);
424}
425
430
431void add_generic_props(wmOperatorType *ot, bool do_editmode)
432{
433 PropertyRNA *prop;
434
435 if (do_editmode) {
436 prop = RNA_def_boolean(ot->srna,
437 "enter_editmode",
438 false,
439 "Enter Edit Mode",
440 "Enter edit mode when adding this object");
442 }
443 /* NOTE: this property gets hidden for add-camera operator. */
444 prop = RNA_def_enum(
445 ot->srna, "align", align_options, ALIGN_WORLD, "Align", "The alignment of the new object");
447
449 "location",
450 3,
451 nullptr,
454 "Location",
455 "Location for the newly added object",
456 -1000.0f,
457 1000.0f);
459 prop = RNA_def_float_rotation(ot->srna,
460 "rotation",
461 3,
462 nullptr,
465 "Rotation",
466 "Rotation for the newly added object",
467 DEG2RADF(-360.0f),
468 DEG2RADF(360.0f));
470
472 "scale",
473 3,
474 nullptr,
477 "Scale",
478 "Scale for the newly added object",
479 -1000.0f,
480 1000.0f);
482}
483
485{
486 RNA_def_boolean(ot->srna, "calc_uvs", true, "Generate UVs", "Generate a default UV map");
487}
488
490 wmOperator *op,
491 const char view_align_axis,
492 float r_loc[3],
493 float r_rot[3],
494 float r_scale[3],
495 bool *r_enter_editmode,
496 ushort *r_local_view_bits,
497 bool *r_is_view_aligned)
498{
499 /* Edit Mode! (optional) */
500 {
501 bool _enter_editmode;
502 if (!r_enter_editmode) {
503 r_enter_editmode = &_enter_editmode;
504 }
505 /* Only to ensure the value is _always_ set.
506 * Typically the property will exist when the argument is non-null. */
507 *r_enter_editmode = false;
508
509 PropertyRNA *prop = RNA_struct_find_property(op->ptr, "enter_editmode");
510 if (prop != nullptr) {
511 if (RNA_property_is_set(op->ptr, prop) && r_enter_editmode) {
512 *r_enter_editmode = RNA_property_boolean_get(op->ptr, prop);
513 }
514 else {
515 *r_enter_editmode = (U.flag & USER_ADD_EDITMODE) != 0;
516 RNA_property_boolean_set(op->ptr, prop, *r_enter_editmode);
517 }
518 }
519 }
520
521 if (r_local_view_bits) {
522 View3D *v3d = CTX_wm_view3d(C);
523 *r_local_view_bits = (v3d && v3d->localvd) ? v3d->local_view_uid : 0;
524 }
525
526 /* Location! */
527 {
528 float _loc[3];
529 if (!r_loc) {
530 r_loc = _loc;
531 }
532
533 if (RNA_struct_property_is_set(op->ptr, "location")) {
534 RNA_float_get_array(op->ptr, "location", r_loc);
535 }
536 else {
537 location_from_view(C, r_loc);
538 RNA_float_set_array(op->ptr, "location", r_loc);
539 }
540 }
541
542 /* Rotation! */
543 {
544 bool _is_view_aligned;
545 float _rot[3];
546 if (!r_is_view_aligned) {
547 r_is_view_aligned = &_is_view_aligned;
548 }
549 if (!r_rot) {
550 r_rot = _rot;
551 }
552
553 if (RNA_struct_property_is_set(op->ptr, "rotation")) {
554 /* If rotation is set, always use it. Alignment (and corresponding user preference)
555 * can be ignored since this is in world space anyway.
556 * To not confuse (e.g. on redo), don't set it to #ALIGN_WORLD in the op UI though. */
557 *r_is_view_aligned = false;
558 RNA_float_get_array(op->ptr, "rotation", r_rot);
559 }
560 else {
561 int alignment = ALIGN_WORLD;
562 PropertyRNA *prop = RNA_struct_find_property(op->ptr, "align");
563
564 if (RNA_property_is_set(op->ptr, prop)) {
565 /* If alignment is set, always use it. */
566 *r_is_view_aligned = alignment == ALIGN_VIEW;
567 alignment = RNA_property_enum_get(op->ptr, prop);
568 }
569 else {
570 /* If alignment is not set, use User Preferences. */
571 *r_is_view_aligned = (U.flag & USER_ADD_VIEWALIGNED) != 0;
572 if (*r_is_view_aligned) {
574 alignment = ALIGN_VIEW;
575 }
576 else if ((U.flag & USER_ADD_CURSORALIGNED) != 0) {
578 alignment = ALIGN_CURSOR;
579 }
580 else {
582 alignment = ALIGN_WORLD;
583 }
584 }
585 switch (alignment) {
586 case ALIGN_WORLD:
587 RNA_float_get_array(op->ptr, "rotation", r_rot);
588 break;
589 case ALIGN_VIEW:
590 rotation_from_view(C, r_rot, view_align_axis);
591 RNA_float_set_array(op->ptr, "rotation", r_rot);
592 break;
593 case ALIGN_CURSOR: {
594 const Scene *scene = CTX_data_scene(C);
595 const float3x3 tmat = scene->cursor.matrix<float3x3>();
596 mat3_normalized_to_eul(r_rot, tmat.ptr());
597 RNA_float_set_array(op->ptr, "rotation", r_rot);
598 break;
599 }
600 }
601 }
602 }
603
604 /* Scale! */
605 {
606 float _scale[3];
607 if (!r_scale) {
608 r_scale = _scale;
609 }
610
611 /* For now this is optional, we can make it always use. */
612 copy_v3_fl(r_scale, 1.0f);
613
614 PropertyRNA *prop = RNA_struct_find_property(op->ptr, "scale");
615 if (prop != nullptr) {
616 if (RNA_property_is_set(op->ptr, prop)) {
617 RNA_property_float_get_array(op->ptr, prop, r_scale);
618 }
619 else {
620 copy_v3_fl(r_scale, 1.0f);
621 RNA_property_float_set_array(op->ptr, prop, r_scale);
622 }
623 }
624 }
625}
626
628 const int type,
629 const char *name,
630 const float loc[3],
631 const float rot[3],
632 const bool enter_editmode,
633 const ushort local_view_bits,
634 ID *obdata)
635{
636 Main *bmain = CTX_data_main(C);
637 Scene *scene = CTX_data_scene(C);
638 ViewLayer *view_layer = CTX_data_view_layer(C);
639
640 /* Ensure we leave edit-mode for all objects (NOOP outside of edit-mode). */
641 editmode_exit_multi_ex(bmain, scene, view_layer, EM_FREEDATA);
642
643 /* deselects all, sets active object */
644 Object *ob;
645 if (obdata != nullptr) {
646 BLI_assert(type == BKE_object_obdata_to_type(obdata));
647 ob = BKE_object_add_for_data(bmain, scene, view_layer, ObjectType(type), name, obdata, true);
648 const short *materials_len_p = BKE_id_material_len_p(obdata);
649 if (materials_len_p && *materials_len_p > 0) {
651 }
652 }
653 else {
654 ob = BKE_object_add(bmain, scene, view_layer, ObjectType(type), name);
655 }
656
657 BKE_view_layer_synced_ensure(*bmain, scene, view_layer);
658 Base *ob_base_act = BKE_view_layer_active_base_get(view_layer);
659 /* While not getting a valid base is not a good thing, it can happen in convoluted corner cases,
660 * better not crash on it in releases. */
661 BLI_assert(ob_base_act != nullptr);
662 if (ob_base_act != nullptr) {
663 ob_base_act->local_view_bits = local_view_bits;
664 /* editor level activate, notifiers */
665 base_activate(C, ob_base_act);
666 }
667
668 /* more editor stuff */
669 init_transform_on_add(ob, loc, rot);
670
671 /* TODO(sergey): This is weird to manually tag objects for update, better to
672 * use DEG_id_tag_update here perhaps.
673 */
674 DEG_id_type_tag(bmain, ID_OB);
676 if (ob->data != nullptr) {
678 }
679
680 if (enter_editmode) {
681 editmode_enter_ex(bmain, scene, ob, 0);
682 }
683
685
687
689
690 return ob;
691}
692
694 const int type,
695 const char *name,
696 const float loc[3],
697 const float rot[3],
698 const bool enter_editmode,
699 const ushort local_view_bits)
700{
701 return add_type_with_obdata(C, type, name, loc, rot, enter_editmode, local_view_bits, nullptr);
702}
703
705{
706 return ELEM(ob->type,
707 OB_MESH,
709 OB_SURF,
710 OB_FONT,
711 OB_CURVES,
713 OB_LATTICE);
714}
715
716/* for object add operator */
718{
719 ushort local_view_bits;
720 bool enter_editmode;
721 float loc[3], rot[3], radius;
723 add_generic_get_opts(C, op, 'Z', loc, rot, nullptr, &enter_editmode, &local_view_bits, nullptr);
724
725 radius = RNA_float_get(op->ptr, "radius");
726 Object *ob = add_type(
727 C, RNA_enum_get(op->ptr, "type"), nullptr, loc, rot, enter_editmode, local_view_bits);
728
729 if (ob->type == OB_LATTICE) {
730 /* lattice is a special case!
731 * we never want to scale the obdata since that is the rest-state */
732 copy_v3_fl(ob->scale, radius);
733 }
734 else {
735 BKE_object_obdata_size_init(ob, radius);
736 }
737
738 return OPERATOR_FINISHED;
739}
740
742{
743 /* identifiers */
744 ot->name = "Add Object";
745 ot->description = "Add an object to the scene";
746 ot->idname = "OBJECT_OT_add";
747
748 /* API callbacks. */
749 ot->exec = object_add_exec;
751
752 /* flags */
754
755 /* properties */
757 PropertyRNA *prop = RNA_def_enum(ot->srna, "type", rna_enum_object_type_items, 0, "Type", "");
759
760 add_generic_props(ot, true);
761}
762
764
765/* -------------------------------------------------------------------- */
768
770 bContext *C, const float orientation_matrix[3][3], Vector<Object *> &r_targets)
771{
772 ViewLayer *view_layer = CTX_data_view_layer(C);
773 View3D *v3d = CTX_wm_view3d(C);
774 Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
775
776 Bounds<float3> local_bounds;
777 local_bounds.min = float3(FLT_MAX);
778 local_bounds.max = float3(-FLT_MAX);
779 bool has_bounds = false;
780
781 float inverse_orientation_matrix[3][3];
782 invert_m3_m3_safe_ortho(inverse_orientation_matrix, orientation_matrix);
783
784 for (Base &base : view_layer->object_bases) {
786 continue;
787 }
788
789 r_targets.append(base.object);
790 const Object *object_eval = DEG_get_evaluated(depsgraph, base.object);
791 if (object_eval && DEG_object_transform_is_evaluated(*object_eval)) {
792 if (std::optional<Bounds<float3>> object_bounds = BKE_object_evaluated_geometry_bounds(
793 object_eval))
794 {
795 const float (*object_to_world_matrix)[4] = object_eval->object_to_world().ptr();
796 /* Generate all 8 corners of the bounding box. */
797 std::array<float3, 8> corners = bounds::corners(*object_bounds);
798 for (float3 &corner : corners) {
799 mul_m4_v3(object_to_world_matrix, corner);
800 mul_m3_v3(inverse_orientation_matrix, corner);
801 local_bounds.min = math::min(local_bounds.min, corner);
802 local_bounds.max = math::max(local_bounds.max, corner);
803 }
804 has_bounds = true;
805 }
806 }
807 }
808
809 if (has_bounds) {
810 return local_bounds;
811 }
812 return std::nullopt;
813}
814
816{
817 Main *bmain = CTX_data_main(C);
818 Scene *scene = CTX_data_scene(C);
819 Object *ob_active = CTX_data_active_object(C);
820 ushort local_view_bits;
821 bool enter_editmode;
822 float location[3], rotation_euler[3];
825 C, op, 'Z', location, rotation_euler, nullptr, &enter_editmode, &local_view_bits, nullptr);
826
827 const float margin = RNA_float_get(op->ptr, "margin");
828 const bool add_modifiers = RNA_boolean_get(op->ptr, "add_modifiers");
829 const int resolution_u = RNA_int_get(op->ptr, "resolution_u");
830 const int resolution_v = RNA_int_get(op->ptr, "resolution_v");
831 const int resolution_w = RNA_int_get(op->ptr, "resolution_w");
833 float orientation_matrix[3][3];
834
835 if (ob_active) {
836 copy_m3_m4(orientation_matrix, ob_active->object_to_world().ptr());
837 normalize_m3(orientation_matrix);
838 }
839 else {
840 unit_m3(orientation_matrix);
841 }
842
843 Vector<Object *> targets;
844 std::optional<Bounds<float3>> bounds_opt =
846
847 /* Disable fit to selected when there are no valid targets
848 * (either nothing is selected or meshes with no geometry). */
849 if (targets.is_empty() || !bounds_opt.has_value()) {
850 RNA_boolean_set(op->ptr, "fit_to_selected", false);
851 }
852 const bool fit_to_selected = RNA_boolean_get(op->ptr, "fit_to_selected");
853
854 Object *ob_lattice = add_type(
855 C, OB_LATTICE, nullptr, location, rotation_euler, enter_editmode, local_view_bits);
856 Lattice *lt = id_cast<Lattice *>(ob_lattice->data);
857
858 if (fit_to_selected && bounds_opt.has_value()) {
859 /* Calculate the center and size of this combined bounding box. */
860 const float3 center_local = bounds_opt->center();
861 const float3 size_local = bounds_opt->size() + float3(margin * 2);
862
863 /* Orient lattice center and apply rotation. */
864 float3 center_world = center_local;
865 mul_m3_v3(orientation_matrix, center_world);
866 BKE_object_mat3_to_rot(ob_lattice, orientation_matrix, false);
867
868 copy_v3_v3(ob_lattice->loc, center_world);
869 copy_v3_v3(ob_lattice->scale, size_local);
870
871 /* Prevent invalid or zero lattice size, fallback to 1.0f. */
872 for (int i = 0; i < 3; i++) {
873 if (!isfinite(ob_lattice->scale[i]) || ob_lattice->scale[i] <= FLT_EPSILON) {
874 ob_lattice->scale[i] = 1.0f;
875 }
876 }
877 }
878 else {
879 /* Fallback when fit to selected is off. */
880 copy_v3_fl(ob_lattice->scale, RNA_float_get(op->ptr, "radius"));
881
882 /* Apply user specified Euler rotation instead of cached quat. */
883 ob_lattice->rotmode = ROT_MODE_EUL;
884 copy_v3_v3(ob_lattice->rot, rotation_euler);
885 }
886
887 if (add_modifiers) {
888 for (Object *ob : targets) {
889 BLI_assert(ob != ob_lattice);
891
892 if (ob->type == OB_GREASE_PENCIL) {
895 op->reports, bmain, scene, ob, nullptr, eModifierType_GreasePencilLattice));
896 if (lmd == nullptr) [[unlikely]] {
897 continue;
898 }
899
900 lmd->object = ob_lattice;
901 }
902 else {
903 LatticeModifierData *lmd = reinterpret_cast<LatticeModifierData *>(
904 modifier_add(op->reports, bmain, scene, ob, nullptr, eModifierType_Lattice));
905 if (lmd == nullptr) [[unlikely]] {
906 continue;
907 }
908
909 lmd->object = ob_lattice;
910 }
913 }
914 }
915
917 lt, max_ii(1, resolution_u), max_ii(1, resolution_v), max_ii(1, resolution_w), ob_lattice);
918
920 return OPERATOR_FINISHED;
921}
922
924 wmOperator *op,
925 const PropertyRNA *prop)
926{
927 const char *prop_id = RNA_property_identifier(prop);
928
929 /* Shows only relevant redo properties.
930 * If `fit_to_selected` is:
931 * - true: location & rotation are ignored.
932 * - false: margin is ignored since it only applies to the "fit".
933 */
934 if (RNA_boolean_get(op->ptr, "fit_to_selected")) {
935 if (STR_ELEM(prop_id, "radius", "align", "location", "rotation")) {
936 return false;
937 }
938 }
939 else {
940 if (STREQ(prop_id, "margin")) {
941 return false;
942 }
943 }
944 return true;
945}
946
948{
949 /* identifiers */
950 ot->name = "Add Lattice Deformer";
951 ot->description = "Add a lattice and use it to deform selected objects";
952 ot->idname = "OBJECT_OT_lattice_add_to_selected";
953
954 /* API callbacks. */
958
960
961 /* properties */
962 PropertyRNA *prop;
963
964 prop = RNA_def_boolean(ot->srna,
965 "fit_to_selected",
966 true,
967 "Fit to Selected",
968 "Resize lattice to fit selected deformable objects");
970
972 prop = RNA_def_float(ot->srna,
973 "margin",
974 0.0f,
975 0.0f,
976 FLT_MAX,
977 "Margin",
978 "Add margin to lattice dimensions",
979 0.0f,
980 10.0f);
982
983 prop = RNA_def_boolean(ot->srna,
984 "add_modifiers",
985 true,
986 "Add Modifiers",
987 "Automatically add lattice modifiers to selected objects");
989
990 prop = RNA_def_int(ot->srna,
991 "resolution_u",
992 2,
993 1,
994 64,
995 "Resolution U",
996 "Lattice resolution in U direction",
997 1,
998 64);
1000
1001 prop = RNA_def_int(
1002 ot->srna, "resolution_v", 2, 1, 64, "V", "Lattice resolution in V direction", 1, 64);
1004
1005 prop = RNA_def_int(
1006 ot->srna, "resolution_w", 2, 1, 64, "W", "Lattice resolution in W direction", 1, 64);
1007 add_generic_props(ot, true);
1008}
1009
1011
1012/* -------------------------------------------------------------------- */
1015
1016/* for object add operator */
1017static const char *get_lightprobe_defname(int type)
1018{
1019 switch (type) {
1021 return CTX_DATA_(BLT_I18NCONTEXT_ID_LIGHT, "Volume");
1023 return CTX_DATA_(BLT_I18NCONTEXT_ID_LIGHT, "Plane");
1025 return CTX_DATA_(BLT_I18NCONTEXT_ID_LIGHT, "Sphere");
1026 default:
1027 return CTX_DATA_(BLT_I18NCONTEXT_ID_LIGHT, "LightProbe");
1028 }
1029}
1030
1032{
1033 bool enter_editmode;
1034 ushort local_view_bits;
1035 float loc[3], rot[3];
1037 add_generic_get_opts(C, op, 'Z', loc, rot, nullptr, &enter_editmode, &local_view_bits, nullptr);
1038
1039 eLightProbeType type = eLightProbeType(RNA_enum_get(op->ptr, "type"));
1040 float radius = RNA_float_get(op->ptr, "radius");
1041
1042 Object *ob = add_type(
1043 C, OB_LIGHTPROBE, get_lightprobe_defname(type), loc, rot, false, local_view_bits);
1044 copy_v3_fl(ob->scale, radius);
1045
1046 LightProbe *probe = id_cast<LightProbe *>(ob->data);
1047
1048 BKE_lightprobe_type_set(probe, type);
1049
1050 return OPERATOR_FINISHED;
1051}
1052
1054{
1055 /* identifiers */
1056 ot->name = "Add Light Probe";
1057 ot->description = "Add a light probe object";
1058 ot->idname = "OBJECT_OT_lightprobe_add";
1059
1060 /* API callbacks. */
1063
1064 /* flags */
1066
1067 /* properties */
1068 ot->prop = RNA_def_enum(ot->srna, "type", lightprobe_type_items, 0, "Type", "");
1069
1071 add_generic_props(ot, true);
1072}
1073
1075
1076/* -------------------------------------------------------------------- */
1079
1080/* for object add operator */
1081
1082static const char *get_effector_defname(ePFieldType type)
1083{
1084 switch (type) {
1085 case PFIELD_FORCE:
1086 return CTX_DATA_(BLT_I18NCONTEXT_ID_OBJECT, "Force");
1087 case PFIELD_VORTEX:
1088 return CTX_DATA_(BLT_I18NCONTEXT_ID_OBJECT, "Vortex");
1089 case PFIELD_MAGNET:
1090 return CTX_DATA_(BLT_I18NCONTEXT_ID_OBJECT, "Magnet");
1091 case PFIELD_WIND:
1092 return CTX_DATA_(BLT_I18NCONTEXT_ID_OBJECT, "Wind");
1093 case PFIELD_GUIDE:
1094 return CTX_DATA_(BLT_I18NCONTEXT_ID_OBJECT, "CurveGuide");
1095 case PFIELD_TEXTURE:
1096 return CTX_DATA_(BLT_I18NCONTEXT_ID_OBJECT, "TextureField");
1097 case PFIELD_HARMONIC:
1098 return CTX_DATA_(BLT_I18NCONTEXT_ID_OBJECT, "Harmonic");
1099 case PFIELD_CHARGE:
1100 return CTX_DATA_(BLT_I18NCONTEXT_ID_OBJECT, "Charge");
1101 case PFIELD_LENNARDJ:
1102 return CTX_DATA_(BLT_I18NCONTEXT_ID_OBJECT, "Lennard-Jones");
1103 case PFIELD_BOID:
1104 return CTX_DATA_(BLT_I18NCONTEXT_ID_OBJECT, "Boid");
1105 case PFIELD_TURBULENCE:
1106 return CTX_DATA_(BLT_I18NCONTEXT_ID_OBJECT, "Turbulence");
1107 case PFIELD_DRAG:
1108 return CTX_DATA_(BLT_I18NCONTEXT_ID_OBJECT, "Drag");
1109 case PFIELD_FLUIDFLOW:
1110 return CTX_DATA_(BLT_I18NCONTEXT_ID_OBJECT, "FluidField");
1111 case PFIELD_NULL:
1112 return CTX_DATA_(BLT_I18NCONTEXT_ID_OBJECT, "Field");
1113 case NUM_PFIELD_TYPES:
1114 break;
1115 }
1116
1117 BLI_assert(false);
1118 return CTX_DATA_(BLT_I18NCONTEXT_ID_OBJECT, "Field");
1119}
1120
1122{
1123 bool enter_editmode;
1124 ushort local_view_bits;
1125 float loc[3], rot[3];
1127 add_generic_get_opts(C, op, 'Z', loc, rot, nullptr, &enter_editmode, &local_view_bits, nullptr);
1128
1129 const ePFieldType type = static_cast<ePFieldType>(RNA_enum_get(op->ptr, "type"));
1130 float dia = RNA_float_get(op->ptr, "radius");
1131
1132 Object *ob;
1133 if (type == PFIELD_GUIDE) {
1134 Main *bmain = CTX_data_main(C);
1135 Scene *scene = CTX_data_scene(C);
1136 ob = add_type(
1137 C, OB_CURVES_LEGACY, get_effector_defname(type), loc, rot, false, local_view_bits);
1138
1139 Curve *cu = id_cast<Curve *>(ob->data);
1140 cu->flag |= CU_PATH | CU_3D;
1141 editmode_enter_ex(bmain, scene, ob, 0);
1142
1143 float mat[4][4];
1144 new_primitive_matrix(C, ob, loc, rot, nullptr, mat);
1145 mul_mat3_m4_fl(mat, dia);
1148 if (!enter_editmode) {
1149 editmode_exit_ex(bmain, scene, ob, EM_FREEDATA);
1150 }
1151 }
1152 else {
1153 ob = add_type(C, OB_EMPTY, get_effector_defname(type), loc, rot, false, local_view_bits);
1155 if (ELEM(type, PFIELD_WIND, PFIELD_VORTEX)) {
1157 }
1158 }
1159
1160 ob->pd = BKE_partdeflect_new(type);
1161
1162 return OPERATOR_FINISHED;
1163}
1164
1166{
1167 /* identifiers */
1168 ot->name = "Add Effector";
1169 ot->description = "Add an empty object with a physics effector to the scene";
1170 ot->idname = "OBJECT_OT_effector_add";
1171
1172 /* API callbacks. */
1173 ot->exec = effector_add_exec;
1175
1176 /* flags */
1178
1179 /* properties */
1180 ot->prop = RNA_def_enum(ot->srna, "type", field_type_items, 0, "Type", "");
1181
1183 add_generic_props(ot, true);
1184}
1185
1187
1188/* -------------------------------------------------------------------- */
1191
1193{
1194 View3D *v3d = CTX_wm_view3d(C);
1195 Scene *scene = CTX_data_scene(C);
1196
1197 /* force view align for cameras */
1198 RNA_enum_set(op->ptr, "align", ALIGN_VIEW);
1199
1200 ushort local_view_bits;
1201 bool enter_editmode;
1202 float loc[3], rot[3];
1203 add_generic_get_opts(C, op, 'Z', loc, rot, nullptr, &enter_editmode, &local_view_bits, nullptr);
1204
1205 Object *ob = add_type(C, OB_CAMERA, nullptr, loc, rot, false, local_view_bits);
1206
1207 if (v3d) {
1208 if (v3d->camera == nullptr) {
1209 v3d->camera = ob;
1210 }
1211 if (v3d->scenelock && scene->camera == nullptr) {
1212 scene->camera = ob;
1213 }
1214 }
1215
1216 Camera *cam = id_cast<Camera *>(ob->data);
1217 cam->drawsize = v3d ? ED_view3d_grid_scale(scene, v3d, nullptr) :
1218 ED_scene_grid_scale(scene, nullptr);
1219
1220 return OPERATOR_FINISHED;
1221}
1222
1224{
1225 PropertyRNA *prop;
1226
1227 /* identifiers */
1228 ot->name = "Add Camera";
1229 ot->description = "Add a camera object to the scene";
1230 ot->idname = "OBJECT_OT_camera_add";
1231
1232 /* API callbacks. */
1235
1236 /* flags */
1238
1239 add_generic_props(ot, true);
1240
1241 /* hide this for cameras, default */
1242 prop = RNA_struct_type_find_property(ot->srna, "align");
1244}
1245
1247
1248/* -------------------------------------------------------------------- */
1251
1253{
1254 Main *bmain = CTX_data_main(C);
1255 Scene *scene = CTX_data_scene(C);
1256 ViewLayer *view_layer = CTX_data_view_layer(C);
1257
1258 ushort local_view_bits;
1259 bool enter_editmode;
1260 float loc[3], rot[3];
1262 add_generic_get_opts(C, op, 'Z', loc, rot, nullptr, &enter_editmode, &local_view_bits, nullptr);
1263
1264 bool newob = false;
1265 BKE_view_layer_synced_ensure(*bmain, scene, view_layer);
1266 Object *obedit = BKE_view_layer_edit_object_get(view_layer);
1267 if (obedit == nullptr || obedit->type != OB_MBALL) {
1268 obedit = add_type(C, OB_MBALL, nullptr, loc, rot, true, local_view_bits);
1269 newob = true;
1270 }
1271 else {
1273 }
1274
1275 float mat[4][4];
1276 new_primitive_matrix(C, obedit, loc, rot, nullptr, mat);
1277 /* Halving here is done to account for constant values from #BKE_mball_element_add.
1278 * While the default radius of the resulting meta element is 2,
1279 * we want to pass in 1 so other values such as resolution are scaled by 1.0. */
1280 float dia = RNA_float_get(op->ptr, "radius") / 2;
1281
1282 ED_mball_add_primitive(C, obedit, newob, mat, dia, RNA_enum_get(op->ptr, "type"));
1283
1284 /* userdef */
1285 if (newob && !enter_editmode) {
1286 editmode_exit_ex(bmain, scene, obedit, EM_FREEDATA);
1287 }
1288 else {
1289 /* Only needed in edit-mode (#add_type normally handles this). */
1291 }
1292
1293 return OPERATOR_FINISHED;
1294}
1295
1297{
1298 /* identifiers */
1299 ot->name = "Add Metaball";
1300 ot->description = "Add a metaball object to the scene";
1301 ot->idname = "OBJECT_OT_metaball_add";
1302
1303 /* API callbacks. */
1304 ot->invoke = WM_menu_invoke;
1307
1308 /* flags */
1310
1311 ot->prop = RNA_def_enum(ot->srna, "type", rna_enum_metaelem_type_items, 0, "Primitive", "");
1312
1313 add_unit_props_radius_ex(ot, 2.0f);
1314 add_generic_props(ot, true);
1315}
1316
1318
1319/* -------------------------------------------------------------------- */
1322
1324{
1325 Object *obedit = CTX_data_edit_object(C);
1326 bool enter_editmode;
1327 ushort local_view_bits;
1328 float loc[3], rot[3];
1329
1331 add_generic_get_opts(C, op, 'Z', loc, rot, nullptr, &enter_editmode, &local_view_bits, nullptr);
1332
1333 if (obedit && obedit->type == OB_FONT) {
1334 return OPERATOR_CANCELLED;
1335 }
1336
1337 obedit = add_type(C, OB_FONT, nullptr, loc, rot, enter_editmode, local_view_bits);
1338 BKE_object_obdata_size_init(obedit, RNA_float_get(op->ptr, "size"));
1339
1340 return OPERATOR_FINISHED;
1341}
1342
1344{
1345 /* identifiers */
1346 ot->name = "Add Text";
1347 ot->description = "Add a text object to the scene";
1348 ot->idname = "OBJECT_OT_text_add";
1349
1350 /* API callbacks. */
1353
1354 /* flags */
1356
1357 /* properties */
1358 add_unit_props_size(ot, 1.0f);
1359 add_generic_props(ot, true);
1360}
1361
1363
1364/* -------------------------------------------------------------------- */
1367
1369{
1370 Main *bmain = CTX_data_main(C);
1371 Scene *scene = CTX_data_scene(C);
1372 ViewLayer *view_layer = CTX_data_view_layer(C);
1373 BKE_view_layer_synced_ensure(*bmain, scene, view_layer);
1374 Object *obedit = BKE_view_layer_edit_object_get(view_layer);
1375
1377 bool newob = false;
1378 bool enter_editmode;
1379 ushort local_view_bits;
1380 float loc[3], rot[3], dia;
1381 bool view_aligned = rv3d && (U.flag & USER_ADD_VIEWALIGNED);
1382
1384 add_generic_get_opts(C, op, 'Z', loc, rot, nullptr, &enter_editmode, &local_view_bits, nullptr);
1385
1386 if ((obedit == nullptr) || (obedit->type != OB_ARMATURE)) {
1387 obedit = add_type(C, OB_ARMATURE, nullptr, loc, rot, true, local_view_bits);
1388 editmode_enter_ex(bmain, scene, obedit, 0);
1389 newob = true;
1390 }
1391 else {
1393 }
1394
1395 if (obedit == nullptr) {
1396 BKE_report(op->reports, RPT_ERROR, "Cannot create editmode armature");
1397 return OPERATOR_CANCELLED;
1398 }
1399
1400 /* Give the Armature its default bone collection. */
1401 bArmature *armature = id_cast<bArmature *>(obedit->data);
1402 BoneCollection *default_bonecoll = ANIM_armature_bonecoll_new(armature, "");
1403 ANIM_armature_bonecoll_active_set(armature, default_bonecoll);
1404
1405 dia = RNA_float_get(op->ptr, "radius");
1406 ED_armature_ebone_add_primitive(obedit, dia, view_aligned);
1407
1408 /* userdef */
1409 if (newob && !enter_editmode) {
1410 editmode_exit_ex(bmain, scene, obedit, EM_FREEDATA);
1411 }
1412
1413 return OPERATOR_FINISHED;
1414}
1415
1417{
1418 /* identifiers */
1419 ot->name = "Add Armature";
1420 ot->description = "Add an armature object to the scene";
1421 ot->idname = "OBJECT_OT_armature_add";
1422
1423 /* API callbacks. */
1426
1427 /* flags */
1429
1430 /* properties */
1432 add_generic_props(ot, true);
1433}
1434
1436
1437/* -------------------------------------------------------------------- */
1440
1442{
1443 Object *ob;
1444 int type = RNA_enum_get(op->ptr, "type");
1445 ushort local_view_bits;
1446 float loc[3], rot[3];
1447
1449 add_generic_get_opts(C, op, 'Z', loc, rot, nullptr, nullptr, &local_view_bits, nullptr);
1450
1451 ob = add_type(C, OB_EMPTY, nullptr, loc, rot, false, local_view_bits);
1452
1454 BKE_object_obdata_size_init(ob, RNA_float_get(op->ptr, "radius"));
1455
1456 return OPERATOR_FINISHED;
1457}
1458
1460{
1461 /* identifiers */
1462 ot->name = "Add Empty";
1463 ot->description = "Add an empty object to the scene";
1464 ot->idname = "OBJECT_OT_empty_add";
1465
1466 /* API callbacks. */
1467 ot->invoke = WM_menu_invoke;
1470
1471 /* flags */
1473
1474 /* properties */
1475 ot->prop = RNA_def_enum(ot->srna, "type", rna_enum_object_empty_drawtype_items, 0, "Type", "");
1476
1478 add_generic_props(ot, false);
1479}
1480
1482{
1483 Image *ima = nullptr;
1484
1485 ima = id_cast<Image *>(WM_operator_drop_load_path(C, op, ID_IM));
1486 if (!ima) {
1487 return OPERATOR_CANCELLED;
1488 }
1489
1490 if (!ED_operator_objectmode(C)) {
1491 BKE_report(op->reports, RPT_ERROR, "Image objects can only be added in Object Mode");
1492 return OPERATOR_CANCELLED;
1493 }
1494
1495 /* Add new empty. */
1496 ushort local_view_bits;
1497 float loc[3], rot[3];
1498
1499 add_generic_get_opts(C, op, 'Z', loc, rot, nullptr, nullptr, &local_view_bits, nullptr);
1500
1501 Object *ob = add_type(C, OB_EMPTY, nullptr, loc, rot, false, local_view_bits);
1502 ob->empty_drawsize = 5.0f;
1503
1504 if (RNA_boolean_get(op->ptr, "background")) {
1505 /* When "background" has been set to "true", set image to render in the background. */
1508
1510 if (rv3d->persp != RV3D_PERSP) {
1512 }
1513 }
1514
1516
1517 ob->data = id_cast<ID *>(ima);
1518
1519 return OPERATOR_FINISHED;
1520}
1521
1523{
1524 if (!RNA_struct_property_is_set(op->ptr, "align")) {
1525 /* Default to Aligned unless something else was explicitly passed. */
1526 RNA_enum_set(op->ptr, "align", ALIGN_VIEW);
1527 }
1528
1529 /* Check if the user has not specified the image to load.
1530 * If they have not, assume this is a drag an drop operation. */
1531 if (!RNA_struct_property_is_set(op->ptr, "filepath") &&
1533 {
1536 }
1537
1538 if (!RNA_struct_property_is_set(op->ptr, "background")) {
1539 /* Check if we should switch to "background" mode. */
1541 if (rv3d->persp != RV3D_PERSP) {
1542 RNA_boolean_set(op->ptr, "background", true);
1543 }
1544 }
1545
1546 float loc[3];
1547 location_from_view(C, loc);
1548 ED_view3d_cursor3d_position(C, event->mval, false, loc);
1549 RNA_float_set_array(op->ptr, "location", loc);
1550
1551 Object *ob_cursor = ED_view3d_give_object_under_cursor(C, event->mval);
1552
1553 /* Either change empty under cursor or create a new empty. */
1554 if (!ob_cursor || ob_cursor->type != OB_EMPTY) {
1555 return object_image_add_exec(C, op);
1556 }
1557 /* User dropped an image on an existing image. */
1558 Image *ima = nullptr;
1559
1560 ima = id_cast<Image *>(WM_operator_drop_load_path(C, op, ID_IM));
1561 if (!ima) {
1562 return OPERATOR_CANCELLED;
1563 }
1564 /* Handled below. */
1565 id_us_min(&ima->id);
1566
1567 Scene *scene = CTX_data_scene(C);
1569 DEG_id_tag_update(id_cast<ID *>(ob_cursor), ID_RECALC_TRANSFORM);
1570
1572
1573 id_us_min(ob_cursor->data);
1574 ob_cursor->data = id_cast<ID *>(ima);
1575 id_us_plus(ob_cursor->data);
1576 return OPERATOR_FINISHED;
1577}
1578
1580{
1581 return CTX_wm_region_view3d(C);
1582}
1583
1585{
1586 /* identifiers */
1587 ot->name = "Add Empty Image/Drop Image to Empty";
1588 ot->description = "Add an empty image type to scene with data";
1589 ot->idname = "OBJECT_OT_empty_image_add";
1590
1591 /* API callbacks. */
1595
1596 /* flags */
1598
1599 /* properties */
1607
1609 add_generic_props(ot, false);
1610 PropertyRNA *prop;
1611 prop = RNA_def_boolean(ot->srna,
1612 "background",
1613 false,
1614 "Put in Background",
1615 "Make the image render behind all objects");
1617 /* Hide the filepath and relative path prop */
1618 prop = RNA_struct_type_find_property(ot->srna, "filepath");
1620 prop = RNA_struct_type_find_property(ot->srna, "relative_path");
1622}
1623
1625
1626/* -------------------------------------------------------------------- */
1629
1632 "2D",
1633 0,
1634 "2D Layers",
1635 "Display strokes using Grease Pencil layers to define order"},
1636 {GP_DRAWMODE_3D, "3D", 0, "3D Location", "Display strokes using real 3D position in 3D space"},
1637 {0, nullptr, 0, nullptr, nullptr},
1638};
1639
1641{
1642 Main *bmain = CTX_data_main(C);
1643 Scene *scene = CTX_data_scene(C);
1644 Object *original_active_object = CTX_data_active_object(C);
1645 /* TODO: For now, only support adding the 'Stroke' type. */
1646 const int type = RNA_enum_get(op->ptr, "type");
1647
1648 ushort local_view_bits;
1649 float loc[3], rot[3];
1650
1651 /* NOTE: We use 'Y' here (not 'Z'), as. */
1653 add_generic_get_opts(C, op, 'Y', loc, rot, nullptr, nullptr, &local_view_bits, nullptr);
1654
1655 const char *ob_name = nullptr;
1656 switch (type) {
1657 case GP_EMPTY: {
1658 ob_name = CTX_DATA_(BLT_I18NCONTEXT_ID_GPENCIL, "GPencil");
1659 break;
1660 }
1661 case GP_STROKE: {
1662 ob_name = CTX_DATA_(BLT_I18NCONTEXT_ID_GPENCIL, "Stroke");
1663 break;
1664 }
1665 case GP_MONKEY: {
1666 ob_name = CTX_DATA_(BLT_I18NCONTEXT_ID_GPENCIL, "Suzanne");
1667 break;
1668 }
1672 ob_name = CTX_DATA_(BLT_I18NCONTEXT_ID_GPENCIL, "LineArt");
1673 break;
1674 }
1675 default: {
1676 break;
1677 }
1678 }
1679
1680 Object *object = add_type(C, OB_GREASE_PENCIL, ob_name, loc, rot, false, local_view_bits);
1681 GreasePencil &grease_pencil_id = *id_cast<GreasePencil *>(object->data);
1682 const bool use_in_front = RNA_boolean_get(op->ptr, "use_in_front");
1683 const bool use_lights = RNA_boolean_get(op->ptr, "use_lights");
1684
1685 switch (type) {
1686 case GP_EMPTY: {
1687 greasepencil::create_blank(*bmain, *object, scene->r.cfra);
1688 break;
1689 }
1690 case GP_STROKE: {
1691 const float radius = RNA_float_get(op->ptr, "radius");
1692 const float3 scale(radius);
1693
1694 float4x4 mat;
1695 new_primitive_matrix(C, object, loc, rot, scale, mat.ptr());
1696
1697 greasepencil::create_stroke(*bmain, *object, mat, scene->r.cfra);
1698 break;
1699 }
1700 case GP_MONKEY: {
1701 const float radius = RNA_float_get(op->ptr, "radius");
1702 const float3 scale(radius);
1703
1704 float4x4 mat;
1705 new_primitive_matrix(C, object, loc, rot, scale, mat.ptr());
1706
1707 greasepencil::create_suzanne(*bmain, *object, mat, scene->r.cfra);
1708 break;
1709 }
1713 const int type = RNA_enum_get(op->ptr, "type");
1714 const int stroke_depth_order = RNA_enum_get(op->ptr, "stroke_depth_order");
1715 const float stroke_depth_offset = RNA_float_get(op->ptr, "stroke_depth_offset");
1716
1717 greasepencil::create_blank(*bmain, *object, scene->r.cfra);
1718
1719 auto *grease_pencil = reinterpret_cast<GreasePencil *>(object->data);
1721 auto *md = reinterpret_cast<GreasePencilLineartModifierData *>(new_md);
1722
1723 BLI_addtail(&object->modifiers, md);
1724 BKE_modifier_unique_name(&object->modifiers, new_md);
1725 BKE_modifiers_persistent_uid_init(*object, *new_md);
1726
1728 md->source_type = LINEART_SOURCE_COLLECTION;
1729 md->source_collection = CTX_data_collection(C);
1730 }
1731 else if (type == GREASE_PENCIL_LINEART_OBJECT) {
1732 md->source_type = LINEART_SOURCE_OBJECT;
1733 md->source_object = original_active_object;
1734 }
1735 else {
1736 /* Whole scene. */
1737 md->source_type = LINEART_SOURCE_SCENE;
1738 }
1739 /* Only created one layer and one material. */
1740 STRNCPY_UTF8(md->target_layer, grease_pencil->get_active_layer()->name().c_str());
1741 md->target_material = BKE_object_material_get(object, 0);
1742 if (md->target_material) {
1743 id_us_plus(&md->target_material->id);
1744 }
1745
1746 if (!use_in_front) {
1747 if (stroke_depth_order == GP_DRAWMODE_3D) {
1749 }
1750 md->stroke_depth_offset = stroke_depth_offset;
1751 }
1752
1753 break;
1754 }
1755 }
1756
1757 SET_FLAG_FROM_TEST(object->dtx, use_in_front, OB_DRAW_IN_FRONT);
1759
1760 for (bke::greasepencil::Layer *layer : grease_pencil_id.layers_for_write()) {
1761 SET_FLAG_FROM_TEST(layer->as_node().flag, use_lights, GP_LAYER_TREE_NODE_USE_LIGHTS);
1762 }
1763
1764 DEG_id_tag_update(&grease_pencil_id.id, ID_RECALC_GEOMETRY);
1765 WM_main_add_notifier(NC_GEOM | ND_DATA, &grease_pencil_id.id);
1766
1767 return OPERATOR_FINISHED;
1768}
1769
1771 wmOperator *op,
1772 const wmEvent * /*event*/)
1773{
1774 const int type = RNA_enum_get(op->ptr, "type");
1775
1776 /* Only disable "use_in_front" if it's one of the non-LineArt types */
1777 if (ELEM(type, GP_EMPTY, GP_STROKE, GP_MONKEY)) {
1778 RNA_boolean_set(op->ptr, "use_in_front", false);
1779 }
1780
1781 return object_grease_pencil_add_exec(C, op);
1782}
1783
1785{
1786 /* identifiers */
1787 ot->name = "Add Grease Pencil";
1788 ot->description = "Add a Grease Pencil object to the scene";
1789 ot->idname = "OBJECT_OT_grease_pencil_add";
1790
1791 /* API callbacks. */
1795
1796 /* flags */
1798
1799 ot->prop = RNA_def_enum(ot->srna, "type", rna_enum_object_gpencil_type_items, 0, "Type", "");
1802 "use_in_front",
1803 true,
1804 "Show In Front",
1805 "Show Line Art Grease Pencil in front of everything");
1806 RNA_def_float(ot->srna,
1807 "stroke_depth_offset",
1808 0.05f,
1809 0.0f,
1810 FLT_MAX,
1811 "Stroke Offset",
1812 "Stroke offset for the Line Art modifier",
1813 0.0f,
1814 0.5f);
1816 ot->srna, "use_lights", true, "Use Lights", "Use lights for this Grease Pencil object");
1818 ot->srna,
1819 "stroke_depth_order",
1822 "Stroke Depth Order",
1823 "Defines how the strokes are ordered in 3D space (for objects not displayed 'In Front')");
1824
1826 add_generic_props(ot, false);
1827}
1828
1830
1831/* -------------------------------------------------------------------- */
1834
1835static const char *get_light_defname(int type)
1836{
1837 switch (type) {
1838 case LA_LOCAL:
1839 return CTX_DATA_(BLT_I18NCONTEXT_ID_LIGHT, "Point");
1840 case LA_SUN:
1841 return CTX_DATA_(BLT_I18NCONTEXT_ID_LIGHT, "Sun");
1842 case LA_SPOT:
1843 return CTX_DATA_(BLT_I18NCONTEXT_ID_LIGHT, "Spot");
1844 case LA_AREA:
1845 return CTX_DATA_(BLT_I18NCONTEXT_ID_LIGHT, "Area");
1846 default:
1847 return CTX_DATA_(BLT_I18NCONTEXT_ID_LIGHT, "Light");
1848 }
1849}
1850
1852{
1853 Object *ob;
1854 Light *la;
1855 eLightType type = eLightType(RNA_enum_get(op->ptr, "type"));
1856 ushort local_view_bits;
1857 float loc[3], rot[3];
1858
1860 add_generic_get_opts(C, op, 'Z', loc, rot, nullptr, nullptr, &local_view_bits, nullptr);
1861
1862 ob = add_type(C, OB_LAMP, get_light_defname(type), loc, rot, false, local_view_bits);
1863
1864 float size = RNA_float_get(op->ptr, "radius");
1865 /* Better defaults for light size. */
1866 switch (type) {
1867 case LA_LOCAL:
1868 case LA_SPOT:
1869 break;
1870 case LA_AREA:
1871 size *= 4.0f;
1872 break;
1873 default:
1874 size *= 0.5f;
1875 break;
1876 }
1878
1879 la = id_cast<Light *>(ob->data);
1880 la->type = type;
1881
1882 if (type == LA_SUN) {
1883 la->energy = 1.0f;
1884 }
1885
1886 return OPERATOR_FINISHED;
1887}
1888
1890{
1891 /* identifiers */
1892 ot->name = "Add Light";
1893 ot->description = "Add a light object to the scene";
1894 ot->idname = "OBJECT_OT_light_add";
1895
1896 /* API callbacks. */
1897 ot->invoke = WM_menu_invoke;
1900
1901 /* flags */
1903
1904 /* properties */
1905 ot->prop = RNA_def_enum(ot->srna, "type", rna_enum_light_type_items, 0, "Type", "");
1907
1909 add_generic_props(ot, false);
1910}
1911
1913
1914/* -------------------------------------------------------------------- */
1917
1919 /* The collection that is supposed to be added, determined through operator properties. */
1921 /* The local-view bits (if any) the object should have set to become visible in current context.
1922 */
1924 /* The transform that should be applied to the collection, determined through operator properties
1925 * if set (e.g. to place the collection under the cursor), otherwise through context (e.g. 3D
1926 * cursor location). */
1927 float loc[3], rot[3], scale[3];
1928};
1929
1930static std::optional<CollectionAddInfo> collection_add_info_get_from_op(bContext *C,
1931 wmOperator *op)
1932{
1933 CollectionAddInfo add_info{};
1934
1935 Main *bmain = CTX_data_main(C);
1936
1937 PropertyRNA *prop_location = RNA_struct_find_property(op->ptr, "location");
1938
1939 add_info.collection = reinterpret_cast<Collection *>(
1941
1942 bool update_location_if_necessary = false;
1943 if (add_info.collection) {
1944 update_location_if_necessary = true;
1945 }
1946 else {
1947 add_info.collection = static_cast<Collection *>(
1948 BLI_findlink(&bmain->collections, RNA_enum_get(op->ptr, "collection")));
1949 }
1950
1951 if (update_location_if_necessary && CTX_wm_region_view3d(C)) {
1952 int mval[2];
1953 if (!RNA_property_is_set(op->ptr, prop_location) && object_add_drop_xy_get(C, op, &mval)) {
1954 location_from_view(C, add_info.loc);
1955 ED_view3d_cursor3d_position(C, mval, false, add_info.loc);
1956 RNA_property_float_set_array(op->ptr, prop_location, add_info.loc);
1957 }
1958 }
1959
1960 if (add_info.collection == nullptr) {
1961 return std::nullopt;
1962 }
1963
1965 op,
1966 'Z',
1967 add_info.loc,
1968 add_info.rot,
1969 add_info.scale,
1970 nullptr,
1971 &add_info.local_view_bits,
1972 nullptr);
1973
1974 ViewLayer *view_layer = CTX_data_view_layer(C);
1975
1976 /* Avoid dependency cycles. */
1977 LayerCollection *active_lc = BKE_layer_collection_get_active(view_layer);
1978 while (BKE_collection_cycle_find(active_lc->collection, add_info.collection)) {
1979 active_lc = BKE_layer_collection_activate_parent(view_layer, active_lc);
1980 }
1981
1982 return add_info;
1983}
1984
1986{
1987 std::optional<CollectionAddInfo> add_info = collection_add_info_get_from_op(C, op);
1988 if (!add_info) {
1989 return OPERATOR_CANCELLED;
1990 }
1991
1992 Object *ob = add_type(C,
1993 OB_EMPTY,
1994 add_info->collection->id.name + 2,
1995 add_info->loc,
1996 add_info->rot,
1997 false,
1998 add_info->local_view_bits);
1999 /* `add_type()` does not have scale argument so copy that value separately. */
2000 copy_v3_v3(ob->scale, add_info->scale);
2001 ob->instance_collection = add_info->collection;
2002 ob->empty_drawsize = U.collection_instance_empty_size;
2004 id_us_plus(&add_info->collection->id);
2005
2006 return OPERATOR_FINISHED;
2007}
2008
2010 wmOperator *op,
2011 const wmEvent *event)
2012{
2013 if (!object_add_drop_xy_is_set(op)) {
2014 RNA_int_set(op->ptr, "drop_x", event->xy[0]);
2015 RNA_int_set(op->ptr, "drop_y", event->xy[1]);
2016 }
2017
2019 return WM_enum_search_invoke(C, op, event);
2020 }
2021 return op->type->exec(C, op);
2022}
2023
2025{
2026 PropertyRNA *prop;
2027
2028 /* identifiers */
2029 ot->name = "Add Collection Instance";
2030 ot->description = "Add a collection instance";
2031 ot->idname = "OBJECT_OT_collection_instance_add";
2032
2033 /* API callbacks. */
2037
2038 /* flags */
2040
2041 /* properties */
2043 ot->srna, "name", "Collection", MAX_ID_NAME - 2, "Name", "Collection name to add");
2044 prop = RNA_def_enum(ot->srna, "collection", rna_enum_dummy_NULL_items, 0, "Collection", "");
2047 ot->prop = prop;
2048 add_generic_props(ot, false);
2049
2051
2053}
2054
2056
2057/* -------------------------------------------------------------------- */
2075
2077{
2078 Main *bmain = CTX_data_main(C);
2081 std::optional<CollectionAddInfo> add_info = collection_add_info_get_from_op(C, op);
2082 if (!add_info) {
2083 return OPERATOR_CANCELLED;
2084 }
2085
2086 if (RNA_boolean_get(op->ptr, "use_instance")) {
2087 /* In case no active editable collection is found, link/append code will have added imported
2088 * collections/objects to a new collection (see code in
2089 * `loose_data_instantiate_ensure_active_collection`). There is no easy way to retrieve these
2090 * currently from here, so just leave the data in these for now - this is not a situation that
2091 * should happen in 'normal expected use-cases' anyway. */
2092 if (active_collection) {
2093 BKE_collection_child_remove(bmain, active_collection, add_info->collection);
2094 DEG_id_tag_update(&active_collection->id, ID_RECALC_SYNC_TO_EVAL);
2095 }
2096
2097 Object *ob = add_type(C,
2098 OB_EMPTY,
2099 add_info->collection->id.name + 2,
2100 add_info->loc,
2101 add_info->rot,
2102 false,
2103 add_info->local_view_bits);
2104 ob->instance_collection = add_info->collection;
2105 ob->empty_drawsize = U.collection_instance_empty_size;
2107 id_us_plus(&add_info->collection->id);
2109 }
2110 else if (ID_IS_EDITABLE(&add_info->collection->id)) {
2111 ViewLayer *view_layer = CTX_data_view_layer(C);
2112 float delta_mat[4][4];
2113 unit_m4(delta_mat);
2114
2115 const float scale[3] = {1.0f, 1.0f, 1.0f};
2116 loc_eul_size_to_mat4(delta_mat, add_info->loc, add_info->rot, scale);
2117
2118 float offset[3];
2119 /* Reverse apply the instance offset, so toggling the Instance option doesn't cause the
2120 * collection to jump. */
2121 negate_v3_v3(offset, add_info->collection->instance_offset);
2122 translate_m4(delta_mat, UNPACK3(offset));
2123
2124 ObjectsInViewLayerParams params = {0};
2126 view_layer, nullptr, &params);
2127 object_xform_array_m4(objects.data(), objects.size(), delta_mat);
2128 }
2129
2130 return OPERATOR_FINISHED;
2131}
2132
2134{
2135 PropertyRNA *prop;
2136
2137 /* identifiers */
2138 /* Name should only be displayed in the drag tooltip. */
2139 ot->name = "Add Collection";
2140 ot->description = "Add the dragged collection to the scene";
2141 ot->idname = "OBJECT_OT_collection_external_asset_drop";
2142
2143 /* API callbacks. */
2147
2148 /* flags */
2150
2151 /* properties */
2153
2154 add_generic_props(ot, false);
2155
2156 prop = RNA_def_boolean(ot->srna,
2157 "use_instance",
2158 true,
2159 "Instance",
2160 "Add the dropped collection as collection instance");
2162
2164
2165 prop = RNA_def_enum(ot->srna, "collection", rna_enum_dummy_NULL_items, 0, "Collection", "");
2168 ot->prop = prop;
2169}
2170
2172
2173/* -------------------------------------------------------------------- */
2178
2180{
2181 Main *bmain = CTX_data_main(C);
2182 ID *id = nullptr;
2183 ushort local_view_bits;
2184 float loc[3], rot[3];
2185
2186 PropertyRNA *prop_type = RNA_struct_find_property(op->ptr, "type");
2187 PropertyRNA *prop_location = RNA_struct_find_property(op->ptr, "location");
2188
2189 const short id_type = RNA_property_enum_get(op->ptr, prop_type);
2191 if (id == nullptr) {
2192 return OPERATOR_CANCELLED;
2193 }
2194 const int object_type = BKE_object_obdata_to_type(id);
2195 if (object_type == -1) {
2196 return OPERATOR_CANCELLED;
2197 }
2198
2199 if (CTX_wm_region_view3d(C)) {
2200 int mval[2];
2201 if (!RNA_property_is_set(op->ptr, prop_location) && object_add_drop_xy_get(C, op, &mval)) {
2202 location_from_view(C, loc);
2203 ED_view3d_cursor3d_position(C, mval, false, loc);
2204 RNA_property_float_set_array(op->ptr, prop_location, loc);
2205 }
2206 }
2207
2208 add_generic_get_opts(C, op, 'Z', loc, rot, nullptr, nullptr, &local_view_bits, nullptr);
2209
2210 add_type_with_obdata(C, object_type, id->name + 2, loc, rot, false, local_view_bits, id);
2211
2212 return OPERATOR_FINISHED;
2213}
2214
2216{
2217 /* identifiers */
2218 ot->name = "Add Object Data Instance";
2219 ot->description = "Add an object data instance";
2220 ot->idname = "OBJECT_OT_data_instance_add";
2221
2222 /* API callbacks. */
2226
2227 /* flags */
2229
2230 /* properties */
2232 PropertyRNA *prop = RNA_def_enum(ot->srna, "type", rna_enum_id_type_items, 0, "Type", "");
2234 add_generic_props(ot, false);
2235
2237}
2238
2240
2241/* -------------------------------------------------------------------- */
2244
2246{
2247 Main *bmain = CTX_data_main(C);
2248 Scene *scene = CTX_data_scene(C);
2249
2250 ushort local_view_bits;
2251 float loc[3], rot[3];
2252 add_generic_get_opts(C, op, 'Z', loc, rot, nullptr, nullptr, &local_view_bits, nullptr);
2253
2254 Object *ob = add_type(C, OB_SPEAKER, nullptr, loc, rot, false, local_view_bits);
2255 const bool is_liboverride = ID_IS_OVERRIDE_LIBRARY(ob);
2256
2257 /* To make it easier to start using this immediately in NLA, a default sound clip is created
2258 * ready to be moved around to re-time the sound and/or make new sound clips. */
2259 {
2260 /* create new data for NLA hierarchy */
2261 AnimData *adt = BKE_animdata_ensure_id(&ob->id);
2262 NlaTrack *nlt = BKE_nlatrack_new_tail(&adt->nla_tracks, is_liboverride);
2264 NlaStrip *strip = BKE_nla_add_soundstrip(bmain, scene, id_cast<Speaker *>(ob->data));
2265 strip->start = scene->r.cfra;
2266 strip->end += strip->start;
2267
2268 /* hook them up */
2269 BKE_nlatrack_add_strip(nlt, strip, is_liboverride);
2270
2271 /* Auto-name the strip, and give the track an interesting name. */
2272 STRNCPY_UTF8(nlt->name, DATA_("SoundTrack"));
2273 BKE_nlastrip_validate_name(adt, strip);
2274
2276 }
2277
2278 return OPERATOR_FINISHED;
2279}
2280
2282{
2283 /* identifiers */
2284 ot->name = "Add Speaker";
2285 ot->description = "Add a speaker object to the scene";
2286 ot->idname = "OBJECT_OT_speaker_add";
2287
2288 /* API callbacks. */
2291
2292 /* flags */
2294
2295 add_generic_props(ot, true);
2296}
2297
2299
2300/* -------------------------------------------------------------------- */
2303
2305{
2306 ushort local_view_bits;
2307 float loc[3], rot[3];
2308 add_generic_get_opts(C, op, 'Z', loc, rot, nullptr, nullptr, &local_view_bits, nullptr);
2309
2310 Object *object = add_type(C, OB_CURVES, nullptr, loc, rot, false, local_view_bits);
2311
2312 Curves *curves_id = id_cast<Curves *>(object->data);
2313 curves_id->geometry.wrap() = ed::curves::primitive_random_sphere(500, 8);
2314
2315 return OPERATOR_FINISHED;
2316}
2317
2319{
2320 /* identifiers */
2321 ot->name = "Add Random Curves";
2322 ot->description = "Add a curves object with random curves to the scene";
2323 ot->idname = "OBJECT_OT_curves_random_add";
2324
2325 /* API callbacks. */
2328
2329 /* flags */
2331
2332 add_generic_props(ot, false);
2333}
2334
2336 Object &object,
2337 const StringRefNull path,
2338 ReportList *reports)
2339{
2340 Scene &scene = *CTX_data_scene(&C);
2341 Main &bmain = *CTX_data_main(&C);
2342
2343 if (ID_IS_LINKED(&object)) {
2344 return nullptr;
2345 }
2346
2347 AssetWeakReference asset_weak_ref{};
2349 asset_weak_ref.relative_asset_identifier = BLI_strdup(path.c_str());
2350 if (G.background) {
2351 /* For testing purposes, make sure assets are loaded (this make take too long to do
2352 * automatically during user interaction). */
2354 }
2356 C, asset_weak_ref, reports);
2357 if (!asset_representation) {
2358 return nullptr;
2359 }
2360 ID *asset_id = asset::asset_local_id_ensure_imported(bmain, *asset_representation);
2361 if (!asset_id) {
2362 return nullptr;
2363 }
2364 if (asset_id->id_type() != ID_NT) {
2365 return nullptr;
2366 }
2367 bNodeTree *node_group = id_cast<bNodeTree *>(asset_id);
2368 NodesModifierData *nmd = reinterpret_cast<NodesModifierData *>(
2369 modifier_add(reports, &bmain, &scene, &object, BKE_id_name(*asset_id), eModifierType_Nodes));
2370 nmd->node_group = node_group;
2371 id_us_plus(&node_group->id);
2373 BKE_modifier_unique_name(&object.modifiers, &nmd->modifier);
2374 MOD_nodes_update_interface(bmain, &object, nmd);
2376 return nmd;
2377}
2378
2380{
2381 for (const ModifierData &md : object->modifiers) {
2382 if (md.type != eModifierType_Nodes) {
2383 continue;
2384 }
2385 const auto &nmd = reinterpret_cast<const NodesModifierData &>(md);
2386 if (!nmd.node_group) {
2387 continue;
2388 }
2389 if (StringRef(BKE_id_name(nmd.node_group->id)) == "Capture Rest Geometry") {
2390 return true;
2391 }
2392 }
2393 return false;
2394}
2395
2397{
2398 Scene *scene = CTX_data_scene(C);
2399
2400 ushort local_view_bits;
2401 add_generic_get_opts(C, op, 'Z', nullptr, nullptr, nullptr, nullptr, &local_view_bits, nullptr);
2402
2403 Object *surface_ob = CTX_data_active_object(C);
2404 BLI_assert(surface_ob != nullptr);
2405
2406 Object *curves_ob = add_type(C, OB_CURVES, nullptr, nullptr, nullptr, false, local_view_bits);
2407 BKE_object_apply_mat4(curves_ob, surface_ob->object_to_world().ptr(), false, false);
2408
2409 /* Set surface object. */
2410 Curves *curves_id = id_cast<Curves *>(curves_ob->data);
2411 curves_id->surface = surface_ob;
2412
2413 /* Parent to surface object. */
2414 parent_set(op->reports, C, scene, curves_ob, surface_ob, PAR_OBJECT, false, true, nullptr);
2415
2416 /* Decide which UV map to use for attachment. */
2417 Mesh *surface_mesh = id_cast<Mesh *>(surface_ob->data);
2418 const StringRef uv_name = surface_mesh->active_uv_map_name();
2419 if (!uv_name.is_empty()) {
2420 curves_id->surface_uv_map = BLI_strdupn(uv_name.data(), uv_name.size());
2421 }
2422
2423 if (!has_capture_rest_geometry_modifier(surface_ob)) {
2425 *C,
2426 *surface_ob,
2427 "nodes/geometry_nodes_essentials.blend/NodeTree/Capture Rest Geometry",
2428 op->reports))
2429 {
2430 if (ID_IS_LINKED(surface_ob)) {
2431 BKE_reportf(op->reports,
2432 RPT_ERROR,
2433 "Can't add \"Capture Rest Geometry\" modifier to linked \"%s\" object",
2434 BKE_id_name(surface_ob->id));
2435 }
2436 else {
2437 BKE_reportf(op->reports,
2438 RPT_ERROR,
2439 "Can't add \"Capture Rest Geometry\" modifier to \"%s\" object",
2440 BKE_id_name(surface_ob->id));
2441 }
2442 }
2443 }
2444 if (NodesModifierData *dynamics_modifier = add_essential_asset_modifier(
2445 *C,
2446 *curves_ob,
2447 "nodes/geometry_nodes_dynamics_assets.blend/NodeTree/Hair Dynamics",
2448 op->reports))
2449 {
2450 dynamics_modifier->modifier.flag |= eModifierFlag_PinLast;
2451 }
2452
2453 /* Make sure the surface object has a rest position attribute which is necessary for
2454 * deformations. */
2456
2457 return OPERATOR_FINISHED;
2458}
2459
2461{
2462 if (!ED_operator_objectmode(C)) {
2463 return false;
2464 }
2466 if (ob == nullptr || ob->type != OB_MESH) {
2467 CTX_wm_operator_poll_msg_set(C, "No active mesh object");
2468 return false;
2469 }
2470 return true;
2471}
2472
2474{
2475 ot->name = "Add Empty Curves";
2476 ot->description = "Add an empty curve object to the scene with the selected mesh as surface";
2477 ot->idname = "OBJECT_OT_curves_empty_hair_add";
2478
2481
2483
2484 add_generic_props(ot, false);
2485}
2486
2488
2489/* -------------------------------------------------------------------- */
2492
2494{
2495 ushort local_view_bits;
2496 float loc[3], rot[3];
2497 add_generic_get_opts(C, op, 'Z', loc, rot, nullptr, nullptr, &local_view_bits, nullptr);
2498
2499 Object *object = add_type(C, OB_POINTCLOUD, nullptr, loc, rot, false, local_view_bits);
2500 PointCloud &pointcloud = *id_cast<PointCloud *>(object->data);
2501 pointcloud.totpoint = 400;
2502
2503 bke::MutableAttributeAccessor attributes = pointcloud.attributes_for_write();
2505 "position", bke::AttrDomain::Point);
2507 "radius", bke::AttrDomain::Point);
2508
2509 RandomNumberGenerator rng(0);
2510 for (const int i : position.span.index_range()) {
2511 position.span[i] = float3(rng.get_float(), rng.get_float(), rng.get_float()) * 2.0f - 1.0f;
2512 radii.span[i] = 0.05f * rng.get_float();
2513 }
2514
2515 position.finish();
2516 radii.finish();
2517
2518 return OPERATOR_FINISHED;
2519}
2520
2522{
2523 ot->name = "Add Point Cloud";
2524 ot->description = "Add a point cloud object to the scene";
2525 ot->idname = "OBJECT_OT_pointcloud_random_add";
2526
2529
2531
2532 add_generic_props(ot, false);
2533}
2534
2536
2537/* -------------------------------------------------------------------- */
2540
2541void base_free_and_unlink(Main *bmain, Scene *scene, Object *ob)
2542{
2543 if (ID_REAL_USERS(ob) <= 1 && ID_EXTRA_USERS(ob) == 0 &&
2545 {
2546 /* We cannot delete indirectly used object... */
2547 printf(
2548 "WARNING, undeletable object '%s', should have been caught before reaching this "
2549 "function!",
2550 ob->id.name + 2);
2551 return;
2552 }
2554 /* Do not delete objects used by overrides of collections. */
2555 return;
2556 }
2557
2559
2560 BKE_scene_collections_object_remove(bmain, scene, ob, true);
2561}
2562
2569
2571{
2572 Main *bmain = CTX_data_main(C);
2573 Scene *scene = CTX_data_scene(C);
2575 const bool use_global = RNA_boolean_get(op->ptr, "use_global");
2576 const bool confirm = op->flag & OP_IS_INVOKE;
2577 uint changed_count = 0;
2578 uint tagged_count = 0;
2579
2580 if (CTX_data_edit_object(C)) {
2581 return OPERATOR_CANCELLED;
2582 }
2583
2584 BKE_main_id_tag_all(bmain, ID_TAG_DOIT, false);
2585
2586 /* Cancel light probe baking when deleting a volumetric light probe. */
2587 bool has_volume_lightprobe = false;
2588 CTX_DATA_BEGIN (C, Object *, ob, selected_objects) {
2589 if (ob->type == OB_LIGHTPROBE &&
2590 id_cast<LightProbe *>(ob->data)->type == LIGHTPROBE_TYPE_VOLUME)
2591 {
2592 has_volume_lightprobe = true;
2593 break;
2594 }
2595 }
2597
2598 if (has_volume_lightprobe && WM_jobs_has_running(wm, scene, WM_JOB_TYPE_LIGHT_BAKE)) {
2600 BKE_report(op->reports,
2602 "Light probe baking canceled because a volume light probe was deleted");
2603 }
2604
2605 CTX_DATA_BEGIN (C, Object *, ob, selected_objects) {
2606 if (ob->id.tag & ID_TAG_INDIRECT) {
2607 /* Can this case ever happen? */
2608 BKE_reportf(op->reports,
2610 "Cannot delete indirectly linked object '%s'",
2611 ob->id.name + 2);
2612 continue;
2613 }
2614
2615 if (!BKE_lib_override_library_id_is_user_deletable(bmain, &ob->id)) {
2616 BKE_reportf(op->reports,
2618 "Cannot delete object '%s' as it is used by override collections",
2619 ob->id.name + 2);
2620 continue;
2621 }
2622
2623 if (ID_REAL_USERS(ob) <= 1 && ID_EXTRA_USERS(ob) == 0 &&
2625 {
2626 BKE_reportf(op->reports,
2628 "Cannot delete object '%s' from scene '%s', indirectly used objects need at "
2629 "least one user",
2630 ob->id.name + 2,
2631 scene->id.name + 2);
2632 continue;
2633 }
2634
2635 /* Use multi tagged delete if `use_global=True`, or the object is used only in one scene. */
2636 if (use_global || ID_REAL_USERS(ob) <= 1) {
2637 ob->id.tag |= ID_TAG_DOIT;
2638 tagged_count += 1;
2639 }
2640 else {
2641 /* Object is used in multiple scenes. Delete the object from the current scene only. */
2643 changed_count += 1;
2644 }
2645 }
2647
2648 if ((changed_count + tagged_count) == 0) {
2649 return OPERATOR_CANCELLED;
2650 }
2651
2652 if (tagged_count > 0) {
2654 }
2655
2656 if (confirm) {
2657 BKE_reportf(op->reports, RPT_INFO, "Deleted %u object(s)", (changed_count + tagged_count));
2658 }
2659
2660 /* delete has to handle all open scenes */
2661 BKE_main_id_tag_listbase(&bmain->scenes.cast<ID>(), ID_TAG_DOIT, true);
2662 for (wmWindow &win : wm->windows) {
2663 scene = WM_window_get_active_scene(&win);
2664
2665 if (scene->id.tag & ID_TAG_DOIT) {
2666 scene->id.tag &= ~ID_TAG_DOIT;
2667
2669
2673 }
2674 }
2675
2676 return OPERATOR_FINISHED;
2677}
2678
2680 wmOperator *op,
2681 const wmEvent * /*event*/)
2682{
2683 if (RNA_boolean_get(op->ptr, "confirm")) {
2685 op,
2686 IFACE_("Delete selected objects?"),
2687 nullptr,
2688 IFACE_("Delete"),
2690 false);
2691 }
2692 return object_delete_exec(C, op);
2693}
2694
2696{
2697 /* identifiers */
2698 ot->name = "Delete";
2699 ot->description = "Delete selected objects";
2700 ot->idname = "OBJECT_OT_delete";
2701
2702 /* API callbacks. */
2706
2707 /* flags */
2709
2710 PropertyRNA *prop;
2711 prop = RNA_def_boolean(
2712 ot->srna, "use_global", false, "Delete Globally", "Remove object from all scenes");
2715}
2716
2718
2719/* -------------------------------------------------------------------- */
2722
2723/* after copying objects, copied data should get new pointers */
2725{
2726 Main *bmain = CTX_data_main(C);
2727
2728 CTX_DATA_BEGIN (C, Object *, ob, selected_editable_objects) {
2730 }
2732
2733#ifndef NDEBUG
2734 /* Call to `BKE_libblock_relink_to_newid` above is supposed to have cleared all those flags. */
2735 ID *id_iter;
2736 FOREACH_MAIN_ID_BEGIN (bmain, id_iter) {
2737 if (GS(id_iter->name) == ID_OB) {
2738 /* Not all duplicated objects would be used by other newly duplicated data, so their flag
2739 * will not always be cleared. */
2740 continue;
2741 }
2742 BLI_assert((id_iter->tag & ID_TAG_NEW) == 0);
2743 }
2745#endif
2746
2748}
2749
2751
2752/* -------------------------------------------------------------------- */
2755
2756/* XXX TODO: That whole hierarchy handling based on persistent_id tricks is
2757 * very confusing and convoluted, and it will fail in many cases besides basic ones.
2758 * Think this should be replaced by a proper tree-like representation of the instantiations,
2759 * should help a lot in both readability, and precise consistent rebuilding of hierarchy.
2760 */
2761
2777 {
2779
2780 if (dob->type == OB_DUPLICOLLECTION) {
2781 for (int i = 1; (i < MAX_DUPLI_RECUR) && dob->persistent_id[i] != INT_MAX; i++) {
2782 hash ^= (dob->persistent_id[i] ^ i);
2783 }
2784 }
2785 else {
2786 hash ^= (dob->persistent_id[0] ^ 0);
2787 }
2788 return hash;
2789 }
2790};
2791
2800 {
2802 for (int i = 1; (i < MAX_DUPLI_RECUR) && dob->persistent_id[i] != INT_MAX; i++) {
2803 hash ^= (dob->persistent_id[i] ^ i);
2804 }
2805 return hash;
2806 }
2807};
2808
2813 bool operator()(const DupliObject *a, const DupliObject *b) const
2814 {
2815 if (a->ob != b->ob) {
2816 return false;
2817 }
2818
2819 if (a->type != b->type) {
2820 return false;
2821 }
2822
2823 if (a->type == OB_DUPLICOLLECTION) {
2824 for (int i = 1; (i < MAX_DUPLI_RECUR); i++) {
2825 if (a->persistent_id[i] != b->persistent_id[i]) {
2826 return false;
2827 }
2828 if (a->persistent_id[i] == INT_MAX) {
2829 break;
2830 }
2831 }
2832 }
2833 else {
2834 if (a->persistent_id[0] != b->persistent_id[0]) {
2835 return false;
2836 }
2837 }
2838
2839 /* matching */
2840 return true;
2841 }
2842};
2843
2844/* Compare function that matches DupliObjectInstancerHash. */
2846 bool operator()(const DupliObject *a, const DupliObject *b) const
2847 {
2848 for (int i = 0; (i < MAX_DUPLI_RECUR); i++) {
2849 if (a->persistent_id[i] != b->persistent_id[i]) {
2850 return false;
2851 }
2852 if (a->persistent_id[i] == INT_MAX) {
2853 break;
2854 }
2855 }
2856
2857 /* matching */
2858 return true;
2859 }
2860};
2861
2863 Depsgraph *depsgraph,
2864 Scene *scene,
2865 Base *base,
2866 const bool use_base_parent,
2867 const bool use_hierarchy)
2868{
2869 Main *bmain = CTX_data_main(C);
2870 ViewLayer *view_layer = CTX_data_view_layer(C);
2871 using ParentMap =
2873 using InstancerMap = Map<DupliObject *,
2874 Object *,
2875 4,
2879 ParentMap *parent_gh = nullptr;
2880 InstancerMap *instancer_gh = nullptr;
2881
2882 Object *object_eval = DEG_get_evaluated(depsgraph, base->object);
2883
2884 if (!(base->object->transflag & OB_DUPLI) &&
2886 {
2887 return;
2888 }
2889
2890 DupliList duplilist;
2891 object_duplilist(depsgraph, object_eval, nullptr, duplilist);
2892
2893 if (duplilist.is_empty()) {
2894 return;
2895 }
2896
2898 if (use_hierarchy) {
2899 parent_gh = MEM_new<ParentMap>(__func__);
2900
2901 if (use_base_parent) {
2902 instancer_gh = MEM_new<InstancerMap>(__func__);
2903 }
2904 }
2905
2906 for (DupliObject &dob : duplilist) {
2907 Object *ob_src = DEG_get_original(dob.ob);
2908 Object *ob_dst = id_cast<Object *>(ID_NEW_SET(ob_src, BKE_id_copy(bmain, &ob_src->id)));
2909 id_us_min(&ob_dst->id);
2910
2911 /* font duplis can have a totcol without material, we get them from parent
2912 * should be implemented better...
2913 */
2914 if (ob_dst->mat == nullptr) {
2915 ob_dst->totcol = 0;
2916 }
2917
2918 BKE_collection_object_add_from(bmain, scene, base->object, ob_dst);
2919 BKE_view_layer_synced_ensure(*bmain, scene, view_layer);
2920 Base *base_dst = BKE_view_layer_base_find(view_layer, ob_dst);
2921 BLI_assert(base_dst != nullptr);
2922
2923 base_select(base_dst, BA_SELECT);
2925
2927
2928 /* make sure apply works */
2929 BKE_animdata_free(&ob_dst->id, true);
2930 ob_dst->adt = nullptr;
2931
2932 ob_dst->parent = nullptr;
2934 ob_dst->runtime->curve_cache = nullptr;
2935 const bool is_dupli_instancer = (ob_dst->transflag & OB_DUPLI) != 0;
2936 ob_dst->transflag &= ~OB_DUPLI;
2937 /* Remove instantiated collection, it's annoying to keep it here
2938 * (and get potentially a lot of usages of it then...). */
2939 id_us_min(id_cast<ID *>(ob_dst->instance_collection));
2940 ob_dst->instance_collection = nullptr;
2941
2942 copy_m4_m4(ob_dst->runtime->object_to_world.ptr(), dob.mat);
2943 BKE_object_apply_mat4(ob_dst, ob_dst->object_to_world().ptr(), false, false);
2944
2945 dupli_map.add(&dob, ob_dst);
2946
2947 if (parent_gh) {
2948 /* Due to nature of hash/comparison of this ghash, a lot of duplis may be considered as
2949 * 'the same', this avoids trying to insert same key several time and
2950 * raise asserts in debug builds... */
2951 parent_gh->add(&dob, ob_dst);
2952
2953 if (is_dupli_instancer && instancer_gh) {
2954 /* Same as above, we may have several 'hits'. */
2955 instancer_gh->add(&dob, ob_dst);
2956 }
2957 }
2958 }
2959
2960 for (DupliObject &dob : duplilist) {
2961 Object *ob_src = dob.ob;
2962 Object *ob_dst = dupli_map.lookup(&dob);
2963
2964 /* Remap new object to itself, and clear again newid pointer of orig object. */
2965 BKE_libblock_relink_to_newid(bmain, &ob_dst->id, 0);
2966
2968
2969 if (use_hierarchy) {
2970 /* original parents */
2971 Object *ob_src_par = ob_src->parent;
2972 Object *ob_dst_par = nullptr;
2973
2974 /* find parent that was also made real */
2975 if (ob_src_par) {
2976 /* OK to keep most of the members uninitialized,
2977 * they won't be read, this is simply for a hash lookup. */
2978 DupliObject dob_key;
2979 dob_key.ob = ob_src_par;
2980 dob_key.type = dob.type;
2981 if (dob.type == OB_DUPLICOLLECTION) {
2982 memcpy(&dob_key.persistent_id[1],
2983 &dob.persistent_id[1],
2984 sizeof(dob.persistent_id[1]) * (MAX_DUPLI_RECUR - 1));
2985 }
2986 else {
2987 dob_key.persistent_id[0] = dob.persistent_id[0];
2988 }
2989 ob_dst_par = parent_gh->lookup_default(&dob_key, nullptr);
2990 }
2991
2992 if (ob_dst_par) {
2993 /* allow for all possible parent types */
2994 ob_dst->partype = ob_src->partype;
2995 STRNCPY_UTF8(ob_dst->parsubstr, ob_src->parsubstr);
2996 ob_dst->par1 = ob_src->par1;
2997 ob_dst->par2 = ob_src->par2;
2998 ob_dst->par3 = ob_src->par3;
2999
3000 copy_m4_m4(ob_dst->parentinv, ob_src->parentinv);
3001
3002 ob_dst->parent = ob_dst_par;
3003 }
3004 }
3005 if (use_base_parent && ob_dst->parent == nullptr) {
3006 Object *ob_dst_par = nullptr;
3007
3008 if (instancer_gh != nullptr) {
3009 /* OK to keep most of the members uninitialized,
3010 * they won't be read, this is simply for a hash lookup. */
3011 DupliObject dob_key;
3012 /* We are looking one step upper in hierarchy, so we need to 'shift' the `persistent_id`,
3013 * ignoring the first item.
3014 * We only check on persistent_id here, since we have no idea what object it might be. */
3015 memcpy(&dob_key.persistent_id[0],
3016 &dob.persistent_id[1],
3017 sizeof(dob_key.persistent_id[0]) * (MAX_DUPLI_RECUR - 1));
3018 ob_dst_par = instancer_gh->lookup_default(&dob_key, nullptr);
3019 }
3020
3021 if (ob_dst_par == nullptr) {
3022 /* Default to parenting to root object...
3023 * Always the case when use_hierarchy is false. */
3024 ob_dst_par = base->object;
3025 }
3026
3027 ob_dst->parent = ob_dst_par;
3028 ob_dst->partype = PAROBJECT;
3029 }
3030
3031 if (ob_dst->parent) {
3032 /* NOTE: this may be the parent of other objects, but it should
3033 * still work out ok */
3034 BKE_object_apply_mat4(ob_dst, dob.mat, false, true);
3035
3036 /* to set ob_dst->orig and in case there's any other discrepancies */
3038 }
3039 }
3040
3042 base->object->instance_collection = nullptr;
3043 }
3044
3045 base_select(base, BA_DESELECT);
3047
3048 MEM_delete(parent_gh);
3049 MEM_delete(instancer_gh);
3050
3052
3053 base->object->transflag &= ~OB_DUPLI;
3055}
3056
3058{
3059 Main *bmain = CTX_data_main(C);
3060 Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
3061 Scene *scene = CTX_data_scene(C);
3062
3063 const bool use_base_parent = RNA_boolean_get(op->ptr, "use_base_parent");
3064 const bool use_hierarchy = RNA_boolean_get(op->ptr, "use_hierarchy");
3065
3067
3068 CTX_DATA_BEGIN (C, Base *, base, selected_editable_bases) {
3069 make_object_duplilist_real(C, depsgraph, scene, base, use_base_parent, use_hierarchy);
3070
3071 /* dependencies were changed */
3072 WM_event_add_notifier(C, NC_OBJECT | ND_PARENT, base->object);
3073 }
3075
3080
3081 return OPERATOR_FINISHED;
3082}
3083
3085{
3086 /* identifiers */
3087 ot->name = "Make Instances Real";
3088 ot->description = "Make instanced objects attached to this object real";
3089 ot->idname = "OBJECT_OT_duplicates_make_real";
3090
3091 /* API callbacks. */
3093
3095
3096 /* flags */
3098
3099 ot->prop = RNA_def_boolean(ot->srna,
3100 "use_base_parent",
3101 false,
3102 "Parent",
3103 "Parent newly created objects to the original instancer");
3106 ot->srna, "use_hierarchy", false, "Keep Hierarchy", "Maintain parent child relationships");
3107}
3108
3110
3111/* -------------------------------------------------------------------- */
3114
3117 "CURVE",
3118 ICON_OUTLINER_OB_CURVE,
3119 "Curve",
3120 "Curve from Mesh or Text objects"},
3121 {OB_MESH,
3122 "MESH",
3123 ICON_OUTLINER_OB_MESH,
3124 "Mesh",
3125 "Mesh from Curve, Surface, Metaball, Text, or Point Cloud objects"},
3127 "POINTCLOUD",
3128 ICON_OUTLINER_OB_POINTCLOUD,
3129 "Point Cloud",
3130 "Point Cloud from Mesh objects"},
3131 {OB_CURVES, "CURVES", ICON_OUTLINER_OB_CURVES, "Curves", "Curves from evaluated curve data"},
3133 "GREASEPENCIL",
3134 ICON_OUTLINER_OB_GREASEPENCIL,
3135 "Grease Pencil",
3136 "Grease Pencil from Curve or Mesh objects"},
3137 {0, nullptr, 0, nullptr, nullptr},
3138};
3139
3141 PointerRNA * /*ptr*/,
3142 PropertyRNA * /*prop*/,
3143 bool *r_free)
3144{
3145 if (!C) { /* needed for docs */
3146 return convert_target_items;
3147 }
3148
3149 EnumPropertyItem *item = nullptr;
3150 int totitem = 0;
3151
3157
3158 RNA_enum_item_end(&item, &totitem);
3159
3160 *r_free = true;
3161
3162 return item;
3163}
3164
3165static void object_data_convert_curve_to_mesh(Main *bmain, Depsgraph *depsgraph, Object *ob)
3166{
3167 Object *object_eval = DEG_get_evaluated(depsgraph, ob);
3168 Curve *curve = id_cast<Curve *>(ob->data);
3169
3170 Mesh *mesh = BKE_mesh_new_from_object_to_bmain(bmain, depsgraph, object_eval, true);
3171 if (mesh == nullptr) {
3172 /* Unable to convert the curve to a mesh. */
3173 return;
3174 }
3175
3177
3179
3180 /* Replace curve used by the object itself. */
3181 ob->data = id_cast<ID *>(mesh);
3182 ob->type = OB_MESH;
3183 id_us_min(&curve->id);
3184 id_us_plus(&mesh->id);
3185 /* Change objects which are using same curve.
3186 * A bit annoying, but:
3187 * - It's possible to have multiple curve objects selected which are sharing the same curve
3188 * data-block. We don't want mesh to be created for every of those objects.
3189 * - This is how conversion worked for a long time. */
3190 for (Object &other_object : bmain->objects) {
3191 if (other_object.data == id_cast<ID *>(curve)) {
3192 other_object.type = OB_MESH;
3193
3194 id_us_min(other_object.data);
3195 other_object.data = ob->data;
3196 id_us_plus(other_object.data);
3197 }
3198 }
3199}
3200
3202{
3203 const Main *bmain = CTX_data_main(C);
3204 Scene *scene = CTX_data_scene(C);
3205 if (!ID_IS_EDITABLE(scene)) {
3206 return false;
3207 }
3208 ViewLayer *view_layer = CTX_data_view_layer(C);
3209 BKE_view_layer_synced_ensure(*bmain, scene, view_layer);
3210 /* Don't use `active_object` in the context, it's important this value
3211 * is from the view-layer as it's used to check if Blender is in object mode. */
3212 Object *obact = BKE_view_layer_active_object_get(view_layer);
3213 if (obact && obact->mode != OB_MODE_OBJECT) {
3214 return false;
3215 }
3216
3217 /* Note that `obact` may not be editable,
3218 * only check the active object to ensure Blender is in object mode. */
3219 return true;
3220}
3221
3222/* Helper for object_convert_exec */
3224 Main *bmain, Depsgraph *depsgraph, Scene *scene, ViewLayer *view_layer, Base *base, Object *ob)
3225{
3226 if (ob == nullptr) {
3227 ob = base->object;
3228 }
3229
3230 Object *obn = id_cast<Object *>(BKE_id_copy(bmain, &ob->id));
3231 id_us_min(&obn->id);
3233 BKE_collection_object_add_from(bmain, scene, ob, obn);
3234
3235 BKE_view_layer_synced_ensure(*bmain, scene, view_layer);
3236 Base *basen = BKE_view_layer_base_find(view_layer, obn);
3237 base_select(basen, BA_SELECT);
3238 base_select(base, BA_DESELECT);
3239
3240 /* XXX: An ugly hack needed because if we re-run depsgraph with some new meta-ball objects
3241 * having same 'family name' as orig ones, they will affect end result of meta-ball computation.
3242 * For until we get rid of that name-based thingy in meta-balls, that should do the trick
3243 * (this is weak, but other solution (to change name of `obn`) is even worse IMHO).
3244 * See #65996. */
3245 const bool is_meta_ball = (obn->type == OB_MBALL);
3246 ID *obdata = obn->data;
3247 if (is_meta_ball) {
3248 obn->type = OB_EMPTY;
3249 obn->data = nullptr;
3250 }
3251
3252 /* XXX Doing that here is stupid, it means we update and re-evaluate the whole depsgraph every
3253 * time we need to duplicate an object to convert it. Even worse, this is not 100% correct, since
3254 * we do not yet have duplicated obdata.
3255 * However, that is a safe solution for now. Proper, longer-term solution is to refactor
3256 * object_convert_exec to:
3257 * - duplicate all data it needs to in a first loop.
3258 * - do a single update.
3259 * - convert data in a second loop. */
3261 CustomData_MeshMasks customdata_mask_prev = scene->customdata_mask;
3263 BKE_scene_graph_update_tagged(depsgraph, bmain);
3264 scene->customdata_mask = customdata_mask_prev;
3265
3266 if (is_meta_ball) {
3267 obn->type = OB_MBALL;
3268 obn->data = obdata;
3269 }
3270
3271 return basen;
3272}
3273
3289
3291{
3292 if (info.keep_original) {
3293 *r_new_base = duplibase_for_convert(
3294 info.bmain, info.depsgraph, info.scene, info.view_layer, &base, nullptr);
3295 Object *newob = (*r_new_base)->object;
3296
3297 /* Decrement original object data usage count. */
3298 ID *original_object_data = newob->data;
3299 id_us_min(original_object_data);
3300
3301 /* Make a copy of the object data. */
3302 newob->data = BKE_id_copy(info.bmain, original_object_data);
3303
3304 return newob;
3305 }
3306 *r_new_base = nullptr;
3307 return base.object;
3308}
3309
3312 Base **r_new_base)
3313{
3314 Object *ob = base.object;
3315 Object *newob = nullptr;
3316 ob->flag |= OB_DONE;
3317
3318 Object *ob_eval = DEG_get_evaluated(info.depsgraph, ob);
3320 if (ob_eval->runtime->geometry_set_eval != nullptr) {
3321 geometry = *ob_eval->runtime->geometry_set_eval;
3322 }
3323
3324 if (geometry.has_curves()) {
3325 newob = get_object_for_conversion(base, info, r_new_base);
3326
3327 const Curves *curves_eval = geometry.get_curves();
3328 Curves *new_curves = BKE_id_new<Curves>(info.bmain, newob->id.name + 2);
3329
3330 newob->data = id_cast<ID *>(new_curves);
3331 newob->type = OB_CURVES;
3332
3333 new_curves->geometry.wrap() = curves_eval->geometry.wrap();
3334 new_curves->geometry.wrap().attributes_for_write().remove_anonymous();
3335 BKE_object_material_from_eval_data(info.bmain, newob, &curves_eval->id);
3336
3338 BKE_object_free_modifiers(newob, 0);
3339 }
3340 else {
3341 BKE_reportf(info.reports,
3343 "Object '%s' has no evaluated Curve or Grease Pencil data",
3344 ob->id.name + 2);
3345 }
3346
3347 return newob;
3348}
3349
3352 Base **r_new_base)
3353{
3354 Object *ob = base.object;
3355 Object *newob = nullptr;
3356 ob->flag |= OB_DONE;
3357
3358 Object *ob_eval = DEG_get_evaluated(info.depsgraph, ob);
3360 if (ob_eval->runtime->geometry_set_eval != nullptr) {
3361 geometry = *ob_eval->runtime->geometry_set_eval;
3362 }
3363
3364 if (geometry.has_pointcloud()) {
3365 newob = get_object_for_conversion(base, info, r_new_base);
3366
3367 const PointCloud *pointcloud_eval = geometry.get_pointcloud();
3368 PointCloud *new_pointcloud = BKE_id_new<PointCloud>(info.bmain, newob->id.name + 2);
3369
3370 newob->data = id_cast<ID *>(new_pointcloud);
3371 newob->type = OB_POINTCLOUD;
3372
3374 new_pointcloud);
3375
3376 new_pointcloud->attributes_for_write().remove_anonymous();
3377
3379 BKE_object_free_modifiers(newob, 0);
3380 }
3381 else {
3382 BKE_reportf(info.reports,
3384 "Object '%s' has no evaluated Point Cloud data",
3385 ob->id.name + 2);
3386 }
3387
3388 return newob;
3389}
3390
3393 Base **r_new_base)
3394{
3395 Object *ob = base.object;
3396 Object *newob = nullptr;
3397 ob->flag |= OB_DONE;
3398
3399 Object *ob_eval = DEG_get_evaluated(info.depsgraph, ob);
3401 if (ob_eval->runtime->geometry_set_eval != nullptr) {
3402 geometry = *ob_eval->runtime->geometry_set_eval;
3403 }
3404
3405 if (geometry.has_mesh()) {
3406 newob = get_object_for_conversion(base, info, r_new_base);
3407
3408 const Mesh *mesh_eval = geometry.get_mesh();
3409 Mesh *new_mesh = BKE_id_new<Mesh>(info.bmain, newob->id.name + 2);
3410
3411 newob->data = id_cast<ID *>(new_mesh);
3412 newob->type = OB_MESH;
3413
3414 BKE_mesh_nomain_to_mesh(BKE_mesh_copy_for_eval(*mesh_eval), new_mesh, newob);
3415 new_mesh->attributes_for_write().remove_anonymous();
3416
3417 BKE_object_material_from_eval_data(info.bmain, newob, &mesh_eval->id);
3418
3420 BKE_object_free_modifiers(newob, 0);
3421 }
3422 else {
3424 info.reports, RPT_WARNING, "Object '%s' has no evaluated Mesh data", ob->id.name + 2);
3425 }
3426
3427 return newob;
3428}
3429
3432 Base **r_new_base)
3433{
3434 Object *ob = base.object;
3435 Object *newob = nullptr;
3436 ob->flag |= OB_DONE;
3437
3438 Object *ob_eval = DEG_get_evaluated(info.depsgraph, ob);
3440 if (ob_eval->runtime->geometry_set_eval != nullptr) {
3441 geometry = *ob_eval->runtime->geometry_set_eval;
3442 }
3443
3444 if (geometry.has_grease_pencil()) {
3445 newob = get_object_for_conversion(base, info, r_new_base);
3446
3447 const GreasePencil *grease_pencil_eval = geometry.get_grease_pencil();
3448 GreasePencil *new_grease_pencil = BKE_id_new<GreasePencil>(info.bmain, newob->id.name + 2);
3449
3450 newob->data = id_cast<ID *>(new_grease_pencil);
3451 newob->type = OB_GREASE_PENCIL;
3452
3454 new_grease_pencil);
3455
3456 new_grease_pencil->attributes_for_write().remove_anonymous();
3457
3458 BKE_object_material_from_eval_data(info.bmain, newob, &grease_pencil_eval->id);
3459
3461 BKE_object_free_modifiers(newob, 0);
3462 }
3463 else {
3464 BKE_reportf(info.reports,
3466 "Object '%s' has no evaluated Grease Pencil data",
3467 ob->id.name + 2);
3468 }
3469
3470 return newob;
3471}
3472
3474 const ObjectType target,
3476 Base **r_new_base)
3477{
3478 switch (target) {
3479 case OB_CURVES:
3480 return convert_curves_component_to_curves(base, info, r_new_base);
3481 case OB_POINTCLOUD:
3482 return convert_pointcloud_component_to_pointcloud(base, info, r_new_base);
3483 case OB_MESH:
3484 return convert_mesh_component_to_mesh(base, info, r_new_base);
3485 case OB_GREASE_PENCIL:
3486 return convert_grease_pencil_component_to_grease_pencil(base, info, r_new_base);
3487 default:
3488 return nullptr;
3489 }
3490}
3491
3494 Base **r_new_base)
3495{
3496 Object *ob = base.object;
3497 ob->flag |= OB_DONE;
3498 Object *newob = get_object_for_conversion(base, info, r_new_base);
3499
3500 BKE_mesh_to_curve(info.bmain, info.depsgraph, info.scene, newob);
3501
3502 if (newob->type == OB_CURVES_LEGACY) {
3503 BKE_object_free_modifiers(newob, 0); /* after derivedmesh calls! */
3504 if (newob->rigidbody_object != nullptr) {
3505 ED_rigidbody_object_remove(info.bmain, info.scene, newob);
3506 }
3507 }
3508
3509 return newob;
3510}
3511
3514 Base **r_new_base)
3515{
3516 Object *ob = base.object, *newob = nullptr;
3517 ob->flag |= OB_DONE;
3518
3519 Object *ob_eval = DEG_get_evaluated(info.depsgraph, ob);
3521 if (ob_eval->runtime->geometry_set_eval != nullptr) {
3522 geometry = *ob_eval->runtime->geometry_set_eval;
3523 }
3524
3525 if (geometry.has_grease_pencil()) {
3526 newob = get_object_for_conversion(base, info, r_new_base);
3527
3528 Curves *new_curves = BKE_id_new<Curves>(info.bmain, newob->id.name + 2);
3529 newob->data = id_cast<ID *>(new_curves);
3530 newob->type = OB_CURVES;
3531
3532 if (const Curves *curves_eval = geometry.get_curves()) {
3533 new_curves->geometry.wrap() = curves_eval->geometry.wrap();
3534 BKE_object_material_from_eval_data(info.bmain, newob, &curves_eval->id);
3535 }
3536 else if (const GreasePencil *grease_pencil = geometry.get_grease_pencil()) {
3539 if (drawings.size() > 0) {
3540 Array<bke::GeometrySet> geometries(drawings.size());
3541 for (const int i : drawings.index_range()) {
3542 Curves *curves_id = BKE_id_new_nomain<Curves>(nullptr);
3543 curves_id->geometry.wrap() = drawings[i].drawing.strokes();
3544 geometries[i] = bke::GeometrySet::from_curves(curves_id);
3545 }
3546 bke::GeometrySet joined_curves = geometry::join_geometries(geometries, {});
3547
3548 new_curves->geometry.wrap() = joined_curves.get_curves()->geometry.wrap();
3549 new_curves->geometry.wrap().tag_topology_changed();
3550 BKE_object_material_from_eval_data(info.bmain, newob, &joined_curves.get_curves()->id);
3551 }
3552 }
3553
3555 BKE_object_free_modifiers(newob, 0);
3556 }
3557 else {
3558 BKE_reportf(info.reports,
3560 "Object '%s' has no evaluated Curve or Grease Pencil data",
3561 ob->id.name + 2);
3562 }
3563
3564 return newob;
3565}
3566
3568{
3569 Object *newob = convert_curves_component_to_curves(base, info, r_new_base);
3570 if (newob) {
3571 return newob;
3572 }
3573 return convert_grease_pencil_component_to_curves(base, info, r_new_base);
3574}
3575
3578 Base **r_new_base)
3579{
3580 Object *ob = base.object;
3581 ob->flag |= OB_DONE;
3582 Object *newob = get_object_for_conversion(base, info, r_new_base);
3583
3584 BKE_mesh_to_pointcloud(info.bmain, info.depsgraph, info.scene, newob);
3585
3586 if (newob->type == OB_POINTCLOUD) {
3587 BKE_object_free_modifiers(newob, 0); /* after derivedmesh calls! */
3588 ED_rigidbody_object_remove(info.bmain, info.scene, newob);
3589 }
3590
3591 return newob;
3592}
3593
3594static Object *convert_mesh_to_mesh(Base &base, ObjectConversionInfo &info, Base **r_new_base)
3595{
3596 Object *ob = base.object;
3597 ob->flag |= OB_DONE;
3598 Object *newob = get_object_for_conversion(base, info, r_new_base);
3599
3600 /* make new mesh data from the original copy */
3601 /* NOTE: get the mesh from the original, not from the copy in some
3602 * cases this doesn't give correct results (when MDEF is used for eg)
3603 */
3604 const Object *ob_eval = DEG_get_evaluated(info.depsgraph, ob);
3605 const Mesh *mesh_eval = BKE_object_get_evaluated_mesh(ob_eval);
3606 Mesh *new_mesh = mesh_eval ? BKE_mesh_copy_for_eval(*mesh_eval) :
3607 BKE_mesh_new_nomain(0, 0, 0, 0);
3609
3610 BKE_object_material_from_eval_data(info.bmain, newob, &new_mesh->id);
3611 /* Anonymous attributes shouldn't be available on the applied geometry. */
3612 new_mesh->attributes_for_write().remove_anonymous();
3613 if (info.do_merge_customdata) {
3615 }
3616
3617 Mesh *ob_data_mesh = id_cast<Mesh *>(newob->data);
3618
3619 if (ob_data_mesh->key) {
3620 /* NOTE(@ideasman42): Clearing the shape-key is needed when the
3621 * number of vertices remains unchanged. Otherwise using this operator
3622 * to "Apply Visual Geometry" will evaluate using the existing shape-key
3623 * which doesn't have the "evaluated" coordinates from `new_mesh`.
3624 * See #128839 for details.
3625 *
3626 * While shape-keys could be supported, this is more of a feature to consider.
3627 * As there is already a `MESH_OT_blend_from_shape` operator,
3628 * it's not clear this is especially useful or needed. */
3629 if (!CustomData_has_layer(&new_mesh->vert_data, CD_SHAPEKEY)) {
3630 id_us_min(&ob_data_mesh->key->id);
3631 ob_data_mesh->key = nullptr;
3632 }
3633 }
3634 BKE_mesh_nomain_to_mesh(new_mesh, ob_data_mesh, newob);
3635
3636 bke::mesh_ensure_active_uv_map(*ob_data_mesh);
3637
3638 BKE_object_free_modifiers(newob, 0); /* after derivedmesh calls! */
3639
3640 if (!info.keep_original) {
3642 }
3643
3644 return newob;
3645}
3646
3648 Object &ob_grease_pencil,
3649 const StringRefNull name,
3650 const std::optional<float4> &stroke_color,
3651 const std::optional<float4> &fill_color)
3652{
3653 int index;
3655 &bmain, &ob_grease_pencil, DATA_(name.c_str()), &index);
3656
3657 if (stroke_color.has_value()) {
3658 copy_v4_v4(ma->gp_style->stroke_rgba, stroke_color.value());
3659 }
3660 else {
3661 copy_v4_v4(ma->gp_style->stroke_rgba, float4(0.0f));
3662 }
3663
3664 if (fill_color.has_value()) {
3665 copy_v4_v4(ma->gp_style->fill_rgba, fill_color.value());
3666 }
3667 else {
3668 copy_v4_v4(ma->gp_style->fill_rgba, float4(0.0f));
3669 }
3670
3671 return index;
3672}
3673
3675 public:
3678 bool operator==(const FillColorRecord &other) const
3679 {
3680 return other.color == color && other.name == name;
3681 }
3683 {
3684 return hash_string(name);
3685 }
3686};
3687
3689 Object &ob_mesh, const Mesh &mesh, Array<int> &material_remap)
3690{
3691 const short num_materials = mesh.totcol;
3692 const FillColorRecord empty_fill = {float4(1.0f), DATA_("Empty Fill")};
3693
3694 /* This function will only be called when we want to create fills out of mesh faces, so always
3695 * ensure that fills would have at least one material to be assigned to. */
3696 if (num_materials == 0) {
3697 VectorSet<FillColorRecord> fill_colors;
3698 fill_colors.add(empty_fill);
3699 material_remap.reinitialize(1);
3700 material_remap[0] = 0;
3701 return fill_colors;
3702 }
3703
3704 VectorSet<FillColorRecord> fill_colors;
3705
3706 material_remap.reinitialize(num_materials);
3707
3708 for (const int material_i : IndexRange(num_materials)) {
3709 const Material *mesh_material = BKE_object_material_get(&ob_mesh, material_i + 1);
3710 if (!mesh_material) {
3711 material_remap[material_i] = fill_colors.index_of_or_add(empty_fill);
3712 continue;
3713 }
3714 const float4 fill_color = float4(
3715 mesh_material->r, mesh_material->g, mesh_material->b, mesh_material->a);
3716 const StringRefNull material_name = BKE_id_name(mesh_material->id);
3717 const FillColorRecord record = {fill_color, material_name};
3718 material_remap[material_i] = fill_colors.index_of_or_add(record);
3719 }
3720
3721 return fill_colors;
3722}
3723static void mesh_data_to_grease_pencil(const Mesh &mesh_eval,
3725 const int current_frame,
3726 const bool generate_faces,
3727 const float stroke_radius,
3728 const float offset,
3729 const Array<int> &material_remap)
3730{
3731 using namespace bke::greasepencil;
3732
3733 if (mesh_eval.edges_num <= 0) {
3734 return;
3735 }
3736
3737 Layer &layer_line = grease_pencil.add_layer(DATA_("Lines"));
3738 Drawing *drawing_line = grease_pencil.insert_frame(layer_line, current_frame);
3739
3740 const Span<float3> mesh_positions = mesh_eval.vert_positions();
3741 const OffsetIndices<int> faces = mesh_eval.faces();
3742 Span<int> faces_span = faces.data();
3743 const Span<int> corner_verts = mesh_eval.corner_verts();
3744
3745 if (generate_faces && !faces.is_empty()) {
3746 Layer &layer_fill = grease_pencil.add_layer(DATA_("Fills"));
3747 Drawing *drawing_fill = grease_pencil.insert_frame(layer_fill, current_frame);
3748 const int fills_num = faces.size();
3749 const int fills_points_num = corner_verts.size();
3750
3751 drawing_fill->strokes_for_write().resize(fills_points_num, fills_num);
3752 bke::CurvesGeometry &curves = drawing_fill->strokes_for_write();
3753 bke::MutableAttributeAccessor attributes = curves.attributes_for_write();
3754 MutableSpan<float3> positions = curves.positions_for_write();
3755 MutableSpan<int> offsets = curves.offsets_for_write();
3756
3757 curves.fill_curve_types(CURVE_TYPE_POLY);
3758 array_utils::gather(mesh_positions, corner_verts, positions);
3759 array_utils::copy(faces_span, offsets);
3760 attributes.add<bool>("cyclic", bke::AttrDomain::Curve, bke::AttributeInitValue(true));
3761
3762 const bke::AttributeAccessor mesh_attributes = mesh_eval.attributes();
3763 VArray<int> mesh_materials = *mesh_attributes.lookup_or_default(
3764 "material_index", bke::AttrDomain::Face, 0);
3765 bke::SpanAttributeWriter<int> material_indices =
3766 attributes.lookup_or_add_for_write_only_span<int>("material_index",
3768 threading::parallel_for(curves.curves_range(), 2048, [&](const IndexRange range) {
3769 for (const int i : range) {
3770 /* Increase material index by 1 to accommodate the stroke material. */
3771 material_indices.span[i] = material_remap[mesh_materials[i]] + 1;
3772 }
3773 });
3774 material_indices.finish();
3775
3776 bke::SpanAttributeWriter<int> fill_ids = attributes.lookup_or_add_for_write_only_span<int>(
3777 "fill_id", bke::AttrDomain::Curve);
3778 threading::parallel_for(curves.curves_range(), 2048, [&](const IndexRange range) {
3779 for (const int i : range) {
3780 const int fill_id = i + 1;
3781 fill_ids.span[i] = fill_id;
3782 }
3783 });
3784 fill_ids.finish();
3785
3786 bke::SpanAttributeWriter<bool> hide_stroke = attributes.lookup_or_add_for_write_span<bool>(
3787 "hide_stroke", bke::AttrDomain::Curve, bke::AttributeInitValue(true));
3788 hide_stroke.finish();
3789
3790 bke::gather_attributes(mesh_attributes,
3794 corner_verts,
3795 attributes);
3796 }
3797
3798 Mesh *mesh_copied = BKE_mesh_copy_for_eval(mesh_eval);
3799 const Span<float3> normals = mesh_copied->vert_normals();
3800
3801 std::string normals_attribute_name = BKE_attribute_calc_unique_name(
3802 AttributeOwner::from_id(&mesh_copied->id), "vertex_normal_for_conversion");
3803
3804 mesh_copied->attributes_for_write().add(
3805 normals_attribute_name,
3808 bke::AttributeInitVArray(VArray<float3>::from_span(normals)));
3809
3810 const int edges_num = mesh_copied->edges_num;
3811 bke::CurvesGeometry curves_edges = geometry::mesh_edges_to_curves_convert(
3812 *mesh_copied, IndexRange(edges_num), bke::attribute_filter_from_skip_ref({"radius"}));
3813
3814 MutableSpan<float3> curve_positions = curves_edges.positions_for_write();
3815 const VArraySpan<float3> point_normals = *curves_edges.attributes().lookup<float3>(
3816 normals_attribute_name);
3817 threading::parallel_for(curve_positions.index_range(), 8192, [&](const IndexRange range) {
3818 for (const int point_i : range) {
3819 curve_positions[point_i] += offset * point_normals[point_i];
3820 }
3821 });
3822 curves_edges.attributes_for_write().remove(normals_attribute_name);
3823
3824 BKE_defgroup_copy_list(&grease_pencil.vertex_group_names, &mesh_copied->vertex_group_names);
3825 grease_pencil.vertex_group_active_index = mesh_copied->vertex_group_active_index;
3826
3828
3829 bke::MutableAttributeAccessor attributes = curves_edges.attributes_for_write();
3830 attributes.add<float>("radius", bke::AttrDomain::Point, bke::AttributeInitValue(stroke_radius));
3831
3832 drawing_line->strokes_for_write() = std::move(curves_edges);
3833 drawing_line->tag_topology_changed();
3834
3835 BKE_id_free(nullptr, mesh_copied);
3836}
3837
3840 Base **r_new_base)
3841{
3842 Object *ob = base.object;
3843 ob->flag |= OB_DONE;
3844 Object *newob = get_object_for_conversion(base, info, r_new_base);
3845
3846 const bool generate_faces = RNA_boolean_get(info.op_props, "faces");
3847 const int thickness = RNA_int_get(info.op_props, "thickness");
3848 const float offset = RNA_float_get(info.op_props, "offset");
3849
3850 /* To be compatible with the thickness value of legacy Grease Pencil. */
3851 const float stroke_radius = float(thickness) / 2 *
3853
3854 Object *ob_eval = DEG_get_evaluated(info.depsgraph, ob);
3855 Mesh *mesh_eval = BKE_object_get_evaluated_mesh(ob_eval);
3857
3858 VectorSet<FillColorRecord> fill_colors;
3859 Array<int> material_remap;
3860 if (generate_faces) {
3861 fill_colors = mesh_to_grease_pencil_get_material_list(*ob_eval, *mesh_eval, material_remap);
3862 }
3863
3865 BKE_object_free_modifiers(newob, 0);
3866
3868 newob->data = id_cast<ID *>(grease_pencil);
3869 newob->type = OB_GREASE_PENCIL;
3870
3871 /* Reset object material array and count since currently the generic / grease pencil material
3872 * functions still depend on this value being coherent (The same value as
3873 * `GreasePencil::material_array_num`).
3874 */
3875 BKE_object_material_resize(info.bmain, newob, 0, true);
3876
3878 *info.bmain, *newob, DATA_("Stroke"), float4(0.0f, 0.0f, 0.0f, 1.0f), {});
3879
3880 if (generate_faces) {
3881 for (const int fill_i : fill_colors.index_range()) {
3882 const FillColorRecord &record = fill_colors[fill_i];
3883 mesh_to_grease_pencil_add_material(*info.bmain, *newob, record.name, {}, record.color);
3884 }
3885 }
3886
3887 mesh_data_to_grease_pencil(*mesh_eval,
3889 info.scene->r.cfra,
3890 generate_faces,
3891 stroke_radius,
3892 offset,
3893 material_remap);
3894
3895 return newob;
3896}
3897
3899 const ObjectType target,
3901 Base **r_new_base)
3902{
3903 switch (target) {
3904 case OB_CURVES_LEGACY:
3905 return convert_mesh_to_curves_legacy(base, info, r_new_base);
3906 case OB_CURVES:
3907 return convert_mesh_to_curves(base, info, r_new_base);
3908 case OB_POINTCLOUD:
3909 return convert_mesh_to_pointcloud(base, info, r_new_base);
3910 case OB_MESH:
3911 return convert_mesh_to_mesh(base, info, r_new_base);
3912 case OB_GREASE_PENCIL:
3913 return convert_mesh_to_grease_pencil(base, info, r_new_base);
3914 default:
3915 /* Current logic does convert mesh to mesh for any other target types. This would change
3916 * after other types of conversion are designed and implemented. */
3917 return convert_mesh_to_mesh(base, info, r_new_base);
3918 }
3919}
3920
3922{
3923 Object *ob = base.object, *newob = nullptr;
3924 ob->flag |= OB_DONE;
3925
3926 Object *ob_eval = DEG_get_evaluated(info.depsgraph, ob);
3928 if (ob_eval->runtime->geometry_set_eval != nullptr) {
3929 geometry = *ob_eval->runtime->geometry_set_eval;
3930 }
3931
3932 const Mesh *mesh_eval = geometry.get_mesh();
3933 const Curves *curves_eval = geometry.get_curves();
3934 Mesh *new_mesh = nullptr;
3935
3936 if (mesh_eval || curves_eval) {
3937 newob = get_object_for_conversion(base, info, r_new_base);
3938 new_mesh = BKE_id_new<Mesh>(info.bmain, newob->id.name + 2);
3939 newob->data = id_cast<ID *>(new_mesh);
3940 newob->type = OB_MESH;
3941 }
3942 else {
3943 BKE_reportf(info.reports,
3945 "Object '%s' has no evaluated mesh or curves data",
3946 ob->id.name + 2);
3947 return nullptr;
3948 }
3949
3950 if (mesh_eval) {
3951 BKE_mesh_nomain_to_mesh(BKE_mesh_copy_for_eval(*mesh_eval), new_mesh, newob);
3952 BKE_object_material_from_eval_data(info.bmain, newob, &mesh_eval->id);
3953 new_mesh->attributes_for_write().remove_anonymous();
3954 }
3955 else if (curves_eval) {
3956 Mesh *mesh = bke::curve_to_wire_mesh(curves_eval->geometry.wrap(),
3958 if (!mesh) {
3959 mesh = BKE_mesh_new_nomain(0, 0, 0, 0);
3960 }
3961 BKE_mesh_nomain_to_mesh(mesh, new_mesh, newob);
3962 BKE_object_material_from_eval_data(info.bmain, newob, &curves_eval->id);
3963 }
3964
3966 BKE_object_free_modifiers(newob, 0);
3967
3969
3970 return newob;
3971}
3972
3975 Base **r_new_base)
3976{
3977 Object *ob = base.object, *newob = nullptr;
3978 ob->flag |= OB_DONE;
3979
3980 Object *ob_eval = DEG_get_evaluated(info.depsgraph, ob);
3982 if (ob_eval->runtime->geometry_set_eval != nullptr) {
3983 geometry = *ob_eval->runtime->geometry_set_eval;
3984 }
3985
3986 const GreasePencil *grease_pencil_eval = geometry.get_grease_pencil();
3987 const Curves *curves_eval = geometry.get_curves();
3988 GreasePencil *new_grease_pencil = nullptr;
3989
3990 if (grease_pencil_eval || curves_eval) {
3991 newob = get_object_for_conversion(base, info, r_new_base);
3992 new_grease_pencil = BKE_id_new<GreasePencil>(info.bmain, newob->id.name + 2);
3993 newob->data = id_cast<ID *>(new_grease_pencil);
3994 newob->type = OB_GREASE_PENCIL;
3995 }
3996 else {
3997 BKE_reportf(info.reports,
3999 "Object '%s' has no evaluated Grease Pencil or Curves data",
4000 ob->id.name + 2);
4001 return nullptr;
4002 }
4003
4004 if (grease_pencil_eval) {
4006 new_grease_pencil);
4007 BKE_object_material_from_eval_data(info.bmain, newob, &grease_pencil_eval->id);
4008 new_grease_pencil->attributes_for_write().remove_anonymous();
4009 }
4010 else if (curves_eval) {
4012 /* Insert a default layer and place the drawing on frame 1. */
4013 const std::string layer_name = "Layer";
4014 const int frame_number = 1;
4015 bke::greasepencil::Layer &layer = grease_pencil->add_layer(layer_name);
4016 bke::greasepencil::Drawing *drawing = grease_pencil->insert_frame(layer, frame_number);
4017 BLI_assert(drawing != nullptr);
4018 drawing->strokes_for_write() = curves_eval->geometry.wrap();
4019 /* Default radius (1.0 unit) is too thick for converted strokes. */
4021 attributes.remove("radius");
4022 attributes.add<float>("radius", bke::AttrDomain::Point, bke::AttributeInitValue(0.01f));
4023
4025 BKE_object_material_from_eval_data(info.bmain, newob, &curves_eval->id);
4026 }
4027
4029 BKE_object_free_modifiers(newob, 0);
4030
4031 return newob;
4032}
4033
4035 const ObjectType target,
4037 Base **r_new_base)
4038{
4039 switch (target) {
4040 case OB_MESH:
4041 return convert_curves_to_mesh(base, info, r_new_base);
4042 case OB_GREASE_PENCIL:
4043 return convert_curves_to_grease_pencil(base, info, r_new_base);
4044 default:
4045 return convert_curves_component_to_curves(base, info, r_new_base);
4046 }
4047}
4048
4051 Base **r_new_base)
4052{
4053 Object *ob = base.object, *newob = nullptr;
4054 ob->flag |= OB_DONE;
4055
4056 /* Mostly same as converting to OB_CURVES, the mesh will be converted from Curves afterwards. */
4057
4058 Object *ob_eval = DEG_get_evaluated(info.depsgraph, ob);
4060 if (ob_eval->runtime->geometry_set_eval != nullptr) {
4061 geometry = *ob_eval->runtime->geometry_set_eval;
4062 }
4063
4064 if (geometry.has_curves()) {
4065 newob = get_object_for_conversion(base, info, r_new_base);
4066
4067 const Curves *curves_eval = geometry.get_curves();
4068 Curves *new_curves = BKE_id_new<Curves>(info.bmain, newob->id.name + 2);
4069
4070 newob->data = id_cast<ID *>(new_curves);
4071 newob->type = OB_CURVES;
4072
4073 new_curves->geometry.wrap() = curves_eval->geometry.wrap();
4074 BKE_object_material_from_eval_data(info.bmain, newob, &curves_eval->id);
4075
4077 BKE_object_free_modifiers(newob, 0);
4078 }
4079 else if (geometry.has_grease_pencil()) {
4080 newob = get_object_for_conversion(base, info, r_new_base);
4081
4082 /* Do not link `new_curves` to `bmain` since it's temporary. */
4083 Curves *new_curves = BKE_id_new_nomain<Curves>(newob->id.name + 2);
4084
4085 newob->data = id_cast<ID *>(new_curves);
4086 newob->type = OB_CURVES;
4087
4088 if (const Curves *curves_eval = geometry.get_curves()) {
4089 new_curves->geometry.wrap() = curves_eval->geometry.wrap();
4090 BKE_object_material_from_eval_data(info.bmain, newob, &curves_eval->id);
4091 }
4092 else if (const GreasePencil *grease_pencil = geometry.get_grease_pencil()) {
4095 Array<bke::GeometrySet> geometries(drawings.size());
4096 for (const int i : drawings.index_range()) {
4097 Curves *curves_id = BKE_id_new_nomain<Curves>(nullptr);
4098 curves_id->geometry.wrap() = drawings[i].drawing.strokes();
4099 const int layer_index = drawings[i].layer_index;
4100 const bke::greasepencil::Layer *layer = grease_pencil->layers()[layer_index];
4101 float4x4 to_object = layer->to_object_space(*ob);
4102 bke::CurvesGeometry &new_curves = curves_id->geometry.wrap();
4103 math::transform_points(to_object, new_curves.positions_for_write());
4104 geometries[i] = bke::GeometrySet::from_curves(curves_id);
4105 }
4106 if (geometries.size() > 0) {
4107 bke::GeometrySet joined_curves = geometry::join_geometries(geometries, {});
4108 if (const Curves *joined_curves_data = joined_curves.get_curves()) {
4109 new_curves->geometry.wrap() = joined_curves_data->geometry.wrap();
4110 new_curves->geometry.wrap().tag_topology_changed();
4111 BKE_object_material_from_eval_data(info.bmain, newob, &joined_curves_data->id);
4112 }
4113 }
4114 }
4115
4116 Mesh *new_mesh = BKE_id_new<Mesh>(info.bmain, newob->id.name + 2);
4117 newob->data = id_cast<ID *>(new_mesh);
4118 newob->type = OB_MESH;
4119
4120 Mesh *mesh = bke::curve_to_wire_mesh(new_curves->geometry.wrap(), {});
4121 if (!mesh) {
4122 mesh = BKE_mesh_new_nomain(0, 0, 0, 0);
4123 }
4124 BKE_mesh_nomain_to_mesh(mesh, new_mesh, newob);
4125 BKE_object_material_from_eval_data(info.bmain, newob, &new_curves->id);
4126
4127 /* Free `new_curves` because it is just an intermediate. */
4128 BKE_id_free(nullptr, new_curves);
4129
4131 BKE_object_free_modifiers(newob, 0);
4132
4134 }
4135 else {
4137 info.reports, RPT_WARNING, "Object '%s' has no evaluated curves data", ob->id.name + 2);
4138 }
4139
4140 return newob;
4141}
4142
4144 const ObjectType target,
4146 Base **r_new_base)
4147{
4148 switch (target) {
4149 case OB_CURVES:
4150 return convert_grease_pencil_component_to_curves(base, info, r_new_base);
4151 case OB_MESH:
4152 return convert_grease_pencil_to_mesh(base, info, r_new_base);
4153 default:
4154 return nullptr;
4155 }
4156 return nullptr;
4157}
4158
4160 Object *newob,
4162{
4163 Curve *cu = id_cast<Curve *>(newob->data);
4164
4165 Object *ob_eval = DEG_get_evaluated(info.depsgraph, ob);
4166 BKE_vfont_to_curve_ex(ob_eval,
4167 *id_cast<const Curve *>(ob_eval->data),
4168 FO_EDIT,
4169 &cu->nurb,
4170 nullptr,
4171 nullptr,
4172 nullptr,
4173 nullptr,
4174 nullptr);
4175
4176 newob->type = OB_CURVES_LEGACY;
4178
4179#define CURVE_VFONT_CLEAR(vfont_member) \
4180 if (cu->vfont_member) { \
4181 id_us_min(&cu->vfont_member->id); \
4182 cu->vfont_member = nullptr; \
4183 } \
4184 ((void)0)
4185
4186 CURVE_VFONT_CLEAR(vfont);
4187 CURVE_VFONT_CLEAR(vfontb);
4188 CURVE_VFONT_CLEAR(vfonti);
4189 CURVE_VFONT_CLEAR(vfontbi);
4190
4191#undef CURVE_VFONT_CLEAR
4192
4193 if (!info.keep_original) {
4194 /* other users */
4195 Object *ob1 = nullptr;
4196 if (ID_REAL_USERS(&cu->id) > 1) {
4197 for (ob1 = info.bmain->objects.first(); ob1; ob1 = static_cast<Object *>(ob1->id.next)) {
4198 if (ob1->data == ob->data && ob1 != ob) {
4199 ob1->type = OB_CURVES_LEGACY;
4200 DEG_id_tag_update(&ob1->id,
4202 }
4203 }
4204 }
4205 }
4206
4207 for (Nurb &nu : cu->nurb) {
4208 nu.charidx = 0;
4209 }
4210
4211 cu->flag &= ~CU_3D;
4213
4214 return newob;
4215}
4216
4219 Base **r_new_base)
4220{
4221 Object *ob = base.object;
4222 ob->flag |= OB_DONE;
4223 Object *newob = get_object_for_conversion(base, info, r_new_base);
4224
4225 return convert_font_to_curve_legacy_generic(ob, newob, info);
4226}
4227
4229{
4230 Object *ob = base.object;
4231 ob->flag |= OB_DONE;
4232 Object *newob = get_object_for_conversion(base, info, r_new_base);
4233 Object *curve_ob = convert_font_to_curve_legacy_generic(ob, newob, info);
4234 BLI_assert(curve_ob->type == OB_CURVES_LEGACY);
4235
4236 Curve *legacy_curve_id = id_cast<Curve *>(curve_ob->data);
4237 Curves *curves_nomain = bke::curve_legacy_to_curves(*legacy_curve_id);
4238
4239 Curves *curves_id = BKE_curves_add(info.bmain, BKE_id_name(legacy_curve_id->id));
4240
4241 if (curves_nomain) {
4242 curves_id->geometry.wrap() = curves_nomain->geometry.wrap();
4243 bke::curves_copy_parameters(*curves_nomain, *curves_id);
4244
4245 BKE_id_free(nullptr, curves_nomain);
4246 }
4247
4248 curve_ob->data = id_cast<ID *>(curves_id);
4249 curve_ob->type = OB_CURVES;
4250
4251 return curve_ob;
4252}
4253
4254static void add_grease_pencil_materials_for_conversion(Main &bmain, ID &from_id, Object &gp_object)
4255{
4256 short *len_p = BKE_id_material_len_p(&from_id);
4257 if (!len_p || *len_p == 0) {
4259 &bmain, &gp_object, IFACE_("Empty Material"), nullptr);
4260 gp_material->gp_style->fill_rgba[3] = 1.0f;
4261 return;
4262 }
4263 Material ***materials = BKE_id_material_array_p(&from_id);
4264 if (!materials || !(*materials)) {
4266 &bmain, &gp_object, IFACE_("Empty Material"), nullptr);
4267 gp_material->gp_style->fill_rgba[3] = 1.0f;
4268 return;
4269 }
4270 for (short i = 0; i < *len_p; i++) {
4271 const Material *orig_material = (*materials)[i];
4272 const char *name = orig_material ? BKE_id_name(orig_material->id) : IFACE_("Empty Material");
4273
4275 &bmain, &gp_object, name, nullptr);
4276
4277 /* If the original object has this material slot but didn't assign any material, then we don't
4278 * have anything to copy color information from. In those cases we still added an empty
4279 * material to keep the material index matching. */
4280 if (!orig_material) {
4281 gp_material->gp_style->fill_rgba[3] = 1.0f;
4282 continue;
4283 }
4284
4285 copy_v4_v4(gp_material->gp_style->stroke_rgba, &orig_material->r);
4286 copy_v4_v4(gp_material->gp_style->fill_rgba, &orig_material->r);
4287 }
4288}
4289
4291{
4293 bke::MutableAttributeAccessor attributes = curves.attributes_for_write();
4294
4295 VArray<int> materials = *attributes.lookup_or_default(
4296 "material_index", bke::AttrDomain::Curve, 0);
4298 "fill_id", bke::AttrDomain::Curve);
4299 /* Hide all the strokes, only show fills. */
4300 attributes.add<bool>("hide_stroke", bke::AttrDomain::Curve, bke::AttributeInitValue(true));
4301
4302 /* Mark all the strokes in the same material as the same fill. */
4303 for (const int curve_i : curves.curves_range()) {
4304 fill_ids.span[curve_i] = materials[curve_i] + 1;
4305 }
4306
4307 fill_ids.finish();
4308}
4309
4312 Base **r_new_base)
4313{
4314 Object *ob = base.object;
4315 ob->flag |= OB_DONE;
4316 Object *newob = get_object_for_conversion(base, info, r_new_base);
4317 Object *curve_ob = convert_font_to_curve_legacy_generic(ob, newob, info);
4318 BLI_assert(curve_ob->type == OB_CURVES_LEGACY);
4319
4320 Curve *legacy_curve_id = id_cast<Curve *>(curve_ob->data);
4321 Curves *curves_nomain = bke::curve_legacy_to_curves(*legacy_curve_id);
4322
4324 BKE_id_name(legacy_curve_id->id));
4325 bke::greasepencil::Layer &layer = grease_pencil->add_layer(DATA_("Converted Layer"));
4326
4327 const int current_frame = info.scene->r.cfra;
4328
4329 bke::greasepencil::Drawing *drawing = grease_pencil->insert_frame(layer, current_frame);
4330
4331 if (curves_nomain) {
4332 bke::CurvesGeometry &curves = curves_nomain->geometry.wrap();
4333
4334 drawing->strokes_for_write() = std::move(curves);
4335 /* Default radius (1.0 unit) is too thick for converted strokes. */
4337 attributes.remove("radius");
4338 attributes.add<float>("radius", bke::AttrDomain::Point, bke::AttributeInitValue(0.01f));
4339
4340 const bool use_fill = (legacy_curve_id->flag & (CU_FRONT | CU_BACK)) != 0;
4341 if (use_fill) {
4343 }
4344
4345 BKE_id_free(nullptr, curves_nomain);
4346 }
4347
4348 curve_ob->data = id_cast<ID *>(grease_pencil);
4349 curve_ob->type = OB_GREASE_PENCIL;
4350 curve_ob->totcol = grease_pencil->material_array_num;
4351
4352 add_grease_pencil_materials_for_conversion(*info.bmain, legacy_curve_id->id, *newob);
4353
4354 /* We don't need the intermediate font/curve data ID any more. */
4355 BKE_id_delete(info.bmain, legacy_curve_id);
4356
4357 /* For some reason this must be called, otherwise evaluated id_cow will still be the original
4358 * curves id (and that seems to only happen if "Keep Original" is enabled, and only with this
4359 * specific conversion combination), not sure why. Ref: #138793 / #146252 */
4361
4362 return curve_ob;
4363}
4364
4365static Object *convert_font_to_mesh(Base &base, ObjectConversionInfo &info, Base **r_new_base)
4366{
4367 Object *newob = convert_font_to_curves_legacy(base, info, r_new_base);
4368
4369 /* No assumption should be made that the resulting objects is a mesh, as conversion can
4370 * fail. */
4372
4373 /* Meshes doesn't use the "curve cache". */
4375
4376 return newob;
4377}
4378
4380 const short target,
4382 Base **r_new_base)
4383{
4384 switch (target) {
4385 case OB_MESH:
4386 return convert_font_to_mesh(base, info, r_new_base);
4387 case OB_CURVES_LEGACY:
4388 return convert_font_to_curves_legacy(base, info, r_new_base);
4389 case OB_CURVES:
4390 return convert_font_to_curves(base, info, r_new_base);
4391 case OB_GREASE_PENCIL:
4392 return convert_font_to_grease_pencil(base, info, r_new_base);
4393 default:
4394 return nullptr;
4395 }
4396 return nullptr;
4397}
4398
4401 Base **r_new_base)
4402{
4403 Object *ob = base.object;
4404 ob->flag |= OB_DONE;
4405 Object *newob = get_object_for_conversion(base, info, r_new_base);
4406
4407 /* No assumption should be made that the resulting objects is a mesh, as conversion can
4408 * fail. */
4410
4411 /* Meshes doesn't use the "curve cache". */
4413
4414 return newob;
4415}
4416
4419 Base **r_new_base)
4420{
4421 Object *newob = convert_curves_component_to_curves(base, info, r_new_base);
4422 if (newob) {
4423 return newob;
4424 }
4425 return convert_grease_pencil_component_to_curves(base, info, r_new_base);
4426}
4427
4430 Base **r_new_base)
4431{
4432 Object *ob = base.object;
4433 ob->flag |= OB_DONE;
4434 Object *newob = get_object_for_conversion(base, info, r_new_base);
4436
4437 Curve *legacy_curve_id = id_cast<Curve *>(newob->data);
4438 Curves *curves_nomain = bke::curve_legacy_to_curves(*legacy_curve_id);
4439
4441 BKE_id_name(legacy_curve_id->id));
4442 bke::greasepencil::Layer &layer = grease_pencil->add_layer(DATA_("Converted Layer"));
4443
4444 const int current_frame = info.scene->r.cfra;
4445
4446 bke::greasepencil::Drawing *drawing = grease_pencil->insert_frame(layer, current_frame);
4447
4448 /* An empty curve (no splines) converts to a #Curves of nullptr, leave the drawing empty. */
4449 if (curves_nomain) {
4450 bke::CurvesGeometry &curves = curves_nomain->geometry.wrap();
4451
4452 drawing->strokes_for_write() = std::move(curves);
4453 /* Default radius (1.0 unit) is too thick for converted strokes. */
4455 attributes.remove("radius");
4456 attributes.add<float>("radius", bke::AttrDomain::Point, bke::AttributeInitValue(0.01f));
4457 drawing->tag_positions_changed();
4458
4459 const bool use_fill = (legacy_curve_id->flag & (CU_FRONT | CU_BACK)) != 0;
4460 if (use_fill) {
4462 }
4463 }
4464
4465 newob->data = id_cast<ID *>(grease_pencil);
4466 newob->type = OB_GREASE_PENCIL;
4467
4468 /* Some functions like #BKE_id_material_len_p still uses Object::totcol so this value must be in
4469 * sync. */
4470 newob->totcol = grease_pencil->material_array_num;
4471
4472 add_grease_pencil_materials_for_conversion(*info.bmain, legacy_curve_id->id, *newob);
4473
4474 /* For some reason this must be called, otherwise evaluated id_cow will still be the original
4475 * curves id (and that seems to only happen if "Keep Original" is enabled, and only with this
4476 * specific conversion combination), not sure why. Ref: #138793 / #146252 */
4478
4479 if (curves_nomain) {
4480 BKE_id_free(nullptr, curves_nomain);
4481 }
4482
4483 return newob;
4484}
4485
4487 const ObjectType target,
4489 Base **r_new_base)
4490{
4491 switch (target) {
4492 case OB_MESH:
4493 return convert_curves_legacy_to_mesh(base, info, r_new_base);
4494 case OB_CURVES:
4495 return convert_curves_legacy_to_curves(base, info, r_new_base);
4496 case OB_GREASE_PENCIL:
4497 return convert_curves_legacy_to_grease_pencil(base, info, r_new_base);
4498 default:
4499 return nullptr;
4500 }
4501}
4502
4505 bool &r_mball_converted,
4506 Base **r_new_base,
4507 Base **r_act_base)
4508{
4509 Object *ob = base.object;
4510 Object *newob = nullptr;
4511 Object *baseob = nullptr;
4512
4513 base.flag &= ~BASE_SELECTED;
4515
4516 baseob = BKE_mball_basis_find(*info.bmain, info.scene, ob);
4517
4518 if (ob != baseob) {
4519 /* If mother-ball is converting it would be marked as done later. */
4520 ob->flag |= OB_DONE;
4521 }
4522
4523 if (!(baseob->flag & OB_DONE)) {
4524 *r_new_base = duplibase_for_convert(
4525 info.bmain, info.depsgraph, info.scene, info.view_layer, &base, baseob);
4526 newob = (*r_new_base)->object;
4527
4528 MetaBall *mb = id_cast<MetaBall *>(newob->data);
4529 id_us_min(&mb->id);
4530
4531 /* Find the evaluated mesh of the basis metaball object. */
4532 Object *object_eval = DEG_get_evaluated(info.depsgraph, baseob);
4533 Mesh *mesh = BKE_mesh_new_from_object_to_bmain(info.bmain, info.depsgraph, object_eval, true);
4534
4535 id_us_plus(&mesh->id);
4536 newob->data = id_cast<ID *>(mesh);
4537 newob->type = OB_MESH;
4538
4540
4541 if (info.obact && (info.obact->type == OB_MBALL)) {
4542 *r_act_base = *r_new_base;
4543 }
4544
4545 baseob->flag |= OB_DONE;
4546 r_mball_converted = true;
4547 }
4548
4549 return newob;
4550}
4551
4553 const ObjectType target,
4555 bool &r_mball_converted,
4556 Base **r_new_base,
4557 Base **r_act_base)
4558{
4559 switch (target) {
4560 case OB_MESH:
4561 return convert_mball_to_mesh(base, info, r_mball_converted, r_new_base, r_act_base);
4562 default:
4563 return nullptr;
4564 }
4565}
4566
4569 Base **r_new_base)
4570{
4571 Object *ob = base.object;
4572 ob->flag |= OB_DONE;
4573 Object *newob = get_object_for_conversion(base, info, r_new_base);
4574
4575 BKE_pointcloud_to_mesh(info.bmain, info.depsgraph, info.scene, newob);
4576
4577 if (newob->type == OB_MESH) {
4578 BKE_object_free_modifiers(newob, 0); /* after derivedmesh calls! */
4579 ED_rigidbody_object_remove(info.bmain, info.scene, newob);
4580 }
4581
4582 return newob;
4583}
4584
4586 const ObjectType target,
4588 Base **r_new_base)
4589{
4590 switch (target) {
4591 case OB_MESH:
4592 return convert_pointcloud_to_mesh(base, info, r_new_base);
4593 default:
4594 return nullptr;
4595 }
4596}
4597
4599{
4600 Main *bmain = CTX_data_main(C);
4601 Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
4602 Scene *scene = CTX_data_scene(C);
4603 ViewLayer *view_layer = CTX_data_view_layer(C);
4604
4605 const short target = RNA_enum_get(op->ptr, "target");
4606 bool keep_original = RNA_boolean_get(op->ptr, "keep_original");
4607 const bool do_merge_customdata = RNA_boolean_get(op->ptr, "merge_customdata");
4608
4609 Vector<PointerRNA> selected_editable_bases;
4610 CTX_data_selected_editable_bases(C, &selected_editable_bases);
4611
4612 /* Too expensive to detect on poll(). */
4613 if (selected_editable_bases.is_empty()) {
4614 BKE_report(op->reports, RPT_INFO, "No editable objects to convert");
4615 return OPERATOR_CANCELLED;
4616 }
4617
4618 /* Disallow conversion if any selected editable object is in Edit Mode.
4619 * This could be supported in the future, but it's a rare corner case
4620 * typically triggered only by Python scripts, see #147387. */
4621 for (const PointerRNA &ptr : selected_editable_bases) {
4622 const Object *ob = (static_cast<const Base *>(ptr.data))->object;
4623 if (ob->mode & OB_MODE_EDIT) {
4624 BKE_report(
4625 op->reports, RPT_ERROR, "Cannot convert selected objects while they are in edit mode");
4626 return OPERATOR_CANCELLED;
4627 }
4628 }
4629
4630 /* don't forget multiple users! */
4631
4632 {
4633 FOREACH_SCENE_OBJECT_BEGIN (scene, ob) {
4634 ob->flag &= ~OB_DONE;
4635
4636 /* flag data that's not been edited (only needed for !keep_original) */
4637 if (ob->data) {
4638 ob->data->tag |= ID_TAG_DOIT;
4639 }
4640
4641 /* possible metaball basis is not in this scene */
4642 if (ob->type == OB_MBALL && target == OB_MESH) {
4643 if (BKE_mball_is_basis(ob) == false) {
4644 Object *ob_basis;
4645 ob_basis = BKE_mball_basis_find(*bmain, scene, ob);
4646 if (ob_basis) {
4647 ob_basis->flag &= ~OB_DONE;
4648 }
4649 }
4650 }
4651 }
4653 }
4654
4656 info.bmain = bmain;
4657 info.depsgraph = depsgraph;
4658 info.scene = scene;
4659 info.view_layer = view_layer;
4660 info.obact = BKE_view_layer_active_object_get(view_layer);
4661 info.keep_original = keep_original;
4662 info.do_merge_customdata = do_merge_customdata;
4663 info.op_props = op->ptr;
4664 info.reports = op->reports;
4665
4666 Base *act_base = nullptr;
4667
4668 /* Ensure we get all meshes calculated with a sufficient data-mask,
4669 * needed since re-evaluating single modifiers causes bugs if they depend
4670 * on other objects data masks too, see: #50950. */
4671 {
4672 for (const PointerRNA &ptr : selected_editable_bases) {
4673 Base *base = static_cast<Base *>(ptr.data);
4674 Object *ob = base->object;
4675
4676 /* The way object type conversion works currently (enforcing conversion of *all* objects
4677 * using converted object-data, even some un-selected/hidden/another scene ones),
4678 * sounds totally bad to me.
4679 * However, changing this is more design than bug-fix, not to mention convoluted code below,
4680 * so that will be for later.
4681 * But at the very least, do not do that with linked IDs! */
4682 if ((!BKE_id_is_editable(bmain, &ob->id) ||
4683 (ob->data && !BKE_id_is_editable(bmain, ob->data))) &&
4684 !keep_original)
4685 {
4686 keep_original = true;
4687 BKE_report(op->reports,
4688 RPT_INFO,
4689 "Converting some non-editable object/object data, enforcing 'Keep Original' "
4690 "option to True");
4691 }
4692
4694 }
4695
4696 CustomData_MeshMasks customdata_mask_prev = scene->customdata_mask;
4698 BKE_scene_graph_update_tagged(depsgraph, bmain);
4699 scene->customdata_mask = customdata_mask_prev;
4700 }
4701
4702 bool mball_converted = false;
4703 int incompatible_count = 0;
4704
4705 for (const PointerRNA &ptr : selected_editable_bases) {
4706 Object *newob = nullptr;
4707 Base *base = static_cast<Base *>(ptr.data), *new_base = nullptr;
4708 Object *ob = base->object;
4709
4710 if (ob->flag & OB_DONE || (ob->data && !IS_TAGGED(ob->data))) {
4711 if (ob->type != target) {
4712 base->flag &= ~BASE_SELECTED;
4713 ob->flag &= ~OB_SELECT;
4714 }
4715
4716 /* obdata already modified */
4717 if (!IS_TAGGED(ob->data)) {
4718 /* When 2 objects with linked data are selected, converting both
4719 * would keep modifiers on all but the converted object #26003. */
4720 if (ob->type == OB_MESH) {
4721 BKE_object_free_modifiers(ob, 0); /* after derivedmesh calls! */
4722 }
4723 }
4724 }
4725 else {
4726 const ObjectType target_type = ObjectType(target);
4727 switch (ob->type) {
4728 case OB_EMPTY:
4729 newob = convert_empty(*base, target_type, info, &new_base);
4730 break;
4731 case OB_MESH:
4732 newob = convert_mesh(*base, target_type, info, &new_base);
4733 break;
4734 case OB_CURVES:
4735 newob = convert_curves(*base, target_type, info, &new_base);
4736 break;
4737 case OB_CURVES_LEGACY:
4739 case OB_SURF:
4740 newob = convert_curves_legacy(*base, target_type, info, &new_base);
4741 break;
4742 case OB_FONT:
4743 newob = convert_font(*base, target_type, info, &new_base);
4744 break;
4745 case OB_GREASE_PENCIL:
4746 newob = convert_grease_pencil(*base, target_type, info, &new_base);
4747 break;
4748 case OB_MBALL:
4749 newob = convert_mball(*base, target_type, info, mball_converted, &new_base, &act_base);
4750 break;
4751 case OB_POINTCLOUD:
4752 newob = convert_pointcloud(*base, target_type, info, &new_base);
4753 break;
4754 default:
4755 incompatible_count++;
4756 continue;
4757 }
4758 }
4759
4760 if (newob) {
4762 /* Ensure new object has consistent material data with its new obdata. */
4763 BKE_object_materials_sync_length(bmain, newob, newob->data);
4764 }
4765
4766 /* tag obdata if it was been changed */
4767
4768 /* If the original object is active then make this object active */
4769 if (new_base) {
4770 if (info.obact && (info.obact == ob)) {
4771 /* Store new active base to update view layer. */
4772 act_base = new_base;
4773 }
4774 new_base = nullptr;
4775 }
4776
4777 if (!keep_original && (ob->flag & OB_DONE)) {
4778 /* NOTE: Tag transform for update because object parenting to curve with path is handled
4779 * differently from all other cases. Converting curve to mesh and mesh to curve will likely
4780 * affect the way children are evaluated.
4781 * It is not enough to tag only geometry and rely on the curve parenting relations because
4782 * this relation is lost when curve is converted to mesh. */
4784 if (ob->data) {
4785 ob->data->tag &= ~ID_TAG_DOIT; /* flag not to convert this datablock again */
4786 }
4787 }
4788 }
4789
4790 if (!keep_original) {
4791 if (mball_converted) {
4792 /* We need to remove non-basis MBalls first, otherwise we won't be able to detect them if
4793 * their basis happens to be removed first. */
4794 FOREACH_SCENE_OBJECT_BEGIN (scene, ob_mball) {
4795 if (ob_mball->type == OB_MBALL) {
4796 Object *ob_basis = nullptr;
4797 if (!BKE_mball_is_basis(ob_mball) &&
4798 ((ob_basis = BKE_mball_basis_find(*bmain, scene, ob_mball)) &&
4799 (ob_basis->flag & OB_DONE)))
4800 {
4801 base_free_and_unlink(bmain, scene, ob_mball);
4802 }
4803 }
4804 }
4806 FOREACH_SCENE_OBJECT_BEGIN (scene, ob_mball) {
4807 if (ob_mball->type == OB_MBALL) {
4808 if (ob_mball->flag & OB_DONE) {
4809 if (BKE_mball_is_basis(ob_mball)) {
4810 base_free_and_unlink(bmain, scene, ob_mball);
4811 }
4812 }
4813 }
4814 }
4816 }
4817 }
4818
4819 // XXX: editmode_enter(C, 0);
4820 // XXX: exit_editmode(C, EM_FREEDATA|); /* free data, but no undo. */
4821
4822 if (act_base) {
4823 /* active base was changed */
4824 base_activate(C, act_base);
4825 view_layer->basact = act_base;
4826 }
4827 else {
4828 BKE_view_layer_synced_ensure(*bmain, scene, view_layer);
4829 if (Object *object = BKE_view_layer_active_object_get(view_layer)) {
4830 if (object->flag & OB_DONE) {
4833 }
4834 }
4835 }
4836
4837 if (incompatible_count != 0) {
4838 const char *target_type_name = "";
4839 PropertyRNA *prop = RNA_struct_find_property(op->ptr, "target");
4840 BLI_assert(prop != nullptr);
4841 RNA_property_enum_name(C, op->ptr, prop, target, &target_type_name);
4842 if (incompatible_count == selected_editable_bases.size()) {
4843 BKE_reportf(op->reports,
4844 RPT_INFO,
4845 "None of the objects are compatible with a conversion to \"%s\"",
4846 RPT_(target_type_name));
4847 }
4848 else {
4850 op->reports,
4851 RPT_INFO,
4852 "The selection included %d object type(s) which do not support conversion to \"%s\"",
4853 incompatible_count,
4854 RPT_(target_type_name));
4855 }
4856 }
4857
4863
4864 return OPERATOR_FINISHED;
4865}
4866
4867static void object_convert_ui(bContext * /*C*/, wmOperator *op)
4868{
4869 ui::Layout &layout = *op->layout;
4870
4871 layout.use_property_split_set(true);
4872
4873 layout.prop(op->ptr, "target", UI_ITEM_NONE, std::nullopt, ICON_NONE);
4874 layout.prop(op->ptr, "keep_original", UI_ITEM_NONE, std::nullopt, ICON_NONE);
4875
4876 const int target = RNA_enum_get(op->ptr, "target");
4877 if (target == OB_MESH) {
4878 layout.prop(op->ptr, "merge_customdata", UI_ITEM_NONE, std::nullopt, ICON_NONE);
4879 }
4880 else if (target == OB_GREASE_PENCIL) {
4881 layout.prop(op->ptr, "thickness", UI_ITEM_NONE, std::nullopt, ICON_NONE);
4882 layout.prop(op->ptr, "offset", UI_ITEM_NONE, std::nullopt, ICON_NONE);
4883 layout.prop(op->ptr, "faces", UI_ITEM_NONE, std::nullopt, ICON_NONE);
4884 }
4885}
4886
4888{
4889 PropertyRNA *prop;
4890
4891 /* identifiers */
4892 ot->name = "Convert To";
4893 ot->description = "Convert selected objects to another type";
4894 ot->idname = "OBJECT_OT_convert";
4895
4896 /* API callbacks. */
4897 ot->invoke = WM_menu_invoke;
4900 ot->ui = object_convert_ui;
4901
4902 /* flags */
4904
4905 /* properties */
4906 ot->prop = prop = RNA_def_enum(
4907 ot->srna, "target", convert_target_items, OB_MESH, "Target", "Type of object to convert to");
4909
4910 prop = RNA_def_boolean(ot->srna,
4911 "keep_original",
4912 false,
4913 "Keep Original",
4914 "Keep original objects instead of replacing them");
4916
4918 ot->srna,
4919 "merge_customdata",
4920 true,
4921 "Merge UVs",
4922 "Merge UV coordinates that share a vertex to account for imprecision in some modifiers");
4923
4924 RNA_def_int(ot->srna, "thickness", 5, 1, 100, "Thickness", "", 1, 100);
4925 RNA_def_boolean(ot->srna, "faces", true, "Export Faces", "Export faces as filled strokes");
4927 "offset",
4928 0.01f,
4929 0.0,
4931 "Stroke Offset",
4932 "Offset strokes from fill",
4933 0.0,
4934 100.00);
4935}
4936
4938
4939/* -------------------------------------------------------------------- */
4942
4944 Main *bmain, Scene *scene, ViewLayer *view_layer, Base *base_src, Object *object_new)
4945{
4946 if ((base_src != nullptr) && (base_src->flag & BASE_ENABLED_AND_MAYBE_VISIBLE_IN_VIEWPORT)) {
4947 BKE_collection_object_add_from(bmain, scene, base_src->object, object_new);
4948 }
4949 else {
4950 LayerCollection *layer_collection = BKE_layer_collection_get_active(view_layer);
4951 BKE_collection_object_add(bmain, layer_collection->collection, object_new);
4952 }
4953}
4954
4955static void object_add_sync_local_view(Base *base_src, Base *base_new)
4956{
4957 base_new->local_view_bits = base_src->local_view_bits;
4958}
4959
4960static void object_add_sync_rigid_body(Main *bmain, Object *object_src, Object *object_new)
4961{
4962 /* 1) duplis should end up in same collection as the original
4963 * 2) Rigid Body sim participants MUST always be part of a collection...
4964 */
4965 /* XXX: is 2) really a good measure here? */
4966 if (object_src->rigidbody_object || object_src->rigidbody_constraint) {
4967 for (Collection &collection : bmain->collections) {
4968 if (BKE_collection_has_object(&collection, object_src)) {
4969 BKE_collection_object_add(bmain, &collection, object_new);
4970 }
4971 }
4972 }
4973}
4974
4981 Object *ob,
4982 const eDupli_ID_Flags dupflag,
4983 const eLibIDDuplicateFlags duplicate_options,
4984 Object **r_ob_new)
4985{
4986 if (ob->mode & OB_MODE_POSE) {
4987 return;
4988 }
4989
4990 Object *obn = BKE_object_duplicate(bmain, ob, dupflag, duplicate_options);
4991 if (r_ob_new) {
4992 *r_ob_new = obn;
4993 }
4995}
4996
4998 Scene *scene,
4999 ViewLayer *view_layer,
5000 Object *ob,
5001 const eDupli_ID_Flags dupflag,
5002 const eLibIDDuplicateFlags duplicate_options,
5003 Object **r_ob_new)
5004{
5005 Object *object_new = nullptr;
5006 object_add_duplicate_internal(bmain, ob, dupflag, duplicate_options, &object_new);
5007 if (r_ob_new) {
5008 *r_ob_new = object_new;
5009 }
5010 if (object_new == nullptr) {
5011 return nullptr;
5012 }
5013
5014 BKE_view_layer_synced_ensure(*bmain, scene, view_layer);
5015 Base *base_src = BKE_view_layer_base_find(view_layer, ob);
5016 object_add_sync_base_collection(bmain, scene, view_layer, base_src, object_new);
5017 BKE_view_layer_synced_ensure(*bmain, scene, view_layer);
5018 Base *base_new = BKE_view_layer_base_find(view_layer, object_new);
5019 if (base_src && base_new) {
5020 object_add_sync_local_view(base_src, base_new);
5021 }
5022 object_add_sync_rigid_body(bmain, ob, object_new);
5023 return base_new;
5024}
5025
5027 Main *bmain, Scene *scene, ViewLayer *view_layer, Base *base, const eDupli_ID_Flags dupflag)
5028{
5029 Base *basen;
5030 Object *ob;
5031
5032 basen = object_add_duplicate_internal(bmain,
5033 scene,
5034 view_layer,
5035 base->object,
5036 dupflag,
5039 nullptr);
5040 if (basen == nullptr) {
5041 return nullptr;
5042 }
5043
5044 ob = basen->object;
5045
5046 /* Link own references to the newly duplicated data #26816.
5047 * Note that this function can be called from edit-mode code, in which case we may have to
5048 * enforce remapping obdata (by default this is forbidden in edit mode). */
5049 const int remap_flag = BKE_object_is_in_editmode(ob) ? ID_REMAP_FORCE_OBDATA_IN_EDITMODE : 0;
5050 BKE_libblock_relink_to_newid(bmain, &ob->id, remap_flag);
5051
5052 /* Correct but the caller must do this. */
5053 // DAG_relations_tag_update(bmain);
5054
5055 if (ob->data != nullptr) {
5057 }
5058
5060
5061 return basen;
5062}
5063
5064/* contextual operator dupli */
5066{
5067 Main *bmain = CTX_data_main(C);
5068 Scene *scene = CTX_data_scene(C);
5069 ViewLayer *view_layer = CTX_data_view_layer(C);
5070 const bool linked = RNA_boolean_get(op->ptr, "linked");
5071 const eDupli_ID_Flags dupflag = (linked) ? eDupli_ID_Flags{} : eDupli_ID_Flags(U.dupflag);
5072
5073 /* We need to handle that here ourselves, because we may duplicate several objects, in which case
5074 * we also want to remap pointers between those... */
5076
5077 /* Duplicate the selected objects, remember data needed to process
5078 * after the sync. */
5079 struct DuplicateObjectLink {
5080 Base *base_src = nullptr;
5081 Object *object_new = nullptr;
5082
5083 DuplicateObjectLink(Base *base_src) : base_src(base_src) {}
5084 };
5085
5086 Vector<DuplicateObjectLink> object_base_links;
5087 CTX_DATA_BEGIN (C, Base *, base, selected_bases) {
5088 object_base_links.append(DuplicateObjectLink(base));
5089 }
5091
5092 bool new_objects_created = false;
5093 for (DuplicateObjectLink &link : object_base_links) {
5095 link.base_src->object,
5096 dupflag,
5098 &link.object_new);
5099 if (link.object_new) {
5100 new_objects_created = true;
5101 }
5102 }
5103
5104 if (!new_objects_created) {
5105 return OPERATOR_CANCELLED;
5106 }
5107
5108 /* Sync that could tag the view_layer out of sync. */
5109 for (DuplicateObjectLink &link : object_base_links) {
5110 /* note that this is safe to do with this context iterator,
5111 * the list is made in advance */
5112 base_select(link.base_src, BA_DESELECT);
5113 if (link.object_new) {
5114 object_add_sync_base_collection(bmain, scene, view_layer, link.base_src, link.object_new);
5115 object_add_sync_rigid_body(bmain, link.base_src->object, link.object_new);
5116 }
5117 }
5118
5119 /* Sync the view layer. Everything else should not tag the view_layer out of sync. */
5120 BKE_view_layer_synced_ensure(*bmain, scene, view_layer);
5121 const Base *active_base = BKE_view_layer_active_base_get(view_layer);
5122 for (DuplicateObjectLink &link : object_base_links) {
5123 if (!link.object_new) {
5124 continue;
5125 }
5126
5127 Base *base_new = BKE_view_layer_base_find(view_layer, link.object_new);
5128 BLI_assert(base_new);
5129 base_select(base_new, BA_SELECT);
5130 if (active_base == link.base_src) {
5131 base_activate(C, base_new);
5132 }
5133
5134 if (link.object_new->data) {
5135 DEG_id_tag_update(link.object_new->data, 0);
5136 }
5137
5138 object_add_sync_local_view(link.base_src, base_new);
5139 }
5140
5141 /* Note that this will also clear newid pointers and tags. */
5143
5145
5148
5151
5152 return OPERATOR_FINISHED;
5153}
5154
5156{
5157 PropertyRNA *prop;
5158
5159 /* identifiers */
5160 ot->name = "Duplicate Objects";
5161 ot->description = "Duplicate selected objects";
5162 ot->idname = "OBJECT_OT_duplicate";
5163
5164 /* API callbacks. */
5165 ot->exec = duplicate_exec;
5167
5168 /* flags */
5170
5171 /* to give to transform */
5172 prop = RNA_def_boolean(ot->srna,
5173 "linked",
5174 false,
5175 "Linked",
5176 "Duplicate object but not object data, linking to the original data");
5178
5179 prop = RNA_def_enum(ot->srna,
5180 "mode",
5183 "Mode",
5184 "");
5186}
5187
5189
5190/* -------------------------------------------------------------------- */
5195
5197{
5198 Main *bmain = CTX_data_main(C);
5199 Scene *scene = CTX_data_scene(C);
5200 ViewLayer *view_layer = CTX_data_view_layer(C);
5201 const bool linked = RNA_boolean_get(op->ptr, "linked");
5202 const eDupli_ID_Flags dupflag = (linked) ? eDupli_ID_Flags{} : eDupli_ID_Flags(U.dupflag);
5203
5204 /* Find object, create fake base. */
5205
5206 Object *ob = reinterpret_cast<Object *>(
5208
5209 if (ob == nullptr) {
5210 BKE_report(op->reports, RPT_ERROR, "Object not found");
5211 return OPERATOR_CANCELLED;
5212 }
5213
5214 /* prepare dupli */
5216 bmain,
5217 scene,
5218 view_layer,
5219 ob,
5220 dupflag,
5221 /* Sub-process flag because the new-ID remapping (#BKE_libblock_relink_to_newid()) in this
5222 * function will only work if the object is already linked in the view layer, which is not
5223 * the case here. So we have to do the new-ID relinking ourselves
5224 * (#copy_object_set_idnew()).
5225 */
5227 nullptr);
5228
5229 if (basen == nullptr) {
5230 BKE_report(op->reports, RPT_ERROR, "Object could not be duplicated");
5231 return OPERATOR_CANCELLED;
5232 }
5233
5235 /* Do immediately, as #copy_object_set_idnew() below operates on visible objects. */
5236 BKE_base_eval_flags(basen);
5237
5238 /* #object_add_duplicate_internal() doesn't deselect other objects,
5239 * unlike #object_add_common() or #BKE_view_layer_base_deselect_all(). */
5240 base_deselect_all(*bmain, scene, view_layer, nullptr, SEL_DESELECT);
5241 base_select(basen, BA_SELECT);
5242 base_activate(C, basen);
5243
5245
5246 /* TODO(sergey): Only update relations for the current scene. */
5248
5254
5255 PropertyRNA *prop_matrix = RNA_struct_find_property(op->ptr, "matrix");
5256 if (RNA_property_is_set(op->ptr, prop_matrix)) {
5257 Object *ob_add = basen->object;
5259 op->ptr, prop_matrix, ob_add->runtime->object_to_world.base_ptr());
5260 BKE_object_apply_mat4(ob_add, ob_add->object_to_world().ptr(), true, true);
5261
5263 }
5264 else if (CTX_wm_region_view3d(C)) {
5265 int mval[2];
5266 if (object_add_drop_xy_get(C, op, &mval)) {
5267 location_from_view(C, basen->object->loc);
5268 ED_view3d_cursor3d_position(C, mval, false, basen->object->loc);
5269 }
5270 }
5271
5272 return OPERATOR_FINISHED;
5273}
5274
5276{
5277 /* identifiers */
5278 ot->name = "Add Object";
5279 ot->description = "Add named object";
5280 ot->idname = "OBJECT_OT_add_named";
5281
5282 /* API callbacks. */
5286
5287 /* flags */
5289
5290 PropertyRNA *prop;
5292 "linked",
5293 false,
5294 "Linked",
5295 "Duplicate object but not object data, linking to the original data");
5296
5298
5299 prop = RNA_def_float_matrix(
5300 ot->srna, "matrix", 4, 4, nullptr, 0.0f, 0.0f, "Matrix", "", 0.0f, 0.0f);
5302
5304}
5305
5307
5308/* -------------------------------------------------------------------- */
5311
5316{
5317 Main *bmain = CTX_data_main(C);
5318 const Scene *scene = CTX_data_scene(C);
5319 ViewLayer *view_layer = CTX_data_view_layer(C);
5320
5321 Object *ob = reinterpret_cast<Object *>(
5323
5324 if (!ob) {
5325 BKE_view_layer_synced_ensure(*bmain, scene, view_layer);
5326 ob = BKE_view_layer_active_object_get(view_layer);
5327 }
5328
5329 if (ob == nullptr) {
5330 BKE_report(op->reports, RPT_ERROR, "Object not found");
5331 return OPERATOR_CANCELLED;
5332 }
5333
5334 /* Don't transform a linked object. There's just nothing to do here in this case, so return
5335 * #OPERATOR_FINISHED. */
5336 if (!BKE_id_is_editable(bmain, &ob->id)) {
5337 return OPERATOR_FINISHED;
5338 }
5339
5340 /* Ensure the locations are updated so snap reads the evaluated active location. */
5342
5343 PropertyRNA *prop_matrix = RNA_struct_find_property(op->ptr, "matrix");
5344 if (RNA_property_is_set(op->ptr, prop_matrix)) {
5345 ObjectsInViewLayerParams params = {0};
5347 view_layer, nullptr, &params);
5348
5349 float matrix[4][4];
5350 RNA_property_float_get_array(op->ptr, prop_matrix, &matrix[0][0]);
5351
5352 float mat_src_unit[4][4];
5353 float mat_dst_unit[4][4];
5354 float final_delta[4][4];
5355
5356 normalize_m4_m4(mat_src_unit, ob->object_to_world().ptr());
5357 normalize_m4_m4(mat_dst_unit, matrix);
5358 invert_m4(mat_src_unit);
5359 mul_m4_m4m4(final_delta, mat_dst_unit, mat_src_unit);
5360
5361 object_xform_array_m4(objects.data(), objects.size(), final_delta);
5362 }
5363 else if (CTX_wm_region_view3d(C)) {
5364 int mval[2];
5365 if (object_add_drop_xy_get(C, op, &mval)) {
5366 float cursor[3];
5367 location_from_view(C, cursor);
5368 ED_view3d_cursor3d_position(C, mval, false, cursor);
5369
5370 /* Use the active objects location since this is the ID which the user selected to drop.
5371 *
5372 * This transforms all selected objects, so that dropping a single object which links in
5373 * other objects will have their relative transformation preserved.
5374 * For example a child/parent relationship or other objects used with a boolean modifier.
5375 *
5376 * The caller is responsible for ensuring the selection state gives useful results.
5377 * Link/append does this using #FILE_AUTOSELECT. */
5379 }
5380 }
5381
5382 return OPERATOR_FINISHED;
5383}
5384
5386{
5387 /* identifiers */
5388 ot->name = "Place Object Under Mouse";
5389 ot->description = "Snap selected item(s) to the mouse location";
5390 ot->idname = "OBJECT_OT_transform_to_mouse";
5391
5392 /* API callbacks. */
5396
5397 /* flags */
5399
5400 PropertyRNA *prop;
5401 prop = RNA_def_string(
5402 ot->srna,
5403 "name",
5404 nullptr,
5405 MAX_ID_NAME - 2,
5406 "Name",
5407 "Object name to place (uses the active object when this and 'session_uid' are unset)");
5409 prop = RNA_def_int(ot->srna,
5410 "session_uid",
5411 0,
5412 INT32_MIN,
5413 INT32_MAX,
5414 "Session UUID",
5415 "Session UUID of the object to place (uses the active object when this and "
5416 "'name' are unset)",
5417 INT32_MIN,
5418 INT32_MAX);
5420
5421 prop = RNA_def_float_matrix(
5422 ot->srna, "matrix", 4, 4, nullptr, 0.0f, 0.0f, "Matrix", "", 0.0f, 0.0f);
5424
5426}
5427
5429
5430/* -------------------------------------------------------------------- */
5433
5435{
5437
5438 if (ob == nullptr || ob->data == nullptr || !ID_IS_EDITABLE(ob) || ID_IS_OVERRIDE_LIBRARY(ob) ||
5440 {
5441 return false;
5442 }
5443
5444 if (ELEM(ob->type,
5445 OB_MESH,
5447 OB_SURF,
5449 OB_CURVES,
5452 {
5453 return true;
5454 }
5455 return false;
5456}
5457
5459{
5460 Main *bmain = CTX_data_main(C);
5462
5463 if (ob->mode & OB_MODE_EDIT) {
5464 BKE_report(op->reports, RPT_ERROR, "This data does not support joining in edit mode");
5465 return OPERATOR_CANCELLED;
5466 }
5468 BKE_report(op->reports, RPT_ERROR, "Cannot edit external library data");
5469 return OPERATOR_CANCELLED;
5470 }
5472 BKE_reportf(op->reports,
5474 "Cannot edit object '%s' as it is used by override collections",
5475 ob->id.name + 2);
5476 return OPERATOR_CANCELLED;
5477 }
5478
5480 if (ob->type == OB_MESH) {
5482 }
5483 else if (ELEM(ob->type, OB_CURVES_LEGACY, OB_SURF)) {
5485 }
5486 else if (ob->type == OB_ARMATURE) {
5488 }
5489 else if (ob->type == OB_POINTCLOUD) {
5491 }
5492 else if (ob->type == OB_CURVES) {
5494 }
5495 else if (ob->type == OB_GREASE_PENCIL) {
5497 }
5498
5499 if (ret & OPERATOR_FINISHED) {
5500 /* Even though internally failure to invert is accounted for with a fallback,
5501 * show a warning since the result may not be what the user expects. See #80077.
5502 *
5503 * Failure to invert the matrix is typically caused by zero scaled axes
5504 * (which can be caused by constraints, even if the input scale isn't zero).
5505 *
5506 * Internally the join functions use #invert_m4_m4_safe_ortho which creates
5507 * an inevitable matrix from one that has one or more degenerate axes.
5508 *
5509 * In most cases we don't worry about special handling for non-inevitable matrices however for
5510 * joining objects there may be flat 2D objects where it's not obvious the scale is zero.
5511 * In this case, using #invert_m4_m4_safe_ortho works as well as we can expect,
5512 * joining the contents, flattening on the axis that's zero scaled.
5513 * If the zero scale is removed, the data on this axis remains un-scaled
5514 * (something that wouldn't work for #invert_m4_m4_safe). */
5515 float imat_test[4][4];
5516 if (!invert_m4_m4(imat_test, ob->object_to_world().ptr())) {
5517 BKE_report(op->reports,
5519 "Active object final transform has one or more zero scaled axes");
5520 }
5521 }
5522
5523 return ret;
5524}
5525
5527{
5528 /* identifiers */
5529 ot->name = "Join";
5530 ot->description = "Join selected objects into active object";
5531 ot->idname = "OBJECT_OT_join";
5532
5533 /* API callbacks. */
5534 ot->exec = object_join_exec;
5535 ot->poll = object_join_poll;
5536
5537 /* flags */
5539}
5540
5542
5543/* -------------------------------------------------------------------- */
5546
5548{
5550 if (!ob) {
5551 return false;
5552 }
5553 if (ob->type != OB_MESH) {
5554 return false;
5555 }
5556
5557 if (ob->mode & OB_MODE_EDIT) {
5558 CTX_wm_operator_poll_msg_set(C, "This operation is not supported in edit mode");
5559 return false;
5560 }
5562 CTX_wm_operator_poll_msg_set(C, "Cannot edit external library data");
5563 return false;
5564 }
5565 Main &bmain = *CTX_data_main(C);
5567 CTX_wm_operator_poll_msg_set(C, "Cannot edit object used by override collections");
5568 return false;
5569 }
5570 return true;
5571}
5572
5574{
5576 C, true, RNA_boolean_get(op->ptr, "use_mirror"), op->reports);
5577}
5578
5580{
5581 ot->name = "Join as Shapes";
5582 ot->description =
5583 "Add the vertex positions of selected objects as shape keys or update existing shape keys "
5584 "with matching names";
5585 ot->idname = "OBJECT_OT_join_shapes";
5586
5587 ot->exec = join_shapes_exec;
5589
5591
5593 ot->srna, "use_mirror", false, "Mirror", "Mirror the new shape key values");
5595}
5596
5598{
5600 C, false, RNA_boolean_get(op->ptr, "use_mirror"), op->reports);
5601}
5602
5604{
5606 return false;
5607 }
5608
5610 const Key *key = BKE_key_from_object(ob);
5611 if (!key || key->block.is_empty()) {
5612 return false;
5613 }
5614 return true;
5615}
5616
5618{
5619 ot->name = "Update from Objects";
5620 ot->description =
5621 "Update existing shape keys with the vertex positions of selected objects with matching "
5622 "names";
5623 ot->idname = "OBJECT_OT_update_shapes";
5624
5627
5629
5631 ot->srna, "use_mirror", false, "Mirror", "Mirror the new shape key values");
5633}
5634
5636
5637} // namespace ed::object
5638} // namespace blender
C++ functions to deal with Armature collections (i.e. the successor of bone layers).
Blender kernel action and pose functionality.
Generic geometry attributes built on CustomData.
Camera data-block and utility functions.
#define FOREACH_SCENE_OBJECT_END
#define FOREACH_SCENE_OBJECT_BEGIN(scene, _instance)
#define CTX_DATA_BEGIN(C, Type, instance, member)
#define CTX_DATA_END
Low-level operations for curves that cannot be defined in the C++ header yet.
Low-level operations for curves.
CustomData interface, see also DNA_customdata_types.h.
support for deformation groups and hooks.
display list (or rather multi purpose list) stuff.
Low-level operations for grease pencil.
#define IS_TAGGED(_id)
General operations, lookup, etc. for blender lights.
General operations for probes.
#define FOREACH_MAIN_ID_END
Definition BKE_main.hh:735
#define FOREACH_MAIN_ID_BEGIN(_bmain, _id)
Definition BKE_main.hh:729
General operations, lookup, etc. for materials.
General operations, lookup, etc. for blender objects.
General operations for point clouds.
#define INT32_MAX
#define ATTR_FALLTHROUGH
#define INT32_MIN
Volume data-block.
#define BLI_ghashutil_inthash(key)
Definition BLI_ghash.hh:579
#define DEG2RADF(_deg)
#define M_PI_2
#define STR_ELEM(...)
#define STRNCPY_UTF8(dst, src)
#define RPT_(msgid)
#define BLT_I18NCONTEXT_ID_ID
#define BLT_I18NCONTEXT_ID_GPENCIL
#define BLT_I18NCONTEXT_ID_LIGHT
#define BLT_I18NCONTEXT_ID_OBJECT
#define BLT_I18NCONTEXT_OPERATOR_DEFAULT
#define CTX_DATA_(context, msgid)
#define IFACE_(msgid)
#define DATA_(msgid)
#define ID_EXTRA_USERS(id)
Definition DNA_ID.h:665
#define ID_IS_LINKED(_id)
Definition DNA_ID.h:697
#define MAX_ID_NAME
Definition DNA_ID.h:367
#define ID_IS_EDITABLE(_id)
Definition DNA_ID.h:708
#define ID_REAL_USERS(id)
Definition DNA_ID.h:679
#define ID_IS_OVERRIDE_LIBRARY(_id)
Definition DNA_ID.h:736
#define ID_NEW_SET(_id, _idn)
Definition DNA_ID.h:757
Object groups, one object can be in many groups at once.
Object is a sort of wrapper for general info.
#define BASE_SELECTED_EDITABLE(v3d, base)
#define OBJECT_ADD_SIZE_MAXF
Definition ED_object.hh:332
#define C
Definition RandGen.cpp:29
#define UI_ITEM_NONE
#define NC_GEOM
Definition WM_types.hh:406
#define ND_DRAW
Definition WM_types.hh:502
#define ND_OB_ACTIVE
Definition WM_types.hh:459
#define ND_DATA
Definition WM_types.hh:552
#define NC_ANIMATION
Definition WM_types.hh:401
#define ND_OB_SELECT
Definition WM_types.hh:461
#define NC_SCENE
Definition WM_types.hh:391
#define NA_ADDED
Definition WM_types.hh:636
#define ND_LAYER_CONTENT
Definition WM_types.hh:472
#define ND_MODIFIER
Definition WM_types.hh:503
#define ND_PARENT
Definition WM_types.hh:508
#define ND_NLA
Definition WM_types.hh:540
#define NC_OBJECT
Definition WM_types.hh:392
#define SET_FLAG_FROM_TEST(value, test, flag)
#define UNPACK3(a)
#define ELEM(...)
#define STREQ(a, b)
int64_t size() const
Definition BLI_array.hh:267
void reinitialize(const int64_t new_size)
Definition BLI_array.hh:430
static AttributeOwner from_id(ID *id)
constexpr IndexRange()=default
bool add(const Key &key, const Value &value)
Definition BLI_map.hh:295
const Value & lookup(const Key &key) const
Definition BLI_map.hh:545
constexpr int64_t size() const
Definition BLI_span.hh:256
constexpr const char * c_str() const
constexpr StringRef()
static VArray from_span(Span< T > values)
bool add(const Key &key)
int64_t index_of_or_add(const Key &key)
IndexRange index_range() const
int64_t size() const
void append(const T &value)
bool is_empty() const
IndexRange index_range() const
GAttributeReader lookup_or_default(StringRef name, AttrDomain domain, AttrType data_type, const void *default_value=nullptr) const
MutableSpan< float3 > positions_for_write()
void resize(int points_num, int curves_num)
MutableAttributeAccessor attributes_for_write()
bool add(const StringRef name, const AttrDomain domain, const AttrType data_type, const AttributeInit &initializer)
GSpanAttributeWriter lookup_or_add_for_write_only_span(StringRef name, AttrDomain domain, AttrType data_type)
bke::CurvesGeometry & strokes_for_write()
constexpr bool is_empty() const
constexpr int64_t size() const
constexpr const char * data() const
bool operator==(const FillColorRecord &other) const
#define rot(x, k)
#define FLT_MAX
#define INT_MAX
#define FLT_EPSILON
#define position
#define layer
float3x3 scale(float3x3 mat, float2 scale)
void gather(const GVArray &src, const IndexMask &indices, GMutableSpan dst, exec_mode::Mode mode=exec_mode::parallel)
void copy(const GVArray &src, GMutableSpan dst, exec_mode::Mode mode=exec_mode::parallel)
AssetLibraryReference all_library_reference()
constexpr float LEGACY_RADIUS_CONVERSION_FACTOR
void curves_copy_parameters(const Curves &src, Curves &dst)
auto attribute_filter_from_skip_ref(const Span< StringRef > skip)
Curves * curve_legacy_to_curves(const Curve &curve_legacy)
void gather_attributes(AttributeAccessor src_attributes, AttrDomain src_domain, AttrDomain dst_domain, const AttributeFilter &attribute_filter, const IndexMask &selection, MutableAttributeAccessor dst_attributes)
Mesh * curve_to_wire_mesh(const CurvesGeometry &curve, const bke::AttributeFilter &attribute_filter={})
void mesh_ensure_active_uv_map(Mesh &mesh)
bool object_has_geometry_set_instances(const Object &object)
std::array< VecBase< T, 3 >, 8 > corners(const Bounds< VecBase< T, 3 > > &bounds)
void storage_fetch_blocking(const AssetLibraryReference &library_reference, const bContext &C)
const asset_system::AssetRepresentation * find_asset_from_weak_ref(const bContext &C, const AssetWeakReference &weak_ref, ReportList *reports)
ID * asset_local_id_ensure_imported(Main &bmain, const asset_system::AssetRepresentation &asset, int flags=0, const std::optional< eAssetImportMethod > import_method=std::nullopt, const std::optional< ImportInstantiateContext > instantiate_context=std::nullopt, ReportList *reports=nullptr)
bke::CurvesGeometry primitive_random_sphere(const int curves_size, const int points_per_curve)
wmOperatorStatus join_objects_exec(bContext *C, wmOperator *op)
void create_suzanne(Main &bmain, Object &object, const float4x4 &matrix, const int frame_number)
Vector< DrawingInfo > retrieve_visible_drawings(const Scene &scene, const GreasePencil &grease_pencil, const bool do_onion_skinning)
void create_blank(Main &bmain, Object &object, const int frame_number)
void create_stroke(Main &bmain, Object &object, const float4x4 &matrix, const int frame_number)
wmOperatorStatus join_objects_exec(bContext *C, wmOperator *op)
Definition mesh_join.cc:523
void OBJECT_OT_metaball_add(wmOperatorType *ot)
static wmOperatorStatus collection_drop_exec(bContext *C, wmOperator *op)
ModifierData * modifier_add(ReportList *reports, Main *bmain, Scene *scene, Object *ob, const char *name, int type)
static wmOperatorStatus duplicate_exec(bContext *C, wmOperator *op)
static void mesh_data_to_grease_pencil(const Mesh &mesh_eval, GreasePencil &grease_pencil, const int current_frame, const bool generate_faces, const float stroke_radius, const float offset, const Array< int > &material_remap)
static wmOperatorStatus object_convert_exec(bContext *C, wmOperator *op)
void add_unit_props_radius(wmOperatorType *ot)
static Object * convert_grease_pencil(Base &base, const ObjectType target, ObjectConversionInfo &info, Base **r_new_base)
static void object_data_convert_curve_to_mesh(Main *bmain, Depsgraph *depsgraph, Object *ob)
static int mesh_to_grease_pencil_add_material(Main &bmain, Object &ob_grease_pencil, const StringRefNull name, const std::optional< float4 > &stroke_color, const std::optional< float4 > &fill_color)
Object * add_type(bContext *C, int type, const char *name, const float loc[3], const float rot[3], bool enter_editmode, unsigned short local_view_bits) ATTR_NONNULL(1) ATTR_RETURNS_NONNULL
void OBJECT_OT_curves_empty_hair_add(wmOperatorType *ot)
static Object * convert_mesh_to_mesh(Base &base, ObjectConversionInfo &info, Base **r_new_base)
static Base * duplibase_for_convert(Main *bmain, Depsgraph *depsgraph, Scene *scene, ViewLayer *view_layer, Base *base, Object *ob)
static void object_add_duplicate_internal(Main *bmain, Object *ob, const eDupli_ID_Flags dupflag, const eLibIDDuplicateFlags duplicate_options, Object **r_ob_new)
void OBJECT_OT_text_add(wmOperatorType *ot)
static Object * convert_curves_legacy_to_mesh(Base &base, ObjectConversionInfo &info, Base **r_new_base)
static Object * convert_curves_legacy(Base &base, const ObjectType target, ObjectConversionInfo &info, Base **r_new_base)
static Object * convert_mesh_to_curves(Base &base, ObjectConversionInfo &info, Base **r_new_base)
Object * add_type_with_obdata(bContext *C, int type, const char *name, const float loc[3], const float rot[3], bool enter_editmode, ushort local_view_bits, ID *obdata)
static const char * get_light_defname(int type)
static wmOperatorStatus effector_add_exec(bContext *C, wmOperator *op)
static wmOperatorStatus object_add_text_exec(bContext *C, wmOperator *op)
static Object * convert_pointcloud_component_to_pointcloud(Base &base, ObjectConversionInfo &info, Base **r_new_base)
static Object * convert_font(Base &base, const short target, ObjectConversionInfo &info, Base **r_new_base)
static Object * convert_mesh(Base &base, const ObjectType target, ObjectConversionInfo &info, Base **r_new_base)
void OBJECT_OT_update_shapes(wmOperatorType *ot)
static void object_add_drop_xy_props(wmOperatorType *ot)
void object_xform_array_m4(Object **objects, uint objects_len, const float matrix[4][4])
static wmOperatorStatus object_pointcloud_add_exec(bContext *C, wmOperator *op)
static Object * convert_curves_legacy_to_grease_pencil(Base &base, ObjectConversionInfo &info, Base **r_new_base)
static void add_grease_pencil_materials_for_conversion(Main &bmain, ID &from_id, Object &gp_object)
void OBJECT_OT_delete(wmOperatorType *ot)
static bool object_convert_poll(bContext *C)
void OBJECT_OT_transform_to_mouse(wmOperatorType *ot)
static Object * convert_font_to_curves(Base &base, ObjectConversionInfo &info, Base **r_new_base)
static bool object_join_poll(bContext *C)
void OBJECT_OT_collection_instance_add(wmOperatorType *ot)
void add_unit_props_size(wmOperatorType *ot, float default_value=2.0f)
static const char * get_effector_defname(ePFieldType type)
static const EnumPropertyItem align_options[]
static EnumPropertyItem rna_enum_gpencil_add_stroke_depth_order_items[]
float new_primitive_matrix(bContext *C, Object *obedit, const float loc[3], const float rot[3], const float scale[3], float primmat[4][4])
static Object * convert_curves_to_grease_pencil(Base &base, ObjectConversionInfo &info, Base **r_new_base)
static VectorSet< FillColorRecord > mesh_to_grease_pencil_get_material_list(Object &ob_mesh, const Mesh &mesh, Array< int > &material_remap)
void rotation_from_view(bContext *C, float rot[3], char align_axis)
static wmOperatorStatus object_armature_add_exec(bContext *C, wmOperator *op)
void base_activate(bContext *C, Base *base)
static bool object_update_shapes_poll(bContext *C)
static const EnumPropertyItem field_type_items[]
void OBJECT_OT_collection_external_asset_drop(wmOperatorType *ot)
static bool object_can_have_lattice_modifier(const Object *ob)
void OBJECT_OT_data_instance_add(wmOperatorType *ot)
void OBJECT_OT_armature_add(wmOperatorType *ot)
void OBJECT_OT_lattice_add_to_selected(wmOperatorType *ot)
static Object * convert_mball(Base &base, const ObjectType target, ObjectConversionInfo &info, bool &r_mball_converted, Base **r_new_base, Base **r_act_base)
void OBJECT_OT_speaker_add(wmOperatorType *ot)
static void object_add_sync_base_collection(Main *bmain, Scene *scene, ViewLayer *view_layer, Base *base_src, Object *object_new)
static bool has_capture_rest_geometry_modifier(const Object *object)
static void object_add_sync_local_view(Base *base_src, Base *base_new)
void base_select(Base *base, eObjectSelect_Mode mode)
static Object * convert_font_to_curves_legacy(Base &base, ObjectConversionInfo &info, Base **r_new_base)
void base_free_and_unlink_no_indirect_check(Main *bmain, Scene *scene, Object *ob)
static void object_add_sync_rigid_body(Main *bmain, Object *object_src, Object *object_new)
static Object * convert_mesh_to_grease_pencil(Base &base, ObjectConversionInfo &info, Base **r_new_base)
static Object * convert_grease_pencil_to_mesh(Base &base, ObjectConversionInfo &info, Base **r_new_base)
void add_unit_props_radius_ex(wmOperatorType *ot, float default_value)
void rotation_from_quat(float rot[3], const float quat[4], char align_axis)
static bool active_shape_key_editable_poll(bContext *C)
static bool object_curves_empty_hair_add_poll(bContext *C)
static void object_convert_ui(bContext *, wmOperator *op)
static void view_align_update(Main *, Scene *, PointerRNA *ptr)
static wmOperatorStatus object_delete_exec(bContext *C, wmOperator *op)
static Object * convert_grease_pencil_component_to_curves(Base &base, ObjectConversionInfo &info, Base **r_new_base)
void OBJECT_OT_pointcloud_random_add(wmOperatorType *ot)
static const EnumPropertyItem * convert_target_itemf(bContext *C, PointerRNA *, PropertyRNA *, bool *r_free)
void OBJECT_OT_lightprobe_add(wmOperatorType *ot)
static const char * get_lightprobe_defname(int type)
void OBJECT_OT_join_shapes(wmOperatorType *ot)
void OBJECT_OT_grease_pencil_add(wmOperatorType *ot)
static wmOperatorStatus object_curves_empty_hair_add_exec(bContext *C, wmOperator *op)
void OBJECT_OT_convert(wmOperatorType *ot)
bool parent_set(ReportList *reports, const bContext *C, Scene *scene, Object *const ob, Object *const par, int partype, bool xmirror, bool keep_transform, const int vert_par[3])
bool editmode_enter_ex(Main *bmain, Scene *scene, Object *ob, int flag)
static wmOperatorStatus object_empty_add_exec(bContext *C, wmOperator *op)
static wmOperatorStatus object_curves_random_add_exec(bContext *C, wmOperator *op)
static wmOperatorStatus object_transform_to_mouse_exec(bContext *C, wmOperator *op)
static void copy_object_set_idnew(bContext *C)
static wmOperatorStatus object_light_add_exec(bContext *C, wmOperator *op)
static Object * convert_mesh_to_curves_legacy(Base &base, ObjectConversionInfo &info, Base **r_new_base)
static wmOperatorStatus object_join_exec(bContext *C, wmOperator *op)
void OBJECT_OT_effector_add(wmOperatorType *ot)
void OBJECT_OT_add_named(wmOperatorType *ot)
static wmOperatorStatus object_instance_add_invoke(bContext *C, wmOperator *op, const wmEvent *event)
static Object * convert_mesh_to_pointcloud(Base &base, ObjectConversionInfo &info, Base **r_new_base)
static Object * convert_empty(Base &base, const ObjectType target, ObjectConversionInfo &info, Base **r_new_base)
Base * add_duplicate(Main *bmain, Scene *scene, ViewLayer *view_layer, Base *base, eDupli_ID_Flags dupflag)
void OBJECT_OT_light_add(wmOperatorType *ot)
static wmOperatorStatus object_add_exec(bContext *C, wmOperator *op)
static wmOperatorStatus join_shapes_exec(bContext *C, wmOperator *op)
static EnumPropertyItem lightprobe_type_items[]
static Object * convert_pointcloud_to_mesh(Base &base, ObjectConversionInfo &info, Base **r_new_base)
static wmOperatorStatus collection_instance_add_exec(bContext *C, wmOperator *op)
static wmOperatorStatus object_metaball_add_exec(bContext *C, wmOperator *op)
static bool object_add_to_selected_poll_property(const bContext *, wmOperator *op, const PropertyRNA *prop)
bool editmode_exit_multi_ex(Main *bmain, Scene *scene, ViewLayer *view_layer, int flag)
static wmOperatorStatus lattice_add_to_selected_exec(bContext *C, wmOperator *op)
static wmOperatorStatus object_grease_pencil_add_invoke(bContext *C, wmOperator *op, const wmEvent *)
void OBJECT_OT_empty_image_add(wmOperatorType *ot)
static wmOperatorStatus object_speaker_add_exec(bContext *C, wmOperator *op)
static bool object_image_add_poll(bContext *C)
static Object * convert_mesh_component_to_mesh(Base &base, ObjectConversionInfo &info, Base **r_new_base)
static wmOperatorStatus object_camera_add_exec(bContext *C, wmOperator *op)
static Object * convert_pointcloud(Base &base, const ObjectType target, ObjectConversionInfo &info, Base **r_new_base)
static Object * convert_grease_pencil_component_to_grease_pencil(Base &base, ObjectConversionInfo &info, Base **r_new_base)
static wmOperatorStatus object_duplicates_make_real_exec(bContext *C, wmOperator *op)
static Object * convert_curves_legacy_to_curves(Base &base, ObjectConversionInfo &info, Base **r_new_base)
static NodesModifierData * add_essential_asset_modifier(bContext &C, Object &object, const StringRefNull path, ReportList *reports)
static bool object_add_drop_xy_get(bContext *C, wmOperator *op, int(*r_mval)[2])
void OBJECT_OT_empty_add(wmOperatorType *ot)
static wmOperatorStatus object_add_named_exec(bContext *C, wmOperator *op)
void base_free_and_unlink(Main *bmain, Scene *scene, Object *ob)
static void create_grease_pencil_fills(bke::greasepencil::Drawing &drawing)
static const EnumPropertyItem convert_target_items[]
static Object * convert_font_to_grease_pencil(Base &base, ObjectConversionInfo &info, Base **r_new_base)
static Object * get_object_for_conversion(Base &base, ObjectConversionInfo &info, Base **r_new_base)
void OBJECT_OT_duplicates_make_real(wmOperatorType *ot)
void init_transform_on_add(Object *object, const float loc[3], const float rot[3])
static wmOperatorStatus object_delete_invoke(bContext *C, wmOperator *op, const wmEvent *)
void OBJECT_OT_add(wmOperatorType *ot)
void add_generic_props(wmOperatorType *ot, bool do_editmode)
static Object * convert_mball_to_mesh(Base &base, ObjectConversionInfo &info, bool &r_mball_converted, Base **r_new_base, Base **r_act_base)
void OBJECT_OT_curves_random_add(wmOperatorType *ot)
void location_from_view(bContext *C, float loc[3])
static std::optional< Bounds< float3 > > lattice_add_to_selected_collect_targets_and_calc_bounds(bContext *C, const float orientation_matrix[3][3], Vector< Object * > &r_targets)
static wmOperatorStatus object_image_add_invoke(bContext *C, wmOperator *op, const wmEvent *event)
static wmOperatorStatus object_data_instance_add_exec(bContext *C, wmOperator *op)
static Object * convert_curves_to_mesh(Base &base, ObjectConversionInfo &info, Base **r_new_base)
static void make_object_duplilist_real(bContext *C, Depsgraph *depsgraph, Scene *scene, Base *base, const bool use_base_parent, const bool use_hierarchy)
static bool object_add_drop_xy_is_set(const wmOperator *op)
void add_mesh_props(wmOperatorType *ot)
static Object * convert_curves_component_to_curves(Base &base, ObjectConversionInfo &info, Base **r_new_base)
static Object * convert_curves(Base &base, const ObjectType target, ObjectConversionInfo &info, Base **r_new_base)
bool base_deselect_all(const Main &bmain, const Scene *scene, ViewLayer *view_layer, View3D *v3d, int action)
static wmOperatorStatus object_image_add_exec(bContext *C, wmOperator *op)
static Object * convert_font_to_mesh(Base &base, ObjectConversionInfo &info, Base **r_new_base)
void OBJECT_OT_duplicate(wmOperatorType *ot)
void OBJECT_OT_join(wmOperatorType *ot)
void add_generic_get_opts(bContext *C, wmOperator *op, char view_align_axis, float r_loc[3], float r_rot[3], float r_scale[3], bool *r_enter_editmode, unsigned short *r_local_view_bits, bool *r_is_view_aligned)
bool editmode_exit_ex(Main *bmain, Scene *scene, Object *obedit, int flag)
void OBJECT_OT_camera_add(wmOperatorType *ot)
static wmOperatorStatus object_grease_pencil_add_exec(bContext *C, wmOperator *op)
static wmOperatorStatus lightprobe_add_exec(bContext *C, wmOperator *op)
static std::optional< CollectionAddInfo > collection_add_info_get_from_op(bContext *C, wmOperator *op)
static Object * convert_font_to_curve_legacy_generic(Object *ob, Object *newob, ObjectConversionInfo &info)
static wmOperatorStatus update_all_shape_keys_exec(bContext *C, wmOperator *op)
static wmOperatorStatus object_add_drop_xy_generic_invoke(bContext *C, wmOperator *op, const wmEvent *event)
wmOperatorStatus join_objects_exec(bContext *C, wmOperator *op)
bke::GeometrySet join_geometries(Span< bke::GeometrySet > geometries, const bke::AttributeFilter &attribute_filter, const std::optional< Span< bke::GeometryComponent::Type > > &component_types_to_join=std::nullopt, bool allow_merging_instance_references=true)
bke::CurvesGeometry mesh_edges_to_curves_convert(const Mesh &mesh, const IndexMask &selection, const bke::AttributeFilter &attribute_filter)
T min(const T &a, const T &b)
T max(const T &a, const T &b)
void transform_points(const float4x4 &transform, MutableSpan< float3 > points, bool use_threading=true)
void parallel_for(const IndexRange range, const int64_t grain_size, const Function &function, const TaskSizeHints &size_hints=detail::TaskSizeHints_Static(1))
Definition BLI_task.hh:69
BMesh Iterators.
ID * WM_operator_drop_load_path(bContext *C, wmOperator *op, const short idcode)
PointCloud * BKE_pointcloud_copy_for_eval(const PointCloud *pointcloud_src)
void CustomData_MeshMasks_update(CustomData_MeshMasks *mask_dst, const CustomData_MeshMasks *mask_src)
Definition customdata.cc:89
void WM_main_add_notifier(uint type, void *reference)
void BKE_constraints_free(ListBaseT< bConstraint > *list)
void DEG_graph_tag_relations_update(Depsgraph *graph)
UserDef U
Definition blender.cc:58
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
MINLINE void negate_v3_v3(float r[3], const float a[3])
void RNA_float_set_array(PointerRNA *ptr, const char *name, const float *values)
void RNA_def_enum_funcs(PropertyRNA *prop, EnumPropertyItemFunc itemfunc)
void mul_m3_v3(const float M[3][3], float r[3])
Object * BKE_object_add(Main *bmain, Scene *scene, ViewLayer *view_layer, ObjectType type, const char *name) ATTR_NONNULL(1
Definition object.cc:2296
bool ED_operator_scene_editable(bContext *C)
struct PartDeflect * BKE_partdeflect_new(ePFieldType type)
Definition effect.cc:76
void BKE_mesh_merge_customdata_for_apply_modifier(Mesh *mesh)
Mesh * BKE_mesh_new_from_object_to_bmain(Main *bmain, Depsgraph *depsgraph, Object *object, bool preserve_all_data_layers)
wmOperatorStatus WM_menu_invoke(bContext *C, wmOperator *op, const wmEvent *)
unsigned __int64 uint64_t
Definition BKE_text.h:91
void eul_to_mat3(float mat[3][3], const float eul[3])
int RNA_enum_get(PointerRNA *ptr, const char *name)
struct Curves * BKE_curves_add(struct Main *bmain, const char *name)
void BKE_object_empty_draw_type_set(Object *ob, int value)
Definition object.cc:3860
Object * BKE_view_layer_active_object_get(const ViewLayer *view_layer)
const EnumPropertyItem rna_enum_id_type_items[]
Definition rna_ID.cc:33
PropertyRNA * RNA_def_string(StructOrFunctionRNA *cont_, const char *identifier, const char *default_value, const int maxlen, const char *ui_name, const char *ui_description)
void RNA_property_float_get_array(PointerRNA *ptr, PropertyRNA *prop, float *values)
@ RPT_WARNING
Definition BKE_report.hh:40
void BKE_lattice_resize(Lattice *lt, int u_new, int v_new, int w_new, Object *lt_ob)
Definition lattice.cc:277
void BKE_id_delete(Main *bmain, void *idv, const BKEIDDeleteOptions &options={}) ATTR_NONNULL()
PropertyRNA * RNA_struct_find_property(PointerRNA *ptr, const char *identifier)
void WM_jobs_stop_type(wmWindowManager *wm, const void *owner, eWM_JobType job_type)
Definition wm_jobs.cc:666
void WM_operator_properties_id_lookup(wmOperatorType *ot, const bool add_name_prop)
MINLINE void copy_v3_v3(float r[3], const float a[3])
unsigned int uint
Definition BKE_text.h:55
bool BKE_mball_is_basis(const Object *ob)
Definition mball.cc:255
const EnumPropertyItem rna_enum_object_type_items[]
void BKE_libblock_relink_to_newid(Main *bmain, ID *id, int remap_flag) ATTR_NONNULL()
Definition lib_remap.cc:932
void BKE_pointcloud_nomain_to_pointcloud(PointCloud *pointcloud_src, PointCloud *pointcloud_dst)
void copy_m3_m4(float m1[3][3], const float m2[4][4])
GreasePencil * BKE_grease_pencil_copy_for_eval(const GreasePencil *grease_pencil_src)
void id_us_plus(ID *id)
Definition lib_id.cc:433
NlaStrip * BKE_nla_add_soundstrip(Main *bmain, Scene *scene, Speaker *speaker)
LayerCollection * BKE_layer_collection_get_active(ViewLayer *view_layer)
bool CustomData_has_layer(const CustomData *data, eCustomDataType type)
Mesh * BKE_mesh_copy_for_eval(const Mesh &source)
@ BASE_ENABLED_AND_MAYBE_VISIBLE_IN_VIEWPORT
ID * WM_operator_properties_id_lookup_from_name_or_session_uid(Main *bmain, PointerRNA *ptr, const ID_Type type)
void BKE_nlatrack_set_active(ListBaseT< NlaTrack > *tracks, NlaTrack *nlt)
void copy_m4_m3(float m1[4][4], const float m2[3][3])
bool invert_m3_m3(float inverse[3][3], const float mat[3][3])
const char * RNA_property_identifier(const PropertyRNA *prop)
Material * BKE_object_material_get(Object *ob, short act)
Object * BKE_object_add_for_data(Main *bmain, const Scene *scene, ViewLayer *view_layer, ObjectType type, const char *name, ID *data, bool do_id_user) ATTR_RETURNS_NONNULL
Definition object.cc:2332
bool BKE_nlatrack_add_strip(NlaTrack *nlt, NlaStrip *strip, bool is_liboverride)
bool RNA_property_enum_name(bContext *C, PointerRNA *ptr, PropertyRNA *prop, const int value, const char **r_name)
void normalize_m3(float R[3][3]) ATTR_NONNULL()
@ WM_JOB_TYPE_LIGHT_BAKE
Definition WM_api.hh:2042
BoneCollection * ANIM_armature_bonecoll_new(bArmature *armature, const char *name, int parent_index=-1)
int RNA_property_enum_get(PointerRNA *ptr, PropertyRNA *prop)
void ED_view3d_cursor3d_position(bContext *C, const int mval[2], bool use_depth, float r_cursor_co[3])
void RNA_int_set(PointerRNA *ptr, const char *name, int value)
void BKE_mesh_nomain_to_mesh(Mesh *mesh_src, Mesh *mesh_dst, Object *ob, bool process_shape_keys=true)
short * BKE_id_material_len_p(ID *id)
bool invert_m4_m4(float inverse[4][4], const float mat[4][4])
@ eModifierType_GreasePencilLineart
@ eModifierType_GreasePencilLattice
unsigned short ushort
Definition BKE_text.h:56
void MOD_nodes_update_interface(Main &bmain, Object *object, NodesModifierData *nmd)
Definition MOD_nodes.cc:405
PropertyRNA * RNA_def_enum(StructOrFunctionRNA *cont_, const char *identifier, const EnumPropertyItem *items, const int default_value, const char *ui_name, const char *ui_description)
void mul_mat3_m4_fl(float R[4][4], float f)
bool BKE_scene_collections_object_remove(Main *bmain, Scene *scene, Object *ob, bool free_us)
void quat_to_eul(float eul[3], const float quat[4])
const EnumPropertyItem rna_enum_metaelem_type_items[]
void BKE_mesh_to_pointcloud(Main *bmain, Depsgraph *depsgraph, Scene *scene, Object *ob)
void axis_angle_to_quat(float r[4], const float axis[3], float angle)
unsigned int BLI_ghashutil_ptrhash(const void *key)
Material *** BKE_id_material_array_p(ID *id)
int RNA_int_get(PointerRNA *ptr, const char *name)
void BKE_mesh_wrapper_ensure_mdata(Mesh *mesh)
const EnumPropertyItem rna_enum_light_type_items[]
void mul_m4_m4m4(float R[4][4], const float A[4][4], const float B[4][4])
void RNA_enum_set(PointerRNA *ptr, const char *name, int value)
bool invert_m4(float mat[4][4])
char * BLI_strdupn(const char *str, size_t len) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Base * BKE_view_layer_active_base_get(ViewLayer *view_layer)
void translate_m4(float mat[4][4], float Tx, float Ty, float Tz)
void RNA_property_float_set_array(PointerRNA *ptr, PropertyRNA *prop, const float *values)
@ ID_REMAP_SKIP_USER_CLEAR
@ ID_REMAP_FORCE_OBDATA_IN_EDITMODE
MINLINE int max_ii(int a, int b)
void BKE_object_free_modifiers(Object *ob, int flag)
Definition object.cc:1337
void mul_qt_qtqt(float q[4], const float a[4], const float b[4])
std::string BKE_attribute_calc_unique_name(const AttributeOwner &owner, StringRef name)
MatBase< float, 4, 4 > float4x4
const char * BKE_id_name(const ID &id)
void BKE_nlastrip_validate_name(AnimData *adt, NlaStrip *strip)
void mat3_normalized_to_eul(float eul[3], const float mat[3][3])
@ ASSET_LIBRARY_ESSENTIALS
void WM_operator_properties_filesel(wmOperatorType *ot, const int filter, const short type, const eFileSel_Action action, const eFileSel_Flag flag, const short display, const short sort)
void BKE_modifiers_persistent_uid_init(const Object &object, ModifierData &md)
void BKE_sculptsession_free_pbvh(Object &object)
GreasePencil * BKE_grease_pencil_add(Main *bmain, const char *name)
@ OB_MODIFIER_FLAG_ADD_REST_POSITION
ViewLayer * CTX_data_view_layer(const bContext *C)
void ED_outliner_select_sync_from_object_tag(bContext *C)
void BKE_object_apply_mat4(Object *ob, const float mat[4][4], bool use_compat, bool use_parent)
Definition object.cc:3663
const EnumPropertyItem * RNA_collection_itemf(bContext *C, PointerRNA *ptr, PropertyRNA *prop, bool *r_free)
AnimData * BKE_animdata_ensure_id(ID *id)
Definition anim_data.cc:107
bool BKE_collection_has_object(Collection *collection, const Object *ob)
bool BKE_vfont_to_curve_ex(Object *ob, const Curve &cu, eEditFontMode mode, ListBaseT< Nurb > *r_nubase, const char32_t **r_text, int *r_text_len, bool *r_text_free, CharTrans **r_chartransdata, float *r_font_size_eval)
bool RNA_property_boolean_get(PointerRNA *ptr, PropertyRNA *prop)
void BKE_object_obdata_size_init(Object *ob, float size)
Definition object.cc:2852
Global G
Definition blender.cc:57
VecBase< float, 4 > float4
@ GREASE_PENCIL_LINEART_OBJECT
@ GREASE_PENCIL_LINEART_COLLECTION
@ GREASE_PENCIL_LINEART_SCENE
void BKE_modifier_unique_name(ListBaseT< ModifierData > *modifiers, ModifierData *md)
eLibIDDuplicateFlags
@ LIB_ID_DUPLICATE_IS_SUBPROCESS
@ LIB_ID_DUPLICATE_IS_ROOT_ID
const EnumPropertyItem rna_enum_object_empty_drawtype_items[]
void mul_m4_v3(const float M[4][4], float r[3])
Material * BKE_grease_pencil_object_material_new(Main *bmain, Object *ob, const char *name, int *r_index)
void * BLI_findlink(const ListBase *listbase, int number) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition listbase.cc:541
bool ED_operator_objectmode_poll_msg(bContext *C)
void WM_operator_properties_confirm_or_exec(wmOperatorType *ot)
void BKE_grease_pencil_nomain_to_grease_pencil(GreasePencil *grease_pencil_src, GreasePencil *grease_pencil_dst)
void WM_operator_view3d_unit_defaults(bContext *C, wmOperator *op)
bool DEG_object_transform_is_evaluated(const Object &object)
void CTX_wm_operator_poll_msg_set(bContext *C, const char *msg)
Nurb * ED_curve_add_nurbs_primitive(bContext *C, Object *obedit, float mat[4][4], int type, int newob)
void DEG_id_tag_update_ex(Main *bmain, ID *id, unsigned int flags)
Scene * WM_window_get_active_scene(const wmWindow *win)
void BKE_lightprobe_type_set(struct LightProbe *probe, eLightProbeType lightprobe_type)
Definition lightprobe.cc:85
wmOperatorStatus ED_grease_pencil_join_objects_exec(bContext *C, wmOperator *op)
void ED_rigidbody_object_remove(Main *bmain, Scene *scene, Object *ob)
void BKE_object_free_derived_caches(Object *ob)
Definition object.cc:1810
void loc_eul_size_to_mat4(float R[4][4], const float loc[3], const float eul[3], const float size[3])
void copy_qt_qt(float q[4], const float a[4])
Object * BKE_view_layer_edit_object_get(const ViewLayer *view_layer)
void BKE_object_to_mat4(const Object *ob, float r_mat[4][4])
Definition object.cc:3125
void DEG_id_tag_update(ID *id, unsigned int flags)
void BKE_report(ReportList *reports, eReportType type, const char *message)
Definition report.cc:162
void BKE_pointcloud_to_mesh(Main *bmain, Depsgraph *depsgraph, Scene *scene, Object *ob)
wmOperatorStatus ED_curve_join_objects_exec(bContext *C, wmOperator *op)
void BKE_object_materials_sync_length(Main *bmain, Object *ob, ID *id)
bool WM_jobs_has_running(const wmWindowManager *window_manager, const void *owner, const eWM_JobType type, const eWM_JobFlag exclude_flags)
Definition wm_jobs.cc:809
T * DEG_get_evaluated(const Depsgraph *depsgraph, T *id)
@ WM_FILESEL_RELPATH
Definition WM_api.hh:1329
@ WM_FILESEL_FILEPATH
Definition WM_api.hh:1332
void BKE_animdata_free(ID *id, bool do_id_user)
Definition anim_data.cc:174
wmOperatorStatus ED_armature_join_objects_exec(bContext *C, wmOperator *op)
void object_duplilist(Depsgraph *depsgraph, Object *ob, Set< const Object * > *include_objects, DupliList &r_duplilist)
wmWindowManager * CTX_wm_manager(const bContext *C)
ModifierData * BKE_modifier_new(int type)
Depsgraph * CTX_data_ensure_evaluated_depsgraph(const bContext *C, bool rna_write_check=false)
Object * BKE_object_duplicate(Main *bmain, Object *ob, eDupli_ID_Flags dupflag, uint duplicate_options)
Definition object.cc:2659
Object * CTX_data_edit_object(const bContext *C)
void DEG_id_type_tag(Main *bmain, short id_type)
bool WM_operator_properties_id_lookup_is_set(PointerRNA *ptr)
void BKE_scene_object_base_flag_sync_from_base(Base *base)
Definition scene.cc:3111
NlaTrack * BKE_nlatrack_new_tail(ListBaseT< NlaTrack > *nla_tracks, const bool is_liboverride)
Mesh * BKE_mesh_new_nomain(int verts_num, int edges_num, int faces_num, int corners_num)
Material * BKE_grease_pencil_object_material_ensure_by_name(Main *bmain, Object *ob, const char *name, int *r_index)
Object * BKE_mball_basis_find(const Main &bmain, Scene *scene, Object *ob)
Definition mball.cc:417
MetaElem * ED_mball_add_primitive(bContext *C, Object *obedit, bool obedit_is_new, float mat[4][4], float dia, int type)
size_t BKE_id_multi_tagged_delete(Main *bmain, const BKEIDDeleteOptions &options={}) ATTR_NONNULL()
void BKE_scene_graph_update_tagged(Depsgraph *depsgraph, Main *bmain)
Definition scene.cc:2867
Collection * BKE_collection_parent_editable_find_recursive(const ViewLayer *view_layer, Collection *collection)
bool BKE_view_layer_synced_ensure(const Main &bmain, const Scene *scene, ViewLayer *view_layer)
VectorList< DupliObject > DupliList
bool ED_view3d_snap_selected_to_location(bContext *C, wmOperator *op, const float target_loc_global[3], int pivot_point)
bool BKE_collection_child_remove(Main *bmain, Collection *parent, Collection *child)
float ED_scene_grid_scale(const Scene *scene, const char **r_grid_unit)
float ED_view3d_grid_scale(const Scene *scene, const View3D *v3d, const char **r_grid_unit)
void BKE_collection_object_add_from(Main *bmain, Scene *scene, Object *ob_src, Object *ob_dst)
bool RNA_struct_property_is_set(PointerRNA *ptr, const char *identifier)
bool BKE_collection_object_add(Main *bmain, Collection *collection, Object *ob)
void unit_m4(float m[4][4])
PropertyRNA * RNA_struct_type_find_property(StructRNA *srna, const char *identifier)
void RNA_enum_items_add_value(EnumPropertyItem **items, int *totitem, const EnumPropertyItem *item, int value)
void RNA_enum_item_end(EnumPropertyItem **items, int *totitem)
RegionView3D * CTX_wm_region_view3d(const bContext *C)
bool RNA_boolean_get(PointerRNA *ptr, const char *name)
wmOperatorStatus WM_operator_confirm_ex(bContext *C, wmOperator *op, const char *title, const char *message, const char *confirm_text, ui::AlertIcon icon, bool cancel_default)
const EnumPropertyItem rna_enum_dummy_NULL_items[]
Definition rna_rna.cc:28
MINLINE void zero_v3(float r[3])
MatBase< float, 3, 3 > float3x3
void BKE_id_free(Main *bmain, void *idv)
void BKE_main_id_tag_all(Main *mainvar, int tag, bool value)
Definition lib_id.cc:1314
void invert_m3_m3_safe_ortho(float inverse[3][3], const float mat[3][3])
void WM_event_add_notifier(const bContext *C, uint type, void *reference)
bool RNA_struct_system_idprops_unset(PointerRNA *ptr, const char *identifier)
void BKE_object_material_resize(Main *bmain, Object *ob, short totcol, bool do_id_user)
int BKE_object_obdata_to_type(const ID *id) ATTR_NONNULL(1)
Definition object.cc:2230
void RNA_boolean_set(PointerRNA *ptr, const char *name, bool value)
bool BKE_collection_cycle_find(Collection *new_ancestor, Collection *collection)
Vector< Object * > BKE_view_layer_array_selected_objects_params(ViewLayer *view_layer, const View3D *v3d, const ObjectsInViewLayerParams *params)
const EnumPropertyItem rna_enum_transform_mode_type_items[]
const EnumPropertyItem rna_enum_object_gpencil_type_items[]
void RNA_def_property_translation_context(PropertyRNA *prop, const char *context)
bool invert_m3(float mat[3][3])
bool BKE_object_is_in_editmode(const Object *ob)
Definition object.cc:1898
void * BKE_id_new_nomain(short type, const char *name)
Definition lib_id.cc:1617
void BKE_main_id_newptr_and_tag_clear(Main *bmain)
Definition lib_id.cc:2097
std::optional< Bounds< float3 > > BKE_object_evaluated_geometry_bounds(const Object *ob)
Definition object.cc:3766
void RNA_def_property_flag(PropertyRNA *prop, PropertyFlag flag)
constexpr int MAX_DUPLI_RECUR
PropertyRNA * RNA_def_int(StructOrFunctionRNA *cont_, const char *identifier, const int default_value, const int hardmin, const int hardmax, const char *ui_name, const char *ui_description, const int softmin, const int softmax)
MINLINE void sub_v3_v3v3(float r[3], const float a[3], const float b[3])
bool ED_operator_objectmode(bContext *C)
void BKE_object_mat3_to_rot(Object *ob, float r_mat[3][3], bool use_compat)
Definition object.cc:2946
PropertyRNA * RNA_def_float_vector_xyz(StructOrFunctionRNA *cont_, const char *identifier, const int len, const float *default_value, const float hardmin, const float hardmax, const char *ui_name, const char *ui_description, const float softmin, const float softmax)
void BKE_reportf(ReportList *reports, eReportType type, const char *format,...) ATTR_PRINTF_FORMAT(3
Definition report.cc:191
@ FILE_OPENFILE
Definition WM_api.hh:1341
T * DEG_get_original(T *id)
@ OB_EMPTY_IMAGE_DEPTH_BACK
void BLI_addtail(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:118
Main * CTX_data_main(const bContext *C)
@ NODES_MODIFIER_HIDE_DATABLOCK_SELECTOR
void unit_m3(float m[3][3])
char * BLI_strdup(const char *str) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1) ATTR_MALLOC
MINLINE void copy_v3_fl(float r[3], float f)
const CustomData_MeshMasks CD_MASK_MESH
PropertyRNA * RNA_def_float_rotation(StructOrFunctionRNA *cont_, const char *identifier, const int len, const float *default_value, const float hardmin, const float hardmax, const char *ui_name, const char *ui_description, const float softmin, const float softmax)
void BKE_base_eval_flags(Base *base)
void ANIM_armature_bonecoll_active_set(bArmature *armature, BoneCollection *bcoll)
PythonProbingStrategy<> DefaultProbingStrategy
@ ID_RECALC_SELECT
Definition DNA_ID.h:1101
@ ID_RECALC_ANIMATION
Definition DNA_ID.h:1077
@ ID_RECALC_TRANSFORM
Definition DNA_ID.h:1054
@ ID_RECALC_SYNC_TO_EVAL
Definition DNA_ID.h:1118
@ ID_RECALC_EDITORS
Definition DNA_ID.h:1111
@ ID_RECALC_GEOMETRY
Definition DNA_ID.h:1074
@ ID_RECALC_BASE_FLAGS
Definition DNA_ID.h:1104
ID_Type GS(const char *name)
Definition DNA_ID.h:410
@ PROP_SKIP_PRESET
Definition RNA_types.hh:543
@ PROP_SKIP_SAVE
Definition RNA_types.hh:414
@ PROP_ENUM_NO_TRANSLATE
Definition RNA_types.hh:502
@ PROP_HIDDEN
Definition RNA_types.hh:408
@ OB_EMPTY_IMAGE_HIDE_BACK
@ OB_EMPTY_IMAGE_HIDE_PERSPECTIVE
void BKE_defgroup_copy_list(ListBaseT< bDeformGroup > *outbase, const ListBaseT< bDeformGroup > *inbase)
Definition deform.cc:75
wmOperatorStatus ED_mesh_shapes_join_objects_exec(bContext *C, bool ensure_keys_exist, bool mirror, ReportList *reports)
Definition meshtools.cc:84
Base * BKE_view_layer_base_find(ViewLayer *view_layer, Object *ob)
@ ID_TAG_INDIRECT
Definition DNA_ID.h:851
@ ID_TAG_DOIT
Definition DNA_ID.h:1029
@ ID_TAG_NEW
Definition DNA_ID.h:922
EditBone * ED_armature_ebone_add_primitive(Object *obedit_arm, const float length, const bool view_aligned)
void BKE_main_id_tag_listbase(ListBaseT< ID > *lb, int tag, bool value)
Definition lib_id.cc:1291
LayerCollection * BKE_layer_collection_activate_parent(ViewLayer *view_layer, LayerCollection *lc)
void RNA_property_enum_set(PointerRNA *ptr, PropertyRNA *prop, int value)
PropertyRNA * RNA_def_float_distance(StructOrFunctionRNA *cont_, const char *identifier, const float default_value, const float hardmin, const float hardmax, const char *ui_name, const char *ui_description, const float softmin, const float softmax)
void rescale_m4(float mat[4][4], const float scale[3])
void RNA_def_property_update_runtime(PropertyRNA *prop, RNAPropertyUpdateFunc func)
Object * ED_view3d_give_object_under_cursor(bContext *C, const int mval[2])
wmOperatorStatus WM_enum_search_invoke(bContext *C, wmOperator *op, const wmEvent *)
constexpr uint64_t hash_string(StringRef str)
Definition BLI_hash.hh:183
void DEG_relations_tag_update(Main *bmain)
void RNA_property_boolean_set(PointerRNA *ptr, PropertyRNA *prop, bool value)
Scene * CTX_data_scene(const bContext *C)
MINLINE void copy_v4_v4(float r[4], const float a[4])
void BKE_mesh_to_curve(Main *bmain, Depsgraph *depsgraph, Scene *scene, Object *ob)
@ OPTYPE_REGISTER
Definition WM_types.hh:188
@ OPTYPE_UNDO
Definition WM_types.hh:190
@ OPTYPE_INTERNAL
Definition WM_types.hh:210
void mul_m3_m3m3(float R[3][3], const float A[3][3], const float B[3][3])
void copy_m4_m4(float m1[4][4], const float m2[4][4])
bool BKE_library_ID_is_indirectly_used(Main *bmain, void *idv)
Definition lib_query.cc:652
VecBase< float, 3 > float3
Key * BKE_key_from_object(Object *ob)
Definition key.cc:1311
PropertyRNA * RNA_def_boolean(StructOrFunctionRNA *cont_, const char *identifier, const bool default_value, const char *ui_name, const char *ui_description)
PropertyRNA * RNA_def_float_matrix(StructOrFunctionRNA *cont_, const char *identifier, const int rows, const int columns, const float *default_value, const float hardmin, const float hardmax, const char *ui_name, const char *ui_description, const float softmin, const float softmax)
void normalize_m4_m4(float rmat[4][4], const float mat[4][4]) ATTR_NONNULL()
bool CTX_data_selected_editable_bases(const bContext *C, Vector< PointerRNA > *list)
bool BKE_id_is_editable(const Main *bmain, const ID *id)
Definition lib_id.cc:2782
ID * BKE_id_copy(Main *bmain, const ID *id)
Definition lib_id.cc:856
PropertyRNA * RNA_def_float(StructOrFunctionRNA *cont_, const char *identifier, const float default_value, const float hardmin, const float hardmax, const char *ui_name, const char *ui_description, const float softmin, const float softmax)
Object * CTX_data_active_object(const bContext *C)
void id_us_min(ID *id)
Definition lib_id.cc:441
ARegion * CTX_wm_region(const bContext *C)
void BKE_object_material_from_eval_data(Main *bmain, Object *ob_orig, const ID *data_eval)
void * BKE_id_new(Main *bmain, short type, const char *name)
Definition lib_id.cc:1612
float RNA_float_get(PointerRNA *ptr, const char *name)
bool RNA_property_is_set(PointerRNA *ptr, PropertyRNA *prop)
bool BKE_lib_override_library_id_is_user_deletable(Main *bmain, ID *id)
GreasePencil * BKE_grease_pencil_new_nomain()
View3D * CTX_wm_view3d(const bContext *C)
void WM_event_add_fileselect(bContext *C, wmOperator *op)
void RNA_float_get_array(PointerRNA *ptr, const char *name, float *values)
bool BKE_object_obdata_is_libdata(const Object *ob)
Definition object.cc:2845
Mesh * BKE_object_get_evaluated_mesh(const Object *object_eval)
Definition object.cc:4436
Collection * CTX_data_collection(const bContext *C)
void BKE_curve_dimension_update(Curve *cu)
Definition curve.cc:459
#define hash
Definition noise_c.cc:156
#define CURVE_VFONT_CLEAR(vfont_member)
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
ListBaseT< NlaTrack > nla_tracks
eAssetLibraryType asset_library_type
struct Object * object
unsigned short local_view_bits
ListBaseT< Nurb > nurb
EditNurb * editnurb
int persistent_id[MAX_DUPLI_RECUR]
ListBaseT< Nurb > nurbs
char name[258]
Definition DNA_ID.h:433
void * next
Definition DNA_ID.h:418
ListBaseT< KeyBlock > block
struct Collection * collection
ListBaseT< Collection > collections
Definition BKE_main.hh:406
ListBaseT< Object > objects
Definition BKE_main.hh:388
ListBaseT< Scene > scenes
Definition BKE_main.hh:386
const c_style_mat & ptr() const
const T * base_ptr() const
struct Key * key
CustomData vert_data
struct PartDeflect * pd
struct Object * parent
float parentinv[4][4]
ObjectModifierFlag modifier_flag
bke::ObjectRuntime * runtime
eObject_VisibilityFlag visibility_flag
eObject_EmptyImageDepth empty_image_depth
eObject_Partype partype
ListBaseT< bConstraint > constraints
struct AnimData * adt
eObject_EmptyImageVisibilityFlag empty_image_visibility_flag
eObject_EmptyDrawType empty_drawtype
struct RigidBodyOb * rigidbody_object
eObject_TransFlag transflag
struct Collection * instance_collection
struct Material ** mat
struct RigidBodyCon * rigidbody_constraint
eRegionView3D_Persp persp
struct Object * camera
struct CustomData_MeshMasks customdata_mask
View3DCursor cursor
struct RenderData r
struct Object * camera
struct View3D * localvd
unsigned short local_view_uid
ListBaseT< Base > object_bases
static GeometrySet from_curves(Curves *curves, GeometryOwnershipType ownership=GeometryOwnershipType::Owned)
const Curves * get_curves() const
bool operator()(const DupliObject *a, const DupliObject *b) const
uint64_t operator()(const DupliObject *dob) const
bool operator()(const DupliObject *a, const DupliObject *b) const
uint64_t operator()(const DupliObject *dob) const
void use_property_split_set(bool is_sep)
void prop(PointerRNA *ptr, PropertyRNA *prop, int index, int value, eUI_Item_Flag flag, std::optional< StringRef > name_opt, int icon, std::optional< StringRef > placeholder=std::nullopt)
wmOperatorStatus(*) exec(bContext *C, wmOperator *op) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1125
bool(*) poll_property(const bContext *C, wmOperator *op, const PropertyRNA *prop) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1171
const char * description
Definition WM_types.hh:1115
void(*) ui(bContext *C, wmOperator *op)
Definition WM_types.hh:1176
bool(*) poll(bContext *C) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1165
wmOperatorStatus(*) invoke(bContext *C, wmOperator *op, const wmEvent *event) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1141
struct ReportList * reports
struct wmOperatorType * type