[Bf-blender-cvs] [27d097e92d5] master: Python API: expose conversion between tweaked NLA strip and scene time.

Alexander Gavrilov noreply at git.blender.org
Mon May 13 21:09:55 CEST 2019


Commit: 27d097e92d543b14ad5400c61fb3ae674064d0d5
Author: Alexander Gavrilov
Date:   Mon May 13 21:01:03 2019 +0300
Branches: master
https://developer.blender.org/rB27d097e92d543b14ad5400c61fb3ae674064d0d5

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.

===================================================================

M	source/blender/makesrna/intern/rna_animation.c
M	source/blender/makesrna/intern/rna_animation_api.c
M	source/blender/makesrna/intern/rna_internal.h

===================================================================

diff --git a/source/blender/makesrna/intern/rna_animation.c b/source/blender/makesrna/intern/rna_animation.c
index 5970149273e..6a5bae28cc1 100644
--- a/source/blender/makesrna/intern/rna_animation.c
+++ b/source/blender/makesrna/intern/rna_animation.c
@@ -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);
 }
 
 /* --- */
diff --git a/source/blender/makesrna/intern/rna_animation_api.c b/source/blender/makesrna/intern/rna_animation_api.c
index f201b8e6e99..e063e5de22c 100644
--- a/source/blender/makesrna/intern/rna_animation_api.c
+++ b/source/blender/makesrna/intern/rna_animation_api.c
@@ -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
diff --git a/source/blender/makesrna/intern/rna_internal.h b/source/blender/makesrna/intern/rna_internal.h
index 3653f28c880..fc0950c1bb0 100644
--- a/source/blender/makesrna/intern/rna_internal.h
+++ b/source/blender/makesrna/intern/rna_internal.h
@@ -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);



More information about the Bf-blender-cvs mailing list