Merge pull request #6 from DarklightGames/feature-static-meshes
Added the ability for users to export "static meshes" for meshes don't have armature modifiers
This commit is contained in:
@@ -30,23 +30,24 @@ class PskBuilder(object):
|
|||||||
if len(obj.data.materials) == 0:
|
if len(obj.data.materials) == 0:
|
||||||
raise RuntimeError(f'Mesh "{obj.name}" must have at least one material')
|
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()
|
armature_modifier_objects = set()
|
||||||
|
|
||||||
for obj in input_objects.mesh_objects:
|
for obj in input_objects.mesh_objects:
|
||||||
modifiers = [x for x in obj.modifiers if x.type == 'ARMATURE']
|
modifiers = [x for x in obj.modifiers if x.type == 'ARMATURE']
|
||||||
if len(modifiers) != 1:
|
if len(modifiers) == 0:
|
||||||
raise RuntimeError(f'Mesh "{obj.name}" must have one armature modifier')
|
continue
|
||||||
|
elif len(modifiers) == 2:
|
||||||
|
raise RuntimeError(f'Mesh "{obj.name}" must have only one armature modifier')
|
||||||
armature_modifier_objects.add(modifiers[0].object)
|
armature_modifier_objects.add(modifiers[0].object)
|
||||||
|
|
||||||
if len(armature_modifier_objects) > 1:
|
if len(armature_modifier_objects) > 1:
|
||||||
raise RuntimeError('All selected meshes must have the same armature modifier')
|
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]
|
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
|
return input_objects
|
||||||
|
|
||||||
def build(self, context) -> Psk:
|
def build(self, context) -> Psk:
|
||||||
@@ -61,6 +62,17 @@ class PskBuilder(object):
|
|||||||
|
|
||||||
materials = OrderedDict()
|
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)
|
bones = list(input_objects.armature_object.data.bones)
|
||||||
for bone in bones:
|
for bone in bones:
|
||||||
psk_bone = Psk.Bone()
|
psk_bone = Psk.Bone()
|
||||||
@@ -143,7 +155,6 @@ class PskBuilder(object):
|
|||||||
material_indices.append(material_index)
|
material_indices.append(material_index)
|
||||||
|
|
||||||
# FACES
|
# FACES
|
||||||
# TODO: this is making the assumption that the mesh is triangulated
|
|
||||||
object.data.calc_loop_triangles()
|
object.data.calc_loop_triangles()
|
||||||
poly_groups, groups = object.data.calc_smooth_groups(use_bitflags=True)
|
poly_groups, groups = object.data.calc_smooth_groups(use_bitflags=True)
|
||||||
for f in object.data.loop_triangles:
|
for f in object.data.loop_triangles:
|
||||||
@@ -160,6 +171,7 @@ class PskBuilder(object):
|
|||||||
|
|
||||||
# WEIGHTS
|
# WEIGHTS
|
||||||
# TODO: bone ~> vg might not be 1:1, provide a nice error message if this is the case
|
# 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
|
armature = input_objects.armature_object.data
|
||||||
bone_names = [x.name for x in armature.bones]
|
bone_names = [x.name for x in armature.bones]
|
||||||
vertex_group_names = [x.name for x in object.vertex_groups]
|
vertex_group_names = [x.name for x in object.vertex_groups]
|
||||||
|
|||||||
Reference in New Issue
Block a user