Skip to content

Commit 194c480

Browse files
author
Roberto De Ioris
committed
added FViewportClient api
1 parent f58c07a commit 194c480

10 files changed

Lines changed: 275 additions & 19 deletions

‎Source/UnrealEnginePython/Private/UEPyEditor.cpp‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2239,8 +2239,6 @@ PyObject *py_unreal_engine_register_settings(PyObject * self, PyObject * args)
22392239

22402240
PyObject *py_unreal_engine_unregister_settings(PyObject * self, PyObject * args)
22412241
{
2242-
2243-
22442242
char *container_name;
22452243
char *category_name;
22462244
char *section_name;
@@ -2261,5 +2259,16 @@ PyObject *py_unreal_engine_unregister_settings(PyObject * self, PyObject * args)
22612259

22622260
Py_RETURN_NONE;
22632261
}
2262+
2263+
PyObject *py_unreal_engine_all_viewport_clients(PyObject * self, PyObject * args)
2264+
{
2265+
TArray<FEditorViewportClient *> clients = GEditor->AllViewportClients;
2266+
PyObject *py_list = PyList_New(0);
2267+
for (FEditorViewportClient *client : clients)
2268+
{
2269+
PyList_Append(py_list, py_ue_new_feditor_viewport_client(TSharedRef<FEditorViewportClient>(client)));
2270+
}
2271+
return py_list;
2272+
}
22642273
#endif
22652274

‎Source/UnrealEnginePython/Private/UEPyEditor.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ PyObject *py_unreal_engine_editor_undo(PyObject *, PyObject *);
104104
PyObject *py_unreal_engine_editor_redo(PyObject *, PyObject *);
105105
PyObject *py_unreal_engine_transactions(PyObject *, PyObject *);
106106

107+
PyObject *py_unreal_engine_all_viewport_clients(PyObject *, PyObject *);
108+
107109
PyObject *py_unreal_engine_heightmap_expand(PyObject *, PyObject *);
108110
PyObject *py_unreal_engine_heightmap_import(PyObject *, PyObject *);
109111

‎Source/UnrealEnginePython/Private/UEPyModule.cpp‎

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,9 @@ static PyMethodDef unreal_engine_methods[] = {
309309
#endif
310310

311311
{ "engine_tick", py_unreal_engine_engine_tick, METH_VARARGS, "" },
312+
#if WITH_EDITOR
313+
{ "all_viewport_clients", py_unreal_engine_all_viewport_clients , METH_VARARGS, "" },
314+
#endif
312315
{ "slate_tick", py_unreal_engine_slate_tick, METH_VARARGS, "" },
313316
{ "get_delta_time", py_unreal_engine_get_delta_time, METH_VARARGS, "" },
314317

@@ -1849,6 +1852,11 @@ void unreal_engine_init_py_module()
18491852

18501853
ue_python_init_fobject_thumbnail(new_unreal_engine_module);
18511854

1855+
ue_python_init_fviewport_client(new_unreal_engine_module);
1856+
#if WITH_EDITOR
1857+
ue_python_init_feditor_viewport_client(new_unreal_engine_module);
1858+
#endif
1859+
18521860
ue_python_init_fpython_output_device(new_unreal_engine_module);
18531861

18541862
ue_python_init_ftimerhandle(new_unreal_engine_module);
@@ -2023,7 +2031,7 @@ void unreal_engine_py_log_error()
20232031
if (zero)
20242032
{
20252033
msg = PyBytes_AsString(zero);
2026-
}
2034+
}
20272035
#else
20282036
msg = PyString_AsString(PyObject_Str(value));
20292037
#endif
@@ -2078,7 +2086,7 @@ void unreal_engine_py_log_error()
20782086
}
20792087

20802088
PyErr_Clear();
2081-
}
2089+
}
20822090

20832091
// retrieve a UWorld from a generic UObject (if possible)
20842092
UWorld *ue_get_uworld(ue_PyUObject *py_obj)
@@ -2953,9 +2961,9 @@ PyObject *py_ue_ufunction_call(UFunction *u_function, UObject *u_obj, PyObject *
29532961
#else
29542962
prop->ImportText(*default_key_value, prop->ContainerPtrToValuePtr<uint8>(buffer), PPF_Localized, NULL);
29552963
#endif
2956-
}
2964+
}
29572965
#endif
2958-
}
2966+
}
29592967

29602968
Py_ssize_t tuple_len = PyTuple_Size(args);
29612969

‎Source/UnrealEnginePython/Private/UObject/UEPyWorld.cpp‎

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -195,12 +195,7 @@ PyObject *py_ue_get_game_viewport(ue_PyUObject *self, PyObject * args)
195195
if (!viewport_client)
196196
return PyErr_Format(PyExc_Exception, "world has no GameViewportClient");
197197

198-
ue_PyUObject *ret = ue_get_python_wrapper(viewport_client);
199-
if (!ret)
200-
return PyErr_Format(PyExc_Exception, "PyUObject is in invalid state");
201-
Py_INCREF(ret);
202-
return (PyObject *)ret;
203-
198+
Py_RETURN_UOBJECT(viewport_client);
204199
}
205200

206201
PyObject *py_ue_has_world(ue_PyUObject *self, PyObject * args)

‎Source/UnrealEnginePython/Private/UnrealEnginePython.cpp‎

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@
77
#include "ClassIconFinder.h"
88
#endif
99

10+
#if ENGINE_MINOR_VERSION >= 18
11+
#define PROJECT_CONTENT_DIR FPaths::ProjectContentDir()
12+
#else
13+
#define PROJECT_CONTENT_DIR FPaths::GameContentDir()
14+
#endif
15+
1016
void unreal_engine_init_py_module();
1117

1218
#if defined(UNREAL_ENGINE_PYTHON_ON_LINUX)
@@ -164,7 +170,7 @@ void FUnrealEnginePythonModule::StartupModule()
164170
}
165171

166172
if (GConfig->GetString(UTF8_TO_TCHAR("Python"), UTF8_TO_TCHAR("RelativeHome"), IniValue, GEngineIni)) {
167-
IniValue = FPaths::Combine(*FPaths::GameContentDir(), *IniValue);
173+
IniValue = FPaths::Combine(*PROJECT_CONTENT_DIR, *IniValue);
168174
#if PY_MAJOR_VERSION >= 3
169175
wchar_t *home = (wchar_t *)*IniValue;
170176
#else
@@ -183,7 +189,7 @@ void FUnrealEnginePythonModule::StartupModule()
183189
}
184190

185191
if (GConfig->GetString(UTF8_TO_TCHAR("Python"), UTF8_TO_TCHAR("RelativeProgramName"), IniValue, GEngineIni)) {
186-
IniValue = FPaths::Combine(*FPaths::GameContentDir(), *IniValue);
192+
IniValue = FPaths::Combine(*PROJECT_CONTENT_DIR, *IniValue);
187193
#if PY_MAJOR_VERSION >= 3
188194
wchar_t *program_name = (wchar_t *)*IniValue;
189195
#else
@@ -197,31 +203,31 @@ void FUnrealEnginePythonModule::StartupModule()
197203
}
198204

199205
if (GConfig->GetString(UTF8_TO_TCHAR("Python"), UTF8_TO_TCHAR("RelativeScriptsPath"), IniValue, GEngineIni)) {
200-
ScriptsPath = FPaths::Combine(*FPaths::GameContentDir(), *IniValue);
206+
ScriptsPath = FPaths::Combine(*PROJECT_CONTENT_DIR, *IniValue);
201207
}
202208

203209
if (GConfig->GetString(UTF8_TO_TCHAR("Python"), UTF8_TO_TCHAR("AdditionalModulesPath"), IniValue, GEngineIni)) {
204210
AdditionalModulesPath = IniValue;
205211
}
206212

