@@ -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
0 commit comments