TrinityCore
|
#include <MeshAlg.h>
Classes | |
class | Edge |
class | Face |
class | Geometry |
class | Vertex |
Public Types | |
typedef PrimitiveType | Primitive |
Static Public Member Functions | |
static void | computeAdjacency (const Array< Vector3 > &vertexGeometry, const Array< int > &indexArray, Array< Face > &faceArray, Array< Edge > &edgeArray, Array< Vertex > &vertexArray) |
static void | computeAdjacency (const Array< Vector3 > &vertexArray, const Array< int > &indexArray, Array< Face > &faceArray, Array< Edge > &edgeArray, Array< Array< int > > &facesAdjacentToVertex) |
static void | computeAreaStatistics (const Array< Vector3 > &vertexArray, const Array< int > &indexArray, double &minEdgeLength, double &meanEdgeLength, double &medianEdgeLength, double &maxEdgeLength, double &minFaceArea, double &meanFaceArea, double &medianFaceArea, double &maxFaceArea) |
static void | computeTangentSpaceBasis (const Array< Vector3 > &vertexArray, const Array< Vector2 > &texCoordArray, const Array< Vector3 > &vertexNormalArray, const Array< Face > &faceArray, Array< Vector3 > &tangent, Array< Vector3 > &binormal) |
static void | computeNormals (const Array< Vector3 > &vertexArray, const Array< Face > &faceArray, const Array< Array< int > > &adjacentFaceArray, Array< Vector3 > &vertexNormalArray, Array< Vector3 > &faceNormalArray) |
static void | computeNormals (const Array< Vector3 > &vertexGeometry, const Array< Face > &faceArray, const Array< Vertex > &vertexArray, Array< Vector3 > &vertexNormalArray, Array< Vector3 > &faceNormalArray) |
static void | computeNormals (Geometry &geometry, const Array< int > &indexArray) |
static void | computeFaceNormals (const Array< Vector3 > &vertexArray, const Array< Face > &faceArray, Array< Vector3 > &faceNormals, bool normalize=true) |
static void | identifyBackfaces (const Array< Vector3 > &vertexArray, const Array< Face > &faceArray, const Vector4 &P, Array< bool > &backface) |
static void | identifyBackfaces (const Array< Vector3 > &vertexArray, const Array< Face > &faceArray, const Vector4 &P, Array< bool > &backface, const Array< Vector3 > &faceNormals) |
static void | computeWeld (const Array< Vector3 > &oldVertexPositions, Array< Vector3 > &newVertexPositions, Array< int > &toNew, Array< int > &toOld, float radius=fuzzyEpsilon32) |
static void | weldAdjacency (const Array< Vector3 > &originalGeometry, Array< Face > &faceArray, Array< Edge > &edgeArray, Array< Vertex > &vertexArray, float radius=fuzzyEpsilon32) |
static int | countBoundaryEdges (const Array< Edge > &edgeArray) |
static void | createIndexArray (int n, Array< int > &array, int start=0, int run=1, int skip=0) |
static void | computeBounds (const Array< Vector3 > &vertex, class AABox &box, class Sphere &sphere) |
static void | computeBounds (const Array< Vector3 > &vertex, const Array< int > &index, class AABox &box, class Sphere &sphere) |
static void | debugCheckConsistency (const Array< Face > &faceArray, const Array< Edge > &edgeArray, const Array< Vertex > &vertexArray) |
static void | generateGrid (Array< Vector3 > &vertex, Array< Vector2 > &texCoord, Array< int > &index, int wCells=10, int hCells=10, const Vector2 &textureScale=Vector2(1, 1), bool spaceCentered=true, bool twoSided=true, const CoordinateFrame &xform=CoordinateFrame(), const Image1::Ref &elevation=Image1::Ref()) |
template<class IndexType > | |
static void | toIndexedTriList (const Array< IndexType > &inIndices, MeshAlg::Primitive inType, Array< IndexType > &outIndices) |
Static Protected Member Functions | |
static int | findEdgeIndex (const Array< Vector3 > &vertexArray, Array< Edge > &geometricEdgeArray, int i0, int i1, int f, double area) |
Static Private Member Functions | |
static void | weldBoundaryEdges (Array< Face > &faceArray, Array< Edge > &edgeArray, Array< Vertex > &vertexArray) |
Indexed mesh algorithms. You have to build your own mesh class.
No mesh class is provided with G3D because there isn't an "ideal" mesh format– one application needs keyframed animation, another skeletal animation, a third texture coordinates, a fourth cannot precompute information, etc. Instead of compromising, this class implements the hard parts of mesh computation and you can write your own ideal mesh class on top of it.
|
static |
Given a set of vertices and a set of indices for traversing them to create triangles, computes other mesh properties.
Colocated vertices are treated as separate. To have colocated vertices collapsed (necessary for many algorithms, like shadowing), weld the mesh before computing adjacency.
Recent change: In version 6.00, colocated vertices were automatically welded by this routine and degenerate faces and edges were removed. That is no longer the case.
Where two faces meet, there are two opposite directed edges. These are collapsed into a single bidirectional edge in the edgeArray. If four faces meet exactly at the same edge, that edge will appear twice in the array, and so on. If an edge is a boundary of the mesh (i.e. if the edge has only one adjacent face) it will appear in the array with one face index set to MeshAlg::Face::NONE.
vertexGeometry | Vertex positions to use when deciding colocation. |
indexArray | Order to traverse vertices to make triangles |
faceArray | Output |
edgeArray | Output. Sorted so that boundary edges are at the end of the array. |
vertexArray | Output |
|
static |
facesAdjacentToVertex | Output adjacentFaceArray[v] is an array of indices for faces touching vertex index v |
|
static |
Computes some basic mesh statistics including: min, max mean and median, edge lengths; and min, mean, median, and max face area.
vertexArray | Vertex positions to use when deciding colocation. |
indexArray | Order to traverse vertices to make triangles |
minEdgeLength | Minimum edge length |
meanEdgeLength | Mean edge length |
medianEdgeLength | Median edge length |
maxEdgeLength | Max edge length |
minFaceArea | Minimum face area |
meanFaceArea | Mean face area |
medianFaceArea | Median face area |
maxFaceArea | Max face area |
|
static |
Computes a conservative, near-optimal axis aligned bounding box and sphere.
[The] bounding sphere uses the method from J. Ritter. An effcient bounding sphere. In Andrew S. Glassner, editor, Graphics Gems. Academic Press, Boston, MA, 1990.
|
static |
Computes bounds for a subset of the vertices. It is ok if vertices appear more than once in the index array.
|
static |
Computes face normals only. Significantly faster (especially if normalize is false) than computeNormals.
|
static |
|
static |
Vertex normals are weighted by the area of adjacent faces. Nelson Max showed this is superior to uniform weighting for general meshes in jgt.
vertexNormalArray | Output. Unit length |
faceNormalArray | Output. Degenerate faces produce zero magnitude normals. Unit length |
Computes unit length normals in place using the other computeNormals methods. If you already have a face array use another method; it will be faster.
|
static |
Computes tangent and binormal vectors, which provide a (mostly) consistent parameterization over the surface for effects like bump mapping. In the resulting coordinate frame, T = x (varies with texture s coordinate), B = y (varies with negative texture t coordinate), and N = z for a right-handed coordinate frame. If a billboard is vertical on the screen in view of the camera, the tangent space matches the camera's coordinate frame.
The vertex, texCoord, tangent, and binormal arrays are parallel arrays.
The resulting tangent and binormal might not be exactly perpendicular to each other. They are guaranteed to be perpendicular to the normal.
[Max] McGuire
|
static |
Welds nearby and colocated elements of the oldVertexArray together so that newVertexArray contains no vertices within radius of one another. Every vertex in newVertexPositions also appears in oldVertexPositions. This is useful for downsampling meshes and welding cracks created by artist errors or numerical imprecision.
The two integer arrays map indices back and forth between the arrays according to:
oldVertexArray[toOld[ni]] == newVertexArray[ni] oldVertexArray[oi] == newVertexArray[toNew[ni]]
Note that newVertexPositions is never longer than oldVertexPositions and is shorter when vertices are welded.
Welding with a large radius will effectively compute a lower level of detail for the mesh.
The welding method runs in roughly linear time in the length of oldVertexArray– a uniform spatial grid is used to achieve nearly constant time vertex collapses for uniformly distributed vertices.
It is sometimes desirable to keep the original vertex ordering but identify the unique vertices. The following code computes array canonical s.t. canonical[v] = first occurance of a vertex near oldVertexPositions[v] in oldVertexPositions.
Array<int> canonical(oldVertexPositions.size()), toNew, toOld; computeWeld(oldVertexPositions, Array<Vector3>(), toNew, toOld, radius); for (int v = 0; v < canonical.size(); ++v) { canonical[v] = toOld[toNew[v]]; }
See also G3D::MeshAlg::weldAdjacency.
[The] method is that described as the 'Grouper' in Baum, Mann, Smith, and Winget, Making Radiosity Usable: Automatic Preprocessing and Meshing Techniques for the Generation of Accurate Radiosity Solutions, Computer Graphics vol 25, no 4, July 1991.
Counts the number of edges (in an edge array returned from MeshAlg::computeAdjacency) that have only one adjacent face.
|
static |
Generates an array of integers from start to start + n - 1 that have run numbers in series then omit the next skip before the next run. Useful for turning a triangle list into an indexed face set.
Example:
createIndexArray(10, x); // x = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
createIndexArray(5, x, 2); // x = [2, 3, 4, 5, 6, 7]
createIndexArray(6, x, 0, 2, 1); // x = [0, 1, 3, 4, 6, 7]
|
static |
In debug mode, asserts that the adjacency references between the face, edge, and vertex array are consistent.
|
staticprotected |
Helper for computeAdjacency. If a directed edge with index e already exists from i0 to i1 then e is returned. If a directed edge with index e already exists from i1 to i0, ~e is returned (the complement) and edgeArray[e] is set to f. Otherwise, a new edge is created from i0 to i1 with first face index f and its index is returned.
vertexArray | Vertex positions to use when deciding colocation. |
area | Area of face f. When multiple edges of the same direction are found between the same vertices (usually because of degenerate edges) the face with larger area is kept in the edge table. |
|
static |
Generates a unit square in the X-Z plane composed of a grid of wCells x hCells squares on the unit interval and then transforms it by xform.
vertex | Output vertices |
texCoord | Output texture coordinates |
index | Output triangle list indices |
textureScale | Lower-right texture coordinate |
spaceCentered | If true, the coordinates generated are centered at the origin before the transformation. |
twoSided | If true, matching top and bottom planes are generated. |
elevation | If non-NULL, values from this image are used as elevations. Apply an xform to adjust the scale |
|
static |
Classifies each face as a backface or a front face relative to the observer point P (which is at infinity when P.w = 0). A face with normal exactly perpendicular to the observer vector may be classified as either a front or a back face arbitrarily.
|
static |
A faster version of identifyBackfaces for the case where face normals have already been computed
|
inlinestatic |
Converts quadlist (QUADS), triangle fan (TRIANGLE_FAN), tristrip(TRIANGLE_STRIP), and quadstrip (QUAD_STRIP) indices into triangle list (TRIANGLES) indices and appends them to outIndices.
|
static |
Modifies the face, edge, and vertex arrays in place so that colocated (within radius) vertices are treated as identical. Note that the vertexArray and corresponding geometry will contain elements that are no longer used. In the vertexArray, these elements are initialized to MeshAlg::Vertex() but not removed (because removal would change the indexing).
This is a good preprocessing step for algorithms that are only concerned with the shape of a mesh (e.g. cartoon rendering, fur, shadows) and not the indexing of the vertices.
Use this method when you have already computed adjacency information and want to collapse colocated vertices within that data without disturbing the actual mesh vertices or indexing scheme.
If you have not computed adjacency already, use MeshAlg::computeWeld instead and compute adjacency information after welding.
faceArray | Mutated in place. Size is maintained (degenerate faces are not removed). |
edgeArray | Mutated in place. May shrink if boundary edges are welded together. |
vertexArray | Mutated in place. Size is maintained (duplicate vertices contain no adjacency info). |
|
staticprivate |
Helper for weldAdjacency