Skip to content

Commit

Permalink
Fixed runtime error with bones number mismatch
Browse files Browse the repository at this point in the history
  • Loading branch information
Psycrow101 committed Mar 24, 2023
1 parent d268912 commit 5aa0461
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion io_scene_bfbb_anm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
bl_info = {
"name": "Battle for Bikini Bottom Animation",
"author": "Psycrow",
"version": (0, 0, 1),
"version": (0, 0, 2),
"blender": (2, 81, 0),
"location": "File > Import-Export",
"description": "Import / Export BFBB Animation (.anm)",
Expand Down
13 changes: 12 additions & 1 deletion io_scene_bfbb_anm/import_bfbb_anm.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ def invalid_active_object(self, context):
self.layout.label(text='You need to select the armature to import animation')


def bones_number_mismatch(self, context):
self.layout.label(text='Bones number mismatch')


def set_keyframe(curves, frame, values):
for i, c in enumerate(curves):
c.keyframe_points.add(1)
Expand Down Expand Up @@ -42,8 +46,12 @@ def create_action(arm_obj, anm, fps):

set_kfs = []

arm_bones_num, anm_bones_num = len(arm_obj.pose.bones), len(anm.offsets[0])
if arm_bones_num > anm_bones_num:
arm_bones_num = anm_bones_num

for off in anm.offsets:
for bone_id, bone in enumerate(arm_obj.pose.bones):
for bone_id, bone in enumerate(arm_obj.pose.bones[:arm_bones_num]):
kf_id = off[bone_id]

if kf_id in set_kfs:
Expand Down Expand Up @@ -74,6 +82,9 @@ def load(context, filepath, *, fps):
context.window_manager.popup_menu(invalid_file_format, title='Error', icon='ERROR')
return {'CANCELLED'}

arm_bones_num, anm_bones_num = len(arm_obj.pose.bones), len(anm.offsets[0])
if arm_bones_num != anm_bones_num:
context.window_manager.popup_menu(bones_number_mismatch, title='Error', icon='ERROR')

animation_data = arm_obj.animation_data
if not animation_data:
Expand Down

0 comments on commit 5aa0461

Please sign in to comment.