Repository navigation
Expand file tree
/
Copy pathUEPyLandscape.cpp
More file actions
97 lines (70 loc) · 2.92 KB
/
Copy pathUEPyLandscape.cpp
File metadata and controls
97 lines (70 loc) · 2.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#include "UnrealEnginePythonPrivatePCH.h"
#include "Runtime/Landscape/Classes/LandscapeProxy.h"
#include "Runtime/Landscape/Classes/LandscapeInfo.h"
#if WITH_EDITOR
PyObject *py_ue_create_landscape_info(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
ALandscapeProxy *landscape = ue_py_check_type<ALandscapeProxy>(self);
if (!landscape)
return PyErr_Format(PyExc_Exception, "uobject is not a ULandscapeProxy");
ue_PyUObject *ret = ue_get_python_wrapper(landscape->CreateLandscapeInfo());
if (!ret)
return PyErr_Format(PyExc_Exception, "uobject is in invalid state");
Py_INCREF(ret);
return (PyObject *)ret;
}
PyObject *py_ue_get_landscape_info(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
ALandscapeProxy *landscape = ue_py_check_type<ALandscapeProxy>(self);
if (!landscape)
return PyErr_Format(PyExc_Exception, "uobject is not a ULandscapeProxy");
ULandscapeInfo *info = landscape->GetLandscapeInfo();
if (!info)
Py_RETURN_NONE;
ue_PyUObject *ret = ue_get_python_wrapper(info);
if (!ret)
return PyErr_Format(PyExc_Exception, "uobject is in invalid state");
Py_INCREF(ret);
return (PyObject *)ret;
}
PyObject *py_ue_landscape_import(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
int section_size;
int sections_per_component;
int component_x;
int component_y;
Py_buffer heightmap_buffer;
int layer_type = (int)ELandscapeImportAlphamapType::Additive;
if (!PyArg_ParseTuple(args, "iiiiy*|i:landscape_import", §ion_size, §ions_per_component, &component_x, &component_y, &heightmap_buffer, &layer_type))
return nullptr;
ALandscapeProxy *landscape = ue_py_check_type<ALandscapeProxy>(self);
if (!landscape)
return PyErr_Format(PyExc_Exception, "uobject is not a ULandscapeProxy");
int quads_per_component = sections_per_component * section_size;
int size_x = component_x * quads_per_component + 1;
int size_y = component_y * quads_per_component + 1;
if (heightmap_buffer.len < (Py_ssize_t)(size_x * size_y * sizeof(uint16)))
return PyErr_Format(PyExc_Exception, "not enough heightmap data, expecting %lu bytes", size_x * size_y * sizeof(uint16));
uint16 *data = (uint16 *)heightmap_buffer.buf;
TArray<FLandscapeImportLayerInfo> infos;
landscape->Import(FGuid::NewGuid(), 0, 0, size_x - 1, size_y - 1, sections_per_component, section_size, data, nullptr, infos, (ELandscapeImportAlphamapType)layer_type);
Py_RETURN_NONE;
}
PyObject *py_ue_landscape_export_to_raw_mesh(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
int lod = 0;
if (!PyArg_ParseTuple(args, "|i:landscape_import", &lod))
return nullptr;
ALandscapeProxy *landscape = ue_py_check_type<ALandscapeProxy>(self);
if (!landscape)
return PyErr_Format(PyExc_Exception, "uobject is not a ULandscapeProxy");
FRawMesh raw_mesh;
if (!landscape->ExportToRawMesh(lod, raw_mesh))
return PyErr_Format(PyExc_Exception, "unable to export landscape to FRawMesh");
return py_ue_new_fraw_mesh(raw_mesh);
}
#endif