Code Monkey home page Code Monkey logo

blender-animation-retargeting's Introduction

Blender Animation Retargeting

This addon enables the transfer of animations and poses from one armature to another.

Installation

  1. Download this repo as .zip

  2. In Blender go to Edit > Preferences > Add-ons > Install...

  3. Select the downloaded .zip

  4. Enable the Add-on, which will appear in the list

How to use

Assuming you have both your target and source armature in the scene, and have them aligned and scaled to match each other.

Both armatures in rest pose next to each other, scaled to be same height

  1. Select your target armature and open the add-on panel on the right side of the 3D View (Retarget tab)

  2. Now choose the source armature as 'Source' on the panel

  3. It should say that there are no bone mappings, yet. Go ahead and click 'Create'.

  4. Now map each relevant source bone to the corresponding target. Make sure to not map any bone multiple times, otherwise you'll get undefined behaviour.

  5. Next you have to set up the rest pose alignment. Click on "Set up", then change the pose of your target armature in a way, that it optimally fits your source armatures rest pose. When done click 'Apply'.

pose adjusted to fit source's rest pose

  1. The add-on will then automatically create drivers for each bone, and you should be good to go.

Correction Features

Foot / Hand Positions Correction

If there's significant 'foot-sliding' or odd arm movements, due to anatomical differences between your armatures, you can turn on:

  • Correct Feet Position

  • Correct Hands Position

You will be asked to specify the leg/foot, arm/hand bones respectively.

This will create and IK bone setup for the specified limbs whereas the target positions for the feet/hands are copied over from the source.

Additionally it will spawn a control empty cube, that allows you to transform the target positions as shown in this gif:

demonstration of the ik correction transform cube

Baking

For convenience you can bake the source's animation into an action for your target via the add-on.

  • The option "Linear Interpolation" causes the F-Curves between the keyframes to be linearized instead of the default Blender Bezier interpolation.
  • The option "Bake Mapped Bones Only" ensures that target bones that have no retarget mapping will remain unaffected.

section for baking in the add-on panel

Since the target bones are driven by drivers, you can bake everything youself, if you want. Make sure to check 'Visual Keying' if you do so.

blender-animation-retargeting's People

Contributors

glitchypsix avatar manmohanbishnoi avatar mwni avatar mystfit avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

blender-animation-retargeting's Issues

Bake issue on Blender 3.1.0

When I try on the 3.1.0, I get the following error :

Error: Python: Traceback (most recent call last):
  File "/home/theo/.config/blender/3.1/scripts/addons/blender-animation-retargeting/baking.py", line 75, in execute
    transfer_anim(context)
  File "/home/theo/.config/blender/3.1/scripts/addons/blender-animation-retargeting/baking.py", line 52, in transfer_anim
    bpy.ops.nla.bake(
  File "/snap/blender/1925/3.1/scripts/modules/bpy/ops.py", line 132, in __call__
    ret = _op_call(self.idname_py(), None, kw)
TypeError: Converting py args to operator properties:  NLA_OT_bake.frame_start expected an int type, not float

However, on 3.0.0 it works fine...

Corrects seem to clear / reset the rest of the rig?

Hello! First off, thank you so much for building this addon. It's incredible seeing a retargetting tool finally come back to blender.

I'm having an issue with corrections - both hands and feet. Once I enable it (and set both hand+upper arm bones), the pose seems to reset, clearing all drivers on the whole rig. Strangely the arms seem to somewhat be animated, even without drivers. I'm guessing that has to do with the hands correction strategy?

Regardless, odd bug. Is this a known issue? It's almost like it had an error and stopped halfway through, but there are no errors in the command window.

Is the add-on compatible with 2.9?

Hello,
Is your tool not compatible with Blender 2.9 or am I not installing it correctly? I get this error when trying to enable it:

Traceback (most recent call last):
File "C:\Program Files\Blender Foundation\Blender 2.90\2.90\scripts\modules\addon_utils.py", line 351, in enable
mod = import(module_name)
File "C:\Users\jbh_work\AppData\Roaming\Blender Foundation\Blender\2.90\scripts\addons\addon.py", line 16, in
from . import data
ImportError: attempted relative import with no known parent package

add_on_error

Thanks!

Original animations cannot be seen after retargeting due to euler rotation mode

Scenario

  • scene has an armature with an associated animation action. this is the target
  • import a source armature which also has animations, and configure the retargeting plugin (bone mappings, rest alignment etc)
  • retargeting preview works
  • now check "disable drivers"
  • retargeting isn't seen any more, but original animation on target skeleton doesn't work any more

looking at the animation in the curve editor it seems like the keyframes are not impacted... they are just not being applied to the armature any more

interestingly, if there are bones not mapped in the plugin, those bones are animated. only the mapped bones don't get animated any more.

my guess is that somehow the plugin overwrites how blender normally applied animation keyframes to the target bones and "disable drivers" does not correctly undo this, but I don't know enough about blender to tell how to solve this problem.

the problem seems to persist after saving and reloading the file.

Inconsistent retargeting after initial bake

Hello! Just want to start by saying thank you for providing this addon! :)

