/**********************************/ /*** SpongeBob 3d Actor Creator ***/ /**********************************/ #include "stdio.h" #include #include #include #include #include #include #include "MkActor3d.h" using namespace std; //*************************************************************************** CMkActor3d ThisActor; //std::vector ExtraTex; //*************************************************************************** char * CycleCommands(char *String,int Num) { int TPBase=-1,TPWidth=-1,TPHeight=-1; char Text[2048],*TextPtr; int Count,i; if (String[0]=='-' || String[0]=='/') { GString TpStr; switch (String[1]) { // Switches case 'o': OutStr = CheckFileString(String); break; case 'i': IncludeFile = CheckFileString(String); break; case 'd': DebugOn =true; break; case 's': TpStr= CheckFileString(String); Scale=atof(TpStr); break; case 't': TpStr= CheckFileString(String); TextPtr=Text; strcpy(TextPtr,TpStr); Count=ZeroAndCountCommas(TextPtr); if (Count!=2) GObject::Error(ERR_FATAL,"Problem with option %s\n",String); TPBase=atol(TextPtr); TextPtr+=strlen(TextPtr)+1; TPWidth=atol(TextPtr); TextPtr+=strlen(TextPtr)+1; TPHeight=atol(TextPtr); ThisActor.SetTPData(TPBase,TPWidth,TPHeight); break; case 'x': TpStr= CheckFileString(String); TextPtr=Text; strcpy(TextPtr,TpStr); Count=ZeroAndCountCommas(TextPtr); for (i=0; i [ .. ] [ 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(" -x: Add Texture\n"); printf(" -d: Add Anim\n"); printf(" -q: Enable Quadding\n"); GObject::Error(ERR_FATAL,ErrStr); } //*************************************************************************** int main (int argc, char *argv[]) { CommandLine(argc,argv,CycleCommands); if (OutStr.Empty()) Usage("No Output File Set\n"); ThisActor.ProcessActor(); ThisActor.ProcessAnim(); return 0; } //*************************************************************************** //*************************************************************************** //*************************************************************************** void CMkActor3d::SetInName(GString const &String) { GString UpperName(String); UpperName.Upper(); GFName File=UpperName; InFilename=UpperName; InPath=File.Drive(); InPath+=File.Dir(); Name=File.File(); } //*************************************************************************** void CMkActor3d::SetTPData(int TPBase,int TPW,int TPH) { TPageBase=TPBase; TPageWidth=TPW ; TPageHeight=TPH; } //*************************************************************************** void CMkActor3d::AddAnim(const char *Name) { InAnimList.push_back(Name); } //*************************************************************************** void CMkActor3d::AddTex(const char *Name) { InTexList.push_back(Name); } //*************************************************************************** void CMkActor3d::ProcessActor() { ThisActor.ActorLoad(); ThisActor.ActorProcess(); ThisActor.ActorWrite(); } //*************************************************************************** void CMkActor3d::ProcessAnim() { ThisActor.AnimLoad(); ThisActor.AnimWrite(); } //*************************************************************************** void CMkActor3d::ActorLoad() { OutStr.Upper(); OutStr.Append('\\'); OutFile=OutStr+Name; IncludeFile.Upper(); IncludeFile.Append('\\'); IncFile=IncludeFile; IncFile+="ACTOR_"; IncFile+=Name; Scene.Load(InFilename); } //*************************************************************************** //*************************************************************************** //*************************************************************************** void CMkActor3d::BuildBoneOut(sBone &OutBone,CNode const &InNode,int ParentBoneIdx) { 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; } //*************************************************************************** void CMkActor3d::ProcessSkel(int Idx,int ParentIdx) { CNode &ThisNode=Scene.GetNode(Idx); CNode &ParentNode=Scene.GetNode(ThisNode.ParentIdx); vector const &NodeTriList = ThisNode.GetTris(); vector const &NodeVtxList = ThisNode.GetPts(); vector const &NodeMatList = ThisNode.GetTriMaterial(); vector const &NodeUVList = ThisNode.GetUVTris(); vector const &SceneTexList= Scene.GetTexList(); vector const &SceneUsedMatList=Scene.GetUsedMaterialIdx(); int TriCount=NodeTriList.size(); int ThisIdx=Skel.size(); sGinSkel &ParentBone=Skel[ParentIdx]; vector VtxList; if (!TriCount) { // Its a Bone!! sGinSkel ThisBone; BuildBoneOut(ThisBone.Bone,ThisNode,ParentIdx); int WeightCount=ThisNode.Weights.size(); if (WeightCount) { // printf("%s %i\n",ThisNode.Name,WeightCount); for (int i=0; iSceneTexList.size()) GObject::Error(ERR_FATAL,"Crap Material ID, wanted %i, only have %i\n",Mat,SceneTexList.size()); ParentBone.FaceList.AddFace( VtxList, NodeTriList[T], NodeUVList[T], SceneTexList[Mat]); } } int ChildCount=ThisNode.GetPruneChildCount(); for (int Loop=0;Loop>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; }; X/=PixPerWord; W/=PixPerWord; Out.x=(TPage<<6)&0x7c0; Out.x+=X; Out.y=(TPage<<4)&0x100; Out.y+=Y; Out.w=W; Out.h=H; } //*************************************************************************** int CMkActor3d::WriteTexInfoList() { CTexGrab &TexGrab=FaceList.GetTexGrab(); std::vector &TexList=TexGrab.GetTexInfo(); int ListSize=TexList.size(); int Pos=ftell(File); for (int i=0; i const &NodeAnim=ThisNode.GetAnim(); int FrameCount=NodeAnim.size(); vector &Move=ThisAnim.Move; Move.resize(FrameCount); for (int i=0; i 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