private List <VisVar> GetVisVarsFromProductionRules() { if (ProductionRules.Count == 0) { return(null); } foreach (var rule in ProductionRules) { if (ExpressoParser.ParseBoolExpression(this, rule.Conditional)) { return(rule.VisVars); } } return(ProductionRules.Last().VisVars); }
private void UpdateViewForVisVar(VisVar visVar) { switch (visVar.Property) { case IATKProperty.X: case IATKProperty.Y: case IATKProperty.Z: case IATKProperty.Colour: case IATKProperty.Size: DataAttribute dataAttribute = ExpressoParser.ParseExpression(VisualisationReference, visVar.Formula); dataAttributes[visVar.Property] = dataAttribute; break; case IATKProperty.ScaleX: float x = ExpressoParser.ParseFloatExpression(VisualisationReference, visVar.Formula); geometry.transform.localScale = new Vector3(x, geometry.transform.localScale.y, geometry.transform.localScale.z); break; case IATKProperty.ScaleY: float y = ExpressoParser.ParseFloatExpression(VisualisationReference, visVar.Formula); geometry.transform.localScale = new Vector3(geometry.transform.localScale.x, y, geometry.transform.localScale.z); break; case IATKProperty.ScaleZ: float z = ExpressoParser.ParseFloatExpression(VisualisationReference, visVar.Formula); geometry.transform.localScale = new Vector3(geometry.transform.localScale.x, geometry.transform.localScale.y, z); break; case IATKProperty.Position: Vector3?position = ExpressoParser.ParseVector3Expression(VisualisationReference, visVar.Formula); if (position.HasValue) { geometry.transform.position = position.Value; } break; case IATKProperty.Rotation: Quaternion?rotation = ExpressoParser.ParseQuaternionExpression(VisualisationReference, visVar.Formula); if (rotation.HasValue) { geometry.transform.rotation = rotation.Value; } break; } }
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()); }