Skip to content

Commit

Permalink
Support export of legacy markers
Browse files Browse the repository at this point in the history
  • Loading branch information
amorgun committed Nov 29, 2024
1 parent d186cd6 commit b822501
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
7 changes: 7 additions & 0 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,12 @@ class ExportModel:
default='flat',
)

use_legacy_marker_orientation: bpy.props.BoolProperty(
name='Legacy markers',
description='Use legacy marker orientation',
default=False,
)

FORMAT: exporter.ExportFormat = None

def execute(self, context):
Expand All @@ -303,6 +309,7 @@ def execute(self, context):
default_texture_path=self.default_texture_path,
convert_textures=self.convert_textures,
max_texture_size=self.max_texture_size,
use_legacy_marker_orientation=self.use_legacy_marker_orientation,
context=context)
try:
ex.export(writer, object_name=object_name, meta=self.meta)
Expand Down
10 changes: 10 additions & 0 deletions exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ def __init__(
default_texture_path: str = '',
max_texture_size: int = 1024,
make_oe_compatable_textures: bool = True,
use_legacy_marker_orientation: bool = False,
context=None,
) -> None:
self.messages = []
Expand All @@ -173,6 +174,7 @@ def __init__(
self.default_texture_path = pathlib.PurePosixPath(default_texture_path)
self.max_texture_size = max_texture_size
self.make_oe_compatable_textures = make_oe_compatable_textures
self.use_legacy_marker_orientation = use_legacy_marker_orientation
self.bpy_context = context if context is not None else bpy.context

self.armature_obj = None
Expand Down Expand Up @@ -884,6 +886,14 @@ def write_marks(self, writer: ChunkWriter):
parent_mat = self.bone_transforms[marker.parent]
else:
parent_mat = self.armature_obj.matrix_world.inverted() @ mathutils.Matrix.Rotation(math.radians(90.0), 4, 'X')
if self.use_legacy_marker_orientation:
delta = mathutils.Matrix.Rotation(math.radians(-90.0), 4, 'Z')
transform = parent_mat.inverted() @ marker.matrix_local @ delta.inverted()
for row_idx in range(3):
writer.write_struct('<3f', *transform[row_idx][:3])
writer.write_struct('<3f', -transform[0][3], transform[1][3], transform[2][3])
self.bone_transforms[marker] = marker.matrix_local @ delta.inverted()
continue
transform = coord_transform @ parent_mat.inverted() @ marker.matrix_local @ coord_transform_inv
loc, rot, _ = transform.decompose()
rot = rot.to_matrix().transposed()
Expand Down

0 comments on commit b822501

Please sign in to comment.