vtlib library
|
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 ¢er, 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 |
A Mesh is a set of graphical primitives (such as lines, triangles, or fans).
vtMesh::vtMesh | ( | PrimType | ePrimType, |
int | VertType, | ||
int | NumVertices | ||
) |
Construct a Mesh. A Mesh is a container for a set of vertices and primitives.
ePrimType | The type of primitive this mesh will contain. Allowed values are:
|
VertType | Flags which indicate what type of information is stored with each vertex. This can be any combination of the following bit flags:
|
NumVertices | The 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. |
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.
idx | An array of vertex indices for the fan. |
iNVerts | the number of vertices in the fan. |
void vtMesh::AddLine | ( | int | p0, |
int | p1 | ||
) |
Add a single line primitive to a mesh.
p0,p1 | The indices of the two vertices of the line. |
Add a single line primitive to a mesh.
pos1,pos2 | The positions of the two vertices of the line. |
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.
iNVerts | The number of vertices in the strip. |
pIndices | An 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.
iNVerts | The number of vertices in the strip. |
iStartIndex | The 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.
int vtMesh::AddVertex | ( | const FPoint3 & | p | ) |
Adds a vertex to the mesh.
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.
Adds a vertex to the mesh, with a vertex normal.
Adds a vertex to the mesh, with a vertex normal and UV coordinates.
int vtMesh::AddVertexUV | ( | float | x, |
float | y, | ||
float | z, | ||
float | u, | ||
float | v | ||
) |
Adds a vertex to the mesh, with UV coordinates.
int vtMesh::AddVertexUV | ( | const FPoint3 & | p, |
float | u, | ||
float | v | ||
) |
Adds a vertex to the mesh, with UV coordinates.
Adds a vertex to the mesh, with UV coordinates.
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().
bAllow | True 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).
tip | The top point of the cone. |
radial_angle | This 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,theta2 | Start and end values for the theta value, which ranges from 0 to 2*PI around the central axis of the cone. |
r1,r2 | Start and end values for the cone's radius. These range from 0 (at the tip of the cone) and increase downward. |
res | Resolution, 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.
height | The height of the cylinder. |
radius | The radius of the cylinder. |
res | The resolution (number of side of the cylinder). |
bTop | True to create the top of the cylinder. |
bBottom | True 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. |
bCentered | True to create a cylinder centered around its origin, false for a cylinder with its base at the origin that extends outward. |
direction | An 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.
center | Position of the center, pass FPoint3(0,0,0) to center on the origin. |
size | The width, height and depth of the ellipsoid. |
res | The resolution (number of quads used in the tesselation) from top to bottom (north pole to south pole). |
hemi | Create only the top of the ellipsoid (e.g. a hemisphere). |
bNormalsIn | Use 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.
iQuads1 | The number of quads along the first axis. |
iQuads2 | The number of quads along the second axis. |
Axis1 | The first axis (X=0, Y=1, Z=2) |
Axis2 | The second axis (X=0, Y=1, Z=2) |
Axis3 | The third axis (X=0, Y=1, Z=2) |
min1 | The lower-left-hand corner of the rectangle's position |
max1 | The size of the rectangle. |
fLevel | The value of the rectangle on the third axis. |
fTiling | UV 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.
xsize | Number of vertices in the first dimension. |
ysize | Number of vertices in the second dimension. |
bReverseNormals | Reverse 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.
i | Index of the vertex. |
color | The 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.
i | Index of the vertex. |
norm | The normal vector. |
void vtMesh::SetVtxPos | ( | uint | i, |
const FPoint3 & | p | ||
) |
Set the position of a vertex.
i | Index of the vertex. |
p | The 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".
i | Index of the vertex. |
uv | The texture coordinate. |
void vtMesh::TransformVertices | ( | const FMatrix4 & | mat | ) |
Transform all the vertices of the mesh by the indicated matrix.