Ejemplo n.º 1
0
        public static void AddRect(
            ref VertexHelper vh,
            Vector2 center,
            float width,
            float height,
            Color32 color,
            GeoUtils.EdgeGradientData edgeGradientData
            )
        {
            width  += edgeGradientData.ShadowOffset * 2.0f;
            height += edgeGradientData.ShadowOffset * 2.0f;

            float innerOffset = Mathf.Min(width, height) * (1.0f - edgeGradientData.InnerScale);

            AddRectVertRing(
                ref vh,
                center,
                width - innerOffset,
                height - innerOffset,
                color,
                width,
                height
                );

            AddRectQuadIndices(ref vh);

            if (edgeGradientData.IsActive)
            {
                color.a = 0;

                GeoUtils.AddOffset(
                    ref width,
                    ref height,
                    edgeGradientData.SizeAdd
                    );

                AddRectVertRing(
                    ref vh,
                    center,
                    width,
                    height,
                    color,
                    width - edgeGradientData.SizeAdd * 2.0f,
                    height - edgeGradientData.SizeAdd * 2.0f,
                    true
                    );
            }
        }
Ejemplo n.º 2
0
        public static void AddRoundedCap(
            ref VertexHelper vh,
            bool isStart,
            int firstVertIndex,
            Vector2 position,
            Vector2 normal,
            Vector2 capOffset,
            int invertIndices,
            LineProperties lineProperties,
            GeoUtils.OutlineProperties outlineProperties,
            Color32 color,
            Vector2 uv,
            PointsList.PointsData pointsData,
            GeoUtils.EdgeGradientData edgeGradientData,
            Vector2[] capOffsets,
            Vector2[] uvOffsets,
            float uvXMin,
            float uvXLength,
            int currentVertCount
            )
        {
            int baseIndex = currentVertCount;

            float innerOffset     = outlineProperties.GetCenterDistace();
            float capOffsetAmount = (edgeGradientData.ShadowOffset + outlineProperties.HalfLineWeight) * edgeGradientData.InnerScale;

            if (isStart)
            {
                uv.x = uvXMin;
            }
            else
            {
                uv.x = uvXMin + uvXLength;
            }

#if CENTER_ROUNDED_CAPS
            // add center vert
            tmpPos.x = position.x;
            tmpPos.y = position.y;
            uv.y     = 0.5f;

            vh.AddVert(tmpPos, color, uv, GeoUtils.ZeroV2, GeoUtils.UINormal, GeoUtils.UITangent);
#endif

            for (int i = 0; i < capOffsets.Length; i++)
            {
                {
                    tmpPos.x = position.x + normal.x * innerOffset + capOffsets[i].x * capOffsetAmount;
                    tmpPos.y = position.y + normal.y * innerOffset + capOffsets[i].y * capOffsetAmount;
                }

                if (isStart)
                {
                    uv.x = Mathf.LerpUnclamped(uvXMin, 0.0f, uvOffsets[i].x);
                }
                else
                {
                    uv.x = Mathf.LerpUnclamped(uvXMin + uvXLength, 1.0f, uvOffsets[i].x);
                }
                uv.y = uvOffsets[i].y;

                vh.AddVert(tmpPos, color, uv, GeoUtils.ZeroV2, GeoUtils.UINormal, GeoUtils.UITangent);

                if (i > 0)
                {
#if CENTER_ROUNDED_CAPS
                    vh.AddTriangle(baseIndex, baseIndex + i - 1, baseIndex + i);
#else
                    vh.AddTriangle(firstVertIndex, baseIndex + i - 1, baseIndex + i);
#endif
                }
            }

            // last fans
            if (isStart)
            {
#if CENTER_ROUNDED_CAPS
                // starting triangle
                vh.AddTriangle(baseIndex + 1, baseIndex, firstVertIndex);

                // end triangles
                vh.AddTriangle(baseIndex, baseIndex + capOffsets.Length - 1, baseIndex + capOffsets.Length);
                vh.AddTriangle(baseIndex, baseIndex + capOffsets.Length, firstVertIndex + 1);
#else
                vh.AddTriangle(baseIndex + capOffsets.Length - 1, firstVertIndex + 1, firstVertIndex);
#endif
            }
            else
            {
#if CENTER_ROUNDED_CAPS
                // starting triangle
                vh.AddTriangle(baseIndex + 1, baseIndex, firstVertIndex + 1);

                // end triangles
                vh.AddTriangle(baseIndex, baseIndex + capOffsets.Length - 1, baseIndex + capOffsets.Length);
                vh.AddTriangle(baseIndex, baseIndex + capOffsets.Length, firstVertIndex);
#else
                vh.AddTriangle(baseIndex, firstVertIndex, firstVertIndex + 1);
#endif
            }

            if (edgeGradientData.IsActive)
            {
                color.a = 0;

                innerOffset = outlineProperties.GetCenterDistace();

                capOffsetAmount = outlineProperties.HalfLineWeight + edgeGradientData.SizeAdd + edgeGradientData.ShadowOffset;

                int antiAliasedIndex = firstVertIndex + pointsData.NumPositions * 2;

                for (int i = 0; i < capOffsets.Length; i++)
                {
                    {
                        tmpPos.x = position.x + normal.x * innerOffset + capOffsets[i].x * capOffsetAmount;
                        tmpPos.y = position.y + normal.y * innerOffset + capOffsets[i].y * capOffsetAmount;
                    }

                    if (isStart)
                    {
                        uv.x = Mathf.LerpUnclamped(uvXMin, 0.0f, uvOffsets[i].x);
                    }
                    else
                    {
                        uv.x = Mathf.LerpUnclamped(uvXMin + uvXLength, 1.0f, uvOffsets[i].x);
                    }
                    uv.y = uvOffsets[i].y;

                    vh.AddVert(tmpPos, color, uv, GeoUtils.ZeroV2, GeoUtils.UINormal, GeoUtils.UITangent);

                    if (i > 0)
                    {
                        vh.AddTriangle(baseIndex + i - 1, baseIndex + capOffsets.Length + i - 1, baseIndex + i);
                        vh.AddTriangle(baseIndex + capOffsets.Length + i, baseIndex + i, baseIndex + capOffsets.Length + i - 1);
                    }
                }

                if (!isStart)
                {
                    vh.AddTriangle(baseIndex, firstVertIndex + 1, antiAliasedIndex + 1);
                    vh.AddTriangle(antiAliasedIndex + 1, baseIndex + capOffsets.Length, baseIndex);

                    vh.AddTriangle(baseIndex + capOffsets.Length * 2 - 1, antiAliasedIndex, firstVertIndex);
                    vh.AddTriangle(baseIndex + capOffsets.Length - 1, baseIndex + capOffsets.Length * 2 - 1, firstVertIndex);
                }
                else
                {
                    vh.AddTriangle(firstVertIndex + 1, baseIndex + capOffsets.Length - 1, baseIndex + capOffsets.Length * 2 - 1);
                    vh.AddTriangle(antiAliasedIndex + 1, firstVertIndex + 1, baseIndex + capOffsets.Length * 2 - 1);

                    vh.AddTriangle(antiAliasedIndex, baseIndex, firstVertIndex);
                    vh.AddTriangle(baseIndex + capOffsets.Length, baseIndex, antiAliasedIndex);
                }
            }
        }
Ejemplo n.º 3
0
        public static void AddProjectedCap(
            ref VertexHelper vh,
            bool isStart,
            int firstVertIndex,
            Vector2 position,
            Vector2 normal,
            Vector2 capOffset,
            int invertIndices,
            LineProperties lineProperties,
            GeoUtils.OutlineProperties outlineProperties,
            Color32 color,
            Vector2 uv,
            PointsList.PointsData pointsData,
            GeoUtils.EdgeGradientData edgeGradientData,
            int currentVertCount
            )
        {
            int baseIndex = currentVertCount;

            if (isStart)
            {
                uv.x = 0.0f;
            }
            else
            {
                uv.x = 1.0f;
            }

            float innerOffset = outlineProperties.GetCenterDistace() - (outlineProperties.HalfLineWeight + edgeGradientData.ShadowOffset) * edgeGradientData.InnerScale;
            float outerOffset = outlineProperties.GetCenterDistace() + (outlineProperties.HalfLineWeight + edgeGradientData.ShadowOffset) * edgeGradientData.InnerScale;

            float capOffsetAmount = edgeGradientData.ShadowOffset + outlineProperties.LineWeight * 0.5f;

            capOffsetAmount *= edgeGradientData.InnerScale;

            // add lineWeight to position
            {
                tmpPos.x = position.x + normal.x * innerOffset + capOffset.x * capOffsetAmount;
                tmpPos.y = position.y + normal.y * innerOffset + capOffset.y * capOffsetAmount;
            }

            uv.y = 0.0f;
            vh.AddVert(tmpPos, color, uv, GeoUtils.ZeroV2, GeoUtils.UINormal, GeoUtils.UITangent);

            {
                tmpPos.x = position.x + normal.x * outerOffset + capOffset.x * capOffsetAmount;
                tmpPos.y = position.y + normal.y * outerOffset + capOffset.y * capOffsetAmount;
            }

            uv.y = 1.0f;
            vh.AddVert(tmpPos, color, uv, GeoUtils.ZeroV2, GeoUtils.UINormal, GeoUtils.UITangent);

            vh.AddTriangle(firstVertIndex, baseIndex + invertIndices, baseIndex + 1 - invertIndices);
            vh.AddTriangle(firstVertIndex + invertIndices, baseIndex + 1, firstVertIndex + 1 - invertIndices);

            if (edgeGradientData.IsActive)
            {
                innerOffset = outlineProperties.GetCenterDistace() - (outlineProperties.HalfLineWeight + edgeGradientData.ShadowOffset) - edgeGradientData.SizeAdd;
                outerOffset = outlineProperties.GetCenterDistace() + (outlineProperties.HalfLineWeight + edgeGradientData.ShadowOffset) + edgeGradientData.SizeAdd;

                capOffsetAmount = outlineProperties.HalfLineWeight + edgeGradientData.SizeAdd + edgeGradientData.ShadowOffset;

                color.a = 0;

                {
                    tmpPos.x = position.x + normal.x * innerOffset + capOffset.x * capOffsetAmount;
                    tmpPos.y = position.y + normal.y * innerOffset + capOffset.y * capOffsetAmount;
                }

                uv.y = 0.0f;
                vh.AddVert(tmpPos, color, uv, GeoUtils.ZeroV2, GeoUtils.UINormal, GeoUtils.UITangent);


                {
                    tmpPos.x = position.x + normal.x * outerOffset + capOffset.x * capOffsetAmount;
                    tmpPos.y = position.y + normal.y * outerOffset + capOffset.y * capOffsetAmount;
                }

                uv.y = 1.0f;
                vh.AddVert(tmpPos, color, uv, GeoUtils.ZeroV2, GeoUtils.UINormal, GeoUtils.UITangent);

                int antiAliasedIndex = firstVertIndex + pointsData.NumPositions * 2;
                baseIndex += 2;

                if (invertIndices != 0)
                {
                    vh.AddTriangle(firstVertIndex, baseIndex, antiAliasedIndex);
                    vh.AddTriangle(firstVertIndex + 1, antiAliasedIndex + 1, baseIndex + 1);

                    vh.AddTriangle(baseIndex - 2, baseIndex - 1, baseIndex);
                    vh.AddTriangle(baseIndex + 1, baseIndex, baseIndex - 1);

                    vh.AddTriangle(firstVertIndex, baseIndex - 2, baseIndex);
                    vh.AddTriangle(firstVertIndex + 1, baseIndex + 1, baseIndex - 1);
                }
                else
                {
                    vh.AddTriangle(firstVertIndex, antiAliasedIndex, baseIndex);
                    vh.AddTriangle(firstVertIndex + 1, baseIndex + 1, antiAliasedIndex + 1);

                    vh.AddTriangle(baseIndex - 2, baseIndex, baseIndex - 1);
                    vh.AddTriangle(baseIndex + 1, baseIndex - 1, baseIndex);

                    vh.AddTriangle(firstVertIndex, baseIndex, baseIndex - 2);
                    vh.AddTriangle(firstVertIndex + 1, baseIndex - 1, baseIndex + 1);
                }
            }
        }
