if (heapSize < 200000) then
        heapSize = 2000000 -- allow ~ 40 MB instead of just 7.5 MB. Prevents "Runtime Error: Out of scripter memory"
gname = getOpenFileName \
caption:"Open .hkx from Mesh folder" \
types:"DS3 Skeleton (Skeleton.hkx)|Skeleton.hkx" \
historyCategory:"DS_3SkelObjectPresets"
g = fopen gname "rb"
fname = getOpenFileName \
caption:"Open .flver from Mesh folder" \
types:"Dark Souls 3 (*.flver)|*.flver" \
historyCategory:"DarkSouls3ObjectPresets"
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
   (
      str0 = ReadByte bstream #unsigned
      if str0!=0x00 do str+= bit.intAsChar str0
   )
   str
)
struct weight_data
(
	boneids,weights
)
struct Vertex_Info_Struct
(
VertexType, VertexSize,VertexCount,VertexOffset
)
struct UV_Info_Struct
(
UVType, UVSize,UVCount,UVOffset
)
struct Face_Info_Struct
(
FaceCount, FaceOffset,FaceSecSize
)

Vertex_Info	= #()
Face_Info = #()	
LodCount_Array = #()	
Bone_Names_Array = #()	
MaxBoneID_Array = #()
Trans_array = #()
Rotation_array = #()
Scale_array = #()	
BNArr2 = #()
bonesNamesArray=#()
boneparent_array = #()
clearlistener()

fseek g 0x2A0 #seek_set
BoneCount=readlong g

fseek g 0x7C #seek_cur

Print ("Parent Start @ 0x"+((bit.intAsHex(ftell g))as string))

for i = 1 to BoneCount do ( --Bone Parent
boneparent = readshort g
append boneparent_array boneparent
)

Print ("Parent End @ 0x"+((bit.intAsHex(ftell g))as string))

for i = 1 to BoneCount do ( --Bone Parent
getPos = ftell g + 16	
fseek g getPos #seek_set	
)

Print ("Padding End @ 0x"+((bit.intAsHex(ftell g))as string))

while (checkNull=readbyte g)==0 do (
Pos=ftell g
chk=readbyte g
if chk==0 then fseek g 0x0 #seek_cur	
if chk!=0 then fseek g Pos #seek_set	
)	
Pos2=ftell g
fseek g (Pos2-1) #seek_set	
	
Print ("Names Start @ 0x"+((bit.intAsHex(ftell g))as string))

bonesNamesPos=#()	
for i = 1 to BoneCount do ( --Bone Names
BoneName = readstring g
StringEnd=ftell g	
while (checkNull=readbyte g)==0 do (
Pos=ftell g
chk=readbyte g
if chk==0 then fseek g 0x0 #seek_cur	
if chk!=0 then fseek g Pos #seek_set	
)	
Pos2=ftell g
fseek g (Pos2-1) #seek_set
append bonesNamesArray BoneName 	
append bonesNamesPos StringEnd
)

Stride=0
print (bonesNamesPos[BoneCount] as string)
if (bonesNamesArray[BoneCount].count)<16 then Stride=16-(bonesNamesArray[BoneCount].count)
if (bonesNamesArray[BoneCount].count)>16 then Stride=32-(bonesNamesArray[BoneCount].count)

print (Stride as string)

Print ("Names End @ 0x"+((bit.intAsHex(ftell g))as string))
	
fseek g (((bonesNamesPos[BoneCount]-1)+Stride)+0) #seek_set	

Print ("Bones Start @ 0x"+((bit.intAsHex(ftell g))as string))	
	
BNArr = #()
tarr2 = #()
rarr2 = #()
for a = 1 to BoneCount Do (
float11 = readfloat g; float12 = readfloat g; float13 = readfloat g; float14 = readfloat g 
float21 = readfloat g; float22 = readfloat g; float23 = readfloat g; float24 = readfloat g *-1
float31 = readfloat g; float32 = readfloat g; float33 = readfloat g; float34 = readfloat g
tfm = (quat float21 float22 float23 float24) as matrix3
Pos = ([float11,float12,float13]*100)
append tarr2 Pos		
append rarr2 tfm	
)

for a = 1 to BoneCount Do (
if isvalidnode (getNodeByName bonesNamesArray[a]) != true then (
tfm = rarr2[a]
tfm.row4 = tarr2[a]
if (boneparent_array[a] != -1) do (
tfm = tfm * BNArr[(boneparent_array[a] + 1)].objecttransform	
)	
newBone = bonesys.createbone	\
				  tfm.row4	\
				  (tfm.row4 + 0.01 * (normalize tfm.row1)) \
				  (normalize tfm.row3)
			newBone.name = bonesNamesArray[a]
			newBone.width  = 0.01
			newBone.height = 0.01
			newBone.transform = tfm
			newBone.setBoneEnable false 0
			newBone.wirecolor = white
			newbone.showlinks = true
			newBone.pos.controller      = TCB_position ()
			newBone.rotation.controller = TCB_rotation ()
if (boneparent_array[a] != -1) then
 newBone.parent = BNArr[(boneparent_array[a] + 1)]	
)	
if isvalidnode (getNodeByName bonesNamesArray[a]) == true then (
newBone = getNodeByName bonesNamesArray[a]
)
append BNArr newBone
)

Print ("Bones End @ 0x"+((bit.intAsHex(ftell g))as string))

if BNArr[1].name=="Master" then BNArr[1].transform = (matrix3 [0,-1,0] [0,0,1] [1,0,0] [0,0,0])		
	
if BNArr[1].name!="Master" then 	
if isvalidnode (getNodeByName "Main_Root") != true then (	
rootRT = dummy name:"Main_Root" boxsize:[.1,.1,.1]
for b in BNArr where b.parent==undefined do b.parent = rootRT
rootRT.transform = (matrix3 [1,0,0] [0,0,1] [0,1,0] [0,0,0])	
)

if isvalidnode (getNodeByName "Main_Root") == true then (
newBone = getNodeByName "Main_Root"
)

fclose g

fseek f 0x6 #seek_set
Endian = ReadShort f
VersionMajor=Readshort f
VersionMinor=Readshort f
dataOffset = Readlong f	
print (dataOffset as string)
dataSize = Readlong f	
count = Readlong f
numMat = Readlong f	
BoneCount = Readlong f		
numParts = Readlong f	
numMesh = Readlong f	

fseek f 0x50  #seek_set
BoneMapCount=readlong f
SkipCount1 = readlong f	
print ("Parse Count "+((SkipCount1)as string))
SkipCount2 = readlong f	

fseek f 0x80  #seek_set
for a = 1 to count  do (
getPos = ftell f + 64
fseek f getPos #seek_set	
)		
for a = 1 to numMat do (
getPos = ftell f + 32
fseek f getPos #seek_set	
)	

Print ("Bone Start @ 0x"+((bit.intAsHex(ftell f))as string))
		
BonePos=ftell f
	
for a = 1 to BoneCount do (

fseek f 0xC #seek_cur

BPos=ftell f
BoneNameOff = Readlong f	
fseek f BoneNameOff #seek_set
BoneNameStart=(ftell f)	
while (CheckNull=readshort f)!=0 do (
Pos=ftell f	
checkByte=readbyte f	
if checkByte==0 then fseek f Pos #seek_set
if checkByte!=0 then fseek f 0x0 #seek_cur
)	
BoneNameEnd=(ftell f+1)
BoneNameSize=BoneNameEnd-BoneNameStart
fseek f BPos #seek_set

fseek f BoneNameOff #seek_set
BoneName=ReadFixedString f BoneNameSize
fseek f BPos #seek_set
	
fseek f 0x74 #seek_cur
append Bone_Names_Array BoneName
)

fseek f BonePos #seek_set
  
