I have written an exporter to export from Max to X-Plane. I'm using max 2010 x64.
The format that I'm exporting to requires a list of vertex records, and so I export them using the following:
for f = 1 to num_faces do( channel = 1 Face = getFace tmesh f TFace = meshop.getMapFace tmesh channel f TVx = meshop.getMapVert tmesh channel (TFace.x as integer) TVy = meshop.getMapVert tmesh channel (TFace.y as integer) TVz = meshop.getMapVert tmesh channel (TFace.z as integer) for v = 1 to 3 do ( if FaceCCW.state == true then ( case v of ( 3: (curVert = Face.x; curTVert = TVx) 2: (curVert = Face.y; curTVert = TVy) 1: (curVert = Face.z; curTVert = TVz) ) ) else ( case v of ( 1: (curVert = Face.x; curTVert = TVx) 2: (curVert = Face.y; curTVert = TVy) 3: (curVert = Face.z; curTVert = TVz) ) ) Vert = getvert tmesh curVert VertNorm = getNormal tmesh curVert VertX = formattedPrint Vert.x format:".6f" VertY = formattedPrint Vert.y format:".6f" VertZ = formattedPrint Vert.z format:".6f" VertNormX = formattedPrint VertNorm.x format:".6f" VertNormY = formattedPrint VertNorm.y format:".6f" VertNormZ = formattedPrint VertNorm.z format:".6f" VertU = formattedPrint curTVert[1] format:".6f" VertV = formattedPrint curTVert[2] format:".6f" append AryVerts ("VT " + VertX + " " + VertY + " " + VertZ + " " + VertNormX + " " + VertNormY + " " + VertNormZ + " " + VertU + " " + VertV + "\n") ))
tmesh is a snapshot of my mesh. I loop through each face in my mesh (CCW or CW) and create a record for each vertex. The vertex requires a triplet for X,Y,Z position, and then an X,Y,Z normal (normalized to 1) and then a U, V coordinate.
Everything is exporting and displaying properly, except my smooth groups are not showing in the engine, and I get an error for each object that says it has normals of the wrong length.
Is there anything I can do in the above code to make sure the normal x,y,z values are normalized to 1 and reflect the smooth groups? The normals also tell X-Plane how to smooth the surfaces, so the normal values should take into account the smooth group choices.
My vertex records are NOT optimized...so they currently reflect num_faces * 3. If anyone has any insight into optimizing my vertex records, that would be awesome!
Here's the specifics from: http://scenery.x-plane.com/library.php?doc=obj8spec.php
Quote:VT <x> <y> <z> <nx> <ny> <nz> <s> <t> This defines a single entry in the triangle vertex table. These are indexed starting from zero based on the record order. The eight numbers represent a triplet coordinate location, a triplet normal, and a pair forming a texture coordinate. This table is only used for triangles.
...
Flat/Smooth shading (default is smooth). In flat shading, the entire triangle is drawn with the same brightness. In smooth shading, the corners of the triangle have the shading levels appropriate for their normals, and the interior is interpolated. Note that since flat shading can be simulating via per-vertex normals, it is usually better to only use smooth shading.
...
Normals are specified as a triplet of fractions forming a 3-space vector whose length is 1. The vector is interpretted in the same coordinate space as the geometry.
Help me get this portion of the exporter working and I'll be set!
I think I need some better way to organize the VT records...a more organized array that I can sort through and compare to as I come across vertices. This way when I loop through my faces I can compare to the array and determine whether to add a new record or not...As long as the vertices are set to make faces in a counter clockwise orientation to determine the facing of a face, and all the vertices are represented based on their texture and vertex information I should be good...but I have NO idea how to go about doing that.
Thanks in advance for the help!