1
0
mirror of https://github.com/DarklightGames/io_scene_psk_psa.git synced 2025-01-31 11:53:47 +01:00

Added the ability for users to export "static meshes" for meshes that don't have armature modifiers

This commit is contained in:
Colin Basnett 2021-08-14 18:00:16 -07:00
parent e51013eec7
commit a76215569d

View File

@ -30,23 +30,24 @@ class PskBuilder(object):
if len(obj.data.materials) == 0:
raise RuntimeError(f'Mesh "{obj.name}" must have at least one material')
# ensure that there is exactly one armature modifier object shared between all selected meshes
# Ensure that there are either no armature modifiers (static mesh)
# or that there is exactly one armature modifier object shared between
# all selected meshes
armature_modifier_objects = set()
for obj in input_objects.mesh_objects:
modifiers = [x for x in obj.modifiers if x.type == 'ARMATURE']
if len(modifiers) != 1:
raise RuntimeError(f'Mesh "{obj.name}" must have one armature modifier')
if len(modifiers) == 0:
continue
elif len(modifiers) == 2:
raise RuntimeError(f'Mesh "{obj.name}" must have only one armature modifier')
armature_modifier_objects.add(modifiers[0].object)
if len(armature_modifier_objects) > 1:
raise RuntimeError('All selected meshes must have the same armature modifier')
elif len(armature_modifier_objects) == 1:
input_objects.armature_object = list(armature_modifier_objects)[0]
if input_objects.armature_object is None:
raise RuntimeError('Armature modifier has no linked object')
return input_objects
def build(self, context) -> Psk:
@ -61,6 +62,17 @@ class PskBuilder(object):
materials = OrderedDict()
if input_objects.armature_object is None:
# Static mesh (no armature)
psk_bone = Psk.Bone()
psk_bone.name = bytes('static', encoding='utf-8')
psk_bone.flags = 0
psk_bone.children_count = 0
psk_bone.parent_index = 0
psk_bone.location = Vector3(0, 0, 0)
psk_bone.rotation = Quaternion(0, 0, 0, 1)
psk.bones.append(psk_bone)
else:
bones = list(input_objects.armature_object.data.bones)
for bone in bones:
psk_bone = Psk.Bone()
@ -143,7 +155,6 @@ class PskBuilder(object):
material_indices.append(material_index)
# FACES
# TODO: this is making the assumption that the mesh is triangulated
object.data.calc_loop_triangles()
poly_groups, groups = object.data.calc_smooth_groups(use_bitflags=True)
for f in object.data.loop_triangles:
@ -160,6 +171,7 @@ class PskBuilder(object):
# WEIGHTS
# TODO: bone ~> vg might not be 1:1, provide a nice error message if this is the case
if input_objects.armature_object is not None:
armature = input_objects.armature_object.data
bone_names = [x.name for x in armature.bones]
vertex_group_names = [x.name for x in object.vertex_groups]