Empeld
Empeld plugin documentation.
pluginbase.Helpers.Mesh.Manipulation.SimpleSubdivide Class Reference

Static Public Member Functions

static Vertex AverageVertices (Vertex a, Vertex b)
 
static Mesh Subdivide (this Mesh mesh)
 

Member Function Documentation

◆ AverageVertices()

static Vertex pluginbase.Helpers.Mesh.Manipulation.SimpleSubdivide.AverageVertices ( Vertex  a,
Vertex  b 
)
static
9  {
10  return new Vertex
11  {
12  Coordinate = (a.Coordinate + b.Coordinate ) * 0.5f,
13  TexCoord = (a.TexCoord + b.TexCoord) * 0.5f,
14  Normal = (a.Normal + b.Normal) * 0.5f,
15  Color = (a.Color + b.Color) * 0.5f
16  };
17  }

◆ Subdivide()

static Mesh pluginbase.Helpers.Mesh.Manipulation.SimpleSubdivide.Subdivide ( this Mesh  mesh)
static

Attribute: mat

= mat.Clone();

Attribute: triangle.Material

: null;

20  {
21  var outMesh = new Mesh();
22 
23  var matMap = new Dictionary<Material, Material>();
24  foreach(var mat in mesh.Materials)
25  {
26  matMap[mat] = mat.Clone();
27  }
28 
29  foreach(var triangle in mesh.Triangles)
30  {
31  Vertex A = triangle.A.Clone();
32  Vertex B = triangle.B.Clone();
33  Vertex C = triangle.C.Clone();
34  Vertex D = AverageVertices(triangle.A, triangle.B);
35  Vertex E = AverageVertices(triangle.B, triangle.C);
36  Vertex F = AverageVertices(triangle.A, triangle.C);
37  Material mat = triangle.Material != null ? matMap[triangle.Material] : null;
38 
39  outMesh.AddTriangle(A, D, F, mat);
40  outMesh.AddTriangle(D, B, E, mat);
41  outMesh.AddTriangle(F, E, C, mat);
42  outMesh.AddTriangle(D, E, F, mat);
43  }
44 
45  return outMesh;
46  }
static Vertex AverageVertices(Vertex a, Vertex b)
Definition: SimpleSubdivide.cs:8

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