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

Added "Scale" option for PSK import

This commit is contained in:
Colin Basnett 2024-01-25 11:43:13 -08:00
parent 9438a35cd1
commit ced03afafe
3 changed files with 53 additions and 33 deletions

View File

@ -176,15 +176,15 @@ def import_psa(context: Context, psa_reader: PsaReader, armature_object: Object,
action = bpy.data.actions.new(name=action_name)
# Calculate the target FPS.
target_fps = sequence.fps
if options.fps_source == 'CUSTOM':
target_fps = options.fps_custom
elif options.fps_source == 'SCENE':
target_fps = context.scene.render.fps
elif options.fps_source == 'SEQUENCE':
target_fps = sequence.fps
else:
raise ValueError(f'Unknown FPS source: {options.fps_source}')
match options.fps_source:
case 'CUSTOM':
target_fps = options.fps_custom
case 'SCENE':
target_fps = context.scene.render.fps
case 'SEQUENCE':
target_fps = sequence.fps
case _:
raise ValueError(f'Unknown FPS source: {options.fps_source}')
keyframe_time_dilation = target_fps / sequence.fps

View File

@ -27,8 +27,8 @@ class PSK_OT_import(Operator, ImportHelper):
should_import_vertex_colors: BoolProperty(
default=True,
options=empty_set,
name='Vertex Colors',
description='Import vertex colors from PSKX files, if available'
name='Import Vertex Colors',
description='Import vertex colors, if available'
)
vertex_color_space: EnumProperty(
name='Vertex Color Space',
@ -42,13 +42,13 @@ class PSK_OT_import(Operator, ImportHelper):
)
should_import_vertex_normals: BoolProperty(
default=True,
name='Vertex Normals',
name='Import Vertex Normals',
options=empty_set,
description='Import vertex normals, if available'
)
should_import_extra_uvs: BoolProperty(
default=True,
name='Extra UVs',
name='Import Extra UVs',
options=empty_set,
description='Import extra UV maps, if available'
)
@ -63,12 +63,6 @@ class PSK_OT_import(Operator, ImportHelper):
name='Import Materials',
options=empty_set,
)
should_reuse_materials: BoolProperty(
default=True,
name='Reuse Materials',
options=empty_set,
description='Existing materials with matching names will be reused when available'
)
should_import_skeleton: BoolProperty(
default=True,
name='Import Skeleton',
@ -87,10 +81,15 @@ class PSK_OT_import(Operator, ImportHelper):
)
should_import_shape_keys: BoolProperty(
default=True,
name='Shape Keys',
name='Import Shape Keys',
options=empty_set,
description='Import shape keys, if available'
)
scale: FloatProperty(
name='Scale',
default=1.0,
soft_min=0.0,
)
def execute(self, context):
psk = read_psk(self.filepath)
@ -106,6 +105,7 @@ class PSK_OT_import(Operator, ImportHelper):
options.bone_length = self.bone_length
options.should_import_materials = self.should_import_materials
options.should_import_shape_keys = self.should_import_shape_keys
options.scale = self.scale
result = import_psk(psk, context, options)
@ -120,24 +120,36 @@ class PSK_OT_import(Operator, ImportHelper):
def draw(self, context):
layout = self.layout
layout.prop(self, 'should_import_materials')
row = layout.row()
col = row.column()
col.use_property_split = True
col.use_property_decorate = False
col.prop(self, 'scale')
layout.prop(self, 'should_import_mesh')
row = layout.column()
row.use_property_split = True
row.use_property_decorate = False
if self.should_import_mesh:
row.prop(self, 'should_import_vertex_normals')
row.prop(self, 'should_import_extra_uvs')
row.prop(self, 'should_import_vertex_colors')
row = layout.row()
col = row.column()
col.use_property_split = True
col.use_property_decorate = False
col.prop(self, 'should_import_materials', text='Materials')
col.prop(self, 'should_import_vertex_normals', text='Vertex Normals')
col.prop(self, 'should_import_extra_uvs', text='Extra UVs')
col.prop(self, 'should_import_vertex_colors', text='Vertex Colors')
if self.should_import_vertex_colors:
row.prop(self, 'vertex_color_space')
row.prop(self, 'should_import_shape_keys')
col.prop(self, 'vertex_color_space')
col.prop(self, 'should_import_shape_keys', text='Shape Keys')
layout.prop(self, 'should_import_skeleton')
row = layout.column()
row.use_property_split = True
row.use_property_decorate = False
if self.should_import_skeleton:
row.prop(self, 'bone_length')
row = layout.row()
col = row.column()
col.use_property_split = True
col.use_property_decorate = False
col.prop(self, 'bone_length')
classes = (

View File

@ -23,6 +23,7 @@ class PskImportOptions:
self.should_import_shape_keys = True
self.bone_length = 1.0
self.should_import_materials = True
self.scale = 1.0
class ImportBone:
@ -51,6 +52,10 @@ class PskImportResult:
def import_psk(psk: Psk, context, options: PskImportOptions) -> PskImportResult:
result = PskImportResult()
armature_object = None
mesh_object = None
if not options.should_import_mesh and not options.should_import_skeleton:
raise Exception('Nothing to import')
if options.should_import_skeleton:
# ARMATURE
@ -266,6 +271,9 @@ def import_psk(psk: Psk, context, options: PskImportOptions) -> PskImportResult:
armature_modifier.object = armature_object
mesh_object.parent = armature_object
root_object = armature_object if options.should_import_skeleton else mesh_object
root_object.scale = (options.scale, options.scale, options.scale)
try:
bpy.ops.object.mode_set(mode='OBJECT')
except: