-------------------------------------------------------------------------------------
-- 3DFormat.ms
-- Exports entire scenes or selected objects as a Simple 3D format
-- 3D Studio MAX
-- By Petro Protsyk
-------------------------------------------------------------------------------------
utility SimpleExport "Simple 3D format Export..."
(
local ostream, tabs = ""
button btn_export "Save As..." width:100
-------------------------------------------------------------------------------------
function ExportMesh meshObj =
(
Format (tabs+"% \n") meshObj.numverts to:ostream
Format (tabs+"% \n") meshObj.numfaces to:ostream
-- Write vertices
if meshObj.numVerts > 0 then
(
for i = 1 to meshObj.numVerts do
Format (tabs+"% % % ") ((GetVert meshObj i)-meshObj.pos).X ((GetVert meshObj i)-meshObj.pos).Y ((GetVert meshObj i)-meshObj.pos).Z to:ostream
Format (tabs+"\n\n") to:ostream
)
-- Write faces
if meshObj.numFaces > 0 then
(
for i = 1 to meshObj.numFaces do
Format (tabs+"% % % ") (((GetFace meshObj i).X) as Integer) (((GetFace meshObj i).Y) as Integer) (((GetFace meshObj i).Z) as Integer) to:ostream
Format (tabs+"\n\n") to:ostream
for i = 1 to meshObj.numFaces do
Format (tabs+"% % % ") (GetFaceNormal meshObj i).X (GetFaceNormal meshObj i).Y (GetFaceNormal meshObj i).Z to:ostream
Format (tabs+"\n\n") to:ostream
)
-- Write texture vertices
if meshObj.numTVerts > 0 then
(
for i = 1 to meshObj.numTVerts do
Format (tabs+"% % % ") (GetTVert meshObj i).X (GetTVert meshObj i).Y (GetTVert meshObj i).Z to:ostream
Format (tabs+"\n\n") to:ostream
)
)
-------------------------------------------------------------------------------------
function ExportNode node =
(
-- Create node and export class specific data
if SuperClassOf node == GeometryClass and ClassOf node == Editable_mesh then
ExportMesh node
else
return false
return true
)
-------------------------------------------------------------------------------------
function RecursiveExportNode node =
(
if (ExportNode node) == false then
return false
for child in node.children do
RecursiveExportNode child
Format "\n\n" to:ostream
)
-------------------------------------------------------------------------------------
function ExportMAXScript =
(
Format "3Dp file\n" to:ostream
Format "========\n" to:ostream
for node in rootnode.children do
RecursiveExportNode node
)
-------------------------------------------------------------------------------------
function GetSaveFileStream =
(
fname = GetSaveFileName types:"Simple 3D format (*.3dp)|*.3dp|All Files(*.*)|*.*|"
if fname == undefined then
return undefined
ostream = CreateFile fname
if ostream == undefined then
(
MessageBox "Couldn't open file for writing !"
return undefined
)
return ostream
)
-------------------------------------------------------------------------------------
on btn_export pressed do
(
ostream = GetSaveFileStream()
if ostream != undefined then
(
ExportMAXScript()
Close ostream
)
)
) -- End MXSExport
Last updated: 28 may 2007