tarr = #()
rarr = #()
Parr = #()

   for a = 1 to BoneCount do (
   getPos = ftell f + 128 
   px = readFloat f
   py = readFloat f
   pz = readFloat f
   BONEposition = ([px,pz,py]*100)
   ofsBONEname = readlong f
   rx = readFloat f;
   ry = readFloat f; 
   rz = readFloat f*-1; 
   ParentID = readshort f
   BoneChild = readshort f
   sx = readFloat f
   sy = readFloat f
   sz = readFloat f
   BONEscale = [sx,sy,sz]
   Unknown02 = readshort f
   Unknown03 = readshort f
   fseek f getPos #seek_set 
   BoneRotation= ((eulerAngles (RadToDeg (rx)) (RadToDeg (ry)) (RadToDeg (rz))) as quat) as matrix3

   append tarr BONEposition   
   append rarr BoneRotation
   append Parr ParentID   
  )
  
 for a=1 to BoneCount do ( 
if isvalidnode (getNodeByName Bone_Names_Array[a]) != true then (
tfm = rarr[a]
tfm.row4 = tarr[a]
if (Parr[a] != -1) do (
tfm = tfm * BNArr2[(Parr[a] + 1)].objecttransform
)
newBone = bonesys.createbone   \
              tfm.row4   \
              (tfm.row4 + 0.01 * (normalize tfm.row1)) \
              (normalize tfm.row3)
         newBone.name = Bone_Names_Array[a]
         newBone.width  = 0.01
         newBone.height = 0.01
         newBone.transform = tfm
         newBone.setBoneEnable false 0
         newBone.wirecolor = yellow
         newbone.showlinks = true
         newBone.pos.controller      = TCB_position ()
         newBone.rotation.controller = TCB_rotation ()
if (Parr[a] != -1) then (
newBone.parent = BNArr2[(Parr[a] + 1)]
)	
)
if isvalidnode (getNodeByName Bone_Names_Array[a]) == true then (
newBone = getNodeByName Bone_Names_Array[a]
)  
append BNArr2 newBone     
)   

Print ("Bone End @ 0x"+((bit.intAsHex(ftell f))as string))
	
BoneMapOff_Array=#()	
for a = 1 to numParts do (
getPos = ftell f + 48	
Unk=readlong f	
MeshId=readlong f		
fseek f 0x8 #seek_cur	
MaxBoneID=readlong f	
fseek f 0x8 #seek_cur	
BoneMapOff=readlong f	
LodCount= readlong f	
fseek f 0x10 #seek_cur	
fseek f getPos #seek_set	
append BoneMapOff_Array BoneMapOff	
append LodCount_Array LodCount
append MaxBoneID_Array MaxBoneID	
)		

print BoneMapCount_Array

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

for a = 1 to numParts do (
if LodCount_Array[a]==1 then
(
LodId= Readlong f
Unk1= readbyte f	
Unk2= readbyte f
Unk3= readbyte f	
Unk4= readbyte f	
FaceCount= Readlong f	
FaceOffset= Readlong f	
FaceSecSize= Readlong f		
null= Readlong f	
FaceFlag= Readlong f
null3= Readlong f	
append Face_Info (Face_Info_Struct FaceCount:FaceCount FaceOffset:FaceOffset FaceSecSize:FaceSecSize )				
)
if LodCount_Array[a]>1 then
(
LodId= Readlong f
Unk1= readbyte f	
Unk2= readbyte f
Unk3= readbyte f	
Unk4= readbyte f	
FaceCount= Readlong f	
FaceOffset= Readlong f	
FaceSecSize= Readlong f		
null= Readlong f	
FaceFlag= Readlong f
null3= Readlong f	
append Face_Info (Face_Info_Struct FaceCount:FaceCount FaceOffset:FaceOffset FaceSecSize:FaceSecSize )		
for i = 1 to (LodCount_Array[a]-1) do (	
getPos = ftell f + 32			
fseek f getPos #seek_set	
)	
)

)	

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

print Face_Info

UV_Info=#()	
VertSecCount=#()	
for a = 1 to numParts do (
BuffCount = Readlong f	
VertexType = ReadLong f
VertexSize= Readlong f	
if VertexSize<24 then (	
VertexCount= Readlong f	
Unk1= Readlong f	
Unk2= Readlong f	
VertexSecSize= Readlong f	
VertexOffset= Readlong f	
readlong f
UVType= readlong f	
UVSize= Readlong f	
UVCount= Readlong f	
Unk1= Readlong f	
Unk2= Readlong f	
UVSecSize= Readlong f	
UVOffset= Readlong f	
)		
if VertexSize>24 then (	
VertexCount= Readlong f	
Unk1= Readlong f	
Unk2= Readlong f	
VertexSecSize= Readlong f	
VertexOffset= Readlong f	
)		
append VertSecCount LodCount
append Vertex_Info (Vertex_Info_Struct VertexType:VertexType VertexSize:VertexSize VertexCount:VertexCount VertexOffset:VertexOffset)	
append UV_Info (UV_Info_Struct UVType:UVType UVSize:UVSize UVCount:UVCount UVOffset:UVOffset)		
)	

print Vertex_Info
print UV_Info

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

