How does AddVertices work?

About Monkey 2 Forums Monkey 2 Programming Help How does AddVertices work?

This topic contains 4 replies, has 3 voices, and was last updated by  DruggedBunny 1 year, 3 months ago.

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #12499

    DruggedBunny
    Participant

    I’m attempting to build my own meshes, but I can only get the first triangle to show up.

    If you comment out the first call to AddMesh (around line 112, below) the second triangle is correctly shown, but with the first call in place, the second triangle doesn’t appear:

    Wondered if AddVertices needed ALL vertices (both current mesh verts PLUS the new ones), but that didn’t work either — see commented-out attempt in AddMesh.

    By way of explanation, AddMesh takes an existing Model, a new Mesh (received from CreateTriangle) and in theory adds the vertices from that new Mesh to the existing Model, though I don’t know if this is correct/appropriate.

    Also not sure if I should be using UpdateNormals, etc… ?

    #12505

    Pakz
    Participant

    Mark added a banana that showed how to create a quad mesh. I asked for a example back then. I made several more examples that I have on my monkey2-3d github.

    https://github.com/Pakz001/Monkey2-3D

    #12517

    DruggedBunny
    Participant

    I was actually looking closely at those earlier, Pakz, but a search suggested AddVertices wasn’t part of it — I’m basically trying to add vertices to an existing mesh that I’ve created, rather than create all vertices in one go, which I think all of your samples do.

    #12521

    Mark Sibly
    Keymaster

    You need to AddTriangles too – all meshes are currently indexed so you will need to add the triangle indices for any newly added vertices.

    In this though, simply going  “model.Mesh.AddTriangles (mesh.GetIndices() )” wont work because you’ll just be adding the same [0,1,2], you’ll need to be trickier.

    [edit]I just added AddMesh and it appears to work, ie: instead of addVertices use: model.Mesh.AddMesh( mesh ) which will add vertices and ‘relocated’ indices – draws a quad here anyway.

    You’ll have to be a bit cleverer with the model.Materials array too – you’ll need to ‘grow’ this for each added material, in fact maybe it should just be a stack?

    Anyway, here’re my tweaks:

    The future of Model.Material is still up in the air, I may yet rip it out and just leave Model.Materials.

    UpdateNormals/Tangents aren’t really needed as AddMesh doesn’t merge vertices so it wont affect existing normals/tangents. Eventually though, there’ll probably be an Optimize() method that will merge vertices and you’ll need to update normals/tangents after that.

    Note the Mesh class is really designed for ‘offline’ stuff. In realtime, it’ll be much faster to directly use VertexBuffers and IndexBuffers and to override OnRender.

    #12528

    DruggedBunny
    Participant

    Thanks, Mark, that’ll do me!

    Yeah, I’ve yet to try and grasp materials, but the Material/Materials[] thing is confusing, and I’d thought iterating through Materials[] would be needed to do things properly.

    Perhaps Materials[0] could be used as the default and then overridden by the user as they see fit?

    Yeah, something that optionally merges vertices would be good.

    Not got anywhere near VertexBuffers and co yet! This’ll let me get started on building things myself, then I’ll no doubt move on and try get vertex buffers and co…

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.