Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- fn FindSkinModifier obj =
- (
- local skinModifier = undefined
- for i = 1 to obj.modifiers.count do
- (
- if obj.modifiers[i].Name == "Skin" then
- (
- skinModifier = obj.modifiers[i]
- max modify mode
- modPanel.setCurrentObject skinModifier
- exit
- )
- )
- return skinModifier
- )
- fn WriteVector3 vec3 =
- (
- -- write vertex according to X - right, Y - up, Z - forward
- cacheWriteFloat file ( vec3.x)
- cacheWriteFloat file ( vec3.z)
- cacheWriteFloat file (-vec3.y)
- )
- fn WriteQuaternion quaternion =
- (
- quaternion = quaternion * Z2YRotation
- cacheWriteFloat file quaternion.x
- cacheWriteFloat file quaternion.y
- cacheWriteFloat file quaternion.z
- cacheWriteFloat file quaternion.w
- )
- fn WriteFace face =
- (
- cacheWriteLong file (face.x - 1)
- cacheWriteLong file (face.y - 1)
- cacheWriteLong file (face.z - 1)
- )
- fn WriteTextureCoordinates texCoord =
- (
- cacheWriteFloat file texCoord.x
- cacheWriteFloat file (1 - texCoord.y)
- )
- fn WriteNodePositionRotation obj =
- (
- -- write position
- WriteVector3 ( obj.position )
- -- write rotation
- WriteQuaternion ( obj.rotation )
- )
- fn GetTextureFileNamesArray obj =
- (
- -- collect textures
- local textures = #()
- local currentMaterial = obj.material
- if( currentMaterial != undefined ) then
- (
- subMaterials = getNumSubmtls currentMaterial
- if (subMaterials == 0) then
- (
- if( currentMaterial.diffuseMap != undefined ) then
- append textures ( FileNameFromPath currentMaterial.diffuseMap.filename )
- )
- else
- (
- for i = 1 to subMaterials do
- (
- local subMaterial = getSubmtl currentMaterial i
- if( subMaterial.diffuseMap != undefined ) then
- append textures ( FileNameFromPath subMaterial.diffuseMap.filename )
- )
- )
- )
- return textures
- )
- rollout unnamedRollout "Untitled" width:160 height:96
- (
- button btn1 "Button" pos:[8,8] width:144 height:48
- on btn1 pressed do
- (
- outputFileName = getSaveFileName caption:"Scene Exporter" types:"Scene Files(*.scene)|*.scene" initialDir:(getDir #export) historyCategory:"ExportSceneFiles"
- if( outputFileName == undefined ) then
- break
- global Z2YRotation = rotateXMatrix -90
- global file = fopen outputFileName "wb"
- -- cache functions - according to MAXScript Help it must save a lot of time, but it's not :/
- global polyop_getVert = getVert
- global polyop_getTVert = getTVert
- global polyop_getFace = getFace
- global polyop_getFaceMatID = getFaceMatID
- global polyop_getTVFace = getTVFace
- global cacheWriteFloat = WriteFloat
- global cacheWriteLong = WriteLong
- global animStart = animationRange.start.frame as integer
- global animEnd = animationRange.end.frame as integer
- global framesCount = (animEnd - animStart + 1)
- if outputFileName != undefined then
- (
- DisableSceneRedraw
- undo off
- animate off
- sliderTime = 0
- writeLong file (objects.count)
- writeLong file (framesCount)
- for currentObject in objects do
- (
- local hasAnimation = 0
- if currentObject.position.isAnimated == true then
- hasAnimation = 1
- if currentObject.rotation.isAnimated == true then
- hasAnimation = 1
- local skinModifier = FindSkinModifier currentObject
- local mesh = currentObject.mesh
- local userProp = getUserPropBuffer currentObject
- -- properties buffer
- writeString file userProp
- -- geometry parameters
- writeLong file mesh.numverts
- writeLong file mesh.numtverts
- writeLong file mesh.numfaces
- -- animation
- if( skinModifier != undefined ) then
- writeLong file 1
- else
- writeLong file 0
- writeLong file hasAnimation
- -- write name
- writeString file currentObject.name
- in coordsys parent
- (
- if hasAnimation == 1 then -- write keyframes
- for frame = animStart to animEnd do
- at time frame
- WriteNodePositionRotation currentObject
- else -- write only position and rotation
- at time 0
- WriteNodePositionRotation currentObject
- )
- -- collect textures
- textures = GetTextureFileNamesArray currentObject
- -- write texture file names
- WriteLong file textures.count
- for texture in textures do
- WriteString file texture
- -- write geometry at start frame
- at time 0
- for i = 1 to mesh.numverts do
- WriteVector3 ((polyop_getVert mesh i) * ( currentObject.scale ))
- -- export bones
- if( skinModifier != undefined ) then
- (
- -- write bone weights
- for i = 1 to mesh.numVerts do
- (
- local weightCount = skinops.GetVertexWeightCount skinModifier i
- if( weightCount > 4 ) then
- weightCount = 4
- WriteLong file weightCount
- for k = 1 to weightCount do
- (
- local weight = skinops.GetVertexWeight skinModifier i k
- local id = skinops.GetVertexWeightBoneID skinModifier i k
- WriteLong file id
- WriteFloat file weight
- )
- )
- local boneCount = skinops.GetNumberBones skinModifier
- WriteLong file boneCount
- for i = 1 to boneCount do
- (
- local boneName = skinops.GetBoneName skinModifier i 1
- WriteString file boneName
- )
- )
- local numTVerts = mesh.numTVerts
- -- write texture coordinates
- for v = 1 to numTVerts do
- WriteTextureCoordinates ( polyop_getTVert mesh v )
- -- write faces
- for f = 1 to mesh.numfaces do
- (
- local face = polyop_getFace mesh f
- WriteFace face
- if ( numTVerts != 0 ) then
- WriteFace ( polyop_getTVFace mesh f )
- else
- WriteFace face
- if (textures.count > 1) then
- writeLong file ((polyop_getFaceMatID mesh f) - 1)
- else
- writeLong file 0
- )
- delete mesh
- )
- for currentObject in objects do
- (
- local parentName = "World";
- if (currentObject.parent != undefined) then
- parentName = currentObject.parent.name
- writeString file currentObject.name
- writeString file parentName
- )
- fclose file
- undo on
- EnableSceneRedraw
- )
- )
- )
- createdialog unnamedRollout
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement