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


C# Mesh.get_Triangle方法代码示例

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


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

示例1: Stream

        private void Stream(ArrayList data, Mesh mesh)
        {
            data.Add(new Snoop.Data.ClassSeparator(typeof(Mesh)));

            // TBD: need a MeshTriangleIterator like the other classes, and then we could use Snoop.Data.Enumerable
            data.Add(new Snoop.Data.CategorySeparator("Triangles"));
            data.Add(new Snoop.Data.Int("Number of triangles", mesh.NumTriangles));
            for (int i = 0; i < mesh.NumTriangles; i++)
            {
                data.Add(new Snoop.Data.Object(string.Format("Triangle [{0:d}]", i), mesh.get_Triangle(i)));
            }

            data.Add(new Snoop.Data.CategorySeparator("Vertices"));
            System.Collections.Generic.IList<XYZ> pts = mesh.Vertices;
            int j = 0;
            foreach (XYZ pt in pts)
            {
                data.Add(new Snoop.Data.Xyz(string.Format("PT [{0:d}]", j++), pt));
            }
        }
开发者ID:jeremytammik,项目名称:RevitLookup,代码行数:20,代码来源:CollectorExtGeom.cs

示例2: Stream

        public virtual void Stream(Mesh mesh)
        {
            for (int i=0; i<mesh.NumTriangles; i++) {
                MeshTriangle mt = mesh.get_Triangle(i);

                Stream(mt.get_Vertex(0), mt.get_Vertex(1));
                Stream(mt.get_Vertex(1), mt.get_Vertex(2));
                Stream(mt.get_Vertex(2), mt.get_Vertex(0));
            }
        }
开发者ID:halad,项目名称:RevitLookup,代码行数:10,代码来源:GraphicsStream.cs

示例3: CanCreateClosedShell

        /// <summary>
        /// Checks if the faces can create a closed shell.
        /// </summary>
        /// <remarks>
        /// Limitation: This could let through an edge shared an even number of times greater than 2.
        /// </remarks>
        /// <param name="faceSet">The collection of face handles.</param>
        /// <returns>True if can, false if can't.</returns>
        public static bool CanCreateClosedShell(Mesh mesh)
        {
            int numFaces = mesh.NumTriangles;

            // Do simple checks first.
            if (numFaces < 4)
                return false;

            // Try to match up edges.
            IDictionary<uint, IList<uint>> unmatchedEdges = new Dictionary<uint, IList<uint>>();
            int unmatchedEdgeSz = 0;

            for (int ii = 0; ii < numFaces; ii++)
            {
                MeshTriangle meshTriangle = mesh.get_Triangle(ii);
                for (int jj = 0; jj < 3; jj++)
                {
                    uint pt1 = meshTriangle.get_Index(jj);
                    uint pt2 = meshTriangle.get_Index((jj + 1) % 3);

                    IList<uint> unmatchedEdgesPt2 = null;
                    if (unmatchedEdges.TryGetValue(pt2, out unmatchedEdgesPt2) && unmatchedEdgesPt2.Contains(pt1))
                    {
                        unmatchedEdgesPt2.Remove(pt1);
                        unmatchedEdgeSz--;
                    }
                    else
                    {
                        IList<uint> unmatchedEdgesPt1 = null;
                        if (unmatchedEdges.TryGetValue(pt1, out unmatchedEdgesPt1) && unmatchedEdgesPt1.Contains(pt2))
                        {
                            // An edge with the same orientation exists twice; can't create solid.
                            return false;
                        }

                        if (unmatchedEdgesPt1 == null)
                        {
                            unmatchedEdgesPt1 = new List<uint>();
                            unmatchedEdges[pt1] = unmatchedEdgesPt1;
                        }

                        unmatchedEdgesPt1.Add(pt2);
                        unmatchedEdgeSz++;
                    }
                }
            }

            return (unmatchedEdgeSz == 0);
        }
开发者ID:whztt07,项目名称:RevitCustomIFCexporter,代码行数:57,代码来源:BodyExporter.cs

示例4: RevitMeshToHelixMesh

        /// <summary>
        /// Convert a Revit mesh to a Helix mesh for visualization.
        /// In order to merge mesh vertices, this method uses a dictionary with a string key formed as x:y:z of the point.
        /// This assumes that where vertices are the "same" in the Revit mesh, they will have the same coordinates. This
        /// is NOT a safe strategy to use in other mesh-processing contexts where vertices might have small discrepancies.
        /// </summary>
        /// <param name="rmesh"></param>
        /// <param name="octree"></param>
        /// <param name="node"></param>
        /// <returns></returns>
        private static MeshGeometry3D RevitMeshToHelixMesh(Mesh rmesh, Octree.OctreeSearch.Octree octree, NodeModel node)
        {
            var builder = new MeshBuilder();
            var points = new Point3DCollection();
            var tex = new PointCollection();
            var norms = new Vector3DCollection();
            var tris = new List<int>();

            //A dictionary which will contain a point, a normal, and an index
            //keyed on the location of the point as a hash
            var pointDict = new Dictionary<string, PointData>();
            for (int i = 0; i < rmesh.NumTriangles; ++i)
            {
                var tri = rmesh.get_Triangle(i);
                //calculate the face normal by
                //getting the cross product of two edges
                var a = tri.get_Vertex(0);
                var b = tri.get_Vertex(1);
                var c = tri.get_Vertex(2);
                var e1 = b - a;
                var e2 = c - a;
                var normXYZ = e1.CrossProduct(e2).Normalize();
                var normal = new Vector3D(normXYZ.X, normXYZ.Y, normXYZ.Z);

                for (int j = 0; j < 3; j++)
                {
                    var pt = RevitPointToWindowsPoint(tri.get_Vertex(j));
                    var key = pt.X + ":" + pt.Y + ":" + pt.Z;
                    if (!pointDict.ContainsKey(key))
                    {
                        //if the dictionary doesn't contain the key
                        var pd = new PointData(pt.X,pt.Y,pt.Z);
                        pd.Normals.Add(normal);
                        pd.Index = pointDict.Count;
                        pointDict.Add(key, pd);
                        tris.Add(pd.Index);
                    }
                    else
                    {
                        //add an index to our tris array
                        //add a normal to our internal collection
                        //for post processing
                        var data = pointDict[key];
                        tris.Add(data.Index);
                        data.Normals.Add(normal);
                    }
                }
            }

            var lst = pointDict.ToList();
            lst.ForEach(x => points.Add(x.Value.Position));
            lst.ForEach(x=>octree.AddNode(x.Value.Position.X, x.Value.Position.Y, x.Value.Position.Z, node.GUID.ToString()));
            lst.ForEach(x=>tex.Add(x.Value.Tex));

            //merge the normals
            foreach (var pd in lst)
            {
                var avg = new Vector3D();
                var nList = pd.Value.Normals;
                foreach (var n in nList)
                {
                    avg.X += n.X;
                    avg.Y += n.Y;
                    avg.Z += n.Z;
                }
                avg.X = avg.X / nList.Count;
                avg.Y = avg.Y / nList.Count;
                avg.Z = avg.Z / nList.Count;
                norms.Add(avg);
            }

            builder.Append(points, tris, norms, tex);
            Debug.WriteLine(string.Format("Mesh had {0} faces coming in and {1} faces going out.", rmesh.NumTriangles, builder.TriangleIndices.Count / 3));

            return builder.ToMesh(true);
        }
开发者ID:riteshchandawar,项目名称:Dynamo,代码行数:86,代码来源:VisualizationManagerRevit.cs


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