本文整理汇总了C#中MeshBuilder.AddTriangleFan方法的典型用法代码示例。如果您正苦于以下问题:C# MeshBuilder.AddTriangleFan方法的具体用法?C# MeshBuilder.AddTriangleFan怎么用?C# MeshBuilder.AddTriangleFan使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MeshBuilder
的用法示例。
在下文中一共展示了MeshBuilder.AddTriangleFan方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ToMeshGeometry3D
/// <summary>
/// Converts the mesh to a MeshGeometry3D.
/// </summary>
/// <param name="sharedVertices">
/// Allow shared vertices (smooth shading) if set to <c>true</c> .
/// </param>
/// <param name="shrinkFactor">
/// The shrink factor.
/// </param>
/// <param name="faceIndices">
/// The face indices.
/// </param>
/// <returns>
/// A mesh geometry.
/// </returns>
public MeshGeometry3D ToMeshGeometry3D(
bool sharedVertices = true, double shrinkFactor = 0.0, List<int> faceIndices = null)
{
bool shrink = Math.Abs(shrinkFactor) > double.Epsilon;
if (!sharedVertices || shrink)
{
// not shared vertices - flat shading
var tm = new MeshBuilder(false, this.TextureCoordinates != null);
int faceIndex = 0;
foreach (var face in this.Faces)
{
var vertices = new int[face.Length];
int j = 0;
var centroid = this.FindCentroid(faceIndex);
// var n = GetFaceNormal(faceIndex);
// for (int i = 0; i < face.Length; i++)
// tm.Normals.Add(n);
foreach (int v in face)
{
vertices[j++] = tm.Positions.Count;
var vertex = this.Vertices[v];
if (shrink)
{
vertex = vertex + (shrinkFactor * (centroid - vertex));
}
tm.Positions.Add(vertex);
if (tm.CreateTextureCoordinates)
{
tm.TextureCoordinates.Add(this.TextureCoordinates[v]);
}
}
tm.AddTriangleFan(vertices);
if (faceIndices != null)
{
int numberOfTriangles = vertices.Length - 2;
for (int i = 0; i < numberOfTriangles; i++)
{
faceIndices.Add(faceIndex);
}
}
faceIndex++;
}
return tm.ToMesh();
}
else
{
// shared vertices - smooth shading
var tm = new MeshBuilder(false, this.TextureCoordinates != null);
foreach (var v in this.Vertices)
{
tm.Positions.Add(v);
}
if (this.TextureCoordinates != null)
{
foreach (var uv in this.TextureCoordinates)
{
tm.TextureCoordinates.Add(uv);
}
}
int faceIndex = 0;
foreach (var face in this.Faces)
{
tm.AddTriangleFan(face);
if (faceIndices != null)
{
int numberOfTriangles = face.Length - 2;
for (int i = 0; i < numberOfTriangles; i++)
{
faceIndices.Add(faceIndex);
}
}
faceIndex++;
}
return tm.ToMesh();
//.........这里部分代码省略.........
示例2: UpdateVisuals
/// <summary>
/// Updates the visuals.
/// </summary>
protected void UpdateVisuals()
{
this.vertexVisuals = new Dictionary<HalfEdgeMesh.Vertex, ModelUIElement3D>();
this.halfEdgeVisuals = new Dictionary<HalfEdgeMesh.HalfEdge, ModelUIElement3D>();
this.faceVisuals = new Dictionary<HalfEdgeMesh.Face, ModelUIElement3D>();
this.Children.Clear();
if (this.Mesh == null)
{
return;
}
if (this.VertexRadius > 0)
{
// Add the vertices
foreach (var vertex in this.Mesh.Vertices)
{
var gm = new MeshBuilder(false, false);
gm.AddSubdivisionSphere(vertex.Position, this.VertexRadius, 4);
var vertexElement = new ModelUIElement3D
{
Model = new GeometryModel3D(gm.ToMesh(), this.VertexMaterial)
};
var currentVertex = vertex;
vertexElement.MouseLeftButtonDown += (s, e) => this.HighlightVertex(currentVertex);
this.vertexVisuals.Add(vertex, vertexElement);
this.Add(vertexElement);
}
}
var faceCenter = new Dictionary<HalfEdgeMesh.Face, Point3D>();
foreach (var face in this.Mesh.Faces)
{
var faceVertices = face.Vertices.Select(v => v.Position).ToList();
// Find the face centroid
var center = this.FindCentroid(faceVertices);
faceCenter.Add(face, center);
if (this.ShrinkFactor < 1)
{
// Add the faces
for (int i = 0; i < faceVertices.Count; i++)
{
faceVertices[i] += (center - faceVertices[i]) * this.ShrinkFactor;
}
var gm = new MeshBuilder(false, false);
gm.AddTriangleFan(faceVertices);
var faceElement = new ModelUIElement3D
{
Model =
new GeometryModel3D(gm.ToMesh(), this.FaceMaterial)
{
BackMaterial = this.FaceBackMaterial
}
};
var currentFace = face;
faceElement.MouseLeftButtonDown += (s, e) => this.HighlightFace(currentFace);
this.faceVisuals.Add(face, faceElement);
this.Add(faceElement);
}
}
if (this.EdgeDiameter > 0)
{
// Add the edges
foreach (var edge in this.Mesh.Edges)
{
var start = edge.StartVertex.Position;
var end = edge.EndVertex.Position;
var center = faceCenter[edge.Face];
start = start + (center - start) * this.ShrinkFactor;
end = end + (center - end) * this.ShrinkFactor;
var gm = new MeshBuilder(false, false);
gm.AddArrow(start, end, this.EdgeDiameter);
var edgeElement = new ModelUIElement3D
{
Model = new GeometryModel3D(gm.ToMesh(), this.EdgeMaterial)
};
var currentEdge = edge;
edgeElement.MouseLeftButtonDown += (s, e) => { this.HighlightEdge(currentEdge); };
this.halfEdgeVisuals.Add(edge, edgeElement);
this.Add(edgeElement);
}
}
}