XNA Creators Club Online
Page 1 of 1 (4 items)
Sort Posts: Previous Next

MeshBuilder issue

Last post 05-08-2008 7:07 PM by Shawn Hargreaves. 3 replies.
  • 05-08-2008 4:15 PM

    MeshBuilder issue

     

    I am writing implementation of custom model importer, processor all the way to my own custom model class.

    Using MeshBuilder class , I am creating a set of positions followed by iteration of all faces (separated by calls to SetMaterial)
    My geometry is composed of a single set of positions (corresponding to a single vertexbuffer) and a set of faces ( which all are indexing the same set of positions)
    Sort of like:

    Positions:
    Position 1
    Position 2
    Position 3
    Faces (material A)
    Face1 index1, index2, index3
    Face2 index4, index5 index6
    Faces ( material B)
    Face1 index7, index8, index9
    Face2 index10, index11 index12


     

    This results in multiple sets of GeometryContent objects corresponding to the number of SetMaterial calls ( in this case material A and material B)
    The only problem is that each of these GeometryContent objects gets its own VertexContent/IndexCollection, which is not what I want in this case.
    In other words, what I get is something like

    GeometryContent - material A
    VertexContent
    IndexCollection - indexes from 0
    GeometryContent - material B
    VertexContent
    IndexCollection - indexes from 0


    In effect, what happens is that my original single vertex buffer/ multiple index buffers geometry gets split into two GeometryContent objects which have their own set of vertex/index buffers.
    The question is, how do I proceed to end up with single VertexContent containing all my positions data and a separate set of IndexCollections , all indexing into the same VertexContent.
    In other words, how does one implement a single vertexbuffer, multiple index buffers within the MeshBuilder/content pipeline framework.

  • 05-08-2008 4:58 PM In reply to

    Re: MeshBuilder issue

    The intermediate object model (GeometryContent, VertexContent, etc) always has a separate vertex collection per GeometryContent.

    I'm curious: is all your vertex data identical between the different sets of faces, or do you also have other vertex data like texture coordinates and colors that is not the same from one material to the next?

    If your vertex data is literally identical (ie. you are drawing the exact same geometry more than once, just with a different material each time)  would suggest only creating a single geometry instance, and then just toggling the material (perhaps using different effect techniques) when you draw this at runtime.

    If you have other vertex channels that are not identical, so that you do need truly different vertex output data per geometry, and are just wanting to merge these into a larger vertex buffer to avoid changing VB so often, you can do that after you convert from the intermediate object model into VertexBufferContent format. VertexBufferContent has some helper methods that make it easy to concatenate several different blocks of data into one.

    If you need some more complex mapping than either of the above, that's not supported by default, but you should be able to roll your own fairly easy by implementing your own version of the built in VertexContent.CreateVertexBuffer. That's a pretty thin wrapper that basically just calls VertexBufferContent.Write for each channel of vertex data. The vertex data channels are all individually exposed as .NET collections, and Write can insert any collection of data you like with any stride value you like, which makes it pretty easy to stitch vertex data together however you need it.

    XNA Framework Developer - blog - homepage
  • 05-08-2008 6:10 PM In reply to

    Re: MeshBuilder issue

    Yes, my vertex data always uses the same set of channels.

    I wrote a plugin for Lightwave which takes care of a lot of stuff and exports data that is pretty much ready for real time rendering ( meaning vertices that share multiple set of UV coordinates get duplicated, same for hard edge vertices etc)

     

    So what I end up with is a collection of positions (vertices) and multiuple sets of (face)triangle definitions which index into the same single set of positions( say first set of faces indexes into positions 0-100, second set of faces into positions 101-200 and so on)

     

    Ultimately what I want to get at the other end of the pipe ( in my custom model content reader) is a single vertex buffer and multiple index buffers so that during rendering I can set the vertex buffer once per mesh and simply issue render calls for each set of index buffers (potentially changing texture and other  shader parameters.)

     

    I guess, what I am missing is a way to concatenate different  VertexContents from  multiple GeometryContent objects (so I could simply call GeometryContent .Vertices.CreateVertexBuffer and serialize that data once) , but still have a different set of GeometryContent .Indices serialized on their own with some custom material attributes per each ( while still indexing into the shared VertexContent)
  • 05-08-2008 7:07 PM In reply to

    Re: MeshBuilder issue

    You can't (easily, anyway) concatenate the VertexContent, but you can separately convert each VertexContent to a VertexBufferContent, and then concatenate the resulting VertexBufferContent.
    XNA Framework Developer - blog - homepage
Page 1 of 1 (4 items) Previous Next