Search code examples
c#xnamonogame

Importing an ultralarge XNA Model (poly count)


I am currently attempting to import a very large Model into XNA/Monogame, a steel construction model with upwards of 80,000,000 vertices. The engine is written to optimise this model for visualisation, with an OcTree and View Frustum culling operating on the ModelMesh level.

I've recently learned that the default base.Process operation in the Model Processor combines the vertex and index buffers of all the ModelMesh's in the Model, per the answer in this post:

Confusion about model's vertexbuffer and indexbuffer

This presents a problem, in that this model exceeds the maximum VertexBuffer size of 67108863. As a result, the Content Processor won't even let me create the xnb file.

Ideally, I would split the Vertex and Index Buffers into multiple smaller buffers in the Content Processor, but the Buffers themselves are generated in the Model Processor's base.Process function, and doesn't appear to be editable afterwards.

Is there any mechanism I can use to split an XNA Model's Vertex and Index Buffers?


Solution

  • I ended up solving this problem. XNA Models simply don't support multiple vertex and index buffers, so the solution was to write a Large Model Custom Content Processor that returns an array of ModelContent objects, rather than just the one.

    This can be called easily enough like so:

    Model[] myModel = Content.Load<Model[]>("myModelFile");
    

    ... and although it required a number of changes to my triangle picking and drawing routines, turned out to be a relatively easy solution to implement.