1
0
mirror of https://github.com/DarklightGames/io_scene_psk_psa.git synced 2025-01-19 15:38:39 +01:00

A warning is now emitted when exporting a PSK with mesh objects that have negative scaling values

This commit is contained in:
Colin Basnett 2023-09-30 00:53:37 -07:00
parent afcfebe84a
commit c18ac85eed
2 changed files with 24 additions and 6 deletions

View File

@ -58,11 +58,17 @@ def get_psk_input_objects(context) -> PskInputObjects:
return input_objects
def build_psk(context, options: PskBuildOptions) -> Psk:
input_objects = get_psk_input_objects(context)
class PskBuildResult(object):
def __init__(self):
self.psk = None
self.warnings = []
def build_psk(context, options: PskBuildOptions) -> PskBuildResult:
input_objects = get_psk_input_objects(context)
armature_object: bpy.types.Object = input_objects.armature_object
result = PskBuildResult()
psk = Psk()
bones = []
@ -168,6 +174,10 @@ def build_psk(context, options: PskBuildOptions) -> Psk:
mesh_object = bpy.data.objects.new('', mesh_data)
mesh_object.matrix_world = input_mesh_object.matrix_world
scale = (input_mesh_object.scale.x, input_mesh_object.scale.y, input_mesh_object.scale.z)
if any(map(lambda x: x < 0, scale)):
result.warnings.append(f'Mesh "{input_mesh_object.name}" has negative scaling which may result in inverted normals.')
# Copy the vertex groups
for vertex_group in input_mesh_object.vertex_groups:
mesh_object.vertex_groups.new(name=vertex_group.name)
@ -278,4 +288,6 @@ def build_psk(context, options: PskBuildOptions) -> Psk:
bpy.data.meshes.remove(mesh_data)
del mesh_data
return psk
result.psk = psk
return result

View File

@ -163,12 +163,18 @@ class PSK_OT_export(Operator, ExportHelper):
options.should_enforce_bone_name_restrictions = pg.should_enforce_bone_name_restrictions
try:
psk = build_psk(context, options)
write_psk(psk, self.filepath)
result = build_psk(context, options)
for warning in result.warnings:
self.report({'WARNING'}, warning)
write_psk(result.psk, self.filepath)
if len(result.warnings) > 0:
self.report({'WARNING'}, f'PSK export successful with {len(result.warnings)} warnings')
else:
self.report({'INFO'}, f'PSK export successful')
except RuntimeError as e:
self.report({'ERROR_INVALID_CONTEXT'}, str(e))
return {'CANCELLED'}
return {'FINISHED'}