Ejemplo n.º 4
0
        public static void AddEndCap(
            ref VertexHelper vh,
            LineProperties lineProperties,
            Vector2 positionOffset,
            GeoUtils.OutlineProperties outlineProperties,
            Color32 color,
            Vector2 uv,
            float uvXMin,
            float uvXLength,
            PointsList.PointsData pointsData,
            GeoUtils.EdgeGradientData edgeGradientData
            )
        {
            int currentVertCount = vh.currentVertCount;
            int startIndex       = currentVertCount;

            if (edgeGradientData.IsActive)
            {
                startIndex -= pointsData.NumPositions * 2;
            }

            int lastPositionIndex = pointsData.NumPositions - 1;

            tmpPos2.x = positionOffset.x + pointsData.Positions[lastPositionIndex].x;
            tmpPos2.y = positionOffset.y + pointsData.Positions[lastPositionIndex].y;

            switch (lineProperties.LineCap)
            {
            case LineProperties.LineCapTypes.Close:

                startIndex -= 4;

                AddCloseCap(
                    ref vh,
                    false,
                    startIndex,
                    tmpPos2,
                    pointsData.PositionNormals[lastPositionIndex],
                    pointsData.EndCapOffset,
                    1,
                    lineProperties,
                    outlineProperties,
                    color,
                    uv,
                    pointsData,
                    edgeGradientData,
                    currentVertCount
                    );

                break;

            case LineProperties.LineCapTypes.Projected:

                startIndex -= 6;

                AddProjectedCap(
                    ref vh,
                    false,
                    startIndex,
                    tmpPos2,
                    pointsData.PositionNormals[lastPositionIndex],
                    pointsData.EndCapOffset,
                    1,
                    lineProperties,
                    outlineProperties,
                    color,
                    uv,
                    pointsData,
                    edgeGradientData,
                    currentVertCount
                    );

                break;

            case LineProperties.LineCapTypes.Round:
#if CENTER_ROUNDED_CAPS
                startIndex -= pointsData.RoundedCapResolution + 3;
#else
                startIndex -= pointsData.RoundedCapResolution + 2;
#endif

                if (edgeGradientData.IsActive)
                {
                    startIndex -= pointsData.RoundedCapResolution;
                }

                AddRoundedCap(
                    ref vh,
                    false,
                    startIndex,
                    tmpPos2,
                    pointsData.PositionNormals[lastPositionIndex],
                    pointsData.EndCapOffset,
                    1,
                    lineProperties,
                    outlineProperties,
                    color,
                    uv,
                    pointsData,
                    edgeGradientData,
                    pointsData.EndCapOffsets,
                    pointsData.EndCapUVs,
                    uvXMin,
                    uvXLength,
                    currentVertCount
                    );

                break;
            }
        }
Ejemplo n.º 5
0
        public static void AddLine(
            ref VertexHelper vh,
            LineProperties lineProperties,
            PointsList.PointListProperties pointListProperties,
            Vector2 positionOffset,
            GeoUtils.OutlineProperties outlineProperties,
            Color32 color,
            Vector2 uv,
            ref PointsList.PointsData pointsData,
            GeoUtils.EdgeGradientData edgeGradientData
            )
        {
            pointListProperties.SetPoints();
            pointsData.IsClosed = lineProperties.Closed && pointListProperties.Positions.Length > 2;

            pointsData.GenerateRoundedCaps = lineProperties.LineCap == LineProperties.LineCapTypes.Round;

            pointsData.LineWeight = outlineProperties.LineWeight;

            if (pointsData.GenerateRoundedCaps)
            {
                lineProperties.RoundedCapResolution.UpdateAdjusted(outlineProperties.HalfLineWeight, 0.0f, 2.0f);
                pointsData.RoundedCapResolution = lineProperties.RoundedCapResolution.AdjustedResolution;
            }

            if (!PointsList.SetLineData(pointListProperties, ref pointsData))
            {
                return;
            }


            // scale uv x for caps
            float uvXMin    = 0.0f;
            float uvXLength = 1.0f;

            if (
                !lineProperties.Closed &&
                lineProperties.LineCap != LineProperties.LineCapTypes.Close
                )
            {
                float uvStartOffset = outlineProperties.LineWeight / pointsData.TotalLength;

                uvXMin    = uvStartOffset * 0.5f;
                uvXLength = 1.0f - uvXMin * 2.0f;
            }

            float innerOffset = outlineProperties.GetCenterDistace() - (outlineProperties.HalfLineWeight + edgeGradientData.ShadowOffset) * edgeGradientData.InnerScale;
            float outerOffset = outlineProperties.GetCenterDistace() + (outlineProperties.HalfLineWeight + edgeGradientData.ShadowOffset) * edgeGradientData.InnerScale;

            float capOffsetAmount = 0.0f;

            if (!lineProperties.Closed && lineProperties.LineCap == LineProperties.LineCapTypes.Close)
            {
                capOffsetAmount = edgeGradientData.ShadowOffset * (edgeGradientData.InnerScale * 2.0f - 1.0f);
            }


            int numVertices = vh.currentVertCount;
            int startVertex = numVertices - 1;
            int baseIndex;

            uv.x = uvXMin + pointsData.NormalizedPositionDistances[0] * uvXLength;
            uv.y = 0.0f;

            {
                tmpPos.x = positionOffset.x + pointsData.Positions[0].x + pointsData.PositionNormals[0].x * innerOffset + pointsData.StartCapOffset.x * capOffsetAmount;
                tmpPos.y = positionOffset.y + pointsData.Positions[0].y + pointsData.PositionNormals[0].y * innerOffset + pointsData.StartCapOffset.y * capOffsetAmount;
            }

            vh.AddVert(tmpPos, color, uv, GeoUtils.ZeroV2, GeoUtils.UINormal, GeoUtils.UITangent);

            uv.y = 1.0f;

            {
                tmpPos.x = positionOffset.x + pointsData.Positions[0].x + pointsData.PositionNormals[0].x * outerOffset + pointsData.StartCapOffset.x * capOffsetAmount;
                tmpPos.y = positionOffset.y + pointsData.Positions[0].y + pointsData.PositionNormals[0].y * outerOffset + pointsData.StartCapOffset.y * capOffsetAmount;
            }

            vh.AddVert(tmpPos, color, uv, GeoUtils.ZeroV2, GeoUtils.UINormal, GeoUtils.UITangent);

            for (int i = 1; i < pointsData.NumPositions - 1; i++)
            {
                uv.x = uvXMin + pointsData.NormalizedPositionDistances[i] * uvXLength;
                uv.y = 0.0f;

                {
                    tmpPos.x = positionOffset.x + pointsData.Positions[i].x + pointsData.PositionNormals[i].x * innerOffset;
                    tmpPos.y = positionOffset.y + pointsData.Positions[i].y + pointsData.PositionNormals[i].y * innerOffset;
                }

                vh.AddVert(tmpPos, color, uv, GeoUtils.ZeroV2, GeoUtils.UINormal, GeoUtils.UITangent);

                uv.y = 1.0f;

                {
                    tmpPos.x = positionOffset.x + pointsData.Positions[i].x + pointsData.PositionNormals[i].x * outerOffset;
                    tmpPos.y = positionOffset.y + pointsData.Positions[i].y + pointsData.PositionNormals[i].y * outerOffset;
                }

                vh.AddVert(tmpPos, color, uv, GeoUtils.ZeroV2, GeoUtils.UINormal, GeoUtils.UITangent);

                baseIndex = startVertex + i * 2;
                vh.AddTriangle(baseIndex - 1, baseIndex, baseIndex + 1);
                vh.AddTriangle(baseIndex, baseIndex + 2, baseIndex + 1);
            }

            // add end vertices
            int endIndex = pointsData.NumPositions - 1;

            uv.x = uvXMin + pointsData.NormalizedPositionDistances[endIndex] * uvXLength;
            uv.y = 0.0f;

            {
                tmpPos.x = positionOffset.x + pointsData.Positions[endIndex].x + pointsData.PositionNormals[endIndex].x * innerOffset + pointsData.EndCapOffset.x * capOffsetAmount;
                tmpPos.y = positionOffset.y + pointsData.Positions[endIndex].y + pointsData.PositionNormals[endIndex].y * innerOffset + pointsData.EndCapOffset.y * capOffsetAmount;
            }

            vh.AddVert(tmpPos, color, uv, GeoUtils.ZeroV2, GeoUtils.UINormal, GeoUtils.UITangent);

            uv.y = 1.0f;

            {
                tmpPos.x = positionOffset.x + pointsData.Positions[endIndex].x + pointsData.PositionNormals[endIndex].x * outerOffset + pointsData.EndCapOffset.x * capOffsetAmount;
                tmpPos.y = positionOffset.y + pointsData.Positions[endIndex].y + pointsData.PositionNormals[endIndex].y * outerOffset + pointsData.EndCapOffset.y * capOffsetAmount;
            }

            vh.AddVert(tmpPos, color, uv, GeoUtils.ZeroV2, GeoUtils.UINormal, GeoUtils.UITangent);

            baseIndex = startVertex + endIndex * 2;
            vh.AddTriangle(baseIndex - 1, baseIndex, baseIndex + 1);
            vh.AddTriangle(baseIndex, baseIndex + 2, baseIndex + 1);

            if (lineProperties.Closed)
            {
                uv.x = 1.0f;
                uv.y = 0.0f;

                {
                    tmpPos.x = positionOffset.x + pointsData.Positions[0].x + pointsData.PositionNormals[0].x * innerOffset + pointsData.StartCapOffset.x * capOffsetAmount;
                    tmpPos.y = positionOffset.y + pointsData.Positions[0].y + pointsData.PositionNormals[0].y * innerOffset + pointsData.StartCapOffset.y * capOffsetAmount;
                }

                vh.AddVert(tmpPos, color, uv, GeoUtils.ZeroV2, GeoUtils.UINormal, GeoUtils.UITangent);

                uv.y = 1.0f;

                {
                    tmpPos.x = positionOffset.x + pointsData.Positions[0].x + pointsData.PositionNormals[0].x * outerOffset + pointsData.StartCapOffset.x * capOffsetAmount;
                    tmpPos.y = positionOffset.y + pointsData.Positions[0].y + pointsData.PositionNormals[0].y * outerOffset + pointsData.StartCapOffset.y * capOffsetAmount;
                }

                vh.AddVert(tmpPos, color, uv, GeoUtils.ZeroV2, GeoUtils.UINormal, GeoUtils.UITangent);

                baseIndex = startVertex + endIndex * 2 + 2;
                vh.AddTriangle(baseIndex - 1, baseIndex, baseIndex + 1);
                vh.AddTriangle(baseIndex, baseIndex + 2, baseIndex + 1);
            }

            if (edgeGradientData.IsActive)
            {
                byte colorAlpha = color.a;

                innerOffset = outlineProperties.GetCenterDistace() - (outlineProperties.HalfLineWeight + edgeGradientData.ShadowOffset);
                outerOffset = outlineProperties.GetCenterDistace() + (outlineProperties.HalfLineWeight + edgeGradientData.ShadowOffset);

                innerOffset -= edgeGradientData.SizeAdd;
                outerOffset += edgeGradientData.SizeAdd;

                color.a = 0;

                int outerBaseIndex = numVertices + pointsData.NumPositions * 2;

                if (lineProperties.Closed)
                {
                    outerBaseIndex += 2;
                }

                uv.x = uvXMin + pointsData.NormalizedPositionDistances[0] * uvXLength;
                uv.y = 0.0f;

                {
                    tmpPos.x = positionOffset.x + pointsData.Positions[0].x + pointsData.PositionNormals[0].x * innerOffset;
                    tmpPos.y = positionOffset.y + pointsData.Positions[0].y + pointsData.PositionNormals[0].y * innerOffset;
                }

                vh.AddVert(tmpPos, color, uv, GeoUtils.ZeroV2, GeoUtils.UINormal, GeoUtils.UITangent);

                uv.y = 1.0f;

                {
                    tmpPos.x = positionOffset.x + pointsData.Positions[0].x + pointsData.PositionNormals[0].x * outerOffset;
                    tmpPos.y = positionOffset.y + pointsData.Positions[0].y + pointsData.PositionNormals[0].y * outerOffset;
                }

                vh.AddVert(tmpPos, color, uv, GeoUtils.ZeroV2, GeoUtils.UINormal, GeoUtils.UITangent);

                for (int i = 1; i < pointsData.NumPositions; i++)
                {
                    uv.x = uvXMin + pointsData.NormalizedPositionDistances[i] * uvXLength;
                    uv.y = 0.0f;

                    {
                        tmpPos.x = positionOffset.x + pointsData.Positions[i].x + pointsData.PositionNormals[i].x * innerOffset;
                        tmpPos.y = positionOffset.y + pointsData.Positions[i].y + pointsData.PositionNormals[i].y * innerOffset;
                    }

                    vh.AddVert(tmpPos, color, uv, GeoUtils.ZeroV2, GeoUtils.UINormal, GeoUtils.UITangent);

                    uv.y = 1.0f;

                    {
                        tmpPos.x = positionOffset.x + pointsData.Positions[i].x + pointsData.PositionNormals[i].x * outerOffset;
                        tmpPos.y = positionOffset.y + pointsData.Positions[i].y + pointsData.PositionNormals[i].y * outerOffset;
                    }

                    vh.AddVert(tmpPos, color, uv, GeoUtils.ZeroV2, GeoUtils.UINormal, GeoUtils.UITangent);

                    // inner quad
                    vh.AddTriangle(startVertex + i * 2 - 1, startVertex + i * 2 + 1, outerBaseIndex + i * 2);
                    vh.AddTriangle(startVertex + i * 2 - 1, outerBaseIndex + i * 2, outerBaseIndex + i * 2 - 2);

                    // outer quad
                    vh.AddTriangle(startVertex + i * 2, outerBaseIndex + i * 2 - 1, startVertex + i * 2 + 2);
                    vh.AddTriangle(startVertex + i * 2 + 2, outerBaseIndex + i * 2 - 1, outerBaseIndex + i * 2 + 1);
                }

                if (lineProperties.Closed)
                {
                    int lastIndex = pointsData.NumPositions;

                    uv.x = 1.0f;
                    uv.y = 0.0f;

                    {
                        tmpPos.x = positionOffset.x + pointsData.Positions[0].x + pointsData.PositionNormals[0].x * innerOffset;
                        tmpPos.y = positionOffset.y + pointsData.Positions[0].y + pointsData.PositionNormals[0].y * innerOffset;
                    }

                    vh.AddVert(tmpPos, color, uv, GeoUtils.ZeroV2, GeoUtils.UINormal, GeoUtils.UITangent);

                    uv.y = 1.0f;

                    {
                        tmpPos.x = positionOffset.x + pointsData.Positions[0].x + pointsData.PositionNormals[0].x * outerOffset;
                        tmpPos.y = positionOffset.y + pointsData.Positions[0].y + pointsData.PositionNormals[0].y * outerOffset;
                    }

                    vh.AddVert(tmpPos, color, uv, GeoUtils.ZeroV2, GeoUtils.UINormal, GeoUtils.UITangent);

                    // inner quad
                    vh.AddTriangle(startVertex + lastIndex * 2 - 1, startVertex + lastIndex * 2 + 1, outerBaseIndex + lastIndex * 2);
                    vh.AddTriangle(startVertex + lastIndex * 2 - 1, outerBaseIndex + lastIndex * 2, outerBaseIndex + lastIndex * 2 - 2);

                    // outer quad
                    vh.AddTriangle(startVertex + lastIndex * 2, outerBaseIndex + lastIndex * 2 - 1, startVertex + lastIndex * 2 + 2);
                    vh.AddTriangle(startVertex + lastIndex * 2 + 2, outerBaseIndex + lastIndex * 2 - 1, outerBaseIndex + lastIndex * 2 + 1);
                }

                color.a = colorAlpha;
            }

            // close line or add caps
            if (!lineProperties.Closed)
            {
                AddStartCap(
                    ref vh,
                    lineProperties,
                    positionOffset,
                    outlineProperties,
                    color,
                    uv,
                    uvXMin,
                    uvXLength,
                    pointsData,
                    edgeGradientData
                    );

                AddEndCap(
                    ref vh,
                    lineProperties,
                    positionOffset,
                    outlineProperties,
                    color,
                    uv,
                    uvXMin,
                    uvXLength,
                    pointsData,
                    edgeGradientData
                    );
            }
        }
Ejemplo n.º 6
0
        public static void AddStartCap(
            ref VertexHelper vh,
            LineProperties lineProperties,
            Vector2 positionOffset,
            GeoUtils.OutlineProperties outlineProperties,
            Color32 color,
            Vector2 uv,
            float uvXMin,
            float uvXLength,
            PointsList.PointsData pointsData,
            GeoUtils.EdgeGradientData edgeGradientData
            )
        {
            int currentVertCount = vh.currentVertCount;
            int startIndex       = currentVertCount - pointsData.NumPositions * 2;

            if (edgeGradientData.IsActive)
            {
                startIndex -= pointsData.NumPositions * 2;
            }

            tmpPos2.x = positionOffset.x + pointsData.Positions[0].x;
            tmpPos2.y = positionOffset.y + pointsData.Positions[0].y;

            switch (lineProperties.LineCap)
            {
            case LineProperties.LineCapTypes.Close:
                AddCloseCap(
                    ref vh,
                    true,
                    startIndex,
                    tmpPos2,
                    pointsData.PositionNormals[0],
                    pointsData.StartCapOffset,
                    0,
                    lineProperties,
                    outlineProperties,
                    color,
                    uv,
                    pointsData,
                    edgeGradientData,
                    currentVertCount
                    );

                break;

            case LineProperties.LineCapTypes.Projected:
                AddProjectedCap(
                    ref vh,
                    true,
                    startIndex,
                    tmpPos2,
                    pointsData.PositionNormals[0],
                    pointsData.StartCapOffset,
                    0,
                    lineProperties,
                    outlineProperties,
                    color,
                    uv,
                    pointsData,
                    edgeGradientData,
                    currentVertCount
                    );

                break;

            case LineProperties.LineCapTypes.Round:
                AddRoundedCap(
                    ref vh,
                    true,
                    startIndex,
                    tmpPos2,
                    pointsData.PositionNormals[0],
                    pointsData.StartCapOffset,
                    0,
                    lineProperties,
                    outlineProperties,
                    color,
                    uv,
                    pointsData,
                    edgeGradientData,
                    pointsData.StartCapOffsets,
                    pointsData.StartCapUVs,
                    uvXMin,
                    uvXLength,
                    currentVertCount
                    );
                break;
            }
        }
Ejemplo n.º 7
0
        public static void AddRectRing(
            ref VertexHelper vh,
            GeoUtils.OutlineProperties OutlineProperties,
            Vector2 center,
            float width,
            float height,
            Color32 color,
            Vector2 uv,
            GeoUtils.EdgeGradientData edgeGradientData
            )
        {
            byte alpha = color.a;

            float fullWidth  = width + OutlineProperties.GetOuterDistace() * 2.0f;
            float fullHeight = height + OutlineProperties.GetOuterDistace() * 2.0f;

            width  += OutlineProperties.GetCenterDistace() * 2.0f;
            height += OutlineProperties.GetCenterDistace() * 2.0f;

            float halfLineWeightOffset      = OutlineProperties.HalfLineWeight * 2.0f + edgeGradientData.ShadowOffset;
            float halfLineWeightInnerOffset = halfLineWeightOffset * edgeGradientData.InnerScale;

            if (edgeGradientData.IsActive)
            {
                color.a = 0;

                AddRectVertRing(
                    ref vh,
                    center,
                    width - halfLineWeightOffset - edgeGradientData.SizeAdd,
                    height - halfLineWeightOffset - edgeGradientData.SizeAdd,
                    color,
                    fullWidth,
                    fullHeight
                    );

                color.a = alpha;
            }



            AddRectVertRing(
                ref vh,
                center,
                width - halfLineWeightInnerOffset,
                height - halfLineWeightInnerOffset,
                color,
                fullWidth,
                fullHeight,
                edgeGradientData.IsActive
                );

            AddRectVertRing(
                ref vh,
                center,
                width + halfLineWeightInnerOffset,
                height + halfLineWeightInnerOffset,
                color,
                fullWidth,
                fullHeight,
                true
                );

            if (edgeGradientData.IsActive)
            {
                color.a = 0;

                AddRectVertRing(
                    ref vh,
                    center,
                    width + halfLineWeightOffset + edgeGradientData.SizeAdd,
                    height + halfLineWeightOffset + edgeGradientData.SizeAdd,
                    color,
                    fullWidth,
                    fullHeight,
                    true
                    );
            }
        }
Ejemplo n.º 8
0
        public static void AddRoundedRect(
            ref VertexHelper vh,
            Vector2 center,
            float width,
            float height,
            RoundedProperties roundedProperties,
            Color32 color,
            Vector2 uv,
            ref RoundedCornerUnitPositionData cornerUnitPositions,
            GeoUtils.EdgeGradientData edgeGradientData
            )
        {
            if (roundedProperties.Type == RoundedProperties.RoundedType.None)
            {
                Rects.AddRect(
                    ref vh,
                    center,
                    width,
                    height,
                    color,
                    edgeGradientData
                    );

                return;
            }


            SetCornerUnitPositions(
                roundedProperties,
                ref cornerUnitPositions
                );

            int numVertices = vh.currentVertCount;

            tmpUV.x = 0.5f;
            tmpUV.y = 0.5f;

            vh.AddVert(center, color, tmpUV, GeoUtils.ZeroV2, GeoUtils.UINormal, GeoUtils.UITangent);

            float sizeSub = Mathf.Min(height, width);

            sizeSub *= 1.0f - edgeGradientData.InnerScale;

            AddRoundedRectVerticesRing(
                ref vh,
                center,
                width - sizeSub,
                height - sizeSub,
                width - sizeSub,
                height - sizeSub,
                roundedProperties.AdjustedTLRadius * edgeGradientData.InnerScale,
                (roundedProperties.AdjustedTLRadius + edgeGradientData.ShadowOffset) * edgeGradientData.InnerScale,
                roundedProperties.AdjustedTRRadius * edgeGradientData.InnerScale,
                (roundedProperties.AdjustedTRRadius + edgeGradientData.ShadowOffset) * edgeGradientData.InnerScale,
                roundedProperties.AdjustedBRRadius * edgeGradientData.InnerScale,
                (roundedProperties.AdjustedBRRadius + edgeGradientData.ShadowOffset) * edgeGradientData.InnerScale,
                roundedProperties.AdjustedBLRadius * edgeGradientData.InnerScale,
                (roundedProperties.AdjustedBLRadius + edgeGradientData.ShadowOffset) * edgeGradientData.InnerScale,
                cornerUnitPositions,
                color,
                uv,
                false
                );


            // set indices
            int numNewVertices = vh.currentVertCount - numVertices;

            for (int i = 0; i < numNewVertices - 1; i++)
            {
                vh.AddTriangle(numVertices, numVertices + i, numVertices + i + 1);
            }

            // set last triangle
            vh.AddTriangle(numVertices, vh.currentVertCount - 1, numVertices + 1);


            if (edgeGradientData.IsActive)
            {
                float outerRadiusMod = 0.0f;                // = roundedProperties.AdjustedRadius;
                outerRadiusMod += edgeGradientData.ShadowOffset;
                outerRadiusMod += edgeGradientData.SizeAdd;

                color.a = 0;

                AddRoundedRectVerticesRing(
                    ref vh,
                    center,
                    width,
                    height,
                    width,
                    height,
                    roundedProperties.AdjustedTLRadius,
                    roundedProperties.AdjustedTLRadius + outerRadiusMod,
                    roundedProperties.AdjustedTRRadius,
                    roundedProperties.AdjustedTRRadius + outerRadiusMod,
                    roundedProperties.AdjustedBRRadius,
                    roundedProperties.AdjustedBRRadius + outerRadiusMod,
                    roundedProperties.AdjustedBLRadius,
                    roundedProperties.AdjustedBLRadius + outerRadiusMod,
                    cornerUnitPositions,
                    color,
                    uv,
                    true
                    );
            }
        }
Ejemplo n.º 9
0
        public static void AddRoundedRectLine(
            ref VertexHelper vh,
            Vector2 center,
            float width,
            float height,
            GeoUtils.OutlineProperties outlineProperties,
            RoundedProperties roundedProperties,
            Color32 color,
            Vector2 uv,
            ref RoundedCornerUnitPositionData cornerUnitPositions,
            GeoUtils.EdgeGradientData edgeGradientData
            )
        {
            float fullWidth  = width + outlineProperties.GetOuterDistace() * 2.0f;
            float fullHeight = height + outlineProperties.GetOuterDistace() * 2.0f;

            if (roundedProperties.Type == RoundedProperties.RoundedType.None)
            {
                Rects.AddRectRing(
                    ref vh,
                    outlineProperties,
                    center,
                    width,
                    height,
                    color,
                    uv,
                    edgeGradientData
                    );

                return;
            }

            SetCornerUnitPositions(
                roundedProperties,
                ref cornerUnitPositions
                );

            float outerRadiusMod;

            byte alpha = color.a;

            if (edgeGradientData.IsActive)
            {
                color.a = 0;

                outerRadiusMod =
                    outlineProperties.GetCenterDistace() - outlineProperties.HalfLineWeight - edgeGradientData.ShadowOffset;
                outerRadiusMod -= edgeGradientData.SizeAdd;

                AddRoundedRectVerticesRing(
                    ref vh,
                    center,
                    width,
                    height,
                    fullWidth,
                    fullHeight,
                    roundedProperties.AdjustedTLRadius,
                    roundedProperties.AdjustedTLRadius + outerRadiusMod,
                    roundedProperties.AdjustedTRRadius,
                    roundedProperties.AdjustedTRRadius + outerRadiusMod,
                    roundedProperties.AdjustedBRRadius,
                    roundedProperties.AdjustedBRRadius + outerRadiusMod,
                    roundedProperties.AdjustedBLRadius,
                    roundedProperties.AdjustedBLRadius + outerRadiusMod,
                    cornerUnitPositions,
                    color,
                    uv,
                    false
                    );

                color.a = alpha;
            }

            outerRadiusMod =
                Mathf.LerpUnclamped(
                    outlineProperties.GetCenterDistace(),
                    outlineProperties.GetCenterDistace() - outlineProperties.HalfLineWeight - edgeGradientData.ShadowOffset,
                    edgeGradientData.InnerScale);

            AddRoundedRectVerticesRing(
                ref vh,
                center,
                width,
                height,
                fullWidth,
                fullHeight,
                roundedProperties.AdjustedTLRadius,
                roundedProperties.AdjustedTLRadius + outerRadiusMod,
                roundedProperties.AdjustedTRRadius,
                roundedProperties.AdjustedTRRadius + outerRadiusMod,
                roundedProperties.AdjustedBRRadius,
                roundedProperties.AdjustedBRRadius + outerRadiusMod,
                roundedProperties.AdjustedBLRadius,
                roundedProperties.AdjustedBLRadius + outerRadiusMod,
                cornerUnitPositions,
                color,
                uv,
                edgeGradientData.IsActive
                );

            outerRadiusMod =
                outlineProperties.GetCenterDistace() +
                (outlineProperties.HalfLineWeight + edgeGradientData.ShadowOffset) * edgeGradientData.InnerScale;

            AddRoundedRectVerticesRing(
                ref vh,
                center,
                width,
                height,
                fullWidth,
                fullHeight,
                roundedProperties.AdjustedTLRadius,
                roundedProperties.AdjustedTLRadius + outerRadiusMod,
                roundedProperties.AdjustedTRRadius,
                roundedProperties.AdjustedTRRadius + outerRadiusMod,
                roundedProperties.AdjustedBRRadius,
                roundedProperties.AdjustedBRRadius + outerRadiusMod,
                roundedProperties.AdjustedBLRadius,
                roundedProperties.AdjustedBLRadius + outerRadiusMod,
                cornerUnitPositions,
                color,
                uv,
                true
                );

            if (edgeGradientData.IsActive)
            {
                outerRadiusMod =
                    outlineProperties.GetCenterDistace() +
                    outlineProperties.HalfLineWeight + edgeGradientData.ShadowOffset;
                outerRadiusMod += edgeGradientData.SizeAdd;

                color.a = 0;

                AddRoundedRectVerticesRing(
                    ref vh,
                    center,
                    width,
                    height,
                    fullWidth,
                    fullHeight,
                    roundedProperties.AdjustedTLRadius,
                    roundedProperties.AdjustedTLRadius + outerRadiusMod,
                    roundedProperties.AdjustedTRRadius,
                    roundedProperties.AdjustedTRRadius + outerRadiusMod,
                    roundedProperties.AdjustedBRRadius,
                    roundedProperties.AdjustedBRRadius + outerRadiusMod,
                    roundedProperties.AdjustedBLRadius,
                    roundedProperties.AdjustedBLRadius + outerRadiusMod,
                    cornerUnitPositions,
                    color,
                    uv,
                    true
                    );
            }
        }
Ejemplo n.º 10
0
        public static void AddArcRing(
            ref VertexHelper vh,
            Vector2 center,
            Vector2 radius,
            UIShapesKit.Ellipses.EllipseProperties ellipseProperties,
            ArcProperties arcProperties,
            GeoUtils.OutlineProperties outlineProperties,
            Color32 color,
            Vector2 uv,
            ref GeoUtils.UnitPositionData unitPositionData,
            GeoUtils.EdgeGradientData edgeGradientData
            )
        {
            if (arcProperties.Length <= 0.0f)
            {
                return;
            }

            GeoUtils.SetUnitPositionData(
                ref unitPositionData,
                ellipseProperties.AdjustedResolution,
                arcProperties.AdjustedBaseAngle,
                arcProperties.AdjustedDirection
                );

            radius.x += outlineProperties.GetCenterDistace();
            radius.y += outlineProperties.GetCenterDistace();

            float halfLineWeightOffset = (outlineProperties.HalfLineWeight + edgeGradientData.ShadowOffset) * edgeGradientData.InnerScale;

            if (arcProperties.Direction == ArcProperties.ArcDirection.Backward)
            {
                tmpInnerRadius.x = radius.x + halfLineWeightOffset;
                tmpInnerRadius.y = radius.y + halfLineWeightOffset;

                tmpOuterRadius.x = radius.x - halfLineWeightOffset;
                tmpOuterRadius.y = radius.y - halfLineWeightOffset;
            }
            else
            {
                tmpInnerRadius.x = radius.x - halfLineWeightOffset;
                tmpInnerRadius.y = radius.y - halfLineWeightOffset;

                tmpOuterRadius.x = radius.x + halfLineWeightOffset;
                tmpOuterRadius.y = radius.y + halfLineWeightOffset;
            }

            float capsExtensionLength = edgeGradientData.ShadowOffset * edgeGradientData.InnerScale;

            if (arcProperties.Length >= 1.0f)
            {
                capsExtensionLength = 0.0f;
            }

            int numVertices = vh.currentVertCount;
            int startVertex = numVertices - 1;

            int baseIndex;

            tmpPosition.x = center.x + unitPositionData.UnitPositions[0].x * tmpInnerRadius.x + arcProperties.StartTangent.x * capsExtensionLength;
            tmpPosition.y = center.y + unitPositionData.UnitPositions[0].y * tmpInnerRadius.y + arcProperties.StartTangent.y * capsExtensionLength;
            tmpPosition.z = 0.0f;
            vh.AddVert(
                tmpPosition, color, uv,
                GeoUtils.ZeroV2, GeoUtils.UINormal, GeoUtils.UITangent);

            tmpPosition.x = center.x + unitPositionData.UnitPositions[0].x * tmpOuterRadius.x + arcProperties.StartTangent.x * capsExtensionLength;
            tmpPosition.y = center.y + unitPositionData.UnitPositions[0].y * tmpOuterRadius.y + arcProperties.StartTangent.y * capsExtensionLength;
            tmpPosition.z = 0.0f;
            vh.AddVert(
                tmpPosition, color, uv,
                GeoUtils.ZeroV2, GeoUtils.UINormal, GeoUtils.UITangent);

            for (int i = 1; i < arcProperties.AdjustedResolution; i++)
            {
                tmpPosition.x = center.x + unitPositionData.UnitPositions[i].x * tmpInnerRadius.x;
                tmpPosition.y = center.y + unitPositionData.UnitPositions[i].y * tmpInnerRadius.y;
                tmpPosition.z = 0.0f;
                vh.AddVert(
                    tmpPosition, color, uv,
                    GeoUtils.ZeroV2, GeoUtils.UINormal, GeoUtils.UITangent);

                tmpPosition.x = center.x + unitPositionData.UnitPositions[i].x * tmpOuterRadius.x;
                tmpPosition.y = center.y + unitPositionData.UnitPositions[i].y * tmpOuterRadius.y;
                tmpPosition.z = 0.0f;
                vh.AddVert(
                    tmpPosition, color, uv,
                    GeoUtils.ZeroV2, GeoUtils.UINormal, GeoUtils.UITangent);

                baseIndex = startVertex + i * 2;
                vh.AddTriangle(baseIndex - 1, baseIndex, baseIndex + 1);
                vh.AddTriangle(baseIndex, baseIndex + 2, baseIndex + 1);
            }

            // add last partial segment
            tmpPosition.x = center.x + arcProperties.EndSegmentUnitPosition.x * tmpInnerRadius.x + arcProperties.EndTangent.x * capsExtensionLength;
            tmpPosition.y = center.y + arcProperties.EndSegmentUnitPosition.y * tmpInnerRadius.y + arcProperties.EndTangent.y * capsExtensionLength;
            tmpPosition.z = 0.0f;
            vh.AddVert(
                tmpPosition, color, uv,
                GeoUtils.ZeroV2, GeoUtils.UINormal, GeoUtils.UITangent);

            tmpPosition.x = center.x + arcProperties.EndSegmentUnitPosition.x * tmpOuterRadius.x + arcProperties.EndTangent.x * capsExtensionLength;
            tmpPosition.y = center.y + arcProperties.EndSegmentUnitPosition.y * tmpOuterRadius.y + arcProperties.EndTangent.y * capsExtensionLength;
            tmpPosition.z = 0.0f;
            vh.AddVert(
                tmpPosition, color, uv,
                GeoUtils.ZeroV2, GeoUtils.UINormal, GeoUtils.UITangent);

            baseIndex = startVertex + arcProperties.AdjustedResolution * 2;
            vh.AddTriangle(baseIndex - 1, baseIndex, baseIndex + 1);
            vh.AddTriangle(baseIndex, baseIndex + 2, baseIndex + 1);

            if (edgeGradientData.IsActive)
            {
                halfLineWeightOffset = outlineProperties.HalfLineWeight + edgeGradientData.ShadowOffset + edgeGradientData.SizeAdd;

                if (arcProperties.Direction == ArcProperties.ArcDirection.Backward)
                {
                    tmpOuterRadius.x = radius.x - halfLineWeightOffset;
                    tmpOuterRadius.y = radius.y - halfLineWeightOffset;

                    tmpInnerRadius.x = radius.x + halfLineWeightOffset;
                    tmpInnerRadius.y = radius.y + halfLineWeightOffset;
                }
                else
                {
                    tmpOuterRadius.x = radius.x + halfLineWeightOffset;
                    tmpOuterRadius.y = radius.y + halfLineWeightOffset;

                    tmpInnerRadius.x = radius.x - halfLineWeightOffset;
                    tmpInnerRadius.y = radius.y - halfLineWeightOffset;
                }

                color.a = 0;

                int edgesBaseIndex;
                int innerBaseIndex;

                // ensure inner vertices don't overlap
                tmpArcInnerRadius.x = Mathf.Max(0.0f, tmpInnerRadius.x);
                tmpArcInnerRadius.y = Mathf.Max(0.0f, tmpInnerRadius.y);

                tmpArcOuterRadius.x = Mathf.Max(0.0f, tmpOuterRadius.x);
                tmpArcOuterRadius.y = Mathf.Max(0.0f, tmpOuterRadius.y);

                noOverlapInnerOffset.x = arcProperties.CenterNormal.x * -Mathf.Min(0.0f, tmpInnerRadius.x);
                noOverlapInnerOffset.y = arcProperties.CenterNormal.y * -Mathf.Min(0.0f, tmpInnerRadius.y);
                noOverlapInnerOffset.z = 0.0f;

                noOverlapOuterOffset.x = arcProperties.CenterNormal.x * -Mathf.Min(0.0f, tmpOuterRadius.x);
                noOverlapOuterOffset.y = arcProperties.CenterNormal.y * -Mathf.Min(0.0f, tmpOuterRadius.y);
                noOverlapOuterOffset.z = 0.0f;

                if (arcProperties.Length >= 1.0f)
                {
                    noOverlapInnerOffset.x = 0.0f;
                    noOverlapInnerOffset.y = 0.0f;
                    noOverlapInnerOffset.z = 0.0f;

                    noOverlapOuterOffset.x = 0.0f;
                    noOverlapOuterOffset.y = 0.0f;
                    noOverlapOuterOffset.z = 0.0f;
                }

                for (int i = 0; i < arcProperties.AdjustedResolution; i++)
                {
                    tmpPosition.x = center.x + unitPositionData.UnitPositions[i].x * tmpArcInnerRadius.x + noOverlapInnerOffset.x;
                    tmpPosition.y = center.y + unitPositionData.UnitPositions[i].y * tmpArcInnerRadius.y + noOverlapInnerOffset.y;
                    tmpPosition.z = noOverlapInnerOffset.z;
                    vh.AddVert(
                        tmpPosition, color, uv,
                        GeoUtils.ZeroV2, GeoUtils.UINormal, GeoUtils.UITangent);

                    tmpPosition.x = center.x + unitPositionData.UnitPositions[i].x * tmpArcOuterRadius.x + noOverlapOuterOffset.x;
                    tmpPosition.y = center.y + unitPositionData.UnitPositions[i].y * tmpArcOuterRadius.y + noOverlapOuterOffset.y;
                    tmpPosition.z = noOverlapOuterOffset.z;
                    vh.AddVert(
                        tmpPosition, color, uv,
                        GeoUtils.ZeroV2, GeoUtils.UINormal, GeoUtils.UITangent);

                    edgesBaseIndex = baseIndex + i * 2;
                    innerBaseIndex = startVertex + i * 2;

                    if (i > 0)
                    {
                        // inner quad
                        vh.AddTriangle(innerBaseIndex - 1, innerBaseIndex + 1, edgesBaseIndex + 3);
                        vh.AddTriangle(edgesBaseIndex + 1, innerBaseIndex - 1, edgesBaseIndex + 3);

                        // outer quad
                        vh.AddTriangle(innerBaseIndex, edgesBaseIndex + 2, innerBaseIndex + 2);
                        vh.AddTriangle(edgesBaseIndex + 2, edgesBaseIndex + 4, innerBaseIndex + 2);
                    }
                }

                // add partial segment antiAliasing
                tmpPosition.x = center.x + arcProperties.EndSegmentUnitPosition.x * tmpArcInnerRadius.x + noOverlapInnerOffset.x;
                tmpPosition.y = center.y + arcProperties.EndSegmentUnitPosition.y * tmpArcInnerRadius.y + noOverlapInnerOffset.y;
                tmpPosition.z = noOverlapInnerOffset.z;
                vh.AddVert(
                    tmpPosition, color, uv,
                    GeoUtils.ZeroV2, GeoUtils.UINormal, GeoUtils.UITangent);

                tmpPosition.x = center.x + arcProperties.EndSegmentUnitPosition.x * tmpArcOuterRadius.x + noOverlapOuterOffset.x;
                tmpPosition.y = center.y + arcProperties.EndSegmentUnitPosition.y * tmpArcOuterRadius.y + noOverlapOuterOffset.y;
                tmpPosition.z = noOverlapOuterOffset.z;
                vh.AddVert(
                    tmpPosition, color, uv,
                    GeoUtils.ZeroV2, GeoUtils.UINormal, GeoUtils.UITangent);

                edgesBaseIndex = baseIndex + arcProperties.AdjustedResolution * 2;
                innerBaseIndex = startVertex + arcProperties.AdjustedResolution * 2;

                // inner quad
                vh.AddTriangle(innerBaseIndex - 1, innerBaseIndex + 1, edgesBaseIndex + 3);
                vh.AddTriangle(edgesBaseIndex + 1, innerBaseIndex - 1, edgesBaseIndex + 3);

                // outer quad
                vh.AddTriangle(innerBaseIndex, edgesBaseIndex + 2, innerBaseIndex + 2);
                vh.AddTriangle(edgesBaseIndex + 2, edgesBaseIndex + 4, innerBaseIndex + 2);

                // skip end antiAliasing if full ring is being generated
                if (arcProperties.Length >= 1.0f)
                {
                    return;
                }

                capsExtensionLength = edgeGradientData.SizeAdd + edgeGradientData.ShadowOffset;

                // add start outer antiAliasing
                tmpPosition.x = center.x + unitPositionData.UnitPositions[0].x * tmpInnerRadius.x + arcProperties.StartTangent.x * capsExtensionLength;
                tmpPosition.y = center.y + unitPositionData.UnitPositions[0].y * tmpInnerRadius.y + arcProperties.StartTangent.y * capsExtensionLength;
                tmpPosition.z = arcProperties.StartTangent.z * capsExtensionLength;
                vh.AddVert(
                    tmpPosition, color, uv,
                    GeoUtils.ZeroV2, GeoUtils.UINormal, GeoUtils.UITangent);


                tmpPosition.x = center.x + unitPositionData.UnitPositions[0].x * tmpOuterRadius.x + arcProperties.StartTangent.x * capsExtensionLength;
                tmpPosition.y = center.y + unitPositionData.UnitPositions[0].y * tmpOuterRadius.y + arcProperties.StartTangent.y * capsExtensionLength;
                tmpPosition.z = 0.0f;
                vh.AddVert(
                    tmpPosition, color, uv,
                    GeoUtils.ZeroV2, GeoUtils.UINormal, GeoUtils.UITangent);

                // add end outer antiAliasing
                tmpPosition.x = center.x + arcProperties.EndSegmentUnitPosition.x * tmpInnerRadius.x + arcProperties.EndTangent.x * capsExtensionLength;
                tmpPosition.y = center.y + arcProperties.EndSegmentUnitPosition.y * tmpInnerRadius.y + arcProperties.EndTangent.y * capsExtensionLength;
                tmpPosition.z = arcProperties.EndTangent.z * capsExtensionLength;
                vh.AddVert(
                    tmpPosition, color, uv,
                    GeoUtils.ZeroV2, GeoUtils.UINormal, GeoUtils.UITangent);

                tmpPosition.x = center.x + arcProperties.EndSegmentUnitPosition.x * tmpOuterRadius.x + arcProperties.EndTangent.x * capsExtensionLength;
                tmpPosition.y = center.y + arcProperties.EndSegmentUnitPosition.y * tmpOuterRadius.y + arcProperties.EndTangent.y * capsExtensionLength;
                tmpPosition.z = arcProperties.EndTangent.z * capsExtensionLength;
                vh.AddVert(
                    tmpPosition, color, uv,
                    GeoUtils.ZeroV2, GeoUtils.UINormal, GeoUtils.UITangent);

                if (arcProperties.Direction == ArcProperties.ArcDirection.Backward)
                {
                    tmpOuterRadius.x += edgeGradientData.SizeAdd;
                    tmpOuterRadius.y += edgeGradientData.SizeAdd;

                    tmpInnerRadius.x -= edgeGradientData.SizeAdd;
                    tmpInnerRadius.y -= edgeGradientData.SizeAdd;
                }
                else
                {
                    tmpOuterRadius.x -= edgeGradientData.SizeAdd;
                    tmpOuterRadius.y -= edgeGradientData.SizeAdd;

                    tmpInnerRadius.x += edgeGradientData.SizeAdd;
                    tmpInnerRadius.y += edgeGradientData.SizeAdd;
                }

                // add start inner antiAliasing
                tmpPosition.x = center.x + unitPositionData.UnitPositions[0].x * tmpInnerRadius.x + arcProperties.StartTangent.x * capsExtensionLength;
                tmpPosition.y = center.y + unitPositionData.UnitPositions[0].y * tmpInnerRadius.y + arcProperties.StartTangent.y * capsExtensionLength;
                tmpPosition.z = arcProperties.StartTangent.z * capsExtensionLength;
                vh.AddVert(
                    tmpPosition, color, uv,
                    GeoUtils.ZeroV2, GeoUtils.UINormal, GeoUtils.UITangent);

                tmpPosition.x = center.x + unitPositionData.UnitPositions[0].x * tmpOuterRadius.x + arcProperties.StartTangent.x * capsExtensionLength;
                tmpPosition.y = center.y + unitPositionData.UnitPositions[0].y * tmpOuterRadius.y + arcProperties.StartTangent.y * capsExtensionLength;
                tmpPosition.z = arcProperties.StartTangent.z * capsExtensionLength;
                vh.AddVert(
                    tmpPosition, color, uv,
                    GeoUtils.ZeroV2, GeoUtils.UINormal, GeoUtils.UITangent);

                // add end inner antiAliasing
                tmpPosition.x = center.x + arcProperties.EndSegmentUnitPosition.x * tmpInnerRadius.x + arcProperties.EndTangent.x * capsExtensionLength;
                tmpPosition.y = center.y + arcProperties.EndSegmentUnitPosition.y * tmpInnerRadius.y + arcProperties.EndTangent.y * capsExtensionLength;
                tmpPosition.z = arcProperties.EndTangent.z * capsExtensionLength;
                vh.AddVert(
                    tmpPosition, color, uv,
                    GeoUtils.ZeroV2, GeoUtils.UINormal, GeoUtils.UITangent);

                tmpPosition.x = center.x + arcProperties.EndSegmentUnitPosition.x * tmpOuterRadius.x + arcProperties.EndTangent.x * capsExtensionLength;
                tmpPosition.y = center.y + arcProperties.EndSegmentUnitPosition.y * tmpOuterRadius.y + arcProperties.EndTangent.y * capsExtensionLength;
                tmpPosition.z = arcProperties.EndTangent.z * capsExtensionLength;
                vh.AddVert(
                    tmpPosition, color, uv,
                    GeoUtils.ZeroV2, GeoUtils.UINormal, GeoUtils.UITangent);

                int currentVertCount = vh.currentVertCount;

                // add end antiAliasing triangles

                // center
                vh.AddTriangle(currentVertCount - 1, currentVertCount - 2, innerBaseIndex + 1);
                vh.AddTriangle(currentVertCount - 1, innerBaseIndex + 1, innerBaseIndex + 2);

                // inner
                vh.AddTriangle(edgesBaseIndex + 3, innerBaseIndex + 1, currentVertCount - 6);
                vh.AddTriangle(currentVertCount - 6, innerBaseIndex + 1, currentVertCount - 2);

                // outer
                vh.AddTriangle(edgesBaseIndex + 4, currentVertCount - 5, innerBaseIndex + 2);
                vh.AddTriangle(currentVertCount - 5, currentVertCount - 1, innerBaseIndex + 2);


                // add start antiAliasing triangles

                // center
                vh.AddTriangle(currentVertCount - 3, numVertices, currentVertCount - 4);
                vh.AddTriangle(currentVertCount - 3, numVertices + 1, numVertices);

                // inner
                vh.AddTriangle(currentVertCount - 4, numVertices, currentVertCount - 8);
                vh.AddTriangle(innerBaseIndex + 3, currentVertCount - 8, numVertices);

                // outer
                vh.AddTriangle(currentVertCount - 7, innerBaseIndex + 4, numVertices + 1);
                vh.AddTriangle(currentVertCount - 7, numVertices + 1, currentVertCount - 3);
            }
        }
Ejemplo n.º 11
0
        public static void AddSegment(
            ref VertexHelper vh,
            Vector2 center,
            Vector2 radius,
            UIShapesKit.Ellipses.EllipseProperties circleProperties,
            ArcProperties arcProperties,
            Color32 color,
            Vector2 uv,
            ref GeoUtils.UnitPositionData unitPositionData,
            GeoUtils.EdgeGradientData edgeGradientData
            )
        {
            if (arcProperties.Length <= 0.0f)
            {
                return;
            }

            bool isReversed = arcProperties.Direction == ArcProperties.ArcDirection.Backward;

            int reversedZeroForwardMinus = isReversed ? 0 : -1;
            int reversedMinusForwardZero = isReversed ? -1 : 0;

            int reversed1Forward2 = isReversed ? 1 : 2;
            int reversed2Forward1 = isReversed ? 2 : 1;

            int reversed1Forward0 = isReversed ? 1 : 0;
            int reversed0Forward1 = isReversed ? 0 : 1;

            GeoUtils.SetUnitPositionData(
                ref unitPositionData,
                circleProperties.AdjustedResolution,
                arcProperties.AdjustedBaseAngle,
                arcProperties.AdjustedDirection
                );

            int numVertices = vh.currentVertCount;

            tmpOuterRadius.x = (radius.x + edgeGradientData.ShadowOffset) * edgeGradientData.InnerScale;
            tmpOuterRadius.y = (radius.y + edgeGradientData.ShadowOffset) * edgeGradientData.InnerScale;

            float capsExtensionLength = edgeGradientData.ShadowOffset * edgeGradientData.InnerScale;

            tmpOffsetCenter.x = center.x + arcProperties.CenterNormal.x * radius.x * (edgeGradientData.InnerScale - 1.0f) * 0.2f;
            tmpOffsetCenter.y = center.y + arcProperties.CenterNormal.y * radius.y * (edgeGradientData.InnerScale - 1.0f) * 0.2f;
            tmpOffsetCenter.z = 0.0f;

            if (arcProperties.Length >= 1.0f)
            {
                capsExtensionLength = 0.0f;
                tmpOffsetCenter     = center;
            }

            vh.AddVert(
                tmpOffsetCenter + arcProperties.CenterNormal * capsExtensionLength,
                color, uv, GeoUtils.ZeroV2, GeoUtils.UINormal, GeoUtils.UITangent);

            tmpPosition.x = tmpOffsetCenter.x + unitPositionData.UnitPositions[0].x * tmpOuterRadius.x + arcProperties.StartTangent.x * capsExtensionLength;
            tmpPosition.y = tmpOffsetCenter.y + unitPositionData.UnitPositions[0].y * tmpOuterRadius.y + arcProperties.StartTangent.y * capsExtensionLength;
            tmpPosition.z = tmpOffsetCenter.z;
            vh.AddVert(tmpPosition, color, uv, GeoUtils.ZeroV2, GeoUtils.UINormal, GeoUtils.UITangent);

            for (int i = 1; i < arcProperties.AdjustedResolution; i++)
            {
                tmpPosition.x = tmpOffsetCenter.x + unitPositionData.UnitPositions[i].x * tmpOuterRadius.x;
                tmpPosition.y = tmpOffsetCenter.y + unitPositionData.UnitPositions[i].y * tmpOuterRadius.y;
                tmpPosition.z = tmpOffsetCenter.z;
                vh.AddVert(tmpPosition, color, uv, GeoUtils.ZeroV2, GeoUtils.UINormal, GeoUtils.UITangent);

                vh.AddTriangle(numVertices, numVertices + i + reversedZeroForwardMinus, numVertices + i + reversedMinusForwardZero);
            }

            int lastFullIndex = numVertices + arcProperties.AdjustedResolution;

            // add last partial segment
            tmpPosition.x = tmpOffsetCenter.x + arcProperties.EndSegmentUnitPosition.x * tmpOuterRadius.x + arcProperties.EndTangent.x * capsExtensionLength;
            tmpPosition.y = tmpOffsetCenter.y + arcProperties.EndSegmentUnitPosition.y * tmpOuterRadius.y + arcProperties.EndTangent.y * capsExtensionLength;
            tmpPosition.z = tmpOffsetCenter.z + +arcProperties.EndTangent.z * capsExtensionLength;
            vh.AddVert(tmpPosition, color, uv, GeoUtils.ZeroV2, GeoUtils.UINormal, GeoUtils.UITangent);

            if (isReversed)
            {
                vh.AddTriangle(numVertices, lastFullIndex, lastFullIndex - 1);
                vh.AddTriangle(numVertices, lastFullIndex + 1, lastFullIndex);
            }
            else
            {
                vh.AddTriangle(numVertices, lastFullIndex - 1, lastFullIndex);
                vh.AddTriangle(numVertices, lastFullIndex, lastFullIndex + 1);
            }


            if (edgeGradientData.IsActive)
            {
                radius.x += edgeGradientData.SizeAdd + edgeGradientData.ShadowOffset;
                radius.y += edgeGradientData.SizeAdd + edgeGradientData.ShadowOffset;
                color.a   = 0;

                tmpPosition.x = center.x + unitPositionData.UnitPositions[0].x * radius.x;
                tmpPosition.y = center.y + unitPositionData.UnitPositions[0].y * radius.y;
                tmpPosition.z = 0.0f;
                vh.AddVert(tmpPosition, color, uv, GeoUtils.ZeroV2, GeoUtils.UINormal, GeoUtils.UITangent);
                int innerBase, outerBase;
                for (int i = 1; i <= arcProperties.AdjustedResolution; i++)
                {
                    if (i < arcProperties.AdjustedResolution)
                    {
                        tmpPosition.x = center.x + unitPositionData.UnitPositions[i].x * radius.x;
                        tmpPosition.y = center.y + unitPositionData.UnitPositions[i].y * radius.y;
                        tmpPosition.z = 0.0f;
                        vh.AddVert(tmpPosition, color, uv, GeoUtils.ZeroV2, GeoUtils.UINormal, GeoUtils.UITangent);
                    }
                    else
                    {
                        tmpPosition.x = center.x + arcProperties.EndSegmentUnitPosition.x * radius.x;
                        tmpPosition.y = center.y + arcProperties.EndSegmentUnitPosition.y * radius.y;
                        tmpPosition.z = 0.0f;
                        vh.AddVert(tmpPosition, color, uv, GeoUtils.ZeroV2, GeoUtils.UINormal, GeoUtils.UITangent);
                    }

                    innerBase = numVertices + i;
                    outerBase = innerBase + arcProperties.AdjustedResolution;

                    vh.AddTriangle(outerBase + 2, innerBase + reversed0Forward1, innerBase + reversed1Forward0);
                    vh.AddTriangle(innerBase, outerBase + reversed2Forward1, outerBase + reversed1Forward2);
                }

                if (arcProperties.Length >= 1.0f)
                {
                    return;
                }

                tmpOuterRadius.x = edgeGradientData.SizeAdd + edgeGradientData.ShadowOffset;
                tmpOuterRadius.y = tmpOuterRadius.x;

                // add start outer vertex
                tmpPosition.x = center.x + unitPositionData.UnitPositions[0].x * radius.x + arcProperties.StartTangent.x * tmpOuterRadius.x;
                tmpPosition.y = center.y + unitPositionData.UnitPositions[0].y * radius.y + arcProperties.StartTangent.y * tmpOuterRadius.y;
                tmpPosition.z = 0.0f;
                vh.AddVert(
                    tmpPosition, color, uv,
                    GeoUtils.ZeroV2, GeoUtils.UINormal, GeoUtils.UITangent);

                // add end outer vertex
                tmpPosition.x = center.x + arcProperties.EndSegmentUnitPosition.x * radius.x + arcProperties.EndTangent.x * tmpOuterRadius.x;
                tmpPosition.y = center.y + arcProperties.EndSegmentUnitPosition.y * radius.y + arcProperties.EndTangent.y * tmpOuterRadius.y;
                tmpPosition.z = 0.0f;
                vh.AddVert(
                    tmpPosition, color, uv,
                    GeoUtils.ZeroV2, GeoUtils.UINormal, GeoUtils.UITangent);

                radius.x -= edgeGradientData.SizeAdd;
                radius.y -= edgeGradientData.SizeAdd;

                // add start inner vertex
                tmpPosition.x = center.x + unitPositionData.UnitPositions[0].x * radius.x + arcProperties.StartTangent.x * tmpOuterRadius.x;
                tmpPosition.y = center.y + unitPositionData.UnitPositions[0].y * radius.y + arcProperties.StartTangent.y * tmpOuterRadius.y;
                tmpPosition.z = 0.0f;
                vh.AddVert(
                    tmpPosition, color, uv,
                    GeoUtils.ZeroV2, GeoUtils.UINormal, GeoUtils.UITangent);

                // add end inner vertex
                tmpPosition.x = center.x + arcProperties.EndSegmentUnitPosition.x * radius.x + arcProperties.EndTangent.x * tmpOuterRadius.x;
                tmpPosition.y = center.y + arcProperties.EndSegmentUnitPosition.y * radius.y + arcProperties.EndTangent.y * tmpOuterRadius.y;
                tmpPosition.z = 0.0f;
                vh.AddVert(
                    tmpPosition, color, uv,
                    GeoUtils.ZeroV2, GeoUtils.UINormal, GeoUtils.UITangent);

                // add center extruded vertex
                tmpPosition.x = center.x + arcProperties.CenterNormal.x * tmpOuterRadius.x;
                tmpPosition.y = center.y + arcProperties.CenterNormal.y * tmpOuterRadius.y;
                tmpPosition.z = 0.0f;
                vh.AddVert(
                    tmpPosition, color, uv,
                    GeoUtils.ZeroV2, GeoUtils.UINormal, GeoUtils.UITangent);

                int baseCornersIndex = vh.currentVertCount - 5;
                int baseOuterIndex   = numVertices + arcProperties.AdjustedResolution;
                int secondOuterIndex = numVertices + arcProperties.AdjustedResolution * 2;



                if (isReversed)
                {
                    // start corner
                    vh.AddTriangle(baseCornersIndex, baseCornersIndex + 2, numVertices + 1);
                    vh.AddTriangle(baseCornersIndex, numVertices + 1, baseOuterIndex + 2);

                    // end corner
                    vh.AddTriangle(baseCornersIndex + 1, baseOuterIndex + 1, baseCornersIndex + 3);
                    vh.AddTriangle(baseCornersIndex + 1, secondOuterIndex + 2, baseOuterIndex + 1);

                    // start corner to center
                    vh.AddTriangle(baseCornersIndex + 2, numVertices, numVertices + 1);
                    vh.AddTriangle(baseCornersIndex + 2, baseCornersIndex + 4, numVertices);

                    // end corner to center
                    vh.AddTriangle(baseCornersIndex + 3, baseOuterIndex + 1, baseCornersIndex + 4);
                    vh.AddTriangle(baseCornersIndex + 4, baseOuterIndex + 1, numVertices);
                }
                else
                {
                    // start corner
                    vh.AddTriangle(baseCornersIndex, numVertices + 1, baseCornersIndex + 2);
                    vh.AddTriangle(baseCornersIndex, baseOuterIndex + 2, numVertices + 1);

                    // end corner
                    vh.AddTriangle(baseCornersIndex + 1, baseCornersIndex + 3, baseOuterIndex + 1);
                    vh.AddTriangle(baseCornersIndex + 1, baseOuterIndex + 1, secondOuterIndex + 2);

                    // start corner to center
                    vh.AddTriangle(baseCornersIndex + 2, numVertices + 1, numVertices);
                    vh.AddTriangle(baseCornersIndex + 2, numVertices, baseCornersIndex + 4);

                    // end corner to center
                    vh.AddTriangle(baseCornersIndex + 3, baseCornersIndex + 4, baseOuterIndex + 1);
                    vh.AddTriangle(baseCornersIndex + 4, numVertices, baseOuterIndex + 1);
                }
            }
        }
