diff --git a/io_export_psk_psa/psa/operator.py b/io_export_psk_psa/psa/operator.py index 227e7a1..019b6d8 100644 --- a/io_export_psk_psa/psa/operator.py +++ b/io_export_psk_psa/psa/operator.py @@ -56,8 +56,9 @@ class PsaExportOperator(Operator, ExportHelper): row.template_list('PSA_UL_ActionList', 'asd', scene, 'psa_action_list', scene, 'psa_action_list_index', rows=len(context.scene.psa_action_list)) def is_action_for_armature(self, action): + if len(action.fcurves) == 0: + return False bone_names = [x.name for x in self.armature.data.bones] - print(bone_names) for fcurve in action.fcurves: match = re.match('pose\.bones\["(.+)"\].\w+', fcurve.data_path) if not match: diff --git a/io_export_psk_psa/psk/builder.py b/io_export_psk_psa/psk/builder.py index 2078fc2..a5d9698 100644 --- a/io_export_psk_psa/psk/builder.py +++ b/io_export_psk_psa/psk/builder.py @@ -26,6 +26,9 @@ class PskBuilder(object): armature_modifier = modifiers[0] armature_object = armature_modifier.object + if object.modifiers[-1] != armature_modifier: + raise RuntimeError('Armature modifier must be the last modifier in the stack') + if armature_object is None: raise RuntimeError('Armature modifier has no linked object') @@ -97,6 +100,7 @@ class PskBuilder(object): psk.wedges[f.loops[i]].material_index = f.material_index # https://github.com/bwrsandman/blender-addons/blob/master/io_export_unreal_psk_psa.py + # TODO: maybe we should use the EDIT bones instead??? bones = list(armature_object.data.bones) for bone in bones: psk_bone = Psk.Bone() diff --git a/io_export_psk_psa/psk/operator.py b/io_export_psk_psa/psk/operator.py index c51d0f4..9505eb8 100644 --- a/io_export_psk_psa/psk/operator.py +++ b/io_export_psk_psa/psk/operator.py @@ -18,6 +18,38 @@ class PskExportOperator(Operator, ExportHelper): maxlen=1024, default='') + def invoke(self, context, event): + object = context.view_layer.objects.active + + if object.type != 'MESH': + self.report({'ERROR_INVALID_CONTEXT'}, 'The selected object must be a mesh.') + return {'CANCELLED'} + + if len(object.data.materials) == 0: + self.report({'ERROR_INVALID_CONTEXT'}, 'Mesh must have at least one material') + return {'CANCELLED'} + + # ensure that there is exactly one armature modifier + modifiers = [x for x in object.modifiers if x.type == 'ARMATURE'] + + if len(modifiers) != 1: + self.report({'ERROR_INVALID_CONTEXT'}, 'Mesh must have one armature modifier') + return {'CANCELLED'} + + armature_modifier = modifiers[0] + armature_object = armature_modifier.object + + if object.modifiers[-1] != armature_modifier: + self.report({'ERROR_INVALID_CONTEXT'}, 'Armature modifier must be the last modifier in the stack') + return {'CANCELLED'} + + if armature_object is None: + self.report({'ERROR_INVALID_CONTEXT'}, 'Armature modifier has no linked object') + return {'CANCELLED'} + + context.window_manager.fileselect_add(self) + return {'RUNNING_MODAL'} + def execute(self, context): builder = PskBuilder() psk = builder.build(context)