Skip to content

Commit 8e98a18

Browse files
committed
added update_raw_track() and apply_raw_anim_changes()
1 parent 28fe1ea commit 8e98a18

File tree

3 files changed

+126
-3
lines changed

3 files changed

+126
-3
lines changed

Source/UnrealEnginePython/Private/UEPyModule.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -639,12 +639,17 @@ static PyMethodDef ue_PyUObject_methods[] = {
639639
{ "get_blend_parameter", (PyCFunction)py_ue_get_blend_parameter, METH_VARARGS, "" },
640640
{ "set_blend_parameter", (PyCFunction)py_ue_set_blend_parameter, METH_VARARGS, "" },
641641

642+
{ "get_bone_transform", (PyCFunction)py_ue_anim_get_bone_transform, METH_VARARGS, "" },
643+
{ "extract_root_motion", (PyCFunction)py_ue_anim_extract_root_motion, METH_VARARGS, "" },
644+
642645
#if WITH_EDITOR
643646
#if ENGINE_MINOR_VERSION > 13
644647
{ "get_raw_animation_data", (PyCFunction)py_ue_anim_sequence_get_raw_animation_data, METH_VARARGS, "" },
645648
{ "get_raw_animation_track", (PyCFunction)py_ue_anim_sequence_get_raw_animation_track, METH_VARARGS, "" },
646649
{ "add_new_raw_track", (PyCFunction)py_ue_anim_sequence_add_new_raw_track, METH_VARARGS, "" },
647650
{ "update_compressed_track_map_from_raw", (PyCFunction)py_ue_anim_sequence_update_compressed_track_map_from_raw, METH_VARARGS, "" },
651+
{ "update_raw_track", (PyCFunction)py_ue_anim_sequence_update_raw_track, METH_VARARGS, "" },
652+
{ "apply_raw_anim_changes", (PyCFunction)py_ue_anim_sequence_apply_raw_anim_changes, METH_VARARGS, "" },
648653
#endif
649654
{ "add_anim_composite_section", (PyCFunction)py_ue_add_anim_composite_section, METH_VARARGS, "" },
650655
#endif

Source/UnrealEnginePython/Private/UObject/UEPyAnimSequence.cpp

Lines changed: 117 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,61 @@ PyObject *py_ue_anim_get_skeleton(ue_PyUObject * self, PyObject * args)
1818
Py_RETURN_UOBJECT((UObject *)skeleton);
1919
}
2020

21+
PyObject *py_ue_anim_get_bone_transform(ue_PyUObject * self, PyObject * args)
22+
{
23+
ue_py_check(self);
24+
25+
int track_index;
26+
float frame_time;
27+
PyObject *py_b_use_raw_data = nullptr;
28+
29+
if (!PyArg_ParseTuple(args, "if|O:get_bone_transform", &track_index, &frame_time, &py_b_use_raw_data))
30+
{
31+
return nullptr;
32+
}
33+
34+
UAnimSequence *anim = ue_py_check_type<UAnimSequence>(self);
35+
if (!anim)
36+
return PyErr_Format(PyExc_Exception, "UObject is not a UAnimSequence.");
37+
38+
bool bUseRawData = false;
39+
if (py_b_use_raw_data && PyObject_IsTrue(py_b_use_raw_data))
40+
bUseRawData = true;
41+
42+
FTransform OutAtom;
43+
anim->GetBoneTransform(OutAtom, track_index, frame_time, bUseRawData);
44+
45+
return py_ue_new_ftransform(OutAtom);
46+
}
47+
48+
PyObject *py_ue_anim_extract_root_motion(ue_PyUObject * self, PyObject * args)
49+
{
50+
ue_py_check(self);
51+
52+
float start_time;
53+
float delta_time;
54+
PyObject *py_b_allow_looping = nullptr;
55+
56+
if (!PyArg_ParseTuple(args, "ff|O:extract_root_motion", &start_time, &delta_time, &py_b_allow_looping))
57+
{
58+
return nullptr;
59+
}
60+
61+
UAnimSequence *anim = ue_py_check_type<UAnimSequence>(self);
62+
if (!anim)
63+
return PyErr_Format(PyExc_Exception, "UObject is not a UAnimSequence.");
64+
65+
bool bAllowLooping = false;
66+
if (py_b_allow_looping && PyObject_IsTrue(py_b_allow_looping))
67+
bAllowLooping = true;
68+
69+
return py_ue_new_ftransform(anim->ExtractRootMotion(start_time, delta_time, bAllowLooping));
70+
}
71+
72+
73+
74+
75+
2176

2277
#if WITH_EDITOR
2378
#if ENGINE_MINOR_VERSION > 13
@@ -73,6 +128,32 @@ PyObject *py_ue_anim_sequence_get_raw_animation_track(ue_PyUObject * self, PyObj
73128
return py_ue_new_fraw_anim_sequence_track(anim_seq->GetRawAnimationTrack(index));
74129
}
75130

