SMesh - Static Mesh exporter for 3D Max

BlitzMax Forums/MiniB3D Module/SMesh - Static Mesh exporter for 3D Max

SLotman(Posted 2010) [#1]
I'm not very happy about b3dpipeline not being updated for the latest 3D MAX for quite some time (b3dpipeline is great, but having no source to it, and no updates since 2008 is bad); so I decided to do something about it.

I looked yesterday and and today the basics of MAXScript - and just made a small "static mesh" (.smesh) exporter. It's fairly basic, it will export mesh xyz, normals and uv data - no texture or materials, no bones or animations.

One of the best things about it being a script, is that it will work on pratically any version of MAX - no need to recompile anything.

The script will export all EDITABLE MESHES on the scene - not anything else.

Please test it - so far I just did some basic testing, and it's working: see screenshot below for that ;)

This is the MaxScript:


This is the loading code:


Just call LoadSmesh(filename) in your program, and it will return an entity (actually a pivot named 'Scene Root') so you can manipulate the model (position, scale, etc)

Here's my first real test with this:


Last edited 2010


SLotman(Posted 2010) [#2]
hmmm... apparently there's some problem with too many vertex. I tried exporting a mesh with 50k+ polys and it rendered completely wrong; optimised the mesh to less than 20k and it's working... is this some restriction on miniB3D part?

Edit: hmmm, no - exporting the full mesh to B3D works.... that's strange, to say the least :P

Last edited 2010


jhocking(Posted 2010) [#3]
fopen fname "wb"


It's great that MaxScript can write binary, so why don't you write b3d files? Lately I've been working on writing b3d files from Python and it's not very complicated to do static meshes:
http://www.blitzmax.com/Community/posts.php?topic=92467

I tried to do this once years ago but MEL (Maya's scripting language) didn't support writing binary; now that Maya has Python I may be able to write a b3d exporter.

Last edited 2010


SLotman(Posted 2010) [#4]
Yeah, I want to in the end generate models in B3D format - but first I would like to get the basics working - and this 'too many vertex problem' is puzzling me right now :(


jhocking(Posted 2010) [#5]
Must say, if it were me I wouldn't bother to investigate this and just switch to writing b3d files. In your second post you said the problem went away went you exported the mesh to b3d. I would guess the problem has to do with limitations on generating the mesh in code, as opposed to minib3d generating the mesh during loading.


SLotman(Posted 2010) [#6]
The problem went away when I used b3d pipeline to export the mesh - not my exporter.

I just tested that way to see if it wasn't a internal problem on miniB3D - I really don't know if it's a problem exporting the data (which apparently is written correct, at least the number of faces/vertex/etc), or a problem rendering the data.


SLotman(Posted 2010) [#7]
Just for testing, the same loader for Blitz3D:


On large meshes, it gives me a mav on renderworld... =(

Last edited 2010


Kryzon(Posted 2010) [#8]
You're in for a pickle, I'll tell you that.

@ your source:
Since when is one face 2 triangles? in MaxScript, when dealing with a Mesh value from a Max node, a single face means a single triangle.

Last edited 2010


SLotman(Posted 2010) [#9]
Is there any limit to how many faces or vertex a surface can have in miniB3D?

The exporter is working - if I sub-divide the mesh in smaller chunks and add the faces to different surfaces the mesh is rendered correctly.


SLotman(Posted 2010) [#10]
Just by changing the loader code to this, I can load the high poly mesh:



Does anyone know if there are really a limit (apparently 21k faces) to miniB3D TSurface?


SLotman(Posted 2010) [#11]
Moving on, I already figure out how to read the material diffuse color, alpha level and glossiness (which I believe is the same as "EntityShininess" on blitz3D) - now just left to read the maps applied to the standard material, get the texture and it's done :)

(I know, it would be nice to have a second UV channel, more than 1 texture level too... but for a start this is good enough!)


SLotman(Posted 2010) [#12]
It's working now!



It will export editable mesh or editable poly - it will convert all editable poly on scene to editable mesh :P

I can now set the mesh as faceted, as double sided, change it's glossiness, the material color and even if I set another texture on another map than "diffuse", the program should be able to read it and apply it on the next texture level.

Textures are saved without any path, so they should be on the same folder as the mesh itself to load. I'm thinking of including a extra parameter on the loader function, to specify a path - so I can have the same mesh loaded over and over, and just change the texturepath, so it would apply a different texture automatically... anyone has some other crazy idea?

This is fun :)

Last edited 2010


Hujiklo(Posted 2010) [#13]
Well done - keep going. You'll become a MiniB3D hero with your own statue in the Blitz Hall of fame!


Gun Ecstasy(Posted 2011) [#14]
This is some excellent work!

Hujiklo said it best. Keep up the good work!


Corum(Posted 2011) [#15]
Is there any limit to how many faces or vertex a surface can have in miniB3D?

The exporter is working - if I sub-divide the mesh in smaller chunks and add the faces to different surfaces the mesh is rendered correctly.

Yes, the limit exists: read this.

Anyway, you did a great job with this exporter!

Last edited 2011