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


C# MeshBuilder.AddTriangleFan方法代码示例

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


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

示例1: Tessellate

        /// <summary>
        /// Do the tessellation and return the <see cref="MeshGeometry3D"/> .
        /// </summary>
        /// <returns>
        /// A triangular mesh geometry.
        /// </returns>
        protected override MeshGeometry3D Tessellate()
        {
            if (this.Path == null || this.Path.Count < 2)
            {
                return null;
            }

            // See also "The GLE Tubing and Extrusion Library":
            // http://linas.org/gle/
            // http://sharpmap.codeplex.com/Thread/View.aspx?ThreadId=18864
            var builder = new MeshBuilder(false, this.TextureCoordinates != null);

            var sectionXAxis = this.SectionXAxis;
            if (sectionXAxis.Length < 1e-6)
            {
                sectionXAxis = new Vector3D(1, 0, 0);
            }

            var forward = this.Path[1] - this.Path[0];
            var up = Vector3D.CrossProduct(forward, sectionXAxis);
            if (up.LengthSquared < 1e-6)
            {
                sectionXAxis = forward.FindAnyPerpendicular();
            }

            builder.AddTube(
                this.Path,
                this.Angles,
                this.TextureCoordinates,
                this.Diameters,
                this.Section,
                sectionXAxis,
                this.IsPathClosed,
                this.IsSectionClosed);

            // Add Caps if wanted and needed
            if (this.AddCaps && !this.IsPathClosed && builder.Positions.Count >= Section.Count)
            {
                var sCount = Section.Count;
                var normals = new Vector3D[sCount];
                var vertices = new Point3D[sCount];
                var pCount = Path.Count;

                //Add back cap
                var circleBack = builder.Positions.Skip(builder.Positions.Count - sCount).Take(sCount).ToArray();
                var normal = Path[pCount - 1] - Path[pCount - 2];
                normal.Normalize();
                for (int i = 0; i < normals.Length; ++i)
                {
                    normals[i] = normal;
                }
                builder.AddTriangleFan(circleBack, normals);
                //Add front cap
                var circleFront = builder.Positions.Take(sCount).ToArray();
                normal = Path[0] - Path[1];
                normal.Normalize();

                for (int i = 0; i < normals.Length; ++i)
                {
                    normals[i] = normal;
                }
                builder.AddTriangleFan(circleFront, normals);
            }

            return builder.ToMesh();
        }
开发者ID:helix-toolkit,项目名称:helix-toolkit,代码行数:72,代码来源:TubeVisual3D.cs

示例2: AddCircleInZCross

        private static void AddCircleInZCross(MeshBuilder mb, Point3D centre, double radius, int div)
        {
            var points = MeshBuilder.GetCircle(div);

            var vectors = new Point3DCollection();
            var normals = new Vector3DCollection();
            var textures = new PointCollection();

            vectors.Add(new Point3D(centre.X, centre.Y, 0));
            normals.Add(new Vector3D(0, 0, 1));
            textures.Add(new Point(0.5, 0.5));

            for (int i = 0; i < points.Count - 1; i++)
            {
                vectors.Add(new Point3D(points[i].X * radius + centre.X, points[i].Y * radius + centre.Y, centre.Z));
                normals.Add(new Vector3D(0, 0, -1));
                textures.Add(new Point(points[i].X * 0.5 + 0.5, points[i].Y * 0.5 + 0.5));

                vectors.Add(new Point3D(points[i + 1].X * radius + centre.X, points[i + 1].Y * radius + centre.Y, centre.Z));
                normals.Add(new Vector3D(0, 0, 01));
                textures.Add(new Point(points[i + 1].X * 0.5 + 0.5, points[i + 1].Y * 0.5 + 0.5));
            }

            mb.AddTriangleFan(vectors, normals, textures);
        }
开发者ID:woodxiang,项目名称:WpfApplication2,代码行数:25,代码来源:TestModelVisual3D.cs

示例3: ToModel3D

        public Model3D ToModel3D()
        {
            var m = new Model3DGroup();

            TriangleIndexToPanelIndex = new List<int>();

            // Add the triangles
            var tm = new MeshBuilder(false, false);
            int panelIndex = 0;
            foreach (var p in Panels)
            {
                p.TriangleIndex = tm.Positions.Count;
                tm.AddTriangleFan(p.Points);
                for (int i = 0; i < p.Points.Length - 2; i++) TriangleIndexToPanelIndex.Add(panelIndex);
                panelIndex++;
            }
            var panelsGeometry = tm.ToMesh();
            m.Children.Add(new GeometryModel3D(panelsGeometry, Materials.Red) { BackMaterial = Materials.Blue });

            // Add the nodes
            var gm = new MeshBuilder();
            foreach (var p in panelsGeometry.Positions)
            {
                gm.AddSphere(p, 0.05);
            }
            m.Children.Add(new GeometryModel3D(gm.ToMesh(), Materials.Gold));

            // Add the edges
            var em = new MeshBuilder();
            foreach (var p in Panels)
            {
                for (int i = 0; i < p.Points.Length; i += 1)
                {
                    em.AddCylinder(p.Points[i], p.Points[(i + 1) % p.Points.Length], 0.05, 10);
                }
            }
            m.Children.Add(new GeometryModel3D(em.ToMesh(), Materials.Gray));

            return m;
        }
开发者ID:dermeister0,项目名称:helix-toolkit,代码行数:40,代码来源:PanelModelBuilder.cs

示例4: CreateMeshGeometry3D

        /// <summary>
        /// Creates a <see cref="MeshGeometry3D" /> object from the loaded file. Polygons are triangulated using triangle fans.
        /// </summary>
        /// <returns>
        /// A <see cref="MeshGeometry3D" />.
        /// </returns>
        public MeshGeometry3D CreateMeshGeometry3D()
        {
            var mb = new MeshBuilder(false, false);
            foreach (var p in this.Vertices)
            {
                mb.Positions.Add(p);
            }

            foreach (var face in this.Faces)
            {
                mb.AddTriangleFan(face);
            }

            return mb.ToMesh();
        }
开发者ID:ondrej11,项目名称:o106,代码行数:21,代码来源:OffReader.cs

示例5: 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();
//.........这里部分代码省略.........
开发者ID:sivarajankumar,项目名称:dentalsmile,代码行数:101,代码来源:Mesh3D.cs

示例6: 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);
                }
            }
        }
开发者ID:BEEden,项目名称:Diplomarbeit,代码行数:90,代码来源:HalfEdgeMeshVisual3D.cs


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