131+
PyObject *py_ue_anim_sequence_apply_raw_anim_changes(ue_PyUObject * self, PyObject * args)
132+
{
133+
ue_py_check(self);
134+
135+
UAnimSequence *anim_seq = ue_py_check_type<UAnimSequence>(self);
136+
if (!anim_seq)
137+
return PyErr_Format(PyExc_Exception, "UObject is not a UAnimSequence.");
138+
139+
140+
if (anim_seq->DoesNeedRebake())
141+
{
142+
anim_seq->Modify(true);
143+
anim_seq->BakeTrackCurvesToRawAnimation();
144+
}
145+
146+
if (anim_seq->DoesNeedRecompress())
147+
{
148+
anim_seq->Modify(true);
149+
anim_seq->RequestSyncAnimRecompression(false);
150+
}
151+
152+
Py_RETURN_NONE;
153+
}
154+
155+
156+
76157
PyObject *py_ue_anim_sequence_add_new_raw_track(ue_PyUObject * self, PyObject * args)
77158
{
78159
ue_py_check(self);
@@ -105,14 +186,47 @@ PyObject *py_ue_anim_sequence_add_new_raw_track(ue_PyUObject * self, PyObject *
105186

106187
int32 index = anim_seq->AddNewRawTrack(FName(UTF8_TO_TCHAR(name)), rast);
107188

108-
if (anim_seq->DoesNeedRebake())
109-
anim_seq->BakeTrackCurvesToRawAnimation();
110-
111189
anim_seq->MarkRawDataAsModified();
190+
anim_seq->MarkPackageDirty();
112191

113192
return PyLong_FromLong(index);
114193
}
115194

195+
PyObject *py_ue_anim_sequence_update_raw_track(ue_PyUObject * self, PyObject * args)
196+
{
197+
ue_py_check(self);
198+
199+
int track_index;
200+
PyObject *py_rast;
201+
if (!PyArg_ParseTuple(args, "iO:update_raw_track", &track_index, &py_rast))
202+
return nullptr;
203+
204+
UAnimSequence *anim_seq = ue_py_check_type<UAnimSequence>(self);
205+
if (!anim_seq)
206+
return PyErr_Format(PyExc_Exception, "UObject is not a UAnimSequence.");
207+
208+
ue_PyFRawAnimSequenceTrack *py_f_rast = py_ue_is_fraw_anim_sequence_track(py_rast);
209+
if (!py_f_rast)
210+
{
211+
return PyErr_Format(PyExc_Exception, "argument is not a FRawAnimSequenceTrack.");
212+
}
213+
214+
anim_seq->Modify();
215+
216+
FRawAnimSequenceTrack& RawRef = anim_seq->GetRawAnimationTrack(track_index);
217+
218+
RawRef.PosKeys = py_f_rast->raw_anim_sequence_track.PosKeys;
219+
RawRef.RotKeys = py_f_rast->raw_anim_sequence_track.RotKeys;
220+
RawRef.ScaleKeys = py_f_rast->raw_anim_sequence_track.ScaleKeys;
221+
222+
anim_seq->MarkRawDataAsModified();
223+
anim_seq->MarkPackageDirty();
224+
225+
Py_RETURN_NONE;
226+
}
227+
228+
229+
116230
PyObject *py_ue_add_anim_composite_section(ue_PyUObject * self, PyObject * args)
117231
{
118232
ue_py_check(self);

Source/UnrealEnginePython/Private/UObject/UEPyAnimSequence.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,14 @@ PyObject *py_ue_anim_get_skeleton(ue_PyUObject *, PyObject *);
1313
PyObject *py_ue_anim_sequence_get_raw_animation_data(ue_PyUObject *, PyObject *);
1414
PyObject *py_ue_anim_sequence_get_raw_animation_track(ue_PyUObject *, PyObject *);
1515
PyObject *py_ue_anim_sequence_add_new_raw_track(ue_PyUObject *, PyObject *);
16+
PyObject *py_ue_anim_sequence_update_raw_track(ue_PyUObject *, PyObject *);
1617
PyObject *py_ue_add_anim_composite_section(ue_PyUObject *, PyObject *);
1718
PyObject *py_ue_anim_sequence_update_compressed_track_map_from_raw(ue_PyUObject *, PyObject *);
19+
PyObject *py_ue_anim_sequence_apply_raw_anim_changes(ue_PyUObject *, PyObject *);
1820
#endif
1921
PyObject *py_ue_anim_set_skeleton(ue_PyUObject *, PyObject *);
22+
PyObject *py_ue_anim_get_bone_transform(ue_PyUObject *, PyObject *);
23+
PyObject *py_ue_anim_extract_root_motion(ue_PyUObject *, PyObject *);
2024

2125
PyObject *py_ue_get_blend_parameter(ue_PyUObject *, PyObject *);
2226
PyObject *py_ue_set_blend_parameter(ue_PyUObject *, PyObject *);

0 commit comments

Comments
 (0)