Fixed a couple of bugs with the PSK exporter (UVs are correctly oriented etc.)
This commit is contained in:
@@ -1,9 +1,27 @@
|
|||||||
import bpy
|
import bpy
|
||||||
import bmesh
|
import bmesh
|
||||||
import mathutils
|
import mathutils
|
||||||
from .psk import Psk, Vector3
|
from .psk import Psk, Vector3, Quaternion
|
||||||
|
|
||||||
|
|
||||||
|
def make_fquat(bquat):
|
||||||
|
quat = Quaternion()
|
||||||
|
# flip handedness for UT = set x,y,z to negative (rotate in other direction)
|
||||||
|
quat.x = -bquat.x
|
||||||
|
quat.y = -bquat.y
|
||||||
|
quat.z = -bquat.z
|
||||||
|
quat.w = bquat.w
|
||||||
|
return quat
|
||||||
|
|
||||||
|
|
||||||
|
def make_fquat_default(bquat):
|
||||||
|
quat = Quaternion()
|
||||||
|
quat.x = bquat.x
|
||||||
|
quat.y = bquat.y
|
||||||
|
quat.z = bquat.z
|
||||||
|
quat.w = bquat.w
|
||||||
|
return quat
|
||||||
|
|
||||||
class PskBuilder(object):
|
class PskBuilder(object):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
pass
|
pass
|
||||||
@@ -69,6 +87,7 @@ class PskBuilder(object):
|
|||||||
wedge.material_index = 0
|
wedge.material_index = 0
|
||||||
wedge.point_index = loop.vertex_index
|
wedge.point_index = loop.vertex_index
|
||||||
wedge.u, wedge.v = uv_layer[loop_index].uv
|
wedge.u, wedge.v = uv_layer[loop_index].uv
|
||||||
|
wedge.v = 1.0 - wedge.v
|
||||||
psk.wedges.append(wedge)
|
psk.wedges.append(wedge)
|
||||||
|
|
||||||
# MATERIALS
|
# MATERIALS
|
||||||
@@ -94,37 +113,45 @@ class PskBuilder(object):
|
|||||||
for i in range(3):
|
for i in range(3):
|
||||||
psk.wedges[f.loops[i]].material_index = f.material_index
|
psk.wedges[f.loops[i]].material_index = f.material_index
|
||||||
|
|
||||||
# BONES
|
# https://github.com/bwrsandman/blender-addons/blob/master/io_export_unreal_psk_psa.py
|
||||||
bone_list = list(armature_object.data.bones)
|
bones = list(armature_object.data.bones)
|
||||||
for b in armature_object.data.bones:
|
for bone in bones:
|
||||||
bone = psk.Bone()
|
psk_bone = Psk.Bone()
|
||||||
bone.name = bytes(b.name, encoding='utf-8')
|
psk_bone.name = bytes(bone.name, encoding='utf-8')
|
||||||
bone.children_count = len(b.children)
|
psk_bone.flags = 0
|
||||||
bone.flags = 0 # look up what this is
|
psk_bone.children_count = len(bone.children)
|
||||||
bone.length = 10.0 # TODO: not sure what this is
|
|
||||||
try:
|
try:
|
||||||
bone.parent_index = bone_list.index(b.parent)
|
psk_bone.parent_index = bones.index(bone.parent)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
# this should be -1?
|
psk_bone.parent_index = 0
|
||||||
bone.parent_index = 0
|
|
||||||
bone.position.x = b.head_local.x
|
if bone.parent is not None:
|
||||||
bone.position.y = b.head_local.y
|
# calc parented bone transform
|
||||||
bone.position.z = b.head_local.z
|
rotation = bone.matrix.to_quaternion()
|
||||||
print(bone.name)
|
rotation.x = -rotation.x
|
||||||
print(bone.position.x)
|
rotation.y = -rotation.y
|
||||||
print(bone.position.y)
|
rotation.z = -rotation.z
|
||||||
print(bone.position.z)
|
quat_parent = bone.parent.matrix.to_quaternion().inverted()
|
||||||
print('----')
|
parent_head = quat_parent @ bone.parent.head
|
||||||
rotation = b.matrix_local.to_quaternion()
|
parent_tail = quat_parent @ bone.parent.tail
|
||||||
bone.rotation.x = rotation.x
|
location = (parent_tail - parent_head) + bone.head
|
||||||
bone.rotation.y = rotation.y
|
else:
|
||||||
bone.rotation.z = rotation.z
|
# calc root bone transform
|
||||||
bone.rotation.w = rotation.w
|
location = armature_object.matrix_local @ bone.head # ARMATURE OBJECT Location
|
||||||
# TODO: not sure what "size" is supposed to be exactly
|
rot_matrix = bone.matrix @ armature_object.matrix_local.to_3x3() # ARMATURE OBJECT Rotation
|
||||||
bone.size.x = 1
|
rotation = rot_matrix.to_quaternion()
|
||||||
bone.size.y = 1
|
|
||||||
bone.size.z = 1
|
psk_bone.location.x = location.x
|
||||||
psk.bones.append(bone)
|
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)
|
||||||
|
|
||||||
# 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
|
||||||
@@ -135,7 +162,10 @@ class PskBuilder(object):
|
|||||||
for vertex_group_index, vertex_group in enumerate(object.vertex_groups):
|
for vertex_group_index, vertex_group in enumerate(object.vertex_groups):
|
||||||
bone_index = bone_indices[vertex_group_index]
|
bone_index = bone_indices[vertex_group_index]
|
||||||
for vertex_index in range(len(object.data.vertices)):
|
for vertex_index in range(len(object.data.vertices)):
|
||||||
weight = vertex_group.weight(vertex_index)
|
try:
|
||||||
|
weight = vertex_group.weight(vertex_index)
|
||||||
|
except RuntimeError:
|
||||||
|
continue
|
||||||
if weight == 0.0:
|
if weight == 0.0:
|
||||||
continue
|
continue
|
||||||
w = Psk.Weight()
|
w = Psk.Weight()
|
||||||
|
|||||||
@@ -78,7 +78,7 @@ class Psk(object):
|
|||||||
('children_count', c_int32),
|
('children_count', c_int32),
|
||||||
('parent_index', c_int32),
|
('parent_index', c_int32),
|
||||||
('rotation', Quaternion),
|
('rotation', Quaternion),
|
||||||
('position', Vector3),
|
('location', Vector3),
|
||||||
('length', c_float),
|
('length', c_float),
|
||||||
('size', Vector3)
|
('size', Vector3)
|
||||||
]
|
]
|
||||||
|
|||||||
Reference in New Issue
Block a user