Advertisement
Guest User

Untitled

a guest
Jun 3rd, 2014
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.28 KB | None | 0 0
  1.  
  2.  
  3. fn FindSkinModifier obj =
  4. (
  5. local skinModifier = undefined
  6.  
  7. for i = 1 to obj.modifiers.count do
  8. (
  9. if obj.modifiers[i].Name == "Skin" then
  10. (
  11. skinModifier = obj.modifiers[i]
  12.  
  13. max modify mode
  14. modPanel.setCurrentObject skinModifier
  15.  
  16. exit
  17. )
  18. )
  19.  
  20. return skinModifier
  21. )
  22.  
  23. fn WriteVector3 vec3 =
  24. (
  25. -- write vertex according to X - right, Y - up, Z - forward
  26. cacheWriteFloat file ( vec3.x)
  27. cacheWriteFloat file ( vec3.z)
  28. cacheWriteFloat file (-vec3.y)
  29. )
  30.  
  31. fn WriteQuaternion quaternion =
  32. (
  33. quaternion = quaternion * Z2YRotation
  34.  
  35. cacheWriteFloat file quaternion.x
  36. cacheWriteFloat file quaternion.y
  37. cacheWriteFloat file quaternion.z
  38. cacheWriteFloat file quaternion.w
  39. )
  40.  
  41. fn WriteFace face =
  42. (
  43. cacheWriteLong file (face.x - 1)
  44. cacheWriteLong file (face.y - 1)
  45. cacheWriteLong file (face.z - 1)
  46. )
  47.  
  48. fn WriteTextureCoordinates texCoord =
  49. (
  50. cacheWriteFloat file texCoord.x
  51. cacheWriteFloat file (1 - texCoord.y)
  52. )
  53.  
  54. fn WriteNodePositionRotation obj =
  55. (
  56. -- write position
  57. WriteVector3 ( obj.position )
  58.  
  59. -- write rotation
  60. WriteQuaternion ( obj.rotation )
  61. )
  62.  
  63. fn GetTextureFileNamesArray obj =
  64. (
  65. -- collect textures
  66. local textures = #()
  67. local currentMaterial = obj.material
  68.  
  69. if( currentMaterial != undefined ) then
  70. (
  71. subMaterials = getNumSubmtls currentMaterial
  72.  
  73. if (subMaterials == 0) then
  74. (
  75. if( currentMaterial.diffuseMap != undefined ) then
  76. append textures ( FileNameFromPath currentMaterial.diffuseMap.filename )
  77. )
  78. else
  79. (
  80. for i = 1 to subMaterials do
  81. (
  82. local subMaterial = getSubmtl currentMaterial i
  83.  
  84. if( subMaterial.diffuseMap != undefined ) then
  85. append textures ( FileNameFromPath subMaterial.diffuseMap.filename )
  86. )
  87. )
  88. )
  89.  
  90. return textures
  91. )
  92.  
  93. rollout unnamedRollout "Untitled" width:160 height:96
  94. (
  95. button btn1 "Button" pos:[8,8] width:144 height:48
  96. on btn1 pressed do
  97. (
  98. outputFileName = getSaveFileName caption:"Scene Exporter" types:"Scene Files(*.scene)|*.scene" initialDir:(getDir #export) historyCategory:"ExportSceneFiles"
  99.  
  100. if( outputFileName == undefined ) then
  101. break
  102.  
  103. global Z2YRotation = rotateXMatrix -90
  104. global file = fopen outputFileName "wb"
  105.  
  106. -- cache functions - according to MAXScript Help it must save a lot of time, but it's not :/
  107. global polyop_getVert = getVert
  108. global polyop_getTVert = getTVert
  109. global polyop_getFace = getFace
  110. global polyop_getFaceMatID = getFaceMatID
  111. global polyop_getTVFace = getTVFace
  112. global cacheWriteFloat = WriteFloat
  113. global cacheWriteLong = WriteLong
  114.  
  115. global animStart = animationRange.start.frame as integer
  116. global animEnd = animationRange.end.frame as integer
  117. global framesCount = (animEnd - animStart + 1)
  118.  
  119. if outputFileName != undefined then
  120. (
  121. DisableSceneRedraw
  122. undo off
  123. animate off
  124.  
  125. sliderTime = 0
  126.  
  127. writeLong file (objects.count)
  128. writeLong file (framesCount)
  129.  
  130. for currentObject in objects do
  131. (
  132. local hasAnimation = 0
  133.  
  134. if currentObject.position.isAnimated == true then
  135. hasAnimation = 1
  136.  
  137. if currentObject.rotation.isAnimated == true then
  138. hasAnimation = 1
  139.  
  140. local skinModifier = FindSkinModifier currentObject
  141.  
  142. local mesh = currentObject.mesh
  143. local userProp = getUserPropBuffer currentObject
  144.  
  145. -- properties buffer
  146. writeString file userProp
  147.  
  148. -- geometry parameters
  149. writeLong file mesh.numverts
  150. writeLong file mesh.numtverts
  151. writeLong file mesh.numfaces
  152.  
  153. -- animation
  154. if( skinModifier != undefined ) then
  155. writeLong file 1
  156. else
  157. writeLong file 0
  158.  
  159. writeLong file hasAnimation
  160.  
  161. -- write name
  162. writeString file currentObject.name
  163.  
  164. in coordsys parent
  165. (
  166. if hasAnimation == 1 then -- write keyframes
  167. for frame = animStart to animEnd do
  168. at time frame
  169. WriteNodePositionRotation currentObject
  170. else -- write only position and rotation
  171. at time 0
  172. WriteNodePositionRotation currentObject
  173. )
  174.  
  175. -- collect textures
  176. textures = GetTextureFileNamesArray currentObject
  177.  
  178. -- write texture file names
  179. WriteLong file textures.count
  180.  
  181. for texture in textures do
  182. WriteString file texture
  183.  
  184. -- write geometry at start frame
  185. at time 0
  186. for i = 1 to mesh.numverts do
  187. WriteVector3 ((polyop_getVert mesh i) * ( currentObject.scale ))
  188.  
  189. -- export bones
  190. if( skinModifier != undefined ) then
  191. (
  192. -- write bone weights
  193. for i = 1 to mesh.numVerts do
  194. (
  195. local weightCount = skinops.GetVertexWeightCount skinModifier i
  196.  
  197. if( weightCount > 4 ) then
  198. weightCount = 4
  199.  
  200. WriteLong file weightCount
  201.  
  202. for k = 1 to weightCount do
  203. (
  204. local weight = skinops.GetVertexWeight skinModifier i k
  205. local id = skinops.GetVertexWeightBoneID skinModifier i k
  206.  
  207. WriteLong file id
  208. WriteFloat file weight
  209. )
  210. )
  211.  
  212. local boneCount = skinops.GetNumberBones skinModifier
  213.  
  214. WriteLong file boneCount
  215.  
  216. for i = 1 to boneCount do
  217. (
  218. local boneName = skinops.GetBoneName skinModifier i 1
  219.  
  220. WriteString file boneName
  221. )
  222. )
  223.  
  224. local numTVerts = mesh.numTVerts
  225.  
  226. -- write texture coordinates
  227. for v = 1 to numTVerts do
  228. WriteTextureCoordinates ( polyop_getTVert mesh v )
  229.  
  230. -- write faces
  231. for f = 1 to mesh.numfaces do
  232. (
  233. local face = polyop_getFace mesh f
  234.  
  235. WriteFace face
  236.  
  237. if ( numTVerts != 0 ) then
  238. WriteFace ( polyop_getTVFace mesh f )
  239. else
  240. WriteFace face
  241.  
  242. if (textures.count > 1) then
  243. writeLong file ((polyop_getFaceMatID mesh f) - 1)
  244. else
  245. writeLong file 0
  246. )
  247.  
  248. delete mesh
  249. )
  250.  
  251. for currentObject in objects do
  252. (
  253. local parentName = "World";
  254.  
  255. if (currentObject.parent != undefined) then
  256. parentName = currentObject.parent.name
  257.  
  258. writeString file currentObject.name
  259. writeString file parentName
  260. )
  261.  
  262. fclose file
  263.  
  264. undo on
  265. EnableSceneRedraw
  266. )
  267. )
  268. )
  269. createdialog unnamedRollout
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement