More polishing (more operator descriptions, better error reporting etc.)

This commit is contained in:
Colin Basnett
2022-01-22 23:40:36 -08:00
parent 41edd61f3d
commit a6c193e059
6 changed files with 38 additions and 19 deletions

View File

@@ -67,7 +67,8 @@ class PskBuilder(object):
materials = OrderedDict()
if armature_object is None:
# Static mesh (no armature)
# If the mesh has no armature object, simply assign it a dummy bone at the root to satisfy the requirement
# that a PSK file must have at least one bone.
psk_bone = Psk.Bone()
psk_bone.name = bytes('static', encoding='utf-8')
psk_bone.flags = 0
@@ -79,13 +80,16 @@ class PskBuilder(object):
else:
bones = list(armature_object.data.bones)
# If bone groups are specified, get only the bones that are in the specified bone groups and their ancestors.
if len(options.bone_group_indices) > 0:
# If we are filtering by bone groups, get only the bones that are in the specified bone groups and their
# ancestors.
if options.bone_filter_mode == 'BONE_GROUPS':
bone_indices = get_export_bone_indices_for_bone_groups(armature_object, options.bone_group_indices)
bones = [bones[bone_index] for bone_index in bone_indices]
# Ensure that the exported hierarchy has a single root bone.
root_bones = [x for x in bones if x.parent is None]
print('root bones')
print(root_bones)
if len(root_bones) > 1:
root_bone_names = [x.name for x in bones]
raise RuntimeError('Exported bone hierarchy must have a single root bone.'

View File

@@ -64,7 +64,7 @@ def is_bone_filter_mode_item_available(context, identifier):
input_objects = PskBuilder.get_input_objects(context)
armature_object = input_objects.armature_object
if identifier == 'BONE_GROUPS':
if not armature_object.pose or not armature_object.pose.bone_groups:
if not armature_object or not armature_object.pose or not armature_object.pose.bone_groups:
return False
# else if... you can set up other conditions if you add more options
return True
@@ -73,7 +73,7 @@ def is_bone_filter_mode_item_available(context, identifier):
class PskExportOperator(Operator, ExportHelper):
bl_idname = 'export.psk'
bl_label = 'Export'
__doc__ = 'PSK Exporter (.psk)'
__doc__ = 'Export mesh and armature to PSK'
filename_ext = '.psk'
filter_glob: StringProperty(default='*.psk', options={'HIDDEN'})
@@ -125,7 +125,11 @@ class PskExportOperator(Operator, ExportHelper):
builder = PskBuilder()
options = PskBuilderOptions()
options.bone_group_indices = [x.index for x in property_group.bone_group_list if x.is_selected]
psk = builder.build(context, options)
try:
psk = builder.build(context, options)
except RuntimeError as e:
self.report({'ERROR_INVALID_CONTEXT'}, str(e))
return {'CANCELLED'}
exporter = PskExporter(psk)
exporter.export(self.filepath)
return {'FINISHED'}

View File

@@ -167,7 +167,7 @@ class PskImporter(object):
class PskImportOperator(Operator, ImportHelper):
bl_idname = 'import.psk'
bl_label = 'Export'
__doc__ = 'PSK Importer (.psk)'
__doc__ = 'Load a PSK file'
filename_ext = '.psk'
filter_glob: StringProperty(default='*.psk', options={'HIDDEN'})
filepath: StringProperty(