PDA

View Full Version : Problem with exporting texture coordinates


lehthanis
02-22-2007, 04:08 PM
I'm writing a script that will export from a 3d studio trimesh to a x-plane obj 8 file format. The format is very specific and kinda odd, but I've figured that much out.

I'm having a problem with the texture coordinates portion of the export. The file format specification wants a list of vertices containing 8 different values. Thos values are:
Xpos, YPos, ZPos, XNorm, YNorm, ZNorm, TexX, TexY

X-Plane uses the Y axis as up, so in the following code, I'm swapping the Y and Z axes. As you can see I am using the getTVert and returning the X and Y values and including the Z value in a comment until I figure out what the problem is.


for v = 1 to num_verts do
(
Vert = getvert tmesh v
VertNorm = getNormal tmesh v
VertTex = getTVert tmesh v

format "VT % % % % % % % % // TextureZ: %\n" Vert.x Vert.z Vert.y VertNorm.x VertNorm.z VertNorm.y VertTex.x VertTex.y VertTex.z to:out_file
)


Here is what is generated when I run the script on a 1x1 plane centered facing towards the positive Z axis in max with only 1 horizontal and vertical segment. The first 3 coordinates are the position coordinates, which are correct. The next three coordinates are the normals, all of which are 1.0 in the Y axis which is correct since I swapped Y and Z. The last two coordinates are what I would assume are U and V. as you can tell the supposed V and commented out W are all zeroes, which is of course incorrect.


VT -0.5 0.0 -0.5 0.0 1.0 0.0 0.0 0.0 // TextureZ: 0.0
VT 0.5 0.0 -0.5 0.0 1.0 0.0 1.0 0.0 // TextureZ: 0.0
VT -0.5 0.0 0.5 0.0 1.0 0.0 0.0 0.0 // TextureZ: 0.0
VT 0.5 0.0 0.5 0.0 1.0 0.0 1.0 0.0 // TextureZ: 0.0


Using my amazing sense of deductive reasoning (just kidding) I've determined in my head (and on paper) that the correct values should be as follows...notice the value of 1.0 on the last value of the last two vertices.


VT -0.5 0.0 -0.5 0.0 1.0 0.0 0.0 0.0
VT 0.5 0.0 -0.5 0.0 1.0 0.0 1.0 0.0
VT -0.5 0.0 0.5 0.0 1.0 0.0 0.0 1.0
VT 0.5 0.0 0.5 0.0 1.0 0.0 1.0 1.0


Anyone have any ideas what I'm doing wrong? The fact that all the commented out Z values are also zero tells me I'm not using the wrong piece of the triplet.

Thanks!

P.S. I would have searched, but the server is too busy.

lehthanis
02-22-2007, 07:30 PM
I believe part of my problem is that X-Plane uses a 1 to 1 relationship between texture vertices and mesh vertices. With that in mind, I need some way of linking up the vertex indices of the mesh with the vertex indices of the texture mesh...right?

CGTalk Moderation
02-22-2007, 07:30 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.