diff --git a/code/nel/tools/ligo/unbuild_land/unbuild_land.cpp b/code/nel/tools/ligo/unbuild_land/unbuild_land.cpp index 4f9ed0d1f..37b3b4e79 100644 --- a/code/nel/tools/ligo/unbuild_land/unbuild_land.cpp +++ b/code/nel/tools/ligo/unbuild_land/unbuild_land.cpp @@ -49,6 +49,8 @@ namespace /* anonymous */ sint32 s_ZoneMinX, s_ZoneMinY, s_ZoneMaxX, s_ZoneMaxY; float s_CellSize = 160.0f; +bool s_Height = false; + std::string s_ZoneBricksDirIn; // UTF-8 path std::string s_ZoneRuntimeDirIn; // UTF-8 path std::string s_LandFileOut; // UTF-8 path @@ -111,9 +113,9 @@ Fail: return false; } -void centerVertices(std::vector &vertices) +void centerVertices(std::vector &vertices) { - CVector2f avg = CVector2f(0, 0); + CVector avg = CVector(0.0f, 0.0f, 0.0f); for (ptrdiff_t i = 0; i < vertices.size(); ++i) avg += vertices[i]; avg /= (float)vertices.size(); @@ -122,19 +124,19 @@ void centerVertices(std::vector &vertices) vertices[i] -= avg; } -void offsetVertices(std::vector &vertices, int x, int y) +void offsetVertices(std::vector &vertices, int x, int y) { - CVector2f off = CVector2f((float)x * s_CellSize, (float)y * s_CellSize); + CVector off = CVector((float)x * s_CellSize, (float)y * s_CellSize, 0.0f); for (ptrdiff_t i = 0; i < vertices.size(); ++i) vertices[i] -= off; } -float ratePoints(const std::vector &zone, const std::vector &ref, float xx, float xy, float yx, float yy) +float ratePoints(const std::vector &zone, const std::vector &ref, float xx, float xy, float yx, float yy) { // Rudimentary distance rating of vertices (not very reliable, but good enough!) float md = 0.f; - // std::vector refcpy = ref; + // std::vector refcpy = ref; std::vector usedref; usedref.resize(ref.size(), false); for (ptrdiff_t i = 0; i < zone.size(); ++i) @@ -142,10 +144,10 @@ float ratePoints(const std::vector &zone, const std::vector &zone, const std::vector &zoneVertices, const std::map> &brickVertices) +void findBestBrick(std::string &brick, int &rotate, int &flip, float &es, std::vector &zoneVertices, const std::map> &brickVertices) { float bestPoints = (float)(uint32)~0; - for (std::map>::const_iterator it = brickVertices.begin(), end = brickVertices.end(); it != end; ++it) + for (std::map>::const_iterator it = brickVertices.begin(), end = brickVertices.end(); it != end; ++it) { float rating; rating = ratePoints(zoneVertices, it->second, 1.0, 0.0, 0.0, 1.0); @@ -323,7 +325,7 @@ bool unbuildLand() // Read in all the bricks std::vector brickFiles; CPath::getPathContent(s_ZoneBricksDirIn, false, false, true, brickFiles); - std::map> brickVertices; + std::map> brickVertices; for (std::vector::const_iterator it = brickFiles.begin(), end = brickFiles.end(); it != end; ++it) { if (CFile::getExtension(*it) != "zone") @@ -352,9 +354,9 @@ bool unbuildLand() std::vector zoneBorderVertices; zone.retrieve(zonePatches, zoneBorderVertices); - brickVertices[CFile::getFilenameWithoutExtension(*it)] = std::vector(); - std::vector &vec = brickVertices[CFile::getFilenameWithoutExtension(*it)]; - CVector2f off = CVector2f(s_CellSize * 0.5f, s_CellSize * 0.5f); + brickVertices[CFile::getFilenameWithoutExtension(*it)] = std::vector(); + std::vector &vec = brickVertices[CFile::getFilenameWithoutExtension(*it)]; + CVector off = CVector(s_CellSize * 0.5f, s_CellSize * 0.5f, 0.0f); for (ptrdiff_t i = 0; i < zonePatches.size(); ++i) { for (ptrdiff_t j = 0; j < 4; ++j) @@ -369,7 +371,7 @@ bool unbuildLand() { float rx = zonePatches[i].Patch.Vertices[j].x - off.x; float ry = zonePatches[i].Patch.Vertices[j].y - off.y; - vec.push_back(CVector2f(rx, ry)); + vec.push_back(CVector(rx, ry, s_Height ? zonePatches[i].Patch.Vertices[j].z : 0.0f)); } SkipA:; } @@ -403,8 +405,8 @@ bool unbuildLand() std::vector zoneBorderVertices; zone.retrieve(zonePatches, zoneBorderVertices); - std::vector vec; - CVector2f off = CVector2f((float)x * s_CellSize, (float)y * s_CellSize) + CVector2f(s_CellSize * 0.5f, s_CellSize * 0.5f); + std::vector vec; + CVector off = CVector((float)x * s_CellSize, (float)y * s_CellSize, 0.0f) + CVector(s_CellSize * 0.5f, s_CellSize * 0.5f, 0.0f); for (ptrdiff_t i = 0; i < zonePatches.size(); ++i) { for (ptrdiff_t j = 0; j < 4; ++j) @@ -419,7 +421,7 @@ bool unbuildLand() { float rx = zonePatches[i].Patch.Vertices[j].x - off.x; float ry = zonePatches[i].Patch.Vertices[j].y - off.y; - vec.push_back(CVector2f(rx, ry)); + vec.push_back(CVector(rx, ry, s_Height ? zonePatches[i].Patch.Vertices[j].z : 0.0f)); } SkipB:; } @@ -457,6 +459,7 @@ int main(int argc, char **argv) args.addAdditionalArg("zonemin", "Zone boundary"); args.addAdditionalArg("zonemax", "Zone boundary"); args.addArg("", "cellsize", "meters", "Zone cell size"); + args.addArg("", "height", "", "Take Z coordinate into account"); if (!args.parse(argc, argv)) { @@ -479,6 +482,8 @@ int main(int argc, char **argv) s_ZoneMinY = min(zoneMinY, zoneMaxY); s_ZoneMaxY = max(zoneMinY, zoneMaxY); + s_Height = args.haveLongArg("height"); + if (args.haveLongArg("cellsize")) { if (!NLMISC::fromString(args.getLongArg("cellsize")[0], s_CellSize))