Make Single User: support object data animation

In addition to _object_ animation, now _object data_ (mesh, curve, ...)
animation can now be made single user as well.

This came up in T89369 and while it is possible to do this via the
Outliner [where all actions have to be selected individually], this
seems to be more convenient to be done from the 3DView.

note: usercount of the action is checked now, if it single-user already,
no copy takes place (same thing could/should be done for
single_object_action_users as well).

note2: obdata is made single user as well (otherwise duplicated actions
will be assigned to the same shared obdata - which does not result in
unique animadata which is what we are after here)

ref. T89369

Maniphest Tasks: T89369

Differential Revision: https://developer.blender.org/D11683
This commit is contained in:
Philipp Oeser 2021-06-23 13:25:40 +02:00
parent 0416aa767f
commit d0c5c67e94
Notes: blender-bot 2023-02-14 07:36:17 +01:00
Referenced by issue #89369, Making single user for linked animation in Object data properties doesn't work
2 changed files with 40 additions and 7 deletions

View File

@ -2765,23 +2765,27 @@ class VIEW3D_MT_make_single_user(Menu):
props = layout.operator("object.make_single_user", text="Object")
props.object = True
props.obdata = props.material = props.animation = False
props.obdata = props.material = props.animation = props.obdata_animation = False
props = layout.operator("object.make_single_user", text="Object & Data")
props.object = props.obdata = True
props.material = props.animation = False
props.material = props.animation = props.obdata_animation = False
props = layout.operator("object.make_single_user", text="Object & Data & Materials")
props.object = props.obdata = props.material = True
props.animation = False
props.animation = props.obdata_animation = False
props = layout.operator("object.make_single_user", text="Materials")
props.material = True
props.object = props.obdata = props.animation = False
props.object = props.obdata = props.animation = props.obdata_animation = False
props = layout.operator("object.make_single_user", text="Object Animation")
props.animation = True
props.object = props.obdata = props.material = False
props.object = props.obdata = props.material = props.obdata_animation = False
props = layout.operator("object.make_single_user", text="Object Data Animation")
props.obdata_animation = props.obdata = True
props.object = props.material = props.animation = False
class VIEW3D_MT_object_convert(Menu):

View File

@ -2061,6 +2061,23 @@ static void single_object_action_users(
FOREACH_OBJECT_FLAG_END;
}
static void single_objectdata_action_users(
Main *bmain, Scene *scene, ViewLayer *view_layer, View3D *v3d, const int flag)
{
FOREACH_OBJECT_FLAG_BEGIN (scene, view_layer, v3d, flag, ob) {
if (!ID_IS_LINKED(ob) && ob->data != NULL) {
ID *id_obdata = (ID *)ob->data;
AnimData *adt = BKE_animdata_from_id(id_obdata);
ID *id_act = (ID *)adt->action;
if (id_act && id_act->us > 1) {
DEG_id_tag_update(&ob->id, ID_RECALC_GEOMETRY);
BKE_animdata_copy_id_action(bmain, id_obdata);
}
}
}
FOREACH_OBJECT_FLAG_END;
}
static void single_mat_users(
Main *bmain, Scene *scene, ViewLayer *view_layer, View3D *v3d, const int flag)
{
@ -2643,6 +2660,10 @@ static int make_single_user_exec(bContext *C, wmOperator *op)
single_object_action_users(bmain, scene, view_layer, v3d, flag);
}
if (RNA_boolean_get(op->ptr, "obdata_animation")) {
single_objectdata_action_users(bmain, scene, view_layer, v3d, flag);
}
BKE_main_id_newptr_and_tag_clear(bmain);
WM_event_add_notifier(C, NC_WINDOW, NULL);
@ -2684,8 +2705,16 @@ void OBJECT_OT_make_single_user(wmOperatorType *ot)
RNA_def_boolean(ot->srna, "object", 0, "Object", "Make single user objects");
RNA_def_boolean(ot->srna, "obdata", 0, "Object Data", "Make single user object data");
RNA_def_boolean(ot->srna, "material", 0, "Materials", "Make materials local to each data-block");
RNA_def_boolean(
ot->srna, "animation", 0, "Object Animation", "Make animation data local to each object");
RNA_def_boolean(ot->srna,
"animation",
0,
"Object Animation",
"Make object animation data local to each object");
RNA_def_boolean(ot->srna,
"obdata_animation",
0,
"Object Data Animation",
"Make object data (mesh, curve etc.) animation data local to each object");
}
/** \} */