Skip to content

Commit b18c5f3

Browse files
author
Roberto De Ioris
committed
added texture_get_source_data()
1 parent b14cf86 commit b18c5f3

File tree

5 files changed

+68
-3
lines changed

5 files changed

+68
-3
lines changed

Source/UnrealEnginePython/Private/UEPyModule.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -752,6 +752,7 @@ static PyMethodDef ue_PyUObject_methods[] = {
752752
#if WITH_EDITOR
753753
{ "skeletal_mesh_build_lod", (PyCFunction)py_ue_skeletal_mesh_build_lod, METH_VARARGS, "" },
754754
#endif
755+
{ "skeletal_mesh_init", (PyCFunction)py_ue_skeletal_mesh_init, METH_VARARGS, "" },
755756

756757
// Timer
757758
{ "set_timer", (PyCFunction)py_ue_set_timer, METH_VARARGS, "" },
@@ -764,6 +765,8 @@ static PyMethodDef ue_PyUObject_methods[] = {
764765
{ "render_target_get_data", (PyCFunction)py_ue_render_target_get_data, METH_VARARGS, "" },
765766
{ "texture_update_resource", (PyCFunction)py_ue_texture_update_resource, METH_VARARGS, "" },
766767

768+
{ "texture_get_source_data", (PyCFunction)py_ue_texture_get_source_data, METH_VARARGS, "" },
769+
767770
// Sequencer
768771
{ "sequencer_master_tracks", (PyCFunction)py_ue_sequencer_master_tracks, METH_VARARGS, "" },
769772
{ "sequencer_possessable_tracks", (PyCFunction)py_ue_sequencer_possessable_tracks, METH_VARARGS, "" },

Source/UnrealEnginePython/Private/UObject/UEPySkeletal.cpp

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -751,4 +751,37 @@ PyObject *py_ue_skeletal_mesh_build_lod(ue_PyUObject *self, PyObject * args) {
751751

752752
Py_RETURN_FALSE;
753753
}
754-
#endif
754+
#endif
755+
756+
PyObject *py_ue_skeletal_mesh_init(ue_PyUObject *self, PyObject * args) {
757+
ue_py_check(self);
758+
759+
PyObject *py_ss_vertex;
760+
int lod_index = 0;
761+
if (!PyArg_ParseTuple(args, "O|i:skeletal_mesh_init", &py_ss_vertex, &lod_index))
762+
return nullptr;
763+
764+
USkeletalMesh *mesh = ue_py_check_type<USkeletalMesh>(self);
765+
if (!mesh)
766+
return PyErr_Format(PyExc_Exception, "uobject is not a USkeletalMesh");
767+
768+
FSkeletalMeshResource *resource = mesh->GetImportedResource();
769+
770+
if (resource->LODModels.Num() > 0) {
771+
return PyErr_Format(PyExc_Exception, "SkeletalMesh has already a LOD");
772+
}
773+
774+
resource->LODModels.Empty();
775+
FStaticLODModel& LODModel = *new (resource->LODModels) FStaticLODModel();
776+
777+
mesh->LODInfo.Empty();
778+
mesh->LODInfo.AddZeroed();
779+
mesh->LODInfo[0].LODHysteresis = 0.02;
780+
781+
FSkeletalMeshOptimizationSettings settings;
782+
mesh->LODInfo[0].ReductionSettings = settings;
783+
784+
LODModel.NumTexCoords = 1;
785+
786+
Py_RETURN_NONE;
787+
}

Source/UnrealEnginePython/Private/UObject/UEPySkeletal.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,6 @@ PyObject *py_ue_skeletal_mesh_get_required_bones(ue_PyUObject *, PyObject *);
2828
PyObject *py_ue_skeletal_mesh_add_lod(ue_PyUObject *, PyObject *);
2929
PyObject *py_ue_skeletal_mesh_lods_num(ue_PyUObject *, PyObject *);
3030
PyObject *py_ue_skeletal_mesh_sections_num(ue_PyUObject *, PyObject *);
31-
PyObject *py_ue_skeletal_mesh_build_lod(ue_PyUObject *, PyObject *);
31+
PyObject *py_ue_skeletal_mesh_build_lod(ue_PyUObject *, PyObject *);
32+
33+
PyObject *py_ue_skeletal_mesh_init(ue_PyUObject *, PyObject *);

Source/UnrealEnginePython/Private/UObject/UEPyTexture.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,31 @@ PyObject *py_ue_texture_get_data(ue_PyUObject *self, PyObject * args) {
6060
return bytes;
6161
}
6262

63+
PyObject *py_ue_texture_get_source_data(ue_PyUObject *self, PyObject * args) {
64+
65+
ue_py_check(self);
66+
67+
int mipmap = 0;
68+
69+
if (!PyArg_ParseTuple(args, "|i:texture_get_data", &mipmap)) {
70+
return NULL;
71+
}
72+
73+
UTexture2D *tex = ue_py_check_type<UTexture2D>(self);
74+
if (!tex)
75+
return PyErr_Format(PyExc_Exception, "object is not a Texture2D");
76+
77+
if (mipmap >= tex->GetNumMips())
78+
return PyErr_Format(PyExc_Exception, "invalid mipmap id");
79+
80+
const uint8 *blob = tex->Source.LockMip(mipmap);
81+
82+
PyObject *bytes = PyByteArray_FromStringAndSize((const char *)blob, (Py_ssize_t)tex->Source.CalcMipSize(mipmap));
83+
84+
tex->Source.UnlockMip(mipmap);
85+
return bytes;
86+
}
87+
6388
PyObject *py_ue_render_target_get_data(ue_PyUObject *self, PyObject * args) {
6489

6590
ue_py_check(self);

Source/UnrealEnginePython/Private/UObject/UEPyTexture.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,6 @@ PyObject *py_ue_texture_update_resource(ue_PyUObject *, PyObject *);
2121

2222
#if WITH_EDITOR
2323
PyObject *py_unreal_engine_create_texture(PyObject * self, PyObject *);
24-
#endif
24+
#endif
25+
26+
PyObject *py_ue_texture_get_source_data(ue_PyUObject *, PyObject *);

0 commit comments

Comments
 (0)