Previous Thread  Next Thread

chat icon Problem exporting vertex coords and UV coords

MortFurd

Posted: Tue Oct 28, 2003 8:22 pm
Joined: 28 Oct 2003
Posts: 4
I've been working on an exporter for a simple file format that I need for a game I'm working on, and I'm having some trouble with coordinates.

The game is based on a modified copy of the cube game engine. I've added a new format for the models, and a great whacking pile of functions to the script language to make it do what I need done. All of that is no problem.

The difficulty is that the coordinates as I export them from Blender don't seem to be the same when I import them into the game - and I don't know if the problem lies on the export side or the import side.

For the Vertex coordinates, I'm having to invert the Y coordinates (-1*y.) If I don't do this, the faces face inwards and the figure is pointed the wrong way. When "looking" at the object in the game, the near side is transparent and you see the far side through it.

The UV coordinates are also driving me batty. For the only half way working model I've got, I have to invert the U component (1-U) for the texture to get where it should be. No other models (I've got three I've made in the course of things) show their textures properly.

If I exchange the U and V coordinates and use the inverse of the V component (1-V,U) then two of the models show more or less correctly - although rotated onto their sides. The third model still doesn't work, though.

The first two are basically disks, and the symmetry lets them look OK even though something is still wrong. The third model is intentionally non-symmetrical, and the textures never match properly no matter what I do.

The thing that really bugs me about this is that none of this twiddling should be neccesary.

I'm taking the data as Blender Python gives it to me, and feeding it back to the OpenGL functions in the same order. The vertexes should be in the same order, so there shouldn't be any trouble with the faces or the normals the OpenGL calculates. I'm certain that I'm using the same number of UV coordinates as I have Vertex coordinates (they're loaded with the same loop) so that shouldn't be a problem.

Blender appears to use (0,0) as the lower left for UV coordinates just as OpenGL does, so that should be fine - except it isn't.

I've tried my script under Blender 2.25 and 2.28a, and both give the same results. I using SuSe Linux 8.2, if that matters.

I've been chasing this for twelve hours straight, and I am stumped. I've been through what OpenGL documents I've got (mostly the .h files and some gleanings from the internet) and through the C code for the Python API in Blender 2.28, and I can't figure out what I'm doing wrong.

Has any one got Blender bat they smack me with?
Reply with quote


ascotan

Posted: Tue Oct 28, 2003 11:40 pm
Joined: 29 May 2003
Posts: 214
Many game engines use left-handed geometry while blender uses right-handed geometry i believe.
Reply with quote


der_ton

Posted: Wed Oct 29, 2003 12:50 pm
Joined: 20 Oct 2003
Posts: 29
You can tell OpenGL the facingness of your faces with glFrontFace(GL_CW) (clockwise specification of vertices) or glFrontFace(GL_CCW) (counterclockwise).
The culling of faces that face away from the viewer is controlled by this.
Reply with quote


MortFurd

Posted: Thu Oct 30, 2003 2:36 am
Joined: 28 Oct 2003
Posts: 4
Thanks for the tips folks.

A couple of hours after I posted here, I figured out what was wrong. Blender uses left handed coordinates, and OpenGL wants right handed ones (if you don't specify otherwise.) I reordered the coordinates on export and that fixed that problem.

I decided to flip the faces rather than telling OpenGL to do it because the game engine still supports another file format, and I didn't want to diddle around switching coordinate systems. It is much easier to fix on export than to add a bunch of "IF THEN flip coordinate" crap to the C++ code.

Next is that blender textures use (0,0) for the top left corner and OpenGL uses (0,0) for the lower left corner. Using (U,1-V) fixes that.

Now my models are right side out with their skins on right side up.

Sorry to have been a bother.
Reply with quote


theeth

Posted: Thu Oct 30, 2003 2:48 am
Joined: 16 Oct 2002
Posts: 1177
Blender use right hand coordinates.

Martin
_________________
Life is what happens to you when you're busy making other plans.
- John Lennon
Reply with quote


MortFurd

Posted: Thu Oct 30, 2003 8:00 pm
Joined: 28 Oct 2003
Posts: 4
That's not what I read here:
http://www.blender.org/pipermail/bf-docboard/2003-June/000788.html
Reply with quote


theeth

Posted: Fri Oct 31, 2003 12:23 am
Joined: 16 Oct 2002
Posts: 1177
Look, whoever said that either made a mistake by accident or don't know the defintion of left and right systems correctly. On a right hand system, X x Y = Z. On a left hand system, Y x X = Z

Martin
_________________
Life is what happens to you when you're busy making other plans.
- John Lennon
Reply with quote


MortFurd

Posted: Fri Oct 31, 2003 6:12 pm
Joined: 28 Oct 2003
Posts: 4
Sorry. I didn't mean to look like I was trying to argue about it, I just wanted to provide a cite for why I thought blender was left handed.

At any rate, I've been over and over and around and round the whole thing and finally have things working together.
Reply with quote


SteelSureal

Posted: Fri Dec 31, 2010 9:08 pm
Joined: 31 Dec 2010
Posts: 1
MortFurd wrote:
Thanks for the tips folks.

A couple of hours after I posted here, I figured out what was wrong. Blender uses left handed coordinates, and OpenGL wants right handed ones (if you don't specify otherwise.) I reordered the coordinates on export and that fixed that problem.

I decided to flip the faces rather than telling OpenGL to do it because the game engine still supports another file format, and I didn't want to diddle around switching coordinate systems. It is much easier to fix on export than to add a bunch of "IF THEN flip coordinate" crap to the C++ code.

Next is that blender textures use (0,0) for the top left corner and OpenGL uses (0,0) for the lower left corner. Using (U,1-V) fixes that.

Now my models are right side out with their skins on right side up.

Sorry to have been a bother.


Thank you thank you thank you

The (U,1-V) was messing up my mapping and I've been trying to fix it for hours. I created an account I wanted to thank you so much Smile
_________________
http://www.step-six.com
Reply with quote


SirHegel

Posted: Wed Nov 07, 2012 5:54 pm
Joined: 07 Nov 2012
Posts: 1
SteelSureal wrote:
The (U,1-V) was messing up my mapping and I've been trying to fix it for hours. I created an account I wanted to thank you so much Smile


Thank you, dudes! You made my day Surprised) Those goddamn V's were driving me nuts.
Reply with quote


 
Jump to:  
Powered by phpBB © 2001, 2005 phpBB Group