Skip to content

Commit f2affef

Browse files
author
Roberto De Ioris
committed
fixed skin weighting
1 parent e19e004 commit f2affef

3 files changed

Lines changed: 120 additions & 96 deletions

File tree

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

Lines changed: 16 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,21 @@ PyObject *py_ue_skeletal_mesh_get_lod(ue_PyUObject *self, PyObject * args)
338338
int32 vertex_index;
339339
bool has_extra_influences;
340340
model.GetSectionFromVertexIndex(indices[index], section_index, vertex_index, has_extra_influences);
341-
ue_PyFSoftSkinVertex *py_ss_vertex = (ue_PyFSoftSkinVertex *)py_ue_new_fsoft_skin_vertex(model.Sections[section_index].SoftVertices[vertex_index]);
341+
FSoftSkinVertex ssv = model.Sections[section_index].SoftVertices[vertex_index];
342+
// fix bone id
343+
for (int32 i = 0; i < MAX_TOTAL_INFLUENCES; i++)
344+
{
345+
if (ssv.InfluenceBones[i] < model.Sections[section_index].BoneMap.Num())
346+
{
347+
ssv.InfluenceBones[i] = model.Sections[section_index].BoneMap[ssv.InfluenceBones[i]];
348+
}
349+
else
350+
{
351+
UE_LOG(LogPython, Warning, TEXT("unable to retrieve bone mapping for index %d, forcing to 0"), ssv.InfluenceBones[i]);
352+
ssv.InfluenceBones[i] = 0;
353+
}
354+
}
355+
ue_PyFSoftSkinVertex *py_ss_vertex = (ue_PyFSoftSkinVertex *)py_ue_new_fsoft_skin_vertex(ssv);
342356
py_ss_vertex->material_index = section_index;
343357
PyList_Append(py_list, (PyObject *)py_ss_vertex);
344358
}
@@ -834,7 +848,7 @@ PyObject *py_ue_skeletal_mesh_build_lod(ue_PyUObject *self, PyObject * args, PyO
834848
FVertInfluence influence;
835849
influence.VertIndex = wedge_index;
836850
influence.BoneIndex = ss_vertex->ss_vertex.InfluenceBones[i];
837-
influence.Weight = ss_vertex->ss_vertex.InfluenceWeights[i];
851+
influence.Weight = ss_vertex->ss_vertex.InfluenceWeights[i] / 255.f;
838852
influences.Add(influence);
839853
}
840854

@@ -1051,50 +1065,3 @@ PyObject *py_ue_skeletal_mesh_to_import_vertex_map(ue_PyUObject *self, PyObject
10511065

10521066
return py_list;
10531067
}
1054-
1055-
PyObject *py_ue_skeleton_add_socket(ue_PyUObject *self, PyObject * args)
1056-
{
1057-
1058-
ue_py_check(self);
1059-
1060-
char *name;
1061-
int parent_index;
1062-
PyObject *py_transform;
1063-
if (!PyArg_ParseTuple(args, "siO:skeleton_add_bone", &name, &parent_index, &py_transform))
1064-
return nullptr;
1065-
1066-
USkeleton *skeleton = ue_py_check_type<USkeleton>(self);
1067-
if (!skeleton)
1068-
return PyErr_Format(PyExc_Exception, "uobject is not a USkeleton");
1069-
1070-
ue_PyFTransform *transform = py_ue_is_ftransform(py_transform);
1071-
if (!transform)
1072-
return PyErr_Format(PyExc_Exception, "argument is not a FTransform");
1073-
1074-
if (skeleton->GetReferenceSkeleton().FindBoneIndex(FName(UTF8_TO_TCHAR(name))) > -1)
1075-
{
1076-
return PyErr_Format(PyExc_Exception, "bone %s already exists", name);
1077-
}
1078-
1079-
#if WITH_EDITOR
1080-
skeleton->PreEditChange(nullptr);
1081-
#endif
1082-
1083-
{
1084-
const FReferenceSkeleton &ref = skeleton->GetReferenceSkeleton();
1085-
// horrible hack to modify the skeleton in place
1086-
FReferenceSkeletonModifier modifier((FReferenceSkeleton &)ref, skeleton);
1087-
1088-
TCHAR *bone_name = UTF8_TO_TCHAR(name);
1089-
1090-
modifier.Add(FMeshBoneInfo(FName(bone_name), FString(bone_name), parent_index), transform->transform);
1091-
}
1092-
1093-
1094-
#if WITH_EDITOR
1095-
skeleton->PostEditChange();
1096-
#endif
1097-
skeleton->MarkPackageDirty();
1098-
1099-
return PyLong_FromLong(skeleton->GetReferenceSkeleton().FindBoneIndex(FName(UTF8_TO_TCHAR(name))));
1100-
}

0 commit comments

Comments
 (0)