Skip to content

Commit

Permalink
Merge pull request #8 from /issues/7/support-2.83
Browse files Browse the repository at this point in the history
Add 2.83 support
  • Loading branch information
igelbox authored Aug 19, 2020
2 parents e78a64d + 51b11f0 commit 96bbb56
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ cache:
- blender

env:
- BLENDER_VERSION=2.81
- BLENDER_VERSION=2.83

install:
- sh ./tests/ci-prepare.sh
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ The main goal is to __link/synchronize__ target armature __bones__ with a source
Thus, allowing you to __use your next favorite tools__ for baking/exporting/using the result motions. For the glory of the Unix way.

# How to Install
* For Blender 2.80+ - use *animation-retarget-x.x.x.zip* from the [latest release](https://github.com/igelbox/blender-retarget/releases/latest) page.
* For Blender 2.80+ (except 2.82) - use *animation-retarget-x.x.x.zip* from the [latest release](https://github.com/igelbox/blender-retarget/releases/latest) page.
* For Blender 2.79 - the initial [animation-retarget-0.1.0.zip](https://github.com/igelbox/blender-retarget/releases/download/v0.1.0/animation-retarget-0.1.0.zip) should work fine.

_Blender 2.82 isn't supported by this addon coz there's no known trick to force `depsgraph` to refresh pose on each frame._

# How to Use
- Select the destination armature object in a 3D View area
- Go to the Object Properties panel
Expand Down
42 changes: 39 additions & 3 deletions animation_retarget/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

__CONFIG_PREFIX_BONE__ = 'bone:'

__TRICK_BLENDER28_ACTION_PREFIX__ = 'Just-a-Trick-to-Refresh'
__TRICK_BLENDER28_PREFIX__ = 'Just-a-Trick-to-Refresh'


def mapping_to_text(target_obj):
Expand Down Expand Up @@ -99,18 +99,48 @@ def clear_mapping(target_obj):
bpy.context.view_layer.update()


def need_to_trick_blender28(target_obj):
if not target_obj.animation_retarget.source:
return False

animation_data = target_obj.animation_data
if not animation_data:
return True
if not animation_data.action:
return True

for fcurve in animation_data.drivers:
for var in fcurve.driver.variables:
for target in var.targets:
if target.data_path == 'animation_retarget.fake_dependency':
return False
return bool(animation_data.drivers) # not empty


def trick_blender283(target_obj, driver):
var = driver.variables.new()
var.name = __TRICK_BLENDER28_PREFIX__
tgt = var.targets[0]
tgt.id = bpy.data.objects[target_obj.animation_retarget.source]
tgt.data_path = 'animation_retarget.fake_dependency'


def trick_blender28(target_obj):
animation_data = target_obj.animation_data_create()
action = animation_data.action
if not action:
for act in bpy.data.actions:
if act.name.startswith(__TRICK_BLENDER28_ACTION_PREFIX__):
if act.name.startswith(__TRICK_BLENDER28_PREFIX__):
action = act
break
if not action:
action = bpy.data.actions.new(__TRICK_BLENDER28_ACTION_PREFIX__)
action = bpy.data.actions.new(__TRICK_BLENDER28_PREFIX__)
animation_data.action = action

for fcurve in animation_data.drivers:
trick_blender283(target_obj, fcurve.driver)
break


class RelativeObjectTransform(bpy.types.PropertyGroup):
b_type = bpy.types.Object
Expand All @@ -130,6 +160,10 @@ def _update_source(self, _context):
update=_update_source,
)

fake_dependency: bpy.props.FloatProperty(
description='Trick the depsgraph to force Target armature drivers update',
get=lambda _s: 0,
)

def _prop_to_pose_bone(obj, prop):
for bone in obj.pose.bones:
Expand Down Expand Up @@ -183,6 +217,7 @@ def _set_use_rotation(self, value):
tgt.data_path = 'pose.bones["%s"].animation_retarget.transform[%d]' % (
bone.name, fcurve.array_index + 3
)
trick_blender283(self.id_data, driver)

use_rotation: bpy.props.BoolProperty(
name='Link Rotation',
Expand Down Expand Up @@ -213,6 +248,7 @@ def _set_use_location(self, value):
tgt.data_path = 'pose.bones["%s"].animation_retarget.transform[%d]' % (
bone.name, fcurve.array_index
)
trick_blender283(self.id_data, driver)

use_location: bpy.props.BoolProperty(
name='Link Location',
Expand Down
9 changes: 4 additions & 5 deletions animation_retarget/ops.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import bpy

from .core import mapping_to_text, text_to_mapping, clear_mapping, trick_blender28
from .core import mapping_to_text, text_to_mapping, clear_mapping
from .core import trick_blender28, need_to_trick_blender28

WM = bpy.context.window_manager

Expand Down Expand Up @@ -81,10 +82,8 @@ def poll(cls, context):
if not target_obj.animation_retarget.source:
return False # No worries, we fix this on source prop update

animation_data = target_obj.animation_data
if animation_data and animation_data.action:
return False
return True
return need_to_trick_blender28(target_obj)


__CLASSES__ = (
OBJECT_OT_CopyMapping,
Expand Down
27 changes: 27 additions & 0 deletions tests/cases/test_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,33 @@ def test_clear(self):
self.assertFalse(prop.use_location)
self.assertFalse(prop.use_rotation)

def test_trick(self):
operator = bpy.ops.animation_retarget.trick_blender
# no armature
self.assertFalse(operator.poll())

src = create_armature('src')
tgt = create_armature('tgt')
tgt.animation_retarget.source = src.name
prop = tgt.pose.bones['root'].animation_retarget
prop.source = 'root'

self.assertFalse(operator.poll())
prop.use_location = True
prop.use_rotation = True

# tricked automatically
self.assertFalse(operator.poll())


for fcurve in tgt.animation_data.drivers:
variables = fcurve.driver.variables
variables.remove(variables['Just-a-Trick-to-Refresh'])
self.assertTrue(operator.poll())

operator()
self.assertFalse(operator.poll())


def create_armature(name):
arm = bpy.data.armatures.new(name)
Expand Down
6 changes: 3 additions & 3 deletions tests/ci-prepare.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ set -e
DIR="blender/$BLENDER_VERSION"
if [ ! -e "$DIR/blender" ]; then
PYTHON_VERSION="3.7"
TBZ="blender-$BLENDER_VERSION-linux-glibc217-x86_64.tar.bz2"
ARC="blender-$BLENDER_VERSION.4-linux64.tar.xz"

mkdir -p "$DIR"
wget "http://download.blender.org/release/Blender$BLENDER_VERSION/$TBZ"
tar jxf $TBZ -C "$DIR" --strip-components 1
wget "http://download.blender.org/release/Blender$BLENDER_VERSION/$ARC"
tar xf $ARC -C "$DIR" --strip-components 1

TGT="$HOME/.config/blender/$BLENDER_VERSION/scripts/addons"
mkdir -p $TGT
Expand Down

0 comments on commit 96bbb56

Please sign in to comment.