diff options
author | Campbell Barton <ideasman42@gmail.com> | 2020-09-07 06:45:14 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2020-09-07 06:56:22 +0300 |
commit | c695523687ef5bd43f50b6d057de785fad454be8 (patch) | |
tree | c404ad28366dcffb8b94b81ca9ba8d71664a6cd8 /source/blender/editors | |
parent | d268a43b25f7655db385fd3664301810bdef0c14 (diff) |
Fix OBJECT_OT_data_instance_add creating empty data-blocks
ED_object_add_type creates empty object data, add
ED_object_add_type_with_obdata which can take existing object data.
Diffstat (limited to 'source/blender/editors')
-rw-r--r-- | source/blender/editors/include/ED_object.h | 14 | ||||
-rw-r--r-- | source/blender/editors/object/object_add.c | 54 |
2 files changed, 50 insertions, 18 deletions
diff --git a/source/blender/editors/include/ED_object.h b/source/blender/editors/include/ED_object.h index afaf11f5a8e..ed5cbd43cb3 100644 --- a/source/blender/editors/include/ED_object.h +++ b/source/blender/editors/include/ED_object.h @@ -289,13 +289,21 @@ bool ED_object_add_generic_get_opts(struct bContext *C, unsigned short *local_view_bits, bool *is_view_aligned); +struct Object *ED_object_add_type_with_obdata(struct bContext *C, + const int type, + const char *name, + const float loc[3], + const float rot[3], + const bool enter_editmode, + const ushort local_view_bits, + struct ID *obdata); struct Object *ED_object_add_type(struct bContext *C, - int type, + const int type, const char *name, const float loc[3], const float rot[3], - bool enter_editmode, - unsigned short local_view_bits) + const bool enter_editmode, + const unsigned short local_view_bits) ATTR_NONNULL(1) ATTR_RETURNS_NONNULL; void ED_object_single_user(struct Main *bmain, struct Scene *scene, struct Object *ob); diff --git a/source/blender/editors/object/object_add.c b/source/blender/editors/object/object_add.c index d35ac4840bd..2d7f903ccd0 100644 --- a/source/blender/editors/object/object_add.c +++ b/source/blender/editors/object/object_add.c @@ -509,15 +509,20 @@ bool ED_object_add_generic_get_opts(bContext *C, return true; } -/* For object add primitive operators. - * Do not call undo push in this function (users of this function have to). */ -Object *ED_object_add_type(bContext *C, - int type, - const char *name, - const float loc[3], - const float rot[3], - bool enter_editmode, - ushort local_view_bits) +/** + * For object add primitive operators, or for object creation when `obdata != NULL`. + * \param obdata: Assigned to #Object.data, with increased user count. + * + * \note Do not call undo push in this function (users of this function have to). + */ +Object *ED_object_add_type_with_obdata(bContext *C, + const int type, + const char *name, + const float loc[3], + const float rot[3], + const bool enter_editmode, + const ushort local_view_bits, + ID *obdata) { Main *bmain = CTX_data_main(C); Scene *scene = CTX_data_scene(C); @@ -530,7 +535,17 @@ Object *ED_object_add_type(bContext *C, } /* deselects all, sets active object */ - ob = BKE_object_add(bmain, scene, view_layer, type, name); + if (obdata != NULL) { + BLI_assert(type == BKE_object_obdata_to_type(obdata)); + ob = BKE_object_add_for_data(bmain, view_layer, type, name, obdata, true); + const short *materials_len_p = BKE_id_material_len_p(obdata); + if (materials_len_p && *materials_len_p > 0) { + BKE_object_materials_test(bmain, ob, ob->data); + } + } + else { + ob = BKE_object_add(bmain, scene, view_layer, type, name); + } BASACT(view_layer)->local_view_bits = local_view_bits; /* editor level activate, notifiers */ ED_object_base_activate(C, view_layer->basact); @@ -561,6 +576,18 @@ Object *ED_object_add_type(bContext *C, return ob; } +Object *ED_object_add_type(bContext *C, + const int type, + const char *name, + const float loc[3], + const float rot[3], + const bool enter_editmode, + const ushort local_view_bits) +{ + return ED_object_add_type_with_obdata( + C, type, name, loc, rot, enter_editmode, local_view_bits, NULL); +} + /* for object add operator */ static int object_add_exec(bContext *C, wmOperator *op) { @@ -1536,11 +1563,8 @@ static int object_data_instance_add_exec(bContext *C, wmOperator *op) Scene *scene = CTX_data_scene(C); - Object *ob = ED_object_add_type(C, object_type, id->name + 2, loc, rot, false, local_view_bits); - ob->data = id; - id_us_plus(id); - - BKE_object_materials_test(bmain, ob, ob->data); + ED_object_add_type_with_obdata( + C, object_type, id->name + 2, loc, rot, false, local_view_bits, id); /* Works without this except if you try render right after, see: T22027. */ DEG_relations_tag_update(bmain); |