Export script help

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

THREAD CLOSED
 
Thread Tools Search this Thread Display Modes
Old 11 November 2010   #1
Export script help

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!
 
Old 11 November 2010   #2
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.
__________________
http://stigatle.no
 
Old 11 November 2010   #3
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.
 
Old 11 November 2010   #4
Originally Posted by stigatle: 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...
 
Old 11 November 2010   #5
Thanks everyone - I just found the problem, and it's indeed on my renderer, not on the exporter.
 
Old 11 November 2010   #6
Thread automatically closed

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.
__________________
CGTalk Policy/Legalities
Note that as CGTalk Members, you agree to the terms and conditions of using this website.
 
Thread Closed share thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
CGSociety
Society of Digital Artists
www.cgsociety.org

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump
Miscellaneous

All times are GMT. The time now is 06:53 PM.


Powered by vBulletin
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.