for i = 1 to numParts do (
	
vertArray = #()
Facearray = #()	
UV_array = #()
Weight_array=#()
BoneMapIdArray= #()	
	
FaceOffset=(dataOffset+(Face_Info[i].FaceOffset))		
fseek f (dataOffset+(Face_Info[i].FaceOffset)) #seek_set	
	
Print ("Face Start @ 0x"+((bit.intAsHex(ftell f))as string))	
	
while ((ftell f) < (FaceOffset + (Face_Info[i].FaceSecSize))) Do (
f1 = ((readshort f #unsigned) + 1) 
f2 = ((Readshort f #unsigned) + 1) 
f3 = ((Readshort f #unsigned) + 1)  
append Facearray [f1,f2,f3]
)	
	
VertOffset=(dataOffset+(Vertex_Info[i].VertexOffset))	
fseek f (dataOffset+(Vertex_Info[i].VertexOffset))	 #seek_set	

Print ("Vertex Start @ 0x"+((bit.intAsHex(ftell f))as string))	
	
if Vertex_Info[i].VertexType==1 then	
if Vertex_Info[i].VertexSize==48 then
for x = 1 to Vertex_Info[i].VertexCount do (

getPos = ftell f + Vertex_Info[i].VertexSize		
	
vx = Readfloat f
vy = Readfloat f
vz = Readfloat f
		
fseek f 0x8 #seek_cur
	
bone1 = readbyte f #unsigned	
bone2 = readbyte f #unsigned	
bone3 = readbyte f #unsigned	
bone4 = readbyte f #unsigned
bone5 = readbyte f #unsigned	
bone6 = readbyte f #unsigned	
	
weight1 = readbyte f #unsigned	
weight2 = readbyte f #unsigned
weight3 = readbyte f #unsigned
weight4 = readbyte f #unsigned
weight5 = readbyte f #unsigned
weight6 = readbyte f #unsigned	
	
fseek f 0x4 #seek_cur
	
tu=ReadShort f	
tv=ReadShort f*-1
	
fseek f 0x4 #seek_cur	

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(weight5 != 0) then
   maxweight = maxweight + weight5
if(weight6 != 0) then
   maxweight = maxweight + weight6


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)
      ) 
      if(weight5 != 0) then (
         w5 = weight5 as float
         append w.boneids (bone5 + 1)
         append w.weights (w5/255)
      )
      if(weight6 != 0) then (
         w6 = weight6 as float
         append w.boneids (bone6 + 1)
        append w.weights (w6/255)
      )     	  
   )
fseek f getPos #seek_set	   
append Weight_array w	
append vertArray ([vx,vz,vy]*100)
append UV_array ([tu,tv,0]/2048)
)		
	
if Vertex_Info[i].VertexType==9 then	
if Vertex_Info[i].VertexSize==48 then
for x = 1 to Vertex_Info[i].VertexCount do (

getPos = ftell f + Vertex_Info[i].VertexSize		
	
vx = Readfloat f
vy = Readfloat f
vz = Readfloat f
		
fseek f 0x8 #seek_cur
	
bone1 = readbyte f #unsigned	
bone2 = readbyte f #unsigned	
bone3 = readbyte f #unsigned	
bone4 = readbyte f #unsigned
bone5 = readbyte f #unsigned	
bone6 = readbyte f #unsigned	
	
weight1 = readbyte f #unsigned	
weight2 = readbyte f #unsigned
weight3 = readbyte f #unsigned
weight4 = readbyte f #unsigned
weight5 = readbyte f #unsigned
weight6 = readbyte f #unsigned	
	
fseek f 0x4 #seek_cur
	
tu=ReadShort f	
tv=ReadShort f*-1
	
fseek f 0x4 #seek_cur	

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(weight5 != 0) then
   maxweight = maxweight + weight5
if(weight6 != 0) then
   maxweight = maxweight + weight6


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)
      ) 
      if(weight5 != 0) then (
         w5 = weight5 as float
         append w.boneids (bone5 + 1)
         append w.weights (w5/255)
      )
      if(weight6 != 0) then (
         w6 = weight6 as float
         append w.boneids (bone6 + 1)
        append w.weights (w6/255)
      )     	  
   )
fseek f getPos #seek_set	   
append Weight_array w	
append vertArray ([vx,vz,vy]*100)
append UV_array ([tu,tv,0]/2048)
)	
if Vertex_Info[i].VertexType!=9 then 
if Vertex_Info[i].VertexType!=1 then	
if Vertex_Info[i].VertexSize==48 then
for x = 1 to Vertex_Info[i].VertexCount do (

getPos = ftell f + Vertex_Info[i].VertexSize		
	
vx = Readfloat f
vy = Readfloat f
vz = Readfloat f
		
fseek f 0x8 #seek_cur
	
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
	
fseek f 0x4 #seek_cur
	
tu=ReadShort f	
tv=ReadShort f*-1
	
fseek f 0x4 #seek_cur	

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)
      ) 	  
   )
