1 //****************************************************************************//
2 // Cal3DFormatConv.cpp //
3 // Copyright (C) 2002 Laurent Desmecht //
4 // Copyright (C) 2006 Loic Dachary <loic@gnu.org> //
5 //****************************************************************************//
6 // This library is free software; you can redistribute it and/or modify it //
7 // under the terms of the GNU Lesser General Public License as published by //
8 // the Free Software Foundation; either version 2.1 of the License, or (at //
9 // your option) any later version. //
10 //****************************************************************************//
11
12 #include "cal3d/cal3d.h"
13
14 #define SKELETON 0
15 #define MESH 1
16 #define ANIMATION 2
17 #define MATERIAL 3
18
19 using namespace std;
20
GetFileType(std::string strFilename)21 int GetFileType(std::string strFilename)
22 {
23 if(strFilename.size()>= 3 && stricmp(strFilename.substr(strFilename.size()-3,3).c_str(),Cal::SKELETON_XMLFILE_MAGIC)==0
24 || strFilename.size()>= 3 && stricmp(strFilename.substr(strFilename.size()-3,3).c_str(),Cal::SKELETON_FILE_MAGIC)==0)
25 return SKELETON;
26 if(strFilename.size()>= 3 && stricmp(strFilename.substr(strFilename.size()-3,3).c_str(),Cal::MESH_XMLFILE_MAGIC)==0
27 || strFilename.size()>= 3 && stricmp(strFilename.substr(strFilename.size()-3,3).c_str(),Cal::MESH_FILE_MAGIC)==0)
28 return MESH;
29 if(strFilename.size()>= 3 && stricmp(strFilename.substr(strFilename.size()-3,3).c_str(),Cal::ANIMATION_XMLFILE_MAGIC)==0
30 || strFilename.size()>= 3 && stricmp(strFilename.substr(strFilename.size()-3,3).c_str(),Cal::ANIMATION_FILE_MAGIC)==0)
31 return ANIMATION;
32 if(strFilename.size()>= 3 && stricmp(strFilename.substr(strFilename.size()-3,3).c_str(),Cal::MATERIAL_XMLFILE_MAGIC)==0
33 || strFilename.size()>= 3 && stricmp(strFilename.substr(strFilename.size()-3,3).c_str(),Cal::MATERIAL_FILE_MAGIC)==0)
34 return MATERIAL;
35 return -1;
36 }
37
38
main(int argc,char * argv[])39 int main(int argc, char* argv[])
40 {
41 std::string strFilename1,strFilename2;
42 int Type=-1;
43
44 if(argc==1)
45 {
46 cout << "Enter the name of the source file :";
47 cin >> strFilename1;
48
49 Type = GetFileType(strFilename1);
50 switch(Type)
51 {
52 case SKELETON:
53 cout << "The file is a skeleton\nEnter the name of the destination file (use .xsf for a XML file) :";
54 cin >> strFilename2;
55 break;
56 case MESH:
57 cout << "The file is a mesh\nEnter the name of the destination file (use .xmf for a XML file) :";
58 cin >> strFilename2;
59 break;
60 case ANIMATION:
61 cout << "The file is an animation\nEnter the name of the destination file (use .xaf for a XML file) :";
62 cin >> strFilename2;
63 break;
64 case MATERIAL:
65 cout << "The file is a material\nEnter the name of the destination file (use .xrf for a XML file) :";
66 cin >> strFilename2;
67 break;
68 case -1:
69 cout << "Format of the file unknown (check the extention)\n";
70 return 1;
71 }
72 }
73 else if(argc==3)
74 {
75 strFilename1 = argv[1];
76 Type = GetFileType(strFilename1);
77 if(Type==-1)
78 {
79 cout << "Format of the file unknown (check the extention)\n";
80 return 1;
81 }
82
83 strFilename2 = argv[2];
84 }
85 else
86 {
87 cout << "Usage :\n";
88 cout << "Cal3DFormatConv [Source Dest]\n";
89 }
90
91
92 CalSaver Saver;
93 CalLoader Loader;
94
95 if(Type==SKELETON)
96 {
97 CalCoreSkeletonPtr Ske = Loader.loadCoreSkeleton(strFilename1);
98 if(!Ske)
99 {
100 cout << "Error during loading of "<< strFilename1<< endl;
101 cout << "Error was:" << CalError::getLastErrorDescription() << endl;
102 return 1;
103 }
104 Saver.saveCoreSkeleton(strFilename2,Ske.get());
105 }
106 if(Type==MESH)
107 {
108 CalCoreMeshPtr Mesh = Loader.loadCoreMesh(strFilename1);
109 if(!Mesh)
110 {
111 cout << "Error during loading of "<< strFilename1<< endl;
112 cout << "Error was:" << CalError::getLastErrorDescription() << endl;
113 return 1;
114 }
115 Saver.saveCoreMesh(strFilename2,Mesh.get());
116 }
117
118 if(Type==ANIMATION)
119 {
120 CalCoreAnimationPtr Ani = Loader.loadCoreAnimation(strFilename1);
121 if(!Ani)
122 {
123 cout << "Error during loading of "<< strFilename1<< endl;
124 cout << "Error was:" << CalError::getLastErrorDescription() << endl;
125 return 1;
126 }
127 Saver.saveCoreAnimation(strFilename2,Ani.get());
128 }
129 if(Type==MATERIAL)
130 {
131 CalCoreMaterialPtr Mat = Loader.loadCoreMaterial(strFilename1);
132 if(!Mat)
133 {
134 cout << "Error during loading of "<< strFilename1<< endl;
135 cout << "Error was:" << CalError::getLastErrorDescription() << endl;
136 return 1;
137 }
138 Saver.saveCoreMaterial(strFilename2,Mat.get());
139 }
140 return 0;
141 }
142