2001-01-06 00:02:31 +01:00
|
|
|
/**********************************/
|
|
|
|
/*** SpongeBob 3d Actor Creator ***/
|
|
|
|
/**********************************/
|
|
|
|
|
|
|
|
#include "stdio.h"
|
|
|
|
#include <misc.hpp>
|
|
|
|
#include <conio.h>
|
|
|
|
#include <iostream.h>
|
|
|
|
#include <vector>
|
2001-02-08 15:04:49 +01:00
|
|
|
#include <DaveLib.h>
|
2001-01-06 00:02:31 +01:00
|
|
|
#include <FaceStore.h>
|
|
|
|
|
|
|
|
#include "MkActor3d.h"
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
//***************************************************************************
|
2001-02-27 20:03:36 +01:00
|
|
|
vector<CMkActor3d> ActorList;
|
|
|
|
int TPBase=-1,TPWidth=-1,TPHeight=-1;
|
|
|
|
GString TPOutStr;
|
2001-02-26 21:14:08 +01:00
|
|
|
//std::vector<GString> ExtraTex;
|
2001-01-06 00:02:31 +01:00
|
|
|
|
2001-02-27 20:03:36 +01:00
|
|
|
CTexGrab CMkActor3d::TexGrab;
|
|
|
|
|
2001-01-06 00:02:31 +01:00
|
|
|
//***************************************************************************
|
|
|
|
|
|
|
|
char * CycleCommands(char *String,int Num)
|
|
|
|
{
|
2001-02-26 21:14:08 +01:00
|
|
|
char Text[2048],*TextPtr;
|
2001-02-27 20:03:36 +01:00
|
|
|
int Count;
|
2001-01-06 00:02:31 +01:00
|
|
|
|
|
|
|
if (String[0]=='-' || String[0]=='/')
|
|
|
|
{
|
|
|
|
GString TpStr;
|
|
|
|
switch (String[1])
|
|
|
|
{
|
|
|
|
// Switches
|
|
|
|
case 'o':
|
|
|
|
OutStr = CheckFileString(String);
|
2001-02-27 20:03:36 +01:00
|
|
|
OutStr.Upper();
|
2001-03-01 18:03:15 +01:00
|
|
|
OutStr.Append('/');
|
2001-01-06 00:02:31 +01:00
|
|
|
break;
|
2001-02-01 23:48:22 +01:00
|
|
|
case 'i':
|
|
|
|
IncludeFile = CheckFileString(String);
|
2001-02-27 20:03:36 +01:00
|
|
|
IncludeFile.Upper();
|
2001-03-01 18:03:15 +01:00
|
|
|
IncludeFile.Append('/');
|
2001-02-01 23:48:22 +01:00
|
|
|
break;
|
2001-01-06 00:02:31 +01:00
|
|
|
case 'd':
|
|
|
|
DebugOn =true;
|
|
|
|
break;
|
|
|
|
case 's':
|
|
|
|
TpStr= CheckFileString(String);
|
|
|
|
Scale=atof(TpStr);
|
|
|
|
break;
|
2001-02-27 20:03:36 +01:00
|
|
|
case 'g':
|
|
|
|
TPOutStr= CheckFileString(String);
|
|
|
|
break;
|
2001-01-06 00:02:31 +01:00
|
|
|
case 't':
|
|
|
|
TpStr= CheckFileString(String);
|
|
|
|
TextPtr=Text;
|
|
|
|
strcpy(TextPtr,TpStr);
|
|
|
|
Count=ZeroAndCountCommas(TextPtr);
|
2001-02-26 21:14:08 +01:00
|
|
|
if (Count!=2) GObject::Error(ERR_FATAL,"Problem with option %s\n",String);
|
2001-01-06 00:02:31 +01:00
|
|
|
TPBase=atol(TextPtr);
|
|
|
|
TextPtr+=strlen(TextPtr)+1;
|
|
|
|
TPWidth=atol(TextPtr);
|
|
|
|
TextPtr+=strlen(TextPtr)+1;
|
|
|
|
TPHeight=atol(TextPtr);
|
2001-02-26 21:14:08 +01:00
|
|
|
break;
|
2001-01-06 00:02:31 +01:00
|
|
|
case 'q':
|
|
|
|
StripLength=4;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
GObject::Error(ERR_FATAL,"Unknown switch %s",String);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2001-02-27 20:03:36 +01:00
|
|
|
GString UpperName(String);
|
|
|
|
UpperName.Upper();
|
|
|
|
MyFiles.AddFile(UpperName);
|
2001-01-06 00:02:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return(String);
|
|
|
|
}
|
|
|
|
|
2001-02-26 21:14:08 +01:00
|
|
|
//***************************************************************************
|
|
|
|
|
|
|
|
void Usage(char *ErrStr)
|
|
|
|
{
|
2001-02-27 20:03:36 +01:00
|
|
|
printf("\nMkActor3d (usese scripts): by Dave\n");
|
2001-02-26 21:14:08 +01:00
|
|
|
printf("Usage: MkActor3d <file> [ <file>.. ] [ switches.. ]\n");
|
|
|
|
printf("Switches:\n");
|
|
|
|
printf(" -o:[FILE] Set output Dir\n");
|
|
|
|
printf(" -s:nn Set Scaling value\n");
|
|
|
|
printf(" -t:p,w,h Set TPage No,Width,Height\n");
|
|
|
|
printf(" -d: Enable Debug output\n");
|
|
|
|
printf(" -q: Enable Quadding\n");
|
|
|
|
GObject::Error(ERR_FATAL,ErrStr);
|
|
|
|
}
|
|
|
|
|
|
|
|
//***************************************************************************
|
|
|
|
int main (int argc, char *argv[])
|
|
|
|
{
|
2001-02-27 20:03:36 +01:00
|
|
|
int i,ListSize;
|
|
|
|
|
2001-02-26 21:14:08 +01:00
|
|
|
CommandLine(argc,argv,CycleCommands);
|
|
|
|
if (OutStr.Empty()) Usage("No Output File Set\n");
|
2001-02-27 20:03:36 +01:00
|
|
|
vector<GString> const &Files = MyFiles.GetFileInfoVector();
|
|
|
|
|
|
|
|
for (i=0; i<Files.size(); i++)
|
|
|
|
{
|
|
|
|
ActorList.push_back(CMkActor3d(Files[i]));
|
|
|
|
}
|
|
|
|
|
|
|
|
CMkActor3d::SetTPData(TPOutStr,TPBase,TPWidth,TPHeight);
|
|
|
|
|
|
|
|
ListSize=ActorList.size();
|
|
|
|
for (i=0; i<ListSize; i++)
|
|
|
|
{
|
|
|
|
ActorList[i].ActorLoad();
|
|
|
|
ActorList[i].ActorProcess();
|
|
|
|
ActorList[i].AnimLoad();
|
|
|
|
}
|
2001-03-12 18:11:40 +01:00
|
|
|
CMkActor3d::TexGrab.Process();
|
2001-02-26 21:14:08 +01:00
|
|
|
|
2001-02-27 20:03:36 +01:00
|
|
|
for (i=0; i<ListSize; i++)
|
|
|
|
{
|
|
|
|
ActorList[i].ActorWrite();
|
|
|
|
}
|
2001-02-26 21:14:08 +01:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2001-01-06 00:02:31 +01:00
|
|
|
//***************************************************************************
|
|
|
|
//***************************************************************************
|
|
|
|
//***************************************************************************
|
2001-02-27 20:03:36 +01:00
|
|
|
CMkActor3d::CMkActor3d(GString const &String)
|
2001-01-06 00:02:31 +01:00
|
|
|
{
|
2001-02-26 21:14:08 +01:00
|
|
|
GString UpperName(String);
|
|
|
|
UpperName.Upper();
|
|
|
|
GFName File=UpperName;
|
2001-01-08 22:40:41 +01:00
|
|
|
|
2001-02-26 21:14:08 +01:00
|
|
|
InFilename=UpperName;
|
2001-01-06 00:02:31 +01:00
|
|
|
InPath=File.Drive();
|
|
|
|
InPath+=File.Dir();
|
2001-03-12 18:11:40 +01:00
|
|
|
InPath.Append('\\');
|
2001-01-06 00:02:31 +01:00
|
|
|
Name=File.File();
|
2001-02-26 21:14:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//***************************************************************************
|
2001-02-27 20:03:36 +01:00
|
|
|
void CMkActor3d::SetTPData(const char *Name,int TPBase,int TPW,int TPH)
|
2001-02-26 21:14:08 +01:00
|
|
|
{
|
2001-02-27 20:03:36 +01:00
|
|
|
GString Filename=OutStr+Name;
|
|
|
|
GString IncName;
|
|
|
|
|
|
|
|
IncName=IncludeFile;
|
|
|
|
IncName+=Name;
|
|
|
|
|
|
|
|
TexGrab.SetTPage(TPBase,TPW,TPH);
|
|
|
|
TexGrab.SetOutFile(Filename+".Tex");
|
|
|
|
TexGrab.SetDebugOut(Filename+".Lbm");
|
|
|
|
TexGrab.SetIncFile(IncName+".h");
|
|
|
|
TexGrab.NoSort();
|
|
|
|
TexGrab.AnimatedHeadersOnly(true);
|
|
|
|
TexGrab.DontOutputBoxes(true);
|
|
|
|
TexGrab.AllowRotate(true);
|
2001-03-01 18:03:15 +01:00
|
|
|
TexGrab.FileRecursion(true);
|
2001-03-12 18:11:40 +01:00
|
|
|
|
2001-02-26 21:14:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//***************************************************************************
|
|
|
|
void CMkActor3d::ActorLoad()
|
2001-01-06 00:02:31 +01:00
|
|
|
{
|
2001-02-26 21:14:08 +01:00
|
|
|
OutFile=OutStr+Name;
|
|
|
|
IncFile=IncludeFile;
|
|
|
|
IncFile+="ACTOR_";
|
|
|
|
IncFile+=Name;
|
2001-01-06 00:02:31 +01:00
|
|
|
Scene.Load(InFilename);
|
2001-02-27 20:03:36 +01:00
|
|
|
ReadScript(InPath+"TexList.Txt",InTexList);
|
|
|
|
ReadScript(InPath+"AnimList.Txt",InAnimList);
|
|
|
|
}
|
|
|
|
|
|
|
|
//***************************************************************************
|
|
|
|
void CMkActor3d::ReadScript(const char *Filename,vector<GString> &List)
|
|
|
|
{
|
|
|
|
char *Script,*Ptr;
|
|
|
|
int Size;
|
|
|
|
File=fopen(Filename,"rb");
|
|
|
|
if (!File) return;
|
|
|
|
fseek(File,0,SEEK_END);
|
|
|
|
Size=ftell(File);
|
|
|
|
fseek(File,0,SEEK_SET);
|
|
|
|
Script=(char*)malloc(Size+1);
|
|
|
|
// Load It
|
|
|
|
fread(Script,Size,1,File);
|
|
|
|
fclose(File);
|
|
|
|
|
|
|
|
// Extract Names
|
|
|
|
Ptr=Script;
|
|
|
|
Script[Size]=0;
|
|
|
|
while (*Ptr)
|
|
|
|
{
|
|
|
|
GString Str;
|
|
|
|
|
|
|
|
while (*Ptr=='\n' || *Ptr=='\r'|| *Ptr==' ') *Ptr++; // Skip gaff
|
|
|
|
if (*Ptr)
|
|
|
|
{
|
|
|
|
if (*Ptr=='#')
|
|
|
|
{ // Skip commented lines
|
|
|
|
while (*Ptr!='\n' && *Ptr) Ptr++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{ // Read data
|
|
|
|
while (*Ptr!=' ' && *Ptr!='\n' && *Ptr!='\r' && *Ptr)
|
|
|
|
{
|
|
|
|
Str.Append(*Ptr++);
|
|
|
|
}
|
|
|
|
List.push_back(Str);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
free(Script);
|
2001-01-06 00:02:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//***************************************************************************
|
2001-01-30 18:39:20 +01:00
|
|
|
//***************************************************************************
|
|
|
|
//***************************************************************************
|
|
|
|
void CMkActor3d::BuildBoneOut(sBone &OutBone,CNode const &InNode,int ParentBoneIdx)
|
2001-01-06 00:02:31 +01:00
|
|
|
{
|
2001-01-30 18:39:20 +01:00
|
|
|
OutBone.BoneSize.vx =round(InNode.Pos.x*Scale);
|
|
|
|
OutBone.BoneSize.vy =round(InNode.Pos.y*Scale);
|
|
|
|
OutBone.BoneSize.vz =round(InNode.Pos.z*Scale);
|
|
|
|
OutBone.Parent=ParentBoneIdx;
|
|
|
|
OutBone.VtxCount=0;
|
|
|
|
OutBone.TriCount=0;
|
|
|
|
OutBone.TriStart=0;
|
2001-01-06 00:02:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//***************************************************************************
|
2001-01-30 18:39:20 +01:00
|
|
|
void CMkActor3d::ProcessSkel(int Idx,int ParentIdx)
|
2001-01-06 00:02:31 +01:00
|
|
|
{
|
2001-01-30 18:39:20 +01:00
|
|
|
CNode &ThisNode=Scene.GetNode(Idx);
|
|
|
|
CNode &ParentNode=Scene.GetNode(ThisNode.ParentIdx);
|
2001-01-06 00:02:31 +01:00
|
|
|
vector<sGinTri> const &NodeTriList = ThisNode.GetTris();
|
2001-02-01 23:48:22 +01:00
|
|
|
vector<Vector3> const &NodeVtxList = ThisNode.GetPts();
|
2001-01-06 00:02:31 +01:00
|
|
|
vector<int> const &NodeMatList = ThisNode.GetTriMaterial();
|
|
|
|
vector<sUVTri> const &NodeUVList = ThisNode.GetUVTris();
|
|
|
|
vector<GString> const &SceneTexList= Scene.GetTexList();
|
2001-01-30 18:39:20 +01:00
|
|
|
vector<int> const &SceneUsedMatList=Scene.GetUsedMaterialIdx();
|
|
|
|
|
|
|
|
int TriCount=NodeTriList.size();
|
|
|
|
int ThisIdx=Skel.size();
|
|
|
|
sGinSkel &ParentBone=Skel[ParentIdx];
|
|
|
|
vector<Vector3> VtxList;
|
|
|
|
|
|
|
|
if (!TriCount)
|
|
|
|
{ // Its a Bone!!
|
|
|
|
sGinSkel ThisBone;
|
|
|
|
BuildBoneOut(ThisBone.Bone,ThisNode,ParentIdx);
|
|
|
|
|
|
|
|
int WeightCount=ThisNode.Weights.size();
|
|
|
|
if (WeightCount)
|
|
|
|
{
|
2001-02-26 21:14:08 +01:00
|
|
|
// printf("%s %i\n",ThisNode.Name,WeightCount);
|
2001-01-30 18:39:20 +01:00
|
|
|
for (int i=0; i<WeightCount; i++)
|
|
|
|
{
|
|
|
|
sGinWeight &ThisWeight=ThisNode.Weights[i];
|
2001-02-01 23:48:22 +01:00
|
|
|
// printf("%i %f %f %f\t\n",ThisWeight.VertNo,NodeVtxList[ThisWeight.VertNo].x,NodeVtxList[ThisWeight.VertNo].y,NodeVtxList[ThisWeight.VertNo].z);
|
2001-01-30 18:39:20 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
Skel.push_back(ThisBone);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{ // Model, attach to parent bone
|
|
|
|
// build TX Vtx List
|
2001-02-01 23:48:22 +01:00
|
|
|
|
2001-01-30 18:39:20 +01:00
|
|
|
int ListSize=NodeVtxList.size();
|
|
|
|
VtxList.resize(ListSize);
|
|
|
|
Matrix4x4 PMtx=ParentNode.Mtx;
|
|
|
|
PMtx.Invert();
|
|
|
|
for (int i=0; i<ListSize; i++)
|
|
|
|
{
|
2001-02-01 23:48:22 +01:00
|
|
|
VtxList[i]=PMtx*NodeVtxList[i];
|
2001-01-30 18:39:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
for (int T=0; T<TriCount; T++)
|
|
|
|
{
|
|
|
|
int Mat=SceneUsedMatList[NodeMatList[T]];
|
|
|
|
|
2001-02-26 21:14:08 +01:00
|
|
|
if (Mat>SceneTexList.size()) GObject::Error(ERR_FATAL,"Crap Material ID, wanted %i, only have %i\n",Mat,SceneTexList.size());
|
2001-03-01 18:03:15 +01:00
|
|
|
GString TexName=InPath+SceneTexList[Mat];
|
2001-03-12 18:11:40 +01:00
|
|
|
Scale*=16;;
|
|
|
|
ParentBone.FaceList.AddFace( VtxList, NodeTriList[T], NodeUVList[T], TexName,0,false);
|
|
|
|
Scale/=16;;
|
2001-01-30 18:39:20 +01:00
|
|
|
}
|
2001-01-06 00:02:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int ChildCount=ThisNode.GetPruneChildCount();
|
2001-01-30 18:39:20 +01:00
|
|
|
for (int Loop=0;Loop<ChildCount ; Loop++) ProcessSkel(ThisNode.PruneChildList[Loop],ThisIdx);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//***************************************************************************
|
|
|
|
void CMkActor3d::BuildSkelOut()
|
|
|
|
{
|
|
|
|
int ListSize=Skel.size();
|
|
|
|
|
2001-02-26 21:14:08 +01:00
|
|
|
BoneCount=Skel.size();
|
2001-03-12 18:11:40 +01:00
|
|
|
FaceList.SetTexGrab(TexGrab);
|
2001-02-26 21:14:08 +01:00
|
|
|
|
2001-01-30 18:39:20 +01:00
|
|
|
for (int i=0; i<ListSize; i++)
|
|
|
|
{
|
|
|
|
sGinSkel &ThisBone=Skel[i];
|
|
|
|
int VtxStart=FaceList.GetVtxCount();
|
|
|
|
int FaceListSize=ThisBone.FaceList.GetFaceCount();
|
2001-02-08 17:30:06 +01:00
|
|
|
|
2001-01-30 18:39:20 +01:00
|
|
|
if (FaceListSize)
|
|
|
|
{
|
|
|
|
ThisBone.Bone.TriStart=FaceList.GetFaceCount();
|
|
|
|
ThisBone.Bone.TriCount=ThisBone.FaceList.GetFaceCount();
|
|
|
|
|
|
|
|
for (int F=0; F<FaceListSize; F++)
|
|
|
|
{
|
2001-03-12 18:11:40 +01:00
|
|
|
Scale*=16;
|
|
|
|
FaceList.AddFace(ThisBone.FaceList[F],true);
|
|
|
|
Scale/=16;
|
2001-01-30 18:39:20 +01:00
|
|
|
}
|
|
|
|
ThisBone.Bone.VtxCount=FaceList.GetVtxCount()-VtxStart;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2001-01-06 00:02:31 +01:00
|
|
|
|
2001-01-30 18:39:20 +01:00
|
|
|
//***************************************************************************
|
|
|
|
void CMkActor3d::WriteSkel()
|
|
|
|
{
|
|
|
|
int ListSize=Skel.size();
|
|
|
|
|
|
|
|
for (int i=0; i<ListSize; i++)
|
|
|
|
{
|
|
|
|
sBone &ThisBone=Skel[i].Bone;
|
|
|
|
|
|
|
|
fwrite(&ThisBone, sizeof(sBone), 1, File);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//***************************************************************************
|
2001-02-26 21:14:08 +01:00
|
|
|
void CMkActor3d::ActorProcess()
|
2001-01-30 18:39:20 +01:00
|
|
|
{
|
2001-02-08 17:30:06 +01:00
|
|
|
ProcessSkel(1,-1);
|
|
|
|
BuildSkelOut();
|
2001-02-26 21:14:08 +01:00
|
|
|
printf("%s has %i bones\n",Name,BoneCount);
|
2001-02-08 17:30:06 +01:00
|
|
|
|
2001-02-26 21:14:08 +01:00
|
|
|
int ListSize=InTexList.size();
|
2001-01-30 18:39:20 +01:00
|
|
|
for (int i=0; i<ListSize; i++)
|
|
|
|
{
|
2001-03-01 18:03:15 +01:00
|
|
|
GString Filename=InPath;
|
|
|
|
Filename+="Textures/";
|
2001-02-27 20:03:36 +01:00
|
|
|
Filename+=InTexList[i]+".Bmp";
|
2001-03-01 18:03:15 +01:00
|
|
|
Filename.Upper();
|
2001-02-27 20:03:36 +01:00
|
|
|
FaceList.AddTex(Filename);
|
2001-01-30 18:39:20 +01:00
|
|
|
}
|
2001-01-06 00:02:31 +01:00
|
|
|
}
|
2001-01-08 22:40:41 +01:00
|
|
|
|
2001-01-30 18:39:20 +01:00
|
|
|
|
2001-01-06 00:02:31 +01:00
|
|
|
//***************************************************************************
|
2001-03-12 18:11:40 +01:00
|
|
|
//***************************************************************************
|
|
|
|
void Rescale(vector<sVtx> const &InList,vector<sVtx> &OutList)
|
|
|
|
{
|
|
|
|
int i,ListSize=InList.size();
|
|
|
|
int S=16;
|
|
|
|
|
|
|
|
OutList.resize(ListSize);
|
|
|
|
if (!ListSize) return;
|
|
|
|
printf("Rescale Factor %i\n",S);
|
|
|
|
|
|
|
|
for (i=0; i<ListSize;i++)
|
|
|
|
{
|
|
|
|
sVtx const &In=InList[i];
|
|
|
|
sVtx &Out=OutList[i];
|
|
|
|
|
|
|
|
Out.vx=In.vx/S;
|
|
|
|
Out.vy=In.vy/S;
|
|
|
|
Out.vz=In.vz/S;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//***************************************************************************
|
|
|
|
|
2001-02-26 21:14:08 +01:00
|
|
|
void CMkActor3d::ActorWrite()
|
2001-01-06 00:02:31 +01:00
|
|
|
{
|
2001-01-08 22:40:41 +01:00
|
|
|
GString OutName=OutFile+".A3d";
|
|
|
|
|
2001-02-27 20:03:36 +01:00
|
|
|
FaceList.Process();
|
|
|
|
|
|
|
|
printf("Write %s:\t",Name);
|
2001-01-08 22:40:41 +01:00
|
|
|
File=fopen(OutName,"wb");
|
|
|
|
|
|
|
|
// Write Dummy Hdr
|
2001-02-26 21:14:08 +01:00
|
|
|
fwrite(&FileHdr,1,sizeof(sActorHdr),File);
|
2001-01-08 22:40:41 +01:00
|
|
|
|
|
|
|
// Write Skeleton
|
2001-01-30 18:39:20 +01:00
|
|
|
FileHdr.BoneCount=Skel.size();
|
2001-01-12 23:38:19 +01:00
|
|
|
FileHdr.BoneList=(sBone*)ftell(File);
|
2001-01-30 18:39:20 +01:00
|
|
|
WriteSkel();
|
2001-01-08 22:40:41 +01:00
|
|
|
|
|
|
|
// Write Tris
|
|
|
|
FileHdr.TriCount=FaceList.GetTriFaceCount();
|
2001-01-30 18:39:20 +01:00
|
|
|
FileHdr.TriList=(sTri*)FaceList.WriteTriList(File);
|
2001-02-27 20:03:36 +01:00
|
|
|
printf("T:%i\t",FileHdr.TriCount);
|
2001-01-08 22:40:41 +01:00
|
|
|
// Write Quads
|
|
|
|
FileHdr.QuadCount=FaceList.GetQuadFaceCount();
|
2001-01-12 23:38:19 +01:00
|
|
|
FileHdr.QuadList=(sQuad*)FaceList.WriteQuadList(File);
|
2001-02-27 20:03:36 +01:00
|
|
|
printf("Q:%i\t",FileHdr.QuadCount);
|
2001-01-30 18:39:20 +01:00
|
|
|
// Write VtxList
|
|
|
|
FileHdr.VtxCount=FaceList.GetVtxCount();
|
2001-03-12 18:11:40 +01:00
|
|
|
// FileHdr.VtxList=(sVtx*)FaceList.WriteVtxList(File);
|
|
|
|
vector<sVtx> VtxList;
|
|
|
|
Rescale(FaceList.GetVtxList(),VtxList);
|
|
|
|
FileHdr.VtxList=(sVtx*)FaceList.WriteVtxList(File,VtxList);
|
|
|
|
|
2001-02-27 20:03:36 +01:00
|
|
|
printf("V:%i\t",FileHdr.VtxCount);
|
2001-01-30 18:39:20 +01:00
|
|
|
|
|
|
|
// Write TexList
|
|
|
|
FileHdr.TexInfo=(sTexInfo*)WriteTexInfoList();
|
2001-01-08 22:40:41 +01:00
|
|
|
|
2001-03-05 21:49:46 +01:00
|
|
|
// Write anims
|
|
|
|
AnimWrite();
|
2001-01-08 22:40:41 +01:00
|
|
|
|
|
|
|
// Rewrite Header
|
|
|
|
fseek(File, 0, SEEK_SET);
|
2001-02-26 21:14:08 +01:00
|
|
|
fwrite(&FileHdr,1,sizeof(sActorHdr),File);
|
2001-03-05 21:49:46 +01:00
|
|
|
fclose(File);
|
|
|
|
|
|
|
|
AnimWriteInclude();
|
2001-01-08 22:40:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//***************************************************************************
|
2001-01-30 18:39:20 +01:00
|
|
|
void CalcTPXY(sTexOutInfo const &In,sTexInfo &Out)
|
2001-01-08 22:40:41 +01:00
|
|
|
{
|
2001-01-30 18:39:20 +01:00
|
|
|
int TPage=In.Tpage;
|
|
|
|
int X,Y,W,H;
|
|
|
|
int PixPerWord;
|
|
|
|
|
|
|
|
X=(u8)In.u;
|
|
|
|
Y=(u8)In.v;
|
|
|
|
W=(u8)In.w;
|
|
|
|
H=(u8)In.h;
|
|
|
|
|
|
|
|
switch (((TPage)>>7)&0x003)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
PixPerWord=4;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
PixPerWord=2;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
PixPerWord=1;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
GObject::Error(ERR_FATAL,"Unknown Pixel Depth");
|
|
|
|
break;
|
|
|
|
};
|
2001-01-08 22:40:41 +01:00
|
|
|
|
2001-01-30 18:39:20 +01:00
|
|
|
X/=PixPerWord;
|
|
|
|
W/=PixPerWord;
|
2001-01-12 23:38:19 +01:00
|
|
|
|
2001-01-30 18:39:20 +01:00
|
|
|
Out.x=(TPage<<6)&0x7c0;
|
|
|
|
Out.x+=X;
|
|
|
|
Out.y=(TPage<<4)&0x100;
|
|
|
|
Out.y+=Y;
|
2001-01-08 22:40:41 +01:00
|
|
|
|
2001-01-30 18:39:20 +01:00
|
|
|
Out.w=W;
|
|
|
|
Out.h=H;
|
2001-01-08 22:40:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//***************************************************************************
|
2001-01-30 18:39:20 +01:00
|
|
|
int CMkActor3d::WriteTexInfoList()
|
2001-01-08 22:40:41 +01:00
|
|
|
{
|
2001-01-30 18:39:20 +01:00
|
|
|
std::vector<sTexOutInfo> &TexList=TexGrab.GetTexInfo();
|
|
|
|
int ListSize=TexList.size();
|
2001-01-08 22:40:41 +01:00
|
|
|
int Pos=ftell(File);
|
|
|
|
|
|
|
|
for (int i=0; i<ListSize; i++)
|
|
|
|
{
|
2001-01-30 18:39:20 +01:00
|
|
|
sTexInfo OutTex;
|
2001-01-12 23:38:19 +01:00
|
|
|
|
2001-01-30 18:39:20 +01:00
|
|
|
CalcTPXY(TexList[i],OutTex);
|
2001-03-01 18:03:15 +01:00
|
|
|
// printf("%i %i %i %i\n",OutTex.x,OutTex.y,OutTex.w,OutTex.h);
|
2001-01-30 18:39:20 +01:00
|
|
|
fwrite(&OutTex, sizeof(sTexInfo), 1, File);
|
2001-01-08 22:40:41 +01:00
|
|
|
}
|
2001-02-26 21:14:08 +01:00
|
|
|
// printf("%i Materials\n",ListSize);
|
2001-01-08 22:40:41 +01:00
|
|
|
|
|
|
|
return (Pos);
|
2001-01-06 00:02:31 +01:00
|
|
|
}
|
|
|
|
|
2001-02-26 21:14:08 +01:00
|
|
|
|
2001-01-06 00:02:31 +01:00
|
|
|
//***************************************************************************
|
2001-02-26 21:14:08 +01:00
|
|
|
//*** Anim ******************************************************************
|
2001-01-06 00:02:31 +01:00
|
|
|
//***************************************************************************
|
2001-02-26 21:14:08 +01:00
|
|
|
void CMkActor3d::AnimLoad()
|
|
|
|
{
|
|
|
|
int ListSize=InAnimList.size();
|
|
|
|
|
|
|
|
for (int i=0; i<ListSize; i++)
|
|
|
|
{
|
|
|
|
CScene Scene;
|
|
|
|
int ThisBoneCount;
|
2001-02-27 20:03:36 +01:00
|
|
|
GString Filename=InPath+InAnimList[i]+".Gin";
|
|
|
|
GFName Name=Filename;
|
2001-02-26 21:14:08 +01:00
|
|
|
|
|
|
|
printf("%s\t",Name.File());
|
2001-02-27 20:03:36 +01:00
|
|
|
|
|
|
|
Scene.Load(Filename);
|
2001-02-26 21:14:08 +01:00
|
|
|
|
|
|
|
// Process Anim
|
|
|
|
sAnim ThisAnim;
|
|
|
|
ThisAnim.Name=Name.File();
|
|
|
|
ThisAnim.Name.Upper();
|
|
|
|
ThisAnim.FrameCount=AnimProcessSkelMove(Scene,ThisAnim,1);
|
|
|
|
AnimProcessSkelAnim(Scene,ThisAnim,1);
|
|
|
|
AnimList.push_back(ThisAnim);
|
|
|
|
|
|
|
|
ThisBoneCount=ThisAnim.BoneAnim.size();
|
2001-03-05 21:49:46 +01:00
|
|
|
printf("\t(%i Frames)\n",ThisAnim.FrameCount);
|
2001-02-26 21:14:08 +01:00
|
|
|
|
|
|
|
// Check Skeleton
|
|
|
|
if (BoneCount!=ThisBoneCount)
|
|
|
|
{
|
|
|
|
GObject::Error(ERR_FATAL,"Invalid skeleton\n");
|
|
|
|
}
|
2001-02-27 20:03:36 +01:00
|
|
|
|
2001-02-26 21:14:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2001-01-06 00:02:31 +01:00
|
|
|
//***************************************************************************
|
2001-02-26 21:14:08 +01:00
|
|
|
int CMkActor3d::AnimProcessSkelMove(CScene &Scene,sAnim &ThisAnim,int Idx)
|
|
|
|
{
|
|
|
|
CNode &ThisNode=Scene.GetNode(Idx);
|
|
|
|
vector<sGinAnim> const &NodeAnim=ThisNode.GetAnim();
|
|
|
|
int FrameCount=NodeAnim.size();
|
|
|
|
vector<s32> &Move=ThisAnim.Move;
|
2001-01-06 00:02:31 +01:00
|
|
|
|
2001-02-26 21:14:08 +01:00
|
|
|
Move.resize(FrameCount);
|
|
|
|
for (int i=0; i<FrameCount; i++)
|
|
|
|
{
|
|
|
|
Move[i]=-round(NodeAnim[i].Pos.y*Scale);
|
|
|
|
}
|
|
|
|
|
|
|
|
return(FrameCount);
|
|
|
|
}
|
|
|
|
|
|
|
|
//***************************************************************************
|
|
|
|
void CMkActor3d::AnimProcessSkelAnim(CScene &Scene,sAnim &ThisAnim,int Idx)
|
2001-01-06 00:02:31 +01:00
|
|
|
{
|
2001-02-26 21:14:08 +01:00
|
|
|
CNode &ThisNode=Scene.GetNode(Idx);
|
|
|
|
vector<sGinAnim> const &NodeAnim=ThisNode.GetAnim();
|
|
|
|
int FrameCount=NodeAnim.size();
|
|
|
|
|
|
|
|
// if (!ThisNode.Pts.size()) // Dont export Skin as bone
|
|
|
|
if (!ThisNode.GetTris().size()) // Dont export Skin as bone
|
|
|
|
{
|
|
|
|
sBoneAnim FrameList;
|
|
|
|
FrameList.Idx.resize(FrameCount);
|
|
|
|
|
|
|
|
for (int i=0; i<FrameCount; i++)
|
|
|
|
{
|
|
|
|
sGinAnim const &InFrame=NodeAnim[i];
|
|
|
|
sQuat ThisFrame;
|
|
|
|
Quaternion const &ThisQuat=InFrame.Ang;
|
|
|
|
|
|
|
|
ThisFrame.vx=round(ThisQuat.x*4096);
|
|
|
|
ThisFrame.vy=round(ThisQuat.y*4096);
|
|
|
|
ThisFrame.vz=round(ThisQuat.z*4096);
|
|
|
|
ThisFrame.vw=round(ThisQuat.w*4096);
|
|
|
|
FrameList.Idx[i]=QuatList.Add(ThisFrame);
|
|
|
|
}
|
|
|
|
ThisAnim.BoneAnim.push_back(FrameList);
|
|
|
|
}
|
|
|
|
|
|
|
|
int ChildCount=ThisNode.GetPruneChildCount();
|
|
|
|
|
|
|
|
for (int Loop=0;Loop<ChildCount;Loop++) AnimProcessSkelAnim(Scene,ThisAnim,ThisNode.PruneChildList[Loop]);
|
2001-01-06 00:02:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//***************************************************************************
|
2001-02-26 21:14:08 +01:00
|
|
|
void CMkActor3d::AnimWrite()
|
2001-01-06 00:02:31 +01:00
|
|
|
{
|
2001-02-26 21:14:08 +01:00
|
|
|
int Anim,AnimCount=AnimList.size();
|
|
|
|
sAnimHdr Hdr;
|
2001-03-05 21:49:46 +01:00
|
|
|
int HdrPos;
|
2001-02-26 21:14:08 +01:00
|
|
|
|
2001-03-05 21:49:46 +01:00
|
|
|
// FileHdr
|
2001-02-26 21:14:08 +01:00
|
|
|
FileHdr.AnimCount=AnimCount;
|
2001-03-05 21:49:46 +01:00
|
|
|
if (!AnimCount) return; // No anims, dont bother
|
2001-01-06 00:02:31 +01:00
|
|
|
|
2001-02-26 21:14:08 +01:00
|
|
|
// Write Dummy AnimHdrs
|
2001-03-05 21:49:46 +01:00
|
|
|
HdrPos=ftell(File);
|
|
|
|
FileHdr.AnimList=(sAnimHdr*)HdrPos;
|
2001-02-26 21:14:08 +01:00
|
|
|
for (Anim=0; Anim<AnimCount; Anim++)
|
2001-01-06 00:02:31 +01:00
|
|
|
{
|
2001-02-26 21:14:08 +01:00
|
|
|
fwrite(&Hdr,1,sizeof(sAnimHdr),File);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Write QuatTable
|
|
|
|
FileHdr.QuatTable=(sQuat*)AnimWriteQuatTable();
|
2001-01-06 00:02:31 +01:00
|
|
|
|
2001-02-26 21:14:08 +01:00
|
|
|
// Write Movements
|
|
|
|
for (Anim=0; Anim<AnimCount; Anim++)
|
|
|
|
{
|
|
|
|
AnimList[Anim].MoveOfs=AnimWriteMove(AnimList[Anim]);
|
2001-01-06 00:02:31 +01:00
|
|
|
}
|
2001-02-26 21:14:08 +01:00
|
|
|
|
|
|
|
// Write Anims (u16 can cause address errors, so write last
|
|
|
|
for (Anim=0; Anim<AnimCount; Anim++)
|
|
|
|
{
|
|
|
|
AnimList[Anim].AnimOfs=AnimWriteAnim(AnimList[Anim]);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Rewrite Dummy AnimHdrs
|
2001-03-05 21:49:46 +01:00
|
|
|
fseek(File,HdrPos,SEEK_SET);
|
2001-02-26 21:14:08 +01:00
|
|
|
for (Anim=0; Anim<AnimCount; Anim++)
|
|
|
|
{
|
|
|
|
Hdr.FrameCount=AnimList[Anim].FrameCount;
|
|
|
|
Hdr.Move=(s32*)AnimList[Anim].MoveOfs;
|
|
|
|
Hdr.Anim=(u16*)AnimList[Anim].AnimOfs;
|
|
|
|
fwrite(&Hdr,1,sizeof(sAnimHdr),File);
|
|
|
|
}
|
2001-03-05 21:49:46 +01:00
|
|
|
|
2001-01-06 00:02:31 +01:00
|
|
|
}
|
|
|
|
|
2001-02-26 21:14:08 +01:00
|
|
|
//***************************************************************************
|
|
|
|
int CMkActor3d::AnimWriteMove(sAnim const &ThisAnim)
|
|
|
|
{
|
|
|
|
int Pos=ftell(File);
|
|
|
|
|
|
|
|
for (int Frame=0; Frame<ThisAnim.FrameCount; Frame++)
|
|
|
|
{
|
|
|
|
s32 ThisMove=ThisAnim.Move[Frame];
|
|
|
|
fwrite(&ThisMove,1,sizeof(s32),File);
|
|
|
|
// printf("%i %i %i\n",ThisMove.vx,ThisMove.vy,ThisMove.vz);
|
|
|
|
}
|
|
|
|
|
|
|
|
return(Pos);
|
|
|
|
}
|
|
|
|
|
|
|
|
//***************************************************************************
|
|
|
|
int CMkActor3d::AnimWriteAnim(sAnim const &ThisAnim)
|
|
|
|
{
|
|
|
|
int Pos=ftell(File);
|
|
|
|
|
|
|
|
for (int Frame=0; Frame<ThisAnim.FrameCount; Frame++)
|
|
|
|
{
|
|
|
|
for (int Bone=0; Bone<BoneCount; Bone++)
|
|
|
|
{
|
|
|
|
u16 ThisIdx=ThisAnim.BoneAnim[Bone].Idx[Frame];
|
|
|
|
fwrite(&ThisIdx,1,sizeof(u16),File);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return(Pos);
|
|
|
|
}
|
|
|
|
|
|
|
|
//***************************************************************************
|
|
|
|
int CMkActor3d::AnimWriteQuatTable()
|
|
|
|
{
|
|
|
|
int Pos=ftell(File);
|
|
|
|
int ListSize=QuatList.size();
|
|
|
|
|
|
|
|
for (int i=0; i<ListSize; i++)
|
|
|
|
{
|
|
|
|
sQuat &ThisQuat=QuatList[i];
|
|
|
|
fwrite(&ThisQuat,1,sizeof(sQuat),File);
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------
|
|
|
|
printf("%i Anims\n",AnimList.size());
|
|
|
|
return(Pos);
|
|
|
|
}
|
|
|
|
|
|
|
|
//***************************************************************************
|
|
|
|
void CMkActor3d::AnimWriteInclude()
|
|
|
|
{
|
|
|
|
GString Filename=IncFile+"_Anim.h";
|
2001-03-05 21:49:46 +01:00
|
|
|
FILE *File;
|
2001-02-26 21:14:08 +01:00
|
|
|
|
|
|
|
File=fopen(Filename,"wt");
|
|
|
|
|
|
|
|
fprintf(File,"// %s Anim Header\n",Name);
|
|
|
|
fprintf(File,"\n");
|
|
|
|
fprintf(File,"#ifndef\t__ANIM_%s_HEADER__\n",Name);
|
|
|
|
fprintf(File,"#define\t__ANIM_%s_HEADER__\n",Name);
|
|
|
|
fprintf(File,"\n");
|
|
|
|
fprintf(File,"\n");
|
|
|
|
fprintf(File,"enum\tANIM_%s_LIST\n",Name);
|
|
|
|
fprintf(File,"{\n");
|
|
|
|
|
|
|
|
int ListSize=AnimList.size();
|
|
|
|
for (int i=0; i<ListSize; i++)
|
|
|
|
{
|
|
|
|
sAnim &ThisAnim=AnimList[i];
|
|
|
|
fprintf(File,"\tANIM_%s_%s",Name,ThisAnim.Name);
|
|
|
|
if (i==0)
|
|
|
|
{
|
|
|
|
fprintf(File,"=0");
|
|
|
|
}
|
|
|
|
fprintf(File,",\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
fprintf(File,"\tNUM_ANIM_%s\n",Name);
|
|
|
|
fprintf(File,"};\n");
|
|
|
|
fprintf(File,"\n");
|
|
|
|
fprintf(File,"#endif\n");
|
|
|
|
|
|
|
|
fclose(File);
|
|
|
|
}
|