Polycode
Polycode::Mesh Class Reference

A polygonal mesh. More...

List of all members.

Public Member Functions

 Mesh (int meshType)
 Construct with an empty mesh of specified type.
 Mesh (const String &fileName)
 Construct from a mesh loaded from a file.
void addPolygon (Polygon *newPolygon)
 Adds a polygon to the mesh.
void loadMesh (const String &fileName)
 Loads a mesh from a file.
void clearMesh ()
 Clears mesh data.
void saveToFile (const String &fileName)
 Saves mesh to a file.
unsigned int getPolygonCount ()
 Returns the number of polygons in the mesh.
unsigned int getVertexCount ()
 Returns the total vertex count in the mesh.
PolygongetPolygon (unsigned int index)
 Returns a polygon at specified index.
void createPlane (Number w, Number h)
 Creates a plane mesh of specified size.
void createVPlane (Number w, Number h)
 Creates a vertical plane mesh of specified size.
void createTorus (Number radius, Number tubeRadius, int rSegments, int tSegments)
 Creates a torus.
void createBox (Number w, Number d, Number h)
 Creates a cube mesh of specified size.
void createSphere (Number radius, int numRings, int numSegments)
 Creates a sphere mesh of specified size.
void createCylinder (Number height, Number radius, int numSegments, bool capped=true)
 Creates a cylinder mesh.
void createCone (Number height, Number radius, int numSegments)
 Creates a cone mesh.
Vector3 recenterMesh ()
 Recenters the mesh with all vertices being as equidistant from origin as possible.
void useVertexNormals (bool val)
 Toggles the mesh between using vertex or polygon normals.
void setVertexBuffer (VertexBuffer *buffer)
 Sets the vertex buffer for the mesh.
VertexBuffer * getVertexBuffer ()
 Returns the vertex buffer for the mesh.
Number getRadius ()
 Returns the radius of the mesh (furthest vertex away from origin).
void calculateNormals (bool smooth=true, Number smoothAngle=90.0)
 Recalculates the mesh normals.
void calculateTangents ()
 Recalculates the tangent space vector for all vertices.
int getMeshType ()
 Returns the mesh type.
void setMeshType (int newType)
 Sets a new mesh type.
Vector3 calculateBBox ()
 Calculates the mesh bounding box.
bool hasVertexBuffer ()
 Checks if the mesh has a vertex buffer.

Public Attributes

bool arrayDirtyMap [16]
 Render array dirty map.
RenderDataArrayrenderDataArrays [16]
 Render arrays.
bool useVertexColors
 If set to true, the renderer will use the vertex colors instead of entity color transform to render this mesh.

Static Public Attributes

static const int QUAD_MESH = 0
 Quad based mesh.
static const int TRI_MESH = 1
 Triangle based mesh.
static const int TRIFAN_MESH = 2
 Triangle fan based mesh.
static const int TRISTRIP_MESH = 3
 Triangle strip based mesh.
static const int LINE_MESH = 4
 Line based mesh.
static const int POINT_MESH = 5
 Point based mesh.

Detailed Description

A polygonal mesh.

The mesh is assembled from Polygon instances, which in turn contain Vertex instances. This structure is provided for convenience and when the mesh is rendered, it is cached into vertex arrays with no notions of separate polygons. When data in the mesh changes, arrayDirtyMap must be set to true for the appropriate array types (color, position, normal, etc). Available types are defined in RenderDataArray.


Constructor & Destructor Documentation

Polycode::Mesh::Mesh ( int  meshType)

Construct with an empty mesh of specified type.

Parameters:
meshTypeType of mesh. Possible values are: Mesh::QUAD_MESH, Mesh::TRI_MESH, Mesh::TRIFAN_MESH, Mesh::TRISTRIP_MESH, Mesh::LINE_MESH, Mesh::POINT_MESH.
Polycode::Mesh::Mesh ( const String fileName)

Construct from a mesh loaded from a file.

Parameters:
fileNamePath to mesh file.

Member Function Documentation

void Polycode::Mesh::addPolygon ( Polygon newPolygon)

Adds a polygon to the mesh.

Parameters:
newPolygonPolygon to add.
void Polycode::Mesh::calculateNormals ( bool  smooth = true,
Number  smoothAngle = 90.0 
)

