Skip to content

Commit

Permalink
Added Linear Loop Mode to looping animations
Browse files Browse the repository at this point in the history
  • Loading branch information
scotmcp committed Aug 10, 2024
1 parent c3a6725 commit d48cefe
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 14 deletions.
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,7 @@ We need make the animations Godot ready. If you are using a standard character m

6. Click on **Reimport** *Note: this step sometimes happens quickly, sometimes it takes a while. Be patient.*

7. *If you are using a standard character model, such as from Mixamo, you can skip this step and go stright to step 8. This step is for Synty characters only.*

While making sure the GLB file is still selected, go back to the Import Tab and assign **explosive_anim_import.gd** as the import script, and click on **Reimport**.
7. If you are using the **Synty character models**, then open the script and change the synty variable to **synty = true**, otherwise check it and make sure it is set to **synty = false.** While making sure the GLB file is still selected, go back to the Import Tab and assign **explosive_anim_import.gd** as the import script, and click on **Reimport**.

8. Verify the animation was imported correctly by adding the library to the animation player, testing each animation out.

Expand Down
46 changes: 35 additions & 11 deletions scripts/explosive_anim_import.gd
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,13 @@ extends EditorScenePostImport
## You can buy and download Explosive.ws animations for godot from:
## https://www.explosive.ws/products/rpg-animation-fbx-for-godot-blender



## ratio difference of leg length different between explosive.ws animation rigs and standard humanoid rigs.
## This ratio should be 0.115, but feel free to test and adjust as needed.
var keyframe_mod_ratio : float = 0.115

var animation_player : AnimationPlayer
var animation : Animation

## ratio difference of leg length different between explosive.ws animation rigs and Synty humanoid rigs.
## This ratio should be 0.115, but feel free to test and adjust as needed.
var synty : bool = false
var keyframe_mod_ratio : float = 0.115


## Called right after the scene is imported and gets the root node and iterates through each animation in the library
Expand All @@ -35,10 +33,12 @@ func _post_import(scene):
iterate(animation, anim_name)
return scene # Remember to return the imported scene

func iterate(animation, anim_name):
adjust_keyframes(animation, anim_name)
#print(animation)

func iterate(animation, anim_name) -> void:
if synty:
adjust_keyframes(animation, anim_name)
set_loop_mode(animation, anim_name)
print("Animation: " + str(anim_name) + " processing processing complete")


## Adjust the Hip bone placement so that it lines up with the Hip Bone on standard humanoid rigs.
func adjust_keyframes(animation: Animation, anim_name) -> void:
Expand All @@ -54,13 +54,37 @@ func adjust_keyframes(animation: Animation, anim_name) -> void:
for i in range(keyframe_count):
var keyframe_time = animation.track_get_key_time(track_index, i)
var keyframe_value = animation.track_get_key_value(track_index, i)

#if anim_name == "RelaxIdle":
#print("Original Keyframe Value: " + str(keyframe_value))
var keyframe_mod : float = keyframe_value.y * keyframe_mod_ratio
keyframe_value.y -= keyframe_mod
animation.track_set_key_value(track_index, i, keyframe_value)
#print("Modified Keyframe Value: " + str(keyframe_value))

print("Animation Keyframes adjusted")
## Set linear loop mode animation names that contain:
## "idle", "fall", "loop", "run", "sprint", "strafe", "stunned", "walk"
## but not "Loop-Start" or "Loop-End"
func set_loop_mode(animation, anim_name) -> void:
if "idle" in anim_name or "Idle" in anim_name or \
"fall" in anim_name or "Fall" in anim_name or \
"loop" in anim_name or "Loop" in anim_name or \
"run" in anim_name or "Run" in anim_name or \
"sprint" in anim_name or "Sprint" in anim_name or \
"strafe" in anim_name or "Strafe" in anim_name or \
"stunned" in anim_name or "Stunned" in anim_name or \
"walk" in anim_name or "Walk" in anim_name:
if "loop-end" in anim_name or "Loop-End" in anim_name or \
"loop-start" in anim_name or "Loop-Start" in anim_name:
return
else:
animation.loop_mode = animation.LOOP_LINEAR
print("Updated loop mode for animation: ", anim_name)

# Notify the user that the process is complete
print("Animation loop mode update complete.")
pass




0 comments on commit d48cefe

Please sign in to comment.