Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scale keys import (SCALEKEYS chunk support) + misc 4.0 changes #84

Open
wants to merge 2 commits into
base: latest
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 63 additions & 3 deletions addons/io_import_scene_unreal_psa_psk_270.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
78 changes: 74 additions & 4 deletions addons/io_import_scene_unreal_psa_psk_280.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, 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",
Expand Down Expand Up @@ -57,9 +57,31 @@
"""

"""
Version': '2.8.0' edited by floxay
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)

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
Expand Down Expand Up @@ -1167,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'
Expand Down Expand Up @@ -1244,6 +1266,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
Expand Down Expand Up @@ -1638,6 +1663,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])

Expand Down Expand Up @@ -1672,6 +1698,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')
Expand Down Expand Up @@ -1763,6 +1811,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:
Expand Down Expand Up @@ -1827,6 +1886,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

Expand Down