Page 1 of 2 12 LastLast
Results 1 to 10 of 15

Thread: Triangle normals

  1. #1

    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.

  2. #2
    Member
    Join Date
    Feb 2005
    Location
    San Jose, CA
    Posts
    63

    Re: Triangle normals

    COLLADA uses vertex normal.
    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.
    http://www.collada.org/mediawiki/index. ... _directory

    Herbert

  3. #3
    Senior Member
    Join Date
    Aug 2004
    Location
    California
    Posts
    771

    Re: Triangle normals

    Quote Originally Posted by uclahklaw
    for each vertex, you have 3 inputs
    0 0 0 means position index 0, normal index 0, texcoord index 0.
    ... because of the values of the offset attribute of the <input> elements.
    Quote Originally Posted by zeeshanzia84
    <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"/>

  4. #4
    cdndave
    Guest

    Re: Triangle normals

    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.

    Code :
    format "<triangles count=\"%\">\n" 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

  5. #5
    Sorlaize
    Guest

    Re: Triangle normals

    Quote Originally Posted by cdndave
    Any help would be greatly apreciated.
    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

  6. #6
    Senior Member
    Join Date
    Aug 2004
    Location
    California
    Posts
    771

    Re: Triangle normals

    Quote Originally Posted by Sorlaize
    The

    is a polygons tag.
    Actually

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

  7. #7
    Dinan
    Guest

    Re: Triangle normals

    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:


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

    Thanks in advance,
    Matthias

  8. #8
    Senior Member
    Join Date
    Aug 2004
    Location
    California
    Posts
    771

    Re: Triangle normals

    Correct.

  9. #9
    Junior Member
    Join Date
    Jan 2011
    Posts
    13

    Re: Triangle normals

    Can somebody explain me how it can be that there are more normals than vertices?
    Code :
    <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 downloaded this model from official Collada library, its name is "Moon Buggy".

  10. #10
    Junior Member
    Join Date
    Jan 2011
    Posts
    13

    Re: Triangle normals

    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?

Page 1 of 2 12 LastLast

Posting Permissions

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