Search code examples
importpolygoncollada

Importing COLLADA file - Wrong vertex positions


I'm working on a .DAE import for my game engine. I've been working with models exported by MilkShape, and they work fine:

Now i've downloaded a bigger poly mesh (with skeleton) form the internet, and im trying to import that one. I would only like the mesh and won't need the skeleton / animations for now.

Problem is, the output in my engine is not correct.

I'm not sure what i'm doing wrong. Do these results ring a bell for someone?

Here's the .DAE files by the way;

Cheers, Rob


Solution

  • Ah, I got it figured out!

    The one model (the Milkshape one) used the

    section like so;

    0 0 0 1 1 1 2 3 2

    Where:

    0=<position index> 0=<normal_index> 0=<vertex index>
    1=<position index> 1=<normal_index> 1=<vertex index>
    2=<position index> 3=<normal_index> 2=<vertex index> 
    

    But the other model didn't use this offset and used shared index over both position, normal and vertex.

    0 1 2 3

    Where:

    0 = <position index & normal_index & vertex index>
    1 = <position index & normal_index & vertex index>
    2 = <position index & normal_index & vertex index>'
    3 = <position index & normal_index & vertex index>
    

    You can see the 4models has:

    <triangles material="Block" count="12">
        <input semantic="VERTEX" source="#Box01-geometry-vertices" offset="0" />
        <input semantic="NORMAL" source="#Box01-normals" offset="1" />
        <input semantic="TEXCOORD" source="#Box01-texcoords" offset="2" />
        <p>0 0 0 1 0 1 2 0 2 1 0 1 3 0 (...)</p> (vertexes X 3 numbers)
    </triangles> 
    

    The other one has:

    <triangles material="Block" count="12">
        <input semantic="VERTEX" source="#Box01-geometry-vertices" />
        <input semantic="NORMAL" source="#Box01-normals" />
        <input semantic="TEXCOORD" source="#Box01-texcoords" />
        <p>0 1 2 3 4 5 6 7 7 8 9 10 11 (...)</p> (vertexes X 1 numbers)
    </triangles>
    

    So, all i had to do is remove the hardcoded offsets and use the offets from the XML.