PDA

View Full Version : Export script help


SLotman
11-20-2010, 03:59 PM
Hi folks,

I'm a complete newbie regarding MaxScripting, and just tried to write a simple "static mesh" exporter.

Everything seems to be ok, simple meshes are exported correctly; problem is - when I try to export meshes with high poly count (20k+) my mesh is rendered completely wrong on my opengl mesh viewer. Optimizing the mesh and reducing the poly count - puf! - the mesh renders correctly.

So I come here to ask for help - could you guys please take a look at my code and see if I didn't make any horrible mistake? Is the data being exported correctly? I just need to know if I have to hunt down a bug on this exporter, or in my viewer =)

Here's the code I've written:

-- SMesh Exporter version 0.01
-- export static meshes with uv and normal coords from max to file
-- (c) Ikone Soft Programas de Computador ltda
-- Selling or distributing this code, in part or full, without prior written consent is expressly forbidden.
--
-- use: open in maxscript, select this whole piece of code and eval it
-- it will export every EDITABLE MESH on the scene to a .smesh file

fname = getSaveFileName caption:"Export to file:" filename:"test.smesh"
deletefile fname
f = fopen fname "wb"

for mesh in objects do
(
if superclassof mesh == GeometryClass and ClassOf mesh == Editable_mesh then
(
-- object name
writestring f mesh.name

if mesh.numVerts > 0 then
(
-- vertex and normal data
writelong f mesh.numVerts
for i = 1 to mesh.numVerts do
(
vert = ((GetVert mesh i))
writefloat f vert.x
writefloat f vert.y
writefloat f vert.z

normal = GetNormal mesh i
writefloat f normal.x
writefloat f normal.y
writefloat f normal.z
)
)

if mesh.numTVerts > 0 then
(
-- UV tex coords
writelong f mesh.numTVerts
for i = 1 to mesh.numTVerts do
(
uvw = GetTVert mesh i
writefloat f uvw.x
writefloat f uvw.y
)
)

if mesh.NumFaces > 0 then
(
-- faces (1 face = 2 triangles)
writelong f mesh.numFaces
for i = 1 to mesh.numFaces do
(
poly = GetFace mesh i
tvert = GetTVFace mesh i
-- write face index
writelong f (poly.x as integer -1)
writelong f (poly.y as integer -1)
writelong f (poly.z as integer -1)
-- write face uv index
writelong f (tvert.x as integer -1)
writelong f (tvert.y as integer -1)
writelong f (tvert.z as integer -1)
)
)

)
)
fclose f


Any help appreciated, thanks in advance!

stigatle
11-21-2010, 06:34 PM
Hi, could you post a screenshot of both highpoly model in max and then in your application?
Would make it easier to understand the problem..

Thanks in advance.

Klunk
11-21-2010, 07:16 PM
check the export data in a hex editor, if it is scrambled then it's the script otherwise it's an issue with your mesh viewer.

SLotman
11-22-2010, 07:08 AM
Hi, could you post a screenshot of both highpoly model in max and then in your application?
Would make it easier to understand the problem..

Thanks in advance.

No problem - to the left the high poly mesh (50k+ faces) exported from the script, and to the right, the same mesh, exported to another file format (both rendered on my program):
http://img94.imageshack.us/img94/480/export1.jpg

Now, the same mesh, reduced to less than 20k faces on the left, exported by the script (to the right, same model as the screenshot above):
http://img59.imageshack.us/img59/6683/export2.jpg

I did check if my program was reading correctly the data on the file, and it is - so that's not the problem...

SLotman
11-22-2010, 09:03 PM
Thanks everyone - I just found the problem, and it's indeed on my renderer, not on the exporter.

CGTalk Moderation
11-22-2010, 09:03 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.