|
22 | 22 | #include "Toolkits/AssetEditorManager.h" |
23 | 23 | #include "LevelEditor.h" |
24 | 24 | #include "Editor/LandscapeEditor/Public/LandscapeEditorUtils.h" |
| 25 | +#include "Editor/LandscapeEditor/Public/LandscapeEditorModule.h" |
| 26 | +#include "Editor/LandscapeEditor/Public/LandscapeFileFormatInterface.h" |
25 | 27 |
|
26 | 28 |
|
27 | 29 | PyObject *py_unreal_engine_editor_play_in_viewport(PyObject * self, PyObject * args) |
@@ -2145,5 +2147,59 @@ PyObject *py_unreal_engine_heightmap_expand(PyObject * self, PyObject * args) |
2145 | 2147 |
|
2146 | 2148 | } |
2147 | 2149 |
|
| 2150 | +PyObject *py_unreal_engine_heightmap_import(PyObject * self, PyObject * args) |
| 2151 | +{ |
| 2152 | + char *filename; |
| 2153 | + int width = 0; |
| 2154 | + int height = 0; |
| 2155 | + if (!PyArg_ParseTuple(args, "s|ii:heightmap_import", &filename, &width, &height)) |
| 2156 | + return nullptr; |
| 2157 | + |
| 2158 | + ILandscapeEditorModule & LandscapeModule = FModuleManager::GetModuleChecked<ILandscapeEditorModule>("LandscapeEditor"); |
| 2159 | + const ILandscapeHeightmapFileFormat *format = LandscapeModule.GetHeightmapFormatByExtension(*FPaths::GetExtension(UTF8_TO_TCHAR(filename), true)); |
| 2160 | + |
| 2161 | + if (!format) |
| 2162 | + { |
| 2163 | + return PyErr_Format(PyExc_Exception, "invalid heightmap format"); |
| 2164 | + } |
| 2165 | + |
| 2166 | + FLandscapeFileResolution resolution = { width, height }; |
| 2167 | + |
| 2168 | + if (width <= 0 || height <= 0) |
| 2169 | + { |
| 2170 | + FLandscapeHeightmapInfo info = format->Validate(UTF8_TO_TCHAR(filename)); |
| 2171 | + if (info.ResultCode == ELandscapeImportResult::Error) |
| 2172 | + { |
| 2173 | + return PyErr_Format(PyExc_Exception, "unable to import heightmap: %s", TCHAR_TO_UTF8(*info.ErrorMessage.ToString())); |
| 2174 | + } |
| 2175 | + |
| 2176 | + if (info.ResultCode == ELandscapeImportResult::Warning) |
| 2177 | + { |
| 2178 | + UE_LOG(LogPython, Warning, TEXT("%s"), *info.ErrorMessage.ToString()); |
| 2179 | + } |
| 2180 | + |
| 2181 | + if (info.PossibleResolutions.Num() < 1) |
| 2182 | + { |
| 2183 | + return PyErr_Format(PyExc_Exception, "unable to retrieve heightmap resolution"); |
| 2184 | + } |
| 2185 | + |
| 2186 | + resolution = info.PossibleResolutions[0]; |
| 2187 | + } |
| 2188 | + |
| 2189 | + FLandscapeHeightmapImportData imported = format->Import(UTF8_TO_TCHAR(filename), resolution); |
| 2190 | + |
| 2191 | + if (imported.ResultCode == ELandscapeImportResult::Error) |
| 2192 | + { |
| 2193 | + return PyErr_Format(PyExc_Exception, "unable to import heightmap: %s", TCHAR_TO_UTF8(*imported.ErrorMessage.ToString())); |
| 2194 | + } |
| 2195 | + |
| 2196 | + if (imported.ResultCode == ELandscapeImportResult::Warning) |
| 2197 | + { |
| 2198 | + UE_LOG(LogPython, Warning, TEXT("%s"), *imported.ErrorMessage.ToString()); |
| 2199 | + } |
| 2200 | + |
| 2201 | + return Py_BuildValue((char *)"Oii", PyByteArray_FromStringAndSize((char *)imported.Data.GetData(), imported.Data.Num() * sizeof(uint16)), resolution.Width, resolution.Height); |
| 2202 | +} |
| 2203 | + |
2148 | 2204 | #endif |
2149 | 2205 |
|
0 commit comments