if (heapSize < 20000000) then
	heapSize = 200000000
fname = getOpenFileName \
caption:"Open .kimesh from Mesh folder" \
types:"Killer Instinct Meshes (*.kimesh)|*.kimesh" \
historyCategory:"KIObjectPresets"
f = fopen fname "rb"

clearlistener()	

fn ReadHalfFloat fstream = 
	(
	hf=readshort fstream
	sign = bit.get hf 16
	exponent = (bit.shift (bit.and hf (bit.hexasint "7C00")) -10) as integer - 16
	fraction = bit.and hf (bit.hexasint "03FF")
	if sign==true then sign = 1 else sign = 0
	exponentF = exponent + 127
	outputAsFloat = bit.or (bit.or (bit.shift fraction 13) \
	(bit.shift exponentF 23)) (bit.shift sign 31)
	return bit.intasfloat outputasfloat*2
)

fn readFixedString bstream fixedLen = (
local str = ""
for i = 1 to fixedLen do (
str += bit.intAsChar (ReadByte bstream #unsigned))
str
)

struct weight_data
(
   boneids,weights
)
	
struct Mesh_Info_Struct
(
VertCount, FaceCount, FaceStride, UVType
)	
	
struct Mesh_Info_Struct2
(
VertStride, VertOff, WStride, WOff 	
)	

clearlistener()

--------------------------------------------------------------------------------------------	
	
FaceStart=#() 
VertStart=#() 
WeightStart=#() 

fseek f 0x8 #seek_set	
OffStride=readlong f	
fseek f 0xDC #seek_set	
for i=1 to 1 do (
getPos = ftell f + 80
append FaceStart (readlong f+(OffStride+12))	
fseek f getPos #seek_set		
)	
for i=1 to 1 do (
getPos = ftell f + 80
append VertStart (readlong f+(OffStride+12))	
fseek f getPos #seek_set		
)	
for i=1 to 1 do (
getPos = ftell f + 80
append WeightStart (readlong f+(OffStride+12))	
fseek f getPos #seek_set		
)	

fseek f 0x25C #seek_set	
MeshCount=readlong f	
MatSize=readlong f	
fseek f 0x290 #seek_set	
StringsCountOff=readlong f	
fseek f 0x2D8 #seek_set	
BoneMapInfo=readlong f	
fseek f 0x368 #seek_set	
BNameOff=readlong f	
fseek f 0x380 #seek_set	
OffVertInfo=readlong f	
fseek f 0x428 #seek_set	
OffUVInfo=readlong f	
fseek f 0x470 #seek_set	
OffMatSize=readlong f

fseek f ((OffUVInfo+(OffMatSize+12))+OffStride) #seek_set	
	
Print ("!!!!! @ 0x"+((bit.intAsHex(ftell f))as string))		

UvTypeArray=#()	
for i=1 to MeshCount do (
getPos = ftell f + 32	
readlong f
UvType = (readlong f)		
fseek f getPos #seek_set	
append UvTypeArray UvType	
)		

print (UvTypeArray as string)

fseek f (OffStride+(StringsCountOff+12)) #seek_set
StringsCount=readlong f	
	
Print ("Start @ 0x"+((bit.intAsHex(ftell f))as string))	

fseek f (OffStride+(BNameOff+12)) #seek_set
	
Print ("BoneNames Start @ 0x"+((bit.intAsHex(ftell f))as string))	

UBoneNameArray=#()	
for i=1 to StringsCount do (
UBoneName=readstring f
append UBoneNameArray UBoneName	
)	

Print ("BoneNames End @ 0x"+((bit.intAsHex(ftell f))as string))	

fseek f (OffStride+(BoneMapInfo+12)) #seek_set
	
Print ("BoneMap Start @ 0x"+((bit.intAsHex(ftell f))as string))		
	
UsedBoneCount=readlong f	
	
fseek f (0x8) #seek_cur

BoneMapArray=#()	
for i=1 to UsedBoneCount do (
BoneId=readlong f
append BoneMapArray (BoneId+1)	
)

print (BoneMapArray as string)

fseek f (OffStride+(MatSize+94)) #seek_set	

Print ("Mesh Info Start @ 0x"+((bit.intAsHex(ftell f))as string))	

Mesh_Info_Array=#()
	
Stride=0
if MeshCount>1 then Stride=432
if MeshCount<=1 then Stride=358
for i=1 to MeshCount do (
getPos = ftell f + Stride		
fseek f 0x16 #seek_cur	
UVType = (readlong f)	
FaceStride = (readlong f)	
FaceCount = (readlong f)
VertCount = (readlong f)	
fseek f getPos #seek_set	
append Mesh_Info_Array (Mesh_Info_Struct VertCount:VertCount FaceCount:FaceCount FaceStride:FaceStride UVType: UVType )	
)	

Print ("Mesh Info End @ 0x"+((bit.intAsHex(ftell f))as string))	
	
-------------------------------------------------------------------------------------------------------------------
		
fseek f (OffStride+(OffVertInfo+12)) #seek_set

-----------------------------------------------------------------------------------------------------------------
	
Print ("Weights Info Start @ 0x"+((bit.intAsHex(ftell f))as string))		
		
Mesh_Info_Array2=#()
	
for i=1 to MeshCount do (
getPos = ftell f + 80	
VertStride = (readlong f)	
VertOff = (readlong f)	
fseek f 0x20 #seek_cur	
WStride = (readlong f)	
WOff = (readlong f)		
fseek f getPos #seek_set	
append Mesh_Info_Array2 (Mesh_Info_Struct2 VertStride:VertStride VertOff:VertOff WStride:WStride WOff:WOff)		
)	

print Mesh_Info_Array
print Mesh_Info_Array2

---------------------------------------------------------------------------------------------------------------	
for i=1 to MeshCount do (	

FaceArray=#()
vertArray=#()
UV_array=#()
Weight_array=#()		

FStride=(Mesh_Info_Array[i].FaceStride*2)	

fseek f (FaceStart[1]+FStride) #seek_set		
	
Print ("Face Start @ 0x"+((bit.intAsHex(ftell f))as string))	
	
for x = 1 to Mesh_Info_Array[i].FaceCount do (
fa=(readshort f #unsigned+1)
fb=(readshort f #unsigned+1)
fc=(readshort f #unsigned+1) 
append FaceArray[fa,fb,fc]	
)	

Print ("Face End @ 0x"+((bit.intAsHex(ftell f))as string))

fseek f (VertStart[1]+(Mesh_Info_Array2[i].VertOff)) #seek_set	
	
Print ("Vertex Start @ 0x"+((bit.intAsHex(ftell f))as string))
	
for x = 1 to Mesh_Info_Array[i].VertCount do(

vx=readfloat f
vy=readfloat f
vz=readfloat f

tu=ReadLong f	
tv=ReadLong f	
	
append VertArray([-vx,-vz,vy]*100)
)
	
Print ("Vertex End @ 0x"+((bit.intAsHex(ftell f))as string))
	
fseek f (WeightStart[1]+(Mesh_Info_Array2[i].WOff)) #seek_set		
	
Print ("Weights Start @ 0x"+((bit.intAsHex(ftell f))as string))	
	
if Mesh_Info_Array2[i].WStride==8 then 	
if UvTypeArray[i]==7 then 	
for x = 1 to Mesh_Info_Array[i].VertCount do(

tu=ReadShort f	
tv=ReadShort f*-1		
	
bone1 = readbyte f #unsigned	
bone2 = readbyte f #unsigned	
		
weight1 = readbyte f #unsigned
weight2 = readbyte f #unsigned
		
w = (weight_data boneids:#() weights:#())
maxweight = 0
if(weight1 != 0) then
   maxweight = maxweight + weight1
if(weight2 != 0) then
   maxweight = maxweight + weight2

if(maxweight != 0) then (
      if(weight1 != 0) then (
         w1 = weight1 as float
         append w.boneids (bone1+1)
         append w.weights (w1/255)
      )
      if(weight2 != 0) then (
         w2 = weight2 as float
         append w.boneids (bone2+1)
         append w.weights (w2/255)
      )    
   )	
append Weight_array w	
append UV_array([tu,tv,0]/32767)	
)	

if Mesh_Info_Array2[i].WStride==8 then 
if UvTypeArray[i]==8 then 
for x = 1 to Mesh_Info_Array[i].VertCount do(

tu=ReadFloat f	
tv=ReadFloat f*-1		

bone1 = 0
	
weight1 = 1.0
		
w = (weight_data boneids:#() weights:#())
maxweight = 0
if(weight1 != 0) then
   maxweight = maxweight + weight1

if(maxweight != 0) then (
      if(weight1 != 0) then (
         w1 = weight1 as float
         append w.boneids (bone1+1)
         append w.weights (w1)
      )    
   )	
append Weight_array w		
append UV_array([tu,tv,0])	
)	

if Mesh_Info_Array2[i].WStride==8 then 
if UvTypeArray[i]==9 then 
for x = 1 to Mesh_Info_Array[i].VertCount do(

readlong f	
	
tu=ReadShort f	
tv=ReadShort f*-1		

bone1 = 0
	
weight1 = 1.0
		
w = (weight_data boneids:#() weights:#())
maxweight = 0
if(weight1 != 0) then
   maxweight = maxweight + weight1

if(maxweight != 0) then (
      if(weight1 != 0) then (
         w1 = weight1 as float
         append w.boneids (bone1+1)
         append w.weights (w1)
      )    
   )	
append Weight_array w		
append UV_array([tu,tv,0])	
)	

if Mesh_Info_Array2[i].WStride==12 then 
if UvTypeArray[i]==8 then 
for x = 1 to Mesh_Info_Array[i].VertCount do(

tu=ReadShort f	
tv=ReadShort f*-1	
	
readlong f		
	
bone1 = readbyte f #unsigned	
bone2 = readbyte f #unsigned	
		
weight1 = readbyte f #unsigned
weight2 = readbyte f #unsigned
		
w = (weight_data boneids:#() weights:#())
maxweight = 0
if(weight1 != 0) then
   maxweight = maxweight + weight1
if(weight2 != 0) then
   maxweight = maxweight + weight2

if(maxweight != 0) then (
      if(weight1 != 0) then (
         w1 = weight1 as float
         append w.boneids (bone1+1)
         append w.weights (w1/255)
      )
      if(weight2 != 0) then (
         w2 = weight2 as float
         append w.boneids (bone2+1)
         append w.weights (w2/255)
      )    
   )	
append Weight_array w	
append UV_array([tu,tv,0]/32767)	
)	

if Mesh_Info_Array2[i].WStride==12 then 
if UvTypeArray[i]==7 then 
for x = 1 to Mesh_Info_Array[i].VertCount do(

tu=ReadFloat f	
tv=ReadFloat f*-1

bone1 = readbyte f #unsigned	
bone2 = readbyte f #unsigned	
		
weight1 = readbyte f #unsigned
weight2 = readbyte f #unsigned
		
w = (weight_data boneids:#() weights:#())
maxweight = 0
if(weight1 != 0) then
   maxweight = maxweight + weight1
if(weight2 != 0) then
   maxweight = maxweight + weight2
if(weight3 != 0) then

if(maxweight != 0) then (
      if(weight1 != 0) then (
         w1 = weight1 as float
         append w.boneids (bone1+1)
         append w.weights (w1/255)
      )
      if(weight2 != 0) then (
         w2 = weight2 as float
         append w.boneids (bone2+1)
         append w.weights (w2/255)
      )
   )	
append Weight_array w	
append UV_array([tu,tv,0])	
)

if Mesh_Info_Array2[i].WStride==12 then 
if UvTypeArray[i]==9 then 
for x = 1 to Mesh_Info_Array[i].VertCount do(

readlong f		
	
tu=ReadShort f	
tv=ReadShort f*-1	
	
bone1 = readbyte f #unsigned	
bone2 = readbyte f #unsigned	
		
weight1 = readbyte f #unsigned
weight2 = readbyte f #unsigned
		
w = (weight_data boneids:#() weights:#())
maxweight = 0
if(weight1 != 0) then
   maxweight = maxweight + weight1
if(weight2 != 0) then
   maxweight = maxweight + weight2

if(maxweight != 0) then (
      if(weight1 != 0) then (
         w1 = weight1 as float
         append w.boneids (bone1+1)
         append w.weights (w1/255)
      )
      if(weight2 != 0) then (
         w2 = weight2 as float
         append w.boneids (bone2+1)
         append w.weights (w2/255)
      )    
   )	
append Weight_array w	
append UV_array([tu,tv,0]/32767)	
)	

if Mesh_Info_Array2[i].WStride==16 then 	
if UvTypeArray[i]==7 then 	
for x = 1 to Mesh_Info_Array[i].VertCount do(

tu=ReadShort f	
tv=ReadShort f*-1		
	
readlong f	
	
bone1 = readbyte f #unsigned	
bone2 = readbyte f #unsigned	
bone3 = readbyte f #unsigned	
bone4 = readbyte f #unsigned		
	
weight1 = readbyte f #unsigned
weight2 = readbyte f #unsigned
weight3 = readbyte f #unsigned
weight4 = readbyte f #unsigned	
		
w = (weight_data boneids:#() weights:#())
maxweight = 0
if(weight1 != 0) then
   maxweight = maxweight + weight1
if(weight2 != 0) then
   maxweight = maxweight + weight2
if(weight3 != 0) then
   maxweight = maxweight + weight3
if(weight4 != 0) then
   maxweight = maxweight + weight4


if(maxweight != 0) then (
      if(weight1 != 0) then (
         w1 = weight1 as float
         append w.boneids (bone1+1)
         append w.weights (w1/255)
      )
      if(weight2 != 0) then (
         w2 = weight2 as float
         append w.boneids (bone2+1)
         append w.weights (w2/255)
      )
      if(weight3 != 0) then (
         w3 = weight3 as float
         append w.boneids (bone3+1)
         append w.weights (w3/255)
      )
      if(weight4 != 0) then (
         w4 = weight4 as float
         append w.boneids (bone4+1)
        append w.weights (w4/255)
      )      
   )	
append Weight_array w	
append UV_array([tu,tv,0]/32767)	
)	

if Mesh_Info_Array2[i].WStride==16 then 	
if UvTypeArray[i]==8 then 
for x = 1 to Mesh_Info_Array[i].VertCount do(
	
tu=ReadFloat f	
tv=ReadFloat f*-1	
	
bone1 = readbyte f #unsigned	
bone2 = readbyte f #unsigned	
bone3 = readbyte f #unsigned	
bone4 = readbyte f #unsigned		
	
weight1 = readbyte f #unsigned
weight2 = readbyte f #unsigned
weight3 = readbyte f #unsigned
weight4 = readbyte f #unsigned	
		
w = (weight_data boneids:#() weights:#())
maxweight = 0
if(weight1 != 0) then
   maxweight = maxweight + weight1
if(weight2 != 0) then
   maxweight = maxweight + weight2
if(weight3 != 0) then
   maxweight = maxweight + weight3
if(weight4 != 0) then
   maxweight = maxweight + weight4


if(maxweight != 0) then (
      if(weight1 != 0) then (
         w1 = weight1 as float
         append w.boneids (bone1+1)
         append w.weights (w1/255)
      )
      if(weight2 != 0) then (
         w2 = weight2 as float
         append w.boneids (bone2+1)
         append w.weights (w2/255)
      )
      if(weight3 != 0) then (
         w3 = weight3 as float
         append w.boneids (bone3+1)
         append w.weights (w3/255)
      )
      if(weight4 != 0) then (
         w4 = weight4 as float
         append w.boneids (bone4+1)
        append w.weights (w4/255)
      )      
   )	
append Weight_array w		
append UV_array([tu,tv,0])	
)	

if Mesh_Info_Array2[i].WStride==16 then 
if UvTypeArray[i]==9 then 	
if Mesh_Info_Array[i].UVType==1264 then 	
for x = 1 to Mesh_Info_Array[i].VertCount do(

readlong f		
	
tu=ReadShort f	
tv=ReadShort f*-1		
	
bone1 = readbyte f #unsigned	
bone2 = readbyte f #unsigned	
bone3 = readbyte f #unsigned	
bone4 = readbyte f #unsigned		
	
weight1 = readbyte f #unsigned
weight2 = readbyte f #unsigned
weight3 = readbyte f #unsigned
weight4 = readbyte f #unsigned	
		
w = (weight_data boneids:#() weights:#())
maxweight = 0
if(weight1 != 0) then
   maxweight = maxweight + weight1
if(weight2 != 0) then
   maxweight = maxweight + weight2
if(weight3 != 0) then
   maxweight = maxweight + weight3
if(weight4 != 0) then
   maxweight = maxweight + weight4


if(maxweight != 0) then (
      if(weight1 != 0) then (
         w1 = weight1 as float
         append w.boneids (bone1+1)
         append w.weights (w1/255)
      )
      if(weight2 != 0) then (
         w2 = weight2 as float
         append w.boneids (bone2+1)
         append w.weights (w2/255)
      )
      if(weight3 != 0) then (
         w3 = weight3 as float
         append w.boneids (bone3+1)
         append w.weights (w3/255)
      )
      if(weight4 != 0) then (
         w4 = weight4 as float
         append w.boneids (bone4+1)
        append w.weights (w4/255)
      )      
   )	
append Weight_array w		
append UV_array([tu,tv,0]/32767)	
)

if Mesh_Info_Array2[i].WStride==16 then 
if UvTypeArray[i]==9 then 	
if Mesh_Info_Array[i].UVType!=1264 then 	
for x = 1 to Mesh_Info_Array[i].VertCount do(

tu=ReadShort f	
tv=ReadShort f*-1		
	
readlong f		
		
bone1 = readbyte f #unsigned	
bone2 = readbyte f #unsigned	
bone3 = readbyte f #unsigned	
bone4 = readbyte f #unsigned		
	
weight1 = readbyte f #unsigned
weight2 = readbyte f #unsigned
weight3 = readbyte f #unsigned
weight4 = readbyte f #unsigned	
		
w = (weight_data boneids:#() weights:#())
maxweight = 0
if(weight1 != 0) then
   maxweight = maxweight + weight1
if(weight2 != 0) then
   maxweight = maxweight + weight2
if(weight3 != 0) then
   maxweight = maxweight + weight3
if(weight4 != 0) then
   maxweight = maxweight + weight4


if(maxweight != 0) then (
      if(weight1 != 0) then (
         w1 = weight1 as float
         append w.boneids (bone1+1)
         append w.weights (w1/255)
      )
      if(weight2 != 0) then (
         w2 = weight2 as float
         append w.boneids (bone2+1)
         append w.weights (w2/255)
      )
      if(weight3 != 0) then (
         w3 = weight3 as float
         append w.boneids (bone3+1)
         append w.weights (w3/255)
      )
      if(weight4 != 0) then (
         w4 = weight4 as float
         append w.boneids (bone4+1)
        append w.weights (w4/255)
      )      
   )	
append Weight_array w		
append UV_array([tu,tv,0]/32767)	
)	

if Mesh_Info_Array2[i].WStride==20 then 
if UvTypeArray[i]==7 then 		
for x = 1 to Mesh_Info_Array[i].VertCount do(

tu=ReadFloat f	
tv=ReadFloat f*-1		

readlong f	
readlong f	
		
bone1 = readbyte f #unsigned	
bone2 = readbyte f #unsigned	
	
weight1 = readbyte f #unsigned
weight2 = readbyte f #unsigned
		
w = (weight_data boneids:#() weights:#())
maxweight = 0
if(weight1 != 0) then
   maxweight = maxweight + weight1
if(weight2 != 0) then
   maxweight = maxweight + weight2

if(maxweight != 0) then (
      if(weight1 != 0) then (
         w1 = weight1 as float
         append w.boneids (bone1+1)
         append w.weights (w1/255)
      )
      if(weight2 != 0) then (
         w2 = weight2 as float
         append w.boneids (bone2+1)
         append w.weights (w2/255)
      )   
   )	
append Weight_array w	
append UV_array([tu,tv,0])	
)	

if Mesh_Info_Array2[i].WStride==20 then 
if UvTypeArray[i]==8 then 	
for x = 1 to Mesh_Info_Array[i].VertCount do(

tu=ReadFloat f	
tv=ReadFloat f*-1		

readlong f	
readlong f	
		
bone1 = readbyte f #unsigned	
bone2 = readbyte f #unsigned	
	
weight1 = readbyte f #unsigned
weight2 = readbyte f #unsigned
		
w = (weight_data boneids:#() weights:#())
maxweight = 0
if(weight1 != 0) then
   maxweight = maxweight + weight1
if(weight2 != 0) then
   maxweight = maxweight + weight2

if(maxweight != 0) then (
      if(weight1 != 0) then (
         w1 = weight1 as float
         append w.boneids (bone1+1)
         append w.weights (w1/255)
      )
      if(weight2 != 0) then (
         w2 = weight2 as float
         append w.boneids (bone2+1)
         append w.weights (w2/255)
      )   
   )	
append Weight_array w	
append UV_array([tu,tv,0])	
)	

if Mesh_Info_Array2[i].WStride==20 then 
if UvTypeArray[i]==9 then 	
for x = 1 to Mesh_Info_Array[i].VertCount do(

tu=ReadShort f	
tv=ReadShort f*-1			

readlong f		
readlong f	
readlong f	
		
bone1 = readbyte f #unsigned	
bone2 = readbyte f #unsigned	
	
weight1 = readbyte f #unsigned
weight2 = readbyte f #unsigned
		
w = (weight_data boneids:#() weights:#())
maxweight = 0
if(weight1 != 0) then
   maxweight = maxweight + weight1
if(weight2 != 0) then
   maxweight = maxweight + weight2

if(maxweight != 0) then (
      if(weight1 != 0) then (
         w1 = weight1 as float
         append w.boneids (bone1+1)
         append w.weights (w1/255)
      )
      if(weight2 != 0) then (
         w2 = weight2 as float
         append w.boneids (bone2+1)
         append w.weights (w2/255)
      )   
   )	
append Weight_array w	
append UV_array([tu,tv,0])	
)	

if Mesh_Info_Array2[i].WStride==24 then 
if UvTypeArray[i]==7 then 		
for x = 1 to Mesh_Info_Array[i].VertCount do(

tu=ReadShort f	
tv=ReadShort f*-1		

readlong f		
readlong f	
readlong f	
	
bone1 = readbyte f #unsigned	
bone2 = readbyte f #unsigned	
bone3 = readbyte f #unsigned	
bone4 = readbyte f #unsigned		
	
weight1 = readbyte f #unsigned
weight2 = readbyte f #unsigned
weight3 = readbyte f #unsigned
weight4 = readbyte f #unsigned	
		
w = (weight_data boneids:#() weights:#())
maxweight = 0
if(weight1 != 0) then
   maxweight = maxweight + weight1
if(weight2 != 0) then
   maxweight = maxweight + weight2
if(weight3 != 0) then
   maxweight = maxweight + weight3
if(weight4 != 0) then
   maxweight = maxweight + weight4


if(maxweight != 0) then (
      if(weight1 != 0) then (
         w1 = weight1 as float
         append w.boneids (bone1+1)
         append w.weights (w1/255)
      )
      if(weight2 != 0) then (
         w2 = weight2 as float
         append w.boneids (bone2+1)
         append w.weights (w2/255)
      )
      if(weight3 != 0) then (
         w3 = weight3 as float
         append w.boneids (bone3+1)
         append w.weights (w3/255)
      )
      if(weight4 != 0) then (
         w4 = weight4 as float
         append w.boneids (bone4+1)
        append w.weights (w4/255)
      )      
   )	
append Weight_array w	
append UV_array([tu,tv,0]/32767)	
)	

if Mesh_Info_Array2[i].WStride==24 then 
if UvTypeArray[i]==8 then 		
for x = 1 to Mesh_Info_Array[i].VertCount do(

tu=ReadShort f	
tv=ReadShort f*-1		

readlong f		
readlong f	
readlong f	
	
bone1 = readbyte f #unsigned	
bone2 = readbyte f #unsigned	
bone3 = readbyte f #unsigned	
bone4 = readbyte f #unsigned		
	
weight1 = readbyte f #unsigned
weight2 = readbyte f #unsigned
weight3 = readbyte f #unsigned
weight4 = readbyte f #unsigned	
		
w = (weight_data boneids:#() weights:#())
maxweight = 0
if(weight1 != 0) then
   maxweight = maxweight + weight1
if(weight2 != 0) then
   maxweight = maxweight + weight2
if(weight3 != 0) then
   maxweight = maxweight + weight3
if(weight4 != 0) then
   maxweight = maxweight + weight4


if(maxweight != 0) then (
      if(weight1 != 0) then (
         w1 = weight1 as float
         append w.boneids (bone1+1)
         append w.weights (w1/255)
      )
      if(weight2 != 0) then (
         w2 = weight2 as float
         append w.boneids (bone2+1)
         append w.weights (w2/255)
      )
      if(weight3 != 0) then (
         w3 = weight3 as float
         append w.boneids (bone3+1)
         append w.weights (w3/255)
      )
      if(weight4 != 0) then (
         w4 = weight4 as float
         append w.boneids (bone4+1)
        append w.weights (w4/255)
      )      
   )	
append Weight_array w	
append UV_array([tu,tv,0]/32767)	
)	

if Mesh_Info_Array2[i].WStride==24 then 
if UvTypeArray[i]==9 then 	 	
for x = 1 to Mesh_Info_Array[i].VertCount do(

tu=ReadFloat f	
tv=ReadFloat f*-1		

readlong f	
readlong f	
	
bone1 = readbyte f #unsigned	
bone2 = readbyte f #unsigned	
bone3 = readbyte f #unsigned	
bone4 = readbyte f #unsigned		
	
weight1 = readbyte f #unsigned
weight2 = readbyte f #unsigned
weight3 = readbyte f #unsigned
weight4 = readbyte f #unsigned	
		
w = (weight_data boneids:#() weights:#())
maxweight = 0
if(weight1 != 0) then
   maxweight = maxweight + weight1
if(weight2 != 0) then
   maxweight = maxweight + weight2
if(weight3 != 0) then
   maxweight = maxweight + weight3
if(weight4 != 0) then
   maxweight = maxweight + weight4


if(maxweight != 0) then (
      if(weight1 != 0) then (
         w1 = weight1 as float
         append w.boneids (bone1+1)
         append w.weights (w1/255)
      )
      if(weight2 != 0) then (
         w2 = weight2 as float
         append w.boneids (bone2+1)
         append w.weights (w2/255)
      )
      if(weight3 != 0) then (
         w3 = weight3 as float
         append w.boneids (bone3+1)
         append w.weights (w3/255)
      )
      if(weight4 != 0) then (
         w4 = weight4 as float
         append w.boneids (bone4+1)
        append w.weights (w4/255)
      )      
   )	
append Weight_array w	
append UV_array([tu,tv,0])	
)	

Print ("Weights End @ 0x"+((bit.intAsHex(ftell f))as string))

Try(	
msh = mesh vertices:vertArray faces:faceArray
msh.numTVerts = UV_array.count
buildTVFaces msh
msh.name=("Killer_Instinct_MDL"+("_"+i as string))
for j = 1 to UV_array.count do setTVert msh j UV_array[j]
for j = 1 to faceArray.count do setTVFace msh j faceArray[j]
msh.wirecolor = (color 230 200 210)	

max modify mode
select msh
skinMod = skin ()
addModifier msh skinMod
for i = 1 to UsedBoneCount do
(
	maxbone = GetNodeByName UBoneNameArray[BoneMapArray[i]]
	if i != UsedBoneCount then 
		skinOps.addBone skinMod maxbone 0
	else
		skinOps.addBone skinMod maxbone 1
)
modPanel.setCurrentObject skinMod
for i = 1 to vertArray.count do (
   w = Weight_array[i]
   bi = #() --bone index array
   wv = #() --weight value array
   
   for j = 1 to w.boneids.count do
   (
      boneid = w.boneids[j]
      weight = w.weights[j]
      append bi boneid
      append wv weight
   )   
   
   skinOps.ReplaceVertexWeights skinMod i bi wv
)	
)catch(format "Import Error!!!\n")
)

fclose f