Advertisement
Guest User

aika msh

a guest
May 6th, 2015
442
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.70 KB | None | 0 0
  1. http://forum.xentax.com/viewtopic.php?f=16&t=5440&hilit=aika
  2.  
  3. if (heapSize < 20000000) then
  4. heapSize = 200000000 -- allow ~ 40 MB instead of just 7.5 MB. Prevents "Runtime Error: Out of scripter memory"
  5.  
  6. fname = getOpenFileName \
  7. caption:"Open Aika Model File" \
  8. types:"Aika Model File(*.msh)|*.msh" \
  9. historyCategory:"AikaObjectPresets"
  10. f = fopen fname "rb"
  11. h = getFilenameFile fname
  12. gg = substring h 1 4 + ".bon"
  13. g2 = getFilenamePath fname + gg
  14. g = fopen g2 "rb"
  15. print g
  16. total_size = getFileSize g2 / 8
  17. boneparentidarray = #()
  18. for a = 1 to total_size Do (
  19. boneparentid = readlong g
  20. realboneid = readlong g
  21. printoffset boneparentid
  22. print realboneid
  23. append boneparentidarray boneparentid
  24. )
  25. fn PrintOffset Var =
  26. (
  27. local Var = Var
  28. print ("This is the offset 0x" + (bit.intAsHex Var) as string)
  29. Var
  30. )
  31. fn PrintCount Var =
  32. (
  33. local Var = Var
  34. print ("This is the Count 0x" + (bit.intAsHex Var) as string)
  35. Var
  36. )
  37.  
  38. fn Readword fstream = (
  39. return readshort fstream #unsigned
  40. )
  41.  
  42. fn ReadFixedString bstream fixedLen =
  43. (
  44. local str = ""
  45. for i = 1 to fixedLen do
  46. (
  47. str += bit.intAsChar (ReadByte bstream #unsigned)
  48. )
  49. str
  50. )
  51.  
  52. struct Mesh_Info_Struct
  53. (
  54. Mesh_Name,vertstart,vertend,vertcount,facecount
  55. )
  56. struct Offset_Info_Struct
  57. (
  58. Section_Start,Vert_Start,Face_Start,vertsize
  59. )
  60. unk01 = readlong f
  61. unk02 = readlong f
  62. unk03 = readlong f
  63. Count01 = readlong f
  64. VertSize = readlong f
  65. unk06 = readlong f
  66. BoneCount = readlong f
  67. VertCount= readlong f
  68. FaceCount = readlong f
  69.  
  70. struct Bone_Table_Data
  71. (
  72. BoneName,BoneParentID,BoneID
  73. )
  74. BoneStart = (ftell f)
  75. fseek f (0x40 * BoneCount) #seek_cur
  76. Bone_ID_Array = #()
  77. for i = 1 to BoneCount Do (
  78. boneid = readlong f
  79. append Bone_ID_Array boneid
  80. )
  81. fseek f BoneStart #seek_set
  82. BNArr = #()
  83. for i = 1 to BoneCount Do (
  84.  
  85. m11 = readfloat f; m12 = readfloat f; m13 = readfloat f; m14 = readfloat f
  86. m21 = readfloat f; m22 = readfloat f; m23 = readfloat f; m24 = readfloat f
  87. m31 = readfloat f; m32 = readfloat f; m33 = readfloat f; m34 = readfloat f
  88. m41 = readfloat f; m42 = readfloat f; m43 = readfloat f; m44 = readfloat f
  89. tfm2 = matrix3 [m11,m12,m13] [m21,m22,m23] [m31,m32,m33] [m41,m42,m43]
  90. tfm = inverse tfm2
  91. if isvalidnode (getnodebyname ("Bone_" + Bone_ID_Array[i] as string)) == true then (
  92. append BNArr (getnodebyname ("Bone_" + Bone_ID_Array[i] as string))
  93. )
  94. if isvalidnode (getnodebyname ("Bone_" + Bone_ID_Array[i] as string)) != true then (
  95. newBone = bonesys.createbone \
  96. tfm.row4 \
  97. (tfm.row4 + 0.01 * (normalize tfm.row1)) \
  98. (normalize tfm.row3)
  99. newBone.name = ("Bone_" + Bone_ID_Array[i] as string)
  100. newBone.width = 0.03
  101. newBone.height = 0.03
  102. newBone.transform = tfm
  103. newBone.wirecolor = yellow
  104. newbone.showlinks = true
  105. newBone.setBoneEnable false 0
  106. newBone.pos.controller = TCB_position ()
  107. newBone.rotation.controller = TCB_rotation ()
  108. append BNArr newBone
  109. )
  110.  
  111. )
  112. for i = 1 to BoneCount Do (
  113. select (getnodebyname ("Bone_" + (Bone_ID_Array[i]) as string))
  114. if boneparentidarray[Bone_ID_Array[(i)]] != 0 then
  115. $.parent = (getnodebyname ("Bone_" + boneparentidarray[Bone_ID_Array[(i)] + 1] as string))
  116. boneid = readlong f
  117. print boneid
  118. print (getnodebyname ("Bone_" + boneparentidarray[Bone_ID_Array[(i)]] as string))
  119. )
  120. struct weight_data
  121. (
  122. boneids,weights
  123. )
  124. Vert_array = #()
  125. Normal_array = #()
  126. UV_array = #()
  127. Face_array = #()
  128. Weight_array = #()
  129. for a = 1 to VertCount Do (
  130. vx = readfloat f --read xyz coordinates
  131. vy = readfloat f
  132. vz = readfloat f
  133. if VertSize == 0x24 do (
  134. bone1 = readbyte f#unsigned
  135. bone2 = readbyte f#unsigned
  136. bone3 = readbyte f#unsigned
  137. bone4 = readbyte f#unsigned
  138. weight1 = readfloat f
  139. weight1 = 1.0
  140. weight2 = 0
  141. weight3 = 0
  142. weight4 = 0
  143. fseek f 0x8#seek_cur
  144. )
  145. if VertSize == 0x28 do (
  146. weight1 = readfloat f
  147. weight2 = 0
  148. bone1 = readbyte f#unsigned
  149. bone2 = readbyte f#unsigned
  150. bone3 = readbyte f#unsigned
  151. bone4 = readbyte f#unsigned
  152. weight3 = 0
  153. weight4 = 0
  154. fseek f 0xC#seek_cur
  155. )
  156. if VertSize == 0x2C do (
  157. weight1 = readfloat f
  158. weight2 = readfloat f
  159. bone1 = readbyte f#unsigned
  160. bone2 = readbyte f#unsigned
  161. bone3 = readbyte f#unsigned
  162. bone4 = readbyte f#unsigned
  163. weight3 = 0
  164. weight4 = 0
  165. fseek f 0xC#seek_cur
  166. )
  167. tu = readfloat f
  168. tv = readfloat f * -1
  169. w = (weight_data boneids:#() weights:#())
  170. maxweight = 0
  171.  
  172. if(weight1 != 0) then
  173. maxweight = maxweight + weight1
  174. if(weight2 != 0) then
  175. maxweight = maxweight + weight2
  176. if(weight3 != 0) then
  177. maxweight = maxweight + weight3
  178. if(weight4 != 0) then
  179. maxweight = maxweight + weight4
  180.  
  181. if(maxweight != 0) Do
  182. (
  183. if(weight1 != 0) Do
  184. (
  185. w1 = weight1 as float
  186. append w.boneids (bone1+1)
  187. append w.weights w1
  188. )
  189. if(weight2 != 0) Do
  190. (
  191. w2 = weight2 as float
  192. append w.boneids (bone2+1)
  193. append w.weights w2
  194. )
  195. if(weight3 != 0) Do
  196. (
  197. w3 = weight3 as float
  198. append w.boneids (bone3+1)
  199. append w.weights w3
  200. )
  201. if(weight4 != 0) Do
  202. (
  203. w4 = weight4 as float
  204. append w.boneids (bone4+1)
  205. append w.weights w4
  206. )
  207. )
  208.  
  209.  
  210. append Vert_array [vx,vy,vz] --save verts to Vert_array
  211. append UV_array [tu,tv,0] --save UVs to UV_array
  212. append Weight_array w
  213. )
  214. for i = 1 to facecount / 3 do (
  215. f1 = (readshort f) + 1 --read face indices, games are start form 0, but Max start from 1
  216. f2 = (readshort f) + 1 --so we add 1 to each index
  217. f3 = (readshort f) + 1
  218. append Face_array [f1,f2,f3] --save faces to Face_array
  219. )
  220.  
  221. msh = mesh vertices:Vert_array faces:Face_array
  222. msh.numTVerts = UV_array.count
  223. buildTVFaces msh
  224. --msh.name = Mesh_Name_array[a]
  225. for j = 1 to UV_array.count do setTVert msh j UV_array[j]
  226. for j = 1 to Face_array.count do setTVFace msh j Face_array[j]
  227. for j = 1 to Normal_array.count do setNormal msh j Normal_array[j]
  228.  
  229. max modify mode
  230. select msh
  231. skinMod = skin ()
  232. addModifier msh skinMod
  233. for i = 1 to BNArr.count do
  234. (
  235. maxbone = getnodebyname BNArr[i].name
  236. if i != BNArr.count then
  237. skinOps.addBone skinMod maxbone 0
  238. else
  239. skinOps.addBone skinMod maxbone 1
  240.  
  241. )
  242.  
  243. modPanel.setCurrentObject skinMod
  244.  
  245. for i = 1 to Weight_array.count do
  246. (
  247. w = Weight_array[i]
  248. bi = #() --bone index array
  249. wv = #() --weight value array
  250.  
  251. for j = 1 to w.boneids.count do
  252. (
  253. boneid = w.boneids[j]
  254. weight = w.weights[j]
  255. append bi boneid
  256. append wv weight
  257. )
  258.  
  259. skinOps.ReplaceVertexWeights skinMod i bi wv
  260.  
  261. )
  262. max create mode
  263.  
  264. printoffset (ftell f)
  265. fclose f
  266. fclose g
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement