PDA

View Full Version : Exporting Vertex Information, optimizing, and indexing.

 lehthanis11-23-2010, 12:19 PMAs most of you probably know, I've been struggling on my exporter for a while now, and I think my primary problem is the method I'm using to store my vertex records and build my index. The simulator I'm exporting to supports optimized vertex records and has an index table for building the triangles. Each vertex record has the following information: X, Y, Z, nX, nY, nZ, U, V. So if there are any duplicates I can omit them. My code is currently just looping through faces and creating one vertex record for each vertex of each face. Which means my vertex records are tricount * 3, which is excessive. I end up with a LOT of duplicate vertexes. I'm also composing the vertex record strings and stuffing them into an array that is basically a build-order listing of vertices, which means the index records just go from 0 to vertex count. Here's my vertex and index code loop: ( num_verts = tmesh.numverts num_faces = tmesh.numfaces num_faceverts = num_faces * 3 totalNumFaceVerts += num_faceverts -- Loop through face vertices 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 VertNorm = normalize VertNorm 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") ) ) -- Loop through triangles for indices startIDX = curIDX for f = 1 to num_faceverts do ( append AryIDX (curIDX as string) curIDX += 1 ) ) As you can see, its pretty simple. And my normals are wrong, thats another issue. Once I figure out how to optimize my vertex records I'll be able to get my normals and average them according to some feedback I got in my other thread. Here's what a simple plane looks like exported with my current code: POINT_COUNTS 6 0 0 6 VT 1.000000 0.000000 -1.000000 0.000000 1.000000 0.000000 1.000000 1.000000 VT -1.000000 0.000000 1.000000 0.000000 1.000000 0.000000 0.000000 0.000000 VT -1.000000 0.000000 -1.000000 0.000000 1.000000 0.000000 0.000000 1.000000 VT -1.000000 0.000000 1.000000 0.000000 1.000000 0.000000 0.000000 0.000000 VT 1.000000 0.000000 -1.000000 0.000000 1.000000 0.000000 1.000000 1.000000 VT 1.000000 0.000000 1.000000 0.000000 1.000000 0.000000 1.000000 0.000000 IDX 0 IDX 1 IDX 2 IDX 3 IDX 4 IDX 5 TRIS 0 6 // Plane001 And here's what the same plane should look like if optimized and indexed. POINT_COUNTS 4 0 0 6 VT 1.000000 0.000000 -1.000000 0.000000 1.000000 0.000000 1.000000 1.000000 VT -1.000000 0.000000 1.000000 0.000000 1.000000 0.000000 0.000000 0.000000 VT -1.000000 0.000000 -1.000000 0.000000 1.000000 0.000000 0.000000 1.000000 VT 1.000000 0.000000 1.000000 0.000000 1.000000 0.000000 1.000000 0.000000 IDX 0 IDX 1 IDX 2 IDX 1 IDX 0 IDX 3 TRIS 0 6 // Plane001 Any thoughts on organizing and optimizing efficiently?
MiranDMC
11-23-2010, 08:11 PM
When you using Maxscript all is stored as "triMeshes", which are "optimized" exactly as you need.
There is array of vertices and aray of faces (which are 3-element arrays that contains indices to the verts).

Take a look for Maxscript help > How to output geometry. You just need to add UV Mapping and normals.

I have done exporter for game meshes, so I can share with you some things I figured out for that.
BTW I already gave you function that returns UVs for verts, now it should be helpfull.

CGTalk Moderation
11-23-2010, 08:11 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.