Skip to content

Commit e82895d

Browse files
author
Roberto De Ioris
committed
added foliage api, #278
1 parent aba54ef commit e82895d

File tree

4 files changed

+72
-2
lines changed

4 files changed

+72
-2
lines changed

Source/UnrealEnginePython/Private/UEPyModule.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -713,6 +713,12 @@ static PyMethodDef ue_PyUObject_methods[] = {
713713
{ "get_current_level", (PyCFunction)py_ue_get_current_level, METH_VARARGS, "" },
714714
{ "set_current_level", (PyCFunction)py_ue_set_current_level, METH_VARARGS, "" },
715715

716+
#if WITH_EDITOR
717+
{ "add_foliage_asset", (PyCFunction)py_ue_add_foliage_asset, METH_VARARGS, "" },
718+
#endif
719+
{ "get_instanced_foliage_actor_for_current_level", (PyCFunction)py_ue_get_instanced_foliage_actor_for_current_level, METH_VARARGS, "" },
720+
721+
716722
{ "add_actor_component", (PyCFunction)py_ue_add_actor_component, METH_VARARGS, "" },
717723
{ "add_actor_root_component", (PyCFunction)py_ue_add_actor_root_component, METH_VARARGS, "" },
718724
{ "get_actor_component_by_type", (PyCFunction)py_ue_get_actor_component_by_type, METH_VARARGS, "" },

Source/UnrealEnginePython/Private/UObject/UEPyWorld.cpp

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#include "UnrealEnginePythonPrivatePCH.h"
22

33
#include "Runtime/Engine/Classes/Kismet/KismetSystemLibrary.h"
4+
#include "Runtime/Foliage/Public/FoliageType.h"
5+
#include "Runtime/Foliage/Public/InstancedFoliageActor.h"
46

57
PyObject *py_ue_world_exec(ue_PyUObject *self, PyObject * args)
68
{
@@ -322,3 +324,59 @@ PyObject *py_ue_set_current_level(ue_PyUObject *self, PyObject * args)
322324
Py_RETURN_FALSE;
323325
}
324326

327+
PyObject *py_ue_get_instanced_foliage_actor_for_current_level(ue_PyUObject *self, PyObject * args)
328+
{
329+
ue_py_check(self);
330+
331+
UWorld *world = ue_get_uworld(self);
332+
if (!world)
333+
return PyErr_Format(PyExc_Exception, "unable to retrieve UWorld from uobject");
334+
335+
Py_RETURN_UOBJECT(AInstancedFoliageActor::GetInstancedFoliageActorForCurrentLevel(world, true));
336+
}
337+
338+
#if WITH_EDITOR
339+
PyObject *py_ue_add_foliage_asset(ue_PyUObject *self, PyObject * args)
340+
{
341+
342+
ue_py_check(self);
343+
344+
PyObject *py_uobject;
345+
346+
if (!PyArg_ParseTuple(args, "O:add_foliage_asset", &py_uobject))
347+
{
348+
return nullptr;
349+
}
350+
351+
UWorld *world = ue_get_uworld(self);
352+
if (!world)
353+
return PyErr_Format(PyExc_Exception, "unable to retrieve UWorld from uobject");
354+
355+
UObject *u_object = ue_py_check_type<UObject>(py_uobject);
356+
if (!u_object)
357+
return PyErr_Format(PyExc_Exception, "argument is not a UObject");
358+
359+
UFoliageType *foliage_type = nullptr;
360+
361+
AInstancedFoliageActor *ifa = AInstancedFoliageActor::GetInstancedFoliageActorForCurrentLevel(world, true);
362+
if (u_object->IsA<UStaticMesh>())
363+
{
364+
foliage_type = ifa->GetLocalFoliageTypeForMesh((UStaticMesh *)u_object);
365+
if (!foliage_type)
366+
{
367+
ifa->AddMesh((UStaticMesh *)u_object, &foliage_type);
368+
}
369+
}
370+
else if (u_object->IsA<UFoliageType>())
371+
{
372+
ifa->AddFoliageType((UFoliageType *)u_object);
373+
}
374+
375+
if (!foliage_type)
376+
return PyErr_Format(PyExc_Exception, "unable to add foliage asset");
377+
378+
Py_RETURN_UOBJECT(foliage_type);
379+
380+
}
381+
#endif
382+

Source/UnrealEnginePython/Private/UObject/UEPyWorld.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,9 @@ PyObject *py_ue_get_game_viewport(ue_PyUObject *, PyObject *);
2828
PyObject *py_ue_get_current_level(ue_PyUObject *, PyObject *);
2929
PyObject *py_ue_set_current_level(ue_PyUObject *, PyObject *);
3030

31-
PyObject *py_ue_get_world_type(ue_PyUObject *, PyObject *);
31+
PyObject *py_ue_get_world_type(ue_PyUObject *, PyObject *);
32+
33+
PyObject *py_ue_get_instanced_foliage_actor_for_current_level(ue_PyUObject *, PyObject *);
34+
#if WITH_EDITOR
35+
PyObject *py_ue_add_foliage_asset(ue_PyUObject *, PyObject *);
36+
#endif

Source/UnrealEnginePython/UnrealEnginePython.Build.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,8 @@ public UnrealEnginePython(TargetInfo Target)
124124
"Voice",
125125
"RenderCore",
126126
"MovieSceneCapture",
127-
"Landscape"
127+
"Landscape",
128+
"Foliage"
128129
// ... add private dependencies that you statically link with here ...
129130
}
130131
);

0 commit comments

Comments
 (0)