DarklightGames / io_scene_psk_psa

A Blender extension for importing and exporting Unreal PSK and PSA files
GNU General Public License v3.0
312 stars 20 forks source link

Add option to import actions as additive animations relative to a base pose #27

Open Noterstone opened 1 year ago

Noterstone commented 1 year ago

Hello! Is it possible to add a function to add the first frame of the animation (BasePose) to the frames of the additive animation? There are two blending modes for additive animations: LocalSpace and MeshSpace. This could be a very useful feature for many. Blend mode difference: https://docs.unrealengine.com/4.27/en-US/AnimatingObjects/SkeletalMeshAnimation/AimOffset/

cmbasnett commented 1 year ago

@Noterstone I'm not sure I understand what the feature request is since I'm not familiar with this feature.

Would it be to insert one frame of animation from the "base" pose on other animations?

image

So for example, the Base Idle Pose would be frame 0 and Upward Anim would be frame 1?

Noterstone commented 1 year ago

To restore an additive animation, you just need to take the first frame of the base animation, and the frame of the additive animation. Everything is simple.

For the case of additive animation in LocalSpace mode blending:

additiveAnimationBone.localPosition += baseFrameBone.localPosition
additiveAnimationBone.localEulerRotation += baseFrameBone.localEulerRotation
//(OR) additiveAnimationBone.localQuaternionRotation*= baseFrameBone.localQuaternionRotation
additiveAnimationBone.localScale *= baseFrameBone.localScale

For the case of additive animation in MeshSpace mode blending:

baseFrameBone.localPosition += baseFrameBone.localPosition
additiveAnimationBone.localEulerRotation = baseFrameBone.localEulerRotation - baseFrameBone.GetParentBone().localEulerRotation
//(OR) additiveAnimationBone.localQuaternionRotation = baseFrameBone.localQuaternionRotation * (baseFrameBone.localQuaternionRotation * InverseQuaternion(baseFrameBone.GetParentBone().localQuaternionRotation))
3)additiveAnimationBone.localScale *= baseFrameBone.localScale

I tried to restore the additive animation that was exposed in LocalSpace. But I couldn't translate position, rotation and scale from POSE space to local space.

psa_additive_anim_restore.py

Noterstone commented 1 year ago

comment - 91 line

psa_additive_anim_restore.py.txt

Noterstone commented 1 year ago

Someone managed to do this for 3dsMax (see AdditiveAnimsAlter.ms). I think the functionality can be done for the import plugin for Blender https://github.com/PeterZhenhh/PSA_ImportHelper

cmbasnett commented 1 year ago

I think I understand now. So you want a new function on the PSA import, where each selected action is imported as though it is an additive animation on top of a specified base pose? If that's the case, that should be simple enough to do. Please confirm if that sounds correct. I just want to make sure I fully understand before I actually write anything! :)

Noterstone commented 1 year ago

Cool) yes)

cmbasnett commented 1 year ago

@Noterstone Would you be able to provide a PSK and PSA for testing? I prefer to work with real data for testing purposes.

Noterstone commented 1 year ago

Sure, no problem! In the archive, the character, and animations in psa and also in fbx (and the results so that you can check the correctness of the restoration) ForTest.zip

Noterstone commented 1 year ago

You can also see how it is implemented in UnrealEngine in terms of calculations. The method in which the logic is written begins on the line 1593. The essence of the calculations that takes place there, I described above in the messages. https://github.com/EpicGames/UnrealEngine/blob/46544fa5e0aa9e6740c19b44b0628b72e7bbd5ce/Engine/Source/Runtime/Engine/Private/Animation/AnimationRuntime.cpp

cmbasnett commented 1 year ago

Thanks, I'm fairly busy at the moment but I will get around to this eventually. It might also be something that could just be added to Blender's native functionality (e.g., taking one action and transforming it so that is it an additive animation of another action).

AleksKavil commented 1 year ago

Thanks, I'm fairly busy at the moment but I will get around to this eventually. It might also be something that could just be added to Blender's native functionality (e.g., taking one action and transforming it so that is it an additive animation of another action).

I'm looking forward to you adding this feature