Code:
import struct
global bytecount
global ms3dbytecount
# -----------------------------------------------------------------------------------
def getbyte( fidin ) :
global bytecount
(thebyte,) = struct.unpack( 'b', fidin.read(1) )
bytecount = bytecount + 1
return thebyte
# -----------------------------------------------------------------------------------
def getubyte( fidin ) :
global bytecount
(thebyte,) = struct.unpack( 'B', fidin.read(1) )
bytecount = bytecount + 1
return thebyte
# -----------------------------------------------------------------------------------
def getshort( fidin ) :
global bytecount
(theshort,) = struct.unpack( 'h', fidin.read(2) )
bytecount = bytecount + 2
return theshort
# -----------------------------------------------------------------------------------
def getushort( fidin ) :
global bytecount
(theshort,) = struct.unpack( 'H', fidin.read(2) )
bytecount = bytecount + 2
return theshort
# -----------------------------------------------------------------------------------
def getint( fidin ) :
global bytecount
(theint,) = struct.unpack( 'i', fidin.read(4) )
bytecount = bytecount + 4
return theint
# -----------------------------------------------------------------------------------
def getuint( fidin ) :
global bytecount
(theint,) = struct.unpack( 'I', fidin.read(4) )
bytecount = bytecount + 4
return theint
# -----------------------------------------------------------------------------------
def getfloat( fidin ) :
global bytecount
(thefloat,) = struct.unpack( 'f', fidin.read(4) )
bytecount = bytecount + 4
return thefloat
# -----------------------------------------------------------------------------------
def putbyte( thebyte, fidout ) :
global ms3dbytecount
fidout.write( struct.pack( 'b', thebyte ) )
ms3dbytecount = ms3dbytecount + 1
return
# -----------------------------------------------------------------------------------
def putubyte( thebyte, fidout ) :
global ms3dbytecount
fidout.write( struct.pack( 'B', thebyte ) )
ms3dbytecount = ms3dbytecount + 1
return
# -----------------------------------------------------------------------------------
def putshort( theshort, fidout ) :
global ms3dbytecount
fidout.write( struct.pack( 'h', theshort ) )
ms3dbytecount = ms3dbytecount + 2
return
# -----------------------------------------------------------------------------------
def putushort( theshort, fidout ) :
global ms3dbytecount
fidout.write( struct.pack( 'H', theshort ) )
ms3dbytecount = ms3dbytecount + 2
return
# -----------------------------------------------------------------------------------
def putint( theint, fidout ) :
global ms3dbytecount
fidout.write( struct.pack( 'i', theint ) )
ms3dbytecount = ms3dbytecount + 4
return
# -----------------------------------------------------------------------------------
def putuint( theint, fidout ) :
global ms3dbytecount
fidout.write( struct.pack( 'I', theint ) )
ms3dbytecount = ms3dbytecount + 4
return
# -----------------------------------------------------------------------------------
def putfloat( thefloat, fidout ) :
global ms3dbytecount
fidout.write( struct.pack( 'f', thefloat ) )
ms3dbytecount = ms3dbytecount + 4
return
# -----------------------------------------------------------------------------------
def putzerobytes( n, fidout ) :
global ms3dbytecount
for ii in range(n) :
putubyte( 0, fidout )
ms3dbytecount = ms3dbytecount + 1
return
# Main.
global bytecount
global ms3dbytecount
bytecount = 0
ms3dbytecount = 0
fnin = 'feudal_knights_lod0_test.mesh'
fnout = 'feudal_knights_lod0_testchop.mesh'
fidin = open( fnin, 'rb' )
fidout = open( fnout, 'wb' )
for ii in range(2*175) :
fidout.write( fidin.read(500) )
fidout.write( fidin.read(477) )
# We're at the mystery blocks.
nvert = getuint( fidin )
putuint( nvert, fidout )
print 'nvert = ' + str( nvert )
for ii in range( nvert ) :
sdummy = getushort( fidin )
sdummy = getushort( fidin )
putushort( 0, fidout )
putushort( 0, fidout )
nheaderfooter = 26
for ii in range( nheaderfooter ) :
thebyte = getubyte( fidin )
putubyte( thebyte, fidout )
# 2nd mystery block.
nvert = getuint( fidin )
putuint( nvert, fidout )
print 'nvert = ' + str( nvert )
for ii in range( nvert ) :
sdummy = getushort( fidin )
sdummy = getushort( fidin )
putushort( 0, fidout )
putushort( 0, fidout )
nheaderfooter = 26
for ii in range( nheaderfooter ) :
thebyte = getubyte( fidin )
putubyte( thebyte, fidout )
# 3rd mystery block.
nvert = getuint( fidin )
putuint( nvert, fidout )
print 'nvert = ' + str( nvert )
for ii in range( nvert ) :
sdummy = getushort( fidin )
sdummy = getushort( fidin )
putushort( 0, fidout )
putushort( 0, fidout )
#fidin.seek( 229468, 0 )
fidout.write( fidin.read(500) )
fidout.write( fidin.read(600) )
fidin.close()
fidout.close()
Bookmarks