Gildor's Forums

Author Topic: "Baking" Retargetted Animations  (Read 3294 times)
allenweisse
Newbie
*
Posts: 27


View Profile
"Baking" Retargetted Animations
« on: September 23, 2025, 04:53 »

As you may know, sometimes animations can look "weird" when importing into blender from umodel. The reason is typically that there is retargetting being performed per-bone. For example, a bone can have TranslationRetargetingMode set to Animation, Skeleton, etc., which affects the way the animation is played, and these changes aren't destructively applied when exporting (which is probably for the better)

The below script fixes this by modifying the fcurves of all actions in current file (be careful) to make it look the way it looks in umodel, i.e. correct.

Here's the code:




import bpy
import re

SKELETON_DUMP = """

"""

parsed_modes = {}
pattern = re.compile(r"^\s*BoneTree\[(\d+)\].*?TranslationRetargetingMode=\w+\s*\((\d+)\)")
for line in SKELETON_DUMP.splitlines():
    match = pattern.search(line)
    if match:
        parsed_modes[int(match.group(1))] = int(match.group(2))

armature = bpy.context.active_object
    
bone_name_to_index = {bone.name: i for i, bone in enumerate(armature.data.bones)}
index_to_bone_name = {i: bone.name for i, bone in enumerate(armature.data.bones)}

for action in bpy.data.actions:
    for bone_name, bone_index in bone_name_to_index.items():
        if parsed_modes.get(bone_index) == 1:
            for i in range(3):
                fcurve = action.fcurves.find(f'pose.bones["{bone_name}"].location', index=i)
                if fcurve:
                    for key in fcurve.keyframe_points:
                        key.co[1] = 0.0



To use it, you must dump the skeleton being used by opening the skeleton and pressing D in umodel. Check console for the dumped properties and place them in the SKELETON_DUMP variable, then select your armature and run the script.


* img1-q.png (65.18 KB, 728x533 - viewed 649 times.)

* img2-q.png (77.95 KB, 1042x761 - viewed 619 times.)

* img3-q.png (149.78 KB, 960x641 - viewed 647 times.)

* img4-q.png (135.14 KB, 956x657 - viewed 669 times.)
« Last Edit: September 23, 2025, 04:56 by allenweisse » Logged
spiritovod
Global Moderator
Hero Member
*****
Posts: 2830


View Profile
Re: "Baking" Retargetted Animations
« Reply #1 on: September 26, 2025, 18:42 »

@allenweisse: Thank you for the blender script, previously it was supported only in ActorX importer.

It's worth to note that required skeleton parameters are dumped to mesh_name.props.txt in case mesh is exported with animations to psk/psa format. I can add export of those properties to gltf export as well, like it was done for materials.
« Last Edit: September 26, 2025, 18:46 by spiritovod » Logged
allenweisse
Newbie
*
Posts: 27


View Profile
Re: "Baking" Retargetted Animations
« Reply #2 on: October 01, 2025, 02:17 »

@spiritovod: In general, that would be a nice addition. Though personally I dump all properties to a file (-dump /* -log=file) and from it I mkdirs generate the .props.txt for all objects.
Logged
Jump to:  

Powered by SMF | SMF © 2006-2009, Simple Machines LLC
Leviathan design by Bloc | XHTML | CSS