|
12 | 12 | #include "FbxMeshUtils.h" |
13 | 13 | #include "Kismet2/BlueprintEditorUtils.h" |
14 | 14 | #include "Editor/LevelEditor/Public/LevelEditorActions.h" |
| 15 | +#include "Editor/UnrealEd/Public/EditorLevelUtils.h" |
15 | 16 |
|
16 | 17 |
|
17 | 18 | PyObject *py_unreal_engine_get_editor_world(PyObject * self, PyObject * args) { |
@@ -832,5 +833,107 @@ PyObject *py_unreal_engine_create_material_instance(PyObject * self, PyObject * |
832 | 833 | return (PyObject *)ret; |
833 | 834 | } |
834 | 835 |
|
| 836 | +PyObject *py_ue_factory_create_new(ue_PyUObject *self, PyObject * args) { |
| 837 | + |
| 838 | + ue_py_check(self); |
| 839 | + |
| 840 | + char *name; |
| 841 | + if (!PyArg_ParseTuple(args, "s:factory_create_new", &name)) { |
| 842 | + return NULL; |
| 843 | + } |
| 844 | + |
| 845 | + if (!self->ue_object->IsA<UFactory>()) |
| 846 | + return PyErr_Format(PyExc_Exception, "uobject is not a Factory"); |
| 847 | + |
| 848 | + UPackage *outer = CreatePackage(nullptr, UTF8_TO_TCHAR(name)); |
| 849 | + if (!outer) |
| 850 | + return PyErr_Format(PyExc_Exception, "unable to create package"); |
| 851 | + |
| 852 | + UFactory *factory = (UFactory *)self->ue_object; |
| 853 | + UClass *u_class = self->ue_object->GetClass(); |
| 854 | + |
| 855 | + char *obj_name = strrchr(name, '/') + 1; |
| 856 | + if (strlen(obj_name) < 1) { |
| 857 | + return PyErr_Format(PyExc_Exception, "invalid object name"); |
| 858 | + } |
| 859 | + |
| 860 | + UObject *u_object = factory->FactoryCreateNew(u_class, outer, FName(UTF8_TO_TCHAR(obj_name)), RF_Public | RF_Standalone, nullptr, GWarn); |
| 861 | + |
| 862 | + if (!u_object) |
| 863 | + return PyErr_Format(PyExc_Exception, "unable to create new object from factory"); |
| 864 | + |
| 865 | + FAssetRegistryModule::AssetCreated(u_object); |
| 866 | + outer->MarkPackageDirty(); |
| 867 | + |
| 868 | + ue_PyUObject *ret = ue_get_python_wrapper(u_object); |
| 869 | + if (!ret) |
| 870 | + return PyErr_Format(PyExc_Exception, "uobject is in invalid state"); |
| 871 | + |
| 872 | + Py_INCREF(ret); |
| 873 | + return (PyObject *)ret; |
| 874 | +} |
| 875 | + |
| 876 | +PyObject *py_unreal_engine_add_level_to_world(PyObject *self, PyObject * args) { |
| 877 | + |
| 878 | + PyObject *py_world; |
| 879 | + char *name; |
| 880 | + PyObject *py_bool = nullptr; |
| 881 | + if (!PyArg_ParseTuple(args, "Os|O:add_level_to_world", &py_world, &name, &py_bool)) { |
| 882 | + return NULL; |
| 883 | + } |
| 884 | + |
| 885 | + if (!ue_is_pyuobject(py_world)) |
| 886 | + return PyErr_Format(PyExc_Exception, "argument is not a UWorld"); |
| 887 | + |
| 888 | + ue_PyUObject *py_obj_world = (ue_PyUObject *)py_world; |
| 889 | + |
| 890 | + if (!py_obj_world->ue_object->IsA<UWorld>()) { |
| 891 | + return PyErr_Format(PyExc_Exception, "argument is not a UWorld"); |
| 892 | + } |
| 893 | + |
| 894 | + UWorld *u_world = (UWorld *)py_obj_world->ue_object; |
| 895 | + |
| 896 | + UClass *streaming_mode_class = ULevelStreamingKismet::StaticClass(); |
| 897 | + if (py_bool && PyObject_IsTrue(py_bool)) { |
| 898 | + streaming_mode_class = ULevelStreamingAlwaysLoaded::StaticClass(); |
| 899 | + } |
| 900 | + |
| 901 | + ULevel *level = EditorLevelUtils::AddLevelToWorld(u_world, UTF8_TO_TCHAR(name), streaming_mode_class); |
| 902 | + if (level) { |
| 903 | + // TODO: update levels list |
| 904 | + } |
| 905 | + |
| 906 | + ue_PyUObject *ret = ue_get_python_wrapper(level); |
| 907 | + if (!ret) |
| 908 | + return PyErr_Format(PyExc_Exception, "uobject is in invalid state"); |
| 909 | + |
| 910 | + Py_INCREF(ret); |
| 911 | + return (PyObject *)ret; |
| 912 | +} |
| 913 | + |
| 914 | +PyObject *py_unreal_engine_move_selected_actors_to_level(PyObject *self, PyObject * args) { |
| 915 | + |
| 916 | + PyObject *py_level; |
| 917 | + if (!PyArg_ParseTuple(args, "OO:move_selected_actors_to_level", &py_level)) { |
| 918 | + return NULL; |
| 919 | + } |
| 920 | + |
| 921 | + if (!ue_is_pyuobject(py_level)) |
| 922 | + return PyErr_Format(PyExc_Exception, "argument is not a ULevelStreaming"); |
| 923 | + |
| 924 | + ue_PyUObject *py_obj_level = (ue_PyUObject *)py_level; |
| 925 | + |
| 926 | + if (!py_obj_level->ue_object->IsA<ULevel>()) { |
| 927 | + return PyErr_Format(PyExc_Exception, "argument is not a ULevelStreaming"); |
| 928 | + } |
| 929 | + |
| 930 | + ULevel *level = (ULevel *)py_obj_level->ue_object; |
| 931 | + |
| 932 | + GEditor->MoveSelectedActorsToLevel(level); |
| 933 | + |
| 934 | + Py_INCREF(Py_None); |
| 935 | + return Py_None; |
| 936 | +} |
| 937 | + |
835 | 938 | #endif |
836 | 939 |
|
0 commit comments