Skip to main content
GameDev.net gamedev.net
🔒 Locked 🎮 Unity

Mesh, SubMesh and Model. Differences and caching?

Started by NLScotty Jan 22, 2017 at 3:49 PM 0 replies 3.8k views
Original Post
NLScotty
NLScotty

Hi,

I hope I could ask you something about Models/Meshes and SubMeshes. I am kinda confused by these 3 terms. From my understanding right now it works like this.


struct SubMesh
{
VertexBuffer m_VB;
IndexBuffer m_IB;
MaterialPtr m_Material;
Transform m_LocalPos;
Transform m_WorldPos;
}

struct Mesh
{
std::vector<SubMeshes> m_SubMeshes;
AnimationData m_AnimData;

}

struct Model
{
std::vector<Mesh> m_Meshes;
Transform m_WorldPos;
}

I am kinda confused about this:

  • What is the point of SubMeshes? You could just create more Meshes inside model?
  • If each SubMesh has its own VBO and IBO(I use dx11 for now, but easy naming), drawing takes more time. You could have only 1 VBO in mesh and use that I guess? My VertexBuffer class saves the format that I specify when I create it.
  • What part should be cached? The Model? The Mesh? The SubMesh? I guess the later 2 make most sense.

My Vertexbuffer class looks now like this : It is not done yet, because I am not sure yet about my Mode/Mesh/SubMesh design. Besides that, I guess a lot of info is missing for now, but it's just a start.


enum class VertexAttributeType
{
    Position,
    Color,
    Reflectance,
    TexCords,
    Normal,
    Tangent
};

struct VertexAttribute
{
    VertexAttributeType Type;
    std::size_t Arity; // Since it's always a float, but it could be float4, float 3 etcetc

    VertexAttribute(VertexAttributeType Type, std::size_t Arity) :
        Type(Type),
        Arity(Arity)
    {

    }
};

struct BufferFormat
{
    bool Interleaved; // If false, it only has 1 Attribute, this is when I want to update the Buffer.
    std::vector<VertexAttribute> Attributes;
};

struct SetupBuffer
{
    BufferFormat Format;
    std::vector<float> Data; //It's always a float I guess
};

class IVertexBuffer : public IBuffer
{
public:

    virtual PResult Setup(SetupBuffer SetupInfo);

protected:
    IVertexBuffer();
    virtual void CreateRaw() = 0; // Call to d3d11, but it makes it easier to add GL if I ever want to.

    BufferFormat m_Format;
};

I guess since a VB know it's format, I could play around the Mesh/SubMesh more, to make them use 1 VB, but the code becomes messier and messier that way.

cozzie
cozzie

My few cents;

- I'd never give a submesh it's own vtx/indexbuffer, just store offsets in the parent/ full mesh's vtx/index buffers

- point of a submesh is/ could be that you want different materials on different submeshes

-- i.e. car is mesh, wheels are submeshes with their own material

- what the code above calls 'Model', I call mesh instance

- basically you have a mesh with data, vertex/indexbuffer, submeshes etc.

-- then you have a meshinstance using that mesh (could be 100 instances using one mesh, maybe trees or so)

- I also store matrices/ orientations of submeshes, with regard to the parent mesh

(so you can individually do things with it, i.e. rotating wheels on the example car)

Crealysm game & engine development: http://www.crealysm.com

Looking for a passionate, disciplined and structured producer? PM me

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.