1
0
mirror of https://github.com/DarklightGames/io_scene_psk_psa.git synced 2024-11-28 00:20:48 +01:00

Vertices without explicit weights are now weighted to the root bone

There is an issue in some older versions of Unreal (e.g. Postal), where
the engine does not handle vertices without explicit weighting,
resulting in corrupted meshes. This now mitigates the issue.

Thank you to makabray for reporting this issue.
This commit is contained in:
Colin Basnett 2024-07-31 19:09:22 -07:00
commit a9706d88a5

View File

@ -311,6 +311,12 @@ def build_psk(context, input_objects: PskInputObjects, options: PskBuildOptions)
break
except ValueError:
bone = bone.parent
# Keep track of which vertices have been assigned weights.
# The ones that have not been assigned weights will be assigned to the root bone.
# Without this, some older versions of UnrealEd may have corrupted meshes.
vertices_assigned_weights = np.full(len(mesh_data.vertices), False)
for vertex_group_index, vertex_group in enumerate(mesh_object.vertex_groups):
if vertex_group_index not in vertex_group_bone_indices:
# Vertex group has no associated bone, skip it.
@ -328,6 +334,16 @@ def build_psk(context, input_objects: PskInputObjects, options: PskBuildOptions)
w.point_index = vertex_offset + vertex_index
w.weight = weight
psk.weights.append(w)
vertices_assigned_weights[vertex_index] = True
# Assign vertices that have not been assigned weights to the root bone.
for vertex_index, assigned in enumerate(vertices_assigned_weights):
if not assigned:
w = Psk.Weight()
w.bone_index = 0
w.point_index = vertex_offset + vertex_index
w.weight = 1.0
psk.weights.append(w)
if options.object_eval_state == 'EVALUATED':
bpy.data.objects.remove(mesh_object)