TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
G3D::MeshBuilder Class Reference

#include <MeshBuilder.h>

Public Types

enum  { AUTO_WELD = -100 }
 

Public Member Functions

 MeshBuilder (bool twoSided=false, bool scaleAndCenter=true)
 
void commit (std::string &name, Array< int > &indexArray, Array< Vector3 > &vertexArray)
 
void addTriangle (const Vector3 &a, const Vector3 &b, const Vector3 &c)
 
void addQuad (const Vector3 &a, const Vector3 &b, const Vector3 &c, const Vector3 &d)
 
void addTriangle (const Triangle &t)
 
void setName (const std::string &n)
 
void setWeldRadius (double r)
 

Private Types

typedef Array< int > List
 

Private Member Functions

void centerTriList ()
 
void computeBounds (Vector3 &min, Vector3 &max)
 

Private Attributes

std::string name
 
bool scaleAndCenter
 
Array< Vector3triList
 
bool _twoSided
 
double close
 

Detailed Description

Allows creation of optimized watertight meshes from unoptimized polygon soups. See also G3D::MeshAlg for algorithms that operate on the output.

Member Typedef Documentation

typedef Array<int> G3D::MeshBuilder::List
private

Indices of vertices in or near a grid cell.

Member Enumeration Documentation

anonymous enum

Set setWeldRadius to AUTO_WELD to weld vertices closer than 1/2 the smallest edge length in a model.

Enumerator
AUTO_WELD 
30 {AUTO_WELD = -100};
Definition: MeshBuilder.h:30

Constructor & Destructor Documentation

G3D::MeshBuilder::MeshBuilder ( bool  twoSided = false,
bool  scaleAndCenter = true 
)
inline
bool _twoSided
Definition: MeshBuilder.h:48
Definition: MeshBuilder.h:30
bool scaleAndCenter
Definition: MeshBuilder.h:38
double close
Definition: MeshBuilder.h:51

Member Function Documentation

void G3D::MeshBuilder::addQuad ( const Vector3 a,
const Vector3 b,
const Vector3 c,
const Vector3 d 
)

Adds two new triangles to the model. (Counter clockwise)

105  {
106  addTriangle(a, b, c);
107  addTriangle(a, c, d);
108 }
void addTriangle(const Vector3 &a, const Vector3 &b, const Vector3 &c)
Definition: MeshBuilder.cpp:96

+ Here is the call graph for this function:

void G3D::MeshBuilder::addTriangle ( const Vector3 a,
const Vector3 b,
const Vector3 c 
)

Adds a new triangle to the model. (Counter clockwise)

96  {
97  triList.append(a, b, c);
98 
99  if (_twoSided) {
100  triList.append(c, b, a);
101  }
102 }
Array< Vector3 > triList
Definition: MeshBuilder.h:43
bool _twoSided
Definition: MeshBuilder.h:48

+ Here is the caller graph for this function:

void G3D::MeshBuilder::addTriangle ( const Triangle t)
111  {
112  addTriangle(t.vertex(0), t.vertex(1), t.vertex(2));
113 }
void addTriangle(const Vector3 &a, const Vector3 &b, const Vector3 &c)
Definition: MeshBuilder.cpp:96

+ Here is the call graph for this function:

void G3D::MeshBuilder::centerTriList ( )
private
59  {
60  // Compute the range of the vertices
61  Vector3 vmin, vmax;
62 
63  computeBounds(vmin, vmax);
64 
65  const Vector3 diagonal = vmax - vmin;
66  float scale = max(max(diagonal.x, diagonal.y), diagonal.z) / 2.0f;
67  debugAssert(scale > 0);
68 
69  const Vector3 translation = vmin + diagonal / 2.0f;
70 
71  // Center and scale all vertices in the input list
72  int v;
73 
74  if (scaleAndCenter) {
75  //Matrix3 rot90 = Matrix3::fromAxisAngle(Vector3::UNIT_Y, toRadians(180)) * Matrix3::fromAxisAngle(Vector3::UNIT_X, toRadians(90));
76  for (v = 0; v < triList.size(); ++v) {
77  triList[v] = (triList[v] - translation) / scale;
78  //triList[v] = rot90 * triList[v];
79  }
80  }
81 }
Array< Vector3 > triList
Definition: MeshBuilder.h:43
void computeBounds(Vector3 &min, Vector3 &max)
Definition: MeshBuilder.cpp:84
T max(const T &x, const T &y)
Definition: g3dmath.h:320
bool scaleAndCenter
Definition: MeshBuilder.h:38
#define debugAssert(exp)
Definition: debugAssert.h:160
static bool diagonal(int i, int j, int n, const int *verts, int *indices)
Definition: RecastMesh.cpp:287

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void G3D::MeshBuilder::commit ( std::string &  name,
Array< int > &  indexArray,
Array< Vector3 > &  vertexArray 
)

Writes the model to the arrays, which can then be used with G3D::IFSModel::save and G3D::MeshAlg

20  {
21  n = name;
22 
23  // Make the data fit in a unit cube
24  centerTriList();
25 
26  Array<int> toNew, toOld;
27 
29  Array<int> index;
30  MeshAlg::createIndexArray(triList.size(), index);
31  double minEdgeLen, maxEdgeLen, meanEdgeLen, medianEdgeLen;
32  double minFaceArea, maxFaceArea, meanFaceArea, medianFaceArea;
34  minEdgeLen, meanEdgeLen, medianEdgeLen, maxEdgeLen,
35  minFaceArea, meanFaceArea, medianFaceArea, maxFaceArea);
36  close = minEdgeLen * 0.1;
37  }
38 
39  MeshAlg::computeWeld(triList, outvertexArray, toNew, toOld, (float)close);
40 
41  // Construct triangles
42  for (int t = 0; t < triList.size(); t += 3) {
43  int index[3];
44 
45  for (int i = 0; i < 3; ++i) {
46  index[i] = toNew[t + i];
47  }
48 
49  // Throw out zero size triangles
50  if ((index[0] != index[1]) &&
51  (index[1] != index[2]) &&
52  (index[2] != index[0])) {
53  indexArray.append(index[0], index[1], index[2]);
54  }
55  }
56 }
Array< Vector3 > triList
Definition: MeshBuilder.h:43
void centerTriList()
Definition: MeshBuilder.cpp:59
static void computeWeld(const Array< Vector3 > &oldVertexPositions, Array< Vector3 > &newVertexPositions, Array< int > &toNew, Array< int > &toOld, float radius=fuzzyEpsilon32)
Definition: MeshAlgWeld.cpp:203
Definition: MeshBuilder.h:30
std::string name
Definition: MeshBuilder.h:36
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)
Definition: MeshAlg.cpp:343
double close
Definition: MeshBuilder.h:51
void append(const T &value)
Definition: Array.h:583
static void createIndexArray(int n, Array< int > &array, int start=0, int run=1, int skip=0)
Definition: MeshAlg.cpp:316

+ Here is the call graph for this function:

void G3D::MeshBuilder::computeBounds ( Vector3 min,
Vector3 max 
)
private
84  {
85  min = Vector3::inf();
86  max = -min;
87 
88  int v;
89  for (v = 0; v < triList.size(); ++v) {
90  min = min.min(triList[v]);
91  max = max.max(triList[v]);
92  }
93 }
Array< Vector3 > triList
Definition: MeshBuilder.h:43
T max(const T &x, const T &y)
Definition: g3dmath.h:320
T min(const T &x, const T &y)
Definition: g3dmath.h:305
static const Vector3 & inf()
Definition: Vector3.cpp:124

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void G3D::MeshBuilder::setName ( const std::string &  n)
15  {
16  name = n;
17 }
std::string name
Definition: MeshBuilder.h:36
void G3D::MeshBuilder::setWeldRadius ( double  r)
inline

Vertices within this distance are considered identical. Use AUTO_WELD (the default) to have the distance be a function of the model size.

77  {
78  close = r;
79  }
double close
Definition: MeshBuilder.h:51

Member Data Documentation

bool G3D::MeshBuilder::_twoSided
private
double G3D::MeshBuilder::close
private

Collapse radius

std::string G3D::MeshBuilder::name
private
bool G3D::MeshBuilder::scaleAndCenter
private
Array<Vector3> G3D::MeshBuilder::triList
private

All of the triangles, as a long triangle list.


The documentation for this class was generated from the following files: