public void UpdateAttribute(DataAttribute attribute) { Attribute = attribute; attributeLabel.text = Attribute.Name; UpdateTickLabels(); }
public int[] GenerateIndices() { dataAttributes.TryGetValue(IATKProperty.X, out DataAttribute xAttribute); dataAttributes.TryGetValue(IATKProperty.Y, out DataAttribute yAttribute); // Create our 2D list of points from x and y attributes int numPoints = xAttribute.Length; Vector2[] allPoints = new Vector2[numPoints]; for (int i = 0; i < numPoints; i++) { allPoints[i].x = xAttribute.Data[i]; allPoints[i].y = yAttribute.Data[i]; } List <int> triangles = new List <int>(); // Get the attribute that we're grouping by DataAttribute grouping = ExpressoParser.ParseExpression(VisualisationReference, VisualisationReference.Group); DataAttribute piecing = ExpressoParser.ParseExpression(VisualisationReference, VisualisationReference.Piece); int dataIdx = 0; int vertexIdx = 0; foreach (int group in grouping.ReverseLevels.Keys) { foreach (int piece in piecing.ReverseLevels.Keys) { // Create a smaller list of points just for this group List <Vector2> pointsList = new List <Vector2>(); for (int i = dataIdx; i < numPoints; i++) { if (grouping.Data[i] != group || piecing.Data[i] != piece) { dataIdx = i; break; } pointsList.Add(allPoints[i]); } if (pointsList.Count == 0) { continue; } Vector2[] points = pointsList.ToArray(); Triangulator triangulator = new Triangulator(points); int[] tris = triangulator.Triangulate(); bool isClockwise = UtilMath.IsPointListClockwise(points); // Front vertices for (int i = 0; i < tris.Length; i += 3) { triangles.Add(vertexIdx + tris[i]); triangles.Add(vertexIdx + tris[i + 1]); triangles.Add(vertexIdx + tris[i + 2]); } // Back vertices for (int i = 0; i < tris.Length; i += 3) { triangles.Add(numPoints + vertexIdx + tris[i + 2]); triangles.Add(numPoints + vertexIdx + tris[i + 1]); triangles.Add(numPoints + vertexIdx + tris[i]); } for (int i = 0; i < points.Length; i++) { int n = (i + 1) % points.Length; triangles.Add(vertexIdx + n); triangles.Add(vertexIdx + i + numPoints); triangles.Add(vertexIdx + i); triangles.Add(vertexIdx + n); triangles.Add(vertexIdx + i + numPoints); triangles.Add(vertexIdx + n + numPoints); } vertexIdx += pointsList.Count; } } return(triangles.ToArray()); }