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!
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!