207213
if (GConfig->GetString(UTF8_TO_TCHAR("Python"), UTF8_TO_TCHAR("RelativeAdditionalModulesPath"), IniValue, GEngineIni)) {
208-
AdditionalModulesPath = FPaths::Combine(*FPaths::GameContentDir(), *IniValue);
214+
AdditionalModulesPath = FPaths::Combine(*PROJECT_CONTENT_DIR, *IniValue);
209215
}
210216

211217
if (GConfig->GetString(UTF8_TO_TCHAR("Python"), UTF8_TO_TCHAR("ZipPath"), IniValue, GEngineIni)) {
212218
ZipPath = IniValue;
213219
}
214220

215221
if (GConfig->GetString(UTF8_TO_TCHAR("Python"), UTF8_TO_TCHAR("RelativeZipPath"), IniValue, GEngineIni)) {
216-
ZipPath = FPaths::Combine(*FPaths::GameContentDir(), *IniValue);
222+
ZipPath = FPaths::Combine(*PROJECT_CONTENT_DIR, *IniValue);
217223
}
218224

219225
if (ScriptsPath.IsEmpty()) {
220-
ScriptsPath = FPaths::Combine(*FPaths::GameContentDir(), UTF8_TO_TCHAR("Scripts"));
226+
ScriptsPath = FPaths::Combine(*PROJECT_CONTENT_DIR, UTF8_TO_TCHAR("Scripts"));
221227
}
222228

223229
if (ZipPath.IsEmpty()) {
224-
ZipPath = FPaths::Combine(*FPaths::GameContentDir(), UTF8_TO_TCHAR("ue_python.zip"));
230+
ZipPath = FPaths::Combine(*PROJECT_CONTENT_DIR, UTF8_TO_TCHAR("ue_python.zip"));
225231
}
226232