I am noticing some issues while using this plugin, which only happen after the initial bake

In this first image, I have the animation set to a default idle pose. You can see the target mesh (textured) and the source mesh (untextured) - the alignment of the arm is pretty good.
image

However, after baking an different animation, re-enabling bone drivers, and selecting the same idle pose as the previous image, the arm alignment is now incorrect
image

I noticed this after working on some script extensions to batch import all motions from a target armature, but the result is the exact same if I do it all manually. Some animations seem to skew subsequent retargeting more than other animations.

After picking source rig, its not showing UI for mapping

Hi, i am using blender 2.82a.
i just downloaded and installed and it load correctly ( without any error )
my character is rigify rig and source is mixamo fbx loaded. after picking source, it simply doesn't show UI for mapping as you have shown in your readme.md
thanks for sharing code. regard,haseeb

New Bone Mapping Controls

Hi there @Mwni , I added some controls to my FFXIV MMD Tools Helper addon today to automate populating the bone mapping and make it easier for users of your addon to use. A lot of the time the bones names are in Japanese or Chinese on the source armature, while the target armature is (usually) in English, so typing in bone names into the mapping table is really hard to do. Making it easier to select a bone on the viewport and add it as a source bone or target bone would really go a long way for users.

I thought you might find some of it useful to integrate some additional controls of the mapping table into your own addon (then I can remove them from mine) :)

image

Video of it in action:

2023-11-30.16-46-10.mp4

Cheers!

Seeking Assistance with this Plugin Integration Using in Unity

I hope this message finds you well. I am a college student currently working on an undergraduate research project that involves utilizing Unity and Blender software. I am reaching out to you as I have encountered some challenges and would greatly appreciate your guidance.

In our project, we are developing an integrated system, and one of the key functionalities involves transferring human body movements from a video to a skeletal structure. We are using this plugin developed by you, and since our final platform is built on Unity, we need to replicate everything from Blender, including this plugin, in Unity.

For various aspects in Blender, such as bone binding, I have successfully used Python code files (bpy package) that can be directly invoked in Unity. However, I am encountering persistent errors with the plugin. The code segment responsible for calling the plugin works flawlessly in Blender but generates errors in Unity. The specific error messages are: [anim-retarget-addon] set source armature to Armature, [anim-retarget-addon] cleared IK controls, [anim-retarget-addon] cleared drivers.

I am truly in need of your expertise and assistance in resolving this issue. Any guidance or suggestions you can provide would be immensely valuable to our project. If possible, could you please share any insights or solutions you may have regarding this error?

Thank you very much for considering my request, and I sincerely hope to hear back from you soon. Your help would be greatly appreciated.

Best regards

Corrections function not working

Hello,
The addon works great except the corrections function with the emptys. The collections are there but there are no corretors for the rig. Is it because my rig already has an ik function? I used the rigify addon for it. Or do i have to manuel set it up? How?

Thank you

old .rtconfig file doesn't work by renaming it to .blend

An old .rtconfig file doesn't work by renaming it to .blend

I didn't create this .rtconfig file it's old but it's used as a template by FFXIV modders to map MMD (Miku Miku Dance) model animations to FFXIV models.

steps to reproduce:

  • open the included blender file in blender (walking rythmically.blend)
  • using latest version of RT addon, import the included config MMD Config REDO (rtconfig renamed to blend).blend

Using an older version of RT addon (apparently the version I have from January 2023, also included) works on the .rtconf file

blender version 3.6.5 LTS

included files:

  • old version and new version of animation retargeting plugin
  • MMD Tools addon (just incase there are any issues loading the blender file, included just in case but probably not needed)
  • MMD Config REDO.rtconf
  • MMD Config REDO (rtconfig renamed to blend).blend
  • walking rythmically.blend - sample blender file before using 'load config' in Animation Retargeting plugin
    old rtconfig file issue for mwni.zip

error message:

Traceback (most recent call last):
  File "C:\Users\wikid\AppData\Roaming\Blender Foundation\Blender\3.6\scripts\addons\blender-animation-retargeting-stable\context.py", line 35, in <lambda>
    target_bone: bpy.props.StringProperty(update=lambda self, ctx: update_ik_limbs(bpy.ctx.object.retargeting_context))
AttributeError: module 'bpy' has no attribute 'ctx'
File "C:\Users\wikid\AppData\Roaming\Blender Foundation\Blender\3.6\scripts\addons\blender-animation-retargeting-stable\context.py", line 35, in <lambda>
Traceback (most recent call last):
  File "C:\Users\wikid\AppData\Roaming\Blender Foundation\Blender\3.6\scripts\addons\blender-animation-retargeting-stable\context.py", line 36, in <lambda>
    origin_bone: bpy.props.StringProperty(update=lambda self, ctx: update_ik_limbs(bpy.ctx.object.retargeting_context))
AttributeError: module 'bpy' has no attribute 'ctx'
File "C:\Users\wikid\AppData\Roaming\Blender Foundation\Blender\3.6\scripts\addons\blender-animation-retargeting-stable\context.py", line 36, in <lambda>
Traceback (most recent call last):
  File "C:\Users\wikid\AppData\Roaming\Blender Foundation\Blender\3.6\scripts\addons\blender-animation-retargeting-stable\context.py", line 35, in <lambda>
    target_bone: bpy.props.StringProperty(update=lambda self, ctx: update_ik_limbs(bpy.ctx.object.retargeting_context))
AttributeError: module 'bpy' has no attribute 'ctx'
File "C:\Users\wikid\AppData\Roaming\Blender Foundation\Blender\3.6\scripts\addons\blender-animation-retargeting-stable\context.py", line 35, in <lambda>
Traceback (most recent call last):
  File "C:\Users\wikid\AppData\Roaming\Blender Foundation\Blender\3.6\scripts\addons\blender-animation-retargeting-stable\context.py", line 36, in <lambda>
    origin_bone: bpy.props.StringProperty(update=lambda self, ctx: update_ik_limbs(bpy.ctx.object.retargeting_context))
AttributeError: module 'bpy' has no attribute 'ctx'
File "C:\Users\wikid\AppData\Roaming\Blender Foundation\Blender\3.6\scripts\addons\blender-animation-retargeting-stable\context.py", line 36, in <lambda>
Traceback (most recent call last):
  File "C:\Users\wikid\AppData\Roaming\Blender Foundation\Blender\3.6\scripts\addons\blender-animation-retargeting-stable\context.py", line 35, in <lambda>
    target_bone: bpy.props.StringProperty(update=lambda self, ctx: update_ik_limbs(bpy.ctx.object.retargeting_context))
AttributeError: module 'bpy' has no attribute 'ctx'
File "C:\Users\wikid\AppData\Roaming\Blender Foundation\Blender\3.6\scripts\addons\blender-animation-retargeting-stable\context.py", line 35, in <lambda>
Traceback (most recent call last):
  File "C:\Users\wikid\AppData\Roaming\Blender Foundation\Blender\3.6\scripts\addons\blender-animation-retargeting-stable\context.py", line 36, in <lambda>
    origin_bone: bpy.props.StringProperty(update=lambda self, ctx: update_ik_limbs(bpy.ctx.object.retargeting_context))
AttributeError: module 'bpy' has no attribute 'ctx'
File "C:\Users\wikid\AppData\Roaming\Blender Foundation\Blender\3.6\scripts\addons\blender-animation-retargeting-stable\context.py", line 36, in <lambda>
Traceback (most recent call last):
  File "C:\Users\wikid\AppData\Roaming\Blender Foundation\Blender\3.6\scripts\addons\blender-animation-retargeting-stable\context.py", line 35, in <lambda>
    target_bone: bpy.props.StringProperty(update=lambda self, ctx: update_ik_limbs(bpy.ctx.object.retargeting_context))
AttributeError: module 'bpy' has no attribute 'ctx'
File "C:\Users\wikid\AppData\Roaming\Blender Foundation\Blender\3.6\scripts\addons\blender-animation-retargeting-stable\context.py", line 35, in <lambda>
Traceback (most recent call last):
  File "C:\Users\wikid\AppData\Roaming\Blender Foundation\Blender\3.6\scripts\addons\blender-animation-retargeting-stable\context.py", line 36, in <lambda>
    origin_bone: bpy.props.StringProperty(update=lambda self, ctx: update_ik_limbs(bpy.ctx.object.retargeting_context))
