Home | Lehre | Videos | Texte | Vorträge | Software | Person | Impressum, Datenschutzerklärung | Blog RSS This example shows how to extract vertex and index data from an .x file.

void FromFile(Device myDevice, string path, out CustomVertex.PositionNormalTextured[] vbOriginalData, out short[] ibOriginalData)
{
    GraphicsStream adjacency;
    Mesh myMesh = Mesh.FromFile(path, MeshFlags.Managed, myDevice, out adjacency);

    VertexBuffer vb = myMesh.VertexBuffer;
    if(vb.Description.VertexFormat != CustomVertex.PositionNormalTextured.Format)
    {
        throw new Exception("Wrong vertex format in mesh.");
    }
    vbOriginalData =
        (CustomVertex.PositionNormalTextured[])
        vb.Lock(0, typeof(CustomVertex.PositionNormalTextured), LockFlags.ReadOnly, myMesh.NumberVertices)
        .Clone();
    vb.Unlock();

    IndexBuffer ib = myMesh.IndexBuffer;
    if(ib.Description.Size % 6 != 0) // 3 vertices, 2 bytes each
    {
        throw new Exception("Mesh needs repair.");
    }
    ibOriginalData =
        (short[])
        ib.Lock(0, typeof(short), LockFlags.ReadOnly, 3*myMesh.NumberFaces)
        .Clone();
    ib.Unlock();

    myMesh.Dispose();
}