ik = inverse kinematics (it's when you don't need to animate all bones because the pc will do this for you)
Code: Select all
#mot
import struct
def dw2sign(mydword):#unsigned32 to signed64 int
return (mydword & 0xffffffff) - (0x100000000 if mydword & 0x80000000 else 0)
#return struct.unpack("=l", struct.pack("=L", (mydword & 0xffffffff)))[0]
def w2dw(myword):#word to dword
return (0xffff0000 if myword & 0x8000 else 0) + (myword & 0xffff)
def b2dw(mybyte):#byte to dword
return (0xffffff00 if mybyte & 0x80 else 0) + (mybyte & 0xff)
def ww2f(kfh):#word+word to float
return dw2sign((w2dw(kfh[0] & 0xF000) << 4) + kfh[1]) / 10000.0
def bw2f(kfb, kfw):#byte+word to float
return dw2sign((b2dw(kfb) << 0x10) + kfw) / 1000000.0
with open("C:\\karate.mot", 'rb') as fmot: #change the "C:\\karate.mot" path to the right one
limbnames = ("pelvis_xyz:\n", "", "", "pelvis:\n", "", "", "chest:\n", "", "", "head:\n", "", "",
"bpalm_xyz:\n", "," ,"", "bpalm:\n", "", "", "belbow:\n", "bshoulder:\n",
"fpalm_xyz:\n", "", "", "fpalm:\n", "", "", "felbow:\n", "fshoulder:\n",
"bfoot_xyz:\n", "", "", "bfoot:\n", "", "", "bheap:\n", "bknee:\n",
"ffoot_xyz:\n", "", "", "ffoot:\n", "", "", "fheap:\n", "fknee:\n")#b = back(right), f = front(left)
limbo = [ord(c)-48 for c in "00011111111100011111000111110001111100011111"]#0 = location, 1 = rotation
animofsets = []
while(True):
animofset = struct.unpack("<L", fmot.read(4))[0]
if animofset == 0: break
if animofset in animofsets: continue
animofsets.append(animofset)
for animofset in animofsets:
print("%x<%x>"% (animofset, animofsets.index(animofset)))
fmot.seek(animofset)
motions = []
for i in range(44): motions.append(struct.unpack("<L", fmot.read(4))[0])
motion = 0
while(motion < 44):
fmot.seek(motions[motion])
if motion < 43 and motions[motion] == motions[motion+1]:
motion += 3
print("unknown technique: xyz =", struct.unpack("<HHH", fmot.read(6)))
continue
print(limbnames[motion], end = "")
kframe = 1
while True:
kfh = struct.unpack("<HH", fmot.read(4)) #keyframe header
myfloat = ww2f(kfh)
frame = (kfh[0] >> 2) & 0x3ff
kfsize = [10, 4, 6, 8][kfh[0] & 3]
kframe += frame
if frame == 0:
print("%x"% (kframe - frame), "-", "%x"% kframe, "[", "%x"% frame, "]\te(", myfloat, ")$\n", sep = "", end = "")
break
print("%x"% (kframe - frame), "-", "%x"% kframe, "[", "%x"% frame, "]\t", int(kfsize/2), "(", myfloat, sep = "", end = "")
if kfsize == 10:
kfw, kfb = struct.unpack("<HB", fmot.read(3))
specificfloat1 = bw2f(kfb, kfw)
kfb, kfw = struct.unpack("<BH", fmot.read(3))
specificfloat2 = bw2f(kfb, kfw)
print(", %.6f, %.6f"% (specificfloat1, specificfloat2), sep = "", end = "")
elif kfsize == 8:
kfww = struct.unpack("<HH", fmot.read(4))
print(", %.6f, %.6f"% ((dw2sign(w2dw(kfww[0])) * (0.5**17)), (dw2sign(w2dw(kfww[1])) * (0.5**17))), sep = "", end = "")
elif kfsize == 6:
kfw = struct.unpack("<H", fmot.read(2))[0]
print(", %.6f"% (dw2sign(w2dw(kfw)) * (0.5**17)), sep = "", end = "")
if(limbo[motion]):print(")\t[%.2f°]"% (myfloat * 54.931640625), sep = "")
else:print(")")
print("")
motion += 1 #increment the motion here
print("[!]\n")
break# remove this to log the whole *.mot