3es  0.7
tes::SimpleMesh Class Reference

An encapsulated definition of a mesh. It manages all its own vertices, indices, etc. More...

#include <3essimplemesh.h>

Inheritance diagram for tes::SimpleMesh:
tes::MeshResource tes::Resource

Public Types

enum  ComponentFlag {
  Vertex = (1 << 0), Index = (1 << 1), Colour = (1 << 2), Color = Colour,
  Normal = (1 << 3), Uv = (1 << 4)
}
 Flags indicating which components are present. More...
 

Public Member Functions

 SimpleMesh (uint32_t id, unsigned vertexCount=0, unsigned indexCount=0, DrawType drawType=DtTriangles, unsigned components=Vertex|Index)
 Construct a SimpleMesh resource. More...
 
 ~SimpleMesh ()
 Destructor.
 
virtual void clear ()
 Reset this mesh to a simple mesh with only Vertex and Index components.
 
virtual void clearData ()
 Clear only the data arrays. Memory is preserved.s.
 
virtual uint32_t id () const override
 The resource ID. More...
 
virtual Matrix4f transform () const override
 
void setTransform (const Matrix4f &transform)
 Set the object transformation matrix for this mesh. More...
 
virtual uint32_t tint () const override
 
void setTint (uint32_t tint)
 Set the colour tint value for the mesh. More...
 
SimpleMeshclone () const override
 Performs a shallow copy of this mesh. More...
 
virtual uint8_t drawType (int stream) const override
 
DrawType getDrawType () const
 Get the drawType() as a DrawType value.
 
void setDrawType (DrawType type)
 Set the draw type as a DrawType value. More...
 
unsigned components () const
 Query the ComponentFlag components used by this mesh. More...
 
void setComponents (unsigned components)
 Set the ComponentFlag components for this mesh. More...
 
void addComponents (unsigned components)
 Add ComponentFlag values to the existing set. More...
 
unsigned vertexCount () const
 
virtual unsigned vertexCount (int stream) const override
 Returns the number of vertices in the mesh. More...
 
void setVertexCount (unsigned count)
 
void reserveVertexCount (unsigned count)
 
unsigned addVertex (const Vector3f &v)
 
unsigned addVertices (const Vector3f *v, unsigned count)
 
bool setVertex (unsigned at, const Vector3f &v)
 
unsigned setVertices (unsigned at, const Vector3f *v, const unsigned count)
 
const Vector3fvertices () const
 
virtual const float * vertices (unsigned &stride, int stream=0) const override
 Returns a pointer to the vertex stream. More...
 
unsigned indexCount () const
 
virtual unsigned indexCount (int stream) const override
 Returns the number of indices in the mesh. More...
 
void setIndexCount (unsigned count)
 
void reserveIndexCount (unsigned count)
 
void addIndex (uint32_t i)
 
void addIndices (const uint32_t *idx, unsigned count)
 
bool setIndex (unsigned at, uint32_t i)
 
unsigned setIndices (unsigned at, const uint32_t *idx, unsigned count)
 
const uint32_t * indices () const
 
virtual const uint8_t * indices (unsigned &stride, unsigned &width, int stream=0) const override
 Returns a pointer to the index stream. More...
 
bool setNormal (unsigned at, const Vector3f &n)
 
unsigned setNormals (unsigned at, const Vector3f *n, const unsigned count)
 
const Vector3fnormals () const
 
virtual const float * normals (unsigned &stride, int stream) const override
 Returns a pointer to the normal stream. More...
 
bool setColour (unsigned at, uint32_t c)
 
unsigned setColours (unsigned at, const uint32_t *c, unsigned count)
 
const uint32_t * colours () const
 
virtual const uint32_t * colours (unsigned &stride, int stream) const override
 Returns a pointer to the colour stream. More...
 
bool setUv (unsigned at, float u, float v)
 
unsigned setUvs (unsigned at, const float *uvs, const unsigned count)
 
const float * uvs () const
 
virtual const float * uvs (unsigned &stride, int stream) const override
 Returns a pointer to the UV stream. More...
 
- Public Member Functions inherited from tes::MeshResource
virtual ~MeshResource ()
 Virtual destructor.
 
uint16_t typeId () const override
 Returns MtMesh.
 
int create (PacketWriter &packet) const override
 Populate a mesh creation packet. More...
 
int destroy (PacketWriter &packet) const override
 Populate a mesh destroy packet. More...
 
int transfer (PacketWriter &packet, int byteLimit, TransferProgress &progress) const override
 Populate the next mesh data packet. More...
 
*tes::PacketWriter packet ()
 Compose a mesh index component message in packet. More...
 
while (offset< mesh->indexCount()) *
 
- Public Member Functions inherited from tes::Resource
virtual ~Resource ()
 Virtual destructor (empty).
 
uint64_t uniqueKey () const
 Returns a unique key for this resource, based on the typeId() and id().
 

Protected Member Functions

 SimpleMesh (const SimpleMesh &other)
 Copy constructor supporting initial, shallow copy with copy on write semantics. More...
 
- Protected Member Functions inherited from tes::MeshResource
virtual void nextPhase (TransferProgress &progress) const
 

Additional Inherited Members

- Static Public Member Functions inherited from tes::MeshResource
static int estimateTransferCount (size_t elementSize, unsigned byteLimit, int overhead=0)
 Estimate the number of elements which can be transferred at the given byteLimit. More...
 
*</code > **param packet Packet to write to *param meshId The mesh to which the data belong *param offset An index count offset to start writing from See remarks *param byteLimit A hard limit on the number of bytes to write *param dataSource Base pointer for the index data *param dataStride Number of bytes between indices *param indexByteWidth The byte size of a single index Generally equal to p dataStride *param componentCount The total number of indices *return The number of indices written *static unsigned writeIndices (PacketWriter &packet, uint32_t meshId, uint32_t offset, unsigned byteLimit, const uint8_t *dataSource, unsigned dataStride, unsigned indexByteWidth, uint32_t componentCount)
 
*</code > **param packet Packet to write to *param meshId The mesh to which the data belong *param offset An vertex count offset to start writing from See remarks *param byteLimit A hard limit on the number of bytes to write *param dataSource Base pointer for the vertex data *param dataStride Number of bytes between indices *param componentCount The total number of indices *return The number of indices written *static unsigned writeVectors3 (PacketWriter &packet, uint32_t meshId, uint32_t offset, unsigned byteLimit, const uint8_t *dataSource, unsigned dataStride, uint32_t componentCount)
 
static unsigned writeVectors2 (PacketWriter &packet, uint32_t meshId, uint32_t offset, unsigned byteLimit, const uint8_t *dataSource, unsigned dataStride, uint32_t componentCount)
 Compose a mesh float vector 2 component message in packet. More...
 
static unsigned writeColours (PacketWriter &packet, uint32_t meshId, uint32_t offset, unsigned byteLimit, const uint8_t *dataSource, unsigned dataStride, uint32_t componentCount)
 Compose a mesh component message for writing colour data in packet. More...
 
- Public Attributes inherited from tes::MeshResource
*const tes::MeshResourcemesh =
 
*uint32_t offset = 0
 
*unsigned dataStride
 
*unsigned indexByteWidth
 
*const uint8_t * indicesPtr = reinterpret_cast<const uint8_t *>(indices(dataStride, indexByteWidth))
 
offset
 Compose a mesh float vector 3 component message in packet. More...
 

Detailed Description

An encapsulated definition of a mesh. It manages all its own vertices, indices, etc.

Member Enumeration Documentation

◆ ComponentFlag

Flags indicating which components are present.

Vertex flag is always set. Other flags are optional, though Index is preferred.

Enumerator
Vertex 

Contains vertices. This flag is enforced.

Constructor & Destructor Documentation

◆ SimpleMesh() [1/2]

tes::SimpleMesh::SimpleMesh ( uint32_t  id,
unsigned  vertexCount = 0,
unsigned  indexCount = 0,
DrawType  drawType = DtTriangles,
unsigned  components = Vertex|Index 
)

Construct a SimpleMesh resource.

Parameters
idAn ID unique among all tes::Resource objects.
vertexCountNumber of vertices to preallocate.
indexCountNumber of indices to preallocate.
drawTypeDefines the primitive type being indexed.
componentsThe components defined by this mesh. See ComponentFlag.

◆ SimpleMesh() [2/2]

tes::SimpleMesh::SimpleMesh ( const SimpleMesh other)
protected

Copy constructor supporting initial, shallow copy with copy on write semantics.

Parameters
otherThe mesh to copy.

Member Function Documentation

◆ addComponents()

void tes::SimpleMesh::addComponents ( unsigned  components)
inline

Add ComponentFlag values to the existing set.

Parameters
componentsAdditional ComponentFlag values to set. Already set values are effectively ignored.

◆ clone()

SimpleMesh* tes::SimpleMesh::clone ( ) const
overridevirtual

Performs a shallow copy of this mesh.

Note that any modification of the mesh data results in a copy of the existing data. Otherwise SimpleMesh objects can share their data.

Implements tes::Resource.

◆ colours()

virtual const uint32_t* tes::SimpleMesh::colours ( unsigned &  stride,
int  stream 
) const
overridevirtual

