Skip to content

Commit

Permalink
ms2 - rename and move pack_swizzle_collision
Browse files Browse the repository at this point in the history
  • Loading branch information
HENDRIX-ZT2 committed Oct 31, 2023
1 parent 5773699 commit 9781f18
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 22 deletions.
11 changes: 11 additions & 0 deletions generated/formats/ms2/compounds/packing_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,17 @@ def pack_ushort_vector_impostor(arr):
arr[:] = np.round(arr * USHORT_MAX)


def pack_swizzle_collision(vec):
# swizzle to avoid a matrix multiplication for global axis correction
return -vec[1], vec[2], vec[0]


def unpack_swizzle_collision(vec):
# swizzle to avoid a matrix multiplication for global axis correction
# Z, -X, Y
return vec[2], -vec[0], vec[1]


def unpack_swizzle(vec):
# swizzle to avoid a matrix multiplication for global axis correction
return -vec[0], -vec[2], vec[1]
Expand Down
9 changes: 3 additions & 6 deletions plugin/modules_export/armature.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import mathutils

from generated.formats.ms2.versions import is_ztuac, is_dla
from generated.formats.ms2.compounds.packing_utils import pack_swizzle
from generated.formats.ms2.compounds.packing_utils import pack_swizzle_collision
from plugin.modules_export.collision import export_hitcheck
from plugin.modules_import.armature import get_matrix
from plugin.utils.matrix_util import bone_name_for_ovl, get_joint_name, Corrector
Expand Down Expand Up @@ -212,15 +212,12 @@ def export_joints(bone_info, corrector):
if b_joint.children:
b_rb = b_joint.children[0]
rb.mass = b_rb.rigid_body.mass
rb.loc.set(pack_swizzle2(b_rb.location))
rb.loc.set(pack_swizzle_collision(b_rb.location))
else:
rb.mass = -1.0
# todo frictions


def pack_swizzle2(vec):
# swizzle to avoid a matrix multiplication for global axis correction
return -vec[1], vec[2], vec[0]

def get_joint_matrix(b_joint):
b_arm = b_joint.parent
b_bone = b_arm.data.bones[b_joint.parent_bone]
Expand Down
9 changes: 2 additions & 7 deletions plugin/modules_export/collision.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from generated.formats.ms2.compounds.Cylinder import Cylinder
from generated.formats.ms2.compounds.MeshCollision import MeshCollision
from generated.formats.ms2.compounds.Sphere import Sphere
from generated.formats.ms2.compounds.packing_utils import pack_swizzle
from generated.formats.ms2.compounds.packing_utils import pack_swizzle, pack_swizzle_collision
from generated.formats.ms2.enums.CollisionType import CollisionType
from plugin.utils.matrix_util import evaluate_mesh, ensure_tri_modifier, get_joint_name

Expand Down Expand Up @@ -153,11 +153,6 @@ def export_meshbv(b_obj, hitcheck, corrector):
assert len(face.vertices) == 3


def pack_swizzle2(vec):
# swizzle to avoid a matrix multiplication for global axis correction
return -vec[1], vec[2], vec[0]


def export_hullbv(b_obj, hitcheck, corrector):
me = b_obj.data
matrix = get_collider_matrix(b_obj)
Expand All @@ -176,7 +171,7 @@ def export_hullbv(b_obj, hitcheck, corrector):
coll.vertices = np.empty((coll.vertex_count, 3), dtype="float")
# coll.vertices.resize((coll.vertex_count, 3))
for vert_i, vert in enumerate(me.vertices):
coll.vertices[vert_i, :] = pack_swizzle2(vert.co)
coll.vertices[vert_i, :] = pack_swizzle_collision(vert.co)


def _capsule_transform(b_obj, hitcheck):
Expand Down
10 changes: 2 additions & 8 deletions plugin/modules_import/collision.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import bpy
import mathutils

from generated.formats.ms2.compounds.packing_utils import unpack_swizzle
from generated.formats.ms2.compounds.packing_utils import unpack_swizzle, unpack_swizzle_collision
from generated.formats.ms2.enums.CollisionType import CollisionType
from plugin.utils import matrix_util
from plugin.utils.object import mesh_from_data, create_ob
Expand Down Expand Up @@ -179,16 +179,10 @@ def import_meshbv(coll, hitcheck_name, corrector):
return b_obj


def unpack_swizzle2(vec):
# swizzle to avoid a matrix multiplication for global axis correction
# Z, -X, Y
return vec[2], -vec[0], vec[1]


def import_hullbv(coll, hitcheck_name, corrector):
# print(coll)
scene = bpy.context.scene
b_obj, b_me = mesh_from_data(scene, hitcheck_name, *qhull3d([unpack_swizzle2(v) for v in coll.vertices]), coll_name="hitchecks")
b_obj, b_me = mesh_from_data(scene, hitcheck_name, *qhull3d([unpack_swizzle_collision(v) for v in coll.vertices]), coll_name="hitchecks")
mat = import_collision_matrix(coll.rotation, corrector)
# this is certainly needed for JWE2 as of 2023-06-12
mat.translation = unpack_swizzle((coll.offset.x, coll.offset.y, coll.offset.z))
Expand Down
11 changes: 11 additions & 0 deletions source/formats/ms2/compounds/packing_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,17 @@ def pack_ushort_vector_impostor(arr):
arr[:] = np.round(arr * USHORT_MAX)


def pack_swizzle_collision(vec):
# swizzle to avoid a matrix multiplication for global axis correction
return -vec[1], vec[2], vec[0]


def unpack_swizzle_collision(vec):
# swizzle to avoid a matrix multiplication for global axis correction
# Z, -X, Y
return vec[2], -vec[0], vec[1]


def unpack_swizzle(vec):
# swizzle to avoid a matrix multiplication for global axis correction
return -vec[0], -vec[2], vec[1]
Expand Down
2 changes: 1 addition & 1 deletion version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
24a9d3c9 - Tue Oct 31 15:05:54 2023 +0100
57736992 - Tue Oct 31 17:48:13 2023 +0100

0 comments on commit 9781f18

Please sign in to comment.