Exemple #1
0
        /// <summary>
        /// Create the vertices of hose mesh.
        /// </summary>
        /// <param name="isSeal">Is seal at both ends of hose?</param>
        /// <returns>Vertices array.</returns>
        protected Vector3[] CreateVertices(bool isSeal = false)
        {
            var vertices   = new List <Vector3>();
            var keySegment = MaxKey / (segmentCount - 1);

            for (int i = 0; i < segmentCount - 1; i++)
            {
                var key     = keySegment * i;
                var center  = Curve.GetPointAt(key);
                var tangent = (Curve.GetPointAt(key + Delta) - center).normalized;
                vertices.AddRange(MeshUtility.CreateVerticesBasePolygon(polygon, radius, center, Quaternion.LookRotation(tangent)));
            }
            var lastCenter  = Curve.GetPointAt(MaxKey);
            var lastTangent = (lastCenter - Curve.GetPointAt(MaxKey - Delta)).normalized;

            vertices.AddRange(MeshUtility.CreateVerticesBasePolygon(polygon, radius, lastCenter, Quaternion.LookRotation(lastTangent)));

            if (isSeal)
            {
                var polygonVertices = polygon + 1;
                vertices.Add(Curve.GetPointAt(0));
                vertices.AddRange(vertices.GetRange(0, polygonVertices));

                var lastPolygonStart = polygonVertices * (segmentCount - 1);
                vertices.Add(lastCenter);
                vertices.AddRange(vertices.GetRange(lastPolygonStart, polygonVertices));
            }
            return(vertices.ToArray());
        }