home *** CD-ROM | disk | FTP | other *** search
/ Xentax forum attachments archive / xentax.7z / 8654 / LOTF_Scripts.7z / LOTF.ms < prev   
Encoding:
Text File  |  2015-02-13  |  20.8 KB  |  953 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 ReadHalfFloat fstream = 
  16.     (
  17.     hf=readshort fstream
  18.     sign = bit.get hf 16
  19.     exponent = (bit.shift (bit.and hf (bit.hexasint "7C00")) -10) as integer - 16
  20.     fraction = bit.and hf (bit.hexasint "03FF")
  21.     if sign==true then sign = 1 else sign = 0
  22.     exponentF = exponent + 127
  23.     outputAsFloat = bit.or (bit.or (bit.shift fraction 13) \
  24.     (bit.shift exponentF 23)) (bit.shift sign 31)
  25.     return bit.intasfloat outputasfloat*2
  26. )
  27.  
  28. fn readFixedString bstream fixedLen = (
  29. local str = ""
  30. for i = 1 to fixedLen do (
  31. str += bit.intAsChar (ReadByte bstream #unsigned))
  32. str
  33. )
  34. struct weight_data
  35. (
  36.     boneids,weights
  37. )
  38. struct Mesh_Info_Struct
  39. (
  40. VertexCount, FaceCount, VertexId,UsedBones, VertexEnd,Vsize
  41. )        
  42. clearlistener()
  43.  
  44. fseek f (0x0) #seek_set
  45. Magic=readlong f 
  46. if Magic!=-1547335172 then fclose f
  47. if Magic==-1547335172 then (
  48. fseek f (0x27) #seek_set
  49. MeshNameSize=readbyte f#unsigned 
  50. MeshName=readFixedString f MeshNameSize
  51.  
  52. Pos00=ftell f
  53. Null00=readbyte f
  54. if Null00==106 then fseek f Pos00 #seek_set     
  55. if Null00!=106 then (
  56. fseek f 0x0 #seek_cur    
  57. Pos01=ftell f
  58. Null01=readbyte f
  59. if Null01==106 then fseek f Pos01 #seek_set     
  60. if Null01!=106 then (
  61. fseek f 0x0 #seek_cur    
  62. Pos02=ftell f
  63. Null02=readbyte f
  64. if Null02==106 then fseek f Pos02 #seek_set     
  65. if Null02!=106 then (
  66. fseek f 0x0 #seek_cur    
  67. Pos03=ftell f
  68. Null03=readbyte f
  69. if Null03==106 then fseek f Pos03 #seek_set     
  70. if Null03!=106 then fseek f 0x0 #seek_cur            
  71. )        
  72. )    
  73. )    
  74.  
  75. fseek f (0xF) #seek_cur
  76.  
  77. Print ("!!!!! @ 0x"+((bit.intAsHex(ftell f))as string))    
  78.     
  79. MeshVersionSize=readbyte f#unsigned 
  80. MeshVersion=readFixedString f MeshVersionSize
  81. CountLong=readBElong f
  82.     
  83. if CountLong==3 then     fseek f (0xC) #seek_cur
  84. if CountLong==6 then     fseek f (0x10) #seek_cur    
  85. fseek f (0x58) #seek_cur
  86. UnkCount=readBElong f
  87. MeshCount=readBElong f    
  88. fseek f (0x8) #seek_cur
  89.  
  90. Start=ftell f
  91.     
  92. for i=1 to MeshCount do (    
  93.     
  94. fseek f (0x204) #seek_cur        
  95.     
  96. vertArray = #()
  97. faceArray = #()
  98. UV_array = #()
  99. Weight_array=#()    
  100.     
  101. VIDSec=readBElong f
  102. VertCount=readBElong f
  103. UnkCount=readBElong f
  104.     
  105. print VIDSec    
  106.  
  107. if VIDSec==88 then
  108. for x = 1 to VertCount do (
  109. getPos = ftell f + VIDSec
  110.  
  111. vx = ReadFloat f
  112. vy = ReadFloat f
  113. vz = ReadFloat f    
  114.     
  115. FFFF=readlong f    
  116.     
  117. fseek f 0x1C #seek_cur        
  118.     
  119. tu00=Readfloat f    
  120. tv00=Readfloat f    *-1    
  121.  
  122. tu01=Readfloat f    
  123. tv01=Readfloat f    *-1        
  124.     
  125. tu02=Readfloat f    
  126. tv02=Readfloat f    *-1    
  127.     
  128. fseek f getPos #seek_set        
  129. )    
  130.     
  131. if VIDSec==84 then
  132. for x = 1 to VertCount do (
  133. getPos = ftell f + VIDSec
  134.  
  135. vx = ReadFloat f
  136. vy = ReadFloat f
  137. vz = ReadFloat f    
  138.     
  139. fseek f 0x1C #seek_cur        
  140.     
  141. tu00=Readfloat f    
  142. tv00=Readfloat f    *-1    
  143.  
  144. tu01=Readfloat f    
  145. tv01=Readfloat f    *-1        
  146.     
  147. tu02=Readfloat f    
  148. tv02=Readfloat f    *-1    
  149.     
  150. fseek f getPos #seek_set        
  151. )    
  152.  
  153. if VIDSec==76 then
  154. for x = 1 to VertCount do (
  155. getPos = ftell f + VIDSec
  156.  
  157. vx = ReadFloat f
  158. vy = ReadFloat f
  159. vz = ReadFloat f    
  160.         
  161. fseek f 0x1C #seek_cur        
  162.     
  163. tu00=Readfloat f    
  164. tv00=Readfloat f    *-1    
  165.  
  166. tu01=Readfloat f    
  167. tv01=Readfloat f    *-1        
  168.     
  169. fseek f getPos #seek_set        
  170. )
  171.  
  172. if VIDSec==72 then
  173. for x = 1 to VertCount do (
  174. getPos = ftell f + VIDSec
  175.  
  176. vx = ReadFloat f
  177. vy = ReadFloat f
  178. vz = ReadFloat f    
  179.  
  180. FFFF=readlong f
  181.     
  182. fseek f 0x1C #seek_cur        
  183.     
  184. tu=Readfloat f    
  185. tv=Readfloat f    *-1    
  186.     
  187. fseek f getPos #seek_set        
  188. )    
  189.  
  190. if VIDSec==68 then
  191. for x = 1 to VertCount do (
  192. getPos = ftell f + VIDSec
  193.  
  194. vx = ReadFloat f
  195. vy = ReadFloat f
  196. vz = ReadFloat f    
  197.     
  198. fseek f 0x1C #seek_cur        
  199.     
  200. tu=Readfloat f    
  201. tv=Readfloat f    *-1    
  202.  
  203. fseek f getPos #seek_set        
  204. )    
  205.  
  206. if VIDSec==64 then
  207. for x = 1 to VertCount do (
  208. getPos = ftell f + VIDSec
  209.  
  210. vx = ReadFloat f
  211. vy = ReadFloat f
  212. vz = ReadFloat f    
  213.     
  214. fseek f getPos #seek_set        
  215. )    
  216.  
  217. if VIDSec==48 then
  218. for x = 1 to VertCount do (
  219. getPos = ftell f + VIDSec
  220.  
  221. vx = ReadFloat f
  222. vy = ReadFloat f
  223. vz = ReadFloat f    
  224.     
  225. fseek f getPos #seek_set        
  226. )    
  227.  
  228. Print ("End @ 0x"+((bit.intAsHex(ftell f))as string))    
  229.     
  230. FacePos=ftell f
  231. FaceCheck=readBElong f
  232. if FaceCheck>1 then (    
  233. fseek f FacePos #seek_set    
  234. FaceSize=readBElong f
  235. FaceCount=readBElong f
  236. )
  237.  
  238. if FaceCheck<=1 then  (    
  239. FaceSize=readBElong f
  240. FaceCount=readBElong f
  241. )
  242.  
  243. Print ("FaceStart @ 0x"+((bit.intAsHex(ftell f))as string))        
  244.     
  245. for x=1 to FaceCount/3 do (    
  246. fa=readshort f #unsigned +1
  247. fb=readshort f #unsigned +1
  248. fc=readshort f #unsigned +1
  249. )    
  250.  
  251. Print ("FaceEnd @ 0x"+((bit.intAsHex(ftell f))as string))    
  252.  
  253. if VIDSec>48 then (    
  254.  
  255. SecId=readBElong f    
  256.     
  257. if SecId==4 then fseek f (0x8) #seek_cur
  258. if SecId!=4 then fseek f (0xA) #seek_cur
  259.     
  260. for x = 1 to VertCount do (
  261. getPos = ftell f + 36
  262. fseek f getPos #seek_set        
  263. )        
  264.     
  265. Print ("SecEnd @ 0x"+((bit.intAsHex(ftell f))as string))    
  266.  
  267. Pos=ftell f
  268. CheckShort=readshort f
  269. if CheckShort!=0 then fseek f Pos #seek_set     
  270. if CheckShort==0 then fseek f 0x0 #seek_cur    
  271.     
  272. BoneMapCount=readbyte f    
  273.  
  274. Print ("Map Start @ 0x"+((bit.intAsHex(ftell f))as string))
  275.  
  276. for x = 1 to BoneMapCount do (
  277. BoneMap=readbyte f    
  278. )            
  279.  
  280. Print ("Map End @ 0x"+((bit.intAsHex(ftell f))as string))
  281.  
  282. if BoneMapCount==0 then (
  283. fseek f (0x7) #seek_cur
  284.     
  285. Pos0=ftell f
  286. Null0=readbyte f
  287. if Null0!=0 then fseek f (Pos0-3) #seek_set     
  288. if Null0==0 then (
  289. fseek f 0x0 #seek_cur    
  290. Pos1=ftell f
  291. Null1=readbyte f
  292. if Null1!=0 then fseek f (Pos1-3) #seek_set     
  293. if Null1==0 then (
  294. fseek f 0x0 #seek_cur    
  295. Pos2=ftell f
  296. Null2=readbyte f
  297. if Null2!=0 then fseek f (Pos2-3) #seek_set     
  298. if Null2==0 then (
  299. fseek f 0x0 #seek_cur    
  300. Pos3=ftell f
  301. Null3=readbyte f
  302. if Null3!=0 then fseek f (Pos3-3) #seek_set     
  303. if Null3==0 then fseek f 0x0 #seek_cur            
  304. )        
  305. )    
  306. )        
  307.     
  308. )    
  309. if BoneMapCount!=0 then (
  310. fseek f (0xB) #seek_cur
  311.  
  312. Pos0=ftell f
  313. Null0=readbyte f
  314. if Null0!=0 then fseek f (Pos0-3) #seek_set     
  315. if Null0==0 then (
  316. fseek f 0x0 #seek_cur    
  317. Pos1=ftell f
  318. Null1=readbyte f
  319. if Null1!=0 then fseek f (Pos1-3) #seek_set     
  320. if Null1==0 then (
  321. fseek f 0x0 #seek_cur    
  322. Pos2=ftell f
  323. Null2=readbyte f
  324. if Null2!=0 then fseek f (Pos2-3) #seek_set     
  325. if Null2==0 then (
  326. fseek f 0x0 #seek_cur    
  327. Pos3=ftell f
  328. Null3=readbyte f
  329. if Null3!=0 then fseek f (Pos3-3) #seek_set     
  330. if Null3==0 then fseek f 0x0 #seek_cur            
  331. )        
  332. )    
  333. )        
  334.     
  335. )
  336. )    
  337. )
  338.  
  339. BNArr=#()
  340.  
  341. Null=readbyte f
  342. Pos00=ftell f
  343. Null00=readbyte f
  344. if Null00!=0 then fseek f Pos00 #seek_set     
  345. if Null00==0 then (
  346. fseek f 0x0 #seek_cur    
  347. Pos01=ftell f
  348. Null01=readbyte f
  349. if Null01!=0 then fseek f Pos01 #seek_set     
  350. if Null01==0 then (
  351. fseek f 0x0 #seek_cur    
  352. Pos02=ftell f
  353. Null02=readbyte f
  354. if Null02!=0 then fseek f Pos02 #seek_set     
  355. if Null02==0 then (
  356. fseek f 0x0 #seek_cur    
  357. Pos03=ftell f
  358. Null03=readbyte f
  359. if Null03!=0 then fseek f Pos03 #seek_set     
  360. if Null03==0 then fseek f 0x0 #seek_cur            
  361. )        
  362. )    
  363. )    
  364. BoneCount=readbyte f#unsigned
  365. for i=1 to BoneCount do (
  366. FloatB=readfloat f    
  367. fseek f (0xB) #seek_cur    
  368. BoneNameSize=readbyte f#unsigned
  369. BoneName=readFixedString f BoneNameSize
  370. Null0=readbyte f        
  371. Null1=readbyte f    
  372. if Null1==0 then (
  373. Check=readbyte f
  374. if Check==0 then fseek f (0xF) #seek_cur
  375. if Check!=0 then fseek f (0xE) #seek_cur    
  376. )    
  377. if Null1!=0 then (
  378. if Null0!=0 then fseek f (0xD) #seek_cur    
  379. if Null0==0 then fseek f (0xE) #seek_cur    
  380. )    
  381. BoneNameSize2=readbyte f#unsigned
  382. BoneName2=readFixedString f BoneNameSize2
  383. FloatB=readBEfloat f
  384. BoneId=readBElong f+1
  385. Unk2=readBElong f
  386. Unk3=readBElong f    
  387. getPos = ftell f + 72
  388. c11=readBEfloat f;c12=readBEfloat f;c13=readBEfloat f
  389. BoneParent=readBElong f+1
  390. c21=readBEfloat f;c22=readBEfloat f;c23=readBEfloat f;c24=readBEfloat f
  391. c31=readBEfloat f;c32=readBEfloat f;c33=readBEfloat f;
  392. vx=readBEfloat f;vy=readBEfloat f;vz=readBEfloat f
  393. rx=readBEfloat f;ry=readBEfloat f;rz=readBEfloat f;rw=readBEfloat f*-1
  394. fseek f getPos #seek_set        
  395.  
  396. tfm = (quat rx ry rz rw) as matrix3
  397. tfm.row4 = [vx,vy,vz]
  398. if (BoneParent != 0) do (
  399. tfm = tfm * BNArr[(BoneParent)].objecttransform    
  400. )    
  401.  
  402. newBone = bonesys.createbone    \
  403.                                       tfm.row4      \
  404.                                       (tfm.row4 + 0.01 * (normalize tfm.row1)) \
  405.                                       (normalize tfm.row3)
  406.                             newBone.width  = 0.01
  407.                             newBone.height = 0.01
  408.                             newBone.name = BoneName                                  
  409.                             newBone.transform = tfm
  410.                             newBone.setBoneEnable false 0
  411.                             newBone.wirecolor = yellow
  412.                             newbone.showlinks = true
  413.                             newBone.pos.controller      = TCB_position ()
  414.                             newBone.rotation.controller = TCB_rotation () 
  415. if BoneParent!=0 then
  416. newBone.parent=BNArr[(BoneParent)]                                              
  417. append BNArr newBone  
  418. )    
  419.  
  420. rootRT = dummy name:"Main_Root" boxsize:[.1,.1,.1]
  421. for b in BNArr where b.parent==undefined do b.parent = rootRT
  422. rootRT.transform = (matrix3 [1,0,0] [0,0,1] [0,-1,0] [0,0,0])    
  423.  
  424. Print ("Bone End @ 0x"+((bit.intAsHex(ftell f))as string))    
  425.     
  426. fseek f (Start) #seek_set    
  427.     
  428. for i=1 to MeshCount do (    
  429.     
  430. fseek f (0x204) #seek_cur        
  431.     
  432. vertArray = #()
  433. faceArray = #()
  434. UV_array = #()
  435. Weight_array = #()    
  436. BoneMapArray = #()
  437.     
  438. VIDSec=readBElong f
  439. VertCount=readBElong f
  440. UnkCount=readBElong f
  441.  
  442. Print ("Start @ 0x"+((bit.intAsHex(ftell f))as string))    
  443.     
  444. print VIDSec    
  445.  
  446. if VIDSec==88 then
  447. for x = 1 to VertCount do (
  448. getPos = ftell f + VIDSec
  449.  
  450. vx = ReadFloat f
  451. vy = ReadFloat f
  452. vz = ReadFloat f    
  453.     
  454. FFFF=readlong f    
  455.     
  456. fseek f 0x1C #seek_cur        
  457.     
  458. tu00=Readfloat f    
  459. tv00=Readfloat f    *-1    
  460.  
  461. tu01=Readfloat f    
  462. tv01=Readfloat f    *-1        
  463.     
  464. tu02=Readfloat f    
  465. tv02=Readfloat f    *-1    
  466.     
  467. bone1 = readbyte f #unsigned    
  468. bone2 = readbyte f #unsigned    
  469. bone3 = readbyte f #unsigned    
  470. bone4 = readbyte f #unsigned
  471.     
  472. weight1 = ReadFloat f
  473. weight2 = ReadFloat f
  474. weight3 = ReadFloat f
  475. weight4 = ReadFloat f
  476.     
  477. w = (weight_data boneids:#() weights:#())
  478. maxweight = 0
  479. if(weight1 != 0) then
  480.    maxweight = maxweight + weight1
  481. if(weight2 != 0) then
  482.    maxweight = maxweight + weight2
  483. if(weight3 != 0) then
  484.    maxweight = maxweight + weight3
  485. if(weight4 != 0) then
  486.    maxweight = maxweight + weight4
  487.  
  488. if(maxweight != 0) then (
  489.       if(weight1 != 0) then (
  490.          w1 = weight1 as float
  491.          append w.boneids (bone1 + 1)
  492.          append w.weights (w1)
  493.       )
  494.       if(weight2 != 0) then (
  495.          w2 = weight2 as float
  496.          append w.boneids (bone2 + 1)
  497.          append w.weights (w2)
  498.       )
  499.       if(weight3 != 0) then (
  500.          w3 = weight3 as float
  501.          append w.boneids (bone3 + 1)
  502.          append w.weights (w3)
  503.       )
  504.       if(weight4 != 0) then (
  505.          w4 = weight4 as float
  506.          append w.boneids (bone4 + 1)
  507.         append w.weights (w4)
  508.       )      
  509.    )    
  510. fseek f getPos #seek_set    
  511. append Weight_array w      
  512. append vertArray ([vx,-vz,vy])
  513. append UV_array [tu00,tv00,0]    
  514. )    
  515.     
  516. if VIDSec==84 then
  517. for x = 1 to VertCount do (
  518. getPos = ftell f + VIDSec
  519.  
  520. vx = ReadFloat f
  521. vy = ReadFloat f
  522. vz = ReadFloat f    
  523.     
  524. fseek f 0x1C #seek_cur        
  525.     
  526. tu00=Readfloat f    
  527. tv00=Readfloat f    *-1    
  528.  
  529. tu01=Readfloat f    
  530. tv01=Readfloat f    *-1        
  531.     
  532. tu02=Readfloat f    
  533. tv02=Readfloat f    *-1    
  534.     
  535. bone1 = readbyte f #unsigned    
  536. bone2 = readbyte f #unsigned    
  537. bone3 = readbyte f #unsigned    
  538. bone4 = readbyte f #unsigned
  539.     
  540. weight1 = ReadFloat f
  541. weight2 = ReadFloat f
  542. weight3 = ReadFloat f
  543. weight4 = ReadFloat f
  544.     
  545. w = (weight_data boneids:#() weights:#())
  546. maxweight = 0
  547. if(weight1 != 0) then
  548.    maxweight = maxweight + weight1
  549. if(weight2 != 0) then
  550.    maxweight = maxweight + weight2
  551. if(weight3 != 0) then
  552.    maxweight = maxweight + weight3
  553. if(weight4 != 0) then
  554.    maxweight = maxweight + weight4
  555.  
  556. if(maxweight != 0) then (
  557.       if(weight1 != 0) then (
  558.          w1 = weight1 as float
  559.          append w.boneids (bone1 + 1)
  560.          append w.weights (w1)
  561.       )
  562.       if(weight2 != 0) then (
  563.          w2 = weight2 as float
  564.          append w.boneids (bone2 + 1)
  565.          append w.weights (w2)
  566.       )
  567.       if(weight3 != 0) then (
  568.          w3 = weight3 as float
  569.          append w.boneids (bone3 + 1)
  570.          append w.weights (w3)
  571.       )
  572.       if(weight4 != 0) then (
  573.          w4 = weight4 as float
  574.          append w.boneids (bone4 + 1)
  575.         append w.weights (w4)
  576.       )      
  577.    )    
  578. fseek f getPos #seek_set    
  579. append Weight_array w          
  580. append vertArray ([vx,-vz,vy])
  581. append UV_array [tu00,tv00,0]    
  582. )    
  583.  
  584. if VIDSec==76 then
  585. for x = 1 to VertCount do (
  586. getPos = ftell f + VIDSec
  587.  
  588. vx = ReadFloat f
  589. vy = ReadFloat f
  590. vz = ReadFloat f    
  591.         
  592. fseek f 0x1C #seek_cur        
  593.     
  594. tu00=Readfloat f    
  595. tv00=Readfloat f    *-1    
  596.  
  597. tu01=Readfloat f    
  598. tv01=Readfloat f    *-1        
  599.     
  600. bone1 = readbyte f #unsigned    
  601. bone2 = readbyte f #unsigned    
  602. bone3 = readbyte f #unsigned    
  603. bone4 = readbyte f #unsigned
  604.     
  605. weight1 = ReadFloat f
  606. weight2 = ReadFloat f
  607. weight3 = ReadFloat f
  608. weight4 = ReadFloat f
  609.     
  610. w = (weight_data boneids:#() weights:#())
  611. maxweight = 0
  612. if(weight1 != 0) then
  613.    maxweight = maxweight + weight1
  614. if(weight2 != 0) then
  615.    maxweight = maxweight + weight2
  616. if(weight3 != 0) then
  617.    maxweight = maxweight + weight3
  618. if(weight4 != 0) then
  619.    maxweight = maxweight + weight4
  620.  
  621. if(maxweight != 0) then (
  622.       if(weight1 != 0) then (
  623.          w1 = weight1 as float
  624.          append w.boneids (bone1 + 1)
  625.          append w.weights (w1)
  626.       )
  627.       if(weight2 != 0) then (
  628.          w2 = weight2 as float
  629.          append w.boneids (bone2 + 1)
  630.          append w.weights (w2)
  631.       )
  632.       if(weight3 != 0) then (
  633.          w3 = weight3 as float
  634.          append w.boneids (bone3 + 1)
  635.          append w.weights (w3)
  636.       )
  637.       if(weight4 != 0) then (
  638.          w4 = weight4 as float
  639.          append w.boneids (bone4 + 1)
  640.         append w.weights (w4)
  641.       )      
  642.    )    
  643. fseek f getPos #seek_set    
  644. append Weight_array w          
  645. append vertArray ([vx,-vz,vy])
  646. append UV_array [tu00,tv00,0]        
  647. )
  648.  
  649. if VIDSec==72 then
  650. for x = 1 to VertCount do (
  651. getPos = ftell f + VIDSec
  652.  
  653. vx = ReadFloat f
  654. vy = ReadFloat f
  655. vz = ReadFloat f    
  656.  
  657. FFFF=readlong f
  658.     
  659. fseek f 0x1C #seek_cur        
  660.     
  661. tu=Readfloat f    
  662. tv=Readfloat f    *-1    
  663.     
  664. bone1 = readbyte f #unsigned    
  665. bone2 = readbyte f #unsigned    
  666. bone3 = readbyte f #unsigned    
  667. bone4 = readbyte f #unsigned
  668.     
  669. weight1 = ReadFloat f
  670. weight2 = ReadFloat f
  671. weight3 = ReadFloat f
  672. weight4 = ReadFloat f
  673.     
  674. w = (weight_data boneids:#() weights:#())
  675. maxweight = 0
  676. if(weight1 != 0) then
  677.    maxweight = maxweight + weight1
  678. if(weight2 != 0) then
  679.    maxweight = maxweight + weight2
  680. if(weight3 != 0) then
  681.    maxweight = maxweight + weight3
  682. if(weight4 != 0) then
  683.    maxweight = maxweight + weight4
  684.  
  685. if(maxweight != 0) then (
  686.       if(weight1 != 0) then (
  687.          w1 = weight1 as float
  688.          append w.boneids (bone1 + 1)
  689.          append w.weights (w1)
  690.       )
  691.       if(weight2 != 0) then (
  692.          w2 = weight2 as float
  693.          append w.boneids (bone2 + 1)
  694.          append w.weights (w2)
  695.       )
  696.       if(weight3 != 0) then (
  697.          w3 = weight3 as float
  698.          append w.boneids (bone3 + 1)
  699.          append w.weights (w3)
  700.       )
  701.       if(weight4 != 0) then (
  702.          w4 = weight4 as float
  703.          append w.boneids (bone4 + 1)
  704.         append w.weights (w4)
  705.       )      
  706.    )    
  707. fseek f getPos #seek_set    
  708. append Weight_array w          
  709. append vertArray ([vx,-vz,vy])
  710. append UV_array [tu,tv,0]        
  711. )    
  712.  
  713. if VIDSec==68 then
  714. for x = 1 to VertCount do (
  715. getPos = ftell f + VIDSec
  716.  
  717. vx = ReadFloat f
  718. vy = ReadFloat f
  719. vz = ReadFloat f    
  720.     
  721. fseek f 0x1C #seek_cur        
  722.     
  723. tu=Readfloat f    
  724. tv=Readfloat f    *-1    
  725.  
  726. bone1 = readbyte f #unsigned    
  727. bone2 = readbyte f #unsigned    
  728. bone3 = readbyte f #unsigned    
  729. bone4 = readbyte f #unsigned
  730.     
  731. weight1 = ReadFloat f
  732. weight2 = ReadFloat f
  733. weight3 = ReadFloat f
  734. weight4 = ReadFloat f
  735.     
  736. w = (weight_data boneids:#() weights:#())
  737. maxweight = 0
  738. if(weight1 != 0) then
  739.    maxweight = maxweight + weight1
  740. if(weight2 != 0) then
  741.    maxweight = maxweight + weight2
  742. if(weight3 != 0) then
  743.    maxweight = maxweight + weight3
  744. if(weight4 != 0) then
  745.    maxweight = maxweight + weight4
  746.  
  747. if(maxweight != 0) then (
  748.       if(weight1 != 0) then (
  749.          w1 = weight1 as float
  750.          append w.boneids (bone1 + 1)
  751.          append w.weights (w1)
  752.       )
  753.       if(weight2 != 0) then (
  754.          w2 = weight2 as float
  755.          append w.boneids (bone2 + 1)
  756.          append w.weights (w2)
  757.       )
  758.       if(weight3 != 0) then (
  759.          w3 = weight3 as float
  760.          append w.boneids (bone3 + 1)
  761.          append w.weights (w3)
  762.       )
  763.       if(weight4 != 0) then (
  764.          w4 = weight4 as float
  765.          append w.boneids (bone4 + 1)
  766.         append w.weights (w4)
  767.       )      
  768.    )    
  769. fseek f getPos #seek_set    
  770. append Weight_array w       
  771. append vertArray ([vx,-vz,vy])
  772. append UV_array [tu,tv,0]        
  773. )    
  774.  
  775. if VIDSec==64 then
  776. for x = 1 to VertCount do (
  777. getPos = ftell f + VIDSec
  778.  
  779. vx = ReadFloat f
  780. vy = ReadFloat f
  781. vz = ReadFloat f    
  782.     
  783. fseek f getPos #seek_set        
  784. append vertArray ([-vx,-vz,vy])
  785. )    
  786.  
  787. if VIDSec==48 then
  788. for x = 1 to VertCount do (
  789. getPos = ftell f + VIDSec
  790.  
  791. vx = ReadFloat f
  792. vy = ReadFloat f
  793. vz = ReadFloat f    
  794.     
  795. fseek f getPos #seek_set        
  796. append vertArray ([-vx,-vz,vy])
  797. )    
  798.  
  799. Print ("End @ 0x"+((bit.intAsHex(ftell f))as string))    
  800.     
  801. FacePos=ftell f
  802. FaceCheck=readBElong f
  803. if FaceCheck>1 then (    
  804. fseek f FacePos #seek_set    
  805. FaceSize=readBElong f
  806. FaceCount=readBElong f
  807. )
  808.  
  809. if FaceCheck<=1 then  (    
  810. FaceSize=readBElong f
  811. FaceCount=readBElong f
  812. )
  813.  
  814. Print ("FaceStart @ 0x"+((bit.intAsHex(ftell f))as string))        
  815.     
  816. for x=1 to FaceCount/3 do (    
  817. fa=readshort f #unsigned +1
  818. fb=readshort f #unsigned +1
  819. fc=readshort f #unsigned +1
  820. append faceArray [fa,fb,fc]    
  821. )    
  822.  
  823. Print ("FaceEnd @ 0x"+((bit.intAsHex(ftell f))as string))    
  824.  
  825. if VIDSec>48 then (    
  826.  
  827. SecId=readBElong f    
  828.     
  829. if SecId==4 then fseek f (0x8) #seek_cur
  830. if SecId!=4 then fseek f (0xA) #seek_cur
  831.     
  832. for x = 1 to VertCount do (
  833. getPos = ftell f + 36
  834. fseek f getPos #seek_set        
  835. )        
  836.     
  837. Print ("SecEnd @ 0x"+((bit.intAsHex(ftell f))as string))    
  838.  
  839. Pos=ftell f
  840. CheckShort=readshort f
  841. if CheckShort!=0 then fseek f Pos #seek_set     
  842. if CheckShort==0 then fseek f 0x0 #seek_cur    
  843.     
  844. BoneMapCount=readbyte f    
  845.  
  846. Print ("Map Start @ 0x"+((bit.intAsHex(ftell f))as string))
  847.  
  848. for x = 1 to BoneMapCount do (
  849. BoneMap=readbyte f+1    
  850. append BoneMapArray BoneMap    
  851. )            
  852.  
  853. Print ("Map End @ 0x"+((bit.intAsHex(ftell f))as string))
  854.  
  855. if BoneMapCount==0 then (
  856. fseek f (0x7) #seek_cur
  857.     
  858. Pos0=ftell f
  859. Null0=readbyte f
  860. if Null0!=0 then fseek f (Pos0-3) #seek_set     
  861. if Null0==0 then (
  862. fseek f 0x0 #seek_cur    
  863. Pos1=ftell f
  864. Null1=readbyte f
  865. if Null1!=0 then fseek f (Pos1-3) #seek_set     
  866. if Null1==0 then (
  867. fseek f 0x0 #seek_cur    
  868. Pos2=ftell f
  869. Null2=readbyte f
  870. if Null2!=0 then fseek f (Pos2-3) #seek_set     
  871. if Null2==0 then (
  872. fseek f 0x0 #seek_cur    
  873. Pos3=ftell f
  874. Null3=readbyte f
  875. if Null3!=0 then fseek f (Pos3-3) #seek_set     
  876. if Null3==0 then fseek f 0x0 #seek_cur            
  877. )        
  878. )    
  879. )        
  880.     
  881. )    
  882. if BoneMapCount!=0 then (
  883. fseek f (0xB) #seek_cur
  884.  
  885. Pos0=ftell f
  886. Null0=readbyte f
  887. if Null0!=0 then fseek f (Pos0-3) #seek_set     
  888. if Null0==0 then (
  889. fseek f 0x0 #seek_cur    
  890. Pos1=ftell f
  891. Null1=readbyte f
  892. if Null1!=0 then fseek f (Pos1-3) #seek_set     
  893. if Null1==0 then (
  894. fseek f 0x0 #seek_cur    
  895. Pos2=ftell f
  896. Null2=readbyte f
  897. if Null2!=0 then fseek f (Pos2-3) #seek_set     
  898. if Null2==0 then (
  899. fseek f 0x0 #seek_cur    
  900. Pos3=ftell f
  901. Null3=readbyte f
  902. if Null3!=0 then fseek f (Pos3-3) #seek_set     
  903. if Null3==0 then fseek f 0x0 #seek_cur            
  904. )        
  905. )    
  906. )        
  907.     
  908. )
  909. )
  910.  
  911. Print ("Model End @ 0x"+((bit.intAsHex(ftell f))as string))    
  912.     
  913. msh = mesh vertices:vertArray faces:faceArray
  914. msh.name = (MeshName+i as string) 
  915. msh.numTVerts = UV_array.count
  916. buildTVFaces msh
  917. for j = 1 to UV_array.count do setTVert msh j UV_array[j]
  918. for j = 1 to faceArray.count do setTVFace msh j faceArray[j]
  919. msh.displayByLayer = false
  920. msh.backfacecull = false
  921. msh.wirecolor = (color 230 200 210)
  922.  
  923. max modify mode
  924. select msh
  925. skinMod = skin ()
  926. addModifier msh skinMod
  927. for i = 1 to BoneMapArray.count do
  928. (
  929.     maxbone = BNArr[(BoneMapArray[i])]
  930.     if i != BoneMapArray.count then 
  931.         skinOps.addBone skinMod maxbone 0
  932.     else
  933.         skinOps.addBone skinMod maxbone 1
  934. )
  935. modPanel.setCurrentObject skinMod
  936. for i = 1 to vertArray.count do (
  937.    w = Weight_array[i]
  938.    bi = #() --bone index array
  939.    wv = #() --weight value array
  940.    
  941.    for j = 1 to w.boneids.count do
  942.    (
  943.       boneid = w.boneids[j]
  944.       weight = w.weights[j]
  945.       append bi boneid
  946.       append wv weight
  947.    )   
  948.    
  949.    skinOps.ReplaceVertexWeights skinMod i bi wv
  950. )    
  951. )    
  952. )
  953. fclose f