public static void AddArcRing( ref VertexHelper vh, Vector2 center, Vector2 radius, ShapeUtils.Ellipses.EllipseProperties ellipseProperties, ArcProperties arcProperties, UI.GeoUtils.OutlineProperties outlineProperties, Color32 color, Vector2 uv, ref UI.GeoUtils.UnitPositionData unitPositionData, ThisOtherThing.UI.GeoUtils.EdgeGradientData edgeGradientData ) { if (arcProperties.Length <= 0.0f) { return; } UI.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, UI.GeoUtils.ZeroV2, UI.GeoUtils.UINormal, UI.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, UI.GeoUtils.ZeroV2, UI.GeoUtils.UINormal, UI.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, UI.GeoUtils.ZeroV2, UI.GeoUtils.UINormal, UI.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, UI.GeoUtils.ZeroV2, UI.GeoUtils.UINormal, UI.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, UI.GeoUtils.ZeroV2, UI.GeoUtils.UINormal, UI.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, UI.GeoUtils.ZeroV2, UI.GeoUtils.UINormal, UI.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, UI.GeoUtils.ZeroV2, UI.GeoUtils.UINormal, UI.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, UI.GeoUtils.ZeroV2, UI.GeoUtils.UINormal, UI.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, UI.GeoUtils.ZeroV2, UI.GeoUtils.UINormal, UI.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, UI.GeoUtils.ZeroV2, UI.GeoUtils.UINormal, UI.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, UI.GeoUtils.ZeroV2, UI.GeoUtils.UINormal, UI.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, UI.GeoUtils.ZeroV2, UI.GeoUtils.UINormal, UI.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, UI.GeoUtils.ZeroV2, UI.GeoUtils.UINormal, UI.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, UI.GeoUtils.ZeroV2, UI.GeoUtils.UINormal, UI.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, UI.GeoUtils.ZeroV2, UI.GeoUtils.UINormal, UI.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, UI.GeoUtils.ZeroV2, UI.GeoUtils.UINormal, UI.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, UI.GeoUtils.ZeroV2, UI.GeoUtils.UINormal, UI.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, UI.GeoUtils.ZeroV2, UI.GeoUtils.UINormal, UI.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); } }
public static void AddRoundedRectLine( ref VertexHelper vh, Vector2 center, float width, float height, UI.GeoUtils.OutlineProperties outlineProperties, RoundedProperties roundedProperties, Color32 color, Vector2 uv, ref RoundedCornerUnitPositionData cornerUnitPositions, UI.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 ); } }
public static void AddRoundedCap( ref VertexHelper vh, bool isStart, int firstVertIndex, Vector2 position, Vector2 normal, Vector2 capOffset, int invertIndices, LineProperties lineProperties, UI.GeoUtils.OutlineProperties outlineProperties, Color32 color, Vector2 uv, PointsList.PointsData pointsData, ThisOtherThing.UI.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, UI.GeoUtils.ZeroV2, UI.GeoUtils.UINormal, UI.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, UI.GeoUtils.ZeroV2, UI.GeoUtils.UINormal, UI.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, UI.GeoUtils.ZeroV2, UI.GeoUtils.UINormal, UI.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); } } }
public static void AddProjectedCap( ref VertexHelper vh, bool isStart, int firstVertIndex, Vector2 position, Vector2 normal, Vector2 capOffset, int invertIndices, LineProperties lineProperties, UI.GeoUtils.OutlineProperties outlineProperties, Color32 color, Vector2 uv, PointsList.PointsData pointsData, ThisOtherThing.UI.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, UI.GeoUtils.ZeroV2, UI.GeoUtils.UINormal, UI.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, UI.GeoUtils.ZeroV2, UI.GeoUtils.UINormal, UI.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, UI.GeoUtils.ZeroV2, UI.GeoUtils.UINormal, UI.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, UI.GeoUtils.ZeroV2, UI.GeoUtils.UINormal, UI.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); } } }
public static void AddLine( ref VertexHelper vh, LineProperties lineProperties, PointsList.PointListProperties pointListProperties, Vector2 positionOffset, UI.GeoUtils.OutlineProperties outlineProperties, Color32 color, Vector2 uv, ref PointsList.PointsData pointsData, ThisOtherThing.UI.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, UI.GeoUtils.ZeroV2, UI.GeoUtils.UINormal, UI.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, UI.GeoUtils.ZeroV2, UI.GeoUtils.UINormal, UI.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, UI.GeoUtils.ZeroV2, UI.GeoUtils.UINormal, UI.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, UI.GeoUtils.ZeroV2, UI.GeoUtils.UINormal, UI.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, UI.GeoUtils.ZeroV2, UI.GeoUtils.UINormal, UI.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, UI.GeoUtils.ZeroV2, UI.GeoUtils.UINormal, UI.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, UI.GeoUtils.ZeroV2, UI.GeoUtils.UINormal, UI.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, UI.GeoUtils.ZeroV2, UI.GeoUtils.UINormal, UI.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, UI.GeoUtils.ZeroV2, UI.GeoUtils.UINormal, UI.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, UI.GeoUtils.ZeroV2, UI.GeoUtils.UINormal, UI.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, UI.GeoUtils.ZeroV2, UI.GeoUtils.UINormal, UI.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, UI.GeoUtils.ZeroV2, UI.GeoUtils.UINormal, UI.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, UI.GeoUtils.ZeroV2, UI.GeoUtils.UINormal, UI.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, UI.GeoUtils.ZeroV2, UI.GeoUtils.UINormal, UI.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 ); } }
public static void AddRing( ref VertexHelper vh, Vector2 center, Vector2 radius, UI.GeoUtils.OutlineProperties outlineProperties, EllipseProperties ellipseProperties, Color32 color, Vector2 uv, ref UI.GeoUtils.UnitPositionData unitPositionData, ThisOtherThing.UI.GeoUtils.EdgeGradientData edgeGradientData ) { UI.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, UI.GeoUtils.ZeroV2, UI.GeoUtils.UINormal, UI.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, UI.GeoUtils.ZeroV2, UI.GeoUtils.UINormal, UI.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, UI.GeoUtils.ZeroV2, UI.GeoUtils.UINormal, UI.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, UI.GeoUtils.ZeroV2, UI.GeoUtils.UINormal, UI.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, UI.GeoUtils.ZeroV2, UI.GeoUtils.UINormal, UI.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, UI.GeoUtils.ZeroV2, UI.GeoUtils.UINormal, UI.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, UI.GeoUtils.ZeroV2, UI.GeoUtils.UINormal, UI.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, UI.GeoUtils.ZeroV2, UI.GeoUtils.UINormal, UI.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); } } }
public static void AddRectRing( ref VertexHelper vh, UI.GeoUtils.OutlineProperties OutlineProperties, Vector2 center, float width, float height, Color32 color, Vector2 uv, ThisOtherThing.UI.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 ); } }