Loading a textured model – Q&A, and another example
A student wrote:
Hello. I’ve tried creating models in Google SketchUp, exported them as collada files and then turned them into .uwsm files; removing the xml code. but for some reason I’ve never managed to get this to work? I’ve added uwsm0_2 in the beginning of the file but still doesnt do it.
I’ve tried several models, even a single square wont work. I’m getting runtime errors. I’ve asked other students if theyve managed to get it to work but no one i’ve asked has been successful doing this. I was wondering if you could explain a little further of how to hack the code.
I’ll post the Collada file i’ve used and also the uwsm(which doesnt work). If you have a spare minute, could you hack this simple collada file and upload the uwsm model so I can see the difference between my one and the working one?
Kind Regards
And this came with a Collada .dae file and a corresponding attempt at making a uwsm file. The uwsm file was as follows:
uwsm0_265.35433070866142 57.8740157480315 0 0 0 0 0 57.8740157480315 0 65.35433070866142 0 0 0 0 -1 0 0 -1 0 0 -1 0 0 -1
(The “_” between the first 0 and 2 is there, but for some reason doesn’t show above)
The reply is as follows:
I don’t think you read the format description here:
http://3dgamedev.wordpress.com/2010/10/16/loading-models-from-file/. This can be summarised as:
uwsm0_2
n1
{n1 many floats - three for each vertex, represents the vertex positions}
n2
{n2 many floats - three for each vertex, represents the normals}
n3
{n3 many floats - two for each vertex, represents the texture co-ords}
n4
{n4 * 6 many integers - n4 is the number of triangles. This is the index list. For each triangle three vertex indices and three texture indices are required. These are interleaved as v1 t1 v2 t2 v3 t3}
To get sketch-up to generate texture coordinates and save them in the Collada file, you need to place a texture on the model in collada.
So, what is wrong with your file (this assumes you are using the load model code that loads a textured model!)… the following:
1. No white space after “uwsm0_2″
2. No integer to say how many floating point numbers to read for vertex positions (this can be found in the collada file in the xml just before the list of vertex positions)
3. No integer to say how many floats to read for normals (again, can be found in collada file)
4. No texture data at all
5. No data for the triangle indices. The data for this can be found in the collada file here:
<triangles count="2" material="Material2">
<input offset="0" semantic="VERTEX" source="#ID7" />
<p>0 1 2 1 0 3</p>
</triangles>
count="2" is the number of triangles. The list of integers is the index list. As you did not texture the model, this does not include texture coords which we will need. For a simple square it isn’t too hard to make these up though.
Fixing these errors I got the square to display. I then swapped the direction of the normals to swap the facing of the square to display better in the existing loadTexModel-GLTools code. With all these changes, the uwsm file is as follows:
uwsm0_2
12
65.35433070866142 57.8740157480315 0 0 0 0 0 57.8740157480315 0 65.35433070866142 0 0
12
0.0 0.0 1.0 0.0 0.0 1.0 0.0 0.0 1.0 0.0 0.0 1.0
8
0.0 0.0 1.0 1.0 0.0 1.0 1.0 0.0
2
0 0 1 1 2 2 1 1 0 0 3 3

