class Mesh

Inherits: MeshBase

Primary class for holding geometry.

Stores data in the form of vertex buffers and optionally an index buffer, which may be bound to the pipeline for drawing. May contain multiple sub-meshes.

Public

Methods

~Mesh

virtual ~Mesh() noexcept = default

Initialize

void Initialize() override

Initializes all the internal data of this object.

Must be called right after construction for new objects, or after deserialization for deserialized objects. If requested, render proxy is created and queued for initialization on the render thread.

WriteData

TAsyncOp<void> WriteData(const SPtr<MeshData> &data, bool discardEntireBuffer)

Updates the mesh with new data.

Provided data buffer will be locked until the operation completes.

data
Data of valid size and format to write to the subresource.
discardEntireBuffer
When true the existing contents of the resource you are updating will be discarded. This can make the operation faster. Resources with certain buffer types might require this flag to be in a specific state otherwise the operation will fail.

Returns: Async operation object you can use to track operation completion.

ReadData

TAsyncOp<void> ReadData(const SPtr<MeshData> &data)

Reads internal mesh data to the provided previously allocated buffer.

Provided data buffer will be locked until the operation completes.

data
Pre-allocated buffer of proper vertex/index format and size where data will be read to. You can use allocBuffer() to allocate a buffer of a correct format and size.

Returns: Async operation object you can use to track operation completion.

AllocBuffer

SPtr<MeshData> AllocBuffer() const

Allocates a buffer that exactly matches the size of this mesh.

This is a helper function, primarily meant for creating buffers when reading from, or writing to a mesh.

GetCachedData

SPtr<MeshData> GetCachedData() const

Returns mesh data cached in the system memory.

If the mesh wasn't created with CPU cached usage flag this method will not return any data. Caller should not modify the returned data.

GetSkeleton

SPtr<Skeleton> GetSkeleton() const

Gets the skeleton required for animation of this mesh, if any is available.

GetMorphShapes

SPtr<MorphShapes> GetMorphShapes() const

Returns an object containing all shapes used for morph animation, if any are available.

staticDummy

static HMesh Dummy()

Returns a dummy mesh, containing just one triangle.

Don't modify the returned mesh.

staticGetRttiStatic

static RTTIType *GetRttiStatic()

GetRtti

RTTIType *GetRtti() const override

Returns an interface you can use to access class' Run Time Type Information.

staticCreate

static HMesh Create(u32 vertexCount, u32 indexCount, const SPtr<VertexDescription> &vertexDescription, MeshFlags flags = MeshFlag::Static, DrawOperationType primitiveType = DOT_TRIANGLE_LIST, IndexType indexType = IT_32BIT)

Creates a new empty mesh.

Created mesh will have no sub-meshes.

vertexCount
Number of vertices in the mesh.
indexCount
Number of indices in the mesh.
vertexDescription
Vertex description structure that describes how are vertices organized in the vertex buffer. When binding a mesh to the pipeline you must ensure vertex description at least partially matches the input description of the currently bound vertex GPU program.
flags
Flags to control various mesh options.
primitiveType
Determines how should the provided indices be interpreted by the pipeline. Default option is a triangle list, where three indices represent a single triangle.
indexType
Size of indices, use smaller size for better performance, however be careful not to go over the number of vertices limited by the size.

staticCreate

static HMesh Create(const MeshCreateInformation &meshCreateInformation)

Creates a new empty mesh.

meshCreateInformation
Descriptor containing the properties of the mesh to create.

staticCreate

static HMesh Create(const SPtr<MeshData> &initialData, const MeshCreateInformation &meshCreateInformation)

Creates a new mesh from an existing mesh data.

Created mesh will match the vertex and index buffers described by the mesh data exactly. Mesh will have no sub-meshes.

initialData
Vertex and index data to initialize the mesh with.
meshCreateInformation
Descriptor containing the properties of the mesh to create. Vertex and index count, vertex descriptor and index type properties are ignored and are read from provided mesh data instead.

staticCreate

static HMesh Create(const SPtr<MeshData> &initialData, MeshFlags flags = MeshFlag::Static, DrawOperationType primitiveType = DOT_TRIANGLE_LIST)

Creates a new mesh from an existing mesh data.

Created mesh will match the vertex and index buffers described by the mesh data exactly. Mesh will have no sub-meshes.

initialData
Vertex and index data to initialize the mesh with.
flags
Flags to control various mesh options.
primitiveType
Determines how should the provided indices be interpreted by the pipeline. Default option is a triangle strip, where three indices represent a single triangle.

Internal

Methods

staticCreateShared

static SPtr<Mesh> CreateShared(const MeshCreateInformation &meshCreateInformation)

staticCreateShared

static SPtr<Mesh> CreateShared(const SPtr<MeshData> &initialData, const MeshCreateInformation &meshCreateInformation)

staticCreateShared

static SPtr<Mesh> CreateShared(const SPtr<MeshData> &initialData, MeshFlags flags = MeshFlag::Static, DrawOperationType primitiveType = DOT_TRIANGLE_LIST)

staticCreateEmptyShared

static SPtr<Mesh> CreateEmptyShared()

Creates a new empty and uninitialized mesh.

You will need to manually initialize the mesh before using it.

Protected

Constructors

Mesh

Mesh(const MeshCreateInformation &meshCreateInformation)

Mesh

Mesh(const SPtr<MeshData> &initialMeshData, const MeshCreateInformation &meshCreateInformation)

Methods

UpdateBounds

void UpdateBounds(const MeshData &meshData)

Updates bounds by calculating them from the vertices in the provided mesh data object.

CreateRenderProxy

SPtr<render::RenderProxy> CreateRenderProxy() const override

Creates an object that contains render thread specific data and methods for this object.

Can be null if such object is not required.

CreateCpuBuffer

void CreateCpuBuffer()

Creates buffers used for caching of CPU mesh data.

UpdateCpuBuffer

void UpdateCpuBuffer(u32 subresourceIndex, const MeshData &data)

Updates the cached CPU buffers with new data.

Fields

mCPUData

SPtr<MeshData> mCPUData

mVertexDescription

SPtr<VertexDescription> mVertexDescription

mFlags

MeshFlags mFlags

mIndexType

IndexType mIndexType

mSkeleton

SPtr<Skeleton> mSkeleton

mMorphShapes

SPtr<MorphShapes> mMorphShapes

Private

Constructors

Mesh

Mesh()

*********************************************************************