From 3e8007a1f9a4277737273c970f3473f573c3a526 Mon Sep 17 00:00:00 2001 From: floxay <57007485+floxay@users.noreply.github.com> Date: Sat, 30 Apr 2022 22:50:40 +0200 Subject: [PATCH 1/2] Scale keys import Support for SCALEKEYS chunk --- addons/io_import_scene_unreal_psa_psk_270.py | 66 +++++++++++++++++- addons/io_import_scene_unreal_psa_psk_280.py | 73 +++++++++++++++++++- 2 files changed, 133 insertions(+), 6 deletions(-) diff --git a/addons/io_import_scene_unreal_psa_psk_270.py b/addons/io_import_scene_unreal_psa_psk_270.py index 34f9518..bd548cd 100644 --- a/addons/io_import_scene_unreal_psa_psk_270.py +++ b/addons/io_import_scene_unreal_psa_psk_270.py @@ -19,7 +19,7 @@ bl_info = { "name": "Import Unreal Skeleton Mesh (.psk)/Animation Set (.psa) (270)", "author": "Darknet, flufy3d, camg188, befzz", - "version": (2, 8, 0), + "version": (2, 8, 4), "blender": (2, 76, 0), "location": "File > Import > Skeleton Mesh (.psk)/Animation Set (.psa) OR View3D > Tool Shelf (key T) > Misc. tab", "description": "Import Skeleton Mesh / Animation Data", @@ -57,9 +57,23 @@ """ """ -Version': '2.8.0' edited by floxay +Changelog: +2.8.4: (floxay) +- Animation bone scaling import (SCALEKEYS chunk) + (requires custom UEViewer build /at the moment/ or Fmodel) + +2.8.3: (beffz) +!CHANGES MISSING FROM 270! + +2.8.2: (beffz) +!CHANGES MISSING FROM 270! + +2.8.1: (beffz) +!CHANGES MISSING FROM 270! + +2.8.0: (floxay) - Vertex normals import (VTXNORMS chunk) - (requires custom UEViewer build /at the moment/) + (requires custom UEViewer build /at the moment/ or Fmodel) """ # https://github.com/gildor2/UModel/blob/master/Exporters/Psk.h @@ -1048,6 +1062,9 @@ class class_psa_bone: fcurve_quat_y = None fcurve_quat_z = None fcurve_quat_w = None + fcurve_scale_x = None + fcurve_scale_y = None + fcurve_scale_z = None post_quat = None orig_quat = None @@ -1283,6 +1300,28 @@ def new_psa_bone(bone, pose_bone): Raw_Key_List[counter] = (pos, quat) + #============================================================================================== + # Raw scale keys (VScaleAnimKey) 3f vec, 1f time + #============================================================================================== + curr_pos = psafile.tell() # save current position + psafile.seek(0, 2) # seek to end + + if (curr_pos != psafile.tell()): # make sure not eof + psafile.seek(curr_pos) # seek back to previous pos + read_chunk() + + Raw_ScaleKey_List = [None] * chunk_datacount + + unpack_data = Struct('3f4x').unpack_from + + for counter in range(chunk_datacount): + scale = Vector() + + (scale.x, scale.y, scale.z) = unpack_data( chunk_data, chunk_datasize * counter) + + Raw_ScaleKey_List[counter] = scale + + psafile.close() utils_set_mode('OBJECT') @@ -1361,6 +1400,17 @@ def new_psa_bone(bone, pose_bone): psa_bone.fcurve_loc_x.keyframe_points.add(keyframes) psa_bone.fcurve_loc_y.keyframe_points.add(keyframes) psa_bone.fcurve_loc_z.keyframe_points.add(keyframes) + + if Raw_ScaleKey_List: + data_path = pose_bone.path_from_id("scale") + psa_bone.fcurve_scale_x = action.fcurves.new(data_path, index = 0) + psa_bone.fcurve_scale_y = action.fcurves.new(data_path, index = 1) + psa_bone.fcurve_scale_z = action.fcurves.new(data_path, index = 2) + + + psa_bone.fcurve_scale_x.keyframe_points.add(keyframes) + psa_bone.fcurve_scale_y.keyframe_points.add(keyframes) + psa_bone.fcurve_scale_z.keyframe_points.add(keyframes) for i in range(0,min(maxframes, NumRawFrames)): # raw_key_index+= Totalbones * 5 #55 @@ -1419,6 +1469,16 @@ def new_psa_bone(bone, pose_bone): psa_bone.fcurve_quat_x.keyframe_points[i].interpolation = fcurve_interpolation psa_bone.fcurve_quat_y.keyframe_points[i].interpolation = fcurve_interpolation psa_bone.fcurve_quat_z.keyframe_points[i].interpolation = fcurve_interpolation + + if Raw_ScaleKey_List: + scale = Raw_ScaleKey_List[raw_key_index] + + psa_bone.fcurve_scale_x.keyframe_points[i].co = i, scale.x + psa_bone.fcurve_scale_y.keyframe_points[i].co = i, scale.y + psa_bone.fcurve_scale_z.keyframe_points[i].co = i, scale.z + psa_bone.fcurve_scale_x.keyframe_points[i].interpolation = fcurve_interpolation + psa_bone.fcurve_scale_y.keyframe_points[i].interpolation = fcurve_interpolation + psa_bone.fcurve_scale_z.keyframe_points[i].interpolation = fcurve_interpolation psa_bone.fcurve_loc_x.keyframe_points[i].co = i, loc.x psa_bone.fcurve_loc_y.keyframe_points[i].co = i, loc.y diff --git a/addons/io_import_scene_unreal_psa_psk_280.py b/addons/io_import_scene_unreal_psa_psk_280.py index 0dee4e0..393141a 100644 --- a/addons/io_import_scene_unreal_psa_psk_280.py +++ b/addons/io_import_scene_unreal_psa_psk_280.py @@ -19,7 +19,7 @@ bl_info = { "name": "Import Unreal Skeleton Mesh (.psk)/Animation Set (.psa) (280)", "author": "Darknet, flufy3d, camg188, befzz", - "version": (2, 8, 3), + "version": (2, 8, 4), "blender": (2, 80, 0), "location": "File > Import > Skeleton Mesh (.psk)/Animation Set (.psa) OR View3D > Tool Shelf (key T) > Misc. tab", "description": "Import Skeleton Mesh / Animation Data", @@ -57,9 +57,28 @@ """ """ -Version': '2.8.0' edited by floxay +Changelog: +2.8.4: (floxay) +- Animation bone scaling import (SCALEKEYS chunk) + (requires custom UEViewer build /at the moment/ or Fmodel) + +2.8.3: (beffz) +- fix panel ui not working #76 + +2.8.2: (beffz) +- bpy.ops.import_scene.psk() now accept "filepath" argument again +- multiple .psa import (bpy.ops) +* don't spam about vertex-color data + +2.8.1: (beffz) +- .config file reading +* case-insensitive bone name comparison is now optional +* duplicated bone names handling +- some "not so useful info" to console + +2.8.0: (floxay) - Vertex normals import (VTXNORMS chunk) - (requires custom UEViewer build /at the moment/) + (requires custom UEViewer build /at the moment/ or Fmodel) """ # https://github.com/gildor2/UModel/blob/master/Exporters/Psk.h @@ -1244,6 +1263,9 @@ class class_psa_bone: fcurve_quat_y = None fcurve_quat_z = None fcurve_quat_w = None + fcurve_scale_x = None + fcurve_scale_y = None + fcurve_scale_z = None post_quat = None orig_quat = None @@ -1638,6 +1660,7 @@ def new_psa_bone(bone, pose_bone, psa_index): AnimFlags[action_name][bone_index].no_translation = True elif flag_str[0] == 'r': #rot AnimFlags[action_name][bone_index].no_rotation = True + # TODO: Handle flag for scale # print(AnimFlags[action_name][bone_index]) @@ -1672,6 +1695,28 @@ def new_psa_bone(bone, pose_bone, psa_index): else: Raw_Key_List[counter] = (pos, quat) + #============================================================================================== + # Raw scale keys (VScaleAnimKey) 3f vec, 1f time + #============================================================================================== + curr_pos = psafile.tell() # save current position + psafile.seek(0, 2) # seek to end + + if (curr_pos != psafile.tell()): # make sure not eof + psafile.seek(curr_pos) # seek back to previous pos + read_chunk() + + Raw_ScaleKey_List = [None] * chunk_datacount + + unpack_data = Struct('3f4x').unpack_from + + for counter in range(chunk_datacount): + scale = Vector() + + (scale.x, scale.y, scale.z) = unpack_data( chunk_data, chunk_datasize * counter) + + Raw_ScaleKey_List[counter] = scale + + psafile.close() utils_set_mode('OBJECT') @@ -1763,6 +1808,17 @@ def new_psa_bone(bone, pose_bone, psa_index): psa_bone.fcurve_quat_y.keyframe_points.add(keyframes) psa_bone.fcurve_quat_z.keyframe_points.add(keyframes) + if Raw_ScaleKey_List: + data_path = pose_bone.path_from_id("scale") + psa_bone.fcurve_scale_x = action.fcurves.new(data_path, index = 0) + psa_bone.fcurve_scale_y = action.fcurves.new(data_path, index = 1) + psa_bone.fcurve_scale_z = action.fcurves.new(data_path, index = 2) + + + psa_bone.fcurve_scale_x.keyframe_points.add(keyframes) + psa_bone.fcurve_scale_y.keyframe_points.add(keyframes) + psa_bone.fcurve_scale_z.keyframe_points.add(keyframes) + if not bRotationOnly: if UseAnimTranslation[psa_bone.psa_index]: if bone_import_trans: @@ -1827,6 +1883,17 @@ def new_psa_bone(bone, pose_bone, psa_index): psa_bone.fcurve_quat_y.keyframe_points[i].interpolation = fcurve_interpolation psa_bone.fcurve_quat_z.keyframe_points[i].interpolation = fcurve_interpolation + if Raw_ScaleKey_List: + scale = Raw_ScaleKey_List[raw_key_index] + + psa_bone.fcurve_scale_x.keyframe_points[i].co = i, scale.x + psa_bone.fcurve_scale_y.keyframe_points[i].co = i, scale.y + psa_bone.fcurve_scale_z.keyframe_points[i].co = i, scale.z + + psa_bone.fcurve_scale_x.keyframe_points[i].interpolation = fcurve_interpolation + psa_bone.fcurve_scale_y.keyframe_points[i].interpolation = fcurve_interpolation + psa_bone.fcurve_scale_z.keyframe_points[i].interpolation = fcurve_interpolation + # @ # loc = psa_bone.post_quat.conjugated() * p_pos - psa_bone.post_quat.conjugated() * psa_bone.orig_loc From 93df4e21ae85bad67a459d7ba3bbae0018991f1f Mon Sep 17 00:00:00 2001 From: Huba Tuba <57007485+floxay@users.noreply.github.com> Date: Thu, 21 Dec 2023 01:19:00 +0100 Subject: [PATCH 2/2] fix: disable bone colorizing on Blender 4 --- addons/io_import_scene_unreal_psa_psk_280.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/addons/io_import_scene_unreal_psa_psk_280.py b/addons/io_import_scene_unreal_psa_psk_280.py index 393141a..f9f0f76 100644 --- a/addons/io_import_scene_unreal_psa_psk_280.py +++ b/addons/io_import_scene_unreal_psa_psk_280.py @@ -19,7 +19,7 @@ bl_info = { "name": "Import Unreal Skeleton Mesh (.psk)/Animation Set (.psa) (280)", "author": "Darknet, flufy3d, camg188, befzz", - "version": (2, 8, 4), + "version": (2, 8, 5), "blender": (2, 80, 0), "location": "File > Import > Skeleton Mesh (.psk)/Animation Set (.psa) OR View3D > Tool Shelf (key T) > Misc. tab", "description": "Import Skeleton Mesh / Animation Data", @@ -58,9 +58,12 @@ """ Changelog: +2.8.5: (floxay) +- Disable bone colorizing on Blender 4 to prevent crashing due to Blender API changes + 2.8.4: (floxay) - Animation bone scaling import (SCALEKEYS chunk) - (requires custom UEViewer build /at the moment/ or Fmodel) + (requires custom UEViewer build /at the moment/ or Fmodel) 2.8.3: (beffz) - fix panel ui not working #76 @@ -1186,7 +1189,7 @@ def init_psk_bone(i, psk_bones, name_raw): #============================================================================================== # Skeleton. Colorize. - if bImportbone: + if bImportbone and bpy.app.version[0] < 4: bone_group_unused = armature_obj.pose.bone_groups.new(name = "Unused bones") bone_group_unused.color_set = 'THEME14'