Ejemplo n.º 12
0
        public static void AddPolygon(
            ref VertexHelper vh,
            PolygonProperties polygonProperties,
            PointsList.PointListProperties pointListProperties,
            Vector2 positionOffset,
            Color32 color,
            Vector2 uv,
            ref PointsList.PointsData pointsData,
            GeoUtils.EdgeGradientData edgeGradientData
            )
        {
            pointListProperties.SetPoints();
            PointsList.SetLineData(pointListProperties, ref pointsData);

            int numVertices      = vh.currentVertCount;
            int firstOuterVertex = vh.currentVertCount + polygonProperties.CutoutProperties.Resolution - 1;

            bool usesCutout = polygonProperties.CenterType == PolygonProperties.CenterTypes.Cutout;

            if (usesCutout)
            {
                float cutoutOffsetDistance = polygonProperties.CutoutProperties.Radius - edgeGradientData.ShadowOffset;
                cutoutOffsetDistance += Mathf.LerpUnclamped(
                    pointsData.PositionNormals[0].magnitude * edgeGradientData.ShadowOffset * 3.0f,
                    0.0f,
                    edgeGradientData.InnerScale
                    );

                for (int i = 0; i < polygonProperties.CutoutProperties.Resolution; i++)
                {
                    tmpPos.x =
                        polygonProperties.AdjustedCenter.x +
                        positionOffset.x +
                        polygonProperties.CutoutProperties.UnitPositionData.UnitPositions[i].x * cutoutOffsetDistance;
                    tmpPos.y =
                        polygonProperties.AdjustedCenter.y +
                        positionOffset.y +
                        polygonProperties.CutoutProperties.UnitPositionData.UnitPositions[i].y * cutoutOffsetDistance;
                    tmpPos.z = 0.0f;

                    vh.AddVert(
                        tmpPos,
                        color, uv, GeoUtils.ZeroV2, GeoUtils.UINormal, GeoUtils.UITangent
                        );
                }
            }
            else
            {
                // add center
                tmpPos.x = polygonProperties.AdjustedCenter.x + positionOffset.x;
                tmpPos.y = polygonProperties.AdjustedCenter.y + positionOffset.y;
                tmpPos.z = 0.0f;

                vh.AddVert(
                    tmpPos,
                    color, uv, GeoUtils.ZeroV2, GeoUtils.UINormal, GeoUtils.UITangent
                    );
            }

            // add first position
            tmpPos.x = positionOffset.x + Mathf.LerpUnclamped(
                polygonProperties.AdjustedCenter.x,
                pointsData.Positions[0].x + pointsData.PositionNormals[0].x * edgeGradientData.ShadowOffset,
                edgeGradientData.InnerScale
                );
            tmpPos.y = positionOffset.y + Mathf.LerpUnclamped(
                polygonProperties.AdjustedCenter.y,
                pointsData.Positions[0].y + pointsData.PositionNormals[0].y * edgeGradientData.ShadowOffset,
                edgeGradientData.InnerScale
                );
            tmpPos.z = 0.0f;

            vh.AddVert(
                tmpPos,
                color, uv, GeoUtils.ZeroV2, GeoUtils.UINormal, GeoUtils.UITangent
                );

            for (int i = 1; i < pointsData.NumPositions; i++)
            {
                tmpPos.x = positionOffset.x + Mathf.LerpUnclamped(
                    polygonProperties.AdjustedCenter.x,
                    pointsData.Positions[i].x + pointsData.PositionNormals[i].x * edgeGradientData.ShadowOffset,
                    edgeGradientData.InnerScale
                    );
                tmpPos.y = positionOffset.y + Mathf.LerpUnclamped(
                    polygonProperties.AdjustedCenter.y,
                    pointsData.Positions[i].y + pointsData.PositionNormals[i].y * edgeGradientData.ShadowOffset,
                    edgeGradientData.InnerScale
                    );

                vh.AddVert(
                    tmpPos,
                    color, uv, GeoUtils.ZeroV2, GeoUtils.UINormal, GeoUtils.UITangent
                    );

                if (!usesCutout)
                {
                    vh.AddTriangle(numVertices, numVertices + i, numVertices + i + 1);
                }
            }

            // add cutout indices
            if (usesCutout)
            {
                for (int i = 1; i < pointsData.NumPositions; i++)
                {
                    vh.AddTriangle(
                        numVertices + GeoUtils.SimpleMap(i, pointsData.NumPositions, polygonProperties.CutoutProperties.Resolution),
                        firstOuterVertex + i,
                        firstOuterVertex + i + 1
                        );
                }

                for (int i = 1; i < polygonProperties.CutoutProperties.Resolution; i++)
                {
                    vh.AddTriangle(
                        numVertices + i,
                        numVertices + i - 1,
                        firstOuterVertex + Mathf.CeilToInt(GeoUtils.SimpleMap((float)i, (float)polygonProperties.CutoutProperties.Resolution, (float)pointsData.NumPositions))
                        );
                }
            }

            // add last triangle
            if (usesCutout)
            {
                vh.AddTriangle(
                    numVertices,
                    firstOuterVertex + pointsData.NumPositions,
                    firstOuterVertex + 1
                    );

                vh.AddTriangle(
                    numVertices,
                    firstOuterVertex,
                    firstOuterVertex + pointsData.NumPositions
                    );
            }
            else
            {
                vh.AddTriangle(numVertices, numVertices + pointsData.NumPositions, numVertices + 1);
            }

            if (edgeGradientData.IsActive)
            {
                color.a = 0;

                int outerFirstIndex = numVertices + pointsData.NumPositions;

                if (usesCutout)
                {
                    outerFirstIndex = firstOuterVertex + pointsData.NumPositions;
                }
                else
                {
                    firstOuterVertex = numVertices;
                }

                float offset = edgeGradientData.SizeAdd + edgeGradientData.ShadowOffset;

                vh.AddVert(positionOffset + pointsData.Positions[0] + pointsData.PositionNormals[0] * offset,
                           color, uv, GeoUtils.ZeroV2, GeoUtils.UINormal, GeoUtils.UITangent);

                for (int i = 1; i < pointsData.NumPositions; i++)
                {
                    vh.AddVert(positionOffset + pointsData.Positions[i] + pointsData.PositionNormals[i] * offset,
                               color, uv, GeoUtils.ZeroV2, GeoUtils.UINormal, GeoUtils.UITangent);

                    vh.AddTriangle(firstOuterVertex + i + 1, outerFirstIndex + i, outerFirstIndex + i + 1);
                    vh.AddTriangle(firstOuterVertex + i + 1, outerFirstIndex + i + 1, firstOuterVertex + i + 2);
                }

                // fill last outer quad
                vh.AddTriangle(firstOuterVertex + 1, outerFirstIndex, outerFirstIndex + 1);
                vh.AddTriangle(firstOuterVertex + 2, firstOuterVertex + 1, outerFirstIndex + 1);


                if (usesCutout)
                {
                    float radius = (polygonProperties.CutoutProperties.Radius - offset);
                    for (int i = 0; i < polygonProperties.CutoutProperties.Resolution; i++)
                    {
                        tmpPos.x =
                            polygonProperties.AdjustedCenter.x +
                            positionOffset.x +
                            polygonProperties.CutoutProperties.UnitPositionData.UnitPositions[i].x * radius;
                        tmpPos.y =
                            polygonProperties.AdjustedCenter.y +
                            positionOffset.y +
                            polygonProperties.CutoutProperties.UnitPositionData.UnitPositions[i].y * radius;
                        tmpPos.z = 0.0f;

                        vh.AddVert(
                            tmpPos,
                            color, uv, GeoUtils.ZeroV2, GeoUtils.UINormal, GeoUtils.UITangent
                            );
                    }

                    for (int i = 1; i < polygonProperties.CutoutProperties.Resolution; i++)
                    {
                        vh.AddTriangle(
                            numVertices + i - 1,
                            numVertices + i,
                            outerFirstIndex + pointsData.NumPositions + i
                            );

                        vh.AddTriangle(
                            numVertices + i,
                            outerFirstIndex + pointsData.NumPositions + i + 1,
                            outerFirstIndex + pointsData.NumPositions + i
                            );
                    }

                    vh.AddTriangle(
                        firstOuterVertex,
                        numVertices,
                        outerFirstIndex + pointsData.NumPositions + polygonProperties.CutoutProperties.Resolution
                        );

                    vh.AddTriangle(
                        numVertices,
                        outerFirstIndex + pointsData.NumPositions + 1,
                        outerFirstIndex + pointsData.NumPositions + polygonProperties.CutoutProperties.Resolution
                        );
                }
            }
        }
