using System.Collections; using System.Collections.Generic; using System.IO; using UnityEditor; using UnityEngine; using ConsoleLSystem; using System; public class Rose : TurtleLSystem { public GameObject obj; public GameObject obj2; public float angle; private Func _roation(Vector3 axis) { Matrix4x4 f(float[] args) { if (args.Length == 0) { return Matrix4x4.Rotate(Quaternion.AngleAxis(angle, axis)); } else { return Matrix4x4.Rotate(Quaternion.AngleAxis(args[0], axis)); } } return f; } protected override void initLiteralInterpretation() { turtleInterpretation = new Dictionary>>(); //turtleInterpretation var transformation = Matrix4x4.Translate(new Vector3(0.0f, 0.1f, 0)) * Matrix4x4.Scale(new Vector3(0.05f, 0.1f, 0.05f)); var path = "Assets/Models/{0}.fbx"; var B = (GameObject)AssetDatabase.LoadAssetAtPath(String.Format(path, "leaf"), typeof(GameObject)); var W = (GameObject)AssetDatabase.LoadAssetAtPath(String.Format(path, "bigL"), typeof(GameObject)); //turtleInterpretation.Add("+", (float[] args) => new Tuple(null, Matrix4x4.Rotate(Quaternion.Euler(0, 0, -angle)))); //turtleInterpretation.Add("-", (float[] args) => new Tuple(null, Matrix4x4.Rotate(Quaternion.Euler(0, 0, angle)))); //turtleInterpretation.Add("\\", (float[] args) => new Tuple(null, Matrix4x4.Rotate(Quaternion.Euler(0, -angle, 0)))); //turtleInterpretation.Add("/", (float[] args) => new Tuple(null, Matrix4x4.Rotate(Quaternion.Euler(0, angle, 0)))); //turtleInterpretation.Add("^", (float[] args) => new Tuple(null, Matrix4x4.Rotate(Quaternion.Euler(-angle, 0, 0)))); //turtleInterpretation.Add("&", (float[] args) => new Tuple(null, Matrix4x4.Rotate(Quaternion.Euler(angle, 0, 0)))); turtleInterpretation.Add("+", (float[] args) => new Tuple(null, _roation(Vector3.back)(args))); turtleInterpretation.Add("-", (float[] args) => new Tuple(null, _roation(Vector3.forward)(args))); turtleInterpretation.Add("\\", (float[] args) => new Tuple(null, _roation(Vector3.down)(args))); turtleInterpretation.Add("/", (float[] args) => new Tuple(null, _roation(Vector3.up)(args))); turtleInterpretation.Add("^", (float[] args) => new Tuple(null, _roation(Vector3.left)(args))); turtleInterpretation.Add("&", (float[] args) => new Tuple(null, _roation(Vector3.right)(args))); turtleInterpretation.Add("f", (float[] args) => new Tuple(null, Matrix4x4.Translate(Vector3.up * args[0]))); turtleInterpretation.Add("C", (float[] args) => new Tuple(null, Matrix4x4.identity)); turtleInterpretation.Add("N", (float[] args) => new Tuple(null, Matrix4x4.identity)); //Wildcard how to represent any other symbol turtleInterpretation.Add("*.*", (float[] args) => new Tuple(obj, transformation)); turtleInterpretation.Add("G", (float[] args) => new Tuple(obj2, Matrix4x4.Translate(new Vector3(0.0f, 0.0f, 0)) * Matrix4x4.Scale(new Vector3(0.65f, 0.65f, 0.65f)))); turtleInterpretation.Add("B", (float[] args) => new Tuple(B, Matrix4x4.Translate(new Vector3(0.0f, 0.0f, 0)) * Matrix4x4.Scale(new Vector3(0.5f, 0.5f, 0.5f)))); turtleInterpretation.Add("W", (float[] args) => new Tuple(W, Matrix4x4.Translate(new Vector3(0.0f, 0.0f, 0)) * Matrix4x4.Scale(new Vector3(0.02f, 0.02f, 0.02f)))); } }