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

Public Member Functions

 vtGeomFactory (vtGeode *pGeode, vtMesh::PrimType ePrimType, int iVertType, int iMaxVertsPerMesh, int iMatIndex, int iExpectedVerts=-1)
 
 vtGeomFactory (vtMesh *pMesh)
 
void PrimStart ()
 
void AddVertex (const FPoint3 &p)
 
void PrimEnd ()
 
float AddSurfaceLineToMesh (vtHeightField3d *pHF, const DLine2 &line, float fSpacing, float fOffset, bool bInterp=true, bool bCurve=false, bool bTrue=false)
 

Detailed Description

The vtGeomFactory class makes it easy to create geometry with a lot of vertices. You simply provide vertices, and it will create as many geometries as necessary to contain them all.

Example:
This example produces a line strip with 10000 vertices. The factory is told to limit the number of vertices in a single primitive to 3000, so it will automatically produce four geometries with 3000, 3000, 3000, and 1000 vertices each. The geometries are automatically added to the indicated geode.
{
vtGeode *pLineGeom = new vtGeode;
vtGeomFactory mf(pLineGeom, osg::PrimitiveSet::LINE_STRIP, 0, 3000, 1);
mf.PrimStart();
for (int i = 0; i < 10000; i++)
mf.AddVertex(FPoint3(i,i,i));
mf.PrimEnd();
}

Constructor & Destructor Documentation

vtGeomFactory::vtGeomFactory ( vtGeode pGeode,
vtMesh::PrimType  ePrimType,
int  iVertType,
int  iMaxVertsPerMesh,
int  iMatIndex,
int  iExpectedVerts = -1 
)

Constructor.

Parameters
pGeodeThe geometry node which will receive the mesh object(s) that this factory will produce.
ePrimTypeThe type of mesh to produce.
iVertTypeThe vertex attributes for the meshes to produce.
iMaxVertsPerMeshThe largest number of vertices to allow in a single mesh. When this number is exceeded, the current mesh will be finished and another mesh begun.
iMatIndexThe material index of the mesh when it is added to the geometry node.
iExpectedVertsIf you know how many vertices will be mesh ahead of time, you can save a little time and memory by passing the number.
vtGeomFactory::vtGeomFactory ( vtMesh pMesh)

Alternate, simpler constructor.

Parameters
pMeshThe mesh which will receive all the vertices that this factory produces.

Member Function Documentation

float vtGeomFactory::AddSurfaceLineToMesh ( vtHeightField3d pHF,
const DLine2 line,
float  fSpacing,
float  fOffset,
bool  bInterp = true,
bool  bCurve = false,
bool  bTrue = false 
)

Create geometry for a 2D line by draping the points on a heightfield.

Parameters
pHFThe heightfield to drape on.
lineThe 2D line to drape, in Earth coordinates.
fSpacingThe approximate spacing of the surface tessellation, used to decide how finely to tessellate the line.
fOffsetAn offset to elevate each point in the resulting geometry, useful for keeping it visibly above the ground.
bInterpTrue to interpolate between the vertices of the input line. This is generally desirable when the ground is much more finely spaced than the input line.
bCurveTrue to interpret the vertices of the input line as control points of a curve. The created geometry will consist of a draped line which passes through the control points.
bTrueTrue to use the true elevation of the terrain, ignoring whatever scale factor is being used to exaggerate elevation for display.
Returns
The approximate length of the resulting 3D line mesh.
Example:
DLine2 line = ...;
vtTerrain *pTerr = ...;
vtGeode *pLineGeom = new vtGeode;
pTerr->AddNode(pLineGeom);
vtGeomFactory mf(pLineGeom, osg::PrimitiveSet::LINE_STRIP, 0, 30000, 1);
float length = mf.AddSurfaceLineToMesh(pTerr->GetHeightfield(), dline, 1, 10, true);
void vtGeomFactory::AddVertex ( const FPoint3 p)

Tell the factory to add a vertex to the current primitive.

void vtGeomFactory::PrimEnd ( )

Tell the factory to end a primitive.

void vtGeomFactory::PrimStart ( )

Tell the factory to start a primitive.