Files

48 lines
2.4 KiB
Python

"""#121 (2026-11-26): keep Tauren hooves flat in a retargeted sequence.
Owner (screenshot 19:52): during /rude and /dancespecial the Tauren stands on the back of his hooves, toes angled up. The
retarget copies the Undead ankle/foot rotation onto the Tauren hock/hoof, but a flat Undead foot is not a flat hoof.
For each hock bone the world rotation is held at the native stand pose (seq stand_seq, t=0): L' = Wp(t)^-1 * W_stand;
each hoof-tip bone keeps its stand local rotation. Legs above the hock (hip, knee, mid) keep the retargeted motion.
Run ground.py afterwards (hoof height changes slightly).
usage: hooves.py native.m2 seq in.anim stand_md20 stand_seq out.anim hock,hock[:tip,tip]"""
import os
import struct
import sys
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
from fkcheck import native, qm
from lean import world, enc, dq
def main(m2, seq, src, stand_src, stand_seq, dst, spec):
seq, stand_seq = int(seq), int(stand_seq)
hocks, _, tips = spec.partition(':')
hocks = [int(x) for x in hocks.split(',')]; tips = [int(x) for x in tips.split(',')] if tips else []
A = bytearray(open(src, 'rb').read())
B = open(m2, 'rb').read(); N = B[8:8 + struct.unpack_from('<I', B, 4)[0]]
bc, bo = struct.unpack_from('<II', N, 0x2C)
stand = native(m2, stand_src, stand_seq)
for j in hocks + tips:
open(dst, 'wb').write(A); bones = native(m2, dst, seq)
assert bones[j]['r'], f'bone {j} has no rotation keys in seq {seq}'
it, gs, tc, to, vc, vo = struct.unpack_from('<HhIIII', N, bo + j * 88 + 36)
n, o = struct.unpack_from('<II', N, to + seq * 8); n2, o2 = struct.unpack_from('<II', N, vo + seq * 8)
ts = struct.unpack_from(f'<{n}I', A, o); prev = None
Ws = world(stand, j, 0)
Ls = stand[j]['r'][0][1] if stand[j]['r'] else (0, 0, 0, 1)
for k, t in enumerate(ts):
if j in hocks:
Wp = world(bones, bones[j]['par'], t)
L2 = qm((-Wp[0], -Wp[1], -Wp[2], Wp[3]), Ws)
else:
L2 = Ls
if prev and sum(a * b for a, b in zip(prev, L2)) < 0: L2 = tuple(-c for c in L2)
prev = L2; A[o2 + k * 8:o2 + k * 8 + 8] = enc(L2)
open(dst, 'wb').write(A)
print(f'{os.path.basename(dst)}: hocks {hocks} held at stand world orientation, tips {tips} at stand local')
if __name__ == '__main__':
main(*sys.argv[1:8])