Skip to content

Commit

Permalink
ska2anm tool and fixes for old-style skanim
Browse files Browse the repository at this point in the history
  • Loading branch information
aap committed Aug 6, 2020
1 parent 171e737 commit 89901f9
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 2 deletions.
13 changes: 13 additions & 0 deletions premake5.lua
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,19 @@ project "lights"
removeplatforms { "*null" }
removeplatforms { "ps2" }

project "ska2anm"
kind "ConsoleApp"
characterset ("MBCS")
targetdir (Bindir)
files { path.join("tools/ska2anm", "*.cpp"),
path.join("tools/ska2anm", "*.h") }
debugdir ( path.join("tools/ska2nm") )
includedirs { "." }
libdirs { Libdir }
links { "librw" }
findlibs()
removeplatforms { "*gl3", "*d3d9", "*ps2" }

project "ps2test"
kind "ConsoleApp"
targetdir (Bindir)
Expand Down
7 changes: 5 additions & 2 deletions src/anim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,10 @@ Animation::streamReadLegacy(Stream *stream)
HAnimKeyFrame *frames = (HAnimKeyFrame*)anim->keyframes;
for(int32 i = 0; i < anim->numFrames; i++){
stream->read32(&frames[i].q, 4*4);
frames[i].q = conj(frames[i].q);
stream->read32(&frames[i].t, 3*4);
frames[i].time = stream->readF32();
int32 prev = stream->readI32();
int32 prev = stream->readI32()/0x24;
frames[i].prev = &frames[prev];
}
return anim;
Expand Down Expand Up @@ -159,10 +160,12 @@ Animation::streamWriteLegacy(Stream *stream)
assert(interpInfo->id == 1);
HAnimKeyFrame *frames = (HAnimKeyFrame*)this->keyframes;
for(int32 i = 0; i < this->numFrames; i++){
frames[i].q = conj(frames[i].q);
stream->write32(&frames[i].q, 4*4);
frames[i].q = conj(frames[i].q);
stream->write32(&frames[i].t, 3*4);
stream->writeF32(frames[i].time);
stream->writeI32(frames[i].prev - frames);
stream->writeI32((frames[i].prev - frames)*0x24);
}
return true;
}
Expand Down
83 changes: 83 additions & 0 deletions tools/ska2anm/ska2anm.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>

#include <rw.h>
#include <args.h>

using namespace rw;

char *argv0;

void
usage(void)
{
fprintf(stderr, "usage: %s in.ska [out.anm]\n", argv0);
fprintf(stderr, " or: %s in.anm [out.ska]\n", argv0);
exit(1);
}

int
main(int argc, char *argv[])
{
rw::Engine::init();
rw::registerHAnimPlugin();
rw::Engine::open(nil);
rw::Engine::start();

ARGBEGIN{
case 'v':
sscanf(EARGF(usage()), "%x", &rw::version);
break;
default:
usage();
}ARGEND;

if(argc < 1)
usage();

StreamFile stream;
if(!stream.open(argv[0], "rb")){
fprintf(stderr, "Error: couldn't open %s\n", argv[0]);
return 1;
}

int32 firstword = stream.readU32();
stream.seek(0, 0);
Animation *anim = nil;
if(firstword == ID_ANIMANIMATION){
// it's an anm file
if(findChunk(&stream, ID_ANIMANIMATION, nil, nil))
anim = Animation::streamRead(&stream);
}else{
// it's a ska file
anim = Animation::streamReadLegacy(&stream);
}
stream.close();

if(anim == nil){
fprintf(stderr, "Error: couldn't read anim file\n");
return 1;
}

const char *file;
if(argc > 1)
file = argv[1];
else if(firstword == ID_ANIMANIMATION)
file = "out.ska";
else
file = "out.anm";
if(!stream.open(file, "wb")){
fprintf(stderr, "Error: couldn't open %s\n", file);
return 1;
}
if(firstword == ID_ANIMANIMATION)
anim->streamWriteLegacy(&stream);
else
anim->streamWrite(&stream);

anim->destroy();

return 0;
}

0 comments on commit 89901f9

Please sign in to comment.