# Triangle normals

Hi,

I want to obtain the normals of the triangles in the collada files. However, what I don’t understand is that, each vertex is assigned a normal instead of the face.

Can someone please tell me, how to obtain the normal of the triangle, from the following.

<triangles material=“FrontColorNoCulling” count=“6”>
<input semantic=“VERTEX” source="#mesh1-geometry-vertex" offset=“0”/>
<input semantic=“NORMAL” source="#mesh1-geometry-normal" offset=“1”/>
<input semantic=“TEXCOORD” source="#mesh1-geometry-uv" offset=“2” set=“0”/>

0 0 0 1 0 1 2 0 2 1 0 1 0 0 0 3 0 3 0 1 4 4 1 5 3 1 1 4 1 5 0 1 4 5 1 6 4 2 7 1 2 1 3 2 8 1 2 1 4 2 7 6 2 5 </p>
</triangles>

I am trying to implement simple backface culling for a game.

In your example, you have 6 triangles, each row is a triangle.

0 0 0 1 0 1 2 0 2
1 0 1 0 0 0 3 0 3
0 1 4 4 1 5 3 1 1
4 1 5 0 1 4 5 1 6
4 2 7 1 2 1 3 2 8
1 2 1 4 2 7 6 2 5
</p>

for first triangle, you have 3 vertices.
vertex 1 has 0 0 0
vertex 2 has 1 0 1
vertex 3 has 2 0 2

for each vertex, you have 3 inputs
0 0 0 means position index 0, normal index 0, texcoord index 0.
second vertex
1 0 1 means position index 1, normal index 0, texcoord index 1.
third vertex
2 0 2 means position index 2, normal index 0, texcoord index 2.

Note that all the normals of vertices that make up the first triangle have index 0.
Since all the normals of each vertices of this triangle is the same, you can kind of consider it the face normal.

To change face culling, you can either change triangle winding order or negate normal vector.
They both can serve as a good example for conditioners.

Herbert

… because of the values of the offset attribute of the <input> elements.

I realize that this doesn’t really belong here but i figure its close enough to the current discussion that there is no reason to start a new thread.

I am currently trying to write a collada exporter in MaxScript and am having trouble figuring out how to generate the triangle primitives. I have the array of vertices and array of normals but dont understand the logic needed to create triangles by referencing them. Any help would be greatly apreciated.

``````
format "<triangles count=\"%\">
" numfaces to:outfile
format "<input offset=\"0\" semantic=\"VERTEX\" source=\"#%-lib-vertices\" />" obname to:outfile
format "<input offset=\"1\" semantic=\"NORMAL\" source=\"#%-lib-normals\" />" obname to:outfile
format "<input offset=\"2\"/>" to:outfile
format "

" to:outfile

not sure how to generate contents of this tag

format"</p>" to:outfile
format "</triangles>" to:outfile

``````

The

is a polygons tag.

In uclahklaw’s post each line is a triangle with 3 vertices; each combination of the vertex format (in this case POSITION, NORMAL, TEXCOORD = 3 ints) just indexes the respective source arrays making a vertex, but you will also need to calssify TEXCOORD as being a 2d array.

In another case though:

<vertices id=“mesh0-vertices”>
<input semantic=“POSITION” source="#mesh0-positions"/>
</vertices>
<triangles material=“mesh0-material” count=“6”>
<input semantic=“VERTEX” source="#mesh0-vertices" offset=“0”/>

</triangles>

You’ll need to be careful what you whitelist to parse Irrlicht has some code that might help, it iterates over the xml tags.

hth

Actually

stands for primitive (i.e. mesh primitive).

Hello!

I’m sorry for waking up this thread again but i feel like my question fits in here somehow,
because it already helped me a lot but there’s still something I don’t understand.
I also have troubles understanding the <triangles> tag.

The following snippet is from my COLLADA file:

``````
<source id="ID5">
<float_array id="ID8" count="72">78.74016 39.37008 0 0 (and so on)
<technique_common>
<accessor count="24" source="#ID8" stride="3">
<param name="X" type="float" />
<param name="Y" type="float" />
<param name="Z" type="float" />
</accessor>
</technique_common>
</source>
<source id="ID6">
<float_array id="ID9" count="72">0 0 -1 0 0 -1 (and so on)
<technique_common>
<accessor count="24" source="#ID9" stride="3">
<param name="X" type="float" />
<param name="Y" type="float" />
<param name="Z" type="float" />
</accessor>
</technique_common>
</source>
<vertices id="ID7">
<input semantic="POSITION" source="#ID5" />
<input semantic="NORMAL" source="#ID6" />
</vertices>
<triangles count="12" material="Material2">
<input offset="0" semantic="VERTEX" source="#ID7" />

0 1 2
1 0 3
4 5 6
5 4 7
8 9 10
9 8 11
12 13 14
13 12 15
16 17 18
17 16 19
20 21 22
21 20 23
</p>
</triangles>

``````

I understood that there are 12 triangles. Each with 3 inputs defined in the <triangles>.
A triangle should be defined by vertices. I can’t see the three points needed for that.

Do the three numbers in this case mean:

Vertex one has POSITION 0 and NORMAL 0,
vertex two has POSITION 1 and NORMAL 1,
vertex three has POSITIN 2 and NORMAL 2?

I’d really appreciate if anyone could confirm or explain this too me.

Matthias

Correct.

Can somebody explain me how it can be that there are more normals than vertices?

``````<geometry id="left_hand-lib" name="left_hand">
<mesh>
<source id="left_hand-lib-positions" name="position">
<float_array id="left_hand-lib-positions-array" count="1293">47.432 -4.1503 13.5184 52.1328 -2.1701 -7.4793 -73.7637 156.806 7.6272 -91.1421 170.003 14.3747 71.3855 -35.4334 4.3607 27.0541 17.1761 -52.4569 34.5556 ... -68.705 33.8767 112.046 -116.297 149.034 39.4086</float_array>
<technique_common>
<accessor count="431" source="#left_hand-lib-positions-array" stride="3">
<param name="X" type="float"/>
<param name="Y" type="float"/>
<param name="Z" type="float"/>
</accessor>
</technique_common>
</source>
<source id="left_hand-lib-normals" name="normal">
<float_array id="left_hand-lib-normals-array" count="5004">0.010859 0.721541 0.692287 0.464285 0.730745 0.500451 0.478567 0.769619 0.422682 -0.014417 0.56493 0.825013 0.533228 0.586976 -0.609202 0.267596 0.529129 -0.805242 0.017901 0.327089 -0.944824 0.217462 0.183122 -0.958737 ....... 0.237381 -0.171585 -0.956143 0.463208 -0.278467 -0.841365</float_array>
<technique_common>
<accessor count="1668" source="#left_hand-lib-normals-array" stride="3">
<param name="X" type="float"/>
<param name="Y" type="float"/>
<param name="Z" type="float"/>
</accessor>
</technique_common>
</source>
<vertices id="left_hand-lib-vertices">
<input semantic="POSITION" source="#left_hand-lib-positions"/>
</vertices>
<triangles count="840" material="mat_hands">
<input offset="0" semantic="VERTEX" source="#left_hand-lib-vertices"/>
<input offset="1" semantic="NORMAL" source="#left_hand-lib-normals"/>

106 1 54 2 371 0 371 0 54 2 370 3 45 4 32 5 423 8 423 8 32 5 397 7 32 5 384 6 397 7 245 10 370 11 46 9 46 9 370 11 3 13 370 11 54 12 3 13 52 16 43 17 ...... 357 1664 349 1666 347 1667</p>
</triangles>
</mesh>
</geometry>

``````

If there are more normals than vertices and they all could not be used. Is it an error?

I have made a few tests and realized that all 1668 normals are used. It means that for one vertex there is more than one normal. What does it mean?

A “vertex” is not just a position. A vertex includes many attributes that make it unique, including position, normal, texture coordinate, color, etc… It means that your mesh has 1668 unique vertices (position + normal).

It is clear. But what is it when one position has more than one normal? What does it mean in 3D graphics?

It means you have more then one vertex with coincident position.

Stupid question Marcus, but as a new user I am wondering what makes a vertex coincident? I checked out the wikipedia, but would like to hear from somebody with Collada experience who could maybe simplify the definition for me.

Coincident vertices are ones that share the same position, e.g. a triangle with two vertices at the origin and one elsewhere results in a line. i.e. it’s a degenerate triangle.

The concept of coincidence can apply to all the vertex attributes (position, normal, color, texcoords, tangents, etc. etc.) if one is sorting vertices to remove all redundency from the set of vertices. Any single attribute of a vertex that is unique, that differentiates it from others for the purpose at hand, makes for a unique vertex.