home *** CD-ROM | disk | FTP | other *** search
/ Xentax forum attachments archive / xentax.7z / 7769 / DSector.7z / DSector_Bones.ms next >
Encoding:
Text File  |  2014-09-04  |  3.1 KB  |  113 lines

  1. if (heapSize < 20000000) then
  2.     heapSize = 200000000
  3. gname = getOpenFileName \
  4. caption:"Open .x.1 from Bones folder" \
  5. types:"DSector_Bones (*.x.1)|*.x.1" \
  6. historyCategory:"DSectorObjectPresets"
  7. g = fopen gname "rb"
  8. fname = getOpenFileName \
  9. caption:"Open .fbx from Mesh folder" \
  10. types:"DSector (*.x.1)|*.x.1" \
  11. historyCategory:"DSectorObjectPresets"
  12. f = fopen fname "rb"
  13.  
  14. fn readHalfFloat fstream = (
  15.     hf=readshort fstream #unsigned
  16.     sign = bit.get hf 16
  17.     exponent = (bit.shift (bit.and hf (bit.hexasint "7C00")) -10) as integer - 16
  18.     fraction = bit.and hf (bit.hexasint "03FF")
  19.     if sign==true then sign = 1 else sign = 0
  20.     exponentF = exponent + 127
  21.     outputAsFloat = bit.or (bit.or (bit.shift fraction 13) \
  22.     (bit.shift exponentF 23)) (bit.shift sign 31)
  23.     return bit.intasfloat outputasfloat*2
  24.     )
  25.  
  26. fn ReadFixedString bstream fixedLen =
  27. (
  28.     local str = ""
  29.     for i = 1 to fixedLen do
  30.     (
  31.         str += bit.intAsChar (ReadByte bstream #unsigned)
  32.     )
  33.     str
  34. )    
  35.  
  36. clearlistener()
  37.  
  38. struct weight_data
  39. (
  40.    boneids,weights
  41. )
  42. struct face_info_struct
  43. (
  44. FacePos,FaceCount
  45. )
  46. clearlistener()
  47.  
  48. BoneNamesArray = #()
  49. BoneNamesArray1 = #()
  50. boneparent_array = #()
  51. UsedBoneCountArray = #()
  52. FaceArray = #()
  53. BNArr1 = #()
  54.  
  55. fseek g 0xb #seek_cur
  56. modelPathS = readlong g
  57. modelPath = ReadFixedString g modelPathS
  58. fseek g 0x8 #seek_cur
  59. materialS = readlong g
  60. materialname = ReadFixedString g materialS
  61. Print ("Last Read @ 0x"+((bit.intAsHex(ftell g))as string))
  62. fseek g 0x28 #seek_cur
  63. BoneCount = readlong g
  64. for a = 1 to BoneCount do (
  65. BoneNameSize = readlong g    
  66. BoneName = ReadFixedString g BoneNameSize    
  67. append BoneNamesArray BoneName
  68. )    
  69.  
  70. Print ("Last Read @ 0x"+((bit.intAsHex(ftell g))as string))
  71.  
  72.     
  73. fseek f 0x0 #seek_set    
  74. BNArr1 = #()
  75. for a = 1 to BoneCount do ( --second bones section
  76. c11 = Readfloat f; c12 = Readfloat f; c13 = Readfloat f; c14 = Readfloat f
  77. c21 = Readfloat f; c22 = Readfloat f; c23 = Readfloat f; c24 = Readfloat f
  78. c31 = Readfloat f; c32 = Readfloat f; c33 = Readfloat f; c34 = Readfloat f
  79. c41 = Readfloat f; c42 = Readfloat f; c43 = Readfloat f; c44 = Readfloat f
  80.  
  81. tfm2 = matrix3 [c11,c12,c13] [c21,c22,c23] [c31,c32,c33] ([c41,c42,c43]*100)    
  82.  
  83.  
  84. if (getNodeByName BoneNamesArray[a]) != undefined do (
  85. append BNArr1 (getNodeByName  BoneNamesArray[a])
  86. )
  87. if (getNodeByName  BoneNamesArray[a]) == undefined do (
  88.  
  89.     newBone2 = bonesys.createbone    \
  90.                   tfm2.row4    \
  91.                   (tfm2.row4 + 0.01 * (normalize tfm2.row1)) \
  92.                   (normalize tfm2.row3)
  93.             newBone2.name = BoneNamesArray[a]          
  94.             newBone2.width  = 0.01
  95.             newBone2.height = 0.01
  96.             newBone2.transform = inverse tfm2          
  97.             newBone2.setBoneEnable false 0
  98.             newBone2.wirecolor = white
  99.             newbone2.showlinks = true
  100.             newBone2.pos.controller      = TCB_position ()
  101.             newBone2.rotation.controller = TCB_rotation ()                          
  102. append BNArr1 newBone2
  103. )    
  104. )
  105.  
  106. Print ("Last Read @ 0x"+((bit.intAsHex(ftell f))as string))
  107.     
  108. rootRT = dummy name:"Main_Root" boxsize:[.1,.1,.1]
  109. for b in BNArr1 where b.parent==undefined do b.parent = rootRT
  110. rootRT.transform = (matrix3 [-1,0,0] [0,0,1] [0,-1,0] [0,0,0])    
  111.  
  112. fclose g    
  113. fclose f