1 // NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
2 // Copyright (C) 2010 Winch Gate Property Limited
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.
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"
29 using namespace NLMISC
;
32 // ***************************************************************************
33 void skipLog(const char *str
)
35 DebugLog
->addNegativeFilter(str
);
36 WarningLog
->addNegativeFilter(str
);
39 // ***************************************************************************
40 int main(int argc
, char* argv
[])
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 ?
58 printf ("anim_builder [directoryIn] [pathOut] [parameter_file] \n");
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());
76 pathOut
= CPath::standardizePath(pathOut
);
77 if( !CFile::isDirectory(pathOut
) )
79 printf("PathOut %s is not a directory", pathOut
.c_str());
83 // Our Animation optimizer.
85 CAnimationOptimizer animationOptimizer
;
86 // Leave thresholds as default.
87 animationOptimizer
.clearLowPrecisionTracks();
90 // Load and setup configFile.
92 CConfigFile parameter
;
93 // Load and parse the param file
94 parameter
.load (paramFile
);
96 // Get the Low Precision Track Key Names
99 CConfigFile::CVar
&anim_low_precision_tracks
= parameter
.getVar ("anim_low_precision_tracks");
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");
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.
121 nlwarning("Bad \"anim_sample_rate\" value. Use Default of 30 fps.");
122 animationOptimizer
.setSampleFrameRate(30);
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
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
;
152 bool mustSkip
= false;
155 if(CFile::fileExists(fileNameOut
))
157 // If newer than file In, skip
158 uint32 fileOutDate
= CFile::getFileModificationDate(fileNameOut
);
159 if( fileOutDate
> CFile::getFileModificationDate(igFile
) )
165 // If must process the file.
168 // Read the animation.
171 fin
.open(CPath::lookup(igFile
));
176 animationOptimizer
.optimize(animIn
, animOut
);
178 // Save this animation.
180 fout
.open(fileNameOut
);
181 fout
.serial(animOut
);
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
)
204 nlwarning ("ERROR %s\n", except
.what());