Problem exporting vertex coords and UV coords

Scripting in Blender with Python, and working on the API

Moderators: jesterKing, stiv

MortFurd
Posts: 4
Joined: Tue Oct 28, 2003 7:29 pm

Problem exporting vertex coords and UV coords

Postby MortFurd » Tue Oct 28, 2003 8:22 pm

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?

ascotan
Posts: 216
Joined: Thu May 29, 2003 10:32 pm
Location: Maryland, U.S.

Postby ascotan » Tue Oct 28, 2003 11:40 pm

Many game engines use left-handed geometry while blender uses right-handed geometry i believe.

der_ton
Posts: 29
Joined: Mon Oct 20, 2003 1:02 am

Postby der_ton » Wed Oct 29, 2003 12:50 pm

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.

MortFurd
Posts: 4
Joined: Tue Oct 28, 2003 7:29 pm

Problem solved

Postby MortFurd » Thu Oct 30, 2003 2:36 am

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.

theeth
Posts: 1184
Joined: Wed Oct 16, 2002 5:47 am
Location: Montreal
Contact:

Postby theeth » Thu Oct 30, 2003 2:48 am

Blender use right hand coordinates.

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

MortFurd
Posts: 4
Joined: Tue Oct 28, 2003 7:29 pm

Postby MortFurd » Thu Oct 30, 2003 8:00 pm


theeth
Posts: 1184
Joined: Wed Oct 16, 2002 5:47 am
Location: Montreal
Contact:

Postby theeth » Fri Oct 31, 2003 12:23 am

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

MortFurd
Posts: 4
Joined: Tue Oct 28, 2003 7:29 pm

Postby MortFurd » Fri Oct 31, 2003 6:12 pm

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.

SteelSureal
Posts: 1
Joined: Fri Dec 31, 2010 9:06 pm
Location: Vancouver

Re: Problem solved

Postby SteelSureal » Fri Dec 31, 2010 9:08 pm

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 :)

SirHegel
Posts: 1
Joined: Wed Nov 07, 2012 5:42 pm

Re: Problem solved

Postby SirHegel » Wed Nov 07, 2012 5:54 pm

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 :)


Thank you, dudes! You made my day :o) Those goddamn V's were driving me nuts.


Return to “Python”

Who is online

Users browsing this forum: No registered users and 1 guest