HelixToolkit.Wpf.MeshBuilder.AddTriangleStrip C# (CSharp) Method

AddTriangleStrip() public method

Adds a triangle strip to the mesh.
See http://en.wikipedia.org/wiki/Triangle_strip.
public AddTriangleStrip ( IList stripPositions, IList stripNormals = null, IList stripTextureCoordinates = null ) : void
stripPositions IList /// The points of the triangle strip. ///
stripNormals IList /// The normal vectors of the triangle strip. ///
stripTextureCoordinates IList /// The texture coordinates of the triangle strip. ///
return void
        public void AddTriangleStrip(
            IList<Point3D> stripPositions,
            IList<Vector3D> stripNormals = null,
            IList<Point> stripTextureCoordinates = null)
        {
            if (stripPositions == null)
            {
                throw new ArgumentNullException("stripPositions");
            }

            if (this.normals != null && stripNormals == null)
            {
                throw new ArgumentNullException("stripNormals");
            }

            if (this.textureCoordinates != null && stripTextureCoordinates == null)
            {
                throw new ArgumentNullException("stripTextureCoordinates");
            }

            if (stripNormals != null && stripNormals.Count != stripPositions.Count)
            {
                throw new InvalidOperationException(WrongNumberOfNormals);
            }

            if (stripTextureCoordinates != null && stripTextureCoordinates.Count != stripPositions.Count)
            {
                throw new InvalidOperationException(WrongNumberOfTextureCoordinates);
            }

            int index0 = this.positions.Count;
            for (int i = 0; i < stripPositions.Count; i++)
            {
                this.positions.Add(stripPositions[i]);
                if (this.normals != null && stripNormals != null)
                {
                    this.normals.Add(stripNormals[i]);
                }

                if (this.textureCoordinates != null && stripTextureCoordinates != null)
                {
                    this.textureCoordinates.Add(stripTextureCoordinates[i]);
                }
            }

            int indexEnd = this.positions.Count;
            for (int i = index0; i + 2 < indexEnd; i += 2)
            {
                this.triangleIndices.Add(i);
                this.triangleIndices.Add(i + 1);
                this.triangleIndices.Add(i + 2);

                if (i + 3 < indexEnd)
                {
                    this.triangleIndices.Add(i + 1);
                    this.triangleIndices.Add(i + 3);
                    this.triangleIndices.Add(i + 2);
                }
            }
        }

Usage Example

示例#1
0
        /// <summary>
        /// Do the tessellation and return the <see cref="MeshGeometry3D"/>.
        /// </summary>
        /// <returns>A triangular mesh geometry.</returns>
        protected override MeshGeometry3D Tessellate()
        {
            var pts = new List<Point3D>();
            var right = Vector3D.CrossProduct(this.UpVector, this.Normal);
            for (int i = 0; i < this.ThetaDiv; i++)
            {
                double angle = this.StartAngle + ((this.EndAngle - this.StartAngle) * i / (this.ThetaDiv - 1));
                double angleRad = angle / 180 * Math.PI;
                var dir = (right * Math.Cos(angleRad)) + (this.UpVector * Math.Sin(angleRad));
                pts.Add(this.Center + (dir * this.InnerRadius));
                pts.Add(this.Center + (dir * this.OuterRadius));
            }

            var b = new MeshBuilder(false, false);
            b.AddTriangleStrip(pts);
            return b.ToMesh();
        }