Ejemplo n.º 13
0
        public static void AddRing(
            ref VertexHelper vh,
            Vector2 center,
            Vector2 radius,
            GeoUtils.OutlineProperties outlineProperties,
            EllipseProperties ellipseProperties,
            Color32 color,
            Vector2 uv,
            ref GeoUtils.UnitPositionData unitPositionData,
            GeoUtils.EdgeGradientData edgeGradientData
            )
        {
            GeoUtils.SetUnitPositionData(
                ref unitPositionData,
                ellipseProperties.AdjustedResolution,
                ellipseProperties.BaseAngle
                );

            float halfLineWeightOffset = (outlineProperties.HalfLineWeight + edgeGradientData.ShadowOffset) * edgeGradientData.InnerScale;

            tmpInnerRadius.x = radius.x + outlineProperties.GetCenterDistace() - halfLineWeightOffset;
            tmpInnerRadius.y = radius.y + outlineProperties.GetCenterDistace() - halfLineWeightOffset;

            tmpOuterRadius.x = radius.x + outlineProperties.GetCenterDistace() + halfLineWeightOffset;
            tmpOuterRadius.y = radius.y + outlineProperties.GetCenterDistace() + halfLineWeightOffset;

            int numVertices = vh.currentVertCount;
            int startVertex = numVertices - 1;

            int baseIndex;

            float uvMaxResolution = (float)ellipseProperties.AdjustedResolution;

            for (int i = 0; i < ellipseProperties.AdjustedResolution; i++)
            {
                uv.x = i / uvMaxResolution;

                tmpVertPos.x = center.x + unitPositionData.UnitPositions[i].x * tmpInnerRadius.x;
                tmpVertPos.y = center.y + unitPositionData.UnitPositions[i].y * tmpInnerRadius.y;
                tmpVertPos.z = 0.0f;
                uv.y         = 0.0f;
                vh.AddVert(tmpVertPos, color, uv, GeoUtils.ZeroV2, GeoUtils.UINormal, GeoUtils.UITangent);

                tmpVertPos.x = center.x + unitPositionData.UnitPositions[i].x * tmpOuterRadius.x;
                tmpVertPos.y = center.y + unitPositionData.UnitPositions[i].y * tmpOuterRadius.y;
                tmpVertPos.z = 0.0f;
                uv.y         = 1.0f;
                vh.AddVert(tmpVertPos, color, uv, GeoUtils.ZeroV2, GeoUtils.UINormal, GeoUtils.UITangent);

                if (i > 0)
                {
                    baseIndex = startVertex + i * 2;
                    vh.AddTriangle(baseIndex - 1, baseIndex, baseIndex + 1);
                    vh.AddTriangle(baseIndex, baseIndex + 2, baseIndex + 1);
                }
            }

            // add last quad
            {
                uv.x = 1.0f;

                tmpVertPos.x = center.x + unitPositionData.UnitPositions[0].x * tmpInnerRadius.x;
                tmpVertPos.y = center.y + unitPositionData.UnitPositions[0].y * tmpInnerRadius.y;
                tmpVertPos.z = 0.0f;
                uv.y         = 0.0f;
                vh.AddVert(tmpVertPos, color, uv, GeoUtils.ZeroV2, GeoUtils.UINormal, GeoUtils.UITangent);

                tmpVertPos.x = center.x + unitPositionData.UnitPositions[0].x * tmpOuterRadius.x;
                tmpVertPos.y = center.y + unitPositionData.UnitPositions[0].y * tmpOuterRadius.y;
                tmpVertPos.z = 0.0f;
                uv.y         = 1.0f;
                vh.AddVert(tmpVertPos, color, uv, GeoUtils.ZeroV2, GeoUtils.UINormal, GeoUtils.UITangent);

                baseIndex = startVertex + ellipseProperties.AdjustedResolution * 2;
                vh.AddTriangle(baseIndex - 1, baseIndex, baseIndex + 1);
                vh.AddTriangle(baseIndex, baseIndex + 2, baseIndex + 1);
            }

            if (edgeGradientData.IsActive)
            {
                halfLineWeightOffset = outlineProperties.HalfLineWeight + edgeGradientData.ShadowOffset + edgeGradientData.SizeAdd;

                tmpInnerRadius.x = radius.x + outlineProperties.GetCenterDistace() - halfLineWeightOffset;
                tmpInnerRadius.y = radius.y + outlineProperties.GetCenterDistace() - halfLineWeightOffset;

                tmpOuterRadius.x = radius.x + outlineProperties.GetCenterDistace() + halfLineWeightOffset;
                tmpOuterRadius.y = radius.y + outlineProperties.GetCenterDistace() + halfLineWeightOffset;

                color.a = 0;

                int edgesBaseIndex;
                int innerBaseIndex;

                for (int i = 0; i < ellipseProperties.AdjustedResolution; i++)
                {
                    uv.x = i / uvMaxResolution;

                    tmpVertPos.x = center.x + unitPositionData.UnitPositions[i].x * tmpInnerRadius.x;
                    tmpVertPos.y = center.y + unitPositionData.UnitPositions[i].y * tmpInnerRadius.y;
                    tmpVertPos.z = 0.0f;
                    uv.y         = 0.0f;
                    vh.AddVert(tmpVertPos, color, uv, GeoUtils.ZeroV2, GeoUtils.UINormal, GeoUtils.UITangent);

                    tmpVertPos.x = center.x + unitPositionData.UnitPositions[i].x * tmpOuterRadius.x;
                    tmpVertPos.y = center.y + unitPositionData.UnitPositions[i].y * tmpOuterRadius.y;
                    tmpVertPos.z = 0.0f;
                    uv.y         = 1.0f;
                    vh.AddVert(tmpVertPos, color, uv, GeoUtils.ZeroV2, GeoUtils.UINormal, GeoUtils.UITangent);

                    edgesBaseIndex = baseIndex + i * 2;
                    innerBaseIndex = startVertex + i * 2;

                    if (i > 0)
                    {
                        // inner quad
                        vh.AddTriangle(innerBaseIndex - 1, innerBaseIndex + 1, edgesBaseIndex + 3);
                        vh.AddTriangle(edgesBaseIndex + 1, innerBaseIndex - 1, edgesBaseIndex + 3);

                        // outer quad
                        vh.AddTriangle(innerBaseIndex, edgesBaseIndex + 2, innerBaseIndex + 2);
                        vh.AddTriangle(edgesBaseIndex + 2, edgesBaseIndex + 4, innerBaseIndex + 2);
                    }
                }

                // add last quads
                {
                    uv.x = 1.0f;

                    tmpVertPos.x = center.x + unitPositionData.UnitPositions[0].x * tmpInnerRadius.x;
                    tmpVertPos.y = center.y + unitPositionData.UnitPositions[0].y * tmpInnerRadius.y;
                    tmpVertPos.z = 0.0f;
                    uv.y         = 0.0f;
                    vh.AddVert(tmpVertPos, color, uv, GeoUtils.ZeroV2, GeoUtils.UINormal, GeoUtils.UITangent);

                    tmpVertPos.x = center.x + unitPositionData.UnitPositions[0].x * tmpOuterRadius.x;
                    tmpVertPos.y = center.y + unitPositionData.UnitPositions[0].y * tmpOuterRadius.y;
                    tmpVertPos.z = 0.0f;
                    uv.y         = 1.0f;
                    vh.AddVert(tmpVertPos, color, uv, GeoUtils.ZeroV2, GeoUtils.UINormal, GeoUtils.UITangent);

                    edgesBaseIndex = baseIndex + ellipseProperties.AdjustedResolution * 2;
                    innerBaseIndex = startVertex + ellipseProperties.AdjustedResolution * 2;

                    // inner quad
                    vh.AddTriangle(innerBaseIndex - 1, innerBaseIndex + 1, edgesBaseIndex + 3);
                    vh.AddTriangle(edgesBaseIndex + 1, innerBaseIndex - 1, edgesBaseIndex + 3);

                    // outer quad
                    vh.AddTriangle(innerBaseIndex, edgesBaseIndex + 2, innerBaseIndex + 2);
                    vh.AddTriangle(edgesBaseIndex + 2, edgesBaseIndex + 4, innerBaseIndex + 2);
                }
            }
        }
Ejemplo n.º 14
0
        public static void AddCircle(
            ref VertexHelper vh,
            Vector2 center,
            Vector2 radius,
            EllipseProperties ellipseProperties,
            Color32 color,
            Vector2 uv,
            ref GeoUtils.UnitPositionData unitPositionData,
            GeoUtils.EdgeGradientData edgeGradientData
            )
        {
            GeoUtils.SetUnitPositionData(
                ref unitPositionData,
                ellipseProperties.AdjustedResolution,
                ellipseProperties.BaseAngle
                );

            int numVertices = vh.currentVertCount;

            tmpUVPos.x = 0.5f;
            tmpUVPos.y = 0.5f;
            vh.AddVert(center, color, tmpUVPos, GeoUtils.ZeroV2, GeoUtils.UINormal, GeoUtils.UITangent);

            // add first circle vertex
            tmpVertPos.x = center.x + unitPositionData.UnitPositions[0].x * (radius.x + edgeGradientData.ShadowOffset) * edgeGradientData.InnerScale;
            tmpVertPos.y = center.y + unitPositionData.UnitPositions[0].y * (radius.y + edgeGradientData.ShadowOffset) * edgeGradientData.InnerScale;
            tmpVertPos.z = 0.0f;

            tmpUVPos.x = (unitPositionData.UnitPositions[0].x * edgeGradientData.InnerScale + 1.0f) * 0.5f;
            tmpUVPos.y = (unitPositionData.UnitPositions[0].y * edgeGradientData.InnerScale + 1.0f) * 0.5f;
            vh.AddVert(tmpVertPos, color, tmpUVPos, GeoUtils.ZeroV2, GeoUtils.UINormal, GeoUtils.UITangent);

            for (int i = 1; i < ellipseProperties.AdjustedResolution; i++)
            {
                tmpVertPos.x = center.x + unitPositionData.UnitPositions[i].x * (radius.x + edgeGradientData.ShadowOffset) * edgeGradientData.InnerScale;
                tmpVertPos.y = center.y + unitPositionData.UnitPositions[i].y * (radius.y + edgeGradientData.ShadowOffset) * edgeGradientData.InnerScale;
                tmpVertPos.z = 0.0f;

                tmpUVPos.x = (unitPositionData.UnitPositions[i].x * edgeGradientData.InnerScale + 1.0f) * 0.5f;
                tmpUVPos.y = (unitPositionData.UnitPositions[i].y * edgeGradientData.InnerScale + 1.0f) * 0.5f;
                vh.AddVert(tmpVertPos, color, tmpUVPos, GeoUtils.ZeroV2, GeoUtils.UINormal, GeoUtils.UITangent);

                vh.AddTriangle(numVertices, numVertices + i, numVertices + i + 1);
            }

            vh.AddTriangle(numVertices, numVertices + ellipseProperties.AdjustedResolution, numVertices + 1);

            if (edgeGradientData.IsActive)
            {
                radius.x += edgeGradientData.ShadowOffset + edgeGradientData.SizeAdd;
                radius.y += edgeGradientData.ShadowOffset + edgeGradientData.SizeAdd;

                int outerFirstIndex = numVertices + ellipseProperties.AdjustedResolution;

                color.a = 0;

                // add first point
                tmpVertPos.x = center.x + unitPositionData.UnitPositions[0].x * radius.x;
                tmpVertPos.y = center.y + unitPositionData.UnitPositions[0].y * radius.y;
                tmpVertPos.z = 0.0f;

                tmpUVPos.x = (unitPositionData.UnitPositions[0].x + 1.0f) * 0.5f;
                tmpUVPos.y = (unitPositionData.UnitPositions[0].y + 1.0f) * 0.5f;
                vh.AddVert(tmpVertPos, color, tmpUVPos, GeoUtils.ZeroV2, GeoUtils.UINormal, GeoUtils.UITangent);

                for (int i = 1; i < ellipseProperties.AdjustedResolution; i++)
                {
                    tmpVertPos.x = center.x + unitPositionData.UnitPositions[i].x * radius.x;
                    tmpVertPos.y = center.y + unitPositionData.UnitPositions[i].y * radius.y;
                    tmpVertPos.z = 0.0f;

                    tmpUVPos.x = (unitPositionData.UnitPositions[i].x + 1.0f) * 0.5f;
                    tmpUVPos.y = (unitPositionData.UnitPositions[i].y + 1.0f) * 0.5f;
                    vh.AddVert(tmpVertPos, color, tmpUVPos, GeoUtils.ZeroV2, GeoUtils.UINormal, GeoUtils.UITangent);

                    vh.AddTriangle(numVertices + i + 1, outerFirstIndex + i, outerFirstIndex + i + 1);
                    vh.AddTriangle(numVertices + i + 1, outerFirstIndex + i + 1, numVertices + i + 2);
                }

                vh.AddTriangle(numVertices + 1, outerFirstIndex, outerFirstIndex + 1);
                vh.AddTriangle(numVertices + 2, numVertices + 1, outerFirstIndex + 1);
            }
        }