Skip to content

Commit bd13df1

Browse files
author
rdeioris
committed
added RHI infrastructure, actor_set_level_sequence()
1 parent df37a17 commit bd13df1

6 files changed

Lines changed: 69 additions & 2 deletions

File tree

‎Source/UnrealEnginePython/Private/UEPyActor.cpp‎

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "UnrealEnginePythonPrivatePCH.h"
22

3-
3+
#include "Runtime/LevelSequence/Public/LevelSequenceActor.h"
4+
#include "Runtime/LevelSequence/Public/LevelSequence.h"
45

56
PyObject *py_ue_actor_has_tag(ue_PyUObject * self, PyObject * args) {
67

@@ -640,6 +641,31 @@ PyObject *py_ue_get_overlapping_actors(ue_PyUObject * self, PyObject * args) {
640641
return py_overlapping_actors;
641642
}
642643

644+
PyObject *py_ue_actor_set_level_sequence(ue_PyUObject * self, PyObject * args) {
645+
646+
ue_py_check(self);
647+
648+
PyObject *py_sequence;
649+
if (!PyArg_ParseTuple(args, "O:actor_set_level_sequence", &py_sequence)) {
650+
return NULL;
651+
}
652+
653+
ALevelSequenceActor *actor = ue_py_check_type<ALevelSequenceActor>(self);
654+
if (!actor) {
655+
return PyErr_Format(PyExc_Exception, "uobject is not a LevelSequenceActor");
656+
}
657+
658+
ULevelSequence *sequence = ue_py_check_type<ULevelSequence>(py_sequence);
659+
if (!sequence) {
660+
return PyErr_Format(PyExc_Exception, "argument is not a LevelSequence");
661+
}
662+
663+
actor->SetSequence(sequence);
664+
665+
Py_RETURN_NONE;
666+
}
667+
668+
643669
#if WITH_EDITOR
644670
PyObject *py_ue_get_editor_world_counterpart_actor(ue_PyUObject * self, PyObject * args) {
645671

‎Source/UnrealEnginePython/Private/UEPyActor.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ PyObject *py_ue_get_actor_component(ue_PyUObject *, PyObject *);
1111
PyObject *py_ue_actor_destroy(ue_PyUObject *, PyObject *);
1212
PyObject *py_ue_actor_components(ue_PyUObject *, PyObject *);
1313
PyObject *py_ue_get_actor_velocity(ue_PyUObject *, PyObject *);
14+
PyObject *py_ue_actor_set_level_sequence(ue_PyUObject *, PyObject *);
1415
#if WITH_EDITOR
1516
PyObject *py_ue_get_actor_label(ue_PyUObject *, PyObject *);
1617
PyObject *py_ue_set_actor_label(ue_PyUObject *, PyObject *);

‎Source/UnrealEnginePython/Private/UEPyModule.cpp‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -593,6 +593,7 @@ static PyMethodDef ue_PyUObject_methods[] = {
593593
{ "get_player_controller", (PyCFunction)py_ue_get_player_controller, METH_VARARGS, "" },
594594

595595
{ "get_overlapping_actors", (PyCFunction)py_ue_get_overlapping_actors, METH_VARARGS, "" },
596+
{ "actor_set_level_sequence", (PyCFunction)py_ue_actor_set_level_sequence, METH_VARARGS, "" },
596597

597598
// Pawn
598599
{ "get_controller", (PyCFunction)py_ue_pawn_get_controller, METH_VARARGS, "" },
@@ -625,6 +626,7 @@ static PyMethodDef ue_PyUObject_methods[] = {
625626
{ "texture_set_data", (PyCFunction)py_ue_texture_set_data, METH_VARARGS, "" },
626627
{ "texture_get_width", (PyCFunction)py_ue_texture_get_width, METH_VARARGS, "" },
627628
{ "texture_get_height", (PyCFunction)py_ue_texture_get_height, METH_VARARGS, "" },
629+
{ "render_target_get_data", (PyCFunction)py_ue_render_target_get_data, METH_VARARGS, "" },
628630

629631
// Sequencer
630632
{ "sequencer_master_tracks", (PyCFunction)py_ue_sequencer_master_tracks, METH_VARARGS, "" },

‎Source/UnrealEnginePython/Private/UEPyTexture.cpp‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,41 @@ PyObject *py_ue_texture_get_data(ue_PyUObject *self, PyObject * args) {
4848
return bytes;
4949
}
5050

51+
PyObject *py_ue_render_target_get_data(ue_PyUObject *self, PyObject * args) {
52+
53+
ue_py_check(self);
54+
55+
int mipmap = 0;
56+
57+
if (!PyArg_ParseTuple(args, "|i:render_target_get_data", &mipmap)) {
58+
return NULL;
59+
}
60+
61+
UTextureRenderTarget2D *tex = ue_py_check_type<UTextureRenderTarget2D>(self);
62+
if (!tex)
63+
return PyErr_Format(PyExc_Exception, "object is not a TextureRenderTarget");
64+
65+
FTexture2DResource *resource = nullptr;
66+
if (IsInRenderingThread()) {
67+
if (IsInGameThread()) {
68+
resource = (FTexture2DResource *)tex->GameThread_GetRenderTargetResource();
69+
}
70+
else {
71+
resource = (FTexture2DResource *)tex->GetRenderTargetResource();
72+
}
73+
}
74+
75+
if (!resource) {
76+
return PyErr_Format(PyExc_Exception, "cannot get render target resource");
77+
}
78+
79+
uint32 stride = 0;
80+
char *data = (char *)RHILockTexture2D(resource->GetTexture2DRHI(), mipmap, RLM_ReadOnly, stride, false);
81+
PyObject *bytes = PyByteArray_FromStringAndSize(data, (Py_ssize_t)(stride * resource->GetSizeY()));
82+
RHIUnlockTexture2D(resource->GetTexture2DRHI(), mipmap, false);
83+
return bytes;
84+
}
85+
5186
PyObject *py_ue_texture_set_data(ue_PyUObject *self, PyObject * args) {
5287

5388
ue_py_check(self);

‎Source/UnrealEnginePython/Private/UEPyTexture.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
#include "UnrealEnginePython.h"
66

77
PyObject *py_ue_texture_get_data(ue_PyUObject *, PyObject *);
8+
PyObject *py_ue_render_target_get_data(ue_PyUObject *, PyObject *);
9+
810
PyObject *py_ue_texture_set_data(ue_PyUObject *, PyObject *);
911
PyObject *py_ue_texture_get_width(ue_PyUObject *, PyObject *);
1012
PyObject *py_ue_texture_get_height(ue_PyUObject *, PyObject *);

‎Source/UnrealEnginePython/UnrealEnginePython.Build.cs‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,8 @@ public UnrealEnginePython(TargetInfo Target)
112112
"LevelSequence",
113113
"HTTP",
114114
"UMG",
115-
"AppFramework"
115+
"AppFramework",
116+
"RHI"
116117
// ... add private dependencies that you statically link with here ...
117118
}
118119
);

0 commit comments

Comments
 (0)