Converting Cheetah's uvcoords to tverts
I am working on a set of scripts for importing and exporting MDL format (a model format used in the ancient game Neverwinter Nights), and am having some trouble creating tverts out of Cheetah's uv information.
Part of this is that I do not understand the relationship between tverts and uvcoords. I suspect that they are the same thing, but I am unclear if there are any differences between the two. And more importantly I do not really understand in precise terms how either work.
So let me break this down into clear questions:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
As to what an MDL looks like here is an example of what some of the mesh data from an ASCII version of a MDL file looks like. As you can see all of these are kept as arrays of structs. The first line of the block is the length of the array, then I only show you the first index of the array, but there would be a much longer list if you ere looking at the file:
vertices
an array of vectors. straightforward except that the axes are not the same as in cheetah. I believe the two systems swap Y and Z.
faces (always triangles)
face[0]'s contents go as follows:
vertId1, vertId2, vertId3, smoothing group id, tvertId1, tvertId2, tvertId3, material
tverts
U, V, material
I am working on a set of scripts for importing and exporting MDL format (a model format used in the ancient game Neverwinter Nights), and am having some trouble creating tverts out of Cheetah's uv information.
Part of this is that I do not understand the relationship between tverts and uvcoords. I suspect that they are the same thing, but I am unclear if there are any differences between the two. And more importantly I do not really understand in precise terms how either work.
So let me break this down into clear questions:
- It appears that each tvert maps to each corner of a polygon, thus each vert maps to 1 or more tverts. Is this the same for UV Coords? Cheetah appears to map UVcoords to each "cindex" of a polygon rather than to each "vindex" of a mesh. Is this correct? It makes sense given that when you generate a UV map you can manipulate the corners of each polygon separately, but one nagging doubt I have is that in the MDL a tvert id can show up more than once on different faces/normals, but it could be that the "UV mesh" shares/recycles tverts with identical coordinates so as to avoid redundancy.
- the method PolyCore.uvCoord(pindex, cindex) is documented to return a "Vec4d" which is basically a structure with 4 numbers. I believe you access these with the properties x, y, z, w. Is that correct and if so what do each of those properties signify? I need to extract the positions U and V when I create my array of "tverts" out of these.
- UV review question: is U a horizontal measurement from left to right, and V vertical from top to bottom? Also is this measurement a percentage of the distance across the image? A bit confused since sometimes a negative value shows up in the matrix.
- the MDL file keeps its tverts in an array, but I don't seem to be able to access uvCoords the same way in Cheetah. Basically uvCoords do not appear to be stored in an ordered list. Is that true? I guess I just want to ensure that when I generate an array of tverts that it won't matter if I inadvertently change the order of the uvCoords as long as I maintain the correct mapping to the corner of each polygon.
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
As to what an MDL looks like here is an example of what some of the mesh data from an ASCII version of a MDL file looks like. As you can see all of these are kept as arrays of structs. The first line of the block is the length of the array, then I only show you the first index of the array, but there would be a much longer list if you ere looking at the file:
vertices
Code:
verts 32
-0.0497328 0.162773 0.724411
faces (always triangles)
Code:
faces 32
0 1 17 4 44 45 47 1
vertId1, vertId2, vertId3, smoothing group id, tvertId1, tvertId2, tvertId3, material
tverts
Code:
tverts 60
0.963345 0.0923299 0
U, V, material
Last edited: