Python API: expose conversion between tweaked NLA strip and scene time.

This is necessary to correctly do low-level keyframe manipulation
in tweak mode, and the logic is complex enough that re-implementing
it in Python is impractical.
This commit is contained in:
Alexander Gavrilov 2019-05-13 21:01:03 +03:00
parent c6f975e3e5
commit 27d097e92d
Notes: blender-bot 2023-02-14 09:24:53 +01:00
Referenced by issue #64572, Blender cant find my gpu for cycles cuda
Referenced by issue #64530, Blender 2.8 crashes on de-selecting verts in mesh edit mode
Referenced by issue #64517, Old and standard behavior gone from navigation while Gizmo's active.
3 changed files with 31 additions and 0 deletions

View File

@ -1303,6 +1303,9 @@ static void rna_def_animdata(BlenderRNA *brna)
RNA_def_property_ui_text(
prop, "Use NLA Tweak Mode", "Whether to enable or disable tweak mode in NLA");
RNA_def_property_update(prop, NC_ANIMATION | ND_NLA, "rna_AnimData_update");
/* Animation Data API */
RNA_api_animdata(srna);
}
/* --- */

View File

@ -37,6 +37,7 @@
# include "BKE_context.h"
# include "BKE_report.h"
# include "BKE_nla.h"
# include "ED_keyframing.h"
@ -59,6 +60,11 @@ static void rna_KeyingSet_context_refresh(KeyingSet *ks, bContext *C, ReportList
}
}
static float rna_AnimData_nla_tweak_strip_time_to_scene(AnimData *adt, float frame, bool invert)
{
return BKE_nla_tweakedit_remap(adt, frame, invert ? NLATIME_CONVERT_UNMAP : NLATIME_CONVERT_MAP);
}
#else
void RNA_api_keyingset(StructRNA *srna)
@ -75,4 +81,25 @@ void RNA_api_keyingset(StructRNA *srna)
RNA_def_function_flag(func, FUNC_USE_CONTEXT | FUNC_USE_REPORTS);
}
void RNA_api_animdata(StructRNA *srna)
{
FunctionRNA *func;
PropertyRNA *parm;
/* Convert between action time and scene time when tweaking a NLA strip. */
func = RNA_def_function(
srna, "nla_tweak_strip_time_to_scene", "rna_AnimData_nla_tweak_strip_time_to_scene");
RNA_def_function_ui_description(func,
"Convert a time value from the local time of the tweaked strip "
"to scene time, exactly as done by built-in key editing tools. "
"Returns the input time unchanged if not tweaking.");
parm = RNA_def_float(
func, "frame", 0.0, MINAFRAME, MAXFRAME, "", "Input time", MINAFRAME, MAXFRAME);
RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
RNA_def_boolean(func, "invert", false, "Invert", "Convert scene time to action time");
parm = RNA_def_float(
func, "result", 0.0, MINAFRAME, MAXFRAME, "", "Converted time", MINAFRAME, MAXFRAME);
RNA_def_function_return(func, parm);
}
#endif

View File

@ -342,6 +342,7 @@ char *rna_Node_ImageUser_path(struct PointerRNA *ptr);
/* API functions */
void RNA_api_action(StructRNA *srna);
void RNA_api_animdata(struct StructRNA *srna);
void RNA_api_armature_edit_bone(StructRNA *srna);
void RNA_api_bone(StructRNA *srna);
void RNA_api_camera(StructRNA *srna);