vtlib library
Public Member Functions | Friends | List of all members
vtMesh Class Reference

Inherits Geometry.

Public Member Functions

 vtMesh (PrimType ePrimType, int VertType, int NumVertices)
 
int AddVertex (float x, float y, float z)
 
int AddVertexN (float x, float y, float z, float nx, float ny, float nz)
 
int AddVertexUV (float x, float y, float z, float u, float v)
 
int AddVertex (const FPoint3 &p)
 
int AddVertexN (const FPoint3 &p, const FPoint3 &n)
 
int AddVertexUV (const FPoint3 &p, float u, float v)
 
int AddVertexUV (const FPoint3 &p, const FPoint2 &uv)
 
int AddVertexNUV (const FPoint3 &p, const FPoint3 &n, const FPoint2 &uv)
 
void AddTri (int p0, int p1, int p2)
 
void AddFan (int p0, int p1, int p2=-1, int p3=-1, int p4=-1, int p5=-1)
 
void AddFan (int *idx, int iNVerts)
 
void AddStrip (int iNVerts, unsigned short *pIndices)
 
void AddStrip2 (int iNVerts, int iStartIndex)
 
void AddLine (int p0, int p1)
 
int AddLine (const FPoint3 &pos1, const FPoint3 &pos2)
 
void AddQuad (int p0, int p1, int p2, int p3)
 
void CreateBlock (const FPoint3 &size)
 
void CreateOptimizedBlock (const FPoint3 &size)
 
void CreatePrism (const FPoint3 &base, const FPoint3 &vector_up, const FPoint2 &size1, const FPoint2 &size2)
 
void CreateRectangularMesh (int xsize, int ysize, bool bReverseNormals=false)
 
void CreateEllipsoid (const FPoint3 &center, const FPoint3 &size, int res, bool hemi=false, bool bNormalsIn=false)
 
void CreateCylinder (float height, float radius, int res, bool bTop=true, bool bBottom=true, bool bCentered=true, int direction=1)
 
void AddRectangleXZ (float xsize, float zsize)
 
void AddRectangleXY (float x, float y, float xsize, float ysize, float z=0.0f, bool bCentered=false)
 
void CreateConicalSurface (const FPoint3 &tip, double radial_angle, double theta1, double theta2, double r1, double r2, int res=40)
 
void CreateRectangle (int iQuads1, int iQuads2, int Axis1, int Axis2, int Axis3, const FPoint2 &min1, const FPoint2 &max1, float fLevel, float fTiling)
 
void TransformVertices (const FMatrix4 &mat)
 
void SetVtxPos (uint, const FPoint3 &)
 
FPoint3 GetVtxPos (uint i) const
 
void SetVtxNormal (uint, const FPoint3 &)
 
FPoint3 GetVtxNormal (uint i) const
 
void SetVtxColor (uint, const RGBAf &)
 
RGBAf GetVtxColor (uint i) const
 
void SetVtxTexCoord (uint, const FPoint2 &)
 
FPoint2 GetVtxTexCoord (uint i) const
 
void SetLineWidth (float fWidth)
 
void AllowOptimize (bool bAllow)
 
void ReOptimize ()
 
void SetNormalsFromPrimitives ()
 

Friends

class vtGeode
 

Detailed Description

A Mesh is a set of graphical primitives (such as lines, triangles, or fans).

The vtMesh class allows you to define and access a Mesh, including many functions useful for creating and dynamically changing Meshes. To add the vtMesh to the visible scene graph, add it to a vtGeode node.

Constructor & Destructor Documentation

vtMesh::vtMesh ( PrimType  ePrimType,
int  VertType,
int  NumVertices 
)

Construct a Mesh. A Mesh is a container for a set of vertices and primitives.

Parameters
ePrimTypeThe type of primitive this mesh will contain. Allowed values are:
  • osg::PrimitiveSet::POINTS
  • osg::PrimitiveSet::LINES
  • osg::PrimitiveSet::LINE_STRIP
  • osg::PrimitiveSet::TRIANGLES
  • osg::PrimitiveSet::TRIANGLE_STRIP
  • osg::PrimitiveSet::TRIANGLE_FAN
  • osg::PrimitiveSet::QUADS
  • osg::PrimitiveSet::POLYGON
VertTypeFlags which indicate what type of information is stored with each vertex. This can be any combination of the following bit flags:
  • VT_Normals - a normal per vertex.
  • VT_Colors - a color per vertex.
  • VT_TexCoords - a texture coordinate (UV) per vertex.
NumVerticesThe expected number of vertices that the mesh will contain. If more than this number of vertices are added, the mesh will automatically grow to contain them. However it is more efficient if you know the number at creation time and pass it in this parameter.

Member Function Documentation

void vtMesh::AddFan ( int  p0,
int  p1,
int  p2 = -1,
int  p3 = -1,
int  p4 = -1,
int  p5 = -1 
)

Add a triangle fan with up to 6 points (center + 5 points). The first 3 arguments are required, the rest are optional. A fan will be created with as many point indices as you pass.

void vtMesh::AddFan ( int *  idx,
int  iNVerts 
)

Add a triangle fan with any number of points.

Parameters
idxAn array of vertex indices for the fan.
iNVertsthe number of vertices in the fan.
void vtMesh::AddLine ( int  p0,
int  p1 
)

Add a single line primitive to a mesh.

Parameters
p0,p1The indices of the two vertices of the line.
int vtMesh::AddLine ( const FPoint3 pos1,
const FPoint3 pos2 
)

Add a single line primitive to a mesh.

Parameters
pos1,pos2The positions of the two vertices of the line.
Returns
The index of the first vertex added.
void vtMesh::AddQuad ( int  p0,
int  p1,
int  p2,
int  p3 
)

Add a triangle. p0, p1, p2 are the indices of the vertices of the triangle.

void vtMesh::AddRectangleXY ( float  x,
float  y,
float  xsize,
float  ysize,
float  z = 0.0f,
bool  bCentered = false 
)

Adds the vertices and a fan primitive for a single flat rectangle.

void vtMesh::AddRectangleXZ ( float  xsize,
float  zsize 
)

Adds the vertices and a fan primitive for a single flat rectangle.

void vtMesh::AddStrip ( int  iNVerts,
unsigned short *  pIndices 
)

Adds an indexed strip to the mesh.

Parameters
iNVertsThe number of vertices in the strip.
pIndicesAn array of the indices of the vertices in the strip.
void vtMesh::AddStrip2 ( int  iNVerts,
int  iStartIndex 
)

Adds an indexed strip to the mesh, with the assumption that the indices are in linear order.

Parameters
iNVertsThe number of vertices in the strip.
iStartIndexThe index that starts the linear sequence.
void vtMesh::AddTri ( int  p0,
int  p1,
int  p2 
)

Add a triangle. p0, p1, p2 are the indices of the vertices of the triangle.

int vtMesh::AddVertex ( float  x,
float  y,
float  z 
)

Adds a vertex to the mesh.

Returns
The index of the vertex that was added.
int vtMesh::AddVertex ( const FPoint3 p)

Adds a vertex to the mesh.

Returns
The index of the vertex that was added.
int vtMesh::AddVertexN ( float  x,
float  y,
float  z,
float  nx,
float  ny,
float  nz 
)

Adds a vertex to the mesh, with a vertex normal.

Returns
The index of the vertex that was added.
int vtMesh::AddVertexN ( const FPoint3 pos,
const FPoint3 norm 
)

Adds a vertex to the mesh, with a vertex normal.

Returns
The index of the vertex that was added.
int vtMesh::AddVertexNUV ( const FPoint3 pos,
const FPoint3 norm,
const FPoint2 uv 
)

Adds a vertex to the mesh, with a vertex normal and UV coordinates.

Returns
The index of the vertex that was added.
int vtMesh::AddVertexUV ( float  x,
float  y,
float  z,
float  u,
float  v 
)

Adds a vertex to the mesh, with UV coordinates.

Returns
The index of the vertex that was added.
int vtMesh::AddVertexUV ( const FPoint3 p,
float  u,
float  v 
)

Adds a vertex to the mesh, with UV coordinates.

Returns
The index of the vertex that was added.
int vtMesh::AddVertexUV ( const FPoint3 p,
const FPoint2 uv 
)

Adds a vertex to the mesh, with UV coordinates.

Returns
The index of the vertex that was added.
void vtMesh::AllowOptimize ( bool  bAllow)

Set whether to allow rendering optimization of this mesh. With OpenGL, this optimization is called a "display list", which increases the speed of rendering by creating a special representation of the mesh the first time it is drawn. The tradeoff is that subsequent changes to the mesh are not applied unless you call ReOptimize().

Parameters
bAllowTrue to allow optimization. The default is true.
void vtMesh::CreateBlock ( const FPoint3 size)

Add a block (rectangular 3d box) to this mesh. The width, height and depth are specified with the 'size' parameter.

void vtMesh::CreateConicalSurface ( const FPoint3 tip,
double  radial_angle,
double  theta1,
double  theta2,
double  r1,
double  r2,
int  res = 40 
)

Adds an conical surface to this mesh. This is a subset of a full cone, bounded by start/end factors along the two degrees of freedom of the surface of the cone. The default orientation of the cone is with the tip pointing up (radius increasing downward).

Parameters
tipThe top point of the cone.
radial_angleThis is the angle between the cone's edge and its center axis, in radians. Expected range is 0 to PI/2. Small values indicate a sharp, pointed cone, large values indicate a blunt cone. The slope of the cone's edge is tan(radial_angle).
theta1,theta2Start and end values for the theta value, which ranges from 0 to 2*PI around the central axis of the cone.
r1,r2Start and end values for the cone's radius. These range from 0 (at the tip of the cone) and increase downward.
resResolution, number of polygons along each side of the surface mesh.
void vtMesh::CreateCylinder ( float  height,
float  radius,
int  res,
bool  bTop = true,
bool  bBottom = true,
bool  bCentered = true,
int  direction = 1 
)

Adds an cylinder to this mesh.

Parameters
heightThe height of the cylinder.
radiusThe radius of the cylinder.
resThe resolution (number of side of the cylinder).
bTopTrue to create the top of the cylinder.
bBottomTrue to create the bottom of the cylinder. You could set this to false, for example, if the cylinder is going to sit on a flat surface where you will never see its bottom.
bCenteredTrue to create a cylinder centered around its origin, false for a cylinder with its base at the origin that extends outward.
directionAn orientation, 0-2 corresponds to X, Y, Z. Default is 1 (Y).
void vtMesh::CreateEllipsoid ( const FPoint3 center,
const FPoint3 size,
int  res,
bool  hemi = false,
bool  bNormalsIn = false 
)

Adds geometry for an ellipsoid to this mesh.

The geometry is created with efficient triangle strips. If the mesh has vertex normals, outward-pointing normals are created for lighting. If the mesh has vertex coordinates, then UVs are set as follows: U ranges from 0 to 1 around the circumference, and V ranges from 0 to 1 from the top to the bottom. For a hemisphere, V ranges from 0 at the top to 1 at the base.

Parameters
centerPosition of the center, pass FPoint3(0,0,0) to center on the origin.
sizeThe width, height and depth of the ellipsoid.
resThe resolution (number of quads used in the tesselation) from top to bottom (north pole to south pole).
hemiCreate only the top of the ellipsoid (e.g. a hemisphere).
bNormalsInUse a vertex order in the mesh so that the normals point in, instead of out. This is useful for, example, a backface-culled sphere that you want to see from the inside, instead of the outside.
void vtMesh::CreateOptimizedBlock ( const FPoint3 size)

Adds a 3D block to a vtMesh as a series of 5 triangle fan primitives. The bottom face is omitted, the base is placed at y=0, and texture coordinates are provided such that texture bitmaps appear right-side-up on the side faces.

void vtMesh::CreatePrism ( const FPoint3 base,
const FPoint3 vector_up,
const FPoint2 size1,
const FPoint2 size2 
)

Adds a 3D block (extruded rectangle) to a vtMesh as a series of 5 triangle fan primitives. The bottom face is omitted, the base is placed at /base/, the extrusion is along /vector_up/. Texture coordinates are provided such that texture bitmaps appear right-side-up on the side faces.

Used by vtFence3d to make fenceposts.

void vtMesh::CreateRectangle ( int  iQuads1,
int  iQuads2,
int  Axis1,
int  Axis2,
int  Axis3,
const FPoint2 min1,
const FPoint2 max1,
float  fLevel,
float  fTiling 
)

Adds an rectangular surface to this mesh. The rectangle will lie in the first two axes given, facing toward the third. Axes can be specified by number. For example, to produce a rectangle in the XZ plane facing along the Y axis, you would pass 0, 2, 1.

Parameters
iQuads1The number of quads along the first axis.
iQuads2The number of quads along the second axis.
Axis1The first axis (X=0, Y=1, Z=2)
Axis2The second axis (X=0, Y=1, Z=2)
Axis3The third axis (X=0, Y=1, Z=2)
min1The lower-left-hand corner of the rectangle's position
max1The size of the rectangle.
fLevelThe value of the rectangle on the third axis.
fTilingUV tiling. Set to 1 for UV coordinate of O..1.
void vtMesh::CreateRectangularMesh ( int  xsize,
int  ysize,
bool  bReverseNormals = false 
)

Adds triangle/quad strips to this mesh, suitable for a (topologically) rectangular grid.

Parameters
xsizeNumber of vertices in the first dimension.
ysizeNumber of vertices in the second dimension.
bReverseNormalsReverse the vertex order so the normals point the other way.
RGBAf vtMesh::GetVtxColor ( uint  i) const

Get the color of a vertex.

FPoint3 vtMesh::GetVtxNormal ( uint  i) const

Get the normal of a vertex.

FPoint3 vtMesh::GetVtxPos ( uint  i) const

Get the position of a vertex.

FPoint2 vtMesh::GetVtxTexCoord ( uint  i) const

Get the texture coordinates of a vertex.

void vtMesh::ReOptimize ( )

For a mesh with rendering optimization enabled, forces an update of the optimized representation.

void vtMesh::SetLineWidth ( float  fWidth)

Set the line width, in pixels, for this mesh's geometry.

You should call this method after the mesh has been added to some geometry with vtGeode::AddMesh() (this requirement was found with the OSG flavor of vtlib.)

void vtMesh::SetNormalsFromPrimitives ( )

Set the normals of the vertices by combining the normals of the surrounding faces. This requires going through all the primitives to average their contribution to each vertex.

void vtMesh::SetVtxColor ( uint  i,
const RGBAf color 
)

Set the color of a vertex. This color multiplies with the color of the material used with the mesh, so if you want the vertex color to be dominant, use a white material.

Parameters
iIndex of the vertex.
colorThe color.
void vtMesh::SetVtxNormal ( uint  i,
const FPoint3 norm 
)

Set the normal of a vertex. This is used for lighting, if the mesh is used with a material with lighting enabled. Generally you will want to use a vector of unit length.

Parameters
iIndex of the vertex.
normThe normal vector.
void vtMesh::SetVtxPos ( uint  i,
const FPoint3 p 
)

Set the position of a vertex.

Parameters
iIndex of the vertex.
pThe position.
void vtMesh::SetVtxTexCoord ( uint  i,
const FPoint2 uv 
)

Set the texture coordinates of a vertex. Generally these values are in the range of 0 to 1, although you can use higher values if you want repeating tiling. The components of the texture coordinates are usually called "u" and "v".

Parameters
iIndex of the vertex.
uvThe texture coordinate.
void vtMesh::TransformVertices ( const FMatrix4 mat)

Transform all the vertices of the mesh by the indicated matrix.