0 votes

I wrote a custom importer for my custom animation file and tested it by animating a mesh using bones.

On bind/rest pose the mesh with skeleton looks right but when I start animating the mesh gets deformed beyond recognition.

My animation data is in localspace. I'm trying to figure out why it doesn't work, so my question is does the animation in Godot require the frames be in different space other than local to hierarchy? modelspace? or am I doing this wrong?

My code for generating the animations:

var anim = Animation.new()

var numBones = file.get_16()
var numFrames = file.get_16()

for x in range(numBones):
    var trackId = anim.add_track(Animation.TYPE_TRANSFORM)
    var boneName  = ".:bone_%d" % x
    anim.track_set_path(trackId, boneName)
    anim.track_set_imported(trackId, true)
    anim.length = float(numFrames)/30

    for y in range(numFrames):
        var loc = Vector3(file.get_float(), file.get_float(), file.get_float())
        var rot = Quat(file.get_float(), file.get_float(), file.get_float(), file.get_float())
        var scale = Vector3(file.get_float(), file.get_float(), file.get_float())

        anim.transform_track_insert_key(trackId, float(y)/30, loc, rot, scale)


return ResourceSaver.save("%s.%s" % [save_path, get_save_extension()], anim)

My code for creating the skeleton with bones:

var numBones = file.get_16()
for _x in range(numBones):
    var boneIndex  = file.get_16()
    var bonePIndex = file.get_16()

    var boneName  = "bone_%d" % boneIndex
    var bonePName = "bone_%d" % bonePIndex if bonePIndex >= 0 else ""

    var xAxis = Vector3(file.get_float(), file.get_float(), file.get_float())
    var yAxis = Vector3(file.get_float(), file.get_float(), file.get_float())
    var zAxis = Vector3(file.get_float(), file.get_float(), file.get_float())
    var origin = Vector3(file.get_float(), file.get_float(), file.get_float())

    var boneId = find_bone(boneName)
    if bonePName != "":
        var bonePId = find_bone(bonePName)
        set_bone_parent(boneId, bonePId)
    set_bone_rest(boneId, Transform(xAxis, yAxis, zAxis, origin))
asked Mar 4 in Engine by majidarif (24 points)
edited Mar 4 by majidarif

1 Answer

0 votes


Transform xform;
xform.basis.setquatscale(rot, scale);
xform.origin = pos;

Skeleton3D skeleton = state.skeletons[node->skeleton].godotskeleton;
int bone
idx = skeleton->findbone(node->name);
xform = skeleton->get
bonerest(boneidx).affine_inverse() * xform;

rot = xform.basis.getrotationquat();
scale = xform.basis.get_scale();
pos = xform.origin;

animation->transformtrackinsertkey(trackidx, time, pos, rot, scale);

answered Jun 24 by doggod (18 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.