227233
if (!FPaths::DirectoryExists(ScriptsPath)) {

‎Source/UnrealEnginePython/Private/UnrealEnginePythonPrivatePCH.h‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@
4747
#include "Wrappers/UEPyFMorphTargetDelta.h"
4848
#include "Wrappers/UEPyFObjectThumbnail.h"
4949

50+
#include "Wrappers/UEPyFViewportClient.h"
51+
#if WITH_EDITOR
52+
#include "Wrappers/UEPyFEditorViewportClient.h"
53+
#endif
54+
5055
#include "UEPyCallable.h"
5156
#include "UEPyUClassesImporter.h"
5257
#include "UEPyEnumsImporter.h"
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
#include "UnrealEnginePythonPrivatePCH.h"
2+
3+
#if WITH_EDITOR
4+
5+
static PyObject *py_ue_feditor_viewport_client_take_high_res_screen_shot(ue_PyFEditorViewportClient *self, PyObject * args)
6+
{
7+
self->editor_viewport_client->TakeHighResScreenShot();
8+
self->editor_viewport_client->Invalidate();
9+
if (self->editor_viewport_client->Viewport)
10+
{
11+
FIntPoint point = self->editor_viewport_client->Viewport->GetSizeXY();
12+
if (point.X > 0 && point.Y > 0)
13+
{
14+
self->editor_viewport_client->Viewport->Draw();
15+
}
16+
}
17+
Py_RETURN_NONE;
18+
}
19+
20+
static PyObject *py_ue_feditor_viewport_client_tick(ue_PyFEditorViewportClient *self, PyObject * args)
21+
{
22+
float delta_seconds = 0;
23+
if (!PyArg_ParseTuple(args, "|f:tick", &delta_seconds))
24+
return nullptr;
25+
self->editor_viewport_client->Tick(delta_seconds);
26+
Py_RETURN_NONE;
27+
}
28+
29+
static PyMethodDef ue_PyFEditorViewportClient_methods[] = {
30+
{ "take_high_res_screen_shot", (PyCFunction)py_ue_feditor_viewport_client_take_high_res_screen_shot, METH_VARARGS, "" },
31+
{ "tick", (PyCFunction)py_ue_feditor_viewport_client_tick, METH_VARARGS, "" },
32+
{ nullptr } /* Sentinel */
33+
};
34+
35+
static PyObject *ue_PyFEditorViewportClient_str(ue_PyFEditorViewportClient *self)
36+
{
37+
return PyUnicode_FromFormat("<unreal_engine.FEditorViewportClient %p>",
38+
&self->editor_viewport_client.Get());
39+
}
40+
41+
static PyTypeObject ue_PyFEditorViewportClientType = {
42+
PyVarObject_HEAD_INIT(NULL, 0)
43+
"unreal_engine.FEditorViewportClient", /* tp_name */
44+
sizeof(ue_PyFEditorViewportClient), /* tp_basicsize */
45+
0, /* tp_itemsize */
46+
0, /* tp_dealloc */
47+
0, /* tp_print */
48+
0, /* tp_getattr */
49+
0, /* tp_setattr */
50+
0, /* tp_reserved */
51+
0, /* tp_repr */
52+
0, /* tp_as_number */
53+
0, /* tp_as_sequence */
54+
0, /* tp_as_mapping */
55+
0, /* tp_hash */
56+
0, /* tp_call */
57+
(reprfunc)ue_PyFEditorViewportClient_str, /* tp_str */
58+
0, /* tp_getattro */
59+
0, /* tp_setattro */
60+
0, /* tp_as_buffer */
61+
#if PY_MAJOR_VERSION < 3
62+
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_CHECKTYPES, /* tp_flags */
63+
#else
64+
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
65+
#endif
66+
"Unreal Engine FEditorViewportClient", /* tp_doc */
67+
0, /* tp_traverse */
68+
0, /* tp_clear */
69+
0, /* tp_richcompare */
70+
0, /* tp_weaklistoffset */
71+
0, /* tp_iter */
72+
0, /* tp_iternext */
73+
ue_PyFEditorViewportClient_methods, /* tp_methods */
74+
0,
75+
};
76+
77+
void ue_python_init_feditor_viewport_client(PyObject *ue_module)
78+
{
79+
ue_PyFEditorViewportClientType.tp_new = PyType_GenericNew;
80+
ue_PyFEditorViewportClientType.tp_base = &ue_PyFViewportClientType;
81+
82+
if (PyType_Ready(&ue_PyFEditorViewportClientType) < 0)
83+
return;
84+
85+
Py_INCREF(&ue_PyFEditorViewportClientType);
86+
PyModule_AddObject(ue_module, "FEditorViewportClient", (PyObject *)&ue_PyFEditorViewportClientType);
87+
}
88+
89+
ue_PyFEditorViewportClient *py_ue_is_feditor_viewport_client(PyObject *obj)
90+
{
91+
if (!PyObject_IsInstance(obj, (PyObject *)&ue_PyFEditorViewportClientType))
92+
return nullptr;
93+
return (ue_PyFEditorViewportClient *)obj;
94+
}
95+
96+
PyObject *py_ue_new_feditor_viewport_client(TSharedRef<FEditorViewportClient> editor_viewport_client)
97+
{
98+
ue_PyFEditorViewportClient *ret = (ue_PyFEditorViewportClient *)PyObject_New(ue_PyFEditorViewportClient, &ue_PyFEditorViewportClientType);
99+
new(&ret->viewport_client.viewport_client) TSharedRef<FViewportClient>(editor_viewport_client);
100+
new(&ret->editor_viewport_client) TSharedRef<FEditorViewportClient>(editor_viewport_client);
101+
return (PyObject *)ret;
102+
}
103+
#endif
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#pragma once
2+
#include "UnrealEnginePython.h"
3+
4+
struct ue_PyFEditorViewportClient {
5+
ue_PyFViewportClient viewport_client;
6+
/* Type-specific fields go here. */
7+
TSharedRef<FEditorViewportClient> editor_viewport_client;;
8+
};
9+
10+
void ue_python_init_feditor_viewport_client(PyObject *);
11+
12+
PyObject *py_ue_new_feditor_viewport_client(TSharedRef<FEditorViewportClient>);
13+
14+
ue_PyFEditorViewportClient *py_ue_is_feditor_viewport_client(PyObject *);

0 commit comments

Comments
 (0)