home *** CD-ROM | disk | FTP | other *** search
/ Xentax forum attachments archive / xentax.7z / 7104 / LOS_2_PC.7z / LOS_2_PC.ms
Encoding:
Text File  |  2014-03-17  |  15.1 KB  |  664 lines

  1. if (heapSize < 20000000) then
  2.     heapSize = 200000000
  3. gname = getOpenFileName \
  4. caption:"Open .sm3 from Bones folder" \
  5. types:"LOS2 (*.sm3)|*.sm3" \
  6. historyCategory:"LOS2ObjectPresets"
  7. g = fopen gname "rb"
  8. fname = getOpenFileName \
  9. caption:"Open .msh from Mesh folder" \
  10. types:"L0S2  (*.msh)|*.msh" \
  11. historyCategory:"LOS2ObjectPresets"
  12. f = fopen fname "rb"
  13.  
  14. fn readHalfFloat fstream = (
  15.     hf=readshort fstream #unsigned
  16.     sign = bit.get hf 16
  17.     exponent = (bit.shift (bit.and hf (bit.hexasint "7C00")) -10) as integer - 16
  18.     fraction = bit.and hf (bit.hexasint "03FF")
  19.     if sign==true then sign = 1 else sign = 0
  20.     exponentF = exponent + 127
  21.     outputAsFloat = bit.or (bit.or (bit.shift fraction 13) \
  22.     (bit.shift exponentF 23)) (bit.shift sign 31)
  23.     return bit.intasfloat outputasfloat*2
  24.     )
  25.  
  26. fn ReadFixedString bstream fixedLen =
  27. (
  28.     local str = ""
  29.     for i = 1 to fixedLen do
  30.     (
  31.         str += bit.intAsChar (ReadByte bstream #unsigned)
  32.     )
  33.     str
  34. )
  35. struct weight_data
  36. (
  37.    boneids,weights
  38. )
  39. struct Weight_Info_Struct
  40. (
  41.         weight1,weight2,weight3,weight4
  42. )
  43. struct Bone_Info_Struct
  44. (
  45.         bone1,bone2,bone3,bone4
  46. )
  47. clearlistener()
  48.  
  49. fseek g 0x38 #seek_set
  50. check=readlong g
  51. if check==0 then 
  52. for i=1 to 1 do (    
  53. Data1Count = readlong g
  54. fseek g Data1Count #seek_cur    
  55. fseek g 0x49 #seek_cur
  56. DataCount1 = readlong g
  57. print DataCount1
  58. for x = 1 to DataCount1 do (
  59. DataNameSize1=readlong g
  60. DataName1=ReadFixedString g DataNameSize1
  61. )        
  62. )
  63.  
  64. if check!=0 then     
  65. for a = 1 to 1 do (        
  66. for i = 1 to 1 do (    
  67. fseek g 0xC #seek_cur        
  68. DataCount = readlong g
  69. print DataCount
  70. for x = 1 to DataCount do (
  71. DataNameSize=readlong g
  72. DataName=ReadFixedString g DataNameSize
  73. )    
  74. )
  75.  
  76. Pos=ftell g
  77. check2=readlong g    
  78. if check2==0 then 
  79. for a=1 to 1 do (        
  80. fseek g Pos #seek_set
  81. fseek g 0x4D #seek_cur
  82. DataCount2 = readlong g
  83. print DataCount2
  84. for x = 1 to DataCount2 do (
  85. DataNameSize2=readlong g
  86. DataName2=ReadFixedString g DataNameSize2
  87. )
  88. )
  89.  
  90. if check2!=0 then 
  91. for a=1 to 1 do (    
  92. fseek g Pos #seek_set
  93. Data2Count = readlong g
  94. fseek g Data2Count #seek_cur    
  95. fseek g 0x49 #seek_cur
  96. DataCount2 = readlong g
  97. print DataCount2
  98. for x = 1 to DataCount2 do (
  99. DataNameSize2=readlong g
  100. DataName2=ReadFixedString g DataNameSize2
  101. )    
  102. )    
  103. )
  104.  
  105. Print ("Skel Info End @ 0x"+((bit.intAsHex(ftell g))as string))        
  106.     
  107. BNArr = #()
  108. BoneIdsArray = #()    
  109.     
  110. BoneCount = readlong g
  111.  
  112. for a = 1 to BoneCount do (
  113. BoneNameSize = readlong g; BoneName = ReadFixedString g BoneNameSize
  114. BoneParentnameSize = readlong g; BoneParentname = ReadFixedString g BoneParentnameSize
  115. BoneParent = readlong g
  116. unk0 = readlong g
  117. if unk0==0 then fseek g 0x0 #seek_cur    
  118. if unk0!=0 then 
  119. for x=1 to 1 do (    
  120. fseek g 0xC #seek_cur        
  121. DataCount = readlong g
  122. for x = 1 to DataCount do (
  123. DataNameSize=readlong g
  124. DataName=ReadFixedString g DataNameSize
  125. )    
  126. )
  127. BoneId = readlong g +1
  128. unk2 = readlong g
  129. fseek g 0x30 #seek_cur
  130. m11 = readFloat g; m12 = readFloat g; m13 = readFloat g; m14 = readFloat g
  131. m21 = readFloat g; m22 = readFloat g; m23 = readFloat g; m24 = readFloat g
  132. m31 = readFloat g; m32 = readFloat g; m33 = readFloat g; m34 = readFloat g
  133. m41 = readFloat g; m42 = readFloat g; m43 = readFloat g; m44 = readFloat g
  134. tfm = matrix3 [m11,m12,m13] [m21,m22,m23] [m31,m32,m33] [m41,m42,m43]
  135. fseek g 0x1C #seek_cur
  136.  
  137. if (getNodeByName BoneName) != undefined do (
  138. append BNArr (getNodeByName BoneName)
  139. )
  140. if (getNodeByName BoneName) == undefined do (
  141.  
  142.  newBone = bonesys.createbone    \
  143.                   tfm.row4    \
  144.                   (tfm.row4 + 0.01 * (normalize tfm.row1)) \
  145.                   (normalize tfm.row3)
  146.             newBone.name = BoneName
  147.             newBone.width  = 0.01
  148.             newBone.height = 0.01
  149.             newBone.transform = inverse tfm
  150.             newBone.setBoneEnable false 0
  151.             newBone.wirecolor = white
  152.             newbone.showlinks = true
  153.             newBone.pos.controller      = TCB_position ()
  154.             newBone.rotation.controller = TCB_rotation ()
  155.  if (BoneParent != -1) then
  156.  newBone.parent = BNArr[(BoneParent + 1)]                      
  157. append BNArr newBone
  158. append BoneIdsArray BoneId                                            
  159. )                      
  160. )
  161. Print ("Last Read @ 0x"+((bit.intAsHex(ftell g))as string))    
  162.     
  163.  fseek f 0xc #seek_set
  164. meshcount = readlong f
  165.     
  166. for x = 1 to meshcount do (
  167.  
  168.     
  169. MainMeshCount = readlong f
  170. meshExt=ReadFixedString f 5    
  171. fseek f 0x20 #seek_cur
  172. SubMeshCount = readlong f
  173. for i = 1 to SubMeshCount do (    
  174.     
  175. Vert_array=#()
  176. Face_array=#()
  177. UV_array=#()    
  178. Weight_array =#()
  179. UsedBonesArray =#()    
  180.     
  181. fseek f 0x10 #seek_cur    
  182. print SubMeshCount    
  183.     
  184. facecount = readlong f    
  185. faceSize = readlong f
  186.  
  187.  
  188. for x = 1 to facecount do(
  189. fa=readshort f +1
  190. fb=readshort f +1
  191. fc=readshort f +1
  192. append Face_array[fa,fb,fc]
  193. )
  194.  
  195. ext=ReadFixedString f 4    
  196. unk = readlong f
  197. subCount = readlong f
  198. Count = readlong f
  199. stringSize = readlong f
  200. extSTR=ReadFixedString f stringSize
  201. print extSTR
  202. null = readlong f
  203. vertexSize = readlong f    
  204. print vertexSize
  205. vertexcount = readlong f    
  206. if vertexSize==44 then (
  207. for x = 1 to vertexcount do(
  208. getPos = ftell f + vertexSize    
  209. dx=readFloat f
  210. dy=readFloat f
  211. dz=readFloat f
  212. x1=readHalfFloat f
  213. x2=readHalfFloat f    
  214. x3=readHalfFloat f
  215. x4=readHalfFloat f
  216. x5=readHalfFloat f
  217. x6=readHalfFloat f    
  218. x7=readHalfFloat f
  219. x8=readHalfFloat f*-1    
  220. x9=readHalfFloat f
  221. x10=readHalfFloat f    
  222. x11=readHalfFloat f
  223. x12=readHalfFloat f    
  224. bone1 = readbyte f #unsigned
  225. bone2 = readbyte f #unsigned
  226. bone3 = readbyte f #unsigned
  227. bone4 = readbyte f #unsigned    
  228. weight1 = readbyte f #unsigned
  229. weight2 = readbyte f #unsigned
  230. weight3 = readbyte f #unsigned
  231. weight4 =readbyte f #unsigned    
  232.     
  233. w = (weight_data boneids:#() weights:#())
  234. maxweight = 0
  235. if(weight1 != 0) then
  236.    maxweight = maxweight + weight1
  237. if(weight2 != 0) then
  238.    maxweight = maxweight + weight2
  239. if(weight3 != 0) then
  240.    maxweight = maxweight + weight3
  241. if(weight4 != 0) then
  242.    maxweight = maxweight + weight4
  243.  
  244. if(maxweight != 0) then (
  245.       if(weight1 != 0) then (
  246.          w1 = weight1 as float
  247.          append w.boneids (bone1 + 1)
  248.          append w.weights (w1 / 255.0)
  249.       )
  250.       if(weight2 != 0) then (
  251.          w2 = weight2 as float
  252.          append w.boneids (bone2 + 1)
  253.          append w.weights (w2 / 255.0)
  254.       )
  255.       if(weight3 != 0) then (
  256.          w3 = weight3 as float
  257.          append w.boneids (bone3 + 1)
  258.          append w.weights (w3 / 255.0)
  259.       )
  260.       if(weight4 != 0) then (
  261.          w4 = weight4 as float
  262.          append w.boneids (bone4 + 1)
  263.          append w.weights (w4 / 255.0)
  264.       )      
  265.    )
  266. append Weight_array w            
  267. fseek f getPos #seek_set
  268. append Vert_array[dx,dy,dz] 
  269. append UV_array[x7,x8,0]
  270. )
  271. )
  272. if vertexSize==36 then (
  273. for x = 1 to vertexcount do(
  274. getPos = ftell f + vertexSize    
  275. bone1 = -1
  276. bone2 = -1
  277. bone3 = -1
  278. bone4 = -1    
  279. weight1 = 0
  280. weight2 = 0
  281. weight3 = 0
  282. weight4 = 0        
  283. dx=readFloat f
  284. dy=readFloat f
  285. dz=readFloat f
  286. x1=readHalfFloat f
  287. x2=readHalfFloat f
  288. x3=readHalfFloat f
  289. x4=readHalfFloat f
  290. x5=readHalfFloat f*-1
  291. x6=readHalfFloat f    
  292. x7=readHalfFloat f
  293. x8=readHalfFloat f    
  294. x9=readHalfFloat f
  295. x10=readHalfFloat f    
  296. x11=readHalfFloat f
  297. x12=readHalfFloat f    
  298.  
  299. w = (weight_data boneids:#() weights:#())
  300. maxweight = 0
  301. if(weight1 != 0) then
  302.    maxweight = maxweight + weight1
  303. if(weight2 != 0) then
  304.    maxweight = maxweight + weight2
  305. if(weight3 != 0) then
  306.    maxweight = maxweight + weight3
  307. if(weight4 != 0) then
  308.    maxweight = maxweight + weight4
  309.  
  310. if(maxweight != 0) then (
  311.       if(weight1 != 0) then (
  312.          w1 = weight1 as float
  313.          append w.boneids (bone1 + 1)
  314.          append w.weights w1
  315.       )
  316.       if(weight2 != 0) then (
  317.          w2 = weight2 as float
  318.          append w.boneids (bone2 + 1)
  319.          append w.weights w2
  320.       )
  321.       if(weight3 != 0) then (
  322.          w3 = weight3 as float
  323.          append w.boneids (bone3 + 1)
  324.          append w.weights w3
  325.       )
  326.       if(weight4 != 0) then (
  327.          w4 = weight4 as float
  328.          append w.boneids (bone4 + 1)
  329.          append w.weights w4
  330.       )      
  331.    )
  332.     
  333. fseek f getPos #seek_set
  334. append Weight_array w         
  335. append Vert_array[dx,dy,dz] 
  336. append UV_array[x7,x8,0]
  337. )
  338. )
  339. if vertexSize==32 then (
  340. for x = 1 to vertexcount do(
  341. getPos = ftell f + vertexSize            
  342. dx=readFloat f
  343. dy=readFloat f
  344. dz=readFloat f
  345. x1=readHalfFloat f
  346. x2=readHalfFloat f
  347. x3=readFloat f
  348. x4=readFloat f*-1
  349. bone1 = readbyte f #unsigned
  350. bone2 = readbyte f #unsigned
  351. bone3 = readbyte f #unsigned
  352. bone4 = readbyte f #unsigned    
  353. weight1 = readbyte f #unsigned
  354. weight2 = readbyte f #unsigned
  355. weight3 = readbyte f #unsigned
  356. weight4 =readbyte f #unsigned    
  357.  
  358. w = (weight_data boneids:#() weights:#())
  359. maxweight = 0
  360. if(weight1 != 0) then
  361.    maxweight = maxweight + weight1
  362. if(weight2 != 0) then
  363.    maxweight = maxweight + weight2
  364. if(weight3 != 0) then
  365.    maxweight = maxweight + weight3
  366. if(weight4 != 0) then
  367.    maxweight = maxweight + weight4
  368.  
  369. if(maxweight != 0) then (
  370.       if(weight1 != 0) then (
  371.          w1 = weight1 as float
  372.          append w.boneids (bone1 + 1)
  373.          append w.weights w1
  374.       )
  375.       if(weight2 != 0) then (
  376.          w2 = weight2 as float
  377.          append w.boneids (bone2 + 1)
  378.          append w.weights w2
  379.       )
  380.       if(weight3 != 0) then (
  381.          w3 = weight3 as float
  382.          append w.boneids (bone3 + 1)
  383.          append w.weights w3
  384.       )
  385.       if(weight4 != 0) then (
  386.          w4 = weight4 as float
  387.          append w.boneids (bone4 + 1)
  388.          append w.weights w4
  389.       )      
  390.    )
  391.     
  392. fseek f getPos #seek_set
  393. append Weight_array w         
  394. append Vert_array[dx,dy,dz] 
  395. append UV_array[x3,x4,0]
  396. )
  397. )
  398. if vertexSize==24 then (
  399. for x = 1 to vertexcount do(
  400. getPos = ftell f + vertexSize    
  401. bone1 = -1
  402. bone2 = -1
  403. bone3 = -1
  404. bone4 = -1    
  405. weight1 = 0
  406. weight2 = 0
  407. weight3 = 0
  408. weight4 = 0        
  409. dx=readFloat f
  410. dy=readFloat f
  411. dz=readFloat f
  412. x1=readHalfFloat f
  413. x2=readHalfFloat f
  414. x3=readFloat f
  415. x4=readFloat f*-1
  416.  
  417. w = (weight_data boneids:#() weights:#())
  418. maxweight = 0
  419. if(weight1 != 0) then
  420.    maxweight = maxweight + weight1
  421. if(weight2 != 0) then
  422.    maxweight = maxweight + weight2
  423. if(weight3 != 0) then
  424.    maxweight = maxweight + weight3
  425. if(weight4 != 0) then
  426.    maxweight = maxweight + weight4
  427.  
  428. if(maxweight != 0) then (
  429.       if(weight1 != 0) then (
  430.          w1 = weight1 as float
  431.          append w.boneids (bone1 + 1)
  432.          append w.weights w1
  433.       )
  434.       if(weight2 != 0) then (
  435.          w2 = weight2 as float
  436.          append w.boneids (bone2 + 1)
  437.          append w.weights w2
  438.       )
  439.       if(weight3 != 0) then (
  440.          w3 = weight3 as float
  441.          append w.boneids (bone3 + 1)
  442.          append w.weights w3
  443.       )
  444.       if(weight4 != 0) then (
  445.          w4 = weight4 as float
  446.          append w.boneids (bone4 + 1)
  447.          append w.weights w4
  448.       )      
  449.    )
  450.     
  451. fseek f getPos #seek_set
  452. append Weight_array w         
  453. append Vert_array[dx,dy,dz] 
  454. append UV_array[x3,x4,0]
  455. )
  456. )
  457. if vertexSize==20 then (
  458. for x = 1 to vertexcount do(
  459. getPos = ftell f + vertexSize    
  460. bone1 = -1
  461. bone2 = -1
  462. bone3 = -1
  463. bone4 = -1    
  464. weight1 = 0
  465. weight2 = 0
  466. weight3 = 0
  467. weight4 = 0        
  468. dx=readFloat f
  469. dy=readFloat f
  470. dz=readFloat f
  471. x1=readFloat f
  472. x2=readFloat f*-1
  473.  
  474. w = (weight_data boneids:#() weights:#())
  475. maxweight = 0
  476. if(weight1 != 0) then
  477.    maxweight = maxweight + weight1
  478. if(weight2 != 0) then
  479.    maxweight = maxweight + weight2
  480. if(weight3 != 0) then
  481.    maxweight = maxweight + weight3
  482. if(weight4 != 0) then
  483.    maxweight = maxweight + weight4
  484.  
  485. if(maxweight != 0) then (
  486.       if(weight1 != 0) then (
  487.          w1 = weight1 as float
  488.          append w.boneids (bone1 + 1)
  489.          append w.weights w1
  490.       )
  491.       if(weight2 != 0) then (
  492.          w2 = weight2 as float
  493.          append w.boneids (bone2 + 1)
  494.          append w.weights w2
  495.       )
  496.       if(weight3 != 0) then (
  497.          w3 = weight3 as float
  498.          append w.boneids (bone3 + 1)
  499.          append w.weights w3
  500.       )
  501.       if(weight4 != 0) then (
  502.          w4 = weight4 as float
  503.          append w.boneids (bone4 + 1)
  504.          append w.weights w4
  505.       )      
  506.    )
  507.     
  508. fseek f getPos #seek_set
  509. append Weight_array w         
  510. append Vert_array[dx,dy,dz] 
  511. append UV_array[x1,x2,0]
  512. )
  513. )
  514. if vertexSize==12 then (
  515. for x = 1 to vertexcount do(
  516. getPos = ftell f + vertexSize    
  517. bone1 = -1
  518. bone2 = -1
  519. bone3 = -1
  520. bone4 = -1    
  521. weight1 = 0
  522. weight2 = 0
  523. weight3 = 0
  524. weight4 = 0        
  525. dx=readFloat f
  526. dy=readFloat f
  527. dz=readFloat f
  528.  
  529. w = (weight_data boneids:#() weights:#())
  530. maxweight = 0
  531. if(weight1 != 0) then
  532.    maxweight = maxweight + weight1
  533. if(weight2 != 0) then
  534.    maxweight = maxweight + weight2
  535. if(weight3 != 0) then
  536.    maxweight = maxweight + weight3
  537. if(weight4 != 0) then
  538.    maxweight = maxweight + weight4
  539.  
  540. if(maxweight != 0) then (
  541.       if(weight1 != 0) then (
  542.          w1 = weight1 as float
  543.          append w.boneids (bone1 + 1)
  544.          append w.weights w1
  545.       )
  546.       if(weight2 != 0) then (
  547.          w2 = weight2 as float
  548.          append w.boneids (bone2 + 1)
  549.          append w.weights w2
  550.       )
  551.       if(weight3 != 0) then (
  552.          w3 = weight3 as float
  553.          append w.boneids (bone3 + 1)
  554.          append w.weights w3
  555.       )
  556.       if(weight4 != 0) then (
  557.          w4 = weight4 as float
  558.          append w.boneids (bone4 + 1)
  559.          append w.weights w4
  560.       )      
  561.    )
  562.     
  563. fseek f getPos #seek_set
  564. append Weight_array w         
  565. append Vert_array[dx,dy,dz] 
  566. )
  567. )
  568. unk1 = readlong f    
  569.  
  570. facecount1 = readlong f    
  571. faceSize1 = readlong f    
  572.     
  573. for x = 1 to facecount1 do(
  574. ca=readshort f +1
  575. cb=readshort f +1
  576. cc=readshort f +1
  577. )
  578.  
  579. ext1=ReadFixedString f 4    
  580. unk2 = readlong f
  581. subCount1 = readlong f
  582. Count1 = readlong f
  583. stringSize1 = readlong f
  584. extSTR1=ReadFixedString f stringSize1
  585. print extSTR1
  586. null1 = readlong f
  587. vertexSize1 = readlong f    
  588. vertexcount1 = readlong f    
  589.  
  590. for x = 1 to vertexcount1 do(
  591. getPos = ftell f + vertexSize1    
  592. xx=readFloat f
  593. xy=readFloat f
  594. xz=readFloat f
  595. fseek f getPos #seek_set
  596. )
  597.     
  598. unit = readlong f
  599. unitcount= readlong f
  600. longcount= readlong f    
  601. for x = 1 to unitcount do(
  602. short=readshort f +1
  603. Append UsedBonesArray short    
  604. )
  605. longNull1= readlong f    
  606. longNull2= readlong f    
  607. ffffffff= readlong f
  608. fseek f 0x20 #seek_cur
  609. Print ("Last Read @ 0x"+((bit.intAsHex(ftell f))as string))    
  610.     
  611. msh = mesh vertices:Vert_array faces:Face_array
  612. msh.numTVerts = UV_array.count
  613. buildTVFaces msh
  614. for j = 1 to UV_array.count do setTVert msh j UV_array[j]
  615. for j = 1 to Face_array.count do setTVFace msh j Face_array[j]
  616.  
  617. max modify mode
  618. select msh
  619. skinMod = skin ()
  620. addModifier msh skinMod
  621. if unitcount== 0 then (
  622. for i = 1 to UsedBonesArray.Count+1 do
  623. (
  624.     maxbone =  BNArr[i]
  625.     if i != BNArr.Count then 
  626.         skinOps.addBone skinMod maxbone 0
  627.     else
  628.         skinOps.addBone skinMod maxbone 1
  629. )
  630. )
  631. if unitcount != 0 then (
  632. for i = 1 to UsedBonesArray.Count do
  633. (
  634.     maxbone =  BNArr[(UsedBonesArray[i])]
  635.     if i != BNArr.Count then 
  636.         skinOps.addBone skinMod maxbone 0
  637.     else
  638.         skinOps.addBone skinMod maxbone 1
  639. )
  640. )
  641. modPanel.setCurrentObject skinMod
  642. for i = 1 to vertexcount do (
  643.    w = Weight_array[i]
  644.    bi = #() --bone index array
  645.    wv = #() --weight value array
  646.    
  647.    for j = 1 to w.boneids.count do
  648.    (
  649.       boneid = w.boneids[j]
  650.       weight = w.weights[j]
  651.       append bi boneid
  652.       append wv weight
  653.    )   
  654.    
  655.    skinOps.ReplaceVertexWeights skinMod i bi wv
  656.  
  657. )
  658. )
  659.  
  660. )
  661.  
  662. fclose g
  663. fclose f
  664.