Skip to content

Commit d56cea0

Browse files
author
Roberto De Ioris
committed
improved animation api, added AnimMontage sections support
1 parent 5e0879d commit d56cea0

3 files changed

Lines changed: 34 additions & 17 deletions

File tree

‎Source/UnrealEnginePython/Private/UEPyModule.cpp‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -461,8 +461,10 @@ static PyMethodDef ue_PyUObject_methods[] = {
461461
#endif
462462

463463
// AnimSequence
464-
{ "anim_sequence_get_skeleton", (PyCFunction)py_ue_anim_sequence_get_skeleton, METH_VARARGS, "" },
465-
{ "anim_sequence_set_skeleton", (PyCFunction)py_ue_anim_sequence_set_skeleton, METH_VARARGS, "" },
464+
{ "anim_get_skeleton", (PyCFunction)py_ue_anim_get_skeleton, METH_VARARGS, "" },
465+
{ "anim_set_skeleton", (PyCFunction)py_ue_anim_set_skeleton, METH_VARARGS, "" },
466+
467+
{ "add_anim_composite_section", (PyCFunction)py_ue_add_anim_composite_section, METH_VARARGS, "" },
466468

467469
#if WITH_EDITOR
468470
{ "get_raw_animation_data", (PyCFunction)py_ue_anim_sequence_get_raw_animation_data, METH_VARARGS, "" },

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

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,16 @@
22
#include "Animation/AnimSequence.h"
33
#include "Animation/BlendSpaceBase.h"
44

5-
PyObject *py_ue_anim_sequence_get_skeleton(ue_PyUObject * self, PyObject * args) {
5+
PyObject *py_ue_anim_get_skeleton(ue_PyUObject * self, PyObject * args) {
66
ue_py_check(self);
77

8-
UAnimSequence *anim_seq = ue_py_check_type<UAnimSequence>(self);
9-
if (!anim_seq)
10-
return PyErr_Format(PyExc_Exception, "UObject is not a UAnimSequence.");
8+
UAnimationAsset *anim = ue_py_check_type<UAnimationAsset>(self);
9+
if (!anim)
10+
return PyErr_Format(PyExc_Exception, "UObject is not a UAnimationAsset.");
1111

12-
USkeleton *skeleton = anim_seq->GetSkeleton();
12+
USkeleton *skeleton = anim->GetSkeleton();
1313
if (!skeleton) {
14-
Py_INCREF(Py_None);
15-
return Py_None;
14+
Py_RETURN_NONE;
1615
}
1716

1817
ue_PyUObject *ret = ue_get_python_wrapper((UObject *)skeleton);
@@ -96,22 +95,37 @@ PyObject *py_ue_anim_sequence_add_new_raw_track(ue_PyUObject * self, PyObject *
9695
}
9796
#endif
9897

99-
PyObject *py_ue_anim_sequence_set_skeleton(ue_PyUObject * self, PyObject * args) {
98+
PyObject *py_ue_anim_set_skeleton(ue_PyUObject * self, PyObject * args) {
10099
ue_py_check(self);
101100

102101
PyObject *py_skeleton;
103-
if (!PyArg_ParseTuple(args, "O:anim_sequence_set_skeleton", &py_skeleton))
102+
if (!PyArg_ParseTuple(args, "O:anim_set_skeleton", &py_skeleton))
104103
return nullptr;
105104

106-
UAnimSequence *anim_seq = ue_py_check_type<UAnimSequence>(self);
107-
if (!anim_seq)
108-
return PyErr_Format(PyExc_Exception, "UObject is not a UAnimSequence.");
105+
UAnimationAsset *anim = ue_py_check_type<UAnimationAsset>(self);
106+
if (!anim)
107+
return PyErr_Format(PyExc_Exception, "UObject is not a UAnimationAsset.");
109108

110109
USkeleton *skeleton = ue_py_check_type<USkeleton>(py_skeleton);
111110
if (!skeleton)
112111
return PyErr_Format(PyExc_Exception, "argument is not a USkeleton.");
113112

114-
anim_seq->SetSkeleton(skeleton);
113+
anim->SetSkeleton(skeleton);
115114

116115
Py_RETURN_NONE;
117116
}
117+
118+
PyObject *py_ue_add_anim_composite_section(ue_PyUObject * self, PyObject * args) {
119+
ue_py_check(self);
120+
121+
char *name;
122+
float time;
123+
if (!PyArg_ParseTuple(args, "sf:add_anim_composite_section", &name, &time))
124+
return nullptr;
125+
126+
UAnimMontage *anim = ue_py_check_type<UAnimMontage>(self);
127+
if (!anim)
128+
return PyErr_Format(PyExc_Exception, "UObject is not a UAnimMontage.");
129+
130+
return PyLong_FromLong(anim->AddAnimCompositeSection(FName(UTF8_TO_TCHAR(name)), time));
131+
}

‎Source/UnrealEnginePython/Private/UObject/UEPyAnimSequence.h‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@
44

55
#include "UnrealEnginePython.h"
66

7-
PyObject *py_ue_anim_sequence_get_skeleton(ue_PyUObject *, PyObject *);
7+
PyObject *py_ue_anim_get_skeleton(ue_PyUObject *, PyObject *);
88

99
#if WITH_EDITOR
1010
PyObject *py_ue_anim_sequence_get_raw_animation_data(ue_PyUObject *, PyObject *);
1111
PyObject *py_ue_anim_sequence_get_raw_animation_track(ue_PyUObject *, PyObject *);
1212
PyObject *py_ue_anim_sequence_add_new_raw_track(ue_PyUObject *, PyObject *);
1313
#endif
14-
PyObject *py_ue_anim_sequence_set_skeleton(ue_PyUObject *, PyObject *);
14+
PyObject *py_ue_anim_set_skeleton(ue_PyUObject *, PyObject *);
15+
PyObject *py_ue_add_anim_composite_section(ue_PyUObject *, PyObject *);

0 commit comments

Comments
 (0)