Skip to content

Commit

Permalink
banis - wrap the rot range
Browse files Browse the repository at this point in the history
  • Loading branch information
HENDRIX-ZT2 committed Sep 26, 2023
1 parent c0095ae commit a1130dc
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 7 deletions.
10 changes: 8 additions & 2 deletions generated/formats/bani/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
import math
import numpy as np

# +-
rot_range = 180


def export_key(key):
# this seems to be a modulo equivalent
Expand Down Expand Up @@ -56,7 +59,7 @@ def load(self, filepath):
stream.readinto(keys_packed)
keys_float = keys_packed.astype(self.dt_float)
print(keys_packed[0, :, ])
keys_float["euler"] = keys_float["euler"] / 32767.0 * 180
keys_float["euler"] = keys_float["euler"] / 32767.0 * rot_range
# keys_float["euler"] = keys_float["euler"] / 32768.0 * 180 + 90.0
keys_float["euler"][:, :, 0] += 90.0
keys_float["euler"][:, :, 1] += 90.0
Expand Down Expand Up @@ -101,7 +104,10 @@ def save(self, filepath):
keys_float["euler"][:, :, 0] -= 90.0
keys_float["euler"][:, :, 1] -= 90.0
keys_float["euler"][:, :, 2] += 90.0
keys_float["euler"] = keys_float["euler"] * 32767.0 / 180
# wrap if they exceed the valid range
keys_float["euler"][keys_float["euler"] > rot_range] -= rot_range
keys_float["euler"][keys_float["euler"] < -rot_range] += rot_range
keys_float["euler"] = keys_float["euler"] * 32767.0 / rot_range
# round parts separately
keys_float["euler"].round(out=keys_float["euler"])
keys_float["loc"].round(out=keys_float["loc"])
Expand Down
4 changes: 2 additions & 2 deletions plugin/export_banis.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ def save(filepath=""):
key = corrector.blender_bind_to_nif_bind(posed_armature_space[bone_i])
# this maybe adds the loc transforms, doesn't seem to correctly transform rot ??
# key = binds[bone_i].inverted() @ key
# key = key @ binds[bone_i].inverted()
key.translation -= binds[bone_i].translation
key = key @ binds[bone_i].inverted()
# key.translation += binds[bone_i].translation
frame["loc"][bone_i] = key.translation
frame["euler"][bone_i] = [math.degrees(v) for v in key.to_euler()]

Expand Down
10 changes: 8 additions & 2 deletions source/formats/bani/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
import math
import numpy as np

# +-
rot_range = 180


def export_key(key):
# this seems to be a modulo equivalent
Expand Down Expand Up @@ -55,7 +58,7 @@ def load(self, filepath):
stream.readinto(keys_packed)
keys_float = keys_packed.astype(self.dt_float)
print(keys_packed[0, :, ])
keys_float["euler"] = keys_float["euler"] / 32767.0 * 180
keys_float["euler"] = keys_float["euler"] / 32767.0 * rot_range
# keys_float["euler"] = keys_float["euler"] / 32768.0 * 180 + 90.0
keys_float["euler"][:, :, 0] += 90.0
keys_float["euler"][:, :, 1] += 90.0
Expand Down Expand Up @@ -100,7 +103,10 @@ def save(self, filepath):
keys_float["euler"][:, :, 0] -= 90.0
keys_float["euler"][:, :, 1] -= 90.0
keys_float["euler"][:, :, 2] += 90.0
keys_float["euler"] = keys_float["euler"] * 32767.0 / 180
# wrap if they exceed the valid range
keys_float["euler"][keys_float["euler"] > rot_range] -= rot_range
keys_float["euler"][keys_float["euler"] < -rot_range] += rot_range
keys_float["euler"] = keys_float["euler"] * 32767.0 / rot_range
# round parts separately
keys_float["euler"].round(out=keys_float["euler"])
keys_float["loc"].round(out=keys_float["loc"])
Expand Down
2 changes: 1 addition & 1 deletion version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
a2570101b - Sun Sep 24 23:15:47 2023 +0200
c0095aed9 - Mon Sep 25 18:50:21 2023 +0200

0 comments on commit a1130dc

Please sign in to comment.