home *** CD-ROM | disk | FTP | other *** search
/ Xentax forum attachments archive / xentax.7z / 8712 / Red_Faction.7z / Red_Faction.ms
Encoding:
Text File  |  2015-02-20  |  2.7 KB  |  113 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. gname = getOpenFileName \
  4. caption:"Open .bone from Mesh folder" \
  5. types:"Red Faction Info (*.ccmesh_pc)|*.ccmesh_pc" \
  6. historyCategory:"RedFactionObjectPresets"
  7. g = fopen gname "rb"
  8. fname = getOpenFileName \
  9. caption:"Open .mesh from Mesh folder" \
  10. types:"Red Faction Models (*.gcmesh_pc)|*.gcmesh_pc" \
  11. historyCategory:"RedFactionObjectPresets"
  12. f = fopen fname "rb"
  13.  
  14. clearlistener()
  15.  
  16. fn readBElong fstream = (bit.swapBytes (bit.swapBytes (readlong fstream #unsigned) 1 4) 2 3)
  17.  
  18. fn readBEfloat fstream = (bit.intAsFloat (bit.swapBytes (bit.swapBytes (readlong fstream #unsigned) 1 4) 2 3))    
  19.  
  20. fn ReadHalfFloat fstream = 
  21.     (
  22.     hf=readshort fstream
  23.     sign = bit.get hf 16
  24.     exponent = (bit.shift (bit.and hf (bit.hexasint "7C00")) -10) as integer - 16
  25.     fraction = bit.and hf (bit.hexasint "03FF")
  26.     if sign==true then sign = 1 else sign = 0
  27.     exponentF = exponent + 127
  28.     outputAsFloat = bit.or (bit.or (bit.shift fraction 13) \
  29.     (bit.shift exponentF 23)) (bit.shift sign 31)
  30.     return bit.intasfloat outputasfloat*2
  31. )
  32.  
  33. fn readFixedString bstream fixedLen = (
  34. local str = ""
  35. for i = 1 to fixedLen do (
  36. str += bit.intAsChar (ReadByte bstream #unsigned))
  37. str
  38. )
  39. struct weight_data
  40. (
  41.     boneids,weights
  42. )
  43.  
  44. clearlistener()
  45.  
  46. fseek g (0x9C) #seek_set
  47. VertCount=readlong g
  48. fseek g (0x1C) #seek_cur
  49. VerOffset=readlong g
  50. FaceCount=readlong g
  51.  
  52. fclose g
  53.  
  54. vertArray = #()
  55. faceArray = #()
  56. UV_array = #()
  57. Weight_array=#()    
  58.  
  59. fseek f (0x10) #seek_set
  60.  
  61. StartDirection = 1
  62. f1 = readshort f #unsigned +1
  63. f2 = readshort f #unsigned +1
  64. FaceDirection = StartDirection
  65. for i = 3 to FaceCount do (   
  66. f3 = (ReadShort f)
  67. if (f3==0xFFFF) then (
  68. f1 = readshort f #unsigned +1
  69. f2 = readshort f #unsigned +1
  70. FaceDirection = StartDirection 
  71. ) else (
  72. f3 += (1)
  73. FaceDirection *= -1
  74. if (f1!=f2)AND(f2!=f3)AND(f3!=f1) then (
  75. if FaceDirection > 0 then append Facearray [f1,f2,f3]
  76. else append Facearray [f1,f3,f2]
  77. )
  78. f1 = f2
  79. f2 = f3
  80.  
  81. fseek f (VerOffset) #seek_set
  82.  
  83. Print ("Vertex Start @ 0x"+((bit.intAsHex(ftell f))as string))
  84.  
  85. for x = 1 to VertCount do (
  86.     
  87. vx = ReadFloat f
  88. vy = ReadFloat f
  89. vz = ReadFloat f    
  90.     
  91. fseek f (0x10) #seek_cur
  92.     
  93. tu = (ReadShort f /1024.00)
  94. tv = (ReadShort f /1024.00)*-1    
  95.     
  96. unk00 = ReadShort f
  97. unk01 = ReadShort f
  98.     
  99. append UV_array [tu,tv,0]        
  100. append vertArray ([-vx,-vz,vy]*100)
  101. )    
  102.  
  103. msh = mesh vertices:vertArray faces:faceArray
  104. msh.name = ("Model")
  105. msh.numTVerts = UV_array.count
  106. buildTVFaces msh
  107. for j = 1 to UV_array.count do setTVert msh j UV_array[j]
  108. for j = 1 to faceArray.count do setTVFace msh j faceArray[j]
  109. msh.wirecolor = (color 230 200 210)    
  110.  
  111. fclose f