AttributeError: module 'bpy' has no attribute 'ctx'
File "C:\Users\wikid\AppData\Roaming\Blender Foundation\Blender\3.6\scripts\addons\blender-animation-retargeting-stable\context.py", line 36, in <lambda>
Traceback (most recent call last):
  File "C:\Users\wikid\AppData\Roaming\Blender Foundation\Blender\3.6\scripts\addons\blender-animation-retargeting-stable\savefile.py", line 28, in execute
    load_serialized_state(context.object.retargeting_context, json.load(f))
  File "C:\Users\wikid\AppData\Roaming\Blender Foundation\Blender\3.6\scripts\addons\blender-animation-retargeting-stable\savefile.py", line 103, in load_serialized_state
    ctx.setting_correct_feet = data['setting_correct_feet']
KeyError: 'setting_correct_feet'

Apply button is missing at "Rest alignment" step.

Spent couple of hours trying to understand what I am doing wrong. Apply button is missing at "Rest alignment" step. It turns out its a bug in 2.80.74 version. Reopened project in 2.83.3 and everything is fine.
Retargeting_bug2 80
Retargeting_bug2 83

Could you show code example to change target bone rotation order and driver expression?

It related with other issue though, I hope to keep target rig Euler rotation order, when retarget.
I check the code (you recommend to edit if user need to change way) and I can see you set all target rig bone Euler rotation as XYZ , then I know most of case it not break anything, but I need to keep the target rig bone rotation order for some reason.

I suppose you convert source bone "rotation matrix" as Euler (XYZ) then set driver for target bone rotation x, y, z property along with XYZ order. Then I can change target bone rotation as same as before.. (to YZX or YXZ), but I may need to set driver expression for each bones reculsively for new rotation order(YZX or YXZ)

I suppose if you show some hint, (which variable in code, may change target bone rotation driver expression to the new Euler rotation order), I may make it work (I hope so), then could you teach me some hint?

Retargeting Addon stuck

Upon selecting a Source Animation the addon gets stuck and I am unable to deselect source. I reinstalled the addon 2 times and the issue persists.
2024-06-12 16_45_17-_ TBSE + TBSE-X + IVCS Blender Kit 1_3mods  D__Gen2-Gen3_Converter_Body ressourc

Could you add option which can count correction future drive for baking?

Hi I really thanks you offer this add on. It worked well even though I mix use IK and FK animation for source rig then retarget.

At same time, to it work correctly I needed to set Correction Features of retarget IK about hand and feet or not work correctly. I suppose it related with the rig custom pole for IK and strucutre. but when I use Correction Feature (and keep those dirver active), this add on retarget pose , animation real time for target FK only rig.

Then I hope to bake the animation to target , but even though I try blender default bake animation, and this add on offered bake option, both not work. Of course I use visual transform option, and after bake animation I disable driver.. ..but it return strange rotation for the hand and foot.

I feel if it related with those Correction future. Is there way I can bake animation include correction future driven value for target rig? or it not matter to bake animaiton?

Add option to bake keyframes for mapped bones only?

I was wondering why the .blend-files I was using to bake the new retargeted actions into were getting so ridiculously large (>1 GB for 5 of the simplest Mixamo animations imported for testing, all only between 120 and 300 frames in length) - until I figured out that the Bake function had apparently created keyframes for every single bone in the armature even though I had only mapped 61...

