Users can now choose not to import either the mesh or the armature when importing a PSK
This commit is contained in:
@@ -19,14 +19,19 @@ from ..helpers import rgb_to_srgb
|
|||||||
class PskImportOptions(object):
|
class PskImportOptions(object):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.name = ''
|
self.name = ''
|
||||||
|
self.should_import_mesh = True
|
||||||
self.should_import_vertex_colors = True
|
self.should_import_vertex_colors = True
|
||||||
self.vertex_color_space = 'sRGB'
|
self.vertex_color_space = 'sRGB'
|
||||||
self.should_import_vertex_normals = True
|
self.should_import_vertex_normals = True
|
||||||
self.should_import_extra_uvs = True
|
self.should_import_extra_uvs = True
|
||||||
|
self.should_import_skeleton = True
|
||||||
self.bone_length = 1.0
|
self.bone_length = 1.0
|
||||||
|
|
||||||
|
|
||||||
def import_psk(psk: Psk, context, options: PskImportOptions):
|
def import_psk(psk: Psk, context, options: PskImportOptions):
|
||||||
|
armature_object = None
|
||||||
|
|
||||||
|
if options.should_import_skeleton:
|
||||||
# ARMATURE
|
# ARMATURE
|
||||||
armature_data = bpy.data.armatures.new(options.name)
|
armature_data = bpy.data.armatures.new(options.name)
|
||||||
armature_object = bpy.data.objects.new(options.name, armature_data)
|
armature_object = bpy.data.objects.new(options.name, armature_data)
|
||||||
@@ -106,6 +111,7 @@ def import_psk(psk: Psk, context, options: PskImportOptions):
|
|||||||
edit_bone['post_quat'] = import_bone.local_rotation.conjugated()
|
edit_bone['post_quat'] = import_bone.local_rotation.conjugated()
|
||||||
|
|
||||||
# MESH
|
# MESH
|
||||||
|
if options.should_import_mesh:
|
||||||
mesh_data = bpy.data.meshes.new(options.name)
|
mesh_data = bpy.data.meshes.new(options.name)
|
||||||
mesh_object = bpy.data.objects.new(options.name, mesh_data)
|
mesh_object = bpy.data.objects.new(options.name, mesh_data)
|
||||||
|
|
||||||
@@ -207,20 +213,21 @@ def import_psk(psk: Psk, context, options: PskImportOptions):
|
|||||||
|
|
||||||
# Get a list of all bones that have weights associated with them.
|
# Get a list of all bones that have weights associated with them.
|
||||||
vertex_group_bone_indices = set(map(lambda weight: weight.bone_index, psk.weights))
|
vertex_group_bone_indices = set(map(lambda weight: weight.bone_index, psk.weights))
|
||||||
for import_bone in map(lambda x: import_bones[x], sorted(list(vertex_group_bone_indices))):
|
vertex_groups = [None] * len(psk.bones)
|
||||||
import_bone.vertex_group = mesh_object.vertex_groups.new(
|
for bone_index, psk_bone in map(lambda x: (x, psk.bones[x]), vertex_group_bone_indices):
|
||||||
name=import_bone.psk_bone.name.decode('windows-1252'))
|
vertex_groups[bone_index] = mesh_object.vertex_groups.new(name=psk_bone.name.decode('windows-1252'))
|
||||||
|
|
||||||
for weight in psk.weights:
|
for weight in psk.weights:
|
||||||
import_bones[weight.bone_index].vertex_group.add((weight.point_index,), weight.weight, 'ADD')
|
vertex_groups[weight.bone_index].add((weight.point_index,), weight.weight, 'ADD')
|
||||||
|
|
||||||
|
context.scene.collection.objects.link(mesh_object)
|
||||||
|
|
||||||
# Add armature modifier to our mesh object.
|
# Add armature modifier to our mesh object.
|
||||||
|
if options.should_import_skeleton:
|
||||||
armature_modifier = mesh_object.modifiers.new(name='Armature', type='ARMATURE')
|
armature_modifier = mesh_object.modifiers.new(name='Armature', type='ARMATURE')
|
||||||
armature_modifier.object = armature_object
|
armature_modifier.object = armature_object
|
||||||
mesh_object.parent = armature_object
|
mesh_object.parent = armature_object
|
||||||
|
|
||||||
context.scene.collection.objects.link(mesh_object)
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
bpy.ops.object.mode_set(mode='OBJECT')
|
bpy.ops.object.mode_set(mode='OBJECT')
|
||||||
except:
|
except:
|
||||||
@@ -256,6 +263,18 @@ class PskImportPropertyGroup(PropertyGroup):
|
|||||||
options=set(),
|
options=set(),
|
||||||
description='Import extra UV maps from PSKX files, if available'
|
description='Import extra UV maps from PSKX files, if available'
|
||||||
)
|
)
|
||||||
|
should_import_mesh: BoolProperty(
|
||||||
|
default=True,
|
||||||
|
name='Import Mesh',
|
||||||
|
options=set(),
|
||||||
|
description='Import mesh'
|
||||||
|
)
|
||||||
|
should_import_skeleton: BoolProperty(
|
||||||
|
default=True,
|
||||||
|
name='Import Skeleton',
|
||||||
|
options=set(),
|
||||||
|
description='Import skeleton'
|
||||||
|
)
|
||||||
bone_length: FloatProperty(
|
bone_length: FloatProperty(
|
||||||
default=1.0,
|
default=1.0,
|
||||||
min=sys.float_info.epsilon,
|
min=sys.float_info.epsilon,
|
||||||
@@ -269,7 +288,7 @@ class PskImportPropertyGroup(PropertyGroup):
|
|||||||
|
|
||||||
class PskImportOperator(Operator, ImportHelper):
|
class PskImportOperator(Operator, ImportHelper):
|
||||||
bl_idname = 'import.psk'
|
bl_idname = 'import.psk'
|
||||||
bl_label = 'Export'
|
bl_label = 'Import'
|
||||||
bl_options = {'INTERNAL', 'UNDO'}
|
bl_options = {'INTERNAL', 'UNDO'}
|
||||||
__doc__ = 'Load a PSK file'
|
__doc__ = 'Load a PSK file'
|
||||||
filename_ext = '.psk'
|
filename_ext = '.psk'
|
||||||
@@ -287,10 +306,12 @@ class PskImportOperator(Operator, ImportHelper):
|
|||||||
|
|
||||||
options = PskImportOptions()
|
options = PskImportOptions()
|
||||||
options.name = os.path.splitext(os.path.basename(self.filepath))[0]
|
options.name = os.path.splitext(os.path.basename(self.filepath))[0]
|
||||||
|
options.should_import_mesh = pg.should_import_mesh
|
||||||
options.should_import_extra_uvs = pg.should_import_extra_uvs
|
options.should_import_extra_uvs = pg.should_import_extra_uvs
|
||||||
options.should_import_vertex_colors = pg.should_import_vertex_colors
|
options.should_import_vertex_colors = pg.should_import_vertex_colors
|
||||||
options.should_import_vertex_normals = pg.should_import_vertex_normals
|
options.should_import_vertex_normals = pg.should_import_vertex_normals
|
||||||
options.vertex_color_space = pg.vertex_color_space
|
options.vertex_color_space = pg.vertex_color_space
|
||||||
|
options.should_import_skeleton = pg.should_import_skeleton
|
||||||
options.bone_length = pg.bone_length
|
options.bone_length = pg.bone_length
|
||||||
|
|
||||||
import_psk(psk, context, options)
|
import_psk(psk, context, options)
|
||||||
@@ -300,14 +321,22 @@ class PskImportOperator(Operator, ImportHelper):
|
|||||||
def draw(self, context):
|
def draw(self, context):
|
||||||
pg = context.scene.psk_import
|
pg = context.scene.psk_import
|
||||||
layout = self.layout
|
layout = self.layout
|
||||||
layout.use_property_split = True
|
layout.prop(pg, 'should_import_mesh')
|
||||||
layout.use_property_decorate = False
|
row = layout.column()
|
||||||
layout.prop(pg, 'should_import_vertex_normals')
|
row.use_property_split = True
|
||||||
layout.prop(pg, 'should_import_extra_uvs')
|
row.use_property_decorate = False
|
||||||
layout.prop(pg, 'should_import_vertex_colors')
|
if pg.should_import_mesh:
|
||||||
|
row.prop(pg, 'should_import_vertex_normals')
|
||||||
|
row.prop(pg, 'should_import_extra_uvs')
|
||||||
|
row.prop(pg, 'should_import_vertex_colors')
|
||||||
if pg.should_import_vertex_colors:
|
if pg.should_import_vertex_colors:
|
||||||
layout.prop(pg, 'vertex_color_space')
|
row.prop(pg, 'vertex_color_space')
|
||||||
layout.prop(pg, 'bone_length')
|
layout.prop(pg, 'should_import_skeleton')
|
||||||
|
row = layout.column()
|
||||||
|
row.use_property_split = True
|
||||||
|
row.use_property_decorate = False
|
||||||
|
if pg.should_import_skeleton:
|
||||||
|
row.prop(pg, 'bone_length')
|
||||||
|
|
||||||
|
|
||||||
classes = (
|
classes = (
|
||||||
|
|||||||
Reference in New Issue
Block a user