Page 1 of 1

Exporting Animations from Blender & Play them

Posted: 19 Feb 2019, 14:49
by Revolvern

Is there any way to export an animation and play it in spring engine? Is there any tutorial? I have tried to get this to work for a month.

Note: No need to answer how to rotate stuff, this is not what I'm asking for. I have a bunch with model's in blender that have been animated and
I'm not planning todo it manually in code.

* The built-in LUA exporter just gives me something like

Code: Select all

return { }
* I have tried other animations then my own, like this one: ... ID/1012108
* I have tried blender2lus which gives me a file with a function that is called PlayAnimation, which I can't find used in any other spring mod.

Code: Select all

local Animations = {};
-- you can include externally saved animations like this:
-- Animations['importedAnimation'] = VFS.Include("Scripts/animations/animationscript.lua", scriptEnv)

Animations['idle'] = {


function constructSkeleton(unit, piece, offset)
    if (offset == nil) then
        offset = {0,0,0};

    local bones = {};
    local info = Spring.GetUnitPieceInfo(unit,piece);

    for i=1,3 do
        info.offset[i] = offset[i]+info.offset[i];

    bones[piece] = info.offset;
    local map = Spring.GetUnitPieceMap(unit);
    local children = info.children;

    if (children) then
        for i, childName in pairs(children) do
            local childId = map[childName];
            local childBones = constructSkeleton(unit, childId, info.offset);
            for cid, cinfo in pairs(childBones) do
                bones[cid] = cinfo;
    return bones;

function script.Create()
    local map = Spring.GetUnitPieceMap(unitID);
    local offsets = constructSkeleton(unitID,map.Scene, {0,0,0});
    for a,anim in pairs(Animations) do
        for i,keyframe in pairs(anim) do
            local commands = keyframe.commands;
            for k,command in pairs(commands) do
                -- commands are described in (c)ommand,(p)iece,(a)xis,(t)arget,(s)peed format
                -- the t attribute needs to be adjusted for move commands from blender's absolute values
                if (command.c == "move") then
                    local adjusted =  command.t - (offsets[command.p][command.a]);
                    Animations[a][i]['commands'][k].t = command.t - (offsets[command.p][command.a]);
-- local animCmd = {['idle']=Turn, ['turn']=Turn,['move']=Move};
local animCmd = {['turn']=Turn,['move']=Move};
function PlayAnimation(animname)
    local anim = Animations[animname];
    for i = 1, #anim do
        local commands = anim[i].commands;
        for j = 1,#commands do
            local cmd = commands[j];
        if(i < #anim) then
            local t = anim[i+1]['time'] - anim[i]['time'];
            Sleep(t*33); -- sleep works on milliseconds

Re: Exporting Animations from Blender & Play them

Posted: 22 Feb 2019, 15:25
by Anarchid

At least the deer model you've linked uses Armature based animations. This is not supported by blender2lus, because it isn't really supported by Spring due to a bunch of reasons:

- There's no skinning shader for Spring, so there's no need to use skeletons
- The axis mapping in Blender gets a bit confused when imported into Spring.

You'll need to cut your model into individual Objects, which will have to have their own keyframes. Can you post the actual for-Spring model that you try to animate?