The rig I was working with at the time has several hundred bones in it (it's a Rigify rig extended with lots of extra stuff - but even a regular Rigify rig including a facial rig will also already have a ton of bones you would typically not map - most notably the facial bones).

After manually purging all the unnecessary bone channels I got the file down to a measly 66MB. However, that is not really a feasible approach (it took me over an hour to manually clean up those 5 actions).

Would it be possible to optionally only bake keyframes for the bones that have actually been mapped? (which is what I had expected to happen - though I can certainly envision situations where it might come in handy to automatically bake additional bones at the same time, e.g. wiggle mechanics - so by all means keep this optional)

How do you bake multiple animations at once?

It's tedious to have to go through every animation in the source armature and select "Bake into Action".
By default users would want their target armature to be able to copy all the animations on the source armature. Why is this so difficult to achieve?

I tried "Batch FBX Import and Bake" on my scene that I've exported as .FBX, but that only flooded my scene with animations that are tied to objects which are not animated. And none of these animations actually animate the target armature's bones.
batch import and bake

Is there any solution to my issue?

Source Pose resets when trying to set up rest alignment

I am currently trying to retarget an exported BVH animation from Rokoko Studio to the Unreal Engine Skeleton. For this, I exported the Unreal Mannequin and imported it into Blender as FBX and then imported the BVH (which has no mesh), set up the bone mapping & ended up with this.

grafik

With the problem being that as I soon as I hit "Set Up" I am greeted with a "resetted" looking source pose.

grafik

I have attached the models and my bone mapping to this issue.

blender-anim-retargeting.zip

Mapping Presets

Anybody have mapping presets for this addon?
You know standard common mappings...
Mixamo ==> Rigify
Rigify ==> Mixamo
Mixamo ==> Unreal
Unreal ==> Mixamo

Would be great to have a library of presets..

getting the animation baked results in a error

Hi, I followed all the steps on a couple of armatures perfectly matching, the source armature have a animation linked, target armature follows. when I try to bake I had this:
image
what could be wrong?

addon not functioning, blender version compatibility?

i'm currently using Blender (2.8.0), i was able to install the addon, set bone mappings, then Save and Load configs correctly

however when trying to setup the rest pose, the "apply" button doesn't show up
image

i inspected the addons source code looking for the issue, i found out that (2.8.0) doesn't like "CHECKMARK" as an operator icon
so i replaced it with "X" as a workaround
image

now the Apply button shows up, but upon clicking it... nothing happens
it pretty much feels like clicking on "Cancel"
once again i inspected the Apply code, and its pretty much exactly the same as the "Cancel" code with an additional call to "store_matrices()"
image

but.... shouldn't there be more code? something like start_drivers() or something? (i haven't looked at all the source)
i'm quite confused on what happens next, since the addon's README states that : "The add-on will then automatically create drivers for each bone, and you should be good to go."

Quaternion mode?

This add-on seem to change many bones' rotation mode to euler which doesn't suit my needs at all. Plus, I think it breaks baking IK constraints entirely. I try to use blender's default pose bake and IK constraints just get deleted without impacting the bones

Option to have the retargeted animation over another animation

Hello! I want to firstly say that this tool is phenomenal as I've been looking for an accurate retargeting tool since the start of this mini-project I am working and helping in.
Although the question I want to pull is the following:
Is there any way to have the retargeted animation over another animation from its target?
In my case, I had the source and target, both with animations as the source has no hand animations. If I enable drivers it will look just like how I want, with the hands and quills from the target's animation, and the body, arms and legs from the source's animation:
https://github.com/Mwni/blender-animation-retargeting/assets/50070802/7a97aabd-2e1a-4955-ae14-325fb24073e8

After I Bake the source's animation, the hands and quills will be posed from the frame I stopped, leaving me with source's animation retargeted only and with no target's animation from the quills (which I didn't mapped them) and hands (there are none as seen from the previous video too):
https://github.com/Mwni/blender-animation-retargeting/assets/50070802/b7c823af-42a9-408e-a9e2-4020cbdd30ce

I will gladly wait for a response and possible solution, as I'm near the finish line for this little project and to end retargeting the animations I have left still.
Thank you for reading and apologies for any inconvenience!

Add Support for Library Override Linked Skeletons ?

Pipeline uses Control rigs set up as Library overrides, to allow for rig updates, customization without having to rework already animated scenes.
Currently this retargeter does not support selecting a source when the target is a Library override skeleton.
image

Error on blender 2.91

Hello,
I am getting an error on blender 2.91:

Python: Traceback (most recent call last):
  File "C:\Users\Trevor\AppData\Roaming\Blender Foundation\Blender\2.91\scripts\addons\blender-animation-retargeting-master\alignment.py", line 136, in execute
    leave_edit()
  File "C:\Users\Trevor\AppData\Roaming\Blender Foundation\Blender\2.91\scripts\addons\blender-animation-retargeting-master\alignment.py", line 75, in leave_edit
    s.update_drivers()
  File "C:\Users\Trevor\AppData\Roaming\Blender Foundation\Blender\2.91\scripts\addons\blender-animation-retargeting-master\addon.py", line 219, in update_drivers
    drivers.build()
  File "C:\Users\Trevor\AppData\Roaming\Blender Foundation\Blender\2.91\scripts\addons\blender-animation-retargeting-master\drivers.py", line 153, in build
    clear()
  File "C:\Users\Trevor\AppData\Roaming\Blender Foundation\Blender\2.91\scripts\addons\blender-animation-retargeting-master\drivers.py", line 116, in clear
    dest_pose.driver_remove('location')
AttributeError: 'NoneType' object has no attribute 'driver_remove'

location: <unknown location>:-1

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.