This commit is contained in:
parent
3cda85e5dc
commit
154b2315ac
3 changed files with 425 additions and 0 deletions
286
Utils/MkAnim3d/MkAnim3d.cpp
Normal file
286
Utils/MkAnim3d/MkAnim3d.cpp
Normal file
|
@ -0,0 +1,286 @@
|
|||
/**********************************/
|
||||
/*** SpongeBob 3d Actor Creator ***/
|
||||
/**********************************/
|
||||
|
||||
#include "stdio.h"
|
||||
#include <misc.hpp>
|
||||
#include <conio.h>
|
||||
#include <iostream.h>
|
||||
#include <vector>
|
||||
#include <PsxLib.h>
|
||||
#include <FaceStore.h>
|
||||
|
||||
#include "MkActor3d.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
//***************************************************************************
|
||||
int TPBase=-1,TPWidth=-1,TPHeight=-1;
|
||||
|
||||
//***************************************************************************
|
||||
|
||||
char * CycleCommands(char *String,int Num)
|
||||
{
|
||||
char Text[256],*TextPtr;
|
||||
int Count;
|
||||
|
||||
if (String[0]=='-' || String[0]=='/')
|
||||
{
|
||||
GString TpStr;
|
||||
switch (String[1])
|
||||
{
|
||||
// Switches
|
||||
case 'o':
|
||||
OutStr = 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);
|
||||
case 'q':
|
||||
StripLength=4;
|
||||
break;
|
||||
default:
|
||||
GObject::Error(ERR_FATAL,"Unknown switch %s",String);
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
GString UpperName(String);
|
||||
UpperName.Upper();
|
||||
MyFiles.AddFile(UpperName);
|
||||
}
|
||||
|
||||
return(String);
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
//***************************************************************************
|
||||
//***************************************************************************
|
||||
CMkActor3d::CMkActor3d(GString const &In,GString const &Out,int TPBase,int TPW,int TPH)
|
||||
{
|
||||
GFName File=In;
|
||||
|
||||
InFilename=In;
|
||||
InPath=File.Drive();
|
||||
InPath+=File.Dir();
|
||||
OutDir=Out;
|
||||
OutDir.Append('\\');
|
||||
|
||||
Name=File.File();
|
||||
// Create Out Filename from inFilename and outdir
|
||||
OutFile=OutDir+File.File();
|
||||
// OutFile+=File.File();
|
||||
|
||||
TPageBase=TPBase;
|
||||
TPageWidth=TPW ;
|
||||
TPageHeight=TPH;
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
void CMkActor3d::Load()
|
||||
{
|
||||
Scene.Load(InFilename);
|
||||
// Scene.PrintPruneTree();
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
void CMkActor3d::Process()
|
||||
{
|
||||
BuildSkin();
|
||||
FaceList.SetTexBasePath(InPath);
|
||||
FaceList.SetTexOut(OutFile+".Tex",TPageBase,TPageWidth,TPageHeight);
|
||||
FaceList.SetTexDebugOut(OutFile+".Lbm");
|
||||
|
||||
FaceList.Process();
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
void CMkActor3d::BuildSkin(int Idx)
|
||||
{
|
||||
CNode &ThisNode=Scene.GetNode(Idx);
|
||||
vector<sGinTri> const &NodeTriList = ThisNode.GetTris();
|
||||
vector<Vector3> const &NodeVtxList = ThisNode.GetPts();
|
||||
vector<int> const &NodeMatList = ThisNode.GetTriMaterial();
|
||||
vector<sUVTri> const &NodeUVList = ThisNode.GetUVTris();
|
||||
vector<GString> const &SceneTexList= Scene.GetTexList();
|
||||
vector<Material> const &SceneMatList= Scene.GetMaterials();
|
||||
|
||||
int TriCount=NodeTriList.size();
|
||||
|
||||
for (int T=0; T<TriCount; T++)
|
||||
{
|
||||
int Mat=NodeMatList[T];
|
||||
Mat=SceneMatList[Mat].TexId;
|
||||
if (Mat<0) Mat=0;
|
||||
CFace &ThisFace=FaceList.AddFace( NodeVtxList, NodeTriList[T], NodeUVList[T], SceneTexList[Mat]);
|
||||
}
|
||||
|
||||
int ChildCount=ThisNode.GetPruneChildCount();
|
||||
for (int Loop=0;Loop<ChildCount ;Loop++) BuildSkin(ThisNode.PruneChildList[Loop]);
|
||||
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
void CMkActor3d::Write()
|
||||
{
|
||||
GString OutName=OutFile+".A3d";
|
||||
|
||||
File=fopen(OutName,"wb");
|
||||
|
||||
// Write Dummy Hdr
|
||||
fwrite(&FileHdr,1,sizeof(sActor3dHdr),File);
|
||||
|
||||
// Write Skeleton
|
||||
FileHdr.BoneCount=Scene.GetPruneTreeSize()-1-1; // Skip Scene & skin
|
||||
FileHdr.BoneList=(sBone*)ftell(File);
|
||||
WriteBone(1);
|
||||
|
||||
// Write Tris
|
||||
FileHdr.TriCount=FaceList.GetTriFaceCount();
|
||||
FileHdr.TriList=(sTri*)FaceList.WriteTriList(File);
|
||||
printf("%i Tris\n",FileHdr.TriCount);
|
||||
// Write Quads
|
||||
FileHdr.QuadCount=FaceList.GetQuadFaceCount();
|
||||
FileHdr.QuadList=(sQuad*)FaceList.WriteQuadList(File);
|
||||
printf("%i Quads\n",FileHdr.QuadCount);
|
||||
// Write WeightList
|
||||
FileHdr.WeightCount=WeightList.size();
|
||||
FileHdr.WeightList=(sWeight*)WriteWeightList();
|
||||
printf("%i Weight\n",FileHdr.WeightCount);
|
||||
|
||||
printf("Size=%i\n",ftell(File));
|
||||
|
||||
// Rewrite Header
|
||||
fseek(File, 0, SEEK_SET);
|
||||
fwrite(&FileHdr,1,sizeof(sActor3dHdr),File);
|
||||
|
||||
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
void CMkActor3d::WriteBone(int Idx)
|
||||
{
|
||||
sBone ThisBone;
|
||||
CNode &ThisNode=Scene.GetNode(Idx);
|
||||
|
||||
if (!ThisNode.Pts.size()) // Dont export Skin as bone
|
||||
{
|
||||
BuildBoneOut(ThisBone,ThisNode);
|
||||
ThisBone.WeightList=(sWeight*)WeightList.size();
|
||||
fwrite(&ThisBone, sizeof(sBone), 1, File);
|
||||
|
||||
// build Weight List
|
||||
for (int Weight=0; Weight<ThisBone.WeightCount; Weight++)
|
||||
{
|
||||
sWeight OutWeight;
|
||||
BuildWeightOut(OutWeight,ThisNode.Weights[Weight]);
|
||||
WeightList.push_back(OutWeight);
|
||||
}
|
||||
}
|
||||
int ChildCount=ThisNode.GetPruneChildCount();
|
||||
for (int Loop=0;Loop<ChildCount;Loop++) WriteBone(ThisNode.PruneChildList[Loop]);
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
void CMkActor3d::BuildBoneOut(sBone &OutBone,CNode const &InNode)
|
||||
{
|
||||
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.Idx=InNode.PruneIdx-1;
|
||||
OutBone.Parent=InNode.PruneParentIdx-1;
|
||||
OutBone.WeightCount=InNode.Weights.size();
|
||||
|
||||
int x,y,z,w;
|
||||
|
||||
x=round(InNode.Ang.x*4096);
|
||||
y=round(InNode.Ang.y*4096);
|
||||
z=round(InNode.Ang.z*4096);
|
||||
w=round(InNode.Ang.w*4096);
|
||||
|
||||
// printf("/*%i*/\t{%f,%f,%f,%f},\t/*%s*/\n",OutBone.Idx,InNode.Ang.x,InNode.Ang.y,InNode.Ang.z,InNode.Ang.w,InNode.Name);
|
||||
printf("/*%i*/\t{%d,%d,%d,%d},\t/*%s*/\n",OutBone.Idx,x,y,z,w,InNode.Name);
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
void CMkActor3d::BuildWeightOut(sWeight &OutWeight,sGinWeight const &InWeight)
|
||||
{
|
||||
OutWeight.vx=round(InWeight.Pos.x*Scale);
|
||||
OutWeight.vy=round(InWeight.Pos.y*Scale);
|
||||
OutWeight.vz=round(InWeight.Pos.z*Scale);
|
||||
OutWeight.VtxNo=InWeight.VertNo;
|
||||
}
|
||||
|
||||
|
||||
//***************************************************************************
|
||||
int CMkActor3d::WriteWeightList()
|
||||
{
|
||||
int ListSize=WeightList.size();
|
||||
int Pos=ftell(File);
|
||||
|
||||
for (int i=0; i<ListSize; i++)
|
||||
{
|
||||
sWeight &OutWeight=WeightList[i];
|
||||
|
||||
fwrite(&OutWeight, sizeof(sWeight), 1, File);
|
||||
}
|
||||
|
||||
return (Pos);
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
//***************************************************************************
|
||||
//***************************************************************************
|
||||
|
||||
void Usage(char *ErrStr)
|
||||
{
|
||||
printf("\nMkActor3d: by Dave\n");
|
||||
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[])
|
||||
{
|
||||
CommandLine(argc,argv,CycleCommands);
|
||||
if (OutStr.Empty()) Usage("No Output File Set\n");
|
||||
|
||||
if (TPBase==-1) Usage("No TPage Set\n");
|
||||
|
||||
vector<GString> const &Files = MyFiles.GetFileInfoVector();
|
||||
|
||||
for (int Loop=0; Loop<Files.size(); Loop++)
|
||||
{
|
||||
CMkActor3d ThisActor(Files[Loop],OutStr,TPBase,TPWidth,TPHeight);
|
||||
|
||||
ThisActor.Load();
|
||||
ThisActor.Process();
|
||||
ThisActor.Write();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
94
Utils/MkAnim3d/MkAnim3d.dsp
Normal file
94
Utils/MkAnim3d/MkAnim3d.dsp
Normal file
|
@ -0,0 +1,94 @@
|
|||
# Microsoft Developer Studio Project File - Name="MkAnim3d" - Package Owner=<4>
|
||||
# Microsoft Developer Studio Generated Build File, Format Version 6.00
|
||||
# ** DO NOT EDIT **
|
||||
|
||||
# TARGTYPE "Win32 (x86) Console Application" 0x0103
|
||||
|
||||
CFG=MkAnim3d - Win32 Debug
|
||||
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
|
||||
!MESSAGE use the Export Makefile command and run
|
||||
!MESSAGE
|
||||
!MESSAGE NMAKE /f "MkAnim3d.mak".
|
||||
!MESSAGE
|
||||
!MESSAGE You can specify a configuration when running NMAKE
|
||||
!MESSAGE by defining the macro CFG on the command line. For example:
|
||||
!MESSAGE
|
||||
!MESSAGE NMAKE /f "MkAnim3d.mak" CFG="MkAnim3d - Win32 Debug"
|
||||
!MESSAGE
|
||||
!MESSAGE Possible choices for configuration are:
|
||||
!MESSAGE
|
||||
!MESSAGE "MkAnim3d - Win32 Release" (based on "Win32 (x86) Console Application")
|
||||
!MESSAGE "MkAnim3d - Win32 Debug" (based on "Win32 (x86) Console Application")
|
||||
!MESSAGE
|
||||
|
||||
# Begin Project
|
||||
# PROP AllowPerConfigDependencies 0
|
||||
# PROP Scc_ProjName ""$/Utils/MkAnim3d", ASEAAAAA"
|
||||
# PROP Scc_LocalPath "."
|
||||
CPP=cl.exe
|
||||
RSC=rc.exe
|
||||
|
||||
!IF "$(CFG)" == "MkAnim3d - Win32 Release"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 0
|
||||
# PROP BASE Output_Dir "Release"
|
||||
# PROP BASE Intermediate_Dir "Release"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 0
|
||||
# PROP Output_Dir "Release"
|
||||
# PROP Intermediate_Dir "Release"
|
||||
# PROP Ignore_Export_Lib 0
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
|
||||
# ADD CPP /nologo /MD /W3 /GX /O2 /I "..\libs\glib" /I "..\libs\maths" /I "..\libs\davelib" /I "..\libs\ginlib" /I "..\libs\psxlib" /I "..\libs\texgrab" /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
|
||||
# ADD BASE RSC /l 0x809 /d "NDEBUG"
|
||||
# ADD RSC /l 0x809 /d "NDEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LINK32=link.exe
|
||||
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
|
||||
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib glib.lib ginlib.lib psxlib.lib texgrab.lib maths.lib psxlib.lib /nologo /subsystem:console /machine:I386 /out:"..\..\tools\data\bin\MkAnim3d.exe" /libpath:"..\libs\psxlib\release" /libpath:"..\libs\ginlib\release" /libpath:"..\libs\glib\release" /libpath:"..\libs\davelib\release" /libpath:"..\libs\texgrab\release" /libpath:"..\libs\maths\release"
|
||||
|
||||
!ELSEIF "$(CFG)" == "MkAnim3d - Win32 Debug"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 1
|
||||
# PROP BASE Output_Dir "Debug"
|
||||
# PROP BASE Intermediate_Dir "Debug"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 1
|
||||
# PROP Output_Dir "Debug"
|
||||
# PROP Intermediate_Dir "Debug"
|
||||
# PROP Ignore_Export_Lib 0
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
|
||||
# ADD CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /I "..\libs\glib" /I "..\libs\maths" /I "..\libs\davelib" /I "..\libs\ginlib" /I "..\libs\psxlib" /I "..\libs\texgrab" /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
|
||||
# ADD BASE RSC /l 0x809 /d "_DEBUG"
|
||||
# ADD RSC /l 0x809 /d "_DEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LINK32=link.exe
|
||||
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
|
||||
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib glib.lib ginlib.lib psxlib.lib texgrab.lib maths.lib psxlib.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept /libpath:"..\libs\psxlib\debug" /libpath:"..\libs\ginlib\debug" /libpath:"..\libs\glib\debug" /libpath:"..\libs\davelib\debug" /libpath:"..\libs\texgrab\debug" /libpath:"..\libs\maths\debug"
|
||||
|
||||
!ENDIF
|
||||
|
||||
# Begin Target
|
||||
|
||||
# Name "MkAnim3d - Win32 Release"
|
||||
# Name "MkAnim3d - Win32 Debug"
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\MkAnim3d.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\MkAnim3d.h
|
||||
# End Source File
|
||||
# End Target
|
||||
# End Project
|
45
Utils/MkAnim3d/MkAnim3d.h
Normal file
45
Utils/MkAnim3d/MkAnim3d.h
Normal file
|
@ -0,0 +1,45 @@
|
|||
/**********************************/
|
||||
/*** SpongeBob 3d Actor Creator ***/
|
||||
/**********************************/
|
||||
|
||||
#include <Vector3.h>
|
||||
#include <List.h>
|
||||
#include <FaceStore.h>
|
||||
|
||||
#include "..\mapedit\ExportPSXHdr.h"
|
||||
|
||||
//***************************************************************************
|
||||
class CMkActor3d
|
||||
{
|
||||
public:
|
||||
CMkActor3d(GString const &In,GString const &Out,int TPBase,int TPW,int TPH);
|
||||
|
||||
void Load();
|
||||
void Process();
|
||||
void Write();
|
||||
|
||||
private:
|
||||
void BuildSkin(int Idx=0);
|
||||
void WriteBone(int Idx);
|
||||
void BuildBoneOut(sBone &OutBone,CNode const &InNode);
|
||||
void BuildWeightOut(sWeight &OutWeight,sGinWeight const &InWeight);
|
||||
int WriteWeightList();
|
||||
|
||||
GString InFilename,InPath,Name,OutFile,OutDir;
|
||||
|
||||
CScene Scene;
|
||||
|
||||
CFaceStore FaceList;
|
||||
vector<sWeight> WeightList;
|
||||
CList<sTri> OutTriList;
|
||||
CList<sVtx> OutVtxList;
|
||||
|
||||
sActor3dHdr FileHdr;
|
||||
FILE *File;
|
||||
|
||||
int TPageBase;
|
||||
int TPageWidth,TPageHeight;
|
||||
|
||||
};
|
||||
|
||||
//***************************************************************************
|
Loading…
Add table
Add a link
Reference in a new issue