Compare commits
8 Commits
feature-mu
...
1.1.0
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4c4900e388 | ||
|
|
08f4960e1f | ||
|
|
f08ecc457f | ||
|
|
0d03e49da3 | ||
|
|
32cadbfe31 | ||
|
|
a76215569d | ||
|
|
e51013eec7 | ||
|
|
94da7b4acf |
26
README.md
26
README.md
@@ -1,3 +1,25 @@
|
|||||||
# io_export_psk_psa
|
This Blender add-on allows you to export meshes and animations to the [PSK and PSA file formats](https://wiki.beyondunreal.com/PSK_%26_PSA_file_formats).
|
||||||
|
|
||||||
If you are looking for a PSK/PSA importer, use [this one](https://github.com/Befzz/blender3d_import_psk_psa)!
|
# Installation
|
||||||
|
1. Download the zip file for the latest version from the [releases](https://github.com/DarklightGames/io_export_psk_psa/releases) page.
|
||||||
|
2. Open Blender 2.80 or later.
|
||||||
|
3. Navigate to the Blender Preferences (Edit > Preferences).
|
||||||
|
4. Select the "Add-ons" tab.
|
||||||
|
5. Click the "Install..." button.
|
||||||
|
6. Select the .zip file that you downloaded earlier and click "Install Add-on".
|
||||||
|
7. Enable the newly added "Import-Export: PSK/PSA Exporter" addon.
|
||||||
|
|
||||||
|
# Usage
|
||||||
|
## Exporting a PSK
|
||||||
|
1. Select the mesh objects you wish to export.
|
||||||
|
3. Navigate to File > Export > Unreal PSK (.psk)
|
||||||
|
4. Enter the file name and click "Export".
|
||||||
|
|
||||||
|
## Exporting a PSA
|
||||||
|
1. Select the armature objects you wish to export.
|
||||||
|
2. Navigate to File > Export > Unreal PSA (.psa)
|
||||||
|
3. Enter the file name and click "Export".
|
||||||
|
|
||||||
|
# FAQ
|
||||||
|
## Can I use this addon to import PSK and PSA files?
|
||||||
|
Currently, no. If you are looking for a PSK/PSA importer, use [this one](https://github.com/Befzz/blender3d_import_psk_psa)!
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
bl_info = {
|
bl_info = {
|
||||||
"name": "PSK/PSA Exporter",
|
"name": "PSK/PSA Exporter",
|
||||||
"author": "Colin Basnett",
|
"author": "Colin Basnett",
|
||||||
"version": ( 1, 0, 0 ),
|
"version": ( 1, 1, 0 ),
|
||||||
"blender": ( 2, 80, 0 ),
|
"blender": ( 2, 80, 0 ),
|
||||||
"location": "File > Export > PSK Export (.psk)",
|
"location": "File > Export > PSK Export (.psk)",
|
||||||
"description": "PSK/PSA Export (.psk)",
|
"description": "PSK/PSA Export (.psk)",
|
||||||
|
|||||||
@@ -30,22 +30,23 @@ 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
|
||||||
|
|
||||||
@@ -61,42 +62,53 @@ class PskBuilder(object):
|
|||||||
|
|
||||||
materials = OrderedDict()
|
materials = OrderedDict()
|
||||||
|
|
||||||
bones = list(input_objects.armature_object.data.bones)
|
if input_objects.armature_object is None:
|
||||||
for bone in bones:
|
# Static mesh (no armature)
|
||||||
psk_bone = Psk.Bone()
|
psk_bone = Psk.Bone()
|
||||||
psk_bone.name = bytes(bone.name, encoding='utf-8')
|
psk_bone.name = bytes('static', encoding='utf-8')
|
||||||
psk_bone.flags = 0
|
psk_bone.flags = 0
|
||||||
psk_bone.children_count = len(bone.children)
|
psk_bone.children_count = 0
|
||||||
|
psk_bone.parent_index = 0
|
||||||
try:
|
psk_bone.location = Vector3(0, 0, 0)
|
||||||
psk_bone.parent_index = bones.index(bone.parent)
|
psk_bone.rotation = Quaternion(0, 0, 0, 1)
|
||||||
except ValueError:
|
|
||||||
psk_bone.parent_index = 0
|
|
||||||
|
|
||||||
if bone.parent is not None:
|
|
||||||
rotation = bone.matrix.to_quaternion()
|
|
||||||
rotation.x = -rotation.x
|
|
||||||
rotation.y = -rotation.y
|
|
||||||
rotation.z = -rotation.z
|
|
||||||
quat_parent = bone.parent.matrix.to_quaternion().inverted()
|
|
||||||
parent_head = quat_parent @ bone.parent.head
|
|
||||||
parent_tail = quat_parent @ bone.parent.tail
|
|
||||||
location = (parent_tail - parent_head) + bone.head
|
|
||||||
else:
|
|
||||||
location = input_objects.armature_object.matrix_local @ bone.head
|
|
||||||
rot_matrix = bone.matrix @ input_objects.armature_object.matrix_local.to_3x3()
|
|
||||||
rotation = rot_matrix.to_quaternion()
|
|
||||||
|
|
||||||
psk_bone.location.x = location.x
|
|
||||||
psk_bone.location.y = location.y
|
|
||||||
psk_bone.location.z = location.z
|
|
||||||
|
|
||||||
psk_bone.rotation.x = rotation.x
|
|
||||||
psk_bone.rotation.y = rotation.y
|
|
||||||
psk_bone.rotation.z = rotation.z
|
|
||||||
psk_bone.rotation.w = rotation.w
|
|
||||||
|
|
||||||
psk.bones.append(psk_bone)
|
psk.bones.append(psk_bone)
|
||||||
|
else:
|
||||||
|
bones = list(input_objects.armature_object.data.bones)
|
||||||
|
for bone in bones:
|
||||||
|
psk_bone = Psk.Bone()
|
||||||
|
psk_bone.name = bytes(bone.name, encoding='utf-8')
|
||||||
|
psk_bone.flags = 0
|
||||||
|
psk_bone.children_count = len(bone.children)
|
||||||
|
|
||||||
|
try:
|
||||||
|
psk_bone.parent_index = bones.index(bone.parent)
|
||||||
|
except ValueError:
|
||||||
|
psk_bone.parent_index = 0
|
||||||
|
|
||||||
|
if bone.parent is not None:
|
||||||
|
rotation = bone.matrix.to_quaternion()
|
||||||
|
rotation.x = -rotation.x
|
||||||
|
rotation.y = -rotation.y
|
||||||
|
rotation.z = -rotation.z
|
||||||
|
quat_parent = bone.parent.matrix.to_quaternion().inverted()
|
||||||
|
parent_head = quat_parent @ bone.parent.head
|
||||||
|
parent_tail = quat_parent @ bone.parent.tail
|
||||||
|
location = (parent_tail - parent_head) + bone.head
|
||||||
|
else:
|
||||||
|
location = input_objects.armature_object.matrix_local @ bone.head
|
||||||
|
rot_matrix = bone.matrix @ input_objects.armature_object.matrix_local.to_3x3()
|
||||||
|
rotation = rot_matrix.to_quaternion()
|
||||||
|
|
||||||
|
psk_bone.location.x = location.x
|
||||||
|
psk_bone.location.y = location.y
|
||||||
|
psk_bone.location.z = location.z
|
||||||
|
|
||||||
|
psk_bone.rotation.x = rotation.x
|
||||||
|
psk_bone.rotation.y = rotation.y
|
||||||
|
psk_bone.rotation.z = rotation.z
|
||||||
|
psk_bone.rotation.w = rotation.w
|
||||||
|
|
||||||
|
psk.bones.append(psk_bone)
|
||||||
|
|
||||||
vertex_offset = 0
|
vertex_offset = 0
|
||||||
wedge_offset = 0
|
wedge_offset = 0
|
||||||
@@ -115,7 +127,6 @@ class PskBuilder(object):
|
|||||||
|
|
||||||
# WEDGES
|
# WEDGES
|
||||||
uv_layer = object.data.uv_layers.active.data
|
uv_layer = object.data.uv_layers.active.data
|
||||||
# needs to be additive!!!
|
|
||||||
psk.wedges.extend([wedge_type() for _ in range(len(object.data.loops))])
|
psk.wedges.extend([wedge_type() for _ in range(len(object.data.loops))])
|
||||||
|
|
||||||
for loop_index, loop in enumerate(object.data.loops):
|
for loop_index, loop in enumerate(object.data.loops):
|
||||||
@@ -143,7 +154,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,24 +170,25 @@ 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
|
||||||
armature = input_objects.armature_object.data
|
if input_objects.armature_object is not None:
|
||||||
bone_names = [x.name for x in armature.bones]
|
armature = input_objects.armature_object.data
|
||||||
vertex_group_names = [x.name for x in object.vertex_groups]
|
bone_names = [x.name for x in armature.bones]
|
||||||
bone_indices = [bone_names.index(name) for name in vertex_group_names]
|
vertex_group_names = [x.name for x in object.vertex_groups]
|
||||||
for vertex_group_index, vertex_group in enumerate(object.vertex_groups):
|
bone_indices = [bone_names.index(name) for name in vertex_group_names]
|
||||||
bone_index = bone_indices[vertex_group_index]
|
for vertex_group_index, vertex_group in enumerate(object.vertex_groups):
|
||||||
for vertex_index in range(len(object.data.vertices)):
|
bone_index = bone_indices[vertex_group_index]
|
||||||
try:
|
for vertex_index in range(len(object.data.vertices)):
|
||||||
weight = vertex_group.weight(vertex_index)
|
try:
|
||||||
except RuntimeError:
|
weight = vertex_group.weight(vertex_index)
|
||||||
continue
|
except RuntimeError:
|
||||||
if weight == 0.0:
|
continue
|
||||||
continue
|
if weight == 0.0:
|
||||||
w = Psk.Weight()
|
continue
|
||||||
w.bone_index = bone_index
|
w = Psk.Weight()
|
||||||
w.point_index = vertex_offset + vertex_index
|
w.bone_index = bone_index
|
||||||
w.weight = weight
|
w.point_index = vertex_offset + vertex_index
|
||||||
psk.weights.append(w)
|
w.weight = weight
|
||||||
|
psk.weights.append(w)
|
||||||
|
|
||||||
vertex_offset += len(psk.points)
|
vertex_offset += len(psk.points)
|
||||||
wedge_offset += len(psk.wedges)
|
wedge_offset += len(psk.wedges)
|
||||||
|
|||||||
@@ -19,13 +19,11 @@ class PskExporter(object):
|
|||||||
fp.write(datum)
|
fp.write(datum)
|
||||||
|
|
||||||
def export(self, path: str):
|
def export(self, path: str):
|
||||||
# TODO: add logic somewhere to assert lengths of ctype structs
|
|
||||||
with open(path, 'wb') as fp:
|
with open(path, 'wb') as fp:
|
||||||
self.write_section(fp, b'ACTRHEAD')
|
self.write_section(fp, b'ACTRHEAD')
|
||||||
self.write_section(fp, b'PNTS0000', Vector3, self.psk.points)
|
self.write_section(fp, b'PNTS0000', Vector3, self.psk.points)
|
||||||
|
|
||||||
# WEDGES
|
# WEDGES
|
||||||
# TODO: this really should be on the level of the builder, not the exporter
|
|
||||||
if len(self.psk.wedges) <= 65536:
|
if len(self.psk.wedges) <= 65536:
|
||||||
wedge_type = Psk.Wedge16
|
wedge_type = Psk.Wedge16
|
||||||
else:
|
else:
|
||||||
|
|||||||
Reference in New Issue
Block a user