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


C# Mesh.Compact方法代码示例

本文整理汇总了C#中Mesh.Compact方法的典型用法代码示例。如果您正苦于以下问题:C# Mesh.Compact方法的具体用法?C# Mesh.Compact怎么用?C# Mesh.Compact使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Mesh的用法示例。


在下文中一共展示了Mesh.Compact方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: MeshSeperate

        public List<Mesh> MeshSeperate(Mesh mesh)
        {
            Rhino.Geometry.Collections.MeshTopologyEdgeList el = mesh.TopologyEdges;
            List<MeshSimplify_Point> PointList = preDivide(mesh);
            List<MeshSimplify_Face> faces = new List<MeshSimplify_Face>();
            for (int i = 0; i < mesh.Faces.Count; i++)
            {
                faces.Add(new MeshSimplify_Face(mesh.Faces[i]));
            }
            for (int i = 0; i < el.Count; i++)
            {
                int a = el.GetTopologyVertices(i).I;
                int b = el.GetTopologyVertices(i).J;
                if (PointList[a].order == 0 || PointList[b].order == 0)
                {
                    int[] index = el.GetConnectedFaces(i);
                    if (index.Length == 2)
                    {
                        faces[index[0]].reffaces.Add(faces[index[1]]);
                        faces[index[1]].reffaces.Add(faces[index[0]]);
                    }
                }
            }
            List<Mesh> outputMesh = new List<Mesh>();
            List<List<MeshSimplify_Face>> outtemp = MeshSimplify_Face.Group(faces);
            for (int i = 0; i < outtemp.Count; i++)
            {
                Mesh meshout = new Mesh();
                meshout.Vertices.AddVertices(mesh.Vertices);
                for (int j = 0; j < outtemp[i].Count; j++)
                {
                    meshout.Faces.AddFace(outtemp[i][j].face);
                }
                meshout.Compact();
                outputMesh.Add(meshout);
            }
            return outputMesh;

            /*
            List<Point3d> outpos = new List<Point3d>();
            List<string> outsign = new  List<string>();
            for(int i = 0;i < faces.Count;i++){
              outpos.Add(faces[i].pos(mesh.Vertices));
              string str = i.ToString() + "/" + faces[i].reffaces.Count.ToString();
              outsign.Add(str);
            }
            B = outpos;C = outsign;
            */
        }
开发者ID:panhao4812,项目名称:MeshClassLibrary,代码行数:49,代码来源:MeshSimplify.cs

示例2: Gauss

        public Gauss(Mesh input_mesh)
        {
            mesh = input_mesh;
            mesh.Compact();
            mesh.UnifyNormals();

            el = mesh.TopologyEdges;
            vs = mesh.TopologyVertices;
            ps = new List<VertexProperties>();

            for (int i = 0; i < vs.Count; i++)
            {
                ps.Add(new VertexProperties
                  (mesh.Normals[vs.MeshVertexIndices(i)[0]]));
                // outputs2.Add(new Vector3d());
            }
        }
开发者ID:panhao4812,项目名称:MeshClassLibrary,代码行数:17,代码来源:Gauss.cs

示例3: LoadHeightMap

 public Mesh LoadHeightMap(double uscale, double vscale, int u, int v, double heightscale, double texturescale, string HeightMapPath)
 {
     if (uscale < 0.001) uscale = 0.001;
     if (vscale < 0.001) vscale = 0.001;
     if (heightscale < 0.001) heightscale = 0.001;
     if (uscale > 10000) uscale = 10000;
     if (vscale > 10000) vscale = 10000;
     if (heightscale > 10000) heightscale = 10000;
     if (u < 4) u = 4;
     if (v < 4) v = 4;
     if (u > 4096) u = 4096;
     if (v > 4096) v = 4096;
     if (texturescale > 4096) texturescale = 4096;
     if (texturescale < 0.001) texturescale = 0.001;
     Mesh mesh = new Mesh();
     try
     {
         Bitmap te2 = new Bitmap(HeightMapPath);
         if (te2.Width < u || te2.Height < v)
         {
             u = te2.Width; v = te2.Height;
         }
         for (int j = 0; j < v; j++)
         {
             for (int i = 0; i < u; i++)
             {
                 mesh.Vertices.Add(new Point3d(i * uscale, te2.GetPixel(i, j).GetBrightness() * heightscale, j * vscale));
                 mesh.TextureCoordinates.Add((double)i / (double)u * texturescale, (double)j / (double)v * texturescale);
                 if (i > 0 && j > 0)
                 {
                     mesh.Faces.AddFace(new MeshFace((j - 1) * u + i - 1, j * u + i - 1, j * u + i, (j - 1) * u + i));
                 }
             }
         }
         mesh.Compact();
         mesh.UnifyNormals();
         return mesh;
     }
     catch{return null;}
 }
开发者ID:panhao4812,项目名称:MeshClassLibrary,代码行数:40,代码来源:HeightMapTools.cs

示例4: SolveInstance

        protected override void SolveInstance(IGH_DataAccess DA)
        {
            List<double> values = new List<double>();

            if (DA.GetDataList(0, values)) {
                bool has_colors = false;
                List<Color> colors = new List<Color>();
                has_colors = DA.GetDataList(1, colors);
                if ((has_colors) && (colors.Count != values.Count)) {
                    this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "If you're going to pass in colors, please pass in a list of colors that is the same length as the list of values you gave me.");
                    return;
                }
                Plane plane = new Plane(new Point3d(0, 0, 0), new Vector3d(0, 0, 1));
                DA.GetData(2, ref plane);

                Interval ival_gr = new Interval();
                //Interval ival_ga = new Interval(0, Math.PI * 2);
                DA.GetData(3, ref ival_gr);
                this.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "You've set your inner or outer radius to 0.  Invalid curves will result.");

                //Interval ival_va = new Interval(0, values.Sum());

                double sum = values.Sum();
                int segments_in_whole_circle = 36;
                Interval ival_angle = new Interval(0, 0);
                List<Grasshopper.Kernel.Types.GH_Curve> regions = new List<Grasshopper.Kernel.Types.GH_Curve>();
                List<Color> colors_out = new List<Color>();
                List<Mesh> meshes = new List<Mesh>();

                for (int n = 0; n < values.Count; n++) {
                    if (values[n] == 0) continue;
                    ival_angle.T1 = ival_angle.T0 + (Math.PI * 2 / sum * values[n]);

                    int cnt = Math.Max(4, (int)Math.Ceiling(segments_in_whole_circle * ival_angle.Length / Math.PI * 2));
                    Polyline pcrv = new Polyline();
                    pcrv.AddRange(FakeArc(plane, ival_gr.T0, ival_angle.T0, ival_angle.T1, cnt));
                    pcrv.AddRange(FakeArc(plane, ival_gr.T1, ival_angle.T1, ival_angle.T0, cnt));
                    pcrv.Add(pcrv[0]);

                    Grasshopper.Kernel.Types.GH_Curve gh_curve = new Grasshopper.Kernel.Types.GH_Curve();
                    Grasshopper.Kernel.GH_Convert.ToGHCurve(pcrv, GH_Conversion.Both, ref gh_curve);
                    regions.Add(gh_curve);
                    colors_out.Add(colors[n]);

                    Rhino.Geometry.Mesh mesh = new Mesh();
                    foreach (Point3d pt in FakeArc(plane, ival_gr.T0, ival_angle.T0, ival_angle.T1, cnt)) {
                        mesh.Vertices.Add(pt);
                        if (has_colors) mesh.VertexColors.Add(colors[n]);
                    }
                    foreach (Point3d pt in FakeArc(plane, ival_gr.T1, ival_angle.T0, ival_angle.T1, cnt)) {
                        mesh.Vertices.Add(pt);
                        if (has_colors) mesh.VertexColors.Add(colors[n]);
                    }
                    for (int i = 0; i < cnt - 1; i++) {
                        mesh.Faces.AddFace(i, i + 1, i + cnt);
                        mesh.Faces.AddFace(i + 1, i + cnt + 1, i + cnt);
                    }
                    mesh.Normals.ComputeNormals();
                    mesh.Compact();
                    meshes.Add(mesh);

                    ival_angle.T0 = ival_angle.T1;
                }

                DA.SetDataList(0, regions);
                DA.SetDataList(1, meshes);
                DA.SetDataList(2, colors_out);
            }
        }
开发者ID:ksteinfe,项目名称:dyear,代码行数:69,代码来源:Components+Spatializing.cs

示例5: Unfold

        public Mesh Unfold(Mesh mesh)
        {
            List<face> Faces = new List<face>();
            List<edge> Edges = new List<edge>();

            mesh.Faces.ConvertQuadsToTriangles();
            mesh.UnifyNormals();
            mesh.Compact();
            Rhino.Geometry.Collections.MeshTopologyEdgeList el = mesh.TopologyEdges;
            Rhino.Geometry.Collections.MeshTopologyVertexList vs = mesh.TopologyVertices;
            mesh.FaceNormals.ComputeFaceNormals();
            //Print(mesh.FaceNormals.Count.ToString());
            //  Print(mesh.Vertices.Count.ToString());
            for (int i = 0; i < mesh.Faces.Count; i++)
            {
                face f1 = new face(
                  new Point3d(mesh.Vertices[mesh.Faces[i].A]),
                  new Point3d(mesh.Vertices[mesh.Faces[i].B]),
                  new Point3d(mesh.Vertices[mesh.Faces[i].C]),
                  mesh.FaceNormals[i]
                  );

                Faces.Add(f1);
            }
            for (int i = 0; i < el.Count; i++)
            {
                int[] faceid = el.GetConnectedFaces(i);

                edge e1 = new edge(vs[el.GetTopologyVertices(i).I], vs[el.GetTopologyVertices(i).J]);
                if (faceid.Length == 1)
                {
                    e1.Faces = new face[1];
                    e1.Faces[0] = Faces[faceid[0]];
                }
                else if (faceid.Length > 1)
                {
                    e1.Faces = new face[2];
                    e1.Faces[0] = Faces[faceid[0]];
                    e1.Faces[1] = Faces[faceid[1]];
                }
                e1.ID = i;
                Edges.Add(e1);
            }
            for (int i = 0; i < mesh.Faces.Count; i++)
            {
                int[] edgeid = el.GetEdgesForFace(i);
                face f1 = Faces[i];
                f1.edges[0] = Edges[edgeid[0]];
                f1.edges[1] = Edges[edgeid[1]];
                f1.edges[2] = Edges[edgeid[2]];
                f1.ID = i;
            }

            /* List<  Mesh> output2 = new List<  Mesh>();
             for (int i = 0; i < Faces.Count; i++)
             {
               output2.Add(Faces[i].DrawFace());
             }
             B = output2;
             */
            face f = Faces[0];
            f.AddTransform(Transform.PlaneToPlane(new Plane(f.Center(), f.Normal), Plane.WorldXY));

            FaceLoop(f);
            //Print(f.Pts[0].X.ToString() + "/" + f.Pts[0].Y.ToString() + "/" + f.Pts[0].Z.ToString());
            Mesh output = new Mesh();
            for (int i = 0; i < Faces.Count; i++)
            {
                output.Append(Faces[i].DrawFace());
            }
            return output;
        }
开发者ID:panhao4812,项目名称:MeshClassLibrary,代码行数:72,代码来源:MeshUnfold.cs

示例6: MeshOffset

 public Mesh MeshOffset(Mesh meshOral, Vector3d v)
 {
     Mesh mesh = new Mesh();
     meshOral.Compact();
     for (int i = 0; i < meshOral.Vertices.Count; i++)
     {
         mesh.Vertices.Add(new Point3d(meshOral.Vertices[i]) + v);
     }
     for (int i = 0; i < meshOral.Faces.Count; i++)
     {
         mesh.Faces.AddFace(meshOral.Faces[i]);
     }
     mesh.UnifyNormals();
     return mesh;
 }
开发者ID:panhao4812,项目名称:MeshClassLibrary,代码行数:15,代码来源:MeshCreation.cs

示例7: MeshFaceGradient

 public Mesh MeshFaceGradient(Point3d p1, Point3d p2, Point3d p3, Vector3d v)
 {
     double[] co = ComputeWeight(p1, p2, p3, v);
     // Print(co[0].ToString() + "/" + co[1].ToString() + "/" + co[2].ToString());
     Mesh mesh = new Mesh();
     mesh.Vertices.Add(p1); mesh.Vertices.Add(p2); mesh.Vertices.Add(p3);
     for (int i = 0; i < co.Length; i++)
     {
         double T = co[i];
         double R; double G;
         if (T >= 0.5)
         {
             R = 255.0;
             G = 510.0 * (1 - T);
         }
         else
         {
             R = 510.0 * (T);
             G = 255.0;
         }
         //R = 255 * T;G = 255 * (1 - T);
         if (R > 255) R = 255;
         if (G > 255) G = 255;
         if (G < 0) G = 0;
         if (R < 0) R = 0;
         mesh.VertexColors.Add(Color.FromArgb((int)R, (int)G, 0));
     }
     mesh.Faces.AddFace(new MeshFace(0, 1, 2));
     mesh.Compact();
     mesh.UnifyNormals();
     return mesh;
 }
开发者ID:panhao4812,项目名称:MeshClassLibrary,代码行数:32,代码来源:MeshCreation.cs

示例8: MeshExtruteEdge

 public Mesh MeshExtruteEdge(Mesh meshOral, Vector3d v)
 {
     Mesh mesh = new Mesh();
     meshOral.UnifyNormals();
     meshOral.Compact();
     Rhino.Geometry.Collections.MeshTopologyEdgeList el = meshOral.TopologyEdges;
     Rhino.Geometry.Collections.MeshTopologyVertexList vs = meshOral.TopologyVertices;
     for (int i = 0; i < el.Count; i++)
     {
         if (el.GetConnectedFaces(i).Length == 1)
         {
             int p1 = el.GetTopologyVertices(i).I;
             int p2 = el.GetTopologyVertices(i).J;
             int VS = mesh.Vertices.Count;
             mesh.Vertices.Add(vs[p1]);
             mesh.Vertices.Add(vs[p2]);
             mesh.Vertices.Add(new Point3d(vs[p2]) + v);
             mesh.Vertices.Add(new Point3d(vs[p1]) + v);
             mesh.Faces.AddFace(VS, VS + 1, VS + 2, VS + 3);
         }
     }
     mesh.UnifyNormals();
     return mesh;
 }
开发者ID:panhao4812,项目名称:MeshClassLibrary,代码行数:24,代码来源:MeshCreation.cs

示例9: subdiv


//.........这里部分代码省略.........
          //first check face type
          Vector3d ab = new Vector3d (oldmesh.Vertices[oldmesh.Faces[i].B] - oldmesh.Vertices[oldmesh.Faces[i].A]);
          Vector3d ac = new Vector3d (oldmesh.Vertices[oldmesh.Faces[i].C] - oldmesh.Vertices[oldmesh.Faces[i].A]);
          Vector3d cb = new Vector3d (oldmesh.Vertices[oldmesh.Faces[i].B] - oldmesh.Vertices[oldmesh.Faces[i].C]);
          Point3d pt0 = new Point3d();
          Point3d pt1 = new Point3d();
          length = ab.Length * 1 / phi;
          ab.Unitize();
          ab = ab * length;
          length = ac.Length * 1 / phi;
          ac.Unitize();
          ac = ac * length;
          length = cb.Length * 1 / phi;
          cb.Unitize();
          cb = cb * length;
          if(Math.Round(ab.Length / ac.Length, 3) == 1.618)
          {
        //vertices
        //      c
        //   /     \
        //a-----------b

        if(oldmesh.Faces[i].A < oldmesh.Faces[i].B)//its fatC
        {
          newmesh.Vertices.Add(oldmesh.Vertices[oldmesh.Faces[i].A]);vcount++;//1
          ab.Reverse();
          pt0 = Point3d.Add(oldmesh.Vertices[oldmesh.Faces[i].B], ab);
          newmesh.Vertices.Add(pt0);vcount++;//2
          newmesh.Vertices.Add(oldmesh.Vertices[oldmesh.Faces[i].B]);vcount++;//3
          newmesh.Vertices.Add(oldmesh.Vertices[oldmesh.Faces[i].C]);vcount++;//4
          cb.Reverse();
          pt1 = Point3d.Add(oldmesh.Vertices[oldmesh.Faces[i].B], cb);
          newmesh.Vertices.Add(pt1);vcount++;//5

          newmesh.Faces.AddFace(vcount - 3, vcount - 4, vcount - 1);//2,1,4
          newmesh.Faces.AddFace(vcount - 1, vcount - 2, vcount - 4);//3,4,1
          newmesh.Faces.AddFace(vcount - 2, vcount - 5, vcount - 4);//3,0,1
        }
        else//its fatCC counter clockwise
        {
          newmesh.Vertices.Add(oldmesh.Vertices[oldmesh.Faces[i].A]);vcount++;//1
          ab.Reverse();
          pt0 = Point3d.Add(oldmesh.Vertices[oldmesh.Faces[i].B], ab);
          newmesh.Vertices.Add(pt0);vcount++;//2
          newmesh.Vertices.Add(oldmesh.Vertices[oldmesh.Faces[i].B]);vcount++;//3
          newmesh.Vertices.Add(oldmesh.Vertices[oldmesh.Faces[i].C]);vcount++;//4
          cb.Reverse();
          pt1 = Point3d.Add(oldmesh.Vertices[oldmesh.Faces[i].B], cb);
          newmesh.Vertices.Add(pt1);vcount++;//5

          newmesh.Faces.AddFace(vcount - 3, vcount - 4, vcount - 1);//2,1,4
          newmesh.Faces.AddFace(vcount - 1, vcount - 2, vcount - 4);//4,3,1
          newmesh.Faces.AddFace(vcount - 2, vcount - 5, vcount - 4);//3,0,1
        }
          }
          else
          {
        //other wise one new point on thin type
        //vertices
        //  c
        // / \
        //a---b
        if(oldmesh.Faces[i].A < oldmesh.Faces[i].B)//its thinC
        {
          ac.Reverse();
          pt1 = Point3d.Add(oldmesh.Vertices[oldmesh.Faces[i].C], ac);
          newmesh.Vertices.Add(oldmesh.Vertices[oldmesh.Faces[i].A]);vcount++;//1
          newmesh.Vertices.Add(oldmesh.Vertices[oldmesh.Faces[i].B]);vcount++;//2
          newmesh.Vertices.Add(oldmesh.Vertices[oldmesh.Faces[i].C]);vcount++;//3
          newmesh.Vertices.Add(pt1);vcount++;//4
          newmesh.Faces.AddFace(vcount - 1, vcount - 4, vcount - 3);//3, 0, 1
          newmesh.Faces.AddFace(vcount - 2, vcount - 3, vcount - 1);//2, 1, 3
        }
        else
        {
          ac.Reverse();
          pt1 = Point3d.Add(oldmesh.Vertices[oldmesh.Faces[i].C], ac);
          newmesh.Vertices.Add(oldmesh.Vertices[oldmesh.Faces[i].A]);vcount++;//1
          newmesh.Vertices.Add(oldmesh.Vertices[oldmesh.Faces[i].B]);vcount++;//2
          newmesh.Vertices.Add(oldmesh.Vertices[oldmesh.Faces[i].C]);vcount++;//3
          newmesh.Vertices.Add(pt1);vcount++;//4
          newmesh.Faces.AddFace(vcount - 1, vcount - 4, vcount - 3);//3, 0, 1
          newmesh.Faces.AddFace(vcount - 2, vcount - 3, vcount - 1);//2, 1, 3
        }
          }

          // Tree.Add(newmesh);

        }
        if(currentdepth < maxdepth)
        {
          return subdiv(newmesh, maxdepth, currentdepth + 1);
        }
        else
        {
          newmesh.Normals.ComputeNormals();
          newmesh.Compact();
          return newmesh;
        }
    }
