本文整理汇总了C#中IMesh.AddVertex方法的典型用法代码示例。如果您正苦于以下问题:C# IMesh.AddVertex方法的具体用法?C# IMesh.AddVertex怎么用?C# IMesh.AddVertex使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IMesh
的用法示例。
在下文中一共展示了IMesh.AddVertex方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Load
public void Load(IMesh mesh, string filePath)
{
var dxfLoad = DxfDocument.Load(filePath);
var vertices = new List<IVertex>();
var faces = new List<IFace>();
var verticesIndexMap = new Dictionary<IVertex, int>();
int currentVertexIndex = 0;
foreach (var face3D in dxfLoad.Faces3d)
{
var v1 = face3D.FirstVertex;
var v2 = face3D.SecondVertex;
var v3 = face3D.ThirdVertex;
var v4 = face3D.FourthVertex;
currentVertexIndex = CreateTriangleFace(v1, v2, v3, verticesIndexMap, currentVertexIndex, vertices, faces);
currentVertexIndex = CreateTriangleFace(v3, v4, v1, verticesIndexMap, currentVertexIndex, vertices, faces);
}
foreach (var vertex in vertices)
{
mesh.AddVertex(vertex);
}
foreach (var face in faces)
{
mesh.AddFace(face);
}
}
示例2: Load
private void Load(TextReader textReader, IMesh mesh)
{
var vertices = new List<IVertex>();
var faces = new List<IFace>();
var verticesIndexMap = new Dictionary<IVertex, int>();
int currentVertexIndex = 0;
var positions = new List<Vector3>();
var normals = new List<Vector3>();
var texCoords = new List<Vector3>();
string line;
while ((line = textReader.ReadLine()) != null)
{
line = line.Trim(_splitCharacters);
line = line.Replace(" ", " ");
var parameters = line.Split(_splitCharacters);
switch (parameters[0])
{
case "p": // Point
break;
case "v": // Vertex
var x = float.Parse(parameters[1], CultureInfo.InvariantCulture);
var y = float.Parse(parameters[2], CultureInfo.InvariantCulture);
var z = float.Parse(parameters[3], CultureInfo.InvariantCulture);
positions.Add(new Vector3(x, y, z));
break;
case "vt": // TexCoord
var u = float.Parse(parameters[1], CultureInfo.InvariantCulture);
var v = float.Parse(parameters[2], CultureInfo.InvariantCulture);
texCoords.Add(new Vector3(u, v, 0));
break;
case "vn": // Normal
var nx = float.Parse(parameters[1], CultureInfo.InvariantCulture);
var ny = float.Parse(parameters[2], CultureInfo.InvariantCulture);
var nz = float.Parse(parameters[3], CultureInfo.InvariantCulture);
normals.Add(new Vector3(nx, ny, nz).Normalized());
break;
case "f":
var faceVertexIndices = new List<int>();
for (int i = 0; i < parameters.Length - 1; i++)
{
//The definition of what is a vertex in an OBJ file only exists appears when the vertex of each face is being defined
//We only want to add distinctive vertices to our list of vertices, so we test here if we already have a vertex with the same
//parameters, in which case we will use the existing vertex, if not we will add the new vertex to our list and increase the vertex
//index counter
var candidateVertex = GetVertex(parameters[i + 1], positions, normals, texCoords);
if (!verticesIndexMap.ContainsKey(candidateVertex))
{
verticesIndexMap.Add(candidateVertex, currentVertexIndex);
vertices.Add(candidateVertex);
currentVertexIndex++;
}
var index = verticesIndexMap[candidateVertex];
faceVertexIndices.Add(index);
}
var face = _faceFactory.CreateFace(faceVertexIndices);
faces.Add(face);
break;
}
}
foreach (var vertex in vertices)
{
mesh.AddVertex(vertex);
}
foreach (var face in faces)
{
mesh.AddFace(face);
}
}