Skip to content

Commit f678c37

Browse files
committed
Add force location & get socket local location
1 parent efd3aa0 commit f678c37

File tree

5 files changed

+81
-0
lines changed

5 files changed

+81
-0
lines changed

Source/UnrealEnginePython/Private/UEPyModule.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -945,6 +945,7 @@ static PyMethodDef ue_PyUObject_methods[] = {
945945
{ "add_impulse", (PyCFunction)py_ue_add_impulse, METH_VARARGS, "" },
946946
{ "add_angular_impulse", (PyCFunction)py_ue_add_angular_impulse, METH_VARARGS, "" },
947947
{ "add_force", (PyCFunction)py_ue_add_force, METH_VARARGS, "" },
948+
{ "add_force_location", (PyCFunction)py_ue_add_force_location, METH_VARARGS, "" },
948949
{ "add_force_location_local", (PyCFunction)py_ue_add_force_location_local, METH_VARARGS, "" },
949950
{ "add_torque", (PyCFunction)py_ue_add_torque, METH_VARARGS, "" },
950951
{ "set_physics_linear_velocity", (PyCFunction)py_ue_set_physics_linear_velocity, METH_VARARGS, "" },
@@ -1035,6 +1036,7 @@ static PyMethodDef ue_PyUObject_methods[] = {
10351036
// Attaching
10361037

10371038
{ "get_socket_location", (PyCFunction)py_ue_get_socket_location, METH_VARARGS, "" },
1039+
{ "get_socket_location_local", (PyCFunction)py_ue_get_socket_location_local, METH_VARARGS, "" },
10381040
{ "get_socket_rotation", (PyCFunction)py_ue_get_socket_rotation, METH_VARARGS, "" },
10391041
{ "get_socket_transform", (PyCFunction)py_ue_get_socket_transform, METH_VARARGS, "" },
10401042
{ "get_socket_world_transform", (PyCFunction)py_ue_get_socket_world_transform, METH_VARARGS, "" },

Source/UnrealEnginePython/Private/UObject/UEPyAttaching.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,27 @@ PyObject *py_ue_get_socket_location(ue_PyUObject *self, PyObject * args)
2323
return py_ue_new_fvector(vec);
2424
}
2525

26+
PyObject* py_ue_get_socket_location_local(ue_PyUObject* self, PyObject* args)
27+
{
28+
29+
ue_py_check(self);
30+
31+
char* socket_name;
32+
if (!PyArg_ParseTuple(args, "s:get_socket_location_local", &socket_name))
33+
{
34+
return NULL;
35+
}
36+
37+
if (!self->ue_object->IsA<USceneComponent>())
38+
return PyErr_Format(PyExc_Exception, "uobject is not a USceneComponent");
39+
40+
USceneComponent* component = (USceneComponent*)self->ue_object;
41+
42+
FTransform transform = component->GetSocketTransform(UTF8_TO_TCHAR(socket_name), ERelativeTransformSpace::RTS_Component);
43+
return py_ue_new_fvector(transform.GetTranslation());
44+
}
45+
46+
2647
PyObject *py_ue_get_socket_rotation(ue_PyUObject *self, PyObject * args)
2748
{
2849

Source/UnrealEnginePython/Private/UObject/UEPyAttaching.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "UEPyModule.h"
66

77
PyObject *py_ue_get_socket_location(ue_PyUObject *, PyObject *);
8+
PyObject* py_ue_get_socket_location_local(ue_PyUObject*, PyObject*);
89
PyObject *py_ue_get_socket_rotation(ue_PyUObject *, PyObject *);
910
PyObject *py_ue_get_socket_transform(ue_PyUObject *, PyObject *);
1011
PyObject *py_ue_get_socket_world_transform(ue_PyUObject *, PyObject *);

Source/UnrealEnginePython/Private/UObject/UEPyPhysics.cpp

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,62 @@ PyObject *py_ue_add_force(ue_PyUObject * self, PyObject * args)
200200
return Py_None;
201201
}
202202

203+
PyObject* py_ue_add_force_location(ue_PyUObject* self, PyObject* args)
204+
{
205+
206+
ue_py_check(self);
207+
208+
PyObject* py_obj_force = nullptr;
209+
PyObject* py_obj_location = nullptr;
210+
char* bone_name = nullptr;
211+
212+
if (!PyArg_ParseTuple(args, "O|Os:add_force_location_local", &py_obj_force, &py_obj_location, &bone_name))
213+
{
214+
return nullptr;
215+
}
216+
217+
UPrimitiveComponent* primitive = nullptr;
218+
219+
if (self->ue_object->IsA<UPrimitiveComponent>())
220+
{
221+
primitive = (UPrimitiveComponent*)self->ue_object;
222+
}
223+
else
224+
{
225+
return PyErr_Format(PyExc_Exception, "uobject is not an UPrimitiveComponent");
226+
}
227+
228+
FVector force = FVector(0, 0, 0);
229+
if (py_obj_force)
230+
{
231+
ue_PyFVector* py_force = py_ue_is_fvector(py_obj_force);
232+
if (!py_force)
233+
return PyErr_Format(PyExc_Exception, "force must be a FVector");
234+
force = py_force->vec;
235+
}
236+
237+
FVector location = FVector(0, 0, 0);
238+
if (py_obj_location)
239+
{
240+
ue_PyFVector* py_location = py_ue_is_fvector(py_obj_location);
241+
if (!py_location)
242+
return PyErr_Format(PyExc_Exception, "location must be a FVector");
243+
location = py_location->vec;
244+
}
245+
246+
FName f_bone_name = NAME_None;
247+
if (bone_name)
248+
{
249+
f_bone_name = FName(UTF8_TO_TCHAR(bone_name));
250+
}
251+
252+
primitive->AddForceAtLocation(force, location, f_bone_name);
253+
254+
255+
Py_INCREF(Py_None);
256+
return Py_None;
257+
}
258+
203259
PyObject* py_ue_add_force_location_local(ue_PyUObject* self, PyObject* args)
204260
{
205261

Source/UnrealEnginePython/Private/UObject/UEPyPhysics.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ PyObject *py_ue_set_simulate_physics(ue_PyUObject *, PyObject *);
88
PyObject *py_ue_add_impulse(ue_PyUObject *, PyObject *);
99
PyObject *py_ue_add_angular_impulse(ue_PyUObject *, PyObject *);
1010
PyObject *py_ue_add_force(ue_PyUObject *, PyObject *);
11+
PyObject* py_ue_add_force_location(ue_PyUObject*, PyObject*);
1112
PyObject* py_ue_add_force_location_local(ue_PyUObject*, PyObject*);
1213
PyObject *py_ue_add_torque(ue_PyUObject *, PyObject *);
1314
PyObject *py_ue_set_physics_linear_velocity(ue_PyUObject *, PyObject *);

0 commit comments

Comments
 (0)