开发者ID:chirs,项目名称:parametric_systems,代码行数:101,代码来源:penrose.cs

示例10: MeshPlannar2

        public Mesh MeshPlannar2(Polyline pl)
        {
            if (pl[0].DistanceTo(pl[pl.Count - 1]) < Rhino.RhinoDoc.ActiveDoc.ModelAbsoluteTolerance)
            {
                pl.RemoveAt(pl.Count - 1);
            }
            Point3d cen = new Point3d();
            Mesh mesh = new Mesh();
            if (pl.Count < 3) return mesh;
            for (int i = 0; i < pl.Count; i++)
            {
                cen += pl[i];
            }
            cen /= pl.Count;
            mesh.Vertices.Add(cen);
            int before = -1, after = -1;
            for (int i = 0; i < pl.Count; i++)
            {
                if (i == pl.Count - 1) after = 0; else after = i + 1;
                mesh.Vertices.Add(pl[i]); mesh.Vertices.Add((pl[i] + pl[after]) / 2);
            }

            for (int i = 1; i < mesh.Vertices.Count - 1; i += 2)
            {
                if (i == 1) before = mesh.Vertices.Count - 1; else before = i - 1;
                if (i == mesh.Vertices.Count - 1) after = 1; else after = i + 1;
                mesh.Faces.AddFace(0, before, i, after);
            }
            mesh.Compact();
            return mesh;
        }
开发者ID:panhao4812,项目名称:MeshClassLibrary,代码行数:31,代码来源:MeshCreation.cs

示例11: MeshClean

        public void MeshClean(ref Mesh mesh, double tolerance)
        {
            try
            {
                List<int> mapping = new List<int>();
                List<Point3d> ps = new List<Point3d>();
                List<double> MapCount = new List<double>();
                ps.Add(mesh.Vertices[0]); mapping.Add(0); MapCount.Add(1);
                for (int j = 1; j < mesh.Vertices.Count; j++)
                {
                    double min = double.MaxValue;
                    int sign = 0;

                    for (int i = 0; i < ps.Count; i++)
                    {
                        double tempt = ps[i].DistanceTo((Point3d)mesh.Vertices[j]);
                        if (tempt < min)
                        {
                            min = tempt; sign = i;
                        }
                    }
                    if (min < tolerance)
                    {
                        mapping.Add(sign);
                        MapCount[sign]++;
                        ps[sign] *= (MapCount[sign] - 1) / MapCount[sign];
                        Point3d tempp = (Point3d)(mesh.Vertices[j]); tempp *= (1 / MapCount[sign]);
                        ps[sign] += tempp;
                    }
                    else { mapping.Add(ps.Count); ps.Add(mesh.Vertices[j]); MapCount.Add(1); }
                }
                Mesh mesh2 = new Mesh();
                for (int i = 0; i < ps.Count; i++)
                {
                    mesh2.Vertices.Add(ps[i]);
                }
                for (int i = 0; i < mesh.Faces.Count; i++)
                {
                    MeshFace f_temp = MeshFace.Unset;
                    bool FaceSign = false;
                    if (mesh.Faces[i].IsQuad)
                    {
                        int p1 = mapping[mesh.Faces[i].A];
                        int p2 = mapping[mesh.Faces[i].B];
                        int p3 = mapping[mesh.Faces[i].C];
                        int p4 = mapping[mesh.Faces[i].D];
                        if (noRepeat(p1, p2, p3, p4))
                        {
                            f_temp = new MeshFace(p1, p2, p3, p4); FaceSign = true;
                        }
                    }
                    else if (mesh.Faces[i].IsTriangle)
                    {
                        int p1 = mapping[mesh.Faces[i].A];
                        int p2 = mapping[mesh.Faces[i].B];
                        int p3 = mapping[mesh.Faces[i].C];
                        if (noRepeat(p1, p2, p3))
                        {
                            f_temp = new MeshFace(p1, p2, p3); FaceSign = true;
                        }
                    }
                    if (mesh2.Faces.Count > 0)
                    {
                        for (int j = 0; j < mesh2.Faces.Count; j++)
                        {
                            if (!noRepeat(mesh2.Faces[j], f_temp)) FaceSign = false;
                        }
                    }
                    if (FaceSign) mesh2.Faces.AddFace(f_temp);
                }
                mesh2.Compact();
                mesh2.UnifyNormals();
                mesh = mesh2;
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.ToString());
            }
        }
开发者ID:panhao4812,项目名称:MeshClassLibrary,代码行数:79,代码来源:MeshCreation.cs

示例12: MeshBay

        public List<Mesh> MeshBay(Mesh mesh, int step)
        {
            List<Rface> faces = new List<Rface>();
            for (int i = 0; i < mesh.Faces.Count; i++)
            {
                faces.Add(new Rface());
            }

            Rhino.Geometry.Collections.MeshTopologyEdgeList el = mesh.TopologyEdges;
            for (int i = 0; i < el.Count; i++)
            {
                int[] index = el.GetConnectedFaces(i);
                if (index.Length == 1)
                {
                    faces[index[0]].age = 1;
                }
                if (index.Length == 2)
                {
                    faces[index[1]]._CollectedFaceIndex.Add(index[0]);
                    faces[index[0]]._CollectedFaceIndex.Add(index[1]);
                }
            }
            for (int k = 1; k < step + 1; k++)
            {
                for (int i = 0; i < faces.Count; i++)
                {
                    if (faces[i].age == k)
                    {
                        for (int j = 0; j < faces[i]._CollectedFaceIndex.Count; j++)
                        {
                            int index2 = faces[i]._CollectedFaceIndex[j];
                            if (faces[index2].age == 0) faces[index2].age = k + 1;
                        }
                    }
                }
            }

            Mesh mesh1 = new Mesh(); Mesh mesh2 = new Mesh();
            mesh1.Vertices.AddVertices(mesh.Vertices);
            mesh2.Vertices.AddVertices(mesh.Vertices);
            for (int i = 0; i < faces.Count; i++)
            {
                if (faces[i].age != 0)
                {
                    mesh2.Faces.AddFace(mesh.Faces[i]);

                }
                else
                {
                    mesh1.Faces.AddFace(mesh.Faces[i]);
                }
            }

            mesh1.Compact(); mesh1.UnifyNormals();
            mesh2.Compact(); mesh2.UnifyNormals();
            List<Mesh> output = new List<Mesh>();
            output.Add(mesh1);
            output.Add(mesh2);
            return output;
        }
开发者ID:panhao4812,项目名称:MeshClassLibrary,代码行数:60,代码来源:MeshRoad.cs

示例13: MeshUVRoad

 public Mesh MeshUVRoad(Polyline pl1, Polyline pl2, double texturescale)
 {
     Polyline pl3 = new Polyline();
     List<double> domain3 = new List<double>();
     double t = 0;
     for (int i = 0; i < pl1.Count; i++)
     {
         Point3d p3 = (pl1[i] + pl2[i]) / 2;
         if (i > 0) t += p3.DistanceTo(pl3[pl3.Count - 1]);
         domain3.Add(t);
         pl3.Add(p3);
     }
     Mesh mesh = new Mesh();
     for (int i = 0; i < pl3.Count; i++)
     {
         mesh.Vertices.Add(pl1[i]);
         mesh.Vertices.Add(pl2[i]);
         double t1 = domain3[i] / pl3.Length;
         // Print(t1.ToString());
         mesh.TextureCoordinates.Add(t1 * texturescale, 0);
         mesh.TextureCoordinates.Add(t1 * texturescale, 1);
         if (i > 0)
         {
             mesh.Faces.AddFace((i - 1) * 2, i * 2, i * 2 + 1, (i - 1) * 2 + 1);
         }
     }
     mesh.Compact();
     mesh.UnifyNormals();
     return mesh;
 }
