Editor: Import Heightmap from image
Function similar to MuwuMs tool https://forum.megaglest.org/index.php?topic=8353.0 Image is resized to the dimensions of the map. Changes in the ratio only work with some image formats (png,jpg) wxWidget bug?
This commit is contained in:
parent
b20002e7dc
commit
880730e5e1
|
@ -18,6 +18,7 @@
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include"platform_util.h"
|
#include"platform_util.h"
|
||||||
#include <wx/stdpaths.h>
|
#include <wx/stdpaths.h>
|
||||||
|
#include "wx/image.h"
|
||||||
#ifndef WIN32
|
#ifndef WIN32
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#endif
|
#endif
|
||||||
|
@ -181,6 +182,7 @@ void MainWindow::init(string fname) {
|
||||||
// ---------------------------------------------------------
|
// ---------------------------------------------------------
|
||||||
|
|
||||||
menuEdit->Append(miEditRandomizeHeights, wxT("Randomize &Heights"));
|
menuEdit->Append(miEditRandomizeHeights, wxT("Randomize &Heights"));
|
||||||
|
menuEdit->Append(miEditImportHeights, wxT("Import Heights from Image"));
|
||||||
menuEdit->Append(miEditRandomize, wxT("Randomi&ze Players"));
|
menuEdit->Append(miEditRandomize, wxT("Randomi&ze Players"));
|
||||||
menuEdit->Append(miEditSwitchSurfaces, wxT("Switch Sur&faces..."));
|
menuEdit->Append(miEditSwitchSurfaces, wxT("Switch Sur&faces..."));
|
||||||
menuEdit->Append(miEditInfo, wxT("&Info..."));
|
menuEdit->Append(miEditInfo, wxT("&Info..."));
|
||||||
|
@ -1067,6 +1069,52 @@ void MainWindow::onMenuEditRandomizeHeights(wxCommandEvent &event) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::onMenuEditImportHeights(wxCommandEvent &event) {
|
||||||
|
if(program == NULL) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
fileDialog->SetMessage(wxT("Select heigthmap image to load"));
|
||||||
|
fileDialog->SetWildcard(wxT("All Images|*.bmp;*.png;*.jpg;*.jpeg;*.gif;.*.tga;*.tiff;*.tif|PNG-Image (*.png)|*.png|JPEG-Image (*.jpg, *.jpeg)|*.jpg;*.jpeg|BMP-Image (*.bmp)|*.bmp|GIF-Image (*.gif)|*.gif|TIFF-Image (*.tif, *.tiff)|*.tiff;*.tif"));
|
||||||
|
if (fileDialog->ShowModal() == wxID_OK) {
|
||||||
|
#ifdef WIN32
|
||||||
|
const wxWX2MBbuf tmp_buf = wxConvCurrent->cWX2MB(wxFNCONV(fileDialog->GetPath()));
|
||||||
|
currentFile = tmp_buf;
|
||||||
|
|
||||||
|
auto_ptr<wchar_t> wstr(Ansi2WideString(currentFile.c_str()));
|
||||||
|
currentFile = utf8_encode(wstr.get());
|
||||||
|
#elif wxCHECK_VERSION(2, 9, 1)
|
||||||
|
currentFile = fileDialog->GetPath().ToStdString();
|
||||||
|
#else
|
||||||
|
const wxWX2MBbuf tmp_buf = wxConvCurrent->cWX2MB(fileDialog->GetPath());
|
||||||
|
currentFile = tmp_buf;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
wxImage* img=new wxImage(currentFile);
|
||||||
|
if(img != NULL) {
|
||||||
|
wxImage grey_img = img->ConvertToGreyscale();
|
||||||
|
delete img;
|
||||||
|
int w =grey_img.GetWidth();
|
||||||
|
int h =grey_img.GetHeight();
|
||||||
|
int map_w = program->getMap()->getW();
|
||||||
|
int map_h = program->getMap()->getH();
|
||||||
|
program->setUndoPoint(ctAll);
|
||||||
|
if(w != map_w && h != map_h) {
|
||||||
|
grey_img.Rescale(map_w,map_h,wxIMAGE_QUALITY_HIGH);
|
||||||
|
}
|
||||||
|
program->importMapHeights(grey_img.GetData());
|
||||||
|
setDirty();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (const string &e) {
|
||||||
|
MsgDialog(this, ToUnicode(e), wxT("Exception"), wxOK | wxICON_ERROR).ShowModal();
|
||||||
|
}
|
||||||
|
catch (const exception &e) {
|
||||||
|
MsgDialog(this, ToUnicode(e.what()), wxT("Exception"), wxOK | wxICON_ERROR).ShowModal();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void MainWindow::onMenuEditRandomize(wxCommandEvent &event) {
|
void MainWindow::onMenuEditRandomize(wxCommandEvent &event) {
|
||||||
if(program == NULL) {
|
if(program == NULL) {
|
||||||
return;
|
return;
|
||||||
|
@ -1464,6 +1512,7 @@ BEGIN_EVENT_TABLE(MainWindow, wxFrame)
|
||||||
EVT_MENU(miEditRotatecopyCorner, MainWindow::onMenuEditRotatecopyCorner)
|
EVT_MENU(miEditRotatecopyCorner, MainWindow::onMenuEditRotatecopyCorner)
|
||||||
|
|
||||||
EVT_MENU(miEditRandomizeHeights, MainWindow::onMenuEditRandomizeHeights)
|
EVT_MENU(miEditRandomizeHeights, MainWindow::onMenuEditRandomizeHeights)
|
||||||
|
EVT_MENU(miEditImportHeights, MainWindow::onMenuEditImportHeights)
|
||||||
EVT_MENU(miEditRandomize, MainWindow::onMenuEditRandomize)
|
EVT_MENU(miEditRandomize, MainWindow::onMenuEditRandomize)
|
||||||
EVT_MENU(miEditSwitchSurfaces, MainWindow::onMenuEditSwitchSurfaces)
|
EVT_MENU(miEditSwitchSurfaces, MainWindow::onMenuEditSwitchSurfaces)
|
||||||
EVT_MENU(miEditInfo, MainWindow::onMenuEditInfo)
|
EVT_MENU(miEditInfo, MainWindow::onMenuEditInfo)
|
||||||
|
|
|
@ -137,6 +137,7 @@ private:
|
||||||
miEditMirror,
|
miEditMirror,
|
||||||
|
|
||||||
miEditRandomizeHeights,
|
miEditRandomizeHeights,
|
||||||
|
miEditImportHeights,
|
||||||
miEditRandomize,
|
miEditRandomize,
|
||||||
miEditSwitchSurfaces,
|
miEditSwitchSurfaces,
|
||||||
miEditInfo,
|
miEditInfo,
|
||||||
|
@ -254,6 +255,7 @@ public:
|
||||||
void onMenuEditRotatecopyCorner(wxCommandEvent &event); // copy top left 1/4 to top right 1/4, rotated
|
void onMenuEditRotatecopyCorner(wxCommandEvent &event); // copy top left 1/4 to top right 1/4, rotated
|
||||||
|
|
||||||
void onMenuEditRandomizeHeights(wxCommandEvent &event);
|
void onMenuEditRandomizeHeights(wxCommandEvent &event);
|
||||||
|
void onMenuEditImportHeights(wxCommandEvent &event);
|
||||||
void onMenuEditRandomize(wxCommandEvent &event);
|
void onMenuEditRandomize(wxCommandEvent &event);
|
||||||
void onMenuEditSwitchSurfaces(wxCommandEvent &event);
|
void onMenuEditSwitchSurfaces(wxCommandEvent &event);
|
||||||
void onMenuEditInfo(wxCommandEvent &event);
|
void onMenuEditInfo(wxCommandEvent &event);
|
||||||
|
|
|
@ -565,6 +565,10 @@ void Program::randomizeMapHeights(bool withReset,int minimumHeight, int maximumH
|
||||||
if(map) map->randomizeHeights(withReset, minimumHeight, maximumHeight, chanceDivider, smoothRecursions);
|
if(map) map->randomizeHeights(withReset, minimumHeight, maximumHeight, chanceDivider, smoothRecursions);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Program::importMapHeights(unsigned char* data) {
|
||||||
|
if(map) map->importMapHeights(data);
|
||||||
|
}
|
||||||
|
|
||||||
void Program::randomizeFactions() {
|
void Program::randomizeFactions() {
|
||||||
if(map) map->randomizeFactions();
|
if(map) map->randomizeFactions();
|
||||||
}
|
}
|
||||||
|
|
|
@ -151,7 +151,8 @@ public:
|
||||||
void shiftUp();
|
void shiftUp();
|
||||||
void shiftDown();
|
void shiftDown();
|
||||||
|
|
||||||
void randomizeMapHeights(bool withReset, int minimumHeight, int maximumHeight, int chanceDivider, int smoothRecursions);;
|
void randomizeMapHeights(bool withReset, int minimumHeight, int maximumHeight, int chanceDivider, int smoothRecursions);
|
||||||
|
void importMapHeights(unsigned char* data);
|
||||||
void randomizeFactions();
|
void randomizeFactions();
|
||||||
void switchMapSurfaces(int surf1, int surf2);
|
void switchMapSurfaces(int surf1, int surf2);
|
||||||
void loadMap(const string &path);
|
void loadMap(const string &path);
|
||||||
|
|
|
@ -208,6 +208,7 @@ public:
|
||||||
void resize(int w, int h, float alt, MapSurfaceType surf);
|
void resize(int w, int h, float alt, MapSurfaceType surf);
|
||||||
void resetFactions(int maxFactions);
|
void resetFactions(int maxFactions);
|
||||||
void randomizeHeights(bool withReset,int minimumHeight, int maximumHeight, int chanceDevider, int smoothRecursions);
|
void randomizeHeights(bool withReset,int minimumHeight, int maximumHeight, int chanceDevider, int smoothRecursions);
|
||||||
|
void importMapHeights(unsigned char* data);
|
||||||
void randomizeFactions();
|
void randomizeFactions();
|
||||||
void smoothSurface(bool limitHeights);
|
void smoothSurface(bool limitHeights);
|
||||||
void switchSurfaces(MapSurfaceType surf1, MapSurfaceType surf2);
|
void switchSurfaces(MapSurfaceType surf1, MapSurfaceType surf2);
|
||||||
|
|
|
@ -710,6 +710,14 @@ void MapPreview::randomizeHeights(bool withReset,int minimumHeight, int maximumH
|
||||||
hasChanged = true;
|
hasChanged = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MapPreview::importMapHeights(unsigned char* data) {
|
||||||
|
for (int i = 0; i < w; ++i) {
|
||||||
|
for (int j = 0; j < h; ++j) {
|
||||||
|
cells[i][j].height=(data[(i+j*w)*3]*MAX_MAP_CELL_HEIGHT/255)+MIN_MAP_CELL_HEIGHT;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void MapPreview::randomizeFactions() {
|
void MapPreview::randomizeFactions() {
|
||||||
int slPlaceFactorX = random.randRange(0, 1);
|
int slPlaceFactorX = random.randRange(0, 1);
|
||||||
int slPlaceFactorY = random.randRange(0, 1) * 2;
|
int slPlaceFactorY = random.randRange(0, 1) * 2;
|
||||||
|
|
Loading…
Reference in New Issue