mirror of
https://github.com/DarklightGames/io_scene_psk_psa.git
synced 2024-11-15 02:37:39 +01:00
Typing and naming improvements
This commit is contained in:
parent
38ed183897
commit
8ada80e243
@ -112,20 +112,20 @@ def build_psa(context: bpy.types.Context, options: PsaBuildOptions) -> Psa:
|
||||
|
||||
psa = Psa()
|
||||
|
||||
armature = active_object
|
||||
armature_data = typing.cast(Armature, armature)
|
||||
armature_object = active_object
|
||||
armature_data = typing.cast(Armature, armature_object.data)
|
||||
bones: List[Bone] = list(iter(armature_data.bones))
|
||||
|
||||
# The order of the armature bones and the pose bones is not guaranteed to be the same.
|
||||
# As a result, we need to reconstruct the list of pose bones in the same order as the
|
||||
# armature bones.
|
||||
bone_names = [x.name for x in bones]
|
||||
pose_bones = [(bone_names.index(bone.name), bone) for bone in armature.pose.bones]
|
||||
pose_bones = [(bone_names.index(bone.name), bone) for bone in armature_object.pose.bones]
|
||||
pose_bones.sort(key=lambda x: x[0])
|
||||
pose_bones = [x[1] for x in pose_bones]
|
||||
|
||||
# Get a list of all the bone indices and instigator bones for the bone filter settings.
|
||||
export_bone_names = get_export_bone_names(armature, options.bone_filter_mode, options.bone_group_indices)
|
||||
export_bone_names = get_export_bone_names(armature_object, options.bone_filter_mode, options.bone_group_indices)
|
||||
bone_indices = [bone_names.index(x) for x in export_bone_names]
|
||||
|
||||
# Make the bone lists contain only the bones that are going to be exported.
|
||||
@ -263,7 +263,7 @@ def build_psa(context: bpy.types.Context, options: PsaBuildOptions) -> Psa:
|
||||
else:
|
||||
if options.root_motion:
|
||||
# Export root motion
|
||||
pose_bone_matrix = armature.matrix_world @ pose_bone.matrix
|
||||
pose_bone_matrix = armature_object.matrix_world @ pose_bone.matrix
|
||||
else:
|
||||
pose_bone_matrix = pose_bone.matrix
|
||||
|
||||
|
@ -1,5 +1,8 @@
|
||||
import typing
|
||||
|
||||
import bmesh
|
||||
import bpy
|
||||
from bpy.types import Armature
|
||||
|
||||
from .data import *
|
||||
from ..helpers import *
|
||||
@ -59,7 +62,7 @@ def get_psk_input_objects(context) -> PskInputObjects:
|
||||
def build_psk(context, options: PskBuildOptions) -> Psk:
|
||||
input_objects = get_psk_input_objects(context)
|
||||
|
||||
armature_object = input_objects.armature_object
|
||||
armature_object: bpy.types.Object = input_objects.armature_object
|
||||
|
||||
psk = Psk()
|
||||
bones = []
|
||||
@ -77,7 +80,8 @@ def build_psk(context, options: PskBuildOptions) -> Psk:
|
||||
psk.bones.append(psk_bone)
|
||||
else:
|
||||
bone_names = get_export_bone_names(armature_object, options.bone_filter_mode, options.bone_group_indices)
|
||||
bones = [armature_object.data.bones[bone_name] for bone_name in bone_names]
|
||||
armature_data = typing.cast(Armature, armature_object.data)
|
||||
bones = [armature_data.bones[bone_name] for bone_name in bone_names]
|
||||
|
||||
# Check that all bone names are valid.
|
||||
if not options.should_ignore_bone_name_restrictions:
|
||||
@ -98,9 +102,9 @@ def build_psk(context, options: PskBuildOptions) -> Psk:
|
||||
|
||||
if bone.parent is not None:
|
||||
rotation = bone.matrix.to_quaternion().conjugated()
|
||||
quat_parent = bone.parent.matrix.to_quaternion().inverted()
|
||||
parent_head = quat_parent @ bone.parent.head
|
||||
parent_tail = quat_parent @ bone.parent.tail
|
||||
inverse_parent_rotation = bone.parent.matrix.to_quaternion().inverted()
|
||||
parent_head = inverse_parent_rotation @ bone.parent.head
|
||||
parent_tail = inverse_parent_rotation @ bone.parent.tail
|
||||
location = (parent_tail - parent_head) + bone.head
|
||||
else:
|
||||
armature_local_matrix = armature_object.matrix_local
|
||||
@ -219,6 +223,7 @@ def build_psk(context, options: PskBuildOptions) -> Psk:
|
||||
|
||||
# WEIGHTS
|
||||
if armature_object is not None:
|
||||
armature_data = typing.cast(Armature, armature_object.data)
|
||||
# Because the vertex groups may contain entries for which there is no matching bone in the armature,
|
||||
# we must filter them out and not export any weights for these vertex groups.
|
||||
bone_names = [x.name for x in bones]
|
||||
@ -232,8 +237,8 @@ def build_psk(context, options: PskBuildOptions) -> Psk:
|
||||
# Check to see if there is an associated bone for this vertex group that exists in the armature.
|
||||
# If there is, we can traverse the ancestors of that bone to find an alternate bone to use for
|
||||
# weighting the vertices belonging to this vertex group.
|
||||
if vertex_group_name in armature_object.data.bones:
|
||||
bone = armature_object.data.bones[vertex_group_name]
|
||||
if vertex_group_name in armature_data.bones:
|
||||
bone = armature_data.bones[vertex_group_name]
|
||||
while bone is not None:
|
||||
try:
|
||||
bone_index = bone_names.index(bone.name)
|
||||
|
Loading…
Reference in New Issue
Block a user