Empeld
Empeld plugin documentation.
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

IEnumerable< TriangleTrianglesInGroup (TriangleGroup group)
 
IEnumerable< TriangleTrianglesInGroup (string groupName)
 
 Mesh (bool autoNormals)
 
 Mesh ()
 
Triangle AddTriangle ()
 
Triangle AddTriangle (Vertex[] v, Material mat=null)
 
Triangle AddTriangle (Vertex a, Vertex b, Vertex c, Material mat=null, TriangleGroup group=null)
 
Triangle AddTriangle (Triangle tri)
 
Triangle [] AddQuad (Vertex a, Vertex b, Vertex c, Vertex d, Material material=null, TriangleGroup group=null)
 
void ReverseVertexOrder ()
 Flips vertex order on all triangles eg. from (1,2,3) to (3,2,1) Useful when normals are generating backwards More...
 
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 ()
 

Public Attributes

IEnumerable< TriangleGroupGroups => _triangles.Select(x => x.Group).Where(x => x != null).Distinct()
 

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

◆ Mesh() [1/3]

pluginbase.Helpers.Mesh.Mesh.Mesh ( bool  autoNormals)
72  {
73  _autoNormal = autoNormals;
74  }

◆ Mesh() [2/3]

pluginbase.Helpers.Mesh.Mesh.Mesh ( )
77  :this(false)
78  {}

◆ Mesh() [3/3]

pluginbase.Helpers.Mesh.Mesh.Mesh ( Mesh  mesh)
protected
81  :this()
82  {
83  this.Merge(mesh);
84  }
void Merge(Mesh mesh)
Merge multiple meshes
Definition: Mesh.cs:218

Member Function Documentation

◆ AddQuad()

Triangle [] pluginbase.Helpers.Mesh.Mesh.AddQuad ( Vertex  a,
Vertex  b,
Vertex  c,
Vertex  d,
Material  material = null,
TriangleGroup  group = null 
)
126  {
127  var tri1 = AddTriangle(a, b, c, material, group);
128  var tri2 = AddTriangle(a, c, d, material, group);
129  return new[]{tri1, tri2};
130  }
Triangle AddTriangle()
Definition: Mesh.cs:88

◆ AddTriangle() [1/4]

Triangle pluginbase.Helpers.Mesh.Mesh.AddTriangle ( )
89  {
90  return AddTriangle(new Vertex(), new Vertex(), new Vertex());
91  }
Triangle AddTriangle()
Definition: Mesh.cs:88

◆ AddTriangle() [2/4]

Triangle pluginbase.Helpers.Mesh.Mesh.AddTriangle ( Vertex []  v,
Material  mat = null 
)

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

, mat);

94  {
95  if (v.Length != 3)
96  {
97  throw new ArgumentException("Expected 3 verts");
98  }
99  return AddTriangle(v[0], v[1], v[2], mat);
100  }
Triangle AddTriangle()
Definition: Mesh.cs:88

◆ AddTriangle() [3/4]

Triangle pluginbase.Helpers.Mesh.Mesh.AddTriangle ( Vertex  a,
Vertex  b,
Vertex  c,
Material  mat = null,
TriangleGroup  group = null 
)
103  {
104  return AddTriangle( new Triangle
105  {
106  A = a,
107  B = b,
108  C = c,
109  Material = mat,
110  Group = group,
111  });
112  }
Triangle AddTriangle()
Definition: Mesh.cs:88

◆ AddTriangle() [4/4]

Triangle pluginbase.Helpers.Mesh.Mesh.AddTriangle ( Triangle  tri)
115  {
116  _triangles.Add(tri);
117  if (_autoNormal)
118  {
119  tri.A.Normal = tri.B.Normal = tri.C.Normal = CalculateNormal ( tri.A.Coordinate, tri.B.Coordinate, tri.C.Coordinate );
120  }
121 
122  return tri;
123  }

◆ Clone()

Mesh pluginbase.Helpers.Mesh.Mesh.Clone ( )
255  {
256  return new Mesh(this);
257  }
Mesh()
Definition: Mesh.cs:76

◆ ComputeBoundingBox()

AxisAlignedBox pluginbase.Helpers.Mesh.Mesh.ComputeBoundingBox ( )
247  {
248  return AxisAlignedBox.FromPointCloud(this.Vertices.Select(x => x.Coordinate));
249  }
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:54
IEnumerable< Vertex > Vertices
Definition: Mesh.cs:36

◆ ComputeFlatNormals()

