PDA

View Full Version : reading fbx or collada



Traveler
20-06-2011, 10:24 PM
Hey guys,

Need some help here, before I'm losing my mind while figuring out what I'm doing wrong. :(

I've been trying to get objects loaded from a fbx or collada file (they are largely similar). Mind you for the moment I'm only interested in loading the vertex info and texture coordinates thats it. No animations or any other info.
Here's the problem: I'm able to load my model just fine, it's the textures however that fail horribly.

In fbx format you have the following info for just two triangles:


Vertices:-2.5,-2.5,2.5,-2.5,2.5,2.5,2.5,-2.5,2.5,-2.5,-2.5,-1.69999992847443
PolygonVertexIndex: 1,0,-3,3,2,-1
GeometryVersion: 124
LayerElementUV: 0 {
Version: 101
Name: "Texture"
MappingInformationType: "ByPolygonVertex"
ReferenceInformationType: "IndexToDirect"
UV: 0.00744416890665889,0.915632724761963,
0.00744416890665889,0.468982636928558,
0.454094290733337,0.468982636928558,

0.355433821678162,0.454094290733337,
0.838598906993866,0.00744416890665889,
0.355433821678162,0.00744416890665889
UVIndex: 0,1,2,3,4,5
}

The parts that matter are underlined. If I use that info in my code I get this as a result.

http://www.gameprogrammer.net/pics/outside/uvmaptest1.jpg

I rotated the model so you can see underneath it, but as you can see the texture coordinates are wrong. I have tried many different things, such as changing the order of the coordinates, but without good results.



0.00744416890665889,0.915632724761963, //1
0.00744416890665889,0.468982636928558, //2
0.454094290733337,0.468982636928558, //3

0.355433821678162,0.454094290733337, //4
0.838598906993866,0.00744416890665889, //5
0.355433821678162,0.00744416890665889 //6
//become s
0.00744416890665889,0.468982636928558, //2
0.00744416890665889,0.915632724761963, //1
0.454094290733337,0.468982636928558, //3

0.355433821678162,0.454094290733337, //4
0.838598906993866,0.00744416890665889, //5
0.355433821678162,0.00744416890665889 //6

For example when the second set is changed only the upper triangle is displayed correctly.

http://www.gameprogrammer.net/pics/outside/uvmaptest2.jpg
No matter what else I change, the other one only gets worse, and never as it should be.
I'm running out of options. It's probably something I'm overlooking, but I don't see it. Perhaps I need to rearrange something else? I don't know....

Anyway, I hope any of you have dealt with this before and knows what to do.
If you want to try the source code, you can download if from [here (http://www.gameprogrammer.net/zip/uvmaptest.zip)] (it's mostly a derivative of the tutorial I translated earlier) The fbx file is included as well.

A big big thanks if you can help me solve this.

Carver413
21-06-2011, 02:31 AM
why are some of the vertex index values negitive?

Traveler
21-06-2011, 07:59 AM
It marks the end of a polygon. You have to negate and then subtract one from its value.

Dan
21-06-2011, 09:02 AM
How are you mapping your vertices, coordinates and indices?

Traveler
21-06-2011, 09:34 AM
I added the values from the fbx file to these arrays.



verts : array [0..11] of GLfloat = (
-2.5,-2.5,2.5, -2.5,2.5,2.5, 2.5,-2.5,2.5, -2.5,-2.5,-1.69999992847443
);

texCoord : array [0..11] of GLfloat = (

0.00744416890665889,0.915632724761963,
0.00744416890665889,0.468982636928558,
0.454094290733337,0.468982636928558,

0.355433821678162,0.454094290733337,
0.838598906993866,0.00744416890665889,
0.355433821678162,0.00744416890665889

);
v_index : array [0..5] of GLInt = (1,0,2,3,2,0);


If you like, the source is [here (http://www.gameprogrammer.net/zip/uvmaptest.zip)] so you can check what I did.

User137
21-06-2011, 10:33 AM
What's the actual texture? Assuming that it's a square with 2x2 color grid with 1 green and 1 blue square, then the texture coordinates are wrong. Simply because a yellow - green - yellow sequence at the bottom will need texture repeat clamping which means coords should go beyond 0..1 range.

Traveler
21-06-2011, 10:47 AM
It's not. Look at the first image at the top right, that is how it should look. The coordinates are correct. I've tested the exported fbx file in Autodesk's FBX Converter and it shows up correctly. There's something wrong with my code, or at least with the way I use the information in my code.

Dan
21-06-2011, 12:47 PM
sorry I did not notice the link to the code before.
so, you are not doing any remapping, you are simply feeding all the data to the buffers. that is not the right way to do it.
this is how your vertices map to the faces: PolygonVertexIndex: 1,0,-3,3,2,-1
this is how texture coordinates map to the faces: UVIndex: 0,1,2,3,4,5
you are using vertex indices for both which gives you the incorrect result.
take a look at the code here, I have done a quick remapping to show you where the problem was.

Traveler
21-06-2011, 01:18 PM
Wow, thank you Dan! This is incredibly helpful. :yes: