home *** CD-ROM | disk | FTP | other *** search
/ Xentax forum attachments archive / xentax.7z / 7756 / SwordsMan_Script.7z / SwordsMan_Bones.ms next >
Encoding:
Text File  |  2014-08-24  |  3.2 KB  |  102 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 .bon from Bones folder" \
  5. types:"SKI Bones (*.bon)|*.bon" \
  6. historyCategory:"SKIObjectPresets"
  7. g = fopen gname "rb"
  8.  
  9. clearlistener()
  10. fn readHalfFloat fstream = (
  11.     hf=readshort fstream #unsigned
  12.     sign = bit.get hf 16
  13.     exponent = (bit.shift (bit.and hf (bit.hexasint "7C00")) -10) as integer - 16
  14.     fraction = bit.and hf (bit.hexasint "03FF")
  15.     if sign==true then sign = 1 else sign = 0
  16.     exponentF = exponent + 127
  17.     outputAsFloat = bit.or (bit.or (bit.shift fraction 13) \
  18.     (bit.shift exponentF 23)) (bit.shift sign 31)
  19.     return bit.intasfloat outputasfloat*2
  20.     )
  21. fn readFixedString bstream fixedLen = (
  22. local str = ""
  23. for i = 1 to fixedLen do (
  24. str += bit.intAsChar (ReadByte bstream #unsigned))
  25. str
  26. )
  27. struct weight_data
  28. (
  29.     boneids,weights
  30. )
  31. clearlistener()
  32.  
  33. fseek g 0x0 #seek_set
  34. MOXBEKSA=readFixedString g 8
  35. Version = ReadLong g
  36. numBones = ReadLong g
  37. numTotalBones = ReadLong g
  38. Unk1 = ReadLong g
  39. numTexture = ReadLong g
  40. numMaterial = ReadLong g
  41. CountLong = ReadLong g
  42. Unk = ReadLong g
  43. fseek g 0x3C #seek_cur
  44.  
  45. Print ("Info End @ 0x"+((bit.intAsHex(ftell g))as string))
  46.     
  47. BNArr = #()
  48.     
  49. for a = 1 to numTotalBones do (
  50.  
  51. BoneNameSize = ReadLong g    
  52. BoneName = readFixedString g BoneNameSize
  53. BoneId = ReadLong g         
  54. BoneParent = ReadLong g
  55. BoneChild = ReadLong g     
  56. LongCount = ReadLong g     
  57.     
  58. c11 = ReadFloat g; c12 = ReadFloat g; c13 = ReadFloat g; c14 = ReadFloat g    
  59. c21 = ReadFloat g; c22 = ReadFloat g; c23 = ReadFloat g; c24 = ReadFloat g    
  60. c31 = ReadFloat g; c32 = ReadFloat g; c33 = ReadFloat g; c34 = ReadFloat g
  61. c41 = ReadFloat g; c42 = ReadFloat g; c43 = ReadFloat g; c44 = ReadFloat g    
  62.     
  63. d11 = ReadFloat g; d12 = ReadFloat g; d13 = ReadFloat g; d14 = ReadFloat g    
  64. d21 = ReadFloat g; d22 = ReadFloat g; d23 = ReadFloat g; d24 = ReadFloat g    
  65. d31 = ReadFloat g; d32 = ReadFloat g; d33 = ReadFloat g; d34 = ReadFloat g
  66. d41 = ReadFloat g; d42 = ReadFloat g; d43 = ReadFloat g; d44 = ReadFloat g    
  67.     
  68. for x = 1 to LongCount do (
  69. Unk1 = Readlong g  
  70. )        
  71.  
  72. tfm = matrix3 [d11,d12,d13] [d21,d22,d23] [d31,d32,d33] ([d41,d42,d43]*100)    
  73. tfm2 = matrix3 [c11,c12,c13] [c21,c22,c23] [c31,c32,c33] [c41,c42,c43]    
  74.  
  75. if (BoneParent != -1) do (
  76. tfm2 = tfm2 * BNArr[(BoneParent + 1)].objecttransform    
  77. )    
  78. newBone = bonesys.createbone    \
  79.                   tfm.row4    \
  80.                   (tfm.row4 + 0.01 * (normalize tfm.row1)) \
  81.                   (normalize tfm.row3)
  82.             newBone.name = BoneName
  83.             newBone.width  = 0.01
  84.             newBone.height = 0.01
  85.             newBone.transform =  inverse tfm
  86.             newBone.setBoneEnable false 0
  87.             newBone.wirecolor = white
  88.             newbone.showlinks = true
  89.             newBone.pos.controller      = TCB_position ()
  90.             newBone.rotation.controller = TCB_rotation ()    
  91.  if (BoneParent != -1) then
  92.  newBone.parent = BNArr[(BoneParent)+1]                          
  93. append BNArr newBone                      
  94. )    
  95.  
  96. rootRT = dummy name:"Main_Root" boxsize:[.1,.1,.1]
  97. for b in BNArr where b.parent==undefined do b.parent = rootRT
  98. rootRT.transform = (matrix3 [-1,0,0] [0,0,1] [0,-1,0] [0,0,0])
  99.  
  100. Print ("Bone End @ 0x"+((bit.intAsHex(ftell g))as string))
  101.  
  102. fclose g