Recalculates the mesh normals.

Parameters:
smoothIf true, will use smooth normals.
smoothAngleIf smooth, this parameter sets the angle tolerance for the approximation function.
void Polycode::Mesh::createBox ( Number  w,
Number  d,
Number  h 
)

Creates a cube mesh of specified size.

Parameters:
wWidth of cube.
dDepth of cube.
hHeight of cube.
void Polycode::Mesh::createCone ( Number  height,
Number  radius,
int  numSegments 
)

Creates a cone mesh.

Parameters:
heightHeight of the cone.
radiusRadius of the cone.
numSegmentsNumber of segments.
void Polycode::Mesh::createCylinder ( Number  height,
Number  radius,
int  numSegments,
bool  capped = true 
)

Creates a cylinder mesh.

Parameters:
heightHeight of the cylinder.
radiusRadius of the cylinder.
numSegmentsNumber of segments.
cappedCreate the end caps.
void Polycode::Mesh::createPlane ( Number  w,
Number  h 
)

Creates a plane mesh of specified size.

Parameters:
wWidth of plane.
hDepth of plane.
void Polycode::Mesh::createSphere ( Number  radius,
int  numRings,
int  numSegments 
)

Creates a sphere mesh of specified size.

Parameters:
radiusRadius of sphere.
numRingsNumber of rings.
numSegmentsNumber of segments.
void Polycode::Mesh::createTorus ( Number  radius,
Number  tubeRadius,
int  rSegments,
int  tSegments 
)

Creates a torus.

Parameters:
radiusRadius of the torus.
tubeRadiusRadious of the tube.
rSegmentsNumber of radial segments.
tSegmentsNumber of tube segments.
void Polycode::Mesh::createVPlane ( Number  w,
Number  h 
)

Creates a vertical plane mesh of specified size.

Parameters:
wWidth of plane.
hDepth of plane.
Polygon * Polycode::Mesh::getPolygon ( unsigned int  index)

Returns a polygon at specified index.

Parameters:
indexIndex of polygon.
Returns:
Polygon at index.
unsigned int Polycode::Mesh::getPolygonCount ( )

Returns the number of polygons in the mesh.

Returns:
Number of polygons in the mesh.
Number Polycode::Mesh::getRadius ( )

Returns the radius of the mesh (furthest vertex away from origin).

Returns:
Mesh radius.
VertexBuffer * Polycode::Mesh::getVertexBuffer ( )

Returns the vertex buffer for the mesh.

Returns:
The vertex buffer for this mesh.
unsigned int Polycode::Mesh::getVertexCount ( )

Returns the total vertex count in the mesh.

Returns:
Number of vertices in the mesh.
bool Polycode::Mesh::hasVertexBuffer ( ) [inline]

Checks if the mesh has a vertex buffer.

Parameters:
Trueif the mesh has a vertex buffer, false if not.
void Polycode::Mesh::loadMesh ( const String fileName)

Loads a mesh from a file.

Parameters:
fileNamePath to mesh file.
void Polycode::Mesh::saveToFile ( const String fileName)

Saves mesh to a file.

Parameters:
fileNamePath to file to save to.
void Polycode::Mesh::setMeshType ( int  newType)

Sets a new mesh type.

Parameters:
newTypeNew mesh type. Possible values are: Mesh::QUAD_MESH, Mesh::TRI_MESH, Mesh::TRIFAN_MESH, Mesh::TRISTRIP_MESH, Mesh::LINE_MESH, Mesh::POINT_MESH.
void Polycode::Mesh::setVertexBuffer ( VertexBuffer *  buffer)

Sets the vertex buffer for the mesh.

Parameters:
bufferNew vertex buffer for mesh.
void Polycode::Mesh::useVertexNormals ( bool  val)

Toggles the mesh between using vertex or polygon normals.

Parameters:
valIf true, the mesh will use vertex normals, otherwise it will use the polygon normals.

Member Data Documentation

Render array dirty map.

If any of these are flagged as dirty, the renderer will rebuild them from the mesh data. See RenderDataArray for types of render arrays.

See also:
RenderDataArray

Render arrays.

See RenderDataArray for types of render arrays.

See also:
RenderDataArray