Archived

This topic is now archived and is closed to further replies.

MAXScript exporter

This topic is 5333 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I've box modelled a simple spaceship, and I now want to create a simple file format consisting of raw vertex and index data...I've searched the net and the MAXScript docs, but I dont know what to look for. I know how to output the result to a file (format " " to:Listener/FileStream), but what commands/vars do I use to get the vertex data from the model? Any help would be appreciated. EDIT: BTW, I dont want to make a plugin...I'm trying to figure out MAXScript...thanks again Brian J [edited by - bjmumblingmiles on May 6, 2003 9:49:35 PM]

Share this post


Link to post
Share on other sites
I can just post some code for a very simple exporter:


  
-- This script provides a powerful (hehe) exporter for triangle meshes into a simple ASCII file format
--
-- 1. for every geometry object
-- convert to a mesh and export it as a submodel of world

macroscript PP3DWorldExporter category:"Exporters" buttonText:"PP3D World Exporter"
(
local PP3D_Export

fn LR_Export filename object =
(
file = createFile filename

if ( file == undefined ) do
(
messagebox "Couldn''t create file for export!"
return false
)

format "# LiquidRun ASCII Model file, exported from 3ds max\n" to:file

format "% % %\n" object.name object.numVerts object.numFaces to:file

format " vf " to:file

format "\n" to:file

for i in 1 to object.numVerts do
(
format "% % %\n" object.verts[i].pos[1] object.verts[i].pos[2] object.verts[i].pos[3] to:file
)

format "\n" to:file

for i in 1 to object.numFaces do
(
iface = getFace object i

format "% % %\n" (iface.x as Integer) (iface.y as Integer) (iface.z as Integer) to:file
)

flush file

close file

)

fn ExportMesh object file =
(
format "% % %\n" object.name object.numVerts object.numFaces to:file

format " vf " to:file

format "\n" to:file

for i in 1 to object.numVerts do
(
format "% % %\n" object.verts[i].pos[1] object.verts[i].pos[2] object.verts[i].pos[3] to:file
)

format "\n" to:file

for i in 1 to object.numFaces do
(
iface = getFace object i

format "% % %\n" (iface.x as Integer) (iface.y as Integer) (iface.z as Integer) to:file
)


)

rollout LRExportRollout "LiquidRun Exporter"
(
group "Options"
(
checkbox auto_conv "AutoConvert to Mesh"
)

button export "Export..." align:#right

on export pressed do
(
object = selection[1]

if( object == undefined ) do
(
messagebox "Must select object to export"
return false
)

if ( isKindOf object Editable_Mesh == false ) do
(
if ( auto_conv.checked == false ) then
(
messagebox "Must be an Editable Mesh, or use AutoConvert"
return false
)
else
(
// object_mesh = converttoMesh object

object_mesh = object.mesh
)
)
else
(
object_mesh = object
)

filename = getSaveFileName types:"LR ASCII Model (*.lam)|*.lam|All (*.*)|*.*"

if( filename != undefined ) do
(
LR_Export filename object_mesh
)

)

)


createDialog LRExportRollout

)


Hopefully you can pick through that, if you''ve any questions just shout.

Share this post


Link to post
Share on other sites
Hehe, by the time I wanted that I figured it would be *much* easier to use the SDK and write an exporter.

You should be able to use object.tverts[] array to access the coords, but it''s not guaranteed to exist (try it in a listener on a few meshes). Also, it''s not in a very hardware-friendly layout (ie verts can share tverts), but that probably won''t matter if you can export to an .OBJ like format (ie with texture coords per-face-corner rather than per-vertex).

Normals are another tricky thing, the smooth groups interact in mind-mangling ways but as long as you are careful it is possible (easiest is probably to make each face part of just 1 smooth group, then create a normal for each vertex, for each group, then merge/discard those that aren''t referenced by a face).

Share this post


Link to post
Share on other sites
quote:
You should be able to use object.tverts[] array to access the coords, but it''s not guaranteed to exist (try it in a listener on a few meshes).


True. You can check to see if the map channel exists though. If it does, you can export the UV''s. If not, you can either nothing or whatever. To find out if a UV channel exists you can do:

meshop.getMapSupport Object MapChannel

quote:
Also, it''s not in a very hardware-friendly layout


True. Each vert can reference multiple texture verts. However, each face does have a 1-to-1 correlation to a texture face. Each texture face is made up of indices to texture verts. So, by going throgh all that, you should be able to get your texture verts.

quote:
Normals are another tricky thing


Yup! All in all, you''re probably best off just gathering everything from Max in a way that you have 3 unique sets of everything for each face. Then, once you have everything you can optimize in your own manner. If you try to map Max''s optimizations to your own format directly, you may go mad

-John

Share this post


Link to post
Share on other sites
quote:

Are those "face" numbers indices of the vert data? I''m having a really hard time loading my format into my program- the index data is off....so if not, what Do they represent?



They are, but I''m pretty sure (can''t remember OTOMH) that they are 1-based and not 0-based so if you subtract one from each index you should get the C array index.

Share this post


Link to post
Share on other sites