|
| 1 | +#if ENGINE_MINOR_VERSION > 12 |
| 2 | +#include "UnrealEnginePythonPrivatePCH.h" |
| 3 | + |
| 4 | +#if WITH_EDITOR |
| 5 | + |
| 6 | +#include "UEPyFbx.h" |
| 7 | + |
| 8 | +static PyObject *py_ue_fbx_pose_get_count(ue_PyFbxPose *self, PyObject *args) { |
| 9 | + return PyLong_FromLong(self->fbx_pose->GetCount()); |
| 10 | +} |
| 11 | + |
| 12 | +static PyObject *py_ue_fbx_pose_get_name(ue_PyFbxPose *self, PyObject *args) { |
| 13 | + return PyUnicode_FromString(self->fbx_pose->GetName()); |
| 14 | +} |
| 15 | + |
| 16 | +static PyObject *py_ue_fbx_pose_is_bind_pose(ue_PyFbxPose *self, PyObject *args) { |
| 17 | + if (self->fbx_pose->IsBindPose()) { |
| 18 | + Py_RETURN_TRUE; |
| 19 | + } |
| 20 | + Py_RETURN_FALSE; |
| 21 | +} |
| 22 | + |
| 23 | +static PyObject *py_ue_fbx_pose_is_rest_pose(ue_PyFbxPose *self, PyObject *args) { |
| 24 | + if (self->fbx_pose->IsRestPose()) { |
| 25 | + Py_RETURN_TRUE; |
| 26 | + } |
| 27 | + Py_RETURN_FALSE; |
| 28 | +} |
| 29 | + |
| 30 | +static PyObject *py_ue_fbx_pose_get_node(ue_PyFbxPose *self, PyObject *args) { |
| 31 | + int index; |
| 32 | + if (!PyArg_ParseTuple(args, "i", &index)) { |
| 33 | + return nullptr; |
| 34 | + } |
| 35 | + FbxNode *fbx_node = self->fbx_pose->GetNode(index); |
| 36 | + if (!fbx_node) { |
| 37 | + return PyErr_Format(PyExc_Exception, "unable to retrieve FbxNode at index %d", index); |
| 38 | + } |
| 39 | + return py_ue_new_fbx_node(fbx_node); |
| 40 | +} |
| 41 | + |
| 42 | +static PyObject *py_ue_fbx_pose_find(ue_PyFbxPose *self, PyObject *args) { |
| 43 | + PyObject *py_obj; |
| 44 | + if (!PyArg_ParseTuple(args, "O", &py_obj)) { |
| 45 | + return nullptr; |
| 46 | + } |
| 47 | + |
| 48 | + ue_PyFbxNode *py_node = py_ue_is_fbx_node(py_obj); |
| 49 | + if (!py_node) |
| 50 | + return PyErr_Format(PyExc_Exception, "argument is not a FbxNode"); |
| 51 | + |
| 52 | + int index = self->fbx_pose->Find(py_node->fbx_node); |
| 53 | + if (index < 0) |
| 54 | + return PyErr_Format(PyExc_Exception, "unable to retrieve FbxNode index from FbxPose"); |
| 55 | + |
| 56 | + return PyLong_FromLong(index); |
| 57 | +} |
| 58 | + |
| 59 | +static PyObject *py_ue_fbx_pose_get_transform(ue_PyFbxPose *self, PyObject *args) { |
| 60 | + int index; |
| 61 | + if (!PyArg_ParseTuple(args, "i", &index)) { |
| 62 | + return nullptr; |
| 63 | + } |
| 64 | + |
| 65 | + FbxMatrix fbx_matrix = self->fbx_pose->GetMatrix(index); |
| 66 | + FbxAMatrix matrix = *(FbxAMatrix *)&fbx_matrix; |
| 67 | + FTransform transform; |
| 68 | + FbxVector4 mt = matrix.GetT(); |
| 69 | + FbxQuaternion mq = matrix.GetQ(); |
| 70 | + FbxVector4 ms = matrix.GetS(); |
| 71 | + transform.SetTranslation(FVector(mt[0], -mt[1], mt[2])); |
| 72 | + transform.SetRotation(FQuat(mq[0], -mq[1], mq[2], -mq[3])); |
| 73 | + transform.SetScale3D(FVector(ms[0], ms[1], ms[2])); |
| 74 | + return py_ue_new_ftransform(transform); |
| 75 | +} |
| 76 | + |
| 77 | +static PyMethodDef ue_PyFbxPose_methods[] = { |
| 78 | + { "get_count", (PyCFunction)py_ue_fbx_pose_get_count, METH_VARARGS, "" }, |
| 79 | + { "get_name", (PyCFunction)py_ue_fbx_pose_get_name, METH_VARARGS, "" }, |
| 80 | + { "get_node", (PyCFunction)py_ue_fbx_pose_get_node, METH_VARARGS, "" }, |
| 81 | + { "is_bind_pose", (PyCFunction)py_ue_fbx_pose_is_bind_pose, METH_VARARGS, "" }, |
| 82 | + { "is_rest_pose", (PyCFunction)py_ue_fbx_pose_is_rest_pose, METH_VARARGS, "" }, |
| 83 | + { "find", (PyCFunction)py_ue_fbx_pose_find, METH_VARARGS, "" }, |
| 84 | + { "get_transform", (PyCFunction)py_ue_fbx_pose_get_transform, METH_VARARGS, "" }, |
| 85 | + { NULL } /* Sentinel */ |
| 86 | +}; |
| 87 | + |
| 88 | +static PyTypeObject ue_PyFbxPoseType = { |
| 89 | + PyVarObject_HEAD_INIT(NULL, 0) |
| 90 | + "unreal_engine.FbxPose", /* tp_name */ |
| 91 | + sizeof(ue_PyFbxPose), /* tp_basicsize */ |
| 92 | + 0, /* tp_itemsize */ |
| 93 | + 0, /* tp_dealloc */ |
| 94 | + 0, /* tp_print */ |
| 95 | + 0, /* tp_getattr */ |
| 96 | + 0, /* tp_setattr */ |
| 97 | + 0, /* tp_reserved */ |
| 98 | + 0, /* tp_repr */ |
| 99 | + 0, /* tp_as_number */ |
| 100 | + 0, /* tp_as_sequence */ |
| 101 | + 0, /* tp_as_mapping */ |
| 102 | + 0, /* tp_hash */ |
| 103 | + 0, /* tp_call */ |
| 104 | + 0, /* tp_str */ |
| 105 | + 0, /* tp_getattro */ |
| 106 | + 0, /* tp_setattro */ |
| 107 | + 0, /* tp_as_buffer */ |
| 108 | + Py_TPFLAGS_DEFAULT, /* tp_flags */ |
| 109 | + "Unreal Engine FbxPose", /* tp_doc */ |
| 110 | + 0, /* tp_traverse */ |
| 111 | + 0, /* tp_clear */ |
| 112 | + 0, /* tp_richcompare */ |
| 113 | + 0, /* tp_weaklistoffset */ |
| 114 | + 0, /* tp_iter */ |
| 115 | + 0, /* tp_iternext */ |
| 116 | + ue_PyFbxPose_methods, /* tp_methods */ |
| 117 | + 0, /* tp_members */ |
| 118 | + 0, /* tp_getset */ |
| 119 | +}; |
| 120 | + |
| 121 | +static int py_ue_fbx_pose_init(ue_PyFbxPose *self, PyObject * args) { |
| 122 | + PyObject *py_object; |
| 123 | + char *name; |
| 124 | + if (!PyArg_ParseTuple(args, "Os", &py_object, &name)) { |
| 125 | + return -1; |
| 126 | + } |
| 127 | + |
| 128 | + ue_PyFbxManager *py_fbx_manager = py_ue_is_fbx_manager(py_object); |
| 129 | + if (!py_fbx_manager) { |
| 130 | + PyErr_SetString(PyExc_Exception, "argument is not a FbxManager"); |
| 131 | + return -1; |
| 132 | + } |
| 133 | + |
| 134 | + self->fbx_pose = FbxPose::Create(py_fbx_manager->fbx_manager, name); |
| 135 | + return 0; |
| 136 | +} |
| 137 | + |
| 138 | +void ue_python_init_fbx_pose(PyObject *ue_module) { |
| 139 | + ue_PyFbxPoseType.tp_new = PyType_GenericNew;; |
| 140 | + ue_PyFbxPoseType.tp_init = (initproc)py_ue_fbx_pose_init; |
| 141 | + if (PyType_Ready(&ue_PyFbxPoseType) < 0) |
| 142 | + return; |
| 143 | + |
| 144 | + Py_INCREF(&ue_PyFbxPoseType); |
| 145 | + PyModule_AddObject(ue_module, "FbxPose", (PyObject *)&ue_PyFbxPoseType); |
| 146 | +} |
| 147 | + |
| 148 | +PyObject *py_ue_new_fbx_pose(FbxPose *fbx_pose) { |
| 149 | + ue_PyFbxPose *ret = (ue_PyFbxPose *)PyObject_New(ue_PyFbxPose, &ue_PyFbxPoseType); |
| 150 | + ret->fbx_pose = fbx_pose; |
| 151 | + return (PyObject *)ret; |
| 152 | +} |
| 153 | + |
| 154 | +#endif |
| 155 | +#endif |
0 commit comments