Notifications
Clear all

[Closed] Exporting flat objects to xml for Kerkythea

Hello All,

 I'm new to maxscript and i try to write a geometry exporter for Kerkythea, which uses
 xml as input.
 
 After studying the maxscript reference here is what i have so far.
tmesh = snapshotAsMesh selection[1]
     out_file = createfile ((GetDir #export)+"/testmesh.dat")
     scale_units = 0.01
     num_verts = tmesh.numverts 
     num_faces = tmesh.numfaces
     num_norm = (3 * tmesh.numfaces)
     mesh_name = (selection[1].name)
     
 format "<Object Identifier=\"./Models/%\" Label=\"Default Model\" Name=\"%\" Type=\"Model\">
"	mesh_name mesh_name to:out_file
 format "<Object Identifier=\"Triangular Mesh\" Label=\"Triangular Mesh\" Name=\"\" Type=\"Surface\">
"	to:out_file
     
     --Vertex
     format "<Parameter Name=\"Vertex List\" Type=\"Point3D List\" Value=\"%\">
" num_verts to:out_file
     for v = 1 to num_verts do (
     
     	vert = (getVert tmesh v)*scale_units
     	format "<P xyz=\"% % %\"/>
" vert.x vert.y vert.z to:out_file
     	)
     	
     format "<\Parameter>
" to:out_file
 --Normals		 		 		 		 		 		--num_norm
     format "<Parameter Name=\"Normal List\" Type=\"Point3D List\" Value=\"%\">
" num_verts to:out_file
     for n = 1 to num_verts do (
     	normx = normalize(getNormal tmesh n)
     	--normx = getFaceNormal  tmesh n
     	format "<P xyz=\"% % %\"/>
" normx.x normx.y normx.z to:out_file
     	--format "<P xyz=\"% % %\"/>
" normx.x normx.y normx.z to:out_file
     	--format "<P xyz=\"% % %\"/>
" normx.x normx.y normx.z to:out_file
     	)
     
     format "<\Parameter>
" to:out_file
     --Face
     format "<Parameter Name=\"Index List\" Type=\"Triangle Index List\" Value=\"%\">
" num_faces to:out_file
     for f = 1 to num_faces do (
     	
     	face = getFace tmesh f
 	format "<F ijk=\"% % %\"/>
" (face.x as integer -1) (face.y as integer -1) (face.z as integer -1) to:out_file
     	)
     	
     format "<\Parameter>
" to:out_file
     format "
" to:out_file
     close out_file
     
     
 So far it works good for smoothed objects like spheres and torus knots.
 But i have a big problem with flat objects. See picture....
 
 [ http://img203.imageshack.us/img203/4070/firstexport5zq.jpg]( http://img203.imageshack.us/img203/4070/firstexport5zq.jpg](  g"/> )
 
 The normals are just not exported right.
 As being part of the beta team i talked alot with the coder of Kerkythea.
 Unfortunatelly he has no expirience with maxscript.
 
 He uses 36 normals for  the cube. One for each of the three vertices associated 
 with each face. So this makes 12x3=36.
 
 I can only get 8 normals from the vetices or 12 from the faces.
 
 I tried to get around this by printing out the normal of the tree vetices associated to
 a face .. i used the getFaceNormal command to get the face normal and then 
 printed it into the xml tree times. This is marked in my code in the section --Normals
 I added "--" to disable the lines. For the count i used (3* num_verts).
 This actually worked for the cube.
 But of course this didn't work for the smoothed objects. 
 
 OK so here is my question.
 
 Is there a better way to print out the normals? So they work for both.
 Or is there a way to differ between flat and smoothed objects so i can 
 just use what i have? ( i would just have to change the smoothed boolean in the xml for that to work )
 Is there something i can do with the objects before 
 exporting?
 
 This is really hard for me and after long searching the net and this forum without finding
 an answer i decide to post here.
 
 I really would apprechiate your help.
 
 Thank you very much in advance.
 
 u3dreal;)
 
 PS : feel free to mail me at: u3dreal "at" googlemail "doty" de.
1 Reply

HI All,

well it seems i’m a bit futher now…

I’m using the “meshOp.explodeAllFaces obj 1” command to separate flat objects into elements but somehow it seems this value (1) is not right as i still get some problems with some faces…when i resmooth them in Kerkythea…everything is fine…

Is there a better value …does anyone have expirience with that…?
or is there another way to do this…?

Help would be greatly apprechiated…

u3dreal