Update checkRpItemsPosition and getTeam
[ryzomcore.git] / nel / tools / pacs / build_ig_boxes / main.cpp
blobabefa9b121083462e8d5653d74eeb2e3a3abf923
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 "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"
35 #include <string>
36 #include <map>
37 #include <deque>
38 #include <set>
40 #include <stdlib.h>
42 using namespace std;
43 using namespace NLMISC;
44 using namespace NL3D;
46 #ifndef NL_BIB_CFG
47 #define NL_BIB_CFG "."
48 #endif // NL_BIB_CFG
50 string Output;
51 string IGPath;
52 vector<string> IGs;
54 class CIGBox
56 public:
57 CIGBox() {}
58 CIGBox(const string &name, const CAABBox &bbox) : Name(name), BBox(bbox) {}
59 string Name;
60 CAABBox BBox;
61 void serial(NLMISC::IStream &f) { f.serial(Name, BBox); }
64 vector<CIGBox> Boxes;
65 set<string> NonWaterShapes;
70 int getInt(CConfigFile &cf, const string &varName)
72 CConfigFile::CVar &var = cf.getVar(varName);
73 return var.asInt();
76 string getString(CConfigFile &cf, const string &varName)
78 CConfigFile::CVar &var = cf.getVar(varName);
79 return var.asString();
82 void init()
84 registerSerial3d();
86 try
88 #ifdef NL_OS_UNIX
89 NLMISC::CPath::addSearchPath(NLMISC::CPath::getApplicationDirectory("NeL"));
90 #endif // NL_OS_UNIX
92 NLMISC::CPath::addSearchPath(NL_BIB_CFG);
94 CConfigFile cf;
95 uint i;
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");
128 createDebug();
129 CFileDisplayer fd(getLogDirectory() + "evallog.log", true);
133 // Init
134 init();
136 uint i, j, k;
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));
143 CInstanceGroup ig;
144 igStream.serial(ig);
146 CAABBox igBBox;
147 bool boxSet = false;
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())
164 continue;
166 string shapeNameLookup = CPath::lookup (shapeName, false, false);
167 if (!shapeNameLookup.empty())
169 CIFile f;
170 if (f.open (shapeNameLookup))
172 CShapeStream shape;
173 shape.serial(f);
175 CWaterShape *wshape = dynamic_cast<CWaterShape *>(shape.getShapePointer());
176 if (wshape == NULL)
178 NonWaterShapes.insert(shapeName);
179 continue;
182 CMatrix matrix;
183 ig.getInstanceMatrix(j, matrix);
185 CPolygon wpoly;
186 wshape->getShapeInWorldSpace(wpoly);
188 for (k=0; k<wpoly.Vertices.size(); ++k)
190 if (boxSet)
192 igBBox.extend(matrix * wpoly.Vertices[k]);
194 else
196 igBBox.setCenter(matrix * wpoly.Vertices[k]);
197 boxSet = true;
201 else
203 nlwarning ("Can't load shape %s", shapeNameLookup.c_str());
206 else
208 NonWaterShapes.insert(shapeName);
212 if (boxSet)
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 ());
226 #ifndef NL_DEBUG
227 catch (...)
229 fprintf(stderr,"main trapped an unknown exception\n");
231 #endif // NL_DEBUG
233 return 0;