Skip to content

Commit b3cdb3b

Browse files
author
Roberto De Ioris
committed
preliminary support for skeleton manipulation
1 parent b2cfe93 commit b3cdb3b

3 files changed

Lines changed: 37 additions & 2 deletions

File tree

Source/UnrealEnginePython/Private/UEPyModule.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -654,6 +654,8 @@ static PyMethodDef ue_PyUObject_methods[] = {
654654
{ "skeleton_find_bone_index", (PyCFunction)py_ue_skeleton_find_bone_index, METH_VARARGS, "" },
655655
{ "skeleton_get_ref_bone_pose", (PyCFunction)py_ue_skeleton_get_ref_bone_pose, METH_VARARGS, "" },
656656

657+
{ "skeleton_add_bone", (PyCFunction)py_ue_skeleton_add_bone, METH_VARARGS, "" },
658+
657659

658660
// Timer
659661
{ "set_timer", (PyCFunction)py_ue_set_timer, METH_VARARGS, "" },

Source/UnrealEnginePython/Private/UObject/UEPySkeletal.cpp

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ PyObject *py_ue_get_anim_instance(ue_PyUObject *self, PyObject * args) {
88

99
if (!self->ue_object->IsA<USkeletalMeshComponent>())
1010
return PyErr_Format(PyExc_Exception, "uobject is not a USkeletalMeshComponent");
11-
11+
1212
USkeletalMeshComponent *skeletal = (USkeletalMeshComponent *)self->ue_object;
1313

1414
UAnimInstance *anim = skeletal->GetAnimInstance();
@@ -135,4 +135,36 @@ PyObject *py_ue_skeleton_get_ref_bone_pose(ue_PyUObject *self, PyObject * args)
135135
return PyErr_Format(PyExc_Exception, "invalid bone index");
136136

137137
return py_ue_new_ftransform(skeleton->GetReferenceSkeleton().GetRefBonePose()[index]);
138+
}
139+
140+
PyObject *py_ue_skeleton_add_bone(ue_PyUObject *self, PyObject * args) {
141+
142+
ue_py_check(self);
143+
144+
char *name;
145+
int parent_index;
146+
PyObject *py_transform;
147+
if (!PyArg_ParseTuple(args, "siO:skeleton_add_bone", &name, &parent_index, &py_transform))
148+
return nullptr;
149+
150+
USkeleton *skeleton = ue_py_check_type<USkeleton>(self);
151+
if (!skeleton)
152+
return PyErr_Format(PyExc_Exception, "uobject is not a USkeleton");
153+
154+
skeleton->PreEditChange(nullptr);
155+
156+
{
157+
const FReferenceSkeleton &ref = skeleton->GetReferenceSkeleton();
158+
// horrible hack to modify the skeleton in place
159+
FReferenceSkeletonModifier modifier((FReferenceSkeleton &)ref, skeleton);
160+
161+
TCHAR *bone_name = UTF8_TO_TCHAR(name);
162+
163+
modifier.Add(FMeshBoneInfo(FName(bone_name), FString(bone_name), parent_index), FTransform());
164+
}
165+
166+
skeleton->PostEditChange();
167+
skeleton->MarkPackageDirty();
168+
169+
Py_RETURN_NONE;
138170
}

Source/UnrealEnginePython/Private/UObject/UEPySkeletal.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@ PyObject *py_ue_skeleton_get_parent_index(ue_PyUObject *, PyObject *);
1111
PyObject *py_ue_skeleton_bones_get_num(ue_PyUObject *, PyObject *);
1212
PyObject *py_ue_skeleton_get_bone_name(ue_PyUObject *, PyObject *);
1313
PyObject *py_ue_skeleton_find_bone_index(ue_PyUObject *, PyObject *);
14-
PyObject *py_ue_skeleton_get_ref_bone_pose(ue_PyUObject *, PyObject *);
14+
PyObject *py_ue_skeleton_get_ref_bone_pose(ue_PyUObject *, PyObject *);
15+
PyObject *py_ue_skeleton_add_bone(ue_PyUObject *, PyObject *);

0 commit comments

Comments
 (0)