Results 1 to 9 of 9

Thread: reading fbx or collada

  1. #1

    reading fbx or collada

    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:
    Code:
    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.

    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.

    Code:
           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.
    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] (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.

  2. #2
    PGDCE Developer Carver413's Avatar
    Join Date
    Jun 2010
    Location
    Spokane,WA,Usa
    Posts
    206
    why are some of the vertex index values negitive?

  3. #3
    It marks the end of a polygon. You have to negate and then subtract one from its value.

  4. #4
    How are you mapping your vertices, coordinates and indices?

  5. #5
    I added the values from the fbx file to these arrays.

    Code:
    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] so you can check what I did.

  6. #6
    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.

  7. #7
    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.

  8. #8
    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.
    Attached Files Attached Files

  9. #9
    Wow, thank you Dan! This is incredibly helpful.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •