Jump to content
  • Advertisement
Sign in to follow this  
NLScotty

Mesh, SubMesh and Model. Differences and caching?

This topic is 542 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

 

 

Share this post


Link to post
Share on other sites
Advertisement

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)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!