Skip to content

Commit f024fa0

Browse files
author
Roberto De Ioris
committed
added preliminary support for FRawMesh
1 parent 9187a3a commit f024fa0

7 files changed

Lines changed: 297 additions & 0 deletions

File tree

‎Source/UnrealEnginePython/Private/UEPyModule.cpp‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "UEPyMovements.h"
1515
#include "UEPyAttaching.h"
1616
#include "UEPySkeletal.h"
17+
#include "UEPyStaticMesh.h"
1718
#include "UEPyTraceAndSweep.h"
1819
#include "UEPyTimer.h"
1920
#include "UEPyTicker.h"
@@ -434,6 +435,12 @@ static PyMethodDef ue_PyUObject_methods[] = {
434435
{ "anim_sequence_get_skeleton", (PyCFunction)py_ue_anim_sequence_get_skeleton, METH_VARARGS, "" },
435436
#endif
436437

438+
// StaticMesh
439+
#if WITH_EDITOR
440+
{ "static_mesh_build", (PyCFunction)py_ue_static_mesh_build, METH_VARARGS, "" },
441+
{ "static_mesh_create_body_setup", (PyCFunction)py_ue_static_mesh_create_body_setup, METH_VARARGS, "" },
442+
#endif
443+
437444
// Input
438445

439446
{ "get_input_axis", (PyCFunction)py_ue_get_input_axis, METH_VARARGS, "" },
@@ -1240,6 +1247,7 @@ void unreal_engine_init_py_module() {
12401247
ue_python_init_farfilter(new_unreal_engine_module);
12411248
ue_python_init_fassetdata(new_unreal_engine_module);
12421249
ue_python_init_edgraphpin(new_unreal_engine_module);
1250+
ue_python_init_fraw_mesh(new_unreal_engine_module);
12431251
ue_python_init_iplugin(new_unreal_engine_module);
12441252
#endif
12451253

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#include "UnrealEnginePythonPrivatePCH.h"
2+
3+
#if WITH_EDITOR
4+
5+
PyObject *py_ue_static_mesh_build(ue_PyUObject *self, PyObject * args) {
6+
7+
ue_py_check(self);
8+
9+
UStaticMesh *mesh = ue_py_check_type<UStaticMesh>(self);
10+
if (!mesh)
11+
return PyErr_Format(PyExc_Exception, "uobject is not a UStaticMesh");
12+
13+
mesh->Build();
14+
15+
Py_RETURN_NONE;
16+
}
17+
18+
PyObject *py_ue_static_mesh_create_body_setup(ue_PyUObject *self, PyObject * args) {
19+
20+
ue_py_check(self);
21+
22+
UStaticMesh *mesh = ue_py_check_type<UStaticMesh>(self);
23+
if (!mesh)
24+
return PyErr_Format(PyExc_Exception, "uobject is not a UStaticMesh");
25+
26+
mesh->CreateBodySetup();
27+
28+
Py_RETURN_NONE;
29+
}
30+
31+
#endif
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#pragma once
2+
3+
4+
5+
#include "UnrealEnginePython.h"
6+
7+
#if WITH_EDITOR
8+
PyObject *py_ue_static_mesh_build(ue_PyUObject *, PyObject *);
9+
PyObject *py_ue_static_mesh_create_body_setup(ue_PyUObject *, PyObject *);
10+
#endif

‎Source/UnrealEnginePython/Private/UnrealEnginePythonPrivatePCH.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
#if WITH_EDITOR
5151
#include "Wrappers/UEPyFAssetData.h"
5252
#include "Wrappers/UEPyFARFilter.h"
53+
#include "Wrappers/UEPyFRawMesh.h"
5354
#include "UEPyAnimSequence.h"
5455
#include "Blueprint/UEPyEdGraphPin.h"
5556
#include "UEPyIPlugin.h"
Lines changed: 229 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,229 @@
1+
#include "UnrealEnginePythonPrivatePCH.h"
2+
3+
#if WITH_EDITOR
4+
5+
static PyObject *py_ue_fraw_mesh_set_vertex_positions(ue_PyFRawMesh *self, PyObject * args) {
6+
PyObject *data;
7+
if (!PyArg_ParseTuple(args, "O:set_vertex_positions", &data)) {
8+
return nullptr;
9+
}
10+
11+
PyObject *iter = PyObject_GetIter(data);
12+
if (!iter)
13+
return PyErr_Format(PyExc_TypeError, "argument is not an iterable");
14+
15+
TArray<FVector> vertex;
16+
17+
for (;;) {
18+
PyObject *item_x = PyIter_Next(iter);
19+
if (!item_x)
20+
break;
21+
if (!PyNumber_Check(item_x))
22+
return PyErr_Format(PyExc_Exception, "argument iterable does not contains only numbers");
23+
PyObject *py_x = PyNumber_Float(item_x);
24+
float x = PyFloat_AsDouble(py_x);
25+
Py_DECREF(py_x);
26+
27+
PyObject *item_y = PyIter_Next(iter);
28+
if (!item_y)
29+
break;
30+
if (!PyNumber_Check(item_y))
31+
return PyErr_Format(PyExc_Exception, "argument iterable does not contains only numbers");
32+
PyObject *py_y = PyNumber_Float(item_y);
33+
float y = PyFloat_AsDouble(py_y);
34+
Py_DECREF(py_y);
35+
36+
PyObject *item_z = PyIter_Next(iter);
37+
if (!item_z)
38+
break;
39+
if (!PyNumber_Check(item_z))
40+
return PyErr_Format(PyExc_Exception, "argument iterable does not contains only numbers");
41+
PyObject *py_z = PyNumber_Float(item_z);
42+
float z = PyFloat_AsDouble(py_z);
43+
Py_DECREF(py_z);
44+
45+
vertex.Add(FVector(x, y, z));
46+
}
47+
48+
49+
self->raw_mesh->VertexPositions = vertex;
50+
51+
Py_DECREF(iter);
52+
53+
Py_RETURN_NONE;
54+
}
55+
56+
static PyObject *py_ue_fraw_mesh_set_wedge_tex_coords(ue_PyFRawMesh *self, PyObject * args) {
57+
PyObject *data;
58+
int index = 0;
59+
if (!PyArg_ParseTuple(args, "O|i:set_wedge_tex_coords", &data, &index)) {
60+
return nullptr;
61+
}
62+
63+
PyObject *iter = PyObject_GetIter(data);
64+
if (!iter)
65+
return PyErr_Format(PyExc_TypeError, "argument is not an iterable");
66+
67+
TArray<FVector2D> uv;
68+
69+
for (;;) {
70+
PyObject *item_x = PyIter_Next(iter);
71+
if (!item_x)
72+
break;
73+
if (!PyNumber_Check(item_x))
74+
return PyErr_Format(PyExc_Exception, "argument iterable does not contains only numbers");
75+
PyObject *py_x = PyNumber_Float(item_x);
76+
float x = PyFloat_AsDouble(py_x);
77+
Py_DECREF(py_x);
78+
79+
PyObject *item_y = PyIter_Next(iter);
80+
if (!item_y)
81+
break;
82+
if (!PyNumber_Check(item_y))
83+
return PyErr_Format(PyExc_Exception, "argument iterable does not contains only numbers");
84+
PyObject *py_y = PyNumber_Float(item_y);
85+
float y = PyFloat_AsDouble(py_y);
86+
Py_DECREF(py_y);
87+
88+
uv.Add(FVector2D(x, y));
89+
}
90+
91+
92+
self->raw_mesh->WedgeTexCoords[index] = uv;
93+
94+
Py_DECREF(iter);
95+
96+
Py_RETURN_NONE;
97+
}
98+
99+
static PyObject *py_ue_fraw_mesh_set_wedge_indices(ue_PyFRawMesh *self, PyObject * args) {
100+
PyObject *data;
101+
if (!PyArg_ParseTuple(args, "O:set_wedge_indices", &data)) {
102+
return nullptr;
103+
}
104+
105+
PyObject *iter = PyObject_GetIter(data);
106+
if (!iter)
107+
return PyErr_Format(PyExc_TypeError, "argument is not an iterable");
108+
109+
TArray<uint32> indices;
110+
111+
for (;;) {
112+
PyObject *item = PyIter_Next(iter);
113+
if (!item)
114+
break;
115+
if (!PyNumber_Check(item))
116+
return PyErr_Format(PyExc_Exception, "argument iterable does not contains only numbers");
117+
PyObject *py_value = PyNumber_Long(item);
118+
uint32 i = PyLong_AsUnsignedLong(py_value);
119+
Py_DECREF(py_value);
120+
121+
indices.Add(i);
122+
}
123+
124+
125+
self->raw_mesh->WedgeIndices = indices;
126+
127+
Py_DECREF(iter);
128+
129+
Py_RETURN_NONE;
130+
}
131+
132+
static PyObject *py_ue_fraw_mesh_save_to_static_mesh_source_model(ue_PyFRawMesh *self, PyObject * args) {
133+
PyObject *model;
134+
if (!PyArg_ParseTuple(args, "O:save_to_static_mesh_source_model", &model)) {
135+
return nullptr;
136+
}
137+
138+
FStaticMeshSourceModel *source_model = ue_py_check_struct<FStaticMeshSourceModel>(model);
139+
if (!source_model)
140+
return PyErr_Format(PyExc_Exception, "argument is not a FStaticMeshSourceModel");
141+
142+
source_model->RawMeshBulkData->SaveRawMesh(*self->raw_mesh);
143+
144+
Py_RETURN_NONE;
145+
}
146+
147+
static PyObject *py_ue_fraw_mesh_get_wedge_position(ue_PyFRawMesh *self, PyObject * args) {
148+
int index ;
149+
if (!PyArg_ParseTuple(args, "i:get_wedge_position", &index)) {
150+
return nullptr;
151+
}
152+
153+
if (index > self->raw_mesh->WedgeIndices.Num()-1 || index < 0)
154+
return PyErr_Format(PyExc_IndexError, "wedge index error");
155+
156+
FVector vec = self->raw_mesh->GetWedgePosition(index);
157+
158+
return py_ue_new_fvector(vec);
159+
}
160+
161+
162+
static PyMethodDef ue_PyFRawMesh_methods[] = {
163+
{ "set_vertex_positions", (PyCFunction)py_ue_fraw_mesh_set_vertex_positions, METH_VARARGS, "" },
164+
{ "set_wedge_indices", (PyCFunction)py_ue_fraw_mesh_set_wedge_indices, METH_VARARGS, "" },
165+
{ "set_wedge_tex_coords", (PyCFunction)py_ue_fraw_mesh_set_wedge_tex_coords, METH_VARARGS, "" },
166+
{ "get_wedge_position", (PyCFunction)py_ue_fraw_mesh_get_wedge_position, METH_VARARGS, "" },
167+
{ "save_to_static_mesh_source_model", (PyCFunction)py_ue_fraw_mesh_save_to_static_mesh_source_model, METH_VARARGS, "" },
168+
{ NULL } /* Sentinel */
169+
};
170+
171+
static int ue_py_fraw_mesh_init(ue_PyFRawMesh *self, PyObject *args, PyObject *kwargs) {
172+
self->raw_mesh = new FRawMesh();
173+
return 0;
174+
}
175+
176+
static void ue_py_fraw_mesh_dealloc(ue_PyFRawMesh *self) {
177+
if (self->raw_mesh)
178+
delete(self->raw_mesh);
179+
#if PY_MAJOR_VERSION < 3
180+
self->ob_type->tp_free((PyObject*)self);
181+
#else
182+
Py_TYPE(self)->tp_free((PyObject*)self);
183+
#endif
184+
}
185+
186+
static PyTypeObject ue_PyFRawMeshType = {
187+
PyVarObject_HEAD_INIT(NULL, 0)
188+
"unreal_engine.FRawMesh", /* tp_name */
189+
sizeof(ue_PyFRawMesh), /* tp_basicsize */
190+
0, /* tp_itemsize */
191+
(destructor)ue_py_fraw_mesh_dealloc, /* tp_dealloc */
192+
0, /* tp_print */
193+
0, /* tp_getattr */
194+
0, /* tp_setattr */
195+
0, /* tp_reserved */
196+
0, /* tp_repr */
197+
0, /* tp_as_number */
198+
0, /* tp_as_sequence */
199+
0, /* tp_as_mapping */
200+
0, /* tp_hash */
201+
0, /* tp_call */
202+
0, /* tp_str */
203+
0, /* tp_getattro */
204+
0, /* tp_setattro */
205+
0, /* tp_as_buffer */
206+
Py_TPFLAGS_DEFAULT, /* tp_flags */
207+
"Unreal Engine FRawMesh", /* tp_doc */
208+
0, /* tp_traverse */
209+
0, /* tp_clear */
210+
0, /* tp_richcompare */
211+
0, /* tp_weaklistoffset */
212+
0, /* tp_iter */
213+
0, /* tp_iternext */
214+
ue_PyFRawMesh_methods, /* tp_methods */
215+
0, /* tp_members */
216+
0, /* tp_getset */
217+
};
218+
219+
void ue_python_init_fraw_mesh(PyObject *ue_module) {
220+
ue_PyFRawMeshType.tp_new = PyType_GenericNew;;
221+
ue_PyFRawMeshType.tp_init = (initproc)ue_py_fraw_mesh_init;
222+
if (PyType_Ready(&ue_PyFRawMeshType) < 0)
223+
return;
224+
225+
Py_INCREF(&ue_PyFRawMeshType);
226+
PyModule_AddObject(ue_module, "FRawMesh", (PyObject *)&ue_PyFRawMeshType);
227+
}
228+
229+
#endif
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#pragma once
2+
#include "UnrealEnginePython.h"
3+
4+
#if WITH_EDITOR
5+
6+
#include "Developer/RawMesh/Public/RawMesh.h"
7+
8+
struct ue_PyFRawMesh {
9+
PyObject_HEAD
10+
/* Type-specific fields go here. */
11+
FRawMesh *raw_mesh;
12+
};
13+
14+
15+
void ue_python_init_fraw_mesh(PyObject *);
16+
17+
#endif

‎Source/UnrealEnginePython/UnrealEnginePython.Build.cs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ public UnrealEnginePython(TargetInfo Target)
142142
"GraphEditor",
143143
"UMGEditor",
144144
"AIGraph",
145+
"RawMesh",
145146
});
146147
}
147148

0 commit comments

Comments
 (0)