Changeset View
Changeset View
Standalone View
Standalone View
source/blender/python/intern/bpy_rna_anim.c
| Show All 30 Lines | |||||
| #include "DNA_anim_types.h" | #include "DNA_anim_types.h" | ||||
| #include "DNA_scene_types.h" | #include "DNA_scene_types.h" | ||||
| #include "ED_keyframes_edit.h" | #include "ED_keyframes_edit.h" | ||||
| #include "ED_keyframing.h" | #include "ED_keyframing.h" | ||||
| #include "BKE_anim_data.h" | #include "BKE_anim_data.h" | ||||
| #include "BKE_animsys.h" | |||||
| #include "BKE_context.h" | #include "BKE_context.h" | ||||
| #include "BKE_fcurve.h" | #include "BKE_fcurve.h" | ||||
| #include "BKE_global.h" | #include "BKE_global.h" | ||||
| #include "BKE_idtype.h" | #include "BKE_idtype.h" | ||||
| #include "BKE_lib_id.h" | #include "BKE_lib_id.h" | ||||
| #include "BKE_report.h" | #include "BKE_report.h" | ||||
| #include "RNA_access.h" | #include "RNA_access.h" | ||||
| ▲ Show 20 Lines • Show All 280 Lines • ▼ Show 20 Lines | if (pyrna_struct_keyframe_parse(&self->ptr, | ||||
| "bpy_struct.keyframe_insert()", | "bpy_struct.keyframe_insert()", | ||||
| &path_full, | &path_full, | ||||
| &index, | &index, | ||||
| &cfra, | &cfra, | ||||
| &group_name, | &group_name, | ||||
| &options) == -1) { | &options) == -1) { | ||||
| return NULL; | return NULL; | ||||
| } | } | ||||
| else if (self->ptr.type == &RNA_NlaStrip) { | |||||
| /* This assumes that keyframes are only added on original data & using the active depsgraph. If | |||||
| * it turns out to be necessary for some reason to insert keyframes on evaluated objects, we can | |||||
| * revisit this and add an explicit `depsgraph` keyword argument to the function call. | |||||
brecht: My understanding is that it will never actually use the depsgraph here, because that's only… | |||||
| * | |||||
| * It is unlikely that driver code (which is the reason this depsgraph pointer is obtained) will | |||||
| * be executed from this function call, as this only happens when `options` has | |||||
| * `INSERTKEY_DRIVER`, which is not exposed to Python. */ | |||||
| bContext *C = BPy_GetContext(); | |||||
| struct Depsgraph *depsgraph = CTX_data_depsgraph_pointer(C); | |||||
| const AnimationEvalContext anim_eval_context = BKE_animsys_eval_context_construct(depsgraph, | |||||
| cfra); | |||||
| if (self->ptr.type == &RNA_NlaStrip) { | |||||
| /* Handle special properties for NLA Strips, whose F-Curves are stored on the | /* Handle special properties for NLA Strips, whose F-Curves are stored on the | ||||
| * strips themselves. These are stored separately or else the properties will | * strips themselves. These are stored separately or else the properties will | ||||
| * not have any effect. | * not have any effect. | ||||
| */ | */ | ||||
| ReportList reports; | ReportList reports; | ||||
| bool result = false; | bool result = false; | ||||
| PointerRNA ptr = self->ptr; | PointerRNA ptr = self->ptr; | ||||
| PropertyRNA *prop = NULL; | PropertyRNA *prop = NULL; | ||||
| const char *prop_name; | const char *prop_name; | ||||
| BKE_reports_init(&reports, RPT_STORE); | BKE_reports_init(&reports, RPT_STORE); | ||||
| /* Retrieve the property identifier from the full path, since we can't get it any other way */ | /* Retrieve the property identifier from the full path, since we can't get it any other way */ | ||||
| prop_name = strrchr(path_full, '.'); | prop_name = strrchr(path_full, '.'); | ||||
| if ((prop_name >= path_full) && (prop_name + 1 < path_full + strlen(path_full))) { | if ((prop_name >= path_full) && (prop_name + 1 < path_full + strlen(path_full))) { | ||||
| prop = RNA_struct_find_property(&ptr, prop_name + 1); | prop = RNA_struct_find_property(&ptr, prop_name + 1); | ||||
| } | } | ||||
| if (prop) { | if (prop) { | ||||
| NlaStrip *strip = ptr.data; | NlaStrip *strip = ptr.data; | ||||
| FCurve *fcu = BKE_fcurve_find(&strip->fcurves, RNA_property_identifier(prop), index); | FCurve *fcu = BKE_fcurve_find(&strip->fcurves, RNA_property_identifier(prop), index); | ||||
| result = insert_keyframe_direct( | |||||
| result = insert_keyframe_direct(&reports, ptr, prop, fcu, cfra, keytype, NULL, options); | &reports, ptr, prop, fcu, &anim_eval_context, keytype, NULL, options); | ||||
| } | } | ||||
| else { | else { | ||||
| BKE_reportf(&reports, RPT_ERROR, "Could not resolve path (%s)", path_full); | BKE_reportf(&reports, RPT_ERROR, "Could not resolve path (%s)", path_full); | ||||
| } | } | ||||
| MEM_freeN((void *)path_full); | MEM_freeN((void *)path_full); | ||||
| if (BPy_reports_to_error(&reports, PyExc_RuntimeError, true) == -1) { | if (BPy_reports_to_error(&reports, PyExc_RuntimeError, true) == -1) { | ||||
| return NULL; | return NULL; | ||||
| Show All 11 Lines | else { | ||||
| BLI_assert(BKE_id_is_in_global_main(id)); | BLI_assert(BKE_id_is_in_global_main(id)); | ||||
| result = (insert_keyframe(G_MAIN, | result = (insert_keyframe(G_MAIN, | ||||
| &reports, | &reports, | ||||
| id, | id, | ||||
| NULL, | NULL, | ||||
| group_name, | group_name, | ||||
| path_full, | path_full, | ||||
| index, | index, | ||||
| cfra, | &anim_eval_context, | ||||
| keytype, | keytype, | ||||
| NULL, | NULL, | ||||
| options) != 0); | options) != 0); | ||||
| MEM_freeN((void *)path_full); | MEM_freeN((void *)path_full); | ||||
| if (BPy_reports_to_error(&reports, PyExc_RuntimeError, true) == -1) { | if (BPy_reports_to_error(&reports, PyExc_RuntimeError, true) == -1) { | ||||
| return NULL; | return NULL; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 262 Lines • Show Last 20 Lines | |||||
My understanding is that it will never actually use the depsgraph here, because that's only used when options has INSERTKEY_DRIVER, which is not available in the Python API.
No harm in leaving the code since that would be a fragile assumption, but would be good to clarify the comment.