home *** CD-ROM | disk | FTP | other *** search
/ Xentax forum attachments archive / xentax.7z / 10789 / DOOM.7z / DOOM_bmd6model.ms next >
Encoding:
Text File  |  2016-04-18  |  4.1 KB  |  196 lines

  1. if (heapSize < 20000000) then
  2.     heapSize = 200000000
  3. fname = getOpenFileName \
  4. caption:"Open .bmd6model from Mesh folder" \
  5. types:"DOOM 2016 Rigged Meshes (*.bmd6model)|*.bmd6model" \
  6. historyCategory:"DOOM_RObjectPresets"
  7. f = fopen fname "rb"
  8.  
  9. clearlistener()    
  10.  
  11. fn ReadBEword fstream = (
  12. return (bit.swapBytes (readshort fstream #unsigned) 1 2)
  13. )
  14.  
  15. fn readBEshort fstream = (
  16. short = readshort fstream #unsigned
  17. short = bit.swapBytes short 1 2
  18. return short
  19. )
  20.  
  21. fn ReadBEfloat fstream = (
  22.     fpt=readfloat fstream
  23.     itger = bit.floatAsInt fpt
  24.     hih = bit.intashex itger
  25.     while hih.count < 8 do hih = "0" + hih
  26.     shn = (substring hih 7 2) + \
  27.     (substring hih 5 2) + \
  28.     (substring hih 3 2) + \
  29.     (substring hih 1 2)
  30.     bit.intAsFloat (bit.hexasint shn)
  31.     )
  32.  
  33. fn readBElong fstream = (
  34. long = readlong fstream
  35. long = bit.swapBytes long 1 4
  36. long = bit.swapBytes long 2 3
  37. return long
  38. )
  39.  
  40. fn ReadBEHalfFloat fstream = 
  41.     (
  42.     hf=ReadBEword fstream
  43.     sign = bit.get hf 16
  44.     exponent = (bit.shift (bit.and hf (bit.hexasint "7C00")) -10) as integer - 16
  45.     fraction = bit.and hf (bit.hexasint "03FF")
  46.     if sign==true then sign = 1 else sign = 0
  47.     exponentF = exponent + 127
  48.     outputAsFloat = bit.or (bit.or (bit.shift fraction 13) \
  49.     (bit.shift exponentF 23)) (bit.shift sign 31)
  50.     return bit.intasfloat outputasfloat*2
  51. )
  52.  
  53. fn readFixedString bstream fixedLen = (
  54. local str = ""
  55. for i = 1 to fixedLen do (
  56. str += bit.intAsChar (ReadByte bstream #unsigned))
  57. str
  58. )
  59.  
  60. struct weight_data
  61. (
  62.    boneids,weights
  63. )
  64.     
  65. struct Mesh_Info_Struct
  66. (
  67. VertCount, FaceCount
  68. )    
  69.     
  70. clearlistener()
  71.  
  72. --------------------------------------------------------------------------------------------    
  73.     
  74. fseek f 0x14 #seek_set    
  75. DataCount=readBEshort f
  76.  
  77. fseek f 0x24 #seek_set    
  78. OffData=readBElong f
  79.  
  80. fseek f OffData #seek_set    
  81.  
  82. VertOff=#()    
  83. MeshNameOff=#()     
  84. FaceOff=#() 
  85. MeshInfoOff=#() 
  86. for i=1 to DataCount do (
  87. getPos = ftell f + 24
  88. Unk_00=readBElong f
  89. DataOffStart=readBElong f
  90. Unk_01=readBElong f
  91. DataSize=readBElong f
  92. Hash=readBElong f
  93. SecId=(readBEshort f+1)
  94. if SecId==9 then (
  95. append MeshNameOff DataOffStart    
  96. )        
  97. if SecId==10 then (
  98. append MeshInfoOff DataOffStart    
  99. )        
  100. if SecId==13 then (
  101. append VertOff DataOffStart        
  102. )    
  103. if SecId==14 then (
  104. append FaceOff DataOffStart    
  105. )    
  106. fseek f getPos #seek_set    
  107. )    
  108.  
  109. fseek f MeshNameOff[1] #seek_set
  110.  
  111. Print ("Mesh Names Start @ 0x"+((bit.intAsHex(ftell f))as string))    
  112.  
  113. MeshCount=readlong f
  114. StringSize=readlong f
  115.  
  116. MeshNameArray=#()
  117. for i=1 to MeshCount do (
  118. MeshName=readstring f    
  119. append MeshNameArray MeshName    
  120. )    
  121.  
  122. fseek f MeshInfoOff[1] #seek_set
  123.  
  124. Print ("Mesh Info Start @ 0x"+((bit.intAsHex(ftell f))as string))    
  125.  
  126. Mesh_Info_Array=#()
  127. for i=1 to MeshCount do (
  128. getPos = ftell f + 52    
  129. fseek f 0x1C #seek_cur
  130. VertCount=readlong f
  131. FaceCount=readlong f    
  132. fseek f getPos #seek_set        
  133. append Mesh_Info_Array (Mesh_Info_Struct VertCount:VertCount FaceCount:FaceCount )    
  134. )    
  135.  
  136. print Mesh_Info_Array 
  137.  
  138. VOff=VertOff[1]     
  139. FOff=FaceOff[1]    
  140.  
  141. for i=1 to MeshCount do (
  142.     
  143. FaceArray=#()
  144. vertArray=#()
  145. UV_array=#()
  146. Weight_array=#()        
  147.     
  148. fseek f VOff #seek_set    
  149.  
  150. Print ("Vertex Start @ 0x"+((bit.intAsHex(ftell f))as string))    
  151.         
  152. for x = 1 to Mesh_Info_Array[i].VertCount do(
  153. getPos = ftell f + 48
  154.     
  155. vx=readfloat f
  156. vy=readfloat f
  157. vz=readfloat f
  158.  
  159. tu=readfloat f
  160. tv=readfloat f*-1    
  161.     
  162. fseek f getPos #seek_set        
  163. append VertArray([vy,-vx,vz])
  164. append UV_array[tu,tv,0]    
  165. )
  166.  
  167. Print ("Vertex End @ 0x"+((bit.intAsHex(ftell f))as string))
  168.     
  169. VOff+=(Mesh_Info_Array[i].VertCount*48)    
  170.         
  171. fseek f FOff #seek_set        
  172.     
  173. Print ("Face Start @ 0x"+((bit.intAsHex(ftell f))as string))    
  174.     
  175. for x = 1 to Mesh_Info_Array[i].FaceCount do (
  176.  
  177. fa=(readshort f +1) 
  178. fb=(readshort f +1)
  179. fc=(readshort f +1)
  180.     
  181. append FaceArray[fc,fb,fa]
  182. )
  183.  
  184. Print ("Face End @ 0x"+((bit.intAsHex(ftell f))as string))
  185.  
  186. FOff+=(Mesh_Info_Array[i].FaceCount*6)
  187.  
  188. msh = mesh vertices:vertArray faces:faceArray
  189. msh.name=MeshNameArray[i]
  190. msh.numTVerts = UV_array.count
  191. buildTVFaces msh
  192. for j = 1 to UV_array.count do setTVert msh j UV_array[j]
  193. for j = 1 to faceArray.count do setTVFace msh j faceArray[j]
  194. )
  195.  
  196. fclose f