Skip to content

Commit 337e4c6

Browse files
author
Roberto De Ioris
committed
completed skeletal mesh building api
1 parent b18c5f3 commit 337e4c6

File tree

5 files changed

+78
-44
lines changed

5 files changed

+78
-44
lines changed

Source/UnrealEnginePython/Private/UEPyModule.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -752,7 +752,6 @@ 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, "" },
756755

757756
// Timer
758757
{ "set_timer", (PyCFunction)py_ue_set_timer, METH_VARARGS, "" },

Source/UnrealEnginePython/Private/UObject/UEPySkeletal.cpp

Lines changed: 42 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -649,7 +649,7 @@ PyObject *py_ue_skeletal_mesh_build_lod(ue_PyUObject *self, PyObject * args) {
649649

650650
PyObject *py_ss_vertex;
651651
int lod_index = 0;
652-
if (!PyArg_ParseTuple(args, "O|i:skeletal_mesh_sections_num", &py_ss_vertex, &lod_index))
652+
if (!PyArg_ParseTuple(args, "O|i:skeletal_mesh_build_lod", &py_ss_vertex, &lod_index))
653653
return nullptr;
654654

655655
USkeletalMesh *mesh = ue_py_check_type<USkeletalMesh>(self);
@@ -658,8 +658,22 @@ PyObject *py_ue_skeletal_mesh_build_lod(ue_PyUObject *self, PyObject * args) {
658658

659659
FSkeletalMeshResource *resource = mesh->GetImportedResource();
660660

661-
if (lod_index < 0 || lod_index >= resource->LODModels.Num())
662-
return PyErr_Format(PyExc_Exception, "invalid LOD index, must be between 0 and %d", resource->LODModels.Num() - 1);
661+
if (lod_index < 0 || lod_index > resource->LODModels.Num())
662+
return PyErr_Format(PyExc_Exception, "invalid LOD index, must be between 0 and %d", resource->LODModels.Num());
663+
664+
if (lod_index == resource->LODModels.Num()) {
665+
resource->LODModels.Add(new FStaticLODModel());
666+
mesh->LODInfo.AddZeroed();
667+
}
668+
669+
FStaticLODModel& LODModel = resource->LODModels[lod_index];
670+
671+
mesh->LODInfo[lod_index].LODHysteresis = 0.02;
672+
673+
FSkeletalMeshOptimizationSettings settings;
674+
mesh->LODInfo[lod_index].ReductionSettings = settings;
675+
676+
LODModel.NumTexCoords = 1;
663677

664678
IMeshUtilities & MeshUtilities = FModuleManager::Get().LoadModuleChecked<IMeshUtilities>("MeshUtilities");
665679

@@ -679,6 +693,8 @@ PyObject *py_ue_skeletal_mesh_build_lod(ue_PyUObject *self, PyObject * args) {
679693
TArray<FVector> tangentsX;
680694
TArray<FVector> tangentsY;
681695
TArray<FVector> tangentsZ;
696+
TArray<uint16> material_indices;
697+
TArray<uint32> smoothing_groups;
682698

683699
while (PyObject *py_item = PyIter_Next(py_iter)) {
684700
ue_PyFSoftSkinVertex *ss_vertex = py_ue_is_fsoft_skin_vertex(py_item);
@@ -709,6 +725,9 @@ PyObject *py_ue_skeletal_mesh_build_lod(ue_PyUObject *self, PyObject * args) {
709725
tangentsX.Add(ss_vertex->ss_vertex.TangentX);
710726
tangentsY.Add(ss_vertex->ss_vertex.TangentY);
711727
tangentsZ.Add(ss_vertex->ss_vertex.TangentZ);
728+
729+
material_indices.Add(ss_vertex->material_index);
730+
smoothing_groups.Add(ss_vertex->smoothing_group);
712731
}
713732

714733
Py_DECREF(py_iter);
@@ -722,8 +741,8 @@ PyObject *py_ue_skeletal_mesh_build_lod(ue_PyUObject *self, PyObject * args) {
722741
face.iWedge[1] = i + 1;
723742
face.iWedge[2] = i + 2;
724743

725-
face.MeshMaterialIndex = 0;
726-
face.SmoothingGroups = 0;
744+
face.MeshMaterialIndex = material_indices[i];
745+
face.SmoothingGroups = smoothing_groups[i];
727746

728747
face.TangentX[0] = tangentsX[i];
729748
face.TangentX[1] = tangentsX[i + 1];
@@ -742,46 +761,28 @@ PyObject *py_ue_skeletal_mesh_build_lod(ue_PyUObject *self, PyObject * args) {
742761

743762
FStaticLODModel & lod_model = resource->LODModels[lod_index];
744763

745-
IMeshUtilities::MeshBuildOptions settings;
746-
settings.bUseMikkTSpace = true;
764+
IMeshUtilities::MeshBuildOptions build_settings;
765+
build_settings.bUseMikkTSpace = true;
747766

748-
if (MeshUtilities.BuildSkeletalMesh(lod_model, mesh->RefSkeleton, influences, wedges, faces, points, points_to_map, settings)) {
749-
Py_RETURN_TRUE;
750-
}
767+
bool success = MeshUtilities.BuildSkeletalMesh(lod_model, mesh->RefSkeleton, influences, wedges, faces, points, points_to_map, build_settings);
751768

752-
Py_RETURN_FALSE;
753-
}
754-
#endif
755-
756-
PyObject *py_ue_skeletal_mesh_init(ue_PyUObject *self, PyObject * args) {
757-
ue_py_check(self);
769+
mesh->CalculateRequiredBones(LODModel, mesh->RefSkeleton, nullptr);
770+
mesh->CalculateInvRefMatrices();
758771

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;
772+
mesh->Skeleton->RecreateBoneTree(mesh);
773+
mesh->Skeleton->SetPreviewMesh(mesh);
763774

764-
USkeletalMesh *mesh = ue_py_check_type<USkeletalMesh>(self);
765-
if (!mesh)
766-
return PyErr_Format(PyExc_Exception, "uobject is not a USkeletalMesh");
775+
mesh->Skeleton->PostEditChange();
776+
mesh->Skeleton->MarkPackageDirty();
767777

768-
FSkeletalMeshResource *resource = mesh->GetImportedResource();
778+
mesh->PostEditChange();
779+
mesh->MarkPackageDirty();
769780

770-
if (resource->LODModels.Num() > 0) {
771-
return PyErr_Format(PyExc_Exception, "SkeletalMesh has already a LOD");
781+
if (success) {
782+
Py_RETURN_TRUE;
772783
}
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-
}
784+
else {
785+
Py_RETURN_FALSE;
786+
}
787+
}
788+
#endif

Source/UnrealEnginePython/Private/UObject/UEPySkeletal.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,3 @@ 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 *);
3131
PyObject *py_ue_skeletal_mesh_build_lod(ue_PyUObject *, PyObject *);
32-
33-
PyObject *py_ue_skeletal_mesh_init(ue_PyUObject *, PyObject *);

Source/UnrealEnginePython/Private/Wrappers/UEPyFSoftSkinVertex.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,38 @@ static int py_ue_fsoft_skin_vertex_set_uvs(ue_PyFSoftSkinVertex *self, PyObject
189189
return -1;
190190
}
191191

192+
static int py_ue_fsoft_skin_vertex_set_material_index(ue_PyFSoftSkinVertex *self, PyObject *value, void *closure) {
193+
194+
if (PyNumber_Check(value)) {
195+
PyObject *py_num = PyNumber_Long(value);
196+
self->material_index = PyLong_AsUnsignedLong(py_num);
197+
Py_DECREF(py_num);
198+
return 0;
199+
}
200+
PyErr_SetString(PyExc_TypeError, "value is not a number");
201+
return -1;
202+
}
203+
204+
static PyObject *py_ue_fsoft_skin_vertex_get_material_index(ue_PyFSoftSkinVertex *self, void *closure) {
205+
return PyLong_FromUnsignedLong(self->material_index);
206+
}
207+
208+
static int py_ue_fsoft_skin_vertex_set_smoothing_group(ue_PyFSoftSkinVertex *self, PyObject *value, void *closure) {
209+
210+
if (PyNumber_Check(value)) {
211+
PyObject *py_num = PyNumber_Long(value);
212+
self->smoothing_group = PyLong_AsUnsignedLong(py_num);
213+
Py_DECREF(py_num);
214+
return 0;
215+
}
216+
PyErr_SetString(PyExc_TypeError, "value is not a number");
217+
return -1;
218+
}
219+
220+
static PyObject *py_ue_fsoft_skin_vertex_get_smoothing_group(ue_PyFSoftSkinVertex *self, void *closure) {
221+
return PyLong_FromUnsignedLong(self->smoothing_group);
222+
}
223+
192224
static PyGetSetDef ue_PyFSoftSkinVertex_getseters[] = {
193225
{ (char *) "color", (getter)py_ue_fsoft_skin_vertex_get_color, (setter)py_ue_fsoft_skin_vertex_set_color, (char *)"", NULL },
194226
{ (char *) "influence_bones", (getter)py_ue_fsoft_skin_vertex_get_influence_bones, (setter)py_ue_fsoft_skin_vertex_set_influence_bones, (char *)"", NULL },
@@ -198,6 +230,8 @@ static PyGetSetDef ue_PyFSoftSkinVertex_getseters[] = {
198230
{ (char *) "tangent_y", (getter)py_ue_fsoft_skin_vertex_get_tangent_y, (setter)py_ue_fsoft_skin_vertex_set_tangent_y, (char *)"", NULL },
199231
{ (char *) "tangent_z", (getter)py_ue_fsoft_skin_vertex_get_tangent_z, (setter)py_ue_fsoft_skin_vertex_set_tangent_z, (char *)"", NULL },
200232
{ (char *) "uvs", (getter)py_ue_fsoft_skin_vertex_get_uvs, (setter)py_ue_fsoft_skin_vertex_set_uvs, (char *)"", NULL },
233+
{ (char *) "material_index", (getter)py_ue_fsoft_skin_vertex_get_material_index, (setter)py_ue_fsoft_skin_vertex_set_material_index, (char *)"", NULL },
234+
{ (char *) "smoothing_group", (getter)py_ue_fsoft_skin_vertex_get_smoothing_group, (setter)py_ue_fsoft_skin_vertex_set_smoothing_group, (char *)"", NULL },
201235
{ NULL } /* Sentinel */
202236
};
203237

Source/UnrealEnginePython/Private/Wrappers/UEPyFSoftSkinVertex.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ struct ue_PyFSoftSkinVertex {
77
PyObject_HEAD
88
/* Type-specific fields go here. */
99
FSoftSkinVertex ss_vertex;
10+
uint16 material_index;
11+
uint32 smoothing_group;
1012
};
1113

1214
void ue_python_init_fsoft_skin_vertex(PyObject *);

0 commit comments

Comments
 (0)