Skip to content

Commit 1b57dd2

Browse files
authored
Merge pull request #497 from Candoran2/develop
Slight fix for triangle assignment to bodypart on partition import
2 parents b187d71 + a68aee7 commit 1b57dd2

2 files changed

Lines changed: 28 additions & 15 deletions

File tree

io_scene_niftools/modules/nif_export/geometry/mesh/__init__.py

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,24 @@ def export_tri_shapes(self, b_obj, n_parent, n_root, trishape_name=None):
460460

461461
if NifData.data.version >= 0x04020100 and NifOp.props.skin_partition:
462462
NifLog.info("Creating skin partition")
463+
464+
# warn on bad config settings
465+
if game == 'OBLIVION':
466+
if NifOp.props.pad_bones:
467+
NifLog.warn("Using padbones on Oblivion export. Disable the pad bones option to get higher quality skin partitions.")
468+
if game in ('OBLIVION', 'FALLOUT_3'):
469+
if NifOp.props.max_bones_per_partition < 18:
470+
NifLog.warn("Using less than 18 bones per partition on Oblivion/Fallout 3 export."
471+
"Set it to 18 to get higher quality skin partitions.")
472+
elif NifOp.props.max_bones_per_partition > 18:
473+
NifLog.warn("Using more than 18 bones per partition on Oblivion/Fallout 3 export."
474+
"This may cause issues in-game.")
475+
if game == 'SKYRIM':
476+
if NifOp.props.max_bones_per_partition < 24:
477+
NifLog.warn("Using less than 24 bones per partition on Skyrim export."
478+
"Set it to 24 to get higher quality skin partitions.")
479+
# Skyrim Special Edition has a limit of 80 bones per partition, but export is not yet supported
480+
463481
part_order = [getattr(NifFormat.BSDismemberBodyPartType, face_map.name, None) for face_map in b_obj.face_maps]
464482
part_order = [body_part for body_part in part_order if body_part is not None]
465483
# override pyffi trishape.update_skin_partition with custom one (that allows ordering)
@@ -475,18 +493,6 @@ def export_tri_shapes(self, b_obj, n_parent, n_root, trishape_name=None):
475493
maximize_bone_sharing=(game in ('FALLOUT_3', 'SKYRIM')),
476494
part_sort_order=part_order)
477495

478-
# warn on bad config settings
479-
if game == 'OBLIVION':
480-
if NifOp.props.pad_bones:
481-
NifLog.warn("Using padbones on Oblivion export. Disable the pad bones option to get higher quality skin partitions.")
482-
if game in ('OBLIVION', 'FALLOUT_3'):
483-
if NifOp.props.max_bones_per_partition < 18:
484-
NifLog.warn("Using less than 18 bones per partition on Oblivion/Fallout 3 export."
485-
"Set it to 18 to get higher quality skin partitions.")
486-
if game == 'SKYRIM':
487-
if NifOp.props.max_bones_per_partition < 24:
488-
NifLog.warn("Using less than 24 bones per partition on Skyrim export."
489-
"Set it to 24 to get higher quality skin partitions.")
490496
if lostweight > NifOp.props.epsilon:
491497
NifLog.warn(f"Lost {lostweight:f} in vertex weights while creating a skin partition for Blender object '{b_obj.name}' (nif block '{trishape.name}')")
492498

io_scene_niftools/modules/nif_import/geometry/vertex/groups.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,14 @@ def import_skin(ni_block, b_obj):
164164
v_group.add([vert], w, 'REPLACE')
165165

166166
# import body parts as face maps
167-
# get faces (triangles) as map of tuples to index
168-
tri_map = {frozenset(polygon.vertices): polygon.index for polygon in b_obj.data.polygons}
167+
# get faces (triangles) as map of unordered vertices to list of indices
168+
tri_map = {}
169+
for polygon in b_obj.data.polygons:
170+
vertices = frozenset(polygon.vertices)
171+
if vertices in tri_map:
172+
tri_map[vertices].append(polygon.index)
173+
else:
174+
tri_map[vertices] = [polygon.index]
169175
if isinstance(skininst, NifFormat.BSDismemberSkinInstance):
170176
skinpart = ni_block.get_skin_partition()
171177
for bodypart, skinpartblock in zip(skininst.partitions, skinpart.skin_partition_blocks):
@@ -178,4 +184,5 @@ def import_skin(ni_block, b_obj):
178184
f_group = b_obj.face_maps.new(name=group_name)
179185

180186
# add the triangles to the face map
181-
f_group.add([tri_map[frozenset(vertices)] for vertices in skinpartblock.get_mapped_triangles()])
187+
for vertices in skinpartblock.get_mapped_triangles():
188+
f_group.add(tri_map[frozenset(vertices)])

0 commit comments

Comments
 (0)