Skip to content

Commit 560a5d0

Browse files
author
Roberto De Ioris
committed
improved ue_site management, added texture_set_source_data()
1 parent 9d85792 commit 560a5d0

File tree

6 files changed

+105
-16
lines changed

6 files changed

+105
-16
lines changed

Source/UnrealEnginePython/Private/UEPyModule.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -640,6 +640,7 @@ static PyMethodDef ue_PyUObject_methods[] = {
640640
{ "set_blend_parameter", (PyCFunction)py_ue_set_blend_parameter, METH_VARARGS, "" },
641641

642642
{ "get_bone_transform", (PyCFunction)py_ue_anim_get_bone_transform, METH_VARARGS, "" },
643+
{ "extract_bone_transform", (PyCFunction)py_ue_anim_extract_bone_transform, METH_VARARGS, "" },
643644
{ "extract_root_motion", (PyCFunction)py_ue_anim_extract_root_motion, METH_VARARGS, "" },
644645

645646
#if WITH_EDITOR
@@ -973,6 +974,7 @@ static PyMethodDef ue_PyUObject_methods[] = {
973974

974975
#if WITH_EDITOR
975976
{ "texture_get_source_data", (PyCFunction)py_ue_texture_get_source_data, METH_VARARGS, "" },
977+
{ "texture_set_source_data", (PyCFunction)py_ue_texture_set_source_data, METH_VARARGS, "" },
976978
#endif
977979

978980
// Sequencer

Source/UnrealEnginePython/Private/UObject/UEPyAnimSequence.cpp

Lines changed: 40 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ PyObject *py_ue_anim_get_bone_transform(ue_PyUObject * self, PyObject * args)
2323
ue_py_check(self);
2424

2525
int track_index;
26-
float frame_time;
26+
float frame_time;
2727
PyObject *py_b_use_raw_data = nullptr;
2828

2929
if (!PyArg_ParseTuple(args, "if|O:get_bone_transform", &track_index, &frame_time, &py_b_use_raw_data))
@@ -45,6 +45,35 @@ PyObject *py_ue_anim_get_bone_transform(ue_PyUObject * self, PyObject * args)
4545
return py_ue_new_ftransform(OutAtom);
4646
}
4747

48+
PyObject *py_ue_anim_extract_bone_transform(ue_PyUObject * self, PyObject * args)
49+
{
50+
ue_py_check(self);
51+
52+
PyObject *py_sources;
53+
float frame_time;
54+
55+
if (!PyArg_ParseTuple(args, "Of:extract_bone_transform", &py_sources, &frame_time))
56+
{
57+
return nullptr;
58+
}
59+
60+
UAnimSequence *anim = ue_py_check_type<UAnimSequence>(self);
61+
if (!anim)
62+
return PyErr_Format(PyExc_Exception, "UObject is not a UAnimSequence.");
63+
64+
ue_PyFRawAnimSequenceTrack *rast = py_ue_is_fraw_anim_sequence_track(py_sources);
65+
if (rast)
66+
{
67+
FTransform OutAtom;
68+
anim->ExtractBoneTransform(rast->raw_anim_sequence_track, OutAtom, frame_time);
69+
70+
return py_ue_new_ftransform(OutAtom);
71+
}
72+
73+
return PyErr_Format(PyExc_Exception, "argument is not an FRawAnimSequenceTrack");
74+
75+
}
76+
4877
PyObject *py_ue_anim_extract_root_motion(ue_PyUObject * self, PyObject * args)
4978
{
5079
ue_py_check(self);
@@ -138,16 +167,16 @@ PyObject *py_ue_anim_sequence_apply_raw_anim_changes(ue_PyUObject * self, PyObje
138167

139168

140169
if (anim_seq->DoesNeedRebake())
141-
{
142-
anim_seq->Modify(true);
143-
anim_seq->BakeTrackCurvesToRawAnimation();
144-
}
170+
{
171+
anim_seq->Modify(true);
172+
anim_seq->BakeTrackCurvesToRawAnimation();
173+
}
145174

146-
if (anim_seq->DoesNeedRecompress())
147-
{
148-
anim_seq->Modify(true);
149-
anim_seq->RequestSyncAnimRecompression(false);
150-
}
175+
if (anim_seq->DoesNeedRecompress())
176+
{
177+
anim_seq->Modify(true);
178+
anim_seq->RequestSyncAnimRecompression(false);
179+
}
151180

152181
Py_RETURN_NONE;
153182
}
@@ -214,7 +243,7 @@ PyObject *py_ue_anim_sequence_update_raw_track(ue_PyUObject * self, PyObject * a
214243
anim_seq->Modify();
215244

216245
FRawAnimSequenceTrack& RawRef = anim_seq->GetRawAnimationTrack(track_index);
217-
246+
218247
RawRef.PosKeys = py_f_rast->raw_anim_sequence_track.PosKeys;
219248
RawRef.RotKeys = py_f_rast->raw_anim_sequence_track.RotKeys;
220249
RawRef.ScaleKeys = py_f_rast->raw_anim_sequence_track.ScaleKeys;

Source/UnrealEnginePython/Private/UObject/UEPyAnimSequence.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ PyObject *py_ue_anim_sequence_apply_raw_anim_changes(ue_PyUObject *, PyObject *)
2020
#endif
2121
PyObject *py_ue_anim_set_skeleton(ue_PyUObject *, PyObject *);
2222
PyObject *py_ue_anim_get_bone_transform(ue_PyUObject *, PyObject *);
23+
PyObject *py_ue_anim_extract_bone_transform(ue_PyUObject *, PyObject *);
2324
PyObject *py_ue_anim_extract_root_motion(ue_PyUObject *, PyObject *);
2425

2526
PyObject *py_ue_get_blend_parameter(ue_PyUObject *, PyObject *);

Source/UnrealEnginePython/Private/UObject/UEPyTexture.cpp

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ PyObject *py_ue_texture_get_source_data(ue_PyUObject *self, PyObject * args)
7979

8080
if (!PyArg_ParseTuple(args, "|i:texture_get_data", &mipmap))
8181
{
82-
return NULL;
82+
return nullptr;
8383
}
8484

8585
UTexture2D *tex = ue_py_check_type<UTexture2D>(self);
@@ -96,6 +96,55 @@ PyObject *py_ue_texture_get_source_data(ue_PyUObject *self, PyObject * args)
9696
tex->Source.UnlockMip(mipmap);
9797
return bytes;
9898
}
99+
100+
PyObject *py_ue_texture_set_source_data(ue_PyUObject *self, PyObject * args)
101+
{
102+
103+
ue_py_check(self);
104+
105+
Py_buffer py_buf;
106+
int mipmap = 0;
107+
108+
if (!PyArg_ParseTuple(args, "z*|i:texture_set_source_data", &py_buf, &mipmap))
109+
{
110+
return NULL;
111+
}
112+
113+
UTexture2D *tex = ue_py_check_type<UTexture2D>(self);
114+
if (!tex)
115+
return PyErr_Format(PyExc_Exception, "object is not a Texture2D");
116+
117+
118+
if (!py_buf.buf)
119+
return PyErr_Format(PyExc_Exception, "invalid data");
120+
121+
if (mipmap >= tex->GetNumMips())
122+
return PyErr_Format(PyExc_Exception, "invalid mipmap id");
123+
124+
int32 wanted_len = py_buf.len;
125+
int32 len = tex->Source.GetSizeX() * tex->Source.GetSizeY() * 4;
126+
// avoid making mess
127+
if (wanted_len > len)
128+
{
129+
UE_LOG(LogPython, Warning, TEXT("truncating buffer to %d bytes"), len);
130+
wanted_len = len;
131+
}
132+
133+
const uint8 *blob = tex->Source.LockMip(mipmap);
134+
135+
FMemory::Memcpy((void *)blob, py_buf.buf, wanted_len);
136+
137+
tex->Source.UnlockMip(mipmap);
138+
Py_BEGIN_ALLOW_THREADS;
139+
tex->MarkPackageDirty();
140+
#if WITH_EDITOR
141+
tex->PostEditChange();
142+
#endif
143+
144+
tex->UpdateResource();
145+
Py_END_ALLOW_THREADS;
146+
Py_RETURN_NONE;
147+
}
99148
#endif
100149

101150
PyObject *py_ue_render_target_get_data(ue_PyUObject *self, PyObject * args)
@@ -274,7 +323,7 @@ PyObject *py_unreal_engine_create_checkerboard_texture(PyObject * self, PyObject
274323
return PyErr_Format(PyExc_Exception, "argument is not a FColor");
275324

276325
UTexture2D *texture = nullptr;
277-
326+
278327
Py_BEGIN_ALLOW_THREADS;
279328
texture = FImageUtils::CreateCheckerboardTexture(color_one->color, color_two->color, checker_size);
280329
Py_END_ALLOW_THREADS;

Source/UnrealEnginePython/Private/UObject/UEPyTexture.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,5 @@ PyObject *py_ue_texture_update_resource(ue_PyUObject *, PyObject *);
2323
#if WITH_EDITOR
2424
PyObject *py_unreal_engine_create_texture(PyObject * self, PyObject *);
2525
PyObject *py_ue_texture_get_source_data(ue_PyUObject *, PyObject *);
26+
PyObject *py_ue_texture_set_source_data(ue_PyUObject *, PyObject *);
2627
#endif

Source/UnrealEnginePython/Private/UnrealEnginePython.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -370,8 +370,15 @@ void FUnrealEnginePythonModule::StartupModule()
370370
}
371371
else
372372
{
373-
// TODO gracefully manage the error
374-
unreal_engine_py_log_error();
373+
if (PyErr_ExceptionMatches(PyExc_ModuleNotFoundError))
374+
{
375+
UE_LOG(LogPython, Log, TEXT("ue_site Python module not found"));
376+
PyErr_Clear();
377+
}
378+
else
379+
{
380+
unreal_engine_py_log_error();
381+
}
375382
}
376383

377384
// release the GIL
@@ -511,7 +518,7 @@ void FUnrealEnginePythonModule::RunFile(char *filename)
511518
{
512519
unreal_engine_py_log_error();
513520
return;
514-
}
521+
}
515522
#endif
516523

517524
}

0 commit comments

Comments
 (0)