text
stringlengths 9
39.2M
| dir
stringlengths 26
295
| lang
stringclasses 185
values | created_date
timestamp[us] | updated_date
timestamp[us] | repo_name
stringlengths 1
97
| repo_full_name
stringlengths 7
106
| star
int64 1k
183k
| len_tokens
int64 1
13.8M
|
|---|---|---|---|---|---|---|---|---|
```objective-c
#pragma once
#include "UnrealEnginePython.h"
#include "UEPySPanel.h"
#include "Runtime/Slate/Public/Widgets/SCanvas.h"
extern PyTypeObject ue_PySCanvasType;
typedef struct {
ue_PySPanel s_panel;
/* Type-specific fields go here. */
} ue_PySCanvas;
void ue_python_init_scanvas(PyObject *);
```
|
/content/code_sandbox/Source/UnrealEnginePython/Private/Slate/UEPySCanvas.h
|
objective-c
| 2016-08-07T05:00:51
| 2024-08-14T06:32:20
|
UnrealEnginePython
|
20tab/UnrealEnginePython
| 2,715
| 80
|
```c++
#include "UEPySBoxPanel.h"
static PyObject *py_ue_sbox_panel_clear_children(ue_PySBoxPanel *self, PyObject * args)
{
ue_py_slate_cast(SBoxPanel);
py_SBoxPanel->ClearChildren();
Py_RETURN_NONE;
}
static PyMethodDef ue_PySBoxPanel_methods[] = {
{ "clear_children", (PyCFunction)py_ue_sbox_panel_clear_children, METH_VARARGS, "" },
{ NULL } /* Sentinel */
};
PyTypeObject ue_PySBoxPanelType = {
PyVarObject_HEAD_INIT(NULL, 0)
"unreal_engine.SBoxPanel", /* tp_name */
sizeof(ue_PySBoxPanel), /* tp_basicsize */
0, /* tp_itemsize */
0, /* tp_dealloc */
0, /* tp_print */
0, /* tp_getattr */
0, /* tp_setattr */
0, /* tp_reserved */
0, /* tp_repr */
0, /* tp_as_number */
0, /* tp_as_sequence */
0, /* tp_as_mapping */
0, /* tp_hash */
0, /* tp_call */
0, /* tp_str */
0, /* tp_getattro */
0, /* tp_setattro */
0, /* tp_as_buffer */
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
"Unreal Engine SBoxPanel", /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
0, /* tp_richcompare */
0, /* tp_weaklistoffset */
0, /* tp_iter */
0, /* tp_iternext */
ue_PySBoxPanel_methods, /* tp_methods */
};
void ue_python_init_sbox_panel(PyObject *ue_module)
{
ue_PySBoxPanelType.tp_base = &ue_PySPanelType;
if (PyType_Ready(&ue_PySBoxPanelType) < 0)
return;
Py_INCREF(&ue_PySBoxPanelType);
PyModule_AddObject(ue_module, "SBoxPanel", (PyObject *)&ue_PySBoxPanelType);
}
```
|
/content/code_sandbox/Source/UnrealEnginePython/Private/Slate/UEPySBoxPanel.cpp
|
c++
| 2016-08-07T05:00:51
| 2024-08-14T06:32:20
|
UnrealEnginePython
|
20tab/UnrealEnginePython
| 2,715
| 487
|
```c++
#include "UEPySBox.h"
static PyObject *py_ue_sbox_set_content(ue_PySBox *self, PyObject * args)
{
ue_py_slate_cast(SBox);
PyObject *py_content;
if (!PyArg_ParseTuple(args, "O:set_content", &py_content))
{
return NULL;
}
TSharedPtr<SWidget> child = py_ue_is_swidget<SWidget>(py_content);
if (!child.IsValid())
return nullptr;
py_SBox->SetContent(child.ToSharedRef());
Py_RETURN_SLATE_SELF;
}
static PyObject *py_ue_sbox_set_height_override(ue_PySBox *self, PyObject * args)
{
ue_py_slate_cast(SBox);
float height_override = 0;
if (!PyArg_ParseTuple(args, "f:set_height_override", &height_override))
{
return NULL;
}
if (height_override != 0)
py_SBox->SetHeightOverride(height_override);
Py_RETURN_NONE;
}
static PyObject *py_ue_sbox_set_width_override(ue_PySBox *self, PyObject * args)
{
ue_py_slate_cast(SBox);
float width_override = 0;
if (!PyArg_ParseTuple(args, "f:set_width_override", &width_override))
{
return NULL;
}
if (width_override != 0)
py_SBox->SetWidthOverride(width_override);
Py_RETURN_NONE;
}
static PyMethodDef ue_PySBox_methods[] = {
{ "set_content", (PyCFunction)py_ue_sbox_set_content, METH_VARARGS, "" },
{ "set_height_override", (PyCFunction)py_ue_sbox_set_height_override, METH_VARARGS, "" },
{ "set_width_override", (PyCFunction)py_ue_sbox_set_width_override, METH_VARARGS, "" },
{ NULL } /* Sentinel */
};
PyTypeObject ue_PySBoxType = {
PyVarObject_HEAD_INIT(NULL, 0)
"unreal_engine.SBox", /* tp_name */
sizeof(ue_PySBox), /* tp_basicsize */
0, /* tp_itemsize */
0, /* tp_dealloc */
0, /* tp_print */
0, /* tp_getattr */
0, /* tp_setattr */
0, /* tp_reserved */
0, /* tp_repr */
0, /* tp_as_number */
0, /* tp_as_sequence */
0, /* tp_as_mapping */
0, /* tp_hash */
0, /* tp_call */
0, /* tp_str */
0, /* tp_getattro */
0, /* tp_setattro */
0, /* tp_as_buffer */
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
"Unreal Engine SBox", /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
0, /* tp_richcompare */
0, /* tp_weaklistoffset */
0, /* tp_iter */
0, /* tp_iternext */
ue_PySBox_methods, /* tp_methods */
};
static int ue_py_sbox_init(ue_PySBox *self, PyObject *args, PyObject *kwargs)
{
ue_py_slate_setup_farguments(SBox);
ue_py_slate_farguments_optional_enum("h_align", HAlign, EHorizontalAlignment);
ue_py_slate_farguments_optional_enum("v_align", VAlign, EVerticalAlignment);
ue_py_slate_farguments_struct("padding", Padding, FMargin);
ue_py_slate_farguments_optional_foptional_size("height_override", HeightOverride);
ue_py_slate_farguments_optional_foptional_size("width_override", WidthOverride);
#if ENGINE_MINOR_VERSION > 12
ue_py_slate_farguments_optional_foptional_size("max_aspect_ratio", MaxAspectRatio);
#endif
ue_py_slate_farguments_optional_foptional_size("max_desired_height", MaxDesiredHeight);
ue_py_slate_farguments_optional_foptional_size("max_desired_width", MaxDesiredWidth);
ue_py_slate_farguments_optional_foptional_size("min_desired_height", MinDesiredHeight);
ue_py_slate_farguments_optional_foptional_size("min_desired_width", MinDesiredWidth);
ue_py_snew(SBox);
return 0;
}
void ue_python_init_sbox(PyObject *ue_module)
{
ue_PySBoxType.tp_init = (initproc)ue_py_sbox_init;
ue_PySBoxType.tp_call = (ternaryfunc)py_ue_sbox_set_content;
ue_PySBoxType.tp_base = &ue_PySPanelType;
if (PyType_Ready(&ue_PySBoxType) < 0)
return;
Py_INCREF(&ue_PySBoxType);
PyModule_AddObject(ue_module, "SBox", (PyObject *)&ue_PySBoxType);
}
```
|
/content/code_sandbox/Source/UnrealEnginePython/Private/Slate/UEPySBox.cpp
|
c++
| 2016-08-07T05:00:51
| 2024-08-14T06:32:20
|
UnrealEnginePython
|
20tab/UnrealEnginePython
| 2,715
| 1,066
|
```c++
#include "UEPySScrollBox.h"
static PyObject *py_ue_sscroll_box_add_slot(ue_PySScrollBox *self, PyObject * args, PyObject *kwargs)
{
ue_py_slate_cast(SScrollBox);
int32 retCode = [&]() {
ue_py_slate_setup_hack_slot_args(SScrollBox, py_SScrollBox);
ue_py_slate_farguments_optional_enum("h_align", HAlign, EHorizontalAlignment);
ue_py_slate_farguments_optional_enum("v_align", VAlign, EVerticalAlignment);
return 0;
}();
if (retCode != 0)
{
return PyErr_Format(PyExc_Exception, "could not add vertical slot");
}
Py_RETURN_SLATE_SELF;
}
static PyObject *py_ue_sscroll_box_clear_children(ue_PySScrollBox *self, PyObject * args)
{
ue_py_slate_cast(SScrollBox);
py_SScrollBox->ClearChildren();
Py_RETURN_NONE;
}
static PyMethodDef ue_PySScrollBox_methods[] = {
{ "clear_children", (PyCFunction)py_ue_sscroll_box_clear_children, METH_VARARGS, "" },
#pragma warning(suppress: 4191)
{ "add_slot", (PyCFunction)py_ue_sscroll_box_add_slot, METH_VARARGS | METH_KEYWORDS, "" },
{ NULL } /* Sentinel */
};
PyTypeObject ue_PySScrollBoxType = {
PyVarObject_HEAD_INIT(NULL, 0)
"unreal_engine.SScrollBox", /* tp_name */
sizeof(ue_PySScrollBox), /* tp_basicsize */
0, /* tp_itemsize */
0, /* tp_dealloc */
0, /* tp_print */
0, /* tp_getattr */
0, /* tp_setattr */
0, /* tp_reserved */
0, /* tp_repr */
0, /* tp_as_number */
0, /* tp_as_sequence */
0, /* tp_as_mapping */
0, /* tp_hash */
0, /* tp_call */
0, /* tp_str */
0, /* tp_getattro */
0, /* tp_setattro */
0, /* tp_as_buffer */
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
"Unreal Engine SScrollBox", /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
0, /* tp_richcompare */
0, /* tp_weaklistoffset */
0, /* tp_iter */
0, /* tp_iternext */
ue_PySScrollBox_methods, /* tp_methods */
};
static int ue_py_sscroll_box_init(ue_PySScrollBox *self, PyObject *args, PyObject *kwargs)
{
ue_py_slate_setup_farguments(SScrollBox);
ue_py_slate_farguments_optional_enum("allow_overscroll", AllowOverscroll, EAllowOverscroll);
ue_py_slate_farguments_optional_enum("consume_mouse_wheel", ConsumeMouseWheel, EConsumeMouseWheel);
ue_py_slate_farguments_optional_enum("orientation", Orientation, EOrientation);
ue_py_slate_farguments_optional_bool("scroll_bar_always_visible", ScrollBarAlwaysVisible);
ue_py_slate_farguments_optional_struct_ptr("scroll_bar_style", ScrollBarStyle, FScrollBarStyle);
ue_py_slate_farguments_optional_fvector2d("scroll_bar_thickness", ScrollBarThickness);
ue_py_slate_farguments_optional_struct_ptr("style", Style, FScrollBoxStyle);
ue_py_snew(SScrollBox);
return 0;
}
void ue_python_init_sscroll_box(PyObject *ue_module)
{
ue_PySScrollBoxType.tp_init = (initproc)ue_py_sscroll_box_init;
ue_PySScrollBoxType.tp_call = (ternaryfunc)py_ue_sscroll_box_add_slot;
ue_PySScrollBoxType.tp_base = &ue_PySCompoundWidgetType;
if (PyType_Ready(&ue_PySScrollBoxType) < 0)
return;
Py_INCREF(&ue_PySScrollBoxType);
PyModule_AddObject(ue_module, "SScrollBox", (PyObject *)&ue_PySScrollBoxType);
}
```
|
/content/code_sandbox/Source/UnrealEnginePython/Private/Slate/UEPySScrollBox.cpp
|
c++
| 2016-08-07T05:00:51
| 2024-08-14T06:32:20
|
UnrealEnginePython
|
20tab/UnrealEnginePython
| 2,715
| 929
|
```objective-c
#pragma once
#include "UEPySlate.h"
#include "UEPyFGeometry.h"
#include "UEPyFPaintContext.h"
#include "UEPyFInputEvent.h"
#include "UEPyFPointerEvent.h"
#include "UEPyFKeyEvent.h"
#include "UEPyFCharacterEvent.h"
#include "UEPyFModifierKeysState.h"
#define ue_py_slate_cast(T) ue_PySWidget *py_self_swidget = (ue_PySWidget *)self;\
TSharedRef<T> py_ ## T = StaticCastSharedRef<T>(py_self_swidget->Widget)
#define ue_py_slate_cast_named(T, name) ue_PySWidget *py_self_swidget = (ue_PySWidget *)self;\
TSharedRef<T> name = StaticCastSharedRef<T>(py_self_swidget->Widget)
#define Py_RETURN_SLATE_SELF Py_INCREF(self);\
return (PyObject *)self
#define DECLARE_UE_PY_SLATE_WIDGET(WIDGETTYPE) PyTypeObject ue_Py##WIDGETTYPE##Type = {\
PyVarObject_HEAD_INIT(NULL, 0)\
"unreal_engine." #WIDGETTYPE, /* tp_name */\
sizeof(ue_Py##WIDGETTYPE), /* tp_basicsize */\
0, /* tp_itemsize */\
0, /* tp_dealloc */\
0, /* tp_print */\
0, /* tp_getattr */\
0, /* tp_setattr */\
0, /* tp_reserved */\
0, /* tp_repr */\
0, /* tp_as_number */\
0, /* tp_as_sequence */\
0, /* tp_as_mapping */\
0, /* tp_hash */\
0, /* tp_call */\
0, /* tp_str */\
0, /* tp_getattro */\
0, /* tp_setattro */\
0, /* tp_as_buffer */\
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */\
"Unreal Engine " #WIDGETTYPE, /* tp_doc */\
0, /* tp_traverse */\
0, /* tp_clear */\
0, /* tp_richcompare */\
0, /* tp_weaklistoffset */\
0, /* tp_iter */\
0, /* tp_iternext */\
ue_Py##WIDGETTYPE##_methods, /* tp_methods */\
}
```
|
/content/code_sandbox/Source/UnrealEnginePython/Private/Slate/UEPySWidget.h
|
objective-c
| 2016-08-07T05:00:51
| 2024-08-14T06:32:20
|
UnrealEnginePython
|
20tab/UnrealEnginePython
| 2,715
| 505
|
```objective-c
#pragma once
#include "UEPyModule.h"
#include "Runtime/UMG/Public/Blueprint/UserWidget.h"
typedef struct
{
PyObject_HEAD
/* Type-specific fields go here. */
FPaintContext paint_context;
} ue_PyFPaintContext;
void ue_python_init_fpaint_context(PyObject *);
PyObject *py_ue_new_fpaint_context(FPaintContext);
```
|
/content/code_sandbox/Source/UnrealEnginePython/Private/Slate/UEPyFPaintContext.h
|
objective-c
| 2016-08-07T05:00:51
| 2024-08-14T06:32:20
|
UnrealEnginePython
|
20tab/UnrealEnginePython
| 2,715
| 79
|
```objective-c
#pragma once
#include "UEPyModule.h"
#include "Runtime/Online/HTTP/Public/Interfaces/IHttpRequest.h"
#include "Runtime/Online/HTTP/Public/HttpModule.h"
#include "UEPyIHttpBase.h"
extern PyTypeObject ue_PyIHttpBaseType;
class FPythonSmartHttpDelegate;
typedef struct
{
ue_PyIHttpBase base;
/* Type-specific fields go here. */
TSharedRef<IHttpRequest> http_request;
TSharedPtr<FPythonSmartHttpDelegate> on_process_request_complete;
TSharedPtr<FPythonSmartHttpDelegate> on_request_progress;
PyObject *py_dict;
} ue_PyIHttpRequest;
class FPythonSmartHttpDelegate : public FPythonSmartDelegate
{
public:
void OnRequestComplete(FHttpRequestPtr request, FHttpResponsePtr response, bool successful);
void OnRequestProgress(FHttpRequestPtr request, int32 sent, int32 received);
void SetPyHttpRequest(ue_PyIHttpRequest *request)
{
py_http_request = request;
Py_INCREF(py_http_request);
}
~FPythonSmartHttpDelegate()
{
Py_XDECREF(py_http_request);
}
protected:
ue_PyIHttpRequest * py_http_request;
};
void ue_python_init_ihttp_request(PyObject *);
```
|
/content/code_sandbox/Source/UnrealEnginePython/Private/Http/UEPyIHttpRequest.h
|
objective-c
| 2016-08-07T05:00:51
| 2024-08-14T06:32:20
|
UnrealEnginePython
|
20tab/UnrealEnginePython
| 2,715
| 262
|
```objective-c
#pragma once
#include "UEPyModule.h"
#include "Runtime/Online/HTTP/Public/Interfaces/IHttpResponse.h"
#include "Runtime/Online/HTTP/Public/HttpModule.h"
#include "UEPyIHttpBase.h"
extern PyTypeObject ue_PyIHttpBaseType;
typedef struct
{
ue_PyIHttpBase base;
/* Type-specific fields go here. */
IHttpResponse *http_response;
} ue_PyIHttpResponse;
void ue_python_init_ihttp_response(PyObject *);
PyObject *py_ue_new_ihttp_response(IHttpResponse *);
```
|
/content/code_sandbox/Source/UnrealEnginePython/Private/Http/UEPyIHttpResponse.h
|
objective-c
| 2016-08-07T05:00:51
| 2024-08-14T06:32:20
|
UnrealEnginePython
|
20tab/UnrealEnginePython
| 2,715
| 115
|
```objective-c
#pragma once
#include "UEPyIHttpBase.h"
#include "UEPyIHttpRequest.h"
#include "UEPyIHttpResponse.h"
```
|
/content/code_sandbox/Source/UnrealEnginePython/Private/Http/UEPyIHttp.h
|
objective-c
| 2016-08-07T05:00:51
| 2024-08-14T06:32:20
|
UnrealEnginePython
|
20tab/UnrealEnginePython
| 2,715
| 29
|
```c++
#include "UEPyIHttpBase.h"
static PyObject *py_ue_ihttp_base_get_content_length(ue_PyIHttpBase *self, PyObject * args)
{
return PyLong_FromLong((int)self->http_base->GetContentLength());
}
static PyObject *py_ue_ihttp_base_get_url(ue_PyIHttpBase *self, PyObject * args)
{
return PyUnicode_FromString(TCHAR_TO_UTF8(*self->http_base->GetURL()));
}
static PyObject *py_ue_ihttp_base_get_content_type(ue_PyIHttpBase *self, PyObject * args)
{
return PyUnicode_FromString(TCHAR_TO_UTF8(*self->http_base->GetContentType()));
}
static PyObject *py_ue_ihttp_base_get_content(ue_PyIHttpBase *self, PyObject * args)
{
TArray<uint8> data = self->http_base->GetContent();
return PyBytes_FromStringAndSize((char *)data.GetData(), data.Num());
}
static PyObject *py_ue_ihttp_base_get_header(ue_PyIHttpBase *self, PyObject * args)
{
char *key;
if (!PyArg_ParseTuple(args, "s:get_header", &key))
{
return NULL;
}
return PyUnicode_FromString(TCHAR_TO_UTF8(*self->http_base->GetHeader(UTF8_TO_TCHAR(key))));
}
static PyObject *py_ue_ihttp_base_get_url_parameter(ue_PyIHttpBase *self, PyObject * args)
{
char *key;
if (!PyArg_ParseTuple(args, "s:get_url_parameter", &key))
{
return NULL;
}
return PyUnicode_FromString(TCHAR_TO_UTF8(*self->http_base->GetURLParameter(UTF8_TO_TCHAR(key))));
}
static PyObject *py_ue_ihttp_base_get_all_headers(ue_PyIHttpBase *self, PyObject * args)
{
TArray<FString> headers = self->http_base->GetAllHeaders();
PyObject *py_headers = PyList_New(0);
for (FString item : headers)
{
PyObject *py_header = PyUnicode_FromString(TCHAR_TO_UTF8(*item));
PyList_Append(py_headers, py_header);
Py_DECREF(py_header);
}
return py_headers;
}
static PyMethodDef ue_PyIHttpBase_methods[] = {
{ "get_content", (PyCFunction)py_ue_ihttp_base_get_content, METH_VARARGS, "" },
{ "get_all_headers", (PyCFunction)py_ue_ihttp_base_get_all_headers, METH_VARARGS, "" },
{ "get_content_length", (PyCFunction)py_ue_ihttp_base_get_content_length, METH_VARARGS, "" },
{ "get_content_type", (PyCFunction)py_ue_ihttp_base_get_content_type, METH_VARARGS, "" },
{ "get_header", (PyCFunction)py_ue_ihttp_base_get_header, METH_VARARGS, "" },
{ "get_url", (PyCFunction)py_ue_ihttp_base_get_url, METH_VARARGS, "" },
{ "get_url_parameter", (PyCFunction)py_ue_ihttp_base_get_url_parameter, METH_VARARGS, "" },
{ NULL } /* Sentinel */
};
static PyObject *ue_PyIHttpBase_str(ue_PyIHttpBase *self)
{
return PyUnicode_FromFormat("<unreal_engine.IHttpBase '%p'>",
self->http_base);
}
PyTypeObject ue_PyIHttpBaseType = {
PyVarObject_HEAD_INIT(NULL, 0)
"unreal_engine.IHttpBase", /* tp_name */
sizeof(ue_PyIHttpBase), /* tp_basicsize */
0, /* tp_itemsize */
0, /* tp_dealloc */
0, /* tp_print */
0, /* tp_getattr */
0, /* tp_setattr */
0, /* tp_reserved */
0, /* tp_repr */
0, /* tp_as_number */
0, /* tp_as_sequence */
0, /* tp_as_mapping */
0, /* tp_hash */
0, /* tp_call */
(reprfunc)ue_PyIHttpBase_str, /* tp_str */
0, /* tp_getattro */
0, /* tp_setattro */
0, /* tp_as_buffer */
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
"Unreal Engine HttpBase Interface", /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
0, /* tp_richcompare */
0, /* tp_weaklistoffset */
0, /* tp_iter */
0, /* tp_iternext */
ue_PyIHttpBase_methods, /* tp_methods */
0,
0,
};
void ue_python_init_ihttp_base(PyObject *ue_module)
{
ue_PyIHttpBaseType.tp_new = PyType_GenericNew;
if (PyType_Ready(&ue_PyIHttpBaseType) < 0)
return;
Py_INCREF(&ue_PyIHttpBaseType);
PyModule_AddObject(ue_module, "IHttpBase", (PyObject *)&ue_PyIHttpBaseType);
}
```
|
/content/code_sandbox/Source/UnrealEnginePython/Private/Http/UEPyIHttpBase.cpp
|
c++
| 2016-08-07T05:00:51
| 2024-08-14T06:32:20
|
UnrealEnginePython
|
20tab/UnrealEnginePython
| 2,715
| 1,113
|
```objective-c
#pragma once
#include "UEPyModule.h"
#include "Runtime/Online/HTTP/Public/HttpModule.h"
#include "Runtime/Online/HTTP/Public/Interfaces/IHttpBase.h"
typedef struct {
PyObject_HEAD
/* Type-specific fields go here. */
IHttpBase *http_base;
} ue_PyIHttpBase;
void ue_python_init_ihttp_base(PyObject *);
```
|
/content/code_sandbox/Source/UnrealEnginePython/Private/Http/UEPyIHttpBase.h
|
objective-c
| 2016-08-07T05:00:51
| 2024-08-14T06:32:20
|
UnrealEnginePython
|
20tab/UnrealEnginePython
| 2,715
| 79
|
```c++
#include "UEPyIHttpRequest.h"
#include "UEPyIHttpResponse.h"
#include "Runtime/Online/HTTP/Public/HttpManager.h"
static PyObject *py_ue_ihttp_request_set_verb(ue_PyIHttpRequest *self, PyObject * args)
{
char *verb;
if (!PyArg_ParseTuple(args, "s:set_verb", &verb))
{
return NULL;
}
self->http_request->SetVerb(UTF8_TO_TCHAR(verb));
Py_RETURN_NONE;
}
static PyObject *py_ue_ihttp_request_set_url(ue_PyIHttpRequest *self, PyObject * args)
{
char *url;
if (!PyArg_ParseTuple(args, "s:set_url", &url))
{
return NULL;
}
self->http_request->SetURL(UTF8_TO_TCHAR(url));
Py_RETURN_NONE;
}
static PyObject *py_ue_ihttp_request_set_header(ue_PyIHttpRequest *self, PyObject * args)
{
char *key;
char *value;
if (!PyArg_ParseTuple(args, "ss:set_header", &key, &value))
{
return NULL;
}
self->http_request->SetHeader(UTF8_TO_TCHAR(key), UTF8_TO_TCHAR(value));
Py_RETURN_NONE;
}
static PyObject *py_ue_ihttp_request_append_to_header(ue_PyIHttpRequest *self, PyObject * args)
{
char *key;
char *value;
if (!PyArg_ParseTuple(args, "ss:append_to_header", &key, &value))
{
return NULL;
}
self->http_request->AppendToHeader(UTF8_TO_TCHAR(key), UTF8_TO_TCHAR(value));
Py_RETURN_NONE;
}
static PyObject *py_ue_ihttp_request_set_content(ue_PyIHttpRequest *self, PyObject * args)
{
PyObject *py_obj;
if (!PyArg_ParseTuple(args, "O:set_content", &py_obj))
{
return NULL;
}
if (PyUnicodeOrString_Check(py_obj))
{
self->http_request->SetContentAsString(UTF8_TO_TCHAR(UEPyUnicode_AsUTF8(py_obj)));
}
else if (PyBytes_Check(py_obj))
{
char *buf = nullptr;
Py_ssize_t len = 0;
PyBytes_AsStringAndSize(py_obj, &buf, &len);
TArray<uint8> data;
data.Append((uint8 *)buf, len);
self->http_request->SetContent(data);
}
Py_RETURN_NONE;
}
static PyObject *py_ue_ihttp_request_tick(ue_PyIHttpRequest *self, PyObject * args)
{
float delta_seconds;
if (!PyArg_ParseTuple(args, "f:tick", &delta_seconds))
{
return NULL;
}
FHttpModule::Get().GetHttpManager().Tick(delta_seconds);
self->http_request->Tick(delta_seconds);
Py_RETURN_NONE;
}
static PyObject *py_ue_ihttp_request_process_request(ue_PyIHttpRequest *self, PyObject * args)
{
self->http_request->ProcessRequest();
Py_RETURN_NONE;
}
static PyObject *py_ue_ihttp_request_cancel_request(ue_PyIHttpRequest *self, PyObject * args)
{
self->http_request->CancelRequest();
Py_RETURN_NONE;
}
static PyObject *py_ue_ihttp_request_get_status(ue_PyIHttpRequest *self, PyObject * args)
{
return PyLong_FromLong((int)self->http_request->GetStatus());
}
static PyObject *py_ue_ihttp_request_get_verb(ue_PyIHttpRequest *self, PyObject * args)
{
return PyUnicode_FromString(TCHAR_TO_UTF8(*self->http_request->GetVerb()));
}
static PyObject *py_ue_ihttp_request_get_elapsed_time(ue_PyIHttpRequest *self, PyObject * args)
{
return PyFloat_FromDouble(self->http_request->GetElapsedTime());
}
static PyObject *py_ue_ihttp_request_get_response(ue_PyIHttpRequest *self, PyObject * args)
{
FHttpResponsePtr response = self->http_request->GetResponse();
if (!response.IsValid())
{
return PyErr_Format(PyExc_Exception, "unable to retrieve IHttpResponse");
}
return py_ue_new_ihttp_response(response.Get());
}
void FPythonSmartHttpDelegate::OnRequestComplete(FHttpRequestPtr request, FHttpResponsePtr response, bool successful)
{
FScopePythonGIL gil;
if (!request.IsValid() || !response.IsValid())
{
UE_LOG(LogPython, Error, TEXT("Unable to retrieve HTTP infos"));
return;
}
PyObject *ret = PyObject_CallFunction(py_callable, (char *)"ONO", py_http_request, py_ue_new_ihttp_response(response.Get()), successful ? Py_True : Py_False);
if (!ret)
{
unreal_engine_py_log_error();
return;
}
Py_DECREF(ret);
}
void FPythonSmartHttpDelegate::OnRequestProgress(FHttpRequestPtr request, int32 sent, int32 received)
{
FScopePythonGIL gil;
if (!request.IsValid())
{
UE_LOG(LogPython, Error, TEXT("Unable to retrieve HTTP infos"));
return;
}
PyObject *ret = PyObject_CallFunction(py_callable, (char *)"Oii", py_http_request, sent, received);
if (!ret)
{
unreal_engine_py_log_error();
return;
}
Py_DECREF(ret);
}
static PyObject *py_ue_ihttp_request_bind_on_process_request_complete(ue_PyIHttpRequest *self, PyObject * args)
{
PyObject *py_callable;
if (!PyArg_ParseTuple(args, "O:bind_on_process_request_complete", &py_callable))
{
return nullptr;
}
if (!PyCallable_Check(py_callable))
{
return PyErr_Format(PyExc_Exception, "argument is not a callable");
}
TSharedRef<FPythonSmartHttpDelegate> py_delegate = MakeShareable(new FPythonSmartHttpDelegate);
py_delegate->SetPyCallable(py_callable);
// this trick avoids generating a new python object
py_delegate->SetPyHttpRequest(self);
self->http_request->OnProcessRequestComplete().BindSP(py_delegate, &FPythonSmartHttpDelegate::OnRequestComplete);
self->on_process_request_complete = py_delegate;
Py_RETURN_NONE;
}
static PyObject *py_ue_ihttp_request_bind_on_request_progress(ue_PyIHttpRequest *self, PyObject * args)
{
PyObject *py_callable;
if (!PyArg_ParseTuple(args, "O:bind_on_request_progress", &py_callable))
{
return nullptr;
}
if (!PyCallable_Check(py_callable))
{
return PyErr_Format(PyExc_Exception, "argument is not a callable");
}
TSharedRef<FPythonSmartHttpDelegate> py_delegate = MakeShareable(new FPythonSmartHttpDelegate);
py_delegate->SetPyCallable(py_callable);
// this trick avoids generating a new python object
py_delegate->SetPyHttpRequest(self);
self->http_request->OnRequestProgress().BindSP(py_delegate, &FPythonSmartHttpDelegate::OnRequestProgress);
Py_RETURN_NONE;
}
static PyMethodDef ue_PyIHttpRequest_methods[] = {
{ "bind_on_process_request_complete", (PyCFunction)py_ue_ihttp_request_bind_on_process_request_complete, METH_VARARGS, "" },
{ "bind_on_request_progress", (PyCFunction)py_ue_ihttp_request_bind_on_request_progress, METH_VARARGS, "" },
{ "append_to_header", (PyCFunction)py_ue_ihttp_request_append_to_header, METH_VARARGS, "" },
{ "cancel_request", (PyCFunction)py_ue_ihttp_request_cancel_request, METH_VARARGS, "" },
{ "get_elapsed_time", (PyCFunction)py_ue_ihttp_request_get_elapsed_time, METH_VARARGS, "" },
{ "get_response", (PyCFunction)py_ue_ihttp_request_get_response, METH_VARARGS, "" },
{ "get_status", (PyCFunction)py_ue_ihttp_request_get_status, METH_VARARGS, "" },
{ "get_verb", (PyCFunction)py_ue_ihttp_request_get_verb, METH_VARARGS, "" },
{ "process_request", (PyCFunction)py_ue_ihttp_request_process_request, METH_VARARGS, "" },
{ "set_content", (PyCFunction)py_ue_ihttp_request_set_content, METH_VARARGS, "" },
{ "set_header", (PyCFunction)py_ue_ihttp_request_set_header, METH_VARARGS, "" },
{ "set_url", (PyCFunction)py_ue_ihttp_request_set_url, METH_VARARGS, "" },
{ "set_verb", (PyCFunction)py_ue_ihttp_request_set_verb, METH_VARARGS, "" },
{ "tick", (PyCFunction)py_ue_ihttp_request_tick, METH_VARARGS, "" },
{ NULL } /* Sentinel */
};
static PyObject *ue_PyIHttpRequest_str(ue_PyIHttpRequest *self)
{
return PyUnicode_FromFormat("<unreal_engine.IHttpRequest '%p'>",
&self->http_request.Get());
}
static void ue_PyIHttpRequest_dealloc(ue_PyIHttpRequest *self)
{
#if defined(UEPY_MEMORY_DEBUG)
UE_LOG(LogPython, Warning, TEXT("Destroying ue_PyIHttpRequest %p mapped to IHttpRequest %p"), self, &self->http_request.Get());
#endif
self->on_process_request_complete = nullptr;
self->on_request_progress = nullptr;
Py_DECREF(self->py_dict);
Py_TYPE(self)->tp_free((PyObject *)self);
}
static PyTypeObject ue_PyIHttpRequestType = {
PyVarObject_HEAD_INIT(NULL, 0)
"unreal_engine.IHttpRequest", /* tp_name */
sizeof(ue_PyIHttpRequest), /* tp_basicsize */
0, /* tp_itemsize */
(destructor)ue_PyIHttpRequest_dealloc, /* tp_dealloc */
0, /* tp_print */
0, /* tp_getattr */
0, /* tp_setattr */
0, /* tp_reserved */
0, /* tp_repr */
0, /* tp_as_number */
0, /* tp_as_sequence */
0, /* tp_as_mapping */
0, /* tp_hash */
0, /* tp_call */
(reprfunc)ue_PyIHttpRequest_str, /* tp_str */
0, /* tp_getattro */
0, /* tp_setattro */
0, /* tp_as_buffer */
Py_TPFLAGS_DEFAULT, /* tp_flags */
"Unreal Engine HttpRequest Interface", /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
0, /* tp_richcompare */
0, /* tp_weaklistoffset */
0, /* tp_iter */
0, /* tp_iternext */
ue_PyIHttpRequest_methods, /* tp_methods */
0,
0,
};
static int ue_py_ihttp_request_init(ue_PyIHttpRequest *self, PyObject *args, PyObject *kwargs)
{
char *verb = nullptr;
char* url = nullptr;
if (!PyArg_ParseTuple(args, "|ss:__init__", &verb, &url))
{
return -1;
}
new(&self->http_request) TSharedRef<IHttpRequest>(FHttpModule::Get().CreateRequest());
new(&self->on_process_request_complete) TSharedPtr<FPythonSmartHttpDelegate>(nullptr);
new(&self->on_request_progress) TSharedPtr<FPythonSmartHttpDelegate>(nullptr);
self->py_dict = PyDict_New();
if (verb)
{
self->http_request->SetVerb(UTF8_TO_TCHAR(verb));
}
if (url)
{
self->http_request->SetURL(UTF8_TO_TCHAR(url));
}
self->base.http_base = &self->http_request.Get();
return 0;
}
void ue_python_init_ihttp_request(PyObject *ue_module)
{
ue_PyIHttpRequestType.tp_new = PyType_GenericNew;
ue_PyIHttpRequestType.tp_init = (initproc)ue_py_ihttp_request_init;
ue_PyIHttpRequestType.tp_base = &ue_PyIHttpBaseType;
ue_PyIHttpRequestType.tp_getattro = PyObject_GenericGetAttr;
ue_PyIHttpRequestType.tp_setattro = PyObject_GenericSetAttr;
ue_PyIHttpRequestType.tp_dictoffset = offsetof(ue_PyIHttpRequest, py_dict);
if (PyType_Ready(&ue_PyIHttpRequestType) < 0)
return;
Py_INCREF(&ue_PyIHttpRequestType);
PyModule_AddObject(ue_module, "IHttpRequest", (PyObject *)&ue_PyIHttpRequestType);
}
```
|
/content/code_sandbox/Source/UnrealEnginePython/Private/Http/UEPyIHttpRequest.cpp
|
c++
| 2016-08-07T05:00:51
| 2024-08-14T06:32:20
|
UnrealEnginePython
|
20tab/UnrealEnginePython
| 2,715
| 2,687
|
```c++
#include "UEPyIHttpResponse.h"
static PyObject *py_ue_ihttp_response_get_response_code(ue_PyIHttpResponse *self, PyObject * args)
{
return PyLong_FromLong(self->http_response->GetResponseCode());
}
static PyObject *py_ue_ihttp_response_get_content_as_string(ue_PyIHttpResponse *self, PyObject * args)
{
return PyUnicode_FromString(TCHAR_TO_UTF8(*self->http_response->GetContentAsString()));
}
static PyMethodDef ue_PyIHttpResponse_methods[] = {
{ "get_response_code", (PyCFunction)py_ue_ihttp_response_get_response_code, METH_VARARGS, "" },
{ "get_content_as_string", (PyCFunction)py_ue_ihttp_response_get_content_as_string, METH_VARARGS, "" },
{ NULL } /* Sentinel */
};
static PyObject *ue_PyIHttpResponse_str(ue_PyIHttpResponse *self)
{
return PyUnicode_FromFormat("<unreal_engine.IHttpResponse '%p'>",
self->http_response);
}
static PyTypeObject ue_PyIHttpResponseType = {
PyVarObject_HEAD_INIT(NULL, 0)
"unreal_engine.IHttpResponse", /* tp_name */
sizeof(ue_PyIHttpResponse), /* tp_basicsize */
0, /* tp_itemsize */
0, /* tp_dealloc */
0, /* tp_print */
0, /* tp_getattr */
0, /* tp_setattr */
0, /* tp_reserved */
0, /* tp_repr */
0, /* tp_as_number */
0, /* tp_as_sequence */
0, /* tp_as_mapping */
0, /* tp_hash */
0, /* tp_call */
(reprfunc)ue_PyIHttpResponse_str, /* tp_str */
0, /* tp_getattro */
0, /* tp_setattro */
0, /* tp_as_buffer */
Py_TPFLAGS_DEFAULT, /* tp_flags */
"Unreal Engine HttpResponse Interface", /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
0, /* tp_richcompare */
0, /* tp_weaklistoffset */
0, /* tp_iter */
0, /* tp_iternext */
ue_PyIHttpResponse_methods, /* tp_methods */
0,
0,
};
void ue_python_init_ihttp_response(PyObject *ue_module)
{
ue_PyIHttpResponseType.tp_new = PyType_GenericNew;
ue_PyIHttpResponseType.tp_base = &ue_PyIHttpBaseType;
if (PyType_Ready(&ue_PyIHttpResponseType) < 0)
return;
Py_INCREF(&ue_PyIHttpResponseType);
PyModule_AddObject(ue_module, "IHttpResponse", (PyObject *)&ue_PyIHttpResponseType);
}
PyObject *py_ue_new_ihttp_response(IHttpResponse *response)
{
ue_PyIHttpResponse *ret = (ue_PyIHttpResponse *)PyObject_New(ue_PyIHttpResponse, &ue_PyIHttpResponseType);
ret->http_response = response;
ret->base.http_base = response;
return (PyObject *)ret;
}
```
|
/content/code_sandbox/Source/UnrealEnginePython/Private/Http/UEPyIHttpResponse.cpp
|
c++
| 2016-08-07T05:00:51
| 2024-08-14T06:32:20
|
UnrealEnginePython
|
20tab/UnrealEnginePython
| 2,715
| 683
|
```c++
#include "UEPyIConsoleManager.h"
static PyObject *py_ue_iconsole_manager_add_history_entry(PyObject *cls, PyObject * args)
{
char *entry;
if (!PyArg_ParseTuple(args, "s:add_history_entry", &entry))
{
return nullptr;
}
#if ENGINE_MINOR_VERSION > 18
IConsoleManager::Get().AddConsoleHistoryEntry(TEXT(""), UTF8_TO_TCHAR(entry));
#else
IConsoleManager::Get().AddConsoleHistoryEntry(UTF8_TO_TCHAR(entry));
#endif
Py_RETURN_NONE;
}
static PyObject *py_ue_iconsole_manager_get_history(PyObject *cls, PyObject * args)
{
TArray<FString> history;
#if ENGINE_MINOR_VERSION > 18
IConsoleManager::Get().GetConsoleHistory(TEXT(""), history);
#else
IConsoleManager::Get().GetConsoleHistory(history);
#endif
PyObject *py_history = PyList_New(0);
for (FString item : history)
{
PyObject *py_item = PyUnicode_FromString(TCHAR_TO_UTF8(*item));
PyList_Append(py_history, py_item);
Py_DECREF(py_item);
}
return py_history;
}
#if ENGINE_MINOR_VERSION > 12
static PyObject *py_ue_iconsole_manager_get_objects(PyObject *cls, PyObject * args)
{
char *key = (char*)"";
if (!PyArg_ParseTuple(args, "|s:get_objects", &key))
{
return nullptr;
}
PyObject *py_names = PyList_New(0);
IConsoleManager::Get().ForEachConsoleObjectThatStartsWith(FConsoleObjectVisitor::CreateLambda([&](const TCHAR *name, IConsoleObject *object)
{
PyObject *py_item = PyUnicode_FromString(TCHAR_TO_UTF8(name));
PyList_Append(py_names, py_item);
Py_DECREF(py_item);
}), UTF8_TO_TCHAR(key));
return py_names;
}
#endif
#if ENGINE_MINOR_VERSION > 12
static PyObject *py_ue_iconsole_manager_get_objects_containing(PyObject *cls, PyObject * args)
{
char *key = (char*)"";
if (!PyArg_ParseTuple(args, "|s:get_objects_containing", &key))
{
return nullptr;
}
PyObject *py_names = PyList_New(0);
IConsoleManager::Get().ForEachConsoleObjectThatContains(FConsoleObjectVisitor::CreateLambda([&](const TCHAR *name, IConsoleObject *object)
{
PyObject *py_item = PyUnicode_FromString(TCHAR_TO_UTF8(name));
PyList_Append(py_names, py_item);
Py_DECREF(py_item);
}), UTF8_TO_TCHAR(key));
return py_names;
}
#endif
static PyObject *py_ue_iconsole_manager_get_help(PyObject *cls, PyObject * args)
{
char *key;
if (!PyArg_ParseTuple(args, "s:get_help", &key))
{
return nullptr;
}
IConsoleObject *c_object = IConsoleManager::Get().FindConsoleObject(UTF8_TO_TCHAR(key));
if (!c_object)
{
return PyErr_Format(PyExc_Exception, "unable to find console object \"%s\"", key);
}
return PyUnicode_FromString(TCHAR_TO_UTF8(c_object->GetHelp()));
}
static PyObject *py_ue_iconsole_manager_set_help(PyObject *cls, PyObject * args)
{
char *key;
char *help;
if (!PyArg_ParseTuple(args, "ss:set_help", &key, &help))
{
return nullptr;
}
IConsoleObject *c_object = IConsoleManager::Get().FindConsoleObject(UTF8_TO_TCHAR(key));
if (!c_object)
{
return PyErr_Format(PyExc_Exception, "unable to find console object \"%s\"", key);
}
c_object->SetHelp(UTF8_TO_TCHAR(help));
Py_RETURN_NONE;
}
static PyObject *py_ue_iconsole_manager_get_string(PyObject *cls, PyObject * args)
{
char *key;
if (!PyArg_ParseTuple(args, "s:get_string", &key))
{
return nullptr;
}
IConsoleObject *c_object = IConsoleManager::Get().FindConsoleObject(UTF8_TO_TCHAR(key));
if (!c_object)
{
return PyErr_Format(PyExc_Exception, "unable to find console object \"%s\"", key);
}
IConsoleVariable *var = c_object->AsVariable();
if (!var)
{
return PyErr_Format(PyExc_Exception, "console object \"%s\" is not a variable", key);
}
/*TConsoleVariableData<FString> *c_string = c_object->AsVariableString();
if (!c_string)
{
return PyErr_Format(PyExc_Exception, "console object \"%s\" is not a string", key);
}*/
return PyUnicode_FromString(TCHAR_TO_UTF8(*var->GetString()));
}
static PyObject *py_ue_iconsole_manager_get_int(PyObject *cls, PyObject * args)
{
char *key;
if (!PyArg_ParseTuple(args, "s:get_int", &key))
{
return nullptr;
}
IConsoleObject *c_object = IConsoleManager::Get().FindConsoleObject(UTF8_TO_TCHAR(key));
if (!c_object)
{
return PyErr_Format(PyExc_Exception, "unable to find console object \"%s\"", key);
}
IConsoleVariable *var = c_object->AsVariable();
if (!var)
{
return PyErr_Format(PyExc_Exception, "console object \"%s\" is not a variable", key);
}
TConsoleVariableData<int32> *c_int = c_object->AsVariableInt();
if (!c_int)
{
return PyErr_Format(PyExc_Exception, "console object \"%s\" is not an int", key);
}
return PyLong_FromLong(var->GetInt());
}
static PyObject *py_ue_iconsole_manager_get_float(PyObject *cls, PyObject * args)
{
char *key;
if (!PyArg_ParseTuple(args, "s:get_float", &key))
{
return nullptr;
}
IConsoleObject *c_object = IConsoleManager::Get().FindConsoleObject(UTF8_TO_TCHAR(key));
if (!c_object)
{
return PyErr_Format(PyExc_Exception, "unable to find console object \"%s\"", key);
}
IConsoleVariable *var = c_object->AsVariable();
if (!var)
{
return PyErr_Format(PyExc_Exception, "console object \"%s\" is not a variable", key);
}
TConsoleVariableData<float> *c_float = c_object->AsVariableFloat();
if (!c_float)
{
return PyErr_Format(PyExc_Exception, "console object \"%s\" is not a float", key);
}
return PyFloat_FromDouble(var->GetFloat());
}
static PyObject *py_ue_iconsole_manager_set_string(PyObject *cls, PyObject * args)
{
char *key;
char *value;
if (!PyArg_ParseTuple(args, "ss:set_string", &key, &value))
{
return nullptr;
}
IConsoleObject *c_object = IConsoleManager::Get().FindConsoleObject(UTF8_TO_TCHAR(key));
if (!c_object)
{
return PyErr_Format(PyExc_Exception, "unable to find console object \"%s\"", key);
}
IConsoleVariable *var = c_object->AsVariable();
if (!var)
{
return PyErr_Format(PyExc_Exception, "console object \"%s\" is not a variable", key);
}
TConsoleVariableData<FString> *c_string = c_object->AsVariableString();
if (!c_string)
{
return PyErr_Format(PyExc_Exception, "console object \"%s\" is not a string", key);
}
var->Set(UTF8_TO_TCHAR(value));
Py_RETURN_NONE;
}
static PyObject *py_ue_iconsole_manager_set_int(PyObject *cls, PyObject * args)
{
char *key;
int value;
if (!PyArg_ParseTuple(args, "si:set_int", &key, &value))
{
return nullptr;
}
IConsoleObject *c_object = IConsoleManager::Get().FindConsoleObject(UTF8_TO_TCHAR(key));
if (!c_object)
{
return PyErr_Format(PyExc_Exception, "unable to find console object \"%s\"", key);
}
IConsoleVariable *var = c_object->AsVariable();
if (!var)
{
return PyErr_Format(PyExc_Exception, "console object \"%s\" is not a variable", key);
}
TConsoleVariableData<int32> *c_int = c_object->AsVariableInt();
if (!c_int)
{
return PyErr_Format(PyExc_Exception, "console object \"%s\" is not an int", key);
}
var->Set(value);
Py_RETURN_NONE;
}
static PyObject *py_ue_iconsole_manager_set_float(PyObject *cls, PyObject * args)
{
char *key;
float value;
if (!PyArg_ParseTuple(args, "sf:set_float", &key, &value))
{
return nullptr;
}
IConsoleObject *c_object = IConsoleManager::Get().FindConsoleObject(UTF8_TO_TCHAR(key));
if (!c_object)
{
return PyErr_Format(PyExc_Exception, "unable to find console object \"%s\"", key);
}
IConsoleVariable *var = c_object->AsVariable();
if (!var)
{
return PyErr_Format(PyExc_Exception, "console object \"%s\" is not a variable", key);
}
TConsoleVariableData<float> *c_float = c_object->AsVariableFloat();
if (!c_float)
{
return PyErr_Format(PyExc_Exception, "console object \"%s\" is not a float", key);
}
var->Set(value);
Py_RETURN_NONE;
}
static PyObject *py_ue_iconsole_manager_is_variable(PyObject *cls, PyObject * args)
{
char *key;
if (!PyArg_ParseTuple(args, "s:is_variable", &key))
{
return nullptr;
}
IConsoleObject *c_object = IConsoleManager::Get().FindConsoleObject(UTF8_TO_TCHAR(key));
if (!c_object)
{
return PyErr_Format(PyExc_Exception, "unable to find console object \"%s\"", key);
}
if (!c_object->AsVariable())
{
Py_RETURN_FALSE;
}
Py_RETURN_TRUE;
}
static PyObject *py_ue_iconsole_manager_is_command(PyObject *cls, PyObject * args)
{
char *key;
if (!PyArg_ParseTuple(args, "s:is_command", &key))
{
return nullptr;
}
IConsoleObject *c_object = IConsoleManager::Get().FindConsoleObject(UTF8_TO_TCHAR(key));
if (!c_object)
{
return PyErr_Format(PyExc_Exception, "unable to find console object \"%s\"", key);
}
if (!c_object->AsCommand())
{
Py_RETURN_FALSE;
}
Py_RETURN_TRUE;
}
static PyObject *py_ue_iconsole_manager_is_variable_string(PyObject *cls, PyObject * args)
{
char *key;
if (!PyArg_ParseTuple(args, "s:is_variable_string", &key))
{
return nullptr;
}
IConsoleObject *c_object = IConsoleManager::Get().FindConsoleObject(UTF8_TO_TCHAR(key));
if (!c_object)
{
return PyErr_Format(PyExc_Exception, "unable to find console object \"%s\"", key);
}
if (!c_object->AsVariableString())
{
Py_RETURN_FALSE;
}
Py_RETURN_TRUE;
}
static PyObject *py_ue_iconsole_manager_is_variable_int(PyObject *cls, PyObject * args)
{
char *key;
if (!PyArg_ParseTuple(args, "s:is_variable_int", &key))
{
return nullptr;
}
IConsoleObject *c_object = IConsoleManager::Get().FindConsoleObject(UTF8_TO_TCHAR(key));
if (!c_object)
{
return PyErr_Format(PyExc_Exception, "unable to find console object \"%s\"", key);
}
if (!c_object->AsVariableInt())
{
Py_RETURN_FALSE;
}
Py_RETURN_TRUE;
}
static PyObject *py_ue_iconsole_manager_is_variable_float(PyObject *cls, PyObject * args)
{
char *key;
if (!PyArg_ParseTuple(args, "s:is_variable_float", &key))
{
return nullptr;
}
IConsoleObject *c_object = IConsoleManager::Get().FindConsoleObject(UTF8_TO_TCHAR(key));
if (!c_object)
{
return PyErr_Format(PyExc_Exception, "unable to find console object \"%s\"", key);
}
if (!c_object->AsVariableFloat())
{
Py_RETURN_FALSE;
}
Py_RETURN_TRUE;
}
static PyObject *py_ue_iconsole_manager_is_name_registered(PyObject *cls, PyObject * args)
{
char *key;
if (!PyArg_ParseTuple(args, "s:is_name_registered", &key))
{
return nullptr;
}
if (!IConsoleManager::Get().IsNameRegistered(UTF8_TO_TCHAR(key)))
{
Py_RETURN_FALSE;
}
Py_RETURN_TRUE;
}
static PyObject *py_ue_iconsole_manager_unregister_object(PyObject *cls, PyObject * args)
{
char *key;
if (!PyArg_ParseTuple(args, "s:unregister_object", &key))
{
return nullptr;
}
IConsoleObject *c_object = IConsoleManager::Get().FindConsoleObject(UTF8_TO_TCHAR(key));
if (!c_object)
{
return PyErr_Format(PyExc_Exception, "unable to find console object \"%s\"", key);
}
FPythonSmartConsoleDelegate::UnregisterPyDelegate(c_object);
IConsoleManager::Get().UnregisterConsoleObject(c_object, false);
Py_RETURN_NONE;
}
static PyObject *py_ue_iconsole_manager_register_variable_string(PyObject *cls, PyObject * args)
{
char *key;
char *help;
char *value = (char *)"";
if (!PyArg_ParseTuple(args, "ss|s:register_variable_string", &key, &help, &value))
{
return nullptr;
}
IConsoleObject *c_object = IConsoleManager::Get().FindConsoleObject(UTF8_TO_TCHAR(key));
if (c_object)
{
return PyErr_Format(PyExc_Exception, "console object \"%s\" already exists", key);
}
if (!IConsoleManager::Get().RegisterConsoleVariable(UTF8_TO_TCHAR(key), FString(UTF8_TO_TCHAR(value)), UTF8_TO_TCHAR(help), 0))
{
return PyErr_Format(PyExc_Exception, "unable to register console object \"%s\"", key);
}
Py_RETURN_NONE;
}
static PyObject *py_ue_iconsole_manager_register_variable_int(PyObject *cls, PyObject * args)
{
char *key;
char *help;
int value = 0;
if (!PyArg_ParseTuple(args, "ss|i:register_variable_int", &key, &help, &value))
{
return nullptr;
}
IConsoleObject *c_object = IConsoleManager::Get().FindConsoleObject(UTF8_TO_TCHAR(key));
if (c_object)
{
return PyErr_Format(PyExc_Exception, "console object \"%s\" already exists", key);
}
if (!IConsoleManager::Get().RegisterConsoleVariable(UTF8_TO_TCHAR(key), value, UTF8_TO_TCHAR(help), 0))
{
return PyErr_Format(PyExc_Exception, "unable to register console object \"%s\"", key);
}
Py_RETURN_NONE;
}
static PyObject *py_ue_iconsole_manager_register_variable_float(PyObject *cls, PyObject * args)
{
char *key;
char *help;
float value = 0;
if (!PyArg_ParseTuple(args, "ss|f:register_variable_float", &key, &help, &value))
{
return nullptr;
}
IConsoleObject *c_object = IConsoleManager::Get().FindConsoleObject(UTF8_TO_TCHAR(key));
if (c_object)
{
return PyErr_Format(PyExc_Exception, "console object \"%s\" already exists", key);
}
if (!IConsoleManager::Get().RegisterConsoleVariable(UTF8_TO_TCHAR(key), value, UTF8_TO_TCHAR(help), 0))
{
return PyErr_Format(PyExc_Exception, "unable to register console object \"%s\"", key);
}
Py_RETURN_NONE;
}
void FPythonSmartConsoleDelegate::OnConsoleCommand(const TArray < FString > & InArgs)
{
FScopePythonGIL gil;
PyObject *ret = nullptr;
if (InArgs.Num() == 0)
{
ret = PyObject_CallFunction(py_callable, nullptr);
}
else
{
PyObject *py_args = PyTuple_New(InArgs.Num());
for (int32 i = 0; i < InArgs.Num(); i++)
{
PyTuple_SetItem(py_args, i, PyUnicode_FromString(TCHAR_TO_UTF8(*InArgs[i])));
}
ret = PyObject_CallObject(py_callable, py_args);
Py_DECREF(py_args);
}
if (!ret)
{
unreal_engine_py_log_error();
return;
}
Py_DECREF(ret);
}
// static TArray declaration
TArray<FPythonSmartConsoleDelegatePair> FPythonSmartConsoleDelegate::PyDelegatesMapping;
static PyObject *py_ue_iconsole_manager_register_command(PyObject *cls, PyObject * args)
{
char *key;
PyObject *py_callable;
char *help = nullptr;
if (!PyArg_ParseTuple(args, "sO|s:register_command", &key, &py_callable, &help))
{
return nullptr;
}
if (!PyCallable_Check(py_callable))
{
return PyErr_Format(PyExc_Exception, "argument is not callable");
}
IConsoleObject *c_object = IConsoleManager::Get().FindConsoleObject(UTF8_TO_TCHAR(key));
if (c_object)
{
return PyErr_Format(PyExc_Exception, "console object \"%s\" already exists", key);
}
TSharedRef<FPythonSmartConsoleDelegate> py_delegate = MakeShareable(new FPythonSmartConsoleDelegate);
py_delegate->SetPyCallable(py_callable);
FConsoleCommandWithArgsDelegate console_delegate;
console_delegate.BindSP(py_delegate, &FPythonSmartConsoleDelegate::OnConsoleCommand);
c_object = IConsoleManager::Get().RegisterConsoleCommand(UTF8_TO_TCHAR(key), help ? UTF8_TO_TCHAR(help) : UTF8_TO_TCHAR(key), console_delegate, 0);
if (!c_object)
return PyErr_Format(PyExc_Exception, "unable to register console command \"%s\"", key);
// this allows the delegates to not be destroyed
FPythonSmartConsoleDelegate::RegisterPyDelegate(c_object, py_delegate);
Py_RETURN_NONE;
}
static PyMethodDef ue_PyIConsoleManager_methods[] = {
{ "get_history", (PyCFunction)py_ue_iconsole_manager_get_history, METH_VARARGS | METH_CLASS, "" },
{ "add_history_entry", (PyCFunction)py_ue_iconsole_manager_add_history_entry, METH_VARARGS | METH_CLASS, "" },
#if ENGINE_MINOR_VERSION > 12
{ "get_objects", (PyCFunction)py_ue_iconsole_manager_get_objects, METH_VARARGS | METH_CLASS, "" },
{ "get_objects_starting_with", (PyCFunction)py_ue_iconsole_manager_get_objects, METH_VARARGS | METH_CLASS, "" },
{ "get_objects_containing", (PyCFunction)py_ue_iconsole_manager_get_objects_containing, METH_VARARGS | METH_CLASS, "" },
#endif
{ "get_help", (PyCFunction)py_ue_iconsole_manager_get_help, METH_VARARGS | METH_CLASS, "" },
{ "set_help", (PyCFunction)py_ue_iconsole_manager_set_help, METH_VARARGS | METH_CLASS, "" },
{ "get_int", (PyCFunction)py_ue_iconsole_manager_get_int, METH_VARARGS | METH_CLASS, "" },
{ "get_float", (PyCFunction)py_ue_iconsole_manager_get_float, METH_VARARGS | METH_CLASS, "" },
{ "get_string", (PyCFunction)py_ue_iconsole_manager_get_string, METH_VARARGS | METH_CLASS, "" },
{ "set_int", (PyCFunction)py_ue_iconsole_manager_set_int, METH_VARARGS | METH_CLASS, "" },
{ "set_float", (PyCFunction)py_ue_iconsole_manager_set_float, METH_VARARGS | METH_CLASS, "" },
{ "set_string", (PyCFunction)py_ue_iconsole_manager_set_string, METH_VARARGS | METH_CLASS, "" },
{ "is_variable", (PyCFunction)py_ue_iconsole_manager_is_variable, METH_VARARGS | METH_CLASS, "" },
{ "is_command", (PyCFunction)py_ue_iconsole_manager_is_command, METH_VARARGS | METH_CLASS, "" },
{ "is_variable_string", (PyCFunction)py_ue_iconsole_manager_is_variable_string, METH_VARARGS | METH_CLASS, "" },
{ "is_variable_float", (PyCFunction)py_ue_iconsole_manager_is_variable_float, METH_VARARGS | METH_CLASS, "" },
{ "is_variable_int", (PyCFunction)py_ue_iconsole_manager_is_variable_int, METH_VARARGS | METH_CLASS, "" },
{ "is_name_registered", (PyCFunction)py_ue_iconsole_manager_is_name_registered, METH_VARARGS | METH_CLASS, "" },
{ "unregister_object", (PyCFunction)py_ue_iconsole_manager_unregister_object, METH_VARARGS | METH_CLASS, "" },
{ "register_variable_string", (PyCFunction)py_ue_iconsole_manager_register_variable_string, METH_VARARGS | METH_CLASS, "" },
{ "register_variable_int", (PyCFunction)py_ue_iconsole_manager_register_variable_int, METH_VARARGS | METH_CLASS, "" },
{ "register_variable_float", (PyCFunction)py_ue_iconsole_manager_register_variable_float, METH_VARARGS | METH_CLASS, "" },
{ "register_command", (PyCFunction)py_ue_iconsole_manager_register_command, METH_VARARGS | METH_CLASS, "" },
{ NULL } /* Sentinel */
};
static PyTypeObject ue_PyIConsoleManagerType = {
PyVarObject_HEAD_INIT(NULL, 0)
"unreal_engine.IConsoleManager", /* tp_name */
sizeof(ue_PyIConsoleManager), /* tp_basicsize */
0, /* tp_itemsize */
0, /* tp_dealloc */
0, /* tp_print */
0, /* tp_getattr */
0, /* tp_setattr */
0, /* tp_reserved */
0, /* tp_repr */
0, /* tp_as_number */
0, /* tp_as_sequence */
0, /* tp_as_mapping */
0, /* tp_hash */
0, /* tp_call */
0, /* tp_str */
0, /* tp_getattro */
0, /* tp_setattro */
0, /* tp_as_buffer */
Py_TPFLAGS_DEFAULT, /* tp_flags */
"Unreal Engine ConsoleManager Interface", /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
0, /* tp_richcompare */
0, /* tp_weaklistoffset */
0, /* tp_iter */
0, /* tp_iternext */
ue_PyIConsoleManager_methods, /* tp_methods */
0,
0,
};
static int py_ue_iconsole_manager_init(ue_PyIConsoleManager *self, PyObject * args)
{
PyErr_SetString(PyExc_Exception, "IConsoleManager is a singleton");
return -1;
}
void ue_python_init_iconsole_manager(PyObject *ue_module)
{
ue_PyIConsoleManagerType.tp_new = PyType_GenericNew;
ue_PyIConsoleManagerType.tp_init = (initproc)py_ue_iconsole_manager_init;
if (PyType_Ready(&ue_PyIConsoleManagerType) < 0)
return;
Py_INCREF(&ue_PyIConsoleManagerType);
PyModule_AddObject(ue_module, "IConsoleManager", (PyObject *)&ue_PyIConsoleManagerType);
}
```
|
/content/code_sandbox/Source/UnrealEnginePython/Private/ConsoleManager/UEPyIConsoleManager.cpp
|
c++
| 2016-08-07T05:00:51
| 2024-08-14T06:32:20
|
UnrealEnginePython
|
20tab/UnrealEnginePython
| 2,715
| 5,071
|
```objective-c
#pragma once
#include "UEPyModule.h"
#include "Runtime/Core/Public/HAL/IConsoleManager.h"
typedef struct
{
PyObject_HEAD
/* Type-specific fields go here. */
} ue_PyIConsoleManager;
class FPythonSmartConsoleDelegate;
struct FPythonSmartConsoleDelegatePair
{
IConsoleObject *Key;
TSharedRef<FPythonSmartConsoleDelegate> Value;
FPythonSmartConsoleDelegatePair(IConsoleObject *InKey, TSharedRef<FPythonSmartConsoleDelegate> InValue) : Key(InKey), Value(InValue)
{
}
};
class FPythonSmartConsoleDelegate : public FPythonSmartDelegate
{
public:
void OnConsoleCommand(const TArray < FString > &InArgs);
static void RegisterPyDelegate(IConsoleObject *InKey, TSharedRef<FPythonSmartConsoleDelegate> InValue)
{
FPythonSmartConsoleDelegatePair Pair(InKey, InValue);
PyDelegatesMapping.Add(Pair);
}
static void UnregisterPyDelegate(IConsoleObject *Key)
{
int32 Index = -1;
for (int32 i = 0; i < PyDelegatesMapping.Num(); i++)
{
if (PyDelegatesMapping[i].Key == Key)
{
Index = i;
break;
}
}
if (Index >= 0)
{
PyDelegatesMapping.RemoveAt(Index);
}
}
private:
static TArray<FPythonSmartConsoleDelegatePair> PyDelegatesMapping;
};
void ue_python_init_iconsole_manager(PyObject *);
```
|
/content/code_sandbox/Source/UnrealEnginePython/Private/ConsoleManager/UEPyIConsoleManager.h
|
objective-c
| 2016-08-07T05:00:51
| 2024-08-14T06:32:20
|
UnrealEnginePython
|
20tab/UnrealEnginePython
| 2,715
| 333
|
```c++
#include "UEPyEdGraphPin.h"
#if WITH_EDITOR
#include "Runtime/Engine/Classes/EdGraph/EdGraphPin.h"
#include "Editor/UnrealEd/Public/Kismet2/BlueprintEditorUtils.h"
static PyObject *py_ue_edgraphpin_make_link_to(ue_PyEdGraphPin *self, PyObject * args)
{
PyObject *other_pin;
if (!PyArg_ParseTuple(args, "O:make_link_to", &other_pin))
{
return NULL;
}
ue_PyEdGraphPin *py_other_pin = py_ue_is_edgraphpin(other_pin);
if (!py_other_pin)
{
return PyErr_Format(PyExc_Exception, "argument is not a UEdGraphPin");
}
self->pin->MakeLinkTo(py_other_pin->pin);
if (UBlueprint *bp = Cast<UBlueprint>(self->pin->GetOwningNode()->GetGraph()->GetOuter()))
{
FBlueprintEditorUtils::MarkBlueprintAsStructurallyModified(bp);
}
Py_RETURN_NONE;
}
static PyObject *py_ue_edgraphpin_connect(ue_PyEdGraphPin *self, PyObject * args)
{
PyObject *other_pin;
if (!PyArg_ParseTuple(args, "O:connect", &other_pin))
{
return NULL;
}
ue_PyEdGraphPin *py_other_pin = py_ue_is_edgraphpin(other_pin);
if (!py_other_pin)
{
return PyErr_Format(PyExc_Exception, "argument is not a UEdGraphPin");
}
if (!self->pin->GetSchema()->TryCreateConnection(self->pin, py_other_pin->pin))
{
return PyErr_Format(PyExc_Exception, "unable to connect pins");
}
if (UBlueprint *bp = Cast<UBlueprint>(self->pin->GetOwningNode()->GetGraph()->GetOuter()))
{
FBlueprintEditorUtils::MarkBlueprintAsStructurallyModified(bp);
}
Py_RETURN_NONE;
}
static PyObject *py_ue_edgraphpin_break_link_to(ue_PyEdGraphPin *self, PyObject * args)
{
PyObject *other_pin;
if (!PyArg_ParseTuple(args, "O:break_link_to", &other_pin))
{
return NULL;
}
ue_PyEdGraphPin *py_other_pin = py_ue_is_edgraphpin(other_pin);
if (!py_other_pin)
{
return PyErr_Format(PyExc_Exception, "argument is not a UEdGraphPin");
}
self->pin->BreakLinkTo(py_other_pin->pin);
if (UBlueprint *bp = Cast<UBlueprint>(self->pin->GetOwningNode()->GetGraph()->GetOuter()))
{
FBlueprintEditorUtils::MarkBlueprintAsStructurallyModified(bp);
}
Py_RETURN_NONE;
}
static PyObject *py_ue_edgraphpin_break_all_pin_links(ue_PyEdGraphPin *self, PyObject * args)
{
PyObject *py_notify_nodes = nullptr;
if (!PyArg_ParseTuple(args, "O:break_all_pin_links", &py_notify_nodes))
{
return NULL;
}
bool notify_nodes = true;
if (py_notify_nodes && !PyObject_IsTrue(py_notify_nodes))
notify_nodes = false;
self->pin->BreakAllPinLinks(notify_nodes);
if (UBlueprint *bp = Cast<UBlueprint>(self->pin->GetOwningNode()->GetGraph()->GetOuter()))
{
FBlueprintEditorUtils::MarkBlueprintAsStructurallyModified(bp);
}
Py_RETURN_NONE;
}
static PyObject *py_ue_edgraphpin_get_linked_to(ue_PyEdGraphPin * self, PyObject * args)
{
PyObject *pins = PyList_New(0);
TArray<UEdGraphPin*> Links = self->pin->LinkedTo;
for (int32 i = 0; i < Links.Num(); i++)
{
UEdGraphPin *pin = Links[i];
ue_PyUObject *item = (ue_PyUObject *)py_ue_new_edgraphpin(pin);
if (item)
PyList_Append(pins, (PyObject *)item);
}
return pins;
}
static PyMethodDef ue_PyEdGraphPin_methods[] = {
{ "make_link_to", (PyCFunction)py_ue_edgraphpin_make_link_to, METH_VARARGS, "" },
{ "break_link_to", (PyCFunction)py_ue_edgraphpin_break_link_to, METH_VARARGS, "" },
{ "break_all_pin_links", (PyCFunction)py_ue_edgraphpin_break_all_pin_links, METH_VARARGS, "" },
{ "get_linked_to", (PyCFunction)py_ue_edgraphpin_get_linked_to, METH_VARARGS, "" },
{ "connect", (PyCFunction)py_ue_edgraphpin_connect, METH_VARARGS, "" },
{ NULL } /* Sentinel */
};
static PyObject *py_ue_edgraphpin_get_name(ue_PyEdGraphPin *self, void *closure)
{
#if ENGINE_MINOR_VERSION > 18
return PyUnicode_FromString(TCHAR_TO_UTF8(*(self->pin->PinName.ToString())));
#else
return PyUnicode_FromString(TCHAR_TO_UTF8(*(self->pin->PinName)));
#endif
}
static PyObject *py_ue_edgraphpin_get_category(ue_PyEdGraphPin *self, void *closure)
{
#if ENGINE_MINOR_VERSION > 18
return PyUnicode_FromString(TCHAR_TO_UTF8(*(self->pin->PinType.PinCategory.ToString())));
#else
return PyUnicode_FromString(TCHAR_TO_UTF8(*(self->pin->PinType.PinCategory)));
#endif
}
static PyObject *py_ue_edgraphpin_get_sub_category(ue_PyEdGraphPin *self, void *closure)
{
#if ENGINE_MINOR_VERSION > 18
return PyUnicode_FromString(TCHAR_TO_UTF8(*(self->pin->PinType.PinSubCategory.ToString())));
#else
return PyUnicode_FromString(TCHAR_TO_UTF8(*(self->pin->PinType.PinSubCategory)));
#endif
}
static PyObject *py_ue_edgraphpin_get_default_value(ue_PyEdGraphPin *self, void *closure)
{
return PyUnicode_FromString(TCHAR_TO_UTF8(*(self->pin->DefaultValue)));
}
static int py_ue_edgraphpin_set_default_value(ue_PyEdGraphPin *self, PyObject *value, void *closure)
{
if (value && PyUnicodeOrString_Check(value))
{
const char *str = UEPyUnicode_AsUTF8(value);
self->pin->DefaultValue = UTF8_TO_TCHAR(str);
return 0;
}
PyErr_SetString(PyExc_TypeError, "value is not a string");
return -1;
}
static PyObject *py_ue_edgraphpin_get_default_text_value(ue_PyEdGraphPin *self, void *closure)
{
return PyUnicode_FromString(TCHAR_TO_UTF8(*(self->pin->DefaultTextValue.ToString())));
}
static int py_ue_edgraphpin_set_default_text_value(ue_PyEdGraphPin *self, PyObject *value, void *closure)
{
if (value && PyUnicodeOrString_Check(value))
{
const char *str = UEPyUnicode_AsUTF8(value);
self->pin->DefaultTextValue = FText::FromString(UTF8_TO_TCHAR(str));
return 0;
}
PyErr_SetString(PyExc_TypeError, "value is not a string");
return -1;
}
static PyObject *py_ue_edgraphpin_get_default_object(ue_PyEdGraphPin *self, void *closure)
{
UObject *u_object = self->pin->DefaultObject;
if (!u_object)
{
Py_RETURN_NONE;
}
Py_RETURN_UOBJECT(u_object);
}
static int py_ue_edgraphpin_set_default_object(ue_PyEdGraphPin *self, PyObject *value, void *closure)
{
if (value && ue_is_pyuobject(value))
{
ue_PyUObject *py_obj = (ue_PyUObject *)value;
self->pin->DefaultObject = py_obj->ue_object;
return 0;
}
PyErr_SetString(PyExc_TypeError, "value is not a UObject");
return -1;
}
static int py_ue_edgraphpin_set_category(ue_PyEdGraphPin *self, PyObject *value, void *closure)
{
if (value && PyUnicodeOrString_Check(value))
{
const char *str = UEPyUnicode_AsUTF8(value);
#if ENGINE_MINOR_VERSION > 18
self->pin->PinType.PinCategory = FName(UTF8_TO_TCHAR(str));
#else
self->pin->PinType.PinCategory = FString(UTF8_TO_TCHAR(str));
#endif
return 0;
}
PyErr_SetString(PyExc_TypeError, "value is not a string");
return -1;
}
static int py_ue_edgraphpin_set_sub_category(ue_PyEdGraphPin *self, PyObject *value, void *closure)
{
if (value)
{
if (ue_is_pyuobject(value))
{
ue_PyUObject *py_obj = (ue_PyUObject *)value;
self->pin->PinType.PinSubCategoryObject = py_obj->ue_object;
return 0;
}
if (PyUnicodeOrString_Check(value))
{
const char *str = UEPyUnicode_AsUTF8(value);
#if ENGINE_MINOR_VERSION > 18
self->pin->PinType.PinSubCategory = FName(UTF8_TO_TCHAR(str));
#else
self->pin->PinType.PinSubCategory = FString(UTF8_TO_TCHAR(str));
#endif
return 0;
}
}
PyErr_SetString(PyExc_TypeError, "value is not a UObject");
return -1;
}
static PyGetSetDef ue_PyEdGraphPin_getseters[] = {
{ (char*)"name", (getter)py_ue_edgraphpin_get_name, NULL, (char *)"", NULL },
{ (char*)"category", (getter)py_ue_edgraphpin_get_category, (setter)py_ue_edgraphpin_set_category, (char *)"", NULL },
{ (char*)"sub_category", (getter)py_ue_edgraphpin_get_sub_category, (setter)py_ue_edgraphpin_set_sub_category, (char *)"", NULL },
{ (char*)"default_value", (getter)py_ue_edgraphpin_get_default_value, (setter)py_ue_edgraphpin_set_default_value, (char *)"", NULL },
{ (char*)"default_text_value", (getter)py_ue_edgraphpin_get_default_text_value, (setter)py_ue_edgraphpin_set_default_text_value, (char *)"", NULL },
{ (char*)"default_object", (getter)py_ue_edgraphpin_get_default_object, (setter)py_ue_edgraphpin_set_default_object, (char *)"", NULL },
{ NULL } /* Sentinel */
};
static PyObject *ue_PyEdGraphPin_str(ue_PyEdGraphPin *self)
{
return PyUnicode_FromFormat("<unreal_engine.EdGraphPin {'name': '%s', 'type': '%s'}>",
#if ENGINE_MINOR_VERSION > 18
TCHAR_TO_UTF8(*self->pin->PinName.ToString()), TCHAR_TO_UTF8(*self->pin->PinType.PinCategory.ToString()));
#else
TCHAR_TO_UTF8(*self->pin->PinName), TCHAR_TO_UTF8(*self->pin->PinType.PinCategory));
#endif
}
static PyTypeObject ue_PyEdGraphPinType = {
PyVarObject_HEAD_INIT(NULL, 0)
"unreal_engine.EdGraphPin", /* tp_name */
sizeof(ue_PyEdGraphPin), /* tp_basicsize */
0, /* tp_itemsize */
0, /* tp_dealloc */
0, /* tp_print */
0, /* tp_getattr */
0, /* tp_setattr */
0, /* tp_reserved */
0, /* tp_repr */
0, /* tp_as_number */
0, /* tp_as_sequence */
0, /* tp_as_mapping */
0, /* tp_hash */
0, /* tp_call */
(reprfunc)ue_PyEdGraphPin_str, /* tp_str */
0, /* tp_getattro */
0, /* tp_setattro */
0, /* tp_as_buffer */
Py_TPFLAGS_DEFAULT, /* tp_flags */
"Unreal Engine Editor GraphPin", /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
0, /* tp_richcompare */
0, /* tp_weaklistoffset */
0, /* tp_iter */
0, /* tp_iternext */
ue_PyEdGraphPin_methods, /* tp_methods */
0,
ue_PyEdGraphPin_getseters,
};
void ue_python_init_edgraphpin(PyObject *ue_module)
{
ue_PyEdGraphPinType.tp_new = PyType_GenericNew;
if (PyType_Ready(&ue_PyEdGraphPinType) < 0)
return;
Py_INCREF(&ue_PyEdGraphPinType);
PyModule_AddObject(ue_module, "EdGraphPin", (PyObject *)&ue_PyEdGraphPinType);
}
PyObject *py_ue_new_edgraphpin(UEdGraphPin *pin)
{
ue_PyEdGraphPin *ret = (ue_PyEdGraphPin *)PyObject_New(ue_PyEdGraphPin, &ue_PyEdGraphPinType);
ret->pin = pin;
return (PyObject *)ret;
}
ue_PyEdGraphPin *py_ue_is_edgraphpin(PyObject *obj)
{
if (!PyObject_IsInstance(obj, (PyObject *)&ue_PyEdGraphPinType))
return nullptr;
return (ue_PyEdGraphPin *)obj;
}
#endif
```
|
/content/code_sandbox/Source/UnrealEnginePython/Private/Blueprint/UEPyEdGraphPin.cpp
|
c++
| 2016-08-07T05:00:51
| 2024-08-14T06:32:20
|
UnrealEnginePython
|
20tab/UnrealEnginePython
| 2,715
| 2,949
|
```objective-c
#pragma once
#include "UEPyModule.h"
#include "UEPyCallable.h"
#include "UEPyEdGraphPin.h"
#if WITH_EDITOR
PyObject *py_ue_graph_add_node_call_function(ue_PyUObject *, PyObject *);
PyObject *py_ue_graph_add_node_custom_event(ue_PyUObject *, PyObject *);
PyObject *py_ue_graph_add_node_variable_get(ue_PyUObject *, PyObject *);
PyObject *py_ue_graph_add_node_variable_set(ue_PyUObject *, PyObject *);
PyObject *py_ue_graph_add_node(ue_PyUObject *, PyObject *);
PyObject *py_ue_graph_add_node_dynamic_cast(ue_PyUObject *, PyObject *);
PyObject *py_ue_graph_add_node_event(ue_PyUObject *, PyObject *);
PyObject *py_ue_graph_reconstruct_node(ue_PyUObject *, PyObject *);
PyObject *py_ue_graph_remove_node(ue_PyUObject *, PyObject *);
PyObject *py_ue_graph_get_good_place_for_new_node(ue_PyUObject *, PyObject *);
PyObject *py_ue_node_pins(ue_PyUObject *, PyObject *);
PyObject *py_ue_node_find_pin(ue_PyUObject *, PyObject *);
PyObject *py_ue_node_create_pin(ue_PyUObject *, PyObject *);
PyObject *py_ue_node_pin_type_changed(ue_PyUObject *, PyObject *);
PyObject *py_ue_node_pin_default_value_changed(ue_PyUObject *, PyObject *);
PyObject *py_ue_node_function_entry_set_pure(ue_PyUObject *, PyObject *);
PyObject *py_ue_node_get_title(ue_PyUObject *, PyObject *);
PyObject *py_ue_node_allocate_default_pins(ue_PyUObject *, PyObject *);
PyObject *py_ue_node_reconstruct(ue_PyUObject *, PyObject *);
#endif
```
|
/content/code_sandbox/Source/UnrealEnginePython/Private/Blueprint/UEPyEdGraph.h
|
objective-c
| 2016-08-07T05:00:51
| 2024-08-14T06:32:20
|
UnrealEnginePython
|
20tab/UnrealEnginePython
| 2,715
| 359
|
```c++
#include "UEPyEdGraph.h"
#if WITH_EDITOR
#include "Runtime/Engine/Classes/EdGraph/EdGraph.h"
#include "Editor/BlueprintGraph/Classes/K2Node_CallFunction.h"
#include "Editor/BlueprintGraph/Classes/K2Node_DynamicCast.h"
#include "Editor/BlueprintGraph/Classes/EdGraphSchema_K2.h"
#include "Editor/BlueprintGraph/Classes/K2Node_CustomEvent.h"
#include "Editor/BlueprintGraph/Classes/K2Node_VariableGet.h"
#include "Editor/BlueprintGraph/Classes/K2Node_VariableSet.h"
#include "Editor/UnrealEd/Public/Kismet2/BlueprintEditorUtils.h"
#include "Editor/BlueprintGraph/Classes/EdGraphSchema_K2_Actions.h"
#include "Editor/AIGraph/Classes/AIGraph.h"
#include "Editor/AIGraph/Classes/AIGraphNode.h"
#include "Editor/BlueprintGraph/Classes/K2Node_FunctionEntry.h"
PyObject *py_ue_graph_add_node_call_function(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
PyObject *py_function = NULL;
int x = 0;
int y = 0;
if (!PyArg_ParseTuple(args, "O|ii:graph_add_node_call_function", &py_function, &x, &y))
{
return NULL;
}
if (!self->ue_object->IsA<UEdGraph>())
{
return PyErr_Format(PyExc_Exception, "uobject is not a UEdGraph");
}
UEdGraph *graph = (UEdGraph *)self->ue_object;
UFunction *function = nullptr;
if (ue_is_pyuobject(py_function))
{
ue_PyUObject *py_function_obj = (ue_PyUObject *)py_function;
if (py_function_obj->ue_object->IsA<UFunction>())
{
function = (UFunction *)py_function_obj->ue_object;
}
else
{
return PyErr_Format(PyExc_Exception, "argument is not a UObject");
}
}
else if (py_ue_is_callable(py_function))
{
ue_PyCallable *py_callable = (ue_PyCallable *)py_function;
function = py_callable->u_function;
}
if (!function)
return PyErr_Format(PyExc_Exception, "uobject is not a UFunction");
UK2Node_CallFunction *node = NewObject<UK2Node_CallFunction>(graph);
node->CreateNewGuid();
node->PostPlacedNewNode();
node->SetFromFunction(function);
node->SetFlags(RF_Transactional);
node->AllocateDefaultPins();
node->NodePosX = x;
node->NodePosY = y;
UEdGraphSchema_K2::SetNodeMetaData(node, FNodeMetadata::DefaultGraphNode);
graph->AddNode(node);
if (UBlueprint *bp = Cast<UBlueprint>(node->GetGraph()->GetOuter()))
{
FBlueprintEditorUtils::MarkBlueprintAsStructurallyModified(bp);
}
Py_RETURN_UOBJECT(node);
}
PyObject *py_ue_graph_add_node_custom_event(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
char *name = nullptr;
int x = 0;
int y = 0;
if (!PyArg_ParseTuple(args, "s|ii:graph_add_node_custom_event", &name, &x, &y))
{
return NULL;
}
if (!self->ue_object->IsA<UEdGraph>())
{
return PyErr_Format(PyExc_Exception, "uobject is not a UEdGraph");
}
UEdGraph *graph = (UEdGraph *)self->ue_object;
UK2Node_CustomEvent *node = NewObject<UK2Node_CustomEvent>(graph);
node->CreateNewGuid();
node->PostPlacedNewNode();
node->CustomFunctionName = name;
node->SetFlags(RF_Transactional);
node->AllocateDefaultPins();
node->NodePosX = x;
node->NodePosY = y;
UEdGraphSchema_K2::SetNodeMetaData(node, FNodeMetadata::DefaultGraphNode);
graph->AddNode(node);
if (UBlueprint *bp = Cast<UBlueprint>(node->GetGraph()->GetOuter()))
{
FBlueprintEditorUtils::MarkBlueprintAsStructurallyModified(bp);
}
Py_RETURN_UOBJECT(node);
}
PyObject *py_ue_graph_get_good_place_for_new_node(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
if (!self->ue_object->IsA<UEdGraph>())
{
return PyErr_Format(PyExc_Exception, "uobject is not a UEdGraph");
}
UEdGraph *graph = (UEdGraph *)self->ue_object;
FVector2D pos = graph->GetGoodPlaceForNewNode();
PyObject *ret = PyTuple_New(2);
PyTuple_SetItem(ret, 0, PyLong_FromDouble(pos.X));
PyTuple_SetItem(ret, 1, PyLong_FromDouble(pos.Y));
return ret;
}
PyObject *py_ue_graph_add_node_event(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
PyObject *py_class = nullptr;
char *name = nullptr;
int x = 0;
int y = 0;
if (!PyArg_ParseTuple(args, "Os|ii:graph_add_node_event", &py_class, &name, &x, &y))
{
return NULL;
}
if (!self->ue_object->IsA<UEdGraph>())
{
return PyErr_Format(PyExc_Exception, "uobject is not a UEdGraph");
}
UEdGraph *graph = (UEdGraph *)self->ue_object;
if (!ue_is_pyuobject(py_class))
{
return PyErr_Format(PyExc_Exception, "argument is not a UObject");
}
ue_PyUObject *py_obj = (ue_PyUObject *)py_class;
if (!py_obj->ue_object->IsA<UClass>())
{
return PyErr_Format(PyExc_Exception, "argument is not a UClass");
}
UClass *u_class = (UClass *)py_obj->ue_object;
UBlueprint *bp = (UBlueprint *)graph->GetOuter();
UK2Node_Event *node = FBlueprintEditorUtils::FindOverrideForFunction(bp, u_class, UTF8_TO_TCHAR(name));
if (!node)
{
node = NewObject<UK2Node_Event>(graph);
UEdGraphSchema_K2::SetNodeMetaData(node, FNodeMetadata::DefaultGraphNode);
node->EventReference.SetExternalMember(UTF8_TO_TCHAR(name), u_class);
node = FEdGraphSchemaAction_K2NewNode::SpawnNodeFromTemplate<UK2Node_Event>(graph, node, FVector2D(x, y));
}
FBlueprintEditorUtils::MarkBlueprintAsStructurallyModified(bp);
Py_RETURN_UOBJECT(node);
}
PyObject *py_ue_graph_add_node_variable_get(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
char *name = nullptr;
PyObject *py_struct = nullptr;
int x = 0;
int y = 0;
if (!PyArg_ParseTuple(args, "s|Oii:graph_add_node_variable_get", &name, &py_struct, &x, &y))
{
return NULL;
}
if (!self->ue_object->IsA<UEdGraph>())
{
return PyErr_Format(PyExc_Exception, "uobject is not a UEdGraph");
}
UEdGraph *graph = (UEdGraph *)self->ue_object;
UStruct *u_struct = nullptr;
if (py_struct && py_struct != Py_None)
{
if (!ue_is_pyuobject(py_struct))
{
return PyErr_Format(PyExc_Exception, "argument is not a UObject");
}
ue_PyUObject *ue_py_struct = (ue_PyUObject *)py_struct;
if (!ue_py_struct->ue_object->IsA<UStruct>())
{
return PyErr_Format(PyExc_Exception, "argument is not a UStruct");
}
u_struct = (UStruct *)ue_py_struct->ue_object;
}
UK2Node_VariableGet *node = NewObject<UK2Node_VariableGet>();
UBlueprint *bp = FBlueprintEditorUtils::FindBlueprintForGraph(graph);
UEdGraphSchema_K2::ConfigureVarNode(node, FName(UTF8_TO_TCHAR(name)), u_struct, bp);
node = FEdGraphSchemaAction_K2NewNode::SpawnNodeFromTemplate<UK2Node_VariableGet>(graph, node, FVector2D(x, y));
FBlueprintEditorUtils::MarkBlueprintAsStructurallyModified(bp);
Py_RETURN_UOBJECT(node);
}
PyObject *py_ue_graph_add_node_variable_set(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
char *name = nullptr;
PyObject *py_struct = nullptr;
int x = 0;
int y = 0;
if (!PyArg_ParseTuple(args, "s|Oii:graph_add_node_variable_set", &name, &py_struct, &x, &y))
{
return NULL;
}
if (!self->ue_object->IsA<UEdGraph>())
{
return PyErr_Format(PyExc_Exception, "uobject is not a UEdGraph");
}
UEdGraph *graph = (UEdGraph *)self->ue_object;
UStruct *u_struct = nullptr;
if (py_struct && py_struct != Py_None)
{
if (!ue_is_pyuobject(py_struct))
{
return PyErr_Format(PyExc_Exception, "argument is not a UObject");
}
ue_PyUObject *ue_py_struct = (ue_PyUObject *)py_struct;
if (!ue_py_struct->ue_object->IsA<UStruct>())
{
return PyErr_Format(PyExc_Exception, "argument is not a UStruct");
}
u_struct = (UStruct *)ue_py_struct->ue_object;
}
UK2Node_VariableSet *node = NewObject<UK2Node_VariableSet>();
UBlueprint *bp = FBlueprintEditorUtils::FindBlueprintForGraph(graph);
UEdGraphSchema_K2::ConfigureVarNode(node, FName(UTF8_TO_TCHAR(name)), u_struct, bp);
node = FEdGraphSchemaAction_K2NewNode::SpawnNodeFromTemplate<UK2Node_VariableSet>(graph, node, FVector2D(x, y));
FBlueprintEditorUtils::MarkBlueprintAsStructurallyModified(bp);
Py_RETURN_UOBJECT(node);
}
PyObject *py_ue_graph_add_node(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
PyObject *py_node_class;
int x = 0;
int y = 0;
char *metadata = nullptr;
PyObject *py_data = nullptr;
if (!PyArg_ParseTuple(args, "O|iisO:graph_add_node", &py_node_class, &x, &y, &metadata, &py_data))
{
return nullptr;
}
UEdGraph *graph = ue_py_check_type<UEdGraph>(self);
if (!graph)
return PyErr_Format(PyExc_Exception, "uobject is not a UEdGraph");
UObject *u_obj = ue_py_check_type<UObject>(py_node_class);
if (!u_obj)
return PyErr_Format(PyExc_Exception, "argument is not a UObject");
UEdGraphNode *node = nullptr;
if (UClass *u_class = Cast<UClass>(u_obj))
{
if (!u_class->IsChildOf<UEdGraphNode>())
{
return PyErr_Format(PyExc_Exception, "argument is not a child of UEdGraphNode");
}
node = NewObject<UEdGraphNode>(graph, u_class);
node->PostLoad();
}
else
{
node = Cast<UEdGraphNode>(u_obj);
if (node)
{
if (node->GetOuter() != graph)
node->Rename(*node->GetName(), graph);
}
}
if (!node)
return PyErr_Format(PyExc_Exception, "argument is not a supported type");
node->CreateNewGuid();
node->PostPlacedNewNode();
node->SetFlags(RF_Transactional);
if (node->Pins.Num() == 0)
{
node->AllocateDefaultPins();
}
node->NodePosX = x;
node->NodePosY = y;
// do something with data, based on the node type
if (node->IsA<UAIGraphNode>())
{
UAIGraphNode *ai_node = (UAIGraphNode *)node;
if (py_data)
{
FGraphNodeClassData *class_data = ue_py_check_struct<FGraphNodeClassData>(py_data);
if (class_data == nullptr)
{
UE_LOG(LogPython, Warning, TEXT("Unable to manage data argument for UAIGraphNode"));
}
else
{
ai_node->ClassData = *class_data;
}
}
}
if (metadata == nullptr || strlen(metadata) == 0)
{
UEdGraphSchema_K2::SetNodeMetaData(node, FNodeMetadata::DefaultGraphNode);
}
else
{
UEdGraphSchema_K2::SetNodeMetaData(node, FName(UTF8_TO_TCHAR(metadata)));
}
graph->AddNode(node);
if (UBlueprint *bp = Cast<UBlueprint>(node->GetGraph()->GetOuter()))
{
FBlueprintEditorUtils::MarkBlueprintAsStructurallyModified(bp);
}
Py_RETURN_UOBJECT(node);
}
PyObject *py_ue_graph_remove_node(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
PyObject *py_node_class;
int x = 0;
int y = 0;
char *metadata = nullptr;
PyObject *py_data = nullptr;
if (!PyArg_ParseTuple(args, "O|iisO:graph_remove_node", &py_node_class, &x, &y, &metadata, &py_data))
{
return nullptr;
}
UEdGraph *graph = ue_py_check_type<UEdGraph>(self);
if (!graph)
return PyErr_Format(PyExc_Exception, "uobject is not a UEdGraph");
UObject *u_obj = ue_py_check_type<UObject>(py_node_class);
if (!u_obj)
return PyErr_Format(PyExc_Exception, "argument is not a UObject");
UEdGraphNode *node = nullptr;
if (UClass *u_class = Cast<UClass>(u_obj))
{
if (!u_class->IsChildOf<UEdGraphNode>())
{
return PyErr_Format(PyExc_Exception, "argument is not a child of UEdGraphNode");
}
node = NewObject<UEdGraphNode>(graph, u_class);
node->PostLoad();
}
else
{
node = Cast<UEdGraphNode>(u_obj);
if (node)
{
if (node->GetOuter() != graph)
node->Rename(*node->GetName(), graph);
}
}
if (!node)
return PyErr_Format(PyExc_Exception, "argument is not a supported type");
graph->RemoveNode(node);
if (UBlueprint *bp = Cast<UBlueprint>(node->GetGraph()->GetOuter()))
{
FBlueprintEditorUtils::MarkBlueprintAsStructurallyModified(bp);
}
Py_RETURN_NONE;
}
PyObject *py_ue_graph_reconstruct_node(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
PyObject *py_node_class;
int x = 0;
int y = 0;
char *metadata = nullptr;
PyObject *py_data = nullptr;
if (!PyArg_ParseTuple(args, "O|iisO:graph_reconstruct_node", &py_node_class, &x, &y, &metadata, &py_data))
{
return nullptr;
}
UEdGraph *graph = ue_py_check_type<UEdGraph>(self);
if (!graph)
return PyErr_Format(PyExc_Exception, "uobject is not a UEdGraph");
UObject *u_obj = ue_py_check_type<UObject>(py_node_class);
if (!u_obj)
return PyErr_Format(PyExc_Exception, "argument is not a UObject");
UEdGraphNode *node = nullptr;
if (UClass *u_class = Cast<UClass>(u_obj))
{
if (!u_class->IsChildOf<UEdGraphNode>())
{
return PyErr_Format(PyExc_Exception, "argument is not a child of UEdGraphNode");
}
node = NewObject<UEdGraphNode>(graph, u_class);
node->PostLoad();
}
else
{
node = Cast<UEdGraphNode>(u_obj);
if (node)
{
if (node->GetOuter() != graph)
node->Rename(*node->GetName(), graph);
}
}
if (!node)
return PyErr_Format(PyExc_Exception, "argument is not a supported type");
//graph->RemoveNode(node);
node->ReconstructNode();
if (UBlueprint *bp = Cast<UBlueprint>(node->GetGraph()->GetOuter()))
{
FBlueprintEditorUtils::MarkBlueprintAsStructurallyModified(bp);
}
Py_RETURN_NONE;
}
PyObject *py_ue_graph_add_node_dynamic_cast(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
PyObject *py_node_class;
int x = 0;
int y = 0;
char *metadata = nullptr;
PyObject *py_data = nullptr;
if(!PyArg_ParseTuple(args, "O|iis:graph_add_node_dynamic_cast", &py_node_class, &x, &y, &metadata))
{
return nullptr;
}
UEdGraph *graph = ue_py_check_type<UEdGraph>(self);
if(!graph)
return PyErr_Format(PyExc_Exception, "uobject is not a UEdGraph");
UClass *u_class = ue_py_check_type<UClass>(py_node_class);
if(!u_class)
return PyErr_Format(PyExc_Exception, "argument is not a UClass");
UK2Node_DynamicCast *node = NewObject<UK2Node_DynamicCast>(graph);
node->TargetType = u_class;
#if ENGINE_MINOR_VERSION > 15
node->SetPurity(false);
#endif
node->AllocateDefaultPins();
node->CreateNewGuid();
node->PostPlacedNewNode();
node->SetFlags(RF_Transactional);
node->NodePosX = x;
node->NodePosY = y;
if(metadata == nullptr || strlen(metadata) == 0)
{
UEdGraphSchema_K2::SetNodeMetaData(node, FNodeMetadata::DefaultGraphNode);
}
else
{
UEdGraphSchema_K2::SetNodeMetaData(node, FName(UTF8_TO_TCHAR(metadata)));
}
graph->AddNode(node);
if(UBlueprint *bp = Cast<UBlueprint>(node->GetGraph()->GetOuter()))
{
FBlueprintEditorUtils::MarkBlueprintAsStructurallyModified(bp);
}
Py_RETURN_UOBJECT(node);
}
PyObject *py_ue_node_pins(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
if (!self->ue_object->IsA<UEdGraphNode>())
{
return PyErr_Format(PyExc_Exception, "uobject is not a UEdGraphNode");
}
UEdGraphNode *node = (UEdGraphNode *)self->ue_object;
PyObject *pins_list = PyList_New(0);
for (UEdGraphPin *pin : node->Pins)
{
PyList_Append(pins_list, (PyObject *)py_ue_new_edgraphpin(pin));
}
return pins_list;
}
PyObject *py_ue_node_get_title(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
int title_type = ENodeTitleType::FullTitle;
if (!PyArg_ParseTuple(args, "|i:node_get_title", &title_type))
{
return NULL;
}
UEdGraphNode *node = ue_py_check_type<UEdGraphNode>(self);
if (!node)
return PyErr_Format(PyExc_Exception, "uobject is not a UEdGraphNode");
FText title = node->GetNodeTitle((ENodeTitleType::Type)title_type);
return PyUnicode_FromString(TCHAR_TO_UTF8(*(title.ToString())));
}
PyObject *py_ue_node_allocate_default_pins(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
UEdGraphNode *node = ue_py_check_type<UEdGraphNode>(self);
if (!node)
return PyErr_Format(PyExc_Exception, "uobject is not a UEdGraphNode");
node->AllocateDefaultPins();
Py_RETURN_NONE;
}
PyObject *py_ue_node_reconstruct(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
UEdGraphNode *node = ue_py_check_type<UEdGraphNode>(self);
if (!node)
return PyErr_Format(PyExc_Exception, "uobject is not a UEdGraphNode");
node->GetSchema()->ReconstructNode(*node);
Py_RETURN_NONE;
}
PyObject *py_ue_node_find_pin(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
char *name = nullptr;
if (!PyArg_ParseTuple(args, "s:node_find_pin", &name))
{
return NULL;
}
if (!self->ue_object->IsA<UEdGraphNode>())
{
return PyErr_Format(PyExc_Exception, "uobject is not a UEdGraphNode");
}
UEdGraphNode *node = (UEdGraphNode *)self->ue_object;
UEdGraphPin *pin = node->FindPin(UTF8_TO_TCHAR(name));
if (!pin)
{
return PyErr_Format(PyExc_Exception, "unable to find pin \"%s\"", name);
}
return py_ue_new_edgraphpin(pin);
}
PyObject *py_ue_node_function_entry_set_pure(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
PyObject *py_bool = nullptr;
if (!PyArg_ParseTuple(args, "O:node_function_entry_set_pure", &py_bool))
{
return nullptr;
}
UK2Node_FunctionEntry *node = ue_py_check_type<UK2Node_FunctionEntry>(self);
if (!node)
return PyErr_Format(PyExc_Exception, "uobject is not a K2Node_FunctionEntry");
UEdGraph *graph = node->GetGraph();
if (!graph)
return PyErr_Format(PyExc_Exception, "unable to get graph from node");
UBlueprint *blueprint = FBlueprintEditorUtils::FindBlueprintForGraph(graph);
if (!blueprint)
return PyErr_Format(PyExc_Exception, "unable to get blueprint from node");
UClass *Class = blueprint->SkeletonGeneratedClass;
UFunction *function = nullptr;
for (TFieldIterator<UFunction> FunctionIt(Class, EFieldIteratorFlags::IncludeSuper); FunctionIt; ++FunctionIt)
{
if (*FunctionIt->GetName() == graph->GetName())
{
function = *FunctionIt;
break;
}
}
if (!function)
return PyErr_Format(PyExc_Exception, "unable to get function from node");
node->Modify();
function->Modify();
if (PyObject_IsTrue(py_bool))
{
function->FunctionFlags |= FUNC_BlueprintPure;
node->AddExtraFlags(FUNC_BlueprintPure);
}
else
{
function->FunctionFlags &= ~FUNC_BlueprintPure;
node->ClearExtraFlags(FUNC_BlueprintPure);
}
Py_RETURN_NONE;
}
PyObject *py_ue_node_create_pin(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
int pin_direction;
PyObject *pin_type;
char *name = nullptr;
int index = 0;
if (!PyArg_ParseTuple(args, "iOs|i:node_create_pin", &pin_direction, &pin_type, &name, &index))
{
return nullptr;
}
UEdGraphNode *node = ue_py_check_type<UEdGraphNode>(self);
if (!node)
return PyErr_Format(PyExc_Exception, "uobject is not a UEdGraphNode");
FEdGraphPinType *pin_struct = ue_py_check_struct<FEdGraphPinType>(pin_type);
if (!pin_struct)
return PyErr_Format(PyExc_Exception, "argument is not a FEdGraphPinType");
UEdGraphPin *pin = nullptr;
if (node->IsA<UK2Node_EditablePinBase>())
{
UK2Node_EditablePinBase *node_base = (UK2Node_EditablePinBase *)node;
pin = node_base->CreateUserDefinedPin(UTF8_TO_TCHAR(name), *pin_struct, (EEdGraphPinDirection)pin_direction);
}
else
{
pin = node->CreatePin((EEdGraphPinDirection)pin_direction, *pin_struct, UTF8_TO_TCHAR(name), index);
}
if (!pin)
{
return PyErr_Format(PyExc_Exception, "unable to create pin \"%s\"", name);
}
if (UBlueprint *bp = Cast<UBlueprint>(node->GetGraph()->GetOuter()))
{
FBlueprintEditorUtils::MarkBlueprintAsStructurallyModified(bp);
}
return py_ue_new_edgraphpin(pin);
}
PyObject *py_ue_node_pin_type_changed(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
PyObject *py_pin;
if (!PyArg_ParseTuple(args, "O:node_pin_type_changed", &py_pin))
{
return nullptr;
}
UEdGraphNode *node = ue_py_check_type<UEdGraphNode>(self);
if (!node)
return PyErr_Format(PyExc_Exception, "uobject is not a UEdGraphNode");
ue_PyEdGraphPin *pin = py_ue_is_edgraphpin(py_pin);
if (!pin)
return PyErr_Format(PyExc_Exception, "argument is not a EdGraphPin");
node->PinTypeChanged(pin->pin);
Py_RETURN_NONE;
}
PyObject *py_ue_node_pin_default_value_changed(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
PyObject *py_pin;
if (!PyArg_ParseTuple(args, "O:node_pin_default_value_changed", &py_pin))
{
return nullptr;
}
UEdGraphNode *node = ue_py_check_type<UEdGraphNode>(self);
if (!node)
return PyErr_Format(PyExc_Exception, "uobject is not a UEdGraphNode");
ue_PyEdGraphPin *pin = py_ue_is_edgraphpin(py_pin);
if (!pin)
return PyErr_Format(PyExc_Exception, "argument is not a EdGraphPin");
node->PinDefaultValueChanged(pin->pin);
Py_RETURN_NONE;
}
#endif
```
|
/content/code_sandbox/Source/UnrealEnginePython/Private/Blueprint/UEPyEdGraph.cpp
|
c++
| 2016-08-07T05:00:51
| 2024-08-14T06:32:20
|
UnrealEnginePython
|
20tab/UnrealEnginePython
| 2,715
| 5,775
|
```objective-c
#pragma once
#include "UEPyModule.h"
#if WITH_EDITOR
#include "Runtime/Engine/Classes/EdGraph/EdGraphPin.h"
typedef struct
{
PyObject_HEAD
/* Type-specific fields go here. */
UEdGraphPin *pin;
} ue_PyEdGraphPin;
PyObject *py_ue_new_edgraphpin(UEdGraphPin *);
ue_PyEdGraphPin *py_ue_is_edgraphpin(PyObject *);
void ue_python_init_edgraphpin(PyObject *);
#endif
```
|
/content/code_sandbox/Source/UnrealEnginePython/Private/Blueprint/UEPyEdGraphPin.h
|
objective-c
| 2016-08-07T05:00:51
| 2024-08-14T06:32:20
|
UnrealEnginePython
|
20tab/UnrealEnginePython
| 2,715
| 105
|
```c++
#include "UEPyICollectionManager.h"
#if WITH_EDITOR
#include "Developer/CollectionManager/Public/CollectionManagerModule.h"
static PyObject *py_ue_icollection_manager_get_collections(PyObject *cls, PyObject * args)
{
PyObject *py_list = PyList_New(0);
ICollectionManager &CollectionManager = FCollectionManagerModule::GetModule().Get();
TArray<FCollectionNameType> collections;
CollectionManager.GetCollections(collections);
for (FCollectionNameType name_type : collections)
{
PyList_Append(py_list, Py_BuildValue((char *)"(si)", TCHAR_TO_UTF8(*name_type.Name.ToString()), (int)name_type.Type));
}
return py_list;
}
static PyObject *py_ue_icollection_manager_get_parent_collection(PyObject *cls, PyObject * args)
{
char *name;
int type;
if (!PyArg_ParseTuple(args, "si", &name, &type))
return nullptr;
ICollectionManager &CollectionManager = FCollectionManagerModule::GetModule().Get();
TOptional<FCollectionNameType> name_type = CollectionManager.GetParentCollection(FName(UTF8_TO_TCHAR(name)), (ECollectionShareType::Type)type);
if (name_type.IsSet())
{
return Py_BuildValue((char *)"(si)", TCHAR_TO_UTF8(*name_type.GetValue().Name.ToString()), (int)name_type.GetValue().Type);
}
Py_RETURN_NONE;
}
static PyObject *py_ue_icollection_manager_get_root_collections(PyObject *cls, PyObject * args)
{
PyObject *py_list = PyList_New(0);
ICollectionManager &CollectionManager = FCollectionManagerModule::GetModule().Get();
TArray<FCollectionNameType> collections;
CollectionManager.GetRootCollections(collections);
for (FCollectionNameType name_type : collections)
{
PyList_Append(py_list, Py_BuildValue((char *)"(si)", TCHAR_TO_UTF8(*name_type.Name.ToString()), (int)name_type.Type));
}
return py_list;
}
static PyObject *py_ue_icollection_manager_get_child_collection_names(PyObject *cls, PyObject * args)
{
char *name;
int type;
int child_type;
if (!PyArg_ParseTuple(args, "sii", &name, &type, &child_type))
return nullptr;
PyObject *py_list = PyList_New(0);
ICollectionManager &CollectionManager = FCollectionManagerModule::GetModule().Get();
TArray<FName> names;
CollectionManager.GetChildCollectionNames(FName(UTF8_TO_TCHAR(name)), (ECollectionShareType::Type)type, (ECollectionShareType::Type)child_type, names);
for (FName cname : names)
{
PyList_Append(py_list, PyUnicode_FromString(TCHAR_TO_UTF8(*cname.ToString())));
}
return py_list;
}
static PyObject *py_ue_icollection_manager_get_child_collections(PyObject *cls, PyObject * args)
{
char *name;
int type;
if (!PyArg_ParseTuple(args, "si", &name, &type))
return nullptr;
PyObject *py_list = PyList_New(0);
ICollectionManager &CollectionManager = FCollectionManagerModule::GetModule().Get();
TArray<FCollectionNameType> collections;
CollectionManager.GetChildCollections(FName(UTF8_TO_TCHAR(name)), (ECollectionShareType::Type)type, collections);
for (FCollectionNameType name_type : collections)
{
PyList_Append(py_list, Py_BuildValue((char *)"(si)", TCHAR_TO_UTF8(*name_type.Name.ToString()), (int)name_type.Type));
}
return py_list;
}
static PyObject *py_ue_icollection_manager_get_collection_names(PyObject *cls, PyObject * args)
{
int type;
if (!PyArg_ParseTuple(args, "i", &type))
return nullptr;
PyObject *py_list = PyList_New(0);
ICollectionManager &CollectionManager = FCollectionManagerModule::GetModule().Get();
TArray<FName> names;
CollectionManager.GetCollectionNames((ECollectionShareType::Type)type, names);
for (FName name : names)
{
PyList_Append(py_list, PyUnicode_FromString(TCHAR_TO_UTF8(*name.ToString())));
}
return py_list;
}
static PyObject *py_ue_icollection_manager_get_root_collection_names(PyObject *cls, PyObject * args)
{
int type;
if (!PyArg_ParseTuple(args, "i", &type))
return nullptr;
PyObject *py_list = PyList_New(0);
ICollectionManager &CollectionManager = FCollectionManagerModule::GetModule().Get();
TArray<FName> names;
CollectionManager.GetRootCollectionNames((ECollectionShareType::Type)type, names);
for (FName name : names)
{
PyList_Append(py_list, PyUnicode_FromString(TCHAR_TO_UTF8(*name.ToString())));
}
return py_list;
}
static PyObject *py_ue_icollection_manager_create_static_collection(PyObject *cls, PyObject * args)
{
char *name;
int type;
if (!PyArg_ParseTuple(args, "si", &name, &type))
return nullptr;
ICollectionManager &CollectionManager = FCollectionManagerModule::GetModule().Get();
if (CollectionManager.CreateCollection(FName(UTF8_TO_TCHAR(name)), (ECollectionShareType::Type)type, ECollectionStorageMode::Static))
Py_RETURN_TRUE;
Py_RETURN_FALSE;
}
static PyObject *py_ue_icollection_manager_create_dynamic_collection(PyObject *cls, PyObject * args)
{
char *name;
int type;
if (!PyArg_ParseTuple(args, "si", &name, &type))
return nullptr;
ICollectionManager &CollectionManager = FCollectionManagerModule::GetModule().Get();
if (CollectionManager.CreateCollection(FName(UTF8_TO_TCHAR(name)), (ECollectionShareType::Type)type, ECollectionStorageMode::Dynamic))
Py_RETURN_TRUE;
Py_RETURN_FALSE;
}
static PyObject *py_ue_icollection_manager_create_collection(PyObject *cls, PyObject * args)
{
char *name;
int type;
int storage;
if (!PyArg_ParseTuple(args, "sii", &name, &type, &storage))
return nullptr;
ICollectionManager &CollectionManager = FCollectionManagerModule::GetModule().Get();
if (CollectionManager.CreateCollection(FName(UTF8_TO_TCHAR(name)), (ECollectionShareType::Type)type, (ECollectionStorageMode::Type)storage))
Py_RETURN_TRUE;
Py_RETURN_FALSE;
}
static PyObject *py_ue_icollection_manager_reparent_collection(PyObject *cls, PyObject * args)
{
char *name;
int type;
char *parent;
int parent_type;
if (!PyArg_ParseTuple(args, "sisi", &name, &type, &parent, &parent_type))
return nullptr;
ICollectionManager &CollectionManager = FCollectionManagerModule::GetModule().Get();
if (CollectionManager.ReparentCollection(
FName(UTF8_TO_TCHAR(name)),
(ECollectionShareType::Type)type,
FName(UTF8_TO_TCHAR(parent)),
(ECollectionShareType::Type)parent_type
))
Py_RETURN_TRUE;
Py_RETURN_FALSE;
}
static PyObject *py_ue_icollection_manager_rename_collection(PyObject *cls, PyObject * args)
{
char *name;
int type;
char *new_name;
int new_type;
if (!PyArg_ParseTuple(args, "sisi", &name, &type, &new_name, &new_type))
return nullptr;
ICollectionManager &CollectionManager = FCollectionManagerModule::GetModule().Get();
if (CollectionManager.RenameCollection(
FName(UTF8_TO_TCHAR(name)),
(ECollectionShareType::Type)type,
FName(UTF8_TO_TCHAR(new_name)),
(ECollectionShareType::Type)new_type
))
Py_RETURN_TRUE;
Py_RETURN_FALSE;
}
static PyObject *py_ue_icollection_manager_remove_from_collection(PyObject *cls, PyObject * args)
{
char *name;
int type;
char *object_path;
if (!PyArg_ParseTuple(args, "sis", &name, &type, &object_path))
return nullptr;
ICollectionManager &CollectionManager = FCollectionManagerModule::GetModule().Get();
if (CollectionManager.RemoveFromCollection(
FName(UTF8_TO_TCHAR(name)),
(ECollectionShareType::Type)type,
FName(UTF8_TO_TCHAR(object_path))
))
Py_RETURN_TRUE;
Py_RETURN_FALSE;
}
static PyObject *py_ue_icollection_manager_add_to_collection(PyObject *cls, PyObject * args)
{
char *name;
int type;
char *object_path;
if (!PyArg_ParseTuple(args, "sis", &name, &type, &object_path))
return nullptr;
ICollectionManager &CollectionManager = FCollectionManagerModule::GetModule().Get();
if (CollectionManager.AddToCollection(
FName(UTF8_TO_TCHAR(name)),
(ECollectionShareType::Type)type,
FName(UTF8_TO_TCHAR(object_path))
))
Py_RETURN_TRUE;
Py_RETURN_FALSE;
}
static PyObject *py_ue_icollection_manager_collection_exists(PyObject *cls, PyObject * args)
{
char *name;
int type;
if (!PyArg_ParseTuple(args, "si", &name, &type))
return nullptr;
ICollectionManager &CollectionManager = FCollectionManagerModule::GetModule().Get();
if (CollectionManager.CollectionExists(
FName(UTF8_TO_TCHAR(name)),
(ECollectionShareType::Type)type
))
Py_RETURN_TRUE;
Py_RETURN_FALSE;
}
static PyObject *py_ue_icollection_manager_create_unique_collection_name(PyObject *cls, PyObject * args)
{
char *base_name;
int type;
if (!PyArg_ParseTuple(args, "si", &base_name, &type))
return nullptr;
ICollectionManager &CollectionManager = FCollectionManagerModule::GetModule().Get();
FName name;
CollectionManager.CreateUniqueCollectionName(
FName(UTF8_TO_TCHAR(base_name)),
(ECollectionShareType::Type)type,
name);
return PyUnicode_FromString(TCHAR_TO_UTF8(*name.ToString()));
}
static PyObject *py_ue_icollection_manager_destroy_collection(PyObject *cls, PyObject * args)
{
char *name;
int type;
if (!PyArg_ParseTuple(args, "si", &name, &type))
return nullptr;
ICollectionManager &CollectionManager = FCollectionManagerModule::GetModule().Get();
if (CollectionManager.DestroyCollection(
FName(UTF8_TO_TCHAR(name)),
(ECollectionShareType::Type)type))
Py_RETURN_TRUE;
Py_RETURN_FALSE;
}
static PyObject *py_ue_icollection_manager_has_collections(PyObject *cls, PyObject * args)
{
ICollectionManager &CollectionManager = FCollectionManagerModule::GetModule().Get();
if (CollectionManager.HasCollections())
Py_RETURN_TRUE;
Py_RETURN_FALSE;
}
static PyObject *py_ue_icollection_manager_empty_collection(PyObject *cls, PyObject * args)
{
char *name;
int type;
if (!PyArg_ParseTuple(args, "si", &name, &type))
return nullptr;
ICollectionManager &CollectionManager = FCollectionManagerModule::GetModule().Get();
if (CollectionManager.EmptyCollection(
FName(UTF8_TO_TCHAR(name)),
(ECollectionShareType::Type)type))
Py_RETURN_TRUE;
Py_RETURN_FALSE;
}
static PyObject *py_ue_icollection_manager_get_dynamic_query_text(PyObject *cls, PyObject * args)
{
char *name;
int type;
if (!PyArg_ParseTuple(args, "si", &name, &type))
return nullptr;
ICollectionManager &CollectionManager = FCollectionManagerModule::GetModule().Get();
FString query_text;
if (!CollectionManager.GetDynamicQueryText(
FName(UTF8_TO_TCHAR(name)),
(ECollectionShareType::Type)type,
query_text))
{
return PyErr_Format(PyExc_Exception, "unable to get dynamic query text");
}
return PyUnicode_FromString(TCHAR_TO_UTF8(*query_text));
}
static PyObject *py_ue_icollection_manager_set_dynamic_query_text(PyObject *cls, PyObject * args)
{
char *name;
int type;
char *query_text;
if (!PyArg_ParseTuple(args, "sis", &name, &type, &query_text))
return nullptr;
ICollectionManager &CollectionManager = FCollectionManagerModule::GetModule().Get();
if (CollectionManager.SetDynamicQueryText(
FName(UTF8_TO_TCHAR(name)),
(ECollectionShareType::Type)type,
FString(UTF8_TO_TCHAR(query_text))))
Py_RETURN_TRUE;
Py_RETURN_FALSE;
}
static PyObject *py_ue_icollection_manager_get_last_error(PyObject *cls, PyObject * args)
{
ICollectionManager &CollectionManager = FCollectionManagerModule::GetModule().Get();
FText error = CollectionManager.GetLastError();
return PyUnicode_FromString(TCHAR_TO_UTF8(*error.ToString()));
}
static PyObject *py_ue_icollection_manager_get_assets_in_collection(PyObject *cls, PyObject * args)
{
char *name;
int type;
int recursion = 1;
if (!PyArg_ParseTuple(args, "si|i", &name, &type, &recursion))
return nullptr;
ICollectionManager &CollectionManager = FCollectionManagerModule::GetModule().Get();
TArray<FName> paths;
if (CollectionManager.GetAssetsInCollection(FName(UTF8_TO_TCHAR(name)), (ECollectionShareType::Type)type, paths, (ECollectionRecursionFlags::Flags)recursion))
{
PyObject *py_list = PyList_New(0);
for (FName path : paths)
{
PyList_Append(py_list, PyUnicode_FromString(TCHAR_TO_UTF8(*path.ToString())));
}
return py_list;
}
return PyErr_Format(PyExc_Exception, "unable to retrieve the assets list from collection");
}
static PyObject *py_ue_icollection_manager_get_objects_in_collection(PyObject *cls, PyObject * args)
{
char *name;
int type;
int recursion = 1;
if (!PyArg_ParseTuple(args, "si|i", &name, &type, &recursion))
return nullptr;
ICollectionManager &CollectionManager = FCollectionManagerModule::GetModule().Get();
TArray<FName> paths;
if (CollectionManager.GetObjectsInCollection(FName(UTF8_TO_TCHAR(name)), (ECollectionShareType::Type)type, paths, (ECollectionRecursionFlags::Flags)recursion))
{
PyObject *py_list = PyList_New(0);
for (FName path : paths)
{
PyList_Append(py_list, PyUnicode_FromString(TCHAR_TO_UTF8(*path.ToString())));
}
return py_list;
}
return PyErr_Format(PyExc_Exception, "unable to retrieve the objects list from collection");
}
static PyObject *py_ue_icollection_manager_get_classes_in_collection(PyObject *cls, PyObject * args)
{
char *name;
int type;
int recursion = 1;
if (!PyArg_ParseTuple(args, "si|i", &name, &type, &recursion))
return nullptr;
ICollectionManager &CollectionManager = FCollectionManagerModule::GetModule().Get();
TArray<FName> paths;
if (CollectionManager.GetClassesInCollection(FName(UTF8_TO_TCHAR(name)), (ECollectionShareType::Type)type, paths, (ECollectionRecursionFlags::Flags)recursion))
{
PyObject *py_list = PyList_New(0);
for (FName path : paths)
{
PyList_Append(py_list, PyUnicode_FromString(TCHAR_TO_UTF8(*path.ToString())));
}
return py_list;
}
return PyErr_Format(PyExc_Exception, "unable to retrieve the classes list from collection");
}
static PyMethodDef ue_PyICollectionManager_methods[] = {
{ "get_collections", (PyCFunction)py_ue_icollection_manager_get_collections, METH_VARARGS | METH_CLASS, "" },
{ "get_root_collections", (PyCFunction)py_ue_icollection_manager_get_root_collections, METH_VARARGS | METH_CLASS, "" },
{ "get_child_collections", (PyCFunction)py_ue_icollection_manager_get_child_collections, METH_VARARGS | METH_CLASS, "" },
{ "get_root_collection_names", (PyCFunction)py_ue_icollection_manager_get_root_collection_names, METH_VARARGS | METH_CLASS, "" },
{ "get_collection_names", (PyCFunction)py_ue_icollection_manager_get_collection_names, METH_VARARGS | METH_CLASS, "" },
{ "create_static_collection", (PyCFunction)py_ue_icollection_manager_create_static_collection, METH_VARARGS | METH_CLASS, "" },
{ "create_dynamic_collection", (PyCFunction)py_ue_icollection_manager_create_dynamic_collection, METH_VARARGS | METH_CLASS, "" },
{ "create_collection", (PyCFunction)py_ue_icollection_manager_create_collection, METH_VARARGS | METH_CLASS, "" },
{ "reparent_collection", (PyCFunction)py_ue_icollection_manager_reparent_collection, METH_VARARGS | METH_CLASS, "" },
{ "rename_collection", (PyCFunction)py_ue_icollection_manager_rename_collection, METH_VARARGS | METH_CLASS, "" },
{ "add_to_collection", (PyCFunction)py_ue_icollection_manager_add_to_collection, METH_VARARGS | METH_CLASS, "" },
{ "collection_exists", (PyCFunction)py_ue_icollection_manager_collection_exists, METH_VARARGS | METH_CLASS, "" },
{ "create_unique_collection_name", (PyCFunction)py_ue_icollection_manager_create_unique_collection_name, METH_VARARGS | METH_CLASS, "" },
{ "destroy_collection", (PyCFunction)py_ue_icollection_manager_destroy_collection, METH_VARARGS | METH_CLASS, "" },
{ "empty_collection", (PyCFunction)py_ue_icollection_manager_empty_collection, METH_VARARGS | METH_CLASS, "" },
{ "get_dynamic_query_text", (PyCFunction)py_ue_icollection_manager_get_dynamic_query_text, METH_VARARGS | METH_CLASS, "" },
{ "set_dynamic_query_text", (PyCFunction)py_ue_icollection_manager_set_dynamic_query_text, METH_VARARGS | METH_CLASS, "" },
{ "remove_from_collection", (PyCFunction)py_ue_icollection_manager_remove_from_collection, METH_VARARGS | METH_CLASS, "" },
{ "get_assets_in_collection", (PyCFunction)py_ue_icollection_manager_get_assets_in_collection, METH_VARARGS | METH_CLASS, "" },
{ "get_objects_in_collection", (PyCFunction)py_ue_icollection_manager_get_objects_in_collection, METH_VARARGS | METH_CLASS, "" },
{ "get_classes_in_collection", (PyCFunction)py_ue_icollection_manager_get_classes_in_collection, METH_VARARGS | METH_CLASS, "" },
{ "get_parent_collection", (PyCFunction)py_ue_icollection_manager_get_parent_collection, METH_VARARGS | METH_CLASS, "" },
{ "has_collections", (PyCFunction)py_ue_icollection_manager_has_collections, METH_VARARGS | METH_CLASS, "" },
{ NULL } /* Sentinel */
};
static PyTypeObject ue_PyICollectionManagerType = {
PyVarObject_HEAD_INIT(NULL, 0)
"unreal_engine.ICollectionManager", /* tp_name */
sizeof(ue_PyICollectionManager), /* tp_basicsize */
0, /* tp_itemsize */
0, /* tp_dealloc */
0, /* tp_print */
0, /* tp_getattr */
0, /* tp_setattr */
0, /* tp_reserved */
0, /* tp_repr */
0, /* tp_as_number */
0, /* tp_as_sequence */
0, /* tp_as_mapping */
0, /* tp_hash */
0, /* tp_call */
0, /* tp_str */
0, /* tp_getattro */
0, /* tp_setattro */
0, /* tp_as_buffer */
Py_TPFLAGS_DEFAULT, /* tp_flags */
"Unreal Engine CollectionManager Interface", /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
0, /* tp_richcompare */
0, /* tp_weaklistoffset */
0, /* tp_iter */
0, /* tp_iternext */
ue_PyICollectionManager_methods, /* tp_methods */
0,
0,
};
static int py_ue_icollection_manager_init(ue_PyICollectionManager *self, PyObject * args)
{
PyErr_SetString(PyExc_Exception, "ICollectionManager is a singleton");
return -1;
}
void ue_python_init_icollection_manager(PyObject *ue_module)
{
ue_PyICollectionManagerType.tp_new = PyType_GenericNew;
ue_PyICollectionManagerType.tp_init = (initproc)py_ue_icollection_manager_init;
if (PyType_Ready(&ue_PyICollectionManagerType) < 0)
return;
Py_INCREF(&ue_PyICollectionManagerType);
PyModule_AddObject(ue_module, "ICollectionManager", (PyObject *)&ue_PyICollectionManagerType);
}
#endif
```
|
/content/code_sandbox/Source/UnrealEnginePython/Private/CollectionManager/UEPyICollectionManager.cpp
|
c++
| 2016-08-07T05:00:51
| 2024-08-14T06:32:20
|
UnrealEnginePython
|
20tab/UnrealEnginePython
| 2,715
| 4,455
|
```objective-c
#pragma once
#if WITH_EDITOR
#include "UnrealEnginePython.h"
#include "Developer/CollectionManager/Public/ICollectionManager.h"
typedef struct
{
PyObject_HEAD
/* Type-specific fields go here. */
} ue_PyICollectionManager;
void ue_python_init_icollection_manager(PyObject *);
#endif
```
|
/content/code_sandbox/Source/UnrealEnginePython/Private/CollectionManager/UEPyICollectionManager.h
|
objective-c
| 2016-08-07T05:00:51
| 2024-08-14T06:32:20
|
UnrealEnginePython
|
20tab/UnrealEnginePython
| 2,715
| 63
|
```c++
#include "UEPyIVoiceCapture.h"
PyObject *py_ue_ivoice_capture_start(ue_PyIVoiceCapture *self, PyObject * args)
{
self->voice_capture->Start();
Py_RETURN_NONE;
}
PyObject *py_ue_ivoice_capture_stop(ue_PyIVoiceCapture *self, PyObject * args)
{
self->voice_capture->Stop();
Py_RETURN_NONE;
}
PyObject *py_ue_ivoice_capture_shutdown(ue_PyIVoiceCapture *self, PyObject * args)
{
self->voice_capture->Shutdown();
Py_RETURN_NONE;
}
PyObject *py_ue_ivoice_capture_init_method(ue_PyIVoiceCapture *self, PyObject * args)
{
int sample_rate;
int channels;
char *name = (char *)"";
if (!PyArg_ParseTuple(args, "ii|s", &sample_rate, &channels, &name))
{
return nullptr;
}
#if ENGINE_MINOR_VERSION < 18
if (self->voice_capture->Init(sample_rate, channels))
#else
if (self->voice_capture->Init(UTF8_TO_TCHAR(name), sample_rate, channels))
#endif
{
Py_RETURN_TRUE;
}
Py_RETURN_FALSE;
}
PyObject *py_ue_ivoice_capture_is_capturing(ue_PyIVoiceCapture *self, PyObject * args)
{
if (self->voice_capture->IsCapturing())
{
Py_RETURN_TRUE;
}
Py_RETURN_FALSE;
}
PyObject *py_ue_ivoice_capture_get_capture_state(ue_PyIVoiceCapture *self, PyObject * args)
{
uint32 available_data;
EVoiceCaptureState::Type state = self->voice_capture->GetCaptureState(available_data);
return Py_BuildValue("ii", (int)state, available_data);
}
PyObject *py_ue_ivoice_capture_get_voice_data(ue_PyIVoiceCapture *self, PyObject * args)
{
int len;
if (!PyArg_ParseTuple(args, "i", &len))
{
return nullptr;
}
uint32 available_data = 0;
uint8 *data = (uint8*)FMemory_Alloca(len);
EVoiceCaptureState::Type state = self->voice_capture->GetVoiceData(data, len, available_data);
return Py_BuildValue("iO", (int)state, PyByteArray_FromStringAndSize((char *)data, (Py_ssize_t)FMath::Min(available_data, (uint32)len)));
}
static PyMethodDef ue_PyIVoiceCapture_methods[] = {
{ "start", (PyCFunction)py_ue_ivoice_capture_start, METH_VARARGS, "" },
{ "stop", (PyCFunction)py_ue_ivoice_capture_stop, METH_VARARGS, "" },
{ "shutdown", (PyCFunction)py_ue_ivoice_capture_shutdown, METH_VARARGS, "" },
{ "init", (PyCFunction)py_ue_ivoice_capture_init_method, METH_VARARGS, "" },
{ "is_capturing", (PyCFunction)py_ue_ivoice_capture_is_capturing, METH_VARARGS, "" },
{ "get_capture_state", (PyCFunction)py_ue_ivoice_capture_get_capture_state, METH_VARARGS, "" },
{ "get_voice_data", (PyCFunction)py_ue_ivoice_capture_get_voice_data, METH_VARARGS, "" },
{ NULL } /* Sentinel */
};
static PyTypeObject ue_PyIVoiceCaptureType = {
PyVarObject_HEAD_INIT(NULL, 0)
"unreal_engine.IVoiceCapture", /* tp_name */
sizeof(ue_PyIVoiceCapture), /* tp_basicsize */
0, /* tp_itemsize */
0, /* tp_dealloc */
0, /* tp_print */
0, /* tp_getattr */
0, /* tp_setattr */
0, /* tp_reserved */
0, /* tp_repr */
0, /* tp_as_number */
0, /* tp_as_sequence */
0, /* tp_as_mapping */
0, /* tp_hash */
0, /* tp_call */
0, /* tp_str */
0, /* tp_getattro */
0, /* tp_setattro */
0, /* tp_as_buffer */
Py_TPFLAGS_DEFAULT, /* tp_flags */
"Unreal Engine VoiceCapture Interface", /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
0, /* tp_richcompare */
0, /* tp_weaklistoffset */
0, /* tp_iter */
0, /* tp_iternext */
ue_PyIVoiceCapture_methods, /* tp_methods */
0,
0,
};
static int py_ue_ivoice_capture_init(ue_PyIVoiceCapture *self, PyObject * args)
{
TSharedPtr<IVoiceCapture> voice_capture_ptr = FVoiceModule::Get().CreateVoiceCapture();
if (!voice_capture_ptr.IsValid())
{
PyErr_SetString(PyExc_Exception, "unable to create a new VoiceCapture");
return -1;
}
new(&self->voice_capture) TSharedRef<IVoiceCapture>(voice_capture_ptr.ToSharedRef());
return 0;
}
void ue_python_init_ivoice_capture(PyObject *ue_module)
{
ue_PyIVoiceCaptureType.tp_new = PyType_GenericNew;
ue_PyIVoiceCaptureType.tp_init = (initproc)py_ue_ivoice_capture_init;
if (PyType_Ready(&ue_PyIVoiceCaptureType) < 0)
return;
Py_INCREF(&ue_PyIVoiceCaptureType);
PyModule_AddObject(ue_module, "IVoiceCapture", (PyObject *)&ue_PyIVoiceCaptureType);
}
```
|
/content/code_sandbox/Source/UnrealEnginePython/Private/Voice/UEPyIVoiceCapture.cpp
|
c++
| 2016-08-07T05:00:51
| 2024-08-14T06:32:20
|
UnrealEnginePython
|
20tab/UnrealEnginePython
| 2,715
| 1,225
|
```objective-c
#pragma once
#include "UnrealEnginePython.h"
#include "Runtime/Online/Voice/Public/VoiceModule.h"
#include "Runtime/Online/Voice/Public/Interfaces/VoiceCapture.h"
typedef struct {
PyObject_HEAD
/* Type-specific fields go here. */
TSharedRef<IVoiceCapture> voice_capture;
} ue_PyIVoiceCapture;
void ue_python_init_ivoice_capture(PyObject *);
```
|
/content/code_sandbox/Source/UnrealEnginePython/Private/Voice/UEPyIVoiceCapture.h
|
objective-c
| 2016-08-07T05:00:51
| 2024-08-14T06:32:20
|
UnrealEnginePython
|
20tab/UnrealEnginePython
| 2,715
| 85
|
```objective-c
#pragma once
#include "UEPyModule.h"
#include "EngineUtils.h"
#include "Runtime/LevelSequence/Public/LevelSequenceActor.h"
#include "Runtime/LevelSequence/Public/LevelSequence.h"
#include "PythonComponent.h"
#include "Kismet/GameplayStatics.h"
#include "Wrappers/UEPyFVector.h"
#include "Wrappers/UEPyFRotator.h"
#include "UObject/UEPyObject.h"
#include "UObject/UObjectThreadContext.h"
PyObject *py_ue_actor_has_tag(ue_PyUObject *, PyObject *);
PyObject *py_ue_component_has_tag(ue_PyUObject *, PyObject *);
PyObject *py_ue_actor_begin_play(ue_PyUObject *, PyObject *);
PyObject *py_ue_get_actor_bounds(ue_PyUObject *, PyObject *);
PyObject *py_ue_get_actor_component(ue_PyUObject *, PyObject *);
PyObject *py_ue_actor_destroy(ue_PyUObject *, PyObject *);
PyObject *py_ue_actor_components(ue_PyUObject *, PyObject *);
PyObject *py_ue_get_actor_velocity(ue_PyUObject *, PyObject *);
PyObject *py_ue_actor_set_level_sequence(ue_PyUObject *, PyObject *);
#if WITH_EDITOR
PyObject *py_ue_get_actor_label(ue_PyUObject *, PyObject *);
PyObject *py_ue_set_actor_label(ue_PyUObject *, PyObject *);
PyObject *py_ue_get_folder_path(ue_PyUObject *, PyObject *);
PyObject *py_ue_set_folder_path(ue_PyUObject *, PyObject *);
PyObject *py_ue_set_actor_hidden_in_game(ue_PyUObject *, PyObject *);
PyObject *py_ue_find_actor_by_label(ue_PyUObject *, PyObject *);
PyObject *py_ue_get_editor_world_counterpart_actor(ue_PyUObject *, PyObject *);
PyObject *py_ue_component_type_registry_invalidate_class(ue_PyUObject *, PyObject *);
#endif
PyObject *py_ue_get_owner(ue_PyUObject *, PyObject *);
PyObject *py_ue_add_actor_component(ue_PyUObject *, PyObject *);
PyObject *py_ue_add_python_component(ue_PyUObject *, PyObject *);
PyObject *py_ue_get_actor_root_component(ue_PyUObject *, PyObject *);
PyObject *py_ue_add_actor_root_component(ue_PyUObject *, PyObject *);
PyObject *py_ue_actor_has_component_of_type(ue_PyUObject *, PyObject *);
PyObject *py_ue_get_actor_component_by_type(ue_PyUObject *, PyObject *);
PyObject *py_ue_get_actor_components_by_type(ue_PyUObject *, PyObject *);
PyObject *py_ue_get_actor_components_by_tag(ue_PyUObject *, PyObject *);
PyObject *py_ue_actor_spawn(ue_PyUObject * self, PyObject *, PyObject *);
PyObject *py_ue_get_overlapping_actors(ue_PyUObject *, PyObject *);
PyObject *py_ue_actor_destroy_component(ue_PyUObject *, PyObject *);
PyObject *py_ue_register_component(ue_PyUObject * self, PyObject *);
PyObject *py_ue_unregister_component(ue_PyUObject * self, PyObject *);
PyObject *py_ue_destroy_component(ue_PyUObject * self, PyObject *);
PyObject *py_ue_component_is_registered(ue_PyUObject * self, PyObject *);
PyObject *py_ue_actor_create_default_subobject(ue_PyUObject * self, PyObject *);
PyObject *py_ue_add_instance_component(ue_PyUObject * self, PyObject *);
```
|
/content/code_sandbox/Source/UnrealEnginePython/Private/UObject/UEPyActor.h
|
objective-c
| 2016-08-07T05:00:51
| 2024-08-14T06:32:20
|
UnrealEnginePython
|
20tab/UnrealEnginePython
| 2,715
| 699
|
```c++
#include "UEPyAudio.h"
#include "Sound/SoundWaveProcedural.h"
#include "Kismet/GameplayStatics.h"
PyObject *py_ue_queue_audio(ue_PyUObject *self, PyObject * args)
{
// Writes from a Python buffer object to a USoundWaveProcedural class
ue_py_check(self);
Py_buffer sound_buffer;
if (!PyArg_ParseTuple(args, "y*:queue_audio", &sound_buffer))
{
return NULL;
}
USoundWaveProcedural *sound_wave_procedural = ue_py_check_type<USoundWaveProcedural>(self);
if (!sound_wave_procedural)
{
// Clean up
PyBuffer_Release(&sound_buffer);
return PyErr_Format(PyExc_Exception, "UObject is not a USoundWaveProcedural.");
}
// Convert the buffer
uint8 *buffer = (uint8 *)sound_buffer.buf;
if (buffer == nullptr)
{
// Clean up
PyBuffer_Release(&sound_buffer);
return PyErr_Format(PyExc_Exception, "Invalid sound buffer.");
}
// Add the audio to the Sound Wave's audio buffer
sound_wave_procedural->QueueAudio(buffer, sound_buffer.len);
// Clean up
PyBuffer_Release(&sound_buffer);
Py_RETURN_NONE;
}
PyObject *py_ue_get_available_audio_byte_count(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
USoundWaveProcedural *sound_wave_procedural = ue_py_check_type<USoundWaveProcedural>(self);
if (!sound_wave_procedural)
{
return PyErr_Format(PyExc_Exception, "UObject is not a USoundWaveProcedural.");
}
return PyLong_FromLong(sound_wave_procedural->GetAvailableAudioByteCount());
}
PyObject *py_ue_reset_audio(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
USoundWaveProcedural *sound_wave_procedural = ue_py_check_type<USoundWaveProcedural>(self);
if (!sound_wave_procedural)
{
return PyErr_Format(PyExc_Exception, "UObject is not a USoundWaveProcedural.");
}
sound_wave_procedural->ResetAudio();
Py_RETURN_NONE;
}
PyObject *py_ue_sound_get_data(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
USoundWave *sound = ue_py_check_type<USoundWave>(self);
if (!sound)
return PyErr_Format(PyExc_Exception, "UObject is not a USoundWave.");
FByteBulkData raw_data = sound->RawData;
char *data = (char *)raw_data.Lock(LOCK_READ_ONLY);
int32 data_size = raw_data.GetBulkDataSize();
PyObject *py_data = PyBytes_FromStringAndSize(data, data_size);
raw_data.Unlock();
return py_data;
}
PyObject *py_ue_sound_set_data(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
Py_buffer sound_buffer;
if (!PyArg_ParseTuple(args, "y*:sound_set_data", &sound_buffer))
{
return NULL;
}
USoundWave *sound = ue_py_check_type<USoundWave>(self);
if (!sound)
return PyErr_Format(PyExc_Exception, "UObject is not a USoundWave.");
sound->FreeResources();
sound->InvalidateCompressedData();
sound->RawData.Lock(LOCK_READ_WRITE);
void *data = sound->RawData.Realloc(sound_buffer.len);
FMemory::Memcpy(data, sound_buffer.buf, sound_buffer.len);
sound->RawData.Unlock();
Py_RETURN_NONE;
}
PyObject *py_ue_play_sound_at_location(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
PyObject *sound;
PyObject *py_location;
float volume = 1;
float pitch = 1;
float start = 0;
if (!PyArg_ParseTuple(args, "OO|fff:play_sound_at_location", &sound, &py_location, &volume, &pitch, &start))
{
return NULL;
}
USoundBase *sound_object = nullptr;
if (ue_is_pyuobject(sound))
{
sound_object = ue_py_check_type<USoundBase>(sound);
}
else if (PyUnicodeOrString_Check(sound))
{
sound_object = FindObject<USoundBase>(ANY_PACKAGE, UTF8_TO_TCHAR(UEPyUnicode_AsUTF8(sound)));
}
if (!sound_object)
return PyErr_Format(PyExc_Exception, "invalid sound object");
ue_PyFVector *location = py_ue_is_fvector(py_location);
if (!location)
return PyErr_Format(PyExc_TypeError, "sound location must be a FVector");
UGameplayStatics::PlaySoundAtLocation(self->ue_object, sound_object, location->vec, volume, pitch, start);
Py_RETURN_NONE;
}
```
|
/content/code_sandbox/Source/UnrealEnginePython/Private/UObject/UEPyAudio.cpp
|
c++
| 2016-08-07T05:00:51
| 2024-08-14T06:32:20
|
UnrealEnginePython
|
20tab/UnrealEnginePython
| 2,715
| 1,048
|
```objective-c
#pragma once
#include "UEPyModule.h"
PyObject *py_unreal_engine_get_game_viewport_client(PyObject *, PyObject *);
#if WITH_EDITOR
PyObject *py_unreal_engine_get_editor_pie_game_viewport_client(PyObject *, PyObject *);
PyObject *py_unreal_engine_editor_set_view_mode(PyObject *, PyObject *);
PyObject *py_unreal_engine_editor_set_camera_speed(PyObject *, PyObject *);
PyObject *py_unreal_engine_editor_set_view_location(PyObject *, PyObject *);
PyObject *py_unreal_engine_editor_set_view_rotation(PyObject *, PyObject *);
#endif
PyObject *py_ue_add_viewport_widget_content(ue_PyUObject *, PyObject *);
PyObject *py_ue_remove_viewport_widget_content(ue_PyUObject *, PyObject *);
PyObject *py_ue_remove_all_viewport_widgets(ue_PyUObject *, PyObject *);
PyObject *py_ue_game_viewport_client_set_rendering_flag(ue_PyUObject *, PyObject *);
PyObject *py_ue_game_viewport_client_get_window(ue_PyUObject *, PyObject *);
```
|
/content/code_sandbox/Source/UnrealEnginePython/Private/UObject/UEPyViewport.h
|
objective-c
| 2016-08-07T05:00:51
| 2024-08-14T06:32:20
|
UnrealEnginePython
|
20tab/UnrealEnginePython
| 2,715
| 200
|
```c++
#include "UEPyLandscape.h"
#if WITH_EDITOR
#include "Wrappers/UEPyFRawMesh.h"
#include "Runtime/Landscape/Classes/LandscapeProxy.h"
#include "Runtime/Landscape/Classes/LandscapeInfo.h"
#include "GameFramework/GameModeBase.h"
PyObject* py_ue_create_landscape_info(ue_PyUObject* self, PyObject* args)
{
ue_py_check(self);
ALandscapeProxy* landscape = ue_py_check_type<ALandscapeProxy>(self);
if (!landscape)
return PyErr_Format(PyExc_Exception, "uobject is not a ULandscapeProxy");
Py_RETURN_UOBJECT(landscape->CreateLandscapeInfo());
}
PyObject* py_ue_get_landscape_info(ue_PyUObject* self, PyObject* args)
{
ue_py_check(self);
ALandscapeProxy* landscape = ue_py_check_type<ALandscapeProxy>(self);
if (!landscape)
return PyErr_Format(PyExc_Exception, "uobject is not a ULandscapeProxy");
ULandscapeInfo* info = landscape->GetLandscapeInfo();
if (!info)
Py_RETURN_NONE;
Py_RETURN_UOBJECT(info);
}
PyObject* py_ue_landscape_import(ue_PyUObject* self, PyObject* args)
{
ue_py_check(self);
int section_size;
int sections_per_component;
int component_x;
int component_y;
Py_buffer heightmap_buffer;
int layer_type = (int)ELandscapeImportAlphamapType::Additive;
if (!PyArg_ParseTuple(args, "iiiiy*|i:landscape_import", §ion_size, §ions_per_component, &component_x, &component_y, &heightmap_buffer, &layer_type))
return nullptr;
ALandscapeProxy* landscape = ue_py_check_type<ALandscapeProxy>(self);
if (!landscape)
return PyErr_Format(PyExc_Exception, "uobject is not a ULandscapeProxy");
int quads_per_component = sections_per_component * section_size;
int size_x = component_x * quads_per_component + 1;
int size_y = component_y * quads_per_component + 1;
if (heightmap_buffer.len < (Py_ssize_t)(size_x * size_y * sizeof(uint16)))
return PyErr_Format(PyExc_Exception, "not enough heightmap data, expecting %lu bytes", size_x * size_y * sizeof(uint16));
uint16* data = (uint16*)heightmap_buffer.buf;
TArray<FLandscapeImportLayerInfo> infos;
#if ENGINE_MINOR_VERSION < 23
landscape->Import(FGuid::NewGuid(), 0, 0, size_x - 1, size_y - 1, sections_per_component, section_size, data, nullptr, infos, (ELandscapeImportAlphamapType)layer_type);
#else
TMap<FGuid, TArray<uint16>> HeightDataPerLayers;
TArray<uint16> HeightData;
for (uint32 i = 0; i < (heightmap_buffer.len / sizeof(uint16)); i++)
{
HeightData.Add(data[i]);
}
HeightDataPerLayers.Add(FGuid(), HeightData);
TMap<FGuid, TArray<FLandscapeImportLayerInfo>> MaterialLayersInfo;
MaterialLayersInfo.Add(FGuid(), infos);
landscape->Import(FGuid::NewGuid(), 0, 0, size_x - 1, size_y - 1, sections_per_component, section_size, HeightDataPerLayers, nullptr, MaterialLayersInfo, (ELandscapeImportAlphamapType)layer_type);
#endif
Py_RETURN_NONE;
}
PyObject* py_ue_landscape_export_to_raw_mesh(ue_PyUObject* self, PyObject* args)
{
ue_py_check(self);
int lod = 0;
if (!PyArg_ParseTuple(args, "|i:landscape_import", &lod))
return nullptr;
ALandscapeProxy* landscape = ue_py_check_type<ALandscapeProxy>(self);
if (!landscape)
return PyErr_Format(PyExc_Exception, "uobject is not a ULandscapeProxy");
#if ENGINE_MINOR_VERSION > 21
return PyErr_Format(PyExc_Exception, "MeshDescription struct is still unsupported");;
#else
FRawMesh raw_mesh;
if (!landscape->ExportToRawMesh(lod, raw_mesh))
return PyErr_Format(PyExc_Exception, "unable to export landscape to FRawMesh");
return py_ue_new_fraw_mesh(raw_mesh);
#endif
}
#endif
```
|
/content/code_sandbox/Source/UnrealEnginePython/Private/UObject/UEPyLandscape.cpp
|
c++
| 2016-08-07T05:00:51
| 2024-08-14T06:32:20
|
UnrealEnginePython
|
20tab/UnrealEnginePython
| 2,715
| 914
|
```c++
#include "UEPyPhysics.h"
#if ENGINE_MINOR_VERSION >= 18
#include "Runtime/Engine/Public/DestructibleInterface.h"
#else
#include "Components/DestructibleComponent.h"
#endif
#include "Components/PrimitiveComponent.h"
PyObject *py_ue_set_simulate_physics(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
bool enabled = true;
PyObject *is_true = NULL;
if (!PyArg_ParseTuple(args, "|O:set_simulate_physics", &is_true))
{
return NULL;
}
if (is_true && !PyObject_IsTrue(is_true))
enabled = false;
UPrimitiveComponent *primitive = nullptr;
if (self->ue_object->IsA<UPrimitiveComponent>())
{
primitive = (UPrimitiveComponent *)self->ue_object;
}
else
{
return PyErr_Format(PyExc_Exception, "uobject is not an UPrimitiveComponent");
}
if (!primitive)
{
return PyErr_Format(PyExc_Exception, "unable to set physics for the object");
}
primitive->SetSimulatePhysics(enabled);
Py_INCREF(Py_None);
return Py_None;
}
PyObject *py_ue_add_impulse(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
PyObject *py_obj_impulse = nullptr;
char *bone_name = nullptr;
PyObject *py_obj_b_vel_change = nullptr;
if (!PyArg_ParseTuple(args, "O|sO:add_impulse", &py_obj_impulse, &bone_name, &py_obj_b_vel_change))
{
return nullptr;
}
UPrimitiveComponent *primitive = nullptr;
if (self->ue_object->IsA<UPrimitiveComponent>())
{
primitive = (UPrimitiveComponent *)self->ue_object;
}
else
{
return PyErr_Format(PyExc_Exception, "uobject is not an UPrimitiveComponent");
}
FVector impulse = FVector(0, 0, 0);
if (py_obj_impulse)
{
ue_PyFVector *py_impulse = py_ue_is_fvector(py_obj_impulse);
if (!py_impulse)
return PyErr_Format(PyExc_Exception, "impulse must be a FVector");
impulse = py_impulse->vec;
}
FName f_bone_name = NAME_None;
if (bone_name)
{
f_bone_name = FName(UTF8_TO_TCHAR(bone_name));
}
bool b_vel_change = false;
if (py_obj_b_vel_change && PyObject_IsTrue(py_obj_b_vel_change))
b_vel_change = true;
primitive->AddImpulse(impulse, f_bone_name, b_vel_change);
Py_INCREF(Py_None);
return Py_None;
}
PyObject *py_ue_add_angular_impulse(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
PyObject *py_obj_impulse = nullptr;
char *bone_name = nullptr;
PyObject *py_obj_b_vel_change = nullptr;
if (!PyArg_ParseTuple(args, "O|sO:add_angular_impulse", &py_obj_impulse, &bone_name, &py_obj_b_vel_change))
{
return nullptr;
}
UPrimitiveComponent *primitive = nullptr;
if (self->ue_object->IsA<UPrimitiveComponent>())
{
primitive = (UPrimitiveComponent *)self->ue_object;
}
else
{
return PyErr_Format(PyExc_Exception, "uobject is not an UPrimitiveComponent");
}
FVector impulse = FVector(0, 0, 0);
if (py_obj_impulse)
{
ue_PyFVector *py_impulse = py_ue_is_fvector(py_obj_impulse);
if (!py_impulse)
return PyErr_Format(PyExc_Exception, "impulse must be a FVector");
impulse = py_impulse->vec;
}
FName f_bone_name = NAME_None;
if (bone_name)
{
f_bone_name = FName(UTF8_TO_TCHAR(bone_name));
}
bool b_vel_change = false;
if (py_obj_b_vel_change && PyObject_IsTrue(py_obj_b_vel_change))
b_vel_change = true;
#if ENGINE_MINOR_VERSION >= 18
primitive->AddAngularImpulseInRadians(impulse, f_bone_name, b_vel_change);
#else
primitive->AddAngularImpulse(impulse, f_bone_name, b_vel_change);
#endif
Py_RETURN_NONE;
}
PyObject *py_ue_add_force(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
PyObject *py_obj_force = nullptr;
char *bone_name = nullptr;
PyObject *py_obj_b_accel_change = nullptr;
if (!PyArg_ParseTuple(args, "O|sO:add_force", &py_obj_force, &bone_name, &py_obj_b_accel_change))
{
return nullptr;
}
UPrimitiveComponent *primitive = nullptr;
if (self->ue_object->IsA<UPrimitiveComponent>())
{
primitive = (UPrimitiveComponent *)self->ue_object;
}
else
{
return PyErr_Format(PyExc_Exception, "uobject is not an UPrimitiveComponent");
}
FVector force = FVector(0, 0, 0);
if (py_obj_force)
{
ue_PyFVector *py_force = py_ue_is_fvector(py_obj_force);
if (!py_force)
return PyErr_Format(PyExc_Exception, "force must be a FVector");
force = py_force->vec;
}
FName f_bone_name = NAME_None;
if (bone_name)
{
f_bone_name = FName(UTF8_TO_TCHAR(bone_name));
}
bool b_accel_change = false;
if (py_obj_b_accel_change && PyObject_IsTrue(py_obj_b_accel_change))
b_accel_change = true;
primitive->AddForce(force, f_bone_name, b_accel_change);
Py_INCREF(Py_None);
return Py_None;
}
PyObject *py_ue_add_torque(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
PyObject *py_obj_torque = nullptr;
char *bone_name = nullptr;
PyObject *py_obj_b_accel_change = nullptr;
if (!PyArg_ParseTuple(args, "O|sO:add_torque", &py_obj_torque, &bone_name, &py_obj_b_accel_change))
{
return nullptr;
}
UPrimitiveComponent *primitive = nullptr;
if (self->ue_object->IsA<UPrimitiveComponent>())
{
primitive = (UPrimitiveComponent *)self->ue_object;
}
else
{
return PyErr_Format(PyExc_Exception, "uobject is not an UPrimitiveComponent");
}
FVector torque = FVector(0, 0, 0);
if (py_obj_torque)
{
ue_PyFVector *py_torque = py_ue_is_fvector(py_obj_torque);
if (!py_torque)
return PyErr_Format(PyExc_Exception, "torque must be a FVector");
torque = py_torque->vec;
}
FName f_bone_name = NAME_None;
if (bone_name)
{
f_bone_name = FName(UTF8_TO_TCHAR(bone_name));
}
bool b_accel_change = false;
if (py_obj_b_accel_change && PyObject_IsTrue(py_obj_b_accel_change))
b_accel_change = true;
#if ENGINE_MINOR_VERSION >= 18
primitive->AddTorqueInRadians(torque, f_bone_name, b_accel_change);
#else
primitive->AddTorque(torque, f_bone_name, b_accel_change);
#endif
Py_RETURN_NONE;
}
PyObject *py_ue_set_physics_linear_velocity(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
UPrimitiveComponent *primitive = nullptr;
if (self->ue_object->IsA<UPrimitiveComponent>())
{
primitive = (UPrimitiveComponent *)self->ue_object;
}
else
{
return PyErr_Format(PyExc_Exception, "uobject is not an UPrimitiveComponent");
}
PyObject *py_obj_new_vel = nullptr;
PyObject *is_add_to_current = NULL;
char *bone_name = nullptr;
if (!PyArg_ParseTuple(args, "O|Os:set_physics_linear_velocity", &py_obj_new_vel, &is_add_to_current, &bone_name))
{
return nullptr;
}
FVector new_vel = FVector(0, 0, 0);
if (py_obj_new_vel)
{
ue_PyFVector *py_new_vel = py_ue_is_fvector(py_obj_new_vel);
if (!py_new_vel)
return PyErr_Format(PyExc_Exception, "torque must be a FVector");
new_vel = py_new_vel->vec;
}
bool add_to_current = false;
if (is_add_to_current && PyObject_IsTrue(is_add_to_current))
add_to_current = true;
FName f_bone_name = NAME_None;
if (bone_name)
{
f_bone_name = FName(UTF8_TO_TCHAR(bone_name));
}
primitive->SetPhysicsLinearVelocity(new_vel, add_to_current, f_bone_name);
Py_INCREF(Py_None);
return Py_None;
}
PyObject *py_ue_get_physics_linear_velocity(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
UPrimitiveComponent *primitive = nullptr;
if (self->ue_object->IsA<UPrimitiveComponent>())
{
primitive = (UPrimitiveComponent *)self->ue_object;
}
else
{
return PyErr_Format(PyExc_Exception, "uobject is not an UPrimitiveComponent");
}
char *bone_name = nullptr;
if (!PyArg_ParseTuple(args, "|s:get_physics_linear_velocity", &bone_name))
{
return nullptr;
}
FName f_bone_name = NAME_None;
if (bone_name)
{
f_bone_name = FName(UTF8_TO_TCHAR(bone_name));
}
return py_ue_new_fvector(primitive->GetPhysicsLinearVelocity(f_bone_name));
}
PyObject *py_ue_set_physics_angular_velocity(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
UPrimitiveComponent *primitive = nullptr;
if (self->ue_object->IsA<UPrimitiveComponent>())
{
primitive = (UPrimitiveComponent *)self->ue_object;
}
else
{
return PyErr_Format(PyExc_Exception, "uobject is not an UPrimitiveComponent");
}
PyObject *py_obj_new_ang_vel = nullptr;
PyObject *is_add_to_current = NULL;
char *bone_name = nullptr;
if (!PyArg_ParseTuple(args, "O|Os:set_physics_angular_velocity", &py_obj_new_ang_vel, &is_add_to_current, &bone_name))
{
return nullptr;
}
FVector new_ang_vel = FVector(0, 0, 0);
if (py_obj_new_ang_vel)
{
ue_PyFVector *py_new_ang_vel = py_ue_is_fvector(py_obj_new_ang_vel);
if (!py_new_ang_vel)
return PyErr_Format(PyExc_Exception, "torque must be a FVector");
new_ang_vel = py_new_ang_vel->vec;
}
bool add_to_current = false;
if (is_add_to_current && PyObject_IsTrue(is_add_to_current))
add_to_current = true;
FName f_bone_name = NAME_None;
if (bone_name)
{
f_bone_name = FName(UTF8_TO_TCHAR(bone_name));
}
#if ENGINE_MINOR_VERSION >= 18
primitive->SetPhysicsAngularVelocityInDegrees(new_ang_vel, add_to_current, f_bone_name);
#else
primitive->SetPhysicsAngularVelocity(new_ang_vel, add_to_current, f_bone_name);
#endif
Py_RETURN_NONE;
}
PyObject *py_ue_get_physics_angular_velocity(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
UPrimitiveComponent *primitive = nullptr;
if (self->ue_object->IsA<UPrimitiveComponent>())
{
primitive = (UPrimitiveComponent *)self->ue_object;
}
else
{
return PyErr_Format(PyExc_Exception, "uobject is not an UPrimitiveComponent");
}
char *bone_name = nullptr;
if (!PyArg_ParseTuple(args, "|s:get_physics_angular_velocity", &bone_name))
{
return nullptr;
}
FName f_bone_name = NAME_None;
if (bone_name)
{
f_bone_name = FName(UTF8_TO_TCHAR(bone_name));
}
#if ENGINE_MINOR_VERSION >= 18
return py_ue_new_fvector(primitive->GetPhysicsAngularVelocityInDegrees(f_bone_name));
#else
return py_ue_new_fvector(primitive->GetPhysicsAngularVelocity(f_bone_name));
#endif
}
PyObject *py_ue_destructible_apply_damage(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
float damage_amount = 0;
float impulse_strength = 0;
PyObject *py_obj_location = nullptr;
PyObject *py_obj_impulse = nullptr;
if (!PyArg_ParseTuple(args, "ffOO:destructible_apply_damage", &damage_amount, &impulse_strength, &py_obj_location, &py_obj_impulse))
{
return NULL;
}
#if ENGINE_MINOR_VERSION < 18
UDestructibleComponent *destructible = ue_py_check_type<UDestructibleComponent>(self);
#else
IDestructibleInterface *destructible = ue_py_check_type<IDestructibleInterface>(self);
#endif
if (!destructible)
{
AActor *actor = ue_py_check_type<AActor>(self);
if (actor)
{
#if ENGINE_MINOR_VERSION < 18
destructible = (UDestructibleComponent *)actor->GetComponentByClass(UDestructibleComponent::StaticClass());
#else
for (UActorComponent *component : actor->GetComponents())
{
if (Cast<IDestructibleInterface>(component))
{
destructible = (IDestructibleInterface *)component;
break;
}
}
#endif
}
else
{
UActorComponent *component = ue_py_check_type<UActorComponent>(self);
if (component)
{
actor = (AActor *)component->GetOuter();
#if ENGINE_MINOR_VERSION < 18
destructible = (UDestructibleComponent *)actor->GetComponentByClass(UDestructibleComponent::StaticClass());
#else
for (UActorComponent *checked_component : actor->GetComponents())
{
if (Cast<IDestructibleInterface>(checked_component))
{
destructible = (IDestructibleInterface *)checked_component;
break;
}
}
#endif
}
}
}
FVector location = FVector(0, 0, 0);
FVector impulse = FVector(0, 0, 0);
if (py_obj_location)
{
ue_PyFVector *py_location = py_ue_is_fvector(py_obj_location);
if (!py_location)
return PyErr_Format(PyExc_Exception, "location must be a FVector");
location = py_location->vec;
}
if (py_obj_impulse)
{
ue_PyFVector *py_impulse = py_ue_is_fvector(py_obj_impulse);
if (!py_impulse)
return PyErr_Format(PyExc_Exception, "impulse must be a FVector");
impulse = py_impulse->vec;
}
if (destructible)
{
destructible->ApplyDamage(damage_amount, location, impulse, impulse_strength);
}
else
{
return PyErr_Format(PyExc_Exception, "UObject is not a destructible");
}
Py_RETURN_NONE;
}
```
|
/content/code_sandbox/Source/UnrealEnginePython/Private/UObject/UEPyPhysics.cpp
|
c++
| 2016-08-07T05:00:51
| 2024-08-14T06:32:20
|
UnrealEnginePython
|
20tab/UnrealEnginePython
| 2,715
| 3,419
|
```c++
#include "UEPyStaticMesh.h"
#include "Engine/StaticMesh.h"
PyObject *py_ue_static_mesh_get_bounds(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
UStaticMesh *mesh = ue_py_check_type<UStaticMesh>(self);
if (!mesh)
return PyErr_Format(PyExc_Exception, "uobject is not a UStaticMesh");
FBoxSphereBounds bounds = mesh->GetBounds();
UScriptStruct *u_struct = FindObject<UScriptStruct>(ANY_PACKAGE, UTF8_TO_TCHAR("BoxSphereBounds"));
if (!u_struct)
{
return PyErr_Format(PyExc_Exception, "unable to get BoxSphereBounds struct");
}
return py_ue_new_owned_uscriptstruct(u_struct, (uint8 *)&bounds);
}
#if WITH_EDITOR
#include "Wrappers/UEPyFRawMesh.h"
#include "Editor/UnrealEd/Private/GeomFitUtils.h"
#include "FbxMeshUtils.h"
static PyObject *generate_kdop(ue_PyUObject *self, const FVector *directions, uint32 num_directions)
{
UStaticMesh *mesh = ue_py_check_type<UStaticMesh>(self);
if (!mesh)
return PyErr_Format(PyExc_Exception, "uobject is not a UStaticMesh");
TArray<FVector> DirArray;
for (uint32 i = 0; i < num_directions; i++)
{
DirArray.Add(directions[i]);
}
if (GenerateKDopAsSimpleCollision(mesh, DirArray) == INDEX_NONE)
{
return PyErr_Format(PyExc_Exception, "unable to generate KDop vectors");
}
PyObject *py_list = PyList_New(0);
for (FVector v : DirArray)
{
PyList_Append(py_list, py_ue_new_fvector(v));
}
return py_list;
}
PyObject *py_ue_static_mesh_generate_kdop10x(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
return generate_kdop(self, KDopDir10X, 10);
}
PyObject *py_ue_static_mesh_generate_kdop10y(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
return generate_kdop(self, KDopDir10Y, 10);
}
PyObject *py_ue_static_mesh_generate_kdop10z(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
return generate_kdop(self, KDopDir10Z, 10);
}
PyObject *py_ue_static_mesh_generate_kdop18(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
return generate_kdop(self, KDopDir18, 18);
}
PyObject *py_ue_static_mesh_generate_kdop26(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
return generate_kdop(self, KDopDir26, 26);
}
PyObject *py_ue_static_mesh_build(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
UStaticMesh *mesh = ue_py_check_type<UStaticMesh>(self);
if (!mesh)
return PyErr_Format(PyExc_Exception, "uobject is not a UStaticMesh");
#if ENGINE_MINOR_VERSION > 13
mesh->ImportVersion = EImportStaticMeshVersion::LastVersion;
#endif
mesh->Build();
Py_RETURN_NONE;
}
PyObject *py_ue_static_mesh_create_body_setup(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
UStaticMesh *mesh = ue_py_check_type<UStaticMesh>(self);
if (!mesh)
return PyErr_Format(PyExc_Exception, "uobject is not a UStaticMesh");
mesh->CreateBodySetup();
Py_RETURN_NONE;
}
PyObject *py_ue_static_mesh_get_raw_mesh(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
int lod_index = 0;
if (!PyArg_ParseTuple(args, "|i:get_raw_mesh", &lod_index))
return nullptr;
UStaticMesh *mesh = ue_py_check_type<UStaticMesh>(self);
if (!mesh)
return PyErr_Format(PyExc_Exception, "uobject is not a UStaticMesh");
FRawMesh raw_mesh;
if (lod_index < 0 || lod_index >= mesh->SourceModels.Num())
return PyErr_Format(PyExc_Exception, "invalid LOD index");
mesh->SourceModels[lod_index].RawMeshBulkData->LoadRawMesh(raw_mesh);
return py_ue_new_fraw_mesh(raw_mesh);
}
PyObject *py_ue_static_mesh_import_lod(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
char *filename;
int lod_level;
if (!PyArg_ParseTuple(args, "si:static_mesh_import_lod", &filename, &lod_level))
return nullptr;
UStaticMesh *mesh = ue_py_check_type<UStaticMesh>(self);
if (!mesh)
return PyErr_Format(PyExc_Exception, "uobject is not a UStaticMesh");
if (FbxMeshUtils::ImportStaticMeshLOD(mesh, FString(UTF8_TO_TCHAR(filename)), lod_level))
{
Py_RETURN_TRUE;
}
Py_RETURN_FALSE;
}
#endif
```
|
/content/code_sandbox/Source/UnrealEnginePython/Private/UObject/UEPyStaticMesh.cpp
|
c++
| 2016-08-07T05:00:51
| 2024-08-14T06:32:20
|
UnrealEnginePython
|
20tab/UnrealEnginePython
| 2,715
| 1,120
|
```c++
#include "UEPyWidget.h"
#include "Runtime/UMG/Public/Components/Widget.h"
#include "Slate/UEPySWidget.h"
PyObject *py_ue_take_widget(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
UWidget *widget = ue_py_check_type<UWidget>(self);
if (!widget)
return PyErr_Format(PyExc_Exception, "uobject is not a UWidget");
ue_PySWidget *s_widget = ue_py_get_swidget(widget->TakeWidget());
return (PyObject *)s_widget;
}
PyObject *py_ue_create_widget(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
PyObject *py_class;
if (!PyArg_ParseTuple(args, "O", &py_class))
return nullptr;
APlayerController *player = ue_py_check_type<APlayerController>(self);
if (!player)
return PyErr_Format(PyExc_Exception, "uobject is not a APlayerController");
UClass *u_class = ue_py_check_type<UClass>(py_class);
if (!u_class)
return PyErr_Format(PyExc_Exception, "argument is not a UClass");
if (!u_class->IsChildOf<UUserWidget>())
return PyErr_Format(PyExc_Exception, "argument is not a child of UUserWidget");
UUserWidget *widget = CreateWidget<UUserWidget>(player, u_class);
if (!widget)
return PyErr_Format(PyExc_Exception, "unable to create new widget");
Py_RETURN_UOBJECT(widget);
}
```
|
/content/code_sandbox/Source/UnrealEnginePython/Private/UObject/UEPyWidget.cpp
|
c++
| 2016-08-07T05:00:51
| 2024-08-14T06:32:20
|
UnrealEnginePython
|
20tab/UnrealEnginePython
| 2,715
| 320
|
```objective-c
#pragma once
#include "UEPyModule.h"
PyObject *py_ue_package_is_dirty(ue_PyUObject *, PyObject *);
PyObject *py_ue_package_get_filename(ue_PyUObject *, PyObject *);
PyObject *py_ue_package_make_unique_object_name(ue_PyUObject *, PyObject *);
```
|
/content/code_sandbox/Source/UnrealEnginePython/Private/UObject/UEPyPackage.h
|
objective-c
| 2016-08-07T05:00:51
| 2024-08-14T06:32:20
|
UnrealEnginePython
|
20tab/UnrealEnginePython
| 2,715
| 61
|
```objective-c
#pragma once
#include "UEPyModule.h"
PyObject *py_ue_set_slate_widget(ue_PyUObject *, PyObject *);
```
|
/content/code_sandbox/Source/UnrealEnginePython/Private/UObject/UEPyWidgetComponent.h
|
objective-c
| 2016-08-07T05:00:51
| 2024-08-14T06:32:20
|
UnrealEnginePython
|
20tab/UnrealEnginePython
| 2,715
| 29
|
```c++
#include "UEPySpline.h"
#include "Components/SplineComponent.h"
PyObject *py_ue_get_spline_length(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
USplineComponent *spline = nullptr;
if (self->ue_object->IsA<USplineComponent>())
{
spline = (USplineComponent *)self->ue_object;
}
else
{
return PyErr_Format(PyExc_Exception, "uobject is not a USplineComponent");
}
if (!spline)
{
return PyErr_Format(PyExc_Exception, "unable to get spline object");
}
return PyFloat_FromDouble(spline->GetSplineLength());
}
PyObject *py_ue_get_world_location_at_distance_along_spline(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
float distance = 0;
if (!PyArg_ParseTuple(args, "f:get_world_location_at_distance_along_spline", &distance))
{
return NULL;
}
USplineComponent *spline = nullptr;
if (self->ue_object->IsA<USplineComponent>())
{
spline = (USplineComponent *)self->ue_object;
}
else
{
return PyErr_Format(PyExc_Exception, "uobject is not a USplineComponent");
}
if (!spline)
{
return PyErr_Format(PyExc_Exception, "unable to get spline object");
}
FVector location = spline->GetWorldLocationAtDistanceAlongSpline(distance);
return py_ue_new_fvector(location);
}
```
|
/content/code_sandbox/Source/UnrealEnginePython/Private/UObject/UEPySpline.cpp
|
c++
| 2016-08-07T05:00:51
| 2024-08-14T06:32:20
|
UnrealEnginePython
|
20tab/UnrealEnginePython
| 2,715
| 334
|
```c++
#include "UEPyObject.h"
#include "PythonDelegate.h"
#include "PythonFunction.h"
#include "Components/ActorComponent.h"
#include "Engine/UserDefinedEnum.h"
#if WITH_EDITOR
#include "Runtime/AssetRegistry/Public/AssetRegistryModule.h"
#include "ObjectTools.h"
#include "UnrealEd.h"
#include "Runtime/Core/Public/HAL/FeedbackContextAnsi.h"
#include "Wrappers/UEPyFObjectThumbnail.h"
#endif
#include "Runtime/Core/Public/Misc/OutputDeviceNull.h"
#include "Runtime/CoreUObject/Public/Serialization/ObjectWriter.h"
#include "Runtime/CoreUObject/Public/Serialization/ObjectReader.h"
PyObject *py_ue_get_class(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
Py_RETURN_UOBJECT(self->ue_object->GetClass());
}
PyObject *py_ue_class_generated_by(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
UClass *u_class = ue_py_check_type<UClass>(self);
if (!u_class)
return PyErr_Format(PyExc_Exception, "uobject is a not a UClass");
UObject *u_object = u_class->ClassGeneratedBy;
if (!u_object)
Py_RETURN_NONE;
Py_RETURN_UOBJECT(u_object);
}
PyObject *py_ue_class_get_flags(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
UClass *u_class = ue_py_check_type<UClass>(self);
if (!u_class)
return PyErr_Format(PyExc_Exception, "uobject is a not a UClass");
return PyLong_FromUnsignedLongLong((uint64)u_class->GetClassFlags());
}
PyObject *py_ue_class_set_flags(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
uint64 flags;
if (!PyArg_ParseTuple(args, "K:class_set_flags", &flags))
{
return nullptr;
}
UClass *u_class = ue_py_check_type<UClass>(self);
if (!u_class)
return PyErr_Format(PyExc_Exception, "uobject is a not a UClass");
u_class->ClassFlags = (EClassFlags)flags;
Py_RETURN_NONE;
}
PyObject *py_ue_get_obj_flags(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
return PyLong_FromUnsignedLongLong((uint64)self->ue_object->GetFlags());
}
PyObject *py_ue_set_obj_flags(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
uint64 flags;
PyObject *py_reset = nullptr;
if (!PyArg_ParseTuple(args, "K|O:set_obj_flags", &flags, &py_reset))
{
return nullptr;
}
if (py_reset && PyObject_IsTrue(py_reset))
{
self->ue_object->ClearFlags(self->ue_object->GetFlags());
}
self->ue_object->SetFlags((EObjectFlags)flags);
Py_RETURN_NONE;
}
PyObject *py_ue_clear_obj_flags(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
uint64 flags;
if (!PyArg_ParseTuple(args, "K:clear_obj_flags", &flags))
{
return nullptr;
}
self->ue_object->ClearFlags((EObjectFlags)flags);
Py_RETURN_NONE;
}
PyObject *py_ue_reset_obj_flags(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
self->ue_object->ClearFlags(self->ue_object->GetFlags());
Py_RETURN_NONE;
}
#if WITH_EDITOR
PyObject *py_ue_class_set_config_name(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
char *config_name;
if (!PyArg_ParseTuple(args, "s:class_set_config_name", &config_name))
{
return nullptr;
}
UClass *u_class = ue_py_check_type<UClass>(self);
if (!u_class)
return PyErr_Format(PyExc_Exception, "uobject is a not a UClass");
u_class->ClassConfigName = UTF8_TO_TCHAR(config_name);
Py_RETURN_NONE;
}
PyObject *py_ue_class_get_config_name(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
UClass *u_class = ue_py_check_type<UClass>(self);
if (!u_class)
return PyErr_Format(PyExc_Exception, "uobject is a not a UClass");
return PyUnicode_FromString(TCHAR_TO_UTF8(*u_class->ClassConfigName.ToString()));
}
#endif
PyObject *py_ue_get_property_struct(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
char *property_name;
if (!PyArg_ParseTuple(args, "s:get_property_struct", &property_name))
{
return NULL;
}
UStruct *u_struct = nullptr;
if (self->ue_object->IsA<UClass>())
{
u_struct = (UStruct *)self->ue_object;
}
else
{
u_struct = (UStruct *)self->ue_object->GetClass();
}
UProperty *u_property = u_struct->FindPropertyByName(FName(UTF8_TO_TCHAR(property_name)));
if (!u_property)
return PyErr_Format(PyExc_Exception, "unable to find property %s", property_name);
UStructProperty *prop = Cast<UStructProperty>(u_property);
if (!prop)
return PyErr_Format(PyExc_Exception, "object is not a StructProperty");
return py_ue_new_uscriptstruct(prop->Struct, prop->ContainerPtrToValuePtr<uint8>(self->ue_object));
}
PyObject *py_ue_get_super_class(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
UClass *u_class = nullptr;
if (self->ue_object->IsA<UClass>())
{
u_class = (UClass *)self->ue_object;
}
else
{
u_class = self->ue_object->GetClass();
}
Py_RETURN_UOBJECT(u_class->GetSuperClass());
}
PyObject *py_ue_get_outer(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
UObject *outer = self->ue_object->GetOuter();
if (!outer)
Py_RETURN_NONE;
Py_RETURN_UOBJECT(outer);
}
PyObject *py_ue_get_outermost(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
UObject *outermost = self->ue_object->GetOutermost();
if (!outermost)
Py_RETURN_NONE;
Py_RETURN_UOBJECT(outermost);
}
PyObject *py_ue_conditional_begin_destroy(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
self->ue_object->ConditionalBeginDestroy();
Py_INCREF(Py_None);
return Py_None;
}
PyObject *py_ue_is_valid(ue_PyUObject * self, PyObject * args)
{
if (!self->ue_object || !self->ue_object->IsValidLowLevel() || self->ue_object->IsPendingKillOrUnreachable())
{
Py_RETURN_FALSE;
}
Py_RETURN_TRUE;
}
PyObject *py_ue_is_a(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
PyObject *obj;
if (!PyArg_ParseTuple(args, "O:is_a", &obj))
{
return NULL;
}
if (!ue_is_pyuobject(obj))
{
return PyErr_Format(PyExc_Exception, "argument is not a UObject");
}
ue_PyUObject *py_obj = (ue_PyUObject *)obj;
if (self->ue_object->IsA((UClass *)py_obj->ue_object))
{
Py_RETURN_TRUE;
}
Py_RETURN_FALSE;
}
PyObject *py_ue_is_child_of(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
PyObject *obj;
if (!PyArg_ParseTuple(args, "O:is_child_of", &obj))
{
return NULL;
}
if (!self->ue_object->IsA<UClass>())
return PyErr_Format(PyExc_Exception, "object is not a UClass");
if (!ue_is_pyuobject(obj))
{
return PyErr_Format(PyExc_Exception, "argument is not a UObject");
}
ue_PyUObject *py_obj = (ue_PyUObject *)obj;
if (!py_obj->ue_object->IsA<UClass>())
return PyErr_Format(PyExc_Exception, "argument is not a UClass");
UClass *parent = (UClass *)py_obj->ue_object;
UClass *child = (UClass *)self->ue_object;
if (child->IsChildOf(parent))
{
Py_RETURN_TRUE;
}
Py_RETURN_FALSE;
}
PyObject *py_ue_post_edit_change(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
#if WITH_EDITOR
Py_BEGIN_ALLOW_THREADS;
self->ue_object->PostEditChange();
Py_END_ALLOW_THREADS;
#endif
Py_RETURN_NONE;
}
PyObject *py_ue_post_edit_change_property(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
char *prop_name = nullptr;
int change_type = (int)EPropertyChangeType::Unspecified;
if (!PyArg_ParseTuple(args, "s|i:post_edit_change_property", &prop_name, &change_type))
{
return nullptr;
}
UStruct *u_struct = nullptr;
if (self->ue_object->IsA<UStruct>())
{
u_struct = (UStruct *)self->ue_object;
}
else
{
u_struct = (UStruct *)self->ue_object->GetClass();
}
UProperty *prop = u_struct->FindPropertyByName(FName(UTF8_TO_TCHAR(prop_name)));
if (!prop)
return PyErr_Format(PyExc_Exception, "unable to find property %s", prop_name);
#if WITH_EDITOR
Py_BEGIN_ALLOW_THREADS;
FPropertyChangedEvent changed(prop, change_type);
self->ue_object->PostEditChangeProperty(changed);
Py_END_ALLOW_THREADS;
#endif
Py_RETURN_NONE;
}
PyObject *py_ue_modify(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
#if WITH_EDITOR
Py_BEGIN_ALLOW_THREADS;
self->ue_object->Modify();
Py_END_ALLOW_THREADS;
#endif
Py_RETURN_NONE;
}
PyObject *py_ue_pre_edit_change(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
UProperty *prop = nullptr;
char *prop_name = nullptr;
if (!PyArg_ParseTuple(args, "|s:pre_edit_change", &prop_name))
{
return nullptr;
}
if (prop_name)
{
UStruct *u_struct = nullptr;
if (self->ue_object->IsA<UStruct>())
{
u_struct = (UStruct *)self->ue_object;
}
else
{
u_struct = (UStruct *)self->ue_object->GetClass();
}
prop = u_struct->FindPropertyByName(FName(UTF8_TO_TCHAR(prop_name)));
if (!prop)
return PyErr_Format(PyExc_Exception, "unable to find property %s", prop_name);
}
#if WITH_EDITOR
Py_BEGIN_ALLOW_THREADS;
self->ue_object->PreEditChange(prop);
Py_END_ALLOW_THREADS;
#endif
Py_RETURN_NONE;
}
#if WITH_EDITOR
PyObject *py_ue_set_metadata(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
char *metadata_key;
char *metadata_value;
if (!PyArg_ParseTuple(args, "ss:set_metadata", &metadata_key, &metadata_value))
{
return NULL;
}
if (self->ue_object->IsA<UClass>())
{
UClass *u_class = (UClass *)self->ue_object;
u_class->SetMetaData(FName(UTF8_TO_TCHAR(metadata_key)), UTF8_TO_TCHAR(metadata_value));
}
else if (self->ue_object->IsA<UField>())
{
UField *u_field = (UField *)self->ue_object;
u_field->SetMetaData(FName(UTF8_TO_TCHAR(metadata_key)), UTF8_TO_TCHAR(metadata_value));
}
else
{
return PyErr_Format(PyExc_TypeError, "the object does not support MetaData");
}
Py_RETURN_NONE;
}
PyObject *py_ue_get_metadata(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
char *metadata_key;
if (!PyArg_ParseTuple(args, "s:get_metadata", &metadata_key))
{
return NULL;
}
char *metadata_value = nullptr;
if (self->ue_object->IsA<UClass>())
{
UClass *u_class = (UClass *)self->ue_object;
FString value = u_class->GetMetaData(FName(UTF8_TO_TCHAR(metadata_key)));
return PyUnicode_FromString(TCHAR_TO_UTF8(*value));
}
if (self->ue_object->IsA<UField>())
{
UField *u_field = (UField *)self->ue_object;
FString value = u_field->GetMetaData(FName(UTF8_TO_TCHAR(metadata_key)));
return PyUnicode_FromString(TCHAR_TO_UTF8(*value));
}
return PyErr_Format(PyExc_TypeError, "the object does not support MetaData");
}
PyObject *py_ue_get_metadata_tag(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
char *metadata_tag_key;
if (!PyArg_ParseTuple(args, "s:get_metadata_tag", &metadata_tag_key))
{
return nullptr;
}
const FString& Value = self->ue_object->GetOutermost()->GetMetaData()->GetValue(self->ue_object, UTF8_TO_TCHAR(metadata_tag_key));
return PyUnicode_FromString(TCHAR_TO_UTF8(*Value));
}
PyObject *py_ue_has_metadata_tag(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
char *metadata_tag_key;
if (!PyArg_ParseTuple(args, "s:has_metadata_tag", &metadata_tag_key))
{
return nullptr;
}
if (self->ue_object->GetOutermost()->GetMetaData()->HasValue(self->ue_object, UTF8_TO_TCHAR(metadata_tag_key)))
{
Py_RETURN_TRUE;
}
Py_RETURN_FALSE;
}
PyObject *py_ue_remove_metadata_tag(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
char *metadata_tag_key;
if (!PyArg_ParseTuple(args, "s:remove_metadata_tag", &metadata_tag_key))
{
return nullptr;
}
self->ue_object->GetOutermost()->GetMetaData()->RemoveValue(self->ue_object, UTF8_TO_TCHAR(metadata_tag_key));
Py_RETURN_NONE;
}
PyObject *py_ue_set_metadata_tag(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
char *metadata_tag_key;
char *metadata_tag_value;
if (!PyArg_ParseTuple(args, "ss:set_metadata_tag", &metadata_tag_key, &metadata_tag_value))
{
return nullptr;
}
self->ue_object->GetOutermost()->GetMetaData()->SetValue(self->ue_object, UTF8_TO_TCHAR(metadata_tag_key), UTF8_TO_TCHAR(metadata_tag_value));
Py_RETURN_NONE;
}
PyObject *py_ue_metadata_tags(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
TMap<FName, FString> *TagsMap = self->ue_object->GetOutermost()->GetMetaData()->GetMapForObject(self->ue_object);
if (!TagsMap)
Py_RETURN_NONE;
PyObject* py_list = PyList_New(0);
for (TPair< FName, FString>& Pair : *TagsMap)
{
PyList_Append(py_list, PyUnicode_FromString(TCHAR_TO_UTF8(*Pair.Key.ToString())));
}
return py_list;
}
PyObject *py_ue_has_metadata(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
char *metadata_key;
if (!PyArg_ParseTuple(args, "s:has_metadata", &metadata_key))
{
return NULL;
}
if (self->ue_object->IsA<UClass>())
{
UClass *u_class = (UClass *)self->ue_object;
if (u_class->HasMetaData(FName(UTF8_TO_TCHAR(metadata_key))))
{
Py_RETURN_TRUE;
}
Py_RETURN_FALSE;
}
if (self->ue_object->IsA<UField>())
{
UField *u_field = (UField *)self->ue_object;
if (u_field->HasMetaData(FName(UTF8_TO_TCHAR(metadata_key))))
{
Py_INCREF(Py_True);
return Py_True;
}
Py_INCREF(Py_False);
return Py_False;
}
return PyErr_Format(PyExc_TypeError, "the object does not support MetaData");
}
#endif
PyObject *py_ue_call_function(ue_PyUObject * self, PyObject * args, PyObject *kwargs)
{
ue_py_check(self);
UFunction *function = nullptr;
if (PyTuple_Size(args) < 1)
{
return PyErr_Format(PyExc_TypeError, "this function requires at least an argument");
}
PyObject *func_id = PyTuple_GetItem(args, 0);
if (PyUnicodeOrString_Check(func_id))
{
function = self->ue_object->FindFunction(FName(UTF8_TO_TCHAR(UEPyUnicode_AsUTF8(func_id))));
}
if (!function)
return PyErr_Format(PyExc_Exception, "unable to find function");
return py_ue_ufunction_call(function, self->ue_object, args, 1, kwargs);
}
PyObject *py_ue_find_function(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
char *name;
if (!PyArg_ParseTuple(args, "s:find_function", &name))
{
return NULL;
}
UFunction *function = self->ue_object->FindFunction(FName(UTF8_TO_TCHAR(name)));
if (!function)
{
Py_RETURN_NONE;
}
Py_RETURN_UOBJECT((UObject *)function);
}
#if ENGINE_MINOR_VERSION >= 15
PyObject *py_ue_can_modify(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
if (self->ue_object->CanModify())
{
Py_RETURN_TRUE;
}
Py_RETURN_FALSE;
}
#endif
PyObject *py_ue_set_name(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
char *name;
if (!PyArg_ParseTuple(args, "s:set_name", &name))
{
return NULL;
}
if (!self->ue_object->Rename(UTF8_TO_TCHAR(name), self->ue_object->GetOutermost(), REN_Test))
{
return PyErr_Format(PyExc_Exception, "cannot set name %s", name);
}
if (self->ue_object->Rename(UTF8_TO_TCHAR(name)))
{
Py_RETURN_TRUE;
}
Py_RETURN_FALSE;
}
PyObject *py_ue_set_outer(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
PyObject *py_outer;
if (!PyArg_ParseTuple(args, "O:set_outer", &py_outer))
{
return nullptr;
}
UPackage *package = ue_py_check_type<UPackage>(py_outer);
if (!package)
return PyErr_Format(PyExc_Exception, "argument is not a UPackage");
if (!self->ue_object->Rename(nullptr, package, REN_Test))
{
return PyErr_Format(PyExc_Exception, "cannot move to package %s", TCHAR_TO_UTF8(*package->GetPathName()));
}
if (self->ue_object->Rename(nullptr, package))
{
Py_RETURN_TRUE;
}
Py_RETURN_FALSE;
}
PyObject *py_ue_get_name(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
return PyUnicode_FromString(TCHAR_TO_UTF8(*(self->ue_object->GetName())));
}
PyObject *py_ue_get_display_name(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
#if WITH_EDITOR
if (UClass *uclass = ue_py_check_type<UClass>(self))
{
return PyUnicode_FromString(TCHAR_TO_UTF8(*uclass->GetDisplayNameText().ToString()));
}
if (AActor *actor = ue_py_check_type<AActor>(self))
{
return PyUnicode_FromString(TCHAR_TO_UTF8(*actor->GetActorLabel()));
}
#endif
if (UActorComponent *component = ue_py_check_type<UActorComponent>(self))
{
return PyUnicode_FromString(TCHAR_TO_UTF8(*component->GetReadableName()));
}
return PyUnicode_FromString(TCHAR_TO_UTF8(*(self->ue_object->GetName())));
}
PyObject *py_ue_get_full_name(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
return PyUnicode_FromString(TCHAR_TO_UTF8(*(self->ue_object->GetFullName())));
}
PyObject *py_ue_get_path_name(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
return PyUnicode_FromString(TCHAR_TO_UTF8(*(self->ue_object->GetPathName())));
}
PyObject *py_ue_save_config(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
Py_BEGIN_ALLOW_THREADS;
self->ue_object->SaveConfig();
Py_END_ALLOW_THREADS;
Py_RETURN_NONE;
}
PyObject *py_ue_set_property(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
char *property_name;
PyObject *property_value;
int index = 0;
if (!PyArg_ParseTuple(args, "sO|i:set_property", &property_name, &property_value, &index))
{
return nullptr;
}
UStruct *u_struct = nullptr;
if (self->ue_object->IsA<UStruct>())
{
u_struct = (UStruct *)self->ue_object;
}
else
{
u_struct = (UStruct *)self->ue_object->GetClass();
}
UProperty *u_property = u_struct->FindPropertyByName(FName(UTF8_TO_TCHAR(property_name)));
if (!u_property)
return PyErr_Format(PyExc_Exception, "unable to find property %s", property_name);
if (!ue_py_convert_pyobject(property_value, u_property, (uint8 *)self->ue_object, index))
{
return PyErr_Format(PyExc_Exception, "unable to set property %s", property_name);
}
Py_RETURN_NONE;
}
PyObject *py_ue_set_property_flags(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
char *property_name;
uint64 flags;
if (!PyArg_ParseTuple(args, "sK:set_property_flags", &property_name, &flags))
{
return NULL;
}
UStruct *u_struct = nullptr;
if (self->ue_object->IsA<UStruct>())
{
u_struct = (UStruct *)self->ue_object;
}
else
{
u_struct = (UStruct *)self->ue_object->GetClass();
}
UProperty *u_property = u_struct->FindPropertyByName(FName(UTF8_TO_TCHAR(property_name)));
if (!u_property)
return PyErr_Format(PyExc_Exception, "unable to find property %s", property_name);
#if ENGINE_MINOR_VERSION < 20
u_property->SetPropertyFlags(flags);
#else
u_property->SetPropertyFlags((EPropertyFlags)flags);
#endif
Py_RETURN_NONE;
}
PyObject *py_ue_add_property_flags(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
char *property_name;
uint64 flags;
if (!PyArg_ParseTuple(args, "sK:add_property_flags", &property_name, &flags))
{
return NULL;
}
UStruct *u_struct = nullptr;
if (self->ue_object->IsA<UStruct>())
{
u_struct = (UStruct *)self->ue_object;
}
else
{
u_struct = (UStruct *)self->ue_object->GetClass();
}
UProperty *u_property = u_struct->FindPropertyByName(FName(UTF8_TO_TCHAR(property_name)));
if (!u_property)
return PyErr_Format(PyExc_Exception, "unable to find property %s", property_name);
#if ENGINE_MINOR_VERSION < 20
u_property->SetPropertyFlags(u_property->GetPropertyFlags() | flags);
#else
u_property->SetPropertyFlags(u_property->GetPropertyFlags() | (EPropertyFlags)flags);
#endif
Py_RETURN_NONE;
}
PyObject *py_ue_get_property_flags(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
char *property_name;
if (!PyArg_ParseTuple(args, "s:get_property_flags", &property_name))
{
return NULL;
}
UStruct *u_struct = nullptr;
if (self->ue_object->IsA<UStruct>())
{
u_struct = (UStruct *)self->ue_object;
}
else
{
u_struct = (UStruct *)self->ue_object->GetClass();
}
UProperty *u_property = u_struct->FindPropertyByName(FName(UTF8_TO_TCHAR(property_name)));
if (!u_property)
return PyErr_Format(PyExc_Exception, "unable to find property %s", property_name);
return PyLong_FromUnsignedLong(u_property->GetPropertyFlags());
}
PyObject *py_ue_enum_values(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
if (!self->ue_object->IsA<UEnum>())
return PyErr_Format(PyExc_TypeError, "uobject is not a UEnum");
UEnum *u_enum = (UEnum *)self->ue_object;
uint8 max_enum_value = u_enum->GetMaxEnumValue();
PyObject *ret = PyList_New(0);
for (uint8 i = 0; i < max_enum_value; i++)
{
PyObject *py_long = PyLong_FromLong(i);
PyList_Append(ret, py_long);
Py_DECREF(py_long);
}
return ret;
}
PyObject *py_ue_enum_names(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
if (!self->ue_object->IsA<UEnum>())
return PyErr_Format(PyExc_TypeError, "uobject is not a UEnum");
UEnum *u_enum = (UEnum *)self->ue_object;
uint8 max_enum_value = u_enum->GetMaxEnumValue();
PyObject *ret = PyList_New(0);
for (uint8 i = 0; i < max_enum_value; i++)
{
#if ENGINE_MINOR_VERSION > 15
PyObject *py_long = PyUnicode_FromString(TCHAR_TO_UTF8(*u_enum->GetNameStringByIndex(i)));
#else
PyObject *py_long = PyUnicode_FromString(TCHAR_TO_UTF8(*u_enum->GetEnumName(i)));
#endif
PyList_Append(ret, py_long);
Py_DECREF(py_long);
}
return ret;
}
#if ENGINE_MINOR_VERSION >= 15
PyObject *py_ue_enum_user_defined_names(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
if (!self->ue_object->IsA<UUserDefinedEnum>())
return PyErr_Format(PyExc_TypeError, "uobject is not a UEnum");
UUserDefinedEnum *u_enum = (UUserDefinedEnum *)self->ue_object;
TArray<FText> user_defined_names;
u_enum->DisplayNameMap.GenerateValueArray(user_defined_names);
PyObject *ret = PyList_New(0);
for (FText text : user_defined_names)
{
PyObject *py_long = PyUnicode_FromString(TCHAR_TO_UTF8(*text.ToString()));
PyList_Append(ret, py_long);
Py_DECREF(py_long);
}
return ret;
}
#endif
PyObject *py_ue_properties(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
UStruct *u_struct = nullptr;
if (self->ue_object->IsA<UStruct>())
{
u_struct = (UStruct *)self->ue_object;
}
else
{
u_struct = (UStruct *)self->ue_object->GetClass();
}
PyObject *ret = PyList_New(0);
for (TFieldIterator<UProperty> PropIt(u_struct); PropIt; ++PropIt)
{
UProperty* property = *PropIt;
PyObject *property_name = PyUnicode_FromString(TCHAR_TO_UTF8(*property->GetName()));
PyList_Append(ret, property_name);
Py_DECREF(property_name);
}
return ret;
}
PyObject *py_ue_functions(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
UStruct *u_struct = nullptr;
if (self->ue_object->IsA<UStruct>())
{
u_struct = (UStruct *)self->ue_object;
}
else
{
u_struct = (UStruct *)self->ue_object->GetClass();
}
PyObject *ret = PyList_New(0);
for (TFieldIterator<UFunction> FuncIt(u_struct); FuncIt; ++FuncIt)
{
UFunction* func = *FuncIt;
PyObject *func_name = PyUnicode_FromString(TCHAR_TO_UTF8(*func->GetFName().ToString()));
PyList_Append(ret, func_name);
Py_DECREF(func_name);
}
return ret;
}
PyObject *py_ue_call(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
char *call_args;
if (!PyArg_ParseTuple(args, "s:call", &call_args))
{
return nullptr;
}
FOutputDeviceNull od_null;
bool success = false;
Py_BEGIN_ALLOW_THREADS;
success = self->ue_object->CallFunctionByNameWithArguments(UTF8_TO_TCHAR(call_args), od_null, NULL, true);
Py_END_ALLOW_THREADS;
if (!success)
{
return PyErr_Format(PyExc_Exception, "error while calling \"%s\"", call_args);
}
Py_RETURN_NONE;
}
PyObject *py_ue_broadcast(ue_PyUObject *self, PyObject *args)
{
ue_py_check(self);
Py_ssize_t args_len = PyTuple_Size(args);
if (args_len < 1)
{
return PyErr_Format(PyExc_Exception, "you need to specify the event to trigger");
}
PyObject *py_property_name = PyTuple_GetItem(args, 0);
if (!PyUnicodeOrString_Check(py_property_name))
{
return PyErr_Format(PyExc_Exception, "event name must be a unicode string");
}
const char *property_name = UEPyUnicode_AsUTF8(py_property_name);
UProperty *u_property = self->ue_object->GetClass()->FindPropertyByName(FName(UTF8_TO_TCHAR(property_name)));
if (!u_property)
return PyErr_Format(PyExc_Exception, "unable to find event property %s", property_name);
if (auto casted_prop = Cast<UMulticastDelegateProperty>(u_property))
{
#if ENGINE_MINOR_VERSION >= 23
FMulticastScriptDelegate multiscript_delegate = *casted_prop->GetMulticastDelegate(self->ue_object);
#else
FMulticastScriptDelegate multiscript_delegate = casted_prop->GetPropertyValue_InContainer(self->ue_object);
#endif
uint8 *parms = (uint8 *)FMemory_Alloca(casted_prop->SignatureFunction->PropertiesSize);
FMemory::Memzero(parms, casted_prop->SignatureFunction->PropertiesSize);
uint32 argn = 1;
// initialize args
for (TFieldIterator<UProperty> IArgs(casted_prop->SignatureFunction); IArgs && IArgs->HasAnyPropertyFlags(CPF_Parm); ++IArgs)
{
UProperty *prop = *IArgs;
if (!prop->HasAnyPropertyFlags(CPF_ZeroConstructor))
{
prop->InitializeValue_InContainer(parms);
}
if ((IArgs->PropertyFlags & (CPF_Parm | CPF_ReturnParm)) == CPF_Parm)
{
if (!prop->IsInContainer(casted_prop->SignatureFunction->ParmsSize))
{
return PyErr_Format(PyExc_Exception, "Attempting to import func param property that's out of bounds. %s", TCHAR_TO_UTF8(*casted_prop->SignatureFunction->GetName()));
}
PyObject *py_arg = PyTuple_GetItem(args, argn);
if (!py_arg)
{
PyErr_Clear();
#if WITH_EDITOR
FString default_key = FString("CPP_Default_") + prop->GetName();
FString default_key_value = casted_prop->SignatureFunction->GetMetaData(FName(*default_key));
if (!default_key_value.IsEmpty())
{
#if ENGINE_MINOR_VERSION >= 17
prop->ImportText(*default_key_value, prop->ContainerPtrToValuePtr<uint8>(parms), PPF_None, NULL);
#else
prop->ImportText(*default_key_value, prop->ContainerPtrToValuePtr<uint8>(parms), PPF_Localized, NULL);
#endif
}
#endif
}
else if (!ue_py_convert_pyobject(py_arg, prop, parms, 0))
{
return PyErr_Format(PyExc_TypeError, "unable to convert pyobject to property %s (%s)", TCHAR_TO_UTF8(*prop->GetName()), TCHAR_TO_UTF8(*prop->GetClass()->GetName()));
}
}
argn++;
}
Py_BEGIN_ALLOW_THREADS;
multiscript_delegate.ProcessMulticastDelegate<UObject>(parms);
Py_END_ALLOW_THREADS;
}
else
{
return PyErr_Format(PyExc_Exception, "property is not a UMulticastDelegateProperty");
}
Py_RETURN_NONE;
}
PyObject *py_ue_get_property(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
char *property_name;
int index = 0;
if (!PyArg_ParseTuple(args, "s|i:get_property", &property_name, &index))
{
return nullptr;
}
UStruct *u_struct = nullptr;
if (self->ue_object->IsA<UClass>())
{
u_struct = (UStruct *)self->ue_object;
}
else
{
u_struct = (UStruct *)self->ue_object->GetClass();
}
UProperty *u_property = u_struct->FindPropertyByName(FName(UTF8_TO_TCHAR(property_name)));
if (!u_property)
return PyErr_Format(PyExc_Exception, "unable to find property %s", property_name);
return ue_py_convert_property(u_property, (uint8 *)self->ue_object, index);
}
PyObject *py_ue_get_property_array_dim(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
char *property_name;
if (!PyArg_ParseTuple(args, "s:get_property_array_dim", &property_name))
{
return NULL;
}
UStruct *u_struct = nullptr;
if (self->ue_object->IsA<UClass>())
{
u_struct = (UStruct *)self->ue_object;
}
else
{
u_struct = (UStruct *)self->ue_object->GetClass();
}
UProperty *u_property = u_struct->FindPropertyByName(FName(UTF8_TO_TCHAR(property_name)));
if (!u_property)
return PyErr_Format(PyExc_Exception, "unable to find property %s", property_name);
return PyLong_FromLongLong(u_property->ArrayDim);
}
#if WITH_EDITOR
PyObject *py_ue_get_thumbnail(ue_PyUObject *self, PyObject * args)
{
PyObject *py_generate = nullptr;
if (!PyArg_ParseTuple(args, "|O:get_thumbnail", &py_generate))
{
return nullptr;
}
ue_py_check(self);
TArray<FName> names;
names.Add(FName(*self->ue_object->GetFullName()));
FThumbnailMap thumb_map;
FObjectThumbnail *object_thumbnail = nullptr;
if (!ThumbnailTools::ConditionallyLoadThumbnailsForObjects(names, thumb_map))
{
if (py_generate && PyObject_IsTrue(py_generate))
{
object_thumbnail = ThumbnailTools::GenerateThumbnailForObjectToSaveToDisk(self->ue_object);
}
}
else
{
object_thumbnail = &thumb_map[names[0]];
}
if (!object_thumbnail)
{
return PyErr_Format(PyExc_Exception, "unable to retrieve thumbnail");
}
return py_ue_new_fobject_thumbnail(*object_thumbnail);
}
PyObject *py_ue_render_thumbnail(ue_PyUObject *self, PyObject * args)
{
int width = ThumbnailTools::DefaultThumbnailSize;
int height = ThumbnailTools::DefaultThumbnailSize;
PyObject *no_flush = nullptr;
if (!PyArg_ParseTuple(args, "|iiO:render_thumbnail", &width, height, &no_flush))
{
return nullptr;
}
ue_py_check(self);
FObjectThumbnail object_thumbnail;
ThumbnailTools::RenderThumbnail(self->ue_object, width, height,
(no_flush && PyObject_IsTrue(no_flush)) ? ThumbnailTools::EThumbnailTextureFlushMode::NeverFlush : ThumbnailTools::EThumbnailTextureFlushMode::AlwaysFlush,
nullptr, &object_thumbnail);
return py_ue_new_fobject_thumbnail(object_thumbnail);
}
#endif
PyObject *py_ue_get_uproperty(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
char *property_name;
if (!PyArg_ParseTuple(args, "s:get_uproperty", &property_name))
{
return NULL;
}
UStruct *u_struct = nullptr;
if (self->ue_object->IsA<UClass>())
{
u_struct = (UStruct *)self->ue_object;
}
else
{
u_struct = (UStruct *)self->ue_object->GetClass();
}
UProperty *u_property = u_struct->FindPropertyByName(FName(UTF8_TO_TCHAR(property_name)));
if (!u_property)
return PyErr_Format(PyExc_Exception, "unable to find property %s", property_name);
Py_RETURN_UOBJECT(u_property);
}
PyObject *py_ue_get_inner(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
UArrayProperty *u_property = ue_py_check_type<UArrayProperty>(self);
if (!u_property)
return PyErr_Format(PyExc_Exception, "object is not a UArrayProperty");
UProperty* inner = u_property->Inner;
if (!inner)
Py_RETURN_NONE;
Py_RETURN_UOBJECT(inner);
}
PyObject *py_ue_get_key_prop(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
UMapProperty *u_property = ue_py_check_type<UMapProperty>(self);
if (!u_property)
return PyErr_Format(PyExc_Exception, "object is not a UMapProperty");
UProperty* key = u_property->KeyProp;
if (!key)
Py_RETURN_NONE;
Py_RETURN_UOBJECT(key);
}
PyObject *py_ue_get_value_prop(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
UMapProperty *u_property = ue_py_check_type<UMapProperty>(self);
if (!u_property)
return PyErr_Format(PyExc_Exception, "object is not a UMapProperty");
UProperty* value = u_property->ValueProp;
if (!value)
Py_RETURN_NONE;
Py_RETURN_UOBJECT(value);
}
PyObject *py_ue_has_property(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
char *property_name;
if (!PyArg_ParseTuple(args, "s:has_property", &property_name))
{
return NULL;
}
UStruct *u_struct = nullptr;
if (self->ue_object->IsA<UClass>())
{
u_struct = (UStruct *)self->ue_object;
}
else
{
u_struct = (UStruct *)self->ue_object->GetClass();
}
UProperty *u_property = u_struct->FindPropertyByName(FName(UTF8_TO_TCHAR(property_name)));
if (!u_property)
Py_RETURN_FALSE;
Py_RETURN_TRUE;
}
PyObject *py_ue_get_property_class(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
char *property_name;
if (!PyArg_ParseTuple(args, "s:get_property_class", &property_name))
{
return NULL;
}
UStruct *u_struct = nullptr;
if (self->ue_object->IsA<UClass>())
{
u_struct = (UStruct *)self->ue_object;
}
else
{
u_struct = (UStruct *)self->ue_object->GetClass();
}
UProperty *u_property = u_struct->FindPropertyByName(FName(UTF8_TO_TCHAR(property_name)));
if (!u_property)
return PyErr_Format(PyExc_Exception, "unable to find property %s", property_name);
Py_RETURN_UOBJECT(u_property->GetClass());
}
PyObject *py_ue_is_rooted(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
if (self->ue_object->IsRooted())
{
Py_RETURN_TRUE;
}
Py_RETURN_FALSE;
}
PyObject *py_ue_add_to_root(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
self->ue_object->AddToRoot();
Py_RETURN_NONE;
}
PyObject *py_ue_own(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
if (self->owned)
{
return PyErr_Format(PyExc_Exception, "uobject already owned");
}
Py_DECREF(self);
self->owned = 1;
FUnrealEnginePythonHouseKeeper::Get()->TrackUObject(self->ue_object);
Py_RETURN_NONE;
}
PyObject *py_ue_disown(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
if (!self->owned)
{
return PyErr_Format(PyExc_Exception, "uobject not owned");
}
Py_INCREF(self);
self->owned = 0;
FUnrealEnginePythonHouseKeeper::Get()->UntrackUObject(self->ue_object);
Py_RETURN_NONE;
}
PyObject *py_ue_is_owned(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
if (!self->owned)
{
Py_RETURN_FALSE;
}
Py_RETURN_TRUE;
}
PyObject *py_ue_auto_root(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
self->ue_object->AddToRoot();
self->auto_rooted = 1;
Py_RETURN_NONE;
}
PyObject *py_ue_remove_from_root(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
self->ue_object->RemoveFromRoot();
Py_INCREF(Py_None);
return Py_None;
}
PyObject *py_ue_bind_event(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
char *event_name;
PyObject *py_callable;
if (!PyArg_ParseTuple(args, "sO:bind_event", &event_name, &py_callable))
{
return NULL;
}
if (!PyCallable_Check(py_callable))
{
return PyErr_Format(PyExc_Exception, "object is not callable");
}
return ue_bind_pyevent(self, FString(event_name), py_callable, true);
}
PyObject *py_ue_unbind_event(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
char *event_name;
PyObject *py_callable;
if (!PyArg_ParseTuple(args, "sO:bind_event", &event_name, &py_callable))
{
return NULL;
}
if (!PyCallable_Check(py_callable))
{
return PyErr_Format(PyExc_Exception, "object is not callable");
}
return ue_unbind_pyevent(self, FString(event_name), py_callable, true);
}
PyObject *py_ue_delegate_bind_ufunction(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
char *delegate_name;
PyObject *py_obj;
char *fname;
if (!PyArg_ParseTuple(args, "sOs:delegate_bind_ufunction", &delegate_name, &py_obj, &fname))
return nullptr;
UProperty *u_property = self->ue_object->GetClass()->FindPropertyByName(FName(delegate_name));
if (!u_property)
return PyErr_Format(PyExc_Exception, "unable to find property %s", delegate_name);
UDelegateProperty *Prop = Cast<UDelegateProperty>(u_property);
if (!Prop)
return PyErr_Format(PyExc_Exception, "property is not a UDelegateProperty");
UObject *Object = ue_py_check_type<UObject>(py_obj);
if (!Object)
return PyErr_Format(PyExc_Exception, "argument is not a UObject");
FScriptDelegate script_delegate;
script_delegate.BindUFunction(Object, FName(fname));
// re-assign multicast delegate
Prop->SetPropertyValue_InContainer(self->ue_object, script_delegate);
Py_RETURN_NONE;
}
#if PY_MAJOR_VERSION >= 3
PyObject *py_ue_add_function(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
char *name;
PyObject *py_callable;
if (!PyArg_ParseTuple(args, "sO:add_function", &name, &py_callable))
{
return NULL;
}
if (!self->ue_object->IsA<UClass>())
{
return PyErr_Format(PyExc_Exception, "uobject is not a UClass");
}
UClass *u_class = (UClass *)self->ue_object;
if (!PyCallable_Check(py_callable))
{
return PyErr_Format(PyExc_Exception, "object is not callable");
}
if (!unreal_engine_add_function(u_class, name, py_callable, FUNC_Native | FUNC_BlueprintCallable | FUNC_Public))
{
return PyErr_Format(PyExc_Exception, "unable to add function");
}
Py_INCREF(Py_None);
return Py_None;
}
#endif
PyObject *py_ue_add_property(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
PyObject *obj;
char *name;
PyObject *property_class = nullptr;
PyObject *property_class2 = nullptr;
if (!PyArg_ParseTuple(args, "Os|OO:add_property", &obj, &name, &property_class, &property_class2))
{
return NULL;
}
if (!self->ue_object->IsA<UStruct>())
return PyErr_Format(PyExc_Exception, "uobject is not a UStruct");
UObject *scope = nullptr;
UProperty *u_property = nullptr;
UClass *u_class = nullptr;
UProperty *u_property2 = nullptr;
UClass *u_class2 = nullptr;
UClass *u_prop_class = nullptr;
UScriptStruct *u_script_struct = nullptr;
UClass *u_prop_class2 = nullptr;
UScriptStruct *u_script_struct2 = nullptr;
bool is_array = false;
bool is_map = false;
if (property_class)
{
if (!ue_is_pyuobject(property_class))
{
return PyErr_Format(PyExc_Exception, "property class arg is not a uobject");
}
ue_PyUObject *py_prop_class = (ue_PyUObject *)property_class;
if (py_prop_class->ue_object->IsA<UClass>())
{
u_prop_class = (UClass *)py_prop_class->ue_object;
}
else if (py_prop_class->ue_object->IsA<UScriptStruct>())
{
u_script_struct = (UScriptStruct *)py_prop_class->ue_object;
}
else
{
return PyErr_Format(PyExc_Exception, "property class arg is not a UClass or a UScriptStruct");
}
}
if (property_class2)
{
if (!ue_is_pyuobject(property_class2))
{
return PyErr_Format(PyExc_Exception, "property class arg is not a uobject");
}
ue_PyUObject *py_prop_class = (ue_PyUObject *)property_class2;
if (py_prop_class->ue_object->IsA<UClass>())
{
u_prop_class2 = (UClass *)py_prop_class->ue_object;
}
else if (py_prop_class->ue_object->IsA<UScriptStruct>())
{
u_script_struct2 = (UScriptStruct *)py_prop_class->ue_object;
}
else
{
return PyErr_Format(PyExc_Exception, "property class arg is not a UClass or a UScriptStruct");
}
}
EObjectFlags o_flags = RF_Public | RF_MarkAsNative;// | RF_Transient;
if (ue_is_pyuobject(obj))
{
ue_PyUObject *py_obj = (ue_PyUObject *)obj;
if (!py_obj->ue_object->IsA<UClass>())
{
return PyErr_Format(PyExc_Exception, "uobject is not a UClass");
}
u_class = (UClass *)py_obj->ue_object;
if (!u_class->IsChildOf<UProperty>())
return PyErr_Format(PyExc_Exception, "uobject is not a UProperty");
if (u_class == UArrayProperty::StaticClass())
return PyErr_Format(PyExc_Exception, "please use a single-item list of property for arrays");
scope = self->ue_object;
}
else if (PyList_Check(obj))
{
if (PyList_Size(obj) == 1)
{
PyObject *py_item = PyList_GetItem(obj, 0);
if (ue_is_pyuobject(py_item))
{
ue_PyUObject *py_obj = (ue_PyUObject *)py_item;
if (!py_obj->ue_object->IsA<UClass>())
{
return PyErr_Format(PyExc_Exception, "uobject is not a UClass");
}
u_class = (UClass *)py_obj->ue_object;
if (!u_class->IsChildOf<UProperty>())
return PyErr_Format(PyExc_Exception, "uobject is not a UProperty");
if (u_class == UArrayProperty::StaticClass())
return PyErr_Format(PyExc_Exception, "please use a single-item list of property for arrays");
UArrayProperty *u_array = NewObject<UArrayProperty>(self->ue_object, UTF8_TO_TCHAR(name), o_flags);
if (!u_array)
return PyErr_Format(PyExc_Exception, "unable to allocate new UProperty");
scope = u_array;
is_array = true;
}
Py_DECREF(py_item);
}
#if ENGINE_MINOR_VERSION >= 15
else if (PyList_Size(obj) == 2)
{
PyObject *py_key = PyList_GetItem(obj, 0);
PyObject *py_value = PyList_GetItem(obj, 1);
if (ue_is_pyuobject(py_key) && ue_is_pyuobject(py_value))
{
// KEY
ue_PyUObject *py_obj = (ue_PyUObject *)py_key;
if (!py_obj->ue_object->IsA<UClass>())
{
return PyErr_Format(PyExc_Exception, "uobject is not a UClass");
}
u_class = (UClass *)py_obj->ue_object;
if (!u_class->IsChildOf<UProperty>())
return PyErr_Format(PyExc_Exception, "uobject is not a UProperty");
if (u_class == UArrayProperty::StaticClass())
return PyErr_Format(PyExc_Exception, "please use a two-items list of properties for maps");
// VALUE
ue_PyUObject *py_obj2 = (ue_PyUObject *)py_value;
if (!py_obj2->ue_object->IsA<UClass>())
{
return PyErr_Format(PyExc_Exception, "uobject is not a UClass");
}
u_class2 = (UClass *)py_obj2->ue_object;
if (!u_class2->IsChildOf<UProperty>())
return PyErr_Format(PyExc_Exception, "uobject is not a UProperty");
if (u_class2 == UArrayProperty::StaticClass())
return PyErr_Format(PyExc_Exception, "please use a two-items list of properties for maps");
UMapProperty *u_map = NewObject<UMapProperty>(self->ue_object, UTF8_TO_TCHAR(name), o_flags);
if (!u_map)
return PyErr_Format(PyExc_Exception, "unable to allocate new UProperty");
scope = u_map;
is_map = true;
}
Py_DECREF(py_key);
Py_DECREF(py_value);
}
#endif
}
if (!scope)
{
return PyErr_Format(PyExc_Exception, "argument is not a UObject or a single item list");
}
u_property = NewObject<UProperty>(scope, u_class, UTF8_TO_TCHAR(name), o_flags);
if (!u_property)
{
if (is_array || is_map)
scope->MarkPendingKill();
return PyErr_Format(PyExc_Exception, "unable to allocate new UProperty");
}
// one day we may want to support transient properties...
//uint64 flags = CPF_Edit | CPF_BlueprintVisible | CPF_Transient | CPF_ZeroConstructor;
uint64 flags = CPF_Edit | CPF_BlueprintVisible | CPF_ZeroConstructor;
// we assumed Actor Components to be non-editable
if (u_prop_class && u_prop_class->IsChildOf<UActorComponent>())
{
flags |= ~CPF_Edit;
}
// TODO manage replication
/*
if (replicate && PyObject_IsTrue(replicate)) {
flags |= CPF_Net;
}*/
if (is_array)
{
UArrayProperty *u_array = (UArrayProperty *)scope;
u_array->AddCppProperty(u_property);
#if ENGINE_MINOR_VERSION < 20
u_property->SetPropertyFlags(flags);
#else
u_property->SetPropertyFlags((EPropertyFlags)flags);
#endif
if (u_property->GetClass() == UObjectProperty::StaticClass())
{
UObjectProperty *obj_prop = (UObjectProperty *)u_property;
if (u_prop_class)
{
obj_prop->SetPropertyClass(u_prop_class);
}
}
if (u_property->GetClass() == UStructProperty::StaticClass())
{
UStructProperty *obj_prop = (UStructProperty *)u_property;
if (u_script_struct)
{
obj_prop->Struct = u_script_struct;
}
}
u_property = u_array;
}
#if ENGINE_MINOR_VERSION >= 15
if (is_map)
{
u_property2 = NewObject<UProperty>(scope, u_class2, NAME_None, o_flags);
if (!u_property2)
{
if (is_array || is_map)
scope->MarkPendingKill();
return PyErr_Format(PyExc_Exception, "unable to allocate new UProperty");
}
UMapProperty *u_map = (UMapProperty *)scope;
#if ENGINE_MINOR_VERSION < 20
u_property->SetPropertyFlags(flags);
u_property2->SetPropertyFlags(flags);
#else
u_property->SetPropertyFlags((EPropertyFlags)flags);
u_property2->SetPropertyFlags((EPropertyFlags)flags);
#endif
if (u_property->GetClass() == UObjectProperty::StaticClass())
{
UObjectProperty *obj_prop = (UObjectProperty *)u_property;
if (u_prop_class)
{
obj_prop->SetPropertyClass(u_prop_class);
}
}
if (u_property->GetClass() == UStructProperty::StaticClass())
{
UStructProperty *obj_prop = (UStructProperty *)u_property;
if (u_script_struct)
{
obj_prop->Struct = u_script_struct;
}
}
if (u_property2->GetClass() == UObjectProperty::StaticClass())
{
UObjectProperty *obj_prop = (UObjectProperty *)u_property2;
if (u_prop_class2)
{
obj_prop->SetPropertyClass(u_prop_class2);
}
}
if (u_property2->GetClass() == UStructProperty::StaticClass())
{
UStructProperty *obj_prop = (UStructProperty *)u_property2;
if (u_script_struct2)
{
obj_prop->Struct = u_script_struct2;
}
}
u_map->KeyProp = u_property;
u_map->ValueProp = u_property2;
u_property = u_map;
}
#endif
if (u_class == UMulticastDelegateProperty::StaticClass())
{
UMulticastDelegateProperty *mcp = (UMulticastDelegateProperty *)u_property;
mcp->SignatureFunction = NewObject<UFunction>(self->ue_object, NAME_None, RF_Public | RF_Transient | RF_MarkAsNative);
mcp->SignatureFunction->FunctionFlags = FUNC_MulticastDelegate | FUNC_BlueprintCallable | FUNC_Native;
flags |= CPF_BlueprintAssignable | CPF_BlueprintCallable;
flags &= ~CPF_Edit;
}
else if (u_class == UDelegateProperty::StaticClass())
{
UDelegateProperty *udp = (UDelegateProperty *)u_property;
udp->SignatureFunction = NewObject<UFunction>(self->ue_object, NAME_None, RF_Public | RF_Transient | RF_MarkAsNative);
udp->SignatureFunction->FunctionFlags = FUNC_MulticastDelegate | FUNC_BlueprintCallable | FUNC_Native;
flags |= CPF_BlueprintAssignable | CPF_BlueprintCallable;
flags &= ~CPF_Edit;
}
else if (u_class == UObjectProperty::StaticClass())
{
// ensure it is not an arry as we have already managed it !
if (!is_array && !is_map)
{
UObjectProperty *obj_prop = (UObjectProperty *)u_property;
if (u_prop_class)
{
obj_prop->SetPropertyClass(u_prop_class);
}
}
}
else if (u_class == UStructProperty::StaticClass())
{
// ensure it is not an arry as we have already managed it !
if (!is_array && !is_map)
{
UStructProperty *obj_prop = (UStructProperty *)u_property;
if (u_script_struct)
{
obj_prop->Struct = u_script_struct;
}
}
}
#if ENGINE_MINOR_VERSION < 20
u_property->SetPropertyFlags(flags);
#else
u_property->SetPropertyFlags((EPropertyFlags)flags);
#endif
u_property->ArrayDim = 1;
UStruct *u_struct = (UStruct *)self->ue_object;
u_struct->AddCppProperty(u_property);
u_struct->StaticLink(true);
if (u_struct->IsA<UClass>())
{
UClass *owner_class = (UClass *)u_struct;
owner_class->GetDefaultObject()->RemoveFromRoot();
owner_class->GetDefaultObject()->ConditionalBeginDestroy();
owner_class->ClassDefaultObject = nullptr;
owner_class->GetDefaultObject()->PostInitProperties();
}
// TODO add default value
Py_RETURN_UOBJECT(u_property);
}
PyObject *py_ue_as_dict(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
UStruct *u_struct = nullptr;
UObject *u_object = self->ue_object;
if (self->ue_object->IsA<UStruct>())
{
u_struct = (UStruct *)self->ue_object;
if (self->ue_object->IsA<UClass>())
{
UClass *u_class = (UClass *)self->ue_object;
u_object = u_class->GetDefaultObject();
}
}
else
{
u_struct = (UStruct *)self->ue_object->GetClass();
}
PyObject *py_struct_dict = PyDict_New();
TFieldIterator<UProperty> SArgs(u_struct);
for (; SArgs; ++SArgs)
{
PyObject *struct_value = ue_py_convert_property(*SArgs, (uint8 *)u_object, 0);
if (!struct_value)
{
Py_DECREF(py_struct_dict);
return NULL;
}
PyDict_SetItemString(py_struct_dict, TCHAR_TO_UTF8(*SArgs->GetName()), struct_value);
}
return py_struct_dict;
}
PyObject *py_ue_get_cdo(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
UClass *u_class = ue_py_check_type<UClass>(self);
if (!u_class)
{
return PyErr_Format(PyExc_Exception, "uobject is not a UClass");
}
Py_RETURN_UOBJECT(u_class->GetDefaultObject());
}
PyObject *py_ue_get_archetype(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
UObject *Archetype = self->ue_object->GetArchetype();
if (!Archetype)
return PyErr_Format(PyExc_Exception, "uobject has no archetype");
Py_RETURN_UOBJECT(Archetype);
}
PyObject *py_ue_get_archetype_instances(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
TArray<UObject *> Instances;
self->ue_object->GetArchetypeInstances(Instances);
PyObject *py_list = PyList_New(0);
for (UObject *Instance : Instances)
{
PyList_Append(py_list, (PyObject *)ue_get_python_uobject(Instance));
}
return py_list;
}
#if WITH_EDITOR
PyObject *py_ue_save_package(ue_PyUObject * self, PyObject * args)
{
/*
Here we have the following cases to manage:
calling on a UObject without an outer
calling on a UObject with an outer
calling on a UObject with an outer and a name arg
*/
ue_py_check(self);
bool has_package = false;
char *name = nullptr;
UPackage *package = nullptr;
if (!PyArg_ParseTuple(args, "|s:save_package", &name))
{
return NULL;
}
UObject *outer = self->ue_object->GetOutermost();
UObject *u_object = self->ue_object;
if (outer && outer->IsA<UPackage>() && outer != GetTransientPackage())
{
package = (UPackage *)outer;
has_package = true;
}
else if (u_object && u_object->IsA<UPackage>() && u_object != GetTransientPackage())
{
package = (UPackage *)u_object;
has_package = true;
}
bool bIsMap = u_object->IsA<UWorld>();
if (!package || name)
{
if (!name)
{
return PyErr_Format(PyExc_Exception, "the object has no associated package, please specify a name");
}
if (!has_package)
{
// unmark transient object
if (u_object->HasAnyFlags(RF_Transient))
{
u_object->ClearFlags(RF_Transient);
}
}
// create a new package if it does not exist
package = CreatePackage(nullptr, UTF8_TO_TCHAR(name));
if (!package)
return PyErr_Format(PyExc_Exception, "unable to create package");
package->FileName = *FPackageName::LongPackageNameToFilename(UTF8_TO_TCHAR(name), bIsMap ? FPackageName::GetMapPackageExtension() : FPackageName::GetAssetPackageExtension());
if (has_package)
{
FString split_path;
FString split_filename;
FString split_extension;
FString split_base(UTF8_TO_TCHAR(name));
FPaths::Split(split_base, split_path, split_filename, split_extension);
u_object = DuplicateObject(self->ue_object, package, FName(*split_filename));
}
else
{
// move to object into the new package
if (!self->ue_object->Rename(*(self->ue_object->GetName()), package, REN_Test))
{
return PyErr_Format(PyExc_Exception, "unable to set object outer to package");
}
if (!self->ue_object->Rename(*(self->ue_object->GetName()), package))
{
return PyErr_Format(PyExc_Exception, "unable to set object outer to package");
}
}
}
// ensure the right flags are applied
u_object->SetFlags(RF_Public | RF_Standalone);
package->FullyLoad();
package->MarkPackageDirty();
if (package->FileName.IsNone())
{
package->FileName = *FPackageName::LongPackageNameToFilename(*package->GetPathName(), bIsMap ? FPackageName::GetMapPackageExtension() : FPackageName::GetAssetPackageExtension());
UE_LOG(LogPython, Warning, TEXT("no file mapped to UPackage %s, setting its FileName to %s"), *package->GetPathName(), *package->FileName.ToString());
}
// NOTE: FileName may not be a fully qualified filepath
if (FPackageName::IsValidLongPackageName(package->FileName.ToString()))
{
package->FileName = *FPackageName::LongPackageNameToFilename(package->GetPathName(), bIsMap ? FPackageName::GetMapPackageExtension() : FPackageName::GetAssetPackageExtension());
}
if (UPackage::SavePackage(package, u_object, RF_Standalone, *package->FileName.ToString()))
{
FAssetRegistryModule::AssetCreated(u_object);
Py_RETURN_UOBJECT(u_object);
}
return PyErr_Format(PyExc_Exception, "unable to save package");
}
PyObject *py_ue_import_custom_properties(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
char *t3d;
if (!PyArg_ParseTuple(args, "s:import_custom_properties", &t3d))
{
return nullptr;
}
FFeedbackContextAnsi context;
Py_BEGIN_ALLOW_THREADS;
self->ue_object->ImportCustomProperties(UTF8_TO_TCHAR(t3d), &context);
Py_END_ALLOW_THREADS;
TArray<FString> errors;
context.GetErrors(errors);
if (errors.Num() > 0)
{
return PyErr_Format(PyExc_Exception, "%s", TCHAR_TO_UTF8(*errors[0]));
}
Py_RETURN_NONE;
}
PyObject *py_ue_asset_can_reimport(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
if (FReimportManager::Instance()->CanReimport(self->ue_object))
{
Py_RETURN_TRUE;
}
Py_RETURN_FALSE;
}
PyObject *py_ue_asset_reimport(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
PyObject *py_ask_for_new_file = nullptr;
PyObject *py_show_notification = nullptr;
char *filename = nullptr;
if (!PyArg_ParseTuple(args, "|OOs:asset_reimport", &py_ask_for_new_file, &py_show_notification, &filename))
{
return NULL;
}
bool ask_for_new_file = false;
bool show_notification = false;
FString f_filename = FString("");
if (py_ask_for_new_file && PyObject_IsTrue(py_ask_for_new_file))
ask_for_new_file = true;
if (py_show_notification && PyObject_IsTrue(py_show_notification))
show_notification = true;
if (filename)
f_filename = FString(UTF8_TO_TCHAR(filename));
if (FReimportManager::Instance()->Reimport(self->ue_object, ask_for_new_file, show_notification, f_filename))
{
Py_RETURN_TRUE;
}
Py_RETURN_FALSE;
}
PyObject *py_ue_duplicate(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
char *package_name;
char *object_name;
PyObject *py_overwrite = nullptr;
if (!PyArg_ParseTuple(args, "ss|O:duplicate", &package_name, &object_name, &py_overwrite))
return nullptr;
ObjectTools::FPackageGroupName pgn;
pgn.ObjectName = UTF8_TO_TCHAR(object_name);
pgn.GroupName = FString("");
pgn.PackageName = UTF8_TO_TCHAR(package_name);
TSet<UPackage *> refused;
UObject *new_asset = nullptr;
Py_BEGIN_ALLOW_THREADS;
#if ENGINE_MINOR_VERSION < 14
new_asset = ObjectTools::DuplicateSingleObject(self->ue_object, pgn, refused);
#else
new_asset = ObjectTools::DuplicateSingleObject(self->ue_object, pgn, refused, (py_overwrite && PyObject_IsTrue(py_overwrite)));
#endif
Py_END_ALLOW_THREADS;
if (!new_asset)
return PyErr_Format(PyExc_Exception, "unable to duplicate object");
Py_RETURN_UOBJECT(new_asset);
}
#endif
PyObject *py_ue_to_bytes(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
TArray<uint8> Bytes;
FObjectWriter(self->ue_object, Bytes);
return PyBytes_FromStringAndSize((const char *)Bytes.GetData(), Bytes.Num());
}
PyObject *py_ue_to_bytearray(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
TArray<uint8> Bytes;
FObjectWriter(self->ue_object, Bytes);
return PyByteArray_FromStringAndSize((const char *)Bytes.GetData(), Bytes.Num());
}
PyObject *py_ue_from_bytes(ue_PyUObject * self, PyObject * args)
{
Py_buffer py_buf;
if (!PyArg_ParseTuple(args, "z*:from_bytes", &py_buf))
return nullptr;
ue_py_check(self);
TArray<uint8> Bytes;
Bytes.AddUninitialized(py_buf.len);
FMemory::Memcpy(Bytes.GetData(), py_buf.buf, py_buf.len);
FObjectReader(self->ue_object, Bytes);
Py_RETURN_NONE;
}
```
|
/content/code_sandbox/Source/UnrealEnginePython/Private/UObject/UEPyObject.cpp
|
c++
| 2016-08-07T05:00:51
| 2024-08-14T06:32:20
|
UnrealEnginePython
|
20tab/UnrealEnginePython
| 2,715
| 15,025
|
```objective-c
#pragma once
#include "UEPyModule.h"
PyObject *py_ue_get_class(ue_PyUObject *, PyObject *);
PyObject *py_ue_is_a(ue_PyUObject *, PyObject *);
PyObject *py_ue_is_valid(ue_PyUObject *, PyObject *);
PyObject *py_ue_is_child_of(ue_PyUObject *, PyObject *);
PyObject *py_ue_call_function(ue_PyUObject *, PyObject *, PyObject *);
PyObject *py_ue_find_function(ue_PyUObject *, PyObject *);
PyObject *py_ue_get_name(ue_PyUObject *, PyObject * args);
PyObject *py_ue_get_display_name(ue_PyUObject *, PyObject * args);
PyObject *py_ue_set_name(ue_PyUObject *, PyObject * args);
PyObject *py_ue_get_full_name(ue_PyUObject *, PyObject *);
PyObject *py_ue_get_path_name(ue_PyUObject *, PyObject *);
PyObject *py_ue_set_property(ue_PyUObject *, PyObject *);
PyObject *py_ue_set_property_flags(ue_PyUObject *, PyObject *);
PyObject *py_ue_add_property_flags(ue_PyUObject *, PyObject *);
PyObject *py_ue_get_property_flags(ue_PyUObject *, PyObject *);
PyObject *py_ue_get_property_struct(ue_PyUObject *, PyObject *);
PyObject *py_ue_properties(ue_PyUObject *, PyObject *);
PyObject *py_ue_call(ue_PyUObject *, PyObject *);
PyObject *py_ue_get_property(ue_PyUObject *, PyObject *);
PyObject *py_ue_get_property_array_dim(ue_PyUObject *, PyObject *);
PyObject *py_ue_get_uproperty(ue_PyUObject *, PyObject *);
PyObject *py_ue_get_inner(ue_PyUObject *, PyObject *);
PyObject *py_ue_get_key_prop(ue_PyUObject *, PyObject *);
PyObject *py_ue_get_value_prop(ue_PyUObject *, PyObject *);
PyObject *py_ue_get_property_class(ue_PyUObject *, PyObject *);
PyObject *py_ue_has_property(ue_PyUObject *, PyObject *);
PyObject *py_ue_is_rooted(ue_PyUObject *, PyObject *);
PyObject *py_ue_add_to_root(ue_PyUObject *, PyObject *);
PyObject *py_ue_remove_from_root(ue_PyUObject *, PyObject *);
PyObject *py_ue_auto_root(ue_PyUObject *, PyObject *);
PyObject *py_ue_own(ue_PyUObject *, PyObject *);
PyObject *py_ue_disown(ue_PyUObject *, PyObject *);
PyObject *py_ue_is_owned(ue_PyUObject *, PyObject *);
PyObject *py_ue_save_config(ue_PyUObject *, PyObject *);
PyObject *py_ue_get_cdo(ue_PyUObject *, PyObject *);
PyObject *py_ue_get_archetype(ue_PyUObject *, PyObject *);
PyObject *py_ue_get_archetype_instances(ue_PyUObject *, PyObject *);
PyObject *py_ue_enum_values(ue_PyUObject *, PyObject *);
PyObject *py_ue_enum_names(ue_PyUObject *, PyObject *);
#if ENGINE_MINOR_VERSION >= 15
PyObject *py_ue_enum_user_defined_names(ue_PyUObject *, PyObject *);
#endif
PyObject *py_ue_bind_event(ue_PyUObject *, PyObject *);
PyObject *py_ue_unbind_event(ue_PyUObject *, PyObject *);
PyObject *py_ue_add_function(ue_PyUObject *, PyObject *);
PyObject *py_ue_add_property(ue_PyUObject *, PyObject *);
PyObject *py_ue_as_dict(ue_PyUObject *, PyObject *);
PyObject *py_ue_can_modify(ue_PyUObject *, PyObject *);
PyObject *py_ue_get_outer(ue_PyUObject *, PyObject *);
PyObject *py_ue_set_outer(ue_PyUObject *, PyObject *);
PyObject *py_ue_get_outermost(ue_PyUObject *, PyObject *);
PyObject *py_ue_conditional_begin_destroy(ue_PyUObject *, PyObject *);
PyObject *py_ue_get_super_class(ue_PyUObject *, PyObject *);
PyObject *py_ue_functions(ue_PyUObject *, PyObject *);
PyObject *py_ue_broadcast(ue_PyUObject *, PyObject *);
PyObject *py_ue_post_edit_change(ue_PyUObject *, PyObject *);
PyObject *py_ue_post_edit_change_property(ue_PyUObject *, PyObject *);
PyObject *py_ue_pre_edit_change(ue_PyUObject *, PyObject *);
PyObject *py_ue_modify(ue_PyUObject *, PyObject *);
PyObject *py_ue_class_generated_by(ue_PyUObject *, PyObject *);
PyObject *py_ue_class_get_flags(ue_PyUObject *, PyObject *);
PyObject *py_ue_class_set_flags(ue_PyUObject *, PyObject *);
PyObject *py_ue_get_obj_flags(ue_PyUObject *, PyObject *);
PyObject *py_ue_set_obj_flags(ue_PyUObject *, PyObject *);
PyObject *py_ue_clear_obj_flags(ue_PyUObject *, PyObject *);
PyObject *py_ue_reset_obj_flags(ue_PyUObject *, PyObject *);
PyObject *py_ue_delegate_bind_ufunction(ue_PyUObject *, PyObject *);
#if WITH_EDITOR
PyObject *py_ue_class_get_config_name(ue_PyUObject *, PyObject *);
PyObject *py_ue_class_set_config_name(ue_PyUObject *, PyObject *);
PyObject *py_ue_save_package(ue_PyUObject *, PyObject *);
PyObject *py_ue_duplicate(ue_PyUObject *, PyObject *);
PyObject *py_ue_asset_can_reimport(ue_PyUObject *, PyObject *);
PyObject *py_ue_asset_reimport(ue_PyUObject *, PyObject *);
PyObject *py_ue_get_metadata(ue_PyUObject *, PyObject *);
PyObject *py_ue_set_metadata(ue_PyUObject *, PyObject *);
PyObject *py_ue_has_metadata(ue_PyUObject *, PyObject *);
PyObject *py_ue_get_metadata_tag(ue_PyUObject *, PyObject *);
PyObject *py_ue_set_metadata_tag(ue_PyUObject *, PyObject *);
PyObject *py_ue_has_metadata_tag(ue_PyUObject *, PyObject *);
PyObject *py_ue_remove_metadata_tag(ue_PyUObject *, PyObject *);
PyObject *py_ue_metadata_tags(ue_PyUObject *, PyObject *);
PyObject *py_ue_import_custom_properties(ue_PyUObject *, PyObject *);
#endif
PyObject *py_ue_get_thumbnail(ue_PyUObject *, PyObject *);
PyObject *py_ue_render_thumbnail(ue_PyUObject *, PyObject *);
PyObject *py_ue_to_bytes(ue_PyUObject *, PyObject *);
PyObject *py_ue_to_bytearray(ue_PyUObject *, PyObject *);
PyObject *py_ue_from_bytes(ue_PyUObject *, PyObject *);
```
|
/content/code_sandbox/Source/UnrealEnginePython/Private/UObject/UEPyObject.h
|
objective-c
| 2016-08-07T05:00:51
| 2024-08-14T06:32:20
|
UnrealEnginePython
|
20tab/UnrealEnginePython
| 2,715
| 1,358
|
```c++
#include "UEPyFoliage.h"
#include "Runtime/Foliage/Public/FoliageType.h"
#include "Runtime/Foliage/Public/InstancedFoliageActor.h"
#include "Wrappers/UEPyFFoliageInstance.h"
PyObject *py_ue_get_instanced_foliage_actor_for_current_level(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
UWorld *world = ue_get_uworld(self);
if (!world)
return PyErr_Format(PyExc_Exception, "unable to retrieve UWorld from uobject");
Py_RETURN_UOBJECT(AInstancedFoliageActor::GetInstancedFoliageActorForCurrentLevel(world, true));
}
PyObject *py_ue_get_instanced_foliage_actor_for_level(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
ULevel *level = ue_py_check_type<ULevel>(self);
if (!level)
return PyErr_Format(PyExc_Exception, "uobject is not a ULevel");
Py_RETURN_UOBJECT(AInstancedFoliageActor::GetInstancedFoliageActorForLevel(level, true));
}
PyObject *py_ue_get_foliage_types(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
AInstancedFoliageActor *foliage_actor = ue_py_check_type<AInstancedFoliageActor>(self);
if (!foliage_actor)
return PyErr_Format(PyExc_Exception, "uobject is not a AInstancedFoliageActor");
PyObject *py_list = PyList_New(0);
TArray<UFoliageType *> FoliageTypes;
#if ENGINE_MINOR_VERSION >=23
foliage_actor->FoliageInfos.GetKeys(FoliageTypes);
#else
foliage_actor->FoliageMeshes.GetKeys(FoliageTypes);
#endif
for (UFoliageType *FoliageType : FoliageTypes)
{
PyList_Append(py_list, (PyObject*)ue_get_python_uobject(FoliageType));
}
return py_list;
}
#if WITH_EDITOR
PyObject *py_ue_get_foliage_instances(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
PyObject *py_foliage_type;
if (!PyArg_ParseTuple(args, "O:get_foliage_instances", &py_foliage_type))
{
return nullptr;
}
AInstancedFoliageActor *foliage_actor = ue_py_check_type<AInstancedFoliageActor>(self);
if (!foliage_actor)
return PyErr_Format(PyExc_Exception, "uobject is not a AInstancedFoliageActor");
UFoliageType *foliage_type = ue_py_check_type<UFoliageType>(py_foliage_type);
if (!foliage_type)
return PyErr_Format(PyExc_Exception, "argument is not a UFoliageType");
#if ENGINE_MINOR_VERSION >= 23
if (!foliage_actor->FoliageInfos.Contains(foliage_type))
#else
if (!foliage_actor->FoliageMeshes.Contains(foliage_type))
#endif
{
return PyErr_Format(PyExc_Exception, "specified UFoliageType not found in AInstancedFoliageActor");
}
#if ENGINE_MINOR_VERSION >= 23
FFoliageInfo& info = foliage_actor->FoliageInfos[foliage_type].Get();
#else
FFoliageMeshInfo& info = foliage_actor->FoliageMeshes[foliage_type].Get();
#endif
PyObject *py_list = PyList_New(0);
for (int32 i=0; i<info.Instances.Num(); i++)
{
PyList_Append(py_list, py_ue_new_ffoliage_instance(foliage_actor, foliage_type, i));
}
return py_list;
}
PyObject *py_ue_add_foliage_asset(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
PyObject *py_uobject;
if (!PyArg_ParseTuple(args, "O:add_foliage_asset", &py_uobject))
{
return nullptr;
}
UWorld *world = ue_get_uworld(self);
if (!world)
return PyErr_Format(PyExc_Exception, "unable to retrieve UWorld from uobject");
UObject *u_object = ue_py_check_type<UObject>(py_uobject);
if (!u_object)
return PyErr_Format(PyExc_Exception, "argument is not a UObject");
UFoliageType *foliage_type = nullptr;
AInstancedFoliageActor *ifa = AInstancedFoliageActor::GetInstancedFoliageActorForCurrentLevel(world, true);
if (u_object->IsA<UStaticMesh>())
{
#if ENGINE_MINOR_VERSION >= 23
foliage_type = ifa->GetLocalFoliageTypeForSource(u_object);
#else
foliage_type = ifa->GetLocalFoliageTypeForMesh((UStaticMesh *)u_object);
#endif
if (!foliage_type)
{
ifa->AddMesh((UStaticMesh *)u_object, &foliage_type);
}
}
else if (u_object->IsA<UFoliageType>())
{
foliage_type = (UFoliageType *)u_object;
ifa->AddFoliageType(foliage_type);
}
if (!foliage_type)
return PyErr_Format(PyExc_Exception, "unable to add foliage asset");
Py_RETURN_UOBJECT(foliage_type);
}
#endif
```
|
/content/code_sandbox/Source/UnrealEnginePython/Private/UObject/UEPyFoliage.cpp
|
c++
| 2016-08-07T05:00:51
| 2024-08-14T06:32:20
|
UnrealEnginePython
|
20tab/UnrealEnginePython
| 2,715
| 1,176
|
```objective-c
#pragma once
#include "UEPyModule.h"
#include "Animation/AnimSequence.h"
#include "Animation/BlendSpaceBase.h"
#include "Animation/AnimMontage.h"
#include "Wrappers/UEPyFRawAnimSequenceTrack.h"
PyObject *py_ue_anim_get_skeleton(ue_PyUObject *, PyObject *);
#if WITH_EDITOR
PyObject *py_ue_anim_sequence_get_raw_animation_data(ue_PyUObject *, PyObject *);
PyObject *py_ue_anim_sequence_get_raw_animation_track(ue_PyUObject *, PyObject *);
PyObject *py_ue_anim_sequence_add_new_raw_track(ue_PyUObject *, PyObject *);
PyObject *py_ue_anim_sequence_update_raw_track(ue_PyUObject *, PyObject *);
PyObject *py_ue_add_anim_composite_section(ue_PyUObject *, PyObject *);
PyObject *py_ue_anim_sequence_update_compressed_track_map_from_raw(ue_PyUObject *, PyObject *);
PyObject *py_ue_anim_sequence_apply_raw_anim_changes(ue_PyUObject *, PyObject *);
PyObject *py_ue_anim_add_key_to_sequence(ue_PyUObject *, PyObject *);
#endif
PyObject *py_ue_anim_set_skeleton(ue_PyUObject *, PyObject *);
PyObject *py_ue_anim_get_bone_transform(ue_PyUObject *, PyObject *);
PyObject *py_ue_anim_extract_bone_transform(ue_PyUObject *, PyObject *);
PyObject *py_ue_anim_extract_root_motion(ue_PyUObject *, PyObject *);
PyObject *py_ue_get_blend_parameter(ue_PyUObject *, PyObject *);
PyObject *py_ue_set_blend_parameter(ue_PyUObject *, PyObject *);
```
|
/content/code_sandbox/Source/UnrealEnginePython/Private/UObject/UEPyAnimSequence.h
|
objective-c
| 2016-08-07T05:00:51
| 2024-08-14T06:32:20
|
UnrealEnginePython
|
20tab/UnrealEnginePython
| 2,715
| 328
|
```c++
#include "UEPyTransform.h"
#include "GameFramework/Actor.h"
#include "Wrappers/UEPyFHitResult.h"
static bool check_vector_args(PyObject *args, FVector &vec, bool &sweep, bool &teleport_physics)
{
PyObject *py_vec = nullptr;
float x = 0, y = 0, z = 0;
PyObject *py_sweep = nullptr;
PyObject *py_teleport_physics = nullptr;
if (!PyArg_ParseTuple(args, "O|OO", &py_vec, &py_sweep, &py_teleport_physics))
{
return false;
}
ue_PyFVector *ue_py_vec = py_ue_is_fvector(py_vec);
if (!ue_py_vec)
{
if (!PyArg_ParseTuple(args, "fff|OO", &x, &y, &z, &py_sweep, &py_teleport_physics))
{
return false;
}
vec.X = x;
vec.Y = y;
vec.Z = z;
}
else
{
vec = ue_py_vec->vec;
}
sweep = (py_sweep && PyObject_IsTrue(py_sweep));
teleport_physics = (py_teleport_physics && PyObject_IsTrue(py_teleport_physics));
return true;
}
static bool check_rotation_args(PyObject *args, FQuat &quat, bool &sweep, bool &teleport_physics)
{
PyObject *py_rotation = nullptr;
float roll = 0, pitch = 0, yaw = 0;
PyObject *py_sweep = nullptr;
PyObject *py_teleport_physics = nullptr;
if (!PyArg_ParseTuple(args, "O|OO", &py_rotation, &py_sweep, &py_teleport_physics))
{
PyErr_Clear();
if (!PyArg_ParseTuple(args, "fff|OO", &roll, &pitch, &yaw, &py_sweep, &py_teleport_physics))
{
return false;
}
}
if (py_rotation)
{
ue_PyFQuat *ue_py_quat = py_ue_is_fquat(py_rotation);
if (ue_py_quat)
{
quat = ue_py_quat->quat;
}
else
{
ue_PyFRotator *ue_py_rot = py_ue_is_frotator(py_rotation);
if (!ue_py_rot)
{
PyErr_SetString(PyExc_Exception, "argument is not a FQuat or FRotator");
return false;
}
quat = ue_py_rot->rot.Quaternion();
}
}
else
{
quat = FQuat(FRotator(pitch, yaw, roll));
}
sweep = (py_sweep && PyObject_IsTrue(py_sweep));
teleport_physics = (py_teleport_physics && PyObject_IsTrue(py_teleport_physics));
return true;
}
static bool check_rotation_args_no_sweep(PyObject *args, FQuat &quat, bool &teleport_physics)
{
PyObject *py_rotation = nullptr;
float roll = 0, pitch = 0, yaw = 0;
PyObject *py_teleport_physics = nullptr;
if (!PyArg_ParseTuple(args, "O|O", &py_rotation, &py_teleport_physics))
{
PyErr_Clear();
if (!PyArg_ParseTuple(args, "fff|O", &roll, &pitch, &yaw, &py_teleport_physics))
{
return false;
}
}
if (py_rotation)
{
ue_PyFQuat *ue_py_quat = py_ue_is_fquat(py_rotation);
if (ue_py_quat)
{
quat = ue_py_quat->quat;
}
else
{
ue_PyFRotator *ue_py_rot = py_ue_is_frotator(py_rotation);
if (!ue_py_rot)
{
PyErr_SetString(PyExc_Exception, "argument is not a FQuat or FRotator");
return false;
}
quat = ue_py_rot->rot.Quaternion();
}
}
else
{
quat = FQuat(FRotator(pitch, yaw, roll));
}
teleport_physics = (py_teleport_physics && PyObject_IsTrue(py_teleport_physics));
return true;
}
PyObject *py_ue_get_actor_location(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
AActor *actor = ue_get_actor(self);
if (!actor)
return PyErr_Format(PyExc_Exception, "uobject is not an actor or a component");
return py_ue_new_fvector(actor->GetActorLocation());
}
PyObject *py_ue_get_actor_scale(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
AActor *actor = ue_get_actor(self);
if (!actor)
return PyErr_Format(PyExc_Exception, "uobject is not an actor or a component");
return py_ue_new_fvector(actor->GetActorScale3D());
}
PyObject *py_ue_get_actor_transform(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
AActor *actor = ue_get_actor(self);
if (!actor)
return PyErr_Format(PyExc_Exception, "uobject is not an actor or a component");
return py_ue_new_ftransform(actor->GetActorTransform());
}
PyObject *py_ue_get_actor_forward(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
AActor *actor = ue_get_actor(self);
if (!actor)
return PyErr_Format(PyExc_Exception, "uobject is not an actor or a component");
return py_ue_new_fvector(actor->GetActorForwardVector());
}
PyObject *py_ue_get_actor_right(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
AActor *actor = ue_get_actor(self);
if (!actor)
return PyErr_Format(PyExc_Exception, "uobject is not an actor or a component");
return py_ue_new_fvector(actor->GetActorRightVector());
}
PyObject *py_ue_get_actor_up(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
AActor *actor = ue_get_actor(self);
if (!actor)
return PyErr_Format(PyExc_Exception, "uobject is not an actor or a component");
return py_ue_new_fvector(actor->GetActorUpVector());
}
PyObject *py_ue_get_actor_rotation(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
AActor *actor = ue_get_actor(self);
if (!actor)
return PyErr_Format(PyExc_Exception, "uobject is not an actor or a component");
FRotator rot = actor->GetActorRotation();
return py_ue_new_frotator(rot);
}
PyObject *py_ue_set_actor_location(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
FVector vec;
bool sweep;
bool teleport_physics;
if (!check_vector_args(args, vec, sweep, teleport_physics))
return nullptr;
AActor *actor = ue_get_actor(self);
if (!actor)
PyErr_Format(PyExc_Exception, "uobject is not an actor or a component");
FHitResult hit;
bool success = false;
success = actor->SetActorLocation(vec, sweep, &hit, teleport_physics ? ETeleportType::TeleportPhysics : ETeleportType::None);
if (!sweep)
{
if (success)
{
Py_RETURN_TRUE;
}
Py_RETURN_FALSE;
}
return Py_BuildValue("(OO)", success ? Py_True : Py_False, py_ue_new_fhitresult(hit));
}
PyObject *py_ue_add_actor_world_offset(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
FVector vec;
bool sweep;
bool teleport_physics;
if (!check_vector_args(args, vec, sweep, teleport_physics))
return nullptr;
AActor *actor = ue_get_actor(self);
if (!actor)
PyErr_Format(PyExc_Exception, "uobject is not an actor or a component");
FHitResult hit;
actor->AddActorWorldOffset(vec, sweep, &hit, teleport_physics ? ETeleportType::TeleportPhysics : ETeleportType::None);
if (!sweep)
{
Py_RETURN_NONE;
}
return py_ue_new_fhitresult(hit);
}
PyObject *py_ue_add_actor_local_offset(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
FVector vec;
bool sweep;
bool teleport_physics;
if (!check_vector_args(args, vec, sweep, teleport_physics))
return nullptr;
AActor *actor = ue_get_actor(self);
if (!actor)
PyErr_Format(PyExc_Exception, "uobject is not an actor or a component");
FHitResult hit;
actor->AddActorLocalOffset(vec, sweep, &hit, teleport_physics ? ETeleportType::TeleportPhysics : ETeleportType::None);
if (!sweep)
{
Py_RETURN_NONE;
}
return py_ue_new_fhitresult(hit);
}
PyObject *py_ue_add_actor_world_rotation(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
FQuat quat;
bool sweep;
bool teleport_physics;
if (!check_rotation_args(args, quat, sweep, teleport_physics))
return nullptr;
AActor *actor = ue_get_actor(self);
if (!actor)
return PyErr_Format(PyExc_Exception, "uobject is not an actor or a component");
FHitResult hit;
actor->AddActorWorldRotation(quat, sweep, &hit, teleport_physics ? ETeleportType::TeleportPhysics : ETeleportType::None);
if (!sweep)
{
Py_RETURN_NONE;
}
return py_ue_new_fhitresult(hit);
}
PyObject *py_ue_add_actor_local_rotation(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
FQuat quat;
bool sweep;
bool teleport_physics;
if (!check_rotation_args(args, quat, sweep, teleport_physics))
return nullptr;
AActor *actor = ue_get_actor(self);
if (!actor)
return PyErr_Format(PyExc_Exception, "uobject is not an actor or a component");
FHitResult hit;
actor->AddActorLocalRotation(quat, sweep, &hit, teleport_physics ? ETeleportType::TeleportPhysics : ETeleportType::None);
if (!sweep)
{
Py_RETURN_NONE;
}
return py_ue_new_fhitresult(hit);
}
PyObject *py_ue_set_actor_scale(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
FVector vec;
if (!py_ue_vector_arg(args, vec))
return nullptr;
AActor *actor = ue_get_actor(self);
if (!actor)
PyErr_Format(PyExc_Exception, "uobject is not an actor or a component");
actor->SetActorScale3D(vec);
Py_RETURN_NONE;
}
PyObject *py_ue_set_actor_rotation(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
FQuat quat;
bool teleport_physics;
if (!check_rotation_args_no_sweep(args, quat, teleport_physics))
return nullptr;
AActor *actor = ue_get_actor(self);
if (!actor)
return PyErr_Format(PyExc_Exception, "uobject is not an actor or a component");
bool success = false;
success = actor->SetActorRotation(quat, teleport_physics ? ETeleportType::TeleportPhysics : ETeleportType::None);
if (success)
{
Py_RETURN_TRUE;
}
Py_RETURN_FALSE;
}
PyObject *py_ue_set_actor_transform(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
FTransform t;
if (!py_ue_transform_arg(args, t))
return nullptr;
AActor *actor = ue_get_actor(self);
if (!actor)
PyErr_Format(PyExc_Exception, "uobject is not an actor or a component");
actor->SetActorTransform(t);
Py_RETURN_NONE;
}
PyObject *py_ue_get_world_location(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
if (self->ue_object->IsA<USceneComponent>())
{
FVector vec3 = ((USceneComponent *)self->ue_object)->GetComponentLocation();
return py_ue_new_fvector(vec3);
}
return PyErr_Format(PyExc_Exception, "uobject is not a USceneComponent");
}
PyObject *py_ue_get_world_rotation(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
if (self->ue_object->IsA<USceneComponent>())
{
FRotator rot = ((USceneComponent *)self->ue_object)->GetComponentRotation();
return py_ue_new_frotator(rot);
}
return PyErr_Format(PyExc_Exception, "uobject is not a USceneComponent");
}
PyObject *py_ue_get_world_scale(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
if (self->ue_object->IsA<USceneComponent>())
{
FVector vec3 = ((USceneComponent *)self->ue_object)->GetComponentScale();
return py_ue_new_fvector(vec3);
}
return PyErr_Format(PyExc_Exception, "uobject is not a USceneComponent");
}
PyObject *py_ue_get_relative_location(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
if (self->ue_object->IsA<USceneComponent>())
{
FVector vec3 = ((USceneComponent *)self->ue_object)->RelativeLocation;
return py_ue_new_fvector(vec3);
}
return PyErr_Format(PyExc_Exception, "uobject is not a USceneComponent");
}
PyObject *py_ue_get_relative_rotation(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
if (self->ue_object->IsA<USceneComponent>())
{
FRotator rot = ((USceneComponent *)self->ue_object)->RelativeRotation;
return py_ue_new_frotator(rot);
}
return PyErr_Format(PyExc_Exception, "uobject is not a USceneComponent");
}
PyObject *py_ue_get_relative_scale(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
if (self->ue_object->IsA<USceneComponent>())
{
FVector vec3 = ((USceneComponent *)self->ue_object)->RelativeScale3D;
return py_ue_new_fvector(vec3);
}
return PyErr_Format(PyExc_Exception, "uobject is not a USceneComponent");
}
PyObject *py_ue_get_relative_transform(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
USceneComponent *component = ue_py_check_type<USceneComponent>(self);
if (!component)
return PyErr_Format(PyExc_Exception, "uobject is not a USceneComponent");
FTransform t = component->GetRelativeTransform();
return py_ue_new_ftransform(t);
}
PyObject *py_ue_get_world_transform(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
USceneComponent *component = ue_py_check_type<USceneComponent>(self);
if (!component)
return PyErr_Format(PyExc_Exception, "uobject is not a USceneComponent");
FTransform t = component->GetComponentTransform();
return py_ue_new_ftransform(t);
}
PyObject *py_ue_get_forward_vector(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
if (self->ue_object->IsA<USceneComponent>())
{
FVector vec3 = ((USceneComponent *)self->ue_object)->GetForwardVector();
return py_ue_new_fvector(vec3);
}
return PyErr_Format(PyExc_Exception, "uobject is not a USceneComponent");
}
PyObject *py_ue_get_up_vector(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
if (self->ue_object->IsA<USceneComponent>())
{
FVector vec3 = ((USceneComponent *)self->ue_object)->GetUpVector();
return py_ue_new_fvector(vec3);
}
return PyErr_Format(PyExc_Exception, "uobject is not a USceneComponent");
}
PyObject *py_ue_get_right_vector(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
if (self->ue_object->IsA<USceneComponent>())
{
FVector vec3 = ((USceneComponent *)self->ue_object)->GetRightVector();
return py_ue_new_fvector(vec3);
}
return PyErr_Format(PyExc_Exception, "uobject is not a USceneComponent");
}
PyObject *py_ue_set_world_location(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
FVector vec;
bool sweep;
bool teleport_physics;
if (!check_vector_args(args, vec, sweep, teleport_physics))
return nullptr;
FHitResult hit;
if (self->ue_object->IsA<USceneComponent>())
{
((USceneComponent *)self->ue_object)->SetWorldLocation(vec, sweep, &hit, teleport_physics ? ETeleportType::TeleportPhysics : ETeleportType::None);
if (!sweep)
{
Py_RETURN_NONE;
}
return py_ue_new_fhitresult(hit);
}
return PyErr_Format(PyExc_Exception, "uobject is not a USceneComponent");
}
PyObject *py_ue_set_world_rotation(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
FRotator rot;
if (!py_ue_rotator_arg(args, rot))
return NULL;
if (self->ue_object->IsA<USceneComponent>())
{
((USceneComponent *)self->ue_object)->SetWorldRotation(rot);
Py_RETURN_NONE;
}
return PyErr_Format(PyExc_Exception, "uobject is not a USceneComponent");
}
PyObject *py_ue_set_world_scale(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
FVector vec;
if (!py_ue_vector_arg(args, vec))
return NULL;
if (self->ue_object->IsA<USceneComponent>())
{
((USceneComponent *)self->ue_object)->SetWorldScale3D(vec);
}
return PyErr_Format(PyExc_Exception, "uobject is not a USceneComponent");
}
PyObject *py_ue_set_world_transform(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
FTransform t;
if (!py_ue_transform_arg(args, t))
return nullptr;
USceneComponent *component = ue_py_check_type<USceneComponent>(self);
if (!component)
return PyErr_Format(PyExc_Exception, "uobject is not a USceneComponent");
component->SetWorldTransform(t);
Py_RETURN_NONE;
}
PyObject *py_ue_set_relative_transform(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
FTransform t;
if (!py_ue_transform_arg(args, t))
return nullptr;
USceneComponent *component = ue_py_check_type<USceneComponent>(self);
if (!component)
return PyErr_Format(PyExc_Exception, "uobject is not a USceneComponent");
component->SetRelativeTransform(t);
Py_RETURN_NONE;
}
PyObject *py_ue_set_relative_location(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
FVector vec;
if (!py_ue_vector_arg(args, vec))
return NULL;
if (self->ue_object->IsA<USceneComponent>())
{
((USceneComponent *)self->ue_object)->SetRelativeLocation(vec);
Py_RETURN_NONE;
}
return PyErr_Format(PyExc_Exception, "uobject is not a USceneComponent");
}
PyObject *py_ue_set_relative_rotation(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
FRotator rot;
if (!py_ue_rotator_arg(args, rot))
return NULL;
if (self->ue_object->IsA<USceneComponent>())
{
((USceneComponent *)self->ue_object)->SetRelativeRotation(rot);
Py_RETURN_NONE;
}
return PyErr_Format(PyExc_Exception, "uobject is not a USceneComponent");
}
PyObject *py_ue_set_relative_scale(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
FVector vec;
if (!py_ue_vector_arg(args, vec))
return NULL;
if (self->ue_object->IsA<USceneComponent>())
{
((USceneComponent *)self->ue_object)->SetRelativeScale3D(vec);
Py_RETURN_NONE;
}
return PyErr_Format(PyExc_Exception, "uobject is not a USceneComponent");
}
```
|
/content/code_sandbox/Source/UnrealEnginePython/Private/UObject/UEPyTransform.cpp
|
c++
| 2016-08-07T05:00:51
| 2024-08-14T06:32:20
|
UnrealEnginePython
|
20tab/UnrealEnginePython
| 2,715
| 4,522
|
```c++
#include "UEPyWidgetComponent.h"
#include "Runtime/UMG/Public/Components/WidgetComponent.h"
#include "PyUserWidget.h"
#include "Slate/UEPySWidget.h"
PyObject *py_ue_set_slate_widget(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
PyObject *py_widget;
if (!PyArg_ParseTuple(args, "O", &py_widget))
{
return nullptr;
}
UWidgetComponent *widget_component = ue_py_check_type<UWidgetComponent>(self);
UPyUserWidget *py_user_widget = ue_py_check_type<UPyUserWidget>(self);
if (!widget_component && !py_user_widget)
return PyErr_Format(PyExc_Exception, "uobject is not a UWidgetComponent or UPyUserWidget");
TSharedPtr<SWidget> Widget = py_ue_is_swidget<SWidget>(py_widget);
if (!Widget.IsValid())
return nullptr;
if (widget_component) { widget_component->SetSlateWidget(Widget); }
else { py_user_widget->SetSlateWidget(Widget.ToSharedRef()); }
Py_RETURN_NONE;
}
```
|
/content/code_sandbox/Source/UnrealEnginePython/Private/UObject/UEPyWidgetComponent.cpp
|
c++
| 2016-08-07T05:00:51
| 2024-08-14T06:32:20
|
UnrealEnginePython
|
20tab/UnrealEnginePython
| 2,715
| 235
|
```c++
#include "UEPyPawn.h"
#include "GameFramework/Pawn.h"
#include "GameFramework/Controller.h"
PyObject *py_ue_pawn_get_controller(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
if (!self->ue_object->IsA<APawn>())
{
return PyErr_Format(PyExc_Exception, "uobject is not an APawn");
}
APawn *pawn = (APawn *)self->ue_object;
Py_RETURN_UOBJECT(pawn->GetController());
}
```
|
/content/code_sandbox/Source/UnrealEnginePython/Private/UObject/UEPyPawn.cpp
|
c++
| 2016-08-07T05:00:51
| 2024-08-14T06:32:20
|
UnrealEnginePython
|
20tab/UnrealEnginePython
| 2,715
| 112
|
```c++
#include "UEPyAttaching.h"
#include "Components/SceneComponent.h"
#include "GameFramework/Actor.h"
PyObject *py_ue_get_socket_location(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
char *socket_name;
if (!PyArg_ParseTuple(args, "s:get_socket_location", &socket_name))
{
return NULL;
}
if (!self->ue_object->IsA<USceneComponent>())
return PyErr_Format(PyExc_Exception, "uobject is not a USceneComponent");
USceneComponent *component = (USceneComponent *)self->ue_object;
FVector vec = component->GetSocketLocation(UTF8_TO_TCHAR(socket_name));
return py_ue_new_fvector(vec);
}
PyObject *py_ue_get_socket_rotation(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
char *socket_name;
if (!PyArg_ParseTuple(args, "s:get_socket_rotation", &socket_name))
{
return NULL;
}
if (!self->ue_object->IsA<USceneComponent>())
return PyErr_Format(PyExc_Exception, "uobject is not a USceneComponent");
USceneComponent *component = (USceneComponent *)self->ue_object;
FRotator rot = component->GetSocketRotation(UTF8_TO_TCHAR(socket_name));
return py_ue_new_frotator(rot);
}
PyObject *py_ue_get_socket_transform(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
char *socket_name;
if (!PyArg_ParseTuple(args, "s:get_socket_transform", &socket_name))
{
return NULL;
}
if (!self->ue_object->IsA<USceneComponent>())
return PyErr_Format(PyExc_Exception, "uobject is not a USceneComponent");
USceneComponent *component = (USceneComponent *)self->ue_object;
FTransform transform = component->GetSocketTransform(UTF8_TO_TCHAR(socket_name), ERelativeTransformSpace::RTS_Component);
return py_ue_new_ftransform(transform);
}
PyObject *py_ue_get_socket_world_transform(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
char *socket_name;
if (!PyArg_ParseTuple(args, "s:get_socket_world_transform", &socket_name))
{
return NULL;
}
if (!self->ue_object->IsA<USceneComponent>())
return PyErr_Format(PyExc_Exception, "uobject is not a USceneComponent");
USceneComponent *component = (USceneComponent *)self->ue_object;
FTransform transform = component->GetSocketTransform(UTF8_TO_TCHAR(socket_name), ERelativeTransformSpace::RTS_World);
return py_ue_new_ftransform(transform);
}
PyObject *py_ue_get_socket_actor_transform(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
char *socket_name;
if (!PyArg_ParseTuple(args, "s:get_socket_actor_transform", &socket_name))
{
return NULL;
}
if (!self->ue_object->IsA<USceneComponent>())
return PyErr_Format(PyExc_Exception, "uobject is not a USceneComponent");
USceneComponent *component = (USceneComponent *)self->ue_object;
FTransform transform = component->GetSocketTransform(UTF8_TO_TCHAR(socket_name), ERelativeTransformSpace::RTS_Actor);
return py_ue_new_ftransform(transform);
}
PyObject *py_ue_get_all_child_actors(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
PyObject *py_include_descendants = NULL;
if (!PyArg_ParseTuple(args, "|O:get_all_child_actors", &py_include_descendants))
{
return NULL;
}
bool include_descendants = true;
if (py_include_descendants && !PyObject_IsTrue(py_include_descendants))
include_descendants = false;
AActor *actor = ue_get_actor(self);
if (!actor)
return PyErr_Format(PyExc_Exception, "cannot retrieve actor from UObject");
PyObject *py_children = PyList_New(0);
TArray<AActor *> children;
actor->GetAllChildActors(children, include_descendants);
for (AActor *child : children)
{
ue_PyUObject *item = ue_get_python_uobject(child);
if (item)
PyList_Append(py_children, (PyObject *)item);
}
return py_children;
}
PyObject *py_ue_get_attached_actors(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
AActor *actor = ue_get_actor(self);
if (!actor)
return PyErr_Format(PyExc_Exception, "cannot retrieve actor from UObject");
PyObject *py_children = PyList_New(0);
TArray<AActor *> children;
actor->GetAttachedActors(children);
for (AActor *child : children)
{
ue_PyUObject *item = ue_get_python_uobject(child);
if (item)
PyList_Append(py_children, (PyObject *)item);
}
return py_children;
}
PyObject *py_ue_attach_to_actor(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
PyObject *obj;
char *socket_name = (char *)"";
int location_rule = (int)EAttachmentRule::SnapToTarget;
int rotation_rule = (int)EAttachmentRule::KeepWorld;
int scale_rule = (int)EAttachmentRule::SnapToTarget;
PyObject *py_weld = nullptr;
if (!PyArg_ParseTuple(args, "O|siiiO:attach_to_actor", &obj, &socket_name, &location_rule, &rotation_rule, &scale_rule, &py_weld))
{
return NULL;
}
AActor *actor = ue_get_actor(self);
if (!actor)
return PyErr_Format(PyExc_Exception, "unable to retrieve Actor from uobject");
ue_PyUObject *py_obj = ue_is_pyuobject(obj);
if (!py_obj)
return PyErr_Format(PyExc_Exception, "argument is not a UObject");
if (!py_obj->ue_object->IsA<AActor>())
return PyErr_Format(PyExc_Exception, "argument is not an Actor");
AActor *other = (AActor *)py_obj->ue_object;
bool weld = false;
if (py_weld && PyObject_IsTrue(py_weld))
weld = true;
actor->AttachToActor(other, FAttachmentTransformRules((EAttachmentRule)location_rule, (EAttachmentRule)rotation_rule, (EAttachmentRule)scale_rule, weld), UTF8_TO_TCHAR(socket_name));
Py_INCREF(Py_None);
return Py_None;
}
PyObject *py_ue_attach_to_component(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
PyObject *obj;
char *socket_name = (char *)"";
int location_rule = (int)EAttachmentRule::SnapToTarget;
int rotation_rule = (int)EAttachmentRule::KeepWorld;
int scale_rule = (int)EAttachmentRule::SnapToTarget;
PyObject *py_weld = nullptr;
if (!PyArg_ParseTuple(args, "O|siiiO:attach_to_component", &obj, &socket_name, &location_rule, &rotation_rule, &scale_rule, &py_weld))
{
return NULL;
}
AActor *actor = ue_get_actor(self);
if (!actor)
return PyErr_Format(PyExc_Exception, "unable to retrieve Actor from uobject");
ue_PyUObject *py_obj = ue_is_pyuobject(obj);
if (!py_obj)
return PyErr_Format(PyExc_Exception, "argument is not a UObject");
if (!py_obj->ue_object->IsA<USceneComponent>())
return PyErr_Format(PyExc_Exception, "argument is not a SceneComponent");
USceneComponent *other = (USceneComponent *)py_obj->ue_object;
bool weld = false;
if (py_weld && PyObject_IsTrue(py_weld))
weld = true;
actor->AttachToComponent(other, FAttachmentTransformRules((EAttachmentRule)location_rule, (EAttachmentRule)rotation_rule, (EAttachmentRule)scale_rule, weld), UTF8_TO_TCHAR(socket_name));
Py_INCREF(Py_None);
return Py_None;
}
```
|
/content/code_sandbox/Source/UnrealEnginePython/Private/UObject/UEPyAttaching.cpp
|
c++
| 2016-08-07T05:00:51
| 2024-08-14T06:32:20
|
UnrealEnginePython
|
20tab/UnrealEnginePython
| 2,715
| 1,755
|
```objective-c
#pragma once
#include "UEPyModule.h"
PyObject *py_ue_get_socket_location(ue_PyUObject *, PyObject *);
PyObject *py_ue_get_socket_rotation(ue_PyUObject *, PyObject *);
PyObject *py_ue_get_socket_transform(ue_PyUObject *, PyObject *);
PyObject *py_ue_get_socket_world_transform(ue_PyUObject *, PyObject *);
PyObject *py_ue_get_socket_actor_transform(ue_PyUObject *, PyObject *);
PyObject *py_ue_get_attached_actors(ue_PyUObject *, PyObject *);
PyObject *py_ue_get_all_child_actors(ue_PyUObject *, PyObject *);
PyObject *py_ue_attach_to_actor(ue_PyUObject *, PyObject *);
PyObject *py_ue_attach_to_component(ue_PyUObject *, PyObject *);
```
|
/content/code_sandbox/Source/UnrealEnginePython/Private/UObject/UEPyAttaching.h
|
objective-c
| 2016-08-07T05:00:51
| 2024-08-14T06:32:20
|
UnrealEnginePython
|
20tab/UnrealEnginePython
| 2,715
| 161
|
```objective-c
#pragma once
#include "UEPyModule.h"
PyObject *py_ue_create_player(ue_PyUObject *, PyObject *);
PyObject *py_ue_get_num_players(ue_PyUObject *, PyObject *);
PyObject *py_ue_get_num_spectators(ue_PyUObject *, PyObject *);
PyObject *py_ue_get_player_controller(ue_PyUObject *, PyObject *);
PyObject *py_ue_get_player_hud(ue_PyUObject *, PyObject *);
PyObject *py_ue_get_player_camera_manager(ue_PyUObject *, PyObject *);
PyObject *py_ue_get_player_pawn(ue_PyUObject *, PyObject *);
PyObject *py_ue_set_player_hud(ue_PyUObject *, PyObject *);
PyObject *py_ue_restart_level(ue_PyUObject *, PyObject *);
```
|
/content/code_sandbox/Source/UnrealEnginePython/Private/UObject/UEPyPlayer.h
|
objective-c
| 2016-08-07T05:00:51
| 2024-08-14T06:32:20
|
UnrealEnginePython
|
20tab/UnrealEnginePython
| 2,715
| 160
|
```c++
#include "UEPyController.h"
#include "GameFramework/Controller.h"
#include "GameFramework/HUD.h"
#include "GameFramework/Pawn.h"
#include "GameFramework/PlayerController.h"
PyObject *py_ue_controller_posses(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
PyObject *obj;
if (!PyArg_ParseTuple(args, "O:posses", &obj))
{
return NULL;
}
AController *controller = ue_py_check_type<AController>(self);
if (!controller)
return PyErr_Format(PyExc_Exception, "uobject is not an AController");
APawn *pawn = ue_py_check_type<APawn>(obj);
if (!pawn)
return PyErr_Format(PyExc_Exception, "uobject is not an APawn");
controller->Possess(pawn);
Py_INCREF(Py_None);
return Py_None;
}
PyObject *py_ue_controller_get_hud(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
APlayerController *controller = ue_py_check_type<APlayerController>(self);
if (!controller)
return PyErr_Format(PyExc_Exception, "uobject is not an AController");
Py_RETURN_UOBJECT((UObject *)controller->GetHUD());
}
PyObject *py_ue_controller_unposses(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
AController *controller = ue_py_check_type<AController>(self);
if (!controller)
return PyErr_Format(PyExc_Exception, "uobject is not an AController");
controller->UnPossess();
Py_RETURN_NONE;
}
PyObject *py_ue_get_controlled_pawn(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
AController *controller = ue_py_check_type<AController>(self);
if (!controller)
return PyErr_Format(PyExc_Exception, "uobject is not an AController");
#if ENGINE_MINOR_VERSION >= 15
APawn *pawn = controller->GetPawn();
#else
APawn *pawn = controller->GetControlledPawn();
#endif
if (!pawn)
{
Py_RETURN_NONE;
}
Py_RETURN_UOBJECT(pawn);
}
PyObject *py_ue_controller_project_world_location_to_screen(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
PyObject *py_obj_point;
PyObject *py_relative = nullptr;
if (!PyArg_ParseTuple(args, "O|O:project_world_location_to_screen", &py_obj_point, &py_relative))
return nullptr;
APlayerController *controller = ue_py_check_type<APlayerController>(self);
if (!controller)
return PyErr_Format(PyExc_Exception, "uobject is not an AController");
ue_PyFVector *point = py_ue_is_fvector(py_obj_point);
if (!point)
return PyErr_Format(PyExc_Exception, "argument is not a FVector");
// TODO: Check return value:
FVector2D screenLocation;
if (!controller->ProjectWorldLocationToScreen(point->vec, screenLocation, (py_relative && PyObject_IsTrue(py_relative))))
{
return PyErr_Format(PyExc_Exception, "unable to project coordinates");
}
return Py_BuildValue("(ff)", screenLocation.X, screenLocation.Y);
}
```
|
/content/code_sandbox/Source/UnrealEnginePython/Private/UObject/UEPyController.cpp
|
c++
| 2016-08-07T05:00:51
| 2024-08-14T06:32:20
|
UnrealEnginePython
|
20tab/UnrealEnginePython
| 2,715
| 688
|
```objective-c
#pragma once
#include "UEPyModule.h"
PyObject *py_ue_texture_get_data(ue_PyUObject *, PyObject *);
PyObject *py_ue_render_target_get_data(ue_PyUObject *, PyObject *);
PyObject *py_ue_render_target_get_data_to_buffer(ue_PyUObject *, PyObject *);
PyObject *py_ue_texture_set_data(ue_PyUObject *, PyObject *);
PyObject *py_ue_texture_get_width(ue_PyUObject *, PyObject *);
PyObject *py_ue_texture_get_height(ue_PyUObject *, PyObject *);
PyObject *py_ue_texture_has_alpha_channel(ue_PyUObject *, PyObject *);
PyObject *py_unreal_engine_compress_image_array(PyObject *, PyObject *);
PyObject *py_unreal_engine_create_checkerboard_texture(PyObject *, PyObject *);
PyObject *py_unreal_engine_create_transient_texture(PyObject *, PyObject *);
PyObject *py_unreal_engine_create_transient_texture_render_target2d(PyObject *, PyObject *);
PyObject *py_ue_texture_update_resource(ue_PyUObject *, PyObject *);
#if WITH_EDITOR
PyObject *py_unreal_engine_create_texture(PyObject * self, PyObject *);
PyObject *py_ue_texture_get_source_data(ue_PyUObject *, PyObject *);
PyObject *py_ue_texture_set_source_data(ue_PyUObject *, PyObject *);
#endif
```
|
/content/code_sandbox/Source/UnrealEnginePython/Private/UObject/UEPyTexture.h
|
objective-c
| 2016-08-07T05:00:51
| 2024-08-14T06:32:20
|
UnrealEnginePython
|
20tab/UnrealEnginePython
| 2,715
| 255
|
```c++
#include "UEPyNavigation.h"
#if ENGINE_MINOR_VERSION < 20
#include "AI/Navigation/NavigationSystem.h"
#else
#include "Blueprint/AIBlueprintHelperLibrary.h"
#endif
#include "GameFramework/Pawn.h"
#include "Engine/World.h"
PyObject *py_ue_simple_move_to_location(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
FVector vec;
if (!py_ue_vector_arg(args, vec))
return NULL;
UWorld *world = ue_get_uworld(self);
if (!world)
return PyErr_Format(PyExc_Exception, "unable to retrieve UWorld from uobject");
APawn *pawn = nullptr;
if (self->ue_object->IsA<APawn>())
{
pawn = (APawn *)self->ue_object;
}
else if (self->ue_object->IsA<UActorComponent>())
{
UActorComponent *component = (UActorComponent *)self->ue_object;
AActor *actor = component->GetOwner();
if (actor)
{
if (actor->IsA<APawn>())
{
pawn = (APawn *)actor;
}
}
}
if (!pawn)
return PyErr_Format(PyExc_Exception, "uobject is not a pawn");
AController *controller = pawn->GetController();
if (!controller)
return PyErr_Format(PyExc_Exception, "Pawn has no controller");
#if ENGINE_MINOR_VERSION < 20
world->GetNavigationSystem()->SimpleMoveToLocation(controller, vec);
#else
UAIBlueprintHelperLibrary::SimpleMoveToLocation(controller, vec);
#endif
Py_RETURN_NONE;
}
```
|
/content/code_sandbox/Source/UnrealEnginePython/Private/UObject/UEPyNavigation.cpp
|
c++
| 2016-08-07T05:00:51
| 2024-08-14T06:32:20
|
UnrealEnginePython
|
20tab/UnrealEnginePython
| 2,715
| 352
|
```objective-c
#pragma once
#include "UEPyModule.h"
PyObject *py_ue_export_to_file(ue_PyUObject *, PyObject *);
```
|
/content/code_sandbox/Source/UnrealEnginePython/Private/UObject/UEPyExporter.h
|
objective-c
| 2016-08-07T05:00:51
| 2024-08-14T06:32:20
|
UnrealEnginePython
|
20tab/UnrealEnginePython
| 2,715
| 28
|
```objective-c
#pragma once
#include "UEPyModule.h"
PyObject *py_ue_simple_move_to_location(ue_PyUObject *, PyObject *);
```
|
/content/code_sandbox/Source/UnrealEnginePython/Private/UObject/UEPyNavigation.h
|
objective-c
| 2016-08-07T05:00:51
| 2024-08-14T06:32:20
|
UnrealEnginePython
|
20tab/UnrealEnginePython
| 2,715
| 29
|
```objective-c
#pragma once
#include "UEPyModule.h"
PyObject *py_ue_sequencer_master_tracks(ue_PyUObject *, PyObject *);
PyObject *py_ue_sequencer_possessable_tracks(ue_PyUObject *, PyObject *);
PyObject *py_ue_sequencer_track_sections(ue_PyUObject *, PyObject *);
PyObject *py_ue_sequencer_get_camera_cut_track(ue_PyUObject *, PyObject *);
#if WITH_EDITOR
PyObject *py_ue_sequencer_set_playback_range(ue_PyUObject *, PyObject *);
PyObject *py_ue_sequencer_set_view_range(ue_PyUObject *, PyObject *);
PyObject *py_ue_sequencer_set_working_range(ue_PyUObject *, PyObject *);
PyObject *py_ue_sequencer_set_section_range(ue_PyUObject *, PyObject *);
PyObject *py_ue_sequencer_get_playback_range(ue_PyUObject *, PyObject *);
PyObject *py_ue_sequencer_get_selection_range(ue_PyUObject *, PyObject *);
PyObject *py_ue_sequencer_folders(ue_PyUObject *, PyObject *);
PyObject *py_ue_sequencer_create_folder(ue_PyUObject *, PyObject *);
PyObject *py_ue_sequencer_set_display_name(ue_PyUObject *, PyObject *);
PyObject *py_ue_sequencer_get_display_name(ue_PyUObject *, PyObject *);
PyObject *py_ue_sequencer_changed(ue_PyUObject *, PyObject *);
PyObject *py_ue_sequencer_section_add_key(ue_PyUObject *, PyObject *);
PyObject *py_ue_sequencer_add_camera_cut_track(ue_PyUObject *, PyObject *);
PyObject *py_ue_sequencer_add_possessable(ue_PyUObject *, PyObject *);
PyObject *py_ue_sequencer_track_add_section(ue_PyUObject *, PyObject *);
PyObject *py_ue_sequencer_add_actor(ue_PyUObject *, PyObject *);
PyObject *py_ue_sequencer_add_actor_component(ue_PyUObject *, PyObject *);
PyObject *py_ue_sequencer_make_new_spawnable(ue_PyUObject *, PyObject *);
PyObject *py_ue_sequencer_remove_possessable(ue_PyUObject *, PyObject *);
PyObject *py_ue_sequencer_remove_spawnable(ue_PyUObject *, PyObject *);
PyObject *py_ue_sequencer_remove_camera_cut_track(ue_PyUObject *, PyObject *);
PyObject *py_ue_sequencer_remove_master_track(ue_PyUObject *, PyObject *);
PyObject *py_ue_sequencer_remove_track(ue_PyUObject *, PyObject *);
PyObject *py_ue_sequencer_import_fbx_transform(ue_PyUObject *, PyObject *);
#endif
PyObject *py_ue_sequencer_sections(ue_PyUObject *, PyObject *);
PyObject *py_ue_sequencer_possessables(ue_PyUObject *, PyObject *);
PyObject *py_ue_sequencer_possessables_guid(ue_PyUObject *, PyObject *);
PyObject *py_ue_sequencer_find_possessable(ue_PyUObject *, PyObject *);
PyObject *py_ue_sequencer_find_spawnable(ue_PyUObject *, PyObject *);
PyObject *py_ue_sequencer_add_master_track(ue_PyUObject *, PyObject *);
PyObject *py_ue_sequencer_add_track(ue_PyUObject *, PyObject *);
```
|
/content/code_sandbox/Source/UnrealEnginePython/Private/UObject/UEPySequencer.h
|
objective-c
| 2016-08-07T05:00:51
| 2024-08-14T06:32:20
|
UnrealEnginePython
|
20tab/UnrealEnginePython
| 2,715
| 689
|
```c++
#include "UEPySequencer.h"
#include "Runtime/MovieScene/Public/MovieScene.h"
#include "Runtime/MovieScene/Public/MovieScenePossessable.h"
#include "Runtime/MovieScene/Public/MovieSceneBinding.h"
#include "Runtime/MovieScene/Public/MovieSceneTrack.h"
#include "Runtime/MovieScene/Public/MovieSceneNameableTrack.h"
#include "Runtime/LevelSequence/Public/LevelSequence.h"
#if WITH_EDITOR
#include "Editor/Sequencer/Public/ISequencer.h"
#include "Editor/Sequencer/Public/ISequencerModule.h"
#include "Editor/UnrealEd/Public/Toolkits/AssetEditorManager.h"
#if ENGINE_MINOR_VERSION >= 20
#include "LevelSequenceEditor/Private/LevelSequenceEditorToolkit.h"
#else
#include "Private/LevelSequenceEditorToolkit.h"
#endif
#include "Tracks/MovieSceneCameraCutTrack.h"
#if ENGINE_MINOR_VERSION < 20
#include "Sections/IKeyframeSection.h"
#endif
#include "Sections/MovieSceneFloatSection.h"
#include "Sections/MovieSceneBoolSection.h"
#include "Sections/MovieScene3DTransformSection.h"
#include "Sections/MovieSceneVectorSection.h"
#include "Runtime/MovieScene/Public/MovieSceneFolder.h"
#include "Runtime/MovieScene/Public/MovieSceneSpawnable.h"
#include "Runtime/MovieScene/Public/MovieScenePossessable.h"
#if ENGINE_MINOR_VERSION < 18
#include "Editor/UnrealEd/Private/FbxImporter.h"
#else
#include "Editor/UnrealEd/Public/FbxImporter.h"
#endif
#include "Editor/MovieSceneTools/Public/MatineeImportTools.h"
#endif
#include "GameFramework/Actor.h"
#include "Runtime/LevelSequence/Public/LevelSequence.h"
#include "Engine/World.h"
#if ENGINE_MINOR_VERSION >= 20
#include "Wrappers/UEPyFFrameNumber.h"
#endif
#if ENGINE_MINOR_VERSION >= 20
static bool magic_get_frame_number(UMovieScene *MovieScene, PyObject *py_obj, FFrameNumber *dest)
{
ue_PyFFrameNumber *py_frame_number = py_ue_is_fframe_number(py_obj);
if (py_frame_number)
{
*dest = py_frame_number->frame_number;
return true;
}
if (PyNumber_Check(py_obj))
{
PyObject *f_value = PyNumber_Float(py_obj);
float value = PyFloat_AsDouble(f_value);
Py_DECREF(f_value);
*dest = MovieScene->GetTickResolution().AsFrameNumber(value);
return true;
}
return false;
}
#if WITH_EDITOR
#if ENGINE_MINOR_VERSION > 21
static void ImportTransformChannel(const FRichCurve& Source, FMovieSceneFloatChannel* Dest, FFrameRate DestFrameRate, bool bNegateTangents)
{
TMovieSceneChannelData<FMovieSceneFloatValue> ChannelData = Dest->GetData();
ChannelData.Reset();
double DecimalRate = DestFrameRate.AsDecimal();
for (int32 KeyIndex = 0; KeyIndex < Source.Keys.Num(); ++KeyIndex)
{
float ArriveTangent = Source.Keys[KeyIndex].ArriveTangent;
if (KeyIndex > 0)
{
ArriveTangent = ArriveTangent / ((Source.Keys[KeyIndex].Value - Source.Keys[KeyIndex - 1].Value) * DecimalRate);
}
float LeaveTangent = Source.Keys[KeyIndex].LeaveTangent;
if (KeyIndex < Source.Keys.Num() - 1)
{
LeaveTangent = LeaveTangent / ((Source.Keys[KeyIndex + 1].Value - Source.Keys[KeyIndex].Value) * DecimalRate);
}
if (bNegateTangents)
{
ArriveTangent = -ArriveTangent;
LeaveTangent = -LeaveTangent;
}
FFrameNumber KeyTime = (Source.Keys[KeyIndex].Value * DestFrameRate).RoundToFrame();
if (ChannelData.FindKey(KeyTime) == INDEX_NONE)
{
FMovieSceneFloatValue NewKey(Source.Keys[KeyIndex].Value);
NewKey.InterpMode = Source.Keys[KeyIndex].InterpMode;
NewKey.TangentMode = Source.Keys[KeyIndex].TangentMode;
NewKey.Tangent.ArriveTangent = ArriveTangent / DestFrameRate.AsDecimal();
NewKey.Tangent.LeaveTangent = LeaveTangent / DestFrameRate.AsDecimal();
NewKey.Tangent.TangentWeightMode = RCTWM_WeightedNone;
NewKey.Tangent.ArriveTangentWeight = 0.0f;
NewKey.Tangent.LeaveTangentWeight = 0.0f;
ChannelData.AddKey(KeyTime, NewKey);
}
}
Dest->AutoSetTangents();
}
#else
static void ImportTransformChannel(const FInterpCurveFloat& Source, FMovieSceneFloatChannel* Dest, FFrameRate DestFrameRate, bool bNegateTangents)
{
TMovieSceneChannelData<FMovieSceneFloatValue> ChannelData = Dest->GetData();
ChannelData.Reset();
double DecimalRate = DestFrameRate.AsDecimal();
for (int32 KeyIndex = 0; KeyIndex < Source.Points.Num(); ++KeyIndex)
{
float ArriveTangent = Source.Points[KeyIndex].ArriveTangent;
if (KeyIndex > 0)
{
ArriveTangent = ArriveTangent / ((Source.Points[KeyIndex].InVal - Source.Points[KeyIndex - 1].InVal) * DecimalRate);
}
float LeaveTangent = Source.Points[KeyIndex].LeaveTangent;
if (KeyIndex < Source.Points.Num() - 1)
{
LeaveTangent = LeaveTangent / ((Source.Points[KeyIndex + 1].InVal - Source.Points[KeyIndex].InVal) * DecimalRate);
}
if (bNegateTangents)
{
ArriveTangent = -ArriveTangent;
LeaveTangent = -LeaveTangent;
}
FFrameNumber KeyTime = (Source.Points[KeyIndex].InVal * DestFrameRate).RoundToFrame();
#if ENGINE_MINOR_VERSION > 20
FMatineeImportTools::SetOrAddKey(ChannelData, KeyTime, Source.Points[KeyIndex].OutVal, ArriveTangent, LeaveTangent, Source.Points[KeyIndex].InterpMode, DestFrameRate);
#else
FMatineeImportTools::SetOrAddKey(ChannelData, KeyTime, Source.Points[KeyIndex].OutVal, ArriveTangent, LeaveTangent, Source.Points[KeyIndex].InterpMode);
#endif
}
Dest->AutoSetTangents();
}
#endif
static bool ImportFBXTransform(FString NodeName, UMovieScene3DTransformSection* TransformSection, UnFbx::FFbxCurvesAPI& CurveAPI)
{
// Look for transforms explicitly
FTransform DefaultTransform;
#if ENGINE_MINOR_VERSION > 21
FRichCurve Translation[3];
FRichCurve EulerRotation[3];
FRichCurve Scale[3];
#else
FInterpCurveFloat Translation[3];
FInterpCurveFloat EulerRotation[3];
FInterpCurveFloat Scale[3];
#endif
CurveAPI.GetConvertedTransformCurveData(NodeName, Translation[0], Translation[1], Translation[2], EulerRotation[0], EulerRotation[1], EulerRotation[2], Scale[0], Scale[1], Scale[2], DefaultTransform);
TransformSection->Modify();
FFrameRate FrameRate = TransformSection->GetTypedOuter<UMovieScene>()->GetTickResolution();
FVector Location = DefaultTransform.GetLocation(), Rotation = DefaultTransform.GetRotation().Euler(), Scale3D = DefaultTransform.GetScale3D();
TArrayView<FMovieSceneFloatChannel*> Channels = TransformSection->GetChannelProxy().GetChannels<FMovieSceneFloatChannel>();
Channels[0]->SetDefault(Location.X);
Channels[1]->SetDefault(Location.Y);
Channels[2]->SetDefault(Location.Z);
Channels[3]->SetDefault(Rotation.X);
Channels[4]->SetDefault(Rotation.Y);
Channels[5]->SetDefault(Rotation.Z);
Channels[6]->SetDefault(Scale3D.X);
Channels[7]->SetDefault(Scale3D.Y);
Channels[8]->SetDefault(Scale3D.Z);
ImportTransformChannel(Translation[0], Channels[0], FrameRate, false);
ImportTransformChannel(Translation[1], Channels[1], FrameRate, true);
ImportTransformChannel(Translation[2], Channels[2], FrameRate, false);
ImportTransformChannel(EulerRotation[0], Channels[3], FrameRate, false);
ImportTransformChannel(EulerRotation[1], Channels[4], FrameRate, true);
ImportTransformChannel(EulerRotation[2], Channels[5], FrameRate, true);
ImportTransformChannel(Scale[0], Channels[6], FrameRate, false);
ImportTransformChannel(Scale[1], Channels[7], FrameRate, false);
ImportTransformChannel(Scale[2], Channels[8], FrameRate, false);
return true;
}
#endif
#endif
#if WITH_EDITOR
PyObject *py_ue_sequencer_changed(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
PyObject *py_bool = nullptr;
if (!PyArg_ParseTuple(args, "|O:sequencer_changed", &py_bool))
{
return NULL;
}
bool force_open = false;
if (!self->ue_object->IsA<ULevelSequence>())
return PyErr_Format(PyExc_Exception, "uobject is not a LevelSequence");
ULevelSequence *seq = (ULevelSequence *)self->ue_object;
if (py_bool && PyObject_IsTrue(py_bool))
{
// try to open the editor for the asset
FAssetEditorManager::Get().OpenEditorForAsset(seq);
}
IAssetEditorInstance *editor = FAssetEditorManager::Get().FindEditorForAsset(seq, true);
if (editor)
{
FLevelSequenceEditorToolkit *toolkit = (FLevelSequenceEditorToolkit *)editor;
ISequencer *sequencer = toolkit->GetSequencer().Get();
#if ENGINE_MINOR_VERSION < 13
sequencer->NotifyMovieSceneDataChanged();
#else
#if ENGINE_MINOR_VERSION > 16
sequencer->NotifyMovieSceneDataChanged(EMovieSceneDataChangeType::RefreshAllImmediately);
#else
sequencer->NotifyMovieSceneDataChanged(EMovieSceneDataChangeType::Unknown);
#endif
#endif
}
Py_RETURN_NONE;
}
#endif
PyObject *py_ue_sequencer_possessable_tracks(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
PyObject *py_possessable;
if (!PyArg_ParseTuple(args, "O:sequencer_possessable_tracks", &py_possessable))
{
return NULL;
}
if (!self->ue_object->IsA<ULevelSequence>())
return PyErr_Format(PyExc_Exception, "uobject is not a LevelSequence");
FGuid f_guid;
if (PyUnicodeOrString_Check(py_possessable))
{
const char *guid = UEPyUnicode_AsUTF8(py_possessable);
if (!FGuid::Parse(FString(guid), f_guid))
{
return PyErr_Format(PyExc_Exception, "invalid GUID");
}
}
else
{
FMovieScenePossessable *possessable = (FMovieScenePossessable *)do_ue_py_check_struct(py_possessable, FMovieScenePossessable::StaticStruct());
if (possessable)
{
f_guid = possessable->GetGuid();
}
}
if (!f_guid.IsValid())
{
return PyErr_Format(PyExc_Exception, "invalid GUID");
}
ULevelSequence *seq = (ULevelSequence *)self->ue_object;
UMovieScene *scene = seq->GetMovieScene();
PyObject *py_tracks = PyList_New(0);
FMovieScenePossessable *possessable = scene->FindPossessable(f_guid);
if (!possessable)
return PyErr_Format(PyExc_Exception, "GUID not found");
TArray<FMovieSceneBinding> bindings = scene->GetBindings();
for (FMovieSceneBinding binding : bindings)
{
if (binding.GetObjectGuid() != f_guid)
continue;
for (UMovieSceneTrack *track : binding.GetTracks())
{
ue_PyUObject *ret = ue_get_python_uobject((UObject *)track);
if (!ret)
{
Py_DECREF(py_tracks);
return PyErr_Format(PyExc_Exception, "PyUObject is in invalid state");
}
PyList_Append(py_tracks, (PyObject *)ret);
}
break;
}
return py_tracks;
}
PyObject *py_ue_sequencer_find_possessable(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
char *guid;
PyObject *py_parent = nullptr;
if (!PyArg_ParseTuple(args, "s|O:sequencer_find_possessable", &guid, &py_parent))
{
return nullptr;
}
ULevelSequence *seq = ue_py_check_type<ULevelSequence>(self);
if (!seq)
{
return PyErr_Format(PyExc_Exception, "uobject is not a ULevelSequence");
}
FGuid f_guid;
if (!FGuid::Parse(FString(guid), f_guid))
{
return PyErr_Format(PyExc_Exception, "invalid GUID");
}
#if ENGINE_MINOR_VERSION < 15
UObject *u_obj = seq->FindPossessableObject(f_guid, seq);
#else
UObject *parent = nullptr;
if (py_parent)
{
parent = ue_py_check_type<UObject>(py_parent);
if (!parent)
{
return PyErr_Format(PyExc_Exception, "argument is not a UObject");
}
}
UObject *u_obj = nullptr;
TArray<UObject *, TInlineAllocator<1>> u_objects;
seq->LocateBoundObjects(f_guid, parent, u_objects);
if (u_objects.Num() > 0)
{
u_obj = u_objects[0];
}
#endif
if (!u_obj)
return PyErr_Format(PyExc_Exception, "unable to find uobject with GUID \"%s\"", guid);
Py_RETURN_UOBJECT(u_obj);
}
PyObject *py_ue_sequencer_find_spawnable(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
char *guid;
if (!PyArg_ParseTuple(args, "s:sequencer_find_spawnable", &guid))
{
return NULL;
}
if (!self->ue_object->IsA<ULevelSequence>())
return PyErr_Format(PyExc_Exception, "uobject is not a LevelSequence");
FGuid f_guid;
if (!FGuid::Parse(FString(guid), f_guid))
{
return PyErr_Format(PyExc_Exception, "invalid GUID");
}
ULevelSequence *seq = (ULevelSequence *)self->ue_object;
FMovieSceneSpawnable *spawnable = seq->MovieScene->FindSpawnable(f_guid);
PyObject *ret = py_ue_new_owned_uscriptstruct(spawnable->StaticStruct(), (uint8 *)spawnable);
Py_INCREF(ret);
return ret;
}
#if WITH_EDITOR
PyObject *py_ue_sequencer_add_possessable(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
PyObject *py_obj;
if (!PyArg_ParseTuple(args, "O:sequencer_add_possessable", &py_obj))
{
return NULL;
}
if (!self->ue_object->IsA<ULevelSequence>())
return PyErr_Format(PyExc_Exception, "uobject is not a LevelSequence");
ue_PyUObject *py_ue_obj = ue_is_pyuobject(py_obj);
if (!py_ue_obj)
return PyErr_Format(PyExc_Exception, "argument is not a uobject");
ULevelSequence *seq = (ULevelSequence *)self->ue_object;
FString name = py_ue_obj->ue_object->GetName();
AActor *actor = Cast<AActor>(py_ue_obj->ue_object);
if (actor)
name = actor->GetActorLabel();
FGuid new_guid = seq->MovieScene->AddPossessable(name, py_ue_obj->ue_object->GetClass());
if (!new_guid.IsValid())
{
return PyErr_Format(PyExc_Exception, "unable to possess object");
}
seq->BindPossessableObject(new_guid, *(py_ue_obj->ue_object), py_ue_obj->ue_object->GetWorld());
return PyUnicode_FromString(TCHAR_TO_UTF8(*new_guid.ToString()));
}
PyObject *py_ue_sequencer_add_actor(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
PyObject *py_obj;
if (!PyArg_ParseTuple(args, "O:sequencer_add_actor", &py_obj))
{
return NULL;
}
if (!self->ue_object->IsA<ULevelSequence>())
return PyErr_Format(PyExc_Exception, "uobject is not a LevelSequence");
ue_PyUObject *py_ue_obj = ue_is_pyuobject(py_obj);
if (!py_ue_obj)
return PyErr_Format(PyExc_Exception, "argument is not a uobject");
if (!py_ue_obj->ue_object->IsA<AActor>())
return PyErr_Format(PyExc_Exception, "argument is not an actor");
ULevelSequence *seq = (ULevelSequence *)self->ue_object;
TArray<TWeakObjectPtr<AActor>> actors;
actors.Add((AActor *)py_ue_obj->ue_object);
// try to open the editor for the asset
FAssetEditorManager::Get().OpenEditorForAsset(seq);
IAssetEditorInstance *editor = FAssetEditorManager::Get().FindEditorForAsset(seq, true);
if (editor)
{
FLevelSequenceEditorToolkit *toolkit = (FLevelSequenceEditorToolkit *)editor;
ISequencer *sequencer = toolkit->GetSequencer().Get();
sequencer->AddActors(actors);
}
else
{
return PyErr_Format(PyExc_Exception, "unable to access sequencer");
}
UObject& u_obj = *actors[0];
#if ENGINE_MINOR_VERSION < 15
FGuid new_guid = seq->FindPossessableObjectId(u_obj);
#else
FGuid new_guid = seq->FindPossessableObjectId(u_obj, u_obj.GetWorld());
#endif
if (!new_guid.IsValid())
{
return PyErr_Format(PyExc_Exception, "unable to find guid");
}
return PyUnicode_FromString(TCHAR_TO_UTF8(*new_guid.ToString()));
}
PyObject *py_ue_sequencer_add_actor_component(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
PyObject *py_obj;
if (!PyArg_ParseTuple(args, "O:sequencer_add_actor_component", &py_obj))
{
return NULL;
}
if (!self->ue_object->IsA<ULevelSequence>())
return PyErr_Format(PyExc_Exception, "uobject is not a LevelSequence");
ue_PyUObject *py_ue_obj = ue_is_pyuobject(py_obj);
if (!py_ue_obj)
return PyErr_Format(PyExc_Exception, "argument is not a uobject");
if (!py_ue_obj->ue_object->IsA<UActorComponent>())
return PyErr_Format(PyExc_Exception, "argument is not an actorcomponent");
ULevelSequence *seq = (ULevelSequence *)self->ue_object;
UActorComponent* actorComponent = (UActorComponent *)py_ue_obj->ue_object;
// try to open the editor for the asset
FAssetEditorManager::Get().OpenEditorForAsset(seq);
IAssetEditorInstance *editor = FAssetEditorManager::Get().FindEditorForAsset(seq, true);
FGuid new_guid;
if (editor)
{
FLevelSequenceEditorToolkit *toolkit = (FLevelSequenceEditorToolkit *)editor;
ISequencer *sequencer = toolkit->GetSequencer().Get();
new_guid = sequencer->GetHandleToObject(actorComponent);
}
else
{
return PyErr_Format(PyExc_Exception, "unable to access sequencer");
}
if (!new_guid.IsValid())
{
return PyErr_Format(PyExc_Exception, "unable to find guid");
}
return PyUnicode_FromString(TCHAR_TO_UTF8(*new_guid.ToString()));
}
PyObject *py_ue_sequencer_make_new_spawnable(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
PyObject *py_obj;
if (!PyArg_ParseTuple(args, "O:sequencer_make_new_spawnable", &py_obj))
{
return NULL;
}
if (!self->ue_object->IsA<ULevelSequence>())
return PyErr_Format(PyExc_Exception, "uobject is not a LevelSequence");
ue_PyUObject *py_ue_obj = ue_is_pyuobject(py_obj);
if (!py_ue_obj)
return PyErr_Format(PyExc_Exception, "argument is not a uobject");
if (!py_ue_obj->ue_object->IsA<AActor>())
return PyErr_Format(PyExc_Exception, "argument is not an actor");
AActor *actor = (AActor *)py_ue_obj->ue_object;
ULevelSequence *seq = (ULevelSequence *)self->ue_object;
// try to open the editor for the asset
FAssetEditorManager::Get().OpenEditorForAsset(seq);
IAssetEditorInstance *editor = FAssetEditorManager::Get().FindEditorForAsset(seq, true);
if (!editor)
{
return PyErr_Format(PyExc_Exception, "unable to access sequencer");
}
FLevelSequenceEditorToolkit *toolkit = (FLevelSequenceEditorToolkit *)editor;
ISequencer *sequencer = toolkit->GetSequencer().Get();
FGuid new_guid = sequencer->MakeNewSpawnable(*actor);
return PyUnicode_FromString(TCHAR_TO_UTF8(*new_guid.ToString()));
}
#endif
PyObject *py_ue_sequencer_master_tracks(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
if (!self->ue_object->IsA<ULevelSequence>())
return PyErr_Format(PyExc_Exception, "uobject is not a LevelSequence");
ULevelSequence *seq = (ULevelSequence *)self->ue_object;
UMovieScene *scene = seq->GetMovieScene();
PyObject *py_tracks = PyList_New(0);
TArray<UMovieSceneTrack *> tracks = scene->GetMasterTracks();
for (UMovieSceneTrack *track : tracks)
{
ue_PyUObject *ret = ue_get_python_uobject((UObject *)track);
if (!ret)
{
Py_DECREF(py_tracks);
return PyErr_Format(PyExc_Exception, "PyUObject is in invalid state");
}
PyList_Append(py_tracks, (PyObject *)ret);
}
return py_tracks;
}
PyObject *py_ue_sequencer_get_camera_cut_track(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
if (!self->ue_object->IsA<ULevelSequence>())
return PyErr_Format(PyExc_Exception, "uobject is not a LevelSequence");
ULevelSequence *seq = (ULevelSequence *)self->ue_object;
UMovieScene *scene = seq->GetMovieScene();
UMovieSceneTrack *track = scene->GetCameraCutTrack();
if (!track)
{
return PyErr_Format(PyExc_Exception, "unable to find camera cut track");
}
Py_RETURN_UOBJECT(track);
}
PyObject *py_ue_sequencer_possessables(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
if (!self->ue_object->IsA<ULevelSequence>())
return PyErr_Format(PyExc_Exception, "uobject is not a LevelSequence");
ULevelSequence *seq = (ULevelSequence *)self->ue_object;
UMovieScene *scene = seq->GetMovieScene();
PyObject *py_possessables = PyList_New(0);
for (int32 i = 0; i < scene->GetPossessableCount(); i++)
{
FMovieScenePossessable possessable = scene->GetPossessable(i);
PyObject *py_possessable = py_ue_new_owned_uscriptstruct(possessable.StaticStruct(), (uint8 *)&possessable);
PyList_Append(py_possessables, py_possessable);
}
return py_possessables;
}
PyObject *py_ue_sequencer_possessables_guid(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
if (!self->ue_object->IsA<ULevelSequence>())
return PyErr_Format(PyExc_Exception, "uobject is not a LevelSequence");
ULevelSequence *seq = (ULevelSequence *)self->ue_object;
UMovieScene *scene = seq->GetMovieScene();
PyObject *py_possessables = PyList_New(0);
for (int32 i = 0; i < scene->GetPossessableCount(); i++)
{
FMovieScenePossessable possessable = scene->GetPossessable(i);
PyObject *py_possessable = PyUnicode_FromString(TCHAR_TO_UTF8(*possessable.GetGuid().ToString()));
PyList_Append(py_possessables, py_possessable);
}
return py_possessables;
}
#if WITH_EDITOR
PyObject *py_ue_sequencer_folders(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
if (!self->ue_object->IsA<ULevelSequence>())
return PyErr_Format(PyExc_Exception, "uobject is not a LevelSequence");
PyObject *py_obj = nullptr;
if (!PyArg_ParseTuple(args, "|O:sequencer_folders", &py_obj))
{
return NULL;
}
UMovieSceneFolder *parent_folder = nullptr;
if (py_obj)
{
ue_PyUObject *ue_py_obj = ue_is_pyuobject(py_obj);
if (!ue_py_obj)
{
return PyErr_Format(PyExc_Exception, "argument is not a UObject");
}
parent_folder = Cast<UMovieSceneFolder>(ue_py_obj->ue_object);
if (!parent_folder)
{
return PyErr_Format(PyExc_Exception, "argument is not a UMovieSceneFolder");
}
}
ULevelSequence *seq = (ULevelSequence *)self->ue_object;
UMovieScene *scene = seq->GetMovieScene();
PyObject *py_folders = PyList_New(0);
TArray<UMovieSceneFolder *> folders;
if (!parent_folder)
folders = scene->GetRootFolders();
else
{
folders = parent_folder->GetChildFolders();
}
for (UMovieSceneFolder *folder : folders)
{
ue_PyUObject *ret = ue_get_python_uobject((UObject *)folder);
if (!ret)
{
Py_DECREF(py_folders);
return PyErr_Format(PyExc_Exception, "PyUObject is in invalid state");
}
PyList_Append(py_folders, (PyObject *)ret);
}
return py_folders;
}
PyObject *py_ue_sequencer_create_folder(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
if (!self->ue_object->IsA<ULevelSequence>())
return PyErr_Format(PyExc_Exception, "uobject is not a LevelSequence");
PyObject *py_obj = nullptr;
char *name;
if (!PyArg_ParseTuple(args, "s|O:sequencer_create_folder", &name, &py_obj))
{
return NULL;
}
UMovieSceneFolder *parent_folder = nullptr;
if (py_obj)
{
ue_PyUObject *ue_py_obj = ue_is_pyuobject(py_obj);
if (!ue_py_obj)
{
return PyErr_Format(PyExc_Exception, "argument is not a UObject");
}
parent_folder = Cast<UMovieSceneFolder>(ue_py_obj->ue_object);
if (!parent_folder)
{
return PyErr_Format(PyExc_Exception, "argument is not a UMovieSceneFolder");
}
}
ULevelSequence *seq = (ULevelSequence *)self->ue_object;
UMovieScene *scene = seq->GetMovieScene();
UMovieSceneFolder *new_folder = NewObject<UMovieSceneFolder>(scene, NAME_None, RF_Transactional);
new_folder->SetFolderName(FName(name));
if (parent_folder)
{
parent_folder->Modify();
parent_folder->AddChildFolder(new_folder);
}
else
{
scene->Modify();
scene->GetRootFolders().Add(new_folder);
}
Py_RETURN_UOBJECT(new_folder);
}
#endif
PyObject *py_ue_sequencer_sections(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
if (!self->ue_object->IsA<ULevelSequence>())
return PyErr_Format(PyExc_Exception, "uobject is not a LevelSequence");
ULevelSequence *seq = (ULevelSequence *)self->ue_object;
UMovieScene *scene = seq->GetMovieScene();
PyObject *py_sections = PyList_New(0);
TArray<UMovieSceneSection *> sections = scene->GetAllSections();
for (UMovieSceneSection *section : sections)
{
ue_PyUObject *ret = ue_get_python_uobject((UObject *)section);
if (!ret)
{
Py_DECREF(py_sections);
return PyErr_Format(PyExc_Exception, "PyUObject is in invalid state");
}
PyList_Append(py_sections, (PyObject *)ret);
}
return py_sections;
}
PyObject *py_ue_sequencer_track_sections(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
if (!self->ue_object->IsA<UMovieSceneTrack>())
return PyErr_Format(PyExc_Exception, "uobject is not a UMovieSceneTrack");
UMovieSceneTrack *track = (UMovieSceneTrack *)self->ue_object;
PyObject *py_sections = PyList_New(0);
TArray<UMovieSceneSection *> sections = track->GetAllSections();
for (UMovieSceneSection *section : sections)
{
ue_PyUObject *ret = ue_get_python_uobject((UObject *)section);
if (!ret)
{
Py_DECREF(py_sections);
return PyErr_Format(PyExc_Exception, "PyUObject is in invalid state");
}
PyList_Append(py_sections, (PyObject *)ret);
}
return py_sections;
}
#if WITH_EDITOR
PyObject *py_ue_sequencer_track_add_section(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
PyObject *py_section = nullptr;
if (!PyArg_ParseTuple(args, "|O:sequencer_track_add_section", &py_section))
return nullptr;
UMovieSceneTrack *track = ue_py_check_type<UMovieSceneTrack>(self);
if (!track)
return PyErr_Format(PyExc_Exception, "uobject is not a UMovieSceneTrack");
UMovieSceneSection *new_section = nullptr;
if (!py_section)
{
new_section = track->CreateNewSection();
}
else
{
new_section = ue_py_check_type<UMovieSceneSection>(py_section);
if (!new_section)
{
UClass *u_class = ue_py_check_type<UClass>(py_section);
if (u_class && u_class->IsChildOf<UMovieSceneSection>())
{
new_section = NewObject<UMovieSceneSection>(track, u_class, NAME_None);
}
}
}
if (!new_section)
return PyErr_Format(PyExc_Exception, "argument is not a UMovieSceneSection");
track->AddSection(*new_section);
Py_RETURN_UOBJECT(new_section);
}
#endif
PyObject *py_ue_sequencer_add_master_track(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
PyObject *obj;
if (!PyArg_ParseTuple(args, "O:sequencer_add_master_track", &obj))
{
return NULL;
}
if (!self->ue_object->IsA<ULevelSequence>())
return PyErr_Format(PyExc_Exception, "uobject is not a LevelSequence");
ULevelSequence *seq = (ULevelSequence *)self->ue_object;
UMovieScene *scene = seq->GetMovieScene();
ue_PyUObject *py_obj = ue_is_pyuobject(obj);
if (!py_obj)
return PyErr_Format(PyExc_Exception, "argument is not a uobject");
if (!py_obj->ue_object->IsA<UClass>())
return PyErr_Format(PyExc_Exception, "uobject is not a UClass");
UClass *u_class = (UClass *)py_obj->ue_object;
if (!u_class->IsChildOf<UMovieSceneTrack>())
return PyErr_Format(PyExc_Exception, "uobject is not a UMovieSceneTrack class");
UMovieSceneTrack *track = scene->AddMasterTrack(u_class);
if (!track)
return PyErr_Format(PyExc_Exception, "unable to create new master track");
Py_RETURN_UOBJECT(track);
}
#if WITH_EDITOR
PyObject *py_ue_sequencer_set_playback_range(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
ULevelSequence *seq = ue_py_check_type<ULevelSequence>(self);
if (!seq)
return PyErr_Format(PyExc_Exception, "uobject is not a LevelSequence");
UMovieScene *scene = seq->GetMovieScene();
#if ENGINE_MINOR_VERSION < 20
float start_time;
float end_time;
if (!PyArg_ParseTuple(args, "ff:sequencer_set_playback_range", &start_time, &end_time))
{
return nullptr;
}
scene->SetPlaybackRange(start_time, end_time);
#else
PyObject *py_start;
PyObject *py_end;
if (!PyArg_ParseTuple(args, "OO:sequencer_set_playback_range", &py_start, &py_end))
{
return nullptr;
}
FFrameNumber FrameStart;
FFrameNumber FrameEnd;
if (!magic_get_frame_number(scene, py_start, &FrameStart))
return PyErr_Format(PyExc_Exception, "range must use float or FrameNumber");
if (!magic_get_frame_number(scene, py_end, &FrameEnd))
return PyErr_Format(PyExc_Exception, "range must use float or FrameNumber");
scene->SetPlaybackRange(TRange<FFrameNumber>::Inclusive(FrameStart, FrameEnd));
#endif
Py_RETURN_NONE;
}
PyObject *py_ue_sequencer_get_playback_range(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
ULevelSequence *seq = ue_py_check_type<ULevelSequence>(self);
if (!seq)
return PyErr_Format(PyExc_Exception, "uobject is not a LevelSequence");
UMovieScene *scene = seq->GetMovieScene();
#if ENGINE_MINOR_VERSION < 20
TRange<float> range = scene->GetPlaybackRange();
return Py_BuildValue("(ff)", range.GetLowerBoundValue(), range.GetUpperBoundValue());
#else
TRange<FFrameNumber> range = scene->GetPlaybackRange();
return Py_BuildValue("(OO)", py_ue_new_fframe_number(range.GetLowerBoundValue()), py_ue_new_fframe_number(range.GetUpperBoundValue()));
#endif
}
PyObject *py_ue_sequencer_set_working_range(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
ULevelSequence *seq = ue_py_check_type<ULevelSequence>(self);
if (!seq)
return PyErr_Format(PyExc_Exception, "uobject is not a LevelSequence");
UMovieScene *scene = seq->GetMovieScene();
float start_time;
float end_time;
if (!PyArg_ParseTuple(args, "ff:sequencer_set_working_range", &start_time, &end_time))
{
return nullptr;
}
scene->SetWorkingRange(start_time, end_time);
Py_RETURN_NONE;
}
PyObject *py_ue_sequencer_set_view_range(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
ULevelSequence *seq = ue_py_check_type<ULevelSequence>(self);
if (!seq)
return PyErr_Format(PyExc_Exception, "uobject is not a LevelSequence");
UMovieScene *scene = seq->GetMovieScene();
float start_time;
float end_time;
if (!PyArg_ParseTuple(args, "ff:sequencer_set_view_range", &start_time, &end_time))
{
return nullptr;
}
scene->SetViewRange(start_time, end_time);
Py_RETURN_NONE;
}
PyObject *py_ue_sequencer_set_section_range(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
UMovieSceneSection *section = ue_py_check_type<UMovieSceneSection>(self);
if (!section)
return PyErr_Format(PyExc_Exception, "uobject is not a MovieSceneSection");
#if ENGINE_MINOR_VERSION < 20
float start_time;
float end_time;
if (!PyArg_ParseTuple(args, "ff:sequencer_set_section_range", &start_time, &end_time))
{
return nullptr;
}
#if ENGINE_MINOR_VERSION > 17
section->SetRange(TRange<float>::Inclusive(start_time, end_time));
#else
section->SetRange(TRange<float>(TRangeBound<float>::Inclusive(start_time), TRangeBound<float>::Inclusive(end_time)));
#endif
#else
PyObject *py_start;
PyObject *py_end;
if (!PyArg_ParseTuple(args, "OO:sequencer_set_section_range", &py_start, &py_end))
{
return nullptr;
}
UMovieSceneTrack *Track = section->GetTypedOuter<UMovieSceneTrack>();
if (!Track)
return PyErr_Format(PyExc_Exception, "unable to retrieve track from section");
UMovieScene *MovieScene = Track->GetTypedOuter<UMovieScene>();
if (!MovieScene)
return PyErr_Format(PyExc_Exception, "unable to retrieve scene from section");
FFrameNumber FrameStart;
FFrameNumber FrameEnd;
if (!magic_get_frame_number(MovieScene, py_start, &FrameStart))
return PyErr_Format(PyExc_Exception, "range must use float or FrameNumber");
if (!magic_get_frame_number(MovieScene, py_end, &FrameEnd))
return PyErr_Format(PyExc_Exception, "range must use float or FrameNumber");
section->SetRange(TRange<FFrameNumber>::Inclusive(FrameStart, FrameEnd));
#endif
Py_RETURN_NONE;
}
PyObject *py_ue_sequencer_get_selection_range(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
ULevelSequence *seq = ue_py_check_type<ULevelSequence>(self);
if (!seq)
return PyErr_Format(PyExc_Exception, "uobject is not a LevelSequence");
UMovieScene *scene = seq->GetMovieScene();
#if ENGINE_MINOR_VERSION < 20
TRange<float> range = scene->GetSelectionRange();
return Py_BuildValue("(ff)", range.GetLowerBoundValue(), range.GetUpperBoundValue());
#else
TRange<FFrameNumber> range = scene->GetSelectionRange();
return Py_BuildValue("(OO)", py_ue_new_fframe_number(range.GetLowerBoundValue()), py_ue_new_fframe_number(range.GetUpperBoundValue()));
#endif
}
PyObject *py_ue_sequencer_section_add_key(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
float time;
PyObject *py_value;
int interpolation = 0;
PyObject *py_unwind = nullptr;
if (!PyArg_ParseTuple(args, "fO|iO:sequencer_section_add_key", &time, &py_value, &interpolation, &py_unwind))
{
return nullptr;
}
UMovieSceneSection *section = ue_py_check_type<UMovieSceneSection>(self);
if (!section)
return PyErr_Format(PyExc_Exception, "uobject is not a MovieSceneSection");
#if ENGINE_MINOR_VERSION >= 20
UMovieSceneTrack *Track = section->GetTypedOuter<UMovieSceneTrack>();
if (!Track)
return PyErr_Format(PyExc_Exception, "unable to retrieve track from section");
UMovieScene *MovieScene = Track->GetTypedOuter<UMovieScene>();
if (!MovieScene)
return PyErr_Format(PyExc_Exception, "unable to retrieve scene from section");
FFrameNumber FrameNumber = MovieScene->GetTickResolution().AsFrameNumber(time);
EMovieSceneKeyInterpolation InterpolationMode = (EMovieSceneKeyInterpolation)interpolation;
section->Modify();
#endif
if (auto section_float = Cast<UMovieSceneFloatSection>(section))
{
if (PyNumber_Check(py_value))
{
PyObject *f_value = PyNumber_Float(py_value);
float value = PyFloat_AsDouble(f_value);
Py_DECREF(f_value);
#if ENGINE_MINOR_VERSION < 20
section_float->AddKey(time, value, (EMovieSceneKeyInterpolation)interpolation);
#else
FMovieSceneFloatChannel& Channel = (FMovieSceneFloatChannel&)section_float->GetChannel();
int32 RetValue = -1;
switch (InterpolationMode)
{
case(EMovieSceneKeyInterpolation::Auto):
RetValue = Channel.AddCubicKey(FrameNumber, value, RCTM_Auto);
break;
case(EMovieSceneKeyInterpolation::User):
RetValue = Channel.AddCubicKey(FrameNumber, value, RCTM_User);
case(EMovieSceneKeyInterpolation::Break):
RetValue = Channel.AddCubicKey(FrameNumber, value, RCTM_Break);
break;
case(EMovieSceneKeyInterpolation::Linear):
RetValue = Channel.AddLinearKey(FrameNumber, value);
break;
case(EMovieSceneKeyInterpolation::Constant):
RetValue = Channel.AddConstantKey(FrameNumber, value);
break;
default:
return PyErr_Format(PyExc_Exception, "unsupported interpolation");
}
return PyLong_FromLong(RetValue);
#endif
Py_RETURN_NONE;
}
}
else if (auto section_bool = Cast<UMovieSceneBoolSection>(section))
{
if (PyBool_Check(py_value))
{
bool value = false;
if (PyObject_IsTrue(py_value))
value = true;
#if ENGINE_MINOR_VERSION < 20
section_bool->AddKey(time, value, (EMovieSceneKeyInterpolation)interpolation);
#else
FMovieSceneBoolChannel& Channel = section_bool->GetChannel();
int32 RetValue = Channel.GetData().AddKey(FrameNumber, value);
return PyLong_FromLong(RetValue);
#endif
Py_RETURN_NONE;
}
}
else if (auto section_transform = Cast<UMovieScene3DTransformSection>(section))
{
if (ue_PyFTransform *py_transform = py_ue_is_ftransform(py_value))
{
bool unwind = (py_unwind && PyObject_IsTrue(py_unwind));
FTransform transform = py_transform->transform;
#if ENGINE_MINOR_VERSION < 20
FTransformKey tx = FTransformKey(EKey3DTransformChannel::Translation, EAxis::X, transform.GetLocation().X, unwind);
FTransformKey ty = FTransformKey(EKey3DTransformChannel::Translation, EAxis::Y, transform.GetLocation().Y, unwind);
FTransformKey tz = FTransformKey(EKey3DTransformChannel::Translation, EAxis::Z, transform.GetLocation().Z, unwind);
section_transform->AddKey(time, tx, (EMovieSceneKeyInterpolation)interpolation);
section_transform->AddKey(time, ty, (EMovieSceneKeyInterpolation)interpolation);
section_transform->AddKey(time, tz, (EMovieSceneKeyInterpolation)interpolation);
FTransformKey rx = FTransformKey(EKey3DTransformChannel::Rotation, EAxis::X, transform.GetRotation().Euler().X, unwind);
FTransformKey ry = FTransformKey(EKey3DTransformChannel::Rotation, EAxis::Y, transform.GetRotation().Euler().Y, unwind);
FTransformKey rz = FTransformKey(EKey3DTransformChannel::Rotation, EAxis::Z, transform.GetRotation().Euler().Z, unwind);
section_transform->AddKey(time, rx, (EMovieSceneKeyInterpolation)interpolation);
section_transform->AddKey(time, ry, (EMovieSceneKeyInterpolation)interpolation);
section_transform->AddKey(time, rz, (EMovieSceneKeyInterpolation)interpolation);
FTransformKey sx = FTransformKey(EKey3DTransformChannel::Scale, EAxis::X, transform.GetScale3D().X, unwind);
FTransformKey sy = FTransformKey(EKey3DTransformChannel::Scale, EAxis::Y, transform.GetScale3D().Y, unwind);
FTransformKey sz = FTransformKey(EKey3DTransformChannel::Scale, EAxis::Z, transform.GetScale3D().Z, unwind);
section_transform->AddKey(time, sx, (EMovieSceneKeyInterpolation)interpolation);
section_transform->AddKey(time, sy, (EMovieSceneKeyInterpolation)interpolation);
section_transform->AddKey(time, sz, (EMovieSceneKeyInterpolation)interpolation);
Py_RETURN_NONE;
#else
int RetValueTX, RetValueTY, RetValueTZ = -1;
int RetValueRX, RetValueRY, RetValueRZ = -1;
int RetValueSX, RetValueSY, RetValueSZ = -1;
FMovieSceneFloatChannel *ChannelTX = section_transform->GetChannelProxy().GetChannel<FMovieSceneFloatChannel>(0);
FMovieSceneFloatChannel *ChannelTY = section_transform->GetChannelProxy().GetChannel<FMovieSceneFloatChannel>(1);
FMovieSceneFloatChannel *ChannelTZ = section_transform->GetChannelProxy().GetChannel<FMovieSceneFloatChannel>(2);
FMovieSceneFloatChannel *ChannelRX = section_transform->GetChannelProxy().GetChannel<FMovieSceneFloatChannel>(3);
FMovieSceneFloatChannel *ChannelRY = section_transform->GetChannelProxy().GetChannel<FMovieSceneFloatChannel>(4);
FMovieSceneFloatChannel *ChannelRZ = section_transform->GetChannelProxy().GetChannel<FMovieSceneFloatChannel>(5);
FMovieSceneFloatChannel *ChannelSX = section_transform->GetChannelProxy().GetChannel<FMovieSceneFloatChannel>(6);
FMovieSceneFloatChannel *ChannelSY = section_transform->GetChannelProxy().GetChannel<FMovieSceneFloatChannel>(7);
FMovieSceneFloatChannel *ChannelSZ = section_transform->GetChannelProxy().GetChannel<FMovieSceneFloatChannel>(8);
switch (InterpolationMode)
{
case(EMovieSceneKeyInterpolation::Auto):
RetValueTX = ChannelTX->AddCubicKey(FrameNumber, transform.GetTranslation().X, RCTM_Auto);
RetValueTY = ChannelTY->AddCubicKey(FrameNumber, transform.GetTranslation().Y, RCTM_Auto);
RetValueTZ = ChannelTZ->AddCubicKey(FrameNumber, transform.GetTranslation().Z, RCTM_Auto);
RetValueRX = ChannelRX->AddCubicKey(FrameNumber, transform.GetRotation().Euler().X, RCTM_Auto);
RetValueRY = ChannelRY->AddCubicKey(FrameNumber, transform.GetRotation().Euler().Y, RCTM_Auto);
RetValueRZ = ChannelRZ->AddCubicKey(FrameNumber, transform.GetRotation().Euler().Z, RCTM_Auto);
RetValueSX = ChannelSX->AddCubicKey(FrameNumber, transform.GetScale3D().X, RCTM_Auto);
RetValueSY = ChannelSY->AddCubicKey(FrameNumber, transform.GetScale3D().Y, RCTM_Auto);
RetValueSZ = ChannelSZ->AddCubicKey(FrameNumber, transform.GetScale3D().Z, RCTM_Auto);
break;
case(EMovieSceneKeyInterpolation::User):
RetValueTX = ChannelTX->AddCubicKey(FrameNumber, transform.GetTranslation().X, RCTM_User);
RetValueTY = ChannelTY->AddCubicKey(FrameNumber, transform.GetTranslation().Y, RCTM_User);
RetValueTZ = ChannelTZ->AddCubicKey(FrameNumber, transform.GetTranslation().Z, RCTM_User);
RetValueRX = ChannelRX->AddCubicKey(FrameNumber, transform.GetRotation().Euler().X, RCTM_User);
RetValueRY = ChannelRY->AddCubicKey(FrameNumber, transform.GetRotation().Euler().Y, RCTM_User);
RetValueRZ = ChannelRZ->AddCubicKey(FrameNumber, transform.GetRotation().Euler().Z, RCTM_User);
RetValueSX = ChannelSX->AddCubicKey(FrameNumber, transform.GetScale3D().X, RCTM_User);
RetValueSY = ChannelSY->AddCubicKey(FrameNumber, transform.GetScale3D().Y, RCTM_User);
RetValueSZ = ChannelSZ->AddCubicKey(FrameNumber, transform.GetScale3D().Z, RCTM_User);
case(EMovieSceneKeyInterpolation::Break):
RetValueTX = ChannelTX->AddCubicKey(FrameNumber, transform.GetTranslation().X, RCTM_Break);
RetValueTY = ChannelTY->AddCubicKey(FrameNumber, transform.GetTranslation().Y, RCTM_Break);
RetValueTZ = ChannelTZ->AddCubicKey(FrameNumber, transform.GetTranslation().Z, RCTM_Break);
RetValueRX = ChannelRX->AddCubicKey(FrameNumber, transform.GetRotation().Euler().X, RCTM_Break);
RetValueRY = ChannelRY->AddCubicKey(FrameNumber, transform.GetRotation().Euler().Y, RCTM_Break);
RetValueRZ = ChannelRZ->AddCubicKey(FrameNumber, transform.GetRotation().Euler().Z, RCTM_Break);
RetValueSX = ChannelSX->AddCubicKey(FrameNumber, transform.GetScale3D().X, RCTM_Break);
RetValueSY = ChannelSY->AddCubicKey(FrameNumber, transform.GetScale3D().Y, RCTM_Break);
RetValueSZ = ChannelSZ->AddCubicKey(FrameNumber, transform.GetScale3D().Z, RCTM_Break);
break;
case(EMovieSceneKeyInterpolation::Linear):
RetValueTX = ChannelTX->AddLinearKey(FrameNumber, transform.GetTranslation().X);
RetValueTY = ChannelTY->AddLinearKey(FrameNumber, transform.GetTranslation().Y);
RetValueTZ = ChannelTZ->AddLinearKey(FrameNumber, transform.GetTranslation().Z);
RetValueRX = ChannelRX->AddLinearKey(FrameNumber, transform.GetRotation().Euler().X);
RetValueRY = ChannelRY->AddLinearKey(FrameNumber, transform.GetRotation().Euler().Y);
RetValueRZ = ChannelRZ->AddLinearKey(FrameNumber, transform.GetRotation().Euler().Z);
RetValueSX = ChannelSX->AddLinearKey(FrameNumber, transform.GetScale3D().X);
RetValueSY = ChannelSY->AddLinearKey(FrameNumber, transform.GetScale3D().Y);
RetValueSZ = ChannelSZ->AddLinearKey(FrameNumber, transform.GetScale3D().Z);
break;
case(EMovieSceneKeyInterpolation::Constant):
RetValueTX = ChannelTX->AddConstantKey(FrameNumber, transform.GetTranslation().X);
RetValueTY = ChannelTY->AddConstantKey(FrameNumber, transform.GetTranslation().Y);
RetValueTZ = ChannelTZ->AddConstantKey(FrameNumber, transform.GetTranslation().Z);
RetValueRX = ChannelRX->AddConstantKey(FrameNumber, transform.GetRotation().Euler().X);
RetValueRY = ChannelRY->AddConstantKey(FrameNumber, transform.GetRotation().Euler().Y);
RetValueRZ = ChannelRZ->AddConstantKey(FrameNumber, transform.GetRotation().Euler().Z);
RetValueSX = ChannelSX->AddConstantKey(FrameNumber, transform.GetScale3D().X);
RetValueSY = ChannelSY->AddConstantKey(FrameNumber, transform.GetScale3D().Y);
RetValueSZ = ChannelSZ->AddConstantKey(FrameNumber, transform.GetScale3D().Z);
break;
default:
return PyErr_Format(PyExc_Exception, "unsupported interpolation");
}
return Py_BuildValue("((iii)(iii)(iii))", RetValueTX, RetValueTY, RetValueTZ, RetValueRX, RetValueRY, RetValueRZ, RetValueSX, RetValueSY, RetValueSZ);
#endif
}
}
else if (auto section_vector = Cast<UMovieSceneVectorSection>(section))
{
if (ue_PyFVector *py_vector = py_ue_is_fvector(py_value))
{
FVector vec = py_vector->vec;
#if ENGINE_MINOR_VERSION < 20
FVectorKey vx = FVectorKey(EKeyVectorChannel::X, vec.X);
FVectorKey vy = FVectorKey(EKeyVectorChannel::Y, vec.Y);
FVectorKey vz = FVectorKey(EKeyVectorChannel::Z, vec.Z);
section_vector->AddKey(time, vx, (EMovieSceneKeyInterpolation)interpolation);
section_vector->AddKey(time, vy, (EMovieSceneKeyInterpolation)interpolation);
section_vector->AddKey(time, vz, (EMovieSceneKeyInterpolation)interpolation);
#else
int RetValueVX, RetValueVY, RetValueVZ = -1;
FMovieSceneFloatChannel& ChannelX = (FMovieSceneFloatChannel&)section_vector->GetChannel(0);
FMovieSceneFloatChannel& ChannelY = (FMovieSceneFloatChannel&)section_vector->GetChannel(1);
FMovieSceneFloatChannel& ChannelZ = (FMovieSceneFloatChannel&)section_vector->GetChannel(2);
switch (InterpolationMode)
{
case(EMovieSceneKeyInterpolation::Auto):
RetValueVX = ChannelX.AddCubicKey(FrameNumber, vec.X, RCTM_Auto);
RetValueVY = ChannelY.AddCubicKey(FrameNumber, vec.Y, RCTM_Auto);
RetValueVZ = ChannelZ.AddCubicKey(FrameNumber, vec.Z, RCTM_Auto);
break;
case(EMovieSceneKeyInterpolation::User):
RetValueVX = ChannelX.AddCubicKey(FrameNumber, vec.X, RCTM_User);
RetValueVY = ChannelY.AddCubicKey(FrameNumber, vec.Y, RCTM_User);
RetValueVZ = ChannelZ.AddCubicKey(FrameNumber, vec.Z, RCTM_User);
case(EMovieSceneKeyInterpolation::Break):
RetValueVX = ChannelX.AddCubicKey(FrameNumber, vec.X, RCTM_Break);
RetValueVY = ChannelY.AddCubicKey(FrameNumber, vec.Y, RCTM_Break);
RetValueVZ = ChannelZ.AddCubicKey(FrameNumber, vec.Z, RCTM_Break);
break;
case(EMovieSceneKeyInterpolation::Linear):
RetValueVX = ChannelX.AddLinearKey(FrameNumber, vec.X);
RetValueVY = ChannelY.AddLinearKey(FrameNumber, vec.Y);
RetValueVZ = ChannelZ.AddLinearKey(FrameNumber, vec.Z);
break;
case(EMovieSceneKeyInterpolation::Constant):
RetValueVX = ChannelX.AddConstantKey(FrameNumber, vec.X);
RetValueVY = ChannelY.AddConstantKey(FrameNumber, vec.Y);
RetValueVZ = ChannelZ.AddConstantKey(FrameNumber, vec.Z);
break;
default:
return PyErr_Format(PyExc_Exception, "unsupported interpolation");
}
return Py_BuildValue("(iii)", RetValueVX, RetValueVY, RetValueVZ);
#endif
Py_RETURN_NONE;
}
}
return PyErr_Format(PyExc_Exception, "unsupported section type: %s", TCHAR_TO_UTF8(*section->GetClass()->GetName()));
}
PyObject *py_ue_sequencer_add_camera_cut_track(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
if (!self->ue_object->IsA<ULevelSequence>())
return PyErr_Format(PyExc_Exception, "uobject is not a LevelSequence");
ULevelSequence *seq = (ULevelSequence *)self->ue_object;
UMovieScene *scene = seq->GetMovieScene();
UMovieSceneTrack *track = scene->AddCameraCutTrack(UMovieSceneCameraCutTrack::StaticClass());
Py_RETURN_UOBJECT(track);
}
PyObject *py_ue_sequencer_remove_possessable(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
char *guid;
if (!PyArg_ParseTuple(args, "s:sequencer_remove_possessable", &guid))
{
return nullptr;
}
ULevelSequence *seq = ue_py_check_type<ULevelSequence>(self);
if (!seq)
return PyErr_Format(PyExc_Exception, "uobject is not a LevelSequence");
UMovieScene *scene = seq->GetMovieScene();
FGuid f_guid;
if (!FGuid::Parse(FString(guid), f_guid))
{
return PyErr_Format(PyExc_Exception, "invalid guid");
}
if (scene->RemovePossessable(f_guid))
Py_RETURN_TRUE;
Py_RETURN_FALSE;
}
PyObject *py_ue_sequencer_remove_spawnable(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
char *guid;
if (!PyArg_ParseTuple(args, "s:sequencer_remove_spawnable", &guid))
{
return nullptr;
}
ULevelSequence *seq = ue_py_check_type<ULevelSequence>(self);
if (!seq)
return PyErr_Format(PyExc_Exception, "uobject is not a LevelSequence");
UMovieScene *scene = seq->GetMovieScene();
FGuid f_guid;
if (!FGuid::Parse(FString(guid), f_guid))
{
return PyErr_Format(PyExc_Exception, "invalid guid");
}
if (scene->RemoveSpawnable(f_guid))
Py_RETURN_TRUE;
Py_RETURN_FALSE;
}
PyObject *py_ue_sequencer_remove_camera_cut_track(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
ULevelSequence *seq = ue_py_check_type<ULevelSequence>(self);
if (!seq)
return PyErr_Format(PyExc_Exception, "uobject is not a LevelSequence");
UMovieScene *scene = seq->GetMovieScene();
scene->RemoveCameraCutTrack();
Py_RETURN_NONE;
}
PyObject *py_ue_sequencer_remove_master_track(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
PyObject *py_track;
if (!PyArg_ParseTuple(args, "O:sequencer_remove_master_track", &py_track))
{
return nullptr;
}
ULevelSequence *seq = ue_py_check_type<ULevelSequence>(self);
if (!seq)
return PyErr_Format(PyExc_Exception, "uobject is not a LevelSequence");
UMovieSceneTrack *track = ue_py_check_type<UMovieSceneTrack>(py_track);
if (!track)
return PyErr_Format(PyExc_Exception, "argument is not a UMovieSceneTrack");
UMovieScene *scene = seq->GetMovieScene();
if (scene->RemoveMasterTrack(*track))
Py_RETURN_TRUE;
Py_RETURN_FALSE;
}
PyObject *py_ue_sequencer_remove_track(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
PyObject *py_track;
if (!PyArg_ParseTuple(args, "O:sequencer_remove_track", &py_track))
{
return nullptr;
}
ULevelSequence *seq = ue_py_check_type<ULevelSequence>(self);
if (!seq)
return PyErr_Format(PyExc_Exception, "uobject is not a LevelSequence");
UMovieSceneTrack *track = ue_py_check_type<UMovieSceneTrack>(py_track);
if (!track)
return PyErr_Format(PyExc_Exception, "argument is not a UMovieSceneTrack");
UMovieScene *scene = seq->GetMovieScene();
if (scene->RemoveTrack(*track))
Py_RETURN_TRUE;
Py_RETURN_FALSE;
}
#endif
PyObject *py_ue_sequencer_add_track(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
PyObject *obj;
char *guid;
if (!PyArg_ParseTuple(args, "Os:sequencer_add_track", &obj, &guid))
{
return NULL;
}
if (!self->ue_object->IsA<ULevelSequence>())
return PyErr_Format(PyExc_Exception, "uobject is not a LevelSequence");
ULevelSequence *seq = (ULevelSequence *)self->ue_object;
UMovieScene *scene = seq->GetMovieScene();
ue_PyUObject *py_obj = ue_is_pyuobject(obj);
if (!py_obj)
return PyErr_Format(PyExc_Exception, "argument is not a uobject");
if (!py_obj->ue_object->IsA<UClass>())
return PyErr_Format(PyExc_Exception, "uobject is not a UClass");
UClass *u_class = (UClass *)py_obj->ue_object;
if (!u_class->IsChildOf<UMovieSceneTrack>())
return PyErr_Format(PyExc_Exception, "uobject is not a UMovieSceneTrack class");
FGuid f_guid;
if (!FGuid::Parse(FString(guid), f_guid))
{
return PyErr_Format(PyExc_Exception, "invalid guid");
}
UMovieSceneTrack *track = scene->AddTrack(u_class, f_guid);
if (!track)
return PyErr_Format(PyExc_Exception, "unable to create new track");
Py_RETURN_UOBJECT(track);
}
#if WITH_EDITOR
// smart functions allowing the set/get of display names to various sequencer objects
PyObject *py_ue_sequencer_set_display_name(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
char *name;
if (!PyArg_ParseTuple(args, "s:sequencer_set_display_name", &name))
{
return NULL;
}
if (self->ue_object->IsA<UMovieSceneNameableTrack>())
{
UMovieSceneNameableTrack *track = (UMovieSceneNameableTrack *)self->ue_object;
track->SetDisplayName(FText::FromString(UTF8_TO_TCHAR(name)));
}
else
{
return PyErr_Format(PyExc_Exception, "the uobject does not expose the SetDisplayName() method");
}
Py_RETURN_NONE;
}
PyObject *py_ue_sequencer_get_display_name(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
if (self->ue_object->IsA<UMovieSceneNameableTrack>())
{
UMovieSceneNameableTrack *track = (UMovieSceneNameableTrack *)self->ue_object;
FText name = track->GetDefaultDisplayName();
return PyUnicode_FromString(TCHAR_TO_UTF8(*name.ToString()));
}
return PyErr_Format(PyExc_Exception, "the uobject does not expose the GetDefaultDisplayName() method");
}
PyObject *py_ue_sequencer_import_fbx_transform(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
char *filename;
char *nodename;
PyObject *py_force_front_x_axis = nullptr;
if (!PyArg_ParseTuple(args, "ss|o:sequencer_import_fbx_transform", &filename, &nodename, &py_force_front_x_axis))
return nullptr;
UMovieScene3DTransformSection *section = ue_py_check_type<UMovieScene3DTransformSection>(self);
if (!section)
return PyErr_Format(PyExc_Exception, "uobject is not a UMovieScene3DTransformSection");
UnFbx::FFbxImporter* FbxImporter = UnFbx::FFbxImporter::GetInstance();
UnFbx::FBXImportOptions* ImportOptions = FbxImporter->GetImportOptions();
bool bConverteScene = ImportOptions->bConvertScene;
bool bConverteSceneUnit = ImportOptions->bConvertSceneUnit;
bool bForceFrontXAxis = ImportOptions->bForceFrontXAxis;
ImportOptions->bConvertScene = true;
ImportOptions->bConvertSceneUnit = true;
ImportOptions->bForceFrontXAxis = py_force_front_x_axis && PyObject_IsTrue(py_force_front_x_axis);
FString FbxFilename = FString(UTF8_TO_TCHAR(filename));
FString FbxNodeName = FString(UTF8_TO_TCHAR(nodename));
const FString Extension = FPaths::GetExtension(FbxFilename);
if (!FbxImporter->ImportFromFile(FbxFilename, Extension, true))
{
FbxImporter->ReleaseScene();
ImportOptions->bConvertScene = bConverteScene;
ImportOptions->bConvertSceneUnit = bConverteSceneUnit;
ImportOptions->bForceFrontXAxis = bForceFrontXAxis;
return PyErr_Format(PyExc_Exception, "unable to import Fbx file");
}
UnFbx::FFbxCurvesAPI CurveAPI;
FbxImporter->PopulateAnimatedCurveData(CurveAPI);
TArray<FString> AllNodeNames;
#if ENGINE_MINOR_VERSION < 18
CurveAPI.GetAnimatedNodeNameArray(AllNodeNames);
#else
CurveAPI.GetAllNodeNameArray(AllNodeNames);
#endif
for (FString NodeName : AllNodeNames)
{
if (NodeName != FbxNodeName)
continue;
// Look for transforms explicitly
#if ENGINE_MINOR_VERSION > 21
FRichCurve Translation[3];
FRichCurve EulerRotation[3];
FRichCurve Scale[3];
#else
FInterpCurveFloat Translation[3];
FInterpCurveFloat EulerRotation[3];
FInterpCurveFloat Scale[3];
#endif
FTransform DefaultTransform;
#if ENGINE_MINOR_VERSION >= 18
CurveAPI.GetConvertedTransformCurveData(NodeName, Translation[0], Translation[1], Translation[2], EulerRotation[0], EulerRotation[1], EulerRotation[2], Scale[0], Scale[1], Scale[2], DefaultTransform);
#if ENGINE_MINOR_VERSION < 20
for (int32 ChannelIndex = 0; ChannelIndex < 3; ++ChannelIndex)
{
EAxis::Type ChannelAxis = EAxis::X;
if (ChannelIndex == 1)
{
ChannelAxis = EAxis::Y;
}
else if (ChannelIndex == 2)
{
ChannelAxis = EAxis::Z;
}
section->GetTranslationCurve(ChannelAxis).SetDefaultValue(DefaultTransform.GetLocation()[ChannelIndex]);
section->GetRotationCurve(ChannelAxis).SetDefaultValue(DefaultTransform.GetRotation().Euler()[ChannelIndex]);
section->GetScaleCurve(ChannelAxis).SetDefaultValue(DefaultTransform.GetScale3D()[ChannelIndex]);
}
#endif
#else
CurveAPI.GetConvertedTransformCurveData(NodeName, Translation[0], Translation[1], Translation[2], EulerRotation[0], EulerRotation[1], EulerRotation[2], Scale[0], Scale[1], Scale[2]);
#endif
#if ENGINE_MINOR_VERSION < 20
float MinTime = FLT_MAX;
float MaxTime = -FLT_MAX;
const int NumCurves = 3; // Trans, Rot, Scale
for (int32 CurveIndex = 0; CurveIndex < NumCurves; ++CurveIndex)
{
for (int32 ChannelIndex = 0; ChannelIndex < 3; ++ChannelIndex)
{
EAxis::Type ChannelAxis = EAxis::X;
if (ChannelIndex == 1)
{
ChannelAxis = EAxis::Y;
}
else if (ChannelIndex == 2)
{
ChannelAxis = EAxis::Z;
}
FInterpCurveFloat* CurveFloat = nullptr;
FRichCurve* ChannelCurve = nullptr;
bool bNegative = false;
if (CurveIndex == 0)
{
CurveFloat = &Translation[ChannelIndex];
ChannelCurve = §ion->GetTranslationCurve(ChannelAxis);
if (ChannelIndex == 1)
{
bNegative = true;
}
}
else if (CurveIndex == 1)
{
CurveFloat = &EulerRotation[ChannelIndex];
ChannelCurve = §ion->GetRotationCurve(ChannelAxis);
if (ChannelIndex == 1 || ChannelIndex == 2)
{
bNegative = true;
}
}
else if (CurveIndex == 2)
{
CurveFloat = &Scale[ChannelIndex];
ChannelCurve = §ion->GetScaleCurve(ChannelAxis);
}
if (ChannelCurve != nullptr && CurveFloat != nullptr)
{
ChannelCurve->Reset();
for (int32 KeyIndex = 0; KeyIndex < CurveFloat->Points.Num(); ++KeyIndex)
{
MinTime = FMath::Min(MinTime, CurveFloat->Points[KeyIndex].InVal);
MaxTime = FMath::Max(MaxTime, CurveFloat->Points[KeyIndex].InVal);
float ArriveTangent = CurveFloat->Points[KeyIndex].ArriveTangent;
if (KeyIndex > 0)
{
ArriveTangent = ArriveTangent / (CurveFloat->Points[KeyIndex].InVal - CurveFloat->Points[KeyIndex - 1].InVal);
}
float LeaveTangent = CurveFloat->Points[KeyIndex].LeaveTangent;
if (KeyIndex < CurveFloat->Points.Num() - 1)
{
LeaveTangent = LeaveTangent / (CurveFloat->Points[KeyIndex + 1].InVal - CurveFloat->Points[KeyIndex].InVal);
}
if (bNegative)
{
ArriveTangent = -ArriveTangent;
LeaveTangent = -LeaveTangent;
}
FMatineeImportTools::SetOrAddKey(*ChannelCurve, CurveFloat->Points[KeyIndex].InVal, CurveFloat->Points[KeyIndex].OutVal, ArriveTangent, LeaveTangent, CurveFloat->Points[KeyIndex].InterpMode);
}
ChannelCurve->RemoveRedundantKeys(KINDA_SMALL_NUMBER);
ChannelCurve->AutoSetTangents();
}
}
}
#else
ImportFBXTransform(nodename, section, CurveAPI);
#endif
#if ENGINE_MINOR_VERSION < 20
section->SetStartTime(MinTime);
section->SetEndTime(MaxTime);
#endif
FbxImporter->ReleaseScene();
ImportOptions->bConvertScene = bConverteScene;
ImportOptions->bConvertSceneUnit = bConverteSceneUnit;
ImportOptions->bForceFrontXAxis = bForceFrontXAxis;
Py_RETURN_NONE;
}
FbxImporter->ReleaseScene();
ImportOptions->bConvertScene = bConverteScene;
ImportOptions->bConvertSceneUnit = bConverteSceneUnit;
ImportOptions->bForceFrontXAxis = bForceFrontXAxis;
return PyErr_Format(PyExc_Exception, "unable to find specified node in Fbx file");
}
#endif
```
|
/content/code_sandbox/Source/UnrealEnginePython/Private/UObject/UEPySequencer.cpp
|
c++
| 2016-08-07T05:00:51
| 2024-08-14T06:32:20
|
UnrealEnginePython
|
20tab/UnrealEnginePython
| 2,715
| 15,746
|
```objective-c
#pragma once
#include "UEPyModule.h"
PyObject *py_ue_controller_posses(ue_PyUObject *, PyObject *);
PyObject *py_ue_controller_unposses(ue_PyUObject *, PyObject *);
PyObject *py_ue_controller_get_hud(ue_PyUObject *, PyObject *);
PyObject *py_ue_get_controlled_pawn(ue_PyUObject *, PyObject *);
PyObject *py_ue_controller_project_world_location_to_screen(ue_PyUObject *, PyObject *);
```
|
/content/code_sandbox/Source/UnrealEnginePython/Private/UObject/UEPyController.h
|
objective-c
| 2016-08-07T05:00:51
| 2024-08-14T06:32:20
|
UnrealEnginePython
|
20tab/UnrealEnginePython
| 2,715
| 100
|
```objective-c
#pragma once
#include "UEPyModule.h"
PyObject *py_ue_get_anim_instance(ue_PyUObject *, PyObject *);
PyObject *py_ue_set_skeletal_mesh(ue_PyUObject *, PyObject *);
PyObject *py_ue_skeleton_get_parent_index(ue_PyUObject *, PyObject *);
PyObject *py_ue_skeleton_bones_get_num(ue_PyUObject *, PyObject *);
PyObject *py_ue_skeleton_get_bone_name(ue_PyUObject *, PyObject *);
PyObject *py_ue_skeleton_find_bone_index(ue_PyUObject *, PyObject *);
PyObject *py_ue_skeleton_get_ref_bone_pose(ue_PyUObject *, PyObject *);
PyObject *py_ue_skeleton_add_bone(ue_PyUObject *, PyObject *);
PyObject *py_ue_skeletal_mesh_set_soft_vertices(ue_PyUObject *, PyObject *);
PyObject *py_ue_skeletal_mesh_get_soft_vertices(ue_PyUObject *, PyObject *);
PyObject *py_ue_skeletal_mesh_set_skeleton(ue_PyUObject *, PyObject *);
PyObject *py_ue_skeletal_mesh_get_lod(ue_PyUObject *, PyObject *);
PyObject *py_ue_skeletal_mesh_get_raw_indices(ue_PyUObject *, PyObject *);
PyObject *py_ue_skeletal_mesh_get_bone_map(ue_PyUObject *, PyObject *);
PyObject *py_ue_skeletal_mesh_set_bone_map(ue_PyUObject *, PyObject *);
PyObject *py_ue_skeletal_mesh_set_active_bone_indices(ue_PyUObject *, PyObject *);
PyObject *py_ue_skeletal_mesh_set_required_bones(ue_PyUObject *, PyObject *);
PyObject *py_ue_skeletal_mesh_get_active_bone_indices(ue_PyUObject *, PyObject *);
PyObject *py_ue_skeletal_mesh_get_required_bones(ue_PyUObject *, PyObject *);
PyObject *py_ue_skeletal_mesh_lods_num(ue_PyUObject *, PyObject *);
PyObject *py_ue_skeletal_mesh_sections_num(ue_PyUObject *, PyObject *);
PyObject *py_ue_skeletal_mesh_build_lod(ue_PyUObject *, PyObject *, PyObject *);
PyObject *py_ue_skeletal_mesh_register_morph_target(ue_PyUObject *, PyObject *);
PyObject *py_ue_morph_target_populate_deltas(ue_PyUObject *, PyObject *);
PyObject *py_ue_morph_target_get_deltas(ue_PyUObject *, PyObject *);
PyObject *py_ue_skeletal_mesh_to_import_vertex_map(ue_PyUObject *, PyObject *);
```
|
/content/code_sandbox/Source/UnrealEnginePython/Private/UObject/UEPySkeletal.h
|
objective-c
| 2016-08-07T05:00:51
| 2024-08-14T06:32:20
|
UnrealEnginePython
|
20tab/UnrealEnginePython
| 2,715
| 511
|
```objective-c
#pragma once
#include "UEPyModule.h"
PyObject *py_ue_add_controller_yaw_input(ue_PyUObject *, PyObject *);
PyObject *py_ue_add_controller_pitch_input(ue_PyUObject *, PyObject *);
PyObject *py_ue_add_controller_roll_input(ue_PyUObject *, PyObject *);
PyObject *py_ue_get_control_rotation(ue_PyUObject *, PyObject *);
PyObject *py_ue_add_movement_input(ue_PyUObject *, PyObject *);
PyObject *py_ue_jump(ue_PyUObject *, PyObject *);
PyObject *py_ue_stop_jumping(ue_PyUObject *, PyObject *);
PyObject *py_ue_crouch(ue_PyUObject *, PyObject *);
PyObject *py_ue_uncrouch(ue_PyUObject *, PyObject *);
PyObject *py_ue_launch(ue_PyUObject *, PyObject *);
PyObject *py_ue_is_jumping(ue_PyUObject *, PyObject *);
PyObject *py_ue_is_crouched(ue_PyUObject *, PyObject *);
PyObject *py_ue_is_falling(ue_PyUObject *, PyObject *);
PyObject *py_ue_is_flying(ue_PyUObject *, PyObject *);
PyObject *py_ue_can_jump(ue_PyUObject *, PyObject *);
PyObject *py_ue_can_crouch(ue_PyUObject *, PyObject *);
```
|
/content/code_sandbox/Source/UnrealEnginePython/Private/UObject/UEPyMovements.h
|
objective-c
| 2016-08-07T05:00:51
| 2024-08-14T06:32:20
|
UnrealEnginePython
|
20tab/UnrealEnginePython
| 2,715
| 265
|
```c++
#include "UEPyTraceAndSweep.h"
#include "Kismet/KismetSystemLibrary.h"
#include "Wrappers/UEPyFHitResult.h"
#include "Kismet/GameplayStatics.h"
#include "Engine/World.h"
PyObject *py_ue_line_trace_single_by_channel(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
PyObject *py_obj_start;
PyObject *py_obj_end;
int channel;
UWorld *world = ue_get_uworld(self);
if (!world)
return PyErr_Format(PyExc_Exception, "unable to retrieve UWorld from uobject");
if (!PyArg_ParseTuple(args, "OOi:line_trace_single_by_channel", &py_obj_start, &py_obj_end, &channel))
{
return NULL;
}
ue_PyFVector *start = py_ue_is_fvector(py_obj_start);
ue_PyFVector *end = py_ue_is_fvector(py_obj_end);
if (!start || !end)
return PyErr_Format(PyExc_Exception, "start and end location must be vectors");
FHitResult hit;
bool got_hit = world->LineTraceSingleByChannel(hit, start->vec, end->vec, (ECollisionChannel)channel);
if (got_hit)
{
return py_ue_new_fhitresult(hit);
}
Py_RETURN_NONE;
}
PyObject *py_ue_line_trace_multi_by_channel(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
PyObject *py_obj_start;
PyObject *py_obj_end;
int channel;
UWorld *world = ue_get_uworld(self);
if (!world)
return PyErr_Format(PyExc_Exception, "unable to retrieve UWorld from uobject");
if (!PyArg_ParseTuple(args, "OOi:line_trace_multi_by_channel", &py_obj_start, &py_obj_end, &channel))
{
return NULL;
}
ue_PyFVector *start = py_ue_is_fvector(py_obj_start);
ue_PyFVector *end = py_ue_is_fvector(py_obj_end);
if (!start || !end)
return PyErr_Format(PyExc_Exception, "start and end location must be vectors");
TArray<struct FHitResult> hits;
hits.Reset();
PyObject *hits_list = PyList_New(0);
bool got_hits = world->LineTraceMultiByChannel(hits, start->vec, end->vec, (ECollisionChannel)channel);
if (got_hits)
{
for (int i = 0; i < hits.Num(); i++)
{
FHitResult hit = hits[i];
PyList_Append(hits_list, py_ue_new_fhitresult(hit));
}
}
return hits_list;
}
PyObject *py_ue_get_hit_result_under_cursor(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
int channel;
PyObject *trace_complex = nullptr;
int controller_id = 0;
UWorld *world = ue_get_uworld(self);
if (!world)
return PyErr_Format(PyExc_Exception, "unable to retrieve UWorld from uobject");
if (!PyArg_ParseTuple(args, "i|Oi:get_hit_result_under_cursor", &channel, &trace_complex, &controller_id))
{
return nullptr;
}
bool complex = false;
if (trace_complex && PyObject_IsTrue(trace_complex))
{
complex = true;
}
APlayerController *controller = UGameplayStatics::GetPlayerController(world, controller_id);
if (!controller)
return PyErr_Format(PyExc_Exception, "unable to retrieve controller %d", controller_id);
FHitResult hit;
bool got_hit = controller->GetHitResultUnderCursor((ECollisionChannel)channel, complex, hit);
if (got_hit)
{
return py_ue_new_fhitresult(hit);
}
Py_RETURN_NONE;
}
PyObject *py_ue_draw_debug_line(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
PyObject *py_obj_start;
PyObject *py_obj_end;
PyObject *py_color;
float duration = 0;
float thickness = 0;
UWorld *world = ue_get_uworld(self);
if (!world)
return PyErr_Format(PyExc_Exception, "unable to retrieve UWorld from uobject");
if (!PyArg_ParseTuple(args, "OOO|ff:draw_debug_line", &py_obj_start, &py_obj_end, &py_color, &duration, &thickness))
{
return NULL;
}
ue_PyFVector *start = py_ue_is_fvector(py_obj_start);
ue_PyFVector *end = py_ue_is_fvector(py_obj_end);
if (!start || !end)
return PyErr_Format(PyExc_Exception, "start and end location must be vectors");
ue_PyFLinearColor *py_linear_color = py_ue_is_flinearcolor(py_color);
if (!py_linear_color)
return PyErr_Format(PyExc_Exception, "argument is not a FLinearColor");
UKismetSystemLibrary::DrawDebugLine(world, start->vec, end->vec, py_linear_color->color, duration, thickness);
Py_RETURN_NONE;
}
```
|
/content/code_sandbox/Source/UnrealEnginePython/Private/UObject/UEPyTraceAndSweep.cpp
|
c++
| 2016-08-07T05:00:51
| 2024-08-14T06:32:20
|
UnrealEnginePython
|
20tab/UnrealEnginePython
| 2,715
| 1,090
|
```objective-c
#pragma once
#include "UEPyModule.h"
PyObject *py_ue_data_table_add_row(ue_PyUObject *, PyObject *);
PyObject *py_ue_data_table_remove_row(ue_PyUObject *, PyObject *);
PyObject *py_ue_data_table_rename_row(ue_PyUObject *, PyObject *);
PyObject *py_ue_data_table_as_dict(ue_PyUObject *, PyObject *);
PyObject *py_ue_data_table_as_json(ue_PyUObject *, PyObject *);
PyObject *py_ue_data_table_find_row(ue_PyUObject *, PyObject *);
PyObject *py_ue_data_table_get_all_rows(ue_PyUObject *, PyObject *);
```
|
/content/code_sandbox/Source/UnrealEnginePython/Private/UObject/UEPyDataTable.h
|
objective-c
| 2016-08-07T05:00:51
| 2024-08-14T06:32:20
|
UnrealEnginePython
|
20tab/UnrealEnginePython
| 2,715
| 132
|
```c++
#include "UEPySkeletal.h"
#include "Runtime/Engine/Public/ComponentReregisterContext.h"
#if WITH_EDITOR
#include "Developer/MeshUtilities/Public/MeshUtilities.h"
#include "Wrappers/UEPyFMorphTargetDelta.h"
#include "Wrappers/UEPyFSoftSkinVertex.h"
#if ENGINE_MINOR_VERSION > 20
#include "Runtime/Engine/Public/Rendering/SkeletalMeshLODImporterData.h"
#endif
#if ENGINE_MINOR_VERSION > 18
#include "Runtime/Engine/Public/Rendering/SkeletalMeshModel.h"
#endif
#endif
#include "Animation/AnimInstance.h"
PyObject *py_ue_get_anim_instance(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
if (!self->ue_object->IsA<USkeletalMeshComponent>())
return PyErr_Format(PyExc_Exception, "uobject is not a USkeletalMeshComponent");
USkeletalMeshComponent *skeletal = (USkeletalMeshComponent *)self->ue_object;
UAnimInstance *anim = skeletal->GetAnimInstance();
if (!anim)
{
Py_INCREF(Py_None);
return Py_None;
}
Py_RETURN_UOBJECT((UObject *)anim);
}
PyObject *py_ue_set_skeletal_mesh(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
PyObject *py_skeletal_mesh;
PyObject *py_reinit_pose = nullptr;
if (!PyArg_ParseTuple(args, "O|O:set_skeletal_mesh", &py_skeletal_mesh, &py_reinit_pose))
return nullptr;
USkinnedMeshComponent *component = ue_py_check_type<USkinnedMeshComponent>(self);
if (!component)
return PyErr_Format(PyExc_Exception, "uobject is not a USkeletalMeshComponent");
USkeletalMesh *mesh = ue_py_check_type<USkeletalMesh>(py_skeletal_mesh);
if (!mesh)
return PyErr_Format(PyExc_Exception, "argument is not a USkeletalMesh");
bool reinit_pose = true;
if (py_reinit_pose && !PyObject_IsTrue(py_reinit_pose))
reinit_pose = false;
component->SetSkeletalMesh(mesh, reinit_pose);
Py_RETURN_NONE;
}
PyObject *py_ue_skeleton_get_parent_index(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
int index;
if (!PyArg_ParseTuple(args, "i:skeleton_get_parent_index", &index))
return nullptr;
USkeleton *skeleton = ue_py_check_type<USkeleton>(self);
if (!skeleton)
return PyErr_Format(PyExc_Exception, "uobject is not a USkeleton");
if (!skeleton->GetReferenceSkeleton().IsValidIndex(index))
return PyErr_Format(PyExc_Exception, "invalid bone index");
return PyLong_FromLong(skeleton->GetReferenceSkeleton().GetParentIndex(index));
}
PyObject *py_ue_skeleton_bones_get_num(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
USkeleton *skeleton = ue_py_check_type<USkeleton>(self);
if (!skeleton)
return PyErr_Format(PyExc_Exception, "uobject is not a USkeleton");
return PyLong_FromLong(skeleton->GetReferenceSkeleton().GetNum());
}
PyObject *py_ue_skeleton_get_bone_name(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
int index;
if (!PyArg_ParseTuple(args, "i:skeleton_get_bone_name", &index))
return nullptr;
USkeleton *skeleton = ue_py_check_type<USkeleton>(self);
if (!skeleton)
return PyErr_Format(PyExc_Exception, "uobject is not a USkeleton");
if (!skeleton->GetReferenceSkeleton().IsValidIndex(index))
return PyErr_Format(PyExc_Exception, "invalid bone index");
return PyUnicode_FromString(TCHAR_TO_UTF8(*skeleton->GetReferenceSkeleton().GetBoneName(index).ToString()));
}
PyObject *py_ue_skeleton_find_bone_index(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
char *name;
if (!PyArg_ParseTuple(args, "s:skeleton_find_bone_index", &name))
return nullptr;
USkeleton *skeleton = ue_py_check_type<USkeleton>(self);
if (!skeleton)
return PyErr_Format(PyExc_Exception, "uobject is not a USkeleton");
int32 index = skeleton->GetReferenceSkeleton().FindBoneIndex(FName(UTF8_TO_TCHAR(name)));
if (!skeleton->GetReferenceSkeleton().IsValidIndex(index))
return PyErr_Format(PyExc_Exception, "unable to find bone");
return PyLong_FromLong(index);
}
PyObject *py_ue_skeleton_get_ref_bone_pose(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
int index;
if (!PyArg_ParseTuple(args, "i:skeleton_get_ref_bone_pose", &index))
return nullptr;
USkeleton *skeleton = ue_py_check_type<USkeleton>(self);
if (!skeleton)
return PyErr_Format(PyExc_Exception, "uobject is not a USkeleton");
if (!skeleton->GetReferenceSkeleton().IsValidIndex(index))
return PyErr_Format(PyExc_Exception, "invalid bone index");
return py_ue_new_ftransform(skeleton->GetReferenceSkeleton().GetRefBonePose()[index]);
}
#if ENGINE_MINOR_VERSION > 13
PyObject *py_ue_skeleton_add_bone(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
char *name;
int parent_index;
PyObject *py_transform;
if (!PyArg_ParseTuple(args, "siO:skeleton_add_bone", &name, &parent_index, &py_transform))
return nullptr;
USkeleton *skeleton = ue_py_check_type<USkeleton>(self);
if (!skeleton)
return PyErr_Format(PyExc_Exception, "uobject is not a USkeleton");
ue_PyFTransform *transform = py_ue_is_ftransform(py_transform);
if (!transform)
return PyErr_Format(PyExc_Exception, "argument is not a FTransform");
if (skeleton->GetReferenceSkeleton().FindBoneIndex(FName(UTF8_TO_TCHAR(name))) > -1)
{
return PyErr_Format(PyExc_Exception, "bone %s already exists", name);
}
#if WITH_EDITOR
skeleton->PreEditChange(nullptr);
#endif
{
const FReferenceSkeleton &ref = skeleton->GetReferenceSkeleton();
// horrible hack to modify the skeleton in place
FReferenceSkeletonModifier modifier((FReferenceSkeleton &)ref, skeleton);
TCHAR *bone_name = UTF8_TO_TCHAR(name);
modifier.Add(FMeshBoneInfo(FName(bone_name), FString(bone_name), parent_index), transform->transform);
}
#if WITH_EDITOR
skeleton->PostEditChange();
#endif
skeleton->MarkPackageDirty();
return PyLong_FromLong(skeleton->GetReferenceSkeleton().FindBoneIndex(FName(UTF8_TO_TCHAR(name))));
}
#endif
#if WITH_EDITOR
#if ENGINE_MINOR_VERSION > 12
PyObject *py_ue_skeletal_mesh_set_soft_vertices(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
PyObject *py_ss_vertex;
int lod_index = 0;
int section_index = 0;
if (!PyArg_ParseTuple(args, "O|ii:skeletal_mesh_set_soft_vertices", &py_ss_vertex, &lod_index, §ion_index))
return nullptr;
USkeletalMesh *mesh = ue_py_check_type<USkeletalMesh>(self);
if (!mesh)
return PyErr_Format(PyExc_Exception, "uobject is not a USkeletalMesh");
#if ENGINE_MINOR_VERSION < 19
FSkeletalMeshResource *resource = mesh->GetImportedResource();
#else
FSkeletalMeshModel *resource = mesh->GetImportedModel();
#endif
if (lod_index < 0 || lod_index >= resource->LODModels.Num())
return PyErr_Format(PyExc_Exception, "invalid LOD index, must be between 0 and %d", resource->LODModels.Num() - 1);
#if ENGINE_MINOR_VERSION < 19
FStaticLODModel &model = resource->LODModels[lod_index];
#else
FSkeletalMeshLODModel &model = resource->LODModels[lod_index];
#endif
if (section_index < 0 || section_index >= model.Sections.Num())
return PyErr_Format(PyExc_Exception, "invalid Section index, must be between 0 and %d", model.Sections.Num() - 1);
PyObject *py_iter = PyObject_GetIter(py_ss_vertex);
if (!py_iter)
{
return PyErr_Format(PyExc_Exception, "argument is not an iterable of FSoftSkinVertex");
}
TArray<FSoftSkinVertex> soft_vertices;
while (PyObject *py_item = PyIter_Next(py_iter))
{
ue_PyFSoftSkinVertex *ss_vertex = py_ue_is_fsoft_skin_vertex(py_item);
if (!ss_vertex)
{
Py_DECREF(py_iter);
return PyErr_Format(PyExc_Exception, "argument is not an iterable of FSoftSkinVertex");
}
soft_vertices.Add(ss_vertex->ss_vertex);
}
Py_DECREF(py_iter);
// temporarily disable all USkinnedMeshComponent's
TComponentReregisterContext<USkinnedMeshComponent> ReregisterContext;
mesh->ReleaseResources();
mesh->ReleaseResourcesFence.Wait();
model.Sections[section_index].SoftVertices = soft_vertices;
model.Sections[section_index].NumVertices = soft_vertices.Num();
model.Sections[section_index].CalcMaxBoneInfluences();
mesh->RefBasesInvMatrix.Empty();
mesh->CalculateInvRefMatrices();
#if WITH_EDITOR
mesh->PostEditChange();
#endif
mesh->InitResources();
mesh->MarkPackageDirty();
Py_RETURN_NONE;
}
#endif
#if ENGINE_MINOR_VERSION > 12
PyObject *py_ue_skeletal_mesh_get_soft_vertices(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
int lod_index = 0;
int section_index = 0;
if (!PyArg_ParseTuple(args, "|ii:skeletal_mesh_get_soft_vertices", &lod_index, §ion_index))
return nullptr;
USkeletalMesh *mesh = ue_py_check_type<USkeletalMesh>(self);
if (!mesh)
return PyErr_Format(PyExc_Exception, "uobject is not a USkeletalMesh");
#if ENGINE_MINOR_VERSION < 19
FSkeletalMeshResource *resource = mesh->GetImportedResource();
#else
FSkeletalMeshModel *resource = mesh->GetImportedModel();
#endif
if (lod_index < 0 || lod_index >= resource->LODModels.Num())
return PyErr_Format(PyExc_Exception, "invalid LOD index, must be between 0 and %d", resource->LODModels.Num() - 1);
#if ENGINE_MINOR_VERSION < 19
FStaticLODModel &model = resource->LODModels[lod_index];
#else
FSkeletalMeshLODModel &model = resource->LODModels[lod_index];
#endif
if (section_index < 0 || section_index >= model.Sections.Num())
return PyErr_Format(PyExc_Exception, "invalid Section index, must be between 0 and %d", model.Sections.Num() - 1);
PyObject *py_list = PyList_New(0);
for (int32 i = 0; i < model.Sections[section_index].SoftVertices.Num(); i++)
{
PyList_Append(py_list, py_ue_new_fsoft_skin_vertex(model.Sections[section_index].SoftVertices[i]));
}
return py_list;
}
#endif
PyObject *py_ue_skeletal_mesh_get_lod(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
int lod_index = 0;
if (!PyArg_ParseTuple(args, "|i:skeletal_mesh_get_lod", &lod_index))
return nullptr;
USkeletalMesh *mesh = ue_py_check_type<USkeletalMesh>(self);
if (!mesh)
return PyErr_Format(PyExc_Exception, "uobject is not a USkeletalMesh");
#if ENGINE_MINOR_VERSION < 19
FSkeletalMeshResource *resource = mesh->GetImportedResource();
#else
FSkeletalMeshModel *resource = mesh->GetImportedModel();
#endif
if (lod_index < 0 || lod_index >= resource->LODModels.Num())
return PyErr_Format(PyExc_Exception, "invalid LOD index, must be between 0 and %d", resource->LODModels.Num() - 1);
#if ENGINE_MINOR_VERSION < 19
FStaticLODModel &model = resource->LODModels[lod_index];
#else
FSkeletalMeshLODModel &model = resource->LODModels[lod_index];
#endif
PyObject *py_list = PyList_New(0);
TArray<uint32> indices;
#if ENGINE_MINOR_VERSION > 18
indices = model.IndexBuffer;
#else
model.MultiSizeIndexContainer.GetIndexBuffer(indices);
#endif
for (int32 index = 0; index < indices.Num(); index++)
{
int32 section_index;
int32 vertex_index;
#if ENGINE_MINOR_VERSION > 18
model.GetSectionFromVertexIndex(indices[index], section_index, vertex_index);
#else
bool has_extra_influences;
model.GetSectionFromVertexIndex(indices[index], section_index, vertex_index, has_extra_influences);
#endif
FSoftSkinVertex ssv = model.Sections[section_index].SoftVertices[vertex_index];
// fix bone id
for (int32 i = 0; i < MAX_TOTAL_INFLUENCES; i++)
{
if (ssv.InfluenceBones[i] < model.Sections[section_index].BoneMap.Num())
{
ssv.InfluenceBones[i] = model.Sections[section_index].BoneMap[ssv.InfluenceBones[i]];
}
else
{
UE_LOG(LogPython, Warning, TEXT("unable to retrieve bone mapping for index %d, forcing to 0"), ssv.InfluenceBones[i]);
ssv.InfluenceBones[i] = 0;
}
}
ue_PyFSoftSkinVertex *py_ss_vertex = (ue_PyFSoftSkinVertex *)py_ue_new_fsoft_skin_vertex(ssv);
py_ss_vertex->material_index = section_index;
PyList_Append(py_list, (PyObject *)py_ss_vertex);
}
return py_list;
}
PyObject *py_ue_skeletal_mesh_get_raw_indices(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
int lod_index = 0;
if (!PyArg_ParseTuple(args, "|i:skeletal_mesh_get_raw_indices", &lod_index))
return nullptr;
USkeletalMesh *mesh = ue_py_check_type<USkeletalMesh>(self);
if (!mesh)
return PyErr_Format(PyExc_Exception, "uobject is not a USkeletalMesh");
#if ENGINE_MINOR_VERSION < 19
FSkeletalMeshResource *resource = mesh->GetImportedResource();
#else
FSkeletalMeshModel *resource = mesh->GetImportedModel();
#endif
if (lod_index < 0 || lod_index >= resource->LODModels.Num())
return PyErr_Format(PyExc_Exception, "invalid LOD index, must be between 0 and %d", resource->LODModels.Num() - 1);
#if ENGINE_MINOR_VERSION < 19
FStaticLODModel &model = resource->LODModels[lod_index];
#else
FSkeletalMeshLODModel &model = resource->LODModels[lod_index];
#endif
PyObject *py_list = PyList_New(0);
int32 *raw_indices = (int32 *)model.RawPointIndices.Lock(LOCK_READ_ONLY);
int32 *indices = (int32 *)FMemory_Alloca(model.RawPointIndices.GetBulkDataSize());
FMemory::Memcpy(indices, raw_indices, model.RawPointIndices.GetBulkDataSize());
model.RawPointIndices.Unlock();
for (int32 index = 0; index < model.RawPointIndices.GetBulkDataSize() / sizeof(int32); index++)
{
PyList_Append(py_list, PyLong_FromLong(indices[index]));
}
return py_list;
}
#endif
PyObject *py_ue_skeletal_mesh_set_skeleton(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
PyObject *py_skeleton;
if (!PyArg_ParseTuple(args, "O:skeletal_mesh_set_skeleton", &py_skeleton))
return nullptr;
USkeletalMesh *mesh = ue_py_check_type<USkeletalMesh>(self);
if (!mesh)
return PyErr_Format(PyExc_Exception, "UObject is not a USkeletalMesh.");
USkeleton *skeleton = ue_py_check_type<USkeleton>(py_skeleton);
if (!skeleton)
return PyErr_Format(PyExc_Exception, "argument is not a USkeleton.");
mesh->ReleaseResources();
mesh->ReleaseResourcesFence.Wait();
mesh->Skeleton = skeleton;
mesh->RefSkeleton = skeleton->GetReferenceSkeleton();
mesh->RefBasesInvMatrix.Empty();
mesh->CalculateInvRefMatrices();
#if WITH_EDITOR
mesh->PostEditChange();
#endif
mesh->InitResources();
mesh->MarkPackageDirty();
Py_RETURN_NONE;
}
#if WITH_EDITOR
#if ENGINE_MINOR_VERSION > 12
PyObject *py_ue_skeletal_mesh_set_bone_map(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
PyObject *py_map;
int lod_index = 0;
int section_index = 0;
if (!PyArg_ParseTuple(args, "O|ii:skeletal_mesh_set_bone_map", &py_map, &lod_index, §ion_index))
return nullptr;
USkeletalMesh *mesh = ue_py_check_type<USkeletalMesh>(self);
if (!mesh)
return PyErr_Format(PyExc_Exception, "uobject is not a USkeletalMesh");
#if ENGINE_MINOR_VERSION < 19
FSkeletalMeshResource *resource = mesh->GetImportedResource();
#else
FSkeletalMeshModel *resource = mesh->GetImportedModel();
#endif
if (lod_index < 0 || lod_index >= resource->LODModels.Num())
return PyErr_Format(PyExc_Exception, "invalid LOD index, must be between 0 and %d", resource->LODModels.Num() - 1);
#if ENGINE_MINOR_VERSION < 19
FStaticLODModel &model = resource->LODModels[lod_index];
#else
FSkeletalMeshLODModel &model = resource->LODModels[lod_index];
#endif
if (section_index < 0 || section_index >= model.Sections.Num())
return PyErr_Format(PyExc_Exception, "invalid Section index, must be between 0 and %d", model.Sections.Num() - 1);
PyObject *py_iter = PyObject_GetIter(py_map);
if (!py_iter)
{
return PyErr_Format(PyExc_Exception, "argument is not an iterable of numbers");
}
TArray<FBoneIndexType> bone_map;
while (PyObject *py_item = PyIter_Next(py_iter))
{
if (!PyNumber_Check(py_item))
{
Py_DECREF(py_iter);
return PyErr_Format(PyExc_Exception, "argument is not an iterable of numbers");
}
PyObject *py_num = PyNumber_Long(py_item);
uint16 index = PyLong_AsUnsignedLong(py_num);
Py_DECREF(py_num);
bone_map.Add(index);
}
Py_DECREF(py_iter);
// temporarily disable all USkinnedMeshComponent's
TComponentReregisterContext<USkinnedMeshComponent> ReregisterContext;
mesh->ReleaseResources();
mesh->ReleaseResourcesFence.Wait();
model.Sections[section_index].BoneMap = bone_map;
mesh->RefBasesInvMatrix.Empty();
mesh->CalculateInvRefMatrices();
#if WITH_EDITOR
mesh->PostEditChange();
#endif
mesh->InitResources();
mesh->MarkPackageDirty();
Py_RETURN_NONE;
}
#endif
#if ENGINE_MINOR_VERSION > 12
PyObject *py_ue_skeletal_mesh_get_bone_map(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
int lod_index = 0;
int section_index = 0;
if (!PyArg_ParseTuple(args, "|ii:skeletal_mesh_get_bone_map", &lod_index, §ion_index))
return nullptr;
USkeletalMesh *mesh = ue_py_check_type<USkeletalMesh>(self);
if (!mesh)
return PyErr_Format(PyExc_Exception, "uobject is not a USkeletalMesh");
#if ENGINE_MINOR_VERSION < 19
FSkeletalMeshResource *resource = mesh->GetImportedResource();
#else
FSkeletalMeshModel *resource = mesh->GetImportedModel();
#endif
if (lod_index < 0 || lod_index >= resource->LODModels.Num())
return PyErr_Format(PyExc_Exception, "invalid LOD index, must be between 0 and %d", resource->LODModels.Num() - 1);
#if ENGINE_MINOR_VERSION < 19
FStaticLODModel &model = resource->LODModels[lod_index];
#else
FSkeletalMeshLODModel &model = resource->LODModels[lod_index];
#endif
if (section_index < 0 || section_index >= model.Sections.Num())
return PyErr_Format(PyExc_Exception, "invalid Section index, must be between 0 and %d", model.Sections.Num() - 1);
PyObject *py_list = PyList_New(0);
for (uint16 index : model.Sections[section_index].BoneMap)
{
PyList_Append(py_list, PyLong_FromUnsignedLong(index));
}
return py_list;
}
#endif
PyObject *py_ue_skeletal_mesh_get_active_bone_indices(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
int lod_index = 0;
if (!PyArg_ParseTuple(args, "|i:skeletal_mesh_get_active_bone_indices", &lod_index))
return nullptr;
USkeletalMesh *mesh = ue_py_check_type<USkeletalMesh>(self);
if (!mesh)
return PyErr_Format(PyExc_Exception, "uobject is not a USkeletalMesh");
#if ENGINE_MINOR_VERSION < 19
FSkeletalMeshResource *resource = mesh->GetImportedResource();
#else
FSkeletalMeshModel *resource = mesh->GetImportedModel();
#endif
if (lod_index < 0 || lod_index >= resource->LODModels.Num())
return PyErr_Format(PyExc_Exception, "invalid LOD index, must be between 0 and %d", resource->LODModels.Num() - 1);
#if ENGINE_MINOR_VERSION < 19
FStaticLODModel &model = resource->LODModels[lod_index];
#else
FSkeletalMeshLODModel &model = resource->LODModels[lod_index];
#endif
PyObject *py_list = PyList_New(0);
for (uint16 index : model.ActiveBoneIndices)
{
PyList_Append(py_list, PyLong_FromUnsignedLong(index));
}
return py_list;
}
PyObject *py_ue_skeletal_mesh_set_active_bone_indices(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
PyObject *py_map;
int lod_index = 0;
if (!PyArg_ParseTuple(args, "O|i:skeletal_mesh_set_active_bone_indices", &py_map, &lod_index))
return nullptr;
USkeletalMesh *mesh = ue_py_check_type<USkeletalMesh>(self);
if (!mesh)
return PyErr_Format(PyExc_Exception, "uobject is not a USkeletalMesh");
#if ENGINE_MINOR_VERSION < 19
FSkeletalMeshResource *resource = mesh->GetImportedResource();
#else
FSkeletalMeshModel *resource = mesh->GetImportedModel();
#endif
if (lod_index < 0 || lod_index >= resource->LODModels.Num())
return PyErr_Format(PyExc_Exception, "invalid LOD index, must be between 0 and %d", resource->LODModels.Num() - 1);
#if ENGINE_MINOR_VERSION < 19
FStaticLODModel &model = resource->LODModels[lod_index];
#else
FSkeletalMeshLODModel &model = resource->LODModels[lod_index];
#endif
PyObject *py_iter = PyObject_GetIter(py_map);
if (!py_iter)
{
return PyErr_Format(PyExc_Exception, "argument is not an iterable of numbers");
}
TArray<FBoneIndexType> active_indices;
while (PyObject *py_item = PyIter_Next(py_iter))
{
if (!PyNumber_Check(py_item))
{
Py_DECREF(py_iter);
return PyErr_Format(PyExc_Exception, "argument is not an iterable of numbers");
}
PyObject *py_num = PyNumber_Long(py_item);
uint16 index = PyLong_AsUnsignedLong(py_num);
Py_DECREF(py_num);
active_indices.Add(index);
}
Py_DECREF(py_iter);
// temporarily disable all USkinnedMeshComponent's
TComponentReregisterContext<USkinnedMeshComponent> ReregisterContext;
mesh->ReleaseResources();
mesh->ReleaseResourcesFence.Wait();
model.ActiveBoneIndices = active_indices;
model.ActiveBoneIndices.Sort();
mesh->RefBasesInvMatrix.Empty();
mesh->CalculateInvRefMatrices();
#if WITH_EDITOR
mesh->PostEditChange();
#endif
mesh->InitResources();
mesh->MarkPackageDirty();
Py_RETURN_NONE;
}
PyObject *py_ue_skeletal_mesh_get_required_bones(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
int lod_index = 0;
if (!PyArg_ParseTuple(args, "|i:skeletal_mesh_get_required_bones", &lod_index))
return nullptr;
USkeletalMesh *mesh = ue_py_check_type<USkeletalMesh>(self);
if (!mesh)
return PyErr_Format(PyExc_Exception, "uobject is not a USkeletalMesh");
#if ENGINE_MINOR_VERSION < 19
FSkeletalMeshResource *resource = mesh->GetImportedResource();
#else
FSkeletalMeshModel *resource = mesh->GetImportedModel();
#endif
if (lod_index < 0 || lod_index >= resource->LODModels.Num())
return PyErr_Format(PyExc_Exception, "invalid LOD index, must be between 0 and %d", resource->LODModels.Num() - 1);
#if ENGINE_MINOR_VERSION < 19
FStaticLODModel &model = resource->LODModels[lod_index];
#else
FSkeletalMeshLODModel &model = resource->LODModels[lod_index];
#endif
PyObject *py_list = PyList_New(0);
for (uint16 index : model.RequiredBones)
{
PyList_Append(py_list, PyLong_FromUnsignedLong(index));
}
return py_list;
}
PyObject *py_ue_skeletal_mesh_set_required_bones(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
PyObject *py_map;
int lod_index = 0;
if (!PyArg_ParseTuple(args, "O|i:skeletal_mesh_set_required_bones", &py_map, &lod_index))
return nullptr;
USkeletalMesh *mesh = ue_py_check_type<USkeletalMesh>(self);
if (!mesh)
return PyErr_Format(PyExc_Exception, "uobject is not a USkeletalMesh");
#if ENGINE_MINOR_VERSION < 19
FSkeletalMeshResource *resource = mesh->GetImportedResource();
#else
FSkeletalMeshModel *resource = mesh->GetImportedModel();
#endif
if (lod_index < 0 || lod_index >= resource->LODModels.Num())
return PyErr_Format(PyExc_Exception, "invalid LOD index, must be between 0 and %d", resource->LODModels.Num() - 1);
#if ENGINE_MINOR_VERSION < 19
FStaticLODModel &model = resource->LODModels[lod_index];
#else
FSkeletalMeshLODModel &model = resource->LODModels[lod_index];
#endif
PyObject *py_iter = PyObject_GetIter(py_map);
if (!py_iter)
{
return PyErr_Format(PyExc_Exception, "argument is not an iterable of numbers");
}
TArray<FBoneIndexType> required_bones;
while (PyObject *py_item = PyIter_Next(py_iter))
{
if (!PyNumber_Check(py_item))
{
Py_DECREF(py_iter);
return PyErr_Format(PyExc_Exception, "argument is not an iterable of numbers");
}
PyObject *py_num = PyNumber_Long(py_item);
uint16 index = PyLong_AsUnsignedLong(py_num);
Py_DECREF(py_num);
required_bones.Add(index);
}
Py_DECREF(py_iter);
// temporarily disable all USkinnedMeshComponent's
TComponentReregisterContext<USkinnedMeshComponent> ReregisterContext;
mesh->ReleaseResources();
mesh->ReleaseResourcesFence.Wait();
model.RequiredBones = required_bones;
model.RequiredBones.Sort();
mesh->RefBasesInvMatrix.Empty();
mesh->CalculateInvRefMatrices();
#if WITH_EDITOR
mesh->PostEditChange();
#endif
mesh->InitResources();
mesh->MarkPackageDirty();
Py_RETURN_NONE;
}
#endif
#if WITH_EDITOR
PyObject *py_ue_skeletal_mesh_lods_num(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
USkeletalMesh *mesh = ue_py_check_type<USkeletalMesh>(self);
if (!mesh)
return PyErr_Format(PyExc_Exception, "uobject is not a USkeletalMesh");
#if ENGINE_MINOR_VERSION < 19
FSkeletalMeshResource *resource = mesh->GetImportedResource();
#else
FSkeletalMeshModel *resource = mesh->GetImportedModel();
#endif
return PyLong_FromLong(resource->LODModels.Num());
}
PyObject *py_ue_skeletal_mesh_sections_num(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
int lod_index = 0;
if (!PyArg_ParseTuple(args, "|i:skeletal_mesh_sections_num", &lod_index))
return nullptr;
USkeletalMesh *mesh = ue_py_check_type<USkeletalMesh>(self);
if (!mesh)
return PyErr_Format(PyExc_Exception, "uobject is not a USkeletalMesh");
#if ENGINE_MINOR_VERSION < 19
FSkeletalMeshResource *resource = mesh->GetImportedResource();
#else
FSkeletalMeshModel *resource = mesh->GetImportedModel();
#endif
if (lod_index < 0 || lod_index >= resource->LODModels.Num())
return PyErr_Format(PyExc_Exception, "invalid LOD index, must be between 0 and %d", resource->LODModels.Num() - 1);
return PyLong_FromLong(resource->LODModels[lod_index].Sections.Num());
}
PyObject *py_ue_skeletal_mesh_build_lod(ue_PyUObject *self, PyObject * args, PyObject * kwargs)
{
ue_py_check(self);
PyObject *py_ss_vertex;
int lod_index = 0;
PyObject *py_compute_normals = nullptr;
PyObject *py_compute_tangents = nullptr;
PyObject *py_use_mikk = nullptr;
static char *kw_names[] = { (char *)"soft_vertices", (char *)"lod", (char *)"compute_normals", (char *)"compute_tangents", (char *)"use_mikk", nullptr };
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|iOOO:skeletal_mesh_build_lod", kw_names, &py_ss_vertex, &lod_index, &py_compute_normals, &py_compute_tangents, &py_use_mikk))
{
return nullptr;
}
USkeletalMesh *mesh = ue_py_check_type<USkeletalMesh>(self);
if (!mesh)
return PyErr_Format(PyExc_Exception, "uobject is not a SkeletalMesh");
#if ENGINE_MINOR_VERSION < 19
FSkeletalMeshResource *resource = mesh->GetImportedResource();
#else
FSkeletalMeshModel *resource = mesh->GetImportedModel();
#endif
if (lod_index < 0 || lod_index > resource->LODModels.Num())
return PyErr_Format(PyExc_Exception, "invalid LOD index, must be between 0 and %d", resource->LODModels.Num());
mesh->PreEditChange(nullptr);
if (lod_index == resource->LODModels.Num())
{
#if ENGINE_MINOR_VERSION < 19
resource->LODModels.Add(new FStaticLODModel());
#else
resource->LODModels.Add(new FSkeletalMeshLODModel());
#endif
#if ENGINE_MINOR_VERSION < 20
mesh->LODInfo.AddZeroed();
#else
mesh->AddLODInfo();
#endif
}
else
{
// reinitialized already existent LOD
#if ENGINE_MINOR_VERSION < 19
new(&resource->LODModels[lod_index]) FStaticLODModel();
#else
new(&resource->LODModels[lod_index]) FSkeletalMeshLODModel();
#endif
}
#if ENGINE_MINOR_VERSION < 19
FStaticLODModel& LODModel = resource->LODModels[lod_index];
#else
FSkeletalMeshLODModel& LODModel = resource->LODModels[lod_index];
#endif
#if ENGINE_MINOR_VERSION < 20
mesh->LODInfo[lod_index].LODHysteresis = 0.02;
#else
mesh->GetLODInfo(lod_index)->LODHysteresis = 0.02;
#endif
FSkeletalMeshOptimizationSettings settings;
#if ENGINE_MINOR_VERSION < 20
mesh->LODInfo[lod_index].ReductionSettings = settings;
#else
mesh->GetLODInfo(lod_index)->ReductionSettings = settings;
#endif
LODModel.NumTexCoords = 1;
IMeshUtilities & MeshUtilities = FModuleManager::Get().LoadModuleChecked<IMeshUtilities>("MeshUtilities");
PyObject *py_iter = PyObject_GetIter(py_ss_vertex);
if (!py_iter)
{
return PyErr_Format(PyExc_Exception, "argument is not an iterable of FSoftSkinVertex");
}
TArray<FSoftSkinVertex> soft_vertices;
TArray<FVector> points;
#if ENGINE_MINOR_VERSION > 20
TArray<SkeletalMeshImportData::FMeshWedge> wedges;
TArray<SkeletalMeshImportData::FMeshFace> faces;
TArray<SkeletalMeshImportData::FVertInfluence> influences;
#else
TArray<FMeshWedge> wedges;
TArray<FMeshFace> faces;
TArray<FVertInfluence> influences;
#endif
TArray<int32> points_to_map;
TArray<FVector> tangentsX;
TArray<FVector> tangentsY;
TArray<FVector> tangentsZ;
TArray<uint16> material_indices;
TArray<uint32> smoothing_groups;
while (PyObject *py_item = PyIter_Next(py_iter))
{
ue_PyFSoftSkinVertex *ss_vertex = py_ue_is_fsoft_skin_vertex(py_item);
if (!ss_vertex)
{
Py_DECREF(py_iter);
return PyErr_Format(PyExc_Exception, "argument is not an iterable of FSoftSkinVertex");
}
int32 vertex_index = points.Add(ss_vertex->ss_vertex.Position);
points_to_map.Add(vertex_index);
#if ENGINE_MINOR_VERSION > 20
SkeletalMeshImportData::FMeshWedge wedge;
#else
FMeshWedge wedge;
#endif
wedge.iVertex = vertex_index;
wedge.Color = ss_vertex->ss_vertex.Color;
for (int32 i = 0; i < MAX_TEXCOORDS; i++)
{
wedge.UVs[i] = ss_vertex->ss_vertex.UVs[i];
}
int32 wedge_index = wedges.Add(wedge);
for (int32 i = 0; i < MAX_TOTAL_INFLUENCES; i++)
{
#if ENGINE_MINOR_VERSION > 20
SkeletalMeshImportData::FVertInfluence influence;
#else
FVertInfluence influence;
#endif
influence.VertIndex = wedge_index;
influence.BoneIndex = ss_vertex->ss_vertex.InfluenceBones[i];
influence.Weight = ss_vertex->ss_vertex.InfluenceWeights[i] / 255.f;
influences.Add(influence);
}
tangentsX.Add(ss_vertex->ss_vertex.TangentX);
tangentsY.Add(ss_vertex->ss_vertex.TangentY);
tangentsZ.Add(ss_vertex->ss_vertex.TangentZ);
material_indices.Add(ss_vertex->material_index);
smoothing_groups.Add(ss_vertex->smoothing_group);
}
Py_DECREF(py_iter);
if (wedges.Num() % 3 != 0)
return PyErr_Format(PyExc_Exception, "invalid number of FSoftSkinVertex, must be a multiple of 3");
for (int32 i = 0; i < wedges.Num(); i += 3)
{
#if ENGINE_MINOR_VERSION > 20
SkeletalMeshImportData::FMeshFace face;
#else
FMeshFace face;
#endif
face.iWedge[0] = i;
face.iWedge[1] = i + 1;
face.iWedge[2] = i + 2;
face.MeshMaterialIndex = material_indices[i];
face.SmoothingGroups = smoothing_groups[i];
face.TangentX[0] = tangentsX[i];
face.TangentX[1] = tangentsX[i + 1];
face.TangentX[2] = tangentsX[i + 2];
face.TangentY[0] = tangentsY[i];
face.TangentY[1] = tangentsY[i + 1];
face.TangentY[2] = tangentsY[i + 2];
face.TangentZ[0] = tangentsZ[i];
face.TangentZ[1] = tangentsZ[i + 1];
face.TangentZ[2] = tangentsZ[i + 2];
faces.Add(face);
}
#if ENGINE_MINOR_VERSION < 19
FStaticLODModel & lod_model = resource->LODModels[lod_index];
#else
FSkeletalMeshLODModel & lod_model = resource->LODModels[lod_index];
#endif
IMeshUtilities::MeshBuildOptions build_settings;
build_settings.bUseMikkTSpace = (py_use_mikk && PyObject_IsTrue(py_use_mikk));
build_settings.bComputeNormals = (py_compute_normals && PyObject_IsTrue(py_compute_normals));
build_settings.bComputeTangents = (py_compute_tangents && PyObject_IsTrue(py_compute_tangents));
build_settings.bRemoveDegenerateTriangles = true;
bool success = MeshUtilities.BuildSkeletalMesh(lod_model, mesh->RefSkeleton, influences, wedges, faces, points, points_to_map, build_settings);
if (!success)
{
return PyErr_Format(PyExc_Exception, "unable to create new Skeletal LOD");
}
#if ENGINE_MINOR_VERSION < 19
for (int32 i = 0; i < lod_model.Sections.Num(); i++)
{
mesh->LODInfo[lod_index].TriangleSortSettings.AddZeroed();
}
#endif
mesh->CalculateRequiredBones(LODModel, mesh->RefSkeleton, nullptr);
mesh->CalculateInvRefMatrices();
mesh->Skeleton->RecreateBoneTree(mesh);
mesh->Skeleton->SetPreviewMesh(mesh);
// calculate bounds from points
mesh->SetImportedBounds(FBoxSphereBounds(points.GetData(), points.Num()));
mesh->Skeleton->PostEditChange();
mesh->Skeleton->MarkPackageDirty();
mesh->PostEditChange();
mesh->MarkPackageDirty();
Py_RETURN_NONE;
}
PyObject *py_ue_skeletal_mesh_register_morph_target(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
PyObject *py_morph;
if (!PyArg_ParseTuple(args, "O:skeletal_mesh_register_morph_target", &py_morph))
{
return nullptr;
}
USkeletalMesh *mesh = ue_py_check_type<USkeletalMesh>(self);
if (!mesh)
return PyErr_Format(PyExc_Exception, "uobject is not a SkeletalMesh");
UMorphTarget *morph = ue_py_check_type<UMorphTarget>(py_morph);
if (!morph)
return PyErr_Format(PyExc_Exception, "argument is not a MorphTarget");
#if ENGINE_MINOR_VERSION > 16
if (!morph->HasValidData())
return PyErr_Format(PyExc_Exception, "the MorphTarget has no valid data");
#endif
mesh->PreEditChange(nullptr);
mesh->RegisterMorphTarget(morph);
mesh->PostEditChange();
mesh->MarkPackageDirty();
Py_RETURN_NONE;
}
PyObject *py_ue_morph_target_populate_deltas(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
PyObject *py_deltas;
int lod_index = 0;
if (!PyArg_ParseTuple(args, "O|i:morph_target_populate_deltas", &py_deltas, &lod_index))
{
return nullptr;
}
UMorphTarget *morph = ue_py_check_type<UMorphTarget>(self);
if (!morph)
return PyErr_Format(PyExc_Exception, "uobject is not a MorphTarget");
if (lod_index < 0)
return PyErr_Format(PyExc_Exception, "invalid LOD index");
PyObject *py_iter = PyObject_GetIter(py_deltas);
if (!py_iter)
return PyErr_Format(PyExc_Exception, "argument is not an iterable of FMorphTargetDelta");
TArray<FMorphTargetDelta> deltas;
while (PyObject *py_item = PyIter_Next(py_iter))
{
ue_PyFMorphTargetDelta *py_delta = py_ue_is_fmorph_target_delta(py_item);
if (!py_delta)
{
Py_DECREF(py_iter);
return PyErr_Format(PyExc_Exception, "argument is not an iterable of FMorphTargetDelta");
}
deltas.Add(py_delta->morph_target_delta);
}
Py_DECREF(py_iter);
#if ENGINE_MINOR_VERSION < 19
morph->PopulateDeltas(deltas, lod_index);
#else
FSkeletalMeshModel *model = morph->BaseSkelMesh->GetImportedModel();
morph->PopulateDeltas(deltas, lod_index, model->LODModels[lod_index].Sections);
#endif
#if ENGINE_MINOR_VERSION > 16
if (morph->HasValidData())
{
Py_RETURN_TRUE;
}
Py_RETURN_FALSE;
#else
Py_RETURN_TRUE;
#endif
}
PyObject *py_ue_morph_target_get_deltas(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
int lod_index = 0;
if (!PyArg_ParseTuple(args, "|i:morph_target_get_deltas", &lod_index))
{
return nullptr;
}
UMorphTarget *morph = ue_py_check_type<UMorphTarget>(self);
if (!morph)
return PyErr_Format(PyExc_Exception, "uobject is not a MorphTarget");
if (lod_index < 0 || lod_index > morph->MorphLODModels.Num())
return PyErr_Format(PyExc_Exception, "invalid LOD index");
PyObject *py_list = PyList_New(0);
for (FMorphTargetDelta delta : morph->MorphLODModels[lod_index].Vertices)
{
PyList_Append(py_list, py_ue_new_fmorph_target_delta(delta));
}
return py_list;
}
PyObject *py_ue_skeletal_mesh_to_import_vertex_map(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
int lod_index = 0;
if (!PyArg_ParseTuple(args, "|i:skeletal_mesh_to_import_vertex_map", &lod_index))
{
return nullptr;
}
USkeletalMesh *mesh = ue_py_check_type<USkeletalMesh>(self);
if (!mesh)
return PyErr_Format(PyExc_Exception, "uobject is not a USkeletalMesh");
#if ENGINE_MINOR_VERSION < 19
FSkeletalMeshResource *resource = mesh->GetImportedResource();
#else
FSkeletalMeshModel *resource = mesh->GetImportedModel();
#endif
if (lod_index < 0 || lod_index > resource->LODModels.Num())
return PyErr_Format(PyExc_Exception, "invalid LOD index, must be between 0 and %d", resource->LODModels.Num());
#if ENGINE_MINOR_VERSION < 19
FStaticLODModel& LODModel = resource->LODModels[lod_index];
#else
FSkeletalMeshLODModel &LODModel = resource->LODModels[lod_index];
#endif
PyObject *py_list = PyList_New(0);
for (int32 value : LODModel.MeshToImportVertexMap)
{
PyList_Append(py_list, PyLong_FromLong(value));
}
return py_list;
}
#endif
```
|
/content/code_sandbox/Source/UnrealEnginePython/Private/UObject/UEPySkeletal.cpp
|
c++
| 2016-08-07T05:00:51
| 2024-08-14T06:32:20
|
UnrealEnginePython
|
20tab/UnrealEnginePython
| 2,715
| 9,554
|
```objective-c
#pragma once
#include "UEPyModule.h"
PyObject *py_ue_line_trace_single_by_channel(ue_PyUObject *, PyObject *);
PyObject *py_ue_line_trace_multi_by_channel(ue_PyUObject *, PyObject *);
PyObject *py_ue_get_hit_result_under_cursor(ue_PyUObject *, PyObject *);
PyObject *py_ue_draw_debug_line(ue_PyUObject *, PyObject *);
```
|
/content/code_sandbox/Source/UnrealEnginePython/Private/UObject/UEPyTraceAndSweep.h
|
objective-c
| 2016-08-07T05:00:51
| 2024-08-14T06:32:20
|
UnrealEnginePython
|
20tab/UnrealEnginePython
| 2,715
| 82
|
```objective-c
#pragma once
#include "UEPyModule.h"
PyObject *py_ue_hud_draw_2d_line(ue_PyUObject *self, PyObject * args);
PyObject *py_ue_hud_draw_line(ue_PyUObject *self, PyObject * args);
PyObject *py_ue_hud_draw_texture(ue_PyUObject *self, PyObject * args);
PyObject *py_ue_hud_draw_text(ue_PyUObject *self, PyObject * args);
PyObject *py_ue_hud_draw_rect(ue_PyUObject *self, PyObject * args);
```
|
/content/code_sandbox/Source/UnrealEnginePython/Private/UObject/UEPyHUD.h
|
objective-c
| 2016-08-07T05:00:51
| 2024-08-14T06:32:20
|
UnrealEnginePython
|
20tab/UnrealEnginePython
| 2,715
| 119
|
```objective-c
#pragma once
#include "UEPyModule.h"
PyObject *py_ue_capture_initialize(ue_PyUObject *, PyObject *);
PyObject *py_ue_capture_start(ue_PyUObject *, PyObject *);
PyObject *py_ue_capture_load_from_config(ue_PyUObject *, PyObject *);
PyObject *py_ue_capture_stop(ue_PyUObject *, PyObject *);
PyObject *py_ue_set_level_sequence_asset(ue_PyUObject *, PyObject *);
PyObject *py_unreal_engine_in_editor_capture(PyObject *, PyObject *);
```
|
/content/code_sandbox/Source/UnrealEnginePython/Private/UObject/UEPyCapture.h
|
objective-c
| 2016-08-07T05:00:51
| 2024-08-14T06:32:20
|
UnrealEnginePython
|
20tab/UnrealEnginePython
| 2,715
| 104
|
```c++
#include "UEPyTexture.h"
#include "Runtime/Engine/Public/ImageUtils.h"
#include "Runtime/Engine/Classes/Engine/Texture.h"
#include "Engine/TextureRenderTarget2D.h"
#include "Engine/Texture2D.h"
PyObject *py_ue_texture_update_resource(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
UTexture *texture = ue_py_check_type<UTexture>(self);
if (!texture)
return PyErr_Format(PyExc_Exception, "object is not a Texture");
Py_BEGIN_ALLOW_THREADS;
texture->UpdateResource();
Py_END_ALLOW_THREADS;
Py_RETURN_NONE;
}
PyObject *py_ue_texture_get_width(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
UTexture2D *texture = ue_py_check_type<UTexture2D>(self);
if (!texture)
return PyErr_Format(PyExc_Exception, "object is not a Texture");
return PyLong_FromLong(texture->GetSizeX());
}
PyObject *py_ue_texture_get_height(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
UTexture2D *texture = ue_py_check_type<UTexture2D>(self);
if (!texture)
return PyErr_Format(PyExc_Exception, "object is not a Texture");
return PyLong_FromLong(texture->GetSizeY());
}
PyObject *py_ue_texture_has_alpha_channel(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
UTexture2D *texture = ue_py_check_type<UTexture2D>(self);
if (!texture)
return PyErr_Format(PyExc_Exception, "object is not a Texture");
if (texture->HasAlphaChannel())
Py_RETURN_TRUE;
Py_RETURN_FALSE;
}
PyObject *py_ue_texture_get_data(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
int mipmap = 0;
if (!PyArg_ParseTuple(args, "|i:texture_get_data", &mipmap))
{
return NULL;
}
UTexture2D *tex = ue_py_check_type<UTexture2D>(self);
if (!tex)
return PyErr_Format(PyExc_Exception, "object is not a Texture2D");
if (mipmap >= tex->GetNumMips())
return PyErr_Format(PyExc_Exception, "invalid mipmap id");
const char *blob = (const char*)tex->PlatformData->Mips[mipmap].BulkData.Lock(LOCK_READ_ONLY);
PyObject *bytes = PyByteArray_FromStringAndSize(blob, (Py_ssize_t)tex->PlatformData->Mips[mipmap].BulkData.GetBulkDataSize());
tex->PlatformData->Mips[mipmap].BulkData.Unlock();
return bytes;
}
#if WITH_EDITOR
PyObject *py_ue_texture_get_source_data(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
int mipmap = 0;
if (!PyArg_ParseTuple(args, "|i:texture_get_data", &mipmap))
{
return nullptr;
}
UTexture2D *tex = ue_py_check_type<UTexture2D>(self);
if (!tex)
return PyErr_Format(PyExc_Exception, "object is not a Texture2D");
if (mipmap >= tex->GetNumMips())
return PyErr_Format(PyExc_Exception, "invalid mipmap id");
const uint8 *blob = tex->Source.LockMip(mipmap);
PyObject *bytes = PyByteArray_FromStringAndSize((const char *)blob, (Py_ssize_t)tex->Source.CalcMipSize(mipmap));
tex->Source.UnlockMip(mipmap);
return bytes;
}
PyObject *py_ue_texture_set_source_data(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
Py_buffer py_buf;
int mipmap = 0;
if (!PyArg_ParseTuple(args, "z*|i:texture_set_source_data", &py_buf, &mipmap))
{
return NULL;
}
UTexture2D *tex = ue_py_check_type<UTexture2D>(self);
if (!tex)
{
PyBuffer_Release(&py_buf);
return PyErr_Format(PyExc_Exception, "object is not a Texture2D");
}
if (!py_buf.buf)
{
PyBuffer_Release(&py_buf);
return PyErr_Format(PyExc_Exception, "invalid data");
}
if (mipmap >= tex->GetNumMips())
{
PyBuffer_Release(&py_buf);
return PyErr_Format(PyExc_Exception, "invalid mipmap id");
}
int32 wanted_len = py_buf.len;
int32 len = tex->Source.GetSizeX() * tex->Source.GetSizeY() * 4;
// avoid making mess
if (wanted_len > len)
{
UE_LOG(LogPython, Warning, TEXT("truncating buffer to %d bytes"), len);
wanted_len = len;
}
const uint8 *blob = tex->Source.LockMip(mipmap);
FMemory::Memcpy((void *)blob, py_buf.buf, wanted_len);
PyBuffer_Release(&py_buf);
tex->Source.UnlockMip(mipmap);
Py_BEGIN_ALLOW_THREADS;
tex->MarkPackageDirty();
#if WITH_EDITOR
tex->PostEditChange();
#endif
tex->UpdateResource();
Py_END_ALLOW_THREADS;
Py_RETURN_NONE;
}
#endif
PyObject *py_ue_render_target_get_data(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
int mipmap = 0;
if (!PyArg_ParseTuple(args, "|i:render_target_get_data", &mipmap))
{
return NULL;
}
UTextureRenderTarget2D *tex = ue_py_check_type<UTextureRenderTarget2D>(self);
if (!tex)
return PyErr_Format(PyExc_Exception, "object is not a TextureRenderTarget");
FTextureRenderTarget2DResource *resource = (FTextureRenderTarget2DResource *)tex->Resource;
if (!resource)
{
return PyErr_Format(PyExc_Exception, "cannot get render target resource");
}
TArray<FColor> pixels;
if (!resource->IsSupportedFormat(tex->GetFormat()))
{
return PyErr_Format(PyExc_Exception, "unsupported format for render texture");
}
if (!resource->ReadPixels(pixels))
{
return PyErr_Format(PyExc_Exception, "unable to read pixels");
}
return PyByteArray_FromStringAndSize((const char *)pixels.GetData(), (Py_ssize_t)(pixels.GetTypeSize() * pixels.Num()));
}
PyObject *py_ue_render_target_get_data_to_buffer(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
Py_buffer py_buf;
int mipmap = 0;
if (!PyArg_ParseTuple(args, "z*|i:render_target_get_data_to_buffer", &py_buf, &mipmap))
{
return NULL;
}
UTextureRenderTarget2D *tex = ue_py_check_type<UTextureRenderTarget2D>(self);
if (!tex)
{
PyBuffer_Release(&py_buf);
return PyErr_Format(PyExc_Exception, "object is not a TextureRenderTarget");
}
FTextureRenderTarget2DResource *resource = (FTextureRenderTarget2DResource *)tex->Resource;
if (!resource)
{
PyBuffer_Release(&py_buf);
return PyErr_Format(PyExc_Exception, "cannot get render target resource");
}
Py_ssize_t data_len = (Py_ssize_t)(tex->GetSurfaceWidth() * 4 * tex->GetSurfaceHeight());
if (py_buf.len < data_len)
{
PyBuffer_Release(&py_buf);
return PyErr_Format(PyExc_Exception, "buffer is not big enough");
}
TArray<FColor> pixels;
if (!resource->ReadPixels(pixels))
{
PyBuffer_Release(&py_buf);
return PyErr_Format(PyExc_Exception, "unable to read pixels");
}
FMemory::Memcpy(py_buf.buf, pixels.GetData(), data_len);
PyBuffer_Release(&py_buf);
Py_RETURN_NONE;
}
PyObject *py_ue_texture_set_data(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
Py_buffer py_buf;
int mipmap = 0;
if (!PyArg_ParseTuple(args, "z*|i:texture_set_data", &py_buf, &mipmap))
{
return NULL;
}
UTexture2D *tex = ue_py_check_type<UTexture2D>(self);
if (!tex)
{
PyBuffer_Release(&py_buf);
return PyErr_Format(PyExc_Exception, "object is not a Texture2D");
}
if (!py_buf.buf)
{
PyBuffer_Release(&py_buf);
return PyErr_Format(PyExc_Exception, "invalid data");
}
if (mipmap >= tex->GetNumMips())
{
PyBuffer_Release(&py_buf);
return PyErr_Format(PyExc_Exception, "invalid mipmap id");
}
char *blob = (char*)tex->PlatformData->Mips[mipmap].BulkData.Lock(LOCK_READ_WRITE);
int32 len = tex->PlatformData->Mips[mipmap].BulkData.GetBulkDataSize();
int32 wanted_len = py_buf.len;
// avoid making mess
if (wanted_len > len)
{
UE_LOG(LogPython, Warning, TEXT("truncating buffer to %d bytes"), len);
wanted_len = len;
}
FMemory::Memcpy(blob, py_buf.buf, wanted_len);
PyBuffer_Release(&py_buf);
tex->PlatformData->Mips[mipmap].BulkData.Unlock();
Py_BEGIN_ALLOW_THREADS;
tex->MarkPackageDirty();
#if WITH_EDITOR
tex->PostEditChange();
#endif
tex->UpdateResource();
Py_END_ALLOW_THREADS;
Py_RETURN_NONE;
}
PyObject *py_unreal_engine_compress_image_array(PyObject * self, PyObject * args)
{
int width;
int height;
Py_buffer py_buf;
if (!PyArg_ParseTuple(args, "iiz*:compress_image_array", &width, &height, &py_buf))
{
return NULL;
}
if (py_buf.buf == nullptr || py_buf.len <= 0)
{
PyBuffer_Release(&py_buf);
return PyErr_Format(PyExc_Exception, "invalid image data");
}
TArray<FColor> colors;
uint8 *buf = (uint8 *)py_buf.buf;
for (int32 i = 0; i < py_buf.len; i += 4)
{
colors.Add(FColor(buf[i], buf[1 + 1], buf[i + 2], buf[i + 3]));
}
PyBuffer_Release(&py_buf);
TArray<uint8> output;
Py_BEGIN_ALLOW_THREADS;
FImageUtils::CompressImageArray(width, height, colors, output);
Py_END_ALLOW_THREADS;
return PyBytes_FromStringAndSize((char *)output.GetData(), output.Num());
}
PyObject *py_unreal_engine_create_checkerboard_texture(PyObject * self, PyObject * args)
{
PyObject *py_color_one;
PyObject *py_color_two;
int checker_size;
if (!PyArg_ParseTuple(args, "OOi:create_checkboard_texture", &py_color_one, &py_color_two, &checker_size))
{
return NULL;
}
ue_PyFColor *color_one = py_ue_is_fcolor(py_color_one);
if (!color_one)
return PyErr_Format(PyExc_Exception, "argument is not a FColor");
ue_PyFColor *color_two = py_ue_is_fcolor(py_color_two);
if (!color_two)
return PyErr_Format(PyExc_Exception, "argument is not a FColor");
UTexture2D *texture = nullptr;
Py_BEGIN_ALLOW_THREADS;
texture = FImageUtils::CreateCheckerboardTexture(color_one->color, color_two->color, checker_size);
Py_END_ALLOW_THREADS;
Py_RETURN_UOBJECT(texture);
}
PyObject *py_unreal_engine_create_transient_texture(PyObject * self, PyObject * args)
{
int width;
int height;
int format = PF_B8G8R8A8;
if (!PyArg_ParseTuple(args, "ii|i:create_transient_texture", &width, &height, &format))
{
return NULL;
}
UTexture2D *texture = UTexture2D::CreateTransient(width, height, (EPixelFormat)format);
if (!texture)
return PyErr_Format(PyExc_Exception, "unable to create texture");
Py_BEGIN_ALLOW_THREADS;
texture->UpdateResource();
Py_END_ALLOW_THREADS;
Py_RETURN_UOBJECT(texture);
}
PyObject *py_unreal_engine_create_transient_texture_render_target2d(PyObject * self, PyObject * args)
{
int width;
int height;
int format = PF_B8G8R8A8;
PyObject *py_linear = nullptr;
if (!PyArg_ParseTuple(args, "ii|iO:create_transient_texture_render_target2d", &width, &height, &format, &py_linear))
{
return NULL;
}
UTextureRenderTarget2D *texture = NewObject<UTextureRenderTarget2D>(GetTransientPackage(), NAME_None, RF_Transient);
if (!texture)
return PyErr_Format(PyExc_Exception, "unable to create texture render target");
Py_BEGIN_ALLOW_THREADS;
texture->InitCustomFormat(width, height, (EPixelFormat)format, py_linear && PyObject_IsTrue(py_linear));
Py_END_ALLOW_THREADS;
Py_RETURN_UOBJECT(texture);
}
#if WITH_EDITOR
PyObject *py_unreal_engine_create_texture(PyObject * self, PyObject * args)
{
PyObject *py_package;
char *name;
int width;
int height;
Py_buffer py_buf;
if (!PyArg_ParseTuple(args, "Osiiz*:create_texture", &py_package, &name, &width, &height, &py_buf))
{
return nullptr;
}
UPackage *u_package = nullptr;
if (py_package == Py_None)
{
u_package = GetTransientPackage();
}
else
{
u_package = ue_py_check_type<UPackage>(py_package);
if (!u_package)
{
PyBuffer_Release(&py_buf);
return PyErr_Format(PyExc_Exception, "argument is not a UPackage");
}
}
SIZE_T wanted_len = width * height * 4;
TArray<FColor> colors;
colors.AddZeroed(wanted_len);
FCreateTexture2DParameters params;
if ((SIZE_T)py_buf.len < wanted_len)
wanted_len = py_buf.len;
FMemory::Memcpy(colors.GetData(), py_buf.buf, wanted_len);
PyBuffer_Release(&py_buf);
UTexture2D *texture = FImageUtils::CreateTexture2D(width, height, colors, u_package, UTF8_TO_TCHAR(name), RF_Public | RF_Standalone, params);
if (!texture)
return PyErr_Format(PyExc_Exception, "unable to create texture");
Py_RETURN_UOBJECT(texture);
}
#endif
```
|
/content/code_sandbox/Source/UnrealEnginePython/Private/UObject/UEPyTexture.cpp
|
c++
| 2016-08-07T05:00:51
| 2024-08-14T06:32:20
|
UnrealEnginePython
|
20tab/UnrealEnginePython
| 2,715
| 3,110
|
```objective-c
#pragma once
#include "UEPyModule.h"
PyObject *py_ue_set_simulate_physics(ue_PyUObject *, PyObject *);
PyObject *py_ue_add_impulse(ue_PyUObject *, PyObject *);
PyObject *py_ue_add_angular_impulse(ue_PyUObject *, PyObject *);
PyObject *py_ue_add_force(ue_PyUObject *, PyObject *);
PyObject *py_ue_add_torque(ue_PyUObject *, PyObject *);
PyObject *py_ue_set_physics_linear_velocity(ue_PyUObject *, PyObject *);
PyObject *py_ue_get_physics_linear_velocity(ue_PyUObject *, PyObject *);
PyObject *py_ue_set_physics_angular_velocity(ue_PyUObject *, PyObject *);
PyObject *py_ue_get_physics_angular_velocity(ue_PyUObject *, PyObject *);
PyObject *py_ue_destructible_apply_damage(ue_PyUObject *, PyObject *);
```
|
/content/code_sandbox/Source/UnrealEnginePython/Private/UObject/UEPyPhysics.h
|
objective-c
| 2016-08-07T05:00:51
| 2024-08-14T06:32:20
|
UnrealEnginePython
|
20tab/UnrealEnginePython
| 2,715
| 186
|
```c++
#include "UEPyActor.h"
#if WITH_EDITOR
#include "Editor.h"
#include "Editor/UnrealEd/Public/ComponentTypeRegistry.h"
#endif
PyObject *py_ue_actor_has_tag(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
char *tag;
if (!PyArg_ParseTuple(args, "s:actor_has_tag", &tag))
{
return nullptr;
}
AActor *actor = ue_py_check_type<AActor>(self);
if (!actor)
return PyErr_Format(PyExc_Exception, "uobject is not an AActor");
if (actor->ActorHasTag(FName(UTF8_TO_TCHAR(tag))))
{
Py_RETURN_TRUE;
}
Py_RETURN_FALSE;
}
PyObject *py_ue_component_has_tag(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
char *tag;
if (!PyArg_ParseTuple(args, "s:component_has_tag", &tag))
{
return nullptr;
}
UActorComponent *component = ue_py_check_type<UActorComponent>(self);
if (!component)
return PyErr_Format(PyExc_Exception, "uobject is not an UActorComponent");
if (component->ComponentHasTag(FName(UTF8_TO_TCHAR(tag))))
{
Py_RETURN_TRUE;
}
Py_RETURN_FALSE;
}
PyObject *py_ue_actor_begin_play(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
AActor *actor = ue_py_check_type<AActor>(self);
if (!actor)
return PyErr_Format(PyExc_Exception, "uobject is not an AActor");
Py_BEGIN_ALLOW_THREADS;
#if ENGINE_MINOR_VERSION > 14
actor->DispatchBeginPlay();
#else
actor->BeginPlay();
#endif
Py_END_ALLOW_THREADS;
Py_RETURN_NONE;
}
PyObject *py_ue_get_actor_bounds(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
AActor *actor = ue_py_check_type<AActor>(self);
if (!actor)
return PyErr_Format(PyExc_Exception, "uobject is not an AActor");
FVector origin;
FVector extent;
actor->GetActorBounds(false, origin, extent);
return Py_BuildValue("OO", py_ue_new_fvector(origin), py_ue_new_fvector(extent));
}
PyObject *py_ue_get_actor_component(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
AActor *actor = ue_get_actor(self);
if (!actor)
return PyErr_Format(PyExc_Exception, "cannot retrieve Actor from uobject");
char *name;
if (!PyArg_ParseTuple(args, "s:get_actor_component", &name))
{
return NULL;
}
for (UActorComponent *component : actor->GetComponents())
{
if (component->GetName().Equals(UTF8_TO_TCHAR(name)))
{
Py_RETURN_UOBJECT(component);
}
}
Py_RETURN_NONE;
}
PyObject *py_ue_actor_destroy_component(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
AActor *actor = ue_get_actor(self);
if (!actor)
return PyErr_Format(PyExc_Exception, "cannot retrieve Actor from uobject");
PyObject *py_component;
if (!PyArg_ParseTuple(args, "O:actor_destroy_component", &py_component))
{
return NULL;
}
UActorComponent *component = ue_py_check_type<UActorComponent>(py_component);
if (!component)
return PyErr_Format(PyExc_Exception, "argument is not a UActorComponent");
Py_BEGIN_ALLOW_THREADS
#if ENGINE_MINOR_VERSION >= 17
component->DestroyComponent();
#else
actor->K2_DestroyComponent(component);
#endif
Py_END_ALLOW_THREADS
Py_RETURN_NONE;
}
PyObject *py_ue_actor_destroy(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
AActor *actor = ue_py_check_type<AActor>(self);
if (!actor)
{
return PyErr_Format(PyExc_Exception, "uobject is not an AActor");
}
Py_BEGIN_ALLOW_THREADS;
actor->Destroy();
Py_END_ALLOW_THREADS;
Py_RETURN_NONE;
}
PyObject *py_ue_actor_components(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
AActor *actor = ue_get_actor(self);
if (!actor)
return PyErr_Format(PyExc_Exception, "cannot retrieve Actor from uobject");
PyObject *ret = PyList_New(0);
for (UActorComponent *component : actor->GetComponents())
{
ue_PyUObject *py_obj = ue_get_python_uobject(component);
if (!py_obj)
continue;
PyList_Append(ret, (PyObject *)py_obj);
}
return ret;
}
PyObject *py_ue_get_actor_velocity(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
AActor *actor = ue_get_actor(self);
if (!actor)
return PyErr_Format(PyExc_Exception, "uobject is not an actor or a component");
return py_ue_new_fvector(actor->GetVelocity());
}
#if WITH_EDITOR
PyObject *py_ue_component_type_registry_invalidate_class(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
UClass *Class = ue_py_check_type<UClass>(self);
if (!Class)
return PyErr_Format(PyExc_Exception, "uobject is not a UClass");
if (!Class->IsChildOf<UActorComponent>())
{
return PyErr_Format(PyExc_Exception, "uobject is not a subclass of UActorComponent");
}
FComponentTypeRegistry::Get().InvalidateClass(Class);
Py_RETURN_NONE;
}
PyObject *py_ue_get_folder_path(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
AActor *actor = ue_py_check_type<AActor>(self);
if (!actor)
return PyErr_Format(PyExc_Exception, "uobject is not an actor");
const FName DirPath = actor->GetFolderPath();
return PyUnicode_FromString(TCHAR_TO_UTF8(*DirPath.ToString()));
}
PyObject *py_ue_set_folder_path(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
char *path;
PyObject *py_bool = nullptr;
if (!PyArg_ParseTuple(args, "s|O:set_folder_path", &path, &py_bool))
return nullptr;
AActor *actor = ue_py_check_type<AActor>(self);
if (!actor)
return PyErr_Format(PyExc_Exception, "uobject is not an actor");
FName DirPath = FName(UTF8_TO_TCHAR(path));
if (py_bool && PyObject_IsTrue(py_bool))
{
actor->SetFolderPath_Recursively(DirPath);
}
else
{
actor->SetFolderPath(DirPath);
}
Py_RETURN_NONE;
}
PyObject *py_ue_get_actor_label(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
if (self->ue_object->IsA<AActor>())
{
AActor *actor = (AActor *)self->ue_object;
return PyUnicode_FromString(TCHAR_TO_UTF8(*(actor->GetActorLabel())));
}
if (self->ue_object->IsA<UActorComponent>())
{
UActorComponent *component = (UActorComponent *)self->ue_object;
return PyUnicode_FromString(TCHAR_TO_UTF8(*(component->GetOwner()->GetActorLabel())));
}
return PyErr_Format(PyExc_Exception, "uobject is not an actor or a component");
}
PyObject *py_ue_set_actor_label(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
AActor *actor = ue_get_actor(self);
if (!actor)
return PyErr_Format(PyExc_Exception, "cannot retrieve Actor from uobject");
char *label;
if (!PyArg_ParseTuple(args, "s:set_actor_label", &label))
{
return NULL;
}
actor->SetActorLabel(UTF8_TO_TCHAR(label), true);
Py_RETURN_NONE;
}
PyObject *py_ue_set_actor_hidden_in_game(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
AActor *actor = ue_get_actor(self);
if (!actor)
return PyErr_Format(PyExc_Exception, "cannot retrieve Actor from uobject");
PyObject *py_bool = nullptr;
if (!PyArg_ParseTuple(args, "O:set_actor_hidden_in_game", &py_bool))
{
return nullptr;
}
if (PyObject_IsTrue(py_bool))
{
actor->SetActorHiddenInGame(true);
}
else
{
actor->SetActorHiddenInGame(false);
}
Py_RETURN_NONE;
}
PyObject *py_ue_find_actor_by_label(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
char *name;
if (!PyArg_ParseTuple(args, "s:find_actor_by_label", &name))
{
return NULL;
}
UWorld *world = ue_get_uworld(self);
if (!world)
return PyErr_Format(PyExc_Exception, "unable to retrieve UWorld from uobject");
UObject *u_object = nullptr;
for (TActorIterator<AActor> Itr(world); Itr; ++Itr)
{
AActor *u_obj = *Itr;
if (u_obj->GetActorLabel().Equals(UTF8_TO_TCHAR(name)))
{
u_object = u_obj;
break;
}
}
if (u_object)
{
Py_RETURN_UOBJECT(u_object);
}
Py_RETURN_NONE;
}
#endif
PyObject *py_ue_get_owner(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
UActorComponent *component = ue_py_check_type<UActorComponent>(self);
if (!component)
return PyErr_Format(PyExc_Exception, "uobject is not a component");
Py_RETURN_UOBJECT(component->GetOwner());
}
PyObject *py_ue_register_component(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
if (!self->ue_object->IsA<UActorComponent>())
{
return PyErr_Format(PyExc_Exception, "uobject is not a component");
}
UActorComponent *component = (UActorComponent *)self->ue_object;
Py_BEGIN_ALLOW_THREADS;
if (!component->IsRegistered())
component->RegisterComponent();
Py_END_ALLOW_THREADS;
Py_RETURN_NONE;
}
PyObject *py_ue_component_is_registered(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
UActorComponent *component = ue_py_check_type<UActorComponent>(self);
if (!component)
return PyErr_Format(PyExc_Exception, "uobject is not a component");
if (component->IsRegistered())
{
Py_RETURN_TRUE;
}
Py_RETURN_FALSE;
}
PyObject *py_ue_setup_attachment(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
PyObject *py_component;
char *socket_name = nullptr;
if (!PyArg_ParseTuple(args, "O|s:setup_attachment", &py_component))
return nullptr;
USceneComponent *child = ue_py_check_type<USceneComponent>(self);
if (!child)
return PyErr_Format(PyExc_Exception, "uobject is not a USceneComponent");
USceneComponent *parent = ue_py_check_type<USceneComponent>(py_component);
if (!parent)
return PyErr_Format(PyExc_Exception, "argument is not a USceneComponent");
FName SocketName = NAME_None;
if (socket_name)
SocketName = FName(UTF8_TO_TCHAR(socket_name));
Py_BEGIN_ALLOW_THREADS;
child->SetupAttachment(parent, SocketName);
Py_END_ALLOW_THREADS;
Py_RETURN_NONE;
}
PyObject *py_ue_unregister_component(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
UActorComponent *component = ue_py_check_type<UActorComponent>(self);
if (!component)
return PyErr_Format(PyExc_Exception, "uobject is not an UActorComponent");
Py_BEGIN_ALLOW_THREADS;
if (component->IsRegistered())
component->UnregisterComponent();
Py_END_ALLOW_THREADS;
Py_RETURN_NONE;
}
PyObject *py_ue_destroy_component(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
UActorComponent *component = ue_py_check_type<UActorComponent>(self);
if (!component)
return PyErr_Format(PyExc_Exception, "uobject is not an UActorComponent");
Py_BEGIN_ALLOW_THREADS;
component->DestroyComponent();
Py_END_ALLOW_THREADS;
Py_RETURN_NONE;
}
PyObject *py_ue_add_instance_component(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
PyObject *py_component;
if (!PyArg_ParseTuple(args, "O:add_instance_component", &py_component))
{
return nullptr;
}
AActor *actor = ue_py_check_type<AActor>(self);
if (!actor)
{
return PyErr_Format(PyExc_Exception, "uobject is not an AActor");
}
UActorComponent *component = ue_py_check_type<UActorComponent>(py_component);
if (!component)
{
return PyErr_Format(PyExc_Exception, "argument is not a UActorComponent");
}
Py_BEGIN_ALLOW_THREADS;
actor->AddInstanceComponent(component);
Py_END_ALLOW_THREADS;
Py_RETURN_NONE;
}
PyObject *py_ue_add_actor_component(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
PyObject *obj;
char *name;
PyObject *py_parent = nullptr;
if (!PyArg_ParseTuple(args, "Os|O:add_actor_component", &obj, &name, &py_parent))
{
return nullptr;
}
AActor *actor = ue_py_check_type<AActor>(self);
if (!actor)
return PyErr_Format(PyExc_Exception, "uobject is not an AActor");
UClass *u_class = ue_py_check_type<UClass>(obj);
if (!u_class)
return PyErr_Format(PyExc_Exception, "argument is not a UClass");
if (!u_class->IsChildOf<UActorComponent>())
{
return PyErr_Format(PyExc_Exception, "argument is not a UClass derived from UActorComponent");
}
USceneComponent *parent_component = nullptr;
if (py_parent)
{
parent_component = ue_py_check_type<USceneComponent>(py_parent);
if (!parent_component)
{
return PyErr_Format(PyExc_Exception, "argument is not a USceneComponent");
}
}
UActorComponent *component = nullptr;
Py_BEGIN_ALLOW_THREADS;
component = NewObject<UActorComponent>(actor, u_class, FName(UTF8_TO_TCHAR(name)), RF_Public);
if (component)
{
if (py_parent && component->IsA<USceneComponent>())
{
USceneComponent *scene_component = (USceneComponent *)component;
scene_component->SetupAttachment(parent_component);
}
if (actor->GetWorld() && !component->IsRegistered())
{
component->RegisterComponent();
}
if (component->bWantsInitializeComponent && !component->HasBeenInitialized() && component->IsRegistered())
component->InitializeComponent();
}
Py_END_ALLOW_THREADS;
if (!component)
return PyErr_Format(PyExc_Exception, "unable to create component");
Py_RETURN_UOBJECT(component);
}
PyObject *py_ue_add_python_component(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
char *name;
char *module_name;
char *class_name;
if (!PyArg_ParseTuple(args, "sss:add_python_component", &name, &module_name, &class_name))
{
return nullptr;
}
AActor *actor = ue_py_check_type<AActor >(self);
if (!actor)
{
return PyErr_Format(PyExc_Exception, "uobject is not an AActor");
}
UPythonComponent *component = nullptr;
Py_BEGIN_ALLOW_THREADS;
component = NewObject<UPythonComponent>(actor, FName(UTF8_TO_TCHAR(name)), RF_Public);
if (component)
{
component->PythonModule = FString(UTF8_TO_TCHAR(module_name));
component->PythonClass = FString(UTF8_TO_TCHAR(class_name));
if (actor->GetWorld() && !component->IsRegistered())
{
component->RegisterComponent();
}
if (component->bWantsInitializeComponent && !component->HasBeenInitialized() && component->IsRegistered())
component->InitializeComponent();
}
Py_END_ALLOW_THREADS;
if (!component)
return PyErr_Format(PyExc_Exception, "unable to create component");
Py_RETURN_UOBJECT(component);
}
PyObject *py_ue_actor_create_default_subobject(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
PyObject *obj;
char *name;
if (!PyArg_ParseTuple(args, "Os:actor_create_default_subobject", &obj, &name))
{
return nullptr;
}
AActor *actor = ue_py_check_type<AActor>(self);
if (!actor)
return PyErr_Format(PyExc_Exception, "uobject is not an AActor");
UClass *u_class = ue_py_check_type<UClass>(obj);
if (!u_class)
return PyErr_Format(PyExc_Exception, "argument is not a UClass");
if (!FUObjectThreadContext::Get().TopInitializer())
return PyErr_Format(PyExc_Exception, "CreateDefaultSubobject() can be called only in a constructor");
UObject *ret_obj = nullptr;
Py_BEGIN_ALLOW_THREADS;
ret_obj = actor->CreateDefaultSubobject(FName(UTF8_TO_TCHAR(name)), UObject::StaticClass(), u_class, false, false, true);
Py_END_ALLOW_THREADS;
if (!ret_obj)
return PyErr_Format(PyExc_Exception, "unable to create component");
Py_RETURN_UOBJECT(ret_obj);
}
PyObject *py_ue_get_actor_root_component(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
AActor *actor = ue_get_actor(self);
if (!actor)
return PyErr_Format(PyExc_Exception, "cannot retrieve Actor from uobject");
UActorComponent *component = actor->GetRootComponent();
if (component)
{
Py_RETURN_UOBJECT(component);
}
Py_RETURN_NONE;
}
PyObject *py_ue_add_actor_root_component(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
PyObject *obj;
char *name;
if (!PyArg_ParseTuple(args, "Os:add_actor_root_component", &obj, &name))
{
return nullptr;
}
AActor *actor = ue_py_check_type<AActor>(self);
if (!actor)
return PyErr_Format(PyExc_Exception, "uobject is not an AActor");
UClass *u_class = ue_py_check_type<UClass>(obj);
if (!u_class)
return PyErr_Format(PyExc_Exception, "argument is not a UClass");
USceneComponent *component = NewObject<USceneComponent>(actor, u_class, FName(UTF8_TO_TCHAR(name)), RF_Public);
if (!component)
return PyErr_Format(PyExc_Exception, "unable to create component");
Py_BEGIN_ALLOW_THREADS;
actor->SetRootComponent(component);
if (actor->GetWorld() && !component->IsRegistered())
{
component->RegisterComponent();
}
if (component->bWantsInitializeComponent && !component->HasBeenInitialized() && component->IsRegistered())
component->InitializeComponent();
Py_END_ALLOW_THREADS;
Py_RETURN_UOBJECT(component);
}
PyObject *py_ue_actor_has_component_of_type(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
PyObject *obj;
if (!PyArg_ParseTuple(args, "O:actor_has_component_of_type", &obj))
{
return NULL;
}
AActor *actor = ue_get_actor(self);
if (!actor)
return PyErr_Format(PyExc_Exception, "uobject is not an AActor");
UClass *u_class = ue_py_check_type<UClass>(obj);
if (!u_class)
return PyErr_Format(PyExc_Exception, "argument is not a UClass");
if (actor->GetComponentByClass(u_class))
{
Py_RETURN_TRUE;
}
Py_RETURN_TRUE;
}
PyObject *py_ue_get_actor_component_by_type(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
PyObject *obj;
if (!PyArg_ParseTuple(args, "O:get_actor_component_by_type", &obj))
{
return nullptr;
}
AActor *actor = ue_get_actor(self);
if (!actor)
return PyErr_Format(PyExc_Exception, "uobject is not an AActor");
UClass *u_class = ue_py_check_type<UClass>(obj);
if (!u_class)
return PyErr_Format(PyExc_Exception, "argument is not a UClass");
UActorComponent *component = actor->GetComponentByClass(u_class);
if (component)
{
Py_RETURN_UOBJECT(component);
}
Py_RETURN_NONE;
}
PyObject *py_ue_get_actor_components_by_type(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
PyObject *obj;
if (!PyArg_ParseTuple(args, "O:get_actor_components_by_type", &obj))
{
return nullptr;
}
AActor *actor = ue_get_actor(self);
if (!actor)
return PyErr_Format(PyExc_Exception, "uobject is not an AActor");
UClass *u_class = ue_py_check_type<UClass>(obj);
if (!u_class)
return PyErr_Format(PyExc_Exception, "argument is not a UClass");
PyObject *components = PyList_New(0);
for (UActorComponent *component : actor->GetComponentsByClass(u_class))
{
ue_PyUObject *item = ue_get_python_uobject(component);
if (item)
PyList_Append(components, (PyObject *)item);
}
return components;
}
PyObject *py_ue_get_actor_components_by_tag(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
char *tag;
PyObject *py_uclass = nullptr;
if (!PyArg_ParseTuple(args, "s|O:get_actor_components_by_tag", &tag, &py_uclass))
{
return nullptr;
}
AActor *actor = ue_get_actor(self);
if (!actor)
return PyErr_Format(PyExc_Exception, "uobject is not an AActor");
PyObject *components = PyList_New(0);
UClass *u_class = UActorComponent::StaticClass();
if (py_uclass)
{
u_class = ue_py_check_type<UClass>(py_uclass);
if (!u_class)
{
return PyErr_Format(PyExc_Exception, "argument is not a UClass");
}
if (!u_class->IsChildOf<UActorComponent>())
{
return PyErr_Format(PyExc_Exception, "argument is not a UClass inheriting from UActorComponent");
}
}
for (UActorComponent *component : actor->GetComponentsByTag(u_class, FName(UTF8_TO_TCHAR(tag))))
{
ue_PyUObject *item = ue_get_python_uobject(component);
if (item)
PyList_Append(components, (PyObject *)item);
}
return components;
}
PyObject *py_ue_actor_spawn(ue_PyUObject * self, PyObject * args, PyObject *kwargs)
{
ue_py_check(self);
PyObject *py_class;
PyObject *py_obj_location = nullptr;
PyObject *py_obj_rotation = nullptr;
if (!PyArg_ParseTuple(args, "O|OO:actor_spawn", &py_class, &py_obj_location, &py_obj_rotation))
{
return nullptr;
}
UWorld *world = ue_get_uworld(self);
if (!world)
return PyErr_Format(PyExc_Exception, "unable to retrieve UWorld from uobject");
UClass *u_class = ue_py_check_type<UClass>(py_class);
if (!u_class)
return PyErr_Format(PyExc_Exception, "argument is not a UClass");
if (!u_class->IsChildOf<AActor>())
{
return PyErr_Format(PyExc_Exception, "argument is not a UClass derived from AActor");
}
FVector location = FVector(0, 0, 0);
FRotator rotation = FRotator(0, 0, 0);
if (py_obj_location)
{
ue_PyFVector *py_location = py_ue_is_fvector(py_obj_location);
if (!py_location)
return PyErr_Format(PyExc_Exception, "location must be an FVector");
location = py_location->vec;
}
if (py_obj_rotation)
{
ue_PyFRotator *py_rotation = py_ue_is_frotator(py_obj_rotation);
if (!py_rotation)
return PyErr_Format(PyExc_Exception, "location must be an FRotator");
rotation = py_rotation->rot;
}
AActor *actor = nullptr;
if (kwargs && PyDict_Size(kwargs) > 0)
{
FTransform transform;
transform.SetTranslation(location);
transform.SetRotation(rotation.Quaternion());
Py_BEGIN_ALLOW_THREADS;
actor = world->SpawnActorDeferred<AActor>(u_class, transform);
Py_END_ALLOW_THREADS;
if (!actor)
return PyErr_Format(PyExc_Exception, "unable to spawn a new Actor");
ue_PyUObject *py_actor = ue_get_python_uobject_inc(actor);
if (!py_actor)
return PyErr_Format(PyExc_Exception, "uobject is in invalid state");
PyObject *py_iter = PyObject_GetIter(kwargs);
while (PyObject *py_key = PyIter_Next(py_iter))
{
PyObject *void_ret = py_ue_set_property(py_actor, Py_BuildValue("OO", py_key, PyDict_GetItem(kwargs, py_key)));
if (!void_ret)
{
Py_DECREF(py_iter);
return PyErr_Format(PyExc_Exception, "unable to set property for new Actor");
}
}
Py_DECREF(py_iter);
Py_BEGIN_ALLOW_THREADS;
UGameplayStatics::FinishSpawningActor(actor, transform);
Py_END_ALLOW_THREADS;
return (PyObject *)py_actor;
}
Py_BEGIN_ALLOW_THREADS;
actor = world->SpawnActor(u_class, &location, &rotation);
Py_END_ALLOW_THREADS;
if (!actor)
return PyErr_Format(PyExc_Exception, "unable to spawn a new Actor");
Py_RETURN_UOBJECT(actor);
}
PyObject *py_ue_get_overlapping_actors(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
PyObject *class_filter = nullptr;
if (!PyArg_ParseTuple(args, "|O:get_overlapping_actors", &class_filter))
{
return nullptr;
}
AActor *actor = ue_get_actor(self);
if (!actor)
return PyErr_Format(PyExc_Exception, "cannot retrieve actor from UObject");
UClass *filtering = AActor::StaticClass();
if (class_filter)
{
if (!ue_is_pyuobject(class_filter))
return PyErr_Format(PyExc_Exception, "argument is not a UObject");
ue_PyUObject *py_obj = (ue_PyUObject *)class_filter;
if (!py_obj->ue_object->IsA((UClass *)py_obj->ue_object))
return PyErr_Format(PyExc_Exception, "argument is not a UClass");
filtering = (UClass *)py_obj->ue_object;
}
PyObject *py_overlapping_actors = PyList_New(0);
TArray<AActor *> overalpping_actors;
actor->GetOverlappingActors(overalpping_actors, filtering);
for (AActor *overlapping_actor : overalpping_actors)
{
ue_PyUObject *item = ue_get_python_uobject(overlapping_actor);
if (item)
{
PyList_Append(py_overlapping_actors, (PyObject *)item);
}
}
return py_overlapping_actors;
}
PyObject *py_ue_actor_set_level_sequence(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
PyObject *py_sequence;
if (!PyArg_ParseTuple(args, "O:actor_set_level_sequence", &py_sequence))
{
return NULL;
}
ALevelSequenceActor *actor = ue_py_check_type<ALevelSequenceActor>(self);
if (!actor)
{
return PyErr_Format(PyExc_Exception, "uobject is not a LevelSequenceActor");
}
ULevelSequence *sequence = ue_py_check_type<ULevelSequence>(py_sequence);
if (!sequence)
{
return PyErr_Format(PyExc_Exception, "argument is not a LevelSequence");
}
Py_BEGIN_ALLOW_THREADS;
actor->SetSequence(sequence);
Py_END_ALLOW_THREADS;
Py_RETURN_NONE;
}
#if WITH_EDITOR
PyObject *py_ue_get_editor_world_counterpart_actor(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
AActor *actor = ue_get_actor(self);
if (!actor)
return PyErr_Format(PyExc_Exception, "cannot retrieve actor from UObject");
AActor *editor_actor = EditorUtilities::GetEditorWorldCounterpartActor(actor);
if (!editor_actor)
return PyErr_Format(PyExc_Exception, "unable to retrieve editor counterpart actor");
Py_RETURN_UOBJECT(editor_actor);
}
#endif
```
|
/content/code_sandbox/Source/UnrealEnginePython/Private/UObject/UEPyActor.cpp
|
c++
| 2016-08-07T05:00:51
| 2024-08-14T06:32:20
|
UnrealEnginePython
|
20tab/UnrealEnginePython
| 2,715
| 6,216
|
```c++
#include "UEPyHUD.h"
#include "GameFramework/HUD.h"
#include "Engine/Texture.h"
PyObject *py_ue_hud_draw_2d_line(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
int x1, y1, x2, y2;
PyObject *py_fcolor;
if (!PyArg_ParseTuple(args, "iiiiO:hud_draw_2d_line", &x1, &y1, &x2, &y2, &py_fcolor))
{
return nullptr;
}
AHUD *hud = ue_py_check_type<AHUD>(self);
if (!hud)
return PyErr_Format(PyExc_Exception, "UObject is not a AHUD.");
FColor color;
if (!py_ue_get_fcolor(py_fcolor, color))
{
return PyErr_Format(PyExc_Exception, "argument is not a FColor or FLinearColor.");
}
hud->Draw2DLine(x1, y1, x2, y2, color);
Py_RETURN_NONE;
}
PyObject *py_ue_hud_draw_line(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
float x1, y1, x2, y2;
PyObject *py_fcolor;
float thickness;
if (!PyArg_ParseTuple(args, "ffffOf:hud_draw_line", &x1, &y1, &x2, &y2, &py_fcolor, &thickness))
{
return nullptr;
}
AHUD *hud = ue_py_check_type<AHUD>(self);
if (!hud)
return PyErr_Format(PyExc_Exception, "UObject is not a AHUD.");
FLinearColor color;
if (!py_ue_get_flinearcolor(py_fcolor, color))
{
return PyErr_Format(PyExc_Exception, "argument is not a FLinearColor or FColor.");
}
hud->DrawLine(x1, y1, x2, y2, color, thickness);
Py_RETURN_NONE;
}
PyObject *py_ue_hud_draw_rect(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
float x, y, w, h;
PyObject *py_fcolor;
if (!PyArg_ParseTuple(args, "ffffO:hud_draw_line", &x, &y, &w, &h, &py_fcolor))
{
return nullptr;
}
AHUD *hud = ue_py_check_type<AHUD>(self);
if (!hud)
return PyErr_Format(PyExc_Exception, "UObject is not a AHUD.");
FLinearColor color;
if (!py_ue_get_flinearcolor(py_fcolor, color))
{
return PyErr_Format(PyExc_Exception, "argument is not a FLinearColor or FColor.");
}
hud->DrawRect(color, x, y, w, h);
Py_RETURN_NONE;
}
PyObject *py_ue_hud_draw_text(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
char *text;
float x, y;
PyObject *py_fcolor;
float scale = 1;
if (!PyArg_ParseTuple(args, "sffO|f:hud_draw_text", &text, &x, &y, &py_fcolor, &scale))
{
return nullptr;
}
AHUD *hud = ue_py_check_type<AHUD>(self);
if (!hud)
return PyErr_Format(PyExc_Exception, "UObject is not a AHUD.");
FLinearColor color;
if (!py_ue_get_flinearcolor(py_fcolor, color))
{
return PyErr_Format(PyExc_Exception, "argument is not a FLinearColor or FColor.");
}
hud->DrawText(FString(UTF8_TO_TCHAR(text)), color, x, y, nullptr, scale);
Py_RETURN_NONE;
}
PyObject *py_ue_hud_draw_texture(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
PyObject *py_texture;
float x, y, w, h;
float u = 0, v = 0, uw = 1, vh = 1;
PyObject *py_flinear_color = nullptr;
int blend_mode = EBlendMode::BLEND_Translucent;
float scale = 1;
PyObject *py_scale_position = nullptr;
float rotation = 0;
float pivot_rot_x = 0, pivot_rot_y = 0;
if (!PyArg_ParseTuple(args, "Offff|ffffOifOf(ff):hud_draw_texture", &py_texture, &x, &y, &w, &h, &u, &v, &uw, &vh, &py_flinear_color, &blend_mode, &scale, &py_scale_position, &rotation, &pivot_rot_x, &pivot_rot_y))
{
return nullptr;
}
AHUD *hud = ue_py_check_type<AHUD>(self);
if (!hud)
return PyErr_Format(PyExc_Exception, "UObject is not a AHUD.");
UTexture *texture = ue_py_check_type<UTexture>(py_texture);
if (!texture)
return PyErr_Format(PyExc_Exception, "argument is not a UTexture.");
FLinearColor tint = FLinearColor::White;
if (py_flinear_color)
{
if (!py_ue_get_flinearcolor(py_flinear_color, tint))
{
return PyErr_Format(PyExc_Exception, "argument is not a FLinearColor or FColor.");
}
}
bool scale_position = false;
if (py_scale_position && PyObject_IsTrue(py_scale_position))
scale_position = true;
hud->DrawTexture(texture, x, y, w, h, u, v, uw, vh, tint, (EBlendMode)blend_mode, scale, scale_position, rotation, FVector2D(pivot_rot_x, pivot_rot_y));
Py_RETURN_NONE;
}
```
|
/content/code_sandbox/Source/UnrealEnginePython/Private/UObject/UEPyHUD.cpp
|
c++
| 2016-08-07T05:00:51
| 2024-08-14T06:32:20
|
UnrealEnginePython
|
20tab/UnrealEnginePython
| 2,715
| 1,245
|
```c++
#include "UEPyExporter.h"
#include "Exporters/Exporter.h"
PyObject *py_ue_export_to_file(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
PyObject *py_object;
char *filename;
if (!PyArg_ParseTuple(args, "Os:export_to_file", &py_object, &filename))
{
return nullptr;
}
UExporter *Exporter = ue_py_check_type<UExporter>(self);
if (!Exporter)
{
return PyErr_Format(PyExc_Exception, "uobject is not a UExporter");
}
UObject *Object = ue_py_check_type<UObject>(py_object);
if (!Object)
{
return PyErr_Format(PyExc_Exception, "argument is not a UObject");
}
if (UExporter::ExportToFile(Object, Exporter, UTF8_TO_TCHAR(filename), false, false, false) > 0)
{
Py_RETURN_TRUE;
}
Py_RETURN_FALSE;
}
```
|
/content/code_sandbox/Source/UnrealEnginePython/Private/UObject/UEPyExporter.cpp
|
c++
| 2016-08-07T05:00:51
| 2024-08-14T06:32:20
|
UnrealEnginePython
|
20tab/UnrealEnginePython
| 2,715
| 202
|
```c++
#include "UEPyPackage.h"
PyObject *py_ue_package_is_dirty(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
UPackage *package = ue_py_check_type<UPackage>(self);
if (!package)
return PyErr_Format(PyExc_Exception, "uobject is not an UPackage");
if (package->IsDirty())
Py_RETURN_TRUE;
Py_RETURN_FALSE;
}
PyObject *py_ue_package_get_filename(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
UPackage *package = ue_py_check_type<UPackage>(self);
if (!package)
return PyErr_Format(PyExc_Exception, "uobject is not an UPackage");
FString Filename;
if (!FPackageName::DoesPackageExist(package->GetPathName(), nullptr, &Filename))
return PyErr_Format(PyExc_Exception, "package does not exist");
return PyUnicode_FromString(TCHAR_TO_UTF8(*Filename));
}
PyObject *py_ue_package_make_unique_object_name(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
PyObject *py_class;
char *prefix = nullptr;
if (!PyArg_ParseTuple(args, "Os:make_unique_object_name", &py_class, &prefix))
return nullptr;
UPackage *package = ue_py_check_type<UPackage>(self);
if (!package)
return PyErr_Format(PyExc_Exception, "uobject is not an UPackage");
UClass *u_class = ue_py_check_type<UClass>(py_class);
if (!u_class)
return PyErr_Format(PyExc_Exception, "argument is not a UClass");
FName name = NAME_None;
if (prefix)
name = FName(UTF8_TO_TCHAR(prefix));
FName new_name = MakeUniqueObjectName(package, u_class, name);
return PyUnicode_FromString(TCHAR_TO_UTF8(*new_name.ToString()));
}
```
|
/content/code_sandbox/Source/UnrealEnginePython/Private/UObject/UEPyPackage.cpp
|
c++
| 2016-08-07T05:00:51
| 2024-08-14T06:32:20
|
UnrealEnginePython
|
20tab/UnrealEnginePython
| 2,715
| 397
|
```c++
#include "UEPyInput.h"
#include "Kismet/GameplayStatics.h"
#include "Engine/World.h"
#include "GameFramework/PlayerInput.h"
PyObject *py_ue_is_input_key_down(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
char *key;
int controller_id = 0;
if (!PyArg_ParseTuple(args, "s|i:is_input_key_down", &key, &controller_id))
{
return NULL;
}
UWorld *world = ue_get_uworld(self);
if (!world)
return PyErr_Format(PyExc_Exception, "unable to retrieve UWorld from uobject");
APlayerController *controller = UGameplayStatics::GetPlayerController(world, controller_id);
if (!controller)
return PyErr_Format(PyExc_Exception, "unable to retrieve controller %d", controller_id);
if (controller->IsInputKeyDown(key))
{
Py_INCREF(Py_True);
return Py_True;
}
Py_INCREF(Py_False);
return Py_False;
}
PyObject *py_ue_was_input_key_just_pressed(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
char *key;
int controller_id = 0;
if (!PyArg_ParseTuple(args, "s|i:was_input_key_just_pressed", &key, &controller_id))
{
return NULL;
}
UWorld *world = ue_get_uworld(self);
if (!world)
return PyErr_Format(PyExc_Exception, "unable to retrieve UWorld from uobject");
APlayerController *controller = UGameplayStatics::GetPlayerController(world, controller_id);
if (!controller)
return PyErr_Format(PyExc_Exception, "unable to retrieve controller %d", controller_id);
if (controller->WasInputKeyJustPressed(key))
{
Py_INCREF(Py_True);
return Py_True;
}
Py_INCREF(Py_False);
return Py_False;
}
PyObject *py_ue_is_action_pressed(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
char *key;
int controller_id = 0;
if (!PyArg_ParseTuple(args, "s|i:is_action_pressed", &key, &controller_id))
{
return NULL;
}
UWorld *world = ue_get_uworld(self);
if (!world)
return PyErr_Format(PyExc_Exception, "unable to retrieve UWorld from uobject");
APlayerController *controller = UGameplayStatics::GetPlayerController(world, controller_id);
if (!controller)
return PyErr_Format(PyExc_Exception, "unable to retrieve controller %d", controller_id);
UPlayerInput *input = controller->PlayerInput;
if (!input)
goto end;
for (FInputActionKeyMapping mapping : input->GetKeysForAction(key))
{
if (controller->WasInputKeyJustPressed(mapping.Key))
{
Py_INCREF(Py_True);
return Py_True;
}
}
end:
Py_INCREF(Py_False);
return Py_False;
}
PyObject *py_ue_was_input_key_just_released(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
char *key;
int controller_id = 0;
if (!PyArg_ParseTuple(args, "s|i:was_input_key_just_released", &key, &controller_id))
{
return NULL;
}
UWorld *world = ue_get_uworld(self);
if (!world)
return PyErr_Format(PyExc_Exception, "unable to retrieve UWorld from uobject");
APlayerController *controller = UGameplayStatics::GetPlayerController(world, controller_id);
if (!controller)
return PyErr_Format(PyExc_Exception, "unable to retrieve controller %d", controller_id);
if (controller->WasInputKeyJustReleased(key))
{
Py_INCREF(Py_True);
return Py_True;
}
Py_INCREF(Py_False);
return Py_False;
}
PyObject *py_ue_is_action_released(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
char *key;
int controller_id = 0;
if (!PyArg_ParseTuple(args, "s|i:is_action_released", &key, &controller_id))
{
return NULL;
}
UWorld *world = ue_get_uworld(self);
if (!world)
return PyErr_Format(PyExc_Exception, "unable to retrieve UWorld from uobject");
APlayerController *controller = UGameplayStatics::GetPlayerController(world, controller_id);
if (!controller)
return PyErr_Format(PyExc_Exception, "unable to retrieve controller %d", controller_id);
UPlayerInput *input = controller->PlayerInput;
if (!input)
goto end;
for (FInputActionKeyMapping mapping : input->GetKeysForAction(key))
{
if (controller->WasInputKeyJustReleased(mapping.Key))
{
Py_INCREF(Py_True);
return Py_True;
}
}
end:
Py_INCREF(Py_False);
return Py_False;
}
PyObject *py_ue_enable_input(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
int controller_id = 0;
if (!PyArg_ParseTuple(args, "|i:enable_input", &controller_id))
{
return NULL;
}
UWorld *world = ue_get_uworld(self);
if (!world)
return PyErr_Format(PyExc_Exception, "unable to retrieve UWorld from uobject");
APlayerController *controller = UGameplayStatics::GetPlayerController(world, controller_id);
if (!controller)
return PyErr_Format(PyExc_Exception, "unable to retrieve controller %d", controller_id);
if (self->ue_object->IsA<AActor>())
{
((AActor *)self->ue_object)->EnableInput(controller);
}
else if (self->ue_object->IsA<UActorComponent>())
{
((UActorComponent *)self->ue_object)->GetOwner()->EnableInput(controller);
}
else
{
return PyErr_Format(PyExc_Exception, "uobject is not an actor or a component");
}
Py_INCREF(Py_None);
return Py_None;
}
PyObject *py_ue_get_input_axis(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
char *axis_name;
if (!PyArg_ParseTuple(args, "s:get_input_axis", &axis_name))
{
return NULL;
}
UInputComponent *input = nullptr;
if (self->ue_object->IsA<AActor>())
{
input = ((AActor *)self->ue_object)->InputComponent;
}
else if (self->ue_object->IsA<UActorComponent>())
{
input = ((UActorComponent *)self->ue_object)->GetOwner()->InputComponent;
}
else
{
return PyErr_Format(PyExc_Exception, "uobject is not an actor or a component");
}
if (!input)
{
return PyErr_Format(PyExc_Exception, "no input manager for this uobject");
}
return Py_BuildValue("f", input->GetAxisValue(FName(UTF8_TO_TCHAR(axis_name))));
}
PyObject *py_ue_bind_input_axis(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
char *axis_name;
if (!PyArg_ParseTuple(args, "s:bind_input_axis", &axis_name))
{
return NULL;
}
UInputComponent *input = nullptr;
if (self->ue_object->IsA<AActor>())
{
input = ((AActor *)self->ue_object)->InputComponent;
}
else if (self->ue_object->IsA<UActorComponent>())
{
input = ((UActorComponent *)self->ue_object)->GetOwner()->InputComponent;
}
else
{
return PyErr_Format(PyExc_Exception, "uobject is not an actor or a component");
}
if (!input)
{
return PyErr_Format(PyExc_Exception, "no input manager for this uobject");
}
input->BindAxis(FName(UTF8_TO_TCHAR(axis_name)));
Py_INCREF(Py_None);
return Py_None;
}
PyObject *py_ue_show_mouse_cursor(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
bool enabled = true;
PyObject *is_true = NULL;
int controller_id = 0;
if (!PyArg_ParseTuple(args, "|Oi:show_mouse_cursor", &is_true, &controller_id))
{
return NULL;
}
if (is_true && !PyObject_IsTrue(is_true))
enabled = false;
UWorld *world = ue_get_uworld(self);
if (!world)
return PyErr_Format(PyExc_Exception, "unable to retrieve UWorld from uobject");
APlayerController *controller = UGameplayStatics::GetPlayerController(world, controller_id);
if (!controller)
return PyErr_Format(PyExc_Exception, "unable to retrieve controller %d", controller_id);
controller->bShowMouseCursor = enabled;
Py_INCREF(Py_None);
return Py_None;
}
PyObject *py_ue_enable_click_events(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
bool enabled = true;
PyObject *is_true = NULL;
int controller_id = 0;
if (!PyArg_ParseTuple(args, "|Oi:enable_click_events", &is_true, &controller_id))
{
return NULL;
}
if (is_true && !PyObject_IsTrue(is_true))
enabled = false;
UWorld *world = ue_get_uworld(self);
if (!world)
return PyErr_Format(PyExc_Exception, "unable to retrieve UWorld from uobject");
APlayerController *controller = UGameplayStatics::GetPlayerController(world, controller_id);
if (!controller)
return PyErr_Format(PyExc_Exception, "unable to retrieve controller %d", controller_id);
controller->bEnableClickEvents = enabled;
Py_INCREF(Py_None);
return Py_None;
}
PyObject *py_ue_enable_mouse_over_events(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
bool enabled = true;
PyObject *is_true = NULL;
int controller_id = 0;
if (!PyArg_ParseTuple(args, "|Oi:enable_mouse_over_events", &is_true, &controller_id))
{
return NULL;
}
if (is_true && !PyObject_IsTrue(is_true))
enabled = false;
UWorld *world = ue_get_uworld(self);
if (!world)
return PyErr_Format(PyExc_Exception, "unable to retrieve UWorld from uobject");
APlayerController *controller = UGameplayStatics::GetPlayerController(world, controller_id);
if (controller)
controller->bEnableMouseOverEvents = enabled;
Py_INCREF(Py_None);
return Py_None;
}
PyObject *py_ue_bind_action(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
char *action_name;
int key;
PyObject *py_callable;
if (!PyArg_ParseTuple(args, "siO:bind_action", &action_name, &key, &py_callable))
{
return NULL;
}
if (!PyCallable_Check(py_callable))
{
return PyErr_Format(PyExc_Exception, "object is not a callable");
}
UInputComponent *input = nullptr;
if (self->ue_object->IsA<AActor>())
{
input = ((AActor *)self->ue_object)->InputComponent;
}
else if (self->ue_object->IsA<UActorComponent>())
{
input = ((UActorComponent *)self->ue_object)->GetOwner()->InputComponent;
}
else
{
return PyErr_Format(PyExc_Exception, "uobject is not an actor or a component");
}
if (!input)
{
return PyErr_Format(PyExc_Exception, "no input manager for this uobject");
}
UPythonDelegate *py_delegate = FUnrealEnginePythonHouseKeeper::Get()->NewDelegate(input, py_callable, nullptr);
FInputActionBinding input_action_binding(FName(UTF8_TO_TCHAR(action_name)), (const EInputEvent)key);
input_action_binding.ActionDelegate.BindDelegate(py_delegate, &UPythonDelegate::PyInputHandler);
input->AddActionBinding(input_action_binding);
Py_RETURN_NONE;
}
PyObject *py_ue_bind_axis(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
char *axis_name;
PyObject *py_callable;
if (!PyArg_ParseTuple(args, "sO:bind_axis", &axis_name, &py_callable))
{
return NULL;
}
if (!PyCallable_Check(py_callable))
{
return PyErr_Format(PyExc_Exception, "object is not a callable");
}
UInputComponent *input = nullptr;
if (self->ue_object->IsA<AActor>())
{
input = ((AActor *)self->ue_object)->InputComponent;
}
else if (self->ue_object->IsA<UActorComponent>())
{
input = ((UActorComponent *)self->ue_object)->GetOwner()->InputComponent;
}
else
{
return PyErr_Format(PyExc_Exception, "uobject is not an actor or a component");
}
if (!input)
{
return PyErr_Format(PyExc_Exception, "no input manager for this uobject");
}
UPythonDelegate *py_delegate = FUnrealEnginePythonHouseKeeper::Get()->NewDelegate(input, py_callable, nullptr);
FInputAxisBinding input_axis_binding(FName(UTF8_TO_TCHAR(axis_name)));
input_axis_binding.AxisDelegate.BindDelegate(py_delegate, &UPythonDelegate::PyInputAxisHandler);
input->AxisBindings.Add(input_axis_binding);
Py_RETURN_NONE;
}
PyObject *py_ue_bind_key(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
char *key_name;
int key;
PyObject *py_callable;
if (!PyArg_ParseTuple(args, "siO:bind_key", &key_name, &key, &py_callable))
{
return NULL;
}
if (!PyCallable_Check(py_callable))
{
return PyErr_Format(PyExc_Exception, "object is not a callable");
}
UInputComponent *input = nullptr;
if (self->ue_object->IsA<AActor>())
{
input = ((AActor *)self->ue_object)->InputComponent;
}
else if (self->ue_object->IsA<UActorComponent>())
{
UActorComponent *component = (UActorComponent *)self->ue_object;
if (!component->GetOwner())
return PyErr_Format(PyExc_Exception, "component is still not mapped to an Actor");
input = component->GetOwner()->InputComponent;
}
else
{
return PyErr_Format(PyExc_Exception, "uobject is not an actor or a component");
}
if (!input)
{
return PyErr_Format(PyExc_Exception, "no input manager for this uobject");
}
UPythonDelegate *py_delegate = FUnrealEnginePythonHouseKeeper::Get()->NewDelegate(input, py_callable, nullptr);
FInputKeyBinding input_key_binding(FKey(UTF8_TO_TCHAR(key_name)), (const EInputEvent)key);
input_key_binding.KeyDelegate.BindDelegate(py_delegate, &UPythonDelegate::PyInputHandler);
input->KeyBindings.Add(input_key_binding);
Py_RETURN_NONE;
}
PyObject *py_ue_bind_pressed_key(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
char *key_name;
PyObject *py_callable;
if (!PyArg_ParseTuple(args, "sO:bind_pressed_key", &key_name, &py_callable))
{
return NULL;
}
return py_ue_bind_key(self, Py_BuildValue("siO", key_name, EInputEvent::IE_Pressed, py_callable));
}
PyObject *py_ue_bind_released_key(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
char *key_name;
PyObject *py_callable;
if (!PyArg_ParseTuple(args, "sO:bind_released_key", &key_name, &py_callable))
{
return NULL;
}
return py_ue_bind_key(self, Py_BuildValue("siO", key_name, EInputEvent::IE_Released, py_callable));
}
PyObject *py_unreal_engine_get_engine_defined_action_mappings(PyObject * self, PyObject * args)
{
PyObject *py_list = PyList_New(0);
TArray<FInputActionKeyMapping> mappings = UPlayerInput::GetEngineDefinedActionMappings();
for (FInputActionKeyMapping mapping : mappings)
{
PyObject *py_mapping = PyDict_New();
PyDict_SetItemString(py_mapping, (char *)"action_name", PyUnicode_FromString(TCHAR_TO_UTF8(*mapping.ActionName.ToString())));
PyDict_SetItemString(py_mapping, (char *)"key", PyUnicode_FromString(TCHAR_TO_UTF8(*mapping.Key.ToString())));
PyDict_SetItemString(py_mapping, (char *)"alt", mapping.bAlt ? Py_True : Py_False);
PyDict_SetItemString(py_mapping, (char *)"cmd", mapping.bCmd ? Py_True : Py_False);
PyDict_SetItemString(py_mapping, (char *)"ctrl", mapping.bCtrl ? Py_True : Py_False);
PyDict_SetItemString(py_mapping, (char *)"shift", mapping.bShift ? Py_True : Py_False);
PyList_Append(py_list, py_mapping);
}
return py_list;
}
PyObject *py_ue_input_axis(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
PyObject *py_fkey;
float delta;
float delta_time;
int num_samples = 1;
PyObject *py_gamepad = nullptr;
int controller_id = 0;
if (!PyArg_ParseTuple(args, "Off|iO:input_axis", &py_fkey, &delta, &delta_time, &num_samples, &py_gamepad))
{
return nullptr;;
}
APlayerController *controller = ue_py_check_type<APlayerController>(self);
if (!controller)
return PyErr_Format(PyExc_Exception, "object is not a APlayerController");
FKey *key = ue_py_check_struct<FKey>(py_fkey);
if (!key)
return PyErr_Format(PyExc_Exception, "argument is not a FKey");
if (controller->InputAxis(*key, delta, delta_time, num_samples, py_gamepad && PyObject_IsTrue(py_gamepad)))
{
Py_RETURN_TRUE;
}
Py_RETURN_FALSE;
}
PyObject *py_ue_input_key(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
PyObject *py_fkey;
int event_type;
float amount = 0.0;
PyObject *py_gamepad = nullptr;
int controller_id = 0;
if (!PyArg_ParseTuple(args, "Oi|fO:input_key", &py_fkey, &event_type, &amount, &py_gamepad))
{
return nullptr;;
}
APlayerController *controller = ue_py_check_type<APlayerController>(self);
if (!controller)
return PyErr_Format(PyExc_Exception, "object is not a APlayerController");
FKey *key = ue_py_check_struct<FKey>(py_fkey);
if (!key)
return PyErr_Format(PyExc_Exception, "argument is not a FKey");
if (controller->InputKey(*key, (EInputEvent)event_type, amount, py_gamepad && PyObject_IsTrue(py_gamepad)))
{
Py_RETURN_TRUE;
}
Py_RETURN_FALSE;
}
```
|
/content/code_sandbox/Source/UnrealEnginePython/Private/UObject/UEPyInput.cpp
|
c++
| 2016-08-07T05:00:51
| 2024-08-14T06:32:20
|
UnrealEnginePython
|
20tab/UnrealEnginePython
| 2,715
| 4,114
|
```objective-c
#pragma once
#include "UEPyModule.h"
PyObject *py_ue_set_material_scalar_parameter(ue_PyUObject *, PyObject *);
PyObject *py_ue_set_material_static_switch_parameter(ue_PyUObject *, PyObject *);
PyObject *py_ue_set_material_vector_parameter(ue_PyUObject *, PyObject *);
PyObject *py_ue_set_material_texture_parameter(ue_PyUObject *, PyObject *);
PyObject *py_ue_get_material_scalar_parameter(ue_PyUObject *, PyObject *);
PyObject *py_ue_get_material_vector_parameter(ue_PyUObject *, PyObject *);
PyObject *py_ue_get_material_texture_parameter(ue_PyUObject *, PyObject *);
PyObject *py_ue_get_material_static_switch_parameter(ue_PyUObject *, PyObject *);
PyObject *py_ue_create_material_instance_dynamic(ue_PyUObject *, PyObject *);
PyObject *py_ue_set_material(ue_PyUObject *, PyObject *);
PyObject *py_ue_set_material_by_name(ue_PyUObject *, PyObject *);
#if WITH_EDITOR
PyObject *py_ue_set_material_parent(ue_PyUObject *, PyObject *);
PyObject *py_ue_static_mesh_set_collision_for_lod(ue_PyUObject *, PyObject *);
PyObject *py_ue_static_mesh_set_shadow_for_lod(ue_PyUObject *, PyObject *);
PyObject *py_ue_get_material_graph(ue_PyUObject *, PyObject *);
#endif
```
|
/content/code_sandbox/Source/UnrealEnginePython/Private/UObject/UEPyMaterial.h
|
objective-c
| 2016-08-07T05:00:51
| 2024-08-14T06:32:20
|
UnrealEnginePython
|
20tab/UnrealEnginePython
| 2,715
| 276
|
```c++
#include "UEPyUserDefinedStruct.h"
#if WITH_EDITOR
#include "Runtime/Engine/Classes/Engine/UserDefinedStruct.h"
#include "Editor/UnrealEd/Classes/UserDefinedStructure/UserDefinedStructEditorData.h"
#include "Editor/UnrealEd/Public/Kismet2/StructureEditorUtils.h"
PyObject *py_ue_struct_add_variable(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
PyObject *py_var;
if (!PyArg_ParseTuple(args, "O:struct_add_variable", &py_var))
{
return nullptr;
}
UUserDefinedStruct *u_struct = ue_py_check_type<UUserDefinedStruct>(self);
if (!u_struct)
return PyErr_Format(PyExc_Exception, "uobject is not a UUserDefinedStruct");
FStructVariableDescription *var = ue_py_check_struct<FStructVariableDescription>(py_var);
if (!var)
return PyErr_Format(PyExc_Exception, "argument is not a FStructVariableDescription");
var->VarGuid = FGuid::NewGuid();
FStructureEditorUtils::GetVarDesc(u_struct).Add(*var);
FStructureEditorUtils::OnStructureChanged(u_struct, FStructureEditorUtils::EStructureEditorChangeInfo::AddedVariable);
return py_ue_new_owned_uscriptstruct(FindObject<UScriptStruct>(ANY_PACKAGE, UTF8_TO_TCHAR((char *)"Guid")), (uint8 *)&var->VarGuid);
}
PyObject *py_ue_struct_get_variables(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
UUserDefinedStruct *u_struct = ue_py_check_type<UUserDefinedStruct>(self);
if (!u_struct)
return PyErr_Format(PyExc_Exception, "uobject is not a UUserDefinedStruct");
TArray<FStructVariableDescription> variables = FStructureEditorUtils::GetVarDesc(u_struct);
PyObject *py_list = PyList_New(0);
for (FStructVariableDescription description : variables)
{
PyList_Append(py_list, py_ue_new_owned_uscriptstruct(FStructVariableDescription::StaticStruct(), (uint8*)&description));
}
return py_list;
}
PyObject *py_ue_struct_remove_variable(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
PyObject *py_guid;
if (!PyArg_ParseTuple(args, "O:struct_remove_variable", &py_guid))
{
return nullptr;
}
UUserDefinedStruct *u_struct = ue_py_check_type<UUserDefinedStruct>(self);
if (!u_struct)
return PyErr_Format(PyExc_Exception, "uobject is not a UUserDefinedStruct");
FGuid *guid = ue_py_check_fguid(py_guid);
if (!guid)
return PyErr_Format(PyExc_Exception, "object is not a FGuid");
if (FStructureEditorUtils::RemoveVariable(u_struct, *guid))
{
Py_RETURN_TRUE;
}
Py_RETURN_FALSE;
}
PyObject *py_ue_struct_move_variable_up(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
PyObject *py_guid;
if (!PyArg_ParseTuple(args, "O:struct_move_variable_up", &py_guid))
{
return nullptr;
}
UUserDefinedStruct *u_struct = ue_py_check_type<UUserDefinedStruct>(self);
if (!u_struct)
return PyErr_Format(PyExc_Exception, "uobject is not a UUserDefinedStruct");
FGuid *guid = ue_py_check_fguid(py_guid);
if (!guid)
return PyErr_Format(PyExc_Exception, "object is not a FGuid");
if (FStructureEditorUtils::MoveVariable(u_struct, *guid, FStructureEditorUtils::EMoveDirection::MD_Up))
{
Py_RETURN_TRUE;
}
Py_RETURN_FALSE;
}
PyObject *py_ue_struct_move_variable_down(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
PyObject *py_guid;
if (!PyArg_ParseTuple(args, "O:struct_move_variable_down", &py_guid))
{
return nullptr;
}
UUserDefinedStruct *u_struct = ue_py_check_type<UUserDefinedStruct>(self);
if (!u_struct)
return PyErr_Format(PyExc_Exception, "uobject is not a UUserDefinedStruct");
FGuid *guid = ue_py_check_fguid(py_guid);
if (!guid)
return PyErr_Format(PyExc_Exception, "object is not a FGuid");
if (FStructureEditorUtils::MoveVariable(u_struct, *guid, FStructureEditorUtils::EMoveDirection::MD_Down))
{
Py_RETURN_TRUE;
}
Py_RETURN_FALSE;
}
#endif
```
|
/content/code_sandbox/Source/UnrealEnginePython/Private/UObject/UEPyUserDefinedStruct.cpp
|
c++
| 2016-08-07T05:00:51
| 2024-08-14T06:32:20
|
UnrealEnginePython
|
20tab/UnrealEnginePython
| 2,715
| 978
|
```objective-c
#pragma once
#include "UEPyModule.h"
PyObject *py_ue_get_actor_location(ue_PyUObject *, PyObject *);
PyObject *py_ue_get_actor_rotation(ue_PyUObject *, PyObject *);
PyObject *py_ue_get_actor_scale(ue_PyUObject *, PyObject *);
PyObject *py_ue_get_actor_transform(ue_PyUObject *, PyObject *);
PyObject *py_ue_get_actor_forward(ue_PyUObject *, PyObject *);
PyObject *py_ue_get_actor_right(ue_PyUObject *, PyObject *);
PyObject *py_ue_get_actor_up(ue_PyUObject *, PyObject *);
PyObject *py_ue_set_actor_rotation(ue_PyUObject *, PyObject *);
PyObject *py_ue_set_actor_location(ue_PyUObject *, PyObject *);
PyObject *py_ue_set_actor_scale(ue_PyUObject *, PyObject *);
PyObject *py_ue_set_actor_transform(ue_PyUObject *, PyObject *);
PyObject *py_ue_add_actor_world_offset(ue_PyUObject *, PyObject *);
PyObject *py_ue_add_actor_local_offset(ue_PyUObject *, PyObject *);
PyObject *py_ue_add_actor_world_rotation(ue_PyUObject *, PyObject *);
PyObject *py_ue_add_actor_local_rotation(ue_PyUObject *, PyObject *);
PyObject *py_ue_get_world_location(ue_PyUObject *, PyObject *);
PyObject *py_ue_get_world_rotation(ue_PyUObject *, PyObject *);
PyObject *py_ue_get_world_scale(ue_PyUObject *, PyObject *);
PyObject *py_ue_get_world_transform(ue_PyUObject *, PyObject *);
PyObject *py_ue_get_relative_location(ue_PyUObject *, PyObject *);
PyObject *py_ue_get_relative_rotation(ue_PyUObject *, PyObject *);
PyObject *py_ue_get_relative_scale(ue_PyUObject *, PyObject *);
PyObject *py_ue_get_relative_transform(ue_PyUObject *, PyObject *);
PyObject *py_ue_set_world_location(ue_PyUObject *, PyObject *);
PyObject *py_ue_set_world_rotation(ue_PyUObject *, PyObject *);
PyObject *py_ue_set_world_scale(ue_PyUObject *, PyObject *);
PyObject *py_ue_set_world_transform(ue_PyUObject *, PyObject *);
PyObject *py_ue_set_relative_location(ue_PyUObject *, PyObject *);
PyObject *py_ue_set_relative_rotation(ue_PyUObject *, PyObject *);
PyObject *py_ue_set_relative_scale(ue_PyUObject *, PyObject *);
PyObject *py_ue_set_relative_transform(ue_PyUObject *, PyObject *);
PyObject *py_ue_get_forward_vector(ue_PyUObject *, PyObject *);
PyObject *py_ue_get_up_vector(ue_PyUObject *, PyObject *);
PyObject *py_ue_get_right_vector(ue_PyUObject *, PyObject *);
```
|
/content/code_sandbox/Source/UnrealEnginePython/Private/UObject/UEPyTransform.h
|
objective-c
| 2016-08-07T05:00:51
| 2024-08-14T06:32:20
|
UnrealEnginePython
|
20tab/UnrealEnginePython
| 2,715
| 562
|
```objective-c
#pragma once
#include "UEPyModule.h"
PyObject *py_ue_get_instanced_foliage_actor_for_current_level(ue_PyUObject *, PyObject *);
PyObject *py_ue_get_instanced_foliage_actor_for_level(ue_PyUObject *, PyObject *);
PyObject *py_ue_get_foliage_types(ue_PyUObject *, PyObject *);
#if WITH_EDITOR
PyObject *py_ue_get_foliage_instances(ue_PyUObject *, PyObject *);
PyObject *py_ue_add_foliage_asset(ue_PyUObject *, PyObject *);
#endif
```
|
/content/code_sandbox/Source/UnrealEnginePython/Private/UObject/UEPyFoliage.h
|
objective-c
| 2016-08-07T05:00:51
| 2024-08-14T06:32:20
|
UnrealEnginePython
|
20tab/UnrealEnginePython
| 2,715
| 116
|
```c++
#include "UEPyWorld.h"
#include "Runtime/Engine/Classes/Kismet/KismetSystemLibrary.h"
#include "EngineUtils.h"
#include "Kismet/GameplayStatics.h"
#include "Runtime/CoreUObject/Public/UObject/UObjectIterator.h"
#if WITH_EDITOR
#include "Editor/UnrealEd/Public/EditorActorFolders.h"
#endif
PyObject *py_ue_world_exec(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
char *command;
if (!PyArg_ParseTuple(args, "s:world_exec", &command))
{
return NULL;
}
UWorld *world = ue_get_uworld(self);
if (!world)
return PyErr_Format(PyExc_Exception, "unable to retrieve UWorld from uobject");
if (world->Exec(world, UTF8_TO_TCHAR(command)))
Py_RETURN_TRUE;
Py_RETURN_FALSE;
}
PyObject *py_ue_quit_game(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
UWorld *world = ue_get_uworld(self);
if (!world)
return PyErr_Format(PyExc_Exception, "unable to retrieve UWorld from uobject");
// no need to support multiple controllers
APlayerController *controller = world->GetFirstPlayerController();
if (!controller)
return PyErr_Format(PyExc_Exception, "unable to retrieve the first controller");
#if ENGINE_MINOR_VERSION > 20
UKismetSystemLibrary::QuitGame(world, controller, EQuitPreference::Quit, false);
#else
UKismetSystemLibrary::QuitGame(world, controller, EQuitPreference::Quit);
#endif
Py_RETURN_NONE;
}
PyObject *py_ue_get_world_type(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
UWorld *world = ue_get_uworld(self);
if (!world)
return PyErr_Format(PyExc_Exception, "unable to retrieve UWorld from uobject");
return PyLong_FromUnsignedLong(world->WorldType);
}
PyObject *py_ue_play(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
UWorld *world = ue_get_uworld(self);
if (!world)
return PyErr_Format(PyExc_Exception, "unable to retrieve UWorld from uobject");
world->BeginPlay();
Py_RETURN_NONE;
}
// mainly used for testing
PyObject *py_ue_world_tick(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
float delta_time;
PyObject *py_increase_fc = nullptr;
if (!PyArg_ParseTuple(args, "f|O:world_tick", &delta_time, &py_increase_fc))
{
return nullptr;
}
UWorld *world = ue_get_uworld(self);
if (!world)
return PyErr_Format(PyExc_Exception, "unable to retrieve UWorld from uobject");
world->Tick(LEVELTICK_All, delta_time);
if (py_increase_fc && PyObject_IsTrue(py_increase_fc))
GFrameCounter++;
Py_RETURN_NONE;
}
PyObject *py_ue_all_objects(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
UWorld *world = ue_get_uworld(self);
if (!world)
return PyErr_Format(PyExc_Exception, "unable to retrieve UWorld from uobject");
PyObject *ret = PyList_New(0);
for (TObjectIterator<UObject> Itr; Itr; ++Itr)
{
UObject *u_obj = *Itr;
if (u_obj->GetWorld() != world)
continue;
ue_PyUObject *py_obj = ue_get_python_uobject(u_obj);
if (!py_obj)
continue;
PyList_Append(ret, (PyObject *)py_obj);
}
return ret;
}
PyObject *py_ue_all_actors(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
UWorld *world = ue_get_uworld(self);
if (!world)
return PyErr_Format(PyExc_Exception, "unable to retrieve UWorld from uobject");
PyObject *ret = PyList_New(0);
for (TActorIterator<AActor> Itr(world); Itr; ++Itr)
{
UObject *u_obj = *Itr;
ue_PyUObject *py_obj = ue_get_python_uobject(u_obj);
if (!py_obj)
continue;
PyList_Append(ret, (PyObject *)py_obj);
}
return ret;
}
PyObject *py_ue_find_object(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
char *name;
if (!PyArg_ParseTuple(args, "s:find_object", &name))
{
return NULL;
}
UWorld *world = ue_get_uworld(self);
if (!world)
return PyErr_Format(PyExc_Exception, "unable to retrieve UWorld from uobject");
UObject *u_object = FindObject<UObject>(world->GetOutermost(), UTF8_TO_TCHAR(name));
if (!u_object)
return PyErr_Format(PyExc_Exception, "unable to find object %s", name);
Py_RETURN_UOBJECT(u_object);
}
PyObject *py_ue_get_world(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
UWorld *world = ue_get_uworld(self);
if (!world)
return PyErr_Format(PyExc_Exception, "unable to retrieve UWorld from uobject");
Py_RETURN_UOBJECT(world);
}
PyObject *py_ue_get_game_viewport(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
UWorld *world = ue_get_uworld(self);
if (!world)
return PyErr_Format(PyExc_Exception, "unable to retrieve UWorld from uobject");
UGameViewportClient *viewport_client = world->GetGameViewport();
if (!viewport_client)
return PyErr_Format(PyExc_Exception, "world has no GameViewportClient");
Py_RETURN_UOBJECT((UObject *)viewport_client);
}
PyObject *py_ue_has_world(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
if (ue_get_uworld(self))
Py_RETURN_TRUE;
Py_RETURN_FALSE;
}
PyObject *py_ue_set_view_target(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
UWorld *world = ue_get_uworld(self);
if (!world)
return PyErr_Format(PyExc_Exception, "unable to retrieve UWorld from uobject");
PyObject *py_obj;
int controller_id = 0;
if (!PyArg_ParseTuple(args, "O|i:set_view_target", &py_obj, &controller_id))
{
return NULL;
}
AActor *actor = ue_py_check_type<AActor>(py_obj);
if (!actor)
{
return PyErr_Format(PyExc_Exception, "argument is not an actor");
}
APlayerController *controller = UGameplayStatics::GetPlayerController(world, controller_id);
if (!controller)
return PyErr_Format(PyExc_Exception, "unable to retrieve controller %d", controller_id);
controller->SetViewTarget(actor);
Py_RETURN_NONE;
}
PyObject *py_ue_get_world_delta_seconds(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
UWorld *world = ue_get_uworld(self);
if (!world)
return PyErr_Format(PyExc_Exception, "unable to retrieve UWorld from uobject");
return Py_BuildValue("f", UGameplayStatics::GetWorldDeltaSeconds(world));
}
PyObject *py_ue_get_levels(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
UWorld *world = ue_get_uworld(self);
if (!world)
return PyErr_Format(PyExc_Exception, "unable to retrieve UWorld from uobject");
PyObject *ret = PyList_New(0);
for (ULevel *level : world->GetLevels())
{
ue_PyUObject *py_obj = ue_get_python_uobject(level);
if (!py_obj)
continue;
PyList_Append(ret, (PyObject *)py_obj);
}
return ret;
}
PyObject *py_ue_get_current_level(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
UWorld *world = ue_get_uworld(self);
if (!world)
return PyErr_Format(PyExc_Exception, "unable to retrieve UWorld from uobject");
ULevel *level = world->GetCurrentLevel();
if (!level)
Py_RETURN_NONE;
Py_RETURN_UOBJECT(level);
}
PyObject *py_ue_set_current_level(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
PyObject *py_level;
if (!PyArg_ParseTuple(args, "O", &py_level))
return nullptr;
UWorld *world = ue_get_uworld(self);
if (!world)
return PyErr_Format(PyExc_Exception, "unable to retrieve UWorld from uobject");
ULevel *level = ue_py_check_type<ULevel>(py_level);
if (!level)
return PyErr_Format(PyExc_Exception, "argument is not a ULevel");
#if WITH_EDITOR || ENGINE_MINOR_VERSION < 22
if (world->SetCurrentLevel(level))
Py_RETURN_TRUE;
#endif
Py_RETURN_FALSE;
}
#if WITH_EDITOR
PyObject *py_ue_get_level_script_blueprint(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
ULevel *level = ue_py_check_type<ULevel>(self);
if (!level)
{
return PyErr_Format(PyExc_Exception, "uobject is not a ULevel");
}
Py_RETURN_UOBJECT((UObject*)level->GetLevelScriptBlueprint());
}
PyObject *py_ue_world_create_folder(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
char *path;
if (!PyArg_ParseTuple(args, "s:world_create_folder", &path))
return nullptr;
if (!FActorFolders::IsAvailable())
return PyErr_Format(PyExc_Exception, "FActorFolders is not available");
UWorld *world = ue_get_uworld(self);
if (!world)
return PyErr_Format(PyExc_Exception, "unable to retrieve UWorld from uobject");
FName FolderPath = FName(UTF8_TO_TCHAR(path));
FActorFolders::Get().CreateFolder(*world, FolderPath);
Py_RETURN_NONE;
}
PyObject *py_ue_world_delete_folder(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
char *path;
if (!PyArg_ParseTuple(args, "s:world_delete_folder", &path))
return nullptr;
if (!FActorFolders::IsAvailable())
return PyErr_Format(PyExc_Exception, "FActorFolders is not available");
UWorld *world = ue_get_uworld(self);
if (!world)
return PyErr_Format(PyExc_Exception, "unable to retrieve UWorld from uobject");
FName FolderPath = FName(UTF8_TO_TCHAR(path));
FActorFolders::Get().DeleteFolder(*world, FolderPath);
Py_RETURN_NONE;
}
PyObject *py_ue_world_rename_folder(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
char *path;
char *new_path;
if (!PyArg_ParseTuple(args, "ss:world_rename_folder", &path, &new_path))
return nullptr;
if (!FActorFolders::IsAvailable())
return PyErr_Format(PyExc_Exception, "FActorFolders is not available");
UWorld *world = ue_get_uworld(self);
if (!world)
return PyErr_Format(PyExc_Exception, "unable to retrieve UWorld from uobject");
FName FolderPath = FName(UTF8_TO_TCHAR(path));
FName NewFolderPath = FName(UTF8_TO_TCHAR(new_path));
if (FActorFolders::Get().RenameFolderInWorld(*world, FolderPath, NewFolderPath))
Py_RETURN_TRUE;
Py_RETURN_FALSE;
}
PyObject *py_ue_world_folders(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
if (!FActorFolders::IsAvailable())
return PyErr_Format(PyExc_Exception, "FActorFolders is not available");
UWorld *world = ue_get_uworld(self);
if (!world)
return PyErr_Format(PyExc_Exception, "unable to retrieve UWorld from uobject");
const TMap<FName, FActorFolderProps> &Folders = FActorFolders::Get().GetFolderPropertiesForWorld(*world);
PyObject *py_list = PyList_New(0);
TArray<FName> FolderNames;
Folders.GenerateKeyArray(FolderNames);
for (FName FolderName : FolderNames)
{
PyObject *py_str = PyUnicode_FromString(TCHAR_TO_UTF8(*FolderName.ToString()));
PyList_Append(py_list, py_str);
Py_DECREF(py_str);
}
return py_list;
}
#endif
```
|
/content/code_sandbox/Source/UnrealEnginePython/Private/UObject/UEPyWorld.cpp
|
c++
| 2016-08-07T05:00:51
| 2024-08-14T06:32:20
|
UnrealEnginePython
|
20tab/UnrealEnginePython
| 2,715
| 2,708
|
```c++
#include "UEPyCapture.h"
#include "Runtime/MovieSceneCapture/Public/MovieSceneCapture.h"
#if WITH_EDITOR
/*
This is taken as-is (more or less) from MovieSceneCaptureDialogModule.cpp
to automate sequencer capturing. The only relevant implementation is the support
for a queue of UMovieSceneCapture objects
*/
#include "AudioDevice.h"
#include "Editor/EditorEngine.h"
#include "Slate/SceneViewport.h"
#include "AutomatedLevelSequenceCapture.h"
#include "Slate/UEPySPythonEditorViewport.h"
#include "GameFramework/GameModeBase.h"
#include "GameFramework/GameMode.h"
#include "Runtime/CoreUObject/Public/Serialization/ObjectReader.h"
#include "Runtime/CoreUObject/Public/Serialization/ObjectWriter.h"
#include "Runtime/Slate/Public/Framework/Application/SlateApplication.h"
#include "Runtime/Core/Public/Containers/Ticker.h"
struct FInEditorMultiCapture : TSharedFromThis<FInEditorMultiCapture>
{
static TWeakPtr<FInEditorMultiCapture> CreateInEditorMultiCapture(TArray<UMovieSceneCapture*> InCaptureObjects, PyObject *py_callable)
{
// FInEditorCapture owns itself, so should only be kept alive by itself, or a pinned (=> temporary) weakptr
FInEditorMultiCapture* Capture = new FInEditorMultiCapture;
Capture->CaptureObjects = InCaptureObjects;
Capture->py_callable = py_callable;
if (Capture->py_callable)
Py_INCREF(Capture->py_callable);
for (UMovieSceneCapture *SceneCapture : Capture->CaptureObjects)
{
SceneCapture->AddToRoot();
}
Capture->Dequeue();
return Capture->AsShared();
}
private:
FInEditorMultiCapture()
{
CapturingFromWorld = nullptr;
}
void Die()
{
for (UMovieSceneCapture *SceneCapture : CaptureObjects)
{
SceneCapture->RemoveFromRoot();
}
OnlyStrongReference = nullptr;
{
FScopePythonGIL gil;
Py_XDECREF(py_callable);
}
}
void Dequeue()
{
if (CaptureObjects.Num() < 1)
{
Die();
return;
}
CurrentCaptureObject = CaptureObjects[0];
check(CurrentCaptureObject);
CapturingFromWorld = nullptr;
if (!OnlyStrongReference.IsValid())
OnlyStrongReference = MakeShareable(this);
ULevelEditorPlaySettings* PlayInEditorSettings = GetMutableDefault<ULevelEditorPlaySettings>();
bScreenMessagesWereEnabled = GAreScreenMessagesEnabled;
GAreScreenMessagesEnabled = false;
if (!CurrentCaptureObject->Settings.bEnableTextureStreaming)
{
const int32 UndefinedTexturePoolSize = -1;
IConsoleVariable* CVarStreamingPoolSize = IConsoleManager::Get().FindConsoleVariable(TEXT("r.Streaming.PoolSize"));
if (CVarStreamingPoolSize)
{
BackedUpStreamingPoolSize = CVarStreamingPoolSize->GetInt();
CVarStreamingPoolSize->Set(UndefinedTexturePoolSize, ECVF_SetByConsole);
}
IConsoleVariable* CVarUseFixedPoolSize = IConsoleManager::Get().FindConsoleVariable(TEXT("r.Streaming.UseFixedPoolSize"));
if (CVarUseFixedPoolSize)
{
BackedUpUseFixedPoolSize = CVarUseFixedPoolSize->GetInt();
CVarUseFixedPoolSize->Set(0, ECVF_SetByConsole);
}
}
// cleanup from previous run
BackedUpPlaySettings.Empty();
FObjectWriter(PlayInEditorSettings, BackedUpPlaySettings);
OverridePlaySettings(PlayInEditorSettings);
//CurrentCaptureObject->AddToRoot();
CurrentCaptureObject->OnCaptureFinished().AddRaw(this, &FInEditorMultiCapture::OnEnd);
UGameViewportClient::OnViewportCreated().AddRaw(this, &FInEditorMultiCapture::OnStart);
FEditorDelegates::EndPIE.AddRaw(this, &FInEditorMultiCapture::OnEndPIE);
FAudioDevice* AudioDevice = GEngine->GetMainAudioDevice();
if (AudioDevice != nullptr)
{
TransientMasterVolume = AudioDevice->GetTransientMasterVolume();
AudioDevice->SetTransientMasterVolume(0.0f);
}
// play at the next tick
FTicker::GetCoreTicker().AddTicker(FTickerDelegate::CreateRaw(this, &FInEditorMultiCapture::PlaySession), 0);
}
bool PlaySession(float DeltaTime)
{
if (py_callable)
{
GEditor->RequestEndPlayMap();
FScopePythonGIL gil;
ue_PyUObject *py_capture = ue_get_python_uobject(CurrentCaptureObject);
PyObject *py_ret = PyObject_CallFunction(py_callable, "O", py_capture);
if (!py_ret)
{
unreal_engine_py_log_error();
}
Py_XDECREF(py_ret);
}
GEditor->RequestPlaySession(true, nullptr, false);
return false;
}
void OverridePlaySettings(ULevelEditorPlaySettings* PlayInEditorSettings)
{
const FMovieSceneCaptureSettings& Settings = CurrentCaptureObject->GetSettings();
PlayInEditorSettings->NewWindowWidth = Settings.Resolution.ResX;
PlayInEditorSettings->NewWindowHeight = Settings.Resolution.ResY;
PlayInEditorSettings->CenterNewWindow = true;
PlayInEditorSettings->LastExecutedPlayModeType = EPlayModeType::PlayMode_InEditorFloating;
TSharedRef<SWindow> CustomWindow = SNew(SWindow)
.Title(FText::FromString("Movie Render - Preview"))
.AutoCenter(EAutoCenter::PrimaryWorkArea)
.UseOSWindowBorder(true)
.FocusWhenFirstShown(false)
#if ENGINE_MINOR_VERSION > 15
.ActivationPolicy(EWindowActivationPolicy::Never)
#endif
.HasCloseButton(true)
.SupportsMaximize(false)
.SupportsMinimize(true)
.MaxWidth(Settings.Resolution.ResX)
.MaxHeight(Settings.Resolution.ResY)
.SizingRule(ESizingRule::FixedSize);
FSlateApplication::Get().AddWindow(CustomWindow);
PlayInEditorSettings->CustomPIEWindow = CustomWindow;
// Reset everything else
PlayInEditorSettings->GameGetsMouseControl = false;
PlayInEditorSettings->ShowMouseControlLabel = false;
PlayInEditorSettings->ViewportGetsHMDControl = false;
#if ENGINE_MINOR_VERSION >= 17
PlayInEditorSettings->ShouldMinimizeEditorOnVRPIE = true;
PlayInEditorSettings->EnableGameSound = false;
#endif
PlayInEditorSettings->bOnlyLoadVisibleLevelsInPIE = false;
PlayInEditorSettings->bPreferToStreamLevelsInPIE = false;
PlayInEditorSettings->PIEAlwaysOnTop = false;
PlayInEditorSettings->DisableStandaloneSound = true;
PlayInEditorSettings->AdditionalLaunchParameters = TEXT("");
PlayInEditorSettings->BuildGameBeforeLaunch = EPlayOnBuildMode::PlayOnBuild_Never;
PlayInEditorSettings->LaunchConfiguration = EPlayOnLaunchConfiguration::LaunchConfig_Default;
PlayInEditorSettings->SetPlayNetMode(EPlayNetMode::PIE_Standalone);
PlayInEditorSettings->SetRunUnderOneProcess(true);
PlayInEditorSettings->SetPlayNetDedicated(false);
PlayInEditorSettings->SetPlayNumberOfClients(1);
}
void OnStart()
{
for (const FWorldContext& Context : GEngine->GetWorldContexts())
{
if (Context.WorldType == EWorldType::PIE)
{
FSlatePlayInEditorInfo* SlatePlayInEditorSession = GEditor->SlatePlayInEditorMap.Find(Context.ContextHandle);
if (SlatePlayInEditorSession)
{
CapturingFromWorld = Context.World();
TSharedPtr<SWindow> Window = SlatePlayInEditorSession->SlatePlayInEditorWindow.Pin();
const FMovieSceneCaptureSettings& Settings = CurrentCaptureObject->GetSettings();
SlatePlayInEditorSession->SlatePlayInEditorWindowViewport->SetViewportSize(Settings.Resolution.ResX, Settings.Resolution.ResY);
FVector2D PreviewWindowSize(Settings.Resolution.ResX, Settings.Resolution.ResY);
// Keep scaling down the window size while we're bigger than half the destop width/height
{
FDisplayMetrics DisplayMetrics;
FSlateApplication::Get().GetDisplayMetrics(DisplayMetrics);
while (PreviewWindowSize.X >= DisplayMetrics.PrimaryDisplayWidth*.5f || PreviewWindowSize.Y >= DisplayMetrics.PrimaryDisplayHeight*.5f)
{
PreviewWindowSize *= .5f;
}
}
// Resize and move the window into the desktop a bit
FVector2D PreviewWindowPosition(50, 50);
Window->ReshapeWindow(PreviewWindowPosition, PreviewWindowSize);
if (CurrentCaptureObject->Settings.GameModeOverride != nullptr)
{
CachedGameMode = CapturingFromWorld->GetWorldSettings()->DefaultGameMode;
CapturingFromWorld->GetWorldSettings()->DefaultGameMode = CurrentCaptureObject->Settings.GameModeOverride;
}
CurrentCaptureObject->Initialize(SlatePlayInEditorSession->SlatePlayInEditorWindowViewport, Context.PIEInstance);
}
return;
}
}
}
void Shutdown()
{
FEditorDelegates::EndPIE.RemoveAll(this);
UGameViewportClient::OnViewportCreated().RemoveAll(this);
CurrentCaptureObject->OnCaptureFinished().RemoveAll(this);
GAreScreenMessagesEnabled = bScreenMessagesWereEnabled;
if (!CurrentCaptureObject->Settings.bEnableTextureStreaming)
{
IConsoleVariable* CVarStreamingPoolSize = IConsoleManager::Get().FindConsoleVariable(TEXT("r.Streaming.PoolSize"));
if (CVarStreamingPoolSize)
{
CVarStreamingPoolSize->Set(BackedUpStreamingPoolSize, ECVF_SetByConsole);
}
IConsoleVariable* CVarUseFixedPoolSize = IConsoleManager::Get().FindConsoleVariable(TEXT("r.Streaming.UseFixedPoolSize"));
if (CVarUseFixedPoolSize)
{
CVarUseFixedPoolSize->Set(BackedUpUseFixedPoolSize, ECVF_SetByConsole);
}
}
if (CurrentCaptureObject->Settings.GameModeOverride != nullptr)
{
CapturingFromWorld->GetWorldSettings()->DefaultGameMode = CachedGameMode;
}
FObjectReader(GetMutableDefault<ULevelEditorPlaySettings>(), BackedUpPlaySettings);
FAudioDevice* AudioDevice = GEngine->GetMainAudioDevice();
if (AudioDevice != nullptr)
{
AudioDevice->SetTransientMasterVolume(TransientMasterVolume);
}
CurrentCaptureObject->Close();
//CurrentCaptureObject->RemoveFromRoot();
}
void OnEndPIE(bool bIsSimulating)
{
Shutdown();
Die();
}
void NextCapture(bool bIsSimulating)
{
FEditorDelegates::EndPIE.RemoveAll(this);
// remove item from the TArray;
CaptureObjects.RemoveAt(0);
if (CaptureObjects.Num() > 0)
{
Dequeue();
}
else
{
Die();
}
}
void OnEnd()
{
Shutdown();
FEditorDelegates::EndPIE.AddRaw(this, &FInEditorMultiCapture::NextCapture);
GEditor->RequestEndPlayMap();
}
TSharedPtr<FInEditorMultiCapture> OnlyStrongReference;
UWorld* CapturingFromWorld;
bool bScreenMessagesWereEnabled;
float TransientMasterVolume;
int32 BackedUpStreamingPoolSize;
int32 BackedUpUseFixedPoolSize;
TArray<uint8> BackedUpPlaySettings;
UMovieSceneCapture* CurrentCaptureObject;
TSubclassOf<AGameModeBase> CachedGameMode;
TArray<UMovieSceneCapture*> CaptureObjects;
PyObject *py_callable;
};
PyObject *py_unreal_engine_in_editor_capture(PyObject * self, PyObject * args)
{
PyObject *py_scene_captures;
PyObject *py_callable = nullptr;
if (!PyArg_ParseTuple(args, "O|O:in_editor_capture", &py_scene_captures, &py_callable))
{
return nullptr;
}
TArray<UMovieSceneCapture *> Captures;
UMovieSceneCapture *capture = ue_py_check_type<UMovieSceneCapture>(py_scene_captures);
if (!capture)
{
PyObject *py_iter = PyObject_GetIter(py_scene_captures);
if (!py_iter)
{
return PyErr_Format(PyExc_Exception, "argument is not a UMovieSceneCapture or an iterable of UMovieSceneCapture");
}
while (PyObject *py_item = PyIter_Next(py_iter))
{
capture = ue_py_check_type<UMovieSceneCapture>(py_item);
if (!capture)
{
Py_DECREF(py_iter);
return PyErr_Format(PyExc_Exception, "argument is not an iterable of UMovieSceneCapture");
}
Captures.Add(capture);
}
Py_DECREF(py_iter);
}
else
{
Captures.Add(capture);
}
Py_BEGIN_ALLOW_THREADS
FInEditorMultiCapture::CreateInEditorMultiCapture(Captures, py_callable);
Py_END_ALLOW_THREADS
Py_RETURN_NONE;
}
PyObject *py_ue_set_level_sequence_asset(ue_PyUObject *self, PyObject *args)
{
ue_py_check(self);
PyObject *py_sequence = nullptr;
if (!PyArg_ParseTuple(args, "O:set_level_sequence_asset", &py_sequence))
{
return nullptr;
}
ULevelSequence *sequence = ue_py_check_type<ULevelSequence>(py_sequence);
if (!sequence)
{
return PyErr_Format(PyExc_Exception, "uobject is not a ULevelSequence");
}
UAutomatedLevelSequenceCapture *capture = ue_py_check_type<UAutomatedLevelSequenceCapture>(self);
if (!capture)
return PyErr_Format(PyExc_Exception, "uobject is not a UAutomatedLevelSequenceCapture");
#if ENGINE_MINOR_VERSION < 20
capture->SetLevelSequenceAsset(sequence->GetPathName());
#else
capture->LevelSequenceAsset = FSoftObjectPath(sequence->GetPathName());
#endif
Py_RETURN_NONE;
}
#endif
PyObject *py_ue_capture_initialize(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
PyObject *py_widget = nullptr;
if (!PyArg_ParseTuple(args, "|O:capture_initialize", &py_widget))
{
return nullptr;
}
UMovieSceneCapture *capture = ue_py_check_type<UMovieSceneCapture>(self);
if (!capture)
return PyErr_Format(PyExc_Exception, "uobject is not a UMovieSceneCapture");
#if WITH_EDITOR
if (py_widget)
{
TSharedPtr<SPythonEditorViewport> Viewport = py_ue_is_swidget<SPythonEditorViewport>(py_widget);
if (Viewport.IsValid())
{
capture->Initialize(Viewport->GetSceneViewport());
capture->StartWarmup();
}
else
{
return PyErr_Format(PyExc_Exception, "argument is not a supported Viewport-based SWidget");
}
}
#endif
Py_RETURN_NONE;
}
PyObject *py_ue_capture_start(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
UMovieSceneCapture *capture = ue_py_check_type<UMovieSceneCapture>(self);
if (!capture)
return PyErr_Format(PyExc_Exception, "uobject is not a UMovieSceneCapture");
capture->StartCapture();
Py_RETURN_NONE;
}
PyObject *py_ue_capture_load_from_config(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
UMovieSceneCapture *capture = ue_py_check_type<UMovieSceneCapture>(self);
if (!capture)
return PyErr_Format(PyExc_Exception, "uobject is not a UMovieSceneCapture");
capture->LoadFromConfig();
Py_RETURN_NONE;
}
PyObject *py_ue_capture_stop(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
UMovieSceneCapture *capture = ue_py_check_type<UMovieSceneCapture>(self);
if (!capture)
return PyErr_Format(PyExc_Exception, "uobject is not a UMovieSceneCapture");
capture->Finalize();
capture->Close();
Py_RETURN_NONE;
}
```
|
/content/code_sandbox/Source/UnrealEnginePython/Private/UObject/UEPyCapture.cpp
|
c++
| 2016-08-07T05:00:51
| 2024-08-14T06:32:20
|
UnrealEnginePython
|
20tab/UnrealEnginePython
| 2,715
| 3,662
|
```objective-c
#pragma once
#include "UEPyModule.h"
PyObject *py_ue_take_widget(ue_PyUObject *, PyObject *);
PyObject *py_ue_create_widget(ue_PyUObject *, PyObject *);
```
|
/content/code_sandbox/Source/UnrealEnginePython/Private/UObject/UEPyWidget.h
|
objective-c
| 2016-08-07T05:00:51
| 2024-08-14T06:32:20
|
UnrealEnginePython
|
20tab/UnrealEnginePython
| 2,715
| 42
|
```objective-c
#pragma once
#include "UEPyModule.h"
PyObject *py_ue_pawn_get_controller(ue_PyUObject *, PyObject *);
```
|
/content/code_sandbox/Source/UnrealEnginePython/Private/UObject/UEPyPawn.h
|
objective-c
| 2016-08-07T05:00:51
| 2024-08-14T06:32:20
|
UnrealEnginePython
|
20tab/UnrealEnginePython
| 2,715
| 28
|
```objective-c
#pragma once
#include "UEPyModule.h"
#if WITH_EDITOR
PyObject *py_ue_create_landscape_info(ue_PyUObject *self, PyObject *);
PyObject *py_ue_get_landscape_info(ue_PyUObject *self, PyObject *);
PyObject *py_ue_landscape_import(ue_PyUObject *self, PyObject *);
PyObject *py_ue_landscape_export_to_raw_mesh(ue_PyUObject *self, PyObject *);
#endif
```
|
/content/code_sandbox/Source/UnrealEnginePython/Private/UObject/UEPyLandscape.h
|
objective-c
| 2016-08-07T05:00:51
| 2024-08-14T06:32:20
|
UnrealEnginePython
|
20tab/UnrealEnginePython
| 2,715
| 93
|
```objective-c
#pragma once
#include "UEPyModule.h"
PyObject *py_ue_is_input_key_down(ue_PyUObject *, PyObject *);
PyObject *py_ue_was_input_key_just_pressed(ue_PyUObject *, PyObject *);
PyObject *py_ue_was_input_key_just_released(ue_PyUObject *, PyObject *);
PyObject *py_ue_is_action_pressed(ue_PyUObject *, PyObject *);
PyObject *py_ue_is_action_released(ue_PyUObject *, PyObject *);
PyObject *py_ue_enable_input(ue_PyUObject *, PyObject *);
PyObject *py_ue_get_input_axis(ue_PyUObject *, PyObject *);
PyObject *py_ue_bind_input_axis(ue_PyUObject *, PyObject *);
PyObject *py_ue_enable_mouse_over_events(ue_PyUObject *, PyObject *);
PyObject *py_ue_enable_click_events(ue_PyUObject *, PyObject *);
PyObject *py_ue_show_mouse_cursor(ue_PyUObject *, PyObject *);
PyObject *py_ue_bind_action(ue_PyUObject *, PyObject *);
PyObject *py_ue_bind_axis(ue_PyUObject *, PyObject *);
PyObject *py_ue_bind_key(ue_PyUObject *, PyObject *);
PyObject *py_ue_bind_pressed_key(ue_PyUObject *, PyObject *);
PyObject *py_ue_bind_released_key(ue_PyUObject *, PyObject *);
PyObject *py_ue_input_key(ue_PyUObject *, PyObject *);
PyObject *py_ue_input_axis(ue_PyUObject *, PyObject *);
PyObject *py_unreal_engine_get_engine_defined_action_mappings(PyObject *, PyObject *);
```
|
/content/code_sandbox/Source/UnrealEnginePython/Private/UObject/UEPyInput.h
|
objective-c
| 2016-08-07T05:00:51
| 2024-08-14T06:32:20
|
UnrealEnginePython
|
20tab/UnrealEnginePython
| 2,715
| 320
|
```c++
#include "UEPyDataTable.h"
#if WITH_EDITOR
#include "Runtime/Engine/Classes/Engine/DataTable.h"
#include "Editor/UnrealEd/Public/DataTableEditorUtils.h"
PyObject *py_ue_data_table_add_row(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
char *name;
PyObject *py_row;
if (!PyArg_ParseTuple(args, "sO:data_table_add_row", &name, &py_row))
{
return nullptr;
}
UDataTable *data_table = ue_py_check_type<UDataTable>(self);
if (!data_table)
return PyErr_Format(PyExc_Exception, "uobject is not a UDataTable");
ue_PyUScriptStruct *u_struct = py_ue_is_uscriptstruct(py_row);
if (!u_struct)
return PyErr_Format(PyExc_Exception, "argument is not a UScriptStruct");
if (data_table->RowStruct != u_struct->u_struct)
{
return PyErr_Format(PyExc_Exception, "argument is not a %s", TCHAR_TO_UTF8(*data_table->RowStruct->GetName()));
}
FName row_name = FName(UTF8_TO_TCHAR(name));
uint8 *row = FDataTableEditorUtils::AddRow(data_table, row_name);
if (!row)
return PyErr_Format(PyExc_Exception, "unable to add row");
data_table->RowStruct->InitializeStruct(row);
data_table->RowStruct->CopyScriptStruct(row, u_struct->u_struct_ptr);
Py_RETURN_NONE;
}
PyObject *py_ue_data_table_remove_row(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
char *name;
if (!PyArg_ParseTuple(args, "s:data_table_remove_row", &name))
{
return nullptr;
}
UDataTable *data_table = ue_py_check_type<UDataTable>(self);
if (!data_table)
return PyErr_Format(PyExc_Exception, "uobject is not a UDataTable");
FName row_name = FName(UTF8_TO_TCHAR(name));
if (FDataTableEditorUtils::RemoveRow(data_table, row_name))
{
Py_RETURN_TRUE;
}
Py_RETURN_FALSE;
}
PyObject *py_ue_data_table_rename_row(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
char *name;
char *new_name;
if (!PyArg_ParseTuple(args, "ss:data_table_rename_row", &name, &new_name))
{
return nullptr;
}
UDataTable *data_table = ue_py_check_type<UDataTable>(self);
if (!data_table)
return PyErr_Format(PyExc_Exception, "uobject is not a UDataTable");
FName row_name = FName(UTF8_TO_TCHAR(name));
FName row_new_name = FName(UTF8_TO_TCHAR(new_name));
if (FDataTableEditorUtils::RenameRow(data_table, row_name, row_new_name))
{
Py_RETURN_TRUE;
}
Py_RETURN_FALSE;
}
PyObject *py_ue_data_table_as_dict(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
UDataTable *data_table = ue_py_check_type<UDataTable>(self);
if (!data_table)
return PyErr_Format(PyExc_Exception, "uobject is not a UDataTable");
PyObject *py_dict = PyDict_New();
#if ENGINE_MINOR_VERSION > 20
for (TMap<FName, uint8*>::TConstIterator RowMapIter(data_table->GetRowMap().CreateConstIterator()); RowMapIter; ++RowMapIter)
#else
for (TMap<FName, uint8*>::TConstIterator RowMapIter(data_table->RowMap.CreateConstIterator()); RowMapIter; ++RowMapIter)
#endif
{
PyDict_SetItemString(py_dict, TCHAR_TO_UTF8(*RowMapIter->Key.ToString()), py_ue_new_owned_uscriptstruct(data_table->RowStruct, RowMapIter->Value));
}
return py_dict;
}
PyObject *py_ue_data_table_as_json(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
int flags = 0;
if (!PyArg_ParseTuple(args, "|i:data_table_as_json", &flags))
{
return nullptr;
}
UDataTable *data_table = ue_py_check_type<UDataTable>(self);
if (!data_table)
return PyErr_Format(PyExc_Exception, "uobject is not a UDataTable");
return PyUnicode_FromString(TCHAR_TO_UTF8(*data_table->GetTableAsJSON((EDataTableExportFlags)flags)));
}
PyObject *py_ue_data_table_find_row(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
char *name;
if (!PyArg_ParseTuple(args, "s:data_table_find_row", &name))
{
return nullptr;
}
UDataTable *data_table = ue_py_check_type<UDataTable>(self);
if (!data_table)
return PyErr_Format(PyExc_Exception, "uobject is not a UDataTable");
uint8 **data = nullptr;
#if ENGINE_MINOR_VERSION > 20
data = (uint8 **)data_table->GetRowMap().Find(FName(UTF8_TO_TCHAR(name)));
#else
data = data_table->RowMap.Find(FName(UTF8_TO_TCHAR(name)));
#endif
if (!data)
{
return PyErr_Format(PyExc_Exception, "key not found in UDataTable");
}
return py_ue_new_owned_uscriptstruct(data_table->RowStruct, *data);
}
PyObject *py_ue_data_table_get_all_rows(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
UDataTable *data_table = ue_py_check_type<UDataTable>(self);
if (!data_table)
return PyErr_Format(PyExc_Exception, "uobject is not a UDataTable");
PyObject *py_list = PyList_New(0);
#if ENGINE_MINOR_VERSION > 20
for (TMap<FName, uint8*>::TConstIterator RowMapIter(data_table->GetRowMap().CreateConstIterator()); RowMapIter; ++RowMapIter)
#else
for (TMap<FName, uint8*>::TConstIterator RowMapIter(data_table->RowMap.CreateConstIterator()); RowMapIter; ++RowMapIter)
#endif
{
PyList_Append(py_list, py_ue_new_owned_uscriptstruct(data_table->RowStruct, RowMapIter->Value));
}
return py_list;
}
#endif
```
|
/content/code_sandbox/Source/UnrealEnginePython/Private/UObject/UEPyDataTable.cpp
|
c++
| 2016-08-07T05:00:51
| 2024-08-14T06:32:20
|
UnrealEnginePython
|
20tab/UnrealEnginePython
| 2,715
| 1,348
|
```c++
#include "UEPyPlayer.h"
#include "Kismet/GameplayStatics.h"
#include "Engine/World.h"
#include "GameFramework/PlayerController.h"
#include "GameFramework/HUD.h"
#include "GameFramework/GameMode.h"
#include "GameFramework/PlayerState.h"
#include "GameFramework/GameModeBase.h"
PyObject *py_ue_get_player_controller(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
int controller_id = 0;
if (!PyArg_ParseTuple(args, "|i:get_player_controller", &controller_id))
{
return NULL;
}
UWorld *world = ue_get_uworld(self);
if (!world)
return PyErr_Format(PyExc_Exception, "unable to retrieve UWorld from uobject");
APlayerController *controller = UGameplayStatics::GetPlayerController(world, controller_id);
if (!controller)
return PyErr_Format(PyExc_Exception, "unable to retrieve controller %d", controller_id);
Py_RETURN_UOBJECT(controller);
}
PyObject *py_ue_get_player_camera_manager(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
int controller_id = 0;
if (!PyArg_ParseTuple(args, "|i:get_player_camera_manager", &controller_id))
{
return NULL;
}
UWorld *world = ue_get_uworld(self);
if (!world)
return PyErr_Format(PyExc_Exception, "unable to retrieve UWorld from uobject");
APlayerCameraManager *camera = UGameplayStatics::GetPlayerCameraManager(world, controller_id);
if (!camera)
return PyErr_Format(PyExc_Exception, "unable to retrieve camera manager for controller %d", controller_id);
Py_RETURN_UOBJECT(camera);
}
PyObject *py_ue_get_player_hud(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
int controller_id = 0;
if (!PyArg_ParseTuple(args, "|i:get_player_hud", &controller_id))
{
return NULL;
}
UWorld *world = ue_get_uworld(self);
if (!world)
return PyErr_Format(PyExc_Exception, "unable to retrieve UWorld from uobject");
APlayerController *controller = UGameplayStatics::GetPlayerController(world, controller_id);
if (!controller)
return PyErr_Format(PyExc_Exception, "unable to retrieve controller %d", controller_id);
Py_RETURN_UOBJECT(controller->GetHUD());
}
PyObject *py_ue_set_player_hud(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
PyObject *py_hud;
int controller_id = 0;
if (!PyArg_ParseTuple(args, "O|i:set_player_hud", &py_hud, &controller_id))
{
return NULL;
}
UWorld *world = ue_get_uworld(self);
if (!world)
return PyErr_Format(PyExc_Exception, "unable to retrieve UWorld from uobject");
AHUD *hud = ue_py_check_type<AHUD>(py_hud);
if (!hud)
return PyErr_Format(PyExc_Exception, "argument is not a AHUD");
APlayerController *controller = UGameplayStatics::GetPlayerController(world, controller_id);
if (!controller)
return PyErr_Format(PyExc_Exception, "unable to retrieve controller %d", controller_id);
controller->MyHUD = hud;
Py_RETURN_NONE;
}
PyObject *py_ue_get_player_pawn(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
int controller_id = 0;
if (!PyArg_ParseTuple(args, "|i:get_player_pawn", &controller_id))
{
return NULL;
}
UWorld *world = ue_get_uworld(self);
if (!world)
return PyErr_Format(PyExc_Exception, "unable to retrieve UWorld from uobject");
APlayerController *controller = UGameplayStatics::GetPlayerController(world, controller_id);
if (!controller)
return PyErr_Format(PyExc_Exception, "unable to retrieve controller %d", controller_id);
// the controller could not have a pawn
if (!controller->GetPawn())
Py_RETURN_NONE;
Py_RETURN_UOBJECT(controller->GetPawn());
}
PyObject *py_ue_create_player(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
int controller_id;
PyObject *spawn_pawn;
if (!PyArg_ParseTuple(args, "i|O:create_player", &controller_id, &spawn_pawn))
{
return NULL;
}
bool b_spawn_pawn = true;
if (spawn_pawn && !PyObject_IsTrue(spawn_pawn))
{
b_spawn_pawn = false;
}
UWorld *world = ue_get_uworld(self);
if (!world)
return PyErr_Format(PyExc_Exception, "unable to retrieve UWorld from uobject");
APlayerController *controller = UGameplayStatics::CreatePlayer(world, controller_id, b_spawn_pawn);
if (!controller)
return PyErr_Format(PyExc_Exception, "unable to create a new player from controller %d", controller_id);
return PyLong_FromLong(controller->PlayerState->PlayerId);
}
PyObject *py_ue_get_num_players(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
UWorld *world = ue_get_uworld(self);
if (!world)
return PyErr_Format(PyExc_Exception, "unable to retrieve UWorld from uobject");
#if ENGINE_MINOR_VERSION < 14
AGameMode *game_mode = world->GetAuthGameMode();
#else
AGameModeBase *game_mode = world->GetAuthGameMode();
#endif
if (!game_mode)
return PyErr_Format(PyExc_Exception, "unable to retrieve GameMode from world");
#if ENGINE_MINOR_VERSION < 14
return PyLong_FromLong(game_mode->NumPlayers);
#else
return PyLong_FromLong(game_mode->GetNumPlayers());
#endif
}
PyObject *py_ue_get_num_spectators(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
UWorld *world = ue_get_uworld(self);
if (!world)
return PyErr_Format(PyExc_Exception, "unable to retrieve UWorld from uobject");
#if ENGINE_MINOR_VERSION < 14
AGameMode *game_mode = world->GetAuthGameMode();
#else
AGameModeBase *game_mode = world->GetAuthGameMode();
#endif
if (!game_mode)
return PyErr_Format(PyExc_Exception, "unable to retrieve GameMode from world");
#if ENGINE_MINOR_VERSION < 14
return PyLong_FromLong(game_mode->NumSpectators);
#else
return PyLong_FromLong(game_mode->GetNumSpectators());
#endif
}
PyObject *py_ue_restart_level(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
int controller_id = 0;
if (!PyArg_ParseTuple(args, "|i:restart_level", &controller_id))
{
return NULL;
}
UWorld *world = ue_get_uworld(self);
if (!world)
return PyErr_Format(PyExc_Exception, "unable to retrieve UWorld from uobject");
APlayerController *controller = UGameplayStatics::GetPlayerController(world, controller_id);
if (!controller)
return PyErr_Format(PyExc_Exception, "unable to retrieve controller %d", controller_id);
controller->RestartLevel();
Py_RETURN_NONE;
}
```
|
/content/code_sandbox/Source/UnrealEnginePython/Private/UObject/UEPyPlayer.cpp
|
c++
| 2016-08-07T05:00:51
| 2024-08-14T06:32:20
|
UnrealEnginePython
|
20tab/UnrealEnginePython
| 2,715
| 1,546
|
```c++
#include "UEPyViewport.h"
#if WITH_EDITOR
#include "LevelEditor.h"
#include "Editor/LevelEditor/Public/ILevelViewport.h"
#include "Editor/UnrealEd/Public/LevelEditorViewport.h"
#endif
#include "Slate/UEPySWidget.h"
#include "Slate/UEPySWindow.h"
// required for GEngine access
#include "Engine/Engine.h"
PyObject *py_ue_game_viewport_client_get_window(ue_PyUObject *self, PyObject *args)
{
ue_py_check(self);
UGameViewportClient *viewport = ue_py_check_type<UGameViewportClient>(self);
if (!viewport)
return PyErr_Format(PyExc_Exception, "uobject is not a GameViewportClient");
TSharedPtr<SWindow> Window = viewport->GetWindow();
if (!Window.IsValid())
return PyErr_Format(PyExc_Exception, "GameViewportClient has no window");
return (PyObject *)py_ue_new_swindow(Window.ToSharedRef());
}
PyObject *py_unreal_engine_get_game_viewport_client(PyObject * self, PyObject * args)
{
UGameViewportClient *viewport_client = GEngine->GameViewport;
if (!viewport_client)
{
return PyErr_Format(PyExc_Exception, "no engine GameViewport found");
}
Py_RETURN_UOBJECT(GEngine->GameViewport);
}
#if WITH_EDITOR
PyObject *py_unreal_engine_get_editor_pie_game_viewport_client(PyObject * self, PyObject * args)
{
UGameViewportClient *viewport_client = GEditor->GameViewport;
if (!viewport_client)
{
return PyErr_Format(PyExc_Exception, "no editor GameViewport found");
}
Py_RETURN_UOBJECT(viewport_client);
}
PyObject *py_unreal_engine_editor_set_view_mode(PyObject * self, PyObject * args)
{
int mode;
if (!PyArg_ParseTuple(args, "i:editor_set_view_mode", &mode))
{
return NULL;
}
FLevelEditorModule &EditorModule = FModuleManager::LoadModuleChecked<FLevelEditorModule>("LevelEditor");
if (!EditorModule.GetFirstActiveViewport().IsValid())
return PyErr_Format(PyExc_Exception, "no active LevelEditor Viewport");
FLevelEditorViewportClient &viewport_client = EditorModule.GetFirstActiveViewport()->GetLevelViewportClient();
viewport_client.SetViewMode((EViewModeIndex)mode);
Py_RETURN_NONE;
}
PyObject *py_unreal_engine_editor_set_camera_speed(PyObject * self, PyObject * args)
{
int speed;
if (!PyArg_ParseTuple(args, "f:editor_set_camera_speed", &speed))
{
return NULL;
}
FLevelEditorModule &EditorModule = FModuleManager::LoadModuleChecked<FLevelEditorModule>("LevelEditor");
if (!EditorModule.GetFirstActiveViewport().IsValid())
return PyErr_Format(PyExc_Exception, "no active LevelEditor Viewport");
FLevelEditorViewportClient &viewport_client = EditorModule.GetFirstActiveViewport()->GetLevelViewportClient();
viewport_client.SetCameraSpeedSetting(speed);
Py_RETURN_NONE;
}
PyObject *py_unreal_engine_editor_set_view_location(PyObject * self, PyObject * args)
{
PyObject *py_vector;
if (!PyArg_ParseTuple(args, "O:editor_set_view_location", &py_vector))
{
return NULL;
}
ue_PyFVector *vector = py_ue_is_fvector(py_vector);
if (!vector)
return PyErr_Format(PyExc_Exception, "argument is not a FVector");
FLevelEditorModule &EditorModule = FModuleManager::LoadModuleChecked<FLevelEditorModule>("LevelEditor");
if (!EditorModule.GetFirstActiveViewport().IsValid())
return PyErr_Format(PyExc_Exception, "no active LevelEditor Viewport");
FLevelEditorViewportClient &viewport_client = EditorModule.GetFirstActiveViewport()->GetLevelViewportClient();
viewport_client.SetViewLocation(vector->vec);
Py_RETURN_NONE;
}
PyObject *py_unreal_engine_editor_set_view_rotation(PyObject * self, PyObject * args)
{
PyObject *py_rotator;
if (!PyArg_ParseTuple(args, "O:editor_set_view_rotation", &py_rotator))
{
return NULL;
}
ue_PyFRotator *rotator = py_ue_is_frotator(py_rotator);
if (!rotator)
return PyErr_Format(PyExc_Exception, "argument is not a FRotator");
FLevelEditorModule &EditorModule = FModuleManager::LoadModuleChecked<FLevelEditorModule>("LevelEditor");
if (!EditorModule.GetFirstActiveViewport().IsValid())
return PyErr_Format(PyExc_Exception, "no active LevelEditor Viewport");
FLevelEditorViewportClient &viewport_client = EditorModule.GetFirstActiveViewport()->GetLevelViewportClient();
viewport_client.SetViewRotation(rotator->rot);
Py_RETURN_NONE;
}
#endif
PyObject *py_ue_add_viewport_widget_content(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
PyObject *py_widget;
int z_order = 0;
if (!PyArg_ParseTuple(args, "O|i:add_viewport_widget_content", &py_widget, &z_order))
{
return NULL;
}
UGameViewportClient *viewport = ue_py_check_type<UGameViewportClient>(self);
if (!viewport)
{
UWorld *world = ue_py_check_type<UWorld>(self);
if (!world)
return PyErr_Format(PyExc_Exception, "object is not a GameViewportClient or a UWorld");
viewport = world->GetGameViewport();
if (!viewport)
return PyErr_Format(PyExc_Exception, "cannot retrieve GameViewportClient from UWorld");
}
TSharedPtr<SWidget> content = py_ue_is_swidget<SWidget>(py_widget);
if (!content.IsValid())
{
return nullptr;
}
viewport->AddViewportWidgetContent(content.ToSharedRef());
Py_RETURN_NONE;
}
PyObject *py_ue_remove_viewport_widget_content(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
PyObject *py_widget;
if (!PyArg_ParseTuple(args, "O:remove_viewport_widget_content", &py_widget))
{
return NULL;
}
UGameViewportClient *viewport = ue_py_check_type<UGameViewportClient>(self);
if (!viewport)
return PyErr_Format(PyExc_Exception, "object is not a GameViewportClient");
TSharedPtr<SWidget> content = py_ue_is_swidget<SWidget>(py_widget);
if (!content.IsValid())
{
return nullptr;
}
viewport->RemoveViewportWidgetContent(content.ToSharedRef());
Py_RETURN_NONE;
}
PyObject *py_ue_remove_all_viewport_widgets(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
UGameViewportClient *viewport = ue_py_check_type<UGameViewportClient>(self);
if (!viewport)
return PyErr_Format(PyExc_Exception, "object is not a GameViewportClient");
viewport->RemoveAllViewportWidgets();
Py_RETURN_NONE;
}
PyObject *py_ue_game_viewport_client_set_rendering_flag(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
PyObject *py_bool;
if (!PyArg_ParseTuple(args, "O:game_viewport_client_set_rendering_flag", &py_bool))
{
return nullptr;
}
bool bEnabled = PyObject_IsTrue(py_bool) ? true : false;
UGameViewportClient *ViewportClient = ue_py_check_type<UGameViewportClient>(self);
if (!ViewportClient)
{
return PyErr_Format(PyExc_Exception, "object is not a UGameViewportClient");
}
ViewportClient->EngineShowFlags.Rendering = bEnabled;
Py_RETURN_NONE;
}
```
|
/content/code_sandbox/Source/UnrealEnginePython/Private/UObject/UEPyViewport.cpp
|
c++
| 2016-08-07T05:00:51
| 2024-08-14T06:32:20
|
UnrealEnginePython
|
20tab/UnrealEnginePython
| 2,715
| 1,595
|
```objective-c
#pragma once
#include "UEPyModule.h"
PyObject *py_ue_get_spline_length(ue_PyUObject *, PyObject *);
PyObject *py_ue_get_world_location_at_distance_along_spline(ue_PyUObject *, PyObject *);
```
|
/content/code_sandbox/Source/UnrealEnginePython/Private/UObject/UEPySpline.h
|
objective-c
| 2016-08-07T05:00:51
| 2024-08-14T06:32:20
|
UnrealEnginePython
|
20tab/UnrealEnginePython
| 2,715
| 51
|
```objective-c
#pragma once
#include "UEPyModule.h"
PyObject *py_ue_quit_game(ue_PyUObject *, PyObject *);
PyObject *py_ue_play(ue_PyUObject *, PyObject *);
PyObject *py_ue_world_exec(ue_PyUObject *, PyObject *);
// mainly used for unit testing
PyObject *py_ue_world_tick(ue_PyUObject *, PyObject *);
PyObject *py_ue_all_objects(ue_PyUObject *, PyObject *);
PyObject *py_ue_all_actors(ue_PyUObject *, PyObject *);
PyObject *py_ue_find_object(ue_PyUObject *, PyObject *);
PyObject *py_ue_get_world(ue_PyUObject *, PyObject *);
PyObject *py_ue_has_world(ue_PyUObject *, PyObject *);
PyObject *py_ue_set_view_target(ue_PyUObject *, PyObject *);
PyObject *py_ue_get_world_delta_seconds(ue_PyUObject *, PyObject *);
PyObject *py_ue_get_levels(ue_PyUObject *, PyObject *);
PyObject *py_ue_get_game_viewport(ue_PyUObject *, PyObject *);
PyObject *py_ue_get_current_level(ue_PyUObject *, PyObject *);
PyObject *py_ue_set_current_level(ue_PyUObject *, PyObject *);
PyObject *py_ue_get_world_type(ue_PyUObject *, PyObject *);
#if WITH_EDITOR
PyObject *py_ue_world_create_folder(ue_PyUObject *, PyObject *);
PyObject *py_ue_world_delete_folder(ue_PyUObject *, PyObject *);
PyObject *py_ue_world_rename_folder(ue_PyUObject *, PyObject *);
PyObject *py_ue_world_folders(ue_PyUObject *, PyObject *);
PyObject *py_ue_get_level_script_blueprint(ue_PyUObject *, PyObject *);
#endif
```
|
/content/code_sandbox/Source/UnrealEnginePython/Private/UObject/UEPyWorld.h
|
objective-c
| 2016-08-07T05:00:51
| 2024-08-14T06:32:20
|
UnrealEnginePython
|
20tab/UnrealEnginePython
| 2,715
| 353
|
```objective-c
#pragma once
#include "UEPyModule.h"
PyObject *py_ue_struct_add_variable(ue_PyUObject *, PyObject *);
PyObject *py_ue_struct_get_variables(ue_PyUObject *, PyObject *);
PyObject *py_ue_struct_remove_variable(ue_PyUObject *, PyObject *);
PyObject *py_ue_struct_move_variable_up(ue_PyUObject *, PyObject *);
PyObject *py_ue_struct_move_variable_down(ue_PyUObject *, PyObject *);
```
|
/content/code_sandbox/Source/UnrealEnginePython/Private/UObject/UEPyUserDefinedStruct.h
|
objective-c
| 2016-08-07T05:00:51
| 2024-08-14T06:32:20
|
UnrealEnginePython
|
20tab/UnrealEnginePython
| 2,715
| 94
|
```objective-c
#pragma once
#include "UEPyModule.h"
PyObject *py_ue_queue_audio(ue_PyUObject *self, PyObject * args);
PyObject *py_ue_play_sound_at_location(ue_PyUObject *, PyObject *);
PyObject *py_ue_sound_get_data(ue_PyUObject *self, PyObject * args);
PyObject *py_ue_sound_set_data(ue_PyUObject *self, PyObject * args);
PyObject *py_ue_get_available_audio_byte_count(ue_PyUObject *, PyObject *);
PyObject *py_ue_reset_audio(ue_PyUObject *, PyObject *);
```
|
/content/code_sandbox/Source/UnrealEnginePython/Private/UObject/UEPyAudio.h
|
objective-c
| 2016-08-07T05:00:51
| 2024-08-14T06:32:20
|
UnrealEnginePython
|
20tab/UnrealEnginePython
| 2,715
| 121
|
```c++
#include "UEPyMaterial.h"
#if WITH_EDITOR
#include "Editor/UnrealEd/Classes/MaterialGraph/MaterialGraph.h"
#include "Editor/UnrealEd/Public/Kismet2/BlueprintEditorUtils.h"
#include "Editor/UnrealEd/Classes/MaterialGraph/MaterialGraphSchema.h"
#endif
#include "Materials/MaterialInstanceConstant.h"
#include "Materials/MaterialInstanceDynamic.h"
#include "Wrappers/UEPyFLinearColor.h"
#include "Wrappers/UEPyFVector.h"
#include "Engine/Texture.h"
#include "Components/PrimitiveComponent.h"
#include "Engine/StaticMesh.h"
PyObject *py_ue_set_material_by_name(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
char *slot_name;
PyObject *py_mat;
if (!PyArg_ParseTuple(args, "sO:set_material_by_name", &slot_name, &py_mat))
{
return nullptr;
}
UPrimitiveComponent *primitive = ue_py_check_type<UPrimitiveComponent>(self);
if (!primitive)
return PyErr_Format(PyExc_Exception, "uobject is not a UPrimitiveComponent");
UMaterialInterface *material = ue_py_check_type<UMaterialInterface>(py_mat);
if (!material)
return PyErr_Format(PyExc_Exception, "argument is not a UMaterialInterface");
primitive->SetMaterialByName(FName(UTF8_TO_TCHAR(slot_name)), material);
Py_RETURN_NONE;
}
PyObject *py_ue_set_material(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
int slot;
PyObject *py_mat;
if (!PyArg_ParseTuple(args, "iO:set_material", &slot, &py_mat))
{
return nullptr;
}
UMaterialInterface *material = ue_py_check_type<UMaterialInterface>(py_mat);
if (!material)
return PyErr_Format(PyExc_Exception, "argument is not a UMaterialInterface");
#if ENGINE_MINOR_VERSION >= 20
#if WITH_EDITOR
UStaticMesh *mesh = ue_py_check_type<UStaticMesh>(self);
if (mesh)
{
mesh->SetMaterial(slot, material);
Py_RETURN_NONE;
}
#endif
#endif
UPrimitiveComponent *primitive = ue_py_check_type<UPrimitiveComponent>(self);
if (!primitive)
return PyErr_Format(PyExc_Exception, "uobject is not a UPrimitiveComponent");
primitive->SetMaterial(slot, material);
Py_RETURN_NONE;
}
PyObject *py_ue_set_material_scalar_parameter(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
char *scalarName = nullptr;
float scalarValue = 0;
if (!PyArg_ParseTuple(args, "sf:set_material_scalar_parameter", &scalarName, &scalarValue))
{
return NULL;
}
FName parameterName(UTF8_TO_TCHAR(scalarName));
bool valid = false;
#if WITH_EDITOR
if (self->ue_object->IsA<UMaterialInstanceConstant>())
{
UMaterialInstanceConstant *material_instance = (UMaterialInstanceConstant *)self->ue_object;
material_instance->SetScalarParameterValueEditorOnly(parameterName, scalarValue);
valid = true;
}
#endif
if (self->ue_object->IsA<UMaterialInstanceDynamic>())
{
UMaterialInstanceDynamic *material_instance = (UMaterialInstanceDynamic *)self->ue_object;
material_instance->SetScalarParameterValue(parameterName, scalarValue);
valid = true;
}
if (!valid)
{
return PyErr_Format(PyExc_Exception, "uobject is not a MaterialInstance");
}
Py_RETURN_NONE;
}
PyObject *py_ue_set_material_static_switch_parameter(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
char *switchName = nullptr;
PyObject *py_bool = nullptr;
if (!PyArg_ParseTuple(args, "sO:set_material_static_switch_parameter", &switchName, &py_bool))
{
return NULL;
}
FName parameterName(UTF8_TO_TCHAR(switchName));
bool switchValue = false;
if (PyObject_IsTrue(py_bool))
{
switchValue = true;
}
bool valid = false;
#if WITH_EDITOR
if (self->ue_object->IsA<UMaterialInstance>())
{
UMaterialInstance *material_instance = (UMaterialInstance *)self->ue_object;
valid = true;
FStaticParameterSet staticParameterSet = material_instance->GetStaticParameters();
bool isExisting = false;
for (auto& parameter : staticParameterSet.StaticSwitchParameters)
{
#if ENGINE_MINOR_VERSION < 19
if (parameter.bOverride && parameter.ParameterName == parameterName)
#else
if (parameter.bOverride && parameter.ParameterInfo.Name == parameterName)
#endif
{
parameter.Value = switchValue;
isExisting = true;
break;
}
}
if (!isExisting)
{
FStaticSwitchParameter SwitchParameter;
#if ENGINE_MINOR_VERSION < 19
SwitchParameter.ParameterName = parameterName;
#else
SwitchParameter.ParameterInfo.Name = parameterName;
#endif
SwitchParameter.Value = switchValue;
SwitchParameter.bOverride = true;
staticParameterSet.StaticSwitchParameters.Add(SwitchParameter);
}
material_instance->UpdateStaticPermutation(staticParameterSet);
}
#endif
if (!valid)
{
return PyErr_Format(PyExc_Exception, "uobject is not a MaterialInstance");
}
Py_RETURN_NONE;
}
PyObject *py_ue_get_material_scalar_parameter(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
char *scalarName = nullptr;
if (!PyArg_ParseTuple(args, "s:get_material_scalar_parameter", &scalarName))
{
return NULL;
}
if (!self->ue_object->IsA<UMaterialInstance>())
{
return PyErr_Format(PyExc_Exception, "uobject is not a UMaterialInstance");
}
FName parameterName(UTF8_TO_TCHAR(scalarName));
UMaterialInstance *material_instance = (UMaterialInstance *)self->ue_object;
float value = 0;
material_instance->GetScalarParameterValue(parameterName, value);
return PyFloat_FromDouble(value);
}
PyObject *py_ue_get_material_static_switch_parameter(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
char *switchName = nullptr;
if (!PyArg_ParseTuple(args, "s:get_material_static_switch_parameter", &switchName))
{
return NULL;
}
if (!self->ue_object->IsA<UMaterialInstance>())
{
return PyErr_Format(PyExc_Exception, "uobject is not a UMaterialInstance");
}
FName parameterName(UTF8_TO_TCHAR(switchName));
UMaterialInstance *material_instance = (UMaterialInstance *)self->ue_object;
bool value = false;
FGuid guid;
material_instance->GetStaticSwitchParameterValue(parameterName, value, guid);
if (value)
{
Py_RETURN_TRUE;
}
Py_RETURN_FALSE;
}
PyObject *py_ue_set_material_vector_parameter(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
char *vectorName;
PyObject *vectorValue = nullptr;
if (!PyArg_ParseTuple(args, "sO:set_material_vector_parameter", &vectorName, &vectorValue))
{
return NULL;
}
FLinearColor vectorParameter(0, 0, 0, 0);
ue_PyFLinearColor *py_vector = py_ue_is_flinearcolor(vectorValue);
if (!py_vector)
{
ue_PyFVector *py_true_vector = py_ue_is_fvector(vectorValue);
if (!py_true_vector)
{
return PyErr_Format(PyExc_Exception, "argument must be an FLinearColor or FVector");
}
else
{
vectorParameter.R = py_true_vector->vec.X;
vectorParameter.G = py_true_vector->vec.Y;
vectorParameter.B = py_true_vector->vec.Z;
vectorParameter.A = 1;
}
}
else
{
vectorParameter = py_vector->color;
}
FName parameterName(UTF8_TO_TCHAR(vectorName));
bool valid = false;
#if WITH_EDITOR
if (self->ue_object->IsA<UMaterialInstanceConstant>())
{
UMaterialInstanceConstant *material_instance = (UMaterialInstanceConstant *)self->ue_object;
material_instance->SetVectorParameterValueEditorOnly(parameterName, vectorParameter);
valid = true;
}
#endif
if (self->ue_object->IsA<UMaterialInstanceDynamic>())
{
UMaterialInstanceDynamic *material_instance = (UMaterialInstanceDynamic *)self->ue_object;
material_instance->SetVectorParameterValue(parameterName, vectorParameter);
valid = true;
}
if (!valid)
{
return PyErr_Format(PyExc_Exception, "uobject is not a MaterialInstance");
}
Py_RETURN_NONE;
}
PyObject *py_ue_get_material_vector_parameter(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
char *scalarName = nullptr;
if (!PyArg_ParseTuple(args, "s:get_material_vector_parameter", &scalarName))
{
return NULL;
}
if (!self->ue_object->IsA<UMaterialInstance>())
{
return PyErr_Format(PyExc_Exception, "uobject is not a UMaterialInstance");
}
FName parameterName(UTF8_TO_TCHAR(scalarName));
UMaterialInstance *material_instance = (UMaterialInstance *)self->ue_object;
FLinearColor vec(0, 0, 0);
material_instance->GetVectorParameterValue(parameterName, vec);
return py_ue_new_flinearcolor(vec);
}
PyObject *py_ue_set_material_texture_parameter(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
char *textureName;
PyObject *textureObject = nullptr;
if (!PyArg_ParseTuple(args, "sO:set_texture_parameter", &textureName, &textureObject))
{
return nullptr;
}
UTexture *ue_texture = ue_py_check_type<UTexture>(textureObject);
if (!ue_texture)
return PyErr_Format(PyExc_Exception, "uobject is not a UTexture");
FName parameterName(UTF8_TO_TCHAR(textureName));
bool valid = false;
#if WITH_EDITOR
if (self->ue_object->IsA<UMaterialInstanceConstant>())
{
UMaterialInstanceConstant *material_instance = (UMaterialInstanceConstant *)self->ue_object;
material_instance->SetTextureParameterValueEditorOnly(parameterName, ue_texture);
valid = true;
}
#endif
if (self->ue_object->IsA<UMaterialInstanceDynamic>())
{
UMaterialInstanceDynamic *material_instance = (UMaterialInstanceDynamic *)self->ue_object;
material_instance->SetTextureParameterValue(parameterName, ue_texture);
valid = true;
}
if (!valid)
{
return PyErr_Format(PyExc_Exception, "uobject is not a MaterialInstance");
}
Py_RETURN_NONE;
}
PyObject *py_ue_get_material_texture_parameter(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
char *scalarName = nullptr;
if (!PyArg_ParseTuple(args, "s:get_material_texture_parameter", &scalarName))
{
return NULL;
}
if (!self->ue_object->IsA<UMaterialInstance>())
{
return PyErr_Format(PyExc_Exception, "uobject is not a UMaterialInstance");
}
FName parameterName(UTF8_TO_TCHAR(scalarName));
UMaterialInstance *material_instance = (UMaterialInstance *)self->ue_object;
UTexture *texture = nullptr;
if (!material_instance->GetTextureParameterValue(parameterName, texture))
{
Py_RETURN_NONE;
}
Py_RETURN_UOBJECT(texture);
}
PyObject *py_ue_create_material_instance_dynamic(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
PyObject *py_material = nullptr;
if (!PyArg_ParseTuple(args, "O:create_material_instance_dynamic", &py_material))
{
return nullptr;
}
UMaterialInterface *material_interface = ue_py_check_type<UMaterialInterface>(py_material);
if (!material_interface)
return PyErr_Format(PyExc_Exception, "argument is not a UMaterialInterface");
UMaterialInstanceDynamic *material_dynamic = UMaterialInstanceDynamic::Create(material_interface, self->ue_object);
Py_RETURN_UOBJECT(material_dynamic);
}
#if WITH_EDITOR
PyObject *py_ue_set_material_parent(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
PyObject *py_material = nullptr;
if (!PyArg_ParseTuple(args, "O:set_parent", &py_material))
{
return NULL;
}
if (!self->ue_object->IsA<UMaterialInstanceConstant>())
{
return PyErr_Format(PyExc_Exception, "uobject is not a UMaterialInstanceConstant");
}
if (!ue_is_pyuobject(py_material))
{
return PyErr_Format(PyExc_Exception, "argument is not a UObject");
}
ue_PyUObject *py_obj = (ue_PyUObject *)py_material;
if (!py_obj->ue_object->IsA<UMaterialInterface>())
return PyErr_Format(PyExc_Exception, "uobject is not a UMaterialInterface");
UMaterialInterface *materialInterface = (UMaterialInterface *)py_obj->ue_object;
UMaterialInstanceConstant *material_instance = (UMaterialInstanceConstant *)self->ue_object;
material_instance->SetParentEditorOnly(materialInterface);
material_instance->PostEditChange();
Py_RETURN_NONE;
}
PyObject *py_ue_static_mesh_set_collision_for_lod(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
int lod_index;
int material_index;
PyObject *py_bool;
if (!PyArg_ParseTuple(args, "iiO:static_mesh_set_collision_for_lod", &lod_index, &material_index, &py_bool))
{
return NULL;
}
if (!self->ue_object->IsA<UStaticMesh>())
{
return PyErr_Format(PyExc_Exception, "uobject is not a StaticMesh");
}
UStaticMesh *mesh = (UStaticMesh *)self->ue_object;
bool enabled = false;
if (PyObject_IsTrue(py_bool))
{
enabled = true;
}
#if ENGINE_MINOR_VERSION >= 23
FMeshSectionInfo info = mesh->GetSectionInfoMap().Get(lod_index, material_index);
#else
FMeshSectionInfo info = mesh->SectionInfoMap.Get(lod_index, material_index);
#endif
info.bEnableCollision = enabled;
mesh->SectionInfoMap.Set(lod_index, material_index, info);
mesh->MarkPackageDirty();
Py_INCREF(Py_None);
return Py_None;
}
PyObject *py_ue_static_mesh_set_shadow_for_lod(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
int lod_index;
int material_index;
PyObject *py_bool;
if (!PyArg_ParseTuple(args, "iiO:static_mesh_set_shadow_for_lod", &lod_index, &material_index, &py_bool))
{
return NULL;
}
if (!self->ue_object->IsA<UStaticMesh>())
{
return PyErr_Format(PyExc_Exception, "uobject is not a StaticMesh");
}
UStaticMesh *mesh = (UStaticMesh *)self->ue_object;
bool enabled = false;
if (PyObject_IsTrue(py_bool))
{
enabled = true;
}
FMeshSectionInfo info = mesh->SectionInfoMap.Get(lod_index, material_index);
info.bCastShadow = enabled;
mesh->SectionInfoMap.Set(lod_index, material_index, info);
mesh->MarkPackageDirty();
Py_RETURN_NONE;
}
PyObject *py_ue_get_material_graph(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
UMaterial *material = ue_py_check_type<UMaterial>(self);
if (!material)
return PyErr_Format(PyExc_Exception, "uobject is not a UMaterialInterface");
UMaterialGraph *graph = material->MaterialGraph;
if (!graph)
{
graph = (UMaterialGraph *)FBlueprintEditorUtils::CreateNewGraph(material, NAME_None, UMaterialGraph::StaticClass(), UMaterialGraphSchema::StaticClass());
material->MaterialGraph = graph;
}
if (!graph)
return PyErr_Format(PyExc_Exception, "Unable to retrieve/allocate MaterialGraph");
Py_RETURN_UOBJECT(graph);
}
#endif
```
|
/content/code_sandbox/Source/UnrealEnginePython/Private/UObject/UEPyMaterial.cpp
|
c++
| 2016-08-07T05:00:51
| 2024-08-14T06:32:20
|
UnrealEnginePython
|
20tab/UnrealEnginePython
| 2,715
| 3,529
|
```objective-c
#pragma once
#include "UEPyModule.h"
PyObject *py_ue_static_mesh_get_bounds(ue_PyUObject *self, PyObject * args);
#if WITH_EDITOR
PyObject *py_ue_static_mesh_build(ue_PyUObject *, PyObject *);
PyObject *py_ue_static_mesh_create_body_setup(ue_PyUObject *, PyObject *);
PyObject *py_ue_static_mesh_get_raw_mesh(ue_PyUObject *, PyObject *);
PyObject *py_ue_static_mesh_generate_kdop10x(ue_PyUObject *, PyObject *);
PyObject *py_ue_static_mesh_generate_kdop10y(ue_PyUObject *, PyObject *);
PyObject *py_ue_static_mesh_generate_kdop10z(ue_PyUObject *, PyObject *);
PyObject *py_ue_static_mesh_generate_kdop18(ue_PyUObject *, PyObject *);
PyObject *py_ue_static_mesh_generate_kdop26(ue_PyUObject *, PyObject *);
PyObject *py_ue_static_mesh_import_lod(ue_PyUObject *, PyObject *);
#endif
```
|
/content/code_sandbox/Source/UnrealEnginePython/Private/UObject/UEPyStaticMesh.h
|
objective-c
| 2016-08-07T05:00:51
| 2024-08-14T06:32:20
|
UnrealEnginePython
|
20tab/UnrealEnginePython
| 2,715
| 211
|
```c++
#include "UEPyAnimSequence.h"
PyObject *py_ue_anim_get_skeleton(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
UAnimationAsset *anim = ue_py_check_type<UAnimationAsset>(self);
if (!anim)
return PyErr_Format(PyExc_Exception, "UObject is not a UAnimationAsset.");
USkeleton *skeleton = anim->GetSkeleton();
if (!skeleton)
{
Py_RETURN_NONE;
}
Py_RETURN_UOBJECT((UObject *)skeleton);
}
PyObject *py_ue_anim_get_bone_transform(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
int track_index;
float frame_time;
PyObject *py_b_use_raw_data = nullptr;
if (!PyArg_ParseTuple(args, "if|O:get_bone_transform", &track_index, &frame_time, &py_b_use_raw_data))
{
return nullptr;
}
UAnimSequence *anim = ue_py_check_type<UAnimSequence>(self);
if (!anim)
return PyErr_Format(PyExc_Exception, "UObject is not a UAnimSequence.");
bool bUseRawData = false;
if (py_b_use_raw_data && PyObject_IsTrue(py_b_use_raw_data))
bUseRawData = true;
FTransform OutAtom;
anim->GetBoneTransform(OutAtom, track_index, frame_time, bUseRawData);
return py_ue_new_ftransform(OutAtom);
}
PyObject *py_ue_anim_extract_bone_transform(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
PyObject *py_sources;
float frame_time;
if (!PyArg_ParseTuple(args, "Of:extract_bone_transform", &py_sources, &frame_time))
{
return nullptr;
}
UAnimSequence *anim = ue_py_check_type<UAnimSequence>(self);
if (!anim)
return PyErr_Format(PyExc_Exception, "UObject is not a UAnimSequence.");
ue_PyFRawAnimSequenceTrack *rast = py_ue_is_fraw_anim_sequence_track(py_sources);
if (rast)
{
FTransform OutAtom;
anim->ExtractBoneTransform(rast->raw_anim_sequence_track, OutAtom, frame_time);
return py_ue_new_ftransform(OutAtom);
}
return PyErr_Format(PyExc_Exception, "argument is not an FRawAnimSequenceTrack");
}
PyObject *py_ue_anim_extract_root_motion(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
float start_time;
float delta_time;
PyObject *py_b_allow_looping = nullptr;
if (!PyArg_ParseTuple(args, "ff|O:extract_root_motion", &start_time, &delta_time, &py_b_allow_looping))
{
return nullptr;
}
UAnimSequence *anim = ue_py_check_type<UAnimSequence>(self);
if (!anim)
return PyErr_Format(PyExc_Exception, "UObject is not a UAnimSequence.");
bool bAllowLooping = false;
if (py_b_allow_looping && PyObject_IsTrue(py_b_allow_looping))
bAllowLooping = true;
return py_ue_new_ftransform(anim->ExtractRootMotion(start_time, delta_time, bAllowLooping));
}
#if WITH_EDITOR
#if ENGINE_MINOR_VERSION > 13
#if ENGINE_MINOR_VERSION < 23
PyObject *py_ue_anim_sequence_update_compressed_track_map_from_raw(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
UAnimSequence *anim_seq = ue_py_check_type<UAnimSequence>(self);
if (!anim_seq)
return PyErr_Format(PyExc_Exception, "UObject is not a UAnimSequence.");
anim_seq->UpdateCompressedTrackMapFromRaw();
Py_RETURN_NONE;
}
#endif
PyObject *py_ue_anim_sequence_get_raw_animation_data(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
UAnimSequence *anim_seq = ue_py_check_type<UAnimSequence>(self);
if (!anim_seq)
return PyErr_Format(PyExc_Exception, "UObject is not a UAnimSequence.");
PyObject *py_list = PyList_New(0);
for (FRawAnimSequenceTrack rast : anim_seq->GetRawAnimationData())
{
PyObject *py_item = py_ue_new_fraw_anim_sequence_track(rast);
PyList_Append(py_list, py_item);
Py_DECREF(py_item);
}
return py_list;
}
PyObject *py_ue_anim_sequence_get_raw_animation_track(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
int index;
if (!PyArg_ParseTuple(args, "i:get_raw_animation_track", &index))
return nullptr;
UAnimSequence *anim_seq = ue_py_check_type<UAnimSequence>(self);
if (!anim_seq)
return PyErr_Format(PyExc_Exception, "UObject is not a UAnimSequence.");
if (index < 0 || index >= anim_seq->GetAnimationTrackNames().Num())
return PyErr_Format(PyExc_Exception, "invalid track index %d", index);
return py_ue_new_fraw_anim_sequence_track(anim_seq->GetRawAnimationTrack(index));
}
PyObject *py_ue_anim_add_key_to_sequence(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
float frame_time;
char *track_name;
PyObject *py_transform;
if (!PyArg_ParseTuple(args, "fsO:add_key_to_sequence", &frame_time, &track_name, &py_transform))
return nullptr;
UAnimSequence *anim_seq = ue_py_check_type<UAnimSequence>(self);
if (!anim_seq)
return PyErr_Format(PyExc_Exception, "UObject is not a UAnimSequence.");
ue_PyFTransform *ue_py_transform = py_ue_is_ftransform(py_transform);
if (!ue_py_transform)
return PyErr_Format(PyExc_Exception, "argument is not a FTransform.");
anim_seq->AddKeyToSequence(frame_time, FName(UTF8_TO_TCHAR(track_name)), ue_py_transform->transform);
Py_RETURN_NONE;
}
PyObject *py_ue_anim_sequence_apply_raw_anim_changes(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
UAnimSequence *anim_seq = ue_py_check_type<UAnimSequence>(self);
if (!anim_seq)
return PyErr_Format(PyExc_Exception, "UObject is not a UAnimSequence.");
if (anim_seq->DoesNeedRebake())
{
anim_seq->Modify(true);
anim_seq->BakeTrackCurvesToRawAnimation();
}
if (anim_seq->DoesNeedRecompress())
{
anim_seq->Modify(true);
anim_seq->RequestSyncAnimRecompression(false);
}
Py_RETURN_NONE;
}
PyObject *py_ue_anim_sequence_add_new_raw_track(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
char *name;
PyObject *py_rast = nullptr;
if (!PyArg_ParseTuple(args, "s|O:add_new_raw_track", &name, &py_rast))
return nullptr;
UAnimSequence *anim_seq = ue_py_check_type<UAnimSequence>(self);
if (!anim_seq)
return PyErr_Format(PyExc_Exception, "UObject is not a UAnimSequence.");
FRawAnimSequenceTrack *rast = nullptr;
if (py_rast)
{
ue_PyFRawAnimSequenceTrack *py_f_rast = py_ue_is_fraw_anim_sequence_track(py_rast);
if (py_f_rast)
{
rast = &py_f_rast->raw_anim_sequence_track;
}
else
{
return PyErr_Format(PyExc_Exception, "argument is not a FRawAnimSequenceTrack.");
}
}
anim_seq->Modify();
int32 index = anim_seq->AddNewRawTrack(FName(UTF8_TO_TCHAR(name)), rast);
anim_seq->MarkRawDataAsModified();
anim_seq->MarkPackageDirty();
return PyLong_FromLong(index);
}
PyObject *py_ue_anim_sequence_update_raw_track(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
int track_index;
PyObject *py_rast;
if (!PyArg_ParseTuple(args, "iO:update_raw_track", &track_index, &py_rast))
return nullptr;
UAnimSequence *anim_seq = ue_py_check_type<UAnimSequence>(self);
if (!anim_seq)
return PyErr_Format(PyExc_Exception, "UObject is not a UAnimSequence.");
ue_PyFRawAnimSequenceTrack *py_f_rast = py_ue_is_fraw_anim_sequence_track(py_rast);
if (!py_f_rast)
{
return PyErr_Format(PyExc_Exception, "argument is not a FRawAnimSequenceTrack.");
}
anim_seq->Modify();
FRawAnimSequenceTrack& RawRef = anim_seq->GetRawAnimationTrack(track_index);
RawRef.PosKeys = py_f_rast->raw_anim_sequence_track.PosKeys;
RawRef.RotKeys = py_f_rast->raw_anim_sequence_track.RotKeys;
RawRef.ScaleKeys = py_f_rast->raw_anim_sequence_track.ScaleKeys;
anim_seq->MarkRawDataAsModified();
anim_seq->MarkPackageDirty();
Py_RETURN_NONE;
}
PyObject *py_ue_add_anim_composite_section(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
char *name;
float time;
if (!PyArg_ParseTuple(args, "sf:add_anim_composite_section", &name, &time))
return nullptr;
UAnimMontage *anim = ue_py_check_type<UAnimMontage>(self);
if (!anim)
return PyErr_Format(PyExc_Exception, "UObject is not a UAnimMontage.");
return PyLong_FromLong(anim->AddAnimCompositeSection(FName(UTF8_TO_TCHAR(name)), time));
}
#endif
#endif
PyObject *py_ue_anim_set_skeleton(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
PyObject *py_skeleton;
if (!PyArg_ParseTuple(args, "O:anim_set_skeleton", &py_skeleton))
return nullptr;
UAnimationAsset *anim = ue_py_check_type<UAnimationAsset>(self);
if (!anim)
return PyErr_Format(PyExc_Exception, "UObject is not a UAnimationAsset.");
USkeleton *skeleton = ue_py_check_type<USkeleton>(py_skeleton);
if (!skeleton)
return PyErr_Format(PyExc_Exception, "argument is not a USkeleton.");
anim->SetSkeleton(skeleton);
Py_RETURN_NONE;
}
PyObject *py_ue_get_blend_parameter(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
int index;
if (!PyArg_ParseTuple(args, "i:get_blend_parameter", &index))
return nullptr;
UBlendSpaceBase *blend = ue_py_check_type<UBlendSpaceBase>(self);
if (!blend)
return PyErr_Format(PyExc_Exception, "UObject is not a UBlendSpaceBase.");
if (index < 0 || index > 2)
return PyErr_Format(PyExc_Exception, "invalid Blend Parameter index");
const FBlendParameter & parameter = blend->GetBlendParameter(index);
return py_ue_new_owned_uscriptstruct(FBlendParameter::StaticStruct(), (uint8 *)¶meter);
}
PyObject *py_ue_set_blend_parameter(ue_PyUObject * self, PyObject * args)
{
ue_py_check(self);
int index;
PyObject *py_blend;
if (!PyArg_ParseTuple(args, "iO:get_blend_parameter", &index, &py_blend))
return nullptr;
UBlendSpaceBase *blend = ue_py_check_type<UBlendSpaceBase>(self);
if (!blend)
return PyErr_Format(PyExc_Exception, "UObject is not a UBlendSpaceBase.");
if (index < 0 || index > 2)
return PyErr_Format(PyExc_Exception, "invalid Blend Parameter index");
FBlendParameter *parameter = ue_py_check_struct<FBlendParameter>(py_blend);
if (!parameter)
return PyErr_Format(PyExc_Exception, "argument is not a FBlendParameter");
const FBlendParameter & orig_parameter = blend->GetBlendParameter(index);
FMemory::Memcpy((uint8 *)&orig_parameter, parameter, FBlendParameter::StaticStruct()->GetStructureSize());
Py_RETURN_NONE;
}
```
|
/content/code_sandbox/Source/UnrealEnginePython/Private/UObject/UEPyAnimSequence.cpp
|
c++
| 2016-08-07T05:00:51
| 2024-08-14T06:32:20
|
UnrealEnginePython
|
20tab/UnrealEnginePython
| 2,715
| 2,618
|
```c++
#include "UEPyMovements.h"
#include "Components/ActorComponent.h"
#include "GameFramework/Pawn.h"
#include "GameFramework/PlayerController.h"
#include "GameFramework/Character.h"
#include "Wrappers/UEPyFVector.h"
#include "Wrappers/UEPyFRotator.h"
#include "GameFramework/CharacterMovementComponent.h"
PyObject *py_ue_add_controller_yaw_input(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
float val;
if (!PyArg_ParseTuple(args, "f:add_controller_yaw_input", &val))
{
return NULL;
}
APawn *pawn = nullptr;
if (self->ue_object->IsA<APawn>())
{
pawn = (APawn *)self->ue_object;
}
else if (UActorComponent *component = ue_py_check_type<UActorComponent>(self))
{
AActor *actor = component->GetOwner();
if (actor)
{
if (actor->IsA<APawn>())
{
pawn = (APawn *)actor;
}
}
}
else if (APlayerController *player = ue_py_check_type<APlayerController>(self))
{
player->AddYawInput(val);
Py_RETURN_NONE;
}
if (!pawn)
return PyErr_Format(PyExc_Exception, "uobject is not a Pawn or a PlayerController");
pawn->AddControllerYawInput(val);
Py_RETURN_NONE;
}
PyObject *py_ue_add_controller_pitch_input(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
float val;
if (!PyArg_ParseTuple(args, "f:add_controller_pitch_input", &val))
{
return NULL;
}
APawn *pawn = nullptr;
if (self->ue_object->IsA<APawn>())
{
pawn = (APawn *)self->ue_object;
}
else if (self->ue_object->IsA<UActorComponent>())
{
UActorComponent *component = (UActorComponent *)self->ue_object;
AActor *actor = component->GetOwner();
if (actor)
{
if (actor->IsA<APawn>())
{
pawn = (APawn *)actor;
}
}
}
else if (APlayerController *player = ue_py_check_type<APlayerController>(self))
{
player->AddPitchInput(val);
Py_RETURN_NONE;
}
if (!pawn)
return PyErr_Format(PyExc_Exception, "uobject is not a Pawn or a PlayerController");
pawn->AddControllerPitchInput(val);
Py_RETURN_NONE;
}
PyObject *py_ue_add_controller_roll_input(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
float val;
if (!PyArg_ParseTuple(args, "f:add_controller_roll_input", &val))
{
return NULL;
}
APawn *pawn = nullptr;
if (self->ue_object->IsA<APawn>())
{
pawn = (APawn *)self->ue_object;
}
else if (UActorComponent *component = ue_py_check_type<UActorComponent>(self))
{
AActor *actor = component->GetOwner();
if (actor)
{
if (actor->IsA<APawn>())
{
pawn = (APawn *)actor;
}
}
}
else if (APlayerController *player = ue_py_check_type<APlayerController>(self))
{
player->AddRollInput(val);
Py_RETURN_NONE;
}
if (!pawn)
return PyErr_Format(PyExc_Exception, "uobject is not a Pawn or a PlayerController");
pawn->AddControllerRollInput(val);
Py_RETURN_NONE;
}
PyObject *py_ue_add_movement_input(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
PyObject *py_obj_movement;
float scale = 1;
PyObject *py_force = nullptr;
bool force = false;
if (!PyArg_ParseTuple(args, "O|fO:add_movement_input", &py_obj_movement, &scale, &py_force))
{
return NULL;
}
if (py_force && PyObject_IsTrue(py_force))
{
force = true;
}
APawn *pawn = nullptr;
if (self->ue_object->IsA<APawn>())
{
pawn = (APawn *)self->ue_object;
}
else if (self->ue_object->IsA<UActorComponent>())
{
UActorComponent *component = (UActorComponent *)self->ue_object;
AActor *actor = component->GetOwner();
if (actor)
{
if (actor->IsA<APawn>())
{
pawn = (APawn *)actor;
}
}
}
if (!pawn)
return PyErr_Format(PyExc_Exception, "uobject is not a pawn");
ue_PyFVector *movement = py_ue_is_fvector(py_obj_movement);
if (!movement)
return PyErr_Format(PyExc_Exception, "movement input must be a FVector");
pawn->AddMovementInput(movement->vec, scale, force);
Py_INCREF(Py_None);
return Py_None;
}
PyObject *py_ue_get_control_rotation(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
APawn *pawn = nullptr;
if (self->ue_object->IsA<APawn>())
{
pawn = (APawn *)self->ue_object;
}
else if (self->ue_object->IsA<UActorComponent>())
{
UActorComponent *component = (UActorComponent *)self->ue_object;
AActor *actor = component->GetOwner();
if (actor)
{
if (actor->IsA<APawn>())
{
pawn = (APawn *)actor;
}
}
}
if (!pawn)
return PyErr_Format(PyExc_Exception, "uobject is not a pawn");
FRotator rot = pawn->GetControlRotation();
return py_ue_new_frotator(rot);
}
PyObject *py_ue_jump(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
ACharacter *character = nullptr;
if (self->ue_object->IsA<ACharacter>())
{
character = (ACharacter *)self->ue_object;
}
else if (self->ue_object->IsA<UActorComponent>())
{
UActorComponent *component = (UActorComponent *)self->ue_object;
AActor *actor = component->GetOwner();
if (actor)
{
if (actor->IsA<ACharacter>())
{
character = (ACharacter *)actor;
}
}
}
if (!character)
return PyErr_Format(PyExc_Exception, "uobject is not a character");
character->Jump();
Py_INCREF(Py_None);
return Py_None;
}
PyObject *py_ue_crouch(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
ACharacter *character = nullptr;
if (self->ue_object->IsA<ACharacter>())
{
character = (ACharacter *)self->ue_object;
}
else if (self->ue_object->IsA<UActorComponent>())
{
UActorComponent *component = (UActorComponent *)self->ue_object;
AActor *actor = component->GetOwner();
if (actor)
{
if (actor->IsA<ACharacter>())
{
character = (ACharacter *)actor;
}
}
}
if (!character)
return PyErr_Format(PyExc_Exception, "uobject is not a character");
character->Crouch();
Py_INCREF(Py_None);
return Py_None;
}
PyObject *py_ue_stop_jumping(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
ACharacter *character = nullptr;
if (self->ue_object->IsA<ACharacter>())
{
character = (ACharacter *)self->ue_object;
}
else if (self->ue_object->IsA<UActorComponent>())
{
UActorComponent *component = (UActorComponent *)self->ue_object;
AActor *actor = component->GetOwner();
if (actor)
{
if (actor->IsA<ACharacter>())
{
character = (ACharacter *)actor;
}
}
}
if (!character)
return PyErr_Format(PyExc_Exception, "uobject is not a character");
character->StopJumping();
Py_INCREF(Py_None);
return Py_None;
}
PyObject *py_ue_uncrouch(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
ACharacter *character = nullptr;
if (self->ue_object->IsA<ACharacter>())
{
character = (ACharacter *)self->ue_object;
}
else if (self->ue_object->IsA<UActorComponent>())
{
UActorComponent *component = (UActorComponent *)self->ue_object;
AActor *actor = component->GetOwner();
if (actor)
{
if (actor->IsA<ACharacter>())
{
character = (ACharacter *)actor;
}
}
}
if (!character)
return PyErr_Format(PyExc_Exception, "uobject is not a character");
character->UnCrouch();
Py_INCREF(Py_None);
return Py_None;
}
PyObject *py_ue_launch(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
PyObject *py_obj_force;
PyObject *py_xy_override = nullptr;
PyObject *py_z_override = nullptr;
bool xy_override = false;
bool z_override;
if (!PyArg_ParseTuple(args, "O|OO:launch", &py_obj_force, &py_xy_override, &z_override))
{
return NULL;
}
ACharacter *character = nullptr;
if (self->ue_object->IsA<ACharacter>())
{
character = (ACharacter *)self->ue_object;
}
else if (self->ue_object->IsA<UActorComponent>())
{
UActorComponent *component = (UActorComponent *)self->ue_object;
AActor *actor = component->GetOwner();
if (actor)
{
if (actor->IsA<ACharacter>())
{
character = (ACharacter *)actor;
}
}
}
if (!character)
return PyErr_Format(PyExc_Exception, "uobject is not a character");
if (py_xy_override && PyObject_IsTrue(py_xy_override))
{
xy_override = true;
}
if (py_z_override && PyObject_IsTrue(py_z_override))
{
z_override = true;
}
ue_PyFVector *force = py_ue_is_fvector(py_obj_force);
if (!force)
return PyErr_Format(PyExc_Exception, "launch force must be a FVector");
character->LaunchCharacter(force->vec, xy_override, z_override);
Py_INCREF(Py_None);
return Py_None;
}
PyObject *py_ue_is_jumping(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
ACharacter *character = nullptr;
if (self->ue_object->IsA<ACharacter>())
{
character = (ACharacter *)self->ue_object;
}
else if (self->ue_object->IsA<UActorComponent>())
{
UActorComponent *component = (UActorComponent *)self->ue_object;
AActor *actor = component->GetOwner();
if (actor)
{
if (actor->IsA<ACharacter>())
{
character = (ACharacter *)actor;
}
}
}
if (!character)
return PyErr_Format(PyExc_Exception, "uobject is not a character");
if (character->IsJumpProvidingForce())
{
Py_INCREF(Py_True);
return Py_True;
}
Py_INCREF(Py_False);
return Py_False;
}
PyObject *py_ue_is_crouched(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
ACharacter *character = nullptr;
if (self->ue_object->IsA<ACharacter>())
{
character = (ACharacter *)self->ue_object;
}
else if (self->ue_object->IsA<UActorComponent>())
{
UActorComponent *component = (UActorComponent *)self->ue_object;
AActor *actor = component->GetOwner();
if (actor)
{
if (actor->IsA<ACharacter>())
{
character = (ACharacter *)actor;
}
}
}
if (!character)
return PyErr_Format(PyExc_Exception, "uobject is not a character");
if (character->bIsCrouched)
{
Py_INCREF(Py_True);
return Py_True;
}
Py_INCREF(Py_False);
return Py_False;
}
PyObject *py_ue_is_falling(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
ACharacter *character = nullptr;
if (self->ue_object->IsA<ACharacter>())
{
character = (ACharacter *)self->ue_object;
}
else if (self->ue_object->IsA<UActorComponent>())
{
UActorComponent *component = (UActorComponent *)self->ue_object;
AActor *actor = component->GetOwner();
if (actor)
{
if (actor->IsA<ACharacter>())
{
character = (ACharacter *)actor;
}
}
}
if (!character)
return PyErr_Format(PyExc_Exception, "uobject is not a character");
UMovementComponent *movement = character->GetMovementComponent();
if (movement && movement->IsA<UCharacterMovementComponent>())
{
UCharacterMovementComponent *character_movement = (UCharacterMovementComponent *)movement;
if (character_movement->IsFalling())
{
Py_INCREF(Py_True);
return Py_True;
}
}
Py_INCREF(Py_False);
return Py_False;
}
PyObject *py_ue_is_flying(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
ACharacter *character = nullptr;
if (self->ue_object->IsA<ACharacter>())
{
character = (ACharacter *)self->ue_object;
}
else if (self->ue_object->IsA<UActorComponent>())
{
UActorComponent *component = (UActorComponent *)self->ue_object;
AActor *actor = component->GetOwner();
if (actor)
{
if (actor->IsA<ACharacter>())
{
character = (ACharacter *)actor;
}
}
}
if (!character)
return PyErr_Format(PyExc_Exception, "uobject is not a character");
UMovementComponent *movement = character->GetMovementComponent();
if (movement && movement->IsA<UCharacterMovementComponent>())
{
UCharacterMovementComponent *character_movement = (UCharacterMovementComponent *)movement;
if (character_movement->IsFlying())
{
Py_INCREF(Py_True);
return Py_True;
}
}
Py_INCREF(Py_False);
return Py_False;
}
PyObject *py_ue_can_jump(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
ACharacter *character = nullptr;
if (self->ue_object->IsA<ACharacter>())
{
character = (ACharacter *)self->ue_object;
}
else if (self->ue_object->IsA<UActorComponent>())
{
UActorComponent *component = (UActorComponent *)self->ue_object;
AActor *actor = component->GetOwner();
if (actor)
{
if (actor->IsA<ACharacter>())
{
character = (ACharacter *)actor;
}
}
}
if (!character)
return PyErr_Format(PyExc_Exception, "uobject is not a character");
if (character->CanJump())
{
Py_INCREF(Py_True);
return Py_True;
}
Py_INCREF(Py_False);
return Py_False;
}
PyObject *py_ue_can_crouch(ue_PyUObject *self, PyObject * args)
{
ue_py_check(self);
ACharacter *character = nullptr;
if (self->ue_object->IsA<ACharacter>())
{
character = (ACharacter *)self->ue_object;
}
else if (self->ue_object->IsA<UActorComponent>())
{
UActorComponent *component = (UActorComponent *)self->ue_object;
AActor *actor = component->GetOwner();
if (actor)
{
if (actor->IsA<ACharacter>())
{
character = (ACharacter *)actor;
}
}
}
if (!character)
return PyErr_Format(PyExc_Exception, "uobject is not a character");
if (character->CanCrouch())
{
Py_INCREF(Py_True);
return Py_True;
}
Py_INCREF(Py_False);
return Py_False;
}
```
|
/content/code_sandbox/Source/UnrealEnginePython/Private/UObject/UEPyMovements.cpp
|
c++
| 2016-08-07T05:00:51
| 2024-08-14T06:32:20
|
UnrealEnginePython
|
20tab/UnrealEnginePython
| 2,715
| 3,698
|
```c++
#include "UEPyFbxProperty.h"
#if ENGINE_MINOR_VERSION > 12
#if WITH_EDITOR
#include "UEPyFbx.h"
static PyObject *py_ue_fbx_property_get_name(ue_PyFbxProperty *self, PyObject *args)
{
return PyUnicode_FromString(self->fbx_property.GetName());
}
static PyObject *py_ue_fbx_property_get_double3(ue_PyFbxProperty *self, PyObject *args)
{
FbxDouble3 value = self->fbx_property.Get<FbxDouble3>();
return Py_BuildValue((char *)"(fff)", value[0], value[1], value[2]);
}
static PyObject *py_ue_fbx_property_get_string(ue_PyFbxProperty *self, PyObject *args)
{
return PyUnicode_FromString(self->fbx_property.Get<FbxString>());
}
static PyObject *py_ue_fbx_property_is_valid(ue_PyFbxProperty *self, PyObject *args)
{
if (self->fbx_property.IsValid())
{
Py_RETURN_TRUE;
}
Py_RETURN_FALSE;
}
static PyObject *py_ue_fbx_property_get_curve_node(ue_PyFbxProperty *self, PyObject *args)
{
PyObject *py_object;
if (!PyArg_ParseTuple(args, "O", &py_object))
{
return nullptr;
}
ue_PyFbxObject *py_fbx_object = py_ue_is_fbx_object(py_object);
if (!py_fbx_object)
return PyErr_Format(PyExc_Exception, "argument is not a FbxObject");
FbxAnimLayer *fbx_anim_layer = FbxCast<FbxAnimLayer>(py_fbx_object->fbx_object);
if (!fbx_anim_layer)
return PyErr_Format(PyExc_Exception, "argument is not a FbxAnimLayer");
FbxAnimCurveNode *fbx_anim_curve_node = self->fbx_property.GetCurveNode(fbx_anim_layer);
if (!fbx_anim_curve_node)
Py_RETURN_NONE;
return py_ue_new_fbx_object(fbx_anim_curve_node);
}
static PyObject *py_ue_fbx_property_get_bool(ue_PyFbxProperty *self, PyObject *args)
{
if (self->fbx_property.Get<FbxBool>())
Py_RETURN_TRUE;
Py_RETURN_FALSE;
}
static PyObject *py_ue_fbx_property_get_int(ue_PyFbxProperty *self, PyObject *args)
{
return PyLong_FromLong(self->fbx_property.Get<FbxInt>());
}
static PyMethodDef ue_PyFbxProperty_methods[] = {
{ "get_name", (PyCFunction)py_ue_fbx_property_get_name, METH_VARARGS, "" },
{ "get_double3", (PyCFunction)py_ue_fbx_property_get_double3, METH_VARARGS, "" },
{ "get_string", (PyCFunction)py_ue_fbx_property_get_string, METH_VARARGS, "" },
{ "get_bool", (PyCFunction)py_ue_fbx_property_get_bool, METH_VARARGS, "" },
{ "get_int", (PyCFunction)py_ue_fbx_property_get_int, METH_VARARGS, "" },
{ "is_valid", (PyCFunction)py_ue_fbx_property_is_valid, METH_VARARGS, "" },
{ "get_curve_node", (PyCFunction)py_ue_fbx_property_get_curve_node, METH_VARARGS, "" },
{ NULL } /* Sentinel */
};
static PyTypeObject ue_PyFbxPropertyType = {
PyVarObject_HEAD_INIT(NULL, 0)
"unreal_engine.FbxProperty", /* tp_name */
sizeof(ue_PyFbxProperty), /* tp_basicsize */
0, /* tp_itemsize */
0, /* tp_dealloc */
0, /* tp_print */
0, /* tp_getattr */
0, /* tp_setattr */
0, /* tp_reserved */
0, /* tp_repr */
0, /* tp_as_number */
0, /* tp_as_sequence */
0, /* tp_as_mapping */
0, /* tp_hash */
0, /* tp_call */
0, /* tp_str */
0, /* tp_getattro */
0, /* tp_setattro */
0, /* tp_as_buffer */
Py_TPFLAGS_DEFAULT, /* tp_flags */
"Unreal Engine FbxProperty", /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
0, /* tp_richcompare */
0, /* tp_weaklistoffset */
0, /* tp_iter */
0, /* tp_iternext */
ue_PyFbxProperty_methods, /* tp_methods */
0, /* tp_members */
0, /* tp_getset */
};
static int py_ue_fbx_property_init(ue_PyFbxProperty *self, PyObject * args)
{
PyErr_SetString(PyExc_Exception, "instantiating a new FbxProperty is currently not supported");
return -1;
}
void ue_python_init_fbx_property(PyObject *ue_module)
{
ue_PyFbxPropertyType.tp_new = PyType_GenericNew;;
ue_PyFbxPropertyType.tp_init = (initproc)py_ue_fbx_property_init;
if (PyType_Ready(&ue_PyFbxPropertyType) < 0)
return;
Py_INCREF(&ue_PyFbxPropertyType);
PyModule_AddObject(ue_module, "FbxProperty", (PyObject *)&ue_PyFbxPropertyType);
}
PyObject *py_ue_new_fbx_property(FbxProperty fbx_property)
{
ue_PyFbxProperty *ret = (ue_PyFbxProperty *)PyObject_New(ue_PyFbxProperty, &ue_PyFbxPropertyType);
ret->fbx_property = fbx_property;
return (PyObject *)ret;
}
ue_PyFbxProperty *py_ue_is_fbx_property(PyObject *obj)
{
if (!PyObject_IsInstance(obj, (PyObject *)&ue_PyFbxPropertyType))
return nullptr;
return (ue_PyFbxProperty *)obj;
}
#endif
#endif
```
|
/content/code_sandbox/Source/UnrealEnginePython/Private/Fbx/UEPyFbxProperty.cpp
|
c++
| 2016-08-07T05:00:51
| 2024-08-14T06:32:20
|
UnrealEnginePython
|
20tab/UnrealEnginePython
| 2,715
| 1,304
|
```objective-c
#pragma once
#include "UEPyModule.h"
#if WITH_EDITOR
#if PLATFORM_LINUX
#if defined(__clang__)
#pragma clang diagnostic ignored "-Wnull-dereference"
#endif
#endif
#include <fbxsdk.h>
struct ue_PyFbxManager
{
PyObject_HEAD
/* Type-specific fields go here. */
FbxManager *fbx_manager;
};
void ue_python_init_fbx_manager(PyObject *);
ue_PyFbxManager *py_ue_is_fbx_manager(PyObject *);
#endif
```
|
/content/code_sandbox/Source/UnrealEnginePython/Private/Fbx/UEPyFbxManager.h
|
objective-c
| 2016-08-07T05:00:51
| 2024-08-14T06:32:20
|
UnrealEnginePython
|
20tab/UnrealEnginePython
| 2,715
| 105
|
```c++
#include "UEPyFbxIOSettings.h"
#if ENGINE_MINOR_VERSION > 12
#if WITH_EDITOR
#include "UEPyFbx.h"
static PyMethodDef ue_PyFbxIOSettings_methods[] = {
{ NULL } /* Sentinel */
};
static PyTypeObject ue_PyFbxIOSettingsType = {
PyVarObject_HEAD_INIT(NULL, 0)
"unreal_engine.FbxIOSettings", /* tp_name */
sizeof(ue_PyFbxIOSettings), /* tp_basicsize */
0, /* tp_itemsize */
0, /* tp_dealloc */
0, /* tp_print */
0, /* tp_getattr */
0, /* tp_setattr */
0, /* tp_reserved */
0, /* tp_repr */
0, /* tp_as_number */
0, /* tp_as_sequence */
0, /* tp_as_mapping */
0, /* tp_hash */
0, /* tp_call */
0, /* tp_str */
0, /* tp_getattro */
0, /* tp_setattro */
0, /* tp_as_buffer */
Py_TPFLAGS_DEFAULT, /* tp_flags */
"Unreal Engine FbxIOSettings", /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
0, /* tp_richcompare */
0, /* tp_weaklistoffset */
0, /* tp_iter */
0, /* tp_iternext */
ue_PyFbxIOSettings_methods, /* tp_methods */
0, /* tp_members */
0, /* tp_getset */
};
static int py_ue_fbx_io_settings_init(ue_PyFbxIOSettings *self, PyObject * args)
{
PyObject *py_object;
char *name;
if (!PyArg_ParseTuple(args, "Os", &py_object, &name))
{
return -1;
}
ue_PyFbxManager *py_fbx_manager = py_ue_is_fbx_manager(py_object);
if (!py_fbx_manager)
{
PyErr_SetString(PyExc_Exception, "argument is not a FbxManager");
return -1;
}
self->fbx_io_settings = FbxIOSettings::Create(py_fbx_manager->fbx_manager, name);
return 0;
}
void ue_python_init_fbx_io_settings(PyObject *ue_module)
{
ue_PyFbxIOSettingsType.tp_new = PyType_GenericNew;;
ue_PyFbxIOSettingsType.tp_init = (initproc)py_ue_fbx_io_settings_init;
if (PyType_Ready(&ue_PyFbxIOSettingsType) < 0)
return;
Py_INCREF(&ue_PyFbxIOSettingsType);
PyModule_AddObject(ue_module, "FbxIOSettings", (PyObject *)&ue_PyFbxIOSettingsType);
}
ue_PyFbxIOSettings *py_ue_is_fbx_io_settings(PyObject *obj)
{
if (!PyObject_IsInstance(obj, (PyObject *)&ue_PyFbxIOSettingsType))
return nullptr;
return (ue_PyFbxIOSettings *)obj;
}
#endif
#endif
```
|
/content/code_sandbox/Source/UnrealEnginePython/Private/Fbx/UEPyFbxIOSettings.cpp
|
c++
| 2016-08-07T05:00:51
| 2024-08-14T06:32:20
|
UnrealEnginePython
|
20tab/UnrealEnginePython
| 2,715
| 685
|
```objective-c
#pragma once
#include "UEPyModule.h"
#if WITH_EDITOR
#if PLATFORM_LINUX
#if defined(__clang__)
#pragma clang diagnostic ignored "-Wnull-dereference"
#endif
#endif
#include <fbxsdk.h>
struct ue_PyFbxImporter
{
PyObject_HEAD
/* Type-specific fields go here. */
FbxImporter *fbx_importer;
};
void ue_python_init_fbx_importer(PyObject *);
#endif
```
|
/content/code_sandbox/Source/UnrealEnginePython/Private/Fbx/UEPyFbxImporter.h
|
objective-c
| 2016-08-07T05:00:51
| 2024-08-14T06:32:20
|
UnrealEnginePython
|
20tab/UnrealEnginePython
| 2,715
| 92
|
```objective-c
#pragma once
#include "UEPyModule.h"
#if WITH_EDITOR
#if PLATFORM_LINUX
#if defined(__clang__)
#pragma clang diagnostic ignored "-Wnull-dereference"
#endif
#endif
#include <fbxsdk.h>
struct ue_PyFbxScene {
PyObject_HEAD
/* Type-specific fields go here. */
FbxScene *fbx_scene;
};
void ue_python_init_fbx_scene(PyObject *);
ue_PyFbxScene *py_ue_is_fbx_scene(PyObject *);
#endif
```
|
/content/code_sandbox/Source/UnrealEnginePython/Private/Fbx/UEPyFbxScene.h
|
objective-c
| 2016-08-07T05:00:51
| 2024-08-14T06:32:20
|
UnrealEnginePython
|
20tab/UnrealEnginePython
| 2,715
| 102
|
```objective-c
#pragma once
#include "UEPyModule.h"
#if WITH_EDITOR
#if PLATFORM_LINUX
#if defined(__clang__)
#pragma clang diagnostic ignored "-Wnull-dereference"
#endif
#endif
#include <fbxsdk.h>
struct ue_PyFbxIOSettings
{
PyObject_HEAD
/* Type-specific fields go here. */
FbxIOSettings *fbx_io_settings;
};
void ue_python_init_fbx_io_settings(PyObject *);
ue_PyFbxIOSettings *py_ue_is_fbx_io_settings(PyObject *);
#endif
```
|
/content/code_sandbox/Source/UnrealEnginePython/Private/Fbx/UEPyFbxIOSettings.h
|
objective-c
| 2016-08-07T05:00:51
| 2024-08-14T06:32:20
|
UnrealEnginePython
|
20tab/UnrealEnginePython
| 2,715
| 111
|
```c++
#include "UEPyFbxManager.h"
#if ENGINE_MINOR_VERSION > 12
#if WITH_EDITOR
#include "UEPyFbx.h"
static PyObject *py_ue_fbx_manager_set_io_settings(ue_PyFbxManager *self, PyObject *args)
{
PyObject *py_object;
if (!PyArg_ParseTuple(args, "O", &py_object))
{
return nullptr;
}
ue_PyFbxIOSettings *py_fbx_io_settings = py_ue_is_fbx_io_settings(py_object);
if (!py_fbx_io_settings)
{
return PyErr_Format(PyExc_Exception, "argument is not a FbxIOSettings");
}
self->fbx_manager->SetIOSettings(py_fbx_io_settings->fbx_io_settings);
Py_RETURN_NONE;
}
static PyObject *py_ue_fbx_manager_create_missing_bind_poses(ue_PyFbxManager *self, PyObject *args)
{
PyObject *py_object;
if (!PyArg_ParseTuple(args, "O", &py_object))
{
return nullptr;
}
ue_PyFbxScene *py_fbx_scene = py_ue_is_fbx_scene(py_object);
if (!py_fbx_scene)
{
return PyErr_Format(PyExc_Exception, "argument is not a FbxScene");
}
self->fbx_manager->CreateMissingBindPoses(py_fbx_scene->fbx_scene);
Py_RETURN_NONE;
}
static PyMethodDef ue_PyFbxManager_methods[] = {
{ "set_io_settings", (PyCFunction)py_ue_fbx_manager_set_io_settings, METH_VARARGS, "" },
{ "create_missing_bind_poses", (PyCFunction)py_ue_fbx_manager_create_missing_bind_poses, METH_VARARGS, "" },
{ NULL } /* Sentinel */
};
static void ue_py_fbx_manager_dealloc(ue_PyFbxManager *self)
{
if (self->fbx_manager)
self->fbx_manager->Destroy();
#if PY_MAJOR_VERSION < 3
self->ob_type->tp_free((PyObject*)self);
#else
Py_TYPE(self)->tp_free((PyObject*)self);
#endif
}
static PyTypeObject ue_PyFbxManagerType = {
PyVarObject_HEAD_INIT(NULL, 0)
"unreal_engine.FbxManager", /* tp_name */
sizeof(ue_PyFbxManager), /* tp_basicsize */
0, /* tp_itemsize */
(destructor)ue_py_fbx_manager_dealloc, /* tp_dealloc */
0, /* tp_print */
0, /* tp_getattr */
0, /* tp_setattr */
0, /* tp_reserved */
0, /* tp_repr */
0, /* tp_as_number */
0, /* tp_as_sequence */
0, /* tp_as_mapping */
0, /* tp_hash */
0, /* tp_call */
0, /* tp_str */
0, /* tp_getattro */
0, /* tp_setattro */
0, /* tp_as_buffer */
Py_TPFLAGS_DEFAULT, /* tp_flags */
"Unreal Engine FbxManager", /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
0, /* tp_richcompare */
0, /* tp_weaklistoffset */
0, /* tp_iter */
0, /* tp_iternext */
ue_PyFbxManager_methods, /* tp_methods */
0, /* tp_members */
0, /* tp_getset */
};
static int py_ue_fbx_manager_init(ue_PyFbxManager *self, PyObject * args)
{
self->fbx_manager = FbxManager::Create();
return 0;
}
void ue_python_init_fbx_manager(PyObject *ue_module)
{
ue_PyFbxManagerType.tp_new = PyType_GenericNew;;
ue_PyFbxManagerType.tp_init = (initproc)py_ue_fbx_manager_init;
if (PyType_Ready(&ue_PyFbxManagerType) < 0)
return;
Py_INCREF(&ue_PyFbxManagerType);
PyModule_AddObject(ue_module, "FbxManager", (PyObject *)&ue_PyFbxManagerType);
}
ue_PyFbxManager *py_ue_is_fbx_manager(PyObject *obj)
{
if (!PyObject_IsInstance(obj, (PyObject *)&ue_PyFbxManagerType))
return nullptr;
return (ue_PyFbxManager *)obj;
}
void ue_python_init_fbx(PyObject *module)
{
ue_python_init_fbx_manager(module);
ue_python_init_fbx_io_settings(module);
ue_python_init_fbx_importer(module);
ue_python_init_fbx_scene(module);
ue_python_init_fbx_node(module);
ue_python_init_fbx_object(module);
ue_python_init_fbx_property(module);
ue_python_init_fbx_pose(module);
ue_python_init_fbx_mesh(module);
}
#endif
#endif
```
|
/content/code_sandbox/Source/UnrealEnginePython/Private/Fbx/UEPyFbxManager.cpp
|
c++
| 2016-08-07T05:00:51
| 2024-08-14T06:32:20
|
UnrealEnginePython
|
20tab/UnrealEnginePython
| 2,715
| 1,061
|
```objective-c
#pragma once
#include "UEPyModule.h"
#if WITH_EDITOR
#if ENGINE_MINOR_VERSION > 12
#if PLATFORM_LINUX
#if defined(__clang__)
#pragma clang diagnostic ignored "-Wnull-dereference"
#endif
#endif
#include <fbxsdk.h>
struct ue_PyFbxNode
{
PyObject_HEAD
/* Type-specific fields go here. */
FbxNode *fbx_node;
};
void ue_python_init_fbx_node(PyObject *);
PyObject *py_ue_new_fbx_node(FbxNode *);
ue_PyFbxNode *py_ue_is_fbx_node(PyObject *);
#endif
#endif
```
|
/content/code_sandbox/Source/UnrealEnginePython/Private/Fbx/UEPyFbxNode.h
|
objective-c
| 2016-08-07T05:00:51
| 2024-08-14T06:32:20
|
UnrealEnginePython
|
20tab/UnrealEnginePython
| 2,715
| 127
|
```c++
#include "UEPyFbxScene.h"
#if ENGINE_MINOR_VERSION > 12
#if WITH_EDITOR
#include "UEPyFbx.h"
static PyObject *py_ue_fbx_scene_get_root_node(ue_PyFbxScene *self, PyObject *args)
{
FbxNode *fbx_node = self->fbx_scene->GetRootNode();
if (!fbx_node)
{
return PyErr_Format(PyExc_Exception, "unable to get RootNode from FbxScene");
}
return py_ue_new_fbx_node(fbx_node);
}
static PyObject *py_ue_fbx_scene_get_src_object_count(ue_PyFbxScene *self, PyObject *args)
{
return PyLong_FromLong(self->fbx_scene->GetSrcObjectCount());
}
static PyObject *py_ue_fbx_scene_get_pose_count(ue_PyFbxScene *self, PyObject *args)
{
return PyLong_FromLong(self->fbx_scene->GetPoseCount());
}
static PyObject *py_ue_fbx_scene_get_src_object(ue_PyFbxScene *self, PyObject *args)
{
int index;
if (!PyArg_ParseTuple(args, "i", &index))
{
return nullptr;
}
FbxObject *fbx_object = self->fbx_scene->GetSrcObject(index);
if (!fbx_object)
return PyErr_Format(PyExc_Exception, "unable to find FbxObject with index %d", index);
return py_ue_new_fbx_object(fbx_object);
}
static PyObject *py_ue_fbx_scene_get_pose(ue_PyFbxScene *self, PyObject *args)
{
int index;
if (!PyArg_ParseTuple(args, "i", &index))
{
return nullptr;
}
FbxPose *fbx_pose = self->fbx_scene->GetPose(index);
if (!fbx_pose)
return PyErr_Format(PyExc_Exception, "unable to find FbxPose with index %d", index);
return py_ue_new_fbx_pose(fbx_pose);
}
static PyObject *py_ue_fbx_scene_convert(ue_PyFbxScene *self, PyObject *args)
{
FbxScene *scene = self->fbx_scene;
FbxAxisSystem::ECoordSystem coord_system = FbxAxisSystem::eRightHanded;
FbxAxisSystem::EUpVector up_vector = FbxAxisSystem::eZAxis;
FbxAxisSystem::EFrontVector front_vector = (FbxAxisSystem::EFrontVector) - FbxAxisSystem::eParityOdd;
FbxAxisSystem unreal(up_vector, front_vector, coord_system);
if (scene->GetGlobalSettings().GetAxisSystem() != unreal)
{
FbxRootNodeUtility::RemoveAllFbxRoots(scene);
unreal.ConvertScene(scene);
}
scene->GetAnimationEvaluator()->Reset();
Py_RETURN_NONE;
}
static PyObject *py_ue_fbx_scene_triangulate(ue_PyFbxScene *self, PyObject *args)
{
FbxScene *scene = self->fbx_scene;
FbxGeometryConverter converter(scene->GetFbxManager());
if (converter.Triangulate(scene, true))
{
Py_RETURN_TRUE;
}
Py_RETURN_FALSE;
}
static PyMethodDef ue_PyFbxScene_methods[] = {
{ "convert", (PyCFunction)py_ue_fbx_scene_convert, METH_VARARGS, "" },
{ "triangulate", (PyCFunction)py_ue_fbx_scene_triangulate, METH_VARARGS, "" },
{ "get_root_node", (PyCFunction)py_ue_fbx_scene_get_root_node, METH_VARARGS, "" },
{ "get_src_object_count", (PyCFunction)py_ue_fbx_scene_get_src_object_count, METH_VARARGS, "" },
{ "get_src_object", (PyCFunction)py_ue_fbx_scene_get_src_object, METH_VARARGS, "" },
{ "get_pose_count", (PyCFunction)py_ue_fbx_scene_get_pose_count, METH_VARARGS, "" },
{ "get_pose", (PyCFunction)py_ue_fbx_scene_get_pose, METH_VARARGS, "" },
{ NULL } /* Sentinel */
};
static PyTypeObject ue_PyFbxSceneType = {
PyVarObject_HEAD_INIT(NULL, 0)
"unreal_engine.FbxScene", /* tp_name */
sizeof(ue_PyFbxScene), /* tp_basicsize */
0, /* tp_itemsize */
0, /* tp_dealloc */
0, /* tp_print */
0, /* tp_getattr */
0, /* tp_setattr */
0, /* tp_reserved */
0, /* tp_repr */
0, /* tp_as_number */
0, /* tp_as_sequence */
0, /* tp_as_mapping */
0, /* tp_hash */
0, /* tp_call */
0, /* tp_str */
0, /* tp_getattro */
0, /* tp_setattro */
0, /* tp_as_buffer */
Py_TPFLAGS_DEFAULT, /* tp_flags */
"Unreal Engine FbxScene", /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
0, /* tp_richcompare */
0, /* tp_weaklistoffset */
0, /* tp_iter */
0, /* tp_iternext */
ue_PyFbxScene_methods, /* tp_methods */
0, /* tp_members */
0, /* tp_getset */
};
static int py_ue_fbx_scene_init(ue_PyFbxScene *self, PyObject * args)
{
PyObject *py_object;
char *name;
if (!PyArg_ParseTuple(args, "Os", &py_object, &name))
{
return -1;
}
ue_PyFbxManager *py_fbx_manager = py_ue_is_fbx_manager(py_object);
if (!py_fbx_manager)
{
PyErr_SetString(PyExc_Exception, "argument is not a FbxManager");
return -1;
}
self->fbx_scene = FbxScene::Create(py_fbx_manager->fbx_manager, name);
return 0;
}
void ue_python_init_fbx_scene(PyObject *ue_module)
{
ue_PyFbxSceneType.tp_new = PyType_GenericNew;;
ue_PyFbxSceneType.tp_init = (initproc)py_ue_fbx_scene_init;
if (PyType_Ready(&ue_PyFbxSceneType) < 0)
return;
Py_INCREF(&ue_PyFbxSceneType);
PyModule_AddObject(ue_module, "FbxScene", (PyObject *)&ue_PyFbxSceneType);
}
ue_PyFbxScene *py_ue_is_fbx_scene(PyObject *obj)
{
if (!PyObject_IsInstance(obj, (PyObject *)&ue_PyFbxSceneType))
return nullptr;
return (ue_PyFbxScene *)obj;
}
#endif
#endif
```
|
/content/code_sandbox/Source/UnrealEnginePython/Private/Fbx/UEPyFbxScene.cpp
|
c++
| 2016-08-07T05:00:51
| 2024-08-14T06:32:20
|
UnrealEnginePython
|
20tab/UnrealEnginePython
| 2,715
| 1,488
|
```objective-c
#pragma once
#include "UEPyModule.h"
#if WITH_EDITOR
#if PLATFORM_LINUX
#if defined(__clang__)
#pragma clang diagnostic ignored "-Wnull-dereference"
#endif
#endif
#include <fbxsdk.h>
struct ue_PyFbxProperty {
PyObject_HEAD
/* Type-specific fields go here. */
FbxProperty fbx_property;
};
void ue_python_init_fbx_property(PyObject *);
PyObject *py_ue_new_fbx_property(FbxProperty);
ue_PyFbxProperty *py_ue_is_fbx_property(PyObject *);
#endif
```
|
/content/code_sandbox/Source/UnrealEnginePython/Private/Fbx/UEPyFbxProperty.h
|
objective-c
| 2016-08-07T05:00:51
| 2024-08-14T06:32:20
|
UnrealEnginePython
|
20tab/UnrealEnginePython
| 2,715
| 113
|
```c++
#include "UEPyFbxImporter.h"
#if ENGINE_MINOR_VERSION > 12
#if WITH_EDITOR
#include "UEPyFbx.h"
static PyObject *py_ue_fbx_importer_get_anim_stack_count(ue_PyFbxImporter *self, PyObject *args)
{
return PyLong_FromLong(self->fbx_importer->GetAnimStackCount());
}
static PyObject *py_ue_fbx_importer_get_take_local_time_span(ue_PyFbxImporter *self, PyObject *args)
{
int index;
if (!PyArg_ParseTuple(args, "i", &index))
{
return nullptr;
}
FbxTakeInfo *take_info = self->fbx_importer->GetTakeInfo(index);
if (!take_info)
return PyErr_Format(PyExc_Exception, "unable to get FbxTakeInfo for index %d", index);
FbxTimeSpan time_span = take_info->mLocalTimeSpan;
return Py_BuildValue((char *)"(ff)", time_span.GetStart().GetSecondDouble(), time_span.GetStop().GetSecondDouble());
}
static PyObject *py_ue_fbx_importer_initialize(ue_PyFbxImporter *self, PyObject *args)
{
char *filename;
PyObject *py_object;
if (!PyArg_ParseTuple(args, "sO", &filename, &py_object))
{
return nullptr;
}
ue_PyFbxIOSettings *py_fbx_io_settings = py_ue_is_fbx_io_settings(py_object);
if (!py_fbx_io_settings)
{
return PyErr_Format(PyExc_Exception, "argument is not a FbxIOSettings");
}
if (self->fbx_importer->Initialize(filename, -1, py_fbx_io_settings->fbx_io_settings))
{
Py_RETURN_TRUE;
}
Py_RETURN_FALSE;
}
static PyObject *py_ue_fbx_importer_import(ue_PyFbxImporter *self, PyObject *args)
{
PyObject *py_object;
if (!PyArg_ParseTuple(args, "O", &py_object))
{
return nullptr;
}
ue_PyFbxScene *py_fbx_scene = py_ue_is_fbx_scene(py_object);
if (!py_fbx_scene)
{
return PyErr_Format(PyExc_Exception, "argument is not a FbxScene");
}
if (self->fbx_importer->Import(py_fbx_scene->fbx_scene))
{
Py_RETURN_TRUE;
}
Py_RETURN_FALSE;
}
static PyMethodDef ue_PyFbxImporter_methods[] = {
{ "initialize", (PyCFunction)py_ue_fbx_importer_initialize, METH_VARARGS, "" },
{ "_import", (PyCFunction)py_ue_fbx_importer_import, METH_VARARGS, "" },
{ "get_anim_stack_count", (PyCFunction)py_ue_fbx_importer_get_anim_stack_count, METH_VARARGS, "" },
{ "get_take_local_time_span", (PyCFunction)py_ue_fbx_importer_get_take_local_time_span, METH_VARARGS, "" },
{ NULL } /* Sentinel */
};
static PyTypeObject ue_PyFbxImporterType = {
PyVarObject_HEAD_INIT(NULL, 0)
"unreal_engine.FbxImporter", /* tp_name */
sizeof(ue_PyFbxImporter), /* tp_basicsize */
0, /* tp_itemsize */
0, /* tp_dealloc */
0, /* tp_print */
0, /* tp_getattr */
0, /* tp_setattr */
0, /* tp_reserved */
0, /* tp_repr */
0, /* tp_as_number */
0, /* tp_as_sequence */
0, /* tp_as_mapping */
0, /* tp_hash */
0, /* tp_call */
0, /* tp_str */
0, /* tp_getattro */
0, /* tp_setattro */
0, /* tp_as_buffer */
Py_TPFLAGS_DEFAULT, /* tp_flags */
"Unreal Engine FbxImporter", /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
0, /* tp_richcompare */
0, /* tp_weaklistoffset */
0, /* tp_iter */
0, /* tp_iternext */
ue_PyFbxImporter_methods, /* tp_methods */
0, /* tp_members */
0, /* tp_getset */
};
static int py_ue_fbx_importer_init(ue_PyFbxImporter *self, PyObject * args)
{
PyObject *py_object;
char *name;
if (!PyArg_ParseTuple(args, "Os", &py_object, &name))
{
return -1;
}
ue_PyFbxManager *py_fbx_manager = py_ue_is_fbx_manager(py_object);
if (!py_fbx_manager)
{
PyErr_SetString(PyExc_Exception, "argument is not a FbxManager");
return -1;
}
self->fbx_importer = FbxImporter::Create(py_fbx_manager->fbx_manager, name);
return 0;
}
void ue_python_init_fbx_importer(PyObject *ue_module)
{
ue_PyFbxImporterType.tp_new = PyType_GenericNew;;
ue_PyFbxImporterType.tp_init = (initproc)py_ue_fbx_importer_init;
if (PyType_Ready(&ue_PyFbxImporterType) < 0)
return;
Py_INCREF(&ue_PyFbxImporterType);
PyModule_AddObject(ue_module, "FbxImporter", (PyObject *)&ue_PyFbxImporterType);
}
#endif
#endif
```
|
/content/code_sandbox/Source/UnrealEnginePython/Private/Fbx/UEPyFbxImporter.cpp
|
c++
| 2016-08-07T05:00:51
| 2024-08-14T06:32:20
|
UnrealEnginePython
|
20tab/UnrealEnginePython
| 2,715
| 1,210
|
```objective-c
#pragma once
#include "UEPyModule.h"
#if WITH_EDITOR
#if PLATFORM_LINUX
#if defined(__clang__)
#pragma clang diagnostic ignored "-Wnull-dereference"
#endif
#endif
#include <fbxsdk.h>
struct ue_PyFbxPose
{
PyObject_HEAD
/* Type-specific fields go here. */
FbxPose *fbx_pose;
};
void ue_python_init_fbx_pose(PyObject *);
PyObject *py_ue_new_fbx_pose(FbxPose *);
#endif
```
|
/content/code_sandbox/Source/UnrealEnginePython/Private/Fbx/UEPyFbxPose.h
|
objective-c
| 2016-08-07T05:00:51
| 2024-08-14T06:32:20
|
UnrealEnginePython
|
20tab/UnrealEnginePython
| 2,715
| 102
|
```c++
#include "UEPyFbxObject.h"
#if ENGINE_MINOR_VERSION > 12
#if WITH_EDITOR
#include "UEPyFbx.h"
#include "Runtime/Engine/Classes/Curves/RichCurve.h"
static PyObject *py_ue_fbx_object_get_name(ue_PyFbxObject *self, PyObject *args)
{
return PyUnicode_FromString(self->fbx_object->GetName());
}
static PyObject *py_ue_fbx_object_get_class_name(ue_PyFbxObject *self, PyObject *args)
{
return PyUnicode_FromString(self->fbx_object->GetClassId().GetName());
}
static PyObject *py_ue_fbx_object_get_member_count(ue_PyFbxObject *self, PyObject *args)
{
FbxCollection *fbx_collection = FbxCast<FbxCollection>(self->fbx_object);
if (!fbx_collection)
return PyErr_Format(PyExc_Exception, "unable to cast to FbxCollection");
return PyLong_FromLong(fbx_collection->GetMemberCount());
}
static PyObject *py_ue_fbx_object_get_member(ue_PyFbxObject *self, PyObject *args)
{
int index;
if (!PyArg_ParseTuple(args, "i", &index))
{
return nullptr;
}
FbxCollection *fbx_collection = FbxCast<FbxCollection>(self->fbx_object);
if (!fbx_collection)
return PyErr_Format(PyExc_Exception, "unable to cast to FbxCollection");
FbxObject *fbx_object = fbx_collection->GetMember(index);
if (!fbx_object)
return PyErr_Format(PyExc_Exception, "unable to find FbxObject with index %d", index);
return py_ue_new_fbx_object(fbx_collection->GetMember(index));
}
static PyObject *py_ue_fbx_object_get_next_property(ue_PyFbxObject *self, PyObject *args)
{
PyObject *py_object;
if (!PyArg_ParseTuple(args, "O", &py_object))
{
return nullptr;
}
ue_PyFbxProperty *py_fbx_property = py_ue_is_fbx_property(py_object);
if (!py_fbx_property)
{
return PyErr_Format(PyExc_Exception, "argument is not a FbxProperty");
}
FbxProperty fbx_property = self->fbx_object->GetNextProperty(py_fbx_property->fbx_property);
if (!fbx_property.IsValid())
Py_RETURN_NONE;
return py_ue_new_fbx_property(fbx_property);
}
static PyObject *py_ue_fbx_object_get_first_property(ue_PyFbxObject *self, PyObject *args)
{
FbxProperty fbx_property = self->fbx_object->GetFirstProperty();
if (!fbx_property.IsValid())
Py_RETURN_NONE;
return py_ue_new_fbx_property(fbx_property);
}
static PyObject *py_ue_fbx_object_get_channels_count(ue_PyFbxObject *self, PyObject *args)
{
FbxAnimCurveNode *fbx_anim_curve_node = FbxCast<FbxAnimCurveNode>(self->fbx_object);
if (!fbx_anim_curve_node)
return PyErr_Format(PyExc_Exception, "object is not a FbxAnimCurveNode");
return PyLong_FromLong(fbx_anim_curve_node->GetChannelsCount());
}
static PyObject *py_ue_fbx_object_to_node(ue_PyFbxObject *self, PyObject *args)
{
FbxNode *fbx_node = FbxCast<FbxNode>(self->fbx_object);
if (!fbx_node)
return PyErr_Format(PyExc_Exception, "object is not a FbxNode");
return py_ue_new_fbx_node(fbx_node);
}
static PyObject *py_ue_fbx_object_get_channel_name(ue_PyFbxObject *self, PyObject *args)
{
int index;
if (!PyArg_ParseTuple(args, "i", &index))
{
return nullptr;
}
FbxAnimCurveNode *fbx_anim_curve_node = FbxCast<FbxAnimCurveNode>(self->fbx_object);
if (!fbx_anim_curve_node)
return PyErr_Format(PyExc_Exception, "object is not a FbxAnimCurveNode");
return PyUnicode_FromString(fbx_anim_curve_node->GetChannelName(index));
}
static PyObject *py_ue_fbx_object_get_curve_count(ue_PyFbxObject *self, PyObject *args)
{
int channel;
if (!PyArg_ParseTuple(args, "i", &channel))
{
return nullptr;
}
FbxAnimCurveNode *fbx_anim_curve_node = FbxCast<FbxAnimCurveNode>(self->fbx_object);
if (!fbx_anim_curve_node)
return PyErr_Format(PyExc_Exception, "object is not a FbxAnimCurveNode");
return PyLong_FromLong(fbx_anim_curve_node->GetCurveCount(channel));
}
static PyObject *py_ue_fbx_object_get_curve(ue_PyFbxObject *self, PyObject *args)
{
int channel;
int index = 0;
if (!PyArg_ParseTuple(args, "i|i:get_curve", &channel, &index))
{
return nullptr;
}
FbxAnimCurveNode *fbx_anim_curve_node = FbxCast<FbxAnimCurveNode>(self->fbx_object);
if (!fbx_anim_curve_node)
return PyErr_Format(PyExc_Exception, "object is not a FbxAnimCurveNode");
FbxAnimCurve *fbx_anim_curve = fbx_anim_curve_node->GetCurve(channel, index);
if (!fbx_anim_curve)
Py_RETURN_NONE;
return py_ue_new_fbx_object(fbx_anim_curve_node->GetCurve(channel, index));
}
static PyObject *py_ue_fbx_object_key_get_count(ue_PyFbxObject *self, PyObject *args)
{
FbxAnimCurve *fbx_anim_curve = FbxCast<FbxAnimCurve>(self->fbx_object);
if (!fbx_anim_curve)
return PyErr_Format(PyExc_Exception, "object is not a FbxAnimCurve");
return PyLong_FromLong(fbx_anim_curve->KeyGetCount());
}
static PyObject *py_ue_fbx_object_key_get_value(ue_PyFbxObject *self, PyObject *args)
{
int index;
if (!PyArg_ParseTuple(args, "i", &index))
{
return nullptr;
}
FbxAnimCurve *fbx_anim_curve = FbxCast<FbxAnimCurve>(self->fbx_object);
if (!fbx_anim_curve)
return PyErr_Format(PyExc_Exception, "object is not a FbxAnimCurve");
return PyFloat_FromDouble(fbx_anim_curve->KeyGetValue(index));
}
static PyObject *py_ue_fbx_object_key_get_seconds(ue_PyFbxObject *self, PyObject *args)
{
int index;
if (!PyArg_ParseTuple(args, "i", &index))
{
return nullptr;
}
FbxAnimCurve *fbx_anim_curve = FbxCast<FbxAnimCurve>(self->fbx_object);
if (!fbx_anim_curve)
return PyErr_Format(PyExc_Exception, "object is not a FbxAnimCurve");
return PyFloat_FromDouble(fbx_anim_curve->KeyGetTime(index).GetSecondDouble());
}
static PyObject *py_ue_fbx_object_key_get_left_tangent(ue_PyFbxObject *self, PyObject *args)
{
int index;
if (!PyArg_ParseTuple(args, "i", &index))
{
return nullptr;
}
FbxAnimCurve *fbx_anim_curve = FbxCast<FbxAnimCurve>(self->fbx_object);
if (!fbx_anim_curve)
return PyErr_Format(PyExc_Exception, "object is not a FbxAnimCurve");
return PyFloat_FromDouble(fbx_anim_curve->KeyGetLeftDerivative(index));
}
static PyObject *py_ue_fbx_object_key_get_right_tangent(ue_PyFbxObject *self, PyObject *args)
{
int index;
if (!PyArg_ParseTuple(args, "i", &index))
{
return nullptr;
}
FbxAnimCurve *fbx_anim_curve = FbxCast<FbxAnimCurve>(self->fbx_object);
if (!fbx_anim_curve)
return PyErr_Format(PyExc_Exception, "object is not a FbxAnimCurve");
return PyFloat_FromDouble(fbx_anim_curve->KeyGetRightDerivative(index));
}
static PyObject *py_ue_fbx_object_key_get_interp_mode(ue_PyFbxObject *self, PyObject *args)
{
int index;
if (!PyArg_ParseTuple(args, "i", &index))
{
return nullptr;
}
FbxAnimCurve *fbx_anim_curve = FbxCast<FbxAnimCurve>(self->fbx_object);
if (!fbx_anim_curve)
return PyErr_Format(PyExc_Exception, "object is not a FbxAnimCurve");
ERichCurveInterpMode Mode = RCIM_Linear;
// Convert the interpolation type from FBX to Unreal.
switch (fbx_anim_curve->KeyGetInterpolation(index))
{
case FbxAnimCurveDef::eInterpolationCubic:
Mode = RCIM_Cubic;
break;
case FbxAnimCurveDef::eInterpolationConstant:
if (fbx_anim_curve->KeyGetTangentMode(index) != (FbxAnimCurveDef::ETangentMode)FbxAnimCurveDef::eConstantStandard)
{
// warning not support
;
}
Mode = RCIM_Constant;
break;
case FbxAnimCurveDef::eInterpolationLinear:
Mode = RCIM_Linear;
break;
}
return PyLong_FromUnsignedLong(uint64(Mode));
}
static PyObject *py_ue_fbx_object_key_get_tangent_mode(ue_PyFbxObject *self, PyObject *args)
{
int index;
if (!PyArg_ParseTuple(args, "i", &index))
{
return nullptr;
}
FbxAnimCurve *fbx_anim_curve = FbxCast<FbxAnimCurve>(self->fbx_object);
if (!fbx_anim_curve)
return PyErr_Format(PyExc_Exception, "object is not a FbxAnimCurve");
ERichCurveTangentMode Mode = RCTM_Auto;
// Convert the interpolation type from FBX to Unreal.
if (fbx_anim_curve->KeyGetInterpolation(index) ==
FbxAnimCurveDef::eInterpolationCubic)
{
switch (fbx_anim_curve->KeyGetTangentMode(index))
{
// Auto tangents will now be imported as user tangents to allow the
// user to modify them without inadvertently resetting other tangents
// case KFbxAnimCurveDef::eTANGENT_AUTO:
// if ((KFbxAnimCurveDef::eTANGENT_GENERIC_CLAMP & FbxKey.GetTangentMode(true)))
// {
// Mode = CIM_CurveAutoClamped;
// }
// else
// {
// Mode = CIM_CurveAuto;
// }
// break;
case FbxAnimCurveDef::eTangentBreak:
Mode = RCTM_Break;
break;
case FbxAnimCurveDef::eTangentAuto:
Mode = RCTM_Auto;
break;
case FbxAnimCurveDef::eTangentUser:
case FbxAnimCurveDef::eTangentTCB:
Mode = RCTM_User;
break;
default:
break;
}
}
return PyLong_FromUnsignedLong(uint64(Mode));
}
static PyMethodDef ue_PyFbxObject_methods[] = {
{ "get_member_count", (PyCFunction)py_ue_fbx_object_get_member_count, METH_VARARGS, "" },
{ "get_member", (PyCFunction)py_ue_fbx_object_get_member, METH_VARARGS, "" },
{ "get_name", (PyCFunction)py_ue_fbx_object_get_name, METH_VARARGS, "" },
{ "to_node", (PyCFunction)py_ue_fbx_object_to_node, METH_VARARGS, "" },
{ "get_class_name", (PyCFunction)py_ue_fbx_object_get_class_name, METH_VARARGS, "" },
{ "get_first_property", (PyCFunction)py_ue_fbx_object_get_first_property, METH_VARARGS, "" },
{ "get_next_property", (PyCFunction)py_ue_fbx_object_get_next_property, METH_VARARGS, "" },
{ "get_channels_count", (PyCFunction)py_ue_fbx_object_get_channels_count, METH_VARARGS, "" },
{ "get_channel_name", (PyCFunction)py_ue_fbx_object_get_channel_name, METH_VARARGS, "" },
{ "get_curve_count", (PyCFunction)py_ue_fbx_object_get_curve_count, METH_VARARGS, "" },
{ "get_curve", (PyCFunction)py_ue_fbx_object_get_curve, METH_VARARGS, "" },
{ "key_get_count", (PyCFunction)py_ue_fbx_object_key_get_count, METH_VARARGS, "" },
{ "key_get_value", (PyCFunction)py_ue_fbx_object_key_get_value, METH_VARARGS, "" },
{ "key_get_seconds", (PyCFunction)py_ue_fbx_object_key_get_seconds, METH_VARARGS, "" },
{ "key_get_left_tangent", (PyCFunction)py_ue_fbx_object_key_get_left_tangent, METH_VARARGS, "" },
{ "key_get_right_tangent", (PyCFunction)py_ue_fbx_object_key_get_right_tangent, METH_VARARGS, "" },
{ "key_get_interp_mode", (PyCFunction)py_ue_fbx_object_key_get_interp_mode, METH_VARARGS, "" },
{ "key_get_tangent_mode", (PyCFunction)py_ue_fbx_object_key_get_tangent_mode, METH_VARARGS, "" },
{ NULL } /* Sentinel */
};
static PyTypeObject ue_PyFbxObjectType = {
PyVarObject_HEAD_INIT(NULL, 0)
"unreal_engine.FbxObject", /* tp_name */
sizeof(ue_PyFbxObject), /* tp_basicsize */
0, /* tp_itemsize */
0, /* tp_dealloc */
0, /* tp_print */
0, /* tp_getattr */
0, /* tp_setattr */
0, /* tp_reserved */
0, /* tp_repr */
0, /* tp_as_number */
0, /* tp_as_sequence */
0, /* tp_as_mapping */
0, /* tp_hash */
0, /* tp_call */
0, /* tp_str */
0, /* tp_getattro */
0, /* tp_setattro */
0, /* tp_as_buffer */
Py_TPFLAGS_DEFAULT, /* tp_flags */
"Unreal Engine FbxObject", /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
0, /* tp_richcompare */
0, /* tp_weaklistoffset */
0, /* tp_iter */
0, /* tp_iternext */
ue_PyFbxObject_methods, /* tp_methods */
0, /* tp_members */
0, /* tp_getset */
};
static int py_ue_fbx_object_init(ue_PyFbxObject *self, PyObject * args)
{
PyObject *py_object;
char *name;
if (!PyArg_ParseTuple(args, "Os", &py_object, &name))
{
return -1;
}
ue_PyFbxManager *py_fbx_manager = py_ue_is_fbx_manager(py_object);
if (!py_fbx_manager)
{
PyErr_SetString(PyExc_Exception, "argument is not a FbxManager");
return -1;
}
self->fbx_object = FbxObject::Create(py_fbx_manager->fbx_manager, name);
return 0;
}
void ue_python_init_fbx_object(PyObject *ue_module)
{
ue_PyFbxObjectType.tp_new = PyType_GenericNew;;
ue_PyFbxObjectType.tp_init = (initproc)py_ue_fbx_object_init;
if (PyType_Ready(&ue_PyFbxObjectType) < 0)
return;
Py_INCREF(&ue_PyFbxObjectType);
PyModule_AddObject(ue_module, "FbxObject", (PyObject *)&ue_PyFbxObjectType);
}
PyObject *py_ue_new_fbx_object(FbxObject *fbx_object)
{
ue_PyFbxObject *ret = (ue_PyFbxObject *)PyObject_New(ue_PyFbxObject, &ue_PyFbxObjectType);
ret->fbx_object = fbx_object;
return (PyObject *)ret;
}
ue_PyFbxObject *py_ue_is_fbx_object(PyObject *obj)
{
if (!PyObject_IsInstance(obj, (PyObject *)&ue_PyFbxObjectType))
return nullptr;
return (ue_PyFbxObject *)obj;
}
#endif
#endif
```
|
/content/code_sandbox/Source/UnrealEnginePython/Private/Fbx/UEPyFbxObject.cpp
|
c++
| 2016-08-07T05:00:51
| 2024-08-14T06:32:20
|
UnrealEnginePython
|
20tab/UnrealEnginePython
| 2,715
| 3,657
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.