Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBastien Montagne <montagne29@wanadoo.fr>2014-04-28 15:26:01 +0400
committerBastien Montagne <montagne29@wanadoo.fr>2014-04-28 15:26:01 +0400
commitc08915042601c83022d352ba99026d13a18f73c2 (patch)
treebdabbdf859b4db7f55042d826ea69187ca0e28ba /release/scripts/startup/bl_operators
parent912151763d0a217ba53e3d566fae655d1f8b8553 (diff)
Fix T39806: Koro rig (Caminandes) wrong in master, worked in 270(a).
Edit existing animsys_refactor module to make able to execute more complex conversions ('to' can now be a callback, instead of a simple prop name), and add a new Update Animated Transform Constraints operator that uses it to handle complex conversion for this constraint (drived or animated properties). Note this operator has to be called manually (from 'space' menu), will make this clear in release notes. Also, similar changes made in 2.70 are *not* addressed by this script (would rather wrote new operators as/if need arise, but Transform constraint looks much more sensible that the others). This op should not remain in more than two or three releases anyway, imho.
Diffstat (limited to 'release/scripts/startup/bl_operators')
-rw-r--r--release/scripts/startup/bl_operators/anim.py85
1 files changed, 85 insertions, 0 deletions
diff --git a/release/scripts/startup/bl_operators/anim.py b/release/scripts/startup/bl_operators/anim.py
index 41f39b90464..01934542853 100644
--- a/release/scripts/startup/bl_operators/anim.py
+++ b/release/scripts/startup/bl_operators/anim.py
@@ -23,6 +23,7 @@ if "bpy" in locals():
if "anim_utils" in locals():
imp.reload(anim_utils)
+
import bpy
from bpy.types import Operator
from bpy.props import (IntProperty,
@@ -281,3 +282,87 @@ class ClearUselessActions(Operator):
self.report({'INFO'}, "Removed %d empty and/or fake-user only Actions"
% removed)
return {'FINISHED'}
+
+
+class UpdateAnimatedTransformConstraint(Operator):
+ """
+ Update fcurves/drivers affecting Transform constraints (use it with files from 2.70 and earlier)
+ """
+ bl_idname = "anim.update_animated_transform_constraints"
+ bl_label = "Update Animated Transform Constraints"
+ bl_options = {'REGISTER', 'UNDO'}
+
+ use_convert_to_radians = BoolProperty(
+ name="Convert To Radians",
+ description="Convert fcurves/drivers affecting rotations to radians (Warning: use this only once!)",
+ default=True,
+ )
+
+ def execute(self, context):
+ import animsys_refactor
+ from math import radians
+ import io
+
+ from_paths = {"from_max_x", "from_max_y", "from_max_z", "from_min_x", "from_min_y", "from_min_z"}
+ to_paths = {"to_max_x", "to_max_y", "to_max_z", "to_min_x", "to_min_y", "to_min_z"}
+ paths = from_paths | to_paths
+
+ def update_cb(base, class_name, old_path, fcurve, options):
+ print(options)
+ def handle_deg2rad(fcurve):
+ if fcurve is not None:
+ if hasattr(fcurve, "keyframes"):
+ for k in fcurve.keyframes:
+ k.co.y = radians(k.co.y)
+ for mod in fcurve.modifiers:
+ if mod.type == 'GENERATOR':
+ if mod.mode == 'POLYNOMIAL':
+ mod.coefficients[:] = [radians(c) for c in mod.coefficients]
+ else: # if mod.type == 'POLYNOMIAL_FACTORISED':
+ mod.coefficients[:2] = [radians(c) for c in mod.coefficients[:2]]
+ elif mod.type == 'FNGENERATOR':
+ mod.amplitude = radians(mod.amplitude)
+ fcurve.update()
+
+ data = ...
+ try:
+ data = eval("base." + old_path)
+ except:
+ pass
+ ret = (data, old_path)
+ if isinstance(base, bpy.types.TransformConstraint) and data is not ...:
+ new_path = None
+ map_info = base.map_from if old_path in from_paths else base.map_to
+ if map_info == 'ROTATION':
+ new_path = old_path + "_rot"
+ if options is not None and options["use_convert_to_radians"]:
+ handle_deg2rad(fcurve)
+ elif map_info == 'SCALE':
+ new_path = old_path + "_scale"
+
+ if new_path is not None:
+ data = ...
+ try:
+ data = eval("base." + new_path)
+ except:
+ pass
+ ret = (data, new_path)
+ #print(ret)
+
+ return ret
+
+ options = {"use_convert_to_radians": self.use_convert_to_radians}
+ replace_ls = [("TransformConstraint", p, update_cb, options) for p in paths]
+ log = io.StringIO()
+
+ animsys_refactor.update_data_paths(replace_ls, log)
+
+ context.scene.frame_set(context.scene.frame_current)
+
+ log = log.getvalue()
+ if log:
+ print(log)
+ text = bpy.data.texts.new("UpdateAnimatedTransformConstraint Report")
+ text.from_string(log)
+ self.report({'INFO'}, "Complete report available on '{}' text datablock".format(text.name))
+ return {'FINISHED'}