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/>.
22 #include "nel/misc/config_file.h"
23 #include "nel/misc/time_nl.h"
24 #include "nel/misc/file.h"
26 #include "nel/pacs/collision_mesh_build.h"
27 #include "nel/pacs/local_retriever.h"
28 #include "nel/pacs/retriever_instance.h"
29 #include "nel/pacs/global_retriever.h"
30 #include "nel/pacs/retriever_bank.h"
32 #include "nel/pacs/u_global_position.h"
37 using namespace NLPACS
;
38 using namespace NLMISC
;
41 #define NL_BIRB_CFG "."
44 bool AddToRetriever
= true;
46 string MergePath
= "c:/data_test/";
47 string MergeInputPrefix
= "fyros";
48 string MergeOutputPrefix
= "city_landscape_fyros";
49 string MeshPath
= "c:/data_test/";
50 vector
<string
> Meshes
;
51 string OutputPath
= "c:/data_test/";
52 string OutputPrefix
= "city_fyros";
55 CVector
getZoneCenterById(uint16 id
)
59 const float zdim
= 160.0f
;
64 return CVector(zdim
*((float)x
+0.5f
), -zdim
*((float)y
+0.5f
), 0.0f
);
67 uint32
getIdByCoord(uint x
, uint y
)
72 uint16
getZoneIdByName(string
&name
)
75 const char *str
= name
.c_str();
78 y
= y
*10 + *(str
++)-'0';
82 x
= (str
[0]-'A')*26+(str
[1]-'A');
88 void serialAndSave(A
&a
, string fn
)
97 void openAndSerial(A
&a
, string fn
)
108 int getInt(CConfigFile
&cf
, const string
&varName
)
110 CConfigFile::CVar
&var
= cf
.getVar(varName
);
114 string
getString(CConfigFile
&cf
, const string
&varName
)
116 CConfigFile::CVar
&var
= cf
.getVar(varName
);
117 return var
.asString();
125 NLMISC::CPath::addSearchPath(NLMISC::CPath::getApplicationDirectory("NeL"));
128 NLMISC::CPath::addSearchPath(NL_BIRB_CFG
);
132 cf
.load("build_indoor_rbank.cfg");
134 Merge
= getInt(cf
, "Merge") != 0;
135 AddToRetriever
= getInt(cf
, "AddToRetriever") != 0;
136 MergePath
= getString(cf
, "MergePath");
137 MergeInputPrefix
= getString(cf
, "MergeInputPrefix");
138 MergeOutputPrefix
= getString(cf
, "MergeOutputPrefix");
139 MeshPath
= getString(cf
, "MeshPath");
141 OutputPath
= getString(cf
, "OutputPath");
142 OutputPrefix
= getString(cf
, "OutputPrefix");
144 CConfigFile::CVar
&meshes
= cf
.getVar("Meshes");
146 for (i
=0; i
<(uint
)meshes
.size(); i
++)
147 Meshes
.push_back(meshes
.asString(i
));
149 catch (const EConfigFile
&e
)
151 printf ("Problem in config file : %s\n", e
.what ());
158 void makeGlobalRetriever(vector
<CVector
> &translation
)
165 openAndSerial(rb
, MergePath
+MergeInputPrefix
+".rbank");
166 gr
.setRetrieverBank(&rb
);
167 openAndSerial(gr
, MergePath
+MergeInputPrefix
+".gr");
171 gr
.setRetrieverBank(&rb
);
177 start
= CTime::getLocalTime();
182 for (i
=0; i
<Meshes
.size(); ++i
)
187 openAndSerial(lr
, OutputPath
+Meshes
[i
]+".lr");
189 uint rid
= rb
.addRetriever(lr
);
193 uint iid
= (gr
.makeInstance(rid
, 0, -translation
[i
])).getInstanceId();
195 ninst
.push_back(iid
);
198 catch (const Exception
&e
)
200 nlwarning("WARNING: can't merge lr '%s.lr': %s", Meshes
[i
].c_str(), e
.what());
206 for (i
=0; i
<ninst
.size(); ++i
)
207 gr
.makeLinks(ninst
[i
]);
210 end
= CTime::getLocalTime();
211 nlinfo("instance making and linking work time: %.3f", (double)(end
-start
)/1000.0);
216 * This way, at the end of the build process,
217 * the rbank should be 5 bytes only and lr should be saved as well next to the rbank
222 serialAndSave(gr
, OutputPath
+MergeOutputPrefix
+".gr");
223 rb
.saveShortBank(OutputPath
, MergeOutputPrefix
, true); // save 5 bytes rbank and lr as well
225 // serialAndSave(rb, OutputPath+MergeOutputPrefix+".rbank");
229 serialAndSave(gr
, OutputPath
+OutputPrefix
+".gr");
230 rb
.saveShortBank(OutputPath
, OutputPrefix
, true); // save 5 bytes rbank and lr as well
232 // serialAndSave(rb, OutputPath+OutputPrefix+".rbank");
238 UGlobalPosition gpos;
240 gpos = gr.retrievePosition(CVector(18630, -24604, 0));
241 const CLocalRetriever &lr = gr.getRetriever(gr.getInstance(gpos.InstanceId).getRetrieverId());
242 lr.dumpSurface(gpos.LocalPosition.Surface, gr.getInstance(gpos.InstanceId).getOrigin());
246 void createRetriever(vector
<CVector
> &translation
)
250 translation
.resize(Meshes
.size());
252 for (i
=0; i
<Meshes
.size(); ++i
)
255 CCollisionMeshBuild cmb
;
257 string meshName
= Meshes
[i
];
259 nlinfo("compute retriever %s", meshName
.c_str());
263 openAndSerial(cmb
, MeshPath
+meshName
+".cmb");
266 vector
<bool> usedMaterials
;
270 for (j
=0; j
<cmb
.Faces
.size(); ++j
)
271 if (cmb
.Faces
[j
].Material
> (sint
)maxMat
)
272 maxMat
= cmb
.Faces
[j
].Material
;
274 usedMaterials
.resize(maxMat
+1);
276 for (j
=0; j
<usedMaterials
.size(); ++j
)
277 usedMaterials
[j
] = false;
278 for (j
=0; j
<cmb
.Faces
.size(); ++j
)
279 usedMaterials
[cmb
.Faces
[j
].Material
] = true;
281 for (j
=0; j
<usedMaterials
.size(); ++j
)
282 if (usedMaterials
[j
])
283 nlinfo("Material %d used", j
);
287 computeRetriever(cmb
, lr
, translation
[i
], true);
291 for (tt=0; tt<lr.getSurfaces().size(); ++tt)
296 // Compute an identifier name
297 string indentifier
= meshName
;
298 string::size_type sharpPos
= indentifier
.rfind ('#');
299 if (sharpPos
!= string::npos
)
300 indentifier
= indentifier
.substr (0, sharpPos
);
301 lr
.setIdentifier(indentifier
);
304 serialAndSave(lr
, OutputPath
+meshName
+".lr");
306 catch (const Exception
&e
)
308 nlwarning("WARNING: can compute lr '%s.lr': %s", meshName
.c_str(), e
.what());
316 void serialGPos(UGlobalPosition
&gp
, NLMISC::IStream
&f
)
318 f
.serial(gp
.InstanceId
, gp
.LocalPosition
.Surface
, gp
.LocalPosition
.Estimation
);
321 struct CGlobalPositionCompare
323 UGlobalPosition ClientPosition
,
327 void serial(NLMISC::IStream
&f
)
329 serialGPos(ClientPosition
, f
);
330 serialGPos(RetrievedPosition
, f
);
335 vector
<CGlobalPositionCompare
> StoredPosition
;
338 void loadAndDumpPositions()
342 f
.open("backup.position");
343 f
.serialCont(StoredPosition
);
347 for (i
=0; i
<StoredPosition
.size(); ++i
)
349 CGlobalPositionCompare
&c
= StoredPosition
[i
];
350 nlinfo("cmp=%s cl(%4d,%4d,%.8f,%.8f,%.8f) gr(%4d,%4d,%.8f,%.8f,%.8f)",
351 c
.Compare
? "true" : "false",
352 c
.ClientPosition
.InstanceId
, c
.ClientPosition
.LocalPosition
.Surface
, c
.ClientPosition
.LocalPosition
.Estimation
.x
, c
.ClientPosition
.LocalPosition
.Estimation
.y
, c
.ClientPosition
.LocalPosition
.Estimation
.z
,
353 c
.RetrievedPosition
.InstanceId
, c
.RetrievedPosition
.LocalPosition
.Surface
, c
.RetrievedPosition
.LocalPosition
.Estimation
.x
, c
.RetrievedPosition
.LocalPosition
.Estimation
.y
, c
.RetrievedPosition
.LocalPosition
.Estimation
.z
);
360 int main(int argc, char **argv)
363 CIFile f("R:/code/ryzom/data/3d/continents/matis/pacs/matis.rbank");
367 bank.saveShortBank("R:/code/ryzom/data/3d/continents/matis/pacs", "matis");
372 int main(int argc
, char **argv
)
374 vector
<CVector
> translation
;
378 ErrorLog
->removeDisplayer("DEFAULT_MBD");
382 start
= CTime::getLocalTime();
383 createRetriever(translation
);
385 // translation[0] = CVector(-4670.0f, 3579.0f, 0.0f);
387 makeGlobalRetriever(translation
);
388 end
= CTime::getLocalTime();
390 nlinfo("%.3f seconds work", (double)(end
-start
)/1000.0);
393 for (i
=0; i
<translation
.size(); ++i
)
394 nlinfo("CVector\ttranslation_%d = CVector(%.1ff, %.1ff, %.1ff);", i
, translation
[i
].x
, translation
[i
].y
, translation
[i
].z
);