home *** CD-ROM | disk | FTP | other *** search
/ Xentax forum attachments archive / xentax.7z / 14862 / TwelveSky_2_Model.7z / TwelveSky_2_Model.ms
Encoding:
Text File  |  2018-09-07  |  3.2 KB  |  134 lines

  1. if (heapSize < 20000000) then
  2.     heapSize = 200000000
  3. fname = getOpenFileName \
  4. caption:"Open .Mesh from Mesh folder" \
  5. types:"TwelveSky 2 Model (*.dat)|*.dat" \
  6. historyCategory:"TwelveSky_2_ModelObjectPresets"
  7. f = fopen fname "rb"
  8.  
  9. clearlistener()    
  10.  
  11. fn readBElong fstream = (bit.swapBytes (bit.swapBytes (readlong fstream #unsigned) 1 4) 2 3)
  12.  
  13. fn ReadBEshort fstream = (
  14. return (bit.swapBytes (readshort fstream #unsigned) 1 2)
  15. )
  16.  
  17. fn readBEfloat fstream = (bit.intAsFloat (bit.swapBytes (bit.swapBytes (readlong fstream #unsigned) 1 4) 2 3))    
  18.         
  19. fn ReadBEword fstream = (
  20. return (bit.swapBytes (readshort fstream #unsigned) 1 2)
  21. )    
  22.  
  23. fn ReadBEHalfFloat fstream = 
  24.     (
  25.     hf=readBEword fstream
  26.     sign = bit.get hf 16
  27.     exponent = (bit.shift (bit.and hf (bit.hexasint "7C00")) -10) as integer - 16
  28.     fraction = bit.and hf (bit.hexasint "03FF")
  29.     if sign==true then sign = 1 else sign = 0
  30.     exponentF = exponent + 127
  31.     outputAsFloat = bit.or (bit.or (bit.shift fraction 13) \
  32.     (bit.shift exponentF 23)) (bit.shift sign 31)
  33.     return bit.intasfloat outputasfloat*2
  34. )
  35.  
  36. fn readHalfFloat fstream = (
  37.     hf=readshort fstream #unsigned
  38.     sign = bit.get hf 16
  39.     exponent = (bit.shift (bit.and hf (bit.hexasint "7C00")) -10) as integer - 16
  40.     fraction = bit.and hf (bit.hexasint "03FF")
  41.     if sign==true then sign = 1 else sign = 0
  42.     exponentF = exponent + 127
  43.     outputAsFloat = bit.or (bit.or (bit.shift fraction 13) \
  44.     (bit.shift exponentF 23)) (bit.shift sign 31)
  45.     return bit.intasfloat outputasfloat*2
  46.     )
  47.  
  48. fn readFixedString bstream fixedLen = (
  49. local str = ""
  50. for i = 1 to fixedLen do (
  51. str += bit.intAsChar (ReadByte bstream #unsigned))
  52. str
  53. )
  54. fn ReadFixedString2 bstream fixedLen =
  55. (
  56.    local str = ""
  57.    for i = 1 to fixedLen do
  58.    (
  59.       str0 = ReadByte bstream #unsigned
  60.       if str0!=0x0 AND str0!=0x0 do str+= bit.intAsChar str0
  61.    )
  62.    str
  63. )
  64. struct weight_data
  65. (
  66.    boneids,weights
  67. )
  68. clearlistener()
  69.     
  70. filename=filenameFromPath fname
  71.  
  72. filename2=getFilenameFile filename
  73.  
  74. print ("This is FileName "+filename2)
  75.  
  76. vertArray=#()
  77. faceArray =#()
  78. UV_array=#()
  79. Weight_array=#()    
  80.  
  81. fseek f (120) #seek_set 
  82.  
  83. VertexCount=readlong f
  84. WeightCount=readlong f
  85. UnkCount=readlong f
  86. FaceCount=readlong f
  87.  
  88. Print ("Vertex Start @ 0x"+((bit.intAsHex(ftell f))as string))    
  89.  
  90. fseek f (0x28) #seek_cur    
  91.     
  92. for x =1 to VertexCount do (
  93.     
  94. getPos = ftell f + 32
  95.     
  96. vx=(readfloat f)
  97. vy=(readfloat f)
  98. vz=(readfloat f)
  99.  
  100. fseek f (12) #seek_cur
  101.         
  102. tu=readFloat f    
  103. tv=readFloat f*-1        
  104.     
  105. fseek f getPos #seek_set       
  106. append vertArray ([(vx),(vz),(vy)])    
  107. append UV_array [tu,(tv),0]    
  108. )    
  109.  
  110. for x =1 to WeightCount do (
  111. getPos = ftell f + 32
  112. fseek f getPos #seek_set       
  113. )    
  114.  
  115. Print ("Face Start @ 0x"+((bit.intAsHex(ftell f))as string))    
  116.  
  117. for y = 1 to FaceCount do ( --Faces
  118. fa=(readshort f #unsigned+ 1)
  119. fb=(readshort f #unsigned+ 1)
  120. fc=(readshort f #unsigned+ 1)
  121. append faceArray [fc,fb,fa] 
  122. )    
  123.  
  124. Print ("Face End @ 0x"+((bit.intAsHex(ftell f))as string))    
  125.  
  126. msh = mesh vertices:vertArray faces:faceArray
  127. msh.name=filename2
  128.  
  129. msh.numTVerts = UV_array.count
  130. buildTVFaces msh
  131. for j = 1 to UV_array.count do setTVert msh j UV_array[j]
  132. for j = 1 to faceArray.count do setTVFace msh j faceArray[j]    
  133.  
  134. fclose f