Creating a triangle strip        

Overview

I found it a little tricky to find information on how to create triangle strips in the ogre mesh file format. So when I found out how, I decided to create a simple tutorial.

What is a triangle strip?

A triangle strip is a series of connected triangles. Because the triangles are connected, the application does not need to repeatedly specify all three vertices for each triangle. For example, you need only six vertices to define the following triangle strip:

How it works in Ogre

The ogre mesh xml format is quite convenient at visualizing triangle strips, as it supports them without having to convert your triangle strip into a list. Specify 'operationtype="triangle_strip"' in the submesh instead of triangle_list.

Since 3 indices no longer directly map to a face, ogre has the vertices v2 and v3 as optional. "For the 2nd face onwards you only need to specify 'v1' when creating a strip or fan. v2 / v3 will be ignored if you include them (except for the first face)." 1 This is a simple neat solution to the index to face mapping problem.

This is the DTD of the mesh format where you can see more information about the optional vertices: Ogre meshxml DTD.

Example

SimpleTriangleStrip.mesh.xml

<mesh>
    <sharedgeometry vertexcount="6">
        <vertexbuffer positions="true" normals="true" texture_coord_dimensions_0="2" texture_coords="1">
            <vertex>
                <position x="-5" y="-5" z="0" />
                <normal x="0" y="0" z="0" />
                <texcoord u="0" v="0" />
            </vertex>
            <vertex>
                <position x="0" y="5" z="0" />
                <normal x="0" y="0" z="0" />
                <texcoord u="0.2" v="1" />
            </vertex>
            <vertex>
                <position x="5" y="-5" z="0" />
                <normal x="0" y="0" z="0" />
                <texcoord u="0.4" v="0" />
            </vertex>
            <vertex>
                <position x="10" y="5" z="0" />
                <normal x="0" y="0" z="0" />
                <texcoord u="0.6" v="1" />
            </vertex>
            <vertex>
                <position x="15" y="-5" z="0" />
                <normal x="0" y="0" z="0" />
                <texcoord u="0.8" v="0" />
            </vertex>
            <vertex>
                <position x="20" y="5" z="0" />
                <normal x="0" y="0" z="0" />
                <texcoord u="1" v="1" />
            </vertex>
        </vertexbuffer>
    </sharedgeometry>
    <submeshes>
        <submesh material="SimpleTriangleStrip.mesh/Material_0" usesharedvertices="true" use32bitindexes="false" operationtype="triangle_strip">
            <faces count="4">
                <face v1="0" v2="1" v3="2" />
                <face v1="3" />
                <face v1="4" />
                <face v1="5" />
            </faces>
        </submesh>
    </submeshes>
</mesh>

SimpleTriangleStrip.mesh.material

material SimpleTriangleStrip.mesh/Material_0
{
    technique
    {
        pass
        {
            ambient 1 1 1
            diffuse 1 1 1
            specular 0 0 0 0
            emissive 1 1 1
            cull_hardware none
            cull_software none
            texture_unit
            {
                texture SimpleTriangleStrip.png
            }
        }
    }
}

SimpleTriangleStrip.png

Texture applied to the triangle strip to make it easier to see.
Texture applied to the triangle strip to make it easier to see.

Tips

  • Use OgreXmlConverter.exe to convert the xml into a .mesh file.
  • Use Show Mesh to view it.

References