I am trying to extend XNA's content pipeline in order to import a model in .obj format (a very simple and text-based format, see here for details). Writing a full extension library seems like an overkill to me so I decided I would only create a custom importer and a processor which returns a ModelContent so that I could use the default writer and reader.
My processor sort of works but not exacly as expected: what should look like an aircraft is actually a bunch of triangles stick together! Before writing this I had a simple class derived from DrawableGameComponent which loaded the model in its LoadContent, but that's not exacly XNA-ish. The point is that the code worked, so there must be a problem in the construction of the MeshContent.
I have followed the pattern I found in this question during my researches.

Here's the relevant part:

[ContentProcessor( DisplayName = "dotObjProcessor" )]
public class dotObjProcessor : ContentProcessor<dotObjContent, ModelContent> {
    public override ModelContent Process( dotObjContent input, 
        ContentProcessorContext context ) {

        var mc = new MeshContent( );
        foreach ( dotObjContent.Vertex p in input.Vertices )
            mc.Positions.Add( new Vector3( p.X, p.Y, p.Z ) );

        var gc = new GeometryContent( );
        foreach ( dotObjContent.Face f in input.Faces ) {
            gc.Vertices.Add( f.V1 );
            gc.Vertices.Add( f.V2 );
            gc.Vertices.Add( f.V3 );

            gc.Indices.Add( f.V1 );
            gc.Indices.Add( f.V2 );
            gc.Indices.Add( f.V3 );

        mc.Geometry.Add( gc );
        MeshHelper.CalculateNormals( mc, true );

        return context.Convert<MeshContent, ModelContent>( mc, "ModelProcessor" );

A dotObjContent is the output of my importer, it simply contains two collections for vertices and indices.

  • \$\begingroup\$ Have you tried the custom model importer before? Are you trying to add compatibility for more kinds of .obj models? \$\endgroup\$
    – ChrisC
    Feb 1, 2013 at 23:00
  • \$\begingroup\$ @ChrisC: no, I didn't know anything about it \$\endgroup\$
    – BlackBear
    Feb 2, 2013 at 12:50

1 Answer 1


Alright, brand new here, so I couldn't comment to try and draw out information to help you out better...

I'm assuming your mesh looks like a bunch of triangles roughly at the right places but with some unsightly gaps? The shader hasn't been given the hint that it needs to draw the tri's continuously, so that is likely what is happening.

XNA has a class specifically for what you are trying to do, they call it MeshBuilder. MSDN page is here:


This will take the triangles your OBJ has defined and stitch them together in the way you're expecting. You just need to call StartMesh(), add the vertexes basically the same way you were in your code but with AddTriangleVertex(), and then FinishMesh() will return the MeshContent you want.

Hope this helps.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .