Yesterday I spent part of the night trying to confirm that I cant reuse a
Mixamo animation in Godot in some simple way. In Unity the process,
though not trivial, was quite easy. I simply could not accept that
Godot, after so many years in development, would not let me use an
animation external to the model.
After looking at the editor, I tried the most obvious way: exported a model without animations and took my Mixamo generated FBXs containing the animations. To my surprise, if you export to FBX a model without animations, Godot doesnt imports it with a corresponding AnimationPlayer node, even if it has an armature. But if you export with the BetterCollada exporter it does include the AnimationPlayer, without animations, of course. With the model imported, there was no way to force it to use the Mixamo animations. But if you open the animations, you can use the Animation tool to save the animation data, and load it in your model. I did it! I thought.
Well, I didnt. Yes, you can make your model load the external animation track you previously saved. But it wont work. In the best case, your whole model will wag, or some parts will move, dragging the other inmobile parts. I even tried with the 4.0 branch from github and made most of my tests there: exporting to Collada, FBX and GlFT.
Why do I insist in this? You can perfectly make the game without it. But I think that it is more optimal to have a single animation that can be reutilized by all the similar models, and that the engine should provide such feature. Probably Im not the only one who thinks that way.
This raised another question: how can i equip and unequip items? Well, I found the solution quickly. I exported the item mesh, the gloves in this case, with the armature, as I did with Unity (FBX worked fine). Then I saved the MeshInstance:
And did the same for the original body parts, the hands. For this case, I opened the exported model not as an inherited scene, because I was getting some errors saying that I had to make the mesh unique. In a script added to the top node in the character model (could be anywhere, of course), I put this:
extends Spatial
var gloves = "res://Models/male-alejandro-dae/iron_gloves_anim.tres"
var hands = "res://Models/male-alejandro-dae/male-hands.tres"
var equip:bool
# Called when the node enters the scene tree for the first time.
func _ready():
equip=false
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
if Input.is_key_pressed(KEY_SPACE):
if !equip:
var res = load(gloves)
get_node("varsoi_male/Skeleton/varsoiM_hands").mesh = res
equip = true
else:
var res = load(hands)
get_node("varsoi_male/Skeleton/varsoiM_hands").mesh = res
equip = false
Not the best way (consider that Im a total newbie), but pressing space switches from bare hands to gloves. The equiped gloves follow the character animation. I just get a weird error in the editor when running the project saying that the format of the required archive is unknown.
Now the next question is, what happens if I add an item, like an armor, using BoneAttachment? Will it follow the character animation? Well, I went to bed late, but got an answer to that too. Yes, you can use an static armor (that is, without armature) and place it in a BoneAttachment. It follows the character animation. Here I faced some problems: unlike the gloves, the exported mesh had a different scale and I had to play with it to make it fit. Both the gloves and armor came from the same blend file, I dont underestand why the difference. Perhaps because of the armature.
Even when I used 4.0, I think that all that can be implemented in 3.2 too, maybe with better results, as the Vulkan branch is quite unstable yet and the FBX importer has little flaws. Please if you have any suggestion to improve this, feel free to leave a comment.
After looking at the editor, I tried the most obvious way: exported a model without animations and took my Mixamo generated FBXs containing the animations. To my surprise, if you export to FBX a model without animations, Godot doesnt imports it with a corresponding AnimationPlayer node, even if it has an armature. But if you export with the BetterCollada exporter it does include the AnimationPlayer, without animations, of course. With the model imported, there was no way to force it to use the Mixamo animations. But if you open the animations, you can use the Animation tool to save the animation data, and load it in your model. I did it! I thought.
Well, I didnt. Yes, you can make your model load the external animation track you previously saved. But it wont work. In the best case, your whole model will wag, or some parts will move, dragging the other inmobile parts. I even tried with the 4.0 branch from github and made most of my tests there: exporting to Collada, FBX and GlFT.
Why do I insist in this? You can perfectly make the game without it. But I think that it is more optimal to have a single animation that can be reutilized by all the similar models, and that the engine should provide such feature. Probably Im not the only one who thinks that way.
This raised another question: how can i equip and unequip items? Well, I found the solution quickly. I exported the item mesh, the gloves in this case, with the armature, as I did with Unity (FBX worked fine). Then I saved the MeshInstance:
And did the same for the original body parts, the hands. For this case, I opened the exported model not as an inherited scene, because I was getting some errors saying that I had to make the mesh unique. In a script added to the top node in the character model (could be anywhere, of course), I put this:
extends Spatial
var gloves = "res://Models/male-alejandro-dae/iron_gloves_anim.tres"
var hands = "res://Models/male-alejandro-dae/male-hands.tres"
var equip:bool
# Called when the node enters the scene tree for the first time.
func _ready():
equip=false
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
if Input.is_key_pressed(KEY_SPACE):
if !equip:
var res = load(gloves)
get_node("varsoi_male/Skeleton/varsoiM_hands").mesh = res
equip = true
else:
var res = load(hands)
get_node("varsoi_male/Skeleton/varsoiM_hands").mesh = res
equip = false
Not the best way (consider that Im a total newbie), but pressing space switches from bare hands to gloves. The equiped gloves follow the character animation. I just get a weird error in the editor when running the project saying that the format of the required archive is unknown.
Now the next question is, what happens if I add an item, like an armor, using BoneAttachment? Will it follow the character animation? Well, I went to bed late, but got an answer to that too. Yes, you can use an static armor (that is, without armature) and place it in a BoneAttachment. It follows the character animation. Here I faced some problems: unlike the gloves, the exported mesh had a different scale and I had to play with it to make it fit. Both the gloves and armor came from the same blend file, I dont underestand why the difference. Perhaps because of the armature.
Even when I used 4.0, I think that all that can be implemented in 3.2 too, maybe with better results, as the Vulkan branch is quite unstable yet and the FBX importer has little flaws. Please if you have any suggestion to improve this, feel free to leave a comment.
Comments
Post a Comment