JD2022-TU1/main/extern/Camcam/LIBS/Input/LoadANIM.cpp

177 lines
5 KiB
C++

#include "SCENE.H"
#include <process.h>
#include "MAD\MAD_Struct_V0.h"
#include "MAD\MAD_mem.h"
#define MEDIA_BASE ".\\Media\\"
#define TEXTURES_DIRECTORY ""//"Textures\\"
#define MESHES_DIRECTORY ""//"Meshs\\"
#define MATERIALS_DIRECTORY ""//"Mats\\"
#define OBJECTS_DIRECTORY ""//"Objects\\"
void COPYMATRIX(MATRIX *DST, MAD_Matrix *SRC);
extern u8 Upper(u8 P);
static u32 XAF_EOF = 0;
char XAF_GetNext(FILE *XAF)
{
char V;
if (fread(&V,1,1,XAF) == 0)
XAF_EOF = 1;
return V;
}
u32 XAF_GetNextBracket(FILE *XAF,char *Line)
{
u32 Counter;
Counter = 0;
while ((XAF_GetNext(XAF)!='<') && (!XAF_EOF)) {};
do
{
*(Line++) = XAF_GetNext(XAF);
Counter++;
}
while ((*(Line-1) != '>') && (!XAF_EOF) && (Counter < 2048));
*(Line-1) = 0;
return Counter;
}
u32 XAF_CMP(char *LineXAF,char *Name)
{
u32 Counter;
Counter = 0;
while (*LineXAF == 32) {LineXAF++;};
while ((Upper(*Name) == Upper(*LineXAF)) && (*Name) && (*LineXAF) )
{
Name++;
LineXAF++;
}
if (*Name == 0)
return 1;
else
return 0;
}
char *XAF_GETString(char *LineXAF,char *STRName)
{
u32 Counter;
char *Name;
Counter = 0;
do
{
Name = STRName;
while (*LineXAF == 32) {LineXAF++;};
while ((Upper(*Name) == Upper(*LineXAF)) && (*Name) && (*LineXAF) )
{
Name++;
LineXAF++;
}
if (*Name == 0) return LineXAF;
else if (*LineXAF) LineXAF++;
} while (*LineXAF);
return NULL;
}
u32 XAF_GETMatrix(char *LineXAF,MATRIX *M2s)
{
while (*LineXAF == 32) {LineXAF++;};M2s->I.x = IO_DecodeNumber(LineXAF);while ((*LineXAF) && (*LineXAF != 32)) {LineXAF++;};
while (*LineXAF == 32) {LineXAF++;};M2s->I.y = IO_DecodeNumber(LineXAF);while ((*LineXAF) && (*LineXAF != 32)) {LineXAF++;};
while (*LineXAF == 32) {LineXAF++;};M2s->I.z = IO_DecodeNumber(LineXAF);while ((*LineXAF) && (*LineXAF != 32)) {LineXAF++;};
while (*LineXAF == 32) {LineXAF++;};M2s->J.x = IO_DecodeNumber(LineXAF);while ((*LineXAF) && (*LineXAF != 32)) {LineXAF++;};
while (*LineXAF == 32) {LineXAF++;};M2s->J.y = IO_DecodeNumber(LineXAF);while ((*LineXAF) && (*LineXAF != 32)) {LineXAF++;};
while (*LineXAF == 32) {LineXAF++;};M2s->J.z = IO_DecodeNumber(LineXAF);while ((*LineXAF) && (*LineXAF != 32)) {LineXAF++;};
while (*LineXAF == 32) {LineXAF++;};M2s->K.x = IO_DecodeNumber(LineXAF);while ((*LineXAF) && (*LineXAF != 32)) {LineXAF++;};
while (*LineXAF == 32) {LineXAF++;};M2s->K.y = IO_DecodeNumber(LineXAF);while ((*LineXAF) && (*LineXAF != 32)) {LineXAF++;};
while (*LineXAF == 32) {LineXAF++;};M2s->K.z = IO_DecodeNumber(LineXAF);while ((*LineXAF) && (*LineXAF != 32)) {LineXAF++;};
while (*LineXAF == 32) {LineXAF++;};M2s->T.x = IO_DecodeNumber(LineXAF);while ((*LineXAF) && (*LineXAF != 32)) {LineXAF++;};
while (*LineXAF == 32) {LineXAF++;};M2s->T.y = IO_DecodeNumber(LineXAF);while ((*LineXAF) && (*LineXAF != 32)) {LineXAF++;};
while (*LineXAF == 32) {LineXAF++;};M2s->T.z = IO_DecodeNumber(LineXAF);while ((*LineXAF) && (*LineXAF != 32)) {LineXAF++;};
return 1;
}
void XAF_TO_TRK(char *XAFName,char *TRKName)
{
FILE *XAF;
char Line[2048];
char ObjectName[2048];
u32 startTick,endTick,frameRate,ticksPerFrame;
u32 CurrentT,SampleCounter;
TrackPlayer Trck;
memset(&Trck,0,sizeof(Trck));
u32 CurrentNodeIndex = -1;
startTick=endTick=frameRate=ticksPerFrame=0;
XAF_EOF = 0;
SampleCounter = 0;
XAF = CC_fopen(XAFName,"rb");
if (XAF)
{
while (!XAF_EOF)
{
char *LocalStr;
XAF_GetNextBracket(XAF,Line);
if (XAF_CMP(Line,"SceneInfo fileName="))
{
if (LocalStr = XAF_GETString(Line,"ticksPerFrame=\""))
ticksPerFrame = (int)IO_DecodeNumber(LocalStr);
if (LocalStr = XAF_GETString(Line,"startTick=\""))
startTick = (int)IO_DecodeNumber(LocalStr);
if (LocalStr = XAF_GETString(Line,"endTick=\""))
endTick = (int)IO_DecodeNumber(LocalStr);
if (LocalStr = XAF_GETString(Line,"frameRate=\""))
frameRate = (int)IO_DecodeNumber(LocalStr);
} else
if (XAF_CMP(Line,"Node name="))
{
if (LocalStr = XAF_GETString(Line,"Node name=\""))
{
SampleCounter = 0;
while (*LocalStr && (*LocalStr != '"'))
ObjectName[SampleCounter++] = Upper(*(LocalStr++));
ObjectName[SampleCounter++] = '.';
ObjectName[SampleCounter++] = 'O';
ObjectName[SampleCounter++] = 'B';
ObjectName[SampleCounter++] = 'J';
ObjectName[SampleCounter] = 0;
CurrentNodeIndex++;
}
} else
if (XAF_CMP(Line,"Samples count="))
{
if (LocalStr = XAF_GETString(Line,"Samples count=\""))
SampleCounter = (int)IO_DecodeNumber(LocalStr);
} else
if (XAF_CMP(Line,"S t=") && SampleCounter)
{
if ((CurrentNodeIndex != -1) && (LocalStr = XAF_GETString(Line,"t=\"")))
{
MATRIX M2S;
CurrentT = ((int)IO_DecodeNumber(LocalStr))/ticksPerFrame;
if (LocalStr = XAF_GETString(Line,"v=\""))
{
if (XAF_GETMatrix(LocalStr,&M2S))
{
Trck.Set(CurrentNodeIndex,CurrentT,&M2S,3);
if (CurrentT < 10)
{
strcpy(Trck.TracksPtrs[CurrentNodeIndex].Name,ObjectName);
}
}
}
}
SampleCounter--;
} ;
}
CC_fclose(XAF);
}
SaveTrackPlayer(&Trck,TRKName);
FreeTrackPlayer(&Trck);
}