Mesh Class Reference

Description

Primary class for holding geometry.

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

Note
Sim thread.

Inherits MeshBase.

Methods

void initialize () override
 Initializes all the internal resources of this object. More...
 
AsyncOp writeData (const SPtr< MeshData > &data, bool discardEntireBuffer)
 Updates the mesh with new data. More...
 
AsyncOp readData (const SPtr< MeshData > &data)
 Reads internal mesh data to the provided previously allocated buffer. More...
 
SPtr< MeshDataallocBuffer () const
 Allocates a buffer that exactly matches the size of this mesh. More...
 
void readCachedData (MeshData &data)
 Reads data from the cached system memory mesh buffer into the provided buffer. More...
 
SPtr< SkeletongetSkeleton () const
 Gets the skeleton required for animation of this mesh, if any is available. More...
 
SPtr< MorphShapesgetMorphShapes () const
 Returns an object containing all shapes used for morph animation, if any are available. More...
 
SPtr< ct::MeshgetCore () const
 Retrieves a core implementation of a mesh usable only from the core thread. More...
 
RTTITypeBasegetRTTI () const override
 Returns an interface you can use to access class' Run Time Type Information. More...
 
- Methods inherited from MeshBase
 MeshBase (UINT32 numVertices, UINT32 numIndices, DrawOperationType drawOp=DOT_TRIANGLE_LIST)
 Constructs a new mesh with no sub-meshes. More...
 
 MeshBase (UINT32 numVertices, UINT32 numIndices, const Vector< SubMesh > &subMeshes)
 Constructs a new mesh with one or multiple sub-meshes. More...
 
const MeshPropertiesgetProperties () const
 Returns properties that contain information about the mesh. More...
 
SPtr< ct::MeshBasegetCore () const
 Retrieves a core implementation of a mesh usable only from the core thread. More...
 
RTTITypeBasegetRTTI () const override
 Returns an interface you can use to access class' Run Time Type Information. More...
 
- Methods inherited from Resource
 Resource (bool requiresGpuInitialization=true)
 
const WStringgetName () const
 Returns the name of the resource. More...
 
void setName (const WString &name)
 Sets the name of the resource. More...
 
SPtr< ResourceMetaDatagetMetaData () const
 Retrieves meta-data containing various information describing a resource. More...
 
virtual bool allowAsyncLoading () const
 Returns whether or not this resource is allowed to be asynchronously loaded. More...
 
RTTITypeBasegetRTTI () const override
 Returns an interface you can use to access class' Run Time Type Information. More...
 
- Methods inherited from IReflectable
bool isDerivedFrom (RTTITypeBase *base)
 Returns true if current RTTI class is derived from base (Or if it is the same type as base). More...
 
UINT32 getTypeId () const
 Returns an unique type identifier of the class. More...
 
const StringgetTypeName () const
 Returns the type name of the class. More...
 
- Methods inherited from CoreObject
virtual void destroy ()
 Frees all the data held by this object. More...
 
bool isDestroyed () const
 Returns true if the object has been destroyed. More...
 
void blockUntilCoreInitialized () const
 Blocks the current thread until the resource is fully initialized. More...
 
UINT64 getInternalID () const
 Returns an unique identifier for this object. More...
 
SPtr< CoreObjectgetThisPtr () const
 Returns a shared_ptr version of "this" pointer. More...
 
SPtr< ct::CoreObjectgetCore () const
 Returns an object that contains a core thread specific implementation of this CoreObject. More...
 
void syncToCore ()
 Ensures all dirty syncable data is send to the core thread counterpart of this object (if any). More...
 
void _setThisPtr (SPtr< CoreObject > ptrThis)
 Sets a shared this pointer to this object. More...
 

Static methods

static HMesh dummy ()
 Returns a dummy mesh, containing just one triangle. More...
 
static RTTITypeBasegetRTTIStatic ()
 
static HMesh create (UINT32 numVertices, UINT32 numIndices, const SPtr< VertexDataDesc > &vertexDesc, int usage=MU_STATIC, DrawOperationType drawOp=DOT_TRIANGLE_LIST, IndexType indexType=IT_32BIT)
 Creates a new empty mesh. More...
 
