home *** CD-ROM | disk | FTP | other *** search
/ Xentax forum attachments archive / xentax.7z / 10885 / DOOM.7z / DOOM_bmodel.ms < prev   
Encoding:
Text File  |  2016-04-18  |  2.8 KB  |  132 lines

  1. if (heapSize < 20000000) then
  2.     heapSize = 200000000
  3. fname = getOpenFileName \
  4. caption:"Open .bmodel from Mesh folder" \
  5. types:"DOOM 2016 Static Meshes (*.bmodel)|*.bmodel" \
  6. historyCategory:"DOOM_SObjectPresets"
  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, FaceStride, UVType
  68. )    
  69.     
  70. struct Mesh_Info_Struct2
  71. (
  72. VertStride, VertOff, WStride, WOff     
  73. )    
  74.  
  75. clearlistener()
  76.  
  77. --------------------------------------------------------------------------------------------    
  78.     
  79. FaceArray=#()
  80. vertArray=#()
  81. UV_array=#()
  82. Weight_array=#()    
  83.  
  84. fseek f 0x8 #seek_set    
  85. MeshCount=readBElong f
  86. NameMSHSize=readlong f    
  87. NameMSH = readFixedString f NameMSHSize
  88.  
  89. fseek f 0x10 #seek_cur
  90.  
  91. VertCount=readBElong f
  92. FaceCount=readBElong f
  93. UnkCount=readBElong f
  94.  
  95. fseek f 0x28 #seek_cur
  96.  
  97. Print ("Mesh Info Start @ 0x"+((bit.intAsHex(ftell f))as string))    
  98.         
  99. for x = 1 to VertCount do(
  100. getPos = ftell f + 48
  101.     
  102. vx=readBEfloat f
  103. vy=readBEfloat f
  104. vz=readBEfloat f
  105.  
  106. tu=readBEfloat f
  107. tv=readBEfloat f*-1    
  108.     
  109. fseek f getPos #seek_set        
  110. append VertArray([vy,-vx,vz])
  111. append UV_array[tu,tv,0]    
  112. )
  113.  
  114. Print ("Vertex End @ 0x"+((bit.intAsHex(ftell f))as string))    
  115.  
  116. for x = 1 to FaceCount/3 do (
  117.  
  118. fa=(readBEshort f +1) 
  119. fb=(readBEshort f +1)
  120. fc=(readBEshort f +1)
  121.     
  122. append FaceArray[fc,fb,fa]
  123. )
  124.  
  125. msh = mesh vertices:vertArray faces:faceArray
  126. msh.name=NameMSH
  127. msh.numTVerts = UV_array.count
  128. buildTVFaces msh
  129. for j = 1 to UV_array.count do setTVert msh j UV_array[j]
  130. for j = 1 to faceArray.count do setTVFace msh j faceArray[j]
  131.  
  132. fclose f