Skip to content

Commit 2597686

Browse files
author
David
committed
Converted Landscape export from RawMesh to MeshDescription from 4.22 onwards.
1 parent 1a8cd3e commit 2597686

File tree

6 files changed

+830
-4
lines changed

6 files changed

+830
-4
lines changed

Source/UnrealEnginePython/Private/UEPyModule.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@
102102
#include "Wrappers/UEPyFAssetData.h"
103103
#include "Wrappers/UEPyFARFilter.h"
104104
#include "Wrappers/UEPyFRawMesh.h"
105+
#if ENGINE_MINOR_VERSION > 21
106+
#include "Wrappers/UEPyFMeshDescription.h"
107+
#endif
105108
#include "Wrappers/UEPyFStringAssetReference.h"
106109

107110
#include "UObject/UEPyAnimSequence.h"
@@ -985,7 +988,11 @@ static PyMethodDef ue_PyUObject_methods[] = {
985988
{ "create_landscape_info", (PyCFunction)py_ue_create_landscape_info, METH_VARARGS, "" },
986989
{ "get_landscape_info", (PyCFunction)py_ue_get_landscape_info, METH_VARARGS, "" },
987990
{ "landscape_import", (PyCFunction)py_ue_landscape_import, METH_VARARGS, "" },
991+
#if ENGINE_MINOR_VERSION > 21
992+
{ "landscape_export_to_mesh_description", (PyCFunction)py_ue_landscape_export_to_mesh_description, METH_VARARGS, "" },
993+
#else
988994
{ "landscape_export_to_raw_mesh", (PyCFunction)py_ue_landscape_export_to_raw_mesh, METH_VARARGS, "" },
995+
#endif
989996
#endif
990997

991998
// Player
@@ -2120,7 +2127,18 @@ void unreal_engine_init_py_module()
21202127
ue_python_init_fbx(new_unreal_engine_module);
21212128
#endif
21222129
#if ENGINE_MINOR_VERSION > 13
2130+
#if ENGINE_MINOR_VERSION > 21
2131+
ue_python_init_fmesh_description(new_unreal_engine_module);
2132+
#if 0
2133+
ue_python_init_fmeshvertex(new_unreal_engine_module);
2134+
ue_python_init_fmeshvertexinstance(new_unreal_engine_module);
2135+
ue_python_init_fmeshpolygon(new_unreal_engine_module);
2136+
#endif
2137+
2138+
ue_python_init_fraw_mesh(new_unreal_engine_module);
2139+
#else
21232140
ue_python_init_fraw_mesh(new_unreal_engine_module);
2141+
#endif
21242142
#endif
21252143
ue_python_init_iplugin(new_unreal_engine_module);
21262144
#endif

Source/UnrealEnginePython/Private/UObject/UEPyLandscape.cpp

Lines changed: 66 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@
88
#include "Runtime/Landscape/Classes/LandscapeInfo.h"
99
#include "GameFramework/GameModeBase.h"
1010

11+
#if ENGINE_MINOR_VERSION > 21
12+
#include "Wrappers/UEPyFMeshDescription.h"
13+
#include "Runtime/MeshDescription/Public/MeshDescription.h"
14+
#if ENGINE_MINOR_VERSION > 24
15+
#include "Runtime/StaticMeshDescription/Public/StaticMeshAttributes.h"
16+
#endif
17+
#endif
18+
1119
PyObject* py_ue_create_landscape_info(ue_PyUObject* self, PyObject* args)
1220
{
1321

@@ -84,6 +92,61 @@ PyObject* py_ue_landscape_import(ue_PyUObject* self, PyObject* args)
8492
Py_RETURN_NONE;
8593
}
8694

95+
// so what to do here - create new function or leave as returning
96+
// a different object type - from FRawMesh to FMeshDescription???
97+
// creating new function
98+
// curious - the original code specified > 21 but FMeshDescription appears to exist in version 4.21.2
99+
// for the moment leave as > 21 - but maybe should be >= 21??
100+
101+
#if ENGINE_MINOR_VERSION > 21
102+
PyObject* py_ue_landscape_export_to_mesh_description(ue_PyUObject* self, PyObject* args)
103+
{
104+
105+
ue_py_check(self);
106+
107+
int lod = 0;
108+
109+
if (!PyArg_ParseTuple(args, "|i:landscape_import", &lod))
110+
return nullptr;
111+
112+
ALandscapeProxy* landscape = ue_py_check_type<ALandscapeProxy>(self);
113+
if (!landscape)
114+
return PyErr_Format(PyExc_Exception, "uobject is not a ULandscapeProxy");
115+
116+
// ah - now think we dont have to set anything into the FMeshDescription
117+
// well apparently we do have to set some attributes
118+
// - we create a new instance, then run ExportToRawMesh which fills the FMeshDescription
119+
// with all the mesh data
120+
121+
// this code is following MeshMergeHelpers.cpp Landscape ExportToRawMesh code
122+
// another example is in WorldTileCollectionModel.cpp which creates a full UStaticMesh class model
123+
// note this is exporting(converting) to StaticMesh type mesh description
124+
// - we now need to write extraction functions in the FMeshDescription wrapper
125+
// to actually get any data
126+
// we use a locally allocated FMeshDescription here
127+
// - py_ue_new_fmesh_description will allocate a new copy from this
128+
// should I worry about the bounds??
129+
130+
//FMeshDescription* mesh_description = new FMeshDescription();
131+
//FBoxSphereBounds LandscapeBounds = EstimatedMeshProxyBounds;
132+
//Landscape->ExportToRawMesh(LandscapeExportLOD, *MeshDescription, LandscapeBounds);
133+
#if ENGINE_MINOR_VERSION > 24
134+
FMeshDescription mesh_description;
135+
FStaticMeshAttributes(mesh_description).Register();
136+
#else
137+
// definitely required for 4.22
138+
FMeshDescription mesh_description;
139+
UStaticMesh::RegisterMeshAttributes(mesh_description);
140+
#endif
141+
142+
if (!landscape->ExportToRawMesh(lod, mesh_description))
143+
return PyErr_Format(PyExc_Exception, "unable to export landscape to FMeshDescription");
144+
145+
return py_ue_new_fmesh_description(mesh_description);
146+
}
147+
#endif
148+
149+
87150
PyObject* py_ue_landscape_export_to_raw_mesh(ue_PyUObject* self, PyObject* args)
88151
{
89152

@@ -99,7 +162,9 @@ PyObject* py_ue_landscape_export_to_raw_mesh(ue_PyUObject* self, PyObject* args)
99162
return PyErr_Format(PyExc_Exception, "uobject is not a ULandscapeProxy");
100163

101164
#if ENGINE_MINOR_VERSION > 21
102-
return PyErr_Format(PyExc_Exception, "MeshDescription struct is still unsupported");;
165+
// well pigs this means UnrealEnginePython does not support FMeshDescription why??
166+
//return PyErr_Format(PyExc_Exception, "MeshDescription struct is still unsupported");
167+
return PyErr_Format(PyExc_Exception, "RawMesh struct no longer supported in Unreal Engine");
103168
#else
104169
FRawMesh raw_mesh;
105170
if (!landscape->ExportToRawMesh(lod, raw_mesh))

Source/UnrealEnginePython/Private/UObject/UEPyLandscape.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,8 @@
88
PyObject *py_ue_create_landscape_info(ue_PyUObject *self, PyObject *);
99
PyObject *py_ue_get_landscape_info(ue_PyUObject *self, PyObject *);
1010
PyObject *py_ue_landscape_import(ue_PyUObject *self, PyObject *);
11+
#if ENGINE_MINOR_VERSION > 21
12+
PyObject *py_ue_landscape_export_to_mesh_description(ue_PyUObject *self, PyObject *);
13+
#endif
1114
PyObject *py_ue_landscape_export_to_raw_mesh(ue_PyUObject *self, PyObject *);
12-
#endif
15+
#endif

0 commit comments

Comments
 (0)