Skip to content

Commit 343c68d

Browse files
author
Roberto De Ioris
committed
improved FTransform usability
1 parent 810db73 commit 343c68d

File tree

3 files changed

+45
-2
lines changed

3 files changed

+45
-2
lines changed

Source/UnrealEnginePython/Private/Wrappers/UEPyFQuat.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ static PyMethodDef ue_PyFQuat_methods[] = {
4444
{ "angular_distance", (PyCFunction)py_ue_fquat_angular_distance, METH_VARARGS, "" },
4545
#endif
4646
{ "euler", (PyCFunction)py_ue_fquat_euler, METH_VARARGS, "" },
47+
{ "rotator", (PyCFunction)py_ue_fquat_euler, METH_VARARGS, "" },
4748
{ "get_axis_x", (PyCFunction)py_ue_fquat_get_axis_x, METH_VARARGS, "" },
4849
{ "get_axis_y", (PyCFunction)py_ue_fquat_get_axis_y, METH_VARARGS, "" },
4950
{ "get_axis_z", (PyCFunction)py_ue_fquat_get_axis_z, METH_VARARGS, "" },

Source/UnrealEnginePython/Private/Wrappers/UEPyFTransform.cpp

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,45 @@ static int ue_py_ftransform_init(ue_PyFTransform *self, PyObject *args, PyObject
178178
}
179179
else
180180
{
181-
PyErr_SetString(PyExc_Exception, "argument is not a FVector");
181+
PyObject *py_iter = PyObject_GetIter(py_translation);
182+
if (py_iter)
183+
{
184+
FMatrix matrix;
185+
for (int row = 0; row < 4; row++)
186+
{
187+
for (int column = 0; column < 4; column++)
188+
{
189+
PyObject *py_item = PyIter_Next(py_iter);
190+
if (!py_item)
191+
{
192+
PyErr_SetString(PyExc_Exception, "matrix is not 4x4");
193+
Py_DECREF(py_iter);
194+
return -1;
195+
}
196+
197+
if (!PyNumber_Check(py_item))
198+
{
199+
PyErr_SetString(PyExc_Exception, "matrix can contains only float");
200+
Py_DECREF(py_iter);
201+
return -1;
202+
}
203+
204+
PyObject *py_num = PyNumber_Float(py_item);
205+
if (!py_num)
206+
{
207+
PyErr_SetString(PyExc_Exception, "matrix can contains only float");
208+
Py_DECREF(py_iter);
209+
return -1;
210+
}
211+
matrix.M[row][column] = PyFloat_AsDouble(py_num);
212+
Py_DECREF(py_num);
213+
}
214+
}
215+
self->transform.SetFromMatrix(matrix);
216+
Py_DECREF(py_iter);
217+
return 0;
218+
}
219+
PyErr_SetString(PyExc_Exception, "argument is not a FVector or a 4x4 float matrix");
182220
return -1;
183221
}
184222
}
@@ -230,13 +268,17 @@ static PyObject *ue_py_ftransform_mul(ue_PyFTransform *self, PyObject *value)
230268
{
231269
t *= py_quat->quat;
232270
}
271+
else if (ue_PyFRotator *py_rot = py_ue_is_frotator(value))
272+
{
273+
t *= py_rot->rot.Quaternion();
274+
}
233275
else if (ue_PyFTransform *py_transform = py_ue_is_ftransform(value))
234276
{
235277
t *= py_transform->transform;
236278
}
237279
else
238280
{
239-
return PyErr_Format(PyExc_TypeError, "FTransform can be multiplied only for an FQuat or an FTransform");
281+
return PyErr_Format(PyExc_TypeError, "FTransform can be multiplied only for an FQuat, an FRotator or an FTransform");
240282
}
241283
return py_ue_new_ftransform(t);
242284
}
1.1 MB
Loading

0 commit comments

Comments
 (0)