开发者ID:panhao4812,项目名称:MeshClassLibrary,代码行数:30,代码来源:MeshRoad.cs

示例14: ObjToMesh

        public Mesh ObjToMesh(string Objpath)
        {
            Mesh mesh = new Mesh();
            StreamReader srd;
            try
            {
                srd = File.OpenText(Objpath);
            }
            catch
            {
                return null;
            }
            try
            {
                while (srd.Peek() != -1)
                {
                    string str = srd.ReadLine();
                    string[] chara = str.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);
                    if (chara.Length > 2)
                    {
                        if (chara[0] == "v")
                        {
                            mesh.Vertices.Add(
                              Convert.ToSingle(chara[1]),
                              -Convert.ToSingle(chara[3]),
                              Convert.ToSingle(chara[2]));

                        }
                        else if (chara[0] == "vt")
                        {
                            mesh.TextureCoordinates.Add(
                              Convert.ToSingle(chara[1]),
                              Convert.ToSingle(chara[2]));
                        }
                        else if (chara[0] == "vn")
                        {
                            mesh.Normals.Add(
                              Convert.ToSingle(chara[1]),
                              -Convert.ToSingle(chara[3]),
                              Convert.ToSingle(chara[2]));

                        }
                        else if (chara[0] == "f")
                        {
                            if (chara.Length == 4)
                            {
                                int a = Convert.ToInt32(chara[1].Split('/')[0]) - 1;
                                int c = Convert.ToInt32(chara[2].Split('/')[0]) - 1;
                                int b = Convert.ToInt32(chara[3].Split('/')[0]) - 1;
                                mesh.Faces.AddFace(a, b, c);
                            }
                            if (chara.Length == 5)
                            {
                                int a = Convert.ToInt32(chara[1].Split('/')[0]) - 1;
                                int b = Convert.ToInt32(chara[2].Split('/')[0]) - 1;
                                int c = Convert.ToInt32(chara[3].Split('/')[0]) - 1;
                                int d = Convert.ToInt32(chara[4].Split('/')[0]) - 1;
                                mesh.Faces.AddFace(a, b, c, d);
                            }
                        }
                    }
                }
                srd.Close();
                mesh.Compact();
                mesh.UnifyNormals();
            }
            catch
            {
                return null;
            }
            return mesh;
        }
开发者ID:panhao4812,项目名称:MeshClassLibrary,代码行数:72,代码来源:ToTXT.cs

示例15: TriangleMeshFromPoints

        public Mesh TriangleMeshFromPoints(List<Point3d> pl, int t)
        {
            //triangle MeshTopo Points From topo of the pyramid to the base
            Mesh mesh = new Mesh();
            if (t < 2) return mesh;
            int n = ((1 + t) * t) / 2;
            if (n > pl.Count) return mesh;

            mesh.Vertices.AddVertices(pl);
            List<int> layer1; List<int> layer2 = new List<int>();
            layer2.Add(0);
            for (int i = 0; i < t - 1; i++)
            {
                layer1 = new List<int>(layer2);
                for (int j = 0; j < layer2.Count; j++)
                {
                    layer2[j] += i + 1;
                }
                layer2.Add(layer2[layer2.Count - 1] + 1);

                if (layer1.Count > 1)
                {
                    for (int j = 0; j < layer1.Count - 1; j++)
                    {
                        mesh.Faces.AddFace(layer1[j], layer1[j + 1], layer2[j + 1]);
                    }
                }
                for (int j = 0; j < layer1.Count; j++)
                {
                    mesh.Faces.AddFace(layer2[j], layer1[j], layer2[j + 1]);
                }
            }
            mesh.Compact();
            mesh.Normals.ComputeNormals();
            return mesh;
        }
开发者ID:panhao4812,项目名称:MeshClassLibrary,代码行数:36,代码来源:MeshCreation.cs


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