void pluginbase.Helpers.Mesh.Mesh.ComputeFlatNormals ( )

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

161  {
162  foreach(var tri in _triangles)
163  {
164  tri.A.Normal = tri.B.Normal = tri.C.Normal = CalculateNormal(tri.A.Coordinate, tri.B.Coordinate, tri.C.Coordinate);
165  }
166  }

◆ ComputeSmoothNormalsByProximity()

void pluginbase.Helpers.Mesh.Mesh.ComputeSmoothNormalsByProximity ( )

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

193  {
194  //OPTIMIZE: This will count each proximity-very more than one. There's some optional optimization to do here
195  foreach(var vert in this.Vertices)
196  {
197  Vector3 sum = Vector3.Zero;
198  foreach(var tri in _triangles)
199  {
200  if ( (tri.A.Coordinate - vert.Coordinate).Length < SAME_BIAS
201  || (tri.B.Coordinate - vert.Coordinate).Length < SAME_BIAS
202  || (tri.C.Coordinate - vert.Coordinate).Length < SAME_BIAS)
203  {
204  sum += CalculateNormal(tri.A.Coordinate, tri.B.Coordinate, tri.C.Coordinate);
205  }
206  }
207  sum.Normalize();
208  vert.Normal = sum;
209  }
210  }
IEnumerable< Vertex > Vertices
Definition: Mesh.cs:36

◆ ComputeSmoothNormalsByRef()

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

173  {
174  foreach(var vert in this.Vertices)
175  {
176  Vector3 sum = Vector3.Zero;
177  foreach(var tri in _triangles)
178  {
179  if (tri.A == vert || tri.B == vert || tri.C == vert)
180  {
181  sum += CalculateNormal(tri.A.Coordinate, tri.B.Coordinate, tri.C.Coordinate);
182  }
183  }
184  sum.Normalize();
185  vert.Normal = sum;
186  }
187  }
IEnumerable< Vertex > Vertices
Definition: Mesh.cs:36

◆ Merge()

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

219  {
220  var matMap = new Dictionary<Material, Material>();
221  var vertMap = new Dictionary<Vertex, Vertex>();
222 
223  foreach (var mat in mesh.Materials)
224  {
225  matMap[mat] = mat.Clone();
226  }
227  foreach (var vert in mesh.Vertices)
228  {
229  vertMap[vert] = vert.Clone();
230  }
231  foreach (var tri in mesh._triangles)
232  {
233  _triangles.Add(new Triangle{
234  A = vertMap[tri.A],
235  B = vertMap[tri.B],
236  C = vertMap[tri.C],
237  Material = tri.Material != null ? matMap[tri.Material] : null
238  });
239  }
240  }

◆ ReverseVertexOrder()

void pluginbase.Helpers.Mesh.Mesh.ReverseVertexOrder ( )

Flips vertex order on all triangles eg. from (1,2,3) to (3,2,1) Useful when normals are generating backwards

146  {
147  foreach (var tri in _triangles)
148  {
149  var tmp = tri.A;
150  tri.A = tri.C;
151  tri.C = tmp;
152  }
153  }

◆ TrianglesInGroup() [1/2]

IEnumerable<Triangle> pluginbase.Helpers.Mesh.Mesh.TrianglesInGroup ( TriangleGroup  group)
26  {
27  return _triangles.Where(x => x.Group == group);
28  }

◆ TrianglesInGroup() [2/2]

IEnumerable<Triangle> pluginbase.Helpers.Mesh.Mesh.TrianglesInGroup ( string  groupName)
31  {
32  return _triangles.Where(x => x.Group?.Name == groupName);
33  }

Member Data Documentation

◆ Groups

IEnumerable<TriangleGroup> pluginbase.Helpers.Mesh.Mesh.Groups => _triangles.Select(x => x.Group).Where(x => x != null).Distinct()

Property Documentation

◆ Empty

bool pluginbase.Helpers.Mesh.Mesh.Empty
get

◆ Materials

IEnumerable<Material> pluginbase.Helpers.Mesh.Mesh.Materials
get

◆ TriangleCount

int pluginbase.Helpers.Mesh.Mesh.TriangleCount
get

◆ Triangles

IEnumerable<Triangle> pluginbase.Helpers.Mesh.Mesh.Triangles
get

◆ VertexCount

int pluginbase.Helpers.Mesh.Mesh.VertexCount
get

◆ Vertices

IEnumerable<Vertex> pluginbase.Helpers.Mesh.Mesh.Vertices
get

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