Linux multi-monitor fullscreen support
[ryzomcore.git] / nel / tools / 3d / anim_builder / anim_builder.cpp
blob778cf081c3988e1e074e2f3dfd828fa5a611c83a
1 // NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as
6 // published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Affero General Public License for more details.
14 // You should have received a copy of the GNU Affero General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 #include "anim_builder.h"
18 #include "nel/misc/stream.h"
19 #include "nel/misc/file.h"
20 #include "nel/misc/config_file.h"
21 #include "nel/misc/path.h"
23 #include "nel/3d/animation.h"
24 #include "nel/3d/animation_optimizer.h"
25 #include "nel/3d/register_3d.h"
28 using namespace std;
29 using namespace NLMISC;
30 using namespace NL3D;
32 // ***************************************************************************
33 void skipLog(const char *str)
35 DebugLog->addNegativeFilter(str);
36 WarningLog->addNegativeFilter(str);
39 // ***************************************************************************
40 int main(int argc, char* argv[])
42 // Register 3d
43 registerSerial3d ();
45 // Avoid some stupids warnings.
46 NLMISC::createDebug();
47 skipLog("variable \"RootConfigFilename\"");
48 skipLog("variable \"anim_low_precision_tracks\"");
49 skipLog("variable \"anim_sample_rate\"");
50 InfoLog->addNegativeFilter("FEHTIMER>");
51 InfoLog->addNegativeFilter("adding the path");
54 // Good number of args ?
55 if (argc<4)
57 // Help message
58 printf ("anim_builder [directoryIn] [pathOut] [parameter_file] \n");
60 else
62 try
64 string directoryIn= argv[1];
65 string pathOut= argv[2];
66 string paramFile= argv[3];
68 // Verify directoryIn.
69 directoryIn= CPath::standardizePath(directoryIn);
70 if( !CFile::isDirectory(directoryIn) )
72 printf("DirectoryIn %s is not a directory", directoryIn.c_str());
73 return -1;
75 // Verify pathOut.
76 pathOut= CPath::standardizePath(pathOut);
77 if( !CFile::isDirectory(pathOut) )
79 printf("PathOut %s is not a directory", pathOut.c_str());
80 return -1;
83 // Our Animation optimizer.
84 //=================
85 CAnimationOptimizer animationOptimizer;
86 // Leave thresholds as default.
87 animationOptimizer.clearLowPrecisionTracks();
90 // Load and setup configFile.
91 //=================
92 CConfigFile parameter;
93 // Load and parse the param file
94 parameter.load (paramFile);
96 // Get the Low Precision Track Key Names
97 try
99 CConfigFile::CVar &anim_low_precision_tracks = parameter.getVar ("anim_low_precision_tracks");
100 uint lpt;
101 for (lpt = 0; lpt < (uint)anim_low_precision_tracks.size(); lpt++)
103 animationOptimizer.addLowPrecisionTrack(anim_low_precision_tracks.asString(lpt));
106 catch(const EUnknownVar &)
108 nlwarning("\"anim_low_precision_tracks\" not found in the parameter file. Add \"Finger\" and \"Ponytail\" by default");
109 animationOptimizer.addLowPrecisionTrack("Finger");
110 animationOptimizer.addLowPrecisionTrack("Ponytail");
113 // Sample Rate.
116 CConfigFile::CVar &anim_sample_rate = parameter.getVar ("anim_sample_rate");
117 float sr= anim_sample_rate.asFloat(0);
118 // Consider values > 1000 as error values.
119 if(sr<=0 || sr>1000)
121 nlwarning("Bad \"anim_sample_rate\" value. Use Default of 30 fps.");
122 animationOptimizer.setSampleFrameRate(30);
124 else
126 animationOptimizer.setSampleFrameRate(sr);
129 catch(const EUnknownVar &)
131 nlwarning("\"anim_sample_rate\" not found in the parameter file. Use Default of 30 fps.");
132 animationOptimizer.setSampleFrameRate(30);
136 // Scan and load all files .ig in directories
137 //=================
138 uint numSkipped= 0;
139 uint numBuilded= 0;
140 vector<string> listFile;
141 CPath::getPathContent(directoryIn, false, false, true, listFile);
142 for(uint iFile=0; iFile<listFile.size(); iFile++)
144 string &igFile= listFile[iFile];
145 // verify it is a .anim.
146 if( CFile::getExtension(igFile) == "anim" )
148 string fileNameIn= CFile::getFilename(igFile);
149 string fileNameOut= pathOut + fileNameIn;
151 // skip the file?
152 bool mustSkip= false;
154 // If File Out exist
155 if(CFile::fileExists(fileNameOut))
157 // If newer than file In, skip
158 uint32 fileOutDate= CFile::getFileModificationDate(fileNameOut);
159 if( fileOutDate > CFile::getFileModificationDate(igFile) )
161 mustSkip= true;
165 // If must process the file.
166 if(!mustSkip)
168 // Read the animation.
169 CAnimation animIn;
170 CIFile fin;
171 fin.open(CPath::lookup(igFile));
172 fin.serial(animIn);
174 // process.
175 CAnimation animOut;
176 animationOptimizer.optimize(animIn, animOut);
178 // Save this animation.
179 COFile fout;
180 fout.open(fileNameOut);
181 fout.serial(animOut);
182 fout.close();
184 numBuilded++;
186 else
188 numSkipped++;
191 // progress
192 printf("Anim builded: %4d. Anim Skipped: %4d\r", numBuilded, numSkipped);
196 // Add some info in the log.
197 nlinfo("Anim builded: %4d", numBuilded);
198 nlinfo("Anim skipped: %4d", numSkipped);
201 catch (const Exception& except)
203 // Error message
204 nlwarning ("ERROR %s\n", except.what());
208 // exit.
209 return 0;