|
1 | 1 | #include "UnrealEnginePythonPrivatePCH.h" |
2 | 2 |
|
3 | 3 | #include "Runtime/Engine/Classes/Kismet/KismetSystemLibrary.h" |
| 4 | +#include "Runtime/Foliage/Public/FoliageType.h" |
| 5 | +#include "Runtime/Foliage/Public/InstancedFoliageActor.h" |
4 | 6 |
|
5 | 7 | PyObject *py_ue_world_exec(ue_PyUObject *self, PyObject * args) |
6 | 8 | { |
@@ -322,3 +324,59 @@ PyObject *py_ue_set_current_level(ue_PyUObject *self, PyObject * args) |
322 | 324 | Py_RETURN_FALSE; |
323 | 325 | } |
324 | 326 |
|
| 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 | + |
0 commit comments