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 { }
https://www.turbosquid.com/FullPreview/ ... 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};
end
local bones = {};
local info = Spring.GetUnitPieceInfo(unit,piece);
for i=1,3 do
info.offset[i] = offset[i]+info.offset[i];
end
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;
end
end
end
return bones;
end
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]);
end
end
end
end
end
-- 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];
animCmd[cmd.c](cmd.p,cmd.a,cmd.t,cmd.s);
end
if(i < #anim) then
local t = anim[i+1]['time'] - anim[i]['time'];
Sleep(t*33); -- sleep works on milliseconds
end
end
end