tex coords

These little ase loader of mine works just fine; but, as you probably know, 3D Max saves coords in different order than x, y, z.
So you have to invert some vert coords :
x = x
y = z
z = -y.
But then your tex coords are flipped, i.e. textures are now upside down (for textures that are like picture on the wall). Is there any way to flip them back? The problem is that you can’t just change the orientation of triangles, because some texs are spred across many of them, and you’ll mess it up.

Negate them?
u*=-1
v*=-1

3ds max uses a different coordinate system than OpenGL. That’s why you have to swap the coords as you do. Now because of this, you are just changing the verticies by converting from one 3d coord system to another but you leave the tex coords alone. So naturally the orientation of the textures will be wrong. Since they are upside down you probably only need to negate the v tex coord, unless they are upside down AND flipped (from left to right if looking straight at the texture), then you have to negate both u and v.

-SirKnight

[This message has been edited by SirKnight (edited 04-25-2003).]

With tools like Deep Exploration you can apply transformations to a mesh when you save/convert them. This is a handy feature.

But then your tex coords are flipped, i.e. textures are now upside down (for textures that are like picture on the wall). Is there any way to flip them back? The problem is that you can’t just change the orientation of triangles, because some texs are spred across many of them, and you’ll mess it up.

Actually, the reason for the texture coordinate flip has nothing to do with Max’s coordinate system. I imagine that your textures are either .bmp or .tga files, yes? If so, Max will flip the V parameter of the texture coordinate because these textures are stored “upside down” in the file. Of course, if your in-game texture loader understood that and flipped them before sending them to GL, then you would be getting 2 flips, which negate each other.

BTW, you don’t flip the texture by negating it. Vnormal = 1.0f - Vflipped.

You’re not “flipping coordinates,” you are rotating 90 degrees around the X axis to compensate for the Max “Y up” world when you’re using a “Z up” world (note: there’s nothing saying you can’t use a Y up world, too, and make it up in the view or model matrix).

This should not affect texture U/V at all, as you should only perform this operation on position and normal values. Again, typically you’ll do this rotation in a pre-process stage, or by baking a 90 degree rotation around X into your object-to-world orientation matrix.

There are at least three things I know of that can cause texture flipping:

  1. S grows to the right, T grows up

  2. Many bitmap formats (TGA, BMP, etc) start with the LOWEST row of pixels first

If you’re confused about 2), you may easily believe that T grows down in 1), leading to all kinds of derived confusion.

  1. DDS textures (DXT1 compressed data) seem to load upside-down from other textures. I haven’t delved into whether this is expected in the spec, or just something that I’m doing wrong; I just compensate in the texture matrix :slight_smile: It is, however, consistent on all cards I’ve tried it on.

Thank you all for your time and effort.
Yes, my texs are tga, and they are applied upside down. I’ll try inverting the pixel data.
Now I understand why we got to change coordinates given by max (thanks jwatte).
Also tried 1-V, but that didn’t do no good.
BTW, is it common to use some extern image loader (like devIL)? I wrote tga loader myself, but don’t have intention to write any more (it’s boring . Or is it better to pick favourite format, and (if have to) convert images.

in ASE normals are stored in objectspace, and the object in worldspace… you should transform the vertices with the inverse of the matrix that is in the header of each object. and yes, its often the same, but ont count on it…

Hey Mazy, that’s very interesting. I never saw anyone mention that before. Do you have some spec’s on ASE file?

Nope, sorry… I did use them much a few years ago, and got to know the most strange stuff about those little suckers , all by trial and error. So no spec.