static HMesh create (const MESH_DESC &desc)
 Creates a new empty mesh. More...
 
static HMesh create (const SPtr< MeshData > &initialData, const MESH_DESC &desc)
 Creates a new mesh from an existing mesh data. More...
 
static HMesh create (const SPtr< MeshData > &initialData, int usage=MU_STATIC, DrawOperationType drawOp=DOT_TRIANGLE_LIST)
 Creates a new mesh from an existing mesh data. More...
 
Internal
static SPtr< Mesh_createPtr (const MESH_DESC &desc)
 Creates a new empty mesh. More...
 
static SPtr< Mesh_createPtr (const SPtr< MeshData > &initialData, const MESH_DESC &desc)
 Creates a new mesh from an existing mesh data. More...
 
static SPtr< Mesh_createPtr (const SPtr< MeshData > &initialData, int usage=MU_STATIC, DrawOperationType drawOp=DOT_TRIANGLE_LIST)
 Creates a new mesh from an existing mesh data. More...
 
static SPtr< MeshcreateEmpty ()
 Creates a new empty and uninitialized mesh. More...
 
- Static methods inherited from MeshBase
static RTTITypeBasegetRTTIStatic ()
 
- Static methods inherited from Resource
static RTTITypeBasegetRTTIStatic ()
 
- Static methods inherited from IReflectable
static Vector< RTTITypeBase * > & getDerivedClasses ()
 Returns all classes deriving directly from IReflectable. More...
 
static SPtr< IReflectablecreateInstanceFromTypeId (UINT32 rttiTypeId)
 Creates an empty instance of a class from a type identifier. More...
 
static void _registerDerivedClass (RTTITypeBase *derivedClass)
 Called by each type deriving from IReflectable, on program load. More...
 
static RTTITypeBase_getRTTIfromTypeId (UINT32 rttiTypeId)
 Returns class' RTTI type from type id. More...
 
static bool _isTypeIdDuplicate (UINT32 typeId)
 Checks if the provided type id is unique. More...
 
static void _checkForCircularReferences ()
 Iterates over all RTTI types and reports any circular references (for example one type having a field referencing another type, and that type having a field referencing the first type). More...
 
static RTTITypeBasegetRTTIStatic ()
 Returns an interface you can use to access class' Run Time Type Information. More...
 
- Static methods inherited from CoreObject
template<class T , class MemAlloc >
static void _delete (CoreObject *obj)
 Schedules the object to be destroyed, and then deleted. More...
 

Additional Inherited Members

- Protected Types inherited from CoreObject
enum  Flags { CGO_DESTROYED = 0x01, CGO_INIT_ON_CORE_THREAD = 0x02 }
 Values that represent current state of the core object. More...
 

Method documentation

static SPtr<Mesh> _createPtr ( const MESH_DESC desc)
static

Creates a new empty mesh.

Parameters
[in]descDescriptor containing the properties of the mesh to create.
Note
Internal method. Use create() for normal use.
static SPtr<Mesh> _createPtr ( const SPtr< MeshData > &  initialData,
const MESH_DESC desc 
)
static

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.

Parameters
[in]initialDataVertex and index data to initialize the mesh with.
[in]descDescriptor 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.
Note
Internal method. Use create() for normal use.
static SPtr<Mesh> _createPtr ( const SPtr< MeshData > &  initialData,
int  usage = MU_STATIC,
DrawOperationType  drawOp = DOT_TRIANGLE_LIST 
)
static

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.

Parameters
[in]initialDataVertex and index data to initialize the mesh with.
[in]usageOptimizes performance depending on planned usage of the mesh.
[in]drawOpDetermines how should the provided indices be interpreted by the pipeline. Default option is a triangle strip, where three indices represent a single triangle.
Note
Internal method. Use create() for normal use.
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.

Note
Thread safe.
static HMesh create ( UINT32  numVertices,
UINT32  numIndices,
const SPtr< VertexDataDesc > &  vertexDesc,
int  usage = MU_STATIC,
DrawOperationType  drawOp = DOT_TRIANGLE_LIST,
IndexType  indexType = IT_32BIT 
)
static

Creates a new empty mesh.

Created mesh will have no sub-meshes.

Parameters
[in]numVerticesNumber of vertices in the mesh.
[in]numIndicesNumber of indices in the mesh.
[in]vertexDescVertex 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.
[in]usageOptimizes performance depending on planned usage of the mesh.
[in]drawOpDetermines how should the provided indices be interpreted by the pipeline. Default option is a triangle list, where three indices represent a single triangle.
[in]indexTypeSize of indices, use smaller size for better performance, however be careful not to go over the number of vertices limited by the size.
static HMesh create ( const MESH_DESC desc)
static

Creates a new empty mesh.

Parameters
[in]descDescriptor containing the properties of the mesh to create.
static HMesh create ( const SPtr< MeshData > &  initialData,
const MESH_DESC desc 
)
static

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.

Parameters
[in]initialDataVertex and index data to initialize the mesh with.
[in]descDescriptor 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.
static HMesh create ( const SPtr< MeshData > &  initialData,
int  usage = MU_STATIC,
DrawOperationType  drawOp = DOT_TRIANGLE_LIST 
)
static

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.

Parameters
[in]initialDataVertex and index data to initialize the mesh with.
[in]usageOptimizes performance depending on planned usage of the mesh.
[in]drawOpDetermines how should the provided indices be interpreted by the pipeline. Default option is a triangle strip, where three indices represent a single triangle.
SPtr<ct::CoreObject> createCore ( ) const
overrideprotectedvirtual

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

Can be null if such object is not required.

Reimplemented from CoreObject.

void createCPUBuffer ( )
protected

Creates buffers used for caching of CPU mesh data.

Note
Make sure to initialize all mesh properties before calling this.
static SPtr<Mesh> createEmpty ( )
static

Creates a new empty and uninitialized mesh.

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

Note
This should only be used for special cases like serialization and is not meant for normal use.
static HMesh dummy ( )
static

Returns a dummy mesh, containing just one triangle.

Don't modify the returned mesh.

SPtr<ct::Mesh> getCore ( ) const

Retrieves a core implementation of a mesh usable only from the core thread.

SPtr<MorphShapes> getMorphShapes ( ) const

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

RTTITypeBase* getRTTI ( ) const
overridevirtual

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

Note
You must derive your own version of RTTITypeBase, in which you may encapsulate all reflection specific operations.

Implements IReflectable.

SPtr<Skeleton> getSkeleton ( ) const

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

void initialize ( )
overridevirtual

Initializes all the internal resources of this object.

Must be called right after construction. Generally you should call this from a factory method to avoid the issue where user forgets to call it.

Note
If this object require initialization on core thread initialization is not done immediately, and is instead just scheduled on the core thread. Otherwise the object is initialized immediately.

Reimplemented from CoreObject.

void readCachedData ( MeshData data)

Reads data from the cached system memory mesh buffer into the provided buffer.

Parameters
[out]dataPre-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.
Note
The data read is the cached mesh data. Any data written to the mesh from the GPU or core thread will not be reflected in this data. Use readData() if you require those changes.
The mesh must have been created with MU_CPUCACHED usage otherwise this method will not return any data.
AsyncOp 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.

Parameters
[out]dataPre-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.
Note
This is an asynchronous method.
void updateBounds ( const MeshData meshData)
protected

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

void updateCPUBuffer ( UINT32  subresourceIdx,
const MeshData data 
)
protected

Updates the cached CPU buffers with new data.

AsyncOp writeData ( const SPtr< MeshData > &  data,
bool  discardEntireBuffer 
)

Updates the mesh with new data.

Provided data buffer will be locked until the operation completes.

Parameters
[in]dataData of valid size and format to write to the subresource.
[in]discardEntireBufferWhen 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.
Note
This is an asynchronous method.