fseek f getPos #seek_set	   
append Weight_array w	
append vertArray ([vx,vz,vy]*100)
append UV_array ([tu,tv,0]/2048)
)	
if Vertex_Info[i].VertexType==9 then
if Vertex_Info[i].VertexSize==44 then
for x = 1 to Vertex_Info[i].VertexCount do (
getPos = ftell f + Vertex_Info[i].VertexSize		
	
vx = Readfloat f
vy = Readfloat f
vz = Readfloat f

fseek f 0x8 #seek_cur
	
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
	
fseek f 0x4 #seek_cur
	
tu=ReadShort f	
tv=ReadShort f*-1
	
fseek f 0x8 #seek_cur	

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)
      )      
   )
fseek f getPos #seek_set	   
append Weight_array w	
append vertArray ([vx,vz,vy]*100)
append UV_array ([tu,tv,0]/2048)	
)	

if Vertex_Info[i].VertexType!=9 then
if Vertex_Info[i].VertexSize==44 then
for x = 1 to Vertex_Info[i].VertexCount do (
getPos = ftell f + Vertex_Info[i].VertexSize		
	
vx = Readfloat f
vy = Readfloat f
vz = Readfloat f

fseek f 0xC #seek_cur
	
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
	
fseek f 0x4 #seek_cur
	
tu=ReadShort f	
tv=ReadShort f*-1
	
fseek f 0x4 #seek_cur	

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)
      )      
   )
fseek f getPos #seek_set	   
append Weight_array w	
append vertArray ([vx,vz,vy]*100)
append UV_array ([tu,tv,0]/2048)	
)	

if Vertex_Info[i].VertexSize==40 then
for x = 1 to Vertex_Info[i].VertexCount do (

vx = Readfloat f
vy = Readfloat f
vz = Readfloat f
			
fseek f 0x8 #seek_cur	
	
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
			
tu=ReadShort f	
tv=ReadShort f*-1
	
fseek f 0x8 #seek_cur	

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 vertArray ([vx,vz,vy]*100)
append UV_array ([tu,tv,0]/2048)	
)	
if Vertex_Info[i].VertexType==0 then
if Vertex_Info[i].VertexSize==36 then
for x = 1 to Vertex_Info[i].VertexCount do (

vx = Readfloat f
vy = Readfloat f
vz = Readfloat f
	
fseek f 0x8 #seek_cur	
	
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	 
	
tu=Readshort f/1024.00	
tv=(Readshort f/1024.00)*-1			
	
fseek f 0x4 #seek_cur	
			
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 vertArray ([vx,vz,vy]*100)
append UV_array ([tu,tv,0]/2)	
)	
if Vertex_Info[i].VertexType!=0 then
if Vertex_Info[i].VertexSize==36 then
for x = 1 to Vertex_Info[i].VertexCount do (

vx = Readfloat f
vy = Readfloat f
vz = Readfloat f
	
fseek f 0x8 #seek_cur	
	
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	 
	
fseek f 0x4 #seek_cur		
	
tu=Readshort f/1024.00	
tv=(Readshort f/1024.00)*-1			
				
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 vertArray ([vx,vz,vy]*100)
append UV_array ([tu,tv,0]/2)	
)	
if Vertex_Info[i].VertexType!=0 then
if Vertex_Info[i].VertexSize==32 then
for x = 1 to Vertex_Info[i].VertexCount do (
getPos = ftell f + Vertex_Info[i].VertexSize		
	
vx = Readfloat f
vy = Readfloat f
vz = Readfloat f
		
bone1 = readbyte f #unsigned	
bone2 = readbyte f #unsigned	
bone3 = readbyte f #unsigned	
bone4 = readbyte f #unsigned
	
weight1 = 1.0	
weight2 = 0
weight3 = 0
weight4 = 0
	
fseek f 0xC #seek_cur
	
tu=Readshort f/1024.00	
tv=(Readshort f/1024.00)*-1	

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)
      )
      if(weight2 != 0) then (
         w2 = weight2 as float
         append w.boneids (bone2 + 1)
         append w.weights (w2)
      )
      if(weight3 != 0) then (
         w3 = weight3 as float
         append w.boneids (bone3 + 1)
         append w.weights (w3)
      )
      if(weight4 != 0) then (
         w4 = weight4 as float
         append w.boneids (bone4 + 1)
        append w.weights (w4)
      )      
   )
fseek f getPos #seek_set	 
append Weight_array w	
append vertArray ([vx,vz,vy]*100)
append UV_array ([tu,tv,0]/2)	
)	
if Vertex_Info[i].VertexType==0 then
if Vertex_Info[i].VertexSize==32 then
for x = 1 to Vertex_Info[i].VertexCount do (
getPos = ftell f + Vertex_Info[i].VertexSize		
	
vx = Readfloat f
vy = Readfloat f
vz = Readfloat f
		
bone1 = 0	
bone2 = -1	
bone3 = -1
bone4 = -1
	
weight1 = 1.0	
weight2 = 0
weight3 = 0
weight4 = 0
	
fseek f 0xC #seek_cur
	
tu=Readshort f/1024.00	
tv=(Readshort f/1024.00)*-1	

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)
      )
      if(weight2 != 0) then (
         w2 = weight2 as float
         append w.boneids (bone2 + 1)
         append w.weights (w2)
      )
      if(weight3 != 0) then (
         w3 = weight3 as float
         append w.boneids (bone3 + 1)
         append w.weights (w3)
      )
      if(weight4 != 0) then (
         w4 = weight4 as float
         append w.boneids (bone4 + 1)
        append w.weights (w4)
      )      
   )
fseek f getPos #seek_set	   
append Weight_array w	
append vertArray ([vx,vz,vy]*100)
append UV_array ([tu,tv,0]/2)	
)		

if Vertex_Info[i].VertexSize==28 then
for x = 1 to Vertex_Info[i].VertexCount do (
getPos = ftell f + Vertex_Info[i].VertexSize	
	
vx = Readfloat f
vy = Readfloat f
vz = Readfloat f
		
bone1 = readbyte f #unsigned	
bone2 = readbyte f #unsigned	
bone3 = readbyte f #unsigned	
bone4 = readbyte f #unsigned
	
weight1 = 1.0	
weight2 = 0
weight3 = 0
weight4 = 0
	
fseek f 0x8 #seek_cur
	
tu=Readshort f/1024.00	
tv=(Readshort f/1024.00)*-1	

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)
      )
      if(weight2 != 0) then (
         w2 = weight2 as float
         append w.boneids (bone2 + 1)
         append w.weights (w2)
      )
      if(weight3 != 0) then (
         w3 = weight3 as float
         append w.boneids (bone3 + 1)
         append w.weights (w3)
      )
      if(weight4 != 0) then (
         w4 = weight4 as float
         append w.boneids (bone4 + 1)
        append w.weights (w4)
      )      
   )
fseek f getPos #seek_set	   
append Weight_array w	
append vertArray ([vx,vz,vy]*100)
append UV_array ([tu,tv,0]/2)	
)	

if Vertex_Info[i].VertexSize==12 then (
	
for x = 1 to Vertex_Info[i].VertexCount do (

vx = Readfloat f
vy = Readfloat f
vz = Readfloat f

append vertArray ([vx,vz,vy]*100)
)	

Print ("Vertex End @ 0x"+((bit.intAsHex(ftell f))as string))		
		
UVOffset=(dataOffset+(UV_Info[i].UVOffset))	
fseek f (dataOffset+(UV_Info[i].UVOffset)) #seek_set	
	
Print ("UV Start @ 0x"+((bit.intAsHex(ftell f))as string))	

if UV_Info[i].UVSize==32 then 	
for x = 1 to UV_Info[i].UVCount do (
getPos = ftell f + UV_Info[i].UVSize	

fseek f 0x8 #seek_cur	
	
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
	
fseek f 0x4 #seek_cur	
	
tu=ReadShort f	
tv=ReadShort f*-1		
	
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)
      )  	  
   )	
fseek f getPos #seek_set	 
append Weight_array w	
append UV_array ([tu,tv,0]/2048)
)	

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

if Vertex_Info[i].VertexSize==20 then (
	
for x = 1 to Vertex_Info[i].VertexCount do (

vx = Readfloat f
vy = Readfloat f
vz = Readfloat f
	
fseek f 0x8 #seek_cur
		
append vertArray ([vx,vz,vy]*100)
)	

Print ("Vertex End @ 0x"+((bit.intAsHex(ftell f))as string))		
		
UVOffset=(dataOffset+(UV_Info[i].UVOffset))	
fseek f (dataOffset+(UV_Info[i].UVOffset)) #seek_set	
	
Print ("UV Start @ 0x"+((bit.intAsHex(ftell f))as string))	

if UV_Info[i].UVSize==24 then 	
for x = 1 to UV_Info[i].UVCount do (
getPos = ftell f + UV_Info[i].UVSize		

fseek f 0x4 #seek_cur	
	
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
	
tu=ReadShort f	
tv=ReadShort f*-1		
	
fseek f 0x4 #seek_cur		
	
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)
      )  	  
   )	
fseek f getPos #seek_set	 
append Weight_array w	
append UV_array ([tu,tv,0]/2048)
)	

if UV_Info[i].UVType==11 then 
if UV_Info[i].UVSize==28 then 	
for x = 1 to UV_Info[i].UVCount do (
getPos = ftell f + UV_Info[i].UVSize	

fseek f 0x4 #seek_cur	
	
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
	
fseek f 0x4 #seek_cur	
	
tu=ReadShort f	
tv=ReadShort f*-1		
	
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)
      )  	  
   )	
fseek f getPos #seek_set	 
append Weight_array w	
append UV_array ([tu,tv,0]/2048)
)	

if UV_Info[i].UVType!=11 then 
if UV_Info[i].UVSize==28 then 	
for x = 1 to UV_Info[i].UVCount do (
getPos = ftell f + UV_Info[i].UVSize	

fseek f 0x8 #seek_cur	
	
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
	
fseek f 0x4 #seek_cur	
	
tu=ReadShort f	
tv=ReadShort f*-1		
	
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)
      )  	  
   )	
fseek f getPos #seek_set	 
append Weight_array w	
append UV_array ([tu,tv,0]/2048)
)	

if UV_Info[i].UVSize==32 then 	
for x = 1 to UV_Info[i].UVCount do (
getPos = ftell f + UV_Info[i].UVSize	

fseek f 0x8 #seek_cur	
	
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
	
fseek f 0x4 #seek_cur	
	
tu=ReadShort f	
tv=ReadShort f*-1		
	
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)
      )  	  
   )	
fseek f getPos #seek_set	 
append Weight_array w	
append UV_array ([tu,tv,0]/2048)
)	
if UV_Info[i].UVType==7 then 
if UV_Info[i].UVSize==36 then 	
for x = 1 to UV_Info[i].UVCount do (
getPos = ftell f + UV_Info[i].UVSize	

fseek f 0xC #seek_cur	
	
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
	
fseek f 0x4 #seek_cur	
	
tu=ReadShort f	
tv=ReadShort f*-1		
	
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)
      )  	  
   )	
fseek f getPos #seek_set	 
append Weight_array w	
append UV_array ([tu,tv,0]/2048)
)	
if UV_Info[i].UVType!=7 then 
if UV_Info[i].UVSize==36 then 	
for x = 1 to UV_Info[i].UVCount do (
getPos = ftell f + UV_Info[i].UVSize	

fseek f 0xC #seek_cur	
	
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
	
fseek f 0x4 #seek_cur	
	
tu=ReadShort f	
tv=ReadShort f*-1		
	
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)
      )  	  
   )	
fseek f getPos #seek_set	 
append Weight_array w	
append UV_array ([tu,tv,0]/2048)
)	

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

try(
msh = mesh vertices:vertArray faces:faceArray
msh.name=("Dark Souls 3 Mesh: "+i as string)	

msh.numTVerts = UV_array.count
buildTVFaces msh	
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.displayByLayer = false
msh.backfacecull = false
msh.wirecolor = (color 230 200 210)

max modify mode
select msh
skinMod = skin ()
addModifier msh skinMod
for i = 1 to Bone_Names_Array.count do
(
	maxbone = getNodeByName Bone_Names_Array[i]
	if i != Bone_Names_Array.count 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 "failed!!\n")
)

fclose f