Empeld
Empeld plugin documentation.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events
pluginbase.Helpers.Mesh.Mesh Class Reference

A raw, un-optimize, fully mutable, representation of a static mesh More...

Inheritance diagram for pluginbase.Helpers.Mesh.Mesh:

Public Member Functions

 Mesh (bool autoNormals)
 
 Mesh ()
 
Triangle AddTriangle ()
 
Triangle AddTriangle (Vertex[] v, Material mat)
 
Triangle AddTriangle (Vertex[] v)
 
Triangle AddTriangle (Vertex a, Vertex b, Vertex c)
 
Triangle AddTriangle (Vertex a, Vertex b, Vertex c, Material mat)
 
Triangle AddTriangle (Triangle tri)
 
Triangle[] AddQuad (Vertex a, Vertex b, Vertex c, Vertex d, Material material)
 
Triangle[] AddQuad (Vertex a, Vertex b, Vertex c, Vertex d)
 
void ComputeFlatNormals ()
 Computes the flat normals. Vert fast, but assumes each triangle has its own unique set of vertices More...
 
void ComputeSmoothNormalsByRef ()
 Computes the smooth normals by reference. Mid-range speed O(v * t). Only works if vertices are propertly created with references to each other in an indexed way More...
 
void ComputeSmoothNormalsByProximity ()
 Computes the smooth normals by proximity of the coordinate. Slowest, but most accurate, method More...
 
void Merge (Mesh mesh)
 Merge multiple meshes More...
 
AxisAlignedBox ComputeBoundingBox ()
 
Mesh Clone ()
 

Protected Member Functions

 Mesh (Mesh mesh)
 

Properties

IEnumerable< TriangleTriangles [get]
 
IEnumerable< VertexVertices [get]
 
IEnumerable< MaterialMaterials [get]
 
int TriangleCount [get]
 
int VertexCount [get]
 
bool Empty [get]
 

Detailed Description

A raw, un-optimize, fully mutable, representation of a static mesh

Constructor & Destructor Documentation

pluginbase.Helpers.Mesh.Mesh.Mesh ( bool  autoNormals)
60  {
61  _autoNormal = autoNormals;
62  }
pluginbase.Helpers.Mesh.Mesh.Mesh ( )
65  :this(false)
66  {}
pluginbase.Helpers.Mesh.Mesh.Mesh ( Mesh  mesh)
protected
69  :this()
70  {
71  this.Merge(mesh);
72  }
void Merge(Mesh mesh)
Merge multiple meshes
Definition: Mesh.cs:206

Member Function Documentation

Triangle [] pluginbase.Helpers.Mesh.Mesh.AddQuad ( Vertex  a,
Vertex  b,
Vertex  c,
Vertex  d,
Material  material 
)
123  {
124  var tri1 = AddTriangle(a, b, c, material);
125  var tri2 = AddTriangle(a, c, d, material);
126  return new[]{tri1, tri2};
127  }
Triangle AddTriangle()
Definition: Mesh.cs:76
Triangle [] pluginbase.Helpers.Mesh.Mesh.AddQuad ( Vertex  a,
Vertex  b,
Vertex  c,
Vertex  d 
)
130  {
131  return AddQuad(a,b,c,d,null);
132  }
Triangle[] AddQuad(Vertex a, Vertex b, Vertex c, Vertex d, Material material)
Definition: Mesh.cs:122
Triangle pluginbase.Helpers.Mesh.Mesh.AddTriangle ( )
77  {
78  return AddTriangle(new Vertex(), new Vertex(), new Vertex());
79  }
Triangle AddTriangle()
Definition: Mesh.cs:76
Triangle pluginbase.Helpers.Mesh.Mesh.AddTriangle ( Vertex[]  v,
Material  mat 
)

Attribute: 0], v[1], v[2

, mat);

82  {
83  if (v.Length != 3)
84  {
85  throw new ArgumentException("Expected 3 verts");
86  }
87  return AddTriangle(v[0], v[1], v[2], mat);
88  }
Triangle AddTriangle()
Definition: Mesh.cs:76
Triangle pluginbase.Helpers.Mesh.Mesh.AddTriangle ( Vertex[]  v)
91  {
92  return AddTriangle(v, null);
93  }
Triangle AddTriangle()
Definition: Mesh.cs:76
Triangle pluginbase.Helpers.Mesh.Mesh.AddTriangle ( Vertex  a,
Vertex  b,
Vertex  c 
)
96  {
97  return AddTriangle(a, b, c, null);
98  }
Triangle AddTriangle()
Definition: Mesh.cs:76
Triangle pluginbase.Helpers.Mesh.Mesh.AddTriangle ( Vertex  a,
Vertex  b,
Vertex  c,
Material  mat 
)
101  {
102  return AddTriangle( new Triangle
103  {
104  A = a,
105  B = b,
106  C = c,
107  Material = mat
108  });
109  }
Triangle AddTriangle()
Definition: Mesh.cs:76
Triangle pluginbase.Helpers.Mesh.Mesh.AddTriangle ( Triangle  tri)
112  {
113  _triangles.Add(tri);
114  if (_autoNormal)
115  {
116  tri.A.Normal = tri.B.Normal = tri.C.Normal = CalculateNormal ( tri.A.Coordinate, tri.B.Coordinate, tri.C.Coordinate );
117  }
118 
119  return tri;
120  }
Mesh pluginbase.Helpers.Mesh.Mesh.Clone ( )
243  {
244  return new Mesh(this);
245  }
Mesh()
Definition: Mesh.cs:64
AxisAlignedBox pluginbase.Helpers.Mesh.Mesh.ComputeBoundingBox ( )
235  {
236  return AxisAlignedBox.FromPointCloud(this.Vertices.Select(x => x.Coordinate));
237  }
Represents an axis-aligned bounding box
Definition: AxisAlignedBox.cs:11
static AxisAlignedBox FromPointCloud(IEnumerable< Vector3 > points)
Gets the AABB from a set of points in a cloud
Definition: AxisAlignedBox.cs:47
IEnumerable< Vertex > Vertices
Definition: Mesh.cs:26
void pluginbase.Helpers.Mesh.Mesh.ComputeFlatNormals ( )

Computes the flat normals. Vert fast, but assumes each triangle has its own unique set of vertices

149  {
150  foreach(var tri in _triangles)
151  {
152  tri.A.Normal = tri.B.Normal = tri.C.Normal = CalculateNormal(tri.A.Coordinate, tri.B.Coordinate, tri.C.Coordinate);
153  }
154  }
void pluginbase.Helpers.Mesh.Mesh.ComputeSmoothNormalsByProximity ( )

Computes the smooth normals by proximity of the coordinate. Slowest, but most accurate, method

181  {
182  //OPTIMIZE: This will count each proximity-very more than one. There's some optional optimization to do here
183  foreach(var vert in this.Vertices)
184  {
185  Vector3 sum = Vector3.Zero;
186  foreach(var tri in _triangles)
187  {
188  if ( (tri.A.Coordinate - vert.Coordinate).Length < SAME_BIAS
189  || (tri.B.Coordinate - vert.Coordinate).Length < SAME_BIAS
190  || (tri.C.Coordinate - vert.Coordinate).Length < SAME_BIAS)
191  {
192  sum += CalculateNormal(tri.A.Coordinate, tri.B.Coordinate, tri.C.Coordinate);
193  }
194  }
195  sum.Normalize();
196  vert.Normal = sum;
197  }
198  }
IEnumerable< Vertex > Vertices
Definition: Mesh.cs:26
void pluginbase.Helpers.Mesh.Mesh.ComputeSmoothNormalsByRef ( )

Computes the smooth normals by reference. Mid-range speed O(v * t). Only works if vertices are propertly created with references to each other in an indexed way

161  {
162  foreach(var vert in this.Vertices)
163  {
164  Vector3 sum = Vector3.Zero;
165  foreach(var tri in _triangles)
166  {
167  if (tri.A == vert || tri.B == vert || tri.C == vert)
168  {
169  sum += CalculateNormal(tri.A.Coordinate, tri.B.Coordinate, tri.C.Coordinate);
170  }
171  }
172  sum.Normalize();
173  vert.Normal = sum;
174  }
175  }
IEnumerable< Vertex > Vertices
Definition: Mesh.cs:26
void pluginbase.Helpers.Mesh.Mesh.Merge ( Mesh  mesh)

Merge multiple meshes

Parameters
meshMesh.

Attribute: mat

= mat.Clone();

Attribute: vert

= vert.Clone();

Attribute: tri.A

,

Attribute: tri.B

,

Attribute: tri.C

,

Attribute: tri.Material

: null

207  {
208  var matMap = new Dictionary<Material, Material>();
209  var vertMap = new Dictionary<Vertex, Vertex>();
210 
211  foreach (var mat in mesh.Materials)
212  {
213  matMap[mat] = mat.Clone();
214  }
215  foreach (var vert in mesh.Vertices)
216  {
217  vertMap[vert] = vert.Clone();
218  }
219  foreach (var tri in mesh._triangles)
220  {
221  _triangles.Add(new Triangle{
222  A = vertMap[tri.A],
223  B = vertMap[tri.B],
224  C = vertMap[tri.C],
225  Material = tri.Material != null ? matMap[tri.Material] : null
226  });
227  }
228  }

Property Documentation

bool pluginbase.Helpers.Mesh.Mesh.Empty
get
IEnumerable<Material> pluginbase.Helpers.Mesh.Mesh.Materials
get
int pluginbase.Helpers.Mesh.Mesh.TriangleCount
get
IEnumerable<Triangle> pluginbase.Helpers.Mesh.Mesh.Triangles
get
int pluginbase.Helpers.Mesh.Mesh.VertexCount
get
IEnumerable<Vertex> pluginbase.Helpers.Mesh.Mesh.Vertices
get

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