home *** CD-ROM | disk | FTP | other *** search
/ Xentax forum attachments archive / xentax.7z / 13476 / IronSight.7z / IronSight.ms
Encoding:
Text File  |  2017-10-21  |  5.9 KB  |  248 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:" (*.msh)|*.msh" \
  6. historyCategory:"ISObjectPresets"
  7. f = fopen fname "rb"
  8.  
  9. clearlistener()
  10.  
  11. fn ReadHalfFloat fstream = 
  12.     (
  13.     hf=readshort fstream
  14.     sign = bit.get hf 16
  15.     exponent = (bit.shift (bit.and hf (bit.hexasint "7C00")) -10) as integer - 16
  16.     fraction = bit.and hf (bit.hexasint "03FF")
  17.     if sign==true then sign = 1 else sign = 0
  18.     exponentF = exponent + 127
  19.     outputAsFloat = bit.or (bit.or (bit.shift fraction 13) \
  20.     (bit.shift exponentF 23)) (bit.shift sign 31)
  21.     return bit.intasfloat outputasfloat*2
  22. )
  23.  
  24. fn readFixedString bstream fixedLen = (
  25. local str = ""
  26. for i = 1 to fixedLen do (
  27. str += bit.intAsChar (ReadByte bstream #unsigned))
  28. str
  29. )
  30. struct weight_data
  31. (
  32.     boneids,weights
  33. )
  34. struct Mesh_Info_Struct
  35. (
  36. VertexCount, VertexStart, FaceCount, FaceStart, VertexId, UsedBones, UsedBonesStart, VertexEnd
  37. )        
  38.  
  39. clearlistener()
  40.  
  41. fseek f 0x24 #seek_set
  42. BoneCount=readlong f
  43.  
  44. Print ("Bones Start @ 0x"+((bit.intAsHex(ftell f))as string))    
  45.  
  46. BNArr=#()    
  47. for a = 1 to BoneCount do (
  48. getPos = ftell f + 56    
  49. BoneHash = readlong f #unsigned
  50. Unk=readlong f    
  51. BoneParent    = readlong f 
  52. a11 = Readfloat f; a12 = Readfloat f; a13 = Readfloat f
  53. a21 = Readfloat f; a22 = Readfloat f; a23 = Readfloat f; a24 = Readfloat f    
  54. fseek f getPos #seek_set    
  55.     
  56. tfm = (quat a21 a22 a23 a24) as matrix3
  57. tfm.row4 = (([a11,a12,a13]))
  58.              
  59.     newBone = bonesys.createbone    \
  60.                   tfm.row4    \
  61.                   (tfm.row4 + 0.01 * (normalize tfm.row1)) \
  62.                   (normalize tfm.row3)
  63.             newBone.name = a as string
  64.             newBone.width  = 0.01
  65.             newBone.height = 0.01
  66.             newBone.transform = tfm          
  67.             newBone.setBoneEnable false 0
  68.             newBone.wirecolor = white
  69.             newbone.showlinks = true
  70.             newBone.pos.controller      = TCB_position ()
  71.             newBone.rotation.controller = TCB_rotation ()
  72. if (boneparent != -1) then
  73.  newBone.parent = BNArr[(boneparent + 1)]                              
  74. append BNArr newBone
  75. )    
  76.  
  77. Print ("Bones End @ 0x"+((bit.intAsHex(ftell f))as string))    
  78.     
  79. rootRT = dummy name:"Main_Root" boxsize:[.1,.1,.1]
  80. for b in BNArr where b.parent==undefined do b.parent = rootRT
  81. rootRT.transform = (matrix3 [-1,0,0] [0,0,1] [0,-1,0] [0,0,0])        
  82.  
  83. readlong f
  84. readlong f
  85. readlong f
  86. MeshCount=readlong f
  87. MatCount=readlong f    
  88.     
  89. for i=1 to MeshCount do (
  90.     
  91. readlong f
  92. readlong f
  93. WShift=readlong f
  94. VSecSize=readlong f
  95.     
  96. vertArray = #()
  97. Facearray = #()    
  98. UV_array = #()
  99. Weight_array=#()
  100.     
  101. if WShift==2 then     
  102. for x = 1 to VSecSize/28 do (
  103. getPos = ftell f + 28
  104. vx = ReadFloat f
  105. vy = ReadFloat f
  106. vz = ReadFloat f
  107.     
  108. tu=ReadShort f    
  109. tv=1.0-ReadShort f    
  110.     
  111. weight1 = 1.0
  112.     
  113. bone1 = 0
  114.     
  115. w = (weight_data boneids:#() weights:#())
  116. maxweight = 0
  117.     
  118. if(weight1 != 0) then
  119.    maxweight = maxweight + weight1
  120.  
  121. if(maxweight != 0) then (
  122.       if(weight1 != 0) then (
  123.          w1 = weight1 as float
  124.          append w.boneids (bone1 + 1)
  125.          append w.weights (w1 / 255.0)
  126.       )
  127.    )
  128. append Weight_array w     
  129. fseek f getPos #seek_set        
  130. append vertArray [-vx,-vz,vy]
  131. append UV_array ([tu,tv,0]/1024.0)        
  132. )        
  133.  
  134. if WShift==3 then     
  135. for x = 1 to VSecSize/32 do (
  136. getPos = ftell f + 32
  137. vx = ReadFloat f
  138. vy = ReadFloat f
  139. vz = ReadFloat f
  140.     
  141. tu=ReadShort f    
  142. tv=1.0-ReadShort f    
  143.  
  144. fseek f 0x8 #seek_cur
  145.     
  146. weight3 = readbyte f #unsigned
  147. weight2 = readbyte f #unsigned
  148. weight1 = readbyte f #unsigned    
  149. weight4 =readbyte f #unsigned    
  150.     
  151. bone1 = (readbyte f #unsigned)/WShift
  152. bone2 = (readbyte f #unsigned)/WShift
  153. bone3 = (readbyte f #unsigned)/WShift
  154. bone4 = (readbyte f #unsigned)/WShift
  155.     
  156. w = (weight_data boneids:#() weights:#())
  157. maxweight = 0
  158.     
  159. if(weight1 != 0) then
  160.    maxweight = maxweight + weight1
  161. if(weight2 != 0) then
  162.    maxweight = maxweight + weight2
  163. if(weight3 != 0) then
  164.    maxweight = maxweight + weight3
  165. if(weight4 != 0) then
  166.    maxweight = maxweight + weight4
  167.  
  168. if(maxweight != 0) then (
  169.       if(weight1 != 0) then (
  170.          w1 = weight1 as float
  171.          append w.boneids (bone1 + 1)
  172.          append w.weights (w1 / 255.0)
  173.       )
  174.       if(weight2 != 0) then (
  175.          w2 = weight2 as float
  176.          append w.boneids (bone2 + 1)
  177.          append w.weights (w2 / 255.0)
  178.       )
  179.       if(weight3 != 0) then (
  180.          w3 = weight3 as float
  181.          append w.boneids (bone3 + 1)
  182.          append w.weights (w3 / 255.0)
  183.       )
  184.       if(weight4 != 0) then (
  185.          w4 = weight4 as float
  186.          append w.boneids (bone4 + 1)
  187.          append w.weights (w4 / 255.0)
  188.       )      
  189.    )
  190. append Weight_array w     
  191. fseek f getPos #seek_set        
  192. append vertArray [-vx,-vz,vy]
  193. append UV_array ([tu,tv,0]/1024.0)        
  194. )    
  195.  
  196. Print ("Face Start @ 0x"+((bit.intAsHex(ftell f))as string))    
  197.     
  198. FSecSize=readlong f
  199.  
  200. for x=1 to     (FSecSize/6) do (    
  201. fa=readshort f #unsigned +1
  202. fb=readshort f #unsigned +1
  203. fc=readshort f #unsigned +1
  204. append faceArray [fc,fb,fa]    
  205. )    
  206.  
  207. Print ("Face End @ 0x"+((bit.intAsHex(ftell f))as string))    
  208.  
  209. msh = mesh vertices:vertArray faces:faceArray
  210. msh.numTVerts = UV_array.count
  211. msh.name=("IronSight MMO mesh: "+i as string)    
  212. buildTVFaces msh
  213. for j = 1 to UV_array.count do setTVert msh j UV_array[j]
  214. for j = 1 to faceArray.count do setTVFace msh j faceArray[j]
  215.     
  216. max modify mode
  217. select msh
  218. skinMod = skin ()
  219. addModifier msh skinMod
  220. for i = 1 to BNArr.count do
  221. (  
  222.     maxbone = BNArr[i]
  223.     if i != BNArr.count then 
  224.         skinOps.addBone skinMod maxbone 0
  225.     else
  226.         skinOps.addBone skinMod maxbone 1
  227. )
  228. modPanel.setCurrentObject skinMod
  229. for i = 1 to (vertArray.count) do (
  230.    w = Weight_array[i]
  231.    bi = #() --bone index array
  232.    wv = #() --weight value array
  233.    
  234.    for j = 1 to w.boneids.count do
  235.    (
  236.       boneid = w.boneids[j]
  237.       weight = w.weights[j]
  238.       append bi boneid
  239.       append wv weight
  240.    )   
  241.    
  242.    skinOps.ReplaceVertexWeights skinMod i bi wv
  243.    
  244. )
  245. )
  246.  
  247. fclose f
  248.