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 "nel/misc/types_nl.h"
18 #include "nel/misc/time_nl.h"
19 #include "nel/misc/config_file.h"
20 #include "nel/misc/debug.h"
21 #include "nel/misc/path.h"
22 #include "nel/misc/common.h"
23 #include "nel/misc/displayer.h"
24 #include "nel/misc/file.h"
25 #include "nel/misc/matrix.h"
27 #include "nel/misc/aabbox.h"
29 #include "nel/3d/register_3d.h"
30 #include "nel/3d/scene_group.h"
31 #include "nel/3d/transform_shape.h"
32 #include "nel/3d/water_model.h"
33 #include "nel/3d/water_shape.h"
43 using namespace NLMISC
;
47 #define NL_BIB_CFG "."
58 CIGBox(const string
&name
, const CAABBox
&bbox
) : Name(name
), BBox(bbox
) {}
61 void serial(NLMISC::IStream
&f
) { f
.serial(Name
, BBox
); }
65 set
<string
> NonWaterShapes
;
70 int getInt(CConfigFile
&cf
, const string
&varName
)
72 CConfigFile::CVar
&var
= cf
.getVar(varName
);
76 string
getString(CConfigFile
&cf
, const string
&varName
)
78 CConfigFile::CVar
&var
= cf
.getVar(varName
);
79 return var
.asString();
89 NLMISC::CPath::addSearchPath(NLMISC::CPath::getApplicationDirectory("NeL"));
92 NLMISC::CPath::addSearchPath(NL_BIB_CFG
);
97 cf
.load("build_ig_boxes.cfg");
99 Output
= getString(cf
, "Output");
100 // nlinfo("Output=%s", Output.c_str());
102 CConfigFile::CVar
&cvIGs
= cf
.getVar("IGs");
103 for (i
=0; i
<cvIGs
.size(); i
++)
105 IGs
.push_back(cvIGs
.asString(i
));
108 CConfigFile::CVar
&cvPathes
= cf
.getVar("Pathes");
109 for (i
=0; i
<cvPathes
.size(); ++i
)
111 nlinfo("Using search path %s", cvPathes
.asString(i
).c_str());
112 CPath::addSearchPath(cvPathes
.asString(i
));
115 catch (const EConfigFile
&e
)
117 printf ("Problem in config file : %s\n", e
.what ());
122 int main(int argc
, char **argv
)
124 // Filter addSearchPath
125 NLMISC::createDebug();
126 InfoLog
->addNegativeFilter("adding the path");
129 CFileDisplayer
fd(getLogDirectory() + "evallog.log", true);
138 for (i
=0; i
<IGs
.size(); ++i
)
140 // load ig associated to the zone
141 string igName
= IGs
[i
]+".ig";
142 CIFile
igStream(CPath::lookup(igName
));
149 nlinfo("Generating BBOX for %s", igName
.c_str());
151 // search in group for water instance
152 for (j
=0; j
<ig
._InstancesInfos
.size(); ++j
)
155 Ben: c'est degueulasse, mais c'est les coders a la 3D, y savent pas coder
156 Hld: ouai, mais ca marche pas ton truc, alors p'tet qu'on sait pas coder mais toi non plus :p Special Dedicace to SupaGreg!
157 string shapeName = ig._InstancesInfos[j].Name+".shape";
159 string shapeName
= ig
._InstancesInfos
[j
].Name
;
160 if (CFile::getExtension (shapeName
) == "")
161 shapeName
+= ".shape";
163 if (NonWaterShapes
.find(shapeName
) != NonWaterShapes
.end())
166 string shapeNameLookup
= CPath::lookup (shapeName
, false, false);
167 if (!shapeNameLookup
.empty())
170 if (f
.open (shapeNameLookup
))
175 CWaterShape
*wshape
= dynamic_cast<CWaterShape
*>(shape
.getShapePointer());
178 NonWaterShapes
.insert(shapeName
);
183 ig
.getInstanceMatrix(j
, matrix
);
186 wshape
->getShapeInWorldSpace(wpoly
);
188 for (k
=0; k
<wpoly
.Vertices
.size(); ++k
)
192 igBBox
.extend(matrix
* wpoly
.Vertices
[k
]);
196 igBBox
.setCenter(matrix
* wpoly
.Vertices
[k
]);
203 nlwarning ("Can't load shape %s", shapeNameLookup
.c_str());
208 NonWaterShapes
.insert(shapeName
);
214 Boxes
.push_back(CIGBox(igName
, igBBox
));
215 nlinfo("Bbox: (%.1f,%.1f)-(%.1f,%.1f)", igBBox
.getMin().x
, igBBox
.getMin().y
, igBBox
.getMax().x
, igBBox
.getMax().y
);
219 COFile
output(Output
);
220 output
.serialCont(Boxes
);
222 catch (const Exception
&e
)
224 fprintf (stderr
,"main trapped an exception: '%s'\n", e
.what ());
229 fprintf(stderr
,"main trapped an unknown exception\n");