![]() |
XII Release 0.1.0
|
Provides functions to generate standard geometric shapes, such as boxes, spheres, cylinders, etc. More...
#include <Geometry.h>
Classes | |
struct | GeoOptions |
Options shared among all geometry creation functions. More... | |
struct | Line |
A line only references two vertices. More... | |
struct | Polygon |
Each polygon has a face normal and a set of indices, which vertices it references. More... | |
struct | Vertex |
The data that is stored per vertex. More... | |
Public Member Functions | |
xiiDeque< Vertex > & | GetVertices () |
Returns the entire vertex data. | |
xiiDeque< Polygon > & | GetPolygons () |
Returns the entire polygon data. | |
xiiDeque< Line > & | GetLines () |
Returns the entire line data. | |
const xiiDeque< Vertex > & | GetVertices () const |
Returns the entire vertex data. | |
const xiiDeque< Polygon > & | GetPolygons () const |
Returns the entire polygon data. | |
const xiiDeque< Line > & | GetLines () const |
Returns the entire line data. | |
void | Clear () |
Clears all data. | |
xiiUInt32 | AddVertex (const xiiVec3 &vPos, const xiiVec3 &vNormal, const xiiVec2 &vTexCoord=xiiVec2(0.0f), const xiiColor &color=xiiColor::White, const xiiVec4U16 &vBoneIndices=xiiVec4U16::MakeZero(), const xiiColorLinearUB &boneWeights=xiiColorLinearUB(255, 0, 0, 0)) |
Adds a vertex, returns the index to the added vertex. | |
xiiUInt32 | AddVertex (const xiiMat4 &mTransform, const xiiVec3 &vPos, const xiiVec3 &vNormal, const xiiVec2 &vTexCoord=xiiVec2(0.0f), const xiiColor &color=xiiColor::White, const xiiVec4U16 &vBoneIndices=xiiVec4U16::MakeZero(), const xiiColorLinearUB &boneWeights=xiiColorLinearUB(255, 0, 0, 0)) |
Overload that transforms position and normal with the given matrix. | |
xiiUInt32 | AddVertex (const GeoOptions &options, const xiiVec3 &vPos, const xiiVec3 &vNormal, const xiiVec2 &vTexCoord=xiiVec2(0.0f)) |
Overload that uses the options for color and to transform position and normal and uses a single bone. | |
xiiUInt32 | AddVertex (const xiiMat4 &mTransform, const GeoOptions &options, const xiiVec3 &vPos, const xiiVec3 &vNormal, const xiiVec2 &vTexCoord=xiiVec2(0.0f)) |
Overload that uses the options for color and a single bone and transforms position and normal by a separately provided matrix. | |
void | AddPolygon (const xiiArrayPtr< xiiUInt32 > &vertices, bool bFlipWinding) |
Adds a polygon that consists of all the referenced vertices. No face normal is computed at this point. | |
void | AddLine (xiiUInt32 uiStartVertex, xiiUInt32 uiEndVertex) |
Adds a line with the given start and end vertex index. | |
void | TriangulatePolygons (xiiUInt32 uiMaxVerticesInPolygon=3) |
Triangulates all polygons that have more than uiMaxVerticesInPolygon vertices. | |
void | ComputeFaceNormals () |
Computes normals for all polygons from the current vertex positions. Call this when you do not intend to make further modifications. | |
void | ComputeSmoothVertexNormals () |
Computes smooth (averaged) normals for each vertex. Requires that face normals are computed. | |
void | ComputeTangents () |
Computes tangents. This function can increase or reduce vertex count. | |
void | ValidateTangents (float fEpsilon=0.01f) |
Checks whether present tangents are meaningful and resets them, if necessary. | |
xiiUInt32 | CalculateTriangleCount () const |
Returns the number of triangles that the polygons are made up of. | |
void | SetAllVertexBoneIndices (const xiiVec4U16 &vBoneIndices, xiiUInt32 uiFirstVertex=0) |
Changes the bone indices for all vertices (starting at vertex uiFirstVertex). | |
void | SetAllVertexColor (const xiiColor &color, xiiUInt32 uiFirstVertex=0) |
Changes the color for all vertices (starting at vertex uiFirstVertex). | |
void | SetAllVertexTexCoord (const xiiVec2 &vTexCoord, xiiUInt32 uiFirstVertex=0) |
Changes the texture coordinates for all vertices (starting at vertex uiFirstVertex). | |
void | Transform (const xiiMat4 &mTransform, bool bTransformPolyNormals) |
Transforms all vertices by the given transform. | |
void | Merge (const xiiGeometry &other) |
Merges the given mesh into this one. Use this to composite multiple shapes into one. | |
void | AddRect (const xiiVec2 &vSize, xiiUInt32 uiTesselationX=1, xiiUInt32 uiTesselationY=1, const GeoOptions &options=GeoOptions()) |
Adds a rectangle shape, with the front pointing into the main axis direction. | |
void | AddBox (const xiiVec3 &vFullExtents, bool bExtraVerticesForTexturing, const GeoOptions &options=GeoOptions()) |
Adds a box. If bExtraVerticesForTexturing is false, 8 shared vertices are added. If bExtraVerticesForTexturing is true, 24 separate vertices with UV coordinates are added. | |
void | AddLineBox (const xiiVec3 &vSize, const GeoOptions &options=GeoOptions()) |
Adds box out of lines (8 vertices). | |
void | AddLineBoxCorners (const xiiVec3 &vSize, float fCornerFraction, const GeoOptions &options=GeoOptions()) |
Adds the 8 corners of a box as lines. | |
void | AddPyramid (float fBaseSize, float fHeight, bool bCap, const GeoOptions &options=GeoOptions()) |
Adds a pyramid. This is different to a low-res cone in that the corners are placed differently (like on a box). | |
void | AddGeodesicSphere (float fRadius, xiiUInt8 uiSubDivisions, const GeoOptions &options=GeoOptions()) |
Adds a geodesic sphere at the origin. | |
void | AddCylinder (float fRadiusTop, float fRadiusBottom, float fPositiveLength, float fNegativeLength, bool bCapTop, bool bCapBottom, xiiUInt16 uiSegments, const GeoOptions &options=GeoOptions(), xiiAngle fraction=xiiAngle::MakeFromDegree(360.0f)) |
Adds a cylinder revolving around the main axis (see GeoOptions). | |
void | AddCylinderOnePiece (float fRadiusTop, float fRadiusBottom, float fPositiveLength, float fNegativeLength, xiiUInt16 uiSegments, const GeoOptions &options=GeoOptions()) |
Same as AddCylinder(), but always adds caps and does not generate separate vertices for the caps. | |
void | AddCone (float fRadius, float fHeight, bool bCap, xiiUInt16 uiSegments, const GeoOptions &options=GeoOptions()) |
Adds a cone with the origin at the center of the bottom and the tip pointing into the direction of the main axis (see GeoOptions). | |
void | AddStackedSphere (float fRadius, xiiUInt16 uiSegments, xiiUInt16 uiStacks, const GeoOptions &options=GeoOptions()) |
Adds a sphere consisting of a number of stacks along the main axis (see GeoOptions) with a fixed tessellation. | |
void | AddHalfSphere (float fRadius, xiiUInt16 uiSegments, xiiUInt16 uiStacks, bool bCap, const GeoOptions &options=GeoOptions()) |
Adds half a stacked sphere with the half being in the direction of the main axis (see GeoOptions). | |
void | AddCapsule (float fRadius, float fHeight, xiiUInt16 uiSegments, xiiUInt16 uiStacks, const GeoOptions &options=GeoOptions()) |
Adds a capsule, revolving around the main axis (see GeoOptions). | |
void | AddTorus (float fInnerRadius, float fOuterRadius, xiiUInt16 uiSegments, xiiUInt16 uiSegmentDetail, bool bExtraVerticesForTexturing, const GeoOptions &options=GeoOptions()) |
Adds a full torus with the ring revolving around the main axis (see GeoOptions). | |
void | AddTexturedRamp (const xiiVec3 &vSize, const GeoOptions &options=GeoOptions()) |
Adds a ramp that has UV coordinates set. | |
void | AddStairs (const xiiVec3 &vSize, xiiUInt32 uiNumSteps, xiiAngle curvature, bool bSmoothSloped, const GeoOptions &options=GeoOptions()) |
Generates a straight stair mesh along the X axis. The number of steps determines the step height and depth. | |
void | AddArch (const xiiVec3 &vSize, xiiUInt32 uiNumSegments, float fThickness, xiiAngle angle, bool bMakeSteps, bool bSmoothBottom, bool bSmoothTop, bool bCapTopAndBottom, const GeoOptions &options=GeoOptions()) |
Creates and arch, pipe or spiral stairs within the defined volume (size) curving around the main axis. | |
Provides functions to generate standard geometric shapes, such as boxes, spheres, cylinders, etc.
This class provides simple functions to create frequently used basic shapes. It allows to transform the shapes, merge them into a single mesh, compute normals, etc. It is meant for debug and editor geometry (gizmos, etc.). Vertices can have position, normal, color and 'shape index'.
void xiiGeometry::AddArch | ( | const xiiVec3 & | vSize, |
xiiUInt32 | uiNumSegments, | ||
float | fThickness, | ||
xiiAngle | angle, | ||
bool | bMakeSteps, | ||
bool | bSmoothBottom, | ||
bool | bSmoothTop, | ||
bool | bCapTopAndBottom, | ||
const GeoOptions & | options = GeoOptions() ) |
Creates and arch, pipe or spiral stairs within the defined volume (size) curving around the main axis.
uiNumSegments | The number of segments of the arch or pipe, or the number of steps in spiral stairs. |
fThickness | The wall thickness of the pipe, or the width of steps. |
angle | How far to curl around the main axis. Values between -360 degree and +360 degree are possible. 0 degree is treated like 360 degree. |
bMakeSteps | If true, segments are only thin and are offset in position from the previous one. |
bSmoothBottom,bSmoothTop | If true and bMakeSteps as well, the segments will have a step, but connect smoothly, like in a spiral. |
bCapTopAndBottom | If false, the top and bottom geometry is skipped. Can be used to reduce detail in pipe geometry that connects with something else anyway. |
void xiiGeometry::AddCapsule | ( | float | fRadius, |
float | fHeight, | ||
xiiUInt16 | uiSegments, | ||
xiiUInt16 | uiStacks, | ||
const GeoOptions & | options = GeoOptions() ) |
Adds a capsule, revolving around the main axis (see GeoOptions).
The origin is at the center of the capsule. Radius and height are added to get the total height of the capsule. uiSegments is the detail around the up axis, must be at least 3. uiStacks is the detail of the rounded top and bottom, must be at least 1.
void xiiGeometry::AddCone | ( | float | fRadius, |
float | fHeight, | ||
bool | bCap, | ||
xiiUInt16 | uiSegments, | ||
const GeoOptions & | options = GeoOptions() ) |
Adds a cone with the origin at the center of the bottom and the tip pointing into the direction of the main axis (see GeoOptions).
uiSegments is the detail around the up axis, must be at least 3.
void xiiGeometry::AddCylinder | ( | float | fRadiusTop, |
float | fRadiusBottom, | ||
float | fPositiveLength, | ||
float | fNegativeLength, | ||
bool | bCapTop, | ||
bool | bCapBottom, | ||
xiiUInt16 | uiSegments, | ||
const GeoOptions & | options = GeoOptions(), | ||
xiiAngle | fraction = xiiAngle::MakeFromDegree(360.0f) ) |
Adds a cylinder revolving around the main axis (see GeoOptions).
If fPositiveLength == fNegativeLength, the origin is at the center. If fNegativeLength is zero, the origin is at the bottom and so on.
uiSegments is the detail around the up axis, must be at least 3. The top or bottom caps can be removed using bCapTop and bCapBottom. When fraction is set to any value below 360 degree, a pie / PacMan-shaped cylinder is created.
void xiiGeometry::AddCylinderOnePiece | ( | float | fRadiusTop, |
float | fRadiusBottom, | ||
float | fPositiveLength, | ||
float | fNegativeLength, | ||
xiiUInt16 | uiSegments, | ||
const GeoOptions & | options = GeoOptions() ) |
Same as AddCylinder(), but always adds caps and does not generate separate vertices for the caps.
This is a more compact representation, but does not allow as good texturing.
void xiiGeometry::AddGeodesicSphere | ( | float | fRadius, |
xiiUInt8 | uiSubDivisions, | ||
const GeoOptions & | options = GeoOptions() ) |
Adds a geodesic sphere at the origin.
When uiSubDivisions is zero, the sphere will have 20 triangles.
For each subdivision step the number of triangles quadruples.
0 = 20 triangles, 12 vertices
1 = 80 triangles, 42 vertices
2 = 320 triangles, 162 vertices
3 = 1280 triangles, 642 vertices
4 = 5120 triangles, 2562 vertices
...
void xiiGeometry::AddHalfSphere | ( | float | fRadius, |
xiiUInt16 | uiSegments, | ||
xiiUInt16 | uiStacks, | ||
bool | bCap, | ||
const GeoOptions & | options = GeoOptions() ) |
Adds half a stacked sphere with the half being in the direction of the main axis (see GeoOptions).
The origin is at the 'full sphere center', ie. at the center of the cap. uiSegments is the detail around the up axis, must be at least 3. uiStacks is the detail of the rounded top and bottom, must be at least 1.
void xiiGeometry::AddLineBoxCorners | ( | const xiiVec3 & | vSize, |
float | fCornerFraction, | ||
const GeoOptions & | options = GeoOptions() ) |
Adds the 8 corners of a box as lines.
fCornerFraction must be between 1.0 and 0.0, with 1 making it a completely closed box and 0 no lines at all.
void xiiGeometry::AddPyramid | ( | float | fBaseSize, |
float | fHeight, | ||
bool | bCap, | ||
const GeoOptions & | options = GeoOptions() ) |
Adds a pyramid. This is different to a low-res cone in that the corners are placed differently (like on a box).
The origin is at the center of the base quad and the tip is in the direction of the main axis (see GeoOptions).
void xiiGeometry::AddRect | ( | const xiiVec2 & | vSize, |
xiiUInt32 | uiTesselationX = 1, | ||
xiiUInt32 | uiTesselationY = 1, | ||
const GeoOptions & | options = GeoOptions() ) |
Adds a rectangle shape, with the front pointing into the main axis direction.
It is centered at the origin, extending half size.x and half size.y into direction +X, -X, +Y and -Y. Optionally tessellates the rectangle for more detail.
void xiiGeometry::AddStackedSphere | ( | float | fRadius, |
xiiUInt16 | uiSegments, | ||
xiiUInt16 | uiStacks, | ||
const GeoOptions & | options = GeoOptions() ) |
Adds a sphere consisting of a number of stacks along the main axis (see GeoOptions) with a fixed tessellation.
uiSegments is the detail around the up axis, must be at least 3. uiStacks is the detail along the up axis, must be at least 2.
void xiiGeometry::AddTorus | ( | float | fInnerRadius, |
float | fOuterRadius, | ||
xiiUInt16 | uiSegments, | ||
xiiUInt16 | uiSegmentDetail, | ||
bool | bExtraVerticesForTexturing, | ||
const GeoOptions & | options = GeoOptions() ) |
Adds a full torus with the ring revolving around the main axis (see GeoOptions).
The origin is at the center of the torus.
fInnerRadius | is the radius from the center to where the torus ring starts. |
fOuterRadius | is the radius to where the torus ring stops. |
uiSegments | is the detail around the main axis. |
uiSegmentDetail | is the number of segments around the torus ring (ie. the cylinder detail) |
bExtraVerticesForTexturing | specifies whether the torus should be one closed piece or have additional vertices at the seams, such that texturing works better. |
void xiiGeometry::ComputeSmoothVertexNormals | ( | ) |
Computes smooth (averaged) normals for each vertex. Requires that face normals are computed.
This only yields smooth normals for vertices that are shared among multiple polygons, otherwise a vertex will have the same normal as the one face that it is used in.
void xiiGeometry::ComputeTangents | ( | ) |
Computes tangents. This function can increase or reduce vertex count.
The tangent generation is done by Morten S. Mikkelsen's tangent space generation code.
void xiiGeometry::Transform | ( | const xiiMat4 & | mTransform, |
bool | bTransformPolyNormals ) |
Transforms all vertices by the given transform.
When bTransformPolyNormals is true, the polygon normals are transformed, as well. Set this to false when face normals are going to be computed later anyway.
void xiiGeometry::TriangulatePolygons | ( | xiiUInt32 | uiMaxVerticesInPolygon = 3 | ) |
Triangulates all polygons that have more than uiMaxVerticesInPolygon vertices.
Set uiMaxVerticesInPolygon to 4, if you want to keep quads unchanged.
void xiiGeometry::ValidateTangents | ( | float | fEpsilon = 0.01f | ) |
Checks whether present tangents are meaningful and resets them, if necessary.
Checks if the tangents are approximately orthogonal to the vertex normal and of unit length. If this is not the case the respective tangent will be zeroed. The caller can provide a comparison epsilon.