How to change Model indexbuffer

I'm currently trying to change indexbuffer of a model with a SetData func, but it remains unchanged...

My general task is to draw certains polygons of a model, what i must to to make it

I found here topic about how to get vertexbuffer of a model, but i still can't set my indices...

Any help would be appreciated :)




Answer this question

How to change Model indexbuffer

  • Vishal Shah

    Yeah, you can get vertices by writing your custom processor.


  • mike11d11

    I posted a topic about changing model vertices, I was inquiring as to whether or not it would work and I was told it would not. I would image the same is true for index buffers as well.
    To get that working, I think you would have to write a custom importer, processor, writer and reader for the ContentPipeline.

  • LouisVanAlphen

    NeTBaPb wrote:

    I'm currently trying to change indexbuffer of a model with a SetData func, but it remains unchanged...

    My general task is to draw certains polygons of a model, what i must to to make it



    That sounds like a bug: SetData should either work, or throw an exception if you're using it in an incorrect way. If you can provide some code that reproduces this problem, could you attach that to a bug over on the connect site

    Regarding selecting only certain polygons, you have many options depending on exactly what you are trying to do:
    • You don't need to call ModelMesh.Draw. That is actaully just a very simple method that begins the effect and then calls DrawIndexedPrimitive once for each ModelMeshPart. If you did this yourself, you could easily use any index buffer you liked, or choose any subset of the existing index buffer.
    • In many cases an easier way may just be to put the different things you want to draw at different times into a separate ModelMesh. That way you can just choose not to bother drawing the ModelMesh that you don't want at any given time. If your incoming artwork isn't already split into suitable meshes, you could use a content pipeline processor to split the geometry up however you like.



  • yabing

    "omg, there is no indexbuffer in modelcontent, so the only way to make what i want is to follow your advice and make custom draw calls using model class. but anyway i need to GET that indices first and i still cant find the way to make it :/"

    ModelContent.Meshes[].IndexBuffer

    Cheers,
    Leaf.


  • jellali

    CodePfo wrote:

    To get that working, I think you would have to write a custom importer, processor, writer and reader for the ContentPipeline.


    You shouldn't need to write a custom importer: that's only neccessary if you are adding support for a whole new source file format.

    Almost always to extend the content pipeline, you only have to write a new processor. If you are adding new data types you may also need to implement a writer and reader, but if you are just altering what data goes into the existing types, the processor is all you need.


  • Roger McKinney

    i don't understand why setdata didnt work...

    anyway this is funny

    "The XNA Framework Content Pipeline, which is a set of tools that allow developers to more easily incorporate 3D content into their games." - XNA FAQ

    in mdx all i needed is load a model and in xna (that helps me save my time!) i need to write my own classes to make things that in mdx i already could use without any problems........



  • Fox Me Up

    the source code is very easy, i just added setdata to standard code that i saw in the xna help:

    foreach (ModelMesh mesh in level.Meshes)

    {

    foreach (BasicEffect effect in mesh.Effects)

    {

    effect.EnableDefaultLighting();

    effect.World = Matrix.Identity;

    effect.View = mainCamera.ViewMatrix;

    effect.Projection = mainCamera.ProjectionMatrix;

    }

    short[] p = new short[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 };  // test array

    mesh.IndexBuffer.SetData<short>(p); // this call do nothing........ no error no result. am i doing something wrong

    mesh.Draw();

    }

     

    and about polygons. i wanna reimplement my octree under xna. all i need is read all vertices postion, than read all triangles (i.e. indices), then build tree. i cant separate level mesh into different parts, coz i dont know what part of my tree will be visible every frame :)

    i think i will get vertex and index buffer using technique in this topic http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=891302&SiteID=1 copy it into my class that contains index and vertex buffers and make my own draw calls out of Model class...

    ---

    omg, there is no indexbuffer in modelcontent, so the only way to make what i want is to follow your advice and make custom draw calls using model class. but anyway i need to GET that indices first and i still cant find the way to make it :/



  • rcurrie

    Leaf. wrote:

    ModelContent.Meshes[].IndexBuffer

    Cheers,
    Leaf.

    ohhhhh, thx a lot... i should sleep more at night -.- otherwise soon i'll loose even System namespace...



  • How to change Model indexbuffer