当前位置: 首页>>代码示例>>C#>>正文


C# IMesh.AddVertex方法代码示例

本文整理汇总了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);
   }
 }
开发者ID:dgopena,项目名称:Starter3D.Base,代码行数:25,代码来源:DxfMeshLoader.cs

示例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);
      }
    }
开发者ID:dgopena,项目名称:Starter3D.Base,代码行数:76,代码来源:ObjMeshLoader.cs


注:本文中的IMesh.AddVertex方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。