Returns a pointer to the colour stream.

Each element is taken 32-bit integer. Expects vertexCount(stream) elements or null if no vertex colours.

Parameters
[out]strideThe stride between colour elements (bytes). This would be 4 for a contiguous array of uint32_t colours.
streamReserved for future use.
Returns
A pointer to the first colour value or null.

Implements tes::MeshResource.

◆ components()

unsigned tes::SimpleMesh::components ( ) const

Query the ComponentFlag components used by this mesh.

Returns
The ComponentFlag values.

◆ drawType()

virtual uint8_t tes::SimpleMesh::drawType ( int  stream) const
overridevirtual

Implements tes::MeshResource.

◆ id()

virtual uint32_t tes::SimpleMesh::id ( ) const
overridevirtual

The resource ID.

Unique among resources of the same typeId().

Returns
The resource's ID.

Implements tes::Resource.

◆ indexCount()

virtual unsigned tes::SimpleMesh::indexCount ( int  stream) const
overridevirtual

Returns the number of indices in the mesh.

Parameters
streamReserved for future use.
Returns
The number of indices.

Implements tes::MeshResource.

◆ indices()

virtual const uint8_t* tes::SimpleMesh::indices ( unsigned &  stride,
unsigned &  width,
int  stream = 0 
) const
overridevirtual

Returns a pointer to the index stream.

Supports different index widths. Expects indexCount(stream) elements or null if no indices.

Parameters
[out]strideSpecifies the stride between index elements (bytes). This would be 4 for a contiguous array of uint32_t indices.
[out]Specifiesthe index byte width. Supports [1, 2, 4].
streamReserved for future use.
Returns
A pointer to the first index.

Implements tes::MeshResource.

◆ normals()

virtual const float* tes::SimpleMesh::normals ( unsigned &  stride,
int  stream 
) const
overridevirtual

Returns a pointer to the normal stream.

Each element is taken as a triple of single precision floats: (x, y, z). Expects vertexColour(stream) elements or null if no normals.

Parameters
[out]strideThe stride between normal elements (bytes). This would be 12 for a contiguous array of float triples.
streamReserved for future use.
Returns
A pointer to the first normal or null

Implements tes::MeshResource.

◆ setComponents()

void tes::SimpleMesh::setComponents ( unsigned  components)

Set the ComponentFlag components for this mesh.

Parameters
componentsComponentFlag values to set.

◆ setDrawType()

void tes::SimpleMesh::setDrawType ( DrawType  type)

Set the draw type as a DrawType value.

Parameters
typeThe draw type to set.

◆ setTint()

void tes::SimpleMesh::setTint ( uint32_t  tint)

Set the colour tint value for the mesh.

The colour is defined in hex as 0xRRGGBBAA, best calculated using the Colour class.

Parameters
tintThe RGBA tint colour.

◆ setTransform()

void tes::SimpleMesh::setTransform ( const Matrix4f transform)

Set the object transformation matrix for this mesh.

This will often be redundant when the mesh is used with a MeshSet object as that object defines its own object matrix and a transformation matrix for each contains MeshResource.

Parameters
transformThe object transformation matrix for the mesh.

◆ tint()

virtual uint32_t tes::SimpleMesh::tint ( ) const
overridevirtual

Implements tes::MeshResource.

◆ transform()

virtual Matrix4f tes::SimpleMesh::transform ( ) const
overridevirtual

Implements tes::MeshResource.

◆ uvs()

virtual const float* tes::SimpleMesh::uvs ( unsigned &  stride,
int  stream 
) const
overridevirtual

Returns a pointer to the UV stream.

Each element is taken as a pair of single precision floats: (u, v). Expects vertexCount(stream) elements or null if no UVs.

Parameters
[out]strideThe stride between UV elements (bytes). This would be 8 for a contiguous array of float pairs.
streamReserved for future use.
Returns
A pointer to the first UV coordinate or null.

Implements tes::MeshResource.

◆ vertexCount()

virtual unsigned tes::SimpleMesh::vertexCount ( int  stream) const
overridevirtual

Returns the number of vertices in the mesh.

Parameters
streamReserved for future use.
Returns
The number of vertices.

Implements tes::MeshResource.

◆ vertices()

virtual const float* tes::SimpleMesh::vertices ( unsigned &  stride,
int  stream = 0 
) const
overridevirtual

Returns a pointer to the vertex stream.

Each element is taken as a triple of single precision floats: (x, y, z).

Parameters
[out]strideThe stride between vertex elements (bytes). This would be 12 for a contiguous array of float triples.
streamReserved for future use.
Returns
A pointer to the first vertex.

Implements tes::MeshResource.


The documentation for this class was generated from the following file: