home *** CD-ROM | disk | FTP | other *** search
/ Xentax forum attachments archive / xentax.7z / 8654 / LOTF_Scripts.7z / LOTF_Apex.ms next >
Encoding:
Text File  |  2015-02-13  |  26.8 KB  |  911 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:"LOTF Models (*.*)|*.*" \
  6. historyCategory:"LOTFObjectPresets"
  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.  
  183. if SizeCount!=0 then (
  184.     
  185. if SizeCount==2 then fseek f (Offset-1) #seek_set
  186. if SizeCount==3 then fseek f (Offset) #seek_set
  187. if SizeCount==4 then fseek f (Offset+1) #seek_set
  188. if SizeCount==5 then fseek f (Offset+2) #seek_set    
  189. Count=readBELong f        
  190.  
  191. Print ("Start 01@ 0x"+((bit.intAsHex(ftell f))as string))            
  192. fseek f (Count-9) #seek_cur    
  193. BOffset=readlong f
  194. fseek f (0xB4) #seek_cur        
  195. Print ("Start 02@ 0x"+((bit.intAsHex(ftell f))as string))            
  196. BoneCount=readlong f        
  197.     
  198. fseek f (BOffset) #seek_set
  199.  
  200. if SizeCount==2 then fseek f (0x12) #seek_cur
  201. if SizeCount==3 then fseek f (0x13) #seek_cur    
  202. if SizeCount==4 then fseek f (0x14) #seek_cur
  203. if SizeCount==5 then fseek f (0x15) #seek_cur    
  204.         
  205. DOffset=readlong f
  206. Print ("Start 03@ 0x"+((bit.intAsHex(ftell f))as string))    
  207.     
  208. fseek f (0xC) #seek_cur    
  209.  
  210. Print ("Bone Start @ 0x"+((bit.intAsHex(ftell f))as string))    
  211.         
  212. for i=1 to BoneCount do (
  213. getPos = ftell f + 88
  214. BoneId=readlong f
  215. BoneChild=readlong f
  216. Unk01=readlong f
  217. Unk02=readlong f    
  218. BoneParent=readlong f+1    
  219. c11=readfloat f;c12=readfloat f;c13=readfloat f;c14=readfloat f
  220. c21=readfloat f;c22=readfloat f;c23=readfloat f;c24=readfloat f
  221. c31=readfloat f;c32=readfloat f;c33=readfloat f;c34=readfloat f
  222. Null=readlong f;BoneNameOff=readlong f    
  223. fseek f (0xC) #seek_cur        
  224. fseek f getPos #seek_set    
  225. Position=ftell f
  226. if SizeCount==2 then fseek f (BoneNameOff+1) #seek_set    
  227. if SizeCount==3 then fseek f (BoneNameOff+2) #seek_set
  228. if SizeCount==4 then fseek f (BoneNameOff+3) #seek_set    
  229. if SizeCount==5 then fseek f (BoneNameOff+4) #seek_set        
  230. BoneName=readstring f    
  231. append BoneNameArray    BoneName
  232. fseek f Position #seek_set    
  233.         
  234. tfm = (quat c24 c23 c22 c21) as matrix3
  235. tfm.row4 = [c32,c33,c34]
  236.  
  237. newBone = bonesys.createbone    \
  238.                                       tfm.row4      \
  239.                                       (tfm.row4 + 0.01 * (normalize tfm.row1)) \
  240.                                       (normalize tfm.row3)
  241.                             newBone.width  = 0.01
  242.                             newBone.height = 0.01
  243.                             newBone.name = BoneName                                  
  244.                             newBone.transform = tfm
  245.                             newBone.setBoneEnable false 0
  246.                             newBone.wirecolor = yellow
  247.                             newbone.showlinks = true
  248.                             newBone.pos.controller      = TCB_position ()
  249.                             newBone.rotation.controller = TCB_rotation () 
  250. if BoneParent!=0 then
  251. newBone.parent=BNArr[(BoneParent)]                                              
  252. append BNArr newBone  
  253. )    
  254.  
  255. Print ("Bone End @ 0x"+((bit.intAsHex(ftell f))as string))        
  256.  
  257. if SizeCount==2 then fseek f (DOffset-1) #seek_set
  258. if SizeCount==3 then fseek f (DOffset) #seek_set    
  259. if SizeCount==4 then fseek f (DOffset+1) #seek_set
  260. if SizeCount==5 then fseek f (DOffset+2) #seek_set    
  261.     
  262. DCount=readBELong f    
  263.     
  264. Print ("Start 04@ 0x"+((bit.intAsHex(ftell f))as string))            
  265. fseek f (DCount-9) #seek_cur    
  266. DataOffset=readlong f
  267. Print ("Start 05@ 0x"+((bit.intAsHex(ftell f))as string))        
  268. fseek f (0x4C) #seek_cur
  269. VertCount=readlong f
  270. FaceCount=readlong f
  271. Unk=readlong f
  272.  
  273. Mesh_Info=#()
  274.  
  275. Print ("Data Start @ 0x"+((bit.intAsHex(ftell f))as string))        
  276. for i=1 to 7 do (
  277. getPos = ftell f + 24
  278. Null01=readlong f
  279. DataOff=readlong f
  280. Null02=readlong f    
  281. Null03=readlong f        
  282. DataSize=readlong f    
  283. DataCount=readlong f    
  284. fseek f getPos #seek_set        
  285. append Mesh_Info (Mesh_Info_Struct DataOff:DataOff DataSize:DataSize DataCount:DataCount)    
  286. )
  287.  
  288. fseek f (0xC) #seek_cur
  289. append FaceOff (readlong f)    
  290. print Mesh_Info
  291. )
  292.  
  293. if SizeCount==0 then fseek f (Mesh_Info[1].DataOff) #seek_set
  294. if SizeCount==2 then fseek f (Mesh_Info[1].DataOff+2) #seek_set
  295. if SizeCount==3 then fseek f (Mesh_Info[1].DataOff+3) #seek_set    
  296. if SizeCount==4 then fseek f (Mesh_Info[1].DataOff+4) #seek_set
  297. if SizeCount==5 then fseek f (Mesh_Info[1].DataOff+5) #seek_set
  298.  
  299. Print ("Vertex Start @ 0x"+((bit.intAsHex(ftell f))as string))    
  300.  
  301. vertArray = #()
  302. faceArray = #()
  303. UV_array = #()
  304. Weight_array=#()    
  305. B1_array=#()
  306. W1_array=#()
  307.     
  308. for x = 1 to VertCount do (
  309. getPos = ftell f + 12
  310. vx = ReadFloat f
  311. vy = ReadFloat f
  312. vz = ReadFloat f    
  313. append vertArray ([vx,vy,vz])    
  314. fseek f getPos #seek_set        
  315. )    
  316.  
  317. if SizeCount==0 then fseek f (Mesh_Info[2].DataOff) #seek_set
  318. if SizeCount==2 then fseek f (Mesh_Info[2].DataOff+2) #seek_set
  319. if SizeCount==3 then fseek f (Mesh_Info[2].DataOff+3) #seek_set    
  320. if SizeCount==4 then fseek f (Mesh_Info[2].DataOff+4) #seek_set
  321. if SizeCount==5 then fseek f (Mesh_Info[2].DataOff+5) #seek_set
  322.  
  323. Print ("Normal Start @ 0x"+((bit.intAsHex(ftell f))as string))    
  324.  
  325. for x = 1 to VertCount do (
  326. getPos = ftell f + 12
  327. fseek f getPos #seek_set            
  328. )    
  329.  
  330. if SizeCount==0 then fseek f (Mesh_Info[3].DataOff) #seek_set
  331. if SizeCount==2 then fseek f (Mesh_Info[3].DataOff+2) #seek_set
  332. if SizeCount==3 then fseek f (Mesh_Info[3].DataOff+3) #seek_set    
  333. if SizeCount==4 then fseek f (Mesh_Info[3].DataOff+4) #seek_set
  334. if SizeCount==5 then fseek f (Mesh_Info[3].DataOff+5) #seek_set
  335.  
  336. Print ("Tangent Start @ 0x"+((bit.intAsHex(ftell f))as string))    
  337.  
  338. for x = 1 to VertCount do (
  339. getPos = ftell f + 12    
  340. fseek f getPos #seek_set        
  341. )    
  342.  
  343. if SizeCount==0 then fseek f (Mesh_Info[4].DataOff) #seek_set
  344. if SizeCount==2 then fseek f (Mesh_Info[4].DataOff+2) #seek_set
  345. if SizeCount==3 then fseek f (Mesh_Info[4].DataOff+3) #seek_set    
  346. if SizeCount==4 then fseek f (Mesh_Info[4].DataOff+4) #seek_set
  347. if SizeCount==5 then fseek f (Mesh_Info[4].DataOff+5) #seek_set
  348.  
  349. Print ("UV's Start @ 0x"+((bit.intAsHex(ftell f))as string))    
  350.  
  351. for x = 1 to VertCount do (
  352. tu=readBEword f 
  353. tv=readBEword f 
  354. fseek f (0x8) #seek_set        
  355. append UV_array ([tu,tv,0]/65535)        
  356. )    
  357.  
  358. Print ("UV's End @ 0x"+((bit.intAsHex(ftell f))as string))    
  359.  
  360. if SizeCount==0 then fseek f (Mesh_Info[5].DataOff) #seek_set    
  361. if SizeCount==2 then fseek f (Mesh_Info[5].DataOff+2) #seek_set
  362. if SizeCount==3 then fseek f (Mesh_Info[5].DataOff+3) #seek_set    
  363. if SizeCount==4 then fseek f (Mesh_Info[5].DataOff+4) #seek_set
  364. if SizeCount==5 then fseek f (Mesh_Info[5].DataOff+5) #seek_set    
  365.  
  366. Print ("BoneID's Start @ 0x"+((bit.intAsHex(ftell f))as string))        
  367.     
  368. for x = 1 to VertCount do (
  369. bone1 = readshort f #unsigned    
  370. bone2 = readshort f #unsigned        
  371. bone3 = readshort f #unsigned    
  372. bone4 = readshort f #unsigned        
  373. append B1_array (Bone_Info_Struct Bone1:Bone1 Bone2:Bone2 Bone3:Bone3 Bone4:Bone4)        
  374. )    
  375.  
  376. if SizeCount==0 then fseek f (Mesh_Info[6].DataOff) #seek_set
  377. if SizeCount==2 then fseek f (Mesh_Info[6].DataOff+2) #seek_set
  378. if SizeCount==3 then fseek f (Mesh_Info[6].DataOff+3) #seek_set    
  379. if SizeCount==4 then fseek f (Mesh_Info[6].DataOff+4) #seek_set
  380. if SizeCount==5 then fseek f (Mesh_Info[6].DataOff+5) #seek_set
  381.  
  382. Print ("Weights Start @ 0x"+((bit.intAsHex(ftell f))as string))    
  383.  
  384. for x = 1 to VertCount do (
  385. weight1 = ReadFloat f
  386. weight2 = ReadFloat f
  387. weight3 = ReadFloat f
  388. weight4 = ReadFloat f        
  389. append W1_array (Weight_Info_Struct Weight1:Weight1 Weight2:Weight2 Weight3:Weight3 Weight4:Weight4)        
  390. )    
  391.  
  392. for b = 1 to W1_array.count Do (
  393. w = (weight_data boneids:#() weights:#())
  394. maxweight = 0
  395. if(W1_array[b].Weight1 != 0) then
  396.    maxweight = maxweight + W1_array[b].Weight1
  397. if(W1_array[b].Weight2 != 0) then
  398.    maxweight = maxweight + W1_array[b].Weight2
  399. if(W1_array[b].Weight3 != 0) then
  400.    maxweight = maxweight + W1_array[b].Weight3
  401. if(W1_array[b].Weight4 != 0) then
  402.    maxweight = maxweight + W1_array[b].Weight4
  403.  
  404. if(maxweight != 0) then
  405.    (
  406.       if(W1_array[b].Weight1 != 0) then
  407.       (
  408.          w1 = W1_array[b].Weight1 as float
  409.          append w.boneids (B1_array[b].Bone1 + 1)
  410.          append w.weights (w1)
  411.       )
  412.       if(W1_array[b].Weight2 != 0) then
  413.       (
  414.          w2 = W1_array[b].Weight2 as float
  415.          append w.boneids (B1_array[b].Bone2 + 1)
  416.          append w.weights (w2)
  417.       )
  418.       if(W1_array[b].Weight3 != 0) then
  419.       (
  420.          w3 = W1_array[b].Weight3 as float
  421.          append w.boneids (B1_array[b].Bone3 + 1)
  422.          append w.weights (w3)
  423.       )
  424.       if(W1_array[b].Weight4 != 0) then
  425.       (
  426.          w4 = W1_array[b].Weight4 as float
  427.          append w.boneids (B1_array[b].Bone4 + 1)
  428.          append w.weights (w4)
  429.       )      
  430.    )
  431. append Weight_array w
  432. )
  433.  
  434. Print ("!!!!! Start @ 0x"+((bit.intAsHex(ftell f))as string))    
  435.  
  436. if SizeCount==0 then fseek f (Mesh_Info[7].DataOff) #seek_set    
  437. if SizeCount==2 then fseek f (Mesh_Info[7].DataOff+2) #seek_set
  438. if SizeCount==3 then fseek f (Mesh_Info[7].DataOff+3) #seek_set    
  439. if SizeCount==4 then fseek f (Mesh_Info[7].DataOff+4) #seek_set
  440. if SizeCount==5 then fseek f (Mesh_Info[7].DataOff+5) #seek_set    
  441.     
  442. for x = 1 to Mesh_Info[7].DataCount do (
  443. id=readbyte f
  444. )    
  445.  
  446. Print ("!!!!! End @ 0x"+((bit.intAsHex(ftell f))as string))    
  447.  
  448. if SizeCount==0 then fseek f (FaceOff[1]) #seek_set    
  449. if SizeCount==2 then fseek f (FaceOff[1]+2) #seek_set
  450. if SizeCount==3 then fseek f (FaceOff[1]+3) #seek_set    
  451. if SizeCount==4 then fseek f (FaceOff[1]+4) #seek_set    
  452. if SizeCount==5 then fseek f (FaceOff[1]+5) #seek_set        
  453.  
  454. Print ("Face Start @ 0x"+((bit.intAsHex(ftell f))as string))    
  455.  
  456. for x=1 to (FaceCount/3) do (    
  457. fa=readlong f +1
  458. fb=readlong f +1
  459. fc=readlong f +1
  460. append faceArray [fa,fb,fc]    
  461. )    
  462.  
  463. Print ("Face End @ 0x"+((bit.intAsHex(ftell f))as string))    
  464.  
  465. msh = mesh vertices:vertArray faces:faceArray
  466. msh.numTVerts = UV_array.count
  467. buildTVFaces msh
  468. for j = 1 to UV_array.count do setTVert msh j UV_array[j]
  469. for j = 1 to faceArray.count do setTVFace msh j faceArray[j]
  470. msh.displayByLayer = false
  471. msh.backfacecull = false
  472. msh.wirecolor = (color 230 200 210)
  473.  
  474. max modify mode
  475. select msh
  476. skinMod = skin ()
  477. addModifier msh skinMod
  478. for i = 1 to BNArr.count do
  479. (
  480.     maxbone = BNArr[i]
  481.     if i != BNArr.count then 
  482.         skinOps.addBone skinMod maxbone 0
  483.     else
  484.         skinOps.addBone skinMod maxbone 1
  485. )
  486. modPanel.setCurrentObject skinMod
  487. for i = 1 to vertArray.count do (
  488.    w = Weight_array[i]
  489.    bi = #() --bone index array
  490.    wv = #() --weight value array
  491.    
  492.    for j = 1 to w.boneids.count do
  493.    (
  494.       boneid = w.boneids[j]
  495.       weight = w.weights[j]
  496.       append bi boneid
  497.       append wv weight
  498.    )   
  499.    
  500.    skinOps.ReplaceVertexWeights skinMod i bi wv
  501. )    
  502. )
  503.  
  504. Pos00=ftell f
  505. Null00=readlong f
  506. if Null00!=0 then fseek f Pos00 #seek_set     
  507. if Null00==0 then (
  508. fseek f 0x0 #seek_cur    
  509. Pos01=ftell f
  510. Null01=readlong f
  511. if Null01!=0 then fseek f Pos01 #seek_set     
  512. if Null01==0 then (
  513. fseek f 0x0 #seek_cur    
  514. Pos02=ftell f
  515. Null02=readlong f
  516. if Null02!=0 then fseek f Pos02 #seek_set     
  517. if Null02==0 then (
  518. fseek f 0x0 #seek_cur    
  519. Pos03=ftell f
  520. Null03=readlong f
  521. if Null03!=0 then fseek f Pos03 #seek_set     
  522. if Null03==0 then fseek f 0x0 #seek_cur            
  523. )        
  524. )    
  525. )    
  526.  
  527. SimMeshEnd=ftell f
  528. if Magic==1566333786 then (
  529. Print ("SimMeshEnd @ 0x"+((bit.intAsHex(ftell f))as string))    
  530. )
  531.  
  532. fseek f (0x0) #seek_end
  533. EndSize=ftell f
  534. fseek f (0x0) #seek_set
  535. Magic=readlong f
  536. if Magic!=1566333786 then fclose f
  537. if Magic==1566333786 then (
  538. for i=1 to 1 do (    
  539. fseek f (0x8) #seek_cur
  540. MeshCount=readBELong f
  541. FileSize=readBELong f
  542. DataStart=readBELong f
  543. DataEnd=readBELong f
  544. DataSize=readBELong f
  545. SizeCount=(EndSize-FileSize)
  546. print SizeCount
  547.     
  548. fseek f (SimMeshEnd) #seek_set
  549. fseek f (0xE8) #seek_cur
  550. MeshOffset=readlong f    
  551. print MeshOffset
  552.     
  553. if SizeCount==0 then fseek f (MeshOffset) #seek_set
  554. if SizeCount==2 then fseek f (MeshOffset+2) #seek_set
  555. if SizeCount==3 then fseek f (MeshOffset+3) #seek_set    
  556. if SizeCount==4 then fseek f (MeshOffset+4) #seek_set
  557. if SizeCount==5 then fseek f (MeshOffset+5) #seek_set
  558.     
  559. fseek f (0x18) #seek_cur
  560.     
  561. Pos00=ftell f
  562. Null00=readlong f
  563. if Null00==48 then fseek f Pos00 #seek_set     
  564. if Null00!=48 then (
  565. fseek f 0x0 #seek_cur    
  566. Pos01=ftell f
  567. Null01=readlong f
  568. if Null01==48 then fseek f Pos01 #seek_set     
  569. if Null01!=48 then (
  570. fseek f 0x0 #seek_cur    
  571. Pos02=ftell f
  572. Null02=readlong f
  573. if Null02==48 then fseek f Pos02 #seek_set     
  574. if Null02!=48 then (
  575. fseek f 0x0 #seek_cur    
  576. Pos03=ftell f
  577. Null03=readlong f
  578. if Null03==48 then fseek f Pos03 #seek_set     
  579. if Null03!=48 then fseek f 0x0 #seek_cur            
  580. )        
  581. )    
  582. )    
  583. Buffer=ftell f
  584. fseek f (0x90) #seek_cur
  585. FaceCount=readlong f
  586. fseek f (Buffer) #seek_set
  587. fseek f (0xE0) #seek_cur
  588. Long048=readlong f
  589. if Long048==48 then (
  590. fseek f (0xDC) #seek_cur
  591. PosLong=ftell f    
  592. Long048_01=readlong f    
  593. if Long048_01!=48 then fseek f (0x94) #seek_cur
  594. if Long048_01==48 then (
  595. fseek f (0xDC) #seek_cur    
  596. PosLong01=ftell f    
  597. Long048_02=readlong f    
  598. if Long048_02!=48 then fseek f (0x94) #seek_cur
  599. if Long048_02==48 then (
  600. fseek f (0xDC) #seek_cur        
  601. PosLong02=ftell f    
  602. Long048_03=readlong f    
  603. if Long048_03!=48 then fseek f (0x94) #seek_cur
  604. if Long048_03==48 then fseek f (0x0) #seek_cur    
  605. )    
  606. )
  607. )    
  608. if Long048!=48 then fseek f (0x94) #seek_cur
  609. Position=ftell f
  610. Print ("Position Start @ 0x"+((bit.intAsHex(ftell f))as string))    
  611. fseek f (0x18) #seek_cur    
  612. FaceStart=ftell f
  613. fseek f (Position) #seek_set
  614. OffsetMesh=readlong f
  615.  
  616. if SizeCount==0 then fseek f (OffsetMesh) #seek_set
  617. if SizeCount==2 then fseek f (OffsetMesh+2) #seek_set
  618. if SizeCount==3 then fseek f (OffsetMesh+3) #seek_set    
  619. if SizeCount==4 then fseek f (OffsetMesh+4) #seek_set
  620. if SizeCount==5 then fseek f (OffsetMesh+5) #seek_set
  621. OffsetMeshInfo=readlong f
  622. if SizeCount==0 then fseek f (OffsetMeshInfo+104) #seek_set
  623. if SizeCount==2 then fseek f (OffsetMeshInfo+106) #seek_set
  624. if SizeCount==3 then fseek f (OffsetMeshInfo+107) #seek_set    
  625. if SizeCount==4 then fseek f (OffsetMeshInfo+108) #seek_set
  626. if SizeCount==5 then fseek f (OffsetMeshInfo+109) #seek_set
  627.  
  628. Print ("Data Start @ 0x"+((bit.intAsHex(ftell f))as string))    
  629.     
  630. Mesh_Info2=#()
  631.  
  632. Print ("Data Start @ 0x"+((bit.intAsHex(ftell f))as string))        
  633. for i=1 to 6 do (
  634. getPos = ftell f + 144
  635. BufferName=readlong f
  636. fseek f 0xC #seek_cur
  637. DataOff2=readlong f    
  638. Null02=readlong f    
  639. Null03=readlong f        
  640. DataSize2=readlong f    
  641. DataCount2=readlong f    
  642. fseek f getPos #seek_set    
  643. append Mesh_Info2 (Mesh_Info_Struct_2 DataOff2:DataOff2 DataSize2:DataSize2 DataCount2:DataCount2)        
  644. )
  645. WeightsInfo=ftell f
  646.  
  647. print Mesh_Info2
  648.  
  649. if SizeCount==0 then fseek f (Mesh_Info2[1].DataOff2) #seek_set
  650. if SizeCount==2 then fseek f (Mesh_Info2[1].DataOff2+2) #seek_set
  651. if SizeCount==3 then fseek f (Mesh_Info2[1].DataOff2+3) #seek_set    
  652. if SizeCount==4 then fseek f (Mesh_Info2[1].DataOff2+4) #seek_set
  653. if SizeCount==5 then fseek f (Mesh_Info2[1].DataOff2+5) #seek_set
  654.  
  655. Print ("Vertex Start @ 0x"+((bit.intAsHex(ftell f))as string))    
  656.  
  657. vertArray2 = #()
  658. faceArray2 = #()
  659. UV_array2 = #()
  660. Weight_array2=#()    
  661. B1_array2=#()
  662. W1_array2=#()
  663.     
  664. for x = 1 to Mesh_Info2[1].DataCount2 do (
  665. getPos = ftell f + 12
  666. vx = ReadFloat f
  667. vy = ReadFloat f
  668. vz = ReadFloat f        
  669. fseek f getPos #seek_set
  670. append vertArray2 [vx,vy,vz]
  671. )    
  672.  
  673. Print ("Vertex End @ 0x"+((bit.intAsHex(ftell f))as string))    
  674.  
  675. fseek f (FaceStart) #seek_set    
  676.  
  677. Print ("Face Start @ 0x"+((bit.intAsHex(ftell f))as string))    
  678.  
  679. for x=1 to (FaceCount/3) do (    
  680. fa=readlong f +1
  681. fb=readlong f +1
  682. fc=readlong f +1
  683. append faceArray2 [fa,fb,fc]    
  684. )    
  685.  
  686. Print ("Face End @ 0x"+((bit.intAsHex(ftell f))as string))    
  687.  
  688. if SizeCount==0 then fseek f (Mesh_Info2[4].DataOff2) #seek_set
  689. if SizeCount==2 then fseek f (Mesh_Info2[4].DataOff2+2) #seek_set
  690. if SizeCount==3 then fseek f (Mesh_Info2[4].DataOff2+3) #seek_set    
  691. if SizeCount==4 then fseek f (Mesh_Info2[4].DataOff2+4) #seek_set
  692. if SizeCount==5 then fseek f (Mesh_Info2[4].DataOff2+5) #seek_set
  693.     
  694. Print ("UV's Start @ 0x"+((bit.intAsHex(ftell f))as string))    
  695.  
  696. for x = 1 to Mesh_Info2[4].DataCount2 do (
  697. tu=readfloat f 
  698. tv=readfloat f*-1 
  699. append UV_array2 [tu,tv,0]            
  700. )    
  701.  
  702. Print ("UV's End @ 0x"+((bit.intAsHex(ftell f))as string))    
  703.  
  704. if (Mesh_Info2[6].DataSize2)==8 then (    
  705. if SizeCount==0 then fseek f (Mesh_Info2[6].DataOff2) #seek_set
  706. if SizeCount==2 then fseek f (Mesh_Info2[6].DataOff2+2) #seek_set
  707. if SizeCount==3 then fseek f (Mesh_Info2[6].DataOff2+3) #seek_set    
  708. if SizeCount==4 then fseek f (Mesh_Info2[6].DataOff2+4) #seek_set    
  709. if SizeCount==5 then fseek f (Mesh_Info2[6].DataOff2+5) #seek_set    
  710.     
  711. Print ("BoneID's Start @ 0x"+((bit.intAsHex(ftell f))as string))        
  712.     
  713. for x = 1 to Mesh_Info2[1].DataCount2 do (
  714. bone1 = readshort f #unsigned    
  715. bone2 = readshort f #unsigned        
  716. bone3 = readshort f #unsigned    
  717. bone4 = readshort f #unsigned        
  718. append B1_array2 (Bone_Info_Struct Bone1:Bone1 Bone2:Bone2 Bone3:Bone3 Bone4:Bone4)        
  719. )    
  720. )
  721.     
  722. if (Mesh_Info2[6].DataSize2)==16 then (    
  723. if SizeCount==0 then fseek f (Mesh_Info2[5].DataOff2) #seek_set
  724. if SizeCount==2 then fseek f (Mesh_Info2[5].DataOff2+2) #seek_set
  725. if SizeCount==3 then fseek f (Mesh_Info2[5].DataOff2+3) #seek_set    
  726. if SizeCount==4 then fseek f (Mesh_Info2[5].DataOff2+4) #seek_set    
  727. if SizeCount==5 then fseek f (Mesh_Info2[5].DataOff2+5) #seek_set    
  728.     
  729. Print ("BoneID's Start @ 0x"+((bit.intAsHex(ftell f))as string))        
  730.     
  731. for x = 1 to Mesh_Info2[1].DataCount2 do (
  732. bone1 = readshort f #unsigned    
  733. bone2 = readshort f #unsigned        
  734. bone3 = readshort f #unsigned    
  735. bone4 = readshort f #unsigned        
  736. append B1_array2 (Bone_Info_Struct Bone1:Bone1 Bone2:Bone2 Bone3:Bone3 Bone4:Bone4)        
  737. )    
  738. )
  739.  
  740. if (Mesh_Info2[6].DataSize2)==8 then (    
  741. fseek f (WeightsInfo) #seek_set
  742. Print ("Weights Info Start @ 0x"+((bit.intAsHex(ftell f))as string))        
  743. WBufferName=readlong f
  744. fseek f 0xC #seek_cur
  745. WDataOff=readlong f    
  746. Null02=readlong f    
  747. Null03=readlong f        
  748. WDataSize=readlong f    
  749. WDataCount=readlong f    
  750.  
  751. if SizeCount==0 then fseek f (WDataOff) #seek_set
  752. if SizeCount==2 then fseek f (WDataOff+2) #seek_set
  753. if SizeCount==3 then fseek f (WDataOff+3) #seek_set    
  754. if SizeCount==4 then fseek f (WDataOff+4) #seek_set    
  755. if SizeCount==5 then fseek f (WDataOff+5) #seek_set    
  756.     
  757. Print ("Weights Start @ 0x"+((bit.intAsHex(ftell f))as string))    
  758.  
  759. for x = 1 to Mesh_Info2[1].DataCount2 do (
  760. weight1 = ReadFloat f
  761. weight2 = ReadFloat f
  762. weight3 = ReadFloat f
  763. weight4 = ReadFloat f        
  764. append W1_array2 (Weight_Info_Struct Weight1:Weight1 Weight2:Weight2 Weight3:Weight3 Weight4:Weight4)        
  765. )    
  766.  
  767. for b = 1 to W1_array2.count Do (
  768. w = (weight_data boneids:#() weights:#())
  769. maxweight = 0
  770. if(W1_array2[b].Weight1 != 0) then
  771.    maxweight = maxweight + W1_array2[b].Weight1
  772. if(W1_array2[b].Weight2 != 0) then
  773.    maxweight = maxweight + W1_array2[b].Weight2
  774. if(W1_array2[b].Weight3 != 0) then
  775.    maxweight = maxweight + W1_array2[b].Weight3
  776. if(W1_array2[b].Weight4 != 0) then
  777.    maxweight = maxweight + W1_array2[b].Weight4
  778.  
  779. if(maxweight != 0) then
  780.    (
  781.       if(W1_array2[b].Weight1 != 0) then
  782.       (
  783.          w1 = W1_array2[b].Weight1 as float
  784.          append w.boneids (B1_array2[b].Bone1 + 1)
  785.          append w.weights (w1)
  786.       )
  787.       if(W1_array2[b].Weight2 != 0) then
  788.       (
  789.          w2 = W1_array2[b].Weight2 as float
  790.          append w.boneids (B1_array2[b].Bone2 + 1)
  791.          append w.weights (w2)
  792.       )
  793.       if(W1_array2[b].Weight3 != 0) then
  794.       (
  795.          w3 = W1_array2[b].Weight3 as float
  796.          append w.boneids (B1_array2[b].Bone3 + 1)
  797.          append w.weights (w3)
  798.       )
  799.       if(W1_array2[b].Weight4 != 0) then
  800.       (
  801.          w4 = W1_array2[b].Weight4 as float
  802.          append w.boneids (B1_array2[b].Bone4 + 1)
  803.          append w.weights (w4)
  804.       )      
  805.    )
  806. append Weight_array2 w
  807. )    
  808. )    
  809.  
  810. if (Mesh_Info2[6].DataSize2)==16 then (
  811. if SizeCount==0 then fseek f (Mesh_Info2[6].DataOff2) #seek_set
  812. if SizeCount==2 then fseek f (Mesh_Info2[6].DataOff2+2) #seek_set
  813. if SizeCount==3 then fseek f (Mesh_Info2[6].DataOff2+3) #seek_set    
  814. if SizeCount==4 then fseek f (Mesh_Info2[6].DataOff2+4) #seek_set    
  815. if SizeCount==5 then fseek f (Mesh_Info2[6].DataOff2+5) #seek_set    
  816.     
  817. Print ("Weights Start @ 0x"+((bit.intAsHex(ftell f))as string))    
  818.  
  819. for x = 1 to Mesh_Info2[4].DataCount2 do (
  820. weight1 = ReadFloat f
  821. weight2 = ReadFloat f
  822. weight3 = ReadFloat f
  823. weight4 = ReadFloat f        
  824. append W1_array2 (Weight_Info_Struct Weight1:Weight1 Weight2:Weight2 Weight3:Weight3 Weight4:Weight4)        
  825. )    
  826.  
  827. for b = 1 to W1_array2.count Do (
  828. w = (weight_data boneids:#() weights:#())
  829. maxweight = 0
  830. if(W1_array2[b].Weight1 != 0) then
  831.    maxweight = maxweight + W1_array2[b].Weight1
  832. if(W1_array2[b].Weight2 != 0) then
  833.    maxweight = maxweight + W1_array2[b].Weight2
  834. if(W1_array2[b].Weight3 != 0) then
  835.    maxweight = maxweight + W1_array2[b].Weight3
  836. if(W1_array2[b].Weight4 != 0) then
  837.    maxweight = maxweight + W1_array2[b].Weight4
  838.  
  839. if(maxweight != 0) then
  840.    (
  841.       if(W1_array2[b].Weight1 != 0) then
  842.       (
  843.          w1 = W1_array2[b].Weight1 as float
  844.          append w.boneids (B1_array2[b].Bone1 + 1)
  845.          append w.weights (w1)
  846.       )
  847.       if(W1_array2[b].Weight2 != 0) then
  848.       (
  849.          w2 = W1_array2[b].Weight2 as float
  850.          append w.boneids (B1_array2[b].Bone2 + 1)
  851.          append w.weights (w2)
  852.       )
  853.       if(W1_array2[b].Weight3 != 0) then
  854.       (
  855.          w3 = W1_array2[b].Weight3 as float
  856.          append w.boneids (B1_array2[b].Bone3 + 1)
  857.          append w.weights (w3)
  858.       )
  859.       if(W1_array2[b].Weight4 != 0) then
  860.       (
  861.          w4 = W1_array2[b].Weight4 as float
  862.          append w.boneids (B1_array2[b].Bone4 + 1)
  863.          append w.weights (w4)
  864.       )      
  865.    )
  866. append Weight_array2 w
  867. )
  868. )
  869.  
  870. msh = mesh vertices:vertArray2 faces:faceArray2
  871. msh.name=("Model_Cloth"+i as string)
  872. msh.numTVerts = UV_array2.count
  873. buildTVFaces msh
  874. for j = 1 to UV_array2.count do setTVert msh j UV_array2[j]
  875. for j = 1 to faceArray2.count do setTVFace msh j faceArray2[j]
  876. msh.displayByLayer = false
  877. msh.backfacecull = false
  878. msh.wirecolor = (color 230 200 210)
  879.  
  880. max modify mode
  881. select msh
  882. skinMod = skin ()
  883. addModifier msh skinMod
  884. for i = 1 to BNArr.count do
  885. (
  886.     maxbone = BNArr[i]
  887.     if i != BNArr.count then 
  888.         skinOps.addBone skinMod maxbone 0
  889.     else
  890.         skinOps.addBone skinMod maxbone 1
  891. )
  892. modPanel.setCurrentObject skinMod
  893. for i = 1 to vertArray2.count do (
  894.    w = Weight_array2[i]
  895.    bi = #() --bone index array
  896.    wv = #() --weight value array
  897.    
  898.    for j = 1 to w.boneids.count do
  899.    (
  900.       boneid = w.boneids[j]
  901.       weight = w.weights[j]
  902.       append bi boneid
  903.       append wv weight
  904.    )   
  905.    
  906.    skinOps.ReplaceVertexWeights skinMod i bi wv
  907. )
  908. )
  909. )
  910.  
  911. fclose f