13 lines
736 B
Python
13 lines
736 B
Python
"""python3 seat.py src dst X Z : set attachment id 0 (mount seat) position x,z in an MD21 model (y kept)."""
|
|
import struct,sys
|
|
src,dst,X,Z=sys.argv[1],sys.argv[2],float(sys.argv[3]),float(sys.argv[4])
|
|
b=bytearray(open(src,'rb').read());o=0
|
|
while o+8<=len(b):
|
|
t,l=bytes(b[o:o+4]),struct.unpack_from('<I',b,o+4)[0]
|
|
if t==b'MD21':mo=o+8;break
|
|
o+=8+l
|
|
h=struct.unpack_from('<64I',b,mo+8);i=2+1+2+2+2+2+2+2+1+2+2+2+2+2+2+2+2+2+2+2+6+1+6+1+2+2+2
|
|
natt,oatt=h[i],h[i+1];k=[k for k in range(natt) if struct.unpack_from('<I',b,mo+oatt+40*k)[0]==0];assert len(k)==1
|
|
at=mo+oatt+40*k[0]+8;x,y,z=struct.unpack_from('<3f',b,at);struct.pack_into('<3f',b,at,X,y,Z)
|
|
open(dst,'wb').write(b);print(src,'seat',(round(x,3),round(z,3)),'->',(X,Z))
|