home *** CD-ROM | disk | FTP | other *** search
/ Xentax forum attachments archive / xentax.7z / 8133 / Apex_Moonlight_MMO.7z / Apex_Moonlight_MMO.ms
Encoding:
Text File  |  2014-11-23  |  18.9 KB  |  737 lines

  1. if (heapSize < 200000) then
  2.         heapSize = 2000000 -- allow ~ 40 MB instead of just 7.5 MB. Prevents "Runtime Error: Out of scripter memory"
  3. fname = getOpenFileName \
  4. caption:"Open .mesh from Mesh folder" \
  5. types:"MLB Models (*.dat)|*.dat" \
  6. historyCategory:"MLBObjectPresets"
  7. f = fopen fname "rb"
  8.  
  9. clearlistener()
  10.  
  11. fn readBElong fstream = (bit.swapBytes (bit.swapBytes (readlong fstream #unsigned) 1 4) 2 3)
  12.     
  13. fn readBEfloat fstream = (bit.intAsFloat (bit.swapBytes (bit.swapBytes (readlong fstream #unsigned) 1 4) 2 3))    
  14.     
  15. fn readBEword fstream = (
  16. short = readshort fstream #unsigned
  17. short = bit.swapBytes short 1 2
  18. return short
  19. )    
  20.  
  21. fn ReadBEHalfFloat fstream = 
  22.     (
  23.     hf=readBEword fstream
  24.     sign = bit.get hf 16
  25.     exponent = (bit.shift (bit.and hf (bit.hexasint "7C00")) -10) as integer - 16
  26.     fraction = bit.and hf (bit.hexasint "03FF")
  27.     if sign==true then sign = 1 else sign = 0
  28.     exponentF = exponent + 127
  29.     outputAsFloat = bit.or (bit.or (bit.shift fraction 13) \
  30.     (bit.shift exponentF 23)) (bit.shift sign 31)
  31.     return bit.intasfloat outputasfloat*2
  32. )    
  33.  
  34. fn ReadHalfFloat fstream = 
  35.     (
  36.     hf=readshort fstream
  37.     sign = bit.get hf 16
  38.     exponent = (bit.shift (bit.and hf (bit.hexasint "7C00")) -10) as integer - 16
  39.     fraction = bit.and hf (bit.hexasint "03FF")
  40.     if sign==true then sign = 1 else sign = 0
  41.     exponentF = exponent + 127
  42.     outputAsFloat = bit.or (bit.or (bit.shift fraction 13) \
  43.     (bit.shift exponentF 23)) (bit.shift sign 31)
  44.     return bit.intasfloat outputasfloat*2
  45. )
  46.  
  47. fn readFixedString bstream fixedLen = (
  48. local str = ""
  49. for i = 1 to fixedLen do (
  50. str += bit.intAsChar (ReadByte bstream #unsigned))
  51. str
  52. )
  53. struct weight_data
  54. (
  55.     boneids,weights
  56. )
  57. struct Bone_Info_Struct
  58. (
  59.     Bone1,Bone2,Bone3,Bone4
  60. )
  61. struct Weight_Info_Struct
  62. (
  63.     Weight1,Weight2,Weight3,Weight4
  64. )
  65. struct Mesh_Info_Struct
  66. (
  67.     DataOff,DataSize,DataCount
  68. )    
  69. struct Mesh_Info_Struct_2 
  70. (
  71.     DataOff2,DataSize2,DataCount2
  72. )    
  73. clearlistener()
  74.  
  75. BNArr=#()    
  76. BoneNameArray=#()
  77.  
  78. fseek f (0x0) #seek_end
  79. EndSize=ftell f
  80. fseek f (0x0) #seek_set
  81. Magic=readlong f
  82. if Magic!=1566333786 then fclose f
  83. if Magic==1566333786 then (
  84. fseek f (0x8) #seek_cur
  85. MeshCount=readBELong f
  86. FileSize=readBELong f
  87. DataStart=readBELong f
  88. DataEnd=readBELong f
  89. DataSize=readBELong f
  90.  
  91. SizeCount=(EndSize-FileSize)
  92. print SizeCount
  93.  
  94. fseek f (DataEnd+SizeCount) #seek_set
  95. Offset=readlong f
  96.  
  97. FaceOff=#()
  98. if SizeCount==0 then (
  99.     
  100. fseek f (Offset) #seek_set    
  101. Print ("Start 00@ 0x"+((bit.intAsHex(ftell f))as string))        
  102. Count=readLong f    
  103. fseek f (Count-12) #seek_cur    
  104. BOffset=readlong f    
  105. fseek f (0x78) #seek_cur        
  106. BoneCount=readlong f    
  107. fseek f (BOffset) #seek_set    
  108. fseek f (0x10) #seek_cur    
  109. DOffset=readlong f    
  110. UnkSize=readlong f
  111.     
  112. Print ("Bone Start @ 0x"+((bit.intAsHex(ftell f))as string))    
  113.         
  114. for i=1 to BoneCount do (
  115. getPos = ftell f + 76
  116. BoneId=readlong f
  117. BoneChild=readlong f
  118. Unk01=readlong f
  119. Unk02=readlong f    
  120. BoneParent=readlong f+1    
  121. c11=readfloat f;c12=readfloat f;c13=readfloat f;c14=readfloat f
  122. c21=readfloat f;c22=readfloat f;c23=readfloat f;c24=readfloat f
  123. c31=readfloat f;c32=readfloat f;c33=readfloat f;c34=readfloat f
  124. BoneNameOff=readlong f;Null=readlong f        
  125. fseek f getPos #seek_set    
  126. Position=ftell f
  127. fseek f (BoneNameOff) #seek_set    
  128. BoneName=readstring f    
  129. append BoneNameArray    BoneName
  130. fseek f Position #seek_set    
  131.         
  132. tfm = (quat c24 c23 c22 c21) as matrix3
  133. tfm.row4 = [c32,c33,c34]
  134.  
  135. newBone = bonesys.createbone    \
  136.                                       tfm.row4      \
  137.                                       (tfm.row4 + 0.01 * (normalize tfm.row1)) \
  138.                                       (normalize tfm.row3)
  139.                             newBone.width  = 0.01
  140.                             newBone.height = 0.01
  141.                             newBone.name = BoneName                                  
  142.                             newBone.transform = tfm
  143.                             newBone.setBoneEnable false 0
  144.                             newBone.wirecolor = yellow
  145.                             newbone.showlinks = true
  146.                             newBone.pos.controller      = TCB_position ()
  147.                             newBone.rotation.controller = TCB_rotation () 
  148. if BoneParent!=0 then
  149. newBone.parent=BNArr[(BoneParent)]                                              
  150. append BNArr newBone  
  151. )    
  152.  
  153. Print ("Bone End @ 0x"+((bit.intAsHex(ftell f))as string))            
  154.     
  155.     
  156. fseek f (DOffset) #seek_set
  157. DCount=readLong f    
  158. fseek f (DCount-12) #seek_cur
  159. DataOffset=readlong f
  160. fseek f (0x28) #seek_cur    
  161. VertCount=readlong f
  162. FaceCount=readlong f
  163. Unk=readlong f
  164.  
  165. Mesh_Info=#()
  166.  
  167. Print ("Data Start @ 0x"+((bit.intAsHex(ftell f))as string))        
  168. for i=1 to 7 do (
  169. getPos = ftell f + 16
  170. DataOff=readlong f
  171. Null=readlong f    
  172. DataSize=readlong f    
  173. DataCount=readlong f    
  174. fseek f getPos #seek_set        
  175. append Mesh_Info (Mesh_Info_Struct DataOff:DataOff DataSize:DataSize DataCount:DataCount)    
  176. )
  177. fseek f (0X4) #seek_cur
  178. append FaceOff (readlong f)
  179. print Mesh_Info
  180. )    
  181.  
  182. fseek f (Mesh_Info[1].DataOff) #seek_set
  183.  
  184. Print ("Vertex Start @ 0x"+((bit.intAsHex(ftell f))as string))    
  185.  
  186. vertArray = #()
  187. faceArray = #()
  188. UV_array = #()
  189. Weight_array=#()    
  190. B1_array=#()
  191. W1_array=#()
  192.     
  193. for x = 1 to VertCount do (
  194. getPos = ftell f + 12
  195. vx = ReadFloat f
  196. vy = ReadFloat f
  197. vz = ReadFloat f    
  198. append vertArray ([vx,vy,vz])    
  199. fseek f getPos #seek_set        
  200. )    
  201.  
  202. fseek f (Mesh_Info[2].DataOff) #seek_set
  203.  
  204. Print ("Normal Start @ 0x"+((bit.intAsHex(ftell f))as string))    
  205.  
  206. for x = 1 to VertCount do (
  207. getPos = ftell f + 12
  208. fseek f getPos #seek_set            
  209. )    
  210.  
  211. fseek f (Mesh_Info[3].DataOff) #seek_set
  212.  
  213. Print ("Tangent Start @ 0x"+((bit.intAsHex(ftell f))as string))    
  214.  
  215. for x = 1 to VertCount do (
  216. getPos = ftell f + 12    
  217. fseek f getPos #seek_set        
  218. )    
  219.  
  220. fseek f (Mesh_Info[4].DataOff) #seek_set
  221.  
  222. Print ("UV's Start @ 0x"+((bit.intAsHex(ftell f))as string))    
  223.  
  224. for x = 1 to VertCount do (
  225. tu=readBEword f 
  226. tv=readBEword f 
  227. fseek f (0x8) #seek_set        
  228. append UV_array ([tu,tv,0]/65535)        
  229. )    
  230.  
  231. Print ("UV's End @ 0x"+((bit.intAsHex(ftell f))as string))    
  232.  
  233. fseek f (Mesh_Info[5].DataOff) #seek_set    
  234.  
  235. Print ("BoneID's Start @ 0x"+((bit.intAsHex(ftell f))as string))        
  236.     
  237. for x = 1 to VertCount do (
  238. bone1 = readshort f #unsigned    
  239. bone2 = readshort f #unsigned        
  240. bone3 = readshort f #unsigned    
  241. bone4 = readshort f #unsigned        
  242. append B1_array (Bone_Info_Struct Bone1:Bone1 Bone2:Bone2 Bone3:Bone3 Bone4:Bone4)        
  243. )    
  244.  
  245. fseek f (Mesh_Info[6].DataOff) #seek_set
  246.  
  247. Print ("Weights Start @ 0x"+((bit.intAsHex(ftell f))as string))    
  248.  
  249. for x = 1 to VertCount do (
  250. weight1 = ReadFloat f
  251. weight2 = ReadFloat f
  252. weight3 = ReadFloat f
  253. weight4 = ReadFloat f        
  254. append W1_array (Weight_Info_Struct Weight1:Weight1 Weight2:Weight2 Weight3:Weight3 Weight4:Weight4)        
  255. )    
  256.  
  257. for b = 1 to W1_array.count Do (
  258. w = (weight_data boneids:#() weights:#())
  259. maxweight = 0
  260. if(W1_array[b].Weight1 != 0) then
  261.    maxweight = maxweight + W1_array[b].Weight1
  262. if(W1_array[b].Weight2 != 0) then
  263.    maxweight = maxweight + W1_array[b].Weight2
  264. if(W1_array[b].Weight3 != 0) then
  265.    maxweight = maxweight + W1_array[b].Weight3
  266. if(W1_array[b].Weight4 != 0) then
  267.    maxweight = maxweight + W1_array[b].Weight4
  268.  
  269. if(maxweight != 0) then
  270.    (
  271.       if(W1_array[b].Weight1 != 0) then
  272.       (
  273.          w1 = W1_array[b].Weight1 as float
  274.          append w.boneids (B1_array[b].Bone1 + 1)
  275.          append w.weights (w1)
  276.       )
  277.       if(W1_array[b].Weight2 != 0) then
  278.       (
  279.          w2 = W1_array[b].Weight2 as float
  280.          append w.boneids (B1_array[b].Bone2 + 1)
  281.          append w.weights (w2)
  282.       )
  283.       if(W1_array[b].Weight3 != 0) then
  284.       (
  285.          w3 = W1_array[b].Weight3 as float
  286.          append w.boneids (B1_array[b].Bone3 + 1)
  287.          append w.weights (w3)
  288.       )
  289.       if(W1_array[b].Weight4 != 0) then
  290.       (
  291.          w4 = W1_array[b].Weight4 as float
  292.          append w.boneids (B1_array[b].Bone4 + 1)
  293.          append w.weights (w4)
  294.       )      
  295.    )
  296. append Weight_array w
  297. )
  298.  
  299. Print ("!!!!! Start @ 0x"+((bit.intAsHex(ftell f))as string))    
  300.  
  301. fseek f (Mesh_Info[7].DataOff) #seek_set    
  302.     
  303. for x = 1 to Mesh_Info[7].DataCount do (
  304. id=readbyte f
  305. )    
  306.  
  307. Print ("!!!!! End @ 0x"+((bit.intAsHex(ftell f))as string))    
  308.  
  309. fseek f (FaceOff[1]) #seek_set    
  310.     
  311. Print ("Face Start @ 0x"+((bit.intAsHex(ftell f))as string))    
  312.  
  313. for x=1 to (FaceCount/3) do (    
  314. fa=readlong f +1
  315. fb=readlong f +1
  316. fc=readlong f +1
  317. append faceArray [fa,fb,fc]    
  318. )    
  319.  
  320. Print ("Face End @ 0x"+((bit.intAsHex(ftell f))as string))    
  321.  
  322. msh = mesh vertices:vertArray faces:faceArray
  323. msh.numTVerts = UV_array.count
  324. buildTVFaces msh
  325. for j = 1 to UV_array.count do setTVert msh j UV_array[j]
  326. for j = 1 to faceArray.count do setTVFace msh j faceArray[j]
  327. msh.displayByLayer = false
  328. msh.backfacecull = false
  329. msh.wirecolor = (color 230 200 210)
  330.  
  331. max modify mode
  332. select msh
  333. skinMod = skin ()
  334. addModifier msh skinMod
  335. for i = 1 to BNArr.count do
  336. (
  337.     maxbone = BNArr[i]
  338.     if i != BNArr.count then 
  339.         skinOps.addBone skinMod maxbone 0
  340.     else
  341.         skinOps.addBone skinMod maxbone 1
  342. )
  343. modPanel.setCurrentObject skinMod
  344. for i = 1 to vertArray.count do (
  345.    w = Weight_array[i]
  346.    bi = #() --bone index array
  347.    wv = #() --weight value array
  348.    
  349.    for j = 1 to w.boneids.count do
  350.    (
  351.       boneid = w.boneids[j]
  352.       weight = w.weights[j]
  353.       append bi boneid
  354.       append wv weight
  355.    )   
  356.    
  357.    skinOps.ReplaceVertexWeights skinMod i bi wv
  358. )    
  359. )
  360.  
  361. Pos00=ftell f
  362. Null00=readlong f
  363. if Null00!=0 then fseek f Pos00 #seek_set     
  364. if Null00==0 then (
  365. fseek f 0x0 #seek_cur    
  366. Pos01=ftell f
  367. Null01=readlong f
  368. if Null01!=0 then fseek f Pos01 #seek_set     
  369. if Null01==0 then (
  370. fseek f 0x0 #seek_cur    
  371. Pos02=ftell f
  372. Null02=readlong f
  373. if Null02!=0 then fseek f Pos02 #seek_set     
  374. if Null02==0 then (
  375. fseek f 0x0 #seek_cur    
  376. Pos03=ftell f
  377. Null03=readlong f
  378. if Null03!=0 then fseek f Pos03 #seek_set     
  379. if Null03==0 then fseek f 0x0 #seek_cur            
  380. )        
  381. )    
  382. )    
  383.  
  384. SimMeshEnd=ftell f
  385. if Magic==1566333786 then (
  386. Print ("SimMeshEnd @ 0x"+((bit.intAsHex(ftell f))as string))    
  387. )
  388.  
  389. fseek f (0x0) #seek_end
  390. EndSize=ftell f
  391. fseek f (0x0) #seek_set
  392. Magic=readlong f
  393. if Magic!=1566333786 then fclose f
  394. if Magic==1566333786 then (
  395. for i=1 to 1 do (    
  396. fseek f (0x8) #seek_cur
  397. MeshCount=readBELong f
  398. FileSize=readBELong f
  399. DataStart=readBELong f
  400. DataEnd=readBELong f
  401. DataSize=readBELong f
  402. SizeCount=(EndSize-FileSize)
  403. print SizeCount
  404.     
  405. fseek f (SimMeshEnd) #seek_set
  406. fseek f (0xA4) #seek_cur
  407. MeshOffset=readlong f    
  408. print MeshOffset
  409.     
  410. if SizeCount==0 then fseek f (MeshOffset) #seek_set
  411. if SizeCount==2 then fseek f (MeshOffset+2) #seek_set
  412. if SizeCount==3 then fseek f (MeshOffset+3) #seek_set    
  413. if SizeCount==4 then fseek f (MeshOffset+4) #seek_set
  414. if SizeCount==5 then fseek f (MeshOffset+5) #seek_set
  415.     
  416. fseek f (0x18) #seek_cur
  417.     
  418. Pos00=ftell f
  419. Null00=readlong f
  420. if Null00==32 then fseek f Pos00 #seek_set     
  421. if Null00!=32 then (
  422. fseek f 0x0 #seek_cur    
  423. Pos01=ftell f
  424. Null01=readlong f
  425. if Null01==32 then fseek f Pos01 #seek_set     
  426. if Null01!=32 then (
  427. fseek f 0x0 #seek_cur    
  428. Pos02=ftell f
  429. Null02=readlong f
  430. if Null02==32 then fseek f Pos02 #seek_set     
  431. if Null02!=32 then (
  432. fseek f 0x0 #seek_cur    
  433. Pos03=ftell f
  434. Null03=readlong f
  435. if Null03==32 then fseek f Pos03 #seek_set     
  436. if Null03!=32 then fseek f 0x0 #seek_cur            
  437. )        
  438. )    
  439. )    
  440. Buffer=ftell f
  441. fseek f (0x54) #seek_cur
  442. FaceCount=readlong f
  443. fseek f (Buffer) #seek_set
  444. fseek f (0x78) #seek_cur
  445. Long032=readlong f
  446. if Long032==32 then (
  447. fseek f (0x74) #seek_cur
  448. PosLong=ftell f    
  449. Long032_01=readlong f    
  450. if Long032_01!=32 then fseek f (0x64) #seek_cur
  451. if Long032_01==32 then (
  452. fseek f (0x74) #seek_cur    
  453. PosLong01=ftell f    
  454. Long032_02=readlong f    
  455. if Long032_02!=32 then fseek f (0x64) #seek_cur
  456. if Long032_02==32 then (
  457. fseek f (0x74) #seek_cur        
  458. PosLong02=ftell f    
  459. Long032_03=readlong f    
  460. if Long032_03!=32 then fseek f (0x64) #seek_cur
  461. if Long032_03==32 then fseek f (0x0) #seek_cur    
  462. )    
  463. )
  464. )    
  465. if Long032!=32 then fseek f (0x64) #seek_cur
  466. Position=ftell f
  467. Print ("Position Start @ 0x"+((bit.intAsHex(ftell f))as string))    
  468. FaceStart=ftell f
  469. fseek f (Position-4) #seek_set
  470. OffsetMesh=readlong f
  471.  
  472. fseek f (OffsetMesh) #seek_set
  473. OffsetMeshInfo=readlong f
  474. fseek f (OffsetMeshInfo+60) #seek_set
  475.  
  476. Print ("Data Start @ 0x"+((bit.intAsHex(ftell f))as string))    
  477.     
  478. Mesh_Info2=#()
  479.  
  480. Print ("Data Start @ 0x"+((bit.intAsHex(ftell f))as string))        
  481. for i=1 to 6 do (
  482. getPos = ftell f + 96
  483. BufferName=readlong f
  484. Unk=readlong f
  485. DataOff2=readlong f    
  486. Null01=readlong f    
  487. DataSize2=readlong f    
  488. DataCount2=readlong f    
  489. fseek f getPos #seek_set    
  490. append Mesh_Info2 (Mesh_Info_Struct_2 DataOff2:DataOff2 DataSize2:DataSize2 DataCount2:DataCount2)        
  491. )
  492. WeightsInfo=ftell f
  493.  
  494. print Mesh_Info2
  495.  
  496. fseek f (Mesh_Info2[1].DataOff2) #seek_set
  497.  
  498. Print ("Vertex Start @ 0x"+((bit.intAsHex(ftell f))as string))    
  499.  
  500. vertArray2 = #()
  501. faceArray2 = #()
  502. UV_array2 = #()
  503. Weight_array2=#()    
  504. B1_array2=#()
  505. W1_array2=#()
  506.     
  507. for x = 1 to Mesh_Info2[1].DataCount2 do (
  508. getPos = ftell f + 12
  509. vx = ReadFloat f
  510. vy = ReadFloat f
  511. vz = ReadFloat f        
  512. fseek f getPos #seek_set
  513. append vertArray2 [vx,vy,vz]
  514. )    
  515.  
  516. Print ("Vertex End @ 0x"+((bit.intAsHex(ftell f))as string))    
  517.  
  518. fseek f (FaceStart) #seek_set    
  519.  
  520. Print ("Face Start @ 0x"+((bit.intAsHex(ftell f))as string))    
  521.  
  522. for x=1 to (FaceCount/3) do (    
  523. fa=readlong f +1
  524. fb=readlong f +1
  525. fc=readlong f +1
  526. append faceArray2 [fa,fb,fc]    
  527. )    
  528.  
  529. Print ("Face End @ 0x"+((bit.intAsHex(ftell f))as string))    
  530.  
  531. fseek f (Mesh_Info2[4].DataOff2) #seek_set
  532.     
  533. Print ("UV's Start @ 0x"+((bit.intAsHex(ftell f))as string))    
  534.  
  535. for x = 1 to Mesh_Info2[4].DataCount2 do (
  536. tu=readfloat f 
  537. tv=readfloat f 
  538. append UV_array2 [tu,tv,0]            
  539. )    
  540.  
  541. Print ("UV's End @ 0x"+((bit.intAsHex(ftell f))as string))    
  542.  
  543. if (Mesh_Info2[6].DataSize2)==8 then (    
  544.     
  545. fseek f (Mesh_Info2[6].DataOff2) #seek_set
  546.  
  547. Print ("BoneID's Start @ 0x"+((bit.intAsHex(ftell f))as string))        
  548.     
  549. for x = 1 to Mesh_Info2[1].DataCount2 do (
  550. bone1 = readshort f #unsigned    
  551. bone2 = readshort f #unsigned        
  552. bone3 = readshort f #unsigned    
  553. bone4 = readshort f #unsigned        
  554. append B1_array2 (Bone_Info_Struct Bone1:Bone1 Bone2:Bone2 Bone3:Bone3 Bone4:Bone4)        
  555. )    
  556. )
  557.     
  558. if (Mesh_Info2[6].DataSize2)==16 then (    
  559.     
  560. fseek f (Mesh_Info2[5].DataOff2) #seek_set
  561.     
  562. Print ("BoneID's Start @ 0x"+((bit.intAsHex(ftell f))as string))        
  563.     
  564. for x = 1 to Mesh_Info2[1].DataCount2 do (
  565. bone1 = readshort f #unsigned    
  566. bone2 = readshort f #unsigned        
  567. bone3 = readshort f #unsigned    
  568. bone4 = readshort f #unsigned        
  569. append B1_array2 (Bone_Info_Struct Bone1:Bone1 Bone2:Bone2 Bone3:Bone3 Bone4:Bone4)        
  570. )    
  571. )
  572.  
  573. if (Mesh_Info2[6].DataSize2)==8 then (    
  574. fseek f (WeightsInfo) #seek_set
  575. Print ("Weights Info Start @ 0x"+((bit.intAsHex(ftell f))as string))        
  576. WBufferName=readlong f
  577. fseek f 0xC #seek_cur
  578. WDataOff=readlong f    
  579. Null02=readlong f    
  580. Null03=readlong f        
  581. WDataSize=readlong f    
  582. WDataCount=readlong f    
  583.  
  584. fseek f (WDataOff) #seek_set
  585.     
  586. Print ("Weights Start @ 0x"+((bit.intAsHex(ftell f))as string))    
  587.  
  588. for x = 1 to Mesh_Info2[1].DataCount2 do (
  589. weight1 = ReadFloat f
  590. weight2 = ReadFloat f
  591. weight3 = ReadFloat f
  592. weight4 = ReadFloat f        
  593. append W1_array2 (Weight_Info_Struct Weight1:Weight1 Weight2:Weight2 Weight3:Weight3 Weight4:Weight4)        
  594. )    
  595.  
  596. for b = 1 to W1_array2.count Do (
  597. w = (weight_data boneids:#() weights:#())
  598. maxweight = 0
  599. if(W1_array2[b].Weight1 != 0) then
  600.    maxweight = maxweight + W1_array2[b].Weight1
  601. if(W1_array2[b].Weight2 != 0) then
  602.    maxweight = maxweight + W1_array2[b].Weight2
  603. if(W1_array2[b].Weight3 != 0) then
  604.    maxweight = maxweight + W1_array2[b].Weight3
  605. if(W1_array2[b].Weight4 != 0) then
  606.    maxweight = maxweight + W1_array2[b].Weight4
  607.  
  608. if(maxweight != 0) then
  609.    (
  610.       if(W1_array2[b].Weight1 != 0) then
  611.       (
  612.          w1 = W1_array2[b].Weight1 as float
  613.          append w.boneids (B1_array2[b].Bone1 + 1)
  614.          append w.weights (w1)
  615.       )
  616.       if(W1_array2[b].Weight2 != 0) then
  617.       (
  618.          w2 = W1_array2[b].Weight2 as float
  619.          append w.boneids (B1_array2[b].Bone2 + 1)
  620.          append w.weights (w2)
  621.       )
  622.       if(W1_array2[b].Weight3 != 0) then
  623.       (
  624.          w3 = W1_array2[b].Weight3 as float
  625.          append w.boneids (B1_array2[b].Bone3 + 1)
  626.          append w.weights (w3)
  627.       )
  628.       if(W1_array2[b].Weight4 != 0) then
  629.       (
  630.          w4 = W1_array2[b].Weight4 as float
  631.          append w.boneids (B1_array2[b].Bone4 + 1)
  632.          append w.weights (w4)
  633.       )      
  634.    )
  635. append Weight_array2 w
  636. )    
  637. )    
  638.  
  639. if (Mesh_Info2[6].DataSize2)==16 then (
  640.     
  641. fseek f (Mesh_Info2[6].DataOff2) #seek_set
  642.     
  643. Print ("Weights Start @ 0x"+((bit.intAsHex(ftell f))as string))    
  644.  
  645. for x = 1 to Mesh_Info2[4].DataCount2 do (
  646. weight1 = ReadFloat f
  647. weight2 = ReadFloat f
  648. weight3 = ReadFloat f
  649. weight4 = ReadFloat f        
  650. append W1_array2 (Weight_Info_Struct Weight1:Weight1 Weight2:Weight2 Weight3:Weight3 Weight4:Weight4)        
  651. )    
  652.  
  653. for b = 1 to W1_array2.count Do (
  654. w = (weight_data boneids:#() weights:#())
  655. maxweight = 0
  656. if(W1_array2[b].Weight1 != 0) then
  657.    maxweight = maxweight + W1_array2[b].Weight1
  658. if(W1_array2[b].Weight2 != 0) then
  659.    maxweight = maxweight + W1_array2[b].Weight2
  660. if(W1_array2[b].Weight3 != 0) then
  661.    maxweight = maxweight + W1_array2[b].Weight3
  662. if(W1_array2[b].Weight4 != 0) then
  663.    maxweight = maxweight + W1_array2[b].Weight4
  664.  
  665. if(maxweight != 0) then
  666.    (
  667.       if(W1_array2[b].Weight1 != 0) then
  668.       (
  669.          w1 = W1_array2[b].Weight1 as float
  670.          append w.boneids (B1_array2[b].Bone1 + 1)
  671.          append w.weights (w1)
  672.       )
  673.       if(W1_array2[b].Weight2 != 0) then
  674.       (
  675.          w2 = W1_array2[b].Weight2 as float
  676.          append w.boneids (B1_array2[b].Bone2 + 1)
  677.          append w.weights (w2)
  678.       )
  679.       if(W1_array2[b].Weight3 != 0) then
  680.       (
  681.          w3 = W1_array2[b].Weight3 as float
  682.          append w.boneids (B1_array2[b].Bone3 + 1)
  683.          append w.weights (w3)
  684.       )
  685.       if(W1_array2[b].Weight4 != 0) then
  686.       (
  687.          w4 = W1_array2[b].Weight4 as float
  688.          append w.boneids (B1_array2[b].Bone4 + 1)
  689.          append w.weights (w4)
  690.       )      
  691.    )
  692. append Weight_array2 w
  693. )
  694. )
  695.  
  696. msh = mesh vertices:vertArray2 faces:faceArray2
  697. msh.name=("Model_Cloth"+i as string)
  698. msh.numTVerts = UV_array2.count
  699. buildTVFaces msh
  700. for j = 1 to UV_array2.count do setTVert msh j UV_array2[j]
  701. for j = 1 to faceArray2.count do setTVFace msh j faceArray2[j]
  702. msh.displayByLayer = false
  703. msh.backfacecull = false
  704. msh.wirecolor = (color 230 200 210)
  705.  
  706. max modify mode
  707. select msh
  708. skinMod = skin ()
  709. addModifier msh skinMod
  710. for i = 1 to BNArr.count do
  711. (
  712.     maxbone = BNArr[i]
  713.     if i != BNArr.count then 
  714.         skinOps.addBone skinMod maxbone 0
  715.     else
  716.         skinOps.addBone skinMod maxbone 1
  717. )
  718. modPanel.setCurrentObject skinMod
  719. for i = 1 to vertArray2.count do (
  720.    w = Weight_array2[i]
  721.    bi = #() --bone index array
  722.    wv = #() --weight value array
  723.    
  724.    for j = 1 to w.boneids.count do
  725.    (
  726.       boneid = w.boneids[j]
  727.       weight = w.weights[j]
  728.       append bi boneid
  729.       append wv weight
  730.    )   
  731.    
  732.    skinOps.ReplaceVertexWeights skinMod i bi wv
  733. )
  734. )
  735. )
  736.  
  737. fclose f