From a0902365aee92b18c2ec0a9941cb52cfb85280d2 Mon Sep 17 00:00:00 2001 From: kaetemi Date: Tue, 23 Apr 2019 01:20:14 +0800 Subject: [PATCH] Add unbuild_interface --- code/nel/tools/3d/CMakeLists.txt | 1 + .../tools/3d/unbuild_interface/CMakeLists.txt | 11 ++ .../unbuild_interface/unbuild_interface.cpp | 155 ++++++++++++++++++ 3 files changed, 167 insertions(+) create mode 100644 code/nel/tools/3d/unbuild_interface/CMakeLists.txt create mode 100644 code/nel/tools/3d/unbuild_interface/unbuild_interface.cpp diff --git a/code/nel/tools/3d/CMakeLists.txt b/code/nel/tools/3d/CMakeLists.txt index 08fd9e776..683f2589a 100644 --- a/code/nel/tools/3d/CMakeLists.txt +++ b/code/nel/tools/3d/CMakeLists.txt @@ -34,6 +34,7 @@ IF(WITH_NEL_TOOLS) ENDIF() SUBDIRS( build_interface + unbuild_interface get_neighbors textures_optimizer textures_tool diff --git a/code/nel/tools/3d/unbuild_interface/CMakeLists.txt b/code/nel/tools/3d/unbuild_interface/CMakeLists.txt new file mode 100644 index 000000000..2a10976d3 --- /dev/null +++ b/code/nel/tools/3d/unbuild_interface/CMakeLists.txt @@ -0,0 +1,11 @@ +FILE(GLOB SRC *.cpp *.h) + +SOURCE_GROUP("" FILES ${SRC}) + +ADD_EXECUTABLE(unbuild_interface ${SRC}) + +TARGET_LINK_LIBRARIES(unbuild_interface nelmisc) +NL_DEFAULT_PROPS(unbuild_interface "NeL, Tools, 3D: unbuild_interface") +NL_ADD_RUNTIME_FLAGS(unbuild_interface) + +INSTALL(TARGETS unbuild_interface RUNTIME DESTINATION bin COMPONENT tools3d) diff --git a/code/nel/tools/3d/unbuild_interface/unbuild_interface.cpp b/code/nel/tools/3d/unbuild_interface/unbuild_interface.cpp new file mode 100644 index 000000000..48443cae7 --- /dev/null +++ b/code/nel/tools/3d/unbuild_interface/unbuild_interface.cpp @@ -0,0 +1,155 @@ +/** + * \file unbuild_interface.cpp + * \brief Unbuild Interface + * \date 2009-03-14 13:25GMT + * \author Jan Boon (Kaetemi) + * Unbuild Interface + */ + +/* + * Copyright (C) 2009 by authors + * + * This file is part of NEVRAX NEL. + * NEVRAX NEL is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published + * by the Free Software Foundation, either version 2 of the License, + * or (at your option) any later version. + * + * NEVRAX NEL is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with NEVRAX NEL; see the file COPYING. If not, see + * . + */ + +#include + +// STL includes +#include +#include +#include +#include +#include + +// NeL includes +#include +#include +#include +#include +#include +#include +#include + +// Project includes +// ... + +using namespace std; +using namespace NLMISC; + +namespace { + +} /* anonymous namespace */ + +int main(int nNbArg, char **ppArgs) +{ + // create debug stuff + createDebug(); + + // verify all params + if (nNbArg < 3) + { + nlinfo("ERROR : Wrong number of arguments\n"); + nlinfo("USAGE : unbuild_interface \n"); + return EXIT_FAILURE; + } + string in_tga_name = string(ppArgs[1]); + if (!CFile::fileExists(in_tga_name)) + { + nlerrornoex("File %s does not exist", in_tga_name.c_str()); + return EXIT_FAILURE; + } + string in_txt_name = in_tga_name.substr(0, in_tga_name.size() - 4) + ".txt"; + if (!CFile::fileExists(in_txt_name)) + { + nlerrornoex("File %s does not exist", in_txt_name.c_str()); + return EXIT_FAILURE; + } + string out_path_maps = ppArgs[2]; + if (!CFile::isDirectory(out_path_maps)) + { + nlerrornoex("Directory %s does not exist", out_path_maps.c_str()); + return EXIT_FAILURE; + } + + // read in the tga + CBitmap in_bitmap; + try + { + CIFile in_file; + in_file.open(in_tga_name); + in_bitmap.load(in_file); + in_file.close(); + } + catch (NLMISC::Exception &e) + { + nlerrornoex("(NLMISC::Exception : %s", e.what()); + return EXIT_FAILURE; + } + + // read maps infos from txt + try + { + ifstream in_file; + in_file.open(in_txt_name.c_str()); + string line; + vector line_expl; + line_expl.reserve(5); + while (getline(in_file, line)) + { + // parse from file + line_expl.clear(); + explode(line, " ", line_expl, false); + nlassertex((line_expl.size() == 5), ("Bad line entry count")); + CVectorH vh; // x, y, z, w; + if (!fromString(line_expl[1], vh.x) + || !fromString(line_expl[2], vh.y) + || !fromString(line_expl[3], vh.z) + || !fromString(line_expl[4], vh.w)) + nlerror("Bad line formatting '%s'", line.c_str()); + vh.x *= (float)in_bitmap.getWidth(); + nlassertex((vh.x == (float)(int)vh.x), ("Bad coordinate")); + vh.y *= (float)in_bitmap.getHeight(); + nlassertex((vh.y == (float)(int)vh.y), ("Bad coordinate")); + vh.z *= (float)in_bitmap.getWidth(); + nlassertex((vh.z == (float)(int)vh.z), ("Bad coordinate")); + vh.w *= (float)in_bitmap.getHeight(); + nlassertex((vh.w == (float)(int)vh.w), ("Bad coordinate")); + nlinfo("%s %f %f %f %f", line_expl[0].c_str(), vh.x, vh.y, vh.z, vh.w); + + // write to tga + CBitmap out_bitmap; + out_bitmap.resize((sint32)vh.z - (sint32)vh.x, (sint32)vh.w - (sint32)vh.y, CBitmap::RGBA, true); + out_bitmap.blit(in_bitmap, (sint)vh.x, (sint)vh.y, (sint)vh.z - (sint)vh.x, (sint)vh.w - (sint)vh.y, 0, 0); + COFile out_file; + if (out_file.open(out_path_maps + "/" + line_expl[0])) + { + out_bitmap.writeTGA(out_file, 32); + out_file.close(); + } + else nlerror("Cannot write tga file '%s/%s'", out_path_maps.c_str(), line_expl[0].c_str()); + } + in_file.close(); + } + catch (std::exception &e) + { + nlerrornoex("std::exception : %s", e.what()); + return EXIT_FAILURE; + } + + return EXIT_SUCCESS; +} + +/* end of file */