1
\$\begingroup\$

Since I could not find any libraries that can help me parse collada files in my c++/opengl project, I decided to write my own. (I did find assimp, but binaries for Visual Studio 2013 were't available, and I don't know enough to build it myself from the source; Can anyone build it and share it please? )

I read up a little about the structure of .dae files, figured I could do it, and exported Suzanne from Blender in a .dae file. Fine. Now I open up the .dae file in Notepad++ just to make sure I got the basic understanding right, and I found something weird.

Screenshot of the .dae file

So the tags [float_array id="Suzanne-mesh-positions-array" count="1521"] and [/float_array] contain the huge list of vertex positions right?

And the tags [p] and [/p] inside [polylist count = "968"] and [/polylist] should contain vertex indices in triangular order right? But that doesn't make sense, cause then the first triangle is going to be vertex[46], vertex[0] and vertex[0].. But how is that possible? Any help please? If I've got it wrong, can someone direct me to some place where i can learn how to parse collada files. Thanks a lot.

EDIT: I finally managed to build Assimp for VS 2013 (YAAYYYY!!)after getting awesome instructions at http://www.learnopengl.com/#!Model-Loading/Assimp

But my confusion regarding the vertex indices remain.

\$\endgroup\$
3
\$\begingroup\$

So the tags [float_array id="Suzanne-mesh-positions-array" count="1521"] and [/float_array] contain the huge list of vertex positions right?

Yes.

And the tags [p] and [/p] inside [polylist count = "968"] and [/polylist] should contain vertex indices in triangular order right? But that doesn't make sense, cause then the first triangle is going to be vertex[46], vertex[0] and vertex[0].. But how is that possible?

Your confusion is that collada uses a different set of indices for each <input, not for each vertex. So each vertex in the <p> array has indeed 2 indices: the first index is the vertex position (because of the offset="0"), and the second indice is the normal. Indeed the indices in the collada file are different than the indices than would be in an OpenGL index buffer.

In your file, the first primitive is a triangle (3 in the <vcount> array), it uses the indices 46 0 0 0 2 0 and you must read its vertices as : {position[46] normal[0]}, {position[0] normal[0]}, {position[2] normal[0]}.

Building an OpenGL index buffer data from this format requires some postprocessing to find the duplicate vertices.

can someone direct me to some place where i can learn how to parse collada files. Thanks a lot

If you want to learn the collada file you should have a look at the collada specification, but it is not the best way to understand the format. You should export a quad or triangle mesh from Blender to have simple example files that you could study.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.