Repository navigation
Expand file tree
/
Copy pathUEPyAnimSequence.cpp
More file actions
181 lines (132 loc) · 5.23 KB
/
Copy pathUEPyAnimSequence.cpp
File metadata and controls
181 lines (132 loc) · 5.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
#include "UnrealEnginePythonPrivatePCH.h"
#include "Animation/AnimSequence.h"
#include "Animation/BlendSpaceBase.h"
#include "Animation/AnimMontage.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;
}
ue_PyUObject *ret = ue_get_python_wrapper((UObject *)skeleton);
if (!ret)
return PyErr_Format(PyExc_Exception, "uobject is in invalid state");
Py_INCREF(ret);
return (PyObject *)ret;
}
#if WITH_EDITOR
#if ENGINE_MINOR_VERSION > 13
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_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);
if (anim_seq->DoesNeedRebake())
anim_seq->BakeTrackCurvesToRawAnimation();
anim_seq->MarkRawDataAsModified();
return PyLong_FromLong(index);
}
#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;
}
#if WITH_EDITOR
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
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_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;
}