Skip to content

Commit 49bd60a

Browse files
author
Roberto De Ioris
committed
added new transform optimization functions
1 parent b2bdca8 commit 49bd60a

7 files changed

Lines changed: 142 additions & 2 deletions

File tree

‎Source/UnrealEnginePython/Private/UEPyModule.cpp‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,7 @@ static PyMethodDef ue_PyUObject_methods[] = {
322322
{ "get_actor_location", (PyCFunction)py_ue_get_actor_location, METH_VARARGS, "" },
323323
{ "get_actor_rotation", (PyCFunction)py_ue_get_actor_rotation, METH_VARARGS, "" },
324324
{ "get_actor_scale", (PyCFunction)py_ue_get_actor_scale, METH_VARARGS, "" },
325+
{ "get_actor_transform", (PyCFunction)py_ue_get_actor_transform, METH_VARARGS, "" },
325326

326327
{ "get_actor_forward", (PyCFunction)py_ue_get_actor_forward, METH_VARARGS, "" },
327328
{ "get_actor_right", (PyCFunction)py_ue_get_actor_right, METH_VARARGS, "" },
@@ -331,6 +332,7 @@ static PyMethodDef ue_PyUObject_methods[] = {
331332
{ "set_actor_location", (PyCFunction)py_ue_set_actor_location, METH_VARARGS, "" },
332333
{ "set_actor_rotation", (PyCFunction)py_ue_set_actor_rotation, METH_VARARGS, "" },
333334
{ "set_actor_scale", (PyCFunction)py_ue_set_actor_scale, METH_VARARGS, "" },
335+
{ "set_actor_transform", (PyCFunction)py_ue_set_actor_transform, METH_VARARGS, "" },
334336

335337
{ "add_actor_world_offset", (PyCFunction)py_ue_add_actor_world_offset, METH_VARARGS, "" },
336338
{ "add_actor_local_offset", (PyCFunction)py_ue_add_actor_local_offset, METH_VARARGS, "" },
@@ -341,16 +343,20 @@ static PyMethodDef ue_PyUObject_methods[] = {
341343
{ "get_world_location", (PyCFunction)py_ue_get_world_location, METH_VARARGS, "" },
342344
{ "get_world_rotation", (PyCFunction)py_ue_get_world_rotation, METH_VARARGS, "" },
343345
{ "get_world_scale", (PyCFunction)py_ue_get_world_scale, METH_VARARGS, "" },
346+
{ "get_world_transform", (PyCFunction)py_ue_get_world_transform, METH_VARARGS, "" },
344347
{ "get_relative_location", (PyCFunction)py_ue_get_relative_location, METH_VARARGS, "" },
345348
{ "get_relative_rotation", (PyCFunction)py_ue_get_relative_rotation, METH_VARARGS, "" },
346349
{ "get_relative_scale", (PyCFunction)py_ue_get_relative_scale, METH_VARARGS, "" },
350+
{ "get_relative_transform", (PyCFunction)py_ue_get_relative_transform, METH_VARARGS, "" },
347351

348352
{ "set_world_location", (PyCFunction)py_ue_set_world_location, METH_VARARGS, "" },
349353
{ "set_world_rotation", (PyCFunction)py_ue_set_world_rotation, METH_VARARGS, "" },
350354
{ "set_world_scale", (PyCFunction)py_ue_set_world_scale, METH_VARARGS, "" },
355+
{ "set_world_transform", (PyCFunction)py_ue_set_world_transform, METH_VARARGS, "" },
351356
{ "set_relative_location", (PyCFunction)py_ue_set_relative_location, METH_VARARGS, "" },
352357
{ "set_relative_rotation", (PyCFunction)py_ue_set_relative_rotation, METH_VARARGS, "" },
353358
{ "set_relative_scale", (PyCFunction)py_ue_set_relative_scale, METH_VARARGS, "" },
359+
{ "set_relative_transform", (PyCFunction)py_ue_set_relative_transform, METH_VARARGS, "" },
354360

355361
{ "get_forward_vector", (PyCFunction)py_ue_get_forward_vector, METH_VARARGS, "" },
356362
{ "get_up_vector", (PyCFunction)py_ue_get_up_vector, METH_VARARGS, "" },
@@ -646,6 +652,8 @@ static PyMethodDef ue_PyUObject_methods[] = {
646652
{ "skeleton_bones_get_num", (PyCFunction)py_ue_skeleton_bones_get_num, METH_VARARGS, "" },
647653
{ "skeleton_get_bone_name", (PyCFunction)py_ue_skeleton_get_bone_name, METH_VARARGS, "" },
648654
{ "skeleton_find_bone_index", (PyCFunction)py_ue_skeleton_find_bone_index, METH_VARARGS, "" },
655+
{ "skeleton_get_ref_bone_pose", (PyCFunction)py_ue_skeleton_get_ref_bone_pose, METH_VARARGS, "" },
656+
649657

650658
// Timer
651659
{ "set_timer", (PyCFunction)py_ue_set_timer, METH_VARARGS, "" },

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,3 +119,20 @@ PyObject *py_ue_skeleton_find_bone_index(ue_PyUObject *self, PyObject * args) {
119119
return PyLong_FromLong(index);
120120
}
121121

122+
PyObject *py_ue_skeleton_get_ref_bone_pose(ue_PyUObject *self, PyObject * args) {
123+
124+
ue_py_check(self);
125+
126+
int index;
127+
if (!PyArg_ParseTuple(args, "i:skeleton_get_ref_bone_pose", &index))
128+
return nullptr;
129+
130+
USkeleton *skeleton = ue_py_check_type<USkeleton>(self);
131+
if (!skeleton)
132+
return PyErr_Format(PyExc_Exception, "uobject is not a USkeleton");
133+
134+
if (!skeleton->GetReferenceSkeleton().IsValidIndex(index))
135+
return PyErr_Format(PyExc_Exception, "invalid bone index");
136+
137+
return py_ue_new_ftransform(skeleton->GetReferenceSkeleton().GetRefBonePose()[index]);
138+
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ PyObject *py_ue_set_skeletal_mesh(ue_PyUObject *, PyObject *);
1010
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 *);
13-
PyObject *py_ue_skeleton_find_bone_index(ue_PyUObject *, PyObject *);
13+
PyObject *py_ue_skeleton_find_bone_index(ue_PyUObject *, PyObject *);
14+
PyObject *py_ue_skeleton_get_ref_bone_pose(ue_PyUObject *, PyObject *);

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

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,18 @@ PyObject *py_ue_get_actor_scale(ue_PyUObject *self, PyObject * args) {
2626

2727
}
2828

29+
PyObject *py_ue_get_actor_transform(ue_PyUObject *self, PyObject * args) {
30+
31+
ue_py_check(self);
32+
33+
AActor *actor = ue_get_actor(self);
34+
if (!actor)
35+
return PyErr_Format(PyExc_Exception, "uobject is not an actor or a component");
36+
37+
return py_ue_new_ftransform(actor->GetActorTransform());
38+
39+
}
40+
2941
PyObject *py_ue_get_actor_forward(ue_PyUObject *self, PyObject * args) {
3042

3143
ue_py_check(self);
@@ -199,6 +211,24 @@ PyObject *py_ue_set_actor_rotation(ue_PyUObject *self, PyObject * args) {
199211
}
200212

201213

214+
PyObject *py_ue_set_actor_transform(ue_PyUObject *self, PyObject * args) {
215+
216+
ue_py_check(self);
217+
218+
FTransform t;
219+
if (!py_ue_transform_arg(args, t))
220+
return nullptr;
221+
222+
AActor *actor = ue_get_actor(self);
223+
if (!actor)
224+
PyErr_Format(PyExc_Exception, "uobject is not an actor or a component");
225+
226+
actor->SetActorTransform(t);
227+
228+
Py_RETURN_NONE;
229+
}
230+
231+
202232
PyObject *py_ue_get_world_location(ue_PyUObject *self, PyObject * args) {
203233
ue_py_check(self);
204234
if (self->ue_object->IsA<USceneComponent>()) {
@@ -253,6 +283,26 @@ PyObject *py_ue_get_relative_scale(ue_PyUObject *self, PyObject * args) {
253283
return PyErr_Format(PyExc_Exception, "uobject is not a USceneComponent");
254284
}
255285

286+
PyObject *py_ue_get_relative_transform(ue_PyUObject *self, PyObject * args) {
287+
ue_py_check(self);
288+
USceneComponent *component = ue_py_check_type<USceneComponent>(self);
289+
if (!component)
290+
return PyErr_Format(PyExc_Exception, "uobject is not a USceneComponent");
291+
292+
FTransform t = component->GetRelativeTransform();
293+
return py_ue_new_ftransform(t);
294+
}
295+
296+
PyObject *py_ue_get_world_transform(ue_PyUObject *self, PyObject * args) {
297+
ue_py_check(self);
298+
USceneComponent *component = ue_py_check_type<USceneComponent>(self);
299+
if (!component)
300+
return PyErr_Format(PyExc_Exception, "uobject is not a USceneComponent");
301+
302+
FTransform t = component->GetComponentTransform();
303+
return py_ue_new_ftransform(t);
304+
}
305+
256306
PyObject *py_ue_get_forward_vector(ue_PyUObject *self, PyObject * args) {
257307
ue_py_check(self);
258308
if (self->ue_object->IsA<USceneComponent>()) {
@@ -321,6 +371,38 @@ PyObject *py_ue_set_world_scale(ue_PyUObject *self, PyObject * args) {
321371
return PyErr_Format(PyExc_Exception, "uobject is not a USceneComponent");
322372
}
323373

374+
PyObject *py_ue_set_world_transform(ue_PyUObject *self, PyObject * args) {
375+
ue_py_check(self);
376+
377+
FTransform t;
378+
379+
if (!py_ue_transform_arg(args, t))
380+
return nullptr;
381+
382+
USceneComponent *component = ue_py_check_type<USceneComponent>(self);
383+
if (!component)
384+
return PyErr_Format(PyExc_Exception, "uobject is not a USceneComponent");
385+
386+
component->SetWorldTransform(t);
387+
Py_RETURN_NONE;
388+
}
389+
390+
PyObject *py_ue_set_relative_transform(ue_PyUObject *self, PyObject * args) {
391+
ue_py_check(self);
392+
393+
FTransform t;
394+
395+
if (!py_ue_transform_arg(args, t))
396+
return nullptr;
397+
398+
USceneComponent *component = ue_py_check_type<USceneComponent>(self);
399+
if (!component)
400+
return PyErr_Format(PyExc_Exception, "uobject is not a USceneComponent");
401+
402+
component->SetRelativeTransform(t);
403+
Py_RETURN_NONE;
404+
}
405+
324406
PyObject *py_ue_set_relative_location(ue_PyUObject *self, PyObject * args) {
325407
ue_py_check(self);
326408
FVector vec;

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
PyObject *py_ue_get_actor_location(ue_PyUObject *, PyObject *);
88
PyObject *py_ue_get_actor_rotation(ue_PyUObject *, PyObject *);
99
PyObject *py_ue_get_actor_scale(ue_PyUObject *, PyObject *);
10+
PyObject *py_ue_get_actor_transform(ue_PyUObject *, PyObject *);
1011

1112
PyObject *py_ue_get_actor_forward(ue_PyUObject *, PyObject *);
1213
PyObject *py_ue_get_actor_right(ue_PyUObject *, PyObject *);
@@ -17,6 +18,7 @@ PyObject *py_ue_get_actor_up(ue_PyUObject *, PyObject *);
1718
PyObject *py_ue_set_actor_rotation(ue_PyUObject *, PyObject *);
1819
PyObject *py_ue_set_actor_location(ue_PyUObject *, PyObject *);
1920
PyObject *py_ue_set_actor_scale(ue_PyUObject *, PyObject *);
21+
PyObject *py_ue_set_actor_transform(ue_PyUObject *, PyObject *);
2022

2123
PyObject *py_ue_add_actor_world_offset(ue_PyUObject *, PyObject *);
2224
PyObject *py_ue_add_actor_local_offset(ue_PyUObject *, PyObject *);
@@ -28,16 +30,20 @@ PyObject *py_ue_add_actor_local_rotation(ue_PyUObject *, PyObject *);
2830
PyObject *py_ue_get_world_location(ue_PyUObject *, PyObject *);
2931
PyObject *py_ue_get_world_rotation(ue_PyUObject *, PyObject *);
3032
PyObject *py_ue_get_world_scale(ue_PyUObject *, PyObject *);
33+
PyObject *py_ue_get_world_transform(ue_PyUObject *, PyObject *);
3134
PyObject *py_ue_get_relative_location(ue_PyUObject *, PyObject *);
3235
PyObject *py_ue_get_relative_rotation(ue_PyUObject *, PyObject *);
3336
PyObject *py_ue_get_relative_scale(ue_PyUObject *, PyObject *);
37+
PyObject *py_ue_get_relative_transform(ue_PyUObject *, PyObject *);
3438

3539
PyObject *py_ue_set_world_location(ue_PyUObject *, PyObject *);
3640
PyObject *py_ue_set_world_rotation(ue_PyUObject *, PyObject *);
3741
PyObject *py_ue_set_world_scale(ue_PyUObject *, PyObject *);
42+
PyObject *py_ue_set_world_transform(ue_PyUObject *, PyObject *);
3843
PyObject *py_ue_set_relative_location(ue_PyUObject *, PyObject *);
3944
PyObject *py_ue_set_relative_rotation(ue_PyUObject *, PyObject *);
4045
PyObject *py_ue_set_relative_scale(ue_PyUObject *, PyObject *);
46+
PyObject *py_ue_set_relative_transform(ue_PyUObject *, PyObject *);
4147

4248
PyObject *py_ue_get_forward_vector(ue_PyUObject *, PyObject *);
4349
PyObject *py_ue_get_up_vector(ue_PyUObject *, PyObject *);

‎Source/UnrealEnginePython/Private/Wrappers/UEPyFTransform.cpp‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,3 +144,28 @@ ue_PyFTransform *py_ue_is_ftransform(PyObject *obj) {
144144
return nullptr;
145145
return (ue_PyFTransform *)obj;
146146
}
147+
148+
bool py_ue_transform_arg(PyObject *args, FTransform &t) {
149+
150+
if (PyTuple_Size(args) == 1) {
151+
PyObject *arg = PyTuple_GetItem(args, 0);
152+
ue_PyFTransform *py_t = py_ue_is_ftransform(arg);
153+
if (!py_t) {
154+
PyErr_Format(PyExc_TypeError, "argument is not a FTransform");
155+
return false;
156+
}
157+
t = py_t->transform;
158+
return true;
159+
}
160+
161+
float x, y, z;
162+
float roll, pitch, yaw;
163+
float sx, sy, sz;
164+
if (!PyArg_ParseTuple(args, "fffffffff", &x, &y, &z, &roll, &pitch, &yaw, &sx, &sy, &sz))
165+
return false;
166+
167+
t.SetLocation(FVector(x, y, z));
168+
t.SetRotation(FRotator(pitch, yaw, roll).Quaternion());
169+
t.SetScale3D(FVector(sx, sy, sz));
170+
return true;
171+
}

‎Source/UnrealEnginePython/Private/Wrappers/UEPyFTransform.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@ typedef struct {
1313
PyObject *py_ue_new_ftransform(FTransform);
1414
ue_PyFTransform *py_ue_is_ftransform(PyObject *);
1515

16-
void ue_python_init_ftransform(PyObject *);
16+
void ue_python_init_ftransform(PyObject *);
17+
bool py_ue_transform_arg(PyObject *, FTransform &);